blob: 7419feec14c5d3ceb4011c479dc81db9f734905d [file] [log] [blame]
robertphillips76948d42016-05-04 12:47:41 -07001/*
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
Greg Danielbcf612b2017-05-01 13:50:58 +000012#include "GrBackendSurface.h"
Robert Phillips1afd4cd2018-01-08 13:40:32 -050013#include "GrContextPriv.h"
Robert Phillips0bd24dc2018-01-16 08:06:32 -050014#include "GrProxyProvider.h"
Robert Phillipsc7635fa2016-10-28 13:25:24 -040015#include "GrRenderTargetPriv.h"
robertphillips76948d42016-05-04 12:47:41 -070016#include "GrRenderTargetProxy.h"
Brian Osman32342f02017-03-04 08:12:46 -050017#include "GrResourceProvider.h"
Robert Phillipsfe0253f2018-03-16 16:47:25 -040018#include "GrSurfacePriv.h"
Robert Phillipsf95b1752017-08-31 08:56:07 -040019#include "GrSurfaceProxyPriv.h"
Robert Phillips646e4292017-06-13 12:44:56 -040020#include "GrTexture.h"
Brian Osman32342f02017-03-04 08:12:46 -050021#include "GrTextureProxy.h"
Greg Daniel2a303902018-02-20 10:25:54 -050022#include "SkGr.h"
robertphillips76948d42016-05-04 12:47:41 -070023
robertphillips8abb3702016-08-31 14:04:06 -070024// Check that the surface proxy's member vars are set as expected
robertphillips76948d42016-05-04 12:47:41 -070025static void check_surface(skiatest::Reporter* reporter,
26 GrSurfaceProxy* proxy,
27 GrSurfaceOrigin origin,
Greg Danielbcf612b2017-05-01 13:50:58 +000028 int width, int height,
robertphillips8abb3702016-08-31 14:04:06 -070029 GrPixelConfig config,
Robert Phillipsabacf092016-11-02 10:23:32 -040030 SkBudgeted budgeted) {
robertphillips76948d42016-05-04 12:47:41 -070031 REPORTER_ASSERT(reporter, proxy->origin() == origin);
32 REPORTER_ASSERT(reporter, proxy->width() == width);
33 REPORTER_ASSERT(reporter, proxy->height() == height);
34 REPORTER_ASSERT(reporter, proxy->config() == config);
Robert Phillips0bd24dc2018-01-16 08:06:32 -050035 REPORTER_ASSERT(reporter, !proxy->uniqueID().isInvalid());
Robert Phillipsabacf092016-11-02 10:23:32 -040036 REPORTER_ASSERT(reporter, proxy->isBudgeted() == budgeted);
robertphillips76948d42016-05-04 12:47:41 -070037}
38
39static void check_rendertarget(skiatest::Reporter* reporter,
Robert Phillipsec2249f2016-11-09 08:54:35 -050040 const GrCaps& caps,
Brian Osman32342f02017-03-04 08:12:46 -050041 GrResourceProvider* provider,
robertphillips76948d42016-05-04 12:47:41 -070042 GrRenderTargetProxy* rtProxy,
Robert Phillipsabacf092016-11-02 10:23:32 -040043 int numSamples,
Robert Phillipsec2249f2016-11-09 08:54:35 -050044 SkBackingFit fit,
Greg Daniel2a303902018-02-20 10:25:54 -050045 int expectedMaxWindowRects) {
Robert Phillipsec2249f2016-11-09 08:54:35 -050046 REPORTER_ASSERT(reporter, rtProxy->maxWindowRectangles(caps) == expectedMaxWindowRects);
Robert Phillipsabacf092016-11-02 10:23:32 -040047 REPORTER_ASSERT(reporter, rtProxy->numStencilSamples() == numSamples);
48
Robert Phillips294870f2016-11-11 12:38:40 -050049 GrSurfaceProxy::UniqueID idBefore = rtProxy->uniqueID();
Brian Salomonfd98c2c2018-07-31 17:25:29 -040050 bool preinstantiated = rtProxy->isInstantiated();
Robert Phillipseee4d6e2017-06-05 09:26:07 -040051 REPORTER_ASSERT(reporter, rtProxy->instantiate(provider));
Brian Salomonfd98c2c2018-07-31 17:25:29 -040052 GrRenderTarget* rt = rtProxy->peekRenderTarget();
robertphillips76948d42016-05-04 12:47:41 -070053
Robert Phillips294870f2016-11-11 12:38:40 -050054 REPORTER_ASSERT(reporter, rtProxy->uniqueID() == idBefore);
Greg Daniel2a303902018-02-20 10:25:54 -050055 // Deferred resources should always have a different ID from their instantiated rendertarget
Brian Salomonf7778972018-03-08 10:13:17 -050056 if (preinstantiated) {
57 REPORTER_ASSERT(reporter, rtProxy->uniqueID().asUInt() == rt->uniqueID().asUInt());
58 } else {
59 REPORTER_ASSERT(reporter, rtProxy->uniqueID().asUInt() != rt->uniqueID().asUInt());
60 }
Robert Phillips294870f2016-11-11 12:38:40 -050061
robertphillips76948d42016-05-04 12:47:41 -070062 if (SkBackingFit::kExact == fit) {
63 REPORTER_ASSERT(reporter, rt->width() == rtProxy->width());
64 REPORTER_ASSERT(reporter, rt->height() == rtProxy->height());
65 } else {
66 REPORTER_ASSERT(reporter, rt->width() >= rtProxy->width());
Robert Phillips294870f2016-11-11 12:38:40 -050067 REPORTER_ASSERT(reporter, rt->height() >= rtProxy->height());
robertphillips76948d42016-05-04 12:47:41 -070068 }
69 REPORTER_ASSERT(reporter, rt->config() == rtProxy->config());
70
Brian Salomon7c8460e2017-05-12 11:36:10 -040071 REPORTER_ASSERT(reporter, rt->fsaaType() == rtProxy->fsaaType());
robertphillips76948d42016-05-04 12:47:41 -070072 REPORTER_ASSERT(reporter, rt->numColorSamples() == rtProxy->numColorSamples());
73 REPORTER_ASSERT(reporter, rt->numStencilSamples() == rtProxy->numStencilSamples());
Robert Phillipsfe0253f2018-03-16 16:47:25 -040074 REPORTER_ASSERT(reporter, rt->surfacePriv().flags() == rtProxy->testingOnly_getFlags());
robertphillips76948d42016-05-04 12:47:41 -070075}
76
77static void check_texture(skiatest::Reporter* reporter,
Brian Osman32342f02017-03-04 08:12:46 -050078 GrResourceProvider* provider,
robertphillips76948d42016-05-04 12:47:41 -070079 GrTextureProxy* texProxy,
Greg Daniel2a303902018-02-20 10:25:54 -050080 SkBackingFit fit) {
Robert Phillips294870f2016-11-11 12:38:40 -050081 GrSurfaceProxy::UniqueID idBefore = texProxy->uniqueID();
Robert Phillipseee4d6e2017-06-05 09:26:07 -040082
Brian Salomonfd98c2c2018-07-31 17:25:29 -040083 bool preinstantiated = texProxy->isInstantiated();
Robert Phillipseee4d6e2017-06-05 09:26:07 -040084 REPORTER_ASSERT(reporter, texProxy->instantiate(provider));
Brian Salomonfd98c2c2018-07-31 17:25:29 -040085 GrTexture* tex = texProxy->peekTexture();
robertphillips76948d42016-05-04 12:47:41 -070086
Robert Phillips294870f2016-11-11 12:38:40 -050087 REPORTER_ASSERT(reporter, texProxy->uniqueID() == idBefore);
Greg Daniel2a303902018-02-20 10:25:54 -050088 // Deferred resources should always have a different ID from their instantiated texture
Brian Salomonf7778972018-03-08 10:13:17 -050089 if (preinstantiated) {
90 REPORTER_ASSERT(reporter, texProxy->uniqueID().asUInt() == tex->uniqueID().asUInt());
91 } else {
92 REPORTER_ASSERT(reporter, texProxy->uniqueID().asUInt() != tex->uniqueID().asUInt());
93 }
Robert Phillips294870f2016-11-11 12:38:40 -050094
robertphillips76948d42016-05-04 12:47:41 -070095 if (SkBackingFit::kExact == fit) {
96 REPORTER_ASSERT(reporter, tex->width() == texProxy->width());
97 REPORTER_ASSERT(reporter, tex->height() == texProxy->height());
98 } else {
99 REPORTER_ASSERT(reporter, tex->width() >= texProxy->width());
100 REPORTER_ASSERT(reporter, tex->height() >= texProxy->height());
101 }
102 REPORTER_ASSERT(reporter, tex->config() == texProxy->config());
103}
104
105
robertphillips8abb3702016-08-31 14:04:06 -0700106DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DeferredProxyTest, reporter, ctxInfo) {
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500107 GrProxyProvider* proxyProvider = ctxInfo.grContext()->contextPriv().proxyProvider();
Robert Phillips6be756b2018-01-16 15:07:54 -0500108 GrResourceProvider* resourceProvider = ctxInfo.grContext()->contextPriv().resourceProvider();
Brian Salomonc7fe0f72018-05-11 10:14:21 -0400109 const GrCaps& caps = *ctxInfo.grContext()->contextPriv().caps();
robertphillips76948d42016-05-04 12:47:41 -0700110
Robert Phillips6520a692017-02-01 09:20:00 -0500111 int attempt = 0; // useful for debugging
112
robertphillips76948d42016-05-04 12:47:41 -0700113 for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin }) {
Robert Phillips40d94952017-01-30 14:15:59 -0500114 for (auto widthHeight : { 100, 128, 1048576 }) {
Robert Phillips6520a692017-02-01 09:20:00 -0500115 for (auto config : { kAlpha_8_GrPixelConfig, kRGB_565_GrPixelConfig,
Jim Van Verth1676cb92019-01-15 13:24:45 -0500116 kRGBA_8888_GrPixelConfig, kRGBA_1010102_GrPixelConfig,
117 kRGB_ETC1_GrPixelConfig }) {
robertphillips76948d42016-05-04 12:47:41 -0700118 for (auto fit : { SkBackingFit::kExact, SkBackingFit::kApprox }) {
119 for (auto budgeted : { SkBudgeted::kYes, SkBudgeted::kNo }) {
Brian Salomonbdecacf2018-02-02 20:32:49 -0500120 for (auto numSamples : {1, 4, 16, 128}) {
Jim Van Verth1676cb92019-01-15 13:24:45 -0500121 // We don't have recycling support for compressed textures
122 if (GrPixelConfigIsCompressed(config) && SkBackingFit::kApprox == fit) {
123 continue;
124 }
125
robertphillips76948d42016-05-04 12:47:41 -0700126 GrSurfaceDesc desc;
Robert Phillips84a81202016-11-04 11:59:10 -0400127 desc.fFlags = kRenderTarget_GrSurfaceFlag;
robertphillips76948d42016-05-04 12:47:41 -0700128 desc.fWidth = widthHeight;
129 desc.fHeight = widthHeight;
130 desc.fConfig = config;
131 desc.fSampleCnt = numSamples;
132
Greg Daniel4065d452018-11-16 15:43:41 -0500133 GrSRGBEncoded srgbEncoded;
134 GrColorType colorType =
135 GrPixelConfigToColorTypeAndEncoding(config, &srgbEncoded);
136 const GrBackendFormat format =
137 caps.getBackendFormatFromGrColorType(colorType, srgbEncoded);
138
Robert Phillips6520a692017-02-01 09:20:00 -0500139 {
140 sk_sp<GrTexture> tex;
141 if (SkBackingFit::kApprox == fit) {
Chris Daltond004e0b2018-09-27 09:28:03 -0600142 tex = resourceProvider->createApproxTexture(
143 desc, GrResourceProvider::Flags::kNone);
Robert Phillips6520a692017-02-01 09:20:00 -0500144 } else {
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500145 tex = resourceProvider->createTexture(desc, budgeted);
Robert Phillips6520a692017-02-01 09:20:00 -0500146 }
147
Brian Salomon2a4f9832018-03-03 22:43:43 -0500148 sk_sp<GrTextureProxy> proxy =
Greg Daniel4065d452018-11-16 15:43:41 -0500149 proxyProvider->createProxy(format, desc, origin, fit,
150 budgeted);
Robert Phillips2f493142017-03-02 18:18:38 -0500151 REPORTER_ASSERT(reporter, SkToBool(tex) == SkToBool(proxy));
152 if (proxy) {
153 REPORTER_ASSERT(reporter, proxy->asRenderTargetProxy());
Robert Phillips40d94952017-01-30 14:15:59 -0500154 // This forces the proxy to compute and cache its
155 // pre-instantiation size guess. Later, when it is actually
156 // instantiated, it checks that the instantiated size is <= to
157 // the pre-computation. If the proxy never computed its
158 // pre-instantiation size then the check is skipped.
Robert Phillips2f493142017-03-02 18:18:38 -0500159 proxy->gpuMemorySize();
Robert Phillipsb4460882016-11-17 14:43:51 -0500160
Robert Phillips2f493142017-03-02 18:18:38 -0500161 check_surface(reporter, proxy.get(), origin,
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500162 widthHeight, widthHeight, config, budgeted);
Brian Salomonbdecacf2018-02-02 20:32:49 -0500163 int supportedSamples =
164 caps.getRenderTargetSampleCount(numSamples, config);
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500165 check_rendertarget(reporter, caps, resourceProvider,
Robert Phillips2f493142017-03-02 18:18:38 -0500166 proxy->asRenderTargetProxy(),
Greg Daniel81e7bf82017-07-19 14:47:42 -0400167 supportedSamples,
Greg Daniel2a303902018-02-20 10:25:54 -0500168 fit, caps.maxWindowRectangles());
Robert Phillips40d94952017-01-30 14:15:59 -0500169 }
robertphillips76948d42016-05-04 12:47:41 -0700170 }
171
Robert Phillips84a81202016-11-04 11:59:10 -0400172 desc.fFlags = kNone_GrSurfaceFlags;
robertphillips76948d42016-05-04 12:47:41 -0700173
Robert Phillips6520a692017-02-01 09:20:00 -0500174 {
175 sk_sp<GrTexture> tex;
176 if (SkBackingFit::kApprox == fit) {
Chris Daltond004e0b2018-09-27 09:28:03 -0600177 tex = resourceProvider->createApproxTexture(
178 desc, GrResourceProvider::Flags::kNone);
Robert Phillips6520a692017-02-01 09:20:00 -0500179 } else {
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500180 tex = resourceProvider->createTexture(desc, budgeted);
Robert Phillips6520a692017-02-01 09:20:00 -0500181 }
Robert Phillipsb4460882016-11-17 14:43:51 -0500182
Brian Salomon2a4f9832018-03-03 22:43:43 -0500183 sk_sp<GrTextureProxy> proxy(
Greg Daniel4065d452018-11-16 15:43:41 -0500184 proxyProvider->createProxy(format, desc, origin, fit,
185 budgeted));
Robert Phillips2f493142017-03-02 18:18:38 -0500186 REPORTER_ASSERT(reporter, SkToBool(tex) == SkToBool(proxy));
187 if (proxy) {
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500188 // This forces the proxy to compute and cache its
189 // pre-instantiation size guess. Later, when it is actually
190 // instantiated, it checks that the instantiated size is <= to
191 // the pre-computation. If the proxy never computed its
192 // pre-instantiation size then the check is skipped.
Robert Phillips2f493142017-03-02 18:18:38 -0500193 proxy->gpuMemorySize();
Robert Phillips6520a692017-02-01 09:20:00 -0500194
Robert Phillips2f493142017-03-02 18:18:38 -0500195 check_surface(reporter, proxy.get(), origin,
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500196 widthHeight, widthHeight, config, budgeted);
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500197 check_texture(reporter, resourceProvider,
Greg Daniel2a303902018-02-20 10:25:54 -0500198 proxy->asTextureProxy(), fit);
Robert Phillips6520a692017-02-01 09:20:00 -0500199 }
Robert Phillips40d94952017-01-30 14:15:59 -0500200 }
Robert Phillips6520a692017-02-01 09:20:00 -0500201
202 attempt++;
robertphillips76948d42016-05-04 12:47:41 -0700203 }
204 }
205 }
206 }
207 }
208 }
209}
210
egdanielab527a52016-06-28 08:07:26 -0700211DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WrappedProxyTest, reporter, ctxInfo) {
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500212 GrProxyProvider* proxyProvider = ctxInfo.grContext()->contextPriv().proxyProvider();
Robert Phillips6be756b2018-01-16 15:07:54 -0500213 GrResourceProvider* resourceProvider = ctxInfo.grContext()->contextPriv().resourceProvider();
Greg Daniel2a303902018-02-20 10:25:54 -0500214 GrGpu* gpu = ctxInfo.grContext()->contextPriv().getGpu();
Brian Salomonc7fe0f72018-05-11 10:14:21 -0400215 const GrCaps& caps = *ctxInfo.grContext()->contextPriv().caps();
robertphillips76948d42016-05-04 12:47:41 -0700216
217 static const int kWidthHeight = 100;
218
219 for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin }) {
Brian Osman10fc6fd2018-03-02 11:01:10 -0500220 for (auto colorType : { kAlpha_8_SkColorType, kRGBA_8888_SkColorType,
221 kRGBA_1010102_SkColorType }) {
Brian Salomon52e943a2018-03-13 09:32:39 -0400222 // External on-screen render target.
223 // Tests wrapBackendRenderTarget with a GrBackendRenderTarget
224 // Our test-only function that creates a backend render target doesn't currently support
225 // sample counts :(.
226 if (ctxInfo.grContext()->colorTypeSupportedAsSurface(colorType)) {
227 GrBackendRenderTarget backendRT = gpu->createTestingOnlyBackendRenderTarget(
Brian Osman2d010b62018-08-09 10:55:09 -0400228 kWidthHeight, kWidthHeight, SkColorTypeToGrColorType(colorType));
Brian Salomon52e943a2018-03-13 09:32:39 -0400229 sk_sp<GrSurfaceProxy> sProxy(
230 proxyProvider->wrapBackendRenderTarget(backendRT, origin));
231 check_surface(reporter, sProxy.get(), origin, kWidthHeight, kWidthHeight,
Greg Daniel108bb232018-07-03 16:18:29 -0400232 backendRT.pixelConfig(), SkBudgeted::kNo);
Brian Salomon52e943a2018-03-13 09:32:39 -0400233 static constexpr int kExpectedNumSamples = 1;
234 check_rendertarget(reporter, caps, resourceProvider, sProxy->asRenderTargetProxy(),
235 kExpectedNumSamples, SkBackingFit::kExact,
236 caps.maxWindowRectangles());
237 gpu->deleteTestingOnlyBackendRenderTarget(backendRT);
238 }
239
Greg Daniel2a303902018-02-20 10:25:54 -0500240 for (auto numSamples : {1, 4}) {
Brian Osman2b23c4b2018-06-01 12:25:08 -0400241 GrPixelConfig config = SkColorType2GrPixelConfig(colorType);
Greg Daniel0a7aa142018-02-21 13:02:32 -0500242 SkASSERT(kUnknown_GrPixelConfig != config);
Greg Daniel2a303902018-02-20 10:25:54 -0500243 int supportedNumSamples = caps.getRenderTargetSampleCount(numSamples, config);
robertphillips76948d42016-05-04 12:47:41 -0700244
Greg Daniel2a303902018-02-20 10:25:54 -0500245 if (!supportedNumSamples) {
246 continue;
247 }
robertphillips76948d42016-05-04 12:47:41 -0700248
Brian Salomon52e943a2018-03-13 09:32:39 -0400249 // Test wrapping FBO 0 (with made up properties). This tests sample count and the
250 // special case where FBO 0 doesn't support window rectangles.
Greg Danielbdf12ad2018-10-12 09:31:11 -0400251 if (GrBackendApi::kOpenGL == ctxInfo.backend()) {
Greg Daniel2a303902018-02-20 10:25:54 -0500252 GrGLFramebufferInfo fboInfo;
253 fboInfo.fFBOID = 0;
Brian Salomon52e943a2018-03-13 09:32:39 -0400254 static constexpr int kStencilBits = 8;
255 GrBackendRenderTarget backendRT(kWidthHeight, kWidthHeight, numSamples,
Greg Daniel108bb232018-07-03 16:18:29 -0400256 kStencilBits, fboInfo);
257 backendRT.setPixelConfig(config);
Brian Salomon7578f3e2018-03-07 14:39:54 -0500258 sk_sp<GrSurfaceProxy> sProxy(
259 proxyProvider->wrapBackendRenderTarget(backendRT, origin));
Greg Daniel2a303902018-02-20 10:25:54 -0500260 check_surface(reporter, sProxy.get(), origin,
261 kWidthHeight, kWidthHeight,
Greg Daniel108bb232018-07-03 16:18:29 -0400262 backendRT.pixelConfig(), SkBudgeted::kNo);
Greg Daniel2a303902018-02-20 10:25:54 -0500263 check_rendertarget(reporter, caps, resourceProvider,
264 sProxy->asRenderTargetProxy(),
265 supportedNumSamples, SkBackingFit::kExact, 0);
266 }
267
Brian Salomon7578f3e2018-03-07 14:39:54 -0500268 // Tests wrapBackendRenderTarget with a GrBackendTexture
Greg Daniel2a303902018-02-20 10:25:54 -0500269 {
270 GrBackendTexture backendTex =
271 gpu->createTestingOnlyBackendTexture(nullptr, kWidthHeight,
Brian Osman2b23c4b2018-06-01 12:25:08 -0400272 kWidthHeight, colorType,
Greg Daniel57bf4a32018-04-19 10:28:37 -0400273 true, GrMipMapped::kNo);
Brian Salomon7578f3e2018-03-07 14:39:54 -0500274 sk_sp<GrSurfaceProxy> sProxy = proxyProvider->wrapBackendTextureAsRenderTarget(
275 backendTex, origin, supportedNumSamples);
Greg Daniel2a303902018-02-20 10:25:54 -0500276 if (!sProxy) {
Brian Salomon26102cb2018-03-09 09:33:19 -0500277 gpu->deleteTestingOnlyBackendTexture(backendTex);
Greg Daniel2a303902018-02-20 10:25:54 -0500278 continue; // This can fail on Mesa
csmartdaltonf9635992016-08-10 11:09:07 -0700279 }
280
Greg Daniel2a303902018-02-20 10:25:54 -0500281 check_surface(reporter, sProxy.get(), origin,
282 kWidthHeight, kWidthHeight,
Greg Daniel108bb232018-07-03 16:18:29 -0400283 backendTex.pixelConfig(), SkBudgeted::kNo);
Greg Daniel2a303902018-02-20 10:25:54 -0500284 check_rendertarget(reporter, caps, resourceProvider,
285 sProxy->asRenderTargetProxy(),
286 supportedNumSamples, SkBackingFit::kExact,
287 caps.maxWindowRectangles());
robertphillips76948d42016-05-04 12:47:41 -0700288
Brian Salomon26102cb2018-03-09 09:33:19 -0500289 gpu->deleteTestingOnlyBackendTexture(backendTex);
Greg Daniel2a303902018-02-20 10:25:54 -0500290 }
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500291
Brian Salomon7578f3e2018-03-07 14:39:54 -0500292 // Tests wrapBackendTexture that is only renderable
Greg Danielf87651e2018-02-21 11:36:53 -0500293 {
294 GrBackendTexture backendTex =
295 gpu->createTestingOnlyBackendTexture(nullptr, kWidthHeight,
Brian Osman2b23c4b2018-06-01 12:25:08 -0400296 kWidthHeight, colorType,
Greg Daniel57bf4a32018-04-19 10:28:37 -0400297 true, GrMipMapped::kNo);
Greg Danielf87651e2018-02-21 11:36:53 -0500298
Brian Salomon7578f3e2018-03-07 14:39:54 -0500299 sk_sp<GrSurfaceProxy> sProxy = proxyProvider->wrapRenderableBackendTexture(
Brian Salomonaa6ca0a2019-01-24 16:03:07 -0500300 backendTex, origin, supportedNumSamples, kBorrow_GrWrapOwnership,
301 GrWrapCacheable::kNo);
Greg Danielf87651e2018-02-21 11:36:53 -0500302 if (!sProxy) {
Brian Salomon26102cb2018-03-09 09:33:19 -0500303 gpu->deleteTestingOnlyBackendTexture(backendTex);
Greg Danielf87651e2018-02-21 11:36:53 -0500304 continue; // This can fail on Mesa
305 }
306
307 check_surface(reporter, sProxy.get(), origin,
308 kWidthHeight, kWidthHeight,
Greg Daniel108bb232018-07-03 16:18:29 -0400309 backendTex.pixelConfig(), SkBudgeted::kNo);
Greg Danielf87651e2018-02-21 11:36:53 -0500310 check_rendertarget(reporter, caps, resourceProvider,
311 sProxy->asRenderTargetProxy(),
312 supportedNumSamples, SkBackingFit::kExact,
313 caps.maxWindowRectangles());
314
Brian Salomon26102cb2018-03-09 09:33:19 -0500315 gpu->deleteTestingOnlyBackendTexture(backendTex);
Greg Danielf87651e2018-02-21 11:36:53 -0500316 }
317
Brian Salomon7578f3e2018-03-07 14:39:54 -0500318 // Tests wrapBackendTexture that is only textureable
Greg Daniel2a303902018-02-20 10:25:54 -0500319 {
320 // Internal offscreen texture
321 GrBackendTexture backendTex =
322 gpu->createTestingOnlyBackendTexture(nullptr, kWidthHeight,
Brian Osman2b23c4b2018-06-01 12:25:08 -0400323 kWidthHeight, colorType,
Greg Daniel57bf4a32018-04-19 10:28:37 -0400324 false, GrMipMapped::kNo);
robertphillips76948d42016-05-04 12:47:41 -0700325
Brian Salomon7578f3e2018-03-07 14:39:54 -0500326 sk_sp<GrSurfaceProxy> sProxy = proxyProvider->wrapBackendTexture(
Brian Salomonaa6ca0a2019-01-24 16:03:07 -0500327 backendTex, origin, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo,
328 kRead_GrIOType);
Greg Daniel2a303902018-02-20 10:25:54 -0500329 if (!sProxy) {
Brian Salomon26102cb2018-03-09 09:33:19 -0500330 gpu->deleteTestingOnlyBackendTexture(backendTex);
Greg Daniel2a303902018-02-20 10:25:54 -0500331 continue;
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500332 }
Greg Daniel2a303902018-02-20 10:25:54 -0500333
334 check_surface(reporter, sProxy.get(), origin,
335 kWidthHeight, kWidthHeight,
Greg Daniel108bb232018-07-03 16:18:29 -0400336 backendTex.pixelConfig(), SkBudgeted::kNo);
Greg Daniel2a303902018-02-20 10:25:54 -0500337 check_texture(reporter, resourceProvider, sProxy->asTextureProxy(),
338 SkBackingFit::kExact);
339
Brian Salomon26102cb2018-03-09 09:33:19 -0500340 gpu->deleteTestingOnlyBackendTexture(backendTex);
robertphillips76948d42016-05-04 12:47:41 -0700341 }
342 }
343 }
344 }
345}
346
Robert Phillips78de2122017-04-26 07:44:26 -0400347DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ZeroSizedProxyTest, reporter, ctxInfo) {
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500348 GrProxyProvider* provider = ctxInfo.grContext()->contextPriv().proxyProvider();
Robert Phillips78de2122017-04-26 07:44:26 -0400349
350 for (auto flags : { kRenderTarget_GrSurfaceFlag, kNone_GrSurfaceFlags }) {
351 for (auto fit : { SkBackingFit::kExact, SkBackingFit::kApprox }) {
352 for (int width : { 0, 100 }) {
353 for (int height : { 0, 100}) {
354 if (width && height) {
355 continue; // not zero-sized
356 }
357
358 GrSurfaceDesc desc;
359 desc.fFlags = flags;
Robert Phillips78de2122017-04-26 07:44:26 -0400360 desc.fWidth = width;
361 desc.fHeight = height;
362 desc.fConfig = kRGBA_8888_GrPixelConfig;
Brian Salomonbdecacf2018-02-02 20:32:49 -0500363 desc.fSampleCnt = 1;
Robert Phillips78de2122017-04-26 07:44:26 -0400364
Greg Daniel4065d452018-11-16 15:43:41 -0500365 const GrBackendFormat format =
366 ctxInfo.grContext()->contextPriv().caps()->getBackendFormatFromColorType(
367 kRGBA_8888_SkColorType);
368
Brian Salomon2a4f9832018-03-03 22:43:43 -0500369 sk_sp<GrTextureProxy> proxy = provider->createProxy(
Greg Daniel4065d452018-11-16 15:43:41 -0500370 format, desc, kBottomLeft_GrSurfaceOrigin, fit, SkBudgeted::kNo);
Robert Phillips78de2122017-04-26 07:44:26 -0400371 REPORTER_ASSERT(reporter, !proxy);
372 }
373 }
374 }
375 }
376}