skia2/tests/ProxyRefTest.cpp

108 lines
3.9 KiB
C++
Raw Normal View History

/*
* 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/GrDirectContext.h"
#include "src/gpu/GrContextPriv.h"
#include "src/gpu/GrProxyProvider.h"
#include "src/gpu/GrRecordingContextPriv.h"
#include "src/gpu/GrRenderTargetProxy.h"
#include "src/gpu/GrResourceProvider.h"
#include "src/gpu/GrSurfaceProxy.h"
Reland "Move GrGpuResource GrSurface and GrTexture into src." This reverts commit f6ed96d1c23b79130ca7344c984b07ef9d94fb7b. Reason for revert: google3 change landed Original change's description: > Revert "Move GrGpuResource GrSurface and GrTexture into src." > > This reverts commit e5a06ce678aad7640411f99f70f220f82ad49908. > > Reason for revert: Need to make change in google3 first > > Original change's description: > > Move GrGpuResource GrSurface and GrTexture into src. > > > > Must land https://chromium-review.googlesource.com/c/chromium/src/+/2087980 > > before this can land. > > > > Bug: skia:7966 > > Change-Id: I60bbb1765bfbb2c96b2bc0c9826b6b9d57eb2a03 > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/275077 > > Commit-Queue: Greg Daniel <egdaniel@google.com> > > Reviewed-by: Robert Phillips <robertphillips@google.com> > > TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com > > Change-Id: Id39e0a351e49a87209de88a6ad9fadb0219db72c > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:7966 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/275216 > Reviewed-by: Greg Daniel <egdaniel@google.com> > Commit-Queue: Greg Daniel <egdaniel@google.com> TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com Change-Id: I746ce739cb084cefc46f9dab24ef773e7c3cc621 No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: skia:7966 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/275436 Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Greg Daniel <egdaniel@google.com>
2020-03-05 19:14:18 +00:00
#include "src/gpu/GrTexture.h"
#include "src/gpu/GrTextureProxy.h"
#include "tests/TestUtils.h"
static const int kWidthHeight = 128;
static sk_sp<GrTextureProxy> make_deferred(GrRecordingContext* rContext) {
GrProxyProvider* proxyProvider = rContext->priv().proxyProvider();
const GrCaps* caps = rContext->priv().caps();
const GrBackendFormat format = caps->getDefaultBackendFormat(GrColorType::kRGBA_8888,
GrRenderable::kYes);
return proxyProvider->createProxy(format, {kWidthHeight, kWidthHeight}, GrRenderable::kYes, 1,
GrMipmapped::kNo, SkBackingFit::kApprox, SkBudgeted::kYes,
GrProtected::kNo);
}
static sk_sp<GrTextureProxy> make_wrapped(GrRecordingContext* rContext) {
GrProxyProvider* proxyProvider = rContext->priv().proxyProvider();
return proxyProvider->testingOnly_createInstantiatedProxy(
{kWidthHeight, kWidthHeight}, GrColorType::kRGBA_8888, GrRenderable::kYes, 1,
SkBackingFit::kExact, SkBudgeted::kNo, GrProtected::kNo);
}
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ProxyRefTest, reporter, ctxInfo) {
auto dContext = ctxInfo.directContext();
GrResourceProvider* resourceProvider = dContext->priv().resourceProvider();
for (auto make : { make_deferred, make_wrapped }) {
// An extra ref
{
sk_sp<GrTextureProxy> proxy((*make)(dContext));
if (proxy) {
sk_sp<GrTextureProxy> extraRef(proxy); // NOLINT(performance-unnecessary-copy-initialization)
int backingRefs = proxy->isInstantiated() ? 1 : -1;
CheckSingleThreadedProxyRefs(reporter, proxy.get(), 2, backingRefs);
proxy->instantiate(resourceProvider);
CheckSingleThreadedProxyRefs(reporter, proxy.get(), 2, 1);
}
CheckSingleThreadedProxyRefs(reporter, proxy.get(), 1, 1);
}
// Multiple normal refs
{
sk_sp<GrTextureProxy> proxy((*make)(dContext));
if (proxy) {
proxy->ref();
proxy->ref();
int backingRefs = proxy->isInstantiated() ? 1 : -1;
CheckSingleThreadedProxyRefs(reporter, proxy.get(), 3, backingRefs);
proxy->instantiate(resourceProvider);
CheckSingleThreadedProxyRefs(reporter, proxy.get(), 3, 1);
proxy->unref();
proxy->unref();
}
CheckSingleThreadedProxyRefs(reporter, proxy.get(), 1, 1);
}
// Continue using (reffing) proxy after instantiation
{
sk_sp<GrTextureProxy> proxy((*make)(dContext));
if (proxy) {
sk_sp<GrTextureProxy> firstExtraRef(proxy); // NOLINT(performance-unnecessary-copy-initialization)
int backingRefs = proxy->isInstantiated() ? 1 : -1;
CheckSingleThreadedProxyRefs(reporter, proxy.get(), 2, backingRefs);
proxy->instantiate(resourceProvider);
CheckSingleThreadedProxyRefs(reporter, proxy.get(), 2, 1);
sk_sp<GrTextureProxy> secondExtraRef(proxy); // NOLINT(performance-unnecessary-copy-initialization)
CheckSingleThreadedProxyRefs(reporter, proxy.get(), 3, 1);
}
CheckSingleThreadedProxyRefs(reporter, proxy.get(), 1, 1);
}
}
}