Flutter Engine
The Flutter Engine
ProxyRefTest.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8// This is a GPU-backend specific test.
9
16#include "include/gpu/GrTypes.h"
25#include "tests/Test.h"
26#include "tests/TestUtils.h"
27
28#include <initializer_list>
29
31struct GrContextOptions;
32
33static const int kWidthHeight = 128;
34
36 GrProxyProvider* proxyProvider = rContext->priv().proxyProvider();
37 const GrCaps* caps = rContext->priv().caps();
38
41 return proxyProvider->createProxy(format,
44 1,
49 /*label=*/"ProxyRefTest");
50}
51
53 GrProxyProvider* proxyProvider = rContext->priv().proxyProvider();
54
55 return proxyProvider->testingOnly_createInstantiatedProxy({kWidthHeight, kWidthHeight},
58 1,
62}
63
66 ctxInfo,
68 auto dContext = ctxInfo.directContext();
69 GrResourceProvider* resourceProvider = dContext->priv().resourceProvider();
70
71 for (auto make : { make_deferred, make_wrapped }) {
72 // An extra ref
73 {
74 sk_sp<GrTextureProxy> proxy((*make)(dContext));
75 if (proxy) {
76 sk_sp<GrTextureProxy> extraRef(proxy); // NOLINT(performance-unnecessary-copy-initialization)
77
78 int backingRefs = proxy->isInstantiated() ? 1 : -1;
79
80 CheckSingleThreadedProxyRefs(reporter, proxy.get(), 2, backingRefs);
81
82 proxy->instantiate(resourceProvider);
83
85 }
87 }
88
89 // Multiple normal refs
90 {
91 sk_sp<GrTextureProxy> proxy((*make)(dContext));
92 if (proxy) {
93 proxy->ref();
94 proxy->ref();
95
96 int backingRefs = proxy->isInstantiated() ? 1 : -1;
97
98 CheckSingleThreadedProxyRefs(reporter, proxy.get(), 3, backingRefs);
99
100 proxy->instantiate(resourceProvider);
101
103
104 proxy->unref();
105 proxy->unref();
106 }
108 }
109
110 // Continue using (reffing) proxy after instantiation
111 {
112 sk_sp<GrTextureProxy> proxy((*make)(dContext));
113 if (proxy) {
114 sk_sp<GrTextureProxy> firstExtraRef(proxy); // NOLINT(performance-unnecessary-copy-initialization)
115
116 int backingRefs = proxy->isInstantiated() ? 1 : -1;
117
118 CheckSingleThreadedProxyRefs(reporter, proxy.get(), 2, backingRefs);
119
120 proxy->instantiate(resourceProvider);
121
123
124 sk_sp<GrTextureProxy> secondExtraRef(proxy); // NOLINT(performance-unnecessary-copy-initialization)
126 }
128 }
129 }
130}
reporter
Definition: FontMgrTest.cpp:39
static sk_sp< GrTextureProxy > make_wrapped(GrRecordingContext *rContext)
static sk_sp< GrTextureProxy > make_deferred(GrRecordingContext *rContext)
DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS(ProxyRefTest, reporter, ctxInfo, CtsEnforcement::kApiLevel_T)
static const int kWidthHeight
void CheckSingleThreadedProxyRefs(skiatest::Reporter *reporter, GrSurfaceProxy *proxy, int32_t expectedProxyRefs, int32_t expectedBackingRefs)
Definition: TestUtils.cpp:231
const GrCaps * caps() const
Definition: GrCaps.h:57
GrBackendFormat getDefaultBackendFormat(GrColorType, GrRenderable) const
Definition: GrCaps.cpp:400
sk_sp< GrTextureProxy > createProxy(const GrBackendFormat &, SkISize dimensions, GrRenderable, int renderTargetSampleCnt, skgpu::Mipmapped, SkBackingFit, skgpu::Budgeted, GrProtected, std::string_view label, GrInternalSurfaceFlags=GrInternalSurfaceFlags::kNone, UseAllocator useAllocator=UseAllocator::kYes)
GrProxyProvider * proxyProvider()
GrRecordingContextPriv priv()
GrResourceProviderPriv priv()
bool isInstantiated() const
bool instantiate(GrResourceProvider *) override
void unref() const
Definition: SkRefCnt.h:177
void ref() const
Definition: SkRefCnt.h:176
T * get() const
Definition: SkRefCnt.h:303
uint32_t uint32_t * format
static void make(SkBitmap *bitmap, SkColorType colorType, SkAlphaType alphaType, sk_sp< SkColorSpace > colorSpace)
Definition: encode_srgb.cpp:35