blob: 98f0985e03dddc8567b2af5d13b3f12e45ae68e8 [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"
Robert Phillips646e4292017-06-13 12:44:56 -040017#include "GrTexture.h"
Brian Osman32342f02017-03-04 08:12:46 -050018#include "GrTextureProxy.h"
Robert Phillips84a81202016-11-04 11:59:10 -040019
Brian Osman32342f02017-03-04 08:12:46 -050020static sk_sp<GrSurfaceProxy> make_wrapped_FBO0(GrResourceProvider* provider,
Robert Phillips37430132016-11-09 06:50:43 -050021 skiatest::Reporter* reporter,
22 const GrSurfaceDesc& desc) {
Greg Danielbcf612b2017-05-01 13:50:58 +000023 GrGLFramebufferInfo fboInfo;
24 fboInfo.fFBOID = 0;
25 GrBackendRenderTarget backendRT(desc.fWidth, desc.fHeight, desc.fSampleCnt, 8,
26 desc.fConfig, fboInfo);
Robert Phillips84a81202016-11-04 11:59:10 -040027
Greg Danielbcf612b2017-05-01 13:50:58 +000028 sk_sp<GrRenderTarget> defaultFBO(provider->wrapBackendRenderTarget(backendRT, desc.fOrigin));
Robert Phillips84a81202016-11-04 11:59:10 -040029 SkASSERT(!defaultFBO->asTexture());
30
Robert Phillips37430132016-11-09 06:50:43 -050031 return GrSurfaceProxy::MakeWrapped(std::move(defaultFBO));
Robert Phillips84a81202016-11-04 11:59:10 -040032}
33
Brian Osman32342f02017-03-04 08:12:46 -050034static sk_sp<GrSurfaceProxy> make_wrapped_offscreen_rt(GrResourceProvider* provider,
Robert Phillips37430132016-11-09 06:50:43 -050035 skiatest::Reporter* reporter,
36 const GrSurfaceDesc& desc,
37 SkBudgeted budgeted) {
Robert Phillips84a81202016-11-04 11:59:10 -040038 SkASSERT(kRenderTarget_GrSurfaceFlag == desc.fFlags);
39
40 sk_sp<GrTexture> tex(provider->createTexture(desc, budgeted));
Robert Phillips84a81202016-11-04 11:59:10 -040041
Robert Phillips37430132016-11-09 06:50:43 -050042 return GrSurfaceProxy::MakeWrapped(std::move(tex));
Robert Phillips84a81202016-11-04 11:59:10 -040043}
44
Brian Osman32342f02017-03-04 08:12:46 -050045static sk_sp<GrSurfaceProxy> make_wrapped_texture(GrResourceProvider* provider,
Robert Phillips84a81202016-11-04 11:59:10 -040046 const GrSurfaceDesc& desc,
47 SkBudgeted budgeted) {
48 sk_sp<GrTexture> tex(provider->createTexture(desc, budgeted));
49
Robert Phillips37430132016-11-09 06:50:43 -050050 return GrSurfaceProxy::MakeWrapped(std::move(tex));
Robert Phillips84a81202016-11-04 11:59:10 -040051}
52
53// Test converting between RenderTargetProxies and TextureProxies for wrapped
54// Proxies
55DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WrappedProxyConversionTest, reporter, ctxInfo) {
Brian Osman32342f02017-03-04 08:12:46 -050056 GrResourceProvider* provider = ctxInfo.grContext()->resourceProvider();
Robert Phillips84a81202016-11-04 11:59:10 -040057
58 GrSurfaceDesc desc;
59 desc.fFlags = kRenderTarget_GrSurfaceFlag;
60 desc.fWidth = 64;
61 desc.fHeight = 64;
62 desc.fConfig = kRGBA_8888_GrPixelConfig;
Greg Danielbcf612b2017-05-01 13:50:58 +000063 desc.fOrigin = kBottomLeft_GrSurfaceOrigin;
Robert Phillips84a81202016-11-04 11:59:10 -040064
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) {
Brian Osman32342f02017-03-04 08:12:46 -0500120 GrResourceProvider* resourceProvider = ctxInfo.grContext()->resourceProvider();
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 {
Robert Phillips26c90e02017-03-14 14:39:29 -0400129 sk_sp<GrTextureProxy> proxy(GrSurfaceProxy::MakeDeferred(resourceProvider, desc,
Robert Phillips2f493142017-03-02 18:18:38 -0500130 SkBackingFit::kApprox,
131 SkBudgeted::kYes));
Robert Phillips84a81202016-11-04 11:59:10 -0400132
133 // Both RenderTarget and Texture
Robert Phillips2f493142017-03-02 18:18:38 -0500134 GrRenderTargetProxy* rtProxy = proxy->asRenderTargetProxy();
Robert Phillips37430132016-11-09 06:50:43 -0500135 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 }
Robert Phillips26c90e02017-03-14 14:39:29 -0400141
Robert Phillips84a81202016-11-04 11:59:10 -0400142 {
Robert Phillips26c90e02017-03-14 14:39:29 -0400143 sk_sp<GrTextureProxy> proxy(GrSurfaceProxy::MakeDeferred(resourceProvider, desc,
Robert Phillips2f493142017-03-02 18:18:38 -0500144 SkBackingFit::kApprox,
145 SkBudgeted::kYes));
Robert Phillips84a81202016-11-04 11:59:10 -0400146
147 // Both RenderTarget and Texture - but via GrTextureProxy
Robert Phillips2f493142017-03-02 18:18:38 -0500148 GrTextureProxy* tProxy = proxy->asTextureProxy();
Robert Phillips37430132016-11-09 06:50:43 -0500149 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 Phillips26c90e02017-03-14 14:39:29 -0400159 sk_sp<GrTextureProxy> proxy(GrSurfaceProxy::MakeDeferred(resourceProvider, desc,
Robert Phillips2f493142017-03-02 18:18:38 -0500160 SkBackingFit::kApprox,
161 SkBudgeted::kYes));
Robert Phillips84a81202016-11-04 11:59:10 -0400162
163 // Texture-only
Robert Phillips2f493142017-03-02 18:18:38 -0500164 GrTextureProxy* tProxy = proxy->asTextureProxy();
Robert Phillips37430132016-11-09 06:50:43 -0500165 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