blob: c8b690528f53dcf62a0ed70d30617044cd26c70e [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,
24 const GrSurfaceDesc& desc) {
Greg Danielbcf612b2017-05-01 13:50:58 +000025 GrGLFramebufferInfo fboInfo;
26 fboInfo.fFBOID = 0;
27 GrBackendRenderTarget backendRT(desc.fWidth, desc.fHeight, desc.fSampleCnt, 8,
28 desc.fConfig, fboInfo);
Robert Phillips84a81202016-11-04 11:59:10 -040029
Robert Phillips0bd24dc2018-01-16 08:06:32 -050030 return provider->createWrappedRenderTargetProxy(backendRT, desc.fOrigin);
Robert Phillips84a81202016-11-04 11:59:10 -040031}
32
Robert Phillips0bd24dc2018-01-16 08:06:32 -050033static sk_sp<GrSurfaceProxy> make_wrapped_offscreen_rt(GrProxyProvider* provider,
34 const GrSurfaceDesc& desc) {
Robert Phillips84a81202016-11-04 11:59:10 -040035 SkASSERT(kRenderTarget_GrSurfaceFlag == desc.fFlags);
36
Robert Phillips0bd24dc2018-01-16 08:06:32 -050037 return provider->createInstantiatedProxy(desc, SkBackingFit::kExact, SkBudgeted::kYes);
Robert Phillips84a81202016-11-04 11:59:10 -040038}
39
Robert Phillips0bd24dc2018-01-16 08:06:32 -050040static sk_sp<GrSurfaceProxy> make_wrapped_texture(GrProxyProvider* provider,
41 const GrSurfaceDesc& desc) {
42 return provider->createInstantiatedProxy(desc, SkBackingFit::kExact, SkBudgeted::kYes);
Robert Phillips84a81202016-11-04 11:59:10 -040043}
44
45// Test converting between RenderTargetProxies and TextureProxies for wrapped
46// Proxies
47DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WrappedProxyConversionTest, reporter, ctxInfo) {
Robert Phillips0bd24dc2018-01-16 08:06:32 -050048 GrProxyProvider* proxyProvider = ctxInfo.grContext()->contextPriv().proxyProvider();
Robert Phillips84a81202016-11-04 11:59:10 -040049
50 GrSurfaceDesc desc;
51 desc.fFlags = kRenderTarget_GrSurfaceFlag;
52 desc.fWidth = 64;
53 desc.fHeight = 64;
54 desc.fConfig = kRGBA_8888_GrPixelConfig;
Greg Danielbcf612b2017-05-01 13:50:58 +000055 desc.fOrigin = kBottomLeft_GrSurfaceOrigin;
Robert Phillips84a81202016-11-04 11:59:10 -040056
57 if (kOpenGL_GrBackend == ctxInfo.backend()) {
58 // External on-screen render target.
Robert Phillips0bd24dc2018-01-16 08:06:32 -050059 sk_sp<GrSurfaceProxy> sProxy(make_wrapped_FBO0(proxyProvider, reporter, desc));
Robert Phillips78d762d2018-01-23 16:57:35 -050060 if (sProxy) {
61 // RenderTarget-only
62 GrRenderTargetProxy* rtProxy = sProxy->asRenderTargetProxy();
63 REPORTER_ASSERT(reporter, rtProxy);
64 REPORTER_ASSERT(reporter, !rtProxy->asTextureProxy());
65 REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy);
66 }
Robert Phillips84a81202016-11-04 11:59:10 -040067 }
68
69 {
70 // Internal offscreen render target.
Robert Phillips0bd24dc2018-01-16 08:06:32 -050071 sk_sp<GrSurfaceProxy> sProxy(make_wrapped_offscreen_rt(proxyProvider, desc));
Robert Phillips78d762d2018-01-23 16:57:35 -050072 if (sProxy) {
73 // Both RenderTarget and Texture
74 GrRenderTargetProxy* rtProxy = sProxy->asRenderTargetProxy();
75 REPORTER_ASSERT(reporter, rtProxy);
76 GrTextureProxy* tProxy = rtProxy->asTextureProxy();
77 REPORTER_ASSERT(reporter, tProxy);
78 REPORTER_ASSERT(reporter, tProxy->asRenderTargetProxy() == rtProxy);
79 REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy);
80 }
Robert Phillips84a81202016-11-04 11:59:10 -040081 }
82
83 {
84 // Internal offscreen render target - but through GrTextureProxy
Robert Phillips0bd24dc2018-01-16 08:06:32 -050085 sk_sp<GrSurfaceProxy> sProxy(make_wrapped_texture(proxyProvider, desc));
Robert Phillips78d762d2018-01-23 16:57:35 -050086 if (sProxy) {
87 // Both RenderTarget and Texture
88 GrTextureProxy* tProxy = sProxy->asTextureProxy();
89 REPORTER_ASSERT(reporter, tProxy);
90 GrRenderTargetProxy* rtProxy = tProxy->asRenderTargetProxy();
91 REPORTER_ASSERT(reporter, rtProxy);
92 REPORTER_ASSERT(reporter, rtProxy->asTextureProxy() == tProxy);
93 REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
94 }
Robert Phillips84a81202016-11-04 11:59:10 -040095 }
96
97 {
98 desc.fFlags = kNone_GrSurfaceFlags; // force no-RT
99
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500100 sk_sp<GrSurfaceProxy> sProxy(make_wrapped_texture(proxyProvider, desc));
Robert Phillips78d762d2018-01-23 16:57:35 -0500101 if (sProxy) {
102 // Texture-only
103 GrTextureProxy* tProxy = sProxy->asTextureProxy();
104 REPORTER_ASSERT(reporter, tProxy);
105 REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
106 REPORTER_ASSERT(reporter, !tProxy->asRenderTargetProxy());
107 }
Robert Phillips84a81202016-11-04 11:59:10 -0400108 }
109}
110
111// Test converting between RenderTargetProxies and TextureProxies for deferred
112// Proxies
113DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DefferredProxyConversionTest, reporter, ctxInfo) {
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500114 GrProxyProvider* proxyProvider = ctxInfo.grContext()->contextPriv().proxyProvider();
Robert Phillips84a81202016-11-04 11:59:10 -0400115
116 GrSurfaceDesc desc;
117 desc.fFlags = kRenderTarget_GrSurfaceFlag;
Robert Phillips16d8ec62017-07-27 16:16:25 -0400118 desc.fOrigin = kBottomLeft_GrSurfaceOrigin;
Robert Phillips84a81202016-11-04 11:59:10 -0400119 desc.fWidth = 64;
120 desc.fHeight = 64;
121 desc.fConfig = kRGBA_8888_GrPixelConfig;
122
123 {
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500124 sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(desc, SkBackingFit::kApprox,
125 SkBudgeted::kYes);
Robert Phillips84a81202016-11-04 11:59:10 -0400126
127 // Both RenderTarget and Texture
Robert Phillips2f493142017-03-02 18:18:38 -0500128 GrRenderTargetProxy* rtProxy = proxy->asRenderTargetProxy();
Robert Phillips37430132016-11-09 06:50:43 -0500129 REPORTER_ASSERT(reporter, rtProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400130 GrTextureProxy* tProxy = rtProxy->asTextureProxy();
131 REPORTER_ASSERT(reporter, tProxy);
Robert Phillips37430132016-11-09 06:50:43 -0500132 REPORTER_ASSERT(reporter, tProxy->asRenderTargetProxy() == rtProxy);
133 REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400134 }
Robert Phillips26c90e02017-03-14 14:39:29 -0400135
Robert Phillips84a81202016-11-04 11:59:10 -0400136 {
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500137 sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(desc, SkBackingFit::kApprox,
138 SkBudgeted::kYes);
Robert Phillips84a81202016-11-04 11:59:10 -0400139
140 // Both RenderTarget and Texture - but via GrTextureProxy
Robert Phillips2f493142017-03-02 18:18:38 -0500141 GrTextureProxy* tProxy = proxy->asTextureProxy();
Robert Phillips37430132016-11-09 06:50:43 -0500142 REPORTER_ASSERT(reporter, tProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400143 GrRenderTargetProxy* rtProxy = tProxy->asRenderTargetProxy();
144 REPORTER_ASSERT(reporter, rtProxy);
Robert Phillips37430132016-11-09 06:50:43 -0500145 REPORTER_ASSERT(reporter, rtProxy->asTextureProxy() == tProxy);
146 REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400147 }
148
149 {
150 desc.fFlags = kNone_GrSurfaceFlags; // force no-RT
Robert Phillips16d8ec62017-07-27 16:16:25 -0400151 desc.fOrigin = kTopLeft_GrSurfaceOrigin;
Robert Phillips84a81202016-11-04 11:59:10 -0400152
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500153 sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(desc, SkBackingFit::kApprox,
154 SkBudgeted::kYes);
Robert Phillips84a81202016-11-04 11:59:10 -0400155 // Texture-only
Robert Phillips2f493142017-03-02 18:18:38 -0500156 GrTextureProxy* tProxy = proxy->asTextureProxy();
Robert Phillips37430132016-11-09 06:50:43 -0500157 REPORTER_ASSERT(reporter, tProxy);
158 REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400159 REPORTER_ASSERT(reporter, !tProxy->asRenderTargetProxy());
160 }
161}
162#endif