blob: 8c351b352f8cdba719e349b9969adc638c348927 [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"
Robert Phillipsb45f47d2019-02-03 17:17:54 -050023#include "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 Phillips1afd4cd2018-01-08 13:40:32 -0500108 GrProxyProvider* proxyProvider = ctxInfo.grContext()->contextPriv().proxyProvider();
Robert Phillips6be756b2018-01-16 15:07:54 -0500109 GrResourceProvider* resourceProvider = ctxInfo.grContext()->contextPriv().resourceProvider();
Brian Salomonc7fe0f72018-05-11 10:14:21 -0400110 const GrCaps& caps = *ctxInfo.grContext()->contextPriv().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(
144 desc, GrResourceProvider::Flags::kNone);
Robert Phillips6520a692017-02-01 09:20:00 -0500145 } else {
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500146 tex = resourceProvider->createTexture(desc, budgeted);
Robert Phillips6520a692017-02-01 09:20:00 -0500147 }
148
Brian Salomon2a4f9832018-03-03 22:43:43 -0500149 sk_sp<GrTextureProxy> proxy =
Greg Daniel4065d452018-11-16 15:43:41 -0500150 proxyProvider->createProxy(format, desc, origin, fit,
151 budgeted);
Robert Phillips2f493142017-03-02 18:18:38 -0500152 REPORTER_ASSERT(reporter, SkToBool(tex) == SkToBool(proxy));
153 if (proxy) {
154 REPORTER_ASSERT(reporter, proxy->asRenderTargetProxy());
Robert Phillips40d94952017-01-30 14:15:59 -0500155 // This forces the proxy to compute and cache its
156 // pre-instantiation size guess. Later, when it is actually
157 // instantiated, it checks that the instantiated size is <= to
158 // the pre-computation. If the proxy never computed its
159 // pre-instantiation size then the check is skipped.
Robert Phillips2f493142017-03-02 18:18:38 -0500160 proxy->gpuMemorySize();
Robert Phillipsb4460882016-11-17 14:43:51 -0500161
Robert Phillips2f493142017-03-02 18:18:38 -0500162 check_surface(reporter, proxy.get(), origin,
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500163 widthHeight, widthHeight, config, budgeted);
Brian Salomonbdecacf2018-02-02 20:32:49 -0500164 int supportedSamples =
165 caps.getRenderTargetSampleCount(numSamples, config);
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500166 check_rendertarget(reporter, caps, resourceProvider,
Robert Phillips2f493142017-03-02 18:18:38 -0500167 proxy->asRenderTargetProxy(),
Greg Daniel81e7bf82017-07-19 14:47:42 -0400168 supportedSamples,
Greg Daniel2a303902018-02-20 10:25:54 -0500169 fit, caps.maxWindowRectangles());
Robert Phillips40d94952017-01-30 14:15:59 -0500170 }
robertphillips76948d42016-05-04 12:47:41 -0700171 }
172
Robert Phillips84a81202016-11-04 11:59:10 -0400173 desc.fFlags = kNone_GrSurfaceFlags;
robertphillips76948d42016-05-04 12:47:41 -0700174
Robert Phillips6520a692017-02-01 09:20:00 -0500175 {
176 sk_sp<GrTexture> tex;
177 if (SkBackingFit::kApprox == fit) {
Chris Daltond004e0b2018-09-27 09:28:03 -0600178 tex = resourceProvider->createApproxTexture(
179 desc, GrResourceProvider::Flags::kNone);
Robert Phillips6520a692017-02-01 09:20:00 -0500180 } else {
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500181 tex = resourceProvider->createTexture(desc, budgeted);
Robert Phillips6520a692017-02-01 09:20:00 -0500182 }
Robert Phillipsb4460882016-11-17 14:43:51 -0500183
Brian Salomon2a4f9832018-03-03 22:43:43 -0500184 sk_sp<GrTextureProxy> proxy(
Greg Daniel4065d452018-11-16 15:43:41 -0500185 proxyProvider->createProxy(format, desc, origin, fit,
186 budgeted));
Robert Phillips2f493142017-03-02 18:18:38 -0500187 REPORTER_ASSERT(reporter, SkToBool(tex) == SkToBool(proxy));
188 if (proxy) {
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500189 // This forces the proxy to compute and cache its
190 // pre-instantiation size guess. Later, when it is actually
191 // instantiated, it checks that the instantiated size is <= to
192 // the pre-computation. If the proxy never computed its
193 // pre-instantiation size then the check is skipped.
Robert Phillips2f493142017-03-02 18:18:38 -0500194 proxy->gpuMemorySize();
Robert Phillips6520a692017-02-01 09:20:00 -0500195
Robert Phillips2f493142017-03-02 18:18:38 -0500196 check_surface(reporter, proxy.get(), origin,
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500197 widthHeight, widthHeight, config, budgeted);
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500198 check_texture(reporter, resourceProvider,
Greg Daniel2a303902018-02-20 10:25:54 -0500199 proxy->asTextureProxy(), fit);
Robert Phillips6520a692017-02-01 09:20:00 -0500200 }
Robert Phillips40d94952017-01-30 14:15:59 -0500201 }
Robert Phillips6520a692017-02-01 09:20:00 -0500202
203 attempt++;
robertphillips76948d42016-05-04 12:47:41 -0700204 }
205 }
206 }
207 }
208 }
209 }
210}
211
egdanielab527a52016-06-28 08:07:26 -0700212DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WrappedProxyTest, reporter, ctxInfo) {
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500213 GrProxyProvider* proxyProvider = ctxInfo.grContext()->contextPriv().proxyProvider();
Robert Phillips6be756b2018-01-16 15:07:54 -0500214 GrResourceProvider* resourceProvider = ctxInfo.grContext()->contextPriv().resourceProvider();
Greg Daniel2a303902018-02-20 10:25:54 -0500215 GrGpu* gpu = ctxInfo.grContext()->contextPriv().getGpu();
Brian Salomonc7fe0f72018-05-11 10:14:21 -0400216 const GrCaps& caps = *ctxInfo.grContext()->contextPriv().caps();
robertphillips76948d42016-05-04 12:47:41 -0700217
218 static const int kWidthHeight = 100;
219
220 for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin }) {
Brian Osman10fc6fd2018-03-02 11:01:10 -0500221 for (auto colorType : { kAlpha_8_SkColorType, kRGBA_8888_SkColorType,
222 kRGBA_1010102_SkColorType }) {
Brian Salomon52e943a2018-03-13 09:32:39 -0400223 // External on-screen render target.
224 // Tests wrapBackendRenderTarget with a GrBackendRenderTarget
225 // Our test-only function that creates a backend render target doesn't currently support
226 // sample counts :(.
227 if (ctxInfo.grContext()->colorTypeSupportedAsSurface(colorType)) {
228 GrBackendRenderTarget backendRT = gpu->createTestingOnlyBackendRenderTarget(
Brian Osman2d010b62018-08-09 10:55:09 -0400229 kWidthHeight, kWidthHeight, SkColorTypeToGrColorType(colorType));
Brian Salomon52e943a2018-03-13 09:32:39 -0400230 sk_sp<GrSurfaceProxy> sProxy(
231 proxyProvider->wrapBackendRenderTarget(backendRT, origin));
232 check_surface(reporter, sProxy.get(), origin, kWidthHeight, kWidthHeight,
Greg Daniel108bb232018-07-03 16:18:29 -0400233 backendRT.pixelConfig(), SkBudgeted::kNo);
Brian Salomon52e943a2018-03-13 09:32:39 -0400234 static constexpr int kExpectedNumSamples = 1;
235 check_rendertarget(reporter, caps, resourceProvider, sProxy->asRenderTargetProxy(),
236 kExpectedNumSamples, SkBackingFit::kExact,
237 caps.maxWindowRectangles());
238 gpu->deleteTestingOnlyBackendRenderTarget(backendRT);
239 }
240
Greg Daniel2a303902018-02-20 10:25:54 -0500241 for (auto numSamples : {1, 4}) {
Brian Osman2b23c4b2018-06-01 12:25:08 -0400242 GrPixelConfig config = SkColorType2GrPixelConfig(colorType);
Greg Daniel0a7aa142018-02-21 13:02:32 -0500243 SkASSERT(kUnknown_GrPixelConfig != config);
Greg Daniel2a303902018-02-20 10:25:54 -0500244 int supportedNumSamples = caps.getRenderTargetSampleCount(numSamples, config);
robertphillips76948d42016-05-04 12:47:41 -0700245
Greg Daniel2a303902018-02-20 10:25:54 -0500246 if (!supportedNumSamples) {
247 continue;
248 }
robertphillips76948d42016-05-04 12:47:41 -0700249
Brian Salomon52e943a2018-03-13 09:32:39 -0400250 // Test wrapping FBO 0 (with made up properties). This tests sample count and the
251 // special case where FBO 0 doesn't support window rectangles.
Greg Danielbdf12ad2018-10-12 09:31:11 -0400252 if (GrBackendApi::kOpenGL == ctxInfo.backend()) {
Greg Daniel2a303902018-02-20 10:25:54 -0500253 GrGLFramebufferInfo fboInfo;
254 fboInfo.fFBOID = 0;
Robert Phillipsb45f47d2019-02-03 17:17:54 -0500255 fboInfo.fFormat = GR_GL_RGBA8;
Brian Salomon52e943a2018-03-13 09:32:39 -0400256 static constexpr int kStencilBits = 8;
257 GrBackendRenderTarget backendRT(kWidthHeight, kWidthHeight, numSamples,
Greg Daniel108bb232018-07-03 16:18:29 -0400258 kStencilBits, fboInfo);
259 backendRT.setPixelConfig(config);
Brian Salomon7578f3e2018-03-07 14:39:54 -0500260 sk_sp<GrSurfaceProxy> sProxy(
261 proxyProvider->wrapBackendRenderTarget(backendRT, origin));
Greg Daniel2a303902018-02-20 10:25:54 -0500262 check_surface(reporter, sProxy.get(), origin,
263 kWidthHeight, kWidthHeight,
Greg Daniel108bb232018-07-03 16:18:29 -0400264 backendRT.pixelConfig(), SkBudgeted::kNo);
Greg Daniel2a303902018-02-20 10:25:54 -0500265 check_rendertarget(reporter, caps, resourceProvider,
266 sProxy->asRenderTargetProxy(),
267 supportedNumSamples, SkBackingFit::kExact, 0);
268 }
269
Brian Salomon7578f3e2018-03-07 14:39:54 -0500270 // Tests wrapBackendRenderTarget with a GrBackendTexture
Greg Daniel2a303902018-02-20 10:25:54 -0500271 {
272 GrBackendTexture backendTex =
273 gpu->createTestingOnlyBackendTexture(nullptr, kWidthHeight,
Brian Osman2b23c4b2018-06-01 12:25:08 -0400274 kWidthHeight, colorType,
Greg Daniel57bf4a32018-04-19 10:28:37 -0400275 true, GrMipMapped::kNo);
Brian Salomon7578f3e2018-03-07 14:39:54 -0500276 sk_sp<GrSurfaceProxy> sProxy = proxyProvider->wrapBackendTextureAsRenderTarget(
277 backendTex, origin, supportedNumSamples);
Greg Daniel2a303902018-02-20 10:25:54 -0500278 if (!sProxy) {
Brian Salomon26102cb2018-03-09 09:33:19 -0500279 gpu->deleteTestingOnlyBackendTexture(backendTex);
Greg Daniel2a303902018-02-20 10:25:54 -0500280 continue; // This can fail on Mesa
csmartdaltonf9635992016-08-10 11:09:07 -0700281 }
282
Greg Daniel2a303902018-02-20 10:25:54 -0500283 check_surface(reporter, sProxy.get(), origin,
284 kWidthHeight, kWidthHeight,
Greg Daniel108bb232018-07-03 16:18:29 -0400285 backendTex.pixelConfig(), SkBudgeted::kNo);
Greg Daniel2a303902018-02-20 10:25:54 -0500286 check_rendertarget(reporter, caps, resourceProvider,
287 sProxy->asRenderTargetProxy(),
288 supportedNumSamples, SkBackingFit::kExact,
289 caps.maxWindowRectangles());
robertphillips76948d42016-05-04 12:47:41 -0700290
Brian Salomon26102cb2018-03-09 09:33:19 -0500291 gpu->deleteTestingOnlyBackendTexture(backendTex);
Greg Daniel2a303902018-02-20 10:25:54 -0500292 }
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500293
Brian Salomon7578f3e2018-03-07 14:39:54 -0500294 // Tests wrapBackendTexture that is only renderable
Greg Danielf87651e2018-02-21 11:36:53 -0500295 {
296 GrBackendTexture backendTex =
297 gpu->createTestingOnlyBackendTexture(nullptr, kWidthHeight,
Brian Osman2b23c4b2018-06-01 12:25:08 -0400298 kWidthHeight, colorType,
Greg Daniel57bf4a32018-04-19 10:28:37 -0400299 true, GrMipMapped::kNo);
Greg Danielf87651e2018-02-21 11:36:53 -0500300
Brian Salomon7578f3e2018-03-07 14:39:54 -0500301 sk_sp<GrSurfaceProxy> sProxy = proxyProvider->wrapRenderableBackendTexture(
Brian Salomonaa6ca0a2019-01-24 16:03:07 -0500302 backendTex, origin, supportedNumSamples, kBorrow_GrWrapOwnership,
303 GrWrapCacheable::kNo);
Greg Danielf87651e2018-02-21 11:36:53 -0500304 if (!sProxy) {
Brian Salomon26102cb2018-03-09 09:33:19 -0500305 gpu->deleteTestingOnlyBackendTexture(backendTex);
Greg Danielf87651e2018-02-21 11:36:53 -0500306 continue; // This can fail on Mesa
307 }
308
309 check_surface(reporter, sProxy.get(), origin,
310 kWidthHeight, kWidthHeight,
Greg Daniel108bb232018-07-03 16:18:29 -0400311 backendTex.pixelConfig(), SkBudgeted::kNo);
Greg Danielf87651e2018-02-21 11:36:53 -0500312 check_rendertarget(reporter, caps, resourceProvider,
313 sProxy->asRenderTargetProxy(),
314 supportedNumSamples, SkBackingFit::kExact,
315 caps.maxWindowRectangles());
316
Brian Salomon26102cb2018-03-09 09:33:19 -0500317 gpu->deleteTestingOnlyBackendTexture(backendTex);
Greg Danielf87651e2018-02-21 11:36:53 -0500318 }
319
Brian Salomon7578f3e2018-03-07 14:39:54 -0500320 // Tests wrapBackendTexture that is only textureable
Greg Daniel2a303902018-02-20 10:25:54 -0500321 {
322 // Internal offscreen texture
323 GrBackendTexture backendTex =
324 gpu->createTestingOnlyBackendTexture(nullptr, kWidthHeight,
Brian Osman2b23c4b2018-06-01 12:25:08 -0400325 kWidthHeight, colorType,
Greg Daniel57bf4a32018-04-19 10:28:37 -0400326 false, GrMipMapped::kNo);
robertphillips76948d42016-05-04 12:47:41 -0700327
Brian Salomon7578f3e2018-03-07 14:39:54 -0500328 sk_sp<GrSurfaceProxy> sProxy = proxyProvider->wrapBackendTexture(
Brian Salomonaa6ca0a2019-01-24 16:03:07 -0500329 backendTex, origin, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo,
330 kRead_GrIOType);
Greg Daniel2a303902018-02-20 10:25:54 -0500331 if (!sProxy) {
Brian Salomon26102cb2018-03-09 09:33:19 -0500332 gpu->deleteTestingOnlyBackendTexture(backendTex);
Greg Daniel2a303902018-02-20 10:25:54 -0500333 continue;
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500334 }
Greg Daniel2a303902018-02-20 10:25:54 -0500335
336 check_surface(reporter, sProxy.get(), origin,
337 kWidthHeight, kWidthHeight,
Greg Daniel108bb232018-07-03 16:18:29 -0400338 backendTex.pixelConfig(), SkBudgeted::kNo);
Greg Daniel2a303902018-02-20 10:25:54 -0500339 check_texture(reporter, resourceProvider, sProxy->asTextureProxy(),
340 SkBackingFit::kExact);
341
Brian Salomon26102cb2018-03-09 09:33:19 -0500342 gpu->deleteTestingOnlyBackendTexture(backendTex);
robertphillips76948d42016-05-04 12:47:41 -0700343 }
344 }
345 }
346 }
347}
348
Robert Phillips78de2122017-04-26 07:44:26 -0400349DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ZeroSizedProxyTest, reporter, ctxInfo) {
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500350 GrProxyProvider* provider = ctxInfo.grContext()->contextPriv().proxyProvider();
Robert Phillips78de2122017-04-26 07:44:26 -0400351
352 for (auto flags : { kRenderTarget_GrSurfaceFlag, kNone_GrSurfaceFlags }) {
353 for (auto fit : { SkBackingFit::kExact, SkBackingFit::kApprox }) {
354 for (int width : { 0, 100 }) {
355 for (int height : { 0, 100}) {
356 if (width && height) {
357 continue; // not zero-sized
358 }
359
360 GrSurfaceDesc desc;
361 desc.fFlags = flags;
Robert Phillips78de2122017-04-26 07:44:26 -0400362 desc.fWidth = width;
363 desc.fHeight = height;
364 desc.fConfig = kRGBA_8888_GrPixelConfig;
Brian Salomonbdecacf2018-02-02 20:32:49 -0500365 desc.fSampleCnt = 1;
Robert Phillips78de2122017-04-26 07:44:26 -0400366
Greg Daniel4065d452018-11-16 15:43:41 -0500367 const GrBackendFormat format =
368 ctxInfo.grContext()->contextPriv().caps()->getBackendFormatFromColorType(
369 kRGBA_8888_SkColorType);
370
Brian Salomon2a4f9832018-03-03 22:43:43 -0500371 sk_sp<GrTextureProxy> proxy = provider->createProxy(
Greg Daniel4065d452018-11-16 15:43:41 -0500372 format, desc, kBottomLeft_GrSurfaceOrigin, fit, SkBudgeted::kNo);
Robert Phillips78de2122017-04-26 07:44:26 -0400373 REPORTER_ASSERT(reporter, !proxy);
374 }
375 }
376 }
377 }
378}