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