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" |
Robert Phillips | b45f47d | 2019-02-03 17:17:54 -0500 | [diff] [blame^] | 23 | #include "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); |
| 35 | REPORTER_ASSERT(reporter, proxy->config() == config); |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 36 | REPORTER_ASSERT(reporter, !proxy->uniqueID().isInvalid()); |
Robert Phillips | abacf09 | 2016-11-02 10:23:32 -0400 | [diff] [blame] | 37 | REPORTER_ASSERT(reporter, proxy->isBudgeted() == budgeted); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | static void check_rendertarget(skiatest::Reporter* reporter, |
Robert Phillips | ec2249f | 2016-11-09 08:54:35 -0500 | [diff] [blame] | 41 | const GrCaps& caps, |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 42 | GrResourceProvider* provider, |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 43 | GrRenderTargetProxy* rtProxy, |
Robert Phillips | abacf09 | 2016-11-02 10:23:32 -0400 | [diff] [blame] | 44 | int numSamples, |
Robert Phillips | ec2249f | 2016-11-09 08:54:35 -0500 | [diff] [blame] | 45 | SkBackingFit fit, |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 46 | int expectedMaxWindowRects) { |
Robert Phillips | ec2249f | 2016-11-09 08:54:35 -0500 | [diff] [blame] | 47 | REPORTER_ASSERT(reporter, rtProxy->maxWindowRectangles(caps) == expectedMaxWindowRects); |
Robert Phillips | abacf09 | 2016-11-02 10:23:32 -0400 | [diff] [blame] | 48 | REPORTER_ASSERT(reporter, rtProxy->numStencilSamples() == numSamples); |
| 49 | |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 50 | GrSurfaceProxy::UniqueID idBefore = rtProxy->uniqueID(); |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 51 | bool preinstantiated = rtProxy->isInstantiated(); |
Robert Phillips | eee4d6e | 2017-06-05 09:26:07 -0400 | [diff] [blame] | 52 | REPORTER_ASSERT(reporter, rtProxy->instantiate(provider)); |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 53 | GrRenderTarget* rt = rtProxy->peekRenderTarget(); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 54 | |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 55 | REPORTER_ASSERT(reporter, rtProxy->uniqueID() == idBefore); |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 56 | // Deferred resources should always have a different ID from their instantiated rendertarget |
Brian Salomon | f777897 | 2018-03-08 10:13:17 -0500 | [diff] [blame] | 57 | if (preinstantiated) { |
| 58 | REPORTER_ASSERT(reporter, rtProxy->uniqueID().asUInt() == rt->uniqueID().asUInt()); |
| 59 | } else { |
| 60 | REPORTER_ASSERT(reporter, rtProxy->uniqueID().asUInt() != rt->uniqueID().asUInt()); |
| 61 | } |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 62 | |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 63 | if (SkBackingFit::kExact == fit) { |
| 64 | REPORTER_ASSERT(reporter, rt->width() == rtProxy->width()); |
| 65 | REPORTER_ASSERT(reporter, rt->height() == rtProxy->height()); |
| 66 | } else { |
| 67 | REPORTER_ASSERT(reporter, rt->width() >= rtProxy->width()); |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 68 | REPORTER_ASSERT(reporter, rt->height() >= rtProxy->height()); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 69 | } |
| 70 | REPORTER_ASSERT(reporter, rt->config() == rtProxy->config()); |
| 71 | |
Brian Salomon | 7c8460e | 2017-05-12 11:36:10 -0400 | [diff] [blame] | 72 | REPORTER_ASSERT(reporter, rt->fsaaType() == rtProxy->fsaaType()); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 73 | REPORTER_ASSERT(reporter, rt->numColorSamples() == rtProxy->numColorSamples()); |
| 74 | REPORTER_ASSERT(reporter, rt->numStencilSamples() == rtProxy->numStencilSamples()); |
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 | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 108 | GrProxyProvider* proxyProvider = ctxInfo.grContext()->contextPriv().proxyProvider(); |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 109 | GrResourceProvider* resourceProvider = ctxInfo.grContext()->contextPriv().resourceProvider(); |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 110 | const GrCaps& caps = *ctxInfo.grContext()->contextPriv().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 | 6520a69 | 2017-02-01 09:20:00 -0500 | [diff] [blame] | 116 | for (auto config : { kAlpha_8_GrPixelConfig, kRGB_565_GrPixelConfig, |
Jim Van Verth | 1676cb9 | 2019-01-15 13:24:45 -0500 | [diff] [blame] | 117 | kRGBA_8888_GrPixelConfig, kRGBA_1010102_GrPixelConfig, |
| 118 | kRGB_ETC1_GrPixelConfig }) { |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 119 | for (auto fit : { SkBackingFit::kExact, SkBackingFit::kApprox }) { |
| 120 | for (auto budgeted : { SkBudgeted::kYes, SkBudgeted::kNo }) { |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 121 | for (auto numSamples : {1, 4, 16, 128}) { |
Jim Van Verth | 1676cb9 | 2019-01-15 13:24:45 -0500 | [diff] [blame] | 122 | // We don't have recycling support for compressed textures |
| 123 | if (GrPixelConfigIsCompressed(config) && SkBackingFit::kApprox == fit) { |
| 124 | continue; |
| 125 | } |
| 126 | |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 127 | GrSurfaceDesc desc; |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 128 | desc.fFlags = kRenderTarget_GrSurfaceFlag; |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 129 | desc.fWidth = widthHeight; |
| 130 | desc.fHeight = widthHeight; |
| 131 | desc.fConfig = config; |
| 132 | desc.fSampleCnt = numSamples; |
| 133 | |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 134 | GrSRGBEncoded srgbEncoded; |
| 135 | GrColorType colorType = |
| 136 | GrPixelConfigToColorTypeAndEncoding(config, &srgbEncoded); |
| 137 | const GrBackendFormat format = |
| 138 | caps.getBackendFormatFromGrColorType(colorType, srgbEncoded); |
| 139 | |
Robert Phillips | 6520a69 | 2017-02-01 09:20:00 -0500 | [diff] [blame] | 140 | { |
| 141 | sk_sp<GrTexture> tex; |
| 142 | if (SkBackingFit::kApprox == fit) { |
Chris Dalton | d004e0b | 2018-09-27 09:28:03 -0600 | [diff] [blame] | 143 | tex = resourceProvider->createApproxTexture( |
| 144 | desc, GrResourceProvider::Flags::kNone); |
Robert Phillips | 6520a69 | 2017-02-01 09:20:00 -0500 | [diff] [blame] | 145 | } else { |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 146 | tex = resourceProvider->createTexture(desc, budgeted); |
Robert Phillips | 6520a69 | 2017-02-01 09:20:00 -0500 | [diff] [blame] | 147 | } |
| 148 | |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 149 | sk_sp<GrTextureProxy> proxy = |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 150 | proxyProvider->createProxy(format, desc, origin, fit, |
| 151 | budgeted); |
Robert Phillips | 2f49314 | 2017-03-02 18:18:38 -0500 | [diff] [blame] | 152 | REPORTER_ASSERT(reporter, SkToBool(tex) == SkToBool(proxy)); |
| 153 | if (proxy) { |
| 154 | REPORTER_ASSERT(reporter, proxy->asRenderTargetProxy()); |
Robert Phillips | 40d9495 | 2017-01-30 14:15:59 -0500 | [diff] [blame] | 155 | // This forces the proxy to compute and cache its |
| 156 | // pre-instantiation size guess. Later, when it is actually |
| 157 | // instantiated, it checks that the instantiated size is <= to |
| 158 | // the pre-computation. If the proxy never computed its |
| 159 | // pre-instantiation size then the check is skipped. |
Robert Phillips | 2f49314 | 2017-03-02 18:18:38 -0500 | [diff] [blame] | 160 | proxy->gpuMemorySize(); |
Robert Phillips | b446088 | 2016-11-17 14:43:51 -0500 | [diff] [blame] | 161 | |
Robert Phillips | 2f49314 | 2017-03-02 18:18:38 -0500 | [diff] [blame] | 162 | check_surface(reporter, proxy.get(), origin, |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 163 | widthHeight, widthHeight, config, budgeted); |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 164 | int supportedSamples = |
| 165 | caps.getRenderTargetSampleCount(numSamples, config); |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 166 | check_rendertarget(reporter, caps, resourceProvider, |
Robert Phillips | 2f49314 | 2017-03-02 18:18:38 -0500 | [diff] [blame] | 167 | proxy->asRenderTargetProxy(), |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 168 | supportedSamples, |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 169 | fit, caps.maxWindowRectangles()); |
Robert Phillips | 40d9495 | 2017-01-30 14:15:59 -0500 | [diff] [blame] | 170 | } |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 171 | } |
| 172 | |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 173 | desc.fFlags = kNone_GrSurfaceFlags; |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 174 | |
Robert Phillips | 6520a69 | 2017-02-01 09:20:00 -0500 | [diff] [blame] | 175 | { |
| 176 | sk_sp<GrTexture> tex; |
| 177 | if (SkBackingFit::kApprox == fit) { |
Chris Dalton | d004e0b | 2018-09-27 09:28:03 -0600 | [diff] [blame] | 178 | tex = resourceProvider->createApproxTexture( |
| 179 | desc, GrResourceProvider::Flags::kNone); |
Robert Phillips | 6520a69 | 2017-02-01 09:20:00 -0500 | [diff] [blame] | 180 | } else { |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 181 | tex = resourceProvider->createTexture(desc, budgeted); |
Robert Phillips | 6520a69 | 2017-02-01 09:20:00 -0500 | [diff] [blame] | 182 | } |
Robert Phillips | b446088 | 2016-11-17 14:43:51 -0500 | [diff] [blame] | 183 | |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 184 | sk_sp<GrTextureProxy> proxy( |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 185 | proxyProvider->createProxy(format, desc, origin, fit, |
| 186 | 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 | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 213 | GrProxyProvider* proxyProvider = ctxInfo.grContext()->contextPriv().proxyProvider(); |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 214 | GrResourceProvider* resourceProvider = ctxInfo.grContext()->contextPriv().resourceProvider(); |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 215 | GrGpu* gpu = ctxInfo.grContext()->contextPriv().getGpu(); |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 216 | const GrCaps& caps = *ctxInfo.grContext()->contextPriv().caps(); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 217 | |
| 218 | static const int kWidthHeight = 100; |
| 219 | |
| 220 | for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin }) { |
Brian Osman | 10fc6fd | 2018-03-02 11:01:10 -0500 | [diff] [blame] | 221 | for (auto colorType : { kAlpha_8_SkColorType, kRGBA_8888_SkColorType, |
| 222 | kRGBA_1010102_SkColorType }) { |
Brian Salomon | 52e943a | 2018-03-13 09:32:39 -0400 | [diff] [blame] | 223 | // External on-screen render target. |
| 224 | // Tests wrapBackendRenderTarget with a GrBackendRenderTarget |
| 225 | // Our test-only function that creates a backend render target doesn't currently support |
| 226 | // sample counts :(. |
| 227 | if (ctxInfo.grContext()->colorTypeSupportedAsSurface(colorType)) { |
| 228 | GrBackendRenderTarget backendRT = gpu->createTestingOnlyBackendRenderTarget( |
Brian Osman | 2d010b6 | 2018-08-09 10:55:09 -0400 | [diff] [blame] | 229 | kWidthHeight, kWidthHeight, SkColorTypeToGrColorType(colorType)); |
Brian Salomon | 52e943a | 2018-03-13 09:32:39 -0400 | [diff] [blame] | 230 | sk_sp<GrSurfaceProxy> sProxy( |
| 231 | proxyProvider->wrapBackendRenderTarget(backendRT, origin)); |
| 232 | check_surface(reporter, sProxy.get(), origin, kWidthHeight, kWidthHeight, |
Greg Daniel | 108bb23 | 2018-07-03 16:18:29 -0400 | [diff] [blame] | 233 | backendRT.pixelConfig(), SkBudgeted::kNo); |
Brian Salomon | 52e943a | 2018-03-13 09:32:39 -0400 | [diff] [blame] | 234 | static constexpr int kExpectedNumSamples = 1; |
| 235 | check_rendertarget(reporter, caps, resourceProvider, sProxy->asRenderTargetProxy(), |
| 236 | kExpectedNumSamples, SkBackingFit::kExact, |
| 237 | caps.maxWindowRectangles()); |
| 238 | gpu->deleteTestingOnlyBackendRenderTarget(backendRT); |
| 239 | } |
| 240 | |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 241 | for (auto numSamples : {1, 4}) { |
Brian Osman | 2b23c4b | 2018-06-01 12:25:08 -0400 | [diff] [blame] | 242 | GrPixelConfig config = SkColorType2GrPixelConfig(colorType); |
Greg Daniel | 0a7aa14 | 2018-02-21 13:02:32 -0500 | [diff] [blame] | 243 | SkASSERT(kUnknown_GrPixelConfig != config); |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 244 | int supportedNumSamples = caps.getRenderTargetSampleCount(numSamples, config); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 245 | |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 246 | if (!supportedNumSamples) { |
| 247 | continue; |
| 248 | } |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 249 | |
Brian Salomon | 52e943a | 2018-03-13 09:32:39 -0400 | [diff] [blame] | 250 | // Test wrapping FBO 0 (with made up properties). This tests sample count and the |
| 251 | // special case where FBO 0 doesn't support window rectangles. |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 252 | if (GrBackendApi::kOpenGL == ctxInfo.backend()) { |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 253 | GrGLFramebufferInfo fboInfo; |
| 254 | fboInfo.fFBOID = 0; |
Robert Phillips | b45f47d | 2019-02-03 17:17:54 -0500 | [diff] [blame^] | 255 | fboInfo.fFormat = GR_GL_RGBA8; |
Brian Salomon | 52e943a | 2018-03-13 09:32:39 -0400 | [diff] [blame] | 256 | static constexpr int kStencilBits = 8; |
| 257 | GrBackendRenderTarget backendRT(kWidthHeight, kWidthHeight, numSamples, |
Greg Daniel | 108bb23 | 2018-07-03 16:18:29 -0400 | [diff] [blame] | 258 | kStencilBits, fboInfo); |
| 259 | backendRT.setPixelConfig(config); |
Brian Salomon | 7578f3e | 2018-03-07 14:39:54 -0500 | [diff] [blame] | 260 | sk_sp<GrSurfaceProxy> sProxy( |
| 261 | proxyProvider->wrapBackendRenderTarget(backendRT, origin)); |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 262 | check_surface(reporter, sProxy.get(), origin, |
| 263 | kWidthHeight, kWidthHeight, |
Greg Daniel | 108bb23 | 2018-07-03 16:18:29 -0400 | [diff] [blame] | 264 | backendRT.pixelConfig(), SkBudgeted::kNo); |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 265 | check_rendertarget(reporter, caps, resourceProvider, |
| 266 | sProxy->asRenderTargetProxy(), |
| 267 | supportedNumSamples, SkBackingFit::kExact, 0); |
| 268 | } |
| 269 | |
Brian Salomon | 7578f3e | 2018-03-07 14:39:54 -0500 | [diff] [blame] | 270 | // Tests wrapBackendRenderTarget with a GrBackendTexture |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 271 | { |
| 272 | GrBackendTexture backendTex = |
| 273 | gpu->createTestingOnlyBackendTexture(nullptr, kWidthHeight, |
Brian Osman | 2b23c4b | 2018-06-01 12:25:08 -0400 | [diff] [blame] | 274 | kWidthHeight, colorType, |
Greg Daniel | 57bf4a3 | 2018-04-19 10:28:37 -0400 | [diff] [blame] | 275 | true, GrMipMapped::kNo); |
Brian Salomon | 7578f3e | 2018-03-07 14:39:54 -0500 | [diff] [blame] | 276 | sk_sp<GrSurfaceProxy> sProxy = proxyProvider->wrapBackendTextureAsRenderTarget( |
| 277 | backendTex, origin, supportedNumSamples); |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 278 | if (!sProxy) { |
Brian Salomon | 26102cb | 2018-03-09 09:33:19 -0500 | [diff] [blame] | 279 | gpu->deleteTestingOnlyBackendTexture(backendTex); |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 280 | continue; // This can fail on Mesa |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 281 | } |
| 282 | |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 283 | check_surface(reporter, sProxy.get(), origin, |
| 284 | kWidthHeight, kWidthHeight, |
Greg Daniel | 108bb23 | 2018-07-03 16:18:29 -0400 | [diff] [blame] | 285 | backendTex.pixelConfig(), SkBudgeted::kNo); |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 286 | check_rendertarget(reporter, caps, resourceProvider, |
| 287 | sProxy->asRenderTargetProxy(), |
| 288 | supportedNumSamples, SkBackingFit::kExact, |
| 289 | caps.maxWindowRectangles()); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 290 | |
Brian Salomon | 26102cb | 2018-03-09 09:33:19 -0500 | [diff] [blame] | 291 | gpu->deleteTestingOnlyBackendTexture(backendTex); |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 292 | } |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 293 | |
Brian Salomon | 7578f3e | 2018-03-07 14:39:54 -0500 | [diff] [blame] | 294 | // Tests wrapBackendTexture that is only renderable |
Greg Daniel | f87651e | 2018-02-21 11:36:53 -0500 | [diff] [blame] | 295 | { |
| 296 | GrBackendTexture backendTex = |
| 297 | gpu->createTestingOnlyBackendTexture(nullptr, kWidthHeight, |
Brian Osman | 2b23c4b | 2018-06-01 12:25:08 -0400 | [diff] [blame] | 298 | kWidthHeight, colorType, |
Greg Daniel | 57bf4a3 | 2018-04-19 10:28:37 -0400 | [diff] [blame] | 299 | true, GrMipMapped::kNo); |
Greg Daniel | f87651e | 2018-02-21 11:36:53 -0500 | [diff] [blame] | 300 | |
Brian Salomon | 7578f3e | 2018-03-07 14:39:54 -0500 | [diff] [blame] | 301 | sk_sp<GrSurfaceProxy> sProxy = proxyProvider->wrapRenderableBackendTexture( |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 302 | backendTex, origin, supportedNumSamples, kBorrow_GrWrapOwnership, |
| 303 | GrWrapCacheable::kNo); |
Greg Daniel | f87651e | 2018-02-21 11:36:53 -0500 | [diff] [blame] | 304 | if (!sProxy) { |
Brian Salomon | 26102cb | 2018-03-09 09:33:19 -0500 | [diff] [blame] | 305 | gpu->deleteTestingOnlyBackendTexture(backendTex); |
Greg Daniel | f87651e | 2018-02-21 11:36:53 -0500 | [diff] [blame] | 306 | continue; // This can fail on Mesa |
| 307 | } |
| 308 | |
| 309 | check_surface(reporter, sProxy.get(), origin, |
| 310 | kWidthHeight, kWidthHeight, |
Greg Daniel | 108bb23 | 2018-07-03 16:18:29 -0400 | [diff] [blame] | 311 | backendTex.pixelConfig(), SkBudgeted::kNo); |
Greg Daniel | f87651e | 2018-02-21 11:36:53 -0500 | [diff] [blame] | 312 | check_rendertarget(reporter, caps, resourceProvider, |
| 313 | sProxy->asRenderTargetProxy(), |
| 314 | supportedNumSamples, SkBackingFit::kExact, |
| 315 | caps.maxWindowRectangles()); |
| 316 | |
Brian Salomon | 26102cb | 2018-03-09 09:33:19 -0500 | [diff] [blame] | 317 | gpu->deleteTestingOnlyBackendTexture(backendTex); |
Greg Daniel | f87651e | 2018-02-21 11:36:53 -0500 | [diff] [blame] | 318 | } |
| 319 | |
Brian Salomon | 7578f3e | 2018-03-07 14:39:54 -0500 | [diff] [blame] | 320 | // Tests wrapBackendTexture that is only textureable |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 321 | { |
| 322 | // Internal offscreen texture |
| 323 | GrBackendTexture backendTex = |
| 324 | gpu->createTestingOnlyBackendTexture(nullptr, kWidthHeight, |
Brian Osman | 2b23c4b | 2018-06-01 12:25:08 -0400 | [diff] [blame] | 325 | kWidthHeight, colorType, |
Greg Daniel | 57bf4a3 | 2018-04-19 10:28:37 -0400 | [diff] [blame] | 326 | false, GrMipMapped::kNo); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 327 | |
Brian Salomon | 7578f3e | 2018-03-07 14:39:54 -0500 | [diff] [blame] | 328 | sk_sp<GrSurfaceProxy> sProxy = proxyProvider->wrapBackendTexture( |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 329 | backendTex, origin, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, |
| 330 | kRead_GrIOType); |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 331 | if (!sProxy) { |
Brian Salomon | 26102cb | 2018-03-09 09:33:19 -0500 | [diff] [blame] | 332 | gpu->deleteTestingOnlyBackendTexture(backendTex); |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 333 | continue; |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 334 | } |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 335 | |
| 336 | check_surface(reporter, sProxy.get(), origin, |
| 337 | kWidthHeight, kWidthHeight, |
Greg Daniel | 108bb23 | 2018-07-03 16:18:29 -0400 | [diff] [blame] | 338 | backendTex.pixelConfig(), SkBudgeted::kNo); |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 339 | check_texture(reporter, resourceProvider, sProxy->asTextureProxy(), |
| 340 | SkBackingFit::kExact); |
| 341 | |
Brian Salomon | 26102cb | 2018-03-09 09:33:19 -0500 | [diff] [blame] | 342 | gpu->deleteTestingOnlyBackendTexture(backendTex); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 343 | } |
| 344 | } |
| 345 | } |
| 346 | } |
| 347 | } |
| 348 | |
Robert Phillips | 78de212 | 2017-04-26 07:44:26 -0400 | [diff] [blame] | 349 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ZeroSizedProxyTest, reporter, ctxInfo) { |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 350 | GrProxyProvider* provider = ctxInfo.grContext()->contextPriv().proxyProvider(); |
Robert Phillips | 78de212 | 2017-04-26 07:44:26 -0400 | [diff] [blame] | 351 | |
| 352 | for (auto flags : { kRenderTarget_GrSurfaceFlag, kNone_GrSurfaceFlags }) { |
| 353 | for (auto fit : { SkBackingFit::kExact, SkBackingFit::kApprox }) { |
| 354 | for (int width : { 0, 100 }) { |
| 355 | for (int height : { 0, 100}) { |
| 356 | if (width && height) { |
| 357 | continue; // not zero-sized |
| 358 | } |
| 359 | |
| 360 | GrSurfaceDesc desc; |
| 361 | desc.fFlags = flags; |
Robert Phillips | 78de212 | 2017-04-26 07:44:26 -0400 | [diff] [blame] | 362 | desc.fWidth = width; |
| 363 | desc.fHeight = height; |
| 364 | desc.fConfig = kRGBA_8888_GrPixelConfig; |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 365 | desc.fSampleCnt = 1; |
Robert Phillips | 78de212 | 2017-04-26 07:44:26 -0400 | [diff] [blame] | 366 | |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 367 | const GrBackendFormat format = |
| 368 | ctxInfo.grContext()->contextPriv().caps()->getBackendFormatFromColorType( |
| 369 | kRGBA_8888_SkColorType); |
| 370 | |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 371 | sk_sp<GrTextureProxy> proxy = provider->createProxy( |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 372 | format, desc, kBottomLeft_GrSurfaceOrigin, fit, SkBudgeted::kNo); |
Robert Phillips | 78de212 | 2017-04-26 07:44:26 -0400 | [diff] [blame] | 373 | REPORTER_ASSERT(reporter, !proxy); |
| 374 | } |
| 375 | } |
| 376 | } |
| 377 | } |
| 378 | } |