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