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/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"
#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,
Revert "Reland "Create updateResourceLabel method."" This reverts commit 35ef74b7a4c5ac23fecea00fa71076bc1be4d8ac. Reason for revert: causing chrome roll failure? Original change's description: > Reland "Create updateResourceLabel method." > > This is a reland of commit 605f92c7d7f97d6edf152f6e9d0fc88f8cd8c700 > > Original change's description: > > Create updateResourceLabel method. > > > > In this CL, the GrSurfaceProxy's and GrDrawOpAtlas's label strings > > are plumbed so that it can be stored in the label string of > > GrGpuResource. updateResourceLabel method, which is called from > > setLabel method, will add labels to Skia OpenGL backend using ANGLE's > > labeling API. > > > > Bug: chromium:1164111 > > Change-Id: I370715d186357e920d260d624d77586cdddd11e8 > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/541230 > > Reviewed-by: Greg Daniel <egdaniel@google.com> > > Commit-Queue: Greg Daniel <egdaniel@google.com> > > Bug: chromium:1164111 > Change-Id: Ia20a81d22e320813cbc4ad1d41e06e47dc3827bb > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/544058 > Reviewed-by: Greg Daniel <egdaniel@google.com> > Commit-Queue: Greg Daniel <egdaniel@google.com> Bug: chromium:1164111 Change-Id: Icacb3a0f2f2ee03afc09e03c2ee59b03d5bdd811 No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://skia-review.googlesource.com/c/skia/+/544241 Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com> Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com> Auto-Submit: Tyler Denniston <tdenniston@google.com>
2022-05-26 15:24:19 +00:00
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);
}
}
}