blob: a1f8b8b2345ba4c895a20ef25d962bfe1bade5a7 [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
Greg Danielbcf612b2017-05-01 13:50:58 +000012#include "GrBackendSurface.h"
Robert Phillips1afd4cd2018-01-08 13:40:32 -050013#include "GrContextPriv.h"
Robert Phillips0bd24dc2018-01-16 08:06:32 -050014#include "GrProxyProvider.h"
Robert Phillipsc7635fa2016-10-28 13:25:24 -040015#include "GrRenderTargetPriv.h"
robertphillips76948d42016-05-04 12:47:41 -070016#include "GrRenderTargetProxy.h"
Brian Osman32342f02017-03-04 08:12:46 -050017#include "GrResourceProvider.h"
Robert Phillipsfe0253f2018-03-16 16:47:25 -040018#include "GrSurfacePriv.h"
Robert Phillipsf95b1752017-08-31 08:56:07 -040019#include "GrSurfaceProxyPriv.h"
Robert Phillips646e4292017-06-13 12:44:56 -040020#include "GrTexture.h"
Brian Osman32342f02017-03-04 08:12:46 -050021#include "GrTextureProxy.h"
Greg Daniel2a303902018-02-20 10:25:54 -050022#include "SkGr.h"
robertphillips76948d42016-05-04 12:47:41 -070023
robertphillips8abb3702016-08-31 14:04:06 -070024// Check that the surface proxy's member vars are set as expected
robertphillips76948d42016-05-04 12:47:41 -070025static void check_surface(skiatest::Reporter* reporter,
26 GrSurfaceProxy* proxy,
27 GrSurfaceOrigin origin,
Greg Danielbcf612b2017-05-01 13:50:58 +000028 int width, int height,
robertphillips8abb3702016-08-31 14:04:06 -070029 GrPixelConfig config,
Robert Phillipsabacf092016-11-02 10:23:32 -040030 SkBudgeted budgeted) {
robertphillips76948d42016-05-04 12:47:41 -070031 REPORTER_ASSERT(reporter, proxy->origin() == origin);
32 REPORTER_ASSERT(reporter, proxy->width() == width);
33 REPORTER_ASSERT(reporter, proxy->height() == height);
34 REPORTER_ASSERT(reporter, proxy->config() == config);
Robert Phillips0bd24dc2018-01-16 08:06:32 -050035 REPORTER_ASSERT(reporter, !proxy->uniqueID().isInvalid());
Robert Phillipsabacf092016-11-02 10:23:32 -040036 REPORTER_ASSERT(reporter, proxy->isBudgeted() == budgeted);
robertphillips76948d42016-05-04 12:47:41 -070037}
38
39static void check_rendertarget(skiatest::Reporter* reporter,
Robert Phillipsec2249f2016-11-09 08:54:35 -050040 const GrCaps& caps,
Brian Osman32342f02017-03-04 08:12:46 -050041 GrResourceProvider* provider,
robertphillips76948d42016-05-04 12:47:41 -070042 GrRenderTargetProxy* rtProxy,
Robert Phillipsabacf092016-11-02 10:23:32 -040043 int numSamples,
Robert Phillipsec2249f2016-11-09 08:54:35 -050044 SkBackingFit fit,
Greg Daniel2a303902018-02-20 10:25:54 -050045 int expectedMaxWindowRects) {
Robert Phillipsec2249f2016-11-09 08:54:35 -050046 REPORTER_ASSERT(reporter, rtProxy->maxWindowRectangles(caps) == expectedMaxWindowRects);
Robert Phillipsabacf092016-11-02 10:23:32 -040047 REPORTER_ASSERT(reporter, rtProxy->numStencilSamples() == numSamples);
48
Robert Phillips294870f2016-11-11 12:38:40 -050049 GrSurfaceProxy::UniqueID idBefore = rtProxy->uniqueID();
Brian Salomonf7778972018-03-08 10:13:17 -050050 bool preinstantiated = rtProxy->priv().isInstantiated();
Robert Phillipseee4d6e2017-06-05 09:26:07 -040051 REPORTER_ASSERT(reporter, rtProxy->instantiate(provider));
52 GrRenderTarget* rt = rtProxy->priv().peekRenderTarget();
robertphillips76948d42016-05-04 12:47:41 -070053
Robert Phillips294870f2016-11-11 12:38:40 -050054 REPORTER_ASSERT(reporter, rtProxy->uniqueID() == idBefore);
Greg Daniel2a303902018-02-20 10:25:54 -050055 // Deferred resources should always have a different ID from their instantiated rendertarget
Brian Salomonf7778972018-03-08 10:13:17 -050056 if (preinstantiated) {
57 REPORTER_ASSERT(reporter, rtProxy->uniqueID().asUInt() == rt->uniqueID().asUInt());
58 } else {
59 REPORTER_ASSERT(reporter, rtProxy->uniqueID().asUInt() != rt->uniqueID().asUInt());
60 }
Robert Phillips294870f2016-11-11 12:38:40 -050061
robertphillips76948d42016-05-04 12:47:41 -070062 if (SkBackingFit::kExact == fit) {
63 REPORTER_ASSERT(reporter, rt->width() == rtProxy->width());
64 REPORTER_ASSERT(reporter, rt->height() == rtProxy->height());
65 } else {
66 REPORTER_ASSERT(reporter, rt->width() >= rtProxy->width());
Robert Phillips294870f2016-11-11 12:38:40 -050067 REPORTER_ASSERT(reporter, rt->height() >= rtProxy->height());
robertphillips76948d42016-05-04 12:47:41 -070068 }
69 REPORTER_ASSERT(reporter, rt->config() == rtProxy->config());
70
Brian Salomon7c8460e2017-05-12 11:36:10 -040071 REPORTER_ASSERT(reporter, rt->fsaaType() == rtProxy->fsaaType());
robertphillips76948d42016-05-04 12:47:41 -070072 REPORTER_ASSERT(reporter, rt->numColorSamples() == rtProxy->numColorSamples());
73 REPORTER_ASSERT(reporter, rt->numStencilSamples() == rtProxy->numStencilSamples());
Robert Phillipsfe0253f2018-03-16 16:47:25 -040074 REPORTER_ASSERT(reporter, rt->surfacePriv().flags() == rtProxy->testingOnly_getFlags());
robertphillips76948d42016-05-04 12:47:41 -070075}
76
77static void check_texture(skiatest::Reporter* reporter,
Brian Osman32342f02017-03-04 08:12:46 -050078 GrResourceProvider* provider,
robertphillips76948d42016-05-04 12:47:41 -070079 GrTextureProxy* texProxy,
Greg Daniel2a303902018-02-20 10:25:54 -050080 SkBackingFit fit) {
Robert Phillips294870f2016-11-11 12:38:40 -050081 GrSurfaceProxy::UniqueID idBefore = texProxy->uniqueID();
Robert Phillipseee4d6e2017-06-05 09:26:07 -040082
Brian Salomonf7778972018-03-08 10:13:17 -050083 bool preinstantiated = texProxy->priv().isInstantiated();
Robert Phillipseee4d6e2017-06-05 09:26:07 -040084 REPORTER_ASSERT(reporter, texProxy->instantiate(provider));
85 GrTexture* tex = texProxy->priv().peekTexture();
robertphillips76948d42016-05-04 12:47:41 -070086
Robert Phillips294870f2016-11-11 12:38:40 -050087 REPORTER_ASSERT(reporter, texProxy->uniqueID() == idBefore);
Greg Daniel2a303902018-02-20 10:25:54 -050088 // Deferred resources should always have a different ID from their instantiated texture
Brian Salomonf7778972018-03-08 10:13:17 -050089 if (preinstantiated) {
90 REPORTER_ASSERT(reporter, texProxy->uniqueID().asUInt() == tex->uniqueID().asUInt());
91 } else {
92 REPORTER_ASSERT(reporter, texProxy->uniqueID().asUInt() != tex->uniqueID().asUInt());
93 }
Robert Phillips294870f2016-11-11 12:38:40 -050094
robertphillips76948d42016-05-04 12:47:41 -070095 if (SkBackingFit::kExact == fit) {
96 REPORTER_ASSERT(reporter, tex->width() == texProxy->width());
97 REPORTER_ASSERT(reporter, tex->height() == texProxy->height());
98 } else {
99 REPORTER_ASSERT(reporter, tex->width() >= texProxy->width());
100 REPORTER_ASSERT(reporter, tex->height() >= texProxy->height());
101 }
102 REPORTER_ASSERT(reporter, tex->config() == texProxy->config());
103}
104
105
robertphillips8abb3702016-08-31 14:04:06 -0700106DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DeferredProxyTest, reporter, ctxInfo) {
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500107 GrProxyProvider* proxyProvider = ctxInfo.grContext()->contextPriv().proxyProvider();
Robert Phillips6be756b2018-01-16 15:07:54 -0500108 GrResourceProvider* resourceProvider = ctxInfo.grContext()->contextPriv().resourceProvider();
Brian Salomonc7fe0f72018-05-11 10:14:21 -0400109 const GrCaps& caps = *ctxInfo.grContext()->contextPriv().caps();
robertphillips76948d42016-05-04 12:47:41 -0700110
Robert Phillips6520a692017-02-01 09:20:00 -0500111 int attempt = 0; // useful for debugging
112
robertphillips76948d42016-05-04 12:47:41 -0700113 for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin }) {
Robert Phillips40d94952017-01-30 14:15:59 -0500114 for (auto widthHeight : { 100, 128, 1048576 }) {
Robert Phillips6520a692017-02-01 09:20:00 -0500115 for (auto config : { kAlpha_8_GrPixelConfig, kRGB_565_GrPixelConfig,
Brian Osman10fc6fd2018-03-02 11:01:10 -0500116 kRGBA_8888_GrPixelConfig, kRGBA_1010102_GrPixelConfig }) {
robertphillips76948d42016-05-04 12:47:41 -0700117 for (auto fit : { SkBackingFit::kExact, SkBackingFit::kApprox }) {
118 for (auto budgeted : { SkBudgeted::kYes, SkBudgeted::kNo }) {
Brian Salomonbdecacf2018-02-02 20:32:49 -0500119 for (auto numSamples : {1, 4, 16, 128}) {
robertphillips76948d42016-05-04 12:47:41 -0700120 GrSurfaceDesc desc;
Robert Phillips84a81202016-11-04 11:59:10 -0400121 desc.fFlags = kRenderTarget_GrSurfaceFlag;
robertphillips76948d42016-05-04 12:47:41 -0700122 desc.fWidth = widthHeight;
123 desc.fHeight = widthHeight;
124 desc.fConfig = config;
125 desc.fSampleCnt = numSamples;
126
Robert Phillips6520a692017-02-01 09:20:00 -0500127 {
128 sk_sp<GrTexture> tex;
129 if (SkBackingFit::kApprox == fit) {
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500130 tex = resourceProvider->createApproxTexture(desc, 0);
Robert Phillips6520a692017-02-01 09:20:00 -0500131 } else {
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500132 tex = resourceProvider->createTexture(desc, budgeted);
Robert Phillips6520a692017-02-01 09:20:00 -0500133 }
134
Brian Salomon2a4f9832018-03-03 22:43:43 -0500135 sk_sp<GrTextureProxy> proxy =
136 proxyProvider->createProxy(desc, origin, fit, budgeted);
Robert Phillips2f493142017-03-02 18:18:38 -0500137 REPORTER_ASSERT(reporter, SkToBool(tex) == SkToBool(proxy));
138 if (proxy) {
139 REPORTER_ASSERT(reporter, proxy->asRenderTargetProxy());
Robert Phillips40d94952017-01-30 14:15:59 -0500140 // This forces the proxy to compute and cache its
141 // pre-instantiation size guess. Later, when it is actually
142 // instantiated, it checks that the instantiated size is <= to
143 // the pre-computation. If the proxy never computed its
144 // pre-instantiation size then the check is skipped.
Robert Phillips2f493142017-03-02 18:18:38 -0500145 proxy->gpuMemorySize();
Robert Phillipsb4460882016-11-17 14:43:51 -0500146
Robert Phillips2f493142017-03-02 18:18:38 -0500147 check_surface(reporter, proxy.get(), origin,
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500148 widthHeight, widthHeight, config, budgeted);
Brian Salomonbdecacf2018-02-02 20:32:49 -0500149 int supportedSamples =
150 caps.getRenderTargetSampleCount(numSamples, config);
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500151 check_rendertarget(reporter, caps, resourceProvider,
Robert Phillips2f493142017-03-02 18:18:38 -0500152 proxy->asRenderTargetProxy(),
Greg Daniel81e7bf82017-07-19 14:47:42 -0400153 supportedSamples,
Greg Daniel2a303902018-02-20 10:25:54 -0500154 fit, caps.maxWindowRectangles());
Robert Phillips40d94952017-01-30 14:15:59 -0500155 }
robertphillips76948d42016-05-04 12:47:41 -0700156 }
157
Robert Phillips84a81202016-11-04 11:59:10 -0400158 desc.fFlags = kNone_GrSurfaceFlags;
robertphillips76948d42016-05-04 12:47:41 -0700159
Robert Phillips6520a692017-02-01 09:20:00 -0500160 {
161 sk_sp<GrTexture> tex;
162 if (SkBackingFit::kApprox == fit) {
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500163 tex = resourceProvider->createApproxTexture(desc, 0);
Robert Phillips6520a692017-02-01 09:20:00 -0500164 } else {
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500165 tex = resourceProvider->createTexture(desc, budgeted);
Robert Phillips6520a692017-02-01 09:20:00 -0500166 }
Robert Phillipsb4460882016-11-17 14:43:51 -0500167
Brian Salomon2a4f9832018-03-03 22:43:43 -0500168 sk_sp<GrTextureProxy> proxy(
169 proxyProvider->createProxy(desc, origin, fit, budgeted));
Robert Phillips2f493142017-03-02 18:18:38 -0500170 REPORTER_ASSERT(reporter, SkToBool(tex) == SkToBool(proxy));
171 if (proxy) {
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500172 // This forces the proxy to compute and cache its
173 // pre-instantiation size guess. Later, when it is actually
174 // instantiated, it checks that the instantiated size is <= to
175 // the pre-computation. If the proxy never computed its
176 // pre-instantiation size then the check is skipped.
Robert Phillips2f493142017-03-02 18:18:38 -0500177 proxy->gpuMemorySize();
Robert Phillips6520a692017-02-01 09:20:00 -0500178
Robert Phillips2f493142017-03-02 18:18:38 -0500179 check_surface(reporter, proxy.get(), origin,
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500180 widthHeight, widthHeight, config, budgeted);
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500181 check_texture(reporter, resourceProvider,
Greg Daniel2a303902018-02-20 10:25:54 -0500182 proxy->asTextureProxy(), fit);
Robert Phillips6520a692017-02-01 09:20:00 -0500183 }
Robert Phillips40d94952017-01-30 14:15:59 -0500184 }
Robert Phillips6520a692017-02-01 09:20:00 -0500185
186 attempt++;
robertphillips76948d42016-05-04 12:47:41 -0700187 }
188 }
189 }
190 }
191 }
192 }
193}
194
egdanielab527a52016-06-28 08:07:26 -0700195DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WrappedProxyTest, reporter, ctxInfo) {
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500196 GrProxyProvider* proxyProvider = ctxInfo.grContext()->contextPriv().proxyProvider();
Robert Phillips6be756b2018-01-16 15:07:54 -0500197 GrResourceProvider* resourceProvider = ctxInfo.grContext()->contextPriv().resourceProvider();
Greg Daniel2a303902018-02-20 10:25:54 -0500198 GrGpu* gpu = ctxInfo.grContext()->contextPriv().getGpu();
Brian Salomonc7fe0f72018-05-11 10:14:21 -0400199 const GrCaps& caps = *ctxInfo.grContext()->contextPriv().caps();
robertphillips76948d42016-05-04 12:47:41 -0700200
201 static const int kWidthHeight = 100;
202
203 for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin }) {
Brian Osman10fc6fd2018-03-02 11:01:10 -0500204 for (auto colorType : { kAlpha_8_SkColorType, kRGBA_8888_SkColorType,
205 kRGBA_1010102_SkColorType }) {
Brian Salomon52e943a2018-03-13 09:32:39 -0400206 // External on-screen render target.
207 // Tests wrapBackendRenderTarget with a GrBackendRenderTarget
208 // Our test-only function that creates a backend render target doesn't currently support
209 // sample counts :(.
210 if (ctxInfo.grContext()->colorTypeSupportedAsSurface(colorType)) {
211 GrBackendRenderTarget backendRT = gpu->createTestingOnlyBackendRenderTarget(
212 kWidthHeight, kWidthHeight, SkColorTypeToGrColorType(colorType),
213 GrSRGBEncoded::kNo);
214 sk_sp<GrSurfaceProxy> sProxy(
215 proxyProvider->wrapBackendRenderTarget(backendRT, origin));
216 check_surface(reporter, sProxy.get(), origin, kWidthHeight, kWidthHeight,
Greg Daniel8a3f55c2018-03-14 17:32:12 +0000217 backendRT.testingOnly_getPixelConfig(), SkBudgeted::kNo);
Brian Salomon52e943a2018-03-13 09:32:39 -0400218 static constexpr int kExpectedNumSamples = 1;
219 check_rendertarget(reporter, caps, resourceProvider, sProxy->asRenderTargetProxy(),
220 kExpectedNumSamples, SkBackingFit::kExact,
221 caps.maxWindowRectangles());
222 gpu->deleteTestingOnlyBackendRenderTarget(backendRT);
223 }
224
Greg Daniel2a303902018-02-20 10:25:54 -0500225 for (auto numSamples : {1, 4}) {
Brian Osman2b23c4b2018-06-01 12:25:08 -0400226 GrPixelConfig config = SkColorType2GrPixelConfig(colorType);
Greg Daniel0a7aa142018-02-21 13:02:32 -0500227 SkASSERT(kUnknown_GrPixelConfig != config);
Greg Daniel2a303902018-02-20 10:25:54 -0500228 int supportedNumSamples = caps.getRenderTargetSampleCount(numSamples, config);
robertphillips76948d42016-05-04 12:47:41 -0700229
Greg Daniel2a303902018-02-20 10:25:54 -0500230 if (!supportedNumSamples) {
231 continue;
232 }
robertphillips76948d42016-05-04 12:47:41 -0700233
Brian Salomon52e943a2018-03-13 09:32:39 -0400234 // Test wrapping FBO 0 (with made up properties). This tests sample count and the
235 // special case where FBO 0 doesn't support window rectangles.
236 if (kOpenGL_GrBackend == ctxInfo.backend()) {
Greg Daniel2a303902018-02-20 10:25:54 -0500237 GrGLFramebufferInfo fboInfo;
238 fboInfo.fFBOID = 0;
Brian Salomon52e943a2018-03-13 09:32:39 -0400239 static constexpr int kStencilBits = 8;
240 GrBackendRenderTarget backendRT(kWidthHeight, kWidthHeight, numSamples,
241 kStencilBits, config, fboInfo);
Brian Salomon7578f3e2018-03-07 14:39:54 -0500242 sk_sp<GrSurfaceProxy> sProxy(
243 proxyProvider->wrapBackendRenderTarget(backendRT, origin));
Greg Daniel2a303902018-02-20 10:25:54 -0500244 check_surface(reporter, sProxy.get(), origin,
245 kWidthHeight, kWidthHeight,
Greg Daniel8a3f55c2018-03-14 17:32:12 +0000246 backendRT.testingOnly_getPixelConfig(), SkBudgeted::kNo);
Greg Daniel2a303902018-02-20 10:25:54 -0500247 check_rendertarget(reporter, caps, resourceProvider,
248 sProxy->asRenderTargetProxy(),
249 supportedNumSamples, SkBackingFit::kExact, 0);
250 }
251
Brian Salomon7578f3e2018-03-07 14:39:54 -0500252 // Tests wrapBackendRenderTarget with a GrBackendTexture
Greg Daniel2a303902018-02-20 10:25:54 -0500253 {
254 GrBackendTexture backendTex =
255 gpu->createTestingOnlyBackendTexture(nullptr, kWidthHeight,
Brian Osman2b23c4b2018-06-01 12:25:08 -0400256 kWidthHeight, colorType,
Greg Daniel57bf4a32018-04-19 10:28:37 -0400257 true, GrMipMapped::kNo);
Brian Salomon7578f3e2018-03-07 14:39:54 -0500258 sk_sp<GrSurfaceProxy> sProxy = proxyProvider->wrapBackendTextureAsRenderTarget(
259 backendTex, origin, supportedNumSamples);
Greg Daniel2a303902018-02-20 10:25:54 -0500260 if (!sProxy) {
Brian Salomon26102cb2018-03-09 09:33:19 -0500261 gpu->deleteTestingOnlyBackendTexture(backendTex);
Greg Daniel2a303902018-02-20 10:25:54 -0500262 continue; // This can fail on Mesa
csmartdaltonf9635992016-08-10 11:09:07 -0700263 }
264
Greg Daniel2a303902018-02-20 10:25:54 -0500265 check_surface(reporter, sProxy.get(), origin,
266 kWidthHeight, kWidthHeight,
Greg Daniel8a3f55c2018-03-14 17:32:12 +0000267 backendTex.testingOnly_getPixelConfig(), SkBudgeted::kNo);
Greg Daniel2a303902018-02-20 10:25:54 -0500268 check_rendertarget(reporter, caps, resourceProvider,
269 sProxy->asRenderTargetProxy(),
270 supportedNumSamples, SkBackingFit::kExact,
271 caps.maxWindowRectangles());
robertphillips76948d42016-05-04 12:47:41 -0700272
Brian Salomon26102cb2018-03-09 09:33:19 -0500273 gpu->deleteTestingOnlyBackendTexture(backendTex);
Greg Daniel2a303902018-02-20 10:25:54 -0500274 }
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500275
Brian Salomon7578f3e2018-03-07 14:39:54 -0500276 // Tests wrapBackendTexture that is only renderable
Greg Danielf87651e2018-02-21 11:36:53 -0500277 {
278 GrBackendTexture backendTex =
279 gpu->createTestingOnlyBackendTexture(nullptr, kWidthHeight,
Brian Osman2b23c4b2018-06-01 12:25:08 -0400280 kWidthHeight, colorType,
Greg Daniel57bf4a32018-04-19 10:28:37 -0400281 true, GrMipMapped::kNo);
Greg Danielf87651e2018-02-21 11:36:53 -0500282
Brian Salomon7578f3e2018-03-07 14:39:54 -0500283 sk_sp<GrSurfaceProxy> sProxy = proxyProvider->wrapRenderableBackendTexture(
284 backendTex, origin, supportedNumSamples);
Greg Danielf87651e2018-02-21 11:36:53 -0500285 if (!sProxy) {
Brian Salomon26102cb2018-03-09 09:33:19 -0500286 gpu->deleteTestingOnlyBackendTexture(backendTex);
Greg Danielf87651e2018-02-21 11:36:53 -0500287 continue; // This can fail on Mesa
288 }
289
290 check_surface(reporter, sProxy.get(), origin,
291 kWidthHeight, kWidthHeight,
Greg Daniel8a3f55c2018-03-14 17:32:12 +0000292 backendTex.testingOnly_getPixelConfig(), SkBudgeted::kNo);
Greg Danielf87651e2018-02-21 11:36:53 -0500293 check_rendertarget(reporter, caps, resourceProvider,
294 sProxy->asRenderTargetProxy(),
295 supportedNumSamples, SkBackingFit::kExact,
296 caps.maxWindowRectangles());
297
Brian Salomon26102cb2018-03-09 09:33:19 -0500298 gpu->deleteTestingOnlyBackendTexture(backendTex);
Greg Danielf87651e2018-02-21 11:36:53 -0500299 }
300
Brian Salomon7578f3e2018-03-07 14:39:54 -0500301 // Tests wrapBackendTexture that is only textureable
Greg Daniel2a303902018-02-20 10:25:54 -0500302 {
303 // Internal offscreen texture
304 GrBackendTexture backendTex =
305 gpu->createTestingOnlyBackendTexture(nullptr, kWidthHeight,
Brian Osman2b23c4b2018-06-01 12:25:08 -0400306 kWidthHeight, colorType,
Greg Daniel57bf4a32018-04-19 10:28:37 -0400307 false, GrMipMapped::kNo);
robertphillips76948d42016-05-04 12:47:41 -0700308
Brian Salomon7578f3e2018-03-07 14:39:54 -0500309 sk_sp<GrSurfaceProxy> sProxy = proxyProvider->wrapBackendTexture(
310 backendTex, origin, kBorrow_GrWrapOwnership, nullptr, nullptr);
Greg Daniel2a303902018-02-20 10:25:54 -0500311 if (!sProxy) {
Brian Salomon26102cb2018-03-09 09:33:19 -0500312 gpu->deleteTestingOnlyBackendTexture(backendTex);
Greg Daniel2a303902018-02-20 10:25:54 -0500313 continue;
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500314 }
Greg Daniel2a303902018-02-20 10:25:54 -0500315
316 check_surface(reporter, sProxy.get(), origin,
317 kWidthHeight, kWidthHeight,
Greg Daniel8a3f55c2018-03-14 17:32:12 +0000318 backendTex.testingOnly_getPixelConfig(), SkBudgeted::kNo);
Greg Daniel2a303902018-02-20 10:25:54 -0500319 check_texture(reporter, resourceProvider, sProxy->asTextureProxy(),
320 SkBackingFit::kExact);
321
Brian Salomon26102cb2018-03-09 09:33:19 -0500322 gpu->deleteTestingOnlyBackendTexture(backendTex);
robertphillips76948d42016-05-04 12:47:41 -0700323 }
324 }
325 }
326 }
327}
328
Robert Phillips78de2122017-04-26 07:44:26 -0400329DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ZeroSizedProxyTest, reporter, ctxInfo) {
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500330 GrProxyProvider* provider = ctxInfo.grContext()->contextPriv().proxyProvider();
Robert Phillips78de2122017-04-26 07:44:26 -0400331
332 for (auto flags : { kRenderTarget_GrSurfaceFlag, kNone_GrSurfaceFlags }) {
333 for (auto fit : { SkBackingFit::kExact, SkBackingFit::kApprox }) {
334 for (int width : { 0, 100 }) {
335 for (int height : { 0, 100}) {
336 if (width && height) {
337 continue; // not zero-sized
338 }
339
340 GrSurfaceDesc desc;
341 desc.fFlags = flags;
Robert Phillips78de2122017-04-26 07:44:26 -0400342 desc.fWidth = width;
343 desc.fHeight = height;
344 desc.fConfig = kRGBA_8888_GrPixelConfig;
Brian Salomonbdecacf2018-02-02 20:32:49 -0500345 desc.fSampleCnt = 1;
Robert Phillips78de2122017-04-26 07:44:26 -0400346
Brian Salomon2a4f9832018-03-03 22:43:43 -0500347 sk_sp<GrTextureProxy> proxy = provider->createProxy(
348 desc, kBottomLeft_GrSurfaceOrigin, fit, SkBudgeted::kNo);
Robert Phillips78de2122017-04-26 07:44:26 -0400349 REPORTER_ASSERT(reporter, !proxy);
350 }
351 }
352 }
353 }
354}