robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 1 | /* |
| 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 Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "tests/Test.h" |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 11 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "include/gpu/GrBackendSurface.h" |
Robert Phillips | 6d344c3 | 2020-07-06 10:56:46 -0400 | [diff] [blame] | 13 | #include "include/gpu/GrDirectContext.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 14 | #include "src/gpu/GrContextPriv.h" |
| 15 | #include "src/gpu/GrProxyProvider.h" |
| 16 | #include "src/gpu/GrRenderTargetPriv.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 17 | #include "src/gpu/GrRenderTargetProxy.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 18 | #include "src/gpu/GrResourceProvider.h" |
| 19 | #include "src/gpu/GrSurfacePriv.h" |
| 20 | #include "src/gpu/GrSurfaceProxyPriv.h" |
Greg Daniel | 456f9b5 | 2020-03-05 19:14:18 +0000 | [diff] [blame] | 21 | #include "src/gpu/GrTexture.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 22 | #include "src/gpu/GrTextureProxy.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 23 | #include "src/gpu/SkGr.h" |
John Rosasco | a9b348f | 2019-11-08 13:18:15 -0800 | [diff] [blame] | 24 | #ifdef SK_GL |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 25 | #include "src/gpu/gl/GrGLDefines.h" |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 26 | #include "src/gpu/gl/GrGLUtil.h" |
John Rosasco | a9b348f | 2019-11-08 13:18:15 -0800 | [diff] [blame] | 27 | #endif |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 28 | |
Greg Daniel | c1ad77c | 2020-05-06 11:40:03 -0400 | [diff] [blame] | 29 | #include "tests/TestUtils.h" |
| 30 | |
robertphillips | 8abb370 | 2016-08-31 14:04:06 -0700 | [diff] [blame] | 31 | // Check that the surface proxy's member vars are set as expected |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 32 | static void check_surface(skiatest::Reporter* reporter, |
| 33 | GrSurfaceProxy* proxy, |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 34 | int width, int height, |
Robert Phillips | abacf09 | 2016-11-02 10:23:32 -0400 | [diff] [blame] | 35 | SkBudgeted budgeted) { |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 36 | REPORTER_ASSERT(reporter, proxy->width() == width); |
| 37 | REPORTER_ASSERT(reporter, proxy->height() == height); |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 38 | REPORTER_ASSERT(reporter, !proxy->uniqueID().isInvalid()); |
Robert Phillips | abacf09 | 2016-11-02 10:23:32 -0400 | [diff] [blame] | 39 | REPORTER_ASSERT(reporter, proxy->isBudgeted() == budgeted); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | static void check_rendertarget(skiatest::Reporter* reporter, |
Robert Phillips | ec2249f | 2016-11-09 08:54:35 -0500 | [diff] [blame] | 43 | const GrCaps& caps, |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 44 | GrResourceProvider* provider, |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 45 | GrRenderTargetProxy* rtProxy, |
Robert Phillips | abacf09 | 2016-11-02 10:23:32 -0400 | [diff] [blame] | 46 | int numSamples, |
Robert Phillips | ec2249f | 2016-11-09 08:54:35 -0500 | [diff] [blame] | 47 | SkBackingFit fit, |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 48 | int expectedMaxWindowRects) { |
Robert Phillips | ec2249f | 2016-11-09 08:54:35 -0500 | [diff] [blame] | 49 | REPORTER_ASSERT(reporter, rtProxy->maxWindowRectangles(caps) == expectedMaxWindowRects); |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 50 | REPORTER_ASSERT(reporter, rtProxy->numSamples() == numSamples); |
Robert Phillips | abacf09 | 2016-11-02 10:23:32 -0400 | [diff] [blame] | 51 | |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 52 | GrSurfaceProxy::UniqueID idBefore = rtProxy->uniqueID(); |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 53 | bool preinstantiated = rtProxy->isInstantiated(); |
Robert Phillips | eee4d6e | 2017-06-05 09:26:07 -0400 | [diff] [blame] | 54 | REPORTER_ASSERT(reporter, rtProxy->instantiate(provider)); |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 55 | GrRenderTarget* rt = rtProxy->peekRenderTarget(); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 56 | |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 57 | REPORTER_ASSERT(reporter, rtProxy->uniqueID() == idBefore); |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 58 | // Deferred resources should always have a different ID from their instantiated rendertarget |
Brian Salomon | f777897 | 2018-03-08 10:13:17 -0500 | [diff] [blame] | 59 | 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 Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 64 | |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 65 | if (SkBackingFit::kExact == fit) { |
Brian Salomon | 9f2b86c | 2019-10-22 10:37:46 -0400 | [diff] [blame] | 66 | REPORTER_ASSERT(reporter, rt->dimensions() == rtProxy->dimensions()); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 67 | } else { |
| 68 | REPORTER_ASSERT(reporter, rt->width() >= rtProxy->width()); |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 69 | REPORTER_ASSERT(reporter, rt->height() >= rtProxy->height()); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 70 | } |
Greg Daniel | d51fa2f | 2020-01-22 16:53:38 -0500 | [diff] [blame] | 71 | REPORTER_ASSERT(reporter, rt->backendFormat() == rtProxy->backendFormat()); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 72 | |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 73 | REPORTER_ASSERT(reporter, rt->numSamples() == rtProxy->numSamples()); |
Robert Phillips | fe0253f | 2018-03-16 16:47:25 -0400 | [diff] [blame] | 74 | REPORTER_ASSERT(reporter, rt->surfacePriv().flags() == rtProxy->testingOnly_getFlags()); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | static void check_texture(skiatest::Reporter* reporter, |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 78 | GrResourceProvider* provider, |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 79 | GrTextureProxy* texProxy, |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 80 | SkBackingFit fit) { |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 81 | GrSurfaceProxy::UniqueID idBefore = texProxy->uniqueID(); |
Robert Phillips | eee4d6e | 2017-06-05 09:26:07 -0400 | [diff] [blame] | 82 | |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 83 | bool preinstantiated = texProxy->isInstantiated(); |
Michael Ludwig | bd2f070 | 2019-09-13 15:29:41 -0400 | [diff] [blame] | 84 | // The instantiated texture should have these dimensions. If the fit is kExact, then |
Robert Phillips | e9462dd | 2019-10-23 12:41:29 -0400 | [diff] [blame] | 85 | // 'backingStoreDimensions' reports the original WxH. If it is kApprox, make sure that |
| 86 | // the texture is that size and didn't reuse one of the kExact surfaces in the provider. |
| 87 | // This is important because upstream usage (e.g. SkImage) reports size based on the |
| 88 | // backingStoreDimensions and client code may rely on that if they are creating backend |
| 89 | // resources. |
| 90 | // NOTE: we store these before instantiating, since after instantiation backingStoreDimensions |
| 91 | // just returns the target's dimensions. In this instance, we want to ensure the target's |
Brian Salomon | 9f2b86c | 2019-10-22 10:37:46 -0400 | [diff] [blame] | 92 | // dimensions are no different from the original approximate (or exact) dimensions. |
Robert Phillips | e9462dd | 2019-10-23 12:41:29 -0400 | [diff] [blame] | 93 | SkISize expectedSize = texProxy->backingStoreDimensions(); |
Michael Ludwig | bd2f070 | 2019-09-13 15:29:41 -0400 | [diff] [blame] | 94 | |
Robert Phillips | eee4d6e | 2017-06-05 09:26:07 -0400 | [diff] [blame] | 95 | REPORTER_ASSERT(reporter, texProxy->instantiate(provider)); |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 96 | GrTexture* tex = texProxy->peekTexture(); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 97 | |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 98 | REPORTER_ASSERT(reporter, texProxy->uniqueID() == idBefore); |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 99 | // Deferred resources should always have a different ID from their instantiated texture |
Brian Salomon | f777897 | 2018-03-08 10:13:17 -0500 | [diff] [blame] | 100 | if (preinstantiated) { |
| 101 | REPORTER_ASSERT(reporter, texProxy->uniqueID().asUInt() == tex->uniqueID().asUInt()); |
| 102 | } else { |
| 103 | REPORTER_ASSERT(reporter, texProxy->uniqueID().asUInt() != tex->uniqueID().asUInt()); |
| 104 | } |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 105 | |
Brian Salomon | 9f2b86c | 2019-10-22 10:37:46 -0400 | [diff] [blame] | 106 | REPORTER_ASSERT(reporter, tex->dimensions() == expectedSize); |
Michael Ludwig | bd2f070 | 2019-09-13 15:29:41 -0400 | [diff] [blame] | 107 | |
Greg Daniel | d51fa2f | 2020-01-22 16:53:38 -0500 | [diff] [blame] | 108 | REPORTER_ASSERT(reporter, tex->backendFormat() == texProxy->backendFormat()); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | |
robertphillips | 8abb370 | 2016-08-31 14:04:06 -0700 | [diff] [blame] | 112 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DeferredProxyTest, reporter, ctxInfo) { |
Robert Phillips | 6d344c3 | 2020-07-06 10:56:46 -0400 | [diff] [blame] | 113 | auto direct = ctxInfo.directContext(); |
| 114 | GrProxyProvider* proxyProvider = direct->priv().proxyProvider(); |
| 115 | GrResourceProvider* resourceProvider = direct->priv().resourceProvider(); |
| 116 | const GrCaps& caps = *direct->priv().caps(); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 117 | |
Robert Phillips | 6520a69 | 2017-02-01 09:20:00 -0500 | [diff] [blame] | 118 | int attempt = 0; // useful for debugging |
| 119 | |
Greg Daniel | 3a36511 | 2020-02-14 10:47:18 -0500 | [diff] [blame] | 120 | for (auto widthHeight : {100, 128, 1048576}) { |
| 121 | for (auto ct : {GrColorType::kAlpha_8, GrColorType::kBGR_565, GrColorType::kRGBA_8888, |
| 122 | GrColorType::kRGBA_1010102}) { |
| 123 | for (auto fit : {SkBackingFit::kExact, SkBackingFit::kApprox}) { |
| 124 | for (auto budgeted : {SkBudgeted::kYes, SkBudgeted::kNo}) { |
| 125 | for (auto numSamples : {1, 4, 16, 128}) { |
| 126 | SkISize dims = {widthHeight, widthHeight}; |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 127 | |
Greg Daniel | 3a36511 | 2020-02-14 10:47:18 -0500 | [diff] [blame] | 128 | auto format = caps.getDefaultBackendFormat(ct, GrRenderable::kYes); |
| 129 | if (!format.isValid()) { |
| 130 | continue; |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 131 | } |
Greg Daniel | 3a36511 | 2020-02-14 10:47:18 -0500 | [diff] [blame] | 132 | |
| 133 | // Renderable |
| 134 | { |
| 135 | sk_sp<GrTexture> tex; |
| 136 | if (SkBackingFit::kApprox == fit) { |
| 137 | tex = resourceProvider->createApproxTexture( |
| 138 | dims, format, GrRenderable::kYes, numSamples, |
| 139 | GrProtected::kNo); |
| 140 | } else { |
| 141 | tex = resourceProvider->createTexture( |
| 142 | dims, format, GrRenderable::kYes, numSamples, |
| 143 | GrMipMapped::kNo, budgeted, GrProtected::kNo); |
| 144 | } |
| 145 | |
| 146 | sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy( |
Brian Salomon | df1bd6d | 2020-03-26 20:37:01 -0400 | [diff] [blame] | 147 | format, dims, GrRenderable::kYes, numSamples, GrMipMapped::kNo, |
| 148 | fit, budgeted, GrProtected::kNo); |
Greg Daniel | 3a36511 | 2020-02-14 10:47:18 -0500 | [diff] [blame] | 149 | REPORTER_ASSERT(reporter, SkToBool(tex) == SkToBool(proxy)); |
| 150 | if (proxy) { |
| 151 | REPORTER_ASSERT(reporter, proxy->asRenderTargetProxy()); |
| 152 | // This forces the proxy to compute and cache its |
| 153 | // pre-instantiation size guess. Later, when it is actually |
| 154 | // instantiated, it checks that the instantiated size is <= to |
| 155 | // the pre-computation. If the proxy never computed its |
| 156 | // pre-instantiation size then the check is skipped. |
| 157 | proxy->gpuMemorySize(caps); |
| 158 | |
| 159 | check_surface(reporter, proxy.get(), widthHeight, widthHeight, |
| 160 | budgeted); |
| 161 | int supportedSamples = |
| 162 | caps.getRenderTargetSampleCount(numSamples, format); |
| 163 | check_rendertarget(reporter, caps, resourceProvider, |
| 164 | proxy->asRenderTargetProxy(), supportedSamples, |
| 165 | fit, caps.maxWindowRectangles()); |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | // Not renderable |
| 170 | { |
| 171 | sk_sp<GrTexture> tex; |
| 172 | if (SkBackingFit::kApprox == fit) { |
| 173 | tex = resourceProvider->createApproxTexture( |
| 174 | dims, format, GrRenderable::kNo, numSamples, |
| 175 | GrProtected::kNo); |
| 176 | } else { |
| 177 | tex = resourceProvider->createTexture( |
| 178 | dims, format, GrRenderable::kNo, numSamples, |
| 179 | GrMipMapped::kNo, budgeted, GrProtected::kNo); |
| 180 | } |
| 181 | |
| 182 | sk_sp<GrTextureProxy> proxy(proxyProvider->createProxy( |
Brian Salomon | df1bd6d | 2020-03-26 20:37:01 -0400 | [diff] [blame] | 183 | format, dims, GrRenderable::kNo, numSamples, GrMipMapped::kNo, |
| 184 | fit, budgeted, GrProtected::kNo)); |
Greg Daniel | 3a36511 | 2020-02-14 10:47:18 -0500 | [diff] [blame] | 185 | REPORTER_ASSERT(reporter, SkToBool(tex) == SkToBool(proxy)); |
| 186 | if (proxy) { |
| 187 | // This forces the proxy to compute and cache its |
| 188 | // pre-instantiation size guess. Later, when it is actually |
| 189 | // instantiated, it checks that the instantiated size is <= to |
| 190 | // the pre-computation. If the proxy never computed its |
| 191 | // pre-instantiation size then the check is skipped. |
| 192 | proxy->gpuMemorySize(caps); |
| 193 | |
| 194 | check_surface(reporter, proxy.get(), widthHeight, widthHeight, |
| 195 | budgeted); |
| 196 | check_texture(reporter, resourceProvider, proxy->asTextureProxy(), |
| 197 | fit); |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | attempt++; |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 202 | } |
| 203 | } |
| 204 | } |
| 205 | } |
| 206 | } |
| 207 | } |
| 208 | |
egdaniel | ab527a5 | 2016-06-28 08:07:26 -0700 | [diff] [blame] | 209 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WrappedProxyTest, reporter, ctxInfo) { |
Robert Phillips | 6d344c3 | 2020-07-06 10:56:46 -0400 | [diff] [blame] | 210 | auto direct = ctxInfo.directContext(); |
| 211 | GrProxyProvider* proxyProvider = direct->priv().proxyProvider(); |
| 212 | GrResourceProvider* resourceProvider = direct->priv().resourceProvider(); |
| 213 | GrGpu* gpu = direct->priv().getGpu(); |
| 214 | const GrCaps& caps = *direct->priv().caps(); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 215 | |
| 216 | static const int kWidthHeight = 100; |
| 217 | |
Greg Daniel | 3a36511 | 2020-02-14 10:47:18 -0500 | [diff] [blame] | 218 | for (auto colorType : |
| 219 | {kAlpha_8_SkColorType, kRGBA_8888_SkColorType, kRGBA_1010102_SkColorType}) { |
| 220 | GrColorType grColorType = SkColorTypeToGrColorType(colorType); |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 221 | |
Greg Daniel | 3a36511 | 2020-02-14 10:47:18 -0500 | [diff] [blame] | 222 | // External on-screen render target. |
| 223 | // Tests wrapBackendRenderTarget with a GrBackendRenderTarget |
| 224 | // Our test-only function that creates a backend render target doesn't currently support |
| 225 | // sample counts :(. |
Robert Phillips | 6d344c3 | 2020-07-06 10:56:46 -0400 | [diff] [blame] | 226 | if (direct->colorTypeSupportedAsSurface(colorType)) { |
Greg Daniel | 3a36511 | 2020-02-14 10:47:18 -0500 | [diff] [blame] | 227 | GrBackendRenderTarget backendRT = gpu->createTestingOnlyBackendRenderTarget( |
| 228 | kWidthHeight, kWidthHeight, grColorType); |
Brian Salomon | 8a78e9c | 2020-03-27 10:42:15 -0400 | [diff] [blame] | 229 | sk_sp<GrSurfaceProxy> sProxy( |
Robert Phillips | a112133 | 2020-06-29 13:05:29 -0400 | [diff] [blame] | 230 | proxyProvider->wrapBackendRenderTarget(backendRT, nullptr)); |
Greg Daniel | 3a36511 | 2020-02-14 10:47:18 -0500 | [diff] [blame] | 231 | check_surface(reporter, sProxy.get(), kWidthHeight, kWidthHeight, SkBudgeted::kNo); |
| 232 | static constexpr int kExpectedNumSamples = 1; |
| 233 | check_rendertarget(reporter, caps, resourceProvider, sProxy->asRenderTargetProxy(), |
| 234 | kExpectedNumSamples, SkBackingFit::kExact, |
| 235 | caps.maxWindowRectangles()); |
| 236 | gpu->deleteTestingOnlyBackendRenderTarget(backendRT); |
| 237 | } |
| 238 | |
| 239 | for (auto numSamples : {1, 4}) { |
| 240 | auto beFormat = caps.getDefaultBackendFormat(grColorType, GrRenderable::kYes); |
| 241 | int supportedNumSamples = caps.getRenderTargetSampleCount(numSamples, beFormat); |
| 242 | if (!supportedNumSamples) { |
| 243 | continue; |
Brian Salomon | 52e943a | 2018-03-13 09:32:39 -0400 | [diff] [blame] | 244 | } |
| 245 | |
Greg Daniel | 3a36511 | 2020-02-14 10:47:18 -0500 | [diff] [blame] | 246 | #ifdef SK_GL |
| 247 | // Test wrapping FBO 0 (with made up properties). This tests sample count and the |
| 248 | // special case where FBO 0 doesn't support window rectangles. |
| 249 | if (GrBackendApi::kOpenGL == ctxInfo.backend()) { |
| 250 | GrGLFramebufferInfo fboInfo; |
| 251 | fboInfo.fFBOID = 0; |
| 252 | fboInfo.fFormat = GrGLFormatToEnum(beFormat.asGLFormat()); |
| 253 | SkASSERT(fboInfo.fFormat); |
| 254 | static constexpr int kStencilBits = 8; |
| 255 | GrBackendRenderTarget backendRT(kWidthHeight, kWidthHeight, numSamples, |
| 256 | kStencilBits, fboInfo); |
Brian Salomon | 8a78e9c | 2020-03-27 10:42:15 -0400 | [diff] [blame] | 257 | sk_sp<GrSurfaceProxy> sProxy( |
Robert Phillips | a112133 | 2020-06-29 13:05:29 -0400 | [diff] [blame] | 258 | proxyProvider->wrapBackendRenderTarget(backendRT, nullptr)); |
Greg Daniel | 3a36511 | 2020-02-14 10:47:18 -0500 | [diff] [blame] | 259 | check_surface(reporter, sProxy.get(), kWidthHeight, kWidthHeight, SkBudgeted::kNo); |
| 260 | check_rendertarget(reporter, caps, resourceProvider, sProxy->asRenderTargetProxy(), |
| 261 | supportedNumSamples, SkBackingFit::kExact, 0); |
| 262 | } |
| 263 | #endif |
| 264 | |
| 265 | // Tests wrapBackendRenderTarget with a GrBackendTexture |
| 266 | { |
Greg Daniel | c1ad77c | 2020-05-06 11:40:03 -0400 | [diff] [blame] | 267 | GrBackendTexture backendTex; |
Robert Phillips | 6d344c3 | 2020-07-06 10:56:46 -0400 | [diff] [blame] | 268 | CreateBackendTexture(direct, &backendTex, kWidthHeight, kWidthHeight, colorType, |
Greg Daniel | c1ad77c | 2020-05-06 11:40:03 -0400 | [diff] [blame] | 269 | SkColors::kTransparent, GrMipMapped::kNo, GrRenderable::kYes, |
| 270 | GrProtected::kNo); |
Greg Daniel | 3a36511 | 2020-02-14 10:47:18 -0500 | [diff] [blame] | 271 | sk_sp<GrSurfaceProxy> sProxy = proxyProvider->wrapBackendTextureAsRenderTarget( |
Brian Salomon | 8a78e9c | 2020-03-27 10:42:15 -0400 | [diff] [blame] | 272 | backendTex, supportedNumSamples); |
Greg Daniel | 3a36511 | 2020-02-14 10:47:18 -0500 | [diff] [blame] | 273 | if (!sProxy) { |
Robert Phillips | 6d344c3 | 2020-07-06 10:56:46 -0400 | [diff] [blame] | 274 | direct->deleteBackendTexture(backendTex); |
Greg Daniel | 3a36511 | 2020-02-14 10:47:18 -0500 | [diff] [blame] | 275 | continue; // This can fail on Mesa |
| 276 | } |
| 277 | |
| 278 | check_surface(reporter, sProxy.get(), kWidthHeight, kWidthHeight, SkBudgeted::kNo); |
| 279 | check_rendertarget(reporter, caps, resourceProvider, sProxy->asRenderTargetProxy(), |
| 280 | supportedNumSamples, SkBackingFit::kExact, |
| 281 | caps.maxWindowRectangles()); |
| 282 | |
Robert Phillips | 6d344c3 | 2020-07-06 10:56:46 -0400 | [diff] [blame] | 283 | direct->deleteBackendTexture(backendTex); |
Greg Daniel | 3a36511 | 2020-02-14 10:47:18 -0500 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | // Tests wrapBackendTexture that is only renderable |
| 287 | { |
Greg Daniel | c1ad77c | 2020-05-06 11:40:03 -0400 | [diff] [blame] | 288 | GrBackendTexture backendTex; |
Robert Phillips | 6d344c3 | 2020-07-06 10:56:46 -0400 | [diff] [blame] | 289 | CreateBackendTexture(direct, &backendTex, kWidthHeight, kWidthHeight, colorType, |
Greg Daniel | c1ad77c | 2020-05-06 11:40:03 -0400 | [diff] [blame] | 290 | SkColors::kTransparent, GrMipMapped::kNo, GrRenderable::kYes, |
| 291 | GrProtected::kNo); |
Greg Daniel | 3a36511 | 2020-02-14 10:47:18 -0500 | [diff] [blame] | 292 | |
| 293 | sk_sp<GrSurfaceProxy> sProxy = proxyProvider->wrapRenderableBackendTexture( |
Brian Salomon | 8a78e9c | 2020-03-27 10:42:15 -0400 | [diff] [blame] | 294 | backendTex, supportedNumSamples, kBorrow_GrWrapOwnership, |
Robert Phillips | a112133 | 2020-06-29 13:05:29 -0400 | [diff] [blame] | 295 | GrWrapCacheable::kNo, nullptr); |
Greg Daniel | 3a36511 | 2020-02-14 10:47:18 -0500 | [diff] [blame] | 296 | if (!sProxy) { |
Robert Phillips | 6d344c3 | 2020-07-06 10:56:46 -0400 | [diff] [blame] | 297 | direct->deleteBackendTexture(backendTex); |
Greg Daniel | 3a36511 | 2020-02-14 10:47:18 -0500 | [diff] [blame] | 298 | continue; // This can fail on Mesa |
| 299 | } |
| 300 | |
| 301 | check_surface(reporter, sProxy.get(), kWidthHeight, kWidthHeight, SkBudgeted::kNo); |
| 302 | check_rendertarget(reporter, caps, resourceProvider, sProxy->asRenderTargetProxy(), |
| 303 | supportedNumSamples, SkBackingFit::kExact, |
| 304 | caps.maxWindowRectangles()); |
| 305 | |
Robert Phillips | 6d344c3 | 2020-07-06 10:56:46 -0400 | [diff] [blame] | 306 | direct->deleteBackendTexture(backendTex); |
Greg Daniel | 3a36511 | 2020-02-14 10:47:18 -0500 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | // Tests wrapBackendTexture that is only textureable |
| 310 | { |
| 311 | // Internal offscreen texture |
Greg Daniel | c1ad77c | 2020-05-06 11:40:03 -0400 | [diff] [blame] | 312 | GrBackendTexture backendTex; |
Robert Phillips | 6d344c3 | 2020-07-06 10:56:46 -0400 | [diff] [blame] | 313 | CreateBackendTexture(direct, &backendTex, kWidthHeight, kWidthHeight, colorType, |
Greg Daniel | c1ad77c | 2020-05-06 11:40:03 -0400 | [diff] [blame] | 314 | SkColors::kTransparent, GrMipMapped::kNo, GrRenderable::kNo, |
| 315 | GrProtected::kNo); |
Greg Daniel | 3a36511 | 2020-02-14 10:47:18 -0500 | [diff] [blame] | 316 | |
| 317 | sk_sp<GrSurfaceProxy> sProxy = proxyProvider->wrapBackendTexture( |
Brian Salomon | 8a78e9c | 2020-03-27 10:42:15 -0400 | [diff] [blame] | 318 | backendTex, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, kRead_GrIOType); |
Greg Daniel | 3a36511 | 2020-02-14 10:47:18 -0500 | [diff] [blame] | 319 | if (!sProxy) { |
Robert Phillips | 6d344c3 | 2020-07-06 10:56:46 -0400 | [diff] [blame] | 320 | direct->deleteBackendTexture(backendTex); |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 321 | continue; |
| 322 | } |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 323 | |
Greg Daniel | 3a36511 | 2020-02-14 10:47:18 -0500 | [diff] [blame] | 324 | check_surface(reporter, sProxy.get(), kWidthHeight, kWidthHeight, SkBudgeted::kNo); |
| 325 | check_texture(reporter, resourceProvider, sProxy->asTextureProxy(), |
| 326 | SkBackingFit::kExact); |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 327 | |
Robert Phillips | 6d344c3 | 2020-07-06 10:56:46 -0400 | [diff] [blame] | 328 | direct->deleteBackendTexture(backendTex); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 329 | } |
| 330 | } |
| 331 | } |
| 332 | } |
| 333 | |
Robert Phillips | 78de212 | 2017-04-26 07:44:26 -0400 | [diff] [blame] | 334 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ZeroSizedProxyTest, reporter, ctxInfo) { |
Robert Phillips | 6d344c3 | 2020-07-06 10:56:46 -0400 | [diff] [blame] | 335 | auto direct = ctxInfo.directContext(); |
| 336 | GrProxyProvider* provider = direct->priv().proxyProvider(); |
Robert Phillips | 78de212 | 2017-04-26 07:44:26 -0400 | [diff] [blame] | 337 | |
Brian Salomon | f2c2ba9 | 2019-07-17 09:59:59 -0400 | [diff] [blame] | 338 | for (auto renderable : {GrRenderable::kNo, GrRenderable::kYes}) { |
Robert Phillips | 78de212 | 2017-04-26 07:44:26 -0400 | [diff] [blame] | 339 | for (auto fit : { SkBackingFit::kExact, SkBackingFit::kApprox }) { |
| 340 | for (int width : { 0, 100 }) { |
| 341 | for (int height : { 0, 100}) { |
| 342 | if (width && height) { |
| 343 | continue; // not zero-sized |
| 344 | } |
| 345 | |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 346 | const GrBackendFormat format = |
Robert Phillips | 6d344c3 | 2020-07-06 10:56:46 -0400 | [diff] [blame] | 347 | direct->priv().caps()->getDefaultBackendFormat( |
Robert Phillips | 0a15cc6 | 2019-07-30 12:49:10 -0400 | [diff] [blame] | 348 | GrColorType::kRGBA_8888, |
| 349 | renderable); |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 350 | |
Greg Daniel | 3a36511 | 2020-02-14 10:47:18 -0500 | [diff] [blame] | 351 | sk_sp<GrTextureProxy> proxy = provider->createProxy( |
Brian Salomon | df1bd6d | 2020-03-26 20:37:01 -0400 | [diff] [blame] | 352 | format, {width, height}, renderable, 1, GrMipMapped::kNo, fit, |
Greg Daniel | 3a36511 | 2020-02-14 10:47:18 -0500 | [diff] [blame] | 353 | SkBudgeted::kNo, GrProtected::kNo); |
Robert Phillips | 78de212 | 2017-04-26 07:44:26 -0400 | [diff] [blame] | 354 | REPORTER_ASSERT(reporter, !proxy); |
| 355 | } |
| 356 | } |
| 357 | } |
| 358 | } |
| 359 | } |