2016-11-16 19:17:17 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2016 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// This is a GPU-backend specific test.
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tests/Test.h"
|
|
|
|
|
|
|
|
#include "include/gpu/GrTexture.h"
|
|
|
|
#include "src/gpu/GrContextPriv.h"
|
|
|
|
#include "src/gpu/GrPendingIOResource.h"
|
|
|
|
#include "src/gpu/GrProxyProvider.h"
|
2019-06-18 13:58:02 +00:00
|
|
|
#include "src/gpu/GrRenderTargetProxy.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/GrResourceProvider.h"
|
2019-06-18 13:58:02 +00:00
|
|
|
#include "src/gpu/GrSurfaceProxy.h"
|
|
|
|
#include "src/gpu/GrTextureProxy.h"
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2017-02-28 21:30:28 +00:00
|
|
|
static const int kWidthHeight = 128;
|
|
|
|
|
2016-11-16 19:17:17 +00:00
|
|
|
static void check_refs(skiatest::Reporter* reporter,
|
2017-03-30 12:02:11 +00:00
|
|
|
GrTextureProxy* proxy,
|
2016-11-16 19:17:17 +00:00
|
|
|
int32_t expectedProxyRefs,
|
2019-06-11 12:08:08 +00:00
|
|
|
int32_t expectedBackingRefs) {
|
|
|
|
int32_t actualProxyRefs = proxy->priv().getProxyRefCnt();
|
2019-06-19 18:12:13 +00:00
|
|
|
int32_t actualBackingRefs = proxy->testingOnly_getBackingRefCnt();
|
2019-06-11 12:08:08 +00:00
|
|
|
|
|
|
|
SkASSERT(actualProxyRefs == expectedProxyRefs);
|
|
|
|
SkASSERT(actualBackingRefs == expectedBackingRefs);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, actualProxyRefs == expectedProxyRefs);
|
|
|
|
REPORTER_ASSERT(reporter, actualBackingRefs == expectedBackingRefs);
|
2016-11-16 19:17:17 +00:00
|
|
|
}
|
|
|
|
|
2019-07-30 16:49:10 +00:00
|
|
|
static sk_sp<GrTextureProxy> make_deferred(GrContext* context) {
|
|
|
|
GrProxyProvider* proxyProvider = context->priv().proxyProvider();
|
|
|
|
const GrCaps* caps = context->priv().caps();
|
|
|
|
|
2016-11-16 19:17:17 +00:00
|
|
|
GrSurfaceDesc desc;
|
|
|
|
desc.fWidth = kWidthHeight;
|
|
|
|
desc.fHeight = kWidthHeight;
|
|
|
|
desc.fConfig = kRGBA_8888_GrPixelConfig;
|
|
|
|
|
2019-07-30 16:49:10 +00:00
|
|
|
const GrBackendFormat format = caps->getDefaultBackendFormat(GrColorType::kRGBA_8888,
|
|
|
|
GrRenderable::kYes);
|
2019-07-22 18:23:45 +00:00
|
|
|
return proxyProvider->createProxy(format, desc, GrRenderable::kYes, 1,
|
|
|
|
kBottomLeft_GrSurfaceOrigin, SkBackingFit::kApprox,
|
|
|
|
SkBudgeted::kYes, GrProtected::kNo);
|
2016-11-16 19:17:17 +00:00
|
|
|
}
|
|
|
|
|
2019-07-30 16:49:10 +00:00
|
|
|
static sk_sp<GrTextureProxy> make_wrapped(GrContext* context) {
|
|
|
|
GrProxyProvider* proxyProvider = context->priv().proxyProvider();
|
|
|
|
|
2018-09-27 15:28:03 +00:00
|
|
|
return proxyProvider->testingOnly_createInstantiatedProxy(
|
2019-08-05 16:58:39 +00:00
|
|
|
{kWidthHeight, kWidthHeight}, GrColorType::kRGBA_8888, GrRenderable::kYes, 1,
|
|
|
|
kBottomLeft_GrSurfaceOrigin, SkBackingFit::kExact, SkBudgeted::kNo, GrProtected::kNo);
|
2016-11-16 19:17:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ProxyRefTest, reporter, ctxInfo) {
|
2019-02-04 18:26:26 +00:00
|
|
|
GrResourceProvider* resourceProvider = ctxInfo.grContext()->priv().resourceProvider();
|
2016-11-16 19:17:17 +00:00
|
|
|
|
|
|
|
for (auto make : { make_deferred, make_wrapped }) {
|
2019-06-11 12:08:08 +00:00
|
|
|
// Pending IO ref
|
2016-11-16 19:17:17 +00:00
|
|
|
{
|
2019-07-30 16:49:10 +00:00
|
|
|
sk_sp<GrTextureProxy> proxy((*make)(ctxInfo.grContext()));
|
2017-09-20 21:51:59 +00:00
|
|
|
if (proxy.get()) {
|
2019-06-11 12:08:08 +00:00
|
|
|
GrProxyPendingIO pendingIO(proxy.get());
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2019-06-19 18:12:13 +00:00
|
|
|
int backingRefs = proxy->isInstantiated() ? 1 : -1;
|
2018-07-18 17:56:48 +00:00
|
|
|
|
2019-06-11 12:08:08 +00:00
|
|
|
check_refs(reporter, proxy.get(), 2, backingRefs);
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2018-01-16 13:06:32 +00:00
|
|
|
proxy->instantiate(resourceProvider);
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2019-06-18 21:15:04 +00:00
|
|
|
check_refs(reporter, proxy.get(), 2, 1);
|
2017-09-20 21:51:59 +00:00
|
|
|
}
|
2019-06-11 12:08:08 +00:00
|
|
|
check_refs(reporter, proxy.get(), 1, 1);
|
2016-11-16 19:17:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Multiple normal refs
|
|
|
|
{
|
2019-07-30 16:49:10 +00:00
|
|
|
sk_sp<GrTextureProxy> proxy((*make)(ctxInfo.grContext()));
|
2017-09-20 21:51:59 +00:00
|
|
|
if (proxy.get()) {
|
|
|
|
proxy->ref();
|
|
|
|
proxy->ref();
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2019-06-19 18:12:13 +00:00
|
|
|
int backingRefs = proxy->isInstantiated() ? 1 : -1;
|
2018-07-18 17:56:48 +00:00
|
|
|
|
2019-06-11 12:08:08 +00:00
|
|
|
check_refs(reporter, proxy.get(), 3, backingRefs);
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2018-01-16 13:06:32 +00:00
|
|
|
proxy->instantiate(resourceProvider);
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2019-06-18 21:15:04 +00:00
|
|
|
check_refs(reporter, proxy.get(), 3, 1);
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2017-09-20 21:51:59 +00:00
|
|
|
proxy->unref();
|
|
|
|
proxy->unref();
|
|
|
|
}
|
2019-06-11 12:08:08 +00:00
|
|
|
check_refs(reporter, proxy.get(), 1, 1);
|
2016-11-16 19:17:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Continue using (reffing) proxy after instantiation
|
|
|
|
{
|
2019-07-30 16:49:10 +00:00
|
|
|
sk_sp<GrTextureProxy> proxy((*make)(ctxInfo.grContext()));
|
2017-09-20 21:51:59 +00:00
|
|
|
if (proxy.get()) {
|
|
|
|
proxy->ref();
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2019-06-11 12:08:08 +00:00
|
|
|
GrProxyPendingIO pendingIO(proxy.get());
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2019-06-19 18:12:13 +00:00
|
|
|
int backingRefs = proxy->isInstantiated() ? 1 : -1;
|
2018-07-18 17:56:48 +00:00
|
|
|
|
2019-06-11 12:08:08 +00:00
|
|
|
check_refs(reporter, proxy.get(), 3, backingRefs);
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2018-01-16 13:06:32 +00:00
|
|
|
proxy->instantiate(resourceProvider);
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2019-06-18 21:15:04 +00:00
|
|
|
check_refs(reporter, proxy.get(), 3, 1);
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2017-09-20 21:51:59 +00:00
|
|
|
proxy->unref();
|
2019-06-18 21:15:04 +00:00
|
|
|
check_refs(reporter, proxy.get(), 2, 1);
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2019-06-11 12:08:08 +00:00
|
|
|
GrProxyPendingIO secondPendingIO(proxy.get());
|
2019-06-18 21:15:04 +00:00
|
|
|
check_refs(reporter, proxy.get(), 3, 1);
|
2017-09-20 21:51:59 +00:00
|
|
|
}
|
2019-06-11 12:08:08 +00:00
|
|
|
check_refs(reporter, proxy.get(), 1, 1);
|
2016-11-16 19:17:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|