skia2/tests/ProxyRefTest.cpp
Brian Salomon beb7f525c8 Make GrSurfaceProxy constructors take arg that determines participation in
GrResourceAllocator.

Removes LazyInstantiationType. All callbacks can be invoked one time (if successful).
Lazy callbacks indicate whether their lifetime should be extended, which is used by
promise image proxy callbacks.

Promise image proxies are no longer deinstantiated at the end of flush and
GrDeinstantiateProxyTracker is removed. They will be instantiated the first time
they are encountered in GrResourceAllocator::addInterval (without actually adding
an interval) and then remain instantiated.

Also removes some "helper" versions of proxy factory functions that took fewer
params. They weren't much used outside of test code and as the total number of params
has grown their relative utility has diminished. We could consider a params struct
or radically simpler helpers that take only a few params if desired.

Change-Id: Ic6b09e7b807b66cb9fcbb7a67ae0f9faf345485f
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/238216
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
2019-09-03 14:58:41 +00:00

123 lines
4.1 KiB
C++

/*
* 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.
#include "tests/Test.h"
#include "include/gpu/GrTexture.h"
#include "src/gpu/GrContextPriv.h"
#include "src/gpu/GrProxyProvider.h"
#include "src/gpu/GrRenderTargetProxy.h"
#include "src/gpu/GrResourceProvider.h"
#include "src/gpu/GrSurfaceProxy.h"
#include "src/gpu/GrTextureProxy.h"
static const int kWidthHeight = 128;
static void check_refs(skiatest::Reporter* reporter,
GrTextureProxy* proxy,
int32_t expectedProxyRefs,
int32_t expectedBackingRefs) {
int32_t actualProxyRefs = proxy->refCnt();
int32_t actualBackingRefs = proxy->testingOnly_getBackingRefCnt();
SkASSERT(actualProxyRefs == expectedProxyRefs);
SkASSERT(actualBackingRefs == expectedBackingRefs);
REPORTER_ASSERT(reporter, actualProxyRefs == expectedProxyRefs);
REPORTER_ASSERT(reporter, actualBackingRefs == expectedBackingRefs);
}
static sk_sp<GrTextureProxy> make_deferred(GrContext* context) {
GrProxyProvider* proxyProvider = context->priv().proxyProvider();
const GrCaps* caps = context->priv().caps();
GrSurfaceDesc desc;
desc.fWidth = kWidthHeight;
desc.fHeight = kWidthHeight;
desc.fConfig = kRGBA_8888_GrPixelConfig;
const GrBackendFormat format = caps->getDefaultBackendFormat(GrColorType::kRGBA_8888,
GrRenderable::kYes);
return proxyProvider->createProxy(format, desc, GrRenderable::kYes, 1,
kBottomLeft_GrSurfaceOrigin, GrMipMapped::kNo,
SkBackingFit::kApprox, SkBudgeted::kYes, GrProtected::kNo);
}
static sk_sp<GrTextureProxy> make_wrapped(GrContext* context) {
GrProxyProvider* proxyProvider = context->priv().proxyProvider();
return proxyProvider->testingOnly_createInstantiatedProxy(
{kWidthHeight, kWidthHeight}, GrColorType::kRGBA_8888, GrRenderable::kYes, 1,
kBottomLeft_GrSurfaceOrigin, SkBackingFit::kExact, SkBudgeted::kNo, GrProtected::kNo);
}
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ProxyRefTest, reporter, ctxInfo) {
GrResourceProvider* resourceProvider = ctxInfo.grContext()->priv().resourceProvider();
for (auto make : { make_deferred, make_wrapped }) {
// An extra ref
{
sk_sp<GrTextureProxy> proxy((*make)(ctxInfo.grContext()));
if (proxy) {
sk_sp<GrTextureProxy> extraRef(proxy);
int backingRefs = proxy->isInstantiated() ? 1 : -1;
check_refs(reporter, proxy.get(), 2, backingRefs);
proxy->instantiate(resourceProvider);
check_refs(reporter, proxy.get(), 2, 1);
}
check_refs(reporter, proxy.get(), 1, 1);
}
// Multiple normal refs
{
sk_sp<GrTextureProxy> proxy((*make)(ctxInfo.grContext()));
if (proxy.get()) {
proxy->ref();
proxy->ref();
int backingRefs = proxy->isInstantiated() ? 1 : -1;
check_refs(reporter, proxy.get(), 3, backingRefs);
proxy->instantiate(resourceProvider);
check_refs(reporter, proxy.get(), 3, 1);
proxy->unref();
proxy->unref();
}
check_refs(reporter, proxy.get(), 1, 1);
}
// Continue using (reffing) proxy after instantiation
{
sk_sp<GrTextureProxy> proxy((*make)(ctxInfo.grContext()));
if (proxy) {
sk_sp<GrTextureProxy> firstExtraRef(proxy);
int backingRefs = proxy->isInstantiated() ? 1 : -1;
check_refs(reporter, proxy.get(), 2, backingRefs);
proxy->instantiate(resourceProvider);
check_refs(reporter, proxy.get(), 2, 1);
sk_sp<GrTextureProxy> secondExtraRef(proxy);
check_refs(reporter, proxy.get(), 3, 1);
}
check_refs(reporter, proxy.get(), 1, 1);
}
}
}