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, |
Brian Osman | 10fc6fd | 2018-03-02 11:01:10 -0500 | [diff] [blame] | 116 | kRGBA_8888_GrPixelConfig, kRGBA_1010102_GrPixelConfig }) { |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 117 | for (auto fit : { SkBackingFit::kExact, SkBackingFit::kApprox }) { |
| 118 | for (auto budgeted : { SkBudgeted::kYes, SkBudgeted::kNo }) { |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 119 | for (auto numSamples : {1, 4, 16, 128}) { |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 120 | GrSurfaceDesc desc; |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 121 | desc.fFlags = kRenderTarget_GrSurfaceFlag; |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 122 | desc.fWidth = widthHeight; |
| 123 | desc.fHeight = widthHeight; |
| 124 | desc.fConfig = config; |
| 125 | desc.fSampleCnt = numSamples; |
| 126 | |
Robert Phillips | 6520a69 | 2017-02-01 09:20:00 -0500 | [diff] [blame] | 127 | { |
| 128 | sk_sp<GrTexture> tex; |
| 129 | if (SkBackingFit::kApprox == fit) { |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 130 | tex = resourceProvider->createApproxTexture(desc, 0); |
Robert Phillips | 6520a69 | 2017-02-01 09:20:00 -0500 | [diff] [blame] | 131 | } else { |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 132 | tex = resourceProvider->createTexture(desc, budgeted); |
Robert Phillips | 6520a69 | 2017-02-01 09:20:00 -0500 | [diff] [blame] | 133 | } |
| 134 | |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 135 | sk_sp<GrTextureProxy> proxy = |
| 136 | proxyProvider->createProxy(desc, origin, fit, budgeted); |
Robert Phillips | 2f49314 | 2017-03-02 18:18:38 -0500 | [diff] [blame] | 137 | REPORTER_ASSERT(reporter, SkToBool(tex) == SkToBool(proxy)); |
| 138 | if (proxy) { |
| 139 | REPORTER_ASSERT(reporter, proxy->asRenderTargetProxy()); |
Robert Phillips | 40d9495 | 2017-01-30 14:15:59 -0500 | [diff] [blame] | 140 | // This forces the proxy to compute and cache its |
| 141 | // pre-instantiation size guess. Later, when it is actually |
| 142 | // instantiated, it checks that the instantiated size is <= to |
| 143 | // the pre-computation. If the proxy never computed its |
| 144 | // pre-instantiation size then the check is skipped. |
Robert Phillips | 2f49314 | 2017-03-02 18:18:38 -0500 | [diff] [blame] | 145 | proxy->gpuMemorySize(); |
Robert Phillips | b446088 | 2016-11-17 14:43:51 -0500 | [diff] [blame] | 146 | |
Robert Phillips | 2f49314 | 2017-03-02 18:18:38 -0500 | [diff] [blame] | 147 | check_surface(reporter, proxy.get(), origin, |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 148 | widthHeight, widthHeight, config, budgeted); |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 149 | int supportedSamples = |
| 150 | caps.getRenderTargetSampleCount(numSamples, config); |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 151 | check_rendertarget(reporter, caps, resourceProvider, |
Robert Phillips | 2f49314 | 2017-03-02 18:18:38 -0500 | [diff] [blame] | 152 | proxy->asRenderTargetProxy(), |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 153 | supportedSamples, |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 154 | fit, caps.maxWindowRectangles()); |
Robert Phillips | 40d9495 | 2017-01-30 14:15:59 -0500 | [diff] [blame] | 155 | } |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 156 | } |
| 157 | |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 158 | desc.fFlags = kNone_GrSurfaceFlags; |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 159 | |
Robert Phillips | 6520a69 | 2017-02-01 09:20:00 -0500 | [diff] [blame] | 160 | { |
| 161 | sk_sp<GrTexture> tex; |
| 162 | if (SkBackingFit::kApprox == fit) { |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 163 | tex = resourceProvider->createApproxTexture(desc, 0); |
Robert Phillips | 6520a69 | 2017-02-01 09:20:00 -0500 | [diff] [blame] | 164 | } else { |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 165 | tex = resourceProvider->createTexture(desc, budgeted); |
Robert Phillips | 6520a69 | 2017-02-01 09:20:00 -0500 | [diff] [blame] | 166 | } |
Robert Phillips | b446088 | 2016-11-17 14:43:51 -0500 | [diff] [blame] | 167 | |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 168 | sk_sp<GrTextureProxy> proxy( |
| 169 | proxyProvider->createProxy(desc, origin, fit, budgeted)); |
Robert Phillips | 2f49314 | 2017-03-02 18:18:38 -0500 | [diff] [blame] | 170 | REPORTER_ASSERT(reporter, SkToBool(tex) == SkToBool(proxy)); |
| 171 | if (proxy) { |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 172 | // This forces the proxy to compute and cache its |
| 173 | // pre-instantiation size guess. Later, when it is actually |
| 174 | // instantiated, it checks that the instantiated size is <= to |
| 175 | // the pre-computation. If the proxy never computed its |
| 176 | // pre-instantiation size then the check is skipped. |
Robert Phillips | 2f49314 | 2017-03-02 18:18:38 -0500 | [diff] [blame] | 177 | proxy->gpuMemorySize(); |
Robert Phillips | 6520a69 | 2017-02-01 09:20:00 -0500 | [diff] [blame] | 178 | |
Robert Phillips | 2f49314 | 2017-03-02 18:18:38 -0500 | [diff] [blame] | 179 | check_surface(reporter, proxy.get(), origin, |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 180 | widthHeight, widthHeight, config, budgeted); |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 181 | check_texture(reporter, resourceProvider, |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 182 | proxy->asTextureProxy(), fit); |
Robert Phillips | 6520a69 | 2017-02-01 09:20:00 -0500 | [diff] [blame] | 183 | } |
Robert Phillips | 40d9495 | 2017-01-30 14:15:59 -0500 | [diff] [blame] | 184 | } |
Robert Phillips | 6520a69 | 2017-02-01 09:20:00 -0500 | [diff] [blame] | 185 | |
| 186 | attempt++; |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 187 | } |
| 188 | } |
| 189 | } |
| 190 | } |
| 191 | } |
| 192 | } |
| 193 | } |
| 194 | |
egdaniel | ab527a5 | 2016-06-28 08:07:26 -0700 | [diff] [blame] | 195 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WrappedProxyTest, reporter, ctxInfo) { |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 196 | GrProxyProvider* proxyProvider = ctxInfo.grContext()->contextPriv().proxyProvider(); |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 197 | GrResourceProvider* resourceProvider = ctxInfo.grContext()->contextPriv().resourceProvider(); |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 198 | GrGpu* gpu = ctxInfo.grContext()->contextPriv().getGpu(); |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 199 | const GrCaps& caps = *ctxInfo.grContext()->contextPriv().caps(); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 200 | |
| 201 | static const int kWidthHeight = 100; |
| 202 | |
| 203 | for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin }) { |
Brian Osman | 10fc6fd | 2018-03-02 11:01:10 -0500 | [diff] [blame] | 204 | for (auto colorType : { kAlpha_8_SkColorType, kRGBA_8888_SkColorType, |
| 205 | kRGBA_1010102_SkColorType }) { |
Brian Salomon | 52e943a | 2018-03-13 09:32:39 -0400 | [diff] [blame] | 206 | // External on-screen render target. |
| 207 | // Tests wrapBackendRenderTarget with a GrBackendRenderTarget |
| 208 | // Our test-only function that creates a backend render target doesn't currently support |
| 209 | // sample counts :(. |
| 210 | if (ctxInfo.grContext()->colorTypeSupportedAsSurface(colorType)) { |
| 211 | GrBackendRenderTarget backendRT = gpu->createTestingOnlyBackendRenderTarget( |
Brian Osman | 2d010b6 | 2018-08-09 10:55:09 -0400 | [diff] [blame] | 212 | kWidthHeight, kWidthHeight, SkColorTypeToGrColorType(colorType)); |
Brian Salomon | 52e943a | 2018-03-13 09:32:39 -0400 | [diff] [blame] | 213 | sk_sp<GrSurfaceProxy> sProxy( |
| 214 | proxyProvider->wrapBackendRenderTarget(backendRT, origin)); |
| 215 | check_surface(reporter, sProxy.get(), origin, kWidthHeight, kWidthHeight, |
Greg Daniel | 108bb23 | 2018-07-03 16:18:29 -0400 | [diff] [blame] | 216 | backendRT.pixelConfig(), SkBudgeted::kNo); |
Brian Salomon | 52e943a | 2018-03-13 09:32:39 -0400 | [diff] [blame] | 217 | static constexpr int kExpectedNumSamples = 1; |
| 218 | check_rendertarget(reporter, caps, resourceProvider, sProxy->asRenderTargetProxy(), |
| 219 | kExpectedNumSamples, SkBackingFit::kExact, |
| 220 | caps.maxWindowRectangles()); |
| 221 | gpu->deleteTestingOnlyBackendRenderTarget(backendRT); |
| 222 | } |
| 223 | |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 224 | for (auto numSamples : {1, 4}) { |
Brian Osman | 2b23c4b | 2018-06-01 12:25:08 -0400 | [diff] [blame] | 225 | GrPixelConfig config = SkColorType2GrPixelConfig(colorType); |
Greg Daniel | 0a7aa14 | 2018-02-21 13:02:32 -0500 | [diff] [blame] | 226 | SkASSERT(kUnknown_GrPixelConfig != config); |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 227 | int supportedNumSamples = caps.getRenderTargetSampleCount(numSamples, config); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 228 | |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 229 | if (!supportedNumSamples) { |
| 230 | continue; |
| 231 | } |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 232 | |
Brian Salomon | 52e943a | 2018-03-13 09:32:39 -0400 | [diff] [blame] | 233 | // Test wrapping FBO 0 (with made up properties). This tests sample count and the |
| 234 | // special case where FBO 0 doesn't support window rectangles. |
| 235 | if (kOpenGL_GrBackend == ctxInfo.backend()) { |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 236 | GrGLFramebufferInfo fboInfo; |
| 237 | fboInfo.fFBOID = 0; |
Brian Salomon | 52e943a | 2018-03-13 09:32:39 -0400 | [diff] [blame] | 238 | static constexpr int kStencilBits = 8; |
| 239 | GrBackendRenderTarget backendRT(kWidthHeight, kWidthHeight, numSamples, |
Greg Daniel | 108bb23 | 2018-07-03 16:18:29 -0400 | [diff] [blame] | 240 | kStencilBits, fboInfo); |
| 241 | backendRT.setPixelConfig(config); |
Brian Salomon | 7578f3e | 2018-03-07 14:39:54 -0500 | [diff] [blame] | 242 | sk_sp<GrSurfaceProxy> sProxy( |
| 243 | proxyProvider->wrapBackendRenderTarget(backendRT, origin)); |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 244 | check_surface(reporter, sProxy.get(), origin, |
| 245 | kWidthHeight, kWidthHeight, |
Greg Daniel | 108bb23 | 2018-07-03 16:18:29 -0400 | [diff] [blame] | 246 | backendRT.pixelConfig(), SkBudgeted::kNo); |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 247 | check_rendertarget(reporter, caps, resourceProvider, |
| 248 | sProxy->asRenderTargetProxy(), |
| 249 | supportedNumSamples, SkBackingFit::kExact, 0); |
| 250 | } |
| 251 | |
Brian Salomon | 7578f3e | 2018-03-07 14:39:54 -0500 | [diff] [blame] | 252 | // Tests wrapBackendRenderTarget with a GrBackendTexture |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 253 | { |
| 254 | GrBackendTexture backendTex = |
| 255 | gpu->createTestingOnlyBackendTexture(nullptr, kWidthHeight, |
Brian Osman | 2b23c4b | 2018-06-01 12:25:08 -0400 | [diff] [blame] | 256 | kWidthHeight, colorType, |
Greg Daniel | 57bf4a3 | 2018-04-19 10:28:37 -0400 | [diff] [blame] | 257 | true, GrMipMapped::kNo); |
Brian Salomon | 7578f3e | 2018-03-07 14:39:54 -0500 | [diff] [blame] | 258 | sk_sp<GrSurfaceProxy> sProxy = proxyProvider->wrapBackendTextureAsRenderTarget( |
| 259 | backendTex, origin, supportedNumSamples); |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 260 | if (!sProxy) { |
Brian Salomon | 26102cb | 2018-03-09 09:33:19 -0500 | [diff] [blame] | 261 | gpu->deleteTestingOnlyBackendTexture(backendTex); |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 262 | continue; // This can fail on Mesa |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 263 | } |
| 264 | |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 265 | check_surface(reporter, sProxy.get(), origin, |
| 266 | kWidthHeight, kWidthHeight, |
Greg Daniel | 108bb23 | 2018-07-03 16:18:29 -0400 | [diff] [blame] | 267 | backendTex.pixelConfig(), SkBudgeted::kNo); |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 268 | check_rendertarget(reporter, caps, resourceProvider, |
| 269 | sProxy->asRenderTargetProxy(), |
| 270 | supportedNumSamples, SkBackingFit::kExact, |
| 271 | caps.maxWindowRectangles()); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 272 | |
Brian Salomon | 26102cb | 2018-03-09 09:33:19 -0500 | [diff] [blame] | 273 | gpu->deleteTestingOnlyBackendTexture(backendTex); |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 274 | } |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 275 | |
Brian Salomon | 7578f3e | 2018-03-07 14:39:54 -0500 | [diff] [blame] | 276 | // Tests wrapBackendTexture that is only renderable |
Greg Daniel | f87651e | 2018-02-21 11:36:53 -0500 | [diff] [blame] | 277 | { |
| 278 | GrBackendTexture backendTex = |
| 279 | gpu->createTestingOnlyBackendTexture(nullptr, kWidthHeight, |
Brian Osman | 2b23c4b | 2018-06-01 12:25:08 -0400 | [diff] [blame] | 280 | kWidthHeight, colorType, |
Greg Daniel | 57bf4a3 | 2018-04-19 10:28:37 -0400 | [diff] [blame] | 281 | true, GrMipMapped::kNo); |
Greg Daniel | f87651e | 2018-02-21 11:36:53 -0500 | [diff] [blame] | 282 | |
Brian Salomon | 7578f3e | 2018-03-07 14:39:54 -0500 | [diff] [blame] | 283 | sk_sp<GrSurfaceProxy> sProxy = proxyProvider->wrapRenderableBackendTexture( |
| 284 | backendTex, origin, supportedNumSamples); |
Greg Daniel | f87651e | 2018-02-21 11:36:53 -0500 | [diff] [blame] | 285 | if (!sProxy) { |
Brian Salomon | 26102cb | 2018-03-09 09:33:19 -0500 | [diff] [blame] | 286 | gpu->deleteTestingOnlyBackendTexture(backendTex); |
Greg Daniel | f87651e | 2018-02-21 11:36:53 -0500 | [diff] [blame] | 287 | continue; // This can fail on Mesa |
| 288 | } |
| 289 | |
| 290 | check_surface(reporter, sProxy.get(), origin, |
| 291 | kWidthHeight, kWidthHeight, |
Greg Daniel | 108bb23 | 2018-07-03 16:18:29 -0400 | [diff] [blame] | 292 | backendTex.pixelConfig(), SkBudgeted::kNo); |
Greg Daniel | f87651e | 2018-02-21 11:36:53 -0500 | [diff] [blame] | 293 | check_rendertarget(reporter, caps, resourceProvider, |
| 294 | sProxy->asRenderTargetProxy(), |
| 295 | supportedNumSamples, SkBackingFit::kExact, |
| 296 | caps.maxWindowRectangles()); |
| 297 | |
Brian Salomon | 26102cb | 2018-03-09 09:33:19 -0500 | [diff] [blame] | 298 | gpu->deleteTestingOnlyBackendTexture(backendTex); |
Greg Daniel | f87651e | 2018-02-21 11:36:53 -0500 | [diff] [blame] | 299 | } |
| 300 | |
Brian Salomon | 7578f3e | 2018-03-07 14:39:54 -0500 | [diff] [blame] | 301 | // Tests wrapBackendTexture that is only textureable |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 302 | { |
| 303 | // Internal offscreen texture |
| 304 | GrBackendTexture backendTex = |
| 305 | gpu->createTestingOnlyBackendTexture(nullptr, kWidthHeight, |
Brian Osman | 2b23c4b | 2018-06-01 12:25:08 -0400 | [diff] [blame] | 306 | kWidthHeight, colorType, |
Greg Daniel | 57bf4a3 | 2018-04-19 10:28:37 -0400 | [diff] [blame] | 307 | false, GrMipMapped::kNo); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 308 | |
Brian Salomon | 7578f3e | 2018-03-07 14:39:54 -0500 | [diff] [blame] | 309 | sk_sp<GrSurfaceProxy> sProxy = proxyProvider->wrapBackendTexture( |
| 310 | backendTex, origin, kBorrow_GrWrapOwnership, nullptr, nullptr); |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 311 | if (!sProxy) { |
Brian Salomon | 26102cb | 2018-03-09 09:33:19 -0500 | [diff] [blame] | 312 | gpu->deleteTestingOnlyBackendTexture(backendTex); |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 313 | continue; |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 314 | } |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 315 | |
| 316 | check_surface(reporter, sProxy.get(), origin, |
| 317 | kWidthHeight, kWidthHeight, |
Greg Daniel | 108bb23 | 2018-07-03 16:18:29 -0400 | [diff] [blame] | 318 | backendTex.pixelConfig(), SkBudgeted::kNo); |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 319 | check_texture(reporter, resourceProvider, sProxy->asTextureProxy(), |
| 320 | SkBackingFit::kExact); |
| 321 | |
Brian Salomon | 26102cb | 2018-03-09 09:33:19 -0500 | [diff] [blame] | 322 | gpu->deleteTestingOnlyBackendTexture(backendTex); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 323 | } |
| 324 | } |
| 325 | } |
| 326 | } |
| 327 | } |
| 328 | |
Robert Phillips | 78de212 | 2017-04-26 07:44:26 -0400 | [diff] [blame] | 329 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ZeroSizedProxyTest, reporter, ctxInfo) { |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 330 | GrProxyProvider* provider = ctxInfo.grContext()->contextPriv().proxyProvider(); |
Robert Phillips | 78de212 | 2017-04-26 07:44:26 -0400 | [diff] [blame] | 331 | |
| 332 | for (auto flags : { kRenderTarget_GrSurfaceFlag, kNone_GrSurfaceFlags }) { |
| 333 | for (auto fit : { SkBackingFit::kExact, SkBackingFit::kApprox }) { |
| 334 | for (int width : { 0, 100 }) { |
| 335 | for (int height : { 0, 100}) { |
| 336 | if (width && height) { |
| 337 | continue; // not zero-sized |
| 338 | } |
| 339 | |
| 340 | GrSurfaceDesc desc; |
| 341 | desc.fFlags = flags; |
Robert Phillips | 78de212 | 2017-04-26 07:44:26 -0400 | [diff] [blame] | 342 | desc.fWidth = width; |
| 343 | desc.fHeight = height; |
| 344 | desc.fConfig = kRGBA_8888_GrPixelConfig; |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 345 | desc.fSampleCnt = 1; |
Robert Phillips | 78de212 | 2017-04-26 07:44:26 -0400 | [diff] [blame] | 346 | |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 347 | sk_sp<GrTextureProxy> proxy = provider->createProxy( |
| 348 | desc, kBottomLeft_GrSurfaceOrigin, fit, SkBudgeted::kNo); |
Robert Phillips | 78de212 | 2017-04-26 07:44:26 -0400 | [diff] [blame] | 349 | REPORTER_ASSERT(reporter, !proxy); |
| 350 | } |
| 351 | } |
| 352 | } |
| 353 | } |
| 354 | } |