Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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
40 GrRenderable::kYes);
41 return proxyProvider->createProxy(format,
43 GrRenderable::kYes,
44 1,
45 skgpu::Mipmapped::kNo,
48 GrProtected::kNo,
49 /*label=*/"ProxyRefTest");
50}
51
53 GrProxyProvider* proxyProvider = rContext->priv().proxyProvider();
54
55 return proxyProvider->testingOnly_createInstantiatedProxy({kWidthHeight, kWidthHeight},
57 GrRenderable::kYes,
58 1,
61 GrProtected::kNo);
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
static sk_sp< GrTextureProxy > make_wrapped(GrRecordingContext *rContext)
static sk_sp< GrTextureProxy > make_deferred(GrRecordingContext *rContext)
static const int kWidthHeight
void CheckSingleThreadedProxyRefs(skiatest::Reporter *reporter, GrSurfaceProxy *proxy, int32_t expectedProxyRefs, int32_t expectedBackingRefs)
#define DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS(name, reporter, context_info, ctsEnforcement)
Definition Test.h:434
const GrCaps * caps() const
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()
T * get() const
Definition SkRefCnt.h:303
uint32_t uint32_t * format
static sk_sp< SkImage > make(sk_sp< SkColorSpace > cs)
Definition mipmap.cpp:65