Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "tests/Test.h" |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 11 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "include/gpu/GrBackendSurface.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 13 | #include "src/gpu/GrContextPriv.h" |
| 14 | #include "src/gpu/GrProxyProvider.h" |
| 15 | #include "src/gpu/GrResourceCache.h" |
| 16 | #include "src/gpu/GrResourceProvider.h" |
Greg Daniel | 456f9b5 | 2020-03-05 19:14:18 +0000 | [diff] [blame] | 17 | #include "src/gpu/GrTexture.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 18 | #include "src/gpu/GrTextureProxy.h" |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 19 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 20 | #include "include/core/SkImage.h" |
| 21 | #include "src/gpu/SkGr.h" |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 22 | |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 23 | int GrProxyProvider::numUniqueKeyProxies_TestOnly() const { |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 24 | return fUniquelyKeyedProxies.count(); |
| 25 | } |
| 26 | |
Brian Salomon | 4eb38b7 | 2019-08-05 12:58:39 -0400 | [diff] [blame] | 27 | static constexpr auto kColorType = GrColorType::kRGBA_8888; |
| 28 | static constexpr auto kSize = SkISize::Make(64, 64); |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 29 | |
| 30 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 31 | // Basic test |
| 32 | |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 33 | static sk_sp<GrTextureProxy> deferred_tex(skiatest::Reporter* reporter, GrContext* ctx, |
Robert Phillips | adbe132 | 2018-01-17 13:35:46 -0500 | [diff] [blame] | 34 | GrProxyProvider* proxyProvider, SkBackingFit fit) { |
Robert Phillips | 0a15cc6 | 2019-07-30 12:49:10 -0400 | [diff] [blame] | 35 | const GrCaps* caps = ctx->priv().caps(); |
| 36 | |
Brian Salomon | 4eb38b7 | 2019-08-05 12:58:39 -0400 | [diff] [blame] | 37 | GrBackendFormat format = caps->getDefaultBackendFormat(kColorType, GrRenderable::kNo); |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 38 | |
Greg Daniel | 3a36511 | 2020-02-14 10:47:18 -0500 | [diff] [blame] | 39 | sk_sp<GrTextureProxy> proxy = |
Brian Salomon | df1bd6d | 2020-03-26 20:37:01 -0400 | [diff] [blame] | 40 | proxyProvider->createProxy(format, kSize, GrRenderable::kNo, 1, GrMipMapped::kNo, fit, |
| 41 | SkBudgeted::kYes, GrProtected::kNo); |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 42 | // Only budgeted & wrapped external proxies get to carry uniqueKeys |
Greg Daniel | cd87140 | 2017-09-26 12:49:26 -0400 | [diff] [blame] | 43 | REPORTER_ASSERT(reporter, !proxy->getUniqueKey().isValid()); |
| 44 | return proxy; |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 45 | } |
| 46 | |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 47 | static sk_sp<GrTextureProxy> deferred_texRT(skiatest::Reporter* reporter, GrContext* ctx, |
Robert Phillips | adbe132 | 2018-01-17 13:35:46 -0500 | [diff] [blame] | 48 | GrProxyProvider* proxyProvider, SkBackingFit fit) { |
Robert Phillips | 0a15cc6 | 2019-07-30 12:49:10 -0400 | [diff] [blame] | 49 | const GrCaps* caps = ctx->priv().caps(); |
| 50 | |
Brian Salomon | 4eb38b7 | 2019-08-05 12:58:39 -0400 | [diff] [blame] | 51 | GrBackendFormat format = caps->getDefaultBackendFormat(kColorType, GrRenderable::kYes); |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 52 | |
Greg Daniel | 3a36511 | 2020-02-14 10:47:18 -0500 | [diff] [blame] | 53 | sk_sp<GrTextureProxy> proxy = |
Brian Salomon | df1bd6d | 2020-03-26 20:37:01 -0400 | [diff] [blame] | 54 | proxyProvider->createProxy(format, kSize, GrRenderable::kYes, 1, GrMipMapped::kNo, fit, |
| 55 | SkBudgeted::kYes, GrProtected::kNo); |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 56 | // Only budgeted & wrapped external proxies get to carry uniqueKeys |
Greg Daniel | cd87140 | 2017-09-26 12:49:26 -0400 | [diff] [blame] | 57 | REPORTER_ASSERT(reporter, !proxy->getUniqueKey().isValid()); |
| 58 | return proxy; |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 59 | } |
| 60 | |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 61 | static sk_sp<GrTextureProxy> wrapped(skiatest::Reporter* reporter, GrContext* ctx, |
Robert Phillips | adbe132 | 2018-01-17 13:35:46 -0500 | [diff] [blame] | 62 | GrProxyProvider* proxyProvider, SkBackingFit fit) { |
Chris Dalton | d004e0b | 2018-09-27 09:28:03 -0600 | [diff] [blame] | 63 | sk_sp<GrTextureProxy> proxy = proxyProvider->testingOnly_createInstantiatedProxy( |
Greg Daniel | 3a36511 | 2020-02-14 10:47:18 -0500 | [diff] [blame] | 64 | kSize, kColorType, GrRenderable::kNo, 1, fit, SkBudgeted::kYes, GrProtected::kNo); |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 65 | // Only budgeted & wrapped external proxies get to carry uniqueKeys |
Greg Daniel | cd87140 | 2017-09-26 12:49:26 -0400 | [diff] [blame] | 66 | REPORTER_ASSERT(reporter, !proxy->getUniqueKey().isValid()); |
| 67 | return proxy; |
| 68 | } |
| 69 | |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 70 | static sk_sp<GrTextureProxy> wrapped_with_key(skiatest::Reporter* reporter, GrContext* ctx, |
Robert Phillips | adbe132 | 2018-01-17 13:35:46 -0500 | [diff] [blame] | 71 | GrProxyProvider* proxyProvider, SkBackingFit fit) { |
Greg Daniel | cd87140 | 2017-09-26 12:49:26 -0400 | [diff] [blame] | 72 | static GrUniqueKey::Domain d = GrUniqueKey::GenerateDomain(); |
| 73 | static int kUniqueKeyData = 0; |
| 74 | |
| 75 | GrUniqueKey key; |
| 76 | |
| 77 | GrUniqueKey::Builder builder(&key, d, 1, nullptr); |
| 78 | builder[0] = kUniqueKeyData++; |
| 79 | builder.finish(); |
| 80 | |
Robert Phillips | adbe132 | 2018-01-17 13:35:46 -0500 | [diff] [blame] | 81 | // Only budgeted & wrapped external proxies get to carry uniqueKeys |
Chris Dalton | d004e0b | 2018-09-27 09:28:03 -0600 | [diff] [blame] | 82 | sk_sp<GrTextureProxy> proxy = proxyProvider->testingOnly_createInstantiatedProxy( |
Greg Daniel | 3a36511 | 2020-02-14 10:47:18 -0500 | [diff] [blame] | 83 | kSize, kColorType, GrRenderable::kNo, 1, fit, SkBudgeted::kYes, GrProtected::kNo); |
Robert Phillips | adbe132 | 2018-01-17 13:35:46 -0500 | [diff] [blame] | 84 | SkAssertResult(proxyProvider->assignUniqueKeyToProxy(key, proxy.get())); |
Greg Daniel | cd87140 | 2017-09-26 12:49:26 -0400 | [diff] [blame] | 85 | REPORTER_ASSERT(reporter, proxy->getUniqueKey().isValid()); |
| 86 | return proxy; |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | static sk_sp<GrTextureProxy> create_wrapped_backend(GrContext* context, SkBackingFit fit, |
| 90 | sk_sp<GrTexture>* backingSurface) { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 91 | GrProxyProvider* proxyProvider = context->priv().proxyProvider(); |
| 92 | GrResourceProvider* resourceProvider = context->priv().resourceProvider(); |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 93 | |
Brian Salomon | 4eb38b7 | 2019-08-05 12:58:39 -0400 | [diff] [blame] | 94 | GrBackendFormat format = |
| 95 | proxyProvider->caps()->getDefaultBackendFormat(kColorType, GrRenderable::kYes); |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 96 | |
Brian Salomon | a90382f | 2019-09-17 09:01:56 -0400 | [diff] [blame] | 97 | *backingSurface = |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 98 | resourceProvider->createTexture(kSize, format, GrRenderable::kNo, 1, GrMipMapped::kNo, |
Brian Salomon | a90382f | 2019-09-17 09:01:56 -0400 | [diff] [blame] | 99 | SkBudgeted::kNo, GrProtected::kNo); |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 100 | if (!(*backingSurface)) { |
| 101 | return nullptr; |
| 102 | } |
| 103 | |
Robert Phillips | b67821d | 2017-12-13 15:00:45 -0500 | [diff] [blame] | 104 | GrBackendTexture backendTex = (*backingSurface)->getBackendTexture(); |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 105 | |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 106 | return proxyProvider->wrapBackendTexture(backendTex, GrColorType::kRGBA_8888, |
Greg Daniel | 3a36511 | 2020-02-14 10:47:18 -0500 | [diff] [blame] | 107 | kBorrow_GrWrapOwnership, GrWrapCacheable::kYes, |
| 108 | kRead_GrIOType); |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | |
| 112 | // This tests the basic capabilities of the uniquely keyed texture proxies. Does assigning |
| 113 | // and looking them up work, etc. |
| 114 | static void basic_test(GrContext* context, |
| 115 | skiatest::Reporter* reporter, |
Greg Daniel | 303e83e | 2018-09-10 14:10:19 -0400 | [diff] [blame] | 116 | sk_sp<GrTextureProxy> proxy) { |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 117 | static int id = 1; |
| 118 | |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 119 | GrResourceProvider* resourceProvider = context->priv().resourceProvider(); |
| 120 | GrProxyProvider* proxyProvider = context->priv().proxyProvider(); |
| 121 | GrResourceCache* cache = context->priv().getResourceCache(); |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 122 | |
| 123 | int startCacheCount = cache->getResourceCount(); |
| 124 | |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 125 | GrUniqueKey key; |
Greg Daniel | cd87140 | 2017-09-26 12:49:26 -0400 | [diff] [blame] | 126 | if (proxy->getUniqueKey().isValid()) { |
| 127 | key = proxy->getUniqueKey(); |
| 128 | } else { |
| 129 | GrMakeKeyFromImageID(&key, id, SkIRect::MakeWH(64, 64)); |
| 130 | ++id; |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 131 | |
Greg Daniel | cd87140 | 2017-09-26 12:49:26 -0400 | [diff] [blame] | 132 | // Assigning the uniqueKey adds the proxy to the hash but doesn't force instantiation |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 133 | REPORTER_ASSERT(reporter, !proxyProvider->numUniqueKeyProxies_TestOnly()); |
Robert Phillips | adbe132 | 2018-01-17 13:35:46 -0500 | [diff] [blame] | 134 | SkAssertResult(proxyProvider->assignUniqueKeyToProxy(key, proxy.get())); |
Greg Daniel | cd87140 | 2017-09-26 12:49:26 -0400 | [diff] [blame] | 135 | } |
| 136 | |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 137 | REPORTER_ASSERT(reporter, 1 == proxyProvider->numUniqueKeyProxies_TestOnly()); |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 138 | REPORTER_ASSERT(reporter, startCacheCount == cache->getResourceCount()); |
| 139 | |
| 140 | // setUniqueKey had better stick |
| 141 | REPORTER_ASSERT(reporter, key == proxy->getUniqueKey()); |
| 142 | |
| 143 | // We just added it, surely we can find it |
Brian Salomon | df1bd6d | 2020-03-26 20:37:01 -0400 | [diff] [blame] | 144 | REPORTER_ASSERT(reporter, proxyProvider->findOrCreateProxyByUniqueKey(key)); |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 145 | REPORTER_ASSERT(reporter, 1 == proxyProvider->numUniqueKeyProxies_TestOnly()); |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 146 | |
Greg Daniel | 303e83e | 2018-09-10 14:10:19 -0400 | [diff] [blame] | 147 | int expectedCacheCount = startCacheCount + (proxy->isInstantiated() ? 0 : 1); |
| 148 | |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 149 | // Once instantiated, the backing resource should have the same key |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 150 | SkAssertResult(proxy->instantiate(resourceProvider)); |
Brian Salomon | 9bc76d9 | 2019-01-24 12:18:33 -0500 | [diff] [blame] | 151 | const GrUniqueKey texKey = proxy->peekSurface()->getUniqueKey(); |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 152 | REPORTER_ASSERT(reporter, texKey.isValid()); |
| 153 | REPORTER_ASSERT(reporter, key == texKey); |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 154 | |
Brian Salomon | 9bc76d9 | 2019-01-24 12:18:33 -0500 | [diff] [blame] | 155 | // An Unbudgeted-cacheable resource will not get purged when a proxy with the same key is |
| 156 | // deleted. |
| 157 | bool expectResourceToOutliveProxy = proxy->peekSurface()->resourcePriv().budgetedType() == |
| 158 | GrBudgetedType::kUnbudgetedCacheable; |
| 159 | |
| 160 | // An Unbudgeted-uncacheable resource is never kept alive if it's ref cnt reaches zero even if |
| 161 | // it has a key. |
| 162 | bool expectDeletingProxyToDeleteResource = |
| 163 | proxy->peekSurface()->resourcePriv().budgetedType() == |
| 164 | GrBudgetedType::kUnbudgetedUncacheable; |
| 165 | |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 166 | // deleting the proxy should delete it from the hash but not the cache |
| 167 | proxy = nullptr; |
Brian Salomon | 9bc76d9 | 2019-01-24 12:18:33 -0500 | [diff] [blame] | 168 | if (expectDeletingProxyToDeleteResource) { |
| 169 | expectedCacheCount -= 1; |
| 170 | } |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 171 | REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly()); |
Greg Daniel | 303e83e | 2018-09-10 14:10:19 -0400 | [diff] [blame] | 172 | REPORTER_ASSERT(reporter, expectedCacheCount == cache->getResourceCount()); |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 173 | |
| 174 | // If the proxy was cached refinding it should bring it back to life |
Brian Salomon | df1bd6d | 2020-03-26 20:37:01 -0400 | [diff] [blame] | 175 | proxy = proxyProvider->findOrCreateProxyByUniqueKey(key); |
Greg Daniel | 303e83e | 2018-09-10 14:10:19 -0400 | [diff] [blame] | 176 | REPORTER_ASSERT(reporter, proxy); |
| 177 | REPORTER_ASSERT(reporter, 1 == proxyProvider->numUniqueKeyProxies_TestOnly()); |
| 178 | REPORTER_ASSERT(reporter, expectedCacheCount == cache->getResourceCount()); |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 179 | |
| 180 | // Mega-purging it should remove it from both the hash and the cache |
| 181 | proxy = nullptr; |
| 182 | cache->purgeAllUnlocked(); |
Brian Salomon | 9bc76d9 | 2019-01-24 12:18:33 -0500 | [diff] [blame] | 183 | if (!expectResourceToOutliveProxy) { |
| 184 | expectedCacheCount--; |
| 185 | } |
Greg Daniel | 303e83e | 2018-09-10 14:10:19 -0400 | [diff] [blame] | 186 | REPORTER_ASSERT(reporter, expectedCacheCount == cache->getResourceCount()); |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 187 | |
Brian Salomon | 9bc76d9 | 2019-01-24 12:18:33 -0500 | [diff] [blame] | 188 | // If the texture was deleted then the proxy should no longer be findable. Otherwise, it should |
| 189 | // be. |
Brian Salomon | df1bd6d | 2020-03-26 20:37:01 -0400 | [diff] [blame] | 190 | proxy = proxyProvider->findOrCreateProxyByUniqueKey(key); |
Brian Salomon | 9bc76d9 | 2019-01-24 12:18:33 -0500 | [diff] [blame] | 191 | REPORTER_ASSERT(reporter, expectResourceToOutliveProxy ? (bool)proxy : !proxy); |
Greg Daniel | 303e83e | 2018-09-10 14:10:19 -0400 | [diff] [blame] | 192 | REPORTER_ASSERT(reporter, expectedCacheCount == cache->getResourceCount()); |
Brian Salomon | 9bc76d9 | 2019-01-24 12:18:33 -0500 | [diff] [blame] | 193 | |
| 194 | if (expectResourceToOutliveProxy) { |
| 195 | proxy.reset(); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 196 | GrUniqueKeyInvalidatedMessage msg(texKey, context->priv().contextID()); |
Brian Salomon | 9bc76d9 | 2019-01-24 12:18:33 -0500 | [diff] [blame] | 197 | SkMessageBus<GrUniqueKeyInvalidatedMessage>::Post(msg); |
| 198 | cache->purgeAsNeeded(); |
| 199 | expectedCacheCount--; |
Brian Salomon | df1bd6d | 2020-03-26 20:37:01 -0400 | [diff] [blame] | 200 | proxy = proxyProvider->findOrCreateProxyByUniqueKey(key); |
Brian Salomon | 9bc76d9 | 2019-01-24 12:18:33 -0500 | [diff] [blame] | 201 | REPORTER_ASSERT(reporter, !proxy); |
| 202 | REPORTER_ASSERT(reporter, expectedCacheCount == cache->getResourceCount()); |
| 203 | } |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 207 | // Invalidation test |
| 208 | |
| 209 | // Test if invalidating unique ids operates as expected for texture proxies. |
| 210 | static void invalidation_test(GrContext* context, skiatest::Reporter* reporter) { |
| 211 | |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 212 | GrProxyProvider* proxyProvider = context->priv().proxyProvider(); |
| 213 | GrResourceCache* cache = context->priv().getResourceCache(); |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 214 | REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
| 215 | |
| 216 | sk_sp<SkImage> rasterImg; |
| 217 | |
| 218 | { |
| 219 | SkImageInfo ii = SkImageInfo::Make(64, 64, kRGBA_8888_SkColorType, kOpaque_SkAlphaType); |
| 220 | |
| 221 | SkBitmap bm; |
| 222 | bm.allocPixels(ii); |
| 223 | |
| 224 | rasterImg = SkImage::MakeFromBitmap(bm); |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 225 | REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly()); |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 226 | REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
| 227 | } |
| 228 | |
Brian Osman | d566e2e | 2019-08-14 13:19:04 -0400 | [diff] [blame] | 229 | sk_sp<SkImage> textureImg = rasterImg->makeTextureImage(context); |
Brian Salomon | bc074a6 | 2020-03-18 10:06:13 -0400 | [diff] [blame] | 230 | REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly()); |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 231 | REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); |
| 232 | |
| 233 | rasterImg = nullptr; // this invalidates the uniqueKey |
| 234 | |
| 235 | // this forces the cache to respond to the inval msg |
Robert Phillips | cf39f37 | 2019-09-03 10:29:20 -0400 | [diff] [blame] | 236 | size_t maxBytes = context->getResourceCacheLimit(); |
| 237 | context->setResourceCacheLimit(maxBytes-1); |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 238 | |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 239 | REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly()); |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 240 | REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); |
| 241 | |
| 242 | textureImg = nullptr; |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 243 | context->priv().testingOnly_purgeAllUnlockedResources(); |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 244 | |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 245 | REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly()); |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 246 | REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
| 247 | } |
| 248 | |
Brian Osman | 28c434b | 2017-09-27 13:11:16 -0400 | [diff] [blame] | 249 | // Test if invalidating unique ids prior to instantiating operates as expected |
| 250 | static void invalidation_and_instantiation_test(GrContext* context, skiatest::Reporter* reporter) { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 251 | GrProxyProvider* proxyProvider = context->priv().proxyProvider(); |
| 252 | GrResourceProvider* resourceProvider = context->priv().resourceProvider(); |
| 253 | GrResourceCache* cache = context->priv().getResourceCache(); |
Brian Osman | 28c434b | 2017-09-27 13:11:16 -0400 | [diff] [blame] | 254 | REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
| 255 | |
| 256 | static GrUniqueKey::Domain d = GrUniqueKey::GenerateDomain(); |
| 257 | GrUniqueKey key; |
| 258 | GrUniqueKey::Builder builder(&key, d, 1, nullptr); |
| 259 | builder[0] = 0; |
| 260 | builder.finish(); |
| 261 | |
| 262 | // Create proxy, assign unique key |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 263 | sk_sp<GrTextureProxy> proxy = deferred_tex(reporter, context, proxyProvider, |
| 264 | SkBackingFit::kExact); |
Robert Phillips | adbe132 | 2018-01-17 13:35:46 -0500 | [diff] [blame] | 265 | SkAssertResult(proxyProvider->assignUniqueKeyToProxy(key, proxy.get())); |
Brian Osman | 28c434b | 2017-09-27 13:11:16 -0400 | [diff] [blame] | 266 | |
| 267 | // Send an invalidation message, which will be sitting in the cache's inbox |
Brian Salomon | 238069b | 2018-07-11 15:58:57 -0400 | [diff] [blame] | 268 | SkMessageBus<GrUniqueKeyInvalidatedMessage>::Post( |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 269 | GrUniqueKeyInvalidatedMessage(key, context->priv().contextID())); |
Brian Osman | 28c434b | 2017-09-27 13:11:16 -0400 | [diff] [blame] | 270 | |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 271 | REPORTER_ASSERT(reporter, 1 == proxyProvider->numUniqueKeyProxies_TestOnly()); |
Brian Osman | 28c434b | 2017-09-27 13:11:16 -0400 | [diff] [blame] | 272 | REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
| 273 | |
| 274 | // Instantiate the proxy. This will trigger the message to be processed, so the resulting |
| 275 | // texture should *not* have the unique key on it! |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 276 | SkAssertResult(proxy->instantiate(resourceProvider)); |
Brian Osman | 28c434b | 2017-09-27 13:11:16 -0400 | [diff] [blame] | 277 | |
| 278 | REPORTER_ASSERT(reporter, !proxy->getUniqueKey().isValid()); |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 279 | REPORTER_ASSERT(reporter, !proxy->peekTexture()->getUniqueKey().isValid()); |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 280 | REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly()); |
Brian Osman | 28c434b | 2017-09-27 13:11:16 -0400 | [diff] [blame] | 281 | REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); |
| 282 | |
| 283 | proxy = nullptr; |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 284 | context->priv().testingOnly_purgeAllUnlockedResources(); |
Brian Osman | 28c434b | 2017-09-27 13:11:16 -0400 | [diff] [blame] | 285 | |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 286 | REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly()); |
Brian Osman | 28c434b | 2017-09-27 13:11:16 -0400 | [diff] [blame] | 287 | REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
| 288 | } |
| 289 | |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 290 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(TextureProxyTest, reporter, ctxInfo) { |
| 291 | GrContext* context = ctxInfo.grContext(); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 292 | GrProxyProvider* proxyProvider = context->priv().proxyProvider(); |
| 293 | GrResourceCache* cache = context->priv().getResourceCache(); |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 294 | |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 295 | REPORTER_ASSERT(reporter, !proxyProvider->numUniqueKeyProxies_TestOnly()); |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 296 | REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
| 297 | |
| 298 | for (auto fit : { SkBackingFit::kExact, SkBackingFit::kApprox }) { |
Greg Daniel | cd87140 | 2017-09-26 12:49:26 -0400 | [diff] [blame] | 299 | for (auto create : { deferred_tex, deferred_texRT, wrapped, wrapped_with_key }) { |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 300 | REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 301 | basic_test(context, reporter, create(reporter, context, proxyProvider, fit)); |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
| 305 | sk_sp<GrTexture> backingTex; |
| 306 | sk_sp<GrTextureProxy> proxy = create_wrapped_backend(context, fit, &backingTex); |
Greg Daniel | 303e83e | 2018-09-10 14:10:19 -0400 | [diff] [blame] | 307 | basic_test(context, reporter, std::move(proxy)); |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 308 | |
| 309 | backingTex = nullptr; |
| 310 | cache->purgeAllUnlocked(); |
| 311 | } |
| 312 | |
| 313 | invalidation_test(context, reporter); |
Robert Phillips | fa8c080 | 2017-10-04 08:42:28 -0400 | [diff] [blame] | 314 | invalidation_and_instantiation_test(context, reporter); |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 315 | } |