blob: bc7187f5e13291b7fa0098a6226bdf2f1e075eda [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
13#include "GrSurfaceProxy.h"
14#include "GrTextureProxy.h"
15#include "GrRenderTargetProxy.h"
16
Robert Phillips37430132016-11-09 06:50:43 -050017static sk_sp<GrSurfaceProxy> make_wrapped_FBO0(GrTextureProvider* provider,
18 skiatest::Reporter* reporter,
19 const GrSurfaceDesc& desc) {
Robert Phillips84a81202016-11-04 11:59:10 -040020 GrBackendRenderTargetDesc backendDesc;
21 backendDesc.fWidth = desc.fWidth;
22 backendDesc.fHeight = desc.fHeight;
23 backendDesc.fConfig = desc.fConfig;
24 backendDesc.fOrigin = desc.fOrigin;
25 backendDesc.fSampleCnt = desc.fSampleCnt;
26 backendDesc.fStencilBits = 8;
27 backendDesc.fRenderTargetHandle = 0;
28
29 sk_sp<GrRenderTarget> defaultFBO(provider->wrapBackendRenderTarget(backendDesc));
30 SkASSERT(!defaultFBO->asTexture());
31
Robert Phillips37430132016-11-09 06:50:43 -050032 return GrSurfaceProxy::MakeWrapped(std::move(defaultFBO));
Robert Phillips84a81202016-11-04 11:59:10 -040033}
34
Robert Phillips37430132016-11-09 06:50:43 -050035static sk_sp<GrSurfaceProxy> make_wrapped_offscreen_rt(GrTextureProvider* provider,
36 skiatest::Reporter* reporter,
37 const GrSurfaceDesc& desc,
38 SkBudgeted budgeted) {
Robert Phillips84a81202016-11-04 11:59:10 -040039 SkASSERT(kRenderTarget_GrSurfaceFlag == desc.fFlags);
40
41 sk_sp<GrTexture> tex(provider->createTexture(desc, budgeted));
Robert Phillips84a81202016-11-04 11:59:10 -040042
Robert Phillips37430132016-11-09 06:50:43 -050043 return GrSurfaceProxy::MakeWrapped(std::move(tex));
Robert Phillips84a81202016-11-04 11:59:10 -040044}
45
Robert Phillips37430132016-11-09 06:50:43 -050046static sk_sp<GrSurfaceProxy> make_wrapped_texture(GrTextureProvider* provider,
Robert Phillips84a81202016-11-04 11:59:10 -040047 const GrSurfaceDesc& desc,
48 SkBudgeted budgeted) {
49 sk_sp<GrTexture> tex(provider->createTexture(desc, budgeted));
50
Robert Phillips37430132016-11-09 06:50:43 -050051 return GrSurfaceProxy::MakeWrapped(std::move(tex));
Robert Phillips84a81202016-11-04 11:59:10 -040052}
53
54// Test converting between RenderTargetProxies and TextureProxies for wrapped
55// Proxies
56DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WrappedProxyConversionTest, reporter, ctxInfo) {
57 GrTextureProvider* provider = ctxInfo.grContext()->textureProvider();
58
59 GrSurfaceDesc desc;
60 desc.fFlags = kRenderTarget_GrSurfaceFlag;
61 desc.fWidth = 64;
62 desc.fHeight = 64;
63 desc.fConfig = kRGBA_8888_GrPixelConfig;
64
65 if (kOpenGL_GrBackend == ctxInfo.backend()) {
66 // External on-screen render target.
Robert Phillips37430132016-11-09 06:50:43 -050067 sk_sp<GrSurfaceProxy> sProxy(make_wrapped_FBO0(provider, reporter, desc));
Robert Phillips84a81202016-11-04 11:59:10 -040068
69 // RenderTarget-only
Robert Phillips37430132016-11-09 06:50:43 -050070 GrRenderTargetProxy* rtProxy = sProxy->asRenderTargetProxy();
71 REPORTER_ASSERT(reporter, rtProxy);
Robert Phillips84a81202016-11-04 11:59:10 -040072 REPORTER_ASSERT(reporter, !rtProxy->asTextureProxy());
Robert Phillips37430132016-11-09 06:50:43 -050073 REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy);
Robert Phillips84a81202016-11-04 11:59:10 -040074 }
75
76 {
77 // Internal offscreen render target.
Robert Phillips37430132016-11-09 06:50:43 -050078 sk_sp<GrSurfaceProxy> sProxy(make_wrapped_offscreen_rt(provider,
79 reporter, desc,
80 SkBudgeted::kYes));
Robert Phillips84a81202016-11-04 11:59:10 -040081
82 // Both RenderTarget and Texture
Robert Phillips37430132016-11-09 06:50:43 -050083 GrRenderTargetProxy* rtProxy = sProxy->asRenderTargetProxy();
84 REPORTER_ASSERT(reporter, rtProxy);
Robert Phillips84a81202016-11-04 11:59:10 -040085 GrTextureProxy* tProxy = rtProxy->asTextureProxy();
86 REPORTER_ASSERT(reporter, tProxy);
Robert Phillips37430132016-11-09 06:50:43 -050087 REPORTER_ASSERT(reporter, tProxy->asRenderTargetProxy() == rtProxy);
88 REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy);
Robert Phillips84a81202016-11-04 11:59:10 -040089 }
90
91 {
92 // Internal offscreen render target - but through GrTextureProxy
Robert Phillips37430132016-11-09 06:50:43 -050093 sk_sp<GrSurfaceProxy> sProxy(make_wrapped_texture(provider, desc, SkBudgeted::kYes));
Robert Phillips84a81202016-11-04 11:59:10 -040094
95 // Both RenderTarget and Texture
Robert Phillips37430132016-11-09 06:50:43 -050096 GrTextureProxy* tProxy = sProxy->asTextureProxy();
97 REPORTER_ASSERT(reporter, tProxy);
Robert Phillips84a81202016-11-04 11:59:10 -040098 GrRenderTargetProxy* rtProxy = tProxy->asRenderTargetProxy();
99 REPORTER_ASSERT(reporter, rtProxy);
Robert Phillips37430132016-11-09 06:50:43 -0500100 REPORTER_ASSERT(reporter, rtProxy->asTextureProxy() == tProxy);
101 REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400102 }
103
104 {
105 desc.fFlags = kNone_GrSurfaceFlags; // force no-RT
106
Robert Phillips37430132016-11-09 06:50:43 -0500107 sk_sp<GrSurfaceProxy> sProxy(make_wrapped_texture(provider, desc, SkBudgeted::kYes));
Robert Phillips84a81202016-11-04 11:59:10 -0400108
109 // Texture-only
Robert Phillips37430132016-11-09 06:50:43 -0500110 GrTextureProxy* tProxy = sProxy->asTextureProxy();
111 REPORTER_ASSERT(reporter, tProxy);
112 REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400113 REPORTER_ASSERT(reporter, !tProxy->asRenderTargetProxy());
114 }
115}
116
117// Test converting between RenderTargetProxies and TextureProxies for deferred
118// Proxies
119DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DefferredProxyConversionTest, reporter, ctxInfo) {
Robert Phillips84a81202016-11-04 11:59:10 -0400120 const GrCaps& caps = *ctxInfo.grContext()->caps();
121
122 GrSurfaceDesc desc;
123 desc.fFlags = kRenderTarget_GrSurfaceFlag;
124 desc.fWidth = 64;
125 desc.fHeight = 64;
126 desc.fConfig = kRGBA_8888_GrPixelConfig;
127
128 {
Robert Phillips37430132016-11-09 06:50:43 -0500129 sk_sp<GrSurfaceProxy> sProxy(GrSurfaceProxy::MakeDeferred(caps, desc,
130 SkBackingFit::kApprox,
131 SkBudgeted::kYes));
Robert Phillips84a81202016-11-04 11:59:10 -0400132
133 // Both RenderTarget and Texture
Robert Phillips37430132016-11-09 06:50:43 -0500134 GrRenderTargetProxy* rtProxy = sProxy->asRenderTargetProxy();
135 REPORTER_ASSERT(reporter, rtProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400136 GrTextureProxy* tProxy = rtProxy->asTextureProxy();
137 REPORTER_ASSERT(reporter, tProxy);
Robert Phillips37430132016-11-09 06:50:43 -0500138 REPORTER_ASSERT(reporter, tProxy->asRenderTargetProxy() == rtProxy);
139 REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400140 }
141
142 {
Robert Phillips37430132016-11-09 06:50:43 -0500143 sk_sp<GrSurfaceProxy> sProxy(GrSurfaceProxy::MakeDeferred(caps, desc,
144 SkBackingFit::kApprox,
145 SkBudgeted::kYes));
Robert Phillips84a81202016-11-04 11:59:10 -0400146
147 // Both RenderTarget and Texture - but via GrTextureProxy
Robert Phillips37430132016-11-09 06:50:43 -0500148 GrTextureProxy* tProxy = sProxy->asTextureProxy();
149 REPORTER_ASSERT(reporter, tProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400150 GrRenderTargetProxy* rtProxy = tProxy->asRenderTargetProxy();
151 REPORTER_ASSERT(reporter, rtProxy);
Robert Phillips37430132016-11-09 06:50:43 -0500152 REPORTER_ASSERT(reporter, rtProxy->asTextureProxy() == tProxy);
153 REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400154 }
155
156 {
157 desc.fFlags = kNone_GrSurfaceFlags; // force no-RT
158
Robert Phillips37430132016-11-09 06:50:43 -0500159 sk_sp<GrSurfaceProxy> sProxy(GrSurfaceProxy::MakeDeferred(caps, desc,
160 SkBackingFit::kApprox,
161 SkBudgeted::kYes));
Robert Phillips84a81202016-11-04 11:59:10 -0400162
163 // Texture-only
Robert Phillips37430132016-11-09 06:50:43 -0500164 GrTextureProxy* tProxy = sProxy->asTextureProxy();
165 REPORTER_ASSERT(reporter, tProxy);
166 REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400167 REPORTER_ASSERT(reporter, !tProxy->asRenderTargetProxy());
168 }
169}
170#endif