blob: def9a7084f1af68d0b8eb4cde67a3a4c563fcca4 [file] [log] [blame]
Robert Phillips84a81202016-11-04 11:59:10 -04001/*
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 "Test.h"
11
Greg Danielbcf612b2017-05-01 13:50:58 +000012#include "GrBackendSurface.h"
Robert Phillips1afd4cd2018-01-08 13:40:32 -050013#include "GrContextPriv.h"
Brian Salomon52e943a2018-03-13 09:32:39 -040014#include "GrGpu.h"
Robert Phillips0bd24dc2018-01-16 08:06:32 -050015#include "GrProxyProvider.h"
Robert Phillips009e9af2017-06-15 14:01:04 -040016#include "GrRenderTarget.h"
Robert Phillips84a81202016-11-04 11:59:10 -040017#include "GrRenderTargetProxy.h"
Brian Osman32342f02017-03-04 08:12:46 -050018#include "GrSurfaceProxy.h"
Robert Phillips646e4292017-06-13 12:44:56 -040019#include "GrTexture.h"
Brian Osman32342f02017-03-04 08:12:46 -050020#include "GrTextureProxy.h"
Robert Phillips84a81202016-11-04 11:59:10 -040021
Brian Salomon52e943a2018-03-13 09:32:39 -040022static sk_sp<GrSurfaceProxy> make_wrapped_rt(GrProxyProvider* provider,
23 GrGpu* gpu,
24 skiatest::Reporter* reporter,
25 const GrSurfaceDesc& desc,
26 GrSurfaceOrigin origin) {
27 // We don't currently have a way of making MSAA backend render targets.
28 SkASSERT(1 == desc.fSampleCnt);
29 GrSRGBEncoded srgbEncoded;
30 auto ct = GrPixelConfigToColorTypeAndEncoding(desc.fConfig, &srgbEncoded);
Brian Osman2d010b62018-08-09 10:55:09 -040031 auto backendRT = gpu->createTestingOnlyBackendRenderTarget(desc.fWidth, desc.fHeight, ct);
Brian Salomon7578f3e2018-03-07 14:39:54 -050032 return provider->wrapBackendRenderTarget(backendRT, origin);
Robert Phillips84a81202016-11-04 11:59:10 -040033}
34
Brian Salomon52e943a2018-03-13 09:32:39 -040035void clean_up_wrapped_rt(GrGpu* gpu, sk_sp<GrSurfaceProxy> proxy) {
36 SkASSERT(proxy->isUnique_debugOnly());
Brian Salomonfd98c2c2018-07-31 17:25:29 -040037 SkASSERT(proxy->peekRenderTarget());
38 GrBackendRenderTarget rt = proxy->peekRenderTarget()->getBackendRenderTarget();
Brian Salomon52e943a2018-03-13 09:32:39 -040039 proxy.reset();
40 gpu->deleteTestingOnlyBackendRenderTarget(rt);
41}
42
43static sk_sp<GrSurfaceProxy> make_offscreen_rt(GrProxyProvider* provider,
44 const GrSurfaceDesc& desc,
45 GrSurfaceOrigin origin) {
Robert Phillips84a81202016-11-04 11:59:10 -040046 SkASSERT(kRenderTarget_GrSurfaceFlag == desc.fFlags);
47
Brian Salomon2a4f9832018-03-03 22:43:43 -050048 return provider->createInstantiatedProxy(desc, origin, SkBackingFit::kExact, SkBudgeted::kYes);
Robert Phillips84a81202016-11-04 11:59:10 -040049}
50
Brian Salomon52e943a2018-03-13 09:32:39 -040051static sk_sp<GrSurfaceProxy> make_texture(GrProxyProvider* provider,
52 const GrSurfaceDesc& desc,
53 GrSurfaceOrigin origin) {
Brian Salomon2a4f9832018-03-03 22:43:43 -050054 return provider->createInstantiatedProxy(desc, origin, SkBackingFit::kExact, SkBudgeted::kYes);
Robert Phillips84a81202016-11-04 11:59:10 -040055}
56
Brian Salomon52e943a2018-03-13 09:32:39 -040057// Test converting between RenderTargetProxies and TextureProxies for preinstantiated Proxies
58DEF_GPUTEST_FOR_RENDERING_CONTEXTS(PreinstantiatedProxyConversionTest, reporter, ctxInfo) {
Robert Phillips0bd24dc2018-01-16 08:06:32 -050059 GrProxyProvider* proxyProvider = ctxInfo.grContext()->contextPriv().proxyProvider();
Brian Salomon52e943a2018-03-13 09:32:39 -040060 GrGpu* gpu = ctxInfo.grContext()->contextPriv().getGpu();
Robert Phillips84a81202016-11-04 11:59:10 -040061
62 GrSurfaceDesc desc;
63 desc.fFlags = kRenderTarget_GrSurfaceFlag;
64 desc.fWidth = 64;
65 desc.fHeight = 64;
66 desc.fConfig = kRGBA_8888_GrPixelConfig;
67
Brian Salomon52e943a2018-03-13 09:32:39 -040068 {
Robert Phillips84a81202016-11-04 11:59:10 -040069 // External on-screen render target.
Brian Salomon2a4f9832018-03-03 22:43:43 -050070 sk_sp<GrSurfaceProxy> sProxy(
Brian Salomon52e943a2018-03-13 09:32:39 -040071 make_wrapped_rt(proxyProvider, gpu, reporter, desc, kBottomLeft_GrSurfaceOrigin));
Robert Phillips78d762d2018-01-23 16:57:35 -050072 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);
Brian Salomon52e943a2018-03-13 09:32:39 -040078 clean_up_wrapped_rt(gpu, std::move(sProxy));
Robert Phillips78d762d2018-01-23 16:57:35 -050079 }
Robert Phillips84a81202016-11-04 11:59:10 -040080 }
81
82 {
83 // Internal offscreen render target.
Brian Salomon2a4f9832018-03-03 22:43:43 -050084 sk_sp<GrSurfaceProxy> sProxy(
Brian Salomon52e943a2018-03-13 09:32:39 -040085 make_offscreen_rt(proxyProvider, desc, kBottomLeft_GrSurfaceOrigin));
Robert Phillips78d762d2018-01-23 16:57:35 -050086 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 }
Robert Phillips84a81202016-11-04 11:59:10 -040095 }
96
97 {
98 // Internal offscreen render target - but through GrTextureProxy
Brian Salomon2a4f9832018-03-03 22:43:43 -050099 sk_sp<GrSurfaceProxy> sProxy(
Brian Salomon52e943a2018-03-13 09:32:39 -0400100 make_texture(proxyProvider, desc, kBottomLeft_GrSurfaceOrigin));
Robert Phillips78d762d2018-01-23 16:57:35 -0500101 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 }
Robert Phillips84a81202016-11-04 11:59:10 -0400110 }
111
112 {
113 desc.fFlags = kNone_GrSurfaceFlags; // force no-RT
114
Brian Salomon2a4f9832018-03-03 22:43:43 -0500115 sk_sp<GrSurfaceProxy> sProxy(
Brian Salomon52e943a2018-03-13 09:32:39 -0400116 make_texture(proxyProvider, desc, kBottomLeft_GrSurfaceOrigin));
Robert Phillips78d762d2018-01-23 16:57:35 -0500117 if (sProxy) {
118 // Texture-only
119 GrTextureProxy* tProxy = sProxy->asTextureProxy();
120 REPORTER_ASSERT(reporter, tProxy);
121 REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
122 REPORTER_ASSERT(reporter, !tProxy->asRenderTargetProxy());
123 }
Robert Phillips84a81202016-11-04 11:59:10 -0400124 }
125}
126
127// Test converting between RenderTargetProxies and TextureProxies for deferred
128// Proxies
129DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DefferredProxyConversionTest, reporter, ctxInfo) {
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500130 GrProxyProvider* proxyProvider = ctxInfo.grContext()->contextPriv().proxyProvider();
Robert Phillips84a81202016-11-04 11:59:10 -0400131
132 GrSurfaceDesc desc;
133 desc.fFlags = kRenderTarget_GrSurfaceFlag;
134 desc.fWidth = 64;
135 desc.fHeight = 64;
136 desc.fConfig = kRGBA_8888_GrPixelConfig;
137
138 {
Brian Salomon2a4f9832018-03-03 22:43:43 -0500139 sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(
140 desc, kBottomLeft_GrSurfaceOrigin, SkBackingFit::kApprox, SkBudgeted::kYes);
Robert Phillips84a81202016-11-04 11:59:10 -0400141
142 // Both RenderTarget and Texture
Robert Phillips2f493142017-03-02 18:18:38 -0500143 GrRenderTargetProxy* rtProxy = proxy->asRenderTargetProxy();
Robert Phillips37430132016-11-09 06:50:43 -0500144 REPORTER_ASSERT(reporter, rtProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400145 GrTextureProxy* tProxy = rtProxy->asTextureProxy();
146 REPORTER_ASSERT(reporter, tProxy);
Robert Phillips37430132016-11-09 06:50:43 -0500147 REPORTER_ASSERT(reporter, tProxy->asRenderTargetProxy() == rtProxy);
148 REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400149 }
Robert Phillips26c90e02017-03-14 14:39:29 -0400150
Robert Phillips84a81202016-11-04 11:59:10 -0400151 {
Brian Salomon2a4f9832018-03-03 22:43:43 -0500152 sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(
153 desc, kBottomLeft_GrSurfaceOrigin, SkBackingFit::kApprox, SkBudgeted::kYes);
Robert Phillips84a81202016-11-04 11:59:10 -0400154
155 // Both RenderTarget and Texture - but via GrTextureProxy
Robert Phillips2f493142017-03-02 18:18:38 -0500156 GrTextureProxy* tProxy = proxy->asTextureProxy();
Robert Phillips37430132016-11-09 06:50:43 -0500157 REPORTER_ASSERT(reporter, tProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400158 GrRenderTargetProxy* rtProxy = tProxy->asRenderTargetProxy();
159 REPORTER_ASSERT(reporter, rtProxy);
Robert Phillips37430132016-11-09 06:50:43 -0500160 REPORTER_ASSERT(reporter, rtProxy->asTextureProxy() == tProxy);
161 REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400162 }
163
164 {
165 desc.fFlags = kNone_GrSurfaceFlags; // force no-RT
166
Brian Salomon2a4f9832018-03-03 22:43:43 -0500167 sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(
168 desc, kTopLeft_GrSurfaceOrigin, SkBackingFit::kApprox, SkBudgeted::kYes);
Robert Phillips84a81202016-11-04 11:59:10 -0400169 // Texture-only
Robert Phillips2f493142017-03-02 18:18:38 -0500170 GrTextureProxy* tProxy = proxy->asTextureProxy();
Robert Phillips37430132016-11-09 06:50:43 -0500171 REPORTER_ASSERT(reporter, tProxy);
172 REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400173 REPORTER_ASSERT(reporter, !tProxy->asRenderTargetProxy());
174 }
175}