Flutter Engine
The Flutter Engine
ProxyTest.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
12#include "include/core/SkSize.h"
17#include "include/gpu/GrTypes.h"
34#include "tests/Test.h"
36
37#if defined(SK_GL)
39#endif
40
41#include <initializer_list>
42
43struct GrContextOptions;
44
45// Check that the surface proxy's member vars are set as expected
47 GrSurfaceProxy* proxy,
48 int width,
49 int height,
50 skgpu::Budgeted budgeted) {
51 REPORTER_ASSERT(reporter, proxy->width() == width);
54 REPORTER_ASSERT(reporter, proxy->isBudgeted() == budgeted);
55}
56
58 const GrCaps& caps,
59 GrResourceProvider* provider,
60 GrRenderTargetProxy* rtProxy,
61 int numSamples,
62 SkBackingFit fit,
63 int expectedMaxWindowRects) {
64 REPORTER_ASSERT(reporter, rtProxy->maxWindowRectangles(caps) == expectedMaxWindowRects);
65 REPORTER_ASSERT(reporter, rtProxy->numSamples() == numSamples);
66
67 GrSurfaceProxy::UniqueID idBefore = rtProxy->uniqueID();
68 bool preinstantiated = rtProxy->isInstantiated();
69 REPORTER_ASSERT(reporter, rtProxy->instantiate(provider));
70 GrRenderTarget* rt = rtProxy->peekRenderTarget();
71
72 REPORTER_ASSERT(reporter, rtProxy->uniqueID() == idBefore);
73 // Deferred resources should always have a different ID from their instantiated rendertarget
74 if (preinstantiated) {
75 REPORTER_ASSERT(reporter, rtProxy->uniqueID().asUInt() == rt->uniqueID().asUInt());
76 } else {
77 REPORTER_ASSERT(reporter, rtProxy->uniqueID().asUInt() != rt->uniqueID().asUInt());
78 }
79
80 if (SkBackingFit::kExact == fit) {
81 REPORTER_ASSERT(reporter, rt->dimensions() == rtProxy->dimensions());
82 } else {
83 REPORTER_ASSERT(reporter, rt->width() >= rtProxy->width());
84 REPORTER_ASSERT(reporter, rt->height() >= rtProxy->height());
85 }
87
88 REPORTER_ASSERT(reporter, rt->numSamples() == rtProxy->numSamples());
89 REPORTER_ASSERT(reporter, rt->flags() == rtProxy->testingOnly_getFlags());
90}
91
93 GrResourceProvider* provider,
94 GrTextureProxy* texProxy,
95 SkBackingFit fit) {
96 GrSurfaceProxy::UniqueID idBefore = texProxy->uniqueID();
97
98 bool preinstantiated = texProxy->isInstantiated();
99 // The instantiated texture should have these dimensions. If the fit is kExact, then
100 // 'backingStoreDimensions' reports the original WxH. If it is kApprox, make sure that
101 // the texture is that size and didn't reuse one of the kExact surfaces in the provider.
102 // This is important because upstream usage (e.g. SkImage) reports size based on the
103 // backingStoreDimensions and client code may rely on that if they are creating backend
104 // resources.
105 // NOTE: we store these before instantiating, since after instantiation backingStoreDimensions
106 // just returns the target's dimensions. In this instance, we want to ensure the target's
107 // dimensions are no different from the original approximate (or exact) dimensions.
108 SkISize expectedSize = texProxy->backingStoreDimensions();
109
110 REPORTER_ASSERT(reporter, texProxy->instantiate(provider));
111 GrTexture* tex = texProxy->peekTexture();
112
113 REPORTER_ASSERT(reporter, texProxy->uniqueID() == idBefore);
114 // Deferred resources should always have a different ID from their instantiated texture
115 if (preinstantiated) {
116 REPORTER_ASSERT(reporter, texProxy->uniqueID().asUInt() == tex->uniqueID().asUInt());
117 } else {
118 REPORTER_ASSERT(reporter, texProxy->uniqueID().asUInt() != tex->uniqueID().asUInt());
119 }
120
121 REPORTER_ASSERT(reporter, tex->dimensions() == expectedSize);
122
123 REPORTER_ASSERT(reporter, tex->backendFormat() == texProxy->backendFormat());
124}
125
127 reporter,
128 ctxInfo,
130 using namespace skgpu;
131
132 auto direct = ctxInfo.directContext();
133 GrProxyProvider* proxyProvider = direct->priv().proxyProvider();
134 GrResourceProvider* resourceProvider = direct->priv().resourceProvider();
135 const GrCaps& caps = *direct->priv().caps();
136
137 Protected isProtected = Protected(caps.supportsProtectedContent());
138
139 for (auto widthHeight : {100, 128, 1048576}) {
142 for (auto fit : {SkBackingFit::kExact, SkBackingFit::kApprox}) {
143 for (auto budgeted : { Budgeted::kYes, Budgeted::kNo }) {
144 for (auto numSamples : {1, 4, 16, 128}) {
145 SkISize dims = {widthHeight, widthHeight};
146
148 if (!format.isValid()) {
149 continue;
150 }
151
152 // Renderable
153 {
155 if (SkBackingFit::kApprox == fit) {
156 tex = resourceProvider->createApproxTexture(dims,
157 format,
160 numSamples,
161 isProtected,
162 /*label=*/{});
163 } else {
164 tex = resourceProvider->createTexture(dims,
165 format,
168 numSamples,
170 budgeted,
171 isProtected,
172 /*label=*/{});
173 }
174
176 proxyProvider->createProxy(format,
177 dims,
179 numSamples,
181 fit,
182 budgeted,
183 isProtected,
184 /*label=*/{});
185 REPORTER_ASSERT(reporter, SkToBool(tex) == SkToBool(proxy));
186 if (proxy) {
188 // This forces the proxy to compute and cache its
189 // pre-instantiation size guess. Later, when it is actually
190 // instantiated, it checks that the instantiated size is <= to
191 // the pre-computation. If the proxy never computed its
192 // pre-instantiation size then the check is skipped.
193 proxy->gpuMemorySize();
194
195 check_surface(reporter, proxy.get(), widthHeight, widthHeight,
196 budgeted);
197 int supportedSamples =
198 caps.getRenderTargetSampleCount(numSamples, format);
199 check_rendertarget(reporter, caps, resourceProvider,
200 proxy->asRenderTargetProxy(), supportedSamples,
201 fit, caps.maxWindowRectangles());
202 }
203 }
204
205 // Not renderable
206 {
208 if (SkBackingFit::kApprox == fit) {
209 tex = resourceProvider->createApproxTexture(dims,
210 format,
213 numSamples,
214 isProtected,
215 /*label=*/{});
216 } else {
217 tex = resourceProvider->createTexture(dims,
218 format,
221 numSamples,
223 budgeted,
224 isProtected,
225 /*label=*/{});
226 }
227
229 proxyProvider->createProxy(format,
230 dims,
232 numSamples,
234 fit,
235 budgeted,
236 isProtected,
237 /*label=*/{}));
238 REPORTER_ASSERT(reporter, SkToBool(tex) == SkToBool(proxy));
239 if (proxy) {
240 // This forces the proxy to compute and cache its
241 // pre-instantiation size guess. Later, when it is actually
242 // instantiated, it checks that the instantiated size is <= to
243 // the pre-computation. If the proxy never computed its
244 // pre-instantiation size then the check is skipped.
245 proxy->gpuMemorySize();
246
247 check_surface(reporter, proxy.get(), widthHeight, widthHeight,
248 budgeted);
249 check_texture(reporter, resourceProvider, proxy->asTextureProxy(),
250 fit);
251 }
252 }
253 }
254 }
255 }
256 }
257 }
258}
259
261 reporter,
262 ctxInfo,
264 using namespace skgpu;
265
266 auto direct = ctxInfo.directContext();
267 GrProxyProvider* proxyProvider = direct->priv().proxyProvider();
268 GrResourceProvider* resourceProvider = direct->priv().resourceProvider();
269 GrGpu* gpu = direct->priv().getGpu();
270 const GrCaps& caps = *direct->priv().caps();
271
272 Protected isProtected = Protected(caps.supportsProtectedContent());
273
274 static const int kWidthHeight = 100;
275
276 for (auto colorType :
279
280 // External on-screen render target.
281 // Tests wrapBackendRenderTarget with a GrBackendRenderTarget
282 // Our test-only function that creates a backend render target doesn't currently support
283 // sample counts :(.
284 if (direct->colorTypeSupportedAsSurface(colorType)) {
285 GrBackendRenderTarget backendRT = gpu->createTestingOnlyBackendRenderTarget(
286 {kWidthHeight, kWidthHeight}, grColorType, /* sampleCount= */ 1, isProtected);
288 proxyProvider->wrapBackendRenderTarget(backendRT, nullptr));
289 check_surface(reporter, sProxy.get(), kWidthHeight, kWidthHeight, Budgeted::kNo);
290 static constexpr int kExpectedNumSamples = 1;
291 check_rendertarget(reporter, caps, resourceProvider, sProxy->asRenderTargetProxy(),
292 kExpectedNumSamples, SkBackingFit::kExact,
293 caps.maxWindowRectangles());
294 gpu->deleteTestingOnlyBackendRenderTarget(backendRT);
295 }
296
297 for (auto numSamples : {1, 4}) {
298 auto beFormat = caps.getDefaultBackendFormat(grColorType, GrRenderable::kYes);
299 int supportedNumSamples = caps.getRenderTargetSampleCount(numSamples, beFormat);
300 if (!supportedNumSamples) {
301 continue;
302 }
303
304#ifdef SK_GL
305 // Test wrapping FBO 0 (with made up properties). This tests sample count and the
306 // special case where FBO 0 doesn't support window rectangles.
307 if (GrBackendApi::kOpenGL == ctxInfo.backend()) {
308 GrGLFramebufferInfo fboInfo;
309 fboInfo.fFBOID = 0;
310 fboInfo.fFormat = GrBackendFormats::AsGLFormatEnum(beFormat);
311 fboInfo.fProtected = isProtected;
312 SkASSERT(fboInfo.fFormat);
313 static constexpr int kStencilBits = 8;
315 kWidthHeight, kWidthHeight, numSamples, kStencilBits, fboInfo);
317 proxyProvider->wrapBackendRenderTarget(backendRT, nullptr));
319 reporter, sProxy.get(), kWidthHeight, kWidthHeight, Budgeted::kNo);
320 check_rendertarget(reporter, caps, resourceProvider, sProxy->asRenderTargetProxy(),
321 supportedNumSamples, SkBackingFit::kExact, 0);
322 }
323#endif
324
325 // Tests wrapBackendTexture that is only renderable
326 {
327 auto mbet =
328 sk_gpu_test::ManagedBackendTexture::MakeWithoutData(direct,
331 colorType,
334 isProtected);
335 if (!mbet) {
337 "Could not create renderable backend texture of color type %d",
338 colorType);
339 continue;
340 }
342 mbet->texture(), supportedNumSamples, kBorrow_GrWrapOwnership,
343 GrWrapCacheable::kNo, nullptr);
344 if (!sProxy) {
345 ERRORF(reporter, "wrapRenderableBackendTexture failed");
346 continue;
347 }
348
350 reporter, sProxy.get(), kWidthHeight, kWidthHeight, Budgeted::kNo);
351 check_rendertarget(reporter, caps, resourceProvider, sProxy->asRenderTargetProxy(),
352 supportedNumSamples, SkBackingFit::kExact,
353 caps.maxWindowRectangles());
354 }
355
356 {
357 // Tests wrapBackendTexture that is only textureable
358 auto mbet =
359 sk_gpu_test::ManagedBackendTexture::MakeWithoutData(direct,
362 colorType,
365 isProtected);
366 if (!mbet) {
368 "Could not create non-renderable backend texture of color type %d",
369 colorType);
370 continue;
371 }
372 sk_sp<GrSurfaceProxy> sProxy = proxyProvider->wrapBackendTexture(
374 kRead_GrIOType, mbet->refCountedCallback());
375 if (!sProxy) {
376 ERRORF(reporter, "wrapBackendTexture failed");
377 continue;
378 }
379
381 reporter, sProxy.get(), kWidthHeight, kWidthHeight, Budgeted::kNo);
382 check_texture(reporter, resourceProvider, sProxy->asTextureProxy(),
384 }
385 }
386 }
387}
388
390 reporter,
391 ctxInfo,
393 auto direct = ctxInfo.directContext();
394 GrProxyProvider* provider = direct->priv().proxyProvider();
395
396 for (auto renderable : {GrRenderable::kNo, GrRenderable::kYes}) {
397 for (auto fit : { SkBackingFit::kExact, SkBackingFit::kApprox }) {
398 for (int width : { 0, 100 }) {
399 for (int height : { 0, 100}) {
400 if (width && height) {
401 continue; // not zero-sized
402 }
403
404 const GrBackendFormat format =
405 direct->priv().caps()->getDefaultBackendFormat(
407 renderable);
408
409 sk_sp<GrTextureProxy> proxy = provider->createProxy(format,
410 {width, height},
411 renderable,
412 1,
414 fit,
417 /*label=*/{});
418 REPORTER_ASSERT(reporter, !proxy);
419 }
420 }
421 }
422 }
423}
reporter
Definition: FontMgrTest.cpp:39
@ kRead_GrIOType
Definition: GrTypesPriv.h:403
@ kBorrow_GrWrapOwnership
Definition: GrTypesPriv.h:79
GrColorType
Definition: GrTypesPriv.h:540
static constexpr GrColorType SkColorTypeToGrColorType(SkColorType ct)
Definition: GrTypesPriv.h:629
skgpu::Protected Protected
static const int kWidthHeight
DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS(DeferredProxyTest, reporter, ctxInfo, CtsEnforcement::kApiLevel_T)
Definition: ProxyTest.cpp:126
static void check_surface(skiatest::Reporter *reporter, GrSurfaceProxy *proxy, int width, int height, skgpu::Budgeted budgeted)
Definition: ProxyTest.cpp:46
static void check_texture(skiatest::Reporter *reporter, GrResourceProvider *provider, GrTextureProxy *texProxy, SkBackingFit fit)
Definition: ProxyTest.cpp:92
static void check_rendertarget(skiatest::Reporter *reporter, const GrCaps &caps, GrResourceProvider *provider, GrRenderTargetProxy *rtProxy, int numSamples, SkBackingFit fit, int expectedMaxWindowRects)
Definition: ProxyTest.cpp:57
#define SkASSERT(cond)
Definition: SkAssert.h:116
SkBackingFit
Definition: SkBackingFit.h:16
@ kAlpha_8_SkColorType
pixel with alpha in 8-bit byte
Definition: SkColorType.h:21
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition: SkColorType.h:24
@ kRGBA_1010102_SkColorType
10 bits for red, green, blue; 2 bits for alpha; in 32-bit word
Definition: SkColorType.h:27
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
static constexpr bool SkToBool(const T &x)
Definition: SkTo.h:35
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
#define ERRORF(r,...)
Definition: Test.h:293
Definition: GrCaps.h:57
bool supportsProtectedContent() const
Definition: GrCaps.h:422
GrBackendFormat getDefaultBackendFormat(GrColorType, GrRenderable) const
Definition: GrCaps.cpp:400
virtual int getRenderTargetSampleCount(int requestedCount, const GrBackendFormat &) const =0
int maxWindowRectangles() const
Definition: GrCaps.h:231
uint32_t asUInt() const
UniqueID uniqueID() const
Definition: GrGpu.h:62
sk_sp< GrTextureProxy > wrapBackendTexture(const GrBackendTexture &, GrWrapOwnership, GrWrapCacheable, GrIOType, sk_sp< skgpu::RefCntedCallback >=nullptr)
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)
sk_sp< GrTextureProxy > wrapRenderableBackendTexture(const GrBackendTexture &, int sampleCnt, GrWrapOwnership, GrWrapCacheable, sk_sp< skgpu::RefCntedCallback > releaseHelper)
sk_sp< GrSurfaceProxy > wrapBackendRenderTarget(const GrBackendRenderTarget &, sk_sp< skgpu::RefCntedCallback > releaseHelper)
int maxWindowRectangles(const GrCaps &caps) const
bool instantiate(GrResourceProvider *) override
int numSamples() const
sk_sp< GrTexture > createApproxTexture(SkISize dimensions, const GrBackendFormat &format, GrTextureType textureType, skgpu::Renderable renderable, int renderTargetSampleCnt, skgpu::Protected isProtected, std::string_view label)
GrResourceProviderPriv priv()
sk_sp< GrTexture > createTexture(SkISize dimensions, const GrBackendFormat &format, GrTextureType textureType, skgpu::Renderable renderable, int renderTargetSampleCnt, skgpu::Mipmapped mipmapped, skgpu::Budgeted budgeted, skgpu::Protected isProtected, std::string_view label)
uint32_t asUInt() const
SkISize backingStoreDimensions() const
virtual GrRenderTargetProxy * asRenderTargetProxy()
const GrBackendFormat & backendFormat() const
size_t gpuMemorySize() const
GrTexture * peekTexture() const
int width() const
skgpu::Budgeted isBudgeted() const
SkISize dimensions() const
virtual GrTextureProxy * asTextureProxy()
bool isInstantiated() const
int height() const
UniqueID uniqueID() const
GrRenderTarget * peekRenderTarget() const
virtual GrBackendFormat backendFormat() const =0
SkISize dimensions() const
Definition: GrSurface.h:27
int height() const
Definition: GrSurface.h:37
int width() const
Definition: GrSurface.h:32
GrInternalSurfaceFlags flags() const
Definition: GrSurface.h:68
bool instantiate(GrResourceProvider *) override
GrTextureProxy * asTextureProxy() override
T * get() const
Definition: SkRefCnt.h:303
uint32_t uint32_t * format
SK_API GrGLenum AsGLFormatEnum(const GrBackendFormat &)
SK_API GrBackendRenderTarget MakeGL(int width, int height, int sampleCnt, int stencilBits, const GrGLFramebufferInfo &glInfo)
Definition: GpuTools.h:21
Budgeted
Definition: GpuTypes.h:35
Protected
Definition: GpuTypes.h:61
int32_t height
int32_t width
skgpu::Protected fProtected
Definition: GrGLTypes.h:199
Definition: SkSize.h:16