blob: 5721a41b6b22a58479f9c6406156e360daddf84d [file] [log] [blame]
robertphillips76948d42016-05-04 12:47:41 -07001/*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8// This is a GPU-backend specific test.
9
10#include "Test.h"
11
12#if SK_SUPPORT_GPU
Robert Phillips8bf1f9f2017-05-31 15:01:20 -040013
Greg Danielbcf612b2017-05-01 13:50:58 +000014#include "GrBackendSurface.h"
Robert Phillips1afd4cd2018-01-08 13:40:32 -050015#include "GrContextPriv.h"
Robert Phillips0bd24dc2018-01-16 08:06:32 -050016#include "GrProxyProvider.h"
Robert Phillipsc7635fa2016-10-28 13:25:24 -040017#include "GrRenderTargetPriv.h"
robertphillips76948d42016-05-04 12:47:41 -070018#include "GrRenderTargetProxy.h"
Brian Osman32342f02017-03-04 08:12:46 -050019#include "GrResourceProvider.h"
Robert Phillipsfe0253f2018-03-16 16:47:25 -040020#include "GrSurfacePriv.h"
Robert Phillipsf95b1752017-08-31 08:56:07 -040021#include "GrSurfaceProxyPriv.h"
Robert Phillips646e4292017-06-13 12:44:56 -040022#include "GrTexture.h"
Brian Osman32342f02017-03-04 08:12:46 -050023#include "GrTextureProxy.h"
Greg Daniel2a303902018-02-20 10:25:54 -050024#include "SkGr.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);
36 REPORTER_ASSERT(reporter, proxy->config() == config);
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);
Robert Phillipsabacf092016-11-02 10:23:32 -040049 REPORTER_ASSERT(reporter, rtProxy->numStencilSamples() == numSamples);
50
Robert Phillips294870f2016-11-11 12:38:40 -050051 GrSurfaceProxy::UniqueID idBefore = rtProxy->uniqueID();
Brian Salomonf7778972018-03-08 10:13:17 -050052 bool preinstantiated = rtProxy->priv().isInstantiated();
Robert Phillipseee4d6e2017-06-05 09:26:07 -040053 REPORTER_ASSERT(reporter, rtProxy->instantiate(provider));
54 GrRenderTarget* rt = rtProxy->priv().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) {
65 REPORTER_ASSERT(reporter, rt->width() == rtProxy->width());
66 REPORTER_ASSERT(reporter, rt->height() == rtProxy->height());
67 } else {
68 REPORTER_ASSERT(reporter, rt->width() >= rtProxy->width());
Robert Phillips294870f2016-11-11 12:38:40 -050069 REPORTER_ASSERT(reporter, rt->height() >= rtProxy->height());
robertphillips76948d42016-05-04 12:47:41 -070070 }
71 REPORTER_ASSERT(reporter, rt->config() == rtProxy->config());
72
Brian Salomon7c8460e2017-05-12 11:36:10 -040073 REPORTER_ASSERT(reporter, rt->fsaaType() == rtProxy->fsaaType());
robertphillips76948d42016-05-04 12:47:41 -070074 REPORTER_ASSERT(reporter, rt->numColorSamples() == rtProxy->numColorSamples());
75 REPORTER_ASSERT(reporter, rt->numStencilSamples() == rtProxy->numStencilSamples());
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 Salomonf7778972018-03-08 10:13:17 -050085 bool preinstantiated = texProxy->priv().isInstantiated();
Robert Phillipseee4d6e2017-06-05 09:26:07 -040086 REPORTER_ASSERT(reporter, texProxy->instantiate(provider));
87 GrTexture* tex = texProxy->priv().peekTexture();
robertphillips76948d42016-05-04 12:47:41 -070088
Robert Phillips294870f2016-11-11 12:38:40 -050089 REPORTER_ASSERT(reporter, texProxy->uniqueID() == idBefore);
Greg Daniel2a303902018-02-20 10:25:54 -050090 // Deferred resources should always have a different ID from their instantiated texture
Brian Salomonf7778972018-03-08 10:13:17 -050091 if (preinstantiated) {
92 REPORTER_ASSERT(reporter, texProxy->uniqueID().asUInt() == tex->uniqueID().asUInt());
93 } else {
94 REPORTER_ASSERT(reporter, texProxy->uniqueID().asUInt() != tex->uniqueID().asUInt());
95 }
Robert Phillips294870f2016-11-11 12:38:40 -050096
robertphillips76948d42016-05-04 12:47:41 -070097 if (SkBackingFit::kExact == fit) {
98 REPORTER_ASSERT(reporter, tex->width() == texProxy->width());
99 REPORTER_ASSERT(reporter, tex->height() == texProxy->height());
100 } else {
101 REPORTER_ASSERT(reporter, tex->width() >= texProxy->width());
102 REPORTER_ASSERT(reporter, tex->height() >= texProxy->height());
103 }
104 REPORTER_ASSERT(reporter, tex->config() == texProxy->config());
105}
106
107
robertphillips8abb3702016-08-31 14:04:06 -0700108DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DeferredProxyTest, reporter, ctxInfo) {
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500109 GrProxyProvider* proxyProvider = ctxInfo.grContext()->contextPriv().proxyProvider();
Robert Phillips6be756b2018-01-16 15:07:54 -0500110 GrResourceProvider* resourceProvider = ctxInfo.grContext()->contextPriv().resourceProvider();
Robert Phillipsabacf092016-11-02 10:23:32 -0400111 const GrCaps& caps = *ctxInfo.grContext()->caps();
robertphillips76948d42016-05-04 12:47:41 -0700112
Robert Phillips6520a692017-02-01 09:20:00 -0500113 int attempt = 0; // useful for debugging
114
robertphillips76948d42016-05-04 12:47:41 -0700115 for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin }) {
Robert Phillips40d94952017-01-30 14:15:59 -0500116 for (auto widthHeight : { 100, 128, 1048576 }) {
Robert Phillips6520a692017-02-01 09:20:00 -0500117 for (auto config : { kAlpha_8_GrPixelConfig, kRGB_565_GrPixelConfig,
Brian Osman10fc6fd2018-03-02 11:01:10 -0500118 kRGBA_8888_GrPixelConfig, kRGBA_1010102_GrPixelConfig }) {
robertphillips76948d42016-05-04 12:47:41 -0700119 for (auto fit : { SkBackingFit::kExact, SkBackingFit::kApprox }) {
120 for (auto budgeted : { SkBudgeted::kYes, SkBudgeted::kNo }) {
Brian Salomonbdecacf2018-02-02 20:32:49 -0500121 for (auto numSamples : {1, 4, 16, 128}) {
robertphillips76948d42016-05-04 12:47:41 -0700122 GrSurfaceDesc desc;
Robert Phillips84a81202016-11-04 11:59:10 -0400123 desc.fFlags = kRenderTarget_GrSurfaceFlag;
robertphillips76948d42016-05-04 12:47:41 -0700124 desc.fWidth = widthHeight;
125 desc.fHeight = widthHeight;
126 desc.fConfig = config;
127 desc.fSampleCnt = numSamples;
128
Robert Phillips6520a692017-02-01 09:20:00 -0500129 {
130 sk_sp<GrTexture> tex;
131 if (SkBackingFit::kApprox == fit) {
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500132 tex = resourceProvider->createApproxTexture(desc, 0);
Robert Phillips6520a692017-02-01 09:20:00 -0500133 } else {
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500134 tex = resourceProvider->createTexture(desc, budgeted);
Robert Phillips6520a692017-02-01 09:20:00 -0500135 }
136
Brian Salomon2a4f9832018-03-03 22:43:43 -0500137 sk_sp<GrTextureProxy> proxy =
138 proxyProvider->createProxy(desc, origin, fit, budgeted);
Robert Phillips2f493142017-03-02 18:18:38 -0500139 REPORTER_ASSERT(reporter, SkToBool(tex) == SkToBool(proxy));
140 if (proxy) {
141 REPORTER_ASSERT(reporter, proxy->asRenderTargetProxy());
Robert Phillips40d94952017-01-30 14:15:59 -0500142 // This forces the proxy to compute and cache its
143 // pre-instantiation size guess. Later, when it is actually
144 // instantiated, it checks that the instantiated size is <= to
145 // the pre-computation. If the proxy never computed its
146 // pre-instantiation size then the check is skipped.
Robert Phillips2f493142017-03-02 18:18:38 -0500147 proxy->gpuMemorySize();
Robert Phillipsb4460882016-11-17 14:43:51 -0500148
Robert Phillips2f493142017-03-02 18:18:38 -0500149 check_surface(reporter, proxy.get(), origin,
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500150 widthHeight, widthHeight, config, budgeted);
Brian Salomonbdecacf2018-02-02 20:32:49 -0500151 int supportedSamples =
152 caps.getRenderTargetSampleCount(numSamples, config);
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500153 check_rendertarget(reporter, caps, resourceProvider,
Robert Phillips2f493142017-03-02 18:18:38 -0500154 proxy->asRenderTargetProxy(),
Greg Daniel81e7bf82017-07-19 14:47:42 -0400155 supportedSamples,
Greg Daniel2a303902018-02-20 10:25:54 -0500156 fit, caps.maxWindowRectangles());
Robert Phillips40d94952017-01-30 14:15:59 -0500157 }
robertphillips76948d42016-05-04 12:47:41 -0700158 }
159
Robert Phillips84a81202016-11-04 11:59:10 -0400160 desc.fFlags = kNone_GrSurfaceFlags;
robertphillips76948d42016-05-04 12:47:41 -0700161
Robert Phillips6520a692017-02-01 09:20:00 -0500162 {
163 sk_sp<GrTexture> tex;
164 if (SkBackingFit::kApprox == fit) {
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500165 tex = resourceProvider->createApproxTexture(desc, 0);
Robert Phillips6520a692017-02-01 09:20:00 -0500166 } else {
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500167 tex = resourceProvider->createTexture(desc, budgeted);
Robert Phillips6520a692017-02-01 09:20:00 -0500168 }
Robert Phillipsb4460882016-11-17 14:43:51 -0500169
Brian Salomon2a4f9832018-03-03 22:43:43 -0500170 sk_sp<GrTextureProxy> proxy(
171 proxyProvider->createProxy(desc, origin, fit, budgeted));
Robert Phillips2f493142017-03-02 18:18:38 -0500172 REPORTER_ASSERT(reporter, SkToBool(tex) == SkToBool(proxy));
173 if (proxy) {
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500174 // This forces the proxy to compute and cache its
175 // pre-instantiation size guess. Later, when it is actually
176 // instantiated, it checks that the instantiated size is <= to
177 // the pre-computation. If the proxy never computed its
178 // pre-instantiation size then the check is skipped.
Robert Phillips2f493142017-03-02 18:18:38 -0500179 proxy->gpuMemorySize();
Robert Phillips6520a692017-02-01 09:20:00 -0500180
Robert Phillips2f493142017-03-02 18:18:38 -0500181 check_surface(reporter, proxy.get(), origin,
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500182 widthHeight, widthHeight, config, budgeted);
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500183 check_texture(reporter, resourceProvider,
Greg Daniel2a303902018-02-20 10:25:54 -0500184 proxy->asTextureProxy(), fit);
Robert Phillips6520a692017-02-01 09:20:00 -0500185 }
Robert Phillips40d94952017-01-30 14:15:59 -0500186 }
Robert Phillips6520a692017-02-01 09:20:00 -0500187
188 attempt++;
robertphillips76948d42016-05-04 12:47:41 -0700189 }
190 }
191 }
192 }
193 }
194 }
195}
196
egdanielab527a52016-06-28 08:07:26 -0700197DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WrappedProxyTest, reporter, ctxInfo) {
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500198 GrProxyProvider* proxyProvider = ctxInfo.grContext()->contextPriv().proxyProvider();
Robert Phillips6be756b2018-01-16 15:07:54 -0500199 GrResourceProvider* resourceProvider = ctxInfo.grContext()->contextPriv().resourceProvider();
Greg Daniel2a303902018-02-20 10:25:54 -0500200 GrGpu* gpu = ctxInfo.grContext()->contextPriv().getGpu();
csmartdaltonf9635992016-08-10 11:09:07 -0700201 const GrCaps& caps = *ctxInfo.grContext()->caps();
robertphillips76948d42016-05-04 12:47:41 -0700202
203 static const int kWidthHeight = 100;
204
205 for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin }) {
Brian Osman10fc6fd2018-03-02 11:01:10 -0500206 for (auto colorType : { kAlpha_8_SkColorType, kRGBA_8888_SkColorType,
207 kRGBA_1010102_SkColorType }) {
Brian Salomon52e943a2018-03-13 09:32:39 -0400208 // External on-screen render target.
209 // Tests wrapBackendRenderTarget with a GrBackendRenderTarget
210 // Our test-only function that creates a backend render target doesn't currently support
211 // sample counts :(.
212 if (ctxInfo.grContext()->colorTypeSupportedAsSurface(colorType)) {
213 GrBackendRenderTarget backendRT = gpu->createTestingOnlyBackendRenderTarget(
214 kWidthHeight, kWidthHeight, SkColorTypeToGrColorType(colorType),
215 GrSRGBEncoded::kNo);
216 sk_sp<GrSurfaceProxy> sProxy(
217 proxyProvider->wrapBackendRenderTarget(backendRT, origin));
218 check_surface(reporter, sProxy.get(), origin, kWidthHeight, kWidthHeight,
Greg Daniel8a3f55c2018-03-14 17:32:12 +0000219 backendRT.testingOnly_getPixelConfig(), SkBudgeted::kNo);
Brian Salomon52e943a2018-03-13 09:32:39 -0400220 static constexpr int kExpectedNumSamples = 1;
221 check_rendertarget(reporter, caps, resourceProvider, sProxy->asRenderTargetProxy(),
222 kExpectedNumSamples, SkBackingFit::kExact,
223 caps.maxWindowRectangles());
224 gpu->deleteTestingOnlyBackendRenderTarget(backendRT);
225 }
226
Greg Daniel2a303902018-02-20 10:25:54 -0500227 for (auto numSamples : {1, 4}) {
228 GrPixelConfig config = SkImageInfo2GrPixelConfig(colorType, nullptr, caps);
Greg Daniel0a7aa142018-02-21 13:02:32 -0500229 SkASSERT(kUnknown_GrPixelConfig != config);
Greg Daniel2a303902018-02-20 10:25:54 -0500230 int supportedNumSamples = caps.getRenderTargetSampleCount(numSamples, config);
robertphillips76948d42016-05-04 12:47:41 -0700231
Greg Daniel2a303902018-02-20 10:25:54 -0500232 if (!supportedNumSamples) {
233 continue;
234 }
robertphillips76948d42016-05-04 12:47:41 -0700235
Brian Salomon52e943a2018-03-13 09:32:39 -0400236 // Test wrapping FBO 0 (with made up properties). This tests sample count and the
237 // special case where FBO 0 doesn't support window rectangles.
238 if (kOpenGL_GrBackend == ctxInfo.backend()) {
Greg Daniel2a303902018-02-20 10:25:54 -0500239 GrGLFramebufferInfo fboInfo;
240 fboInfo.fFBOID = 0;
Brian Salomon52e943a2018-03-13 09:32:39 -0400241 static constexpr int kStencilBits = 8;
242 GrBackendRenderTarget backendRT(kWidthHeight, kWidthHeight, numSamples,
243 kStencilBits, config, fboInfo);
Brian Salomon7578f3e2018-03-07 14:39:54 -0500244 sk_sp<GrSurfaceProxy> sProxy(
245 proxyProvider->wrapBackendRenderTarget(backendRT, origin));
Greg Daniel2a303902018-02-20 10:25:54 -0500246 check_surface(reporter, sProxy.get(), origin,
247 kWidthHeight, kWidthHeight,
Greg Daniel8a3f55c2018-03-14 17:32:12 +0000248 backendRT.testingOnly_getPixelConfig(), SkBudgeted::kNo);
Greg Daniel2a303902018-02-20 10:25:54 -0500249 check_rendertarget(reporter, caps, resourceProvider,
250 sProxy->asRenderTargetProxy(),
251 supportedNumSamples, SkBackingFit::kExact, 0);
252 }
253
Brian Salomon7578f3e2018-03-07 14:39:54 -0500254 // Tests wrapBackendRenderTarget with a GrBackendTexture
Greg Daniel2a303902018-02-20 10:25:54 -0500255 {
256 GrBackendTexture backendTex =
257 gpu->createTestingOnlyBackendTexture(nullptr, kWidthHeight,
Greg Daniel57bf4a32018-04-19 10:28:37 -0400258 kWidthHeight, colorType, nullptr,
259 true, GrMipMapped::kNo);
Brian Salomon7578f3e2018-03-07 14:39:54 -0500260 sk_sp<GrSurfaceProxy> sProxy = proxyProvider->wrapBackendTextureAsRenderTarget(
261 backendTex, origin, supportedNumSamples);
Greg Daniel2a303902018-02-20 10:25:54 -0500262 if (!sProxy) {
Brian Salomon26102cb2018-03-09 09:33:19 -0500263 gpu->deleteTestingOnlyBackendTexture(backendTex);
Greg Daniel2a303902018-02-20 10:25:54 -0500264 continue; // This can fail on Mesa
csmartdaltonf9635992016-08-10 11:09:07 -0700265 }
266
Greg Daniel2a303902018-02-20 10:25:54 -0500267 check_surface(reporter, sProxy.get(), origin,
268 kWidthHeight, kWidthHeight,
Greg Daniel8a3f55c2018-03-14 17:32:12 +0000269 backendTex.testingOnly_getPixelConfig(), SkBudgeted::kNo);
Greg Daniel2a303902018-02-20 10:25:54 -0500270 check_rendertarget(reporter, caps, resourceProvider,
271 sProxy->asRenderTargetProxy(),
272 supportedNumSamples, SkBackingFit::kExact,
273 caps.maxWindowRectangles());
robertphillips76948d42016-05-04 12:47:41 -0700274
Brian Salomon26102cb2018-03-09 09:33:19 -0500275 gpu->deleteTestingOnlyBackendTexture(backendTex);
Greg Daniel2a303902018-02-20 10:25:54 -0500276 }
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500277
Brian Salomon7578f3e2018-03-07 14:39:54 -0500278 // Tests wrapBackendTexture that is only renderable
Greg Danielf87651e2018-02-21 11:36:53 -0500279 {
280 GrBackendTexture backendTex =
281 gpu->createTestingOnlyBackendTexture(nullptr, kWidthHeight,
Greg Daniel57bf4a32018-04-19 10:28:37 -0400282 kWidthHeight, colorType, nullptr,
283 true, GrMipMapped::kNo);
Greg Danielf87651e2018-02-21 11:36:53 -0500284
Brian Salomon7578f3e2018-03-07 14:39:54 -0500285 sk_sp<GrSurfaceProxy> sProxy = proxyProvider->wrapRenderableBackendTexture(
286 backendTex, origin, supportedNumSamples);
Greg Danielf87651e2018-02-21 11:36:53 -0500287 if (!sProxy) {
Brian Salomon26102cb2018-03-09 09:33:19 -0500288 gpu->deleteTestingOnlyBackendTexture(backendTex);
Greg Danielf87651e2018-02-21 11:36:53 -0500289 continue; // This can fail on Mesa
290 }
291
292 check_surface(reporter, sProxy.get(), origin,
293 kWidthHeight, kWidthHeight,
Greg Daniel8a3f55c2018-03-14 17:32:12 +0000294 backendTex.testingOnly_getPixelConfig(), SkBudgeted::kNo);
Greg Danielf87651e2018-02-21 11:36:53 -0500295 check_rendertarget(reporter, caps, resourceProvider,
296 sProxy->asRenderTargetProxy(),
297 supportedNumSamples, SkBackingFit::kExact,
298 caps.maxWindowRectangles());
299
Brian Salomon26102cb2018-03-09 09:33:19 -0500300 gpu->deleteTestingOnlyBackendTexture(backendTex);
Greg Danielf87651e2018-02-21 11:36:53 -0500301 }
302
Brian Salomon7578f3e2018-03-07 14:39:54 -0500303 // Tests wrapBackendTexture that is only textureable
Greg Daniel2a303902018-02-20 10:25:54 -0500304 {
305 // Internal offscreen texture
306 GrBackendTexture backendTex =
307 gpu->createTestingOnlyBackendTexture(nullptr, kWidthHeight,
Greg Daniel57bf4a32018-04-19 10:28:37 -0400308 kWidthHeight, colorType, nullptr,
309 false, GrMipMapped::kNo);
robertphillips76948d42016-05-04 12:47:41 -0700310
Brian Salomon7578f3e2018-03-07 14:39:54 -0500311 sk_sp<GrSurfaceProxy> sProxy = proxyProvider->wrapBackendTexture(
312 backendTex, origin, kBorrow_GrWrapOwnership, nullptr, nullptr);
Greg Daniel2a303902018-02-20 10:25:54 -0500313 if (!sProxy) {
Brian Salomon26102cb2018-03-09 09:33:19 -0500314 gpu->deleteTestingOnlyBackendTexture(backendTex);
Greg Daniel2a303902018-02-20 10:25:54 -0500315 continue;
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500316 }
Greg Daniel2a303902018-02-20 10:25:54 -0500317
318 check_surface(reporter, sProxy.get(), origin,
319 kWidthHeight, kWidthHeight,
Greg Daniel8a3f55c2018-03-14 17:32:12 +0000320 backendTex.testingOnly_getPixelConfig(), SkBudgeted::kNo);
Greg Daniel2a303902018-02-20 10:25:54 -0500321 check_texture(reporter, resourceProvider, sProxy->asTextureProxy(),
322 SkBackingFit::kExact);
323
Brian Salomon26102cb2018-03-09 09:33:19 -0500324 gpu->deleteTestingOnlyBackendTexture(backendTex);
robertphillips76948d42016-05-04 12:47:41 -0700325 }
326 }
327 }
328 }
329}
330
Robert Phillips78de2122017-04-26 07:44:26 -0400331DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ZeroSizedProxyTest, reporter, ctxInfo) {
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500332 GrProxyProvider* provider = ctxInfo.grContext()->contextPriv().proxyProvider();
Robert Phillips78de2122017-04-26 07:44:26 -0400333
334 for (auto flags : { kRenderTarget_GrSurfaceFlag, kNone_GrSurfaceFlags }) {
335 for (auto fit : { SkBackingFit::kExact, SkBackingFit::kApprox }) {
336 for (int width : { 0, 100 }) {
337 for (int height : { 0, 100}) {
338 if (width && height) {
339 continue; // not zero-sized
340 }
341
342 GrSurfaceDesc desc;
343 desc.fFlags = flags;
Robert Phillips78de2122017-04-26 07:44:26 -0400344 desc.fWidth = width;
345 desc.fHeight = height;
346 desc.fConfig = kRGBA_8888_GrPixelConfig;
Brian Salomonbdecacf2018-02-02 20:32:49 -0500347 desc.fSampleCnt = 1;
Robert Phillips78de2122017-04-26 07:44:26 -0400348
Brian Salomon2a4f9832018-03-03 22:43:43 -0500349 sk_sp<GrTextureProxy> proxy = provider->createProxy(
350 desc, kBottomLeft_GrSurfaceOrigin, fit, SkBudgeted::kNo);
Robert Phillips78de2122017-04-26 07:44:26 -0400351 REPORTER_ASSERT(reporter, !proxy);
352 }
353 }
354 }
355 }
356}
357
robertphillips76948d42016-05-04 12:47:41 -0700358#endif