Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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());
47 GrBackendRenderTarget rt = proxy->peekRenderTarget()->getBackendRenderTarget();
48 proxy.reset();
49 gpu->deleteTestingOnlyBackendRenderTarget(rt);
50}
51
53 SkISize dimensions,
55 return provider->testingOnly_createInstantiatedProxy(dimensions,
57 GrRenderable::kYes,
58 1,
61 GrProtected::kNo);
62}
63
65 SkISize dimensions,
67 GrRenderable renderable) {
68 return provider->testingOnly_createInstantiatedProxy(dimensions,
70 renderable,
71 1,
74 GrProtected::kNo);
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
120 make_texture(proxyProvider, kSize, kColorType, GrRenderable::kYes));
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
135 make_texture(proxyProvider, kSize, kColorType, GrRenderable::kNo));
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
159 GrRenderable::kYes);
160 {
161 sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(format,
162 kDims,
163 GrRenderable::kYes,
164 1,
165 skgpu::Mipmapped::kNo,
168 GrProtected::kNo,
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,
183 GrRenderable::kYes,
184 1,
185 skgpu::Mipmapped::kNo,
188 GrProtected::kNo,
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,
203 GrRenderable::kNo,
204 1,
205 skgpu::Mipmapped::kNo,
208 GrProtected::kNo,
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
GrColorType
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)
#define SkASSERT(cond)
Definition SkAssert.h:116
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
#define DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS(name, reporter, context_info, ctsEnforcement)
Definition Test.h:434
static constexpr auto kColorType
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 GrRenderTargetProxy * asRenderTargetProxy()
virtual GrTextureProxy * asTextureProxy()
GrTextureProxy * asTextureProxy() override
void reset(T *ptr=nullptr)
Definition SkRefCnt.h:310
static constexpr int kSize
uint32_t uint32_t * format
Renderable
Definition GpuTypes.h:69
static constexpr SkISize Make(int32_t w, int32_t h)
Definition SkSize.h:20