bsalomon@google.com | 686bcb8 | 2013-04-09 15:04:12 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 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 | |
Brian Salomon | 614c1a8 | 2018-12-19 15:42:06 -0500 | [diff] [blame] | 8 | #include <set> |
| 9 | #include "GrClip.h" |
bsalomon@google.com | 686bcb8 | 2013-04-09 15:04:12 +0000 | [diff] [blame] | 10 | #include "GrContext.h" |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 11 | #include "GrContextPriv.h" |
bsalomon | 091f60c | 2015-11-10 11:54:56 -0800 | [diff] [blame] | 12 | #include "GrGpu.h" |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 13 | #include "GrProxyProvider.h" |
Robert Phillips | 2890fbf | 2017-07-26 15:48:41 -0400 | [diff] [blame] | 14 | #include "GrRenderTarget.h" |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 15 | #include "GrResourceProvider.h" |
bsalomon@google.com | 686bcb8 | 2013-04-09 15:04:12 +0000 | [diff] [blame] | 16 | #include "GrTexture.h" |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 17 | #include "GrTexturePriv.h" |
| 18 | #include "SkAutoPixmapStorage.h" |
Brian Osman | 48c9919 | 2017-06-02 08:45:06 -0400 | [diff] [blame] | 19 | #include "SkMipMap.h" |
Brian Salomon | 614c1a8 | 2018-12-19 15:42:06 -0500 | [diff] [blame] | 20 | #include "SkSurface.h" |
tfarina@chromium.org | 4ee16bf | 2014-01-10 22:08:27 +0000 | [diff] [blame] | 21 | #include "Test.h" |
bsalomon@google.com | 686bcb8 | 2013-04-09 15:04:12 +0000 | [diff] [blame] | 22 | |
bsalomon | a2c2323 | 2014-11-25 07:41:12 -0800 | [diff] [blame] | 23 | // Tests that GrSurface::asTexture(), GrSurface::asRenderTarget(), and static upcasting of texture |
| 24 | // and render targets to GrSurface all work as expected. |
bsalomon | 758586c | 2016-04-06 14:02:39 -0700 | [diff] [blame] | 25 | DEF_GPUTEST_FOR_NULLGL_CONTEXT(GrSurface, reporter, ctxInfo) { |
bsalomon | 8b7451a | 2016-05-11 06:33:06 -0700 | [diff] [blame] | 26 | GrContext* context = ctxInfo.grContext(); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 27 | auto resourceProvider = context->priv().resourceProvider(); |
| 28 | GrGpu* gpu = context->priv().getGpu(); |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 29 | |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 30 | GrSurfaceDesc desc; |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 31 | desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 32 | desc.fWidth = 256; |
| 33 | desc.fHeight = 256; |
Robert Phillips | 16d8ec6 | 2017-07-27 16:16:25 -0400 | [diff] [blame] | 34 | desc.fConfig = kRGBA_8888_GrPixelConfig; |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 35 | desc.fSampleCnt = 1; |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 36 | sk_sp<GrSurface> texRT1 = resourceProvider->createTexture(desc, SkBudgeted::kNo); |
bsalomon | a2c2323 | 2014-11-25 07:41:12 -0800 | [diff] [blame] | 37 | |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 38 | REPORTER_ASSERT(reporter, texRT1.get() == texRT1->asRenderTarget()); |
| 39 | REPORTER_ASSERT(reporter, texRT1.get() == texRT1->asTexture()); |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 40 | REPORTER_ASSERT(reporter, static_cast<GrSurface*>(texRT1->asRenderTarget()) == |
| 41 | texRT1->asTexture()); |
| 42 | REPORTER_ASSERT(reporter, texRT1->asRenderTarget() == |
| 43 | static_cast<GrSurface*>(texRT1->asTexture())); |
| 44 | REPORTER_ASSERT(reporter, static_cast<GrSurface*>(texRT1->asRenderTarget()) == |
| 45 | static_cast<GrSurface*>(texRT1->asTexture())); |
bsalomon | a2c2323 | 2014-11-25 07:41:12 -0800 | [diff] [blame] | 46 | |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 47 | desc.fFlags = kNone_GrSurfaceFlags; |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 48 | sk_sp<GrTexture> tex1 = resourceProvider->createTexture(desc, SkBudgeted::kNo); |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 49 | REPORTER_ASSERT(reporter, nullptr == tex1->asRenderTarget()); |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 50 | REPORTER_ASSERT(reporter, tex1.get() == tex1->asTexture()); |
| 51 | REPORTER_ASSERT(reporter, static_cast<GrSurface*>(tex1.get()) == tex1->asTexture()); |
bsalomon@google.com | 686bcb8 | 2013-04-09 15:04:12 +0000 | [diff] [blame] | 52 | |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 53 | GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture( |
Robert Phillips | 646f637 | 2018-09-25 09:31:10 -0400 | [diff] [blame] | 54 | nullptr, 256, 256, GrColorType::kRGBA_8888, false, GrMipMapped::kNo); |
bsalomon | 091f60c | 2015-11-10 11:54:56 -0800 | [diff] [blame] | 55 | |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 56 | sk_sp<GrSurface> texRT2 = resourceProvider->wrapRenderableBackendTexture( |
| 57 | backendTex, 1, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo); |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 58 | |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 59 | REPORTER_ASSERT(reporter, texRT2.get() == texRT2->asRenderTarget()); |
| 60 | REPORTER_ASSERT(reporter, texRT2.get() == texRT2->asTexture()); |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 61 | REPORTER_ASSERT(reporter, static_cast<GrSurface*>(texRT2->asRenderTarget()) == |
| 62 | texRT2->asTexture()); |
| 63 | REPORTER_ASSERT(reporter, texRT2->asRenderTarget() == |
| 64 | static_cast<GrSurface*>(texRT2->asTexture())); |
| 65 | REPORTER_ASSERT(reporter, static_cast<GrSurface*>(texRT2->asRenderTarget()) == |
| 66 | static_cast<GrSurface*>(texRT2->asTexture())); |
bsalomon@google.com | 686bcb8 | 2013-04-09 15:04:12 +0000 | [diff] [blame] | 67 | |
Brian Salomon | 26102cb | 2018-03-09 09:33:19 -0500 | [diff] [blame] | 68 | gpu->deleteTestingOnlyBackendTexture(backendTex); |
bsalomon@google.com | 686bcb8 | 2013-04-09 15:04:12 +0000 | [diff] [blame] | 69 | } |
| 70 | |
Robert Phillips | b7b7e5f | 2017-05-22 13:23:19 -0400 | [diff] [blame] | 71 | // This test checks that the isConfigTexturable and isConfigRenderable are |
| 72 | // consistent with createTexture's result. |
| 73 | DEF_GPUTEST_FOR_ALL_CONTEXTS(GrSurfaceRenderability, reporter, ctxInfo) { |
| 74 | GrContext* context = ctxInfo.grContext(); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 75 | GrProxyProvider* proxyProvider = context->priv().proxyProvider(); |
| 76 | GrResourceProvider* resourceProvider = context->priv().resourceProvider(); |
| 77 | const GrCaps* caps = context->priv().caps(); |
Robert Phillips | b7b7e5f | 2017-05-22 13:23:19 -0400 | [diff] [blame] | 78 | |
| 79 | GrPixelConfig configs[] = { |
| 80 | kUnknown_GrPixelConfig, |
| 81 | kAlpha_8_GrPixelConfig, |
Greg Daniel | ef59d87 | 2017-11-17 16:47:21 -0500 | [diff] [blame] | 82 | kAlpha_8_as_Alpha_GrPixelConfig, |
| 83 | kAlpha_8_as_Red_GrPixelConfig, |
Robert Phillips | b7b7e5f | 2017-05-22 13:23:19 -0400 | [diff] [blame] | 84 | kGray_8_GrPixelConfig, |
Greg Daniel | 7af060a | 2017-12-05 16:27:11 -0500 | [diff] [blame] | 85 | kGray_8_as_Lum_GrPixelConfig, |
| 86 | kGray_8_as_Red_GrPixelConfig, |
Robert Phillips | b7b7e5f | 2017-05-22 13:23:19 -0400 | [diff] [blame] | 87 | kRGB_565_GrPixelConfig, |
| 88 | kRGBA_4444_GrPixelConfig, |
| 89 | kRGBA_8888_GrPixelConfig, |
Brian Salomon | 5fba7ad | 2018-03-22 10:01:16 -0400 | [diff] [blame] | 90 | kRGB_888_GrPixelConfig, |
Greg Daniel | f259b8b | 2019-02-14 09:03:43 -0500 | [diff] [blame] | 91 | kRGB_888X_GrPixelConfig, |
Jim Van Verth | 69e5785 | 2018-12-05 13:38:59 -0500 | [diff] [blame] | 92 | kRG_88_GrPixelConfig, |
Robert Phillips | b7b7e5f | 2017-05-22 13:23:19 -0400 | [diff] [blame] | 93 | kBGRA_8888_GrPixelConfig, |
| 94 | kSRGBA_8888_GrPixelConfig, |
| 95 | kSBGRA_8888_GrPixelConfig, |
Brian Osman | 10fc6fd | 2018-03-02 11:01:10 -0500 | [diff] [blame] | 96 | kRGBA_1010102_GrPixelConfig, |
Robert Phillips | b7b7e5f | 2017-05-22 13:23:19 -0400 | [diff] [blame] | 97 | kRGBA_float_GrPixelConfig, |
| 98 | kRG_float_GrPixelConfig, |
| 99 | kAlpha_half_GrPixelConfig, |
Greg Daniel | ef59d87 | 2017-11-17 16:47:21 -0500 | [diff] [blame] | 100 | kAlpha_half_as_Red_GrPixelConfig, |
Robert Phillips | b7b7e5f | 2017-05-22 13:23:19 -0400 | [diff] [blame] | 101 | kRGBA_half_GrPixelConfig, |
Jim Van Verth | 1676cb9 | 2019-01-15 13:24:45 -0500 | [diff] [blame] | 102 | kRGB_ETC1_GrPixelConfig, |
Robert Phillips | b7b7e5f | 2017-05-22 13:23:19 -0400 | [diff] [blame] | 103 | }; |
Brian Salomon | 5fba7ad | 2018-03-22 10:01:16 -0400 | [diff] [blame] | 104 | GR_STATIC_ASSERT(kGrPixelConfigCnt == SK_ARRAY_COUNT(configs)); |
Robert Phillips | b7b7e5f | 2017-05-22 13:23:19 -0400 | [diff] [blame] | 105 | |
| 106 | GrSurfaceDesc desc; |
| 107 | desc.fWidth = 64; |
| 108 | desc.fHeight = 64; |
| 109 | |
| 110 | for (GrPixelConfig config : configs) { |
| 111 | for (GrSurfaceOrigin origin : { kTopLeft_GrSurfaceOrigin, kBottomLeft_GrSurfaceOrigin }) { |
| 112 | desc.fFlags = kNone_GrSurfaceFlags; |
Robert Phillips | b7b7e5f | 2017-05-22 13:23:19 -0400 | [diff] [blame] | 113 | desc.fConfig = config; |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 114 | desc.fSampleCnt = 1; |
Robert Phillips | b7b7e5f | 2017-05-22 13:23:19 -0400 | [diff] [blame] | 115 | |
Robert Phillips | 3b3307f | 2017-05-24 07:44:02 -0400 | [diff] [blame] | 116 | sk_sp<GrSurface> tex = resourceProvider->createTexture(desc, SkBudgeted::kNo); |
Brian Salomon | 1c80e99 | 2018-01-29 09:50:47 -0500 | [diff] [blame] | 117 | bool ict = caps->isConfigTexturable(desc.fConfig); |
| 118 | REPORTER_ASSERT(reporter, SkToBool(tex) == ict, |
| 119 | "config:%d, tex:%d, isConfigTexturable:%d", config, SkToBool(tex), ict); |
Robert Phillips | b7b7e5f | 2017-05-22 13:23:19 -0400 | [diff] [blame] | 120 | |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 121 | GrSRGBEncoded srgbEncoded = GrSRGBEncoded::kNo; |
| 122 | GrColorType colorType = GrPixelConfigToColorTypeAndEncoding(config, &srgbEncoded); |
| 123 | const GrBackendFormat format = |
| 124 | caps->getBackendFormatFromGrColorType(colorType, srgbEncoded); |
| 125 | |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 126 | sk_sp<GrTextureProxy> proxy = |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 127 | proxyProvider->createMipMapProxy(format, desc, origin, SkBudgeted::kNo); |
Brian Osman | 48c9919 | 2017-06-02 08:45:06 -0400 | [diff] [blame] | 128 | REPORTER_ASSERT(reporter, SkToBool(proxy.get()) == |
| 129 | (caps->isConfigTexturable(desc.fConfig) && |
Brian Salomon | 5711133 | 2018-02-05 15:55:54 -0500 | [diff] [blame] | 130 | caps->mipMapSupport())); |
Brian Osman | 48c9919 | 2017-06-02 08:45:06 -0400 | [diff] [blame] | 131 | |
Robert Phillips | b7b7e5f | 2017-05-22 13:23:19 -0400 | [diff] [blame] | 132 | desc.fFlags = kRenderTarget_GrSurfaceFlag; |
Robert Phillips | 3b3307f | 2017-05-24 07:44:02 -0400 | [diff] [blame] | 133 | tex = resourceProvider->createTexture(desc, SkBudgeted::kNo); |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 134 | bool isRenderable = caps->isConfigRenderable(config); |
| 135 | REPORTER_ASSERT(reporter, SkToBool(tex) == isRenderable, |
| 136 | "config:%d, tex:%d, isRenderable:%d", config, SkToBool(tex), |
| 137 | isRenderable); |
Robert Phillips | b7b7e5f | 2017-05-22 13:23:19 -0400 | [diff] [blame] | 138 | |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 139 | desc.fSampleCnt = 2; |
Robert Phillips | 3b3307f | 2017-05-24 07:44:02 -0400 | [diff] [blame] | 140 | tex = resourceProvider->createTexture(desc, SkBudgeted::kNo); |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 141 | isRenderable = SkToBool(caps->getRenderTargetSampleCount(2, config)); |
| 142 | REPORTER_ASSERT(reporter, SkToBool(tex) == isRenderable, |
| 143 | "config:%d, tex:%d, isRenderable:%d", config, SkToBool(tex), |
| 144 | isRenderable); |
Robert Phillips | b7b7e5f | 2017-05-22 13:23:19 -0400 | [diff] [blame] | 145 | } |
| 146 | } |
| 147 | } |
Robert Phillips | b7b7e5f | 2017-05-22 13:23:19 -0400 | [diff] [blame] | 148 | |
Brian Salomon | d17b4a6 | 2017-05-23 16:53:47 -0400 | [diff] [blame] | 149 | #include "GrDrawingManager.h" |
| 150 | #include "GrSurfaceProxy.h" |
| 151 | #include "GrTextureContext.h" |
| 152 | |
| 153 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(InitialTextureClear, reporter, context_info) { |
| 154 | static constexpr int kSize = 100; |
| 155 | GrSurfaceDesc desc; |
| 156 | desc.fWidth = desc.fHeight = kSize; |
| 157 | std::unique_ptr<uint32_t[]> data(new uint32_t[kSize * kSize]); |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 158 | |
Brian Salomon | d17b4a6 | 2017-05-23 16:53:47 -0400 | [diff] [blame] | 159 | GrContext* context = context_info.grContext(); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 160 | const GrCaps* caps = context->priv().caps(); |
| 161 | GrProxyProvider* proxyProvider = context->priv().proxyProvider(); |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 162 | |
Brian Salomon | d17b4a6 | 2017-05-23 16:53:47 -0400 | [diff] [blame] | 163 | for (int c = 0; c <= kLast_GrPixelConfig; ++c) { |
| 164 | desc.fConfig = static_cast<GrPixelConfig>(c); |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 165 | if (!caps->isConfigTexturable(desc.fConfig)) { |
Brian Salomon | d17b4a6 | 2017-05-23 16:53:47 -0400 | [diff] [blame] | 166 | continue; |
| 167 | } |
| 168 | desc.fFlags = kPerformInitialClear_GrSurfaceFlag; |
| 169 | for (bool rt : {false, true}) { |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 170 | if (rt && !caps->isConfigRenderable(desc.fConfig)) { |
Brian Salomon | d17b4a6 | 2017-05-23 16:53:47 -0400 | [diff] [blame] | 171 | continue; |
| 172 | } |
| 173 | desc.fFlags |= rt ? kRenderTarget_GrSurfaceFlag : kNone_GrSurfaceFlags; |
Greg Daniel | 90f28ec | 2017-09-25 12:26:58 -0400 | [diff] [blame] | 174 | for (GrSurfaceOrigin origin : |
| 175 | {kTopLeft_GrSurfaceOrigin, kBottomLeft_GrSurfaceOrigin}) { |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 176 | for (auto fit : { SkBackingFit::kApprox, SkBackingFit::kExact }) { |
Greg Daniel | 90f28ec | 2017-09-25 12:26:58 -0400 | [diff] [blame] | 177 | // Try directly creating the texture. |
| 178 | // Do this twice in an attempt to hit the cache on the second time through. |
| 179 | for (int i = 0; i < 2; ++i) { |
Chris Dalton | d004e0b | 2018-09-27 09:28:03 -0600 | [diff] [blame] | 180 | auto proxy = proxyProvider->testingOnly_createInstantiatedProxy( |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 181 | desc, origin, fit, SkBudgeted::kYes); |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 182 | if (!proxy) { |
Greg Daniel | 90f28ec | 2017-09-25 12:26:58 -0400 | [diff] [blame] | 183 | continue; |
| 184 | } |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 185 | auto texCtx = context->priv().makeWrappedSurfaceContext(std::move(proxy)); |
Greg Daniel | 90f28ec | 2017-09-25 12:26:58 -0400 | [diff] [blame] | 186 | SkImageInfo info = SkImageInfo::Make( |
| 187 | kSize, kSize, kRGBA_8888_SkColorType, kPremul_SkAlphaType); |
| 188 | memset(data.get(), 0xAB, kSize * kSize * sizeof(uint32_t)); |
| 189 | if (texCtx->readPixels(info, data.get(), 0, 0, 0)) { |
| 190 | uint32_t cmp = GrPixelConfigIsOpaque(desc.fConfig) ? 0xFF000000 : 0; |
| 191 | for (int i = 0; i < kSize * kSize; ++i) { |
| 192 | if (cmp != data.get()[i]) { |
| 193 | ERRORF(reporter, "Failed on config %d", desc.fConfig); |
| 194 | break; |
Brian Salomon | d17b4a6 | 2017-05-23 16:53:47 -0400 | [diff] [blame] | 195 | } |
| 196 | } |
Brian Salomon | d17b4a6 | 2017-05-23 16:53:47 -0400 | [diff] [blame] | 197 | } |
Greg Daniel | 90f28ec | 2017-09-25 12:26:58 -0400 | [diff] [blame] | 198 | memset(data.get(), 0xBC, kSize * kSize * sizeof(uint32_t)); |
| 199 | // Here we overwrite the texture so that the second time through we |
| 200 | // test against recycling without reclearing. |
| 201 | if (0 == i) { |
| 202 | texCtx->writePixels(info, data.get(), 0, 0, 0); |
Greg Daniel | 52cb5fe | 2017-09-05 15:45:15 -0400 | [diff] [blame] | 203 | } |
Greg Daniel | 52cb5fe | 2017-09-05 15:45:15 -0400 | [diff] [blame] | 204 | } |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 205 | context->priv().testingOnly_purgeAllUnlockedResources(); |
Greg Daniel | 90f28ec | 2017-09-25 12:26:58 -0400 | [diff] [blame] | 206 | |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 207 | GrSRGBEncoded srgbEncoded = GrSRGBEncoded::kNo; |
| 208 | GrColorType colorType = GrPixelConfigToColorTypeAndEncoding(desc.fConfig, |
| 209 | &srgbEncoded); |
| 210 | const GrBackendFormat format = |
| 211 | caps->getBackendFormatFromGrColorType(colorType, srgbEncoded); |
| 212 | |
Greg Daniel | 90f28ec | 2017-09-25 12:26:58 -0400 | [diff] [blame] | 213 | // Try creating the texture as a deferred proxy. |
| 214 | for (int i = 0; i < 2; ++i) { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 215 | auto surfCtx = context->priv().makeDeferredSurfaceContext( |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 216 | format, desc, origin, GrMipMapped::kNo, fit, SkBudgeted::kYes); |
Greg Daniel | 90f28ec | 2017-09-25 12:26:58 -0400 | [diff] [blame] | 217 | if (!surfCtx) { |
| 218 | continue; |
| 219 | } |
| 220 | SkImageInfo info = SkImageInfo::Make( |
| 221 | kSize, kSize, kRGBA_8888_SkColorType, kPremul_SkAlphaType); |
| 222 | memset(data.get(), 0xAB, kSize * kSize * sizeof(uint32_t)); |
| 223 | if (surfCtx->readPixels(info, data.get(), 0, 0, 0)) { |
| 224 | uint32_t cmp = GrPixelConfigIsOpaque(desc.fConfig) ? 0xFF000000 : 0; |
| 225 | for (int i = 0; i < kSize * kSize; ++i) { |
| 226 | if (cmp != data.get()[i]) { |
| 227 | ERRORF(reporter, "Failed on config %d", desc.fConfig); |
| 228 | break; |
| 229 | } |
| 230 | } |
| 231 | } |
| 232 | // Here we overwrite the texture so that the second time through we |
| 233 | // test against recycling without reclearing. |
| 234 | if (0 == i) { |
| 235 | surfCtx->writePixels(info, data.get(), 0, 0, 0); |
| 236 | } |
| 237 | } |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 238 | context->priv().testingOnly_purgeAllUnlockedResources(); |
Brian Salomon | d17b4a6 | 2017-05-23 16:53:47 -0400 | [diff] [blame] | 239 | } |
| 240 | } |
| 241 | } |
| 242 | } |
| 243 | } |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 244 | |
| 245 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadOnlyTexture, reporter, context_info) { |
| 246 | auto fillPixels = [](const SkPixmap* p, const std::function<uint32_t(int x, int y)>& f) { |
| 247 | for (int y = 0; y < p->height(); ++y) { |
| 248 | for (int x = 0; x < p->width(); ++x) { |
| 249 | *p->writable_addr32(x, y) = f(x, y); |
| 250 | } |
| 251 | } |
| 252 | }; |
| 253 | |
| 254 | auto comparePixels = [](const SkPixmap& p1, const SkPixmap& p2, skiatest::Reporter* reporter) { |
| 255 | SkASSERT(p1.info() == p2.info()); |
| 256 | for (int y = 0; y < p1.height(); ++y) { |
| 257 | for (int x = 0; x < p1.width(); ++x) { |
| 258 | REPORTER_ASSERT(reporter, p1.getColor(x, y) == p2.getColor(x, y)); |
| 259 | if (p1.getColor(x, y) != p2.getColor(x, y)) { |
| 260 | return; |
| 261 | } |
| 262 | } |
| 263 | } |
| 264 | }; |
| 265 | |
| 266 | static constexpr int kSize = 100; |
| 267 | SkAutoPixmapStorage pixels; |
| 268 | pixels.alloc(SkImageInfo::Make(kSize, kSize, kRGBA_8888_SkColorType, kPremul_SkAlphaType)); |
Brian Osman | 50ea3c0 | 2019-02-04 10:01:53 -0500 | [diff] [blame] | 269 | fillPixels(&pixels, [](int x, int y) { |
| 270 | return (0xFFU << 24) | (x << 16) | (y << 8) | uint8_t((x * y) & 0xFF); |
| 271 | }); |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 272 | |
| 273 | GrContext* context = context_info.grContext(); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 274 | GrProxyProvider* proxyProvider = context->priv().proxyProvider(); |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 275 | |
| 276 | // We test both kRW in addition to kRead mostly to ensure that the calls are structured such |
| 277 | // that they'd succeed if the texture wasn't kRead. We want to be sure we're failing with |
| 278 | // kRead for the right reason. |
| 279 | for (auto ioType : {kRead_GrIOType, kRW_GrIOType}) { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 280 | auto backendTex = context->priv().getGpu()->createTestingOnlyBackendTexture( |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 281 | pixels.addr(), kSize, kSize, kRGBA_8888_SkColorType, true, GrMipMapped::kNo); |
| 282 | auto proxy = proxyProvider->wrapBackendTexture(backendTex, kTopLeft_GrSurfaceOrigin, |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 283 | kBorrow_GrWrapOwnership, |
| 284 | GrWrapCacheable::kNo, ioType); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 285 | auto surfContext = context->priv().makeWrappedSurfaceContext(proxy); |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 286 | |
| 287 | // Read pixels should work with a read-only texture. |
| 288 | SkAutoPixmapStorage read; |
| 289 | read.alloc(pixels.info()); |
| 290 | auto readResult = surfContext->readPixels(pixels.info(), read.writable_addr(), 0, 0, 0); |
| 291 | REPORTER_ASSERT(reporter, readResult); |
| 292 | if (readResult) { |
| 293 | comparePixels(pixels, read, reporter); |
| 294 | } |
| 295 | |
| 296 | // Write pixels should not work with a read-only texture. |
| 297 | SkAutoPixmapStorage write; |
| 298 | write.alloc(pixels.info()); |
| 299 | fillPixels(&write, [&pixels](int x, int y) { return ~*pixels.addr32(); }); |
| 300 | auto writeResult = surfContext->writePixels(pixels.info(), pixels.addr(), 0, 0, 0); |
| 301 | REPORTER_ASSERT(reporter, writeResult == (ioType == kRW_GrIOType)); |
| 302 | // Try the low level write. |
| 303 | context->flush(); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 304 | auto gpuWriteResult = context->priv().getGpu()->writePixels( |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 305 | proxy->peekTexture(), 0, 0, kSize, kSize, GrColorType::kRGBA_8888, write.addr32(), |
| 306 | 0); |
| 307 | REPORTER_ASSERT(reporter, gpuWriteResult == (ioType == kRW_GrIOType)); |
| 308 | |
| 309 | // Copies should not work with a read-only texture |
| 310 | auto copySrc = proxyProvider->createTextureProxy( |
| 311 | SkImage::MakeFromRaster(write, nullptr, nullptr), kNone_GrSurfaceFlags, 1, |
| 312 | SkBudgeted::kYes, SkBackingFit::kExact); |
| 313 | REPORTER_ASSERT(reporter, copySrc); |
| 314 | auto copyResult = surfContext->copy(copySrc.get()); |
| 315 | REPORTER_ASSERT(reporter, copyResult == (ioType == kRW_GrIOType)); |
| 316 | // Try the low level copy. |
| 317 | context->flush(); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 318 | auto gpuCopyResult = context->priv().getGpu()->copySurface( |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 319 | proxy->peekTexture(), kTopLeft_GrSurfaceOrigin, copySrc->peekTexture(), |
| 320 | kTopLeft_GrSurfaceOrigin, SkIRect::MakeWH(kSize, kSize), {0, 0}); |
| 321 | REPORTER_ASSERT(reporter, gpuCopyResult == (ioType == kRW_GrIOType)); |
| 322 | |
| 323 | // Mip regen should not work with a read only texture. |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 324 | if (context->priv().caps()->mipMapSupport()) { |
| 325 | backendTex = context->priv().getGpu()->createTestingOnlyBackendTexture( |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 326 | nullptr, kSize, kSize, kRGBA_8888_SkColorType, true, GrMipMapped::kYes); |
| 327 | proxy = proxyProvider->wrapBackendTexture(backendTex, kTopLeft_GrSurfaceOrigin, |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 328 | kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, |
| 329 | ioType); |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 330 | context->flush(); |
| 331 | proxy->peekTexture()->texturePriv().markMipMapsDirty(); // avoids assert in GrGpu. |
| 332 | auto regenResult = |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 333 | context->priv().getGpu()->regenerateMipMapLevels(proxy->peekTexture()); |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 334 | REPORTER_ASSERT(reporter, regenResult == (ioType == kRW_GrIOType)); |
| 335 | } |
| 336 | } |
| 337 | } |
Brian Salomon | 614c1a8 | 2018-12-19 15:42:06 -0500 | [diff] [blame] | 338 | |
| 339 | DEF_GPUTEST(TextureIdleProcTest, reporter, options) { |
Brian Salomon | 614c1a8 | 2018-12-19 15:42:06 -0500 | [diff] [blame] | 340 | static const int kS = 10; |
| 341 | |
| 342 | // Helper to delete a backend texture in a GrTexture's release proc. |
| 343 | static const auto installBackendTextureReleaseProc = [](GrTexture* texture) { |
| 344 | auto backendTexture = texture->getBackendTexture(); |
| 345 | auto context = texture->getContext(); |
| 346 | struct ReleaseContext { |
| 347 | GrContext* fContext; |
| 348 | GrBackendTexture fBackendTexture; |
| 349 | }; |
| 350 | auto release = [](void* rc) { |
| 351 | auto releaseContext = static_cast<ReleaseContext*>(rc); |
| 352 | if (!releaseContext->fContext->abandoned()) { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 353 | if (auto gpu = releaseContext->fContext->priv().getGpu()) { |
Brian Salomon | 614c1a8 | 2018-12-19 15:42:06 -0500 | [diff] [blame] | 354 | gpu->deleteTestingOnlyBackendTexture(releaseContext->fBackendTexture); |
| 355 | } |
| 356 | } |
| 357 | delete releaseContext; |
| 358 | }; |
| 359 | texture->setRelease(sk_make_sp<GrReleaseProcHelper>( |
| 360 | release, new ReleaseContext{context, backendTexture})); |
| 361 | }; |
| 362 | |
| 363 | // Various ways of making textures. |
| 364 | auto makeWrapped = [](GrContext* context) { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 365 | auto backendTexture = context->priv().getGpu()->createTestingOnlyBackendTexture( |
Brian Salomon | 614c1a8 | 2018-12-19 15:42:06 -0500 | [diff] [blame] | 366 | nullptr, kS, kS, GrColorType::kRGBA_8888, false, GrMipMapped::kNo); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 367 | auto texture = context->priv().resourceProvider()->wrapBackendTexture( |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 368 | backendTexture, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, kRW_GrIOType); |
Brian Salomon | 614c1a8 | 2018-12-19 15:42:06 -0500 | [diff] [blame] | 369 | installBackendTextureReleaseProc(texture.get()); |
| 370 | return texture; |
| 371 | }; |
| 372 | |
| 373 | auto makeWrappedRenderable = [](GrContext* context) { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 374 | auto backendTexture = context->priv().getGpu()->createTestingOnlyBackendTexture( |
Brian Salomon | 614c1a8 | 2018-12-19 15:42:06 -0500 | [diff] [blame] | 375 | nullptr, kS, kS, GrColorType::kRGBA_8888, true, GrMipMapped::kNo); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 376 | auto texture = context->priv().resourceProvider()->wrapRenderableBackendTexture( |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 377 | backendTexture, 1, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo); |
Brian Salomon | 614c1a8 | 2018-12-19 15:42:06 -0500 | [diff] [blame] | 378 | installBackendTextureReleaseProc(texture.get()); |
| 379 | return texture; |
| 380 | }; |
| 381 | |
| 382 | auto makeNormal = [](GrContext* context) { |
| 383 | GrSurfaceDesc desc; |
| 384 | desc.fConfig = kRGBA_8888_GrPixelConfig; |
| 385 | desc.fWidth = desc.fHeight = kS; |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 386 | return context->priv().resourceProvider()->createTexture(desc, SkBudgeted::kNo); |
Brian Salomon | 614c1a8 | 2018-12-19 15:42:06 -0500 | [diff] [blame] | 387 | }; |
| 388 | |
| 389 | auto makeRenderable = [](GrContext* context) { |
| 390 | GrSurfaceDesc desc; |
| 391 | desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 392 | desc.fConfig = kRGBA_8888_GrPixelConfig; |
| 393 | desc.fWidth = desc.fHeight = kS; |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 394 | return context->priv().resourceProvider()->createTexture(desc, SkBudgeted::kNo); |
Brian Salomon | 614c1a8 | 2018-12-19 15:42:06 -0500 | [diff] [blame] | 395 | }; |
| 396 | |
| 397 | std::function<sk_sp<GrTexture>(GrContext*)> makers[] = {makeWrapped, makeWrappedRenderable, |
| 398 | makeNormal, makeRenderable}; |
| 399 | |
| 400 | // Add a unique key, or not. |
| 401 | auto addKey = [](GrTexture* texture) { |
| 402 | static uint32_t gN = 0; |
| 403 | static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); |
| 404 | GrUniqueKey key; |
| 405 | GrUniqueKey::Builder builder(&key, kDomain, 1); |
| 406 | builder[0] = gN++; |
| 407 | builder.finish(); |
| 408 | texture->resourcePriv().setUniqueKey(key); |
| 409 | }; |
| 410 | auto dontAddKey = [](GrTexture* texture) {}; |
| 411 | std::function<void(GrTexture*)> keyAdders[] = {addKey, dontAddKey}; |
| 412 | |
| 413 | for (const auto& m : makers) { |
| 414 | for (const auto& keyAdder : keyAdders) { |
| 415 | for (int type = 0; type < sk_gpu_test::GrContextFactory::kContextTypeCnt; ++type) { |
| 416 | sk_gpu_test::GrContextFactory factory; |
| 417 | auto contextType = static_cast<sk_gpu_test::GrContextFactory::ContextType>(type); |
Brian Salomon | 9bc76d9 | 2019-01-24 12:18:33 -0500 | [diff] [blame] | 418 | GrContext* context = factory.get(contextType); |
Brian Salomon | 614c1a8 | 2018-12-19 15:42:06 -0500 | [diff] [blame] | 419 | if (!context) { |
| 420 | continue; |
| 421 | } |
| 422 | |
| 423 | // The callback we add simply adds an integer to a set. |
| 424 | std::set<int> idleIDs; |
| 425 | struct Context { |
| 426 | std::set<int>* fIdleIDs; |
| 427 | int fNum; |
| 428 | }; |
| 429 | auto proc = [](void* context) { |
| 430 | static_cast<Context*>(context)->fIdleIDs->insert( |
| 431 | static_cast<Context*>(context)->fNum); |
| 432 | delete static_cast<Context*>(context); |
| 433 | }; |
| 434 | |
| 435 | // Makes a texture, possibly adds a key, and sets the callback. |
| 436 | auto make = [&m, &keyAdder, &proc, &idleIDs](GrContext* context, int num) { |
| 437 | sk_sp<GrTexture> texture = m(context); |
| 438 | texture->setIdleProc(proc, new Context{&idleIDs, num}); |
| 439 | keyAdder(texture.get()); |
| 440 | return texture; |
| 441 | }; |
| 442 | |
| 443 | auto texture = make(context, 1); |
| 444 | REPORTER_ASSERT(reporter, idleIDs.find(1) == idleIDs.end()); |
| 445 | bool isRT = SkToBool(texture->asRenderTarget()); |
| 446 | auto backendFormat = texture->backendFormat(); |
| 447 | texture.reset(); |
| 448 | REPORTER_ASSERT(reporter, idleIDs.find(1) != idleIDs.end()); |
| 449 | |
| 450 | texture = make(context, 2); |
| 451 | SkImageInfo info = |
| 452 | SkImageInfo::Make(kS, kS, kRGBA_8888_SkColorType, kPremul_SkAlphaType); |
| 453 | auto rt = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info, 0, nullptr); |
| 454 | auto rtc = rt->getCanvas()->internal_private_accessTopLayerRenderTargetContext(); |
| 455 | auto singleUseLazyCB = [&texture](GrResourceProvider* rp) { |
Brian Salomon | 67f0195 | 2019-02-14 13:05:25 -0500 | [diff] [blame] | 456 | return std::move(texture); |
Brian Salomon | 614c1a8 | 2018-12-19 15:42:06 -0500 | [diff] [blame] | 457 | }; |
| 458 | GrSurfaceDesc desc; |
| 459 | desc.fWidth = desc.fHeight = kS; |
| 460 | desc.fConfig = kRGBA_8888_GrPixelConfig; |
| 461 | if (isRT) { |
| 462 | desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 463 | } |
Brian Salomon | fa2ebea | 2019-01-24 15:58:58 -0500 | [diff] [blame] | 464 | SkBudgeted budgeted; |
| 465 | if (texture->resourcePriv().budgetedType() == GrBudgetedType::kBudgeted) { |
| 466 | budgeted = SkBudgeted::kYes; |
| 467 | } else { |
| 468 | budgeted = SkBudgeted::kNo; |
| 469 | } |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 470 | auto proxy = context->priv().proxyProvider()->createLazyProxy( |
Brian Salomon | 614c1a8 | 2018-12-19 15:42:06 -0500 | [diff] [blame] | 471 | singleUseLazyCB, backendFormat, desc, |
| 472 | GrSurfaceOrigin::kTopLeft_GrSurfaceOrigin, GrMipMapped::kNo, |
| 473 | GrInternalSurfaceFlags ::kNone, SkBackingFit::kExact, budgeted, |
| 474 | GrSurfaceProxy::LazyInstantiationType::kSingleUse); |
Michael Ludwig | d54ca8f | 2019-02-13 13:25:21 -0500 | [diff] [blame] | 475 | rtc->drawTexture(GrNoClip(), proxy, GrSamplerState::Filter::kNearest, |
| 476 | SkBlendMode::kSrcOver, SkPMColor4f(), SkRect::MakeWH(kS, kS), |
Michael Ludwig | 136f45a | 2019-02-19 11:44:41 -0500 | [diff] [blame] | 477 | SkRect::MakeWH(kS, kS), GrAA::kNo, GrQuadAAFlags::kNone, |
Michael Ludwig | d54ca8f | 2019-02-13 13:25:21 -0500 | [diff] [blame] | 478 | SkCanvas::kFast_SrcRectConstraint, SkMatrix::I(), nullptr); |
Brian Salomon | 614c1a8 | 2018-12-19 15:42:06 -0500 | [diff] [blame] | 479 | // We still have the proxy, which should remain instantiated, thereby keeping the |
| 480 | // texture not purgeable. |
| 481 | REPORTER_ASSERT(reporter, idleIDs.find(2) == idleIDs.end()); |
| 482 | context->flush(); |
| 483 | REPORTER_ASSERT(reporter, idleIDs.find(2) == idleIDs.end()); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 484 | context->priv().getGpu()->testingOnly_flushGpuAndSync(); |
Brian Salomon | 614c1a8 | 2018-12-19 15:42:06 -0500 | [diff] [blame] | 485 | REPORTER_ASSERT(reporter, idleIDs.find(2) == idleIDs.end()); |
| 486 | |
| 487 | // This time we move the proxy into the draw. |
| 488 | rtc->drawTexture(GrNoClip(), std::move(proxy), GrSamplerState::Filter::kNearest, |
Michael Ludwig | d54ca8f | 2019-02-13 13:25:21 -0500 | [diff] [blame] | 489 | SkBlendMode::kSrcOver, SkPMColor4f(), SkRect::MakeWH(kS, kS), |
Michael Ludwig | 136f45a | 2019-02-19 11:44:41 -0500 | [diff] [blame] | 490 | SkRect::MakeWH(kS, kS), GrAA::kNo, GrQuadAAFlags::kNone, |
Michael Ludwig | d54ca8f | 2019-02-13 13:25:21 -0500 | [diff] [blame] | 491 | SkCanvas::kFast_SrcRectConstraint, SkMatrix::I(), nullptr); |
Brian Salomon | 614c1a8 | 2018-12-19 15:42:06 -0500 | [diff] [blame] | 492 | REPORTER_ASSERT(reporter, idleIDs.find(2) == idleIDs.end()); |
| 493 | context->flush(); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 494 | context->priv().getGpu()->testingOnly_flushGpuAndSync(); |
Brian Salomon | 614c1a8 | 2018-12-19 15:42:06 -0500 | [diff] [blame] | 495 | // Now that the draw is fully consumed by the GPU, the texture should be idle. |
| 496 | REPORTER_ASSERT(reporter, idleIDs.find(2) != idleIDs.end()); |
| 497 | |
| 498 | // Make a proxy that should deinstantiate even if we keep a ref on it. |
| 499 | auto deinstantiateLazyCB = [&make, &context](GrResourceProvider* rp) { |
Brian Salomon | 67f0195 | 2019-02-14 13:05:25 -0500 | [diff] [blame] | 500 | return make(context, 3); |
Brian Salomon | 614c1a8 | 2018-12-19 15:42:06 -0500 | [diff] [blame] | 501 | }; |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 502 | proxy = context->priv().proxyProvider()->createLazyProxy( |
Brian Salomon | 614c1a8 | 2018-12-19 15:42:06 -0500 | [diff] [blame] | 503 | deinstantiateLazyCB, backendFormat, desc, |
| 504 | GrSurfaceOrigin::kTopLeft_GrSurfaceOrigin, GrMipMapped::kNo, |
| 505 | GrInternalSurfaceFlags ::kNone, SkBackingFit::kExact, budgeted, |
| 506 | GrSurfaceProxy::LazyInstantiationType::kDeinstantiate); |
| 507 | rtc->drawTexture(GrNoClip(), std::move(proxy), GrSamplerState::Filter::kNearest, |
Michael Ludwig | d54ca8f | 2019-02-13 13:25:21 -0500 | [diff] [blame] | 508 | SkBlendMode::kSrcOver, SkPMColor4f(), SkRect::MakeWH(kS, kS), |
Michael Ludwig | 136f45a | 2019-02-19 11:44:41 -0500 | [diff] [blame] | 509 | SkRect::MakeWH(kS, kS), GrAA::kNo, GrQuadAAFlags::kNone, |
Michael Ludwig | d54ca8f | 2019-02-13 13:25:21 -0500 | [diff] [blame] | 510 | SkCanvas::kFast_SrcRectConstraint, SkMatrix::I(), nullptr); |
Brian Salomon | 614c1a8 | 2018-12-19 15:42:06 -0500 | [diff] [blame] | 511 | // At this point the proxy shouldn't even be instantiated, there is no texture with |
| 512 | // id 3. |
| 513 | REPORTER_ASSERT(reporter, idleIDs.find(3) == idleIDs.end()); |
| 514 | context->flush(); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 515 | context->priv().getGpu()->testingOnly_flushGpuAndSync(); |
Brian Salomon | 614c1a8 | 2018-12-19 15:42:06 -0500 | [diff] [blame] | 516 | // Now that the draw is fully consumed, we should have deinstantiated the proxy and |
| 517 | // the texture it made should be idle. |
| 518 | REPORTER_ASSERT(reporter, idleIDs.find(3) != idleIDs.end()); |
| 519 | |
Brian Salomon | 9bc76d9 | 2019-01-24 12:18:33 -0500 | [diff] [blame] | 520 | // Make sure we make the call during various shutdown scenarios where the texture |
| 521 | // might persist after context is destroyed, abandoned, etc. We test three |
| 522 | // variations of each scenario. One where the texture is just created. Another, |
| 523 | // where the texture has been used in a draw and then the context is flushed. And |
| 524 | // one where the the texture was drawn but the context is not flushed. |
| 525 | // In each scenario we test holding a ref beyond the context shutdown and not. |
Brian Salomon | 614c1a8 | 2018-12-19 15:42:06 -0500 | [diff] [blame] | 526 | |
Brian Salomon | 9bc76d9 | 2019-01-24 12:18:33 -0500 | [diff] [blame] | 527 | // These tests are difficult to get working with Vulkan. See http://skbug.com/8705 |
| 528 | // and http://skbug.com/8275 |
| 529 | GrBackendApi api = sk_gpu_test::GrContextFactory::ContextTypeBackend(contextType); |
| 530 | if (api == GrBackendApi::kVulkan) { |
| 531 | continue; |
| 532 | } |
| 533 | int id = 4; |
| 534 | enum class DrawType { |
| 535 | kNoDraw, |
| 536 | kDraw, |
| 537 | kDrawAndFlush, |
| 538 | }; |
| 539 | for (auto drawType : |
| 540 | {DrawType::kNoDraw, DrawType::kDraw, DrawType::kDrawAndFlush}) { |
| 541 | for (bool unrefFirst : {false, true}) { |
| 542 | auto possiblyDrawAndFlush = [&context, &texture, drawType, unrefFirst] { |
| 543 | if (drawType == DrawType::kNoDraw) { |
| 544 | return; |
| 545 | } |
| 546 | SkImageInfo info = SkImageInfo::Make(kS, kS, kRGBA_8888_SkColorType, |
| 547 | kPremul_SkAlphaType); |
| 548 | auto rt = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info, 0, |
| 549 | nullptr); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 550 | auto rtc = rt->getCanvas() |
Brian Salomon | 9bc76d9 | 2019-01-24 12:18:33 -0500 | [diff] [blame] | 551 | ->internal_private_accessTopLayerRenderTargetContext(); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 552 | auto proxy = context->priv().proxyProvider()->testingOnly_createWrapped( |
Brian Salomon | 9bc76d9 | 2019-01-24 12:18:33 -0500 | [diff] [blame] | 553 | texture, kTopLeft_GrSurfaceOrigin); |
| 554 | rtc->drawTexture(GrNoClip(), proxy, GrSamplerState::Filter::kNearest, |
Michael Ludwig | d54ca8f | 2019-02-13 13:25:21 -0500 | [diff] [blame] | 555 | SkBlendMode::kSrcOver, SkPMColor4f(), |
| 556 | SkRect::MakeWH(kS, kS), SkRect::MakeWH(kS, kS), |
Michael Ludwig | 136f45a | 2019-02-19 11:44:41 -0500 | [diff] [blame] | 557 | GrAA::kNo, GrQuadAAFlags::kNone, |
Brian Salomon | 9bc76d9 | 2019-01-24 12:18:33 -0500 | [diff] [blame] | 558 | SkCanvas::kFast_SrcRectConstraint, SkMatrix::I(), |
| 559 | nullptr); |
| 560 | if (drawType == DrawType::kDrawAndFlush) { |
| 561 | context->flush(); |
| 562 | } |
| 563 | if (unrefFirst) { |
| 564 | texture.reset(); |
| 565 | } |
| 566 | }; |
| 567 | texture = make(context, id); |
| 568 | possiblyDrawAndFlush(); |
| 569 | context->abandonContext(); |
| 570 | texture.reset(); |
| 571 | REPORTER_ASSERT(reporter, idleIDs.find(id) != idleIDs.end()); |
| 572 | factory.destroyContexts(); |
| 573 | context = factory.get(contextType); |
| 574 | ++id; |
Brian Salomon | 614c1a8 | 2018-12-19 15:42:06 -0500 | [diff] [blame] | 575 | |
Brian Salomon | 9bc76d9 | 2019-01-24 12:18:33 -0500 | [diff] [blame] | 576 | // Similar to previous, but reset the texture after the context was |
| 577 | // abandoned and then destroyed. |
| 578 | texture = make(context, id); |
| 579 | possiblyDrawAndFlush(); |
| 580 | context->abandonContext(); |
| 581 | factory.destroyContexts(); |
| 582 | texture.reset(); |
| 583 | REPORTER_ASSERT(reporter, idleIDs.find(id) != idleIDs.end()); |
| 584 | context = factory.get(contextType); |
| 585 | id++; |
| 586 | |
| 587 | texture = make(context, id); |
| 588 | possiblyDrawAndFlush(); |
| 589 | factory.destroyContexts(); |
| 590 | texture.reset(); |
| 591 | REPORTER_ASSERT(reporter, idleIDs.find(id) != idleIDs.end()); |
| 592 | context = factory.get(contextType); |
| 593 | id++; |
| 594 | |
| 595 | texture = make(context, id); |
| 596 | possiblyDrawAndFlush(); |
| 597 | factory.releaseResourcesAndAbandonContexts(); |
| 598 | texture.reset(); |
| 599 | REPORTER_ASSERT(reporter, idleIDs.find(id) != idleIDs.end()); |
| 600 | context = factory.get(contextType); |
| 601 | id++; |
| 602 | } |
| 603 | } |
Brian Salomon | 614c1a8 | 2018-12-19 15:42:06 -0500 | [diff] [blame] | 604 | } |
| 605 | } |
| 606 | } |
| 607 | } |