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