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 | |
| 10 | #include "Test.h" |
| 11 | |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 12 | #include "GrBackendSurface.h" |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 13 | #include "GrContextPriv.h" |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 14 | #include "GrProxyProvider.h" |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 15 | #include "GrRenderTargetPriv.h" |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 16 | #include "GrRenderTargetProxy.h" |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 17 | #include "GrResourceProvider.h" |
Robert Phillips | fe0253f | 2018-03-16 16:47:25 -0400 | [diff] [blame] | 18 | #include "GrSurfacePriv.h" |
Robert Phillips | f95b175 | 2017-08-31 08:56:07 -0400 | [diff] [blame] | 19 | #include "GrSurfaceProxyPriv.h" |
Robert Phillips | 646e429 | 2017-06-13 12:44:56 -0400 | [diff] [blame] | 20 | #include "GrTexture.h" |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 21 | #include "GrTextureProxy.h" |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 22 | #include "SkGr.h" |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 23 | |
robertphillips | 8abb370 | 2016-08-31 14:04:06 -0700 | [diff] [blame] | 24 | // Check that the surface proxy's member vars are set as expected |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 25 | static void check_surface(skiatest::Reporter* reporter, |
| 26 | GrSurfaceProxy* proxy, |
| 27 | GrSurfaceOrigin origin, |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 28 | int width, int height, |
robertphillips | 8abb370 | 2016-08-31 14:04:06 -0700 | [diff] [blame] | 29 | GrPixelConfig config, |
Robert Phillips | abacf09 | 2016-11-02 10:23:32 -0400 | [diff] [blame] | 30 | SkBudgeted budgeted) { |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 31 | REPORTER_ASSERT(reporter, proxy->origin() == origin); |
| 32 | REPORTER_ASSERT(reporter, proxy->width() == width); |
| 33 | REPORTER_ASSERT(reporter, proxy->height() == height); |
| 34 | REPORTER_ASSERT(reporter, proxy->config() == config); |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 35 | REPORTER_ASSERT(reporter, !proxy->uniqueID().isInvalid()); |
Robert Phillips | abacf09 | 2016-11-02 10:23:32 -0400 | [diff] [blame] | 36 | REPORTER_ASSERT(reporter, proxy->isBudgeted() == budgeted); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | static void check_rendertarget(skiatest::Reporter* reporter, |
Robert Phillips | ec2249f | 2016-11-09 08:54:35 -0500 | [diff] [blame] | 40 | const GrCaps& caps, |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 41 | GrResourceProvider* provider, |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 42 | GrRenderTargetProxy* rtProxy, |
Robert Phillips | abacf09 | 2016-11-02 10:23:32 -0400 | [diff] [blame] | 43 | int numSamples, |
Robert Phillips | ec2249f | 2016-11-09 08:54:35 -0500 | [diff] [blame] | 44 | SkBackingFit fit, |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 45 | int expectedMaxWindowRects) { |
Robert Phillips | ec2249f | 2016-11-09 08:54:35 -0500 | [diff] [blame] | 46 | REPORTER_ASSERT(reporter, rtProxy->maxWindowRectangles(caps) == expectedMaxWindowRects); |
Robert Phillips | abacf09 | 2016-11-02 10:23:32 -0400 | [diff] [blame] | 47 | REPORTER_ASSERT(reporter, rtProxy->numStencilSamples() == numSamples); |
| 48 | |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 49 | GrSurfaceProxy::UniqueID idBefore = rtProxy->uniqueID(); |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 50 | bool preinstantiated = rtProxy->isInstantiated(); |
Robert Phillips | eee4d6e | 2017-06-05 09:26:07 -0400 | [diff] [blame] | 51 | REPORTER_ASSERT(reporter, rtProxy->instantiate(provider)); |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 52 | GrRenderTarget* rt = rtProxy->peekRenderTarget(); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 53 | |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 54 | REPORTER_ASSERT(reporter, rtProxy->uniqueID() == idBefore); |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 55 | // Deferred resources should always have a different ID from their instantiated rendertarget |
Brian Salomon | f777897 | 2018-03-08 10:13:17 -0500 | [diff] [blame] | 56 | if (preinstantiated) { |
| 57 | REPORTER_ASSERT(reporter, rtProxy->uniqueID().asUInt() == rt->uniqueID().asUInt()); |
| 58 | } else { |
| 59 | REPORTER_ASSERT(reporter, rtProxy->uniqueID().asUInt() != rt->uniqueID().asUInt()); |
| 60 | } |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 61 | |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 62 | if (SkBackingFit::kExact == fit) { |
| 63 | REPORTER_ASSERT(reporter, rt->width() == rtProxy->width()); |
| 64 | REPORTER_ASSERT(reporter, rt->height() == rtProxy->height()); |
| 65 | } else { |
| 66 | REPORTER_ASSERT(reporter, rt->width() >= rtProxy->width()); |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 67 | REPORTER_ASSERT(reporter, rt->height() >= rtProxy->height()); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 68 | } |
| 69 | REPORTER_ASSERT(reporter, rt->config() == rtProxy->config()); |
| 70 | |
Brian Salomon | 7c8460e | 2017-05-12 11:36:10 -0400 | [diff] [blame] | 71 | REPORTER_ASSERT(reporter, rt->fsaaType() == rtProxy->fsaaType()); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 72 | REPORTER_ASSERT(reporter, rt->numColorSamples() == rtProxy->numColorSamples()); |
| 73 | REPORTER_ASSERT(reporter, rt->numStencilSamples() == rtProxy->numStencilSamples()); |
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(); |
Robert Phillips | eee4d6e | 2017-06-05 09:26:07 -0400 | [diff] [blame] | 84 | REPORTER_ASSERT(reporter, texProxy->instantiate(provider)); |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 85 | GrTexture* tex = texProxy->peekTexture(); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 86 | |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 87 | REPORTER_ASSERT(reporter, texProxy->uniqueID() == idBefore); |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 88 | // Deferred resources should always have a different ID from their instantiated texture |
Brian Salomon | f777897 | 2018-03-08 10:13:17 -0500 | [diff] [blame] | 89 | if (preinstantiated) { |
| 90 | REPORTER_ASSERT(reporter, texProxy->uniqueID().asUInt() == tex->uniqueID().asUInt()); |
| 91 | } else { |
| 92 | REPORTER_ASSERT(reporter, texProxy->uniqueID().asUInt() != tex->uniqueID().asUInt()); |
| 93 | } |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 94 | |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 95 | if (SkBackingFit::kExact == fit) { |
| 96 | REPORTER_ASSERT(reporter, tex->width() == texProxy->width()); |
| 97 | REPORTER_ASSERT(reporter, tex->height() == texProxy->height()); |
| 98 | } else { |
| 99 | REPORTER_ASSERT(reporter, tex->width() >= texProxy->width()); |
| 100 | REPORTER_ASSERT(reporter, tex->height() >= texProxy->height()); |
| 101 | } |
| 102 | REPORTER_ASSERT(reporter, tex->config() == texProxy->config()); |
| 103 | } |
| 104 | |
| 105 | |
robertphillips | 8abb370 | 2016-08-31 14:04:06 -0700 | [diff] [blame] | 106 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DeferredProxyTest, reporter, ctxInfo) { |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 107 | GrProxyProvider* proxyProvider = ctxInfo.grContext()->contextPriv().proxyProvider(); |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 108 | GrResourceProvider* resourceProvider = ctxInfo.grContext()->contextPriv().resourceProvider(); |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 109 | const GrCaps& caps = *ctxInfo.grContext()->contextPriv().caps(); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 110 | |
Robert Phillips | 6520a69 | 2017-02-01 09:20:00 -0500 | [diff] [blame] | 111 | int attempt = 0; // useful for debugging |
| 112 | |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 113 | for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin }) { |
Robert Phillips | 40d9495 | 2017-01-30 14:15:59 -0500 | [diff] [blame] | 114 | for (auto widthHeight : { 100, 128, 1048576 }) { |
Robert Phillips | 6520a69 | 2017-02-01 09:20:00 -0500 | [diff] [blame] | 115 | for (auto config : { kAlpha_8_GrPixelConfig, kRGB_565_GrPixelConfig, |
Jim Van Verth | 1676cb9 | 2019-01-15 13:24:45 -0500 | [diff] [blame] | 116 | kRGBA_8888_GrPixelConfig, kRGBA_1010102_GrPixelConfig, |
| 117 | kRGB_ETC1_GrPixelConfig }) { |
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}) { |
Jim Van Verth | 1676cb9 | 2019-01-15 13:24:45 -0500 | [diff] [blame] | 121 | // We don't have recycling support for compressed textures |
| 122 | if (GrPixelConfigIsCompressed(config) && SkBackingFit::kApprox == fit) { |
| 123 | continue; |
| 124 | } |
| 125 | |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 126 | GrSurfaceDesc desc; |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 127 | desc.fFlags = kRenderTarget_GrSurfaceFlag; |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 128 | desc.fWidth = widthHeight; |
| 129 | desc.fHeight = widthHeight; |
| 130 | desc.fConfig = config; |
| 131 | desc.fSampleCnt = numSamples; |
| 132 | |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 133 | GrSRGBEncoded srgbEncoded; |
| 134 | GrColorType colorType = |
| 135 | GrPixelConfigToColorTypeAndEncoding(config, &srgbEncoded); |
| 136 | const GrBackendFormat format = |
| 137 | caps.getBackendFormatFromGrColorType(colorType, srgbEncoded); |
| 138 | |
Robert Phillips | 6520a69 | 2017-02-01 09:20:00 -0500 | [diff] [blame] | 139 | { |
| 140 | sk_sp<GrTexture> tex; |
| 141 | if (SkBackingFit::kApprox == fit) { |
Chris Dalton | d004e0b | 2018-09-27 09:28:03 -0600 | [diff] [blame] | 142 | tex = resourceProvider->createApproxTexture( |
| 143 | desc, GrResourceProvider::Flags::kNone); |
Robert Phillips | 6520a69 | 2017-02-01 09:20:00 -0500 | [diff] [blame] | 144 | } else { |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 145 | tex = resourceProvider->createTexture(desc, budgeted); |
Robert Phillips | 6520a69 | 2017-02-01 09:20:00 -0500 | [diff] [blame] | 146 | } |
| 147 | |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 148 | sk_sp<GrTextureProxy> proxy = |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 149 | proxyProvider->createProxy(format, desc, origin, fit, |
| 150 | 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 | |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 172 | desc.fFlags = kNone_GrSurfaceFlags; |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 173 | |
Robert Phillips | 6520a69 | 2017-02-01 09:20:00 -0500 | [diff] [blame] | 174 | { |
| 175 | sk_sp<GrTexture> tex; |
| 176 | if (SkBackingFit::kApprox == fit) { |
Chris Dalton | d004e0b | 2018-09-27 09:28:03 -0600 | [diff] [blame] | 177 | tex = resourceProvider->createApproxTexture( |
| 178 | desc, GrResourceProvider::Flags::kNone); |
Robert Phillips | 6520a69 | 2017-02-01 09:20:00 -0500 | [diff] [blame] | 179 | } else { |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 180 | tex = resourceProvider->createTexture(desc, budgeted); |
Robert Phillips | 6520a69 | 2017-02-01 09:20:00 -0500 | [diff] [blame] | 181 | } |
Robert Phillips | b446088 | 2016-11-17 14:43:51 -0500 | [diff] [blame] | 182 | |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 183 | sk_sp<GrTextureProxy> proxy( |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 184 | proxyProvider->createProxy(format, desc, origin, fit, |
| 185 | budgeted)); |
Robert Phillips | 2f49314 | 2017-03-02 18:18:38 -0500 | [diff] [blame] | 186 | REPORTER_ASSERT(reporter, SkToBool(tex) == SkToBool(proxy)); |
| 187 | if (proxy) { |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 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. |
Robert Phillips | 2f49314 | 2017-03-02 18:18:38 -0500 | [diff] [blame] | 193 | proxy->gpuMemorySize(); |
Robert Phillips | 6520a69 | 2017-02-01 09:20:00 -0500 | [diff] [blame] | 194 | |
Robert Phillips | 2f49314 | 2017-03-02 18:18:38 -0500 | [diff] [blame] | 195 | check_surface(reporter, proxy.get(), origin, |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 196 | widthHeight, widthHeight, config, budgeted); |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 197 | check_texture(reporter, resourceProvider, |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 198 | proxy->asTextureProxy(), fit); |
Robert Phillips | 6520a69 | 2017-02-01 09:20:00 -0500 | [diff] [blame] | 199 | } |
Robert Phillips | 40d9495 | 2017-01-30 14:15:59 -0500 | [diff] [blame] | 200 | } |
Robert Phillips | 6520a69 | 2017-02-01 09:20:00 -0500 | [diff] [blame] | 201 | |
| 202 | attempt++; |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 203 | } |
| 204 | } |
| 205 | } |
| 206 | } |
| 207 | } |
| 208 | } |
| 209 | } |
| 210 | |
egdaniel | ab527a5 | 2016-06-28 08:07:26 -0700 | [diff] [blame] | 211 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WrappedProxyTest, reporter, ctxInfo) { |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 212 | GrProxyProvider* proxyProvider = ctxInfo.grContext()->contextPriv().proxyProvider(); |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 213 | GrResourceProvider* resourceProvider = ctxInfo.grContext()->contextPriv().resourceProvider(); |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 214 | GrGpu* gpu = ctxInfo.grContext()->contextPriv().getGpu(); |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 215 | const GrCaps& caps = *ctxInfo.grContext()->contextPriv().caps(); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 216 | |
| 217 | static const int kWidthHeight = 100; |
| 218 | |
| 219 | for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin }) { |
Brian Osman | 10fc6fd | 2018-03-02 11:01:10 -0500 | [diff] [blame] | 220 | for (auto colorType : { kAlpha_8_SkColorType, kRGBA_8888_SkColorType, |
| 221 | kRGBA_1010102_SkColorType }) { |
Brian Salomon | 52e943a | 2018-03-13 09:32:39 -0400 | [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 :(. |
| 226 | if (ctxInfo.grContext()->colorTypeSupportedAsSurface(colorType)) { |
| 227 | GrBackendRenderTarget backendRT = gpu->createTestingOnlyBackendRenderTarget( |
Brian Osman | 2d010b6 | 2018-08-09 10:55:09 -0400 | [diff] [blame] | 228 | kWidthHeight, kWidthHeight, SkColorTypeToGrColorType(colorType)); |
Brian Salomon | 52e943a | 2018-03-13 09:32:39 -0400 | [diff] [blame] | 229 | sk_sp<GrSurfaceProxy> sProxy( |
| 230 | proxyProvider->wrapBackendRenderTarget(backendRT, origin)); |
| 231 | check_surface(reporter, sProxy.get(), origin, kWidthHeight, kWidthHeight, |
Greg Daniel | 108bb23 | 2018-07-03 16:18:29 -0400 | [diff] [blame] | 232 | backendRT.pixelConfig(), SkBudgeted::kNo); |
Brian Salomon | 52e943a | 2018-03-13 09:32:39 -0400 | [diff] [blame] | 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 | |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 240 | for (auto numSamples : {1, 4}) { |
Brian Osman | 2b23c4b | 2018-06-01 12:25:08 -0400 | [diff] [blame] | 241 | GrPixelConfig config = SkColorType2GrPixelConfig(colorType); |
Greg Daniel | 0a7aa14 | 2018-02-21 13:02:32 -0500 | [diff] [blame] | 242 | SkASSERT(kUnknown_GrPixelConfig != config); |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 243 | int supportedNumSamples = caps.getRenderTargetSampleCount(numSamples, config); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 244 | |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 245 | if (!supportedNumSamples) { |
| 246 | continue; |
| 247 | } |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 248 | |
Brian Salomon | 52e943a | 2018-03-13 09:32:39 -0400 | [diff] [blame] | 249 | // Test wrapping FBO 0 (with made up properties). This tests sample count and the |
| 250 | // special case where FBO 0 doesn't support window rectangles. |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 251 | if (GrBackendApi::kOpenGL == ctxInfo.backend()) { |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 252 | GrGLFramebufferInfo fboInfo; |
| 253 | fboInfo.fFBOID = 0; |
Brian Salomon | 52e943a | 2018-03-13 09:32:39 -0400 | [diff] [blame] | 254 | static constexpr int kStencilBits = 8; |
| 255 | GrBackendRenderTarget backendRT(kWidthHeight, kWidthHeight, numSamples, |
Greg Daniel | 108bb23 | 2018-07-03 16:18:29 -0400 | [diff] [blame] | 256 | kStencilBits, fboInfo); |
| 257 | backendRT.setPixelConfig(config); |
Brian Salomon | 7578f3e | 2018-03-07 14:39:54 -0500 | [diff] [blame] | 258 | sk_sp<GrSurfaceProxy> sProxy( |
| 259 | proxyProvider->wrapBackendRenderTarget(backendRT, origin)); |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 260 | check_surface(reporter, sProxy.get(), origin, |
| 261 | kWidthHeight, kWidthHeight, |
Greg Daniel | 108bb23 | 2018-07-03 16:18:29 -0400 | [diff] [blame] | 262 | backendRT.pixelConfig(), SkBudgeted::kNo); |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 263 | check_rendertarget(reporter, caps, resourceProvider, |
| 264 | sProxy->asRenderTargetProxy(), |
| 265 | supportedNumSamples, SkBackingFit::kExact, 0); |
| 266 | } |
| 267 | |
Brian Salomon | 7578f3e | 2018-03-07 14:39:54 -0500 | [diff] [blame] | 268 | // Tests wrapBackendRenderTarget with a GrBackendTexture |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 269 | { |
| 270 | GrBackendTexture backendTex = |
| 271 | gpu->createTestingOnlyBackendTexture(nullptr, kWidthHeight, |
Brian Osman | 2b23c4b | 2018-06-01 12:25:08 -0400 | [diff] [blame] | 272 | kWidthHeight, colorType, |
Greg Daniel | 57bf4a3 | 2018-04-19 10:28:37 -0400 | [diff] [blame] | 273 | true, GrMipMapped::kNo); |
Brian Salomon | 7578f3e | 2018-03-07 14:39:54 -0500 | [diff] [blame] | 274 | sk_sp<GrSurfaceProxy> sProxy = proxyProvider->wrapBackendTextureAsRenderTarget( |
| 275 | backendTex, origin, supportedNumSamples); |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 276 | if (!sProxy) { |
Brian Salomon | 26102cb | 2018-03-09 09:33:19 -0500 | [diff] [blame] | 277 | gpu->deleteTestingOnlyBackendTexture(backendTex); |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 278 | continue; // This can fail on Mesa |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 279 | } |
| 280 | |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 281 | check_surface(reporter, sProxy.get(), origin, |
| 282 | kWidthHeight, kWidthHeight, |
Greg Daniel | 108bb23 | 2018-07-03 16:18:29 -0400 | [diff] [blame] | 283 | backendTex.pixelConfig(), SkBudgeted::kNo); |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 284 | check_rendertarget(reporter, caps, resourceProvider, |
| 285 | sProxy->asRenderTargetProxy(), |
| 286 | supportedNumSamples, SkBackingFit::kExact, |
| 287 | caps.maxWindowRectangles()); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 288 | |
Brian Salomon | 26102cb | 2018-03-09 09:33:19 -0500 | [diff] [blame] | 289 | gpu->deleteTestingOnlyBackendTexture(backendTex); |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 290 | } |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 291 | |
Brian Salomon | 7578f3e | 2018-03-07 14:39:54 -0500 | [diff] [blame] | 292 | // Tests wrapBackendTexture that is only renderable |
Greg Daniel | f87651e | 2018-02-21 11:36:53 -0500 | [diff] [blame] | 293 | { |
| 294 | GrBackendTexture backendTex = |
| 295 | gpu->createTestingOnlyBackendTexture(nullptr, kWidthHeight, |
Brian Osman | 2b23c4b | 2018-06-01 12:25:08 -0400 | [diff] [blame] | 296 | kWidthHeight, colorType, |
Greg Daniel | 57bf4a3 | 2018-04-19 10:28:37 -0400 | [diff] [blame] | 297 | true, GrMipMapped::kNo); |
Greg Daniel | f87651e | 2018-02-21 11:36:53 -0500 | [diff] [blame] | 298 | |
Brian Salomon | 7578f3e | 2018-03-07 14:39:54 -0500 | [diff] [blame] | 299 | sk_sp<GrSurfaceProxy> sProxy = proxyProvider->wrapRenderableBackendTexture( |
| 300 | backendTex, origin, supportedNumSamples); |
Greg Daniel | f87651e | 2018-02-21 11:36:53 -0500 | [diff] [blame] | 301 | if (!sProxy) { |
Brian Salomon | 26102cb | 2018-03-09 09:33:19 -0500 | [diff] [blame] | 302 | gpu->deleteTestingOnlyBackendTexture(backendTex); |
Greg Daniel | f87651e | 2018-02-21 11:36:53 -0500 | [diff] [blame] | 303 | continue; // This can fail on Mesa |
| 304 | } |
| 305 | |
| 306 | check_surface(reporter, sProxy.get(), origin, |
| 307 | kWidthHeight, kWidthHeight, |
Greg Daniel | 108bb23 | 2018-07-03 16:18:29 -0400 | [diff] [blame] | 308 | backendTex.pixelConfig(), SkBudgeted::kNo); |
Greg Daniel | f87651e | 2018-02-21 11:36:53 -0500 | [diff] [blame] | 309 | check_rendertarget(reporter, caps, resourceProvider, |
| 310 | sProxy->asRenderTargetProxy(), |
| 311 | supportedNumSamples, SkBackingFit::kExact, |
| 312 | caps.maxWindowRectangles()); |
| 313 | |
Brian Salomon | 26102cb | 2018-03-09 09:33:19 -0500 | [diff] [blame] | 314 | gpu->deleteTestingOnlyBackendTexture(backendTex); |
Greg Daniel | f87651e | 2018-02-21 11:36:53 -0500 | [diff] [blame] | 315 | } |
| 316 | |
Brian Salomon | 7578f3e | 2018-03-07 14:39:54 -0500 | [diff] [blame] | 317 | // Tests wrapBackendTexture that is only textureable |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 318 | { |
| 319 | // Internal offscreen texture |
| 320 | GrBackendTexture backendTex = |
| 321 | gpu->createTestingOnlyBackendTexture(nullptr, kWidthHeight, |
Brian Osman | 2b23c4b | 2018-06-01 12:25:08 -0400 | [diff] [blame] | 322 | kWidthHeight, colorType, |
Greg Daniel | 57bf4a3 | 2018-04-19 10:28:37 -0400 | [diff] [blame] | 323 | false, GrMipMapped::kNo); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 324 | |
Brian Salomon | 7578f3e | 2018-03-07 14:39:54 -0500 | [diff] [blame] | 325 | sk_sp<GrSurfaceProxy> sProxy = proxyProvider->wrapBackendTexture( |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 326 | backendTex, origin, kBorrow_GrWrapOwnership, kRead_GrIOType); |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 327 | if (!sProxy) { |
Brian Salomon | 26102cb | 2018-03-09 09:33:19 -0500 | [diff] [blame] | 328 | gpu->deleteTestingOnlyBackendTexture(backendTex); |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 329 | continue; |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 330 | } |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 331 | |
| 332 | check_surface(reporter, sProxy.get(), origin, |
| 333 | kWidthHeight, kWidthHeight, |
Greg Daniel | 108bb23 | 2018-07-03 16:18:29 -0400 | [diff] [blame] | 334 | backendTex.pixelConfig(), SkBudgeted::kNo); |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 335 | check_texture(reporter, resourceProvider, sProxy->asTextureProxy(), |
| 336 | SkBackingFit::kExact); |
| 337 | |
Brian Salomon | 26102cb | 2018-03-09 09:33:19 -0500 | [diff] [blame] | 338 | gpu->deleteTestingOnlyBackendTexture(backendTex); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 339 | } |
| 340 | } |
| 341 | } |
| 342 | } |
| 343 | } |
| 344 | |
Robert Phillips | 78de212 | 2017-04-26 07:44:26 -0400 | [diff] [blame] | 345 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ZeroSizedProxyTest, reporter, ctxInfo) { |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 346 | GrProxyProvider* provider = ctxInfo.grContext()->contextPriv().proxyProvider(); |
Robert Phillips | 78de212 | 2017-04-26 07:44:26 -0400 | [diff] [blame] | 347 | |
| 348 | for (auto flags : { kRenderTarget_GrSurfaceFlag, kNone_GrSurfaceFlags }) { |
| 349 | for (auto fit : { SkBackingFit::kExact, SkBackingFit::kApprox }) { |
| 350 | for (int width : { 0, 100 }) { |
| 351 | for (int height : { 0, 100}) { |
| 352 | if (width && height) { |
| 353 | continue; // not zero-sized |
| 354 | } |
| 355 | |
| 356 | GrSurfaceDesc desc; |
| 357 | desc.fFlags = flags; |
Robert Phillips | 78de212 | 2017-04-26 07:44:26 -0400 | [diff] [blame] | 358 | desc.fWidth = width; |
| 359 | desc.fHeight = height; |
| 360 | desc.fConfig = kRGBA_8888_GrPixelConfig; |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 361 | desc.fSampleCnt = 1; |
Robert Phillips | 78de212 | 2017-04-26 07:44:26 -0400 | [diff] [blame] | 362 | |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 363 | const GrBackendFormat format = |
| 364 | ctxInfo.grContext()->contextPriv().caps()->getBackendFormatFromColorType( |
| 365 | kRGBA_8888_SkColorType); |
| 366 | |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 367 | sk_sp<GrTextureProxy> proxy = provider->createProxy( |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 368 | format, desc, kBottomLeft_GrSurfaceOrigin, fit, SkBudgeted::kNo); |
Robert Phillips | 78de212 | 2017-04-26 07:44:26 -0400 | [diff] [blame] | 369 | REPORTER_ASSERT(reporter, !proxy); |
| 370 | } |
| 371 | } |
| 372 | } |
| 373 | } |
| 374 | } |