• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
10 #include "tests/Test.h"
11 
12 #include "include/gpu/GrBackendSurface.h"
13 #include "include/gpu/GrTexture.h"
14 #include "src/gpu/GrContextPriv.h"
15 #include "src/gpu/GrGpu.h"
16 #include "src/gpu/GrProxyProvider.h"
17 #include "src/gpu/GrRenderTarget.h"
18 #include "src/gpu/GrRenderTargetProxy.h"
19 #include "src/gpu/GrSurfaceProxy.h"
20 #include "src/gpu/GrTextureProxy.h"
21 
make_wrapped_rt(GrProxyProvider * provider,GrGpu * gpu,skiatest::Reporter * reporter,const SkISize & size,GrColorType colorType,GrSurfaceOrigin origin)22 static sk_sp<GrSurfaceProxy> make_wrapped_rt(GrProxyProvider* provider,
23                                              GrGpu* gpu,
24                                              skiatest::Reporter* reporter,
25                                              const SkISize& size,
26                                              GrColorType colorType,
27                                              GrSurfaceOrigin origin) {
28     auto backendRT =
29             gpu->createTestingOnlyBackendRenderTarget(size.width(), size.height(), colorType);
30     return provider->wrapBackendRenderTarget(backendRT, colorType, origin, nullptr, nullptr);
31 }
32 
clean_up_wrapped_rt(GrGpu * gpu,sk_sp<GrSurfaceProxy> proxy)33 void clean_up_wrapped_rt(GrGpu* gpu, sk_sp<GrSurfaceProxy> proxy) {
34     SkASSERT(proxy->unique());
35     SkASSERT(proxy->peekRenderTarget());
36     GrBackendRenderTarget rt = proxy->peekRenderTarget()->getBackendRenderTarget();
37     proxy.reset();
38     gpu->deleteTestingOnlyBackendRenderTarget(rt);
39 }
40 
make_offscreen_rt(GrProxyProvider * provider,const SkISize & size,GrColorType colorType,GrSurfaceOrigin origin)41 static sk_sp<GrSurfaceProxy> make_offscreen_rt(GrProxyProvider* provider,
42                                                const SkISize& size,
43                                                GrColorType colorType,
44                                                GrSurfaceOrigin origin) {
45     return provider->testingOnly_createInstantiatedProxy(size, colorType, GrRenderable::kYes, 1,
46                                                          origin, SkBackingFit::kExact,
47                                                          SkBudgeted::kYes, GrProtected::kNo);
48 }
49 
make_texture(GrProxyProvider * provider,const SkISize & size,GrColorType colorType,GrRenderable renderable,GrSurfaceOrigin origin)50 static sk_sp<GrSurfaceProxy> make_texture(GrProxyProvider* provider,
51                                           const SkISize& size,
52                                           GrColorType colorType,
53                                           GrRenderable renderable,
54                                           GrSurfaceOrigin origin) {
55     return provider->testingOnly_createInstantiatedProxy(size, colorType, renderable, 1, origin,
56                                                          SkBackingFit::kExact, SkBudgeted::kYes,
57                                                          GrProtected::kNo);
58 }
59 
60 // Test converting between RenderTargetProxies and TextureProxies for preinstantiated Proxies
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(PreinstantiatedProxyConversionTest,reporter,ctxInfo)61 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(PreinstantiatedProxyConversionTest, reporter, ctxInfo) {
62     GrProxyProvider* proxyProvider = ctxInfo.grContext()->priv().proxyProvider();
63     GrGpu* gpu = ctxInfo.grContext()->priv().getGpu();
64 
65     static constexpr auto kSize = SkISize::Make(64, 64);
66     static constexpr auto kColorType = GrColorType::kRGBA_8888;
67 
68     {
69         // External on-screen render target.
70         sk_sp<GrSurfaceProxy> sProxy(make_wrapped_rt(proxyProvider, gpu, reporter, kSize,
71                                                      kColorType, kBottomLeft_GrSurfaceOrigin));
72         if (sProxy) {
73             // RenderTarget-only
74             GrRenderTargetProxy* rtProxy = sProxy->asRenderTargetProxy();
75             REPORTER_ASSERT(reporter, rtProxy);
76             REPORTER_ASSERT(reporter, !rtProxy->asTextureProxy());
77             REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy);
78             clean_up_wrapped_rt(gpu, std::move(sProxy));
79         }
80     }
81 
82     {
83         // Internal offscreen render target.
84         sk_sp<GrSurfaceProxy> sProxy(
85                 make_offscreen_rt(proxyProvider, kSize, kColorType, kBottomLeft_GrSurfaceOrigin));
86         if (sProxy) {
87             // Both RenderTarget and Texture
88             GrRenderTargetProxy* rtProxy = sProxy->asRenderTargetProxy();
89             REPORTER_ASSERT(reporter, rtProxy);
90             GrTextureProxy* tProxy = rtProxy->asTextureProxy();
91             REPORTER_ASSERT(reporter, tProxy);
92             REPORTER_ASSERT(reporter, tProxy->asRenderTargetProxy() == rtProxy);
93             REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy);
94         }
95     }
96 
97     {
98         // Internal offscreen render target - but through GrTextureProxy
99         sk_sp<GrSurfaceProxy> sProxy(make_texture(proxyProvider, kSize, kColorType,
100                                                   GrRenderable::kYes, kBottomLeft_GrSurfaceOrigin));
101         if (sProxy) {
102             // Both RenderTarget and Texture
103             GrTextureProxy* tProxy = sProxy->asTextureProxy();
104             REPORTER_ASSERT(reporter, tProxy);
105             GrRenderTargetProxy* rtProxy = tProxy->asRenderTargetProxy();
106             REPORTER_ASSERT(reporter, rtProxy);
107             REPORTER_ASSERT(reporter, rtProxy->asTextureProxy() == tProxy);
108             REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
109         }
110     }
111 
112     {
113         // force no-RT
114         sk_sp<GrSurfaceProxy> sProxy(make_texture(proxyProvider, kSize, kColorType,
115                                                   GrRenderable::kNo, kBottomLeft_GrSurfaceOrigin));
116         if (sProxy) {
117             // Texture-only
118             GrTextureProxy* tProxy = sProxy->asTextureProxy();
119             REPORTER_ASSERT(reporter, tProxy);
120             REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
121             REPORTER_ASSERT(reporter, !tProxy->asRenderTargetProxy());
122         }
123     }
124 }
125 
126 // Test converting between RenderTargetProxies and TextureProxies for deferred
127 // Proxies
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DefferredProxyConversionTest,reporter,ctxInfo)128 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DefferredProxyConversionTest, reporter, ctxInfo) {
129     GrContext* context = ctxInfo.grContext();
130     GrProxyProvider* proxyProvider = context->priv().proxyProvider();
131     const GrCaps* caps = context->priv().caps();
132 
133     GrSurfaceDesc desc;
134     desc.fWidth = 64;
135     desc.fHeight = 64;
136     desc.fConfig = kRGBA_8888_GrPixelConfig;
137 
138     const GrBackendFormat format = caps->getDefaultBackendFormat(GrColorType::kRGBA_8888,
139                                                                  GrRenderable::kYes);
140 
141     {
142         sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(
143                 format, desc, GrRenderable::kYes, 1, kBottomLeft_GrSurfaceOrigin,
144                 SkBackingFit::kApprox, SkBudgeted::kYes, GrProtected::kNo);
145 
146         // Both RenderTarget and Texture
147         GrRenderTargetProxy* rtProxy = proxy->asRenderTargetProxy();
148         REPORTER_ASSERT(reporter, rtProxy);
149         GrTextureProxy* tProxy = rtProxy->asTextureProxy();
150         REPORTER_ASSERT(reporter, tProxy);
151         REPORTER_ASSERT(reporter, tProxy->asRenderTargetProxy() == rtProxy);
152         REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy);
153     }
154 
155     {
156         sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(
157                 format, desc, GrRenderable::kYes, 1, kBottomLeft_GrSurfaceOrigin,
158                 SkBackingFit::kApprox, SkBudgeted::kYes, GrProtected::kNo);
159 
160         // Both RenderTarget and Texture - but via GrTextureProxy
161         GrTextureProxy* tProxy = proxy->asTextureProxy();
162         REPORTER_ASSERT(reporter, tProxy);
163         GrRenderTargetProxy* rtProxy = tProxy->asRenderTargetProxy();
164         REPORTER_ASSERT(reporter, rtProxy);
165         REPORTER_ASSERT(reporter, rtProxy->asTextureProxy() == tProxy);
166         REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
167     }
168 
169     {
170         sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(
171                 format, desc, GrRenderable::kNo, 1, kTopLeft_GrSurfaceOrigin, SkBackingFit::kApprox,
172                 SkBudgeted::kYes, GrProtected::kNo);
173         // Texture-only
174         GrTextureProxy* tProxy = proxy->asTextureProxy();
175         REPORTER_ASSERT(reporter, tProxy);
176         REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
177         REPORTER_ASSERT(reporter, !tProxy->asRenderTargetProxy());
178     }
179 }
180