blob: 0b7f28248b053a276b28d89858e356909743a669 [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"
Brian Salomond4764a12019-08-08 12:08:24 -040024#include "src/gpu/gl/GrGLUtil.h"
robertphillips76948d42016-05-04 12:47:41 -070025
robertphillips8abb3702016-08-31 14:04:06 -070026// Check that the surface proxy's member vars are set as expected
robertphillips76948d42016-05-04 12:47:41 -070027static void check_surface(skiatest::Reporter* reporter,
28 GrSurfaceProxy* proxy,
29 GrSurfaceOrigin origin,
Greg Danielbcf612b2017-05-01 13:50:58 +000030 int width, int height,
robertphillips8abb3702016-08-31 14:04:06 -070031 GrPixelConfig config,
Robert Phillipsabacf092016-11-02 10:23:32 -040032 SkBudgeted budgeted) {
robertphillips76948d42016-05-04 12:47:41 -070033 REPORTER_ASSERT(reporter, proxy->origin() == origin);
34 REPORTER_ASSERT(reporter, proxy->width() == width);
35 REPORTER_ASSERT(reporter, proxy->height() == height);
Robert Phillipsc80b0e92019-07-23 10:27:09 -040036#ifdef SK_DEBUG
37 REPORTER_ASSERT(reporter, GrCaps::AreConfigsCompatible(config, proxy->config()));
38#endif
Robert Phillips0bd24dc2018-01-16 08:06:32 -050039 REPORTER_ASSERT(reporter, !proxy->uniqueID().isInvalid());
Robert Phillipsabacf092016-11-02 10:23:32 -040040 REPORTER_ASSERT(reporter, proxy->isBudgeted() == budgeted);
robertphillips76948d42016-05-04 12:47:41 -070041}
42
43static void check_rendertarget(skiatest::Reporter* reporter,
Robert Phillipsec2249f2016-11-09 08:54:35 -050044 const GrCaps& caps,
Brian Osman32342f02017-03-04 08:12:46 -050045 GrResourceProvider* provider,
robertphillips76948d42016-05-04 12:47:41 -070046 GrRenderTargetProxy* rtProxy,
Robert Phillipsabacf092016-11-02 10:23:32 -040047 int numSamples,
Robert Phillipsec2249f2016-11-09 08:54:35 -050048 SkBackingFit fit,
Greg Daniel2a303902018-02-20 10:25:54 -050049 int expectedMaxWindowRects) {
Robert Phillipsec2249f2016-11-09 08:54:35 -050050 REPORTER_ASSERT(reporter, rtProxy->maxWindowRectangles(caps) == expectedMaxWindowRects);
Chris Dalton6ce447a2019-06-23 18:07:38 -060051 REPORTER_ASSERT(reporter, rtProxy->numSamples() == numSamples);
Robert Phillipsabacf092016-11-02 10:23:32 -040052
Robert Phillips294870f2016-11-11 12:38:40 -050053 GrSurfaceProxy::UniqueID idBefore = rtProxy->uniqueID();
Brian Salomonfd98c2c2018-07-31 17:25:29 -040054 bool preinstantiated = rtProxy->isInstantiated();
Robert Phillipseee4d6e2017-06-05 09:26:07 -040055 REPORTER_ASSERT(reporter, rtProxy->instantiate(provider));
Brian Salomonfd98c2c2018-07-31 17:25:29 -040056 GrRenderTarget* rt = rtProxy->peekRenderTarget();
robertphillips76948d42016-05-04 12:47:41 -070057
Robert Phillips294870f2016-11-11 12:38:40 -050058 REPORTER_ASSERT(reporter, rtProxy->uniqueID() == idBefore);
Greg Daniel2a303902018-02-20 10:25:54 -050059 // Deferred resources should always have a different ID from their instantiated rendertarget
Brian Salomonf7778972018-03-08 10:13:17 -050060 if (preinstantiated) {
61 REPORTER_ASSERT(reporter, rtProxy->uniqueID().asUInt() == rt->uniqueID().asUInt());
62 } else {
63 REPORTER_ASSERT(reporter, rtProxy->uniqueID().asUInt() != rt->uniqueID().asUInt());
64 }
Robert Phillips294870f2016-11-11 12:38:40 -050065
robertphillips76948d42016-05-04 12:47:41 -070066 if (SkBackingFit::kExact == fit) {
67 REPORTER_ASSERT(reporter, rt->width() == rtProxy->width());
68 REPORTER_ASSERT(reporter, rt->height() == rtProxy->height());
69 } else {
70 REPORTER_ASSERT(reporter, rt->width() >= rtProxy->width());
Robert Phillips294870f2016-11-11 12:38:40 -050071 REPORTER_ASSERT(reporter, rt->height() >= rtProxy->height());
robertphillips76948d42016-05-04 12:47:41 -070072 }
73 REPORTER_ASSERT(reporter, rt->config() == rtProxy->config());
74
Chris Dalton6ce447a2019-06-23 18:07:38 -060075 REPORTER_ASSERT(reporter, rt->numSamples() == rtProxy->numSamples());
Robert Phillipsfe0253f2018-03-16 16:47:25 -040076 REPORTER_ASSERT(reporter, rt->surfacePriv().flags() == rtProxy->testingOnly_getFlags());
robertphillips76948d42016-05-04 12:47:41 -070077}
78
79static void check_texture(skiatest::Reporter* reporter,
Brian Osman32342f02017-03-04 08:12:46 -050080 GrResourceProvider* provider,
robertphillips76948d42016-05-04 12:47:41 -070081 GrTextureProxy* texProxy,
Greg Daniel2a303902018-02-20 10:25:54 -050082 SkBackingFit fit) {
Robert Phillips294870f2016-11-11 12:38:40 -050083 GrSurfaceProxy::UniqueID idBefore = texProxy->uniqueID();
Robert Phillipseee4d6e2017-06-05 09:26:07 -040084
Brian Salomonfd98c2c2018-07-31 17:25:29 -040085 bool preinstantiated = texProxy->isInstantiated();
Michael Ludwigbd2f0702019-09-13 15:29:41 -040086 // The instantiated texture should have these dimensions. If the fit is kExact, then
87 // 'worst-case' reports the original WxH. If it is kApprox, make sure that the texture
88 // is that size and didn't reuse one of the kExact surfaces in the provider. This is important
89 // because upstream usage (e.g. SkImage) reports size based on the worst case dimensions and
90 // client code may rely on that if they are creating backend resources.
91 // NOTE: we store these before instantiating, since after instantiation worstCaseWH() just
92 // return the target's dimensions. In this instance, we want to ensure the target's dimensions
93 // are no different from the original approximate (or exact) dimensions.
94 int expectedWidth = texProxy->worstCaseWidth();
95 int expectedHeight = texProxy->worstCaseHeight();
96
Robert Phillipseee4d6e2017-06-05 09:26:07 -040097 REPORTER_ASSERT(reporter, texProxy->instantiate(provider));
Brian Salomonfd98c2c2018-07-31 17:25:29 -040098 GrTexture* tex = texProxy->peekTexture();
robertphillips76948d42016-05-04 12:47:41 -070099
Robert Phillips294870f2016-11-11 12:38:40 -0500100 REPORTER_ASSERT(reporter, texProxy->uniqueID() == idBefore);
Greg Daniel2a303902018-02-20 10:25:54 -0500101 // Deferred resources should always have a different ID from their instantiated texture
Brian Salomonf7778972018-03-08 10:13:17 -0500102 if (preinstantiated) {
103 REPORTER_ASSERT(reporter, texProxy->uniqueID().asUInt() == tex->uniqueID().asUInt());
104 } else {
105 REPORTER_ASSERT(reporter, texProxy->uniqueID().asUInt() != tex->uniqueID().asUInt());
106 }
Robert Phillips294870f2016-11-11 12:38:40 -0500107
Michael Ludwigbd2f0702019-09-13 15:29:41 -0400108 REPORTER_ASSERT(reporter, tex->width() == expectedWidth);
109 REPORTER_ASSERT(reporter, tex->height() == expectedHeight);
110
robertphillips76948d42016-05-04 12:47:41 -0700111 REPORTER_ASSERT(reporter, tex->config() == texProxy->config());
112}
113
114
robertphillips8abb3702016-08-31 14:04:06 -0700115DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DeferredProxyTest, reporter, ctxInfo) {
Robert Phillips9da87e02019-02-04 13:26:26 -0500116 GrProxyProvider* proxyProvider = ctxInfo.grContext()->priv().proxyProvider();
117 GrResourceProvider* resourceProvider = ctxInfo.grContext()->priv().resourceProvider();
118 const GrCaps& caps = *ctxInfo.grContext()->priv().caps();
robertphillips76948d42016-05-04 12:47:41 -0700119
Robert Phillips6520a692017-02-01 09:20:00 -0500120 int attempt = 0; // useful for debugging
121
robertphillips76948d42016-05-04 12:47:41 -0700122 for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin }) {
Robert Phillips40d94952017-01-30 14:15:59 -0500123 for (auto widthHeight : { 100, 128, 1048576 }) {
Robert Phillipsa5e78be2019-07-09 12:34:38 -0400124 for (auto ct : { GrColorType::kAlpha_8, GrColorType::kBGR_565,
125 GrColorType::kRGBA_8888, GrColorType::kRGBA_1010102 } ) {
robertphillips76948d42016-05-04 12:47:41 -0700126 for (auto fit : { SkBackingFit::kExact, SkBackingFit::kApprox }) {
127 for (auto budgeted : { SkBudgeted::kYes, SkBudgeted::kNo }) {
Brian Salomonbdecacf2018-02-02 20:32:49 -0500128 for (auto numSamples : {1, 4, 16, 128}) {
Robert Phillipsa5e78be2019-07-09 12:34:38 -0400129
Greg Daniele877dce2019-07-11 10:52:43 -0400130 auto config = GrColorTypeToPixelConfig(ct);
Robert Phillipsa5e78be2019-07-09 12:34:38 -0400131 SkASSERT(kUnknown_GrPixelConfig != config);
Jim Van Verth1676cb92019-01-15 13:24:45 -0500132
robertphillips76948d42016-05-04 12:47:41 -0700133 GrSurfaceDesc desc;
robertphillips76948d42016-05-04 12:47:41 -0700134 desc.fWidth = widthHeight;
135 desc.fHeight = widthHeight;
136 desc.fConfig = config;
robertphillips76948d42016-05-04 12:47:41 -0700137
Robert Phillips0a15cc62019-07-30 12:49:10 -0400138 auto format = caps.getDefaultBackendFormat(ct, GrRenderable::kYes);
Greg Danielfa55f2e2019-06-13 15:21:38 -0400139 if (!format.isValid()) {
140 continue;
141 }
Greg Daniel4065d452018-11-16 15:43:41 -0500142
Brian Salomonf2c2ba92019-07-17 09:59:59 -0400143 // Renderable
Robert Phillips6520a692017-02-01 09:20:00 -0500144 {
145 sk_sp<GrTexture> tex;
146 if (SkBackingFit::kApprox == fit) {
Chris Daltond004e0b2018-09-27 09:28:03 -0600147 tex = resourceProvider->createApproxTexture(
Brian Salomon4eb38b72019-08-05 12:58:39 -0400148 desc, format, GrRenderable::kYes, numSamples,
Robert Phillipsaee18c92019-09-06 11:48:27 -0400149 GrProtected::kNo);
Robert Phillips6520a692017-02-01 09:20:00 -0500150 } else {
Robert Phillips9313aa72019-04-09 18:41:27 -0400151 tex = resourceProvider->createTexture(
Brian Salomona90382f2019-09-17 09:01:56 -0400152 desc, format, GrRenderable::kYes, numSamples,
153 GrMipMapped::kNo, budgeted, GrProtected::kNo);
Robert Phillips6520a692017-02-01 09:20:00 -0500154 }
155
Brian Salomonf2c2ba92019-07-17 09:59:59 -0400156 sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(
Brian Salomonbeb7f522019-08-30 16:19:42 -0400157 format, desc, GrRenderable::kYes, numSamples, origin,
158 GrMipMapped::kNo, fit, budgeted, GrProtected::kNo);
Robert Phillips2f493142017-03-02 18:18:38 -0500159 REPORTER_ASSERT(reporter, SkToBool(tex) == SkToBool(proxy));
160 if (proxy) {
161 REPORTER_ASSERT(reporter, proxy->asRenderTargetProxy());
Robert Phillips40d94952017-01-30 14:15:59 -0500162 // This forces the proxy to compute and cache its
163 // pre-instantiation size guess. Later, when it is actually
164 // instantiated, it checks that the instantiated size is <= to
165 // the pre-computation. If the proxy never computed its
166 // pre-instantiation size then the check is skipped.
Robert Phillips2f493142017-03-02 18:18:38 -0500167 proxy->gpuMemorySize();
Robert Phillipsb4460882016-11-17 14:43:51 -0500168
Robert Phillips2f493142017-03-02 18:18:38 -0500169 check_surface(reporter, proxy.get(), origin,
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500170 widthHeight, widthHeight, config, budgeted);
Brian Salomonbdecacf2018-02-02 20:32:49 -0500171 int supportedSamples =
Greg Daniel6fa62e22019-08-07 15:52:37 -0400172 caps.getRenderTargetSampleCount(numSamples, format);
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500173 check_rendertarget(reporter, caps, resourceProvider,
Robert Phillips2f493142017-03-02 18:18:38 -0500174 proxy->asRenderTargetProxy(),
Greg Daniel81e7bf82017-07-19 14:47:42 -0400175 supportedSamples,
Greg Daniel2a303902018-02-20 10:25:54 -0500176 fit, caps.maxWindowRectangles());
Robert Phillips40d94952017-01-30 14:15:59 -0500177 }
robertphillips76948d42016-05-04 12:47:41 -0700178 }
179
Brian Salomonf2c2ba92019-07-17 09:59:59 -0400180 // Not renderable
Robert Phillips6520a692017-02-01 09:20:00 -0500181 {
182 sk_sp<GrTexture> tex;
183 if (SkBackingFit::kApprox == fit) {
Chris Daltond004e0b2018-09-27 09:28:03 -0600184 tex = resourceProvider->createApproxTexture(
Brian Salomon4eb38b72019-08-05 12:58:39 -0400185 desc, format, GrRenderable::kNo, numSamples,
Robert Phillipsaee18c92019-09-06 11:48:27 -0400186 GrProtected::kNo);
Robert Phillips6520a692017-02-01 09:20:00 -0500187 } else {
Robert Phillips9313aa72019-04-09 18:41:27 -0400188 tex = resourceProvider->createTexture(
Brian Salomona90382f2019-09-17 09:01:56 -0400189 desc, format, GrRenderable::kNo, numSamples,
190 GrMipMapped::kNo, budgeted, GrProtected::kNo);
Robert Phillips6520a692017-02-01 09:20:00 -0500191 }
Robert Phillipsb4460882016-11-17 14:43:51 -0500192
Brian Salomonf2c2ba92019-07-17 09:59:59 -0400193 sk_sp<GrTextureProxy> proxy(proxyProvider->createProxy(
Brian Salomonbeb7f522019-08-30 16:19:42 -0400194 format, desc, GrRenderable::kNo, numSamples, origin,
195 GrMipMapped::kNo, fit, budgeted, GrProtected::kNo));
Robert Phillips2f493142017-03-02 18:18:38 -0500196 REPORTER_ASSERT(reporter, SkToBool(tex) == SkToBool(proxy));
197 if (proxy) {
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500198 // This forces the proxy to compute and cache its
199 // pre-instantiation size guess. Later, when it is actually
200 // instantiated, it checks that the instantiated size is <= to
201 // the pre-computation. If the proxy never computed its
202 // pre-instantiation size then the check is skipped.
Robert Phillips2f493142017-03-02 18:18:38 -0500203 proxy->gpuMemorySize();
Robert Phillips6520a692017-02-01 09:20:00 -0500204
Robert Phillips2f493142017-03-02 18:18:38 -0500205 check_surface(reporter, proxy.get(), origin,
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500206 widthHeight, widthHeight, config, budgeted);
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500207 check_texture(reporter, resourceProvider,
Greg Daniel2a303902018-02-20 10:25:54 -0500208 proxy->asTextureProxy(), fit);
Robert Phillips6520a692017-02-01 09:20:00 -0500209 }
Robert Phillips40d94952017-01-30 14:15:59 -0500210 }
Robert Phillips6520a692017-02-01 09:20:00 -0500211
212 attempt++;
robertphillips76948d42016-05-04 12:47:41 -0700213 }
214 }
215 }
216 }
217 }
218 }
219}
220
egdanielab527a52016-06-28 08:07:26 -0700221DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WrappedProxyTest, reporter, ctxInfo) {
Robert Phillips9da87e02019-02-04 13:26:26 -0500222 GrProxyProvider* proxyProvider = ctxInfo.grContext()->priv().proxyProvider();
Robert Phillips9b16f812019-05-17 10:01:21 -0400223 GrContext* context = ctxInfo.grContext();
224 GrResourceProvider* resourceProvider = context->priv().resourceProvider();
225 GrGpu* gpu = context->priv().getGpu();
226 const GrCaps& caps = *context->priv().caps();
robertphillips76948d42016-05-04 12:47:41 -0700227
228 static const int kWidthHeight = 100;
229
230 for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin }) {
Brian Osman10fc6fd2018-03-02 11:01:10 -0500231 for (auto colorType : { kAlpha_8_SkColorType, kRGBA_8888_SkColorType,
232 kRGBA_1010102_SkColorType }) {
Greg Daniel627d0532019-07-08 16:48:14 -0400233 GrColorType grColorType = SkColorTypeToGrColorType(colorType);
Robert Phillipsc80b0e92019-07-23 10:27:09 -0400234 GrPixelConfig config = GrColorTypeToPixelConfig(grColorType);
235 SkASSERT(kUnknown_GrPixelConfig != config);
236
Brian Salomon52e943a2018-03-13 09:32:39 -0400237 // External on-screen render target.
238 // Tests wrapBackendRenderTarget with a GrBackendRenderTarget
239 // Our test-only function that creates a backend render target doesn't currently support
240 // sample counts :(.
241 if (ctxInfo.grContext()->colorTypeSupportedAsSurface(colorType)) {
242 GrBackendRenderTarget backendRT = gpu->createTestingOnlyBackendRenderTarget(
Greg Daniel627d0532019-07-08 16:48:14 -0400243 kWidthHeight, kWidthHeight, grColorType);
Brian Salomon52e943a2018-03-13 09:32:39 -0400244 sk_sp<GrSurfaceProxy> sProxy(
Robert Phillipsc80b0e92019-07-23 10:27:09 -0400245 proxyProvider->wrapBackendRenderTarget(backendRT, grColorType,
246 origin, nullptr, nullptr));
Brian Salomon52e943a2018-03-13 09:32:39 -0400247 check_surface(reporter, sProxy.get(), origin, kWidthHeight, kWidthHeight,
Robert Phillipsc80b0e92019-07-23 10:27:09 -0400248 config, SkBudgeted::kNo);
Brian Salomon52e943a2018-03-13 09:32:39 -0400249 static constexpr int kExpectedNumSamples = 1;
250 check_rendertarget(reporter, caps, resourceProvider, sProxy->asRenderTargetProxy(),
251 kExpectedNumSamples, SkBackingFit::kExact,
252 caps.maxWindowRectangles());
253 gpu->deleteTestingOnlyBackendRenderTarget(backendRT);
254 }
255
Greg Daniel2a303902018-02-20 10:25:54 -0500256 for (auto numSamples : {1, 4}) {
Greg Daniel6fa62e22019-08-07 15:52:37 -0400257 auto beFormat = caps.getDefaultBackendFormat(grColorType, GrRenderable::kYes);
258 int supportedNumSamples = caps.getRenderTargetSampleCount(numSamples, beFormat);
Greg Daniel2a303902018-02-20 10:25:54 -0500259 if (!supportedNumSamples) {
260 continue;
261 }
robertphillips76948d42016-05-04 12:47:41 -0700262
Brian Salomon52e943a2018-03-13 09:32:39 -0400263 // Test wrapping FBO 0 (with made up properties). This tests sample count and the
264 // special case where FBO 0 doesn't support window rectangles.
Greg Danielbdf12ad2018-10-12 09:31:11 -0400265 if (GrBackendApi::kOpenGL == ctxInfo.backend()) {
Greg Daniel2a303902018-02-20 10:25:54 -0500266 GrGLFramebufferInfo fboInfo;
267 fboInfo.fFBOID = 0;
Brian Salomond4764a12019-08-08 12:08:24 -0400268 fboInfo.fFormat = GrGLFormatToEnum(beFormat.asGLFormat());
269 SkASSERT(fboInfo.fFormat);
Brian Salomon52e943a2018-03-13 09:32:39 -0400270 static constexpr int kStencilBits = 8;
271 GrBackendRenderTarget backendRT(kWidthHeight, kWidthHeight, numSamples,
Greg Daniel108bb232018-07-03 16:18:29 -0400272 kStencilBits, fboInfo);
Brian Salomon7578f3e2018-03-07 14:39:54 -0500273 sk_sp<GrSurfaceProxy> sProxy(
Robert Phillipsc80b0e92019-07-23 10:27:09 -0400274 proxyProvider->wrapBackendRenderTarget(backendRT, grColorType,
275 origin, nullptr, nullptr));
Greg Daniel2a303902018-02-20 10:25:54 -0500276 check_surface(reporter, sProxy.get(), origin,
277 kWidthHeight, kWidthHeight,
Robert Phillipsc80b0e92019-07-23 10:27:09 -0400278 config, SkBudgeted::kNo);
Greg Daniel2a303902018-02-20 10:25:54 -0500279 check_rendertarget(reporter, caps, resourceProvider,
280 sProxy->asRenderTargetProxy(),
281 supportedNumSamples, SkBackingFit::kExact, 0);
282 }
283
Brian Salomon7578f3e2018-03-07 14:39:54 -0500284 // Tests wrapBackendRenderTarget with a GrBackendTexture
Greg Daniel2a303902018-02-20 10:25:54 -0500285 {
286 GrBackendTexture backendTex =
Robert Phillips4bdd36f2019-06-04 11:03:06 -0400287 context->createBackendTexture(kWidthHeight, kWidthHeight,
288 colorType,
289 SkColors::kTransparent,
290 GrMipMapped::kNo,
Robert Phillipsda2e67a2019-07-01 15:04:06 -0400291 GrRenderable::kYes,
292 GrProtected::kNo);
Brian Salomon7578f3e2018-03-07 14:39:54 -0500293 sk_sp<GrSurfaceProxy> sProxy = proxyProvider->wrapBackendTextureAsRenderTarget(
Robert Phillipsc80b0e92019-07-23 10:27:09 -0400294 backendTex, grColorType, origin, supportedNumSamples);
Greg Daniel2a303902018-02-20 10:25:54 -0500295 if (!sProxy) {
Robert Phillips5c7a25b2019-05-20 08:38:07 -0400296 context->deleteBackendTexture(backendTex);
Greg Daniel2a303902018-02-20 10:25:54 -0500297 continue; // This can fail on Mesa
csmartdaltonf9635992016-08-10 11:09:07 -0700298 }
299
Greg Daniel2a303902018-02-20 10:25:54 -0500300 check_surface(reporter, sProxy.get(), origin,
301 kWidthHeight, kWidthHeight,
Robert Phillipsc80b0e92019-07-23 10:27:09 -0400302 config, SkBudgeted::kNo);
Greg Daniel2a303902018-02-20 10:25:54 -0500303 check_rendertarget(reporter, caps, resourceProvider,
304 sProxy->asRenderTargetProxy(),
305 supportedNumSamples, SkBackingFit::kExact,
306 caps.maxWindowRectangles());
robertphillips76948d42016-05-04 12:47:41 -0700307
Robert Phillips5c7a25b2019-05-20 08:38:07 -0400308 context->deleteBackendTexture(backendTex);
Greg Daniel2a303902018-02-20 10:25:54 -0500309 }
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500310
Brian Salomon7578f3e2018-03-07 14:39:54 -0500311 // Tests wrapBackendTexture that is only renderable
Greg Danielf87651e2018-02-21 11:36:53 -0500312 {
313 GrBackendTexture backendTex =
Robert Phillips4bdd36f2019-06-04 11:03:06 -0400314 context->createBackendTexture(kWidthHeight, kWidthHeight,
315 colorType,
316 SkColors::kTransparent,
317 GrMipMapped::kNo,
Robert Phillipsda2e67a2019-07-01 15:04:06 -0400318 GrRenderable::kYes,
319 GrProtected::kNo);
Greg Danielf87651e2018-02-21 11:36:53 -0500320
Brian Salomon7578f3e2018-03-07 14:39:54 -0500321 sk_sp<GrSurfaceProxy> sProxy = proxyProvider->wrapRenderableBackendTexture(
Robert Phillips0902c982019-07-16 07:47:56 -0400322 backendTex, origin, supportedNumSamples,
323 grColorType, kBorrow_GrWrapOwnership,
Greg Daniel8ce79912019-02-05 10:08:43 -0500324 GrWrapCacheable::kNo, nullptr, nullptr);
Greg Danielf87651e2018-02-21 11:36:53 -0500325 if (!sProxy) {
Robert Phillips5c7a25b2019-05-20 08:38:07 -0400326 context->deleteBackendTexture(backendTex);
Greg Danielf87651e2018-02-21 11:36:53 -0500327 continue; // This can fail on Mesa
328 }
329
330 check_surface(reporter, sProxy.get(), origin,
331 kWidthHeight, kWidthHeight,
Robert Phillipsc80b0e92019-07-23 10:27:09 -0400332 config, SkBudgeted::kNo);
Greg Danielf87651e2018-02-21 11:36:53 -0500333 check_rendertarget(reporter, caps, resourceProvider,
334 sProxy->asRenderTargetProxy(),
335 supportedNumSamples, SkBackingFit::kExact,
336 caps.maxWindowRectangles());
337
Robert Phillips5c7a25b2019-05-20 08:38:07 -0400338 context->deleteBackendTexture(backendTex);
Greg Danielf87651e2018-02-21 11:36:53 -0500339 }
340
Brian Salomon7578f3e2018-03-07 14:39:54 -0500341 // Tests wrapBackendTexture that is only textureable
Greg Daniel2a303902018-02-20 10:25:54 -0500342 {
343 // Internal offscreen texture
344 GrBackendTexture backendTex =
Robert Phillips4bdd36f2019-06-04 11:03:06 -0400345 context->createBackendTexture(kWidthHeight, kWidthHeight,
346 colorType,
347 SkColors::kTransparent,
348 GrMipMapped::kNo,
Robert Phillipsda2e67a2019-07-01 15:04:06 -0400349 GrRenderable::kNo,
350 GrProtected::kNo);
robertphillips76948d42016-05-04 12:47:41 -0700351
Brian Salomon7578f3e2018-03-07 14:39:54 -0500352 sk_sp<GrSurfaceProxy> sProxy = proxyProvider->wrapBackendTexture(
Robert Phillipsc80b0e92019-07-23 10:27:09 -0400353 backendTex, grColorType, origin, kBorrow_GrWrapOwnership,
354 GrWrapCacheable::kNo, kRead_GrIOType);
Greg Daniel2a303902018-02-20 10:25:54 -0500355 if (!sProxy) {
Robert Phillips5c7a25b2019-05-20 08:38:07 -0400356 context->deleteBackendTexture(backendTex);
Greg Daniel2a303902018-02-20 10:25:54 -0500357 continue;
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500358 }
Greg Daniel2a303902018-02-20 10:25:54 -0500359
360 check_surface(reporter, sProxy.get(), origin,
361 kWidthHeight, kWidthHeight,
Robert Phillipsc80b0e92019-07-23 10:27:09 -0400362 config, SkBudgeted::kNo);
Greg Daniel2a303902018-02-20 10:25:54 -0500363 check_texture(reporter, resourceProvider, sProxy->asTextureProxy(),
364 SkBackingFit::kExact);
365
Robert Phillips5c7a25b2019-05-20 08:38:07 -0400366 context->deleteBackendTexture(backendTex);
robertphillips76948d42016-05-04 12:47:41 -0700367 }
368 }
369 }
370 }
371}
372
Robert Phillips78de2122017-04-26 07:44:26 -0400373DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ZeroSizedProxyTest, reporter, ctxInfo) {
Robert Phillips0a15cc62019-07-30 12:49:10 -0400374 GrContext* context = ctxInfo.grContext();
375 GrProxyProvider* provider = context->priv().proxyProvider();
Robert Phillips78de2122017-04-26 07:44:26 -0400376
Brian Salomonf2c2ba92019-07-17 09:59:59 -0400377 for (auto renderable : {GrRenderable::kNo, GrRenderable::kYes}) {
Robert Phillips78de2122017-04-26 07:44:26 -0400378 for (auto fit : { SkBackingFit::kExact, SkBackingFit::kApprox }) {
379 for (int width : { 0, 100 }) {
380 for (int height : { 0, 100}) {
381 if (width && height) {
382 continue; // not zero-sized
383 }
384
385 GrSurfaceDesc desc;
Robert Phillips78de2122017-04-26 07:44:26 -0400386 desc.fWidth = width;
387 desc.fHeight = height;
388 desc.fConfig = kRGBA_8888_GrPixelConfig;
Robert Phillips78de2122017-04-26 07:44:26 -0400389
Greg Daniel4065d452018-11-16 15:43:41 -0500390 const GrBackendFormat format =
Robert Phillips0a15cc62019-07-30 12:49:10 -0400391 context->priv().caps()->getDefaultBackendFormat(
392 GrColorType::kRGBA_8888,
393 renderable);
Greg Daniel4065d452018-11-16 15:43:41 -0500394
Brian Salomone8a766b2019-07-19 14:24:36 -0400395 sk_sp<GrTextureProxy> proxy = provider->createProxy(
Brian Salomonbeb7f522019-08-30 16:19:42 -0400396 format, desc, renderable, 1, kBottomLeft_GrSurfaceOrigin,
397 GrMipMapped::kNo, fit, SkBudgeted::kNo, GrProtected::kNo);
Robert Phillips78de2122017-04-26 07:44:26 -0400398 REPORTER_ASSERT(reporter, !proxy);
399 }
400 }
401 }
402 }
403}