Flutter Engine
The Flutter Engine
ProxyConversionTest.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
11#include "include/core/SkSize.h"
16#include "include/gpu/GrTypes.h"
29#include "tests/Test.h"
30
31#include <utility>
32
33struct GrContextOptions;
34
36 GrGpu* gpu,
38 const SkISize& size,
40 auto backendRT = gpu->createTestingOnlyBackendRenderTarget(size, colorType);
41 return provider->wrapBackendRenderTarget(backendRT, nullptr);
42}
43
45 SkASSERT(proxy->unique());
46 SkASSERT(proxy->peekRenderTarget());
48 proxy.reset();
49 gpu->deleteTestingOnlyBackendRenderTarget(rt);
50}
51
53 SkISize dimensions,
55 return provider->testingOnly_createInstantiatedProxy(dimensions,
58 1,
62}
63
65 SkISize dimensions,
67 GrRenderable renderable) {
68 return provider->testingOnly_createInstantiatedProxy(dimensions,
70 renderable,
71 1,
75}
76
77// Test converting between RenderTargetProxies and TextureProxies for preinstantiated Proxies
78DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS(PreinstantiatedProxyConversionTest,
80 ctxInfo,
82 auto context = ctxInfo.directContext();
83 GrProxyProvider* proxyProvider = context->priv().proxyProvider();
84 GrGpu* gpu = context->priv().getGpu();
85
86 static constexpr auto kSize = SkISize::Make(64, 64);
87 static constexpr auto kColorType = GrColorType::kRGBA_8888;
88
89 {
90 // External on-screen render target.
92 make_wrapped_rt(proxyProvider, gpu, reporter, kSize, kColorType));
93 if (sProxy) {
94 // RenderTarget-only
95 GrRenderTargetProxy* rtProxy = sProxy->asRenderTargetProxy();
96 REPORTER_ASSERT(reporter, rtProxy);
98 REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy);
99 clean_up_wrapped_rt(gpu, std::move(sProxy));
100 }
101 }
102
103 {
104 // Internal offscreen render target.
106 if (sProxy) {
107 // Both RenderTarget and Texture
108 GrRenderTargetProxy* rtProxy = sProxy->asRenderTargetProxy();
109 REPORTER_ASSERT(reporter, rtProxy);
110 GrTextureProxy* tProxy = rtProxy->asTextureProxy();
111 REPORTER_ASSERT(reporter, tProxy);
112 REPORTER_ASSERT(reporter, tProxy->asRenderTargetProxy() == rtProxy);
113 REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy);
114 }
115 }
116
117 {
118 // Internal offscreen render target - but through GrTextureProxy
121 if (sProxy) {
122 // Both RenderTarget and Texture
123 GrTextureProxy* tProxy = sProxy->asTextureProxy();
124 REPORTER_ASSERT(reporter, tProxy);
125 GrRenderTargetProxy* rtProxy = tProxy->asRenderTargetProxy();
126 REPORTER_ASSERT(reporter, rtProxy);
127 REPORTER_ASSERT(reporter, rtProxy->asTextureProxy() == tProxy);
128 REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
129 }
130 }
131
132 {
133 // force no-RT
136 if (sProxy) {
137 // Texture-only
138 GrTextureProxy* tProxy = sProxy->asTextureProxy();
139 REPORTER_ASSERT(reporter, tProxy);
140 REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
142 }
143 }
144}
145
146// Test converting between RenderTargetProxies and TextureProxies for deferred
147// Proxies
148DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS(DefferredProxyConversionTest,
149 reporter,
150 ctxInfo,
152 auto context = ctxInfo.directContext();
153 GrProxyProvider* proxyProvider = context->priv().proxyProvider();
154 const GrCaps* caps = context->priv().caps();
155
156 static constexpr SkISize kDims = {64, 64};
157
160 {
161 sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(format,
162 kDims,
164 1,
169 /*label=*/{});
170
171 // Both RenderTarget and Texture
172 GrRenderTargetProxy* rtProxy = proxy->asRenderTargetProxy();
173 REPORTER_ASSERT(reporter, rtProxy);
174 GrTextureProxy* tProxy = rtProxy->asTextureProxy();
175 REPORTER_ASSERT(reporter, tProxy);
176 REPORTER_ASSERT(reporter, tProxy->asRenderTargetProxy() == rtProxy);
177 REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy);
178 }
179
180 {
181 sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(format,
182 kDims,
184 1,
189 /*label=*/{});
190
191 // Both RenderTarget and Texture - but via GrTextureProxy
192 GrTextureProxy* tProxy = proxy->asTextureProxy();
193 REPORTER_ASSERT(reporter, tProxy);
194 GrRenderTargetProxy* rtProxy = tProxy->asRenderTargetProxy();
195 REPORTER_ASSERT(reporter, rtProxy);
196 REPORTER_ASSERT(reporter, rtProxy->asTextureProxy() == tProxy);
197 REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
198 }
199
200 {
201 sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(format,
202 kDims,
204 1,
209 /*label=*/{});
210 // Texture-only
211 GrTextureProxy* tProxy = proxy->asTextureProxy();
212 REPORTER_ASSERT(reporter, tProxy);
213 REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
215 }
216}
reporter
Definition: FontMgrTest.cpp:39
GrColorType
Definition: GrTypesPriv.h:540
void clean_up_wrapped_rt(GrGpu *gpu, sk_sp< GrSurfaceProxy > proxy)
static sk_sp< GrSurfaceProxy > make_texture(GrProxyProvider *provider, SkISize dimensions, GrColorType colorType, GrRenderable renderable)
static sk_sp< GrSurfaceProxy > make_wrapped_rt(GrProxyProvider *provider, GrGpu *gpu, skiatest::Reporter *reporter, const SkISize &size, GrColorType colorType)
static sk_sp< GrSurfaceProxy > make_offscreen_rt(GrProxyProvider *provider, SkISize dimensions, GrColorType colorType)
DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS(PreinstantiatedProxyConversionTest, reporter, ctxInfo, CtsEnforcement::kApiLevel_T)
#define SkASSERT(cond)
Definition: SkAssert.h:116
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
static constexpr auto kColorType
Definition: GrCaps.h:57
GrBackendFormat getDefaultBackendFormat(GrColorType, GrRenderable) const
Definition: GrCaps.cpp:400
Definition: GrGpu.h:62
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< GrSurfaceProxy > wrapBackendRenderTarget(const GrBackendRenderTarget &, sk_sp< skgpu::RefCntedCallback > releaseHelper)
GrRenderTargetProxy * asRenderTargetProxy() override
virtual GrBackendRenderTarget getBackendRenderTarget() const =0
virtual GrRenderTargetProxy * asRenderTargetProxy()
virtual GrTextureProxy * asTextureProxy()
GrRenderTarget * peekRenderTarget() const
GrTextureProxy * asTextureProxy() override
bool unique() const
Definition: SkRefCnt.h:175
void reset(T *ptr=nullptr)
Definition: SkRefCnt.h:310
uint32_t uint32_t * format
constexpr int kSize
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
Renderable
Definition: GpuTypes.h:69
Definition: SkSize.h:16
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20