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/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"
|
2019-10-24 14:37:08 +00:00
|
|
|
#include "tests/TestUtils.h"
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2017-02-28 21:30:28 +00:00
|
|
|
static const int kWidthHeight = 128;
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
const GrBackendFormat format = caps->getDefaultBackendFormat(GrColorType::kRGBA_8888,
|
|
|
|
GrRenderable::kYes);
|
2020-01-21 19:29:57 +00:00
|
|
|
GrSwizzle swizzle = caps->getReadSwizzle(format, GrColorType::kRGBA_8888);
|
2020-02-07 19:17:25 +00:00
|
|
|
return proxyProvider->createProxy(format, {kWidthHeight, kWidthHeight}, swizzle,
|
2020-02-14 15:47:18 +00:00
|
|
|
GrRenderable::kYes, 1, GrMipMapped::kNo,
|
|
|
|
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,
|
2020-02-14 15:47:18 +00:00
|
|
|
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-08-20 20:56:18 +00:00
|
|
|
// An extra ref
|
2016-11-16 19:17:17 +00:00
|
|
|
{
|
2019-07-30 16:49:10 +00:00
|
|
|
sk_sp<GrTextureProxy> proxy((*make)(ctxInfo.grContext()));
|
2019-08-20 20:56:18 +00:00
|
|
|
if (proxy) {
|
|
|
|
sk_sp<GrTextureProxy> extraRef(proxy);
|
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-10-25 00:07:39 +00:00
|
|
|
CheckSingleThreadedProxyRefs(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-10-25 00:07:39 +00:00
|
|
|
CheckSingleThreadedProxyRefs(reporter, proxy.get(), 2, 1);
|
2017-09-20 21:51:59 +00:00
|
|
|
}
|
2019-10-25 00:07:39 +00:00
|
|
|
CheckSingleThreadedProxyRefs(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-10-25 00:07:39 +00:00
|
|
|
CheckSingleThreadedProxyRefs(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-10-25 00:07:39 +00:00
|
|
|
CheckSingleThreadedProxyRefs(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-10-25 00:07:39 +00:00
|
|
|
CheckSingleThreadedProxyRefs(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()));
|
2019-08-20 20:56:18 +00:00
|
|
|
if (proxy) {
|
|
|
|
sk_sp<GrTextureProxy> firstExtraRef(proxy);
|
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-10-25 00:07:39 +00:00
|
|
|
CheckSingleThreadedProxyRefs(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-10-25 00:07:39 +00:00
|
|
|
CheckSingleThreadedProxyRefs(reporter, proxy.get(), 2, 1);
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2019-08-20 20:56:18 +00:00
|
|
|
sk_sp<GrTextureProxy> secondExtraRef(proxy);
|
2019-10-25 00:07:39 +00:00
|
|
|
CheckSingleThreadedProxyRefs(reporter, proxy.get(), 3, 1);
|
2017-09-20 21:51:59 +00:00
|
|
|
}
|
2019-10-25 00:07:39 +00:00
|
|
|
CheckSingleThreadedProxyRefs(reporter, proxy.get(), 1, 1);
|
2016-11-16 19:17:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|