blob: 23ca695d4283900bc630e6bcc158d5931cd91ace [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
Greg Danielbcf612b2017-05-01 13:50:58 +000029 sk_sp<GrRenderTarget> defaultFBO(provider->wrapBackendRenderTarget(backendRT, desc.fOrigin));
Robert Phillips84a81202016-11-04 11:59:10 -040030 SkASSERT(!defaultFBO->asTexture());
31
Robert Phillips066f0202017-07-25 10:16:35 -040032 return GrSurfaceProxy::MakeWrapped(std::move(defaultFBO), desc.fOrigin);
Robert Phillips84a81202016-11-04 11:59:10 -040033}
34
Brian Osman32342f02017-03-04 08:12:46 -050035static sk_sp<GrSurfaceProxy> make_wrapped_offscreen_rt(GrResourceProvider* provider,
Robert Phillips37430132016-11-09 06:50:43 -050036 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 Phillips066f0202017-07-25 10:16:35 -040043 return GrSurfaceProxy::MakeWrapped(std::move(tex), desc.fOrigin);
Robert Phillips84a81202016-11-04 11:59:10 -040044}
45
Brian Osman32342f02017-03-04 08:12:46 -050046static sk_sp<GrSurfaceProxy> make_wrapped_texture(GrResourceProvider* 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 Phillips066f0202017-07-25 10:16:35 -040051 return GrSurfaceProxy::MakeWrapped(std::move(tex), desc.fOrigin);
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) {
Brian Osman32342f02017-03-04 08:12:46 -050057 GrResourceProvider* provider = ctxInfo.grContext()->resourceProvider();
Robert Phillips84a81202016-11-04 11:59:10 -040058
59 GrSurfaceDesc desc;
60 desc.fFlags = kRenderTarget_GrSurfaceFlag;
61 desc.fWidth = 64;
62 desc.fHeight = 64;
63 desc.fConfig = kRGBA_8888_GrPixelConfig;
Greg Danielbcf612b2017-05-01 13:50:58 +000064 desc.fOrigin = kBottomLeft_GrSurfaceOrigin;
Robert Phillips84a81202016-11-04 11:59:10 -040065
66 if (kOpenGL_GrBackend == ctxInfo.backend()) {
67 // External on-screen render target.
Robert Phillips37430132016-11-09 06:50:43 -050068 sk_sp<GrSurfaceProxy> sProxy(make_wrapped_FBO0(provider, reporter, desc));
Robert Phillips84a81202016-11-04 11:59:10 -040069
70 // RenderTarget-only
Robert Phillips37430132016-11-09 06:50:43 -050071 GrRenderTargetProxy* rtProxy = sProxy->asRenderTargetProxy();
72 REPORTER_ASSERT(reporter, rtProxy);
Robert Phillips84a81202016-11-04 11:59:10 -040073 REPORTER_ASSERT(reporter, !rtProxy->asTextureProxy());
Robert Phillips37430132016-11-09 06:50:43 -050074 REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy);
Robert Phillips84a81202016-11-04 11:59:10 -040075 }
76
77 {
78 // Internal offscreen render target.
Robert Phillips37430132016-11-09 06:50:43 -050079 sk_sp<GrSurfaceProxy> sProxy(make_wrapped_offscreen_rt(provider,
80 reporter, desc,
81 SkBudgeted::kYes));
Robert Phillips84a81202016-11-04 11:59:10 -040082
83 // Both RenderTarget and Texture
Robert Phillips37430132016-11-09 06:50:43 -050084 GrRenderTargetProxy* rtProxy = sProxy->asRenderTargetProxy();
85 REPORTER_ASSERT(reporter, rtProxy);
Robert Phillips84a81202016-11-04 11:59:10 -040086 GrTextureProxy* tProxy = rtProxy->asTextureProxy();
87 REPORTER_ASSERT(reporter, tProxy);
Robert Phillips37430132016-11-09 06:50:43 -050088 REPORTER_ASSERT(reporter, tProxy->asRenderTargetProxy() == rtProxy);
89 REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy);
Robert Phillips84a81202016-11-04 11:59:10 -040090 }
91
92 {
93 // Internal offscreen render target - but through GrTextureProxy
Robert Phillips37430132016-11-09 06:50:43 -050094 sk_sp<GrSurfaceProxy> sProxy(make_wrapped_texture(provider, desc, SkBudgeted::kYes));
Robert Phillips84a81202016-11-04 11:59:10 -040095
96 // Both RenderTarget and Texture
Robert Phillips37430132016-11-09 06:50:43 -050097 GrTextureProxy* tProxy = sProxy->asTextureProxy();
98 REPORTER_ASSERT(reporter, tProxy);
Robert Phillips84a81202016-11-04 11:59:10 -040099 GrRenderTargetProxy* rtProxy = tProxy->asRenderTargetProxy();
100 REPORTER_ASSERT(reporter, rtProxy);
Robert Phillips37430132016-11-09 06:50:43 -0500101 REPORTER_ASSERT(reporter, rtProxy->asTextureProxy() == tProxy);
102 REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400103 }
104
105 {
106 desc.fFlags = kNone_GrSurfaceFlags; // force no-RT
107
Robert Phillips37430132016-11-09 06:50:43 -0500108 sk_sp<GrSurfaceProxy> sProxy(make_wrapped_texture(provider, desc, SkBudgeted::kYes));
Robert Phillips84a81202016-11-04 11:59:10 -0400109
110 // Texture-only
Robert Phillips37430132016-11-09 06:50:43 -0500111 GrTextureProxy* tProxy = sProxy->asTextureProxy();
112 REPORTER_ASSERT(reporter, tProxy);
113 REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400114 REPORTER_ASSERT(reporter, !tProxy->asRenderTargetProxy());
115 }
116}
117
118// Test converting between RenderTargetProxies and TextureProxies for deferred
119// Proxies
120DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DefferredProxyConversionTest, reporter, ctxInfo) {
Brian Osman32342f02017-03-04 08:12:46 -0500121 GrResourceProvider* resourceProvider = ctxInfo.grContext()->resourceProvider();
Robert Phillips84a81202016-11-04 11:59:10 -0400122
123 GrSurfaceDesc desc;
124 desc.fFlags = kRenderTarget_GrSurfaceFlag;
125 desc.fWidth = 64;
126 desc.fHeight = 64;
127 desc.fConfig = kRGBA_8888_GrPixelConfig;
128
129 {
Robert Phillips26c90e02017-03-14 14:39:29 -0400130 sk_sp<GrTextureProxy> proxy(GrSurfaceProxy::MakeDeferred(resourceProvider, desc,
Robert Phillips2f493142017-03-02 18:18:38 -0500131 SkBackingFit::kApprox,
132 SkBudgeted::kYes));
Robert Phillips84a81202016-11-04 11:59:10 -0400133
134 // Both RenderTarget and Texture
Robert Phillips2f493142017-03-02 18:18:38 -0500135 GrRenderTargetProxy* rtProxy = proxy->asRenderTargetProxy();
Robert Phillips37430132016-11-09 06:50:43 -0500136 REPORTER_ASSERT(reporter, rtProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400137 GrTextureProxy* tProxy = rtProxy->asTextureProxy();
138 REPORTER_ASSERT(reporter, tProxy);
Robert Phillips37430132016-11-09 06:50:43 -0500139 REPORTER_ASSERT(reporter, tProxy->asRenderTargetProxy() == rtProxy);
140 REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400141 }
Robert Phillips26c90e02017-03-14 14:39:29 -0400142
Robert Phillips84a81202016-11-04 11:59:10 -0400143 {
Robert Phillips26c90e02017-03-14 14:39:29 -0400144 sk_sp<GrTextureProxy> proxy(GrSurfaceProxy::MakeDeferred(resourceProvider, desc,
Robert Phillips2f493142017-03-02 18:18:38 -0500145 SkBackingFit::kApprox,
146 SkBudgeted::kYes));
Robert Phillips84a81202016-11-04 11:59:10 -0400147
148 // Both RenderTarget and Texture - but via GrTextureProxy
Robert Phillips2f493142017-03-02 18:18:38 -0500149 GrTextureProxy* tProxy = proxy->asTextureProxy();
Robert Phillips37430132016-11-09 06:50:43 -0500150 REPORTER_ASSERT(reporter, tProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400151 GrRenderTargetProxy* rtProxy = tProxy->asRenderTargetProxy();
152 REPORTER_ASSERT(reporter, rtProxy);
Robert Phillips37430132016-11-09 06:50:43 -0500153 REPORTER_ASSERT(reporter, rtProxy->asTextureProxy() == tProxy);
154 REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400155 }
156
157 {
158 desc.fFlags = kNone_GrSurfaceFlags; // force no-RT
159
Robert Phillips26c90e02017-03-14 14:39:29 -0400160 sk_sp<GrTextureProxy> proxy(GrSurfaceProxy::MakeDeferred(resourceProvider, desc,
Robert Phillips2f493142017-03-02 18:18:38 -0500161 SkBackingFit::kApprox,
162 SkBudgeted::kYes));
Robert Phillips84a81202016-11-04 11:59:10 -0400163
164 // Texture-only
Robert Phillips2f493142017-03-02 18:18:38 -0500165 GrTextureProxy* tProxy = proxy->asTextureProxy();
Robert Phillips37430132016-11-09 06:50:43 -0500166 REPORTER_ASSERT(reporter, tProxy);
167 REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400168 REPORTER_ASSERT(reporter, !tProxy->asRenderTargetProxy());
169 }
170}
171#endif