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