blob: 78465f989f141d5acd9e8224bb4cbf409dff35f5 [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 Phillips009e9af2017-06-15 14:01:04 -040014#include "GrRenderTarget.h"
Robert Phillips84a81202016-11-04 11:59:10 -040015#include "GrRenderTargetProxy.h"
Brian Osman32342f02017-03-04 08:12:46 -050016#include "GrResourceProvider.h"
17#include "GrSurfaceProxy.h"
Robert Phillips646e4292017-06-13 12:44:56 -040018#include "GrTexture.h"
Brian Osman32342f02017-03-04 08:12:46 -050019#include "GrTextureProxy.h"
Robert Phillips84a81202016-11-04 11:59:10 -040020
Brian Osman32342f02017-03-04 08:12:46 -050021static sk_sp<GrSurfaceProxy> make_wrapped_FBO0(GrResourceProvider* provider,
Robert Phillips37430132016-11-09 06:50:43 -050022 skiatest::Reporter* reporter,
23 const GrSurfaceDesc& desc) {
Greg Danielbcf612b2017-05-01 13:50:58 +000024 GrGLFramebufferInfo fboInfo;
25 fboInfo.fFBOID = 0;
26 GrBackendRenderTarget backendRT(desc.fWidth, desc.fHeight, desc.fSampleCnt, 8,
27 desc.fConfig, fboInfo);
Robert Phillips84a81202016-11-04 11:59:10 -040028
Robert Phillips16d8ec62017-07-27 16:16:25 -040029 SkASSERT(kDefault_GrSurfaceOrigin != desc.fOrigin);
Robert Phillips7294b852017-08-01 13:51:44 +000030 sk_sp<GrRenderTarget> defaultFBO(provider->wrapBackendRenderTarget(backendRT, desc.fOrigin));
Robert Phillips84a81202016-11-04 11:59:10 -040031 SkASSERT(!defaultFBO->asTexture());
32
Robert Phillips066f0202017-07-25 10:16:35 -040033 return GrSurfaceProxy::MakeWrapped(std::move(defaultFBO), desc.fOrigin);
Robert Phillips84a81202016-11-04 11:59:10 -040034}
35
Brian Osman32342f02017-03-04 08:12:46 -050036static sk_sp<GrSurfaceProxy> make_wrapped_offscreen_rt(GrResourceProvider* provider,
Robert Phillips37430132016-11-09 06:50:43 -050037 skiatest::Reporter* reporter,
38 const GrSurfaceDesc& desc,
39 SkBudgeted budgeted) {
Robert Phillips84a81202016-11-04 11:59:10 -040040 SkASSERT(kRenderTarget_GrSurfaceFlag == desc.fFlags);
41
42 sk_sp<GrTexture> tex(provider->createTexture(desc, budgeted));
Robert Phillips84a81202016-11-04 11:59:10 -040043
Robert Phillips066f0202017-07-25 10:16:35 -040044 return GrSurfaceProxy::MakeWrapped(std::move(tex), desc.fOrigin);
Robert Phillips84a81202016-11-04 11:59:10 -040045}
46
Brian Osman32342f02017-03-04 08:12:46 -050047static sk_sp<GrSurfaceProxy> make_wrapped_texture(GrResourceProvider* provider,
Robert Phillips84a81202016-11-04 11:59:10 -040048 const GrSurfaceDesc& desc,
49 SkBudgeted budgeted) {
50 sk_sp<GrTexture> tex(provider->createTexture(desc, budgeted));
51
Robert Phillips066f0202017-07-25 10:16:35 -040052 return GrSurfaceProxy::MakeWrapped(std::move(tex), desc.fOrigin);
Robert Phillips84a81202016-11-04 11:59:10 -040053}
54
55// Test converting between RenderTargetProxies and TextureProxies for wrapped
56// Proxies
57DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WrappedProxyConversionTest, reporter, ctxInfo) {
Brian Osman32342f02017-03-04 08:12:46 -050058 GrResourceProvider* provider = ctxInfo.grContext()->resourceProvider();
Robert Phillips84a81202016-11-04 11:59:10 -040059
60 GrSurfaceDesc desc;
61 desc.fFlags = kRenderTarget_GrSurfaceFlag;
62 desc.fWidth = 64;
63 desc.fHeight = 64;
64 desc.fConfig = kRGBA_8888_GrPixelConfig;
Greg Danielbcf612b2017-05-01 13:50:58 +000065 desc.fOrigin = kBottomLeft_GrSurfaceOrigin;
Robert Phillips84a81202016-11-04 11:59:10 -040066
67 if (kOpenGL_GrBackend == ctxInfo.backend()) {
68 // External on-screen render target.
Robert Phillips37430132016-11-09 06:50:43 -050069 sk_sp<GrSurfaceProxy> sProxy(make_wrapped_FBO0(provider, reporter, desc));
Robert Phillips84a81202016-11-04 11:59:10 -040070
71 // RenderTarget-only
Robert Phillips37430132016-11-09 06:50:43 -050072 GrRenderTargetProxy* rtProxy = sProxy->asRenderTargetProxy();
73 REPORTER_ASSERT(reporter, rtProxy);
Robert Phillips84a81202016-11-04 11:59:10 -040074 REPORTER_ASSERT(reporter, !rtProxy->asTextureProxy());
Robert Phillips37430132016-11-09 06:50:43 -050075 REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy);
Robert Phillips84a81202016-11-04 11:59:10 -040076 }
77
78 {
79 // Internal offscreen render target.
Robert Phillips37430132016-11-09 06:50:43 -050080 sk_sp<GrSurfaceProxy> sProxy(make_wrapped_offscreen_rt(provider,
81 reporter, desc,
82 SkBudgeted::kYes));
Robert Phillips84a81202016-11-04 11:59:10 -040083
84 // Both RenderTarget and Texture
Robert Phillips37430132016-11-09 06:50:43 -050085 GrRenderTargetProxy* rtProxy = sProxy->asRenderTargetProxy();
86 REPORTER_ASSERT(reporter, rtProxy);
Robert Phillips84a81202016-11-04 11:59:10 -040087 GrTextureProxy* tProxy = rtProxy->asTextureProxy();
88 REPORTER_ASSERT(reporter, tProxy);
Robert Phillips37430132016-11-09 06:50:43 -050089 REPORTER_ASSERT(reporter, tProxy->asRenderTargetProxy() == rtProxy);
90 REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy);
Robert Phillips84a81202016-11-04 11:59:10 -040091 }
92
93 {
94 // Internal offscreen render target - but through GrTextureProxy
Robert Phillips37430132016-11-09 06:50:43 -050095 sk_sp<GrSurfaceProxy> sProxy(make_wrapped_texture(provider, desc, SkBudgeted::kYes));
Robert Phillips84a81202016-11-04 11:59:10 -040096
97 // Both RenderTarget and Texture
Robert Phillips37430132016-11-09 06:50:43 -050098 GrTextureProxy* tProxy = sProxy->asTextureProxy();
99 REPORTER_ASSERT(reporter, tProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400100 GrRenderTargetProxy* rtProxy = tProxy->asRenderTargetProxy();
101 REPORTER_ASSERT(reporter, rtProxy);
Robert Phillips37430132016-11-09 06:50:43 -0500102 REPORTER_ASSERT(reporter, rtProxy->asTextureProxy() == tProxy);
103 REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400104 }
105
106 {
107 desc.fFlags = kNone_GrSurfaceFlags; // force no-RT
108
Robert Phillips37430132016-11-09 06:50:43 -0500109 sk_sp<GrSurfaceProxy> sProxy(make_wrapped_texture(provider, desc, SkBudgeted::kYes));
Robert Phillips84a81202016-11-04 11:59:10 -0400110
111 // Texture-only
Robert Phillips37430132016-11-09 06:50:43 -0500112 GrTextureProxy* tProxy = sProxy->asTextureProxy();
113 REPORTER_ASSERT(reporter, tProxy);
114 REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400115 REPORTER_ASSERT(reporter, !tProxy->asRenderTargetProxy());
116 }
117}
118
119// Test converting between RenderTargetProxies and TextureProxies for deferred
120// Proxies
121DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DefferredProxyConversionTest, reporter, ctxInfo) {
Brian Osman32342f02017-03-04 08:12:46 -0500122 GrResourceProvider* resourceProvider = ctxInfo.grContext()->resourceProvider();
Robert Phillips84a81202016-11-04 11:59:10 -0400123
124 GrSurfaceDesc desc;
125 desc.fFlags = kRenderTarget_GrSurfaceFlag;
Robert Phillips16d8ec62017-07-27 16:16:25 -0400126 desc.fOrigin = kBottomLeft_GrSurfaceOrigin;
Robert Phillips84a81202016-11-04 11:59:10 -0400127 desc.fWidth = 64;
128 desc.fHeight = 64;
129 desc.fConfig = kRGBA_8888_GrPixelConfig;
130
131 {
Robert Phillips26c90e02017-03-14 14:39:29 -0400132 sk_sp<GrTextureProxy> proxy(GrSurfaceProxy::MakeDeferred(resourceProvider, desc,
Robert Phillips2f493142017-03-02 18:18:38 -0500133 SkBackingFit::kApprox,
134 SkBudgeted::kYes));
Robert Phillips84a81202016-11-04 11:59:10 -0400135
136 // Both RenderTarget and Texture
Robert Phillips2f493142017-03-02 18:18:38 -0500137 GrRenderTargetProxy* rtProxy = proxy->asRenderTargetProxy();
Robert Phillips37430132016-11-09 06:50:43 -0500138 REPORTER_ASSERT(reporter, rtProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400139 GrTextureProxy* tProxy = rtProxy->asTextureProxy();
140 REPORTER_ASSERT(reporter, tProxy);
Robert Phillips37430132016-11-09 06:50:43 -0500141 REPORTER_ASSERT(reporter, tProxy->asRenderTargetProxy() == rtProxy);
142 REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400143 }
Robert Phillips26c90e02017-03-14 14:39:29 -0400144
Robert Phillips84a81202016-11-04 11:59:10 -0400145 {
Robert Phillips26c90e02017-03-14 14:39:29 -0400146 sk_sp<GrTextureProxy> proxy(GrSurfaceProxy::MakeDeferred(resourceProvider, desc,
Robert Phillips2f493142017-03-02 18:18:38 -0500147 SkBackingFit::kApprox,
148 SkBudgeted::kYes));
Robert Phillips84a81202016-11-04 11:59:10 -0400149
150 // Both RenderTarget and Texture - but via GrTextureProxy
Robert Phillips2f493142017-03-02 18:18:38 -0500151 GrTextureProxy* tProxy = proxy->asTextureProxy();
Robert Phillips37430132016-11-09 06:50:43 -0500152 REPORTER_ASSERT(reporter, tProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400153 GrRenderTargetProxy* rtProxy = tProxy->asRenderTargetProxy();
154 REPORTER_ASSERT(reporter, rtProxy);
Robert Phillips37430132016-11-09 06:50:43 -0500155 REPORTER_ASSERT(reporter, rtProxy->asTextureProxy() == tProxy);
156 REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400157 }
158
159 {
160 desc.fFlags = kNone_GrSurfaceFlags; // force no-RT
Robert Phillips16d8ec62017-07-27 16:16:25 -0400161 desc.fOrigin = kTopLeft_GrSurfaceOrigin;
Robert Phillips84a81202016-11-04 11:59:10 -0400162
Robert Phillips26c90e02017-03-14 14:39:29 -0400163 sk_sp<GrTextureProxy> proxy(GrSurfaceProxy::MakeDeferred(resourceProvider, desc,
Robert Phillips2f493142017-03-02 18:18:38 -0500164 SkBackingFit::kApprox,
165 SkBudgeted::kYes));
Robert Phillips84a81202016-11-04 11:59:10 -0400166
167 // Texture-only
Robert Phillips2f493142017-03-02 18:18:38 -0500168 GrTextureProxy* tProxy = proxy->asTextureProxy();
Robert Phillips37430132016-11-09 06:50:43 -0500169 REPORTER_ASSERT(reporter, tProxy);
170 REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400171 REPORTER_ASSERT(reporter, !tProxy->asRenderTargetProxy());
172 }
173}
174#endif