blob: 167cc4b10d4059e3b52f49ce2a6587831fcbf779 [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 Phillips84a81202016-11-04 11:59:10 -040014#include "GrRenderTargetProxy.h"
Brian Osman32342f02017-03-04 08:12:46 -050015#include "GrResourceProvider.h"
16#include "GrSurfaceProxy.h"
17#include "GrTextureProxy.h"
Robert Phillips84a81202016-11-04 11:59:10 -040018
Brian Osman32342f02017-03-04 08:12:46 -050019static sk_sp<GrSurfaceProxy> make_wrapped_FBO0(GrResourceProvider* provider,
Robert Phillips37430132016-11-09 06:50:43 -050020 skiatest::Reporter* reporter,
21 const GrSurfaceDesc& desc) {
Greg Danielbcf612b2017-05-01 13:50:58 +000022 GrGLFramebufferInfo fboInfo;
23 fboInfo.fFBOID = 0;
24 GrBackendRenderTarget backendRT(desc.fWidth, desc.fHeight, desc.fSampleCnt, 8,
25 desc.fConfig, fboInfo);
Robert Phillips84a81202016-11-04 11:59:10 -040026
Greg Danielbcf612b2017-05-01 13:50:58 +000027 sk_sp<GrRenderTarget> defaultFBO(provider->wrapBackendRenderTarget(backendRT, desc.fOrigin));
Robert Phillips84a81202016-11-04 11:59:10 -040028 SkASSERT(!defaultFBO->asTexture());
29
Robert Phillips37430132016-11-09 06:50:43 -050030 return GrSurfaceProxy::MakeWrapped(std::move(defaultFBO));
Robert Phillips84a81202016-11-04 11:59:10 -040031}
32
Brian Osman32342f02017-03-04 08:12:46 -050033static sk_sp<GrSurfaceProxy> make_wrapped_offscreen_rt(GrResourceProvider* provider,
Robert Phillips37430132016-11-09 06:50:43 -050034 skiatest::Reporter* reporter,
35 const GrSurfaceDesc& desc,
36 SkBudgeted budgeted) {
Robert Phillips84a81202016-11-04 11:59:10 -040037 SkASSERT(kRenderTarget_GrSurfaceFlag == desc.fFlags);
38
39 sk_sp<GrTexture> tex(provider->createTexture(desc, budgeted));
Robert Phillips84a81202016-11-04 11:59:10 -040040
Robert Phillips37430132016-11-09 06:50:43 -050041 return GrSurfaceProxy::MakeWrapped(std::move(tex));
Robert Phillips84a81202016-11-04 11:59:10 -040042}
43
Brian Osman32342f02017-03-04 08:12:46 -050044static sk_sp<GrSurfaceProxy> make_wrapped_texture(GrResourceProvider* provider,
Robert Phillips84a81202016-11-04 11:59:10 -040045 const GrSurfaceDesc& desc,
46 SkBudgeted budgeted) {
47 sk_sp<GrTexture> tex(provider->createTexture(desc, budgeted));
48
Robert Phillips37430132016-11-09 06:50:43 -050049 return GrSurfaceProxy::MakeWrapped(std::move(tex));
Robert Phillips84a81202016-11-04 11:59:10 -040050}
51
52// Test converting between RenderTargetProxies and TextureProxies for wrapped
53// Proxies
54DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WrappedProxyConversionTest, reporter, ctxInfo) {
Brian Osman32342f02017-03-04 08:12:46 -050055 GrResourceProvider* provider = ctxInfo.grContext()->resourceProvider();
Robert Phillips84a81202016-11-04 11:59:10 -040056
57 GrSurfaceDesc desc;
58 desc.fFlags = kRenderTarget_GrSurfaceFlag;
59 desc.fWidth = 64;
60 desc.fHeight = 64;
61 desc.fConfig = kRGBA_8888_GrPixelConfig;
Greg Danielbcf612b2017-05-01 13:50:58 +000062 desc.fOrigin = kBottomLeft_GrSurfaceOrigin;
Robert Phillips84a81202016-11-04 11:59:10 -040063
64 if (kOpenGL_GrBackend == ctxInfo.backend()) {
65 // External on-screen render target.
Robert Phillips37430132016-11-09 06:50:43 -050066 sk_sp<GrSurfaceProxy> sProxy(make_wrapped_FBO0(provider, reporter, desc));
Robert Phillips84a81202016-11-04 11:59:10 -040067
68 // RenderTarget-only
Robert Phillips37430132016-11-09 06:50:43 -050069 GrRenderTargetProxy* rtProxy = sProxy->asRenderTargetProxy();
70 REPORTER_ASSERT(reporter, rtProxy);
Robert Phillips84a81202016-11-04 11:59:10 -040071 REPORTER_ASSERT(reporter, !rtProxy->asTextureProxy());
Robert Phillips37430132016-11-09 06:50:43 -050072 REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy);
Robert Phillips84a81202016-11-04 11:59:10 -040073 }
74
75 {
76 // Internal offscreen render target.
Robert Phillips37430132016-11-09 06:50:43 -050077 sk_sp<GrSurfaceProxy> sProxy(make_wrapped_offscreen_rt(provider,
78 reporter, desc,
79 SkBudgeted::kYes));
Robert Phillips84a81202016-11-04 11:59:10 -040080
81 // Both RenderTarget and Texture
Robert Phillips37430132016-11-09 06:50:43 -050082 GrRenderTargetProxy* rtProxy = sProxy->asRenderTargetProxy();
83 REPORTER_ASSERT(reporter, rtProxy);
Robert Phillips84a81202016-11-04 11:59:10 -040084 GrTextureProxy* tProxy = rtProxy->asTextureProxy();
85 REPORTER_ASSERT(reporter, tProxy);
Robert Phillips37430132016-11-09 06:50:43 -050086 REPORTER_ASSERT(reporter, tProxy->asRenderTargetProxy() == rtProxy);
87 REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy);
Robert Phillips84a81202016-11-04 11:59:10 -040088 }
89
90 {
91 // Internal offscreen render target - but through GrTextureProxy
Robert Phillips37430132016-11-09 06:50:43 -050092 sk_sp<GrSurfaceProxy> sProxy(make_wrapped_texture(provider, desc, SkBudgeted::kYes));
Robert Phillips84a81202016-11-04 11:59:10 -040093
94 // Both RenderTarget and Texture
Robert Phillips37430132016-11-09 06:50:43 -050095 GrTextureProxy* tProxy = sProxy->asTextureProxy();
96 REPORTER_ASSERT(reporter, tProxy);
Robert Phillips84a81202016-11-04 11:59:10 -040097 GrRenderTargetProxy* rtProxy = tProxy->asRenderTargetProxy();
98 REPORTER_ASSERT(reporter, rtProxy);
Robert Phillips37430132016-11-09 06:50:43 -050099 REPORTER_ASSERT(reporter, rtProxy->asTextureProxy() == tProxy);
100 REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400101 }
102
103 {
104 desc.fFlags = kNone_GrSurfaceFlags; // force no-RT
105
Robert Phillips37430132016-11-09 06:50:43 -0500106 sk_sp<GrSurfaceProxy> sProxy(make_wrapped_texture(provider, desc, SkBudgeted::kYes));
Robert Phillips84a81202016-11-04 11:59:10 -0400107
108 // Texture-only
Robert Phillips37430132016-11-09 06:50:43 -0500109 GrTextureProxy* tProxy = sProxy->asTextureProxy();
110 REPORTER_ASSERT(reporter, tProxy);
111 REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400112 REPORTER_ASSERT(reporter, !tProxy->asRenderTargetProxy());
113 }
114}
115
116// Test converting between RenderTargetProxies and TextureProxies for deferred
117// Proxies
118DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DefferredProxyConversionTest, reporter, ctxInfo) {
Brian Osman32342f02017-03-04 08:12:46 -0500119 GrResourceProvider* resourceProvider = ctxInfo.grContext()->resourceProvider();
Robert Phillips84a81202016-11-04 11:59:10 -0400120
121 GrSurfaceDesc desc;
122 desc.fFlags = kRenderTarget_GrSurfaceFlag;
123 desc.fWidth = 64;
124 desc.fHeight = 64;
125 desc.fConfig = kRGBA_8888_GrPixelConfig;
126
127 {
Robert Phillips26c90e02017-03-14 14:39:29 -0400128 sk_sp<GrTextureProxy> proxy(GrSurfaceProxy::MakeDeferred(resourceProvider, desc,
Robert Phillips2f493142017-03-02 18:18:38 -0500129 SkBackingFit::kApprox,
130 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 {
Robert Phillips26c90e02017-03-14 14:39:29 -0400142 sk_sp<GrTextureProxy> proxy(GrSurfaceProxy::MakeDeferred(resourceProvider, desc,
Robert Phillips2f493142017-03-02 18:18:38 -0500143 SkBackingFit::kApprox,
144 SkBudgeted::kYes));
Robert Phillips84a81202016-11-04 11:59:10 -0400145
146 // Both RenderTarget and Texture - but via GrTextureProxy
Robert Phillips2f493142017-03-02 18:18:38 -0500147 GrTextureProxy* tProxy = proxy->asTextureProxy();
Robert Phillips37430132016-11-09 06:50:43 -0500148 REPORTER_ASSERT(reporter, tProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400149 GrRenderTargetProxy* rtProxy = tProxy->asRenderTargetProxy();
150 REPORTER_ASSERT(reporter, rtProxy);
Robert Phillips37430132016-11-09 06:50:43 -0500151 REPORTER_ASSERT(reporter, rtProxy->asTextureProxy() == tProxy);
152 REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400153 }
154
155 {
156 desc.fFlags = kNone_GrSurfaceFlags; // force no-RT
157
Robert Phillips26c90e02017-03-14 14:39:29 -0400158 sk_sp<GrTextureProxy> proxy(GrSurfaceProxy::MakeDeferred(resourceProvider, desc,
Robert Phillips2f493142017-03-02 18:18:38 -0500159 SkBackingFit::kApprox,
160 SkBudgeted::kYes));
Robert Phillips84a81202016-11-04 11:59:10 -0400161
162 // Texture-only
Robert Phillips2f493142017-03-02 18:18:38 -0500163 GrTextureProxy* tProxy = proxy->asTextureProxy();
Robert Phillips37430132016-11-09 06:50:43 -0500164 REPORTER_ASSERT(reporter, tProxy);
165 REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400166 REPORTER_ASSERT(reporter, !tProxy->asRenderTargetProxy());
167 }
168}
169#endif