blob: 9a5a0d14b6863d9c2f1a426fc463fcdccaeece92 [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 Salomonfd98c2c2018-07-31 17:25:29 -040050 bool preinstantiated = rtProxy->isInstantiated();
Robert Phillipseee4d6e2017-06-05 09:26:07 -040051 REPORTER_ASSERT(reporter, rtProxy->instantiate(provider));
Brian Salomonfd98c2c2018-07-31 17:25:29 -040052 GrRenderTarget* rt = rtProxy->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 Salomonfd98c2c2018-07-31 17:25:29 -040083 bool preinstantiated = texProxy->isInstantiated();
Robert Phillipseee4d6e2017-06-05 09:26:07 -040084 REPORTER_ASSERT(reporter, texProxy->instantiate(provider));
Brian Salomonfd98c2c2018-07-31 17:25:29 -040085 GrTexture* tex = texProxy->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
Greg Daniel4065d452018-11-16 15:43:41 -0500127 GrSRGBEncoded srgbEncoded;
128 GrColorType colorType =
129 GrPixelConfigToColorTypeAndEncoding(config, &srgbEncoded);
130 const GrBackendFormat format =
131 caps.getBackendFormatFromGrColorType(colorType, srgbEncoded);
132
Robert Phillips6520a692017-02-01 09:20:00 -0500133 {
134 sk_sp<GrTexture> tex;
135 if (SkBackingFit::kApprox == fit) {
Chris Daltond004e0b2018-09-27 09:28:03 -0600136 tex = resourceProvider->createApproxTexture(
137 desc, GrResourceProvider::Flags::kNone);
Robert Phillips6520a692017-02-01 09:20:00 -0500138 } else {
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500139 tex = resourceProvider->createTexture(desc, budgeted);
Robert Phillips6520a692017-02-01 09:20:00 -0500140 }
141
Brian Salomon2a4f9832018-03-03 22:43:43 -0500142 sk_sp<GrTextureProxy> proxy =
Greg Daniel4065d452018-11-16 15:43:41 -0500143 proxyProvider->createProxy(format, desc, origin, fit,
144 budgeted);
Robert Phillips2f493142017-03-02 18:18:38 -0500145 REPORTER_ASSERT(reporter, SkToBool(tex) == SkToBool(proxy));
146 if (proxy) {
147 REPORTER_ASSERT(reporter, proxy->asRenderTargetProxy());
Robert Phillips40d94952017-01-30 14:15:59 -0500148 // This forces the proxy to compute and cache its
149 // pre-instantiation size guess. Later, when it is actually
150 // instantiated, it checks that the instantiated size is <= to
151 // the pre-computation. If the proxy never computed its
152 // pre-instantiation size then the check is skipped.
Robert Phillips2f493142017-03-02 18:18:38 -0500153 proxy->gpuMemorySize();
Robert Phillipsb4460882016-11-17 14:43:51 -0500154
Robert Phillips2f493142017-03-02 18:18:38 -0500155 check_surface(reporter, proxy.get(), origin,
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500156 widthHeight, widthHeight, config, budgeted);
Brian Salomonbdecacf2018-02-02 20:32:49 -0500157 int supportedSamples =
158 caps.getRenderTargetSampleCount(numSamples, config);
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500159 check_rendertarget(reporter, caps, resourceProvider,
Robert Phillips2f493142017-03-02 18:18:38 -0500160 proxy->asRenderTargetProxy(),
Greg Daniel81e7bf82017-07-19 14:47:42 -0400161 supportedSamples,
Greg Daniel2a303902018-02-20 10:25:54 -0500162 fit, caps.maxWindowRectangles());
Robert Phillips40d94952017-01-30 14:15:59 -0500163 }
robertphillips76948d42016-05-04 12:47:41 -0700164 }
165
Robert Phillips84a81202016-11-04 11:59:10 -0400166 desc.fFlags = kNone_GrSurfaceFlags;
robertphillips76948d42016-05-04 12:47:41 -0700167
Robert Phillips6520a692017-02-01 09:20:00 -0500168 {
169 sk_sp<GrTexture> tex;
170 if (SkBackingFit::kApprox == fit) {
Chris Daltond004e0b2018-09-27 09:28:03 -0600171 tex = resourceProvider->createApproxTexture(
172 desc, GrResourceProvider::Flags::kNone);
Robert Phillips6520a692017-02-01 09:20:00 -0500173 } else {
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500174 tex = resourceProvider->createTexture(desc, budgeted);
Robert Phillips6520a692017-02-01 09:20:00 -0500175 }
Robert Phillipsb4460882016-11-17 14:43:51 -0500176
Brian Salomon2a4f9832018-03-03 22:43:43 -0500177 sk_sp<GrTextureProxy> proxy(
Greg Daniel4065d452018-11-16 15:43:41 -0500178 proxyProvider->createProxy(format, desc, origin, fit,
179 budgeted));
Robert Phillips2f493142017-03-02 18:18:38 -0500180 REPORTER_ASSERT(reporter, SkToBool(tex) == SkToBool(proxy));
181 if (proxy) {
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500182 // This forces the proxy to compute and cache its
183 // pre-instantiation size guess. Later, when it is actually
184 // instantiated, it checks that the instantiated size is <= to
185 // the pre-computation. If the proxy never computed its
186 // pre-instantiation size then the check is skipped.
Robert Phillips2f493142017-03-02 18:18:38 -0500187 proxy->gpuMemorySize();
Robert Phillips6520a692017-02-01 09:20:00 -0500188
Robert Phillips2f493142017-03-02 18:18:38 -0500189 check_surface(reporter, proxy.get(), origin,
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500190 widthHeight, widthHeight, config, budgeted);
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500191 check_texture(reporter, resourceProvider,
Greg Daniel2a303902018-02-20 10:25:54 -0500192 proxy->asTextureProxy(), fit);
Robert Phillips6520a692017-02-01 09:20:00 -0500193 }
Robert Phillips40d94952017-01-30 14:15:59 -0500194 }
Robert Phillips6520a692017-02-01 09:20:00 -0500195
196 attempt++;
robertphillips76948d42016-05-04 12:47:41 -0700197 }
198 }
199 }
200 }
201 }
202 }
203}
204
egdanielab527a52016-06-28 08:07:26 -0700205DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WrappedProxyTest, reporter, ctxInfo) {
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500206 GrProxyProvider* proxyProvider = ctxInfo.grContext()->contextPriv().proxyProvider();
Robert Phillips6be756b2018-01-16 15:07:54 -0500207 GrResourceProvider* resourceProvider = ctxInfo.grContext()->contextPriv().resourceProvider();
Greg Daniel2a303902018-02-20 10:25:54 -0500208 GrGpu* gpu = ctxInfo.grContext()->contextPriv().getGpu();
Brian Salomonc7fe0f72018-05-11 10:14:21 -0400209 const GrCaps& caps = *ctxInfo.grContext()->contextPriv().caps();
robertphillips76948d42016-05-04 12:47:41 -0700210
211 static const int kWidthHeight = 100;
212
213 for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin }) {
Brian Osman10fc6fd2018-03-02 11:01:10 -0500214 for (auto colorType : { kAlpha_8_SkColorType, kRGBA_8888_SkColorType,
215 kRGBA_1010102_SkColorType }) {
Brian Salomon52e943a2018-03-13 09:32:39 -0400216 // External on-screen render target.
217 // Tests wrapBackendRenderTarget with a GrBackendRenderTarget
218 // Our test-only function that creates a backend render target doesn't currently support
219 // sample counts :(.
220 if (ctxInfo.grContext()->colorTypeSupportedAsSurface(colorType)) {
221 GrBackendRenderTarget backendRT = gpu->createTestingOnlyBackendRenderTarget(
Brian Osman2d010b62018-08-09 10:55:09 -0400222 kWidthHeight, kWidthHeight, SkColorTypeToGrColorType(colorType));
Brian Salomon52e943a2018-03-13 09:32:39 -0400223 sk_sp<GrSurfaceProxy> sProxy(
224 proxyProvider->wrapBackendRenderTarget(backendRT, origin));
225 check_surface(reporter, sProxy.get(), origin, kWidthHeight, kWidthHeight,
Greg Daniel108bb232018-07-03 16:18:29 -0400226 backendRT.pixelConfig(), SkBudgeted::kNo);
Brian Salomon52e943a2018-03-13 09:32:39 -0400227 static constexpr int kExpectedNumSamples = 1;
228 check_rendertarget(reporter, caps, resourceProvider, sProxy->asRenderTargetProxy(),
229 kExpectedNumSamples, SkBackingFit::kExact,
230 caps.maxWindowRectangles());
231 gpu->deleteTestingOnlyBackendRenderTarget(backendRT);
232 }
233
Greg Daniel2a303902018-02-20 10:25:54 -0500234 for (auto numSamples : {1, 4}) {
Brian Osman2b23c4b2018-06-01 12:25:08 -0400235 GrPixelConfig config = SkColorType2GrPixelConfig(colorType);
Greg Daniel0a7aa142018-02-21 13:02:32 -0500236 SkASSERT(kUnknown_GrPixelConfig != config);
Greg Daniel2a303902018-02-20 10:25:54 -0500237 int supportedNumSamples = caps.getRenderTargetSampleCount(numSamples, config);
robertphillips76948d42016-05-04 12:47:41 -0700238
Greg Daniel2a303902018-02-20 10:25:54 -0500239 if (!supportedNumSamples) {
240 continue;
241 }
robertphillips76948d42016-05-04 12:47:41 -0700242
Brian Salomon52e943a2018-03-13 09:32:39 -0400243 // Test wrapping FBO 0 (with made up properties). This tests sample count and the
244 // special case where FBO 0 doesn't support window rectangles.
Greg Danielbdf12ad2018-10-12 09:31:11 -0400245 if (GrBackendApi::kOpenGL == ctxInfo.backend()) {
Greg Daniel2a303902018-02-20 10:25:54 -0500246 GrGLFramebufferInfo fboInfo;
247 fboInfo.fFBOID = 0;
Brian Salomon52e943a2018-03-13 09:32:39 -0400248 static constexpr int kStencilBits = 8;
249 GrBackendRenderTarget backendRT(kWidthHeight, kWidthHeight, numSamples,
Greg Daniel108bb232018-07-03 16:18:29 -0400250 kStencilBits, fboInfo);
251 backendRT.setPixelConfig(config);
Brian Salomon7578f3e2018-03-07 14:39:54 -0500252 sk_sp<GrSurfaceProxy> sProxy(
253 proxyProvider->wrapBackendRenderTarget(backendRT, origin));
Greg Daniel2a303902018-02-20 10:25:54 -0500254 check_surface(reporter, sProxy.get(), origin,
255 kWidthHeight, kWidthHeight,
Greg Daniel108bb232018-07-03 16:18:29 -0400256 backendRT.pixelConfig(), SkBudgeted::kNo);
Greg Daniel2a303902018-02-20 10:25:54 -0500257 check_rendertarget(reporter, caps, resourceProvider,
258 sProxy->asRenderTargetProxy(),
259 supportedNumSamples, SkBackingFit::kExact, 0);
260 }
261
Brian Salomon7578f3e2018-03-07 14:39:54 -0500262 // Tests wrapBackendRenderTarget with a GrBackendTexture
Greg Daniel2a303902018-02-20 10:25:54 -0500263 {
264 GrBackendTexture backendTex =
265 gpu->createTestingOnlyBackendTexture(nullptr, kWidthHeight,
Brian Osman2b23c4b2018-06-01 12:25:08 -0400266 kWidthHeight, colorType,
Greg Daniel57bf4a32018-04-19 10:28:37 -0400267 true, GrMipMapped::kNo);
Brian Salomon7578f3e2018-03-07 14:39:54 -0500268 sk_sp<GrSurfaceProxy> sProxy = proxyProvider->wrapBackendTextureAsRenderTarget(
269 backendTex, origin, supportedNumSamples);
Greg Daniel2a303902018-02-20 10:25:54 -0500270 if (!sProxy) {
Brian Salomon26102cb2018-03-09 09:33:19 -0500271 gpu->deleteTestingOnlyBackendTexture(backendTex);
Greg Daniel2a303902018-02-20 10:25:54 -0500272 continue; // This can fail on Mesa
csmartdaltonf9635992016-08-10 11:09:07 -0700273 }
274
Greg Daniel2a303902018-02-20 10:25:54 -0500275 check_surface(reporter, sProxy.get(), origin,
276 kWidthHeight, kWidthHeight,
Greg Daniel108bb232018-07-03 16:18:29 -0400277 backendTex.pixelConfig(), SkBudgeted::kNo);
Greg Daniel2a303902018-02-20 10:25:54 -0500278 check_rendertarget(reporter, caps, resourceProvider,
279 sProxy->asRenderTargetProxy(),
280 supportedNumSamples, SkBackingFit::kExact,
281 caps.maxWindowRectangles());
robertphillips76948d42016-05-04 12:47:41 -0700282
Brian Salomon26102cb2018-03-09 09:33:19 -0500283 gpu->deleteTestingOnlyBackendTexture(backendTex);
Greg Daniel2a303902018-02-20 10:25:54 -0500284 }
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500285
Brian Salomon7578f3e2018-03-07 14:39:54 -0500286 // Tests wrapBackendTexture that is only renderable
Greg Danielf87651e2018-02-21 11:36:53 -0500287 {
288 GrBackendTexture backendTex =
289 gpu->createTestingOnlyBackendTexture(nullptr, kWidthHeight,
Brian Osman2b23c4b2018-06-01 12:25:08 -0400290 kWidthHeight, colorType,
Greg Daniel57bf4a32018-04-19 10:28:37 -0400291 true, GrMipMapped::kNo);
Greg Danielf87651e2018-02-21 11:36:53 -0500292
Brian Salomon7578f3e2018-03-07 14:39:54 -0500293 sk_sp<GrSurfaceProxy> sProxy = proxyProvider->wrapRenderableBackendTexture(
294 backendTex, origin, supportedNumSamples);
Greg Danielf87651e2018-02-21 11:36:53 -0500295 if (!sProxy) {
Brian Salomon26102cb2018-03-09 09:33:19 -0500296 gpu->deleteTestingOnlyBackendTexture(backendTex);
Greg Danielf87651e2018-02-21 11:36:53 -0500297 continue; // This can fail on Mesa
298 }
299
300 check_surface(reporter, sProxy.get(), origin,
301 kWidthHeight, kWidthHeight,
Greg Daniel108bb232018-07-03 16:18:29 -0400302 backendTex.pixelConfig(), SkBudgeted::kNo);
Greg Danielf87651e2018-02-21 11:36:53 -0500303 check_rendertarget(reporter, caps, resourceProvider,
304 sProxy->asRenderTargetProxy(),
305 supportedNumSamples, SkBackingFit::kExact,
306 caps.maxWindowRectangles());
307
Brian Salomon26102cb2018-03-09 09:33:19 -0500308 gpu->deleteTestingOnlyBackendTexture(backendTex);
Greg Danielf87651e2018-02-21 11:36:53 -0500309 }
310
Brian Salomon7578f3e2018-03-07 14:39:54 -0500311 // Tests wrapBackendTexture that is only textureable
Greg Daniel2a303902018-02-20 10:25:54 -0500312 {
313 // Internal offscreen texture
314 GrBackendTexture backendTex =
315 gpu->createTestingOnlyBackendTexture(nullptr, kWidthHeight,
Brian Osman2b23c4b2018-06-01 12:25:08 -0400316 kWidthHeight, colorType,
Greg Daniel57bf4a32018-04-19 10:28:37 -0400317 false, GrMipMapped::kNo);
robertphillips76948d42016-05-04 12:47:41 -0700318
Brian Salomon7578f3e2018-03-07 14:39:54 -0500319 sk_sp<GrSurfaceProxy> sProxy = proxyProvider->wrapBackendTexture(
320 backendTex, origin, kBorrow_GrWrapOwnership, nullptr, nullptr);
Greg Daniel2a303902018-02-20 10:25:54 -0500321 if (!sProxy) {
Brian Salomon26102cb2018-03-09 09:33:19 -0500322 gpu->deleteTestingOnlyBackendTexture(backendTex);
Greg Daniel2a303902018-02-20 10:25:54 -0500323 continue;
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500324 }
Greg Daniel2a303902018-02-20 10:25:54 -0500325
326 check_surface(reporter, sProxy.get(), origin,
327 kWidthHeight, kWidthHeight,
Greg Daniel108bb232018-07-03 16:18:29 -0400328 backendTex.pixelConfig(), SkBudgeted::kNo);
Greg Daniel2a303902018-02-20 10:25:54 -0500329 check_texture(reporter, resourceProvider, sProxy->asTextureProxy(),
330 SkBackingFit::kExact);
331
Brian Salomon26102cb2018-03-09 09:33:19 -0500332 gpu->deleteTestingOnlyBackendTexture(backendTex);
robertphillips76948d42016-05-04 12:47:41 -0700333 }
334 }
335 }
336 }
337}
338
Robert Phillips78de2122017-04-26 07:44:26 -0400339DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ZeroSizedProxyTest, reporter, ctxInfo) {
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500340 GrProxyProvider* provider = ctxInfo.grContext()->contextPriv().proxyProvider();
Robert Phillips78de2122017-04-26 07:44:26 -0400341
342 for (auto flags : { kRenderTarget_GrSurfaceFlag, kNone_GrSurfaceFlags }) {
343 for (auto fit : { SkBackingFit::kExact, SkBackingFit::kApprox }) {
344 for (int width : { 0, 100 }) {
345 for (int height : { 0, 100}) {
346 if (width && height) {
347 continue; // not zero-sized
348 }
349
350 GrSurfaceDesc desc;
351 desc.fFlags = flags;
Robert Phillips78de2122017-04-26 07:44:26 -0400352 desc.fWidth = width;
353 desc.fHeight = height;
354 desc.fConfig = kRGBA_8888_GrPixelConfig;
Brian Salomonbdecacf2018-02-02 20:32:49 -0500355 desc.fSampleCnt = 1;
Robert Phillips78de2122017-04-26 07:44:26 -0400356
Greg Daniel4065d452018-11-16 15:43:41 -0500357 const GrBackendFormat format =
358 ctxInfo.grContext()->contextPriv().caps()->getBackendFormatFromColorType(
359 kRGBA_8888_SkColorType);
360
Brian Salomon2a4f9832018-03-03 22:43:43 -0500361 sk_sp<GrTextureProxy> proxy = provider->createProxy(
Greg Daniel4065d452018-11-16 15:43:41 -0500362 format, desc, kBottomLeft_GrSurfaceOrigin, fit, SkBudgeted::kNo);
Robert Phillips78de2122017-04-26 07:44:26 -0400363 REPORTER_ASSERT(reporter, !proxy);
364 }
365 }
366 }
367 }
368}