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 | |
| 12 | #if SK_SUPPORT_GPU |
Robert Phillips | 8bf1f9f | 2017-05-31 15:01:20 -0400 | [diff] [blame] | 13 | |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 14 | #include "GrBackendSurface.h" |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 15 | #include "GrContextPriv.h" |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 16 | #include "GrProxyProvider.h" |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 17 | #include "GrRenderTargetPriv.h" |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 18 | #include "GrRenderTargetProxy.h" |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 19 | #include "GrResourceProvider.h" |
Robert Phillips | f95b175 | 2017-08-31 08:56:07 -0400 | [diff] [blame] | 20 | #include "GrSurfaceProxyPriv.h" |
Robert Phillips | 646e429 | 2017-06-13 12:44:56 -0400 | [diff] [blame] | 21 | #include "GrTexture.h" |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 22 | #include "GrTextureProxy.h" |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 23 | #include "SkGr.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(); |
Robert Phillips | eee4d6e | 2017-06-05 09:26:07 -0400 | [diff] [blame] | 51 | REPORTER_ASSERT(reporter, rtProxy->instantiate(provider)); |
| 52 | GrRenderTarget* rt = rtProxy->priv().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 |
| 56 | REPORTER_ASSERT(reporter, rtProxy->uniqueID().asUInt() != rt->uniqueID().asUInt()); |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 57 | |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 58 | if (SkBackingFit::kExact == fit) { |
| 59 | REPORTER_ASSERT(reporter, rt->width() == rtProxy->width()); |
| 60 | REPORTER_ASSERT(reporter, rt->height() == rtProxy->height()); |
| 61 | } else { |
| 62 | REPORTER_ASSERT(reporter, rt->width() >= rtProxy->width()); |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 63 | REPORTER_ASSERT(reporter, rt->height() >= rtProxy->height()); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 64 | } |
| 65 | REPORTER_ASSERT(reporter, rt->config() == rtProxy->config()); |
| 66 | |
Brian Salomon | 7c8460e | 2017-05-12 11:36:10 -0400 | [diff] [blame] | 67 | REPORTER_ASSERT(reporter, rt->fsaaType() == rtProxy->fsaaType()); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 68 | REPORTER_ASSERT(reporter, rt->numColorSamples() == rtProxy->numColorSamples()); |
| 69 | REPORTER_ASSERT(reporter, rt->numStencilSamples() == rtProxy->numStencilSamples()); |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 70 | REPORTER_ASSERT(reporter, rt->renderTargetPriv().flags() == rtProxy->testingOnly_getFlags()); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | static void check_texture(skiatest::Reporter* reporter, |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 74 | GrResourceProvider* provider, |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 75 | GrTextureProxy* texProxy, |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 76 | SkBackingFit fit) { |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 77 | GrSurfaceProxy::UniqueID idBefore = texProxy->uniqueID(); |
Robert Phillips | eee4d6e | 2017-06-05 09:26:07 -0400 | [diff] [blame] | 78 | |
| 79 | REPORTER_ASSERT(reporter, texProxy->instantiate(provider)); |
| 80 | GrTexture* tex = texProxy->priv().peekTexture(); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 81 | |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 82 | REPORTER_ASSERT(reporter, texProxy->uniqueID() == idBefore); |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 83 | // Deferred resources should always have a different ID from their instantiated texture |
| 84 | REPORTER_ASSERT(reporter, texProxy->uniqueID().asUInt() != tex->uniqueID().asUInt()); |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 85 | |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 86 | if (SkBackingFit::kExact == fit) { |
| 87 | REPORTER_ASSERT(reporter, tex->width() == texProxy->width()); |
| 88 | REPORTER_ASSERT(reporter, tex->height() == texProxy->height()); |
| 89 | } else { |
| 90 | REPORTER_ASSERT(reporter, tex->width() >= texProxy->width()); |
| 91 | REPORTER_ASSERT(reporter, tex->height() >= texProxy->height()); |
| 92 | } |
| 93 | REPORTER_ASSERT(reporter, tex->config() == texProxy->config()); |
| 94 | } |
| 95 | |
| 96 | |
robertphillips | 8abb370 | 2016-08-31 14:04:06 -0700 | [diff] [blame] | 97 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DeferredProxyTest, reporter, ctxInfo) { |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 98 | GrProxyProvider* proxyProvider = ctxInfo.grContext()->contextPriv().proxyProvider(); |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 99 | GrResourceProvider* resourceProvider = ctxInfo.grContext()->contextPriv().resourceProvider(); |
Robert Phillips | abacf09 | 2016-11-02 10:23:32 -0400 | [diff] [blame] | 100 | const GrCaps& caps = *ctxInfo.grContext()->caps(); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 101 | |
Robert Phillips | 6520a69 | 2017-02-01 09:20:00 -0500 | [diff] [blame] | 102 | int attempt = 0; // useful for debugging |
| 103 | |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 104 | for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin }) { |
Robert Phillips | 40d9495 | 2017-01-30 14:15:59 -0500 | [diff] [blame] | 105 | for (auto widthHeight : { 100, 128, 1048576 }) { |
Robert Phillips | 6520a69 | 2017-02-01 09:20:00 -0500 | [diff] [blame] | 106 | for (auto config : { kAlpha_8_GrPixelConfig, kRGB_565_GrPixelConfig, |
Robert Phillips | 92de631 | 2017-05-23 07:43:48 -0400 | [diff] [blame] | 107 | kRGBA_8888_GrPixelConfig }) { |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 108 | for (auto fit : { SkBackingFit::kExact, SkBackingFit::kApprox }) { |
| 109 | for (auto budgeted : { SkBudgeted::kYes, SkBudgeted::kNo }) { |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 110 | for (auto numSamples : {1, 4, 16, 128}) { |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 111 | GrSurfaceDesc desc; |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 112 | desc.fFlags = kRenderTarget_GrSurfaceFlag; |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 113 | desc.fOrigin = origin; |
| 114 | desc.fWidth = widthHeight; |
| 115 | desc.fHeight = widthHeight; |
| 116 | desc.fConfig = config; |
| 117 | desc.fSampleCnt = numSamples; |
| 118 | |
Robert Phillips | 6520a69 | 2017-02-01 09:20:00 -0500 | [diff] [blame] | 119 | { |
| 120 | sk_sp<GrTexture> tex; |
| 121 | if (SkBackingFit::kApprox == fit) { |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 122 | tex = resourceProvider->createApproxTexture(desc, 0); |
Robert Phillips | 6520a69 | 2017-02-01 09:20:00 -0500 | [diff] [blame] | 123 | } else { |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 124 | tex = resourceProvider->createTexture(desc, budgeted); |
Robert Phillips | 6520a69 | 2017-02-01 09:20:00 -0500 | [diff] [blame] | 125 | } |
| 126 | |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 127 | sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy( |
| 128 | desc, fit, budgeted); |
Robert Phillips | 2f49314 | 2017-03-02 18:18:38 -0500 | [diff] [blame] | 129 | REPORTER_ASSERT(reporter, SkToBool(tex) == SkToBool(proxy)); |
| 130 | if (proxy) { |
| 131 | REPORTER_ASSERT(reporter, proxy->asRenderTargetProxy()); |
Robert Phillips | 40d9495 | 2017-01-30 14:15:59 -0500 | [diff] [blame] | 132 | // This forces the proxy to compute and cache its |
| 133 | // pre-instantiation size guess. Later, when it is actually |
| 134 | // instantiated, it checks that the instantiated size is <= to |
| 135 | // the pre-computation. If the proxy never computed its |
| 136 | // pre-instantiation size then the check is skipped. |
Robert Phillips | 2f49314 | 2017-03-02 18:18:38 -0500 | [diff] [blame] | 137 | proxy->gpuMemorySize(); |
Robert Phillips | b446088 | 2016-11-17 14:43:51 -0500 | [diff] [blame] | 138 | |
Robert Phillips | 2f49314 | 2017-03-02 18:18:38 -0500 | [diff] [blame] | 139 | check_surface(reporter, proxy.get(), origin, |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 140 | widthHeight, widthHeight, config, budgeted); |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 141 | int supportedSamples = |
| 142 | caps.getRenderTargetSampleCount(numSamples, config); |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 143 | check_rendertarget(reporter, caps, resourceProvider, |
Robert Phillips | 2f49314 | 2017-03-02 18:18:38 -0500 | [diff] [blame] | 144 | proxy->asRenderTargetProxy(), |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 145 | supportedSamples, |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 146 | fit, caps.maxWindowRectangles()); |
Robert Phillips | 40d9495 | 2017-01-30 14:15:59 -0500 | [diff] [blame] | 147 | } |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 148 | } |
| 149 | |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 150 | desc.fFlags = kNone_GrSurfaceFlags; |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 151 | |
Robert Phillips | 6520a69 | 2017-02-01 09:20:00 -0500 | [diff] [blame] | 152 | { |
| 153 | sk_sp<GrTexture> tex; |
| 154 | if (SkBackingFit::kApprox == fit) { |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 155 | tex = resourceProvider->createApproxTexture(desc, 0); |
Robert Phillips | 6520a69 | 2017-02-01 09:20:00 -0500 | [diff] [blame] | 156 | } else { |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 157 | tex = resourceProvider->createTexture(desc, budgeted); |
Robert Phillips | 6520a69 | 2017-02-01 09:20:00 -0500 | [diff] [blame] | 158 | } |
Robert Phillips | b446088 | 2016-11-17 14:43:51 -0500 | [diff] [blame] | 159 | |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 160 | sk_sp<GrTextureProxy> proxy(proxyProvider->createProxy( |
| 161 | desc, fit, budgeted)); |
Robert Phillips | 2f49314 | 2017-03-02 18:18:38 -0500 | [diff] [blame] | 162 | REPORTER_ASSERT(reporter, SkToBool(tex) == SkToBool(proxy)); |
| 163 | if (proxy) { |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 164 | // This forces the proxy to compute and cache its |
| 165 | // pre-instantiation size guess. Later, when it is actually |
| 166 | // instantiated, it checks that the instantiated size is <= to |
| 167 | // the pre-computation. If the proxy never computed its |
| 168 | // pre-instantiation size then the check is skipped. |
Robert Phillips | 2f49314 | 2017-03-02 18:18:38 -0500 | [diff] [blame] | 169 | proxy->gpuMemorySize(); |
Robert Phillips | 6520a69 | 2017-02-01 09:20:00 -0500 | [diff] [blame] | 170 | |
Robert Phillips | 2f49314 | 2017-03-02 18:18:38 -0500 | [diff] [blame] | 171 | check_surface(reporter, proxy.get(), origin, |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 172 | widthHeight, widthHeight, config, budgeted); |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 173 | check_texture(reporter, resourceProvider, |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 174 | proxy->asTextureProxy(), fit); |
Robert Phillips | 6520a69 | 2017-02-01 09:20:00 -0500 | [diff] [blame] | 175 | } |
Robert Phillips | 40d9495 | 2017-01-30 14:15:59 -0500 | [diff] [blame] | 176 | } |
Robert Phillips | 6520a69 | 2017-02-01 09:20:00 -0500 | [diff] [blame] | 177 | |
| 178 | attempt++; |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 179 | } |
| 180 | } |
| 181 | } |
| 182 | } |
| 183 | } |
| 184 | } |
| 185 | } |
| 186 | |
egdaniel | ab527a5 | 2016-06-28 08:07:26 -0700 | [diff] [blame] | 187 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WrappedProxyTest, reporter, ctxInfo) { |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 188 | GrProxyProvider* proxyProvider = ctxInfo.grContext()->contextPriv().proxyProvider(); |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 189 | GrResourceProvider* resourceProvider = ctxInfo.grContext()->contextPriv().resourceProvider(); |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 190 | GrGpu* gpu = ctxInfo.grContext()->contextPriv().getGpu(); |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 191 | const GrCaps& caps = *ctxInfo.grContext()->caps(); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 192 | |
| 193 | static const int kWidthHeight = 100; |
| 194 | |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 195 | if (kOpenGL_GrBackend != ctxInfo.backend()) { |
| 196 | return; |
| 197 | } |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 198 | for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin }) { |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 199 | for (auto colorType : { kAlpha_8_SkColorType, kRGBA_8888_SkColorType }) { |
| 200 | for (auto numSamples : {1, 4}) { |
| 201 | GrPixelConfig config = SkImageInfo2GrPixelConfig(colorType, nullptr, caps); |
Greg Daniel | 0a7aa14 | 2018-02-21 13:02:32 -0500 | [diff] [blame^] | 202 | SkASSERT(kUnknown_GrPixelConfig != config); |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 203 | int supportedNumSamples = caps.getRenderTargetSampleCount(numSamples, config); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 204 | |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 205 | if (!supportedNumSamples) { |
| 206 | continue; |
| 207 | } |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 208 | |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 209 | // External on-screen render target. |
Greg Daniel | f87651e | 2018-02-21 11:36:53 -0500 | [diff] [blame] | 210 | // Tests createWrappedRenderTargetProxy with a GrBackendRenderTarget |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 211 | { |
| 212 | GrGLFramebufferInfo fboInfo; |
| 213 | fboInfo.fFBOID = 0; |
| 214 | GrBackendRenderTarget backendRT(kWidthHeight, kWidthHeight, numSamples, 8, |
| 215 | config, fboInfo); |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 216 | |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 217 | sk_sp<GrSurfaceProxy> sProxy(proxyProvider->createWrappedRenderTargetProxy( |
| 218 | backendRT, origin)); |
| 219 | check_surface(reporter, sProxy.get(), origin, |
| 220 | kWidthHeight, kWidthHeight, |
| 221 | backendRT.testingOnly_getPixelConfig(), SkBudgeted::kNo); |
| 222 | check_rendertarget(reporter, caps, resourceProvider, |
| 223 | sProxy->asRenderTargetProxy(), |
| 224 | supportedNumSamples, SkBackingFit::kExact, 0); |
| 225 | } |
| 226 | |
Greg Daniel | f87651e | 2018-02-21 11:36:53 -0500 | [diff] [blame] | 227 | // Tests createWrappedRenderTargetProxy with a GrBackendTexture |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 228 | { |
| 229 | GrBackendTexture backendTex = |
| 230 | gpu->createTestingOnlyBackendTexture(nullptr, kWidthHeight, |
| 231 | kWidthHeight, colorType, true, |
| 232 | GrMipMapped::kNo); |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 233 | sk_sp<GrSurfaceProxy> sProxy = |
Greg Daniel | f87651e | 2018-02-21 11:36:53 -0500 | [diff] [blame] | 234 | proxyProvider->createWrappedRenderTargetProxy(backendTex, origin, |
| 235 | supportedNumSamples); |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 236 | if (!sProxy) { |
Greg Daniel | f87651e | 2018-02-21 11:36:53 -0500 | [diff] [blame] | 237 | gpu->deleteTestingOnlyBackendTexture(&backendTex); |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 238 | continue; // This can fail on Mesa |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 239 | } |
| 240 | |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 241 | check_surface(reporter, sProxy.get(), origin, |
| 242 | kWidthHeight, kWidthHeight, |
| 243 | backendTex.testingOnly_getPixelConfig(), SkBudgeted::kNo); |
| 244 | check_rendertarget(reporter, caps, resourceProvider, |
| 245 | sProxy->asRenderTargetProxy(), |
| 246 | supportedNumSamples, SkBackingFit::kExact, |
| 247 | caps.maxWindowRectangles()); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 248 | |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 249 | gpu->deleteTestingOnlyBackendTexture(&backendTex); |
| 250 | } |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 251 | |
Greg Daniel | f87651e | 2018-02-21 11:36:53 -0500 | [diff] [blame] | 252 | // Tests createWrappedTextureProxy that is only renderable |
| 253 | { |
| 254 | GrBackendTexture backendTex = |
| 255 | gpu->createTestingOnlyBackendTexture(nullptr, kWidthHeight, |
| 256 | kWidthHeight, colorType, true, |
| 257 | GrMipMapped::kNo); |
| 258 | |
| 259 | sk_sp<GrSurfaceProxy> sProxy = |
| 260 | proxyProvider->createWrappedTextureProxy(backendTex, origin, |
| 261 | supportedNumSamples); |
| 262 | if (!sProxy) { |
| 263 | gpu->deleteTestingOnlyBackendTexture(&backendTex); |
| 264 | continue; // This can fail on Mesa |
| 265 | } |
| 266 | |
| 267 | check_surface(reporter, sProxy.get(), origin, |
| 268 | kWidthHeight, kWidthHeight, |
| 269 | backendTex.testingOnly_getPixelConfig(), SkBudgeted::kNo); |
| 270 | check_rendertarget(reporter, caps, resourceProvider, |
| 271 | sProxy->asRenderTargetProxy(), |
| 272 | supportedNumSamples, SkBackingFit::kExact, |
| 273 | caps.maxWindowRectangles()); |
| 274 | |
| 275 | gpu->deleteTestingOnlyBackendTexture(&backendTex); |
| 276 | } |
| 277 | |
| 278 | // Tests createWrappedTextureProxy that is only textureable |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 279 | { |
| 280 | // Internal offscreen texture |
| 281 | GrBackendTexture backendTex = |
| 282 | gpu->createTestingOnlyBackendTexture(nullptr, kWidthHeight, |
| 283 | kWidthHeight, colorType, false, |
| 284 | GrMipMapped::kNo); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 285 | |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 286 | sk_sp<GrSurfaceProxy> sProxy = |
| 287 | proxyProvider->createWrappedTextureProxy(backendTex, origin, |
| 288 | kBorrow_GrWrapOwnership, |
| 289 | nullptr, nullptr); |
| 290 | if (!sProxy) { |
Greg Daniel | f87651e | 2018-02-21 11:36:53 -0500 | [diff] [blame] | 291 | gpu->deleteTestingOnlyBackendTexture(&backendTex); |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 292 | continue; |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 293 | } |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 294 | |
| 295 | check_surface(reporter, sProxy.get(), origin, |
| 296 | kWidthHeight, kWidthHeight, |
| 297 | backendTex.testingOnly_getPixelConfig(), SkBudgeted::kNo); |
| 298 | check_texture(reporter, resourceProvider, sProxy->asTextureProxy(), |
| 299 | SkBackingFit::kExact); |
| 300 | |
| 301 | gpu->deleteTestingOnlyBackendTexture(&backendTex); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 302 | } |
| 303 | } |
| 304 | } |
| 305 | } |
| 306 | } |
| 307 | |
Robert Phillips | 78de212 | 2017-04-26 07:44:26 -0400 | [diff] [blame] | 308 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ZeroSizedProxyTest, reporter, ctxInfo) { |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 309 | GrProxyProvider* provider = ctxInfo.grContext()->contextPriv().proxyProvider(); |
Robert Phillips | 78de212 | 2017-04-26 07:44:26 -0400 | [diff] [blame] | 310 | |
| 311 | for (auto flags : { kRenderTarget_GrSurfaceFlag, kNone_GrSurfaceFlags }) { |
| 312 | for (auto fit : { SkBackingFit::kExact, SkBackingFit::kApprox }) { |
| 313 | for (int width : { 0, 100 }) { |
| 314 | for (int height : { 0, 100}) { |
| 315 | if (width && height) { |
| 316 | continue; // not zero-sized |
| 317 | } |
| 318 | |
| 319 | GrSurfaceDesc desc; |
| 320 | desc.fFlags = flags; |
| 321 | desc.fOrigin = kBottomLeft_GrSurfaceOrigin; |
| 322 | desc.fWidth = width; |
| 323 | desc.fHeight = height; |
| 324 | desc.fConfig = kRGBA_8888_GrPixelConfig; |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 325 | desc.fSampleCnt = 1; |
Robert Phillips | 78de212 | 2017-04-26 07:44:26 -0400 | [diff] [blame] | 326 | |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 327 | sk_sp<GrTextureProxy> proxy = provider->createProxy(desc, fit, SkBudgeted::kNo); |
Robert Phillips | 78de212 | 2017-04-26 07:44:26 -0400 | [diff] [blame] | 328 | REPORTER_ASSERT(reporter, !proxy); |
| 329 | } |
| 330 | } |
| 331 | } |
| 332 | } |
| 333 | } |
| 334 | |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 335 | #endif |