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
|
|
|
}
|
|
|
|
|
2018-11-16 20:43:41 +00:00
|
|
|
static sk_sp<GrTextureProxy> make_deferred(GrProxyProvider* proxyProvider, const GrCaps* caps) {
|
2016-11-16 19:17:17 +00:00
|
|
|
GrSurfaceDesc desc;
|
|
|
|
desc.fFlags = kRenderTarget_GrSurfaceFlag;
|
|
|
|
desc.fWidth = kWidthHeight;
|
|
|
|
desc.fHeight = kWidthHeight;
|
|
|
|
desc.fConfig = kRGBA_8888_GrPixelConfig;
|
|
|
|
|
2018-11-16 20:43:41 +00:00
|
|
|
const GrBackendFormat format = caps->getBackendFormatFromColorType(kRGBA_8888_SkColorType);
|
|
|
|
return proxyProvider->createProxy(format, desc, kBottomLeft_GrSurfaceOrigin,
|
2019-04-24 18:09:10 +00:00
|
|
|
SkBackingFit::kApprox, SkBudgeted::kYes);
|
2016-11-16 19:17:17 +00:00
|
|
|
}
|
|
|
|
|
2018-11-16 20:43:41 +00:00
|
|
|
static sk_sp<GrTextureProxy> make_wrapped(GrProxyProvider* proxyProvider, const GrCaps* caps) {
|
2016-11-16 19:17:17 +00:00
|
|
|
GrSurfaceDesc desc;
|
|
|
|
desc.fFlags = kRenderTarget_GrSurfaceFlag;
|
|
|
|
desc.fWidth = kWidthHeight;
|
|
|
|
desc.fHeight = kWidthHeight;
|
|
|
|
desc.fConfig = kRGBA_8888_GrPixelConfig;
|
|
|
|
|
2018-09-27 15:28:03 +00:00
|
|
|
return proxyProvider->testingOnly_createInstantiatedProxy(
|
|
|
|
desc, kBottomLeft_GrSurfaceOrigin, SkBackingFit::kExact, SkBudgeted::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
|
|
|
GrProxyProvider* proxyProvider = ctxInfo.grContext()->priv().proxyProvider();
|
|
|
|
GrResourceProvider* resourceProvider = ctxInfo.grContext()->priv().resourceProvider();
|
|
|
|
const GrCaps* caps = ctxInfo.grContext()->priv().caps();
|
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
|
|
|
{
|
2018-11-16 20:43:41 +00:00
|
|
|
sk_sp<GrTextureProxy> proxy((*make)(proxyProvider, caps));
|
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
|
|
|
|
{
|
2018-11-16 20:43:41 +00:00
|
|
|
sk_sp<GrTextureProxy> proxy((*make)(proxyProvider, caps));
|
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
|
|
|
|
{
|
2018-11-16 20:43:41 +00:00
|
|
|
sk_sp<GrTextureProxy> proxy((*make)(proxyProvider, caps));
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|