blob: bd646e8533ac72e6f70c7bc02ae3c4091a3797a0 [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#include "tests/Test.h"
robertphillips76948d42016-05-04 12:47:41 -070011
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#include "include/gpu/GrBackendSurface.h"
13#include "include/gpu/GrTexture.h"
14#include "include/private/GrRenderTargetProxy.h"
15#include "include/private/GrTextureProxy.h"
16#include "src/gpu/GrContextPriv.h"
17#include "src/gpu/GrProxyProvider.h"
18#include "src/gpu/GrRenderTargetPriv.h"
19#include "src/gpu/GrResourceProvider.h"
20#include "src/gpu/GrSurfacePriv.h"
21#include "src/gpu/GrSurfaceProxyPriv.h"
22#include "src/gpu/SkGr.h"
23#include "src/gpu/gl/GrGLDefines.h"
robertphillips76948d42016-05-04 12:47:41 -070024
robertphillips8abb3702016-08-31 14:04:06 -070025// Check that the surface proxy's member vars are set as expected
robertphillips76948d42016-05-04 12:47:41 -070026static void check_surface(skiatest::Reporter* reporter,
27 GrSurfaceProxy* proxy,
28 GrSurfaceOrigin origin,
Greg Danielbcf612b2017-05-01 13:50:58 +000029 int width, int height,
robertphillips8abb3702016-08-31 14:04:06 -070030 GrPixelConfig config,
Robert Phillipsabacf092016-11-02 10:23:32 -040031 SkBudgeted budgeted) {
robertphillips76948d42016-05-04 12:47:41 -070032 REPORTER_ASSERT(reporter, proxy->origin() == origin);
33 REPORTER_ASSERT(reporter, proxy->width() == width);
34 REPORTER_ASSERT(reporter, proxy->height() == height);
35 REPORTER_ASSERT(reporter, proxy->config() == config);
Robert Phillips0bd24dc2018-01-16 08:06:32 -050036 REPORTER_ASSERT(reporter, !proxy->uniqueID().isInvalid());
Robert Phillipsabacf092016-11-02 10:23:32 -040037 REPORTER_ASSERT(reporter, proxy->isBudgeted() == budgeted);
robertphillips76948d42016-05-04 12:47:41 -070038}
39
40static void check_rendertarget(skiatest::Reporter* reporter,
Robert Phillipsec2249f2016-11-09 08:54:35 -050041 const GrCaps& caps,
Brian Osman32342f02017-03-04 08:12:46 -050042 GrResourceProvider* provider,
robertphillips76948d42016-05-04 12:47:41 -070043 GrRenderTargetProxy* rtProxy,
Robert Phillipsabacf092016-11-02 10:23:32 -040044 int numSamples,
Robert Phillipsec2249f2016-11-09 08:54:35 -050045 SkBackingFit fit,
Greg Daniel2a303902018-02-20 10:25:54 -050046 int expectedMaxWindowRects) {
Robert Phillipsec2249f2016-11-09 08:54:35 -050047 REPORTER_ASSERT(reporter, rtProxy->maxWindowRectangles(caps) == expectedMaxWindowRects);
Robert Phillipsabacf092016-11-02 10:23:32 -040048 REPORTER_ASSERT(reporter, rtProxy->numStencilSamples() == numSamples);
49
Robert Phillips294870f2016-11-11 12:38:40 -050050 GrSurfaceProxy::UniqueID idBefore = rtProxy->uniqueID();
Brian Salomonfd98c2c2018-07-31 17:25:29 -040051 bool preinstantiated = rtProxy->isInstantiated();
Robert Phillipseee4d6e2017-06-05 09:26:07 -040052 REPORTER_ASSERT(reporter, rtProxy->instantiate(provider));
Brian Salomonfd98c2c2018-07-31 17:25:29 -040053 GrRenderTarget* rt = rtProxy->peekRenderTarget();
robertphillips76948d42016-05-04 12:47:41 -070054
Robert Phillips294870f2016-11-11 12:38:40 -050055 REPORTER_ASSERT(reporter, rtProxy->uniqueID() == idBefore);
Greg Daniel2a303902018-02-20 10:25:54 -050056 // Deferred resources should always have a different ID from their instantiated rendertarget
Brian Salomonf7778972018-03-08 10:13:17 -050057 if (preinstantiated) {
58 REPORTER_ASSERT(reporter, rtProxy->uniqueID().asUInt() == rt->uniqueID().asUInt());
59 } else {
60 REPORTER_ASSERT(reporter, rtProxy->uniqueID().asUInt() != rt->uniqueID().asUInt());
61 }
Robert Phillips294870f2016-11-11 12:38:40 -050062
robertphillips76948d42016-05-04 12:47:41 -070063 if (SkBackingFit::kExact == fit) {
64 REPORTER_ASSERT(reporter, rt->width() == rtProxy->width());
65 REPORTER_ASSERT(reporter, rt->height() == rtProxy->height());
66 } else {
67 REPORTER_ASSERT(reporter, rt->width() >= rtProxy->width());
Robert Phillips294870f2016-11-11 12:38:40 -050068 REPORTER_ASSERT(reporter, rt->height() >= rtProxy->height());
robertphillips76948d42016-05-04 12:47:41 -070069 }
70 REPORTER_ASSERT(reporter, rt->config() == rtProxy->config());
71
Brian Salomon7c8460e2017-05-12 11:36:10 -040072 REPORTER_ASSERT(reporter, rt->fsaaType() == rtProxy->fsaaType());
robertphillips76948d42016-05-04 12:47:41 -070073 REPORTER_ASSERT(reporter, rt->numColorSamples() == rtProxy->numColorSamples());
74 REPORTER_ASSERT(reporter, rt->numStencilSamples() == rtProxy->numStencilSamples());
Robert Phillipsfe0253f2018-03-16 16:47:25 -040075 REPORTER_ASSERT(reporter, rt->surfacePriv().flags() == rtProxy->testingOnly_getFlags());
robertphillips76948d42016-05-04 12:47:41 -070076}
77
78static void check_texture(skiatest::Reporter* reporter,
Brian Osman32342f02017-03-04 08:12:46 -050079 GrResourceProvider* provider,
robertphillips76948d42016-05-04 12:47:41 -070080 GrTextureProxy* texProxy,
Greg Daniel2a303902018-02-20 10:25:54 -050081 SkBackingFit fit) {
Robert Phillips294870f2016-11-11 12:38:40 -050082 GrSurfaceProxy::UniqueID idBefore = texProxy->uniqueID();
Robert Phillipseee4d6e2017-06-05 09:26:07 -040083
Brian Salomonfd98c2c2018-07-31 17:25:29 -040084 bool preinstantiated = texProxy->isInstantiated();
Robert Phillipseee4d6e2017-06-05 09:26:07 -040085 REPORTER_ASSERT(reporter, texProxy->instantiate(provider));
Brian Salomonfd98c2c2018-07-31 17:25:29 -040086 GrTexture* tex = texProxy->peekTexture();
robertphillips76948d42016-05-04 12:47:41 -070087
Robert Phillips294870f2016-11-11 12:38:40 -050088 REPORTER_ASSERT(reporter, texProxy->uniqueID() == idBefore);
Greg Daniel2a303902018-02-20 10:25:54 -050089 // Deferred resources should always have a different ID from their instantiated texture
Brian Salomonf7778972018-03-08 10:13:17 -050090 if (preinstantiated) {
91 REPORTER_ASSERT(reporter, texProxy->uniqueID().asUInt() == tex->uniqueID().asUInt());
92 } else {
93 REPORTER_ASSERT(reporter, texProxy->uniqueID().asUInt() != tex->uniqueID().asUInt());
94 }
Robert Phillips294870f2016-11-11 12:38:40 -050095
robertphillips76948d42016-05-04 12:47:41 -070096 if (SkBackingFit::kExact == fit) {
97 REPORTER_ASSERT(reporter, tex->width() == texProxy->width());
98 REPORTER_ASSERT(reporter, tex->height() == texProxy->height());
99 } else {
100 REPORTER_ASSERT(reporter, tex->width() >= texProxy->width());
101 REPORTER_ASSERT(reporter, tex->height() >= texProxy->height());
102 }
103 REPORTER_ASSERT(reporter, tex->config() == texProxy->config());
104}
105
106
robertphillips8abb3702016-08-31 14:04:06 -0700107DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DeferredProxyTest, reporter, ctxInfo) {
Robert Phillips9da87e02019-02-04 13:26:26 -0500108 GrProxyProvider* proxyProvider = ctxInfo.grContext()->priv().proxyProvider();
109 GrResourceProvider* resourceProvider = ctxInfo.grContext()->priv().resourceProvider();
110 const GrCaps& caps = *ctxInfo.grContext()->priv().caps();
robertphillips76948d42016-05-04 12:47:41 -0700111
Robert Phillips6520a692017-02-01 09:20:00 -0500112 int attempt = 0; // useful for debugging
113
robertphillips76948d42016-05-04 12:47:41 -0700114 for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin }) {
Robert Phillips40d94952017-01-30 14:15:59 -0500115 for (auto widthHeight : { 100, 128, 1048576 }) {
Robert Phillips6520a692017-02-01 09:20:00 -0500116 for (auto config : { kAlpha_8_GrPixelConfig, kRGB_565_GrPixelConfig,
Jim Van Verth1676cb92019-01-15 13:24:45 -0500117 kRGBA_8888_GrPixelConfig, kRGBA_1010102_GrPixelConfig,
118 kRGB_ETC1_GrPixelConfig }) {
robertphillips76948d42016-05-04 12:47:41 -0700119 for (auto fit : { SkBackingFit::kExact, SkBackingFit::kApprox }) {
120 for (auto budgeted : { SkBudgeted::kYes, SkBudgeted::kNo }) {
Brian Salomonbdecacf2018-02-02 20:32:49 -0500121 for (auto numSamples : {1, 4, 16, 128}) {
Jim Van Verth1676cb92019-01-15 13:24:45 -0500122 // We don't have recycling support for compressed textures
123 if (GrPixelConfigIsCompressed(config) && SkBackingFit::kApprox == fit) {
124 continue;
125 }
126
robertphillips76948d42016-05-04 12:47:41 -0700127 GrSurfaceDesc desc;
Robert Phillips84a81202016-11-04 11:59:10 -0400128 desc.fFlags = kRenderTarget_GrSurfaceFlag;
robertphillips76948d42016-05-04 12:47:41 -0700129 desc.fWidth = widthHeight;
130 desc.fHeight = widthHeight;
131 desc.fConfig = config;
132 desc.fSampleCnt = numSamples;
133
Greg Daniel4065d452018-11-16 15:43:41 -0500134 GrSRGBEncoded srgbEncoded;
135 GrColorType colorType =
136 GrPixelConfigToColorTypeAndEncoding(config, &srgbEncoded);
137 const GrBackendFormat format =
138 caps.getBackendFormatFromGrColorType(colorType, srgbEncoded);
139
Robert Phillips6520a692017-02-01 09:20:00 -0500140 {
141 sk_sp<GrTexture> tex;
142 if (SkBackingFit::kApprox == fit) {
Chris Daltond004e0b2018-09-27 09:28:03 -0600143 tex = resourceProvider->createApproxTexture(
Robert Phillips7eeb74f2019-03-29 07:26:46 -0400144 desc, GrResourceProvider::Flags::kNoPendingIO);
Robert Phillips6520a692017-02-01 09:20:00 -0500145 } else {
Robert Phillips9313aa72019-04-09 18:41:27 -0400146 tex = resourceProvider->createTexture(
147 desc, budgeted, GrResourceProvider::Flags::kNoPendingIO);
Robert Phillips6520a692017-02-01 09:20:00 -0500148 }
149
Brian Salomon2a4f9832018-03-03 22:43:43 -0500150 sk_sp<GrTextureProxy> proxy =
Greg Daniel4065d452018-11-16 15:43:41 -0500151 proxyProvider->createProxy(format, desc, origin, fit,
152 budgeted);
Robert Phillips2f493142017-03-02 18:18:38 -0500153 REPORTER_ASSERT(reporter, SkToBool(tex) == SkToBool(proxy));
154 if (proxy) {
155 REPORTER_ASSERT(reporter, proxy->asRenderTargetProxy());
Robert Phillips40d94952017-01-30 14:15:59 -0500156 // This forces the proxy to compute and cache its
157 // pre-instantiation size guess. Later, when it is actually
158 // instantiated, it checks that the instantiated size is <= to
159 // the pre-computation. If the proxy never computed its
160 // pre-instantiation size then the check is skipped.
Robert Phillips2f493142017-03-02 18:18:38 -0500161 proxy->gpuMemorySize();
Robert Phillipsb4460882016-11-17 14:43:51 -0500162
Robert Phillips2f493142017-03-02 18:18:38 -0500163 check_surface(reporter, proxy.get(), origin,
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500164 widthHeight, widthHeight, config, budgeted);
Brian Salomonbdecacf2018-02-02 20:32:49 -0500165 int supportedSamples =
166 caps.getRenderTargetSampleCount(numSamples, config);
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500167 check_rendertarget(reporter, caps, resourceProvider,
Robert Phillips2f493142017-03-02 18:18:38 -0500168 proxy->asRenderTargetProxy(),
Greg Daniel81e7bf82017-07-19 14:47:42 -0400169 supportedSamples,
Greg Daniel2a303902018-02-20 10:25:54 -0500170 fit, caps.maxWindowRectangles());
Robert Phillips40d94952017-01-30 14:15:59 -0500171 }
robertphillips76948d42016-05-04 12:47:41 -0700172 }
173
Robert Phillips84a81202016-11-04 11:59:10 -0400174 desc.fFlags = kNone_GrSurfaceFlags;
robertphillips76948d42016-05-04 12:47:41 -0700175
Robert Phillips6520a692017-02-01 09:20:00 -0500176 {
177 sk_sp<GrTexture> tex;
178 if (SkBackingFit::kApprox == fit) {
Chris Daltond004e0b2018-09-27 09:28:03 -0600179 tex = resourceProvider->createApproxTexture(
Robert Phillips9313aa72019-04-09 18:41:27 -0400180 desc, GrResourceProvider::Flags::kNoPendingIO);
Robert Phillips6520a692017-02-01 09:20:00 -0500181 } else {
Robert Phillips9313aa72019-04-09 18:41:27 -0400182 tex = resourceProvider->createTexture(
183 desc, budgeted, GrResourceProvider::Flags::kNoPendingIO);
Robert Phillips6520a692017-02-01 09:20:00 -0500184 }
Robert Phillipsb4460882016-11-17 14:43:51 -0500185
Brian Salomon2a4f9832018-03-03 22:43:43 -0500186 sk_sp<GrTextureProxy> proxy(
Greg Daniel4065d452018-11-16 15:43:41 -0500187 proxyProvider->createProxy(format, desc, origin, fit,
188 budgeted));
Robert Phillips2f493142017-03-02 18:18:38 -0500189 REPORTER_ASSERT(reporter, SkToBool(tex) == SkToBool(proxy));
190 if (proxy) {
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500191 // This forces the proxy to compute and cache its
192 // pre-instantiation size guess. Later, when it is actually
193 // instantiated, it checks that the instantiated size is <= to
194 // the pre-computation. If the proxy never computed its
195 // pre-instantiation size then the check is skipped.
Robert Phillips2f493142017-03-02 18:18:38 -0500196 proxy->gpuMemorySize();
Robert Phillips6520a692017-02-01 09:20:00 -0500197
Robert Phillips2f493142017-03-02 18:18:38 -0500198 check_surface(reporter, proxy.get(), origin,
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500199 widthHeight, widthHeight, config, budgeted);
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500200 check_texture(reporter, resourceProvider,
Greg Daniel2a303902018-02-20 10:25:54 -0500201 proxy->asTextureProxy(), fit);
Robert Phillips6520a692017-02-01 09:20:00 -0500202 }
Robert Phillips40d94952017-01-30 14:15:59 -0500203 }
Robert Phillips6520a692017-02-01 09:20:00 -0500204
205 attempt++;
robertphillips76948d42016-05-04 12:47:41 -0700206 }
207 }
208 }
209 }
210 }
211 }
212}
213
egdanielab527a52016-06-28 08:07:26 -0700214DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WrappedProxyTest, reporter, ctxInfo) {
Robert Phillips9da87e02019-02-04 13:26:26 -0500215 GrProxyProvider* proxyProvider = ctxInfo.grContext()->priv().proxyProvider();
216 GrResourceProvider* resourceProvider = ctxInfo.grContext()->priv().resourceProvider();
217 GrGpu* gpu = ctxInfo.grContext()->priv().getGpu();
218 const GrCaps& caps = *ctxInfo.grContext()->priv().caps();
robertphillips76948d42016-05-04 12:47:41 -0700219
220 static const int kWidthHeight = 100;
221
222 for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin }) {
Brian Osman10fc6fd2018-03-02 11:01:10 -0500223 for (auto colorType : { kAlpha_8_SkColorType, kRGBA_8888_SkColorType,
224 kRGBA_1010102_SkColorType }) {
Brian Salomon52e943a2018-03-13 09:32:39 -0400225 // External on-screen render target.
226 // Tests wrapBackendRenderTarget with a GrBackendRenderTarget
227 // Our test-only function that creates a backend render target doesn't currently support
228 // sample counts :(.
229 if (ctxInfo.grContext()->colorTypeSupportedAsSurface(colorType)) {
230 GrBackendRenderTarget backendRT = gpu->createTestingOnlyBackendRenderTarget(
Brian Osman2d010b62018-08-09 10:55:09 -0400231 kWidthHeight, kWidthHeight, SkColorTypeToGrColorType(colorType));
Brian Salomon52e943a2018-03-13 09:32:39 -0400232 sk_sp<GrSurfaceProxy> sProxy(
Greg Daniel8ce79912019-02-05 10:08:43 -0500233 proxyProvider->wrapBackendRenderTarget(backendRT, origin, nullptr,
234 nullptr));
Brian Salomon52e943a2018-03-13 09:32:39 -0400235 check_surface(reporter, sProxy.get(), origin, kWidthHeight, kWidthHeight,
Greg Daniel108bb232018-07-03 16:18:29 -0400236 backendRT.pixelConfig(), SkBudgeted::kNo);
Brian Salomon52e943a2018-03-13 09:32:39 -0400237 static constexpr int kExpectedNumSamples = 1;
238 check_rendertarget(reporter, caps, resourceProvider, sProxy->asRenderTargetProxy(),
239 kExpectedNumSamples, SkBackingFit::kExact,
240 caps.maxWindowRectangles());
241 gpu->deleteTestingOnlyBackendRenderTarget(backendRT);
242 }
243
Greg Daniel2a303902018-02-20 10:25:54 -0500244 for (auto numSamples : {1, 4}) {
Brian Osman2b23c4b2018-06-01 12:25:08 -0400245 GrPixelConfig config = SkColorType2GrPixelConfig(colorType);
Greg Daniel0a7aa142018-02-21 13:02:32 -0500246 SkASSERT(kUnknown_GrPixelConfig != config);
Greg Daniel2a303902018-02-20 10:25:54 -0500247 int supportedNumSamples = caps.getRenderTargetSampleCount(numSamples, config);
robertphillips76948d42016-05-04 12:47:41 -0700248
Greg Daniel2a303902018-02-20 10:25:54 -0500249 if (!supportedNumSamples) {
250 continue;
251 }
robertphillips76948d42016-05-04 12:47:41 -0700252
Brian Salomon52e943a2018-03-13 09:32:39 -0400253 // Test wrapping FBO 0 (with made up properties). This tests sample count and the
254 // special case where FBO 0 doesn't support window rectangles.
Greg Danielbdf12ad2018-10-12 09:31:11 -0400255 if (GrBackendApi::kOpenGL == ctxInfo.backend()) {
Greg Daniel2a303902018-02-20 10:25:54 -0500256 GrGLFramebufferInfo fboInfo;
257 fboInfo.fFBOID = 0;
Robert Phillipsb45f47d2019-02-03 17:17:54 -0500258 fboInfo.fFormat = GR_GL_RGBA8;
Brian Salomon52e943a2018-03-13 09:32:39 -0400259 static constexpr int kStencilBits = 8;
260 GrBackendRenderTarget backendRT(kWidthHeight, kWidthHeight, numSamples,
Greg Daniel108bb232018-07-03 16:18:29 -0400261 kStencilBits, fboInfo);
262 backendRT.setPixelConfig(config);
Brian Salomon7578f3e2018-03-07 14:39:54 -0500263 sk_sp<GrSurfaceProxy> sProxy(
Greg Daniel8ce79912019-02-05 10:08:43 -0500264 proxyProvider->wrapBackendRenderTarget(backendRT, origin, nullptr,
265 nullptr));
Greg Daniel2a303902018-02-20 10:25:54 -0500266 check_surface(reporter, sProxy.get(), origin,
267 kWidthHeight, kWidthHeight,
Greg Daniel108bb232018-07-03 16:18:29 -0400268 backendRT.pixelConfig(), SkBudgeted::kNo);
Greg Daniel2a303902018-02-20 10:25:54 -0500269 check_rendertarget(reporter, caps, resourceProvider,
270 sProxy->asRenderTargetProxy(),
271 supportedNumSamples, SkBackingFit::kExact, 0);
272 }
273
Brian Salomon7578f3e2018-03-07 14:39:54 -0500274 // Tests wrapBackendRenderTarget with a GrBackendTexture
Greg Daniel2a303902018-02-20 10:25:54 -0500275 {
276 GrBackendTexture backendTex =
277 gpu->createTestingOnlyBackendTexture(nullptr, kWidthHeight,
Brian Osman2b23c4b2018-06-01 12:25:08 -0400278 kWidthHeight, colorType,
Greg Daniel57bf4a32018-04-19 10:28:37 -0400279 true, GrMipMapped::kNo);
Brian Salomon7578f3e2018-03-07 14:39:54 -0500280 sk_sp<GrSurfaceProxy> sProxy = proxyProvider->wrapBackendTextureAsRenderTarget(
281 backendTex, origin, supportedNumSamples);
Greg Daniel2a303902018-02-20 10:25:54 -0500282 if (!sProxy) {
Brian Salomon26102cb2018-03-09 09:33:19 -0500283 gpu->deleteTestingOnlyBackendTexture(backendTex);
Greg Daniel2a303902018-02-20 10:25:54 -0500284 continue; // This can fail on Mesa
csmartdaltonf9635992016-08-10 11:09:07 -0700285 }
286
Greg Daniel2a303902018-02-20 10:25:54 -0500287 check_surface(reporter, sProxy.get(), origin,
288 kWidthHeight, kWidthHeight,
Greg Daniel108bb232018-07-03 16:18:29 -0400289 backendTex.pixelConfig(), SkBudgeted::kNo);
Greg Daniel2a303902018-02-20 10:25:54 -0500290 check_rendertarget(reporter, caps, resourceProvider,
291 sProxy->asRenderTargetProxy(),
292 supportedNumSamples, SkBackingFit::kExact,
293 caps.maxWindowRectangles());
robertphillips76948d42016-05-04 12:47:41 -0700294
Brian Salomon26102cb2018-03-09 09:33:19 -0500295 gpu->deleteTestingOnlyBackendTexture(backendTex);
Greg Daniel2a303902018-02-20 10:25:54 -0500296 }
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500297
Brian Salomon7578f3e2018-03-07 14:39:54 -0500298 // Tests wrapBackendTexture that is only renderable
Greg Danielf87651e2018-02-21 11:36:53 -0500299 {
300 GrBackendTexture backendTex =
301 gpu->createTestingOnlyBackendTexture(nullptr, kWidthHeight,
Brian Osman2b23c4b2018-06-01 12:25:08 -0400302 kWidthHeight, colorType,
Greg Daniel57bf4a32018-04-19 10:28:37 -0400303 true, GrMipMapped::kNo);
Greg Danielf87651e2018-02-21 11:36:53 -0500304
Brian Salomon7578f3e2018-03-07 14:39:54 -0500305 sk_sp<GrSurfaceProxy> sProxy = proxyProvider->wrapRenderableBackendTexture(
Brian Salomonaa6ca0a2019-01-24 16:03:07 -0500306 backendTex, origin, supportedNumSamples, kBorrow_GrWrapOwnership,
Greg Daniel8ce79912019-02-05 10:08:43 -0500307 GrWrapCacheable::kNo, nullptr, nullptr);
Greg Danielf87651e2018-02-21 11:36:53 -0500308 if (!sProxy) {
Brian Salomon26102cb2018-03-09 09:33:19 -0500309 gpu->deleteTestingOnlyBackendTexture(backendTex);
Greg Danielf87651e2018-02-21 11:36:53 -0500310 continue; // This can fail on Mesa
311 }
312
313 check_surface(reporter, sProxy.get(), origin,
314 kWidthHeight, kWidthHeight,
Greg Daniel108bb232018-07-03 16:18:29 -0400315 backendTex.pixelConfig(), SkBudgeted::kNo);
Greg Danielf87651e2018-02-21 11:36:53 -0500316 check_rendertarget(reporter, caps, resourceProvider,
317 sProxy->asRenderTargetProxy(),
318 supportedNumSamples, SkBackingFit::kExact,
319 caps.maxWindowRectangles());
320
Brian Salomon26102cb2018-03-09 09:33:19 -0500321 gpu->deleteTestingOnlyBackendTexture(backendTex);
Greg Danielf87651e2018-02-21 11:36:53 -0500322 }
323
Brian Salomon7578f3e2018-03-07 14:39:54 -0500324 // Tests wrapBackendTexture that is only textureable
Greg Daniel2a303902018-02-20 10:25:54 -0500325 {
326 // Internal offscreen texture
327 GrBackendTexture backendTex =
328 gpu->createTestingOnlyBackendTexture(nullptr, kWidthHeight,
Brian Osman2b23c4b2018-06-01 12:25:08 -0400329 kWidthHeight, colorType,
Greg Daniel57bf4a32018-04-19 10:28:37 -0400330 false, GrMipMapped::kNo);
robertphillips76948d42016-05-04 12:47:41 -0700331
Brian Salomon7578f3e2018-03-07 14:39:54 -0500332 sk_sp<GrSurfaceProxy> sProxy = proxyProvider->wrapBackendTexture(
Brian Salomonaa6ca0a2019-01-24 16:03:07 -0500333 backendTex, origin, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo,
334 kRead_GrIOType);
Greg Daniel2a303902018-02-20 10:25:54 -0500335 if (!sProxy) {
Brian Salomon26102cb2018-03-09 09:33:19 -0500336 gpu->deleteTestingOnlyBackendTexture(backendTex);
Greg Daniel2a303902018-02-20 10:25:54 -0500337 continue;
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500338 }
Greg Daniel2a303902018-02-20 10:25:54 -0500339
340 check_surface(reporter, sProxy.get(), origin,
341 kWidthHeight, kWidthHeight,
Greg Daniel108bb232018-07-03 16:18:29 -0400342 backendTex.pixelConfig(), SkBudgeted::kNo);
Greg Daniel2a303902018-02-20 10:25:54 -0500343 check_texture(reporter, resourceProvider, sProxy->asTextureProxy(),
344 SkBackingFit::kExact);
345
Brian Salomon26102cb2018-03-09 09:33:19 -0500346 gpu->deleteTestingOnlyBackendTexture(backendTex);
robertphillips76948d42016-05-04 12:47:41 -0700347 }
348 }
349 }
350 }
351}
352
Robert Phillips78de2122017-04-26 07:44:26 -0400353DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ZeroSizedProxyTest, reporter, ctxInfo) {
Robert Phillips9da87e02019-02-04 13:26:26 -0500354 GrProxyProvider* provider = ctxInfo.grContext()->priv().proxyProvider();
Robert Phillips78de2122017-04-26 07:44:26 -0400355
356 for (auto flags : { kRenderTarget_GrSurfaceFlag, kNone_GrSurfaceFlags }) {
357 for (auto fit : { SkBackingFit::kExact, SkBackingFit::kApprox }) {
358 for (int width : { 0, 100 }) {
359 for (int height : { 0, 100}) {
360 if (width && height) {
361 continue; // not zero-sized
362 }
363
364 GrSurfaceDesc desc;
365 desc.fFlags = flags;
Robert Phillips78de2122017-04-26 07:44:26 -0400366 desc.fWidth = width;
367 desc.fHeight = height;
368 desc.fConfig = kRGBA_8888_GrPixelConfig;
Brian Salomonbdecacf2018-02-02 20:32:49 -0500369 desc.fSampleCnt = 1;
Robert Phillips78de2122017-04-26 07:44:26 -0400370
Greg Daniel4065d452018-11-16 15:43:41 -0500371 const GrBackendFormat format =
Robert Phillips9da87e02019-02-04 13:26:26 -0500372 ctxInfo.grContext()->priv().caps()->getBackendFormatFromColorType(
Greg Daniel4065d452018-11-16 15:43:41 -0500373 kRGBA_8888_SkColorType);
374
Brian Salomon2a4f9832018-03-03 22:43:43 -0500375 sk_sp<GrTextureProxy> proxy = provider->createProxy(
Greg Daniel4065d452018-11-16 15:43:41 -0500376 format, desc, kBottomLeft_GrSurfaceOrigin, fit, SkBudgeted::kNo);
Robert Phillips78de2122017-04-26 07:44:26 -0400377 REPORTER_ASSERT(reporter, !proxy);
378 }
379 }
380 }
381 }
382}