blob: 8bf260348a528c73edc9f50397539cdcbec8ea76 [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 Phillipsc80b0e92019-07-23 10:27:09 -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;
robertphillips76948d42016-05-04 12:47:41 -0700129
Robert Phillips0a15cc62019-07-30 12:49:10 -0400130 auto format = caps.getDefaultBackendFormat(ct, GrRenderable::kYes);
Greg Danielfa55f2e2019-06-13 15:21:38 -0400131 if (!format.isValid()) {
132 continue;
133 }
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,
141 GrProtected::kNo,
Brian Salomonf2c2ba92019-07-17 09:59:59 -0400142 GrResourceProvider::Flags::kNoPendingIO);
Robert Phillips6520a692017-02-01 09:20:00 -0500143 } else {
Robert Phillips9313aa72019-04-09 18:41:27 -0400144 tex = resourceProvider->createTexture(
Brian Salomon4eb38b72019-08-05 12:58:39 -0400145 desc, format, GrRenderable::kYes, numSamples, budgeted,
Brian Salomon27b4d8d2019-07-22 14:23:45 -0400146 GrProtected::kNo,
Brian Salomonf2c2ba92019-07-17 09:59:59 -0400147 GrResourceProvider::Flags::kNoPendingIO);
Robert Phillips6520a692017-02-01 09:20:00 -0500148 }
149
Brian Salomonf2c2ba92019-07-17 09:59:59 -0400150 sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(
Brian Salomon27b4d8d2019-07-22 14:23:45 -0400151 format, desc, GrRenderable::kYes, numSamples, origin, fit,
152 budgeted, GrProtected::kNo);
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
Brian Salomonf2c2ba92019-07-17 09:59:59 -0400174 // Not renderable
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(
Brian Salomon4eb38b72019-08-05 12:58:39 -0400179 desc, format, GrRenderable::kNo, numSamples,
180 GrProtected::kNo,
Brian Salomonf2c2ba92019-07-17 09:59:59 -0400181 GrResourceProvider::Flags::kNoPendingIO);
Robert Phillips6520a692017-02-01 09:20:00 -0500182 } else {
Robert Phillips9313aa72019-04-09 18:41:27 -0400183 tex = resourceProvider->createTexture(
Brian Salomon4eb38b72019-08-05 12:58:39 -0400184 desc, format, GrRenderable::kNo, numSamples, budgeted,
Brian Salomon27b4d8d2019-07-22 14:23:45 -0400185 GrProtected::kNo,
Brian Salomonf2c2ba92019-07-17 09:59:59 -0400186 GrResourceProvider::Flags::kNoPendingIO);
Robert Phillips6520a692017-02-01 09:20:00 -0500187 }
Robert Phillipsb4460882016-11-17 14:43:51 -0500188
Brian Salomonf2c2ba92019-07-17 09:59:59 -0400189 sk_sp<GrTextureProxy> proxy(proxyProvider->createProxy(
Brian Salomon27b4d8d2019-07-22 14:23:45 -0400190 format, desc, GrRenderable::kNo, numSamples, origin, fit,
191 budgeted, GrProtected::kNo));
Robert Phillips2f493142017-03-02 18:18:38 -0500192 REPORTER_ASSERT(reporter, SkToBool(tex) == SkToBool(proxy));
193 if (proxy) {
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500194 // This forces the proxy to compute and cache its
195 // pre-instantiation size guess. Later, when it is actually
196 // instantiated, it checks that the instantiated size is <= to
197 // the pre-computation. If the proxy never computed its
198 // pre-instantiation size then the check is skipped.
Robert Phillips2f493142017-03-02 18:18:38 -0500199 proxy->gpuMemorySize();
Robert Phillips6520a692017-02-01 09:20:00 -0500200
Robert Phillips2f493142017-03-02 18:18:38 -0500201 check_surface(reporter, proxy.get(), origin,
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500202 widthHeight, widthHeight, config, budgeted);
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500203 check_texture(reporter, resourceProvider,
Greg Daniel2a303902018-02-20 10:25:54 -0500204 proxy->asTextureProxy(), fit);
Robert Phillips6520a692017-02-01 09:20:00 -0500205 }
Robert Phillips40d94952017-01-30 14:15:59 -0500206 }
Robert Phillips6520a692017-02-01 09:20:00 -0500207
208 attempt++;
robertphillips76948d42016-05-04 12:47:41 -0700209 }
210 }
211 }
212 }
213 }
214 }
215}
216
egdanielab527a52016-06-28 08:07:26 -0700217DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WrappedProxyTest, reporter, ctxInfo) {
Robert Phillips9da87e02019-02-04 13:26:26 -0500218 GrProxyProvider* proxyProvider = ctxInfo.grContext()->priv().proxyProvider();
Robert Phillips9b16f812019-05-17 10:01:21 -0400219 GrContext* context = ctxInfo.grContext();
220 GrResourceProvider* resourceProvider = context->priv().resourceProvider();
221 GrGpu* gpu = context->priv().getGpu();
222 const GrCaps& caps = *context->priv().caps();
robertphillips76948d42016-05-04 12:47:41 -0700223
224 static const int kWidthHeight = 100;
225
226 for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin }) {
Brian Osman10fc6fd2018-03-02 11:01:10 -0500227 for (auto colorType : { kAlpha_8_SkColorType, kRGBA_8888_SkColorType,
228 kRGBA_1010102_SkColorType }) {
Greg Daniel627d0532019-07-08 16:48:14 -0400229 GrColorType grColorType = SkColorTypeToGrColorType(colorType);
Robert Phillipsc80b0e92019-07-23 10:27:09 -0400230 GrPixelConfig config = GrColorTypeToPixelConfig(grColorType);
231 SkASSERT(kUnknown_GrPixelConfig != config);
232
Brian Salomon52e943a2018-03-13 09:32:39 -0400233 // External on-screen render target.
234 // Tests wrapBackendRenderTarget with a GrBackendRenderTarget
235 // Our test-only function that creates a backend render target doesn't currently support
236 // sample counts :(.
237 if (ctxInfo.grContext()->colorTypeSupportedAsSurface(colorType)) {
238 GrBackendRenderTarget backendRT = gpu->createTestingOnlyBackendRenderTarget(
Greg Daniel627d0532019-07-08 16:48:14 -0400239 kWidthHeight, kWidthHeight, grColorType);
Brian Salomon52e943a2018-03-13 09:32:39 -0400240 sk_sp<GrSurfaceProxy> sProxy(
Robert Phillipsc80b0e92019-07-23 10:27:09 -0400241 proxyProvider->wrapBackendRenderTarget(backendRT, grColorType,
242 origin, nullptr, nullptr));
Brian Salomon52e943a2018-03-13 09:32:39 -0400243 check_surface(reporter, sProxy.get(), origin, kWidthHeight, kWidthHeight,
Robert Phillipsc80b0e92019-07-23 10:27:09 -0400244 config, SkBudgeted::kNo);
Brian Salomon52e943a2018-03-13 09:32:39 -0400245 static constexpr int kExpectedNumSamples = 1;
246 check_rendertarget(reporter, caps, resourceProvider, sProxy->asRenderTargetProxy(),
247 kExpectedNumSamples, SkBackingFit::kExact,
248 caps.maxWindowRectangles());
249 gpu->deleteTestingOnlyBackendRenderTarget(backendRT);
250 }
251
Greg Daniel2a303902018-02-20 10:25:54 -0500252 for (auto numSamples : {1, 4}) {
Greg Daniel2a303902018-02-20 10:25:54 -0500253 int supportedNumSamples = caps.getRenderTargetSampleCount(numSamples, config);
robertphillips76948d42016-05-04 12:47:41 -0700254
Greg Daniel2a303902018-02-20 10:25:54 -0500255 if (!supportedNumSamples) {
256 continue;
257 }
robertphillips76948d42016-05-04 12:47:41 -0700258
Brian Salomon52e943a2018-03-13 09:32:39 -0400259 // Test wrapping FBO 0 (with made up properties). This tests sample count and the
260 // special case where FBO 0 doesn't support window rectangles.
Greg Danielbdf12ad2018-10-12 09:31:11 -0400261 if (GrBackendApi::kOpenGL == ctxInfo.backend()) {
Robert Phillips0a15cc62019-07-30 12:49:10 -0400262 auto beFormat = caps.getDefaultBackendFormat(grColorType, GrRenderable::kYes);
Greg Daniel2a303902018-02-20 10:25:54 -0500263 GrGLFramebufferInfo fboInfo;
264 fboInfo.fFBOID = 0;
Greg Danielfa55f2e2019-06-13 15:21:38 -0400265 SkASSERT(beFormat.getGLFormat());
266 fboInfo.fFormat = *beFormat.getGLFormat();
Brian Salomon52e943a2018-03-13 09:32:39 -0400267 static constexpr int kStencilBits = 8;
268 GrBackendRenderTarget backendRT(kWidthHeight, kWidthHeight, numSamples,
Greg Daniel108bb232018-07-03 16:18:29 -0400269 kStencilBits, fboInfo);
Brian Salomon7578f3e2018-03-07 14:39:54 -0500270 sk_sp<GrSurfaceProxy> sProxy(
Robert Phillipsc80b0e92019-07-23 10:27:09 -0400271 proxyProvider->wrapBackendRenderTarget(backendRT, grColorType,
272 origin, nullptr, nullptr));
Greg Daniel2a303902018-02-20 10:25:54 -0500273 check_surface(reporter, sProxy.get(), origin,
274 kWidthHeight, kWidthHeight,
Robert Phillipsc80b0e92019-07-23 10:27:09 -0400275 config, SkBudgeted::kNo);
Greg Daniel2a303902018-02-20 10:25:54 -0500276 check_rendertarget(reporter, caps, resourceProvider,
277 sProxy->asRenderTargetProxy(),
278 supportedNumSamples, SkBackingFit::kExact, 0);
279 }
280
Brian Salomon7578f3e2018-03-07 14:39:54 -0500281 // Tests wrapBackendRenderTarget with a GrBackendTexture
Greg Daniel2a303902018-02-20 10:25:54 -0500282 {
283 GrBackendTexture backendTex =
Robert Phillips4bdd36f2019-06-04 11:03:06 -0400284 context->createBackendTexture(kWidthHeight, kWidthHeight,
285 colorType,
286 SkColors::kTransparent,
287 GrMipMapped::kNo,
Robert Phillipsda2e67a2019-07-01 15:04:06 -0400288 GrRenderable::kYes,
289 GrProtected::kNo);
Brian Salomon7578f3e2018-03-07 14:39:54 -0500290 sk_sp<GrSurfaceProxy> sProxy = proxyProvider->wrapBackendTextureAsRenderTarget(
Robert Phillipsc80b0e92019-07-23 10:27:09 -0400291 backendTex, grColorType, origin, supportedNumSamples);
Greg Daniel2a303902018-02-20 10:25:54 -0500292 if (!sProxy) {
Robert Phillips5c7a25b2019-05-20 08:38:07 -0400293 context->deleteBackendTexture(backendTex);
Greg Daniel2a303902018-02-20 10:25:54 -0500294 continue; // This can fail on Mesa
csmartdaltonf9635992016-08-10 11:09:07 -0700295 }
296
Greg Daniel2a303902018-02-20 10:25:54 -0500297 check_surface(reporter, sProxy.get(), origin,
298 kWidthHeight, kWidthHeight,
Robert Phillipsc80b0e92019-07-23 10:27:09 -0400299 config, SkBudgeted::kNo);
Greg Daniel2a303902018-02-20 10:25:54 -0500300 check_rendertarget(reporter, caps, resourceProvider,
301 sProxy->asRenderTargetProxy(),
302 supportedNumSamples, SkBackingFit::kExact,
303 caps.maxWindowRectangles());
robertphillips76948d42016-05-04 12:47:41 -0700304
Robert Phillips5c7a25b2019-05-20 08:38:07 -0400305 context->deleteBackendTexture(backendTex);
Greg Daniel2a303902018-02-20 10:25:54 -0500306 }
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500307
Brian Salomon7578f3e2018-03-07 14:39:54 -0500308 // Tests wrapBackendTexture that is only renderable
Greg Danielf87651e2018-02-21 11:36:53 -0500309 {
310 GrBackendTexture backendTex =
Robert Phillips4bdd36f2019-06-04 11:03:06 -0400311 context->createBackendTexture(kWidthHeight, kWidthHeight,
312 colorType,
313 SkColors::kTransparent,
314 GrMipMapped::kNo,
Robert Phillipsda2e67a2019-07-01 15:04:06 -0400315 GrRenderable::kYes,
316 GrProtected::kNo);
Greg Danielf87651e2018-02-21 11:36:53 -0500317
Brian Salomon7578f3e2018-03-07 14:39:54 -0500318 sk_sp<GrSurfaceProxy> sProxy = proxyProvider->wrapRenderableBackendTexture(
Robert Phillips0902c982019-07-16 07:47:56 -0400319 backendTex, origin, supportedNumSamples,
320 grColorType, kBorrow_GrWrapOwnership,
Greg Daniel8ce79912019-02-05 10:08:43 -0500321 GrWrapCacheable::kNo, nullptr, nullptr);
Greg Danielf87651e2018-02-21 11:36:53 -0500322 if (!sProxy) {
Robert Phillips5c7a25b2019-05-20 08:38:07 -0400323 context->deleteBackendTexture(backendTex);
Greg Danielf87651e2018-02-21 11:36:53 -0500324 continue; // This can fail on Mesa
325 }
326
327 check_surface(reporter, sProxy.get(), origin,
328 kWidthHeight, kWidthHeight,
Robert Phillipsc80b0e92019-07-23 10:27:09 -0400329 config, SkBudgeted::kNo);
Greg Danielf87651e2018-02-21 11:36:53 -0500330 check_rendertarget(reporter, caps, resourceProvider,
331 sProxy->asRenderTargetProxy(),
332 supportedNumSamples, SkBackingFit::kExact,
333 caps.maxWindowRectangles());
334
Robert Phillips5c7a25b2019-05-20 08:38:07 -0400335 context->deleteBackendTexture(backendTex);
Greg Danielf87651e2018-02-21 11:36:53 -0500336 }
337
Brian Salomon7578f3e2018-03-07 14:39:54 -0500338 // Tests wrapBackendTexture that is only textureable
Greg Daniel2a303902018-02-20 10:25:54 -0500339 {
340 // Internal offscreen texture
341 GrBackendTexture backendTex =
Robert Phillips4bdd36f2019-06-04 11:03:06 -0400342 context->createBackendTexture(kWidthHeight, kWidthHeight,
343 colorType,
344 SkColors::kTransparent,
345 GrMipMapped::kNo,
Robert Phillipsda2e67a2019-07-01 15:04:06 -0400346 GrRenderable::kNo,
347 GrProtected::kNo);
robertphillips76948d42016-05-04 12:47:41 -0700348
Brian Salomon7578f3e2018-03-07 14:39:54 -0500349 sk_sp<GrSurfaceProxy> sProxy = proxyProvider->wrapBackendTexture(
Robert Phillipsc80b0e92019-07-23 10:27:09 -0400350 backendTex, grColorType, origin, kBorrow_GrWrapOwnership,
351 GrWrapCacheable::kNo, kRead_GrIOType);
Greg Daniel2a303902018-02-20 10:25:54 -0500352 if (!sProxy) {
Robert Phillips5c7a25b2019-05-20 08:38:07 -0400353 context->deleteBackendTexture(backendTex);
Greg Daniel2a303902018-02-20 10:25:54 -0500354 continue;
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500355 }
Greg Daniel2a303902018-02-20 10:25:54 -0500356
357 check_surface(reporter, sProxy.get(), origin,
358 kWidthHeight, kWidthHeight,
Robert Phillipsc80b0e92019-07-23 10:27:09 -0400359 config, SkBudgeted::kNo);
Greg Daniel2a303902018-02-20 10:25:54 -0500360 check_texture(reporter, resourceProvider, sProxy->asTextureProxy(),
361 SkBackingFit::kExact);
362
Robert Phillips5c7a25b2019-05-20 08:38:07 -0400363 context->deleteBackendTexture(backendTex);
robertphillips76948d42016-05-04 12:47:41 -0700364 }
365 }
366 }
367 }
368}
369
Robert Phillips78de2122017-04-26 07:44:26 -0400370DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ZeroSizedProxyTest, reporter, ctxInfo) {
Robert Phillips0a15cc62019-07-30 12:49:10 -0400371 GrContext* context = ctxInfo.grContext();
372 GrProxyProvider* provider = context->priv().proxyProvider();
Robert Phillips78de2122017-04-26 07:44:26 -0400373
Brian Salomonf2c2ba92019-07-17 09:59:59 -0400374 for (auto renderable : {GrRenderable::kNo, GrRenderable::kYes}) {
Robert Phillips78de2122017-04-26 07:44:26 -0400375 for (auto fit : { SkBackingFit::kExact, SkBackingFit::kApprox }) {
376 for (int width : { 0, 100 }) {
377 for (int height : { 0, 100}) {
378 if (width && height) {
379 continue; // not zero-sized
380 }
381
382 GrSurfaceDesc desc;
Robert Phillips78de2122017-04-26 07:44:26 -0400383 desc.fWidth = width;
384 desc.fHeight = height;
385 desc.fConfig = kRGBA_8888_GrPixelConfig;
Robert Phillips78de2122017-04-26 07:44:26 -0400386
Greg Daniel4065d452018-11-16 15:43:41 -0500387 const GrBackendFormat format =
Robert Phillips0a15cc62019-07-30 12:49:10 -0400388 context->priv().caps()->getDefaultBackendFormat(
389 GrColorType::kRGBA_8888,
390 renderable);
Greg Daniel4065d452018-11-16 15:43:41 -0500391
Brian Salomone8a766b2019-07-19 14:24:36 -0400392 sk_sp<GrTextureProxy> proxy = provider->createProxy(
Brian Salomon27b4d8d2019-07-22 14:23:45 -0400393 format, desc, renderable, 1, kBottomLeft_GrSurfaceOrigin, fit,
Brian Salomone8a766b2019-07-19 14:24:36 -0400394 SkBudgeted::kNo, GrProtected::kNo);
Robert Phillips78de2122017-04-26 07:44:26 -0400395 REPORTER_ASSERT(reporter, !proxy);
396 }
397 }
398 }
399 }
400}