blob: 77b85fb263dcf0d106eb030ee39f2aaf9e4493fc [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"
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);
Robert Phillips97256382019-07-17 15:26:36 -040035#ifdef SK_DEBUG
36 REPORTER_ASSERT(reporter, GrCaps::AreConfigsCompatible(config, proxy->config()));
37#endif
Robert Phillips0bd24dc2018-01-16 08:06:32 -050038 REPORTER_ASSERT(reporter, !proxy->uniqueID().isInvalid());
Robert Phillipsabacf092016-11-02 10:23:32 -040039 REPORTER_ASSERT(reporter, proxy->isBudgeted() == budgeted);
robertphillips76948d42016-05-04 12:47:41 -070040}
41
42static void check_rendertarget(skiatest::Reporter* reporter,
Robert Phillipsec2249f2016-11-09 08:54:35 -050043 const GrCaps& caps,
Brian Osman32342f02017-03-04 08:12:46 -050044 GrResourceProvider* provider,
robertphillips76948d42016-05-04 12:47:41 -070045 GrRenderTargetProxy* rtProxy,
Robert Phillipsabacf092016-11-02 10:23:32 -040046 int numSamples,
Robert Phillipsec2249f2016-11-09 08:54:35 -050047 SkBackingFit fit,
Greg Daniel2a303902018-02-20 10:25:54 -050048 int expectedMaxWindowRects) {
Robert Phillipsec2249f2016-11-09 08:54:35 -050049 REPORTER_ASSERT(reporter, rtProxy->maxWindowRectangles(caps) == expectedMaxWindowRects);
Chris Dalton6ce447a2019-06-23 18:07:38 -060050 REPORTER_ASSERT(reporter, rtProxy->numSamples() == numSamples);
Robert Phillipsabacf092016-11-02 10:23:32 -040051
Robert Phillips294870f2016-11-11 12:38:40 -050052 GrSurfaceProxy::UniqueID idBefore = rtProxy->uniqueID();
Brian Salomonfd98c2c2018-07-31 17:25:29 -040053 bool preinstantiated = rtProxy->isInstantiated();
Robert Phillipseee4d6e2017-06-05 09:26:07 -040054 REPORTER_ASSERT(reporter, rtProxy->instantiate(provider));
Brian Salomonfd98c2c2018-07-31 17:25:29 -040055 GrRenderTarget* rt = rtProxy->peekRenderTarget();
robertphillips76948d42016-05-04 12:47:41 -070056
Robert Phillips294870f2016-11-11 12:38:40 -050057 REPORTER_ASSERT(reporter, rtProxy->uniqueID() == idBefore);
Greg Daniel2a303902018-02-20 10:25:54 -050058 // Deferred resources should always have a different ID from their instantiated rendertarget
Brian Salomonf7778972018-03-08 10:13:17 -050059 if (preinstantiated) {
60 REPORTER_ASSERT(reporter, rtProxy->uniqueID().asUInt() == rt->uniqueID().asUInt());
61 } else {
62 REPORTER_ASSERT(reporter, rtProxy->uniqueID().asUInt() != rt->uniqueID().asUInt());
63 }
Robert Phillips294870f2016-11-11 12:38:40 -050064
robertphillips76948d42016-05-04 12:47:41 -070065 if (SkBackingFit::kExact == fit) {
66 REPORTER_ASSERT(reporter, rt->width() == rtProxy->width());
67 REPORTER_ASSERT(reporter, rt->height() == rtProxy->height());
68 } else {
69 REPORTER_ASSERT(reporter, rt->width() >= rtProxy->width());
Robert Phillips294870f2016-11-11 12:38:40 -050070 REPORTER_ASSERT(reporter, rt->height() >= rtProxy->height());
robertphillips76948d42016-05-04 12:47:41 -070071 }
72 REPORTER_ASSERT(reporter, rt->config() == rtProxy->config());
73
Chris Dalton6ce447a2019-06-23 18:07:38 -060074 REPORTER_ASSERT(reporter, rt->numSamples() == rtProxy->numSamples());
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 Phillipsa5e78be2019-07-09 12:34:38 -0400116 for (auto ct : { GrColorType::kAlpha_8, GrColorType::kBGR_565,
117 GrColorType::kRGBA_8888, GrColorType::kRGBA_1010102 } ) {
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}) {
Robert Phillipsa5e78be2019-07-09 12:34:38 -0400121
Greg Daniele877dce2019-07-11 10:52:43 -0400122 auto config = GrColorTypeToPixelConfig(ct);
Robert Phillipsa5e78be2019-07-09 12:34:38 -0400123 SkASSERT(kUnknown_GrPixelConfig != config);
Jim Van Verth1676cb92019-01-15 13:24:45 -0500124
robertphillips76948d42016-05-04 12:47:41 -0700125 GrSurfaceDesc desc;
robertphillips76948d42016-05-04 12:47:41 -0700126 desc.fWidth = widthHeight;
127 desc.fHeight = widthHeight;
128 desc.fConfig = config;
129 desc.fSampleCnt = numSamples;
130
Greg Daniele877dce2019-07-11 10:52:43 -0400131 const GrBackendFormat format = caps.getBackendFormatFromColorType(ct);
Greg Danielfa55f2e2019-06-13 15:21:38 -0400132 if (!format.isValid()) {
133 continue;
134 }
Greg Daniel4065d452018-11-16 15:43:41 -0500135
Brian Salomonf2c2ba92019-07-17 09:59:59 -0400136 // Renderable
Robert Phillips6520a692017-02-01 09:20:00 -0500137 {
138 sk_sp<GrTexture> tex;
139 if (SkBackingFit::kApprox == fit) {
Chris Daltond004e0b2018-09-27 09:28:03 -0600140 tex = resourceProvider->createApproxTexture(
Brian Salomonf2c2ba92019-07-17 09:59:59 -0400141 desc, GrRenderable::kYes,
142 GrResourceProvider::Flags::kNoPendingIO);
Robert Phillips6520a692017-02-01 09:20:00 -0500143 } else {
Robert Phillips9313aa72019-04-09 18:41:27 -0400144 tex = resourceProvider->createTexture(
Brian Salomonf2c2ba92019-07-17 09:59:59 -0400145 desc, GrRenderable::kYes, budgeted,
146 GrResourceProvider::Flags::kNoPendingIO);
Robert Phillips6520a692017-02-01 09:20:00 -0500147 }
148
Brian Salomonf2c2ba92019-07-17 09:59:59 -0400149 sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(
150 format, desc, GrRenderable::kYes, origin, fit, 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
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 Salomonf2c2ba92019-07-17 09:59:59 -0400177 desc, GrRenderable::kNo,
178 GrResourceProvider::Flags::kNoPendingIO);
Robert Phillips6520a692017-02-01 09:20:00 -0500179 } else {
Robert Phillips9313aa72019-04-09 18:41:27 -0400180 tex = resourceProvider->createTexture(
Brian Salomonf2c2ba92019-07-17 09:59:59 -0400181 desc, GrRenderable::kNo, budgeted,
182 GrResourceProvider::Flags::kNoPendingIO);
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(
186 format, desc, GrRenderable::kNo, origin, fit, 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 Phillips9da87e02019-02-04 13:26:26 -0500213 GrProxyProvider* proxyProvider = ctxInfo.grContext()->priv().proxyProvider();
Robert Phillips9b16f812019-05-17 10:01:21 -0400214 GrContext* context = ctxInfo.grContext();
215 GrResourceProvider* resourceProvider = context->priv().resourceProvider();
216 GrGpu* gpu = context->priv().getGpu();
217 const GrCaps& caps = *context->priv().caps();
robertphillips76948d42016-05-04 12:47:41 -0700218
219 static const int kWidthHeight = 100;
220
221 for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin }) {
Brian Osman10fc6fd2018-03-02 11:01:10 -0500222 for (auto colorType : { kAlpha_8_SkColorType, kRGBA_8888_SkColorType,
223 kRGBA_1010102_SkColorType }) {
Greg Daniel627d0532019-07-08 16:48:14 -0400224 GrColorType grColorType = SkColorTypeToGrColorType(colorType);
Robert Phillips97256382019-07-17 15:26:36 -0400225 GrPixelConfig config = GrColorTypeToPixelConfig(grColorType);
226 SkASSERT(kUnknown_GrPixelConfig != config);
227
Brian Salomon52e943a2018-03-13 09:32:39 -0400228 // External on-screen render target.
229 // Tests wrapBackendRenderTarget with a GrBackendRenderTarget
230 // Our test-only function that creates a backend render target doesn't currently support
231 // sample counts :(.
232 if (ctxInfo.grContext()->colorTypeSupportedAsSurface(colorType)) {
233 GrBackendRenderTarget backendRT = gpu->createTestingOnlyBackendRenderTarget(
Greg Daniel627d0532019-07-08 16:48:14 -0400234 kWidthHeight, kWidthHeight, grColorType);
Brian Salomon52e943a2018-03-13 09:32:39 -0400235 sk_sp<GrSurfaceProxy> sProxy(
Robert Phillips97256382019-07-17 15:26:36 -0400236 proxyProvider->wrapBackendRenderTarget(backendRT, grColorType,
237 origin, nullptr, nullptr));
Brian Salomon52e943a2018-03-13 09:32:39 -0400238 check_surface(reporter, sProxy.get(), origin, kWidthHeight, kWidthHeight,
Robert Phillips97256382019-07-17 15:26:36 -0400239 config, SkBudgeted::kNo);
Brian Salomon52e943a2018-03-13 09:32:39 -0400240 static constexpr int kExpectedNumSamples = 1;
241 check_rendertarget(reporter, caps, resourceProvider, sProxy->asRenderTargetProxy(),
242 kExpectedNumSamples, SkBackingFit::kExact,
243 caps.maxWindowRectangles());
244 gpu->deleteTestingOnlyBackendRenderTarget(backendRT);
245 }
246
Greg Daniel2a303902018-02-20 10:25:54 -0500247 for (auto numSamples : {1, 4}) {
Greg Daniel2a303902018-02-20 10:25:54 -0500248 int supportedNumSamples = caps.getRenderTargetSampleCount(numSamples, config);
robertphillips76948d42016-05-04 12:47:41 -0700249
Greg Daniel2a303902018-02-20 10:25:54 -0500250 if (!supportedNumSamples) {
251 continue;
252 }
robertphillips76948d42016-05-04 12:47:41 -0700253
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 Daniel627d0532019-07-08 16:48:14 -0400257 GrBackendFormat beFormat = caps.getBackendFormatFromColorType(grColorType);
Greg Daniel2a303902018-02-20 10:25:54 -0500258 GrGLFramebufferInfo fboInfo;
259 fboInfo.fFBOID = 0;
Greg Danielfa55f2e2019-06-13 15:21:38 -0400260 SkASSERT(beFormat.getGLFormat());
261 fboInfo.fFormat = *beFormat.getGLFormat();
Brian Salomon52e943a2018-03-13 09:32:39 -0400262 static constexpr int kStencilBits = 8;
263 GrBackendRenderTarget backendRT(kWidthHeight, kWidthHeight, numSamples,
Greg Daniel108bb232018-07-03 16:18:29 -0400264 kStencilBits, fboInfo);
265 backendRT.setPixelConfig(config);
Brian Salomon7578f3e2018-03-07 14:39:54 -0500266 sk_sp<GrSurfaceProxy> sProxy(
Robert Phillips97256382019-07-17 15:26:36 -0400267 proxyProvider->wrapBackendRenderTarget(backendRT, grColorType,
268 origin, nullptr, nullptr));
Greg Daniel2a303902018-02-20 10:25:54 -0500269 check_surface(reporter, sProxy.get(), origin,
270 kWidthHeight, kWidthHeight,
Robert Phillips97256382019-07-17 15:26:36 -0400271 config, SkBudgeted::kNo);
Greg Daniel2a303902018-02-20 10:25:54 -0500272 check_rendertarget(reporter, caps, resourceProvider,
273 sProxy->asRenderTargetProxy(),
274 supportedNumSamples, SkBackingFit::kExact, 0);
275 }
276
Brian Salomon7578f3e2018-03-07 14:39:54 -0500277 // Tests wrapBackendRenderTarget with a GrBackendTexture
Greg Daniel2a303902018-02-20 10:25:54 -0500278 {
279 GrBackendTexture backendTex =
Robert Phillips4bdd36f2019-06-04 11:03:06 -0400280 context->createBackendTexture(kWidthHeight, kWidthHeight,
281 colorType,
282 SkColors::kTransparent,
283 GrMipMapped::kNo,
Robert Phillipsda2e67a2019-07-01 15:04:06 -0400284 GrRenderable::kYes,
285 GrProtected::kNo);
Brian Salomon7578f3e2018-03-07 14:39:54 -0500286 sk_sp<GrSurfaceProxy> sProxy = proxyProvider->wrapBackendTextureAsRenderTarget(
Robert Phillips97256382019-07-17 15:26:36 -0400287 backendTex, grColorType, origin, supportedNumSamples);
Greg Daniel2a303902018-02-20 10:25:54 -0500288 if (!sProxy) {
Robert Phillips5c7a25b2019-05-20 08:38:07 -0400289 context->deleteBackendTexture(backendTex);
Greg Daniel2a303902018-02-20 10:25:54 -0500290 continue; // This can fail on Mesa
csmartdaltonf9635992016-08-10 11:09:07 -0700291 }
292
Greg Daniel2a303902018-02-20 10:25:54 -0500293 check_surface(reporter, sProxy.get(), origin,
294 kWidthHeight, kWidthHeight,
Robert Phillips97256382019-07-17 15:26:36 -0400295 config, SkBudgeted::kNo);
Greg Daniel2a303902018-02-20 10:25:54 -0500296 check_rendertarget(reporter, caps, resourceProvider,
297 sProxy->asRenderTargetProxy(),
298 supportedNumSamples, SkBackingFit::kExact,
299 caps.maxWindowRectangles());
robertphillips76948d42016-05-04 12:47:41 -0700300
Robert Phillips5c7a25b2019-05-20 08:38:07 -0400301 context->deleteBackendTexture(backendTex);
Greg Daniel2a303902018-02-20 10:25:54 -0500302 }
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500303
Brian Salomon7578f3e2018-03-07 14:39:54 -0500304 // Tests wrapBackendTexture that is only renderable
Greg Danielf87651e2018-02-21 11:36:53 -0500305 {
306 GrBackendTexture backendTex =
Robert Phillips4bdd36f2019-06-04 11:03:06 -0400307 context->createBackendTexture(kWidthHeight, kWidthHeight,
308 colorType,
309 SkColors::kTransparent,
310 GrMipMapped::kNo,
Robert Phillipsda2e67a2019-07-01 15:04:06 -0400311 GrRenderable::kYes,
312 GrProtected::kNo);
Greg Danielf87651e2018-02-21 11:36:53 -0500313
Brian Salomon7578f3e2018-03-07 14:39:54 -0500314 sk_sp<GrSurfaceProxy> sProxy = proxyProvider->wrapRenderableBackendTexture(
Robert Phillips0902c982019-07-16 07:47:56 -0400315 backendTex, origin, supportedNumSamples,
316 grColorType, kBorrow_GrWrapOwnership,
Greg Daniel8ce79912019-02-05 10:08:43 -0500317 GrWrapCacheable::kNo, nullptr, nullptr);
Greg Danielf87651e2018-02-21 11:36:53 -0500318 if (!sProxy) {
Robert Phillips5c7a25b2019-05-20 08:38:07 -0400319 context->deleteBackendTexture(backendTex);
Greg Danielf87651e2018-02-21 11:36:53 -0500320 continue; // This can fail on Mesa
321 }
322
323 check_surface(reporter, sProxy.get(), origin,
324 kWidthHeight, kWidthHeight,
Robert Phillips97256382019-07-17 15:26:36 -0400325 config, SkBudgeted::kNo);
Greg Danielf87651e2018-02-21 11:36:53 -0500326 check_rendertarget(reporter, caps, resourceProvider,
327 sProxy->asRenderTargetProxy(),
328 supportedNumSamples, SkBackingFit::kExact,
329 caps.maxWindowRectangles());
330
Robert Phillips5c7a25b2019-05-20 08:38:07 -0400331 context->deleteBackendTexture(backendTex);
Greg Danielf87651e2018-02-21 11:36:53 -0500332 }
333
Brian Salomon7578f3e2018-03-07 14:39:54 -0500334 // Tests wrapBackendTexture that is only textureable
Greg Daniel2a303902018-02-20 10:25:54 -0500335 {
336 // Internal offscreen texture
337 GrBackendTexture backendTex =
Robert Phillips4bdd36f2019-06-04 11:03:06 -0400338 context->createBackendTexture(kWidthHeight, kWidthHeight,
339 colorType,
340 SkColors::kTransparent,
341 GrMipMapped::kNo,
Robert Phillipsda2e67a2019-07-01 15:04:06 -0400342 GrRenderable::kNo,
343 GrProtected::kNo);
robertphillips76948d42016-05-04 12:47:41 -0700344
Brian Salomon7578f3e2018-03-07 14:39:54 -0500345 sk_sp<GrSurfaceProxy> sProxy = proxyProvider->wrapBackendTexture(
Robert Phillips97256382019-07-17 15:26:36 -0400346 backendTex, grColorType, origin, kBorrow_GrWrapOwnership,
347 GrWrapCacheable::kNo, kRead_GrIOType);
Greg Daniel2a303902018-02-20 10:25:54 -0500348 if (!sProxy) {
Robert Phillips5c7a25b2019-05-20 08:38:07 -0400349 context->deleteBackendTexture(backendTex);
Greg Daniel2a303902018-02-20 10:25:54 -0500350 continue;
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500351 }
Greg Daniel2a303902018-02-20 10:25:54 -0500352
353 check_surface(reporter, sProxy.get(), origin,
354 kWidthHeight, kWidthHeight,
Robert Phillips97256382019-07-17 15:26:36 -0400355 config, SkBudgeted::kNo);
Greg Daniel2a303902018-02-20 10:25:54 -0500356 check_texture(reporter, resourceProvider, sProxy->asTextureProxy(),
357 SkBackingFit::kExact);
358
Robert Phillips5c7a25b2019-05-20 08:38:07 -0400359 context->deleteBackendTexture(backendTex);
robertphillips76948d42016-05-04 12:47:41 -0700360 }
361 }
362 }
363 }
364}
365
Robert Phillips78de2122017-04-26 07:44:26 -0400366DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ZeroSizedProxyTest, reporter, ctxInfo) {
Robert Phillips9da87e02019-02-04 13:26:26 -0500367 GrProxyProvider* provider = ctxInfo.grContext()->priv().proxyProvider();
Robert Phillips78de2122017-04-26 07:44:26 -0400368
Brian Salomonf2c2ba92019-07-17 09:59:59 -0400369 for (auto renderable : {GrRenderable::kNo, GrRenderable::kYes}) {
Robert Phillips78de2122017-04-26 07:44:26 -0400370 for (auto fit : { SkBackingFit::kExact, SkBackingFit::kApprox }) {
371 for (int width : { 0, 100 }) {
372 for (int height : { 0, 100}) {
373 if (width && height) {
374 continue; // not zero-sized
375 }
376
377 GrSurfaceDesc desc;
Robert Phillips78de2122017-04-26 07:44:26 -0400378 desc.fWidth = width;
379 desc.fHeight = height;
380 desc.fConfig = kRGBA_8888_GrPixelConfig;
Brian Salomonbdecacf2018-02-02 20:32:49 -0500381 desc.fSampleCnt = 1;
Robert Phillips78de2122017-04-26 07:44:26 -0400382
Greg Daniel4065d452018-11-16 15:43:41 -0500383 const GrBackendFormat format =
Robert Phillips9da87e02019-02-04 13:26:26 -0500384 ctxInfo.grContext()->priv().caps()->getBackendFormatFromColorType(
Greg Daniel627d0532019-07-08 16:48:14 -0400385 GrColorType::kRGBA_8888);
Greg Daniel4065d452018-11-16 15:43:41 -0500386
Brian Salomonf2c2ba92019-07-17 09:59:59 -0400387 sk_sp<GrTextureProxy> proxy = provider->createProxy(format, desc, renderable,
388 kBottomLeft_GrSurfaceOrigin,
389 fit, SkBudgeted::kNo);
Robert Phillips78de2122017-04-26 07:44:26 -0400390 REPORTER_ASSERT(reporter, !proxy);
391 }
392 }
393 }
394 }
395}