blob: e316da7a20b8e7e87f039ca3695ac726666a17bd [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
Chris Daltond004e0b2018-09-27 09:28:03 -060048 return provider->testingOnly_createInstantiatedProxy(desc, origin, SkBackingFit::kExact,
49 SkBudgeted::kYes);
Robert Phillips84a81202016-11-04 11:59:10 -040050}
51
Brian Salomon52e943a2018-03-13 09:32:39 -040052static sk_sp<GrSurfaceProxy> make_texture(GrProxyProvider* provider,
53 const GrSurfaceDesc& desc,
54 GrSurfaceOrigin origin) {
Chris Daltond004e0b2018-09-27 09:28:03 -060055 return provider->testingOnly_createInstantiatedProxy(desc, origin, SkBackingFit::kExact,
56 SkBudgeted::kYes);
Robert Phillips84a81202016-11-04 11:59:10 -040057}
58
Brian Salomon52e943a2018-03-13 09:32:39 -040059// Test converting between RenderTargetProxies and TextureProxies for preinstantiated Proxies
60DEF_GPUTEST_FOR_RENDERING_CONTEXTS(PreinstantiatedProxyConversionTest, reporter, ctxInfo) {
Robert Phillips0bd24dc2018-01-16 08:06:32 -050061 GrProxyProvider* proxyProvider = ctxInfo.grContext()->contextPriv().proxyProvider();
Brian Salomon52e943a2018-03-13 09:32:39 -040062 GrGpu* gpu = ctxInfo.grContext()->contextPriv().getGpu();
Robert Phillips84a81202016-11-04 11:59:10 -040063
64 GrSurfaceDesc desc;
65 desc.fFlags = kRenderTarget_GrSurfaceFlag;
66 desc.fWidth = 64;
67 desc.fHeight = 64;
68 desc.fConfig = kRGBA_8888_GrPixelConfig;
69
Brian Salomon52e943a2018-03-13 09:32:39 -040070 {
Robert Phillips84a81202016-11-04 11:59:10 -040071 // External on-screen render target.
Brian Salomon2a4f9832018-03-03 22:43:43 -050072 sk_sp<GrSurfaceProxy> sProxy(
Brian Salomon52e943a2018-03-13 09:32:39 -040073 make_wrapped_rt(proxyProvider, gpu, reporter, desc, kBottomLeft_GrSurfaceOrigin));
Robert Phillips78d762d2018-01-23 16:57:35 -050074 if (sProxy) {
75 // RenderTarget-only
76 GrRenderTargetProxy* rtProxy = sProxy->asRenderTargetProxy();
77 REPORTER_ASSERT(reporter, rtProxy);
78 REPORTER_ASSERT(reporter, !rtProxy->asTextureProxy());
79 REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy);
Brian Salomon52e943a2018-03-13 09:32:39 -040080 clean_up_wrapped_rt(gpu, std::move(sProxy));
Robert Phillips78d762d2018-01-23 16:57:35 -050081 }
Robert Phillips84a81202016-11-04 11:59:10 -040082 }
83
84 {
85 // Internal offscreen render target.
Brian Salomon2a4f9832018-03-03 22:43:43 -050086 sk_sp<GrSurfaceProxy> sProxy(
Brian Salomon52e943a2018-03-13 09:32:39 -040087 make_offscreen_rt(proxyProvider, desc, kBottomLeft_GrSurfaceOrigin));
Robert Phillips78d762d2018-01-23 16:57:35 -050088 if (sProxy) {
89 // Both RenderTarget and Texture
90 GrRenderTargetProxy* rtProxy = sProxy->asRenderTargetProxy();
91 REPORTER_ASSERT(reporter, rtProxy);
92 GrTextureProxy* tProxy = rtProxy->asTextureProxy();
93 REPORTER_ASSERT(reporter, tProxy);
94 REPORTER_ASSERT(reporter, tProxy->asRenderTargetProxy() == rtProxy);
95 REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy);
96 }
Robert Phillips84a81202016-11-04 11:59:10 -040097 }
98
99 {
100 // Internal offscreen render target - but through GrTextureProxy
Brian Salomon2a4f9832018-03-03 22:43:43 -0500101 sk_sp<GrSurfaceProxy> sProxy(
Brian Salomon52e943a2018-03-13 09:32:39 -0400102 make_texture(proxyProvider, desc, kBottomLeft_GrSurfaceOrigin));
Robert Phillips78d762d2018-01-23 16:57:35 -0500103 if (sProxy) {
104 // Both RenderTarget and Texture
105 GrTextureProxy* tProxy = sProxy->asTextureProxy();
106 REPORTER_ASSERT(reporter, tProxy);
107 GrRenderTargetProxy* rtProxy = tProxy->asRenderTargetProxy();
108 REPORTER_ASSERT(reporter, rtProxy);
109 REPORTER_ASSERT(reporter, rtProxy->asTextureProxy() == tProxy);
110 REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
111 }
Robert Phillips84a81202016-11-04 11:59:10 -0400112 }
113
114 {
115 desc.fFlags = kNone_GrSurfaceFlags; // force no-RT
116
Brian Salomon2a4f9832018-03-03 22:43:43 -0500117 sk_sp<GrSurfaceProxy> sProxy(
Brian Salomon52e943a2018-03-13 09:32:39 -0400118 make_texture(proxyProvider, desc, kBottomLeft_GrSurfaceOrigin));
Robert Phillips78d762d2018-01-23 16:57:35 -0500119 if (sProxy) {
120 // Texture-only
121 GrTextureProxy* tProxy = sProxy->asTextureProxy();
122 REPORTER_ASSERT(reporter, tProxy);
123 REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
124 REPORTER_ASSERT(reporter, !tProxy->asRenderTargetProxy());
125 }
Robert Phillips84a81202016-11-04 11:59:10 -0400126 }
127}
128
129// Test converting between RenderTargetProxies and TextureProxies for deferred
130// Proxies
131DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DefferredProxyConversionTest, reporter, ctxInfo) {
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500132 GrProxyProvider* proxyProvider = ctxInfo.grContext()->contextPriv().proxyProvider();
Robert Phillips84a81202016-11-04 11:59:10 -0400133
134 GrSurfaceDesc desc;
135 desc.fFlags = kRenderTarget_GrSurfaceFlag;
136 desc.fWidth = 64;
137 desc.fHeight = 64;
138 desc.fConfig = kRGBA_8888_GrPixelConfig;
139
140 {
Brian Salomon2a4f9832018-03-03 22:43:43 -0500141 sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(
142 desc, kBottomLeft_GrSurfaceOrigin, SkBackingFit::kApprox, SkBudgeted::kYes);
Robert Phillips84a81202016-11-04 11:59:10 -0400143
144 // Both RenderTarget and Texture
Robert Phillips2f493142017-03-02 18:18:38 -0500145 GrRenderTargetProxy* rtProxy = proxy->asRenderTargetProxy();
Robert Phillips37430132016-11-09 06:50:43 -0500146 REPORTER_ASSERT(reporter, rtProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400147 GrTextureProxy* tProxy = rtProxy->asTextureProxy();
148 REPORTER_ASSERT(reporter, tProxy);
Robert Phillips37430132016-11-09 06:50:43 -0500149 REPORTER_ASSERT(reporter, tProxy->asRenderTargetProxy() == rtProxy);
150 REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400151 }
Robert Phillips26c90e02017-03-14 14:39:29 -0400152
Robert Phillips84a81202016-11-04 11:59:10 -0400153 {
Brian Salomon2a4f9832018-03-03 22:43:43 -0500154 sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(
155 desc, kBottomLeft_GrSurfaceOrigin, SkBackingFit::kApprox, SkBudgeted::kYes);
Robert Phillips84a81202016-11-04 11:59:10 -0400156
157 // Both RenderTarget and Texture - but via GrTextureProxy
Robert Phillips2f493142017-03-02 18:18:38 -0500158 GrTextureProxy* tProxy = proxy->asTextureProxy();
Robert Phillips37430132016-11-09 06:50:43 -0500159 REPORTER_ASSERT(reporter, tProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400160 GrRenderTargetProxy* rtProxy = tProxy->asRenderTargetProxy();
161 REPORTER_ASSERT(reporter, rtProxy);
Robert Phillips37430132016-11-09 06:50:43 -0500162 REPORTER_ASSERT(reporter, rtProxy->asTextureProxy() == tProxy);
163 REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400164 }
165
166 {
167 desc.fFlags = kNone_GrSurfaceFlags; // force no-RT
168
Brian Salomon2a4f9832018-03-03 22:43:43 -0500169 sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(
170 desc, kTopLeft_GrSurfaceOrigin, SkBackingFit::kApprox, SkBudgeted::kYes);
Robert Phillips84a81202016-11-04 11:59:10 -0400171 // Texture-only
Robert Phillips2f493142017-03-02 18:18:38 -0500172 GrTextureProxy* tProxy = proxy->asTextureProxy();
Robert Phillips37430132016-11-09 06:50:43 -0500173 REPORTER_ASSERT(reporter, tProxy);
174 REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400175 REPORTER_ASSERT(reporter, !tProxy->asRenderTargetProxy());
176 }
177}