blob: a4c4a604497321e61f07e19269529a31329d61e7 [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
12#if SK_SUPPORT_GPU
Greg Danielbcf612b2017-05-01 13:50:58 +000013#include "GrBackendSurface.h"
Robert Phillips1afd4cd2018-01-08 13:40:32 -050014#include "GrContextPriv.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
Robert Phillips0bd24dc2018-01-16 08:06:32 -050022static sk_sp<GrSurfaceProxy> make_wrapped_FBO0(GrProxyProvider* provider,
Robert Phillips37430132016-11-09 06:50:43 -050023 skiatest::Reporter* reporter,
Brian Salomon2a4f9832018-03-03 22:43:43 -050024 const GrSurfaceDesc& desc,
25 GrSurfaceOrigin origin) {
Greg Danielbcf612b2017-05-01 13:50:58 +000026 GrGLFramebufferInfo fboInfo;
27 fboInfo.fFBOID = 0;
28 GrBackendRenderTarget backendRT(desc.fWidth, desc.fHeight, desc.fSampleCnt, 8,
29 desc.fConfig, fboInfo);
Robert Phillips84a81202016-11-04 11:59:10 -040030
Brian Salomon2a4f9832018-03-03 22:43:43 -050031 return provider->createWrappedRenderTargetProxy(backendRT, origin);
Robert Phillips84a81202016-11-04 11:59:10 -040032}
33
Robert Phillips0bd24dc2018-01-16 08:06:32 -050034static sk_sp<GrSurfaceProxy> make_wrapped_offscreen_rt(GrProxyProvider* provider,
Brian Salomon2a4f9832018-03-03 22:43:43 -050035 const GrSurfaceDesc& desc,
36 GrSurfaceOrigin origin) {
Robert Phillips84a81202016-11-04 11:59:10 -040037 SkASSERT(kRenderTarget_GrSurfaceFlag == desc.fFlags);
38
Brian Salomon2a4f9832018-03-03 22:43:43 -050039 return provider->createInstantiatedProxy(desc, origin, SkBackingFit::kExact, SkBudgeted::kYes);
Robert Phillips84a81202016-11-04 11:59:10 -040040}
41
Robert Phillips0bd24dc2018-01-16 08:06:32 -050042static sk_sp<GrSurfaceProxy> make_wrapped_texture(GrProxyProvider* provider,
Brian Salomon2a4f9832018-03-03 22:43:43 -050043 const GrSurfaceDesc& desc,
44 GrSurfaceOrigin origin) {
45 return provider->createInstantiatedProxy(desc, origin, SkBackingFit::kExact, SkBudgeted::kYes);
Robert Phillips84a81202016-11-04 11:59:10 -040046}
47
48// Test converting between RenderTargetProxies and TextureProxies for wrapped
49// Proxies
50DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WrappedProxyConversionTest, reporter, ctxInfo) {
Robert Phillips0bd24dc2018-01-16 08:06:32 -050051 GrProxyProvider* proxyProvider = ctxInfo.grContext()->contextPriv().proxyProvider();
Robert Phillips84a81202016-11-04 11:59:10 -040052
53 GrSurfaceDesc desc;
54 desc.fFlags = kRenderTarget_GrSurfaceFlag;
55 desc.fWidth = 64;
56 desc.fHeight = 64;
57 desc.fConfig = kRGBA_8888_GrPixelConfig;
58
59 if (kOpenGL_GrBackend == ctxInfo.backend()) {
60 // External on-screen render target.
Brian Salomon2a4f9832018-03-03 22:43:43 -050061 sk_sp<GrSurfaceProxy> sProxy(
62 make_wrapped_FBO0(proxyProvider, reporter, desc, kBottomLeft_GrSurfaceOrigin));
Robert Phillips78d762d2018-01-23 16:57:35 -050063 if (sProxy) {
64 // RenderTarget-only
65 GrRenderTargetProxy* rtProxy = sProxy->asRenderTargetProxy();
66 REPORTER_ASSERT(reporter, rtProxy);
67 REPORTER_ASSERT(reporter, !rtProxy->asTextureProxy());
68 REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy);
69 }
Robert Phillips84a81202016-11-04 11:59:10 -040070 }
71
72 {
73 // Internal offscreen render target.
Brian Salomon2a4f9832018-03-03 22:43:43 -050074 sk_sp<GrSurfaceProxy> sProxy(
75 make_wrapped_offscreen_rt(proxyProvider, desc, kBottomLeft_GrSurfaceOrigin));
Robert Phillips78d762d2018-01-23 16:57:35 -050076 if (sProxy) {
77 // Both RenderTarget and Texture
78 GrRenderTargetProxy* rtProxy = sProxy->asRenderTargetProxy();
79 REPORTER_ASSERT(reporter, rtProxy);
80 GrTextureProxy* tProxy = rtProxy->asTextureProxy();
81 REPORTER_ASSERT(reporter, tProxy);
82 REPORTER_ASSERT(reporter, tProxy->asRenderTargetProxy() == rtProxy);
83 REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy);
84 }
Robert Phillips84a81202016-11-04 11:59:10 -040085 }
86
87 {
88 // Internal offscreen render target - but through GrTextureProxy
Brian Salomon2a4f9832018-03-03 22:43:43 -050089 sk_sp<GrSurfaceProxy> sProxy(
90 make_wrapped_texture(proxyProvider, desc, kBottomLeft_GrSurfaceOrigin));
Robert Phillips78d762d2018-01-23 16:57:35 -050091 if (sProxy) {
92 // Both RenderTarget and Texture
93 GrTextureProxy* tProxy = sProxy->asTextureProxy();
94 REPORTER_ASSERT(reporter, tProxy);
95 GrRenderTargetProxy* rtProxy = tProxy->asRenderTargetProxy();
96 REPORTER_ASSERT(reporter, rtProxy);
97 REPORTER_ASSERT(reporter, rtProxy->asTextureProxy() == tProxy);
98 REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
99 }
Robert Phillips84a81202016-11-04 11:59:10 -0400100 }
101
102 {
103 desc.fFlags = kNone_GrSurfaceFlags; // force no-RT
104
Brian Salomon2a4f9832018-03-03 22:43:43 -0500105 sk_sp<GrSurfaceProxy> sProxy(
106 make_wrapped_texture(proxyProvider, desc, kBottomLeft_GrSurfaceOrigin));
Robert Phillips78d762d2018-01-23 16:57:35 -0500107 if (sProxy) {
108 // Texture-only
109 GrTextureProxy* tProxy = sProxy->asTextureProxy();
110 REPORTER_ASSERT(reporter, tProxy);
111 REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
112 REPORTER_ASSERT(reporter, !tProxy->asRenderTargetProxy());
113 }
Robert Phillips84a81202016-11-04 11:59:10 -0400114 }
115}
116
117// Test converting between RenderTargetProxies and TextureProxies for deferred
118// Proxies
119DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DefferredProxyConversionTest, reporter, ctxInfo) {
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500120 GrProxyProvider* proxyProvider = ctxInfo.grContext()->contextPriv().proxyProvider();
Robert Phillips84a81202016-11-04 11:59:10 -0400121
122 GrSurfaceDesc desc;
123 desc.fFlags = kRenderTarget_GrSurfaceFlag;
124 desc.fWidth = 64;
125 desc.fHeight = 64;
126 desc.fConfig = kRGBA_8888_GrPixelConfig;
127
128 {
Brian Salomon2a4f9832018-03-03 22:43:43 -0500129 sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(
130 desc, kBottomLeft_GrSurfaceOrigin, SkBackingFit::kApprox, SkBudgeted::kYes);
Robert Phillips84a81202016-11-04 11:59:10 -0400131
132 // Both RenderTarget and Texture
Robert Phillips2f493142017-03-02 18:18:38 -0500133 GrRenderTargetProxy* rtProxy = proxy->asRenderTargetProxy();
Robert Phillips37430132016-11-09 06:50:43 -0500134 REPORTER_ASSERT(reporter, rtProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400135 GrTextureProxy* tProxy = rtProxy->asTextureProxy();
136 REPORTER_ASSERT(reporter, tProxy);
Robert Phillips37430132016-11-09 06:50:43 -0500137 REPORTER_ASSERT(reporter, tProxy->asRenderTargetProxy() == rtProxy);
138 REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400139 }
Robert Phillips26c90e02017-03-14 14:39:29 -0400140
Robert Phillips84a81202016-11-04 11:59:10 -0400141 {
Brian Salomon2a4f9832018-03-03 22:43:43 -0500142 sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(
143 desc, kBottomLeft_GrSurfaceOrigin, SkBackingFit::kApprox, SkBudgeted::kYes);
Robert Phillips84a81202016-11-04 11:59:10 -0400144
145 // Both RenderTarget and Texture - but via GrTextureProxy
Robert Phillips2f493142017-03-02 18:18:38 -0500146 GrTextureProxy* tProxy = proxy->asTextureProxy();
Robert Phillips37430132016-11-09 06:50:43 -0500147 REPORTER_ASSERT(reporter, tProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400148 GrRenderTargetProxy* rtProxy = tProxy->asRenderTargetProxy();
149 REPORTER_ASSERT(reporter, rtProxy);
Robert Phillips37430132016-11-09 06:50:43 -0500150 REPORTER_ASSERT(reporter, rtProxy->asTextureProxy() == tProxy);
151 REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400152 }
153
154 {
155 desc.fFlags = kNone_GrSurfaceFlags; // force no-RT
156
Brian Salomon2a4f9832018-03-03 22:43:43 -0500157 sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(
158 desc, kTopLeft_GrSurfaceOrigin, SkBackingFit::kApprox, SkBudgeted::kYes);
Robert Phillips84a81202016-11-04 11:59:10 -0400159 // Texture-only
Robert Phillips2f493142017-03-02 18:18:38 -0500160 GrTextureProxy* tProxy = proxy->asTextureProxy();
Robert Phillips37430132016-11-09 06:50:43 -0500161 REPORTER_ASSERT(reporter, tProxy);
162 REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400163 REPORTER_ASSERT(reporter, !tProxy->asRenderTargetProxy());
164 }
165}
166#endif