blob: 695f72962982c4182a25a19cd19741dabd70cc20 [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"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050014#include "src/gpu/GrContextPriv.h"
15#include "src/gpu/GrProxyProvider.h"
16#include "src/gpu/GrRenderTargetPriv.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040017#include "src/gpu/GrRenderTargetProxy.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050018#include "src/gpu/GrResourceProvider.h"
19#include "src/gpu/GrSurfacePriv.h"
20#include "src/gpu/GrSurfaceProxyPriv.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040021#include "src/gpu/GrTextureProxy.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050022#include "src/gpu/SkGr.h"
John Rosascoa9b348f2019-11-08 13:18:15 -080023#ifdef SK_GL
Mike Kleinc0bd9f92019-04-23 12:05:21 -050024#include "src/gpu/gl/GrGLDefines.h"
Brian Salomond4764a12019-08-08 12:08:24 -040025#include "src/gpu/gl/GrGLUtil.h"
John Rosascoa9b348f2019-11-08 13:18:15 -080026#endif
robertphillips76948d42016-05-04 12:47:41 -070027
robertphillips8abb3702016-08-31 14:04:06 -070028// Check that the surface proxy's member vars are set as expected
robertphillips76948d42016-05-04 12:47:41 -070029static void check_surface(skiatest::Reporter* reporter,
30 GrSurfaceProxy* proxy,
31 GrSurfaceOrigin origin,
Greg Danielbcf612b2017-05-01 13:50:58 +000032 int width, int height,
Robert Phillipsabacf092016-11-02 10:23:32 -040033 SkBudgeted budgeted) {
robertphillips76948d42016-05-04 12:47:41 -070034 REPORTER_ASSERT(reporter, proxy->origin() == origin);
35 REPORTER_ASSERT(reporter, proxy->width() == width);
36 REPORTER_ASSERT(reporter, proxy->height() == height);
Robert Phillips0bd24dc2018-01-16 08:06:32 -050037 REPORTER_ASSERT(reporter, !proxy->uniqueID().isInvalid());
Robert Phillipsabacf092016-11-02 10:23:32 -040038 REPORTER_ASSERT(reporter, proxy->isBudgeted() == budgeted);
robertphillips76948d42016-05-04 12:47:41 -070039}
40
41static void check_rendertarget(skiatest::Reporter* reporter,
Robert Phillipsec2249f2016-11-09 08:54:35 -050042 const GrCaps& caps,
Brian Osman32342f02017-03-04 08:12:46 -050043 GrResourceProvider* provider,
robertphillips76948d42016-05-04 12:47:41 -070044 GrRenderTargetProxy* rtProxy,
Robert Phillipsabacf092016-11-02 10:23:32 -040045 int numSamples,
Robert Phillipsec2249f2016-11-09 08:54:35 -050046 SkBackingFit fit,
Greg Daniel2a303902018-02-20 10:25:54 -050047 int expectedMaxWindowRects) {
Robert Phillipsec2249f2016-11-09 08:54:35 -050048 REPORTER_ASSERT(reporter, rtProxy->maxWindowRectangles(caps) == expectedMaxWindowRects);
Chris Dalton6ce447a2019-06-23 18:07:38 -060049 REPORTER_ASSERT(reporter, rtProxy->numSamples() == numSamples);
Robert Phillipsabacf092016-11-02 10:23:32 -040050
Robert Phillips294870f2016-11-11 12:38:40 -050051 GrSurfaceProxy::UniqueID idBefore = rtProxy->uniqueID();
Brian Salomonfd98c2c2018-07-31 17:25:29 -040052 bool preinstantiated = rtProxy->isInstantiated();
Robert Phillipseee4d6e2017-06-05 09:26:07 -040053 REPORTER_ASSERT(reporter, rtProxy->instantiate(provider));
Brian Salomonfd98c2c2018-07-31 17:25:29 -040054 GrRenderTarget* rt = rtProxy->peekRenderTarget();
robertphillips76948d42016-05-04 12:47:41 -070055
Robert Phillips294870f2016-11-11 12:38:40 -050056 REPORTER_ASSERT(reporter, rtProxy->uniqueID() == idBefore);
Greg Daniel2a303902018-02-20 10:25:54 -050057 // Deferred resources should always have a different ID from their instantiated rendertarget
Brian Salomonf7778972018-03-08 10:13:17 -050058 if (preinstantiated) {
59 REPORTER_ASSERT(reporter, rtProxy->uniqueID().asUInt() == rt->uniqueID().asUInt());
60 } else {
61 REPORTER_ASSERT(reporter, rtProxy->uniqueID().asUInt() != rt->uniqueID().asUInt());
62 }
Robert Phillips294870f2016-11-11 12:38:40 -050063
robertphillips76948d42016-05-04 12:47:41 -070064 if (SkBackingFit::kExact == fit) {
Brian Salomon9f2b86c2019-10-22 10:37:46 -040065 REPORTER_ASSERT(reporter, rt->dimensions() == rtProxy->dimensions());
robertphillips76948d42016-05-04 12:47:41 -070066 } 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 }
Greg Danield51fa2f2020-01-22 16:53:38 -050070 REPORTER_ASSERT(reporter, rt->backendFormat() == rtProxy->backendFormat());
robertphillips76948d42016-05-04 12:47:41 -070071
Chris Dalton6ce447a2019-06-23 18:07:38 -060072 REPORTER_ASSERT(reporter, rt->numSamples() == rtProxy->numSamples());
Robert Phillipsfe0253f2018-03-16 16:47:25 -040073 REPORTER_ASSERT(reporter, rt->surfacePriv().flags() == rtProxy->testingOnly_getFlags());
robertphillips76948d42016-05-04 12:47:41 -070074}
75
76static void check_texture(skiatest::Reporter* reporter,
Brian Osman32342f02017-03-04 08:12:46 -050077 GrResourceProvider* provider,
robertphillips76948d42016-05-04 12:47:41 -070078 GrTextureProxy* texProxy,
Greg Daniel2a303902018-02-20 10:25:54 -050079 SkBackingFit fit) {
Robert Phillips294870f2016-11-11 12:38:40 -050080 GrSurfaceProxy::UniqueID idBefore = texProxy->uniqueID();
Robert Phillipseee4d6e2017-06-05 09:26:07 -040081
Brian Salomonfd98c2c2018-07-31 17:25:29 -040082 bool preinstantiated = texProxy->isInstantiated();
Michael Ludwigbd2f0702019-09-13 15:29:41 -040083 // The instantiated texture should have these dimensions. If the fit is kExact, then
Robert Phillipse9462dd2019-10-23 12:41:29 -040084 // 'backingStoreDimensions' reports the original WxH. If it is kApprox, make sure that
85 // the texture is that size and didn't reuse one of the kExact surfaces in the provider.
86 // This is important because upstream usage (e.g. SkImage) reports size based on the
87 // backingStoreDimensions and client code may rely on that if they are creating backend
88 // resources.
89 // NOTE: we store these before instantiating, since after instantiation backingStoreDimensions
90 // just returns the target's dimensions. In this instance, we want to ensure the target's
Brian Salomon9f2b86c2019-10-22 10:37:46 -040091 // dimensions are no different from the original approximate (or exact) dimensions.
Robert Phillipse9462dd2019-10-23 12:41:29 -040092 SkISize expectedSize = texProxy->backingStoreDimensions();
Michael Ludwigbd2f0702019-09-13 15:29:41 -040093
Robert Phillipseee4d6e2017-06-05 09:26:07 -040094 REPORTER_ASSERT(reporter, texProxy->instantiate(provider));
Brian Salomonfd98c2c2018-07-31 17:25:29 -040095 GrTexture* tex = texProxy->peekTexture();
robertphillips76948d42016-05-04 12:47:41 -070096
Robert Phillips294870f2016-11-11 12:38:40 -050097 REPORTER_ASSERT(reporter, texProxy->uniqueID() == idBefore);
Greg Daniel2a303902018-02-20 10:25:54 -050098 // Deferred resources should always have a different ID from their instantiated texture
Brian Salomonf7778972018-03-08 10:13:17 -050099 if (preinstantiated) {
100 REPORTER_ASSERT(reporter, texProxy->uniqueID().asUInt() == tex->uniqueID().asUInt());
101 } else {
102 REPORTER_ASSERT(reporter, texProxy->uniqueID().asUInt() != tex->uniqueID().asUInt());
103 }
Robert Phillips294870f2016-11-11 12:38:40 -0500104
Brian Salomon9f2b86c2019-10-22 10:37:46 -0400105 REPORTER_ASSERT(reporter, tex->dimensions() == expectedSize);
Michael Ludwigbd2f0702019-09-13 15:29:41 -0400106
Greg Danield51fa2f2020-01-22 16:53:38 -0500107 REPORTER_ASSERT(reporter, tex->backendFormat() == texProxy->backendFormat());
robertphillips76948d42016-05-04 12:47:41 -0700108}
109
110
robertphillips8abb3702016-08-31 14:04:06 -0700111DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DeferredProxyTest, reporter, ctxInfo) {
Robert Phillips9da87e02019-02-04 13:26:26 -0500112 GrProxyProvider* proxyProvider = ctxInfo.grContext()->priv().proxyProvider();
113 GrResourceProvider* resourceProvider = ctxInfo.grContext()->priv().resourceProvider();
114 const GrCaps& caps = *ctxInfo.grContext()->priv().caps();
robertphillips76948d42016-05-04 12:47:41 -0700115
Robert Phillips6520a692017-02-01 09:20:00 -0500116 int attempt = 0; // useful for debugging
117
robertphillips76948d42016-05-04 12:47:41 -0700118 for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin }) {
Robert Phillips40d94952017-01-30 14:15:59 -0500119 for (auto widthHeight : { 100, 128, 1048576 }) {
Robert Phillipsa5e78be2019-07-09 12:34:38 -0400120 for (auto ct : { GrColorType::kAlpha_8, GrColorType::kBGR_565,
121 GrColorType::kRGBA_8888, GrColorType::kRGBA_1010102 } ) {
robertphillips76948d42016-05-04 12:47:41 -0700122 for (auto fit : { SkBackingFit::kExact, SkBackingFit::kApprox }) {
123 for (auto budgeted : { SkBudgeted::kYes, SkBudgeted::kNo }) {
Brian Salomonbdecacf2018-02-02 20:32:49 -0500124 for (auto numSamples : {1, 4, 16, 128}) {
robertphillips76948d42016-05-04 12:47:41 -0700125 GrSurfaceDesc desc;
robertphillips76948d42016-05-04 12:47:41 -0700126 desc.fWidth = widthHeight;
127 desc.fHeight = widthHeight;
robertphillips76948d42016-05-04 12:47:41 -0700128
Robert Phillips0a15cc62019-07-30 12:49:10 -0400129 auto format = caps.getDefaultBackendFormat(ct, GrRenderable::kYes);
Greg Danielfa55f2e2019-06-13 15:21:38 -0400130 if (!format.isValid()) {
131 continue;
132 }
Greg Daniel47c20e82020-01-21 14:29:57 -0500133 GrSwizzle swizzle = caps.getReadSwizzle(format, ct);
Greg Daniel4065d452018-11-16 15:43:41 -0500134
Brian Salomonf2c2ba92019-07-17 09:59:59 -0400135 // Renderable
Robert Phillips6520a692017-02-01 09:20:00 -0500136 {
137 sk_sp<GrTexture> tex;
138 if (SkBackingFit::kApprox == fit) {
Chris Daltond004e0b2018-09-27 09:28:03 -0600139 tex = resourceProvider->createApproxTexture(
Brian Salomon4eb38b72019-08-05 12:58:39 -0400140 desc, format, GrRenderable::kYes, numSamples,
Robert Phillipsaee18c92019-09-06 11:48:27 -0400141 GrProtected::kNo);
Robert Phillips6520a692017-02-01 09:20:00 -0500142 } else {
Robert Phillips9313aa72019-04-09 18:41:27 -0400143 tex = resourceProvider->createTexture(
Brian Salomona90382f2019-09-17 09:01:56 -0400144 desc, format, GrRenderable::kYes, numSamples,
145 GrMipMapped::kNo, budgeted, GrProtected::kNo);
Robert Phillips6520a692017-02-01 09:20:00 -0500146 }
147
Brian Salomonf2c2ba92019-07-17 09:59:59 -0400148 sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(
Greg Daniel47c20e82020-01-21 14:29:57 -0500149 format, desc, swizzle, GrRenderable::kYes, numSamples,
150 origin, GrMipMapped::kNo, fit, budgeted, GrProtected::kNo);
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.
Greg Daniel7fd7a8a2019-10-10 16:10:31 -0400159 proxy->gpuMemorySize(caps);
Robert Phillipsb4460882016-11-17 14:43:51 -0500160
Robert Phillips2f493142017-03-02 18:18:38 -0500161 check_surface(reporter, proxy.get(), origin,
Greg Danield51fa2f2020-01-22 16:53:38 -0500162 widthHeight, widthHeight, budgeted);
Brian Salomonbdecacf2018-02-02 20:32:49 -0500163 int supportedSamples =
Greg Daniel6fa62e22019-08-07 15:52:37 -0400164 caps.getRenderTargetSampleCount(numSamples, format);
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
Brian Salomonf2c2ba92019-07-17 09:59:59 -0400172 // Not renderable
Robert Phillips6520a692017-02-01 09:20:00 -0500173 {
174 sk_sp<GrTexture> tex;
175 if (SkBackingFit::kApprox == fit) {
Chris Daltond004e0b2018-09-27 09:28:03 -0600176 tex = resourceProvider->createApproxTexture(
Brian Salomon4eb38b72019-08-05 12:58:39 -0400177 desc, format, GrRenderable::kNo, numSamples,
Robert Phillipsaee18c92019-09-06 11:48:27 -0400178 GrProtected::kNo);
Robert Phillips6520a692017-02-01 09:20:00 -0500179 } else {
Robert Phillips9313aa72019-04-09 18:41:27 -0400180 tex = resourceProvider->createTexture(
Brian Salomona90382f2019-09-17 09:01:56 -0400181 desc, format, GrRenderable::kNo, numSamples,
182 GrMipMapped::kNo, budgeted, GrProtected::kNo);
Robert Phillips6520a692017-02-01 09:20:00 -0500183 }
Robert Phillipsb4460882016-11-17 14:43:51 -0500184
Brian Salomonf2c2ba92019-07-17 09:59:59 -0400185 sk_sp<GrTextureProxy> proxy(proxyProvider->createProxy(
Greg Daniel47c20e82020-01-21 14:29:57 -0500186 format, desc, swizzle, GrRenderable::kNo, numSamples,
187 origin, GrMipMapped::kNo, fit, budgeted, GrProtected::kNo));
Robert Phillips2f493142017-03-02 18:18:38 -0500188 REPORTER_ASSERT(reporter, SkToBool(tex) == SkToBool(proxy));
189 if (proxy) {
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500190 // This forces the proxy to compute and cache its
191 // pre-instantiation size guess. Later, when it is actually
192 // instantiated, it checks that the instantiated size is <= to
193 // the pre-computation. If the proxy never computed its
194 // pre-instantiation size then the check is skipped.
Greg Daniel7fd7a8a2019-10-10 16:10:31 -0400195 proxy->gpuMemorySize(caps);
Robert Phillips6520a692017-02-01 09:20:00 -0500196
Robert Phillips2f493142017-03-02 18:18:38 -0500197 check_surface(reporter, proxy.get(), origin,
Greg Danield51fa2f2020-01-22 16:53:38 -0500198 widthHeight, widthHeight, budgeted);
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500199 check_texture(reporter, resourceProvider,
Greg Daniel2a303902018-02-20 10:25:54 -0500200 proxy->asTextureProxy(), fit);
Robert Phillips6520a692017-02-01 09:20:00 -0500201 }
Robert Phillips40d94952017-01-30 14:15:59 -0500202 }
Robert Phillips6520a692017-02-01 09:20:00 -0500203
204 attempt++;
robertphillips76948d42016-05-04 12:47:41 -0700205 }
206 }
207 }
208 }
209 }
210 }
211}
212
egdanielab527a52016-06-28 08:07:26 -0700213DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WrappedProxyTest, reporter, ctxInfo) {
Robert Phillips9da87e02019-02-04 13:26:26 -0500214 GrProxyProvider* proxyProvider = ctxInfo.grContext()->priv().proxyProvider();
Robert Phillips9b16f812019-05-17 10:01:21 -0400215 GrContext* context = ctxInfo.grContext();
216 GrResourceProvider* resourceProvider = context->priv().resourceProvider();
217 GrGpu* gpu = context->priv().getGpu();
218 const GrCaps& caps = *context->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 }) {
Greg Daniel627d0532019-07-08 16:48:14 -0400225 GrColorType grColorType = SkColorTypeToGrColorType(colorType);
Robert Phillipsc80b0e92019-07-23 10:27:09 -0400226
Brian Salomon52e943a2018-03-13 09:32:39 -0400227 // External on-screen render target.
228 // Tests wrapBackendRenderTarget with a GrBackendRenderTarget
229 // Our test-only function that creates a backend render target doesn't currently support
230 // sample counts :(.
231 if (ctxInfo.grContext()->colorTypeSupportedAsSurface(colorType)) {
232 GrBackendRenderTarget backendRT = gpu->createTestingOnlyBackendRenderTarget(
Greg Daniel627d0532019-07-08 16:48:14 -0400233 kWidthHeight, kWidthHeight, grColorType);
Brian Salomon52e943a2018-03-13 09:32:39 -0400234 sk_sp<GrSurfaceProxy> sProxy(
Robert Phillipsc80b0e92019-07-23 10:27:09 -0400235 proxyProvider->wrapBackendRenderTarget(backendRT, grColorType,
236 origin, nullptr, nullptr));
Brian Salomon52e943a2018-03-13 09:32:39 -0400237 check_surface(reporter, sProxy.get(), origin, kWidthHeight, kWidthHeight,
Greg Danield51fa2f2020-01-22 16:53:38 -0500238 SkBudgeted::kNo);
Brian Salomon52e943a2018-03-13 09:32:39 -0400239 static constexpr int kExpectedNumSamples = 1;
240 check_rendertarget(reporter, caps, resourceProvider, sProxy->asRenderTargetProxy(),
241 kExpectedNumSamples, SkBackingFit::kExact,
242 caps.maxWindowRectangles());
243 gpu->deleteTestingOnlyBackendRenderTarget(backendRT);
244 }
245
Greg Daniel2a303902018-02-20 10:25:54 -0500246 for (auto numSamples : {1, 4}) {
Greg Daniel6fa62e22019-08-07 15:52:37 -0400247 auto beFormat = caps.getDefaultBackendFormat(grColorType, GrRenderable::kYes);
248 int supportedNumSamples = caps.getRenderTargetSampleCount(numSamples, beFormat);
Greg Daniel2a303902018-02-20 10:25:54 -0500249 if (!supportedNumSamples) {
250 continue;
251 }
robertphillips76948d42016-05-04 12:47:41 -0700252
John Rosascoa9b348f2019-11-08 13:18:15 -0800253#ifdef SK_GL
Brian Salomon52e943a2018-03-13 09:32:39 -0400254 // Test wrapping FBO 0 (with made up properties). This tests sample count and the
255 // special case where FBO 0 doesn't support window rectangles.
Greg Danielbdf12ad2018-10-12 09:31:11 -0400256 if (GrBackendApi::kOpenGL == ctxInfo.backend()) {
Greg Daniel2a303902018-02-20 10:25:54 -0500257 GrGLFramebufferInfo fboInfo;
258 fboInfo.fFBOID = 0;
Brian Salomond4764a12019-08-08 12:08:24 -0400259 fboInfo.fFormat = GrGLFormatToEnum(beFormat.asGLFormat());
260 SkASSERT(fboInfo.fFormat);
Brian Salomon52e943a2018-03-13 09:32:39 -0400261 static constexpr int kStencilBits = 8;
262 GrBackendRenderTarget backendRT(kWidthHeight, kWidthHeight, numSamples,
Greg Daniel108bb232018-07-03 16:18:29 -0400263 kStencilBits, fboInfo);
Brian Salomon7578f3e2018-03-07 14:39:54 -0500264 sk_sp<GrSurfaceProxy> sProxy(
Robert Phillipsc80b0e92019-07-23 10:27:09 -0400265 proxyProvider->wrapBackendRenderTarget(backendRT, grColorType,
266 origin, nullptr, nullptr));
Greg Daniel2a303902018-02-20 10:25:54 -0500267 check_surface(reporter, sProxy.get(), origin,
Greg Danield51fa2f2020-01-22 16:53:38 -0500268 kWidthHeight, kWidthHeight, SkBudgeted::kNo);
Greg Daniel2a303902018-02-20 10:25:54 -0500269 check_rendertarget(reporter, caps, resourceProvider,
270 sProxy->asRenderTargetProxy(),
271 supportedNumSamples, SkBackingFit::kExact, 0);
272 }
John Rosascoa9b348f2019-11-08 13:18:15 -0800273#endif
Greg Daniel2a303902018-02-20 10:25:54 -0500274
Brian Salomon7578f3e2018-03-07 14:39:54 -0500275 // Tests wrapBackendRenderTarget with a GrBackendTexture
Greg Daniel2a303902018-02-20 10:25:54 -0500276 {
277 GrBackendTexture backendTex =
Robert Phillips4bdd36f2019-06-04 11:03:06 -0400278 context->createBackendTexture(kWidthHeight, kWidthHeight,
279 colorType,
280 SkColors::kTransparent,
281 GrMipMapped::kNo,
Robert Phillipsda2e67a2019-07-01 15:04:06 -0400282 GrRenderable::kYes,
283 GrProtected::kNo);
Brian Salomon7578f3e2018-03-07 14:39:54 -0500284 sk_sp<GrSurfaceProxy> sProxy = proxyProvider->wrapBackendTextureAsRenderTarget(
Robert Phillipsc80b0e92019-07-23 10:27:09 -0400285 backendTex, grColorType, origin, supportedNumSamples);
Greg Daniel2a303902018-02-20 10:25:54 -0500286 if (!sProxy) {
Robert Phillips5c7a25b2019-05-20 08:38:07 -0400287 context->deleteBackendTexture(backendTex);
Greg Daniel2a303902018-02-20 10:25:54 -0500288 continue; // This can fail on Mesa
csmartdaltonf9635992016-08-10 11:09:07 -0700289 }
290
Greg Daniel2a303902018-02-20 10:25:54 -0500291 check_surface(reporter, sProxy.get(), origin,
Greg Danield51fa2f2020-01-22 16:53:38 -0500292 kWidthHeight, kWidthHeight, SkBudgeted::kNo);
Greg Daniel2a303902018-02-20 10:25:54 -0500293 check_rendertarget(reporter, caps, resourceProvider,
294 sProxy->asRenderTargetProxy(),
295 supportedNumSamples, SkBackingFit::kExact,
296 caps.maxWindowRectangles());
robertphillips76948d42016-05-04 12:47:41 -0700297
Robert Phillips5c7a25b2019-05-20 08:38:07 -0400298 context->deleteBackendTexture(backendTex);
Greg Daniel2a303902018-02-20 10:25:54 -0500299 }
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500300
Brian Salomon7578f3e2018-03-07 14:39:54 -0500301 // Tests wrapBackendTexture that is only renderable
Greg Danielf87651e2018-02-21 11:36:53 -0500302 {
303 GrBackendTexture backendTex =
Robert Phillips4bdd36f2019-06-04 11:03:06 -0400304 context->createBackendTexture(kWidthHeight, kWidthHeight,
305 colorType,
306 SkColors::kTransparent,
307 GrMipMapped::kNo,
Robert Phillipsda2e67a2019-07-01 15:04:06 -0400308 GrRenderable::kYes,
309 GrProtected::kNo);
Greg Danielf87651e2018-02-21 11:36:53 -0500310
Brian Salomon7578f3e2018-03-07 14:39:54 -0500311 sk_sp<GrSurfaceProxy> sProxy = proxyProvider->wrapRenderableBackendTexture(
Robert Phillips0902c982019-07-16 07:47:56 -0400312 backendTex, origin, supportedNumSamples,
313 grColorType, kBorrow_GrWrapOwnership,
Greg Daniel8ce79912019-02-05 10:08:43 -0500314 GrWrapCacheable::kNo, nullptr, nullptr);
Greg Danielf87651e2018-02-21 11:36:53 -0500315 if (!sProxy) {
Robert Phillips5c7a25b2019-05-20 08:38:07 -0400316 context->deleteBackendTexture(backendTex);
Greg Danielf87651e2018-02-21 11:36:53 -0500317 continue; // This can fail on Mesa
318 }
319
320 check_surface(reporter, sProxy.get(), origin,
Greg Danield51fa2f2020-01-22 16:53:38 -0500321 kWidthHeight, kWidthHeight, SkBudgeted::kNo);
Greg Danielf87651e2018-02-21 11:36:53 -0500322 check_rendertarget(reporter, caps, resourceProvider,
323 sProxy->asRenderTargetProxy(),
324 supportedNumSamples, SkBackingFit::kExact,
325 caps.maxWindowRectangles());
326
Robert Phillips5c7a25b2019-05-20 08:38:07 -0400327 context->deleteBackendTexture(backendTex);
Greg Danielf87651e2018-02-21 11:36:53 -0500328 }
329
Brian Salomon7578f3e2018-03-07 14:39:54 -0500330 // Tests wrapBackendTexture that is only textureable
Greg Daniel2a303902018-02-20 10:25:54 -0500331 {
332 // Internal offscreen texture
333 GrBackendTexture backendTex =
Robert Phillips4bdd36f2019-06-04 11:03:06 -0400334 context->createBackendTexture(kWidthHeight, kWidthHeight,
335 colorType,
336 SkColors::kTransparent,
337 GrMipMapped::kNo,
Robert Phillipsda2e67a2019-07-01 15:04:06 -0400338 GrRenderable::kNo,
339 GrProtected::kNo);
robertphillips76948d42016-05-04 12:47:41 -0700340
Brian Salomon7578f3e2018-03-07 14:39:54 -0500341 sk_sp<GrSurfaceProxy> sProxy = proxyProvider->wrapBackendTexture(
Robert Phillipsc80b0e92019-07-23 10:27:09 -0400342 backendTex, grColorType, origin, kBorrow_GrWrapOwnership,
343 GrWrapCacheable::kNo, kRead_GrIOType);
Greg Daniel2a303902018-02-20 10:25:54 -0500344 if (!sProxy) {
Robert Phillips5c7a25b2019-05-20 08:38:07 -0400345 context->deleteBackendTexture(backendTex);
Greg Daniel2a303902018-02-20 10:25:54 -0500346 continue;
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500347 }
Greg Daniel2a303902018-02-20 10:25:54 -0500348
349 check_surface(reporter, sProxy.get(), origin,
Greg Danield51fa2f2020-01-22 16:53:38 -0500350 kWidthHeight, kWidthHeight, SkBudgeted::kNo);
Greg Daniel2a303902018-02-20 10:25:54 -0500351 check_texture(reporter, resourceProvider, sProxy->asTextureProxy(),
352 SkBackingFit::kExact);
353
Robert Phillips5c7a25b2019-05-20 08:38:07 -0400354 context->deleteBackendTexture(backendTex);
robertphillips76948d42016-05-04 12:47:41 -0700355 }
356 }
357 }
358 }
359}
360
Robert Phillips78de2122017-04-26 07:44:26 -0400361DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ZeroSizedProxyTest, reporter, ctxInfo) {
Robert Phillips0a15cc62019-07-30 12:49:10 -0400362 GrContext* context = ctxInfo.grContext();
363 GrProxyProvider* provider = context->priv().proxyProvider();
Robert Phillips78de2122017-04-26 07:44:26 -0400364
Brian Salomonf2c2ba92019-07-17 09:59:59 -0400365 for (auto renderable : {GrRenderable::kNo, GrRenderable::kYes}) {
Robert Phillips78de2122017-04-26 07:44:26 -0400366 for (auto fit : { SkBackingFit::kExact, SkBackingFit::kApprox }) {
367 for (int width : { 0, 100 }) {
368 for (int height : { 0, 100}) {
369 if (width && height) {
370 continue; // not zero-sized
371 }
372
373 GrSurfaceDesc desc;
Robert Phillips78de2122017-04-26 07:44:26 -0400374 desc.fWidth = width;
375 desc.fHeight = height;
Robert Phillips78de2122017-04-26 07:44:26 -0400376
Greg Daniel4065d452018-11-16 15:43:41 -0500377 const GrBackendFormat format =
Robert Phillips0a15cc62019-07-30 12:49:10 -0400378 context->priv().caps()->getDefaultBackendFormat(
379 GrColorType::kRGBA_8888,
380 renderable);
Greg Daniel47c20e82020-01-21 14:29:57 -0500381 GrSwizzle swizzle = context->priv().caps()->getReadSwizzle(
382 format, GrColorType::kRGBA_8888);
Greg Daniel4065d452018-11-16 15:43:41 -0500383
Brian Salomone8a766b2019-07-19 14:24:36 -0400384 sk_sp<GrTextureProxy> proxy = provider->createProxy(
Greg Daniel47c20e82020-01-21 14:29:57 -0500385 format, desc, swizzle, renderable, 1, kBottomLeft_GrSurfaceOrigin,
Brian Salomonbeb7f522019-08-30 16:19:42 -0400386 GrMipMapped::kNo, fit, SkBudgeted::kNo, GrProtected::kNo);
Robert Phillips78de2122017-04-26 07:44:26 -0400387 REPORTER_ASSERT(reporter, !proxy);
388 }
389 }
390 }
391 }
392}