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"
|
|
|
|
|
2020-07-06 14:56:46 +00:00
|
|
|
#include "include/gpu/GrDirectContext.h"
|
2022-04-07 15:20:24 +00:00
|
|
|
#include "src/gpu/ganesh/GrDirectContextPriv.h"
|
|
|
|
#include "src/gpu/ganesh/GrProxyProvider.h"
|
|
|
|
#include "src/gpu/ganesh/GrRecordingContextPriv.h"
|
|
|
|
#include "src/gpu/ganesh/GrRenderTargetProxy.h"
|
|
|
|
#include "src/gpu/ganesh/GrResourceProvider.h"
|
|
|
|
#include "src/gpu/ganesh/GrSurfaceProxy.h"
|
|
|
|
#include "src/gpu/ganesh/GrTexture.h"
|
|
|
|
#include "src/gpu/ganesh/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;
|
|
|
|
|
2020-07-23 17:54:35 +00:00
|
|
|
static sk_sp<GrTextureProxy> make_deferred(GrRecordingContext* rContext) {
|
|
|
|
GrProxyProvider* proxyProvider = rContext->priv().proxyProvider();
|
|
|
|
const GrCaps* caps = rContext->priv().caps();
|
2019-07-30 16:49:10 +00:00
|
|
|
|
|
|
|
const GrBackendFormat format = caps->getDefaultBackendFormat(GrColorType::kRGBA_8888,
|
|
|
|
GrRenderable::kYes);
|
2020-03-27 00:37:01 +00:00
|
|
|
return proxyProvider->createProxy(format, {kWidthHeight, kWidthHeight}, GrRenderable::kYes, 1,
|
2020-07-21 13:27:25 +00:00
|
|
|
GrMipmapped::kNo, SkBackingFit::kApprox, SkBudgeted::kYes,
|
2022-05-26 15:24:19 +00:00
|
|
|
GrProtected::kNo);
|
2016-11-16 19:17:17 +00:00
|
|
|
}
|
|
|
|
|
2020-07-23 17:54:35 +00:00
|
|
|
static sk_sp<GrTextureProxy> make_wrapped(GrRecordingContext* rContext) {
|
|
|
|
GrProxyProvider* proxyProvider = rContext->priv().proxyProvider();
|
2019-07-30 16:49:10 +00:00
|
|
|
|
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) {
|
2020-07-23 17:54:35 +00:00
|
|
|
auto dContext = ctxInfo.directContext();
|
|
|
|
GrResourceProvider* resourceProvider = dContext->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
|
|
|
{
|
2020-07-23 17:54:35 +00:00
|
|
|
sk_sp<GrTextureProxy> proxy((*make)(dContext));
|
2019-08-20 20:56:18 +00:00
|
|
|
if (proxy) {
|
2020-08-07 21:35:54 +00:00
|
|
|
sk_sp<GrTextureProxy> extraRef(proxy); // NOLINT(performance-unnecessary-copy-initialization)
|
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
|
|
|
|
{
|
2020-07-23 17:54:35 +00:00
|
|
|
sk_sp<GrTextureProxy> proxy((*make)(dContext));
|
2020-08-16 12:48:02 +00:00
|
|
|
if (proxy) {
|
2017-09-20 21:51:59 +00:00
|
|
|
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
|
|
|
|
{
|
2020-07-23 17:54:35 +00:00
|
|
|
sk_sp<GrTextureProxy> proxy((*make)(dContext));
|
2019-08-20 20:56:18 +00:00
|
|
|
if (proxy) {
|
2020-08-07 21:35:54 +00:00
|
|
|
sk_sp<GrTextureProxy> firstExtraRef(proxy); // NOLINT(performance-unnecessary-copy-initialization)
|
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
|
|
|
|
2020-08-07 21:35:54 +00:00
|
|
|
sk_sp<GrTextureProxy> secondExtraRef(proxy); // NOLINT(performance-unnecessary-copy-initialization)
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|