blob: 2a6222cf9b908e2302f7c77438a60c186345d711 [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 Phillipsb0e93a22017-08-29 08:26:54 -040029 sk_sp<GrRenderTarget> defaultFBO(provider->wrapBackendRenderTarget(backendRT));
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;
Robert Phillips16d8ec62017-07-27 16:16:25 -0400125 desc.fOrigin = kBottomLeft_GrSurfaceOrigin;
Robert Phillips84a81202016-11-04 11:59:10 -0400126 desc.fWidth = 64;
127 desc.fHeight = 64;
128 desc.fConfig = kRGBA_8888_GrPixelConfig;
129
130 {
Robert Phillips26c90e02017-03-14 14:39:29 -0400131 sk_sp<GrTextureProxy> proxy(GrSurfaceProxy::MakeDeferred(resourceProvider, desc,
Robert Phillips2f493142017-03-02 18:18:38 -0500132 SkBackingFit::kApprox,
133 SkBudgeted::kYes));
Robert Phillips84a81202016-11-04 11:59:10 -0400134
135 // Both RenderTarget and Texture
Robert Phillips2f493142017-03-02 18:18:38 -0500136 GrRenderTargetProxy* rtProxy = proxy->asRenderTargetProxy();
Robert Phillips37430132016-11-09 06:50:43 -0500137 REPORTER_ASSERT(reporter, rtProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400138 GrTextureProxy* tProxy = rtProxy->asTextureProxy();
139 REPORTER_ASSERT(reporter, tProxy);
Robert Phillips37430132016-11-09 06:50:43 -0500140 REPORTER_ASSERT(reporter, tProxy->asRenderTargetProxy() == rtProxy);
141 REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400142 }
Robert Phillips26c90e02017-03-14 14:39:29 -0400143
Robert Phillips84a81202016-11-04 11:59:10 -0400144 {
Robert Phillips26c90e02017-03-14 14:39:29 -0400145 sk_sp<GrTextureProxy> proxy(GrSurfaceProxy::MakeDeferred(resourceProvider, desc,
Robert Phillips2f493142017-03-02 18:18:38 -0500146 SkBackingFit::kApprox,
147 SkBudgeted::kYes));
Robert Phillips84a81202016-11-04 11:59:10 -0400148
149 // Both RenderTarget and Texture - but via GrTextureProxy
Robert Phillips2f493142017-03-02 18:18:38 -0500150 GrTextureProxy* tProxy = proxy->asTextureProxy();
Robert Phillips37430132016-11-09 06:50:43 -0500151 REPORTER_ASSERT(reporter, tProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400152 GrRenderTargetProxy* rtProxy = tProxy->asRenderTargetProxy();
153 REPORTER_ASSERT(reporter, rtProxy);
Robert Phillips37430132016-11-09 06:50:43 -0500154 REPORTER_ASSERT(reporter, rtProxy->asTextureProxy() == tProxy);
155 REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400156 }
157
158 {
159 desc.fFlags = kNone_GrSurfaceFlags; // force no-RT
Robert Phillips16d8ec62017-07-27 16:16:25 -0400160 desc.fOrigin = kTopLeft_GrSurfaceOrigin;
Robert Phillips84a81202016-11-04 11:59:10 -0400161
Robert Phillips26c90e02017-03-14 14:39:29 -0400162 sk_sp<GrTextureProxy> proxy(GrSurfaceProxy::MakeDeferred(resourceProvider, desc,
Robert Phillips2f493142017-03-02 18:18:38 -0500163 SkBackingFit::kApprox,
164 SkBudgeted::kYes));
Robert Phillips84a81202016-11-04 11:59:10 -0400165
166 // Texture-only
Robert Phillips2f493142017-03-02 18:18:38 -0500167 GrTextureProxy* tProxy = proxy->asTextureProxy();
Robert Phillips37430132016-11-09 06:50:43 -0500168 REPORTER_ASSERT(reporter, tProxy);
169 REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400170 REPORTER_ASSERT(reporter, !tProxy->asRenderTargetProxy());
171 }
172}
173#endif