blob: 4a95d486c5a83051893c02778ed162bba9200c4e [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);
31 auto backendRT = gpu->createTestingOnlyBackendRenderTarget(desc.fWidth, desc.fHeight, ct,
32 GrSRGBEncoded::kNo);
Brian Salomon7578f3e2018-03-07 14:39:54 -050033 return provider->wrapBackendRenderTarget(backendRT, origin);
Robert Phillips84a81202016-11-04 11:59:10 -040034}
35
Brian Salomon52e943a2018-03-13 09:32:39 -040036void clean_up_wrapped_rt(GrGpu* gpu, sk_sp<GrSurfaceProxy> proxy) {
37 SkASSERT(proxy->isUnique_debugOnly());
38 SkASSERT(proxy->priv().peekRenderTarget());
39 GrBackendRenderTarget rt = proxy->priv().peekRenderTarget()->getBackendRenderTarget();
40 proxy.reset();
41 gpu->deleteTestingOnlyBackendRenderTarget(rt);
42}
43
44static sk_sp<GrSurfaceProxy> make_offscreen_rt(GrProxyProvider* provider,
45 const GrSurfaceDesc& desc,
46 GrSurfaceOrigin origin) {
Robert Phillips84a81202016-11-04 11:59:10 -040047 SkASSERT(kRenderTarget_GrSurfaceFlag == desc.fFlags);
48
Brian Salomon2a4f9832018-03-03 22:43:43 -050049 return provider->createInstantiatedProxy(desc, origin, SkBackingFit::kExact, 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) {
Brian Salomon2a4f9832018-03-03 22:43:43 -050055 return provider->createInstantiatedProxy(desc, origin, SkBackingFit::kExact, SkBudgeted::kYes);
Robert Phillips84a81202016-11-04 11:59:10 -040056}
57
Brian Salomon52e943a2018-03-13 09:32:39 -040058// Test converting between RenderTargetProxies and TextureProxies for preinstantiated Proxies
59DEF_GPUTEST_FOR_RENDERING_CONTEXTS(PreinstantiatedProxyConversionTest, reporter, ctxInfo) {
Robert Phillips0bd24dc2018-01-16 08:06:32 -050060 GrProxyProvider* proxyProvider = ctxInfo.grContext()->contextPriv().proxyProvider();
Brian Salomon52e943a2018-03-13 09:32:39 -040061 GrGpu* gpu = ctxInfo.grContext()->contextPriv().getGpu();
Robert Phillips84a81202016-11-04 11:59:10 -040062
63 GrSurfaceDesc desc;
64 desc.fFlags = kRenderTarget_GrSurfaceFlag;
65 desc.fWidth = 64;
66 desc.fHeight = 64;
67 desc.fConfig = kRGBA_8888_GrPixelConfig;
68
Brian Salomon52e943a2018-03-13 09:32:39 -040069 {
Robert Phillips84a81202016-11-04 11:59:10 -040070 // External on-screen render target.
Brian Salomon2a4f9832018-03-03 22:43:43 -050071 sk_sp<GrSurfaceProxy> sProxy(
Brian Salomon52e943a2018-03-13 09:32:39 -040072 make_wrapped_rt(proxyProvider, gpu, reporter, desc, kBottomLeft_GrSurfaceOrigin));
Robert Phillips78d762d2018-01-23 16:57:35 -050073 if (sProxy) {
74 // RenderTarget-only
75 GrRenderTargetProxy* rtProxy = sProxy->asRenderTargetProxy();
76 REPORTER_ASSERT(reporter, rtProxy);
77 REPORTER_ASSERT(reporter, !rtProxy->asTextureProxy());
78 REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy);
Brian Salomon52e943a2018-03-13 09:32:39 -040079 clean_up_wrapped_rt(gpu, std::move(sProxy));
Robert Phillips78d762d2018-01-23 16:57:35 -050080 }
Robert Phillips84a81202016-11-04 11:59:10 -040081 }
82
83 {
84 // Internal offscreen render target.
Brian Salomon2a4f9832018-03-03 22:43:43 -050085 sk_sp<GrSurfaceProxy> sProxy(
Brian Salomon52e943a2018-03-13 09:32:39 -040086 make_offscreen_rt(proxyProvider, desc, kBottomLeft_GrSurfaceOrigin));
Robert Phillips78d762d2018-01-23 16:57:35 -050087 if (sProxy) {
88 // Both RenderTarget and Texture
89 GrRenderTargetProxy* rtProxy = sProxy->asRenderTargetProxy();
90 REPORTER_ASSERT(reporter, rtProxy);
91 GrTextureProxy* tProxy = rtProxy->asTextureProxy();
92 REPORTER_ASSERT(reporter, tProxy);
93 REPORTER_ASSERT(reporter, tProxy->asRenderTargetProxy() == rtProxy);
94 REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy);
95 }
Robert Phillips84a81202016-11-04 11:59:10 -040096 }
97
98 {
99 // Internal offscreen render target - but through GrTextureProxy
Brian Salomon2a4f9832018-03-03 22:43:43 -0500100 sk_sp<GrSurfaceProxy> sProxy(
Brian Salomon52e943a2018-03-13 09:32:39 -0400101 make_texture(proxyProvider, desc, kBottomLeft_GrSurfaceOrigin));
Robert Phillips78d762d2018-01-23 16:57:35 -0500102 if (sProxy) {
103 // Both RenderTarget and Texture
104 GrTextureProxy* tProxy = sProxy->asTextureProxy();
105 REPORTER_ASSERT(reporter, tProxy);
106 GrRenderTargetProxy* rtProxy = tProxy->asRenderTargetProxy();
107 REPORTER_ASSERT(reporter, rtProxy);
108 REPORTER_ASSERT(reporter, rtProxy->asTextureProxy() == tProxy);
109 REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
110 }
Robert Phillips84a81202016-11-04 11:59:10 -0400111 }
112
113 {
114 desc.fFlags = kNone_GrSurfaceFlags; // force no-RT
115
Brian Salomon2a4f9832018-03-03 22:43:43 -0500116 sk_sp<GrSurfaceProxy> sProxy(
Brian Salomon52e943a2018-03-13 09:32:39 -0400117 make_texture(proxyProvider, desc, kBottomLeft_GrSurfaceOrigin));
Robert Phillips78d762d2018-01-23 16:57:35 -0500118 if (sProxy) {
119 // Texture-only
120 GrTextureProxy* tProxy = sProxy->asTextureProxy();
121 REPORTER_ASSERT(reporter, tProxy);
122 REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
123 REPORTER_ASSERT(reporter, !tProxy->asRenderTargetProxy());
124 }
Robert Phillips84a81202016-11-04 11:59:10 -0400125 }
126}
127
128// Test converting between RenderTargetProxies and TextureProxies for deferred
129// Proxies
130DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DefferredProxyConversionTest, reporter, ctxInfo) {
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500131 GrProxyProvider* proxyProvider = ctxInfo.grContext()->contextPriv().proxyProvider();
Robert Phillips84a81202016-11-04 11:59:10 -0400132
133 GrSurfaceDesc desc;
134 desc.fFlags = kRenderTarget_GrSurfaceFlag;
135 desc.fWidth = 64;
136 desc.fHeight = 64;
137 desc.fConfig = kRGBA_8888_GrPixelConfig;
138
139 {
Brian Salomon2a4f9832018-03-03 22:43:43 -0500140 sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(
141 desc, kBottomLeft_GrSurfaceOrigin, SkBackingFit::kApprox, SkBudgeted::kYes);
Robert Phillips84a81202016-11-04 11:59:10 -0400142
143 // Both RenderTarget and Texture
Robert Phillips2f493142017-03-02 18:18:38 -0500144 GrRenderTargetProxy* rtProxy = proxy->asRenderTargetProxy();
Robert Phillips37430132016-11-09 06:50:43 -0500145 REPORTER_ASSERT(reporter, rtProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400146 GrTextureProxy* tProxy = rtProxy->asTextureProxy();
147 REPORTER_ASSERT(reporter, tProxy);
Robert Phillips37430132016-11-09 06:50:43 -0500148 REPORTER_ASSERT(reporter, tProxy->asRenderTargetProxy() == rtProxy);
149 REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400150 }
Robert Phillips26c90e02017-03-14 14:39:29 -0400151
Robert Phillips84a81202016-11-04 11:59:10 -0400152 {
Brian Salomon2a4f9832018-03-03 22:43:43 -0500153 sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(
154 desc, kBottomLeft_GrSurfaceOrigin, SkBackingFit::kApprox, SkBudgeted::kYes);
Robert Phillips84a81202016-11-04 11:59:10 -0400155
156 // Both RenderTarget and Texture - but via GrTextureProxy
Robert Phillips2f493142017-03-02 18:18:38 -0500157 GrTextureProxy* tProxy = proxy->asTextureProxy();
Robert Phillips37430132016-11-09 06:50:43 -0500158 REPORTER_ASSERT(reporter, tProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400159 GrRenderTargetProxy* rtProxy = tProxy->asRenderTargetProxy();
160 REPORTER_ASSERT(reporter, rtProxy);
Robert Phillips37430132016-11-09 06:50:43 -0500161 REPORTER_ASSERT(reporter, rtProxy->asTextureProxy() == tProxy);
162 REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400163 }
164
165 {
166 desc.fFlags = kNone_GrSurfaceFlags; // force no-RT
167
Brian Salomon2a4f9832018-03-03 22:43:43 -0500168 sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(
169 desc, kTopLeft_GrSurfaceOrigin, SkBackingFit::kApprox, SkBudgeted::kYes);
Robert Phillips84a81202016-11-04 11:59:10 -0400170 // Texture-only
Robert Phillips2f493142017-03-02 18:18:38 -0500171 GrTextureProxy* tProxy = proxy->asTextureProxy();
Robert Phillips37430132016-11-09 06:50:43 -0500172 REPORTER_ASSERT(reporter, tProxy);
173 REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400174 REPORTER_ASSERT(reporter, !tProxy->asRenderTargetProxy());
175 }
176}