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