commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +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 | |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 8 | #if SK_SUPPORT_GPU |
tfarina@chromium.org | 4ee16bf | 2014-01-10 22:08:27 +0000 | [diff] [blame] | 9 | |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 10 | #include "GrContext.h" |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 11 | #include "GrContextFactory.h" |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 12 | #include "GrGpu.h" |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 13 | #include "GrResourceCache2.h" |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 14 | #include "SkCanvas.h" |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 15 | #include "SkGr.h" |
| 16 | #include "SkMessageBus.h" |
reed | 69f6f00 | 2014-09-18 06:09:44 -0700 | [diff] [blame] | 17 | #include "SkSurface.h" |
tfarina@chromium.org | 4ee16bf | 2014-01-10 22:08:27 +0000 | [diff] [blame] | 18 | #include "Test.h" |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 19 | |
| 20 | static const int gWidth = 640; |
| 21 | static const int gHeight = 480; |
| 22 | |
| 23 | //////////////////////////////////////////////////////////////////////////////// |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 24 | static void test_cache(skiatest::Reporter* reporter, GrContext* context, SkCanvas* canvas) { |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 25 | const SkIRect size = SkIRect::MakeWH(gWidth, gHeight); |
| 26 | |
| 27 | SkBitmap src; |
mike@reedtribe.org | deee496 | 2014-02-13 14:41:43 +0000 | [diff] [blame] | 28 | src.allocN32Pixels(size.width(), size.height()); |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 29 | src.eraseColor(SK_ColorBLACK); |
| 30 | size_t srcSize = src.getSize(); |
| 31 | |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 32 | size_t initialCacheSize; |
| 33 | context->getResourceCacheUsage(NULL, &initialCacheSize); |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 34 | |
| 35 | int oldMaxNum; |
| 36 | size_t oldMaxBytes; |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 37 | context->getResourceCacheLimits(&oldMaxNum, &oldMaxBytes); |
skia.committer@gmail.com | 17f1ae6 | 2013-08-09 07:01:22 +0000 | [diff] [blame] | 38 | |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 39 | // Set the cache limits so we can fit 10 "src" images and the |
| 40 | // max number of textures doesn't matter |
| 41 | size_t maxCacheSize = initialCacheSize + 10*srcSize; |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 42 | context->setResourceCacheLimits(1000, maxCacheSize); |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 43 | |
| 44 | SkBitmap readback; |
mike@reedtribe.org | deee496 | 2014-02-13 14:41:43 +0000 | [diff] [blame] | 45 | readback.allocN32Pixels(size.width(), size.height()); |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 46 | |
| 47 | for (int i = 0; i < 100; ++i) { |
| 48 | canvas->drawBitmap(src, 0, 0); |
| 49 | canvas->readPixels(size, &readback); |
| 50 | |
| 51 | // "modify" the src texture |
| 52 | src.notifyPixelsChanged(); |
| 53 | |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 54 | size_t curCacheSize; |
| 55 | context->getResourceCacheUsage(NULL, &curCacheSize); |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 56 | |
| 57 | // we should never go over the size limit |
| 58 | REPORTER_ASSERT(reporter, curCacheSize <= maxCacheSize); |
| 59 | } |
| 60 | |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 61 | context->setResourceCacheLimits(oldMaxNum, oldMaxBytes); |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 62 | } |
| 63 | |
bsalomon | 6d3fe02 | 2014-07-25 08:35:45 -0700 | [diff] [blame] | 64 | class TestResource : public GrGpuResource { |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 65 | static const size_t kDefaultSize = 100; |
| 66 | |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 67 | public: |
| 68 | SK_DECLARE_INST_COUNT(TestResource); |
bsalomon | dace19e | 2014-11-17 07:34:06 -0800 | [diff] [blame^] | 69 | TestResource(GrGpu* gpu, bool isWrapped) |
| 70 | : INHERITED(gpu, isWrapped) |
| 71 | , fToDelete(NULL) |
| 72 | , fSize(kDefaultSize) { |
| 73 | ++fNumAlive; |
| 74 | this->registerWithCache(); |
| 75 | } |
| 76 | |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 77 | TestResource(GrGpu* gpu) |
bsalomon | c44be0e | 2014-07-25 07:32:33 -0700 | [diff] [blame] | 78 | : INHERITED(gpu, false) |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 79 | , fToDelete(NULL) |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 80 | , fSize(kDefaultSize) { |
| 81 | ++fNumAlive; |
| 82 | this->registerWithCache(); |
| 83 | } |
| 84 | |
| 85 | TestResource(GrGpu* gpu, const GrResourceKey& scratchKey) |
| 86 | : INHERITED(gpu, false) |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 87 | , fToDelete(NULL) |
| 88 | , fSize(kDefaultSize) { |
| 89 | this->setScratchKey(scratchKey); |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 90 | ++fNumAlive; |
bsalomon | 1696126 | 2014-08-26 14:01:07 -0700 | [diff] [blame] | 91 | this->registerWithCache(); |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | ~TestResource() { |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 95 | --fNumAlive; |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 96 | SkSafeUnref(fToDelete); |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 97 | } |
| 98 | |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 99 | void setSize(size_t size) { |
| 100 | fSize = size; |
| 101 | this->didChangeGpuMemorySize(); |
| 102 | } |
| 103 | |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 104 | static int NumAlive() { return fNumAlive; } |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 105 | |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 106 | void setUnrefWhenDestroyed(TestResource* resource) { |
| 107 | SkRefCnt_SafeAssign(fToDelete, resource); |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | private: |
bsalomon | 69ed47f | 2014-11-12 11:13:39 -0800 | [diff] [blame] | 111 | size_t onGpuMemorySize() const SK_OVERRIDE { return fSize; } |
| 112 | |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 113 | TestResource* fToDelete; |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 114 | size_t fSize; |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 115 | static int fNumAlive; |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 116 | |
bsalomon | 6d3fe02 | 2014-07-25 08:35:45 -0700 | [diff] [blame] | 117 | typedef GrGpuResource INHERITED; |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 118 | }; |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 119 | int TestResource::fNumAlive = 0; |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 120 | |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 121 | static void test_no_key(skiatest::Reporter* reporter) { |
| 122 | SkAutoTUnref<GrContext> context(GrContext::CreateMockContext()); |
| 123 | REPORTER_ASSERT(reporter, SkToBool(context)); |
| 124 | if (NULL == context) { |
| 125 | return; |
| 126 | } |
| 127 | context->setResourceCacheLimits(10, 30000); |
| 128 | GrResourceCache2* cache2 = context->getResourceCache2(); |
| 129 | cache2->purgeAllUnlocked(); |
| 130 | SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes()); |
| 131 | |
| 132 | // Create a bunch of resources with no keys |
| 133 | TestResource* a = new TestResource(context->getGpu()); |
| 134 | TestResource* b = new TestResource(context->getGpu()); |
| 135 | TestResource* c = new TestResource(context->getGpu()); |
| 136 | TestResource* d = new TestResource(context->getGpu()); |
| 137 | a->setSize(11); |
| 138 | b->setSize(12); |
| 139 | c->setSize(13); |
| 140 | d->setSize(14); |
| 141 | |
| 142 | REPORTER_ASSERT(reporter, 4 == TestResource::NumAlive()); |
| 143 | REPORTER_ASSERT(reporter, 4 == cache2->getResourceCount()); |
| 144 | REPORTER_ASSERT(reporter, a->gpuMemorySize() + b->gpuMemorySize() + c->gpuMemorySize() + |
| 145 | d->gpuMemorySize() == cache2->getResourceBytes()); |
| 146 | |
| 147 | // Should be safe to purge without deleting the resources since we still have refs. |
| 148 | cache2->purgeAllUnlocked(); |
| 149 | REPORTER_ASSERT(reporter, 4 == TestResource::NumAlive()); |
| 150 | |
| 151 | // Since the resources have neither content nor scratch keys, delete immediately upon unref. |
| 152 | |
| 153 | a->unref(); |
| 154 | REPORTER_ASSERT(reporter, 3 == TestResource::NumAlive()); |
| 155 | REPORTER_ASSERT(reporter, 3 == cache2->getResourceCount()); |
| 156 | REPORTER_ASSERT(reporter, b->gpuMemorySize() + c->gpuMemorySize() + d->gpuMemorySize() == |
| 157 | cache2->getResourceBytes()); |
| 158 | |
| 159 | c->unref(); |
| 160 | REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); |
| 161 | REPORTER_ASSERT(reporter, 2 == cache2->getResourceCount()); |
| 162 | REPORTER_ASSERT(reporter, b->gpuMemorySize() + d->gpuMemorySize() == |
| 163 | cache2->getResourceBytes()); |
| 164 | |
| 165 | d->unref(); |
| 166 | REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive()); |
| 167 | REPORTER_ASSERT(reporter, 1 == cache2->getResourceCount()); |
| 168 | REPORTER_ASSERT(reporter, b->gpuMemorySize() == cache2->getResourceBytes()); |
| 169 | |
| 170 | b->unref(); |
| 171 | REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive()); |
| 172 | REPORTER_ASSERT(reporter, 0 == cache2->getResourceCount()); |
| 173 | REPORTER_ASSERT(reporter, 0 == cache2->getResourceBytes()); |
| 174 | } |
| 175 | |
bsalomon | dace19e | 2014-11-17 07:34:06 -0800 | [diff] [blame^] | 176 | static void test_wrapped(skiatest::Reporter* reporter) { |
| 177 | SkAutoTUnref<GrContext> context(GrContext::CreateMockContext()); |
| 178 | REPORTER_ASSERT(reporter, SkToBool(context)); |
| 179 | if (NULL == context) { |
| 180 | return; |
| 181 | } |
| 182 | context->setResourceCacheLimits(10, 300); |
| 183 | GrResourceCache2* cache2 = context->getResourceCache2(); |
| 184 | cache2->purgeAllUnlocked(); |
| 185 | SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes()); |
| 186 | SkASSERT(0 == cache2->getBudgetedResourceCount() && 0 == cache2->getBudgetedResourceBytes()); |
| 187 | |
| 188 | GrCacheID::Key keyData; |
| 189 | memset(&keyData, 0, sizeof(keyData)); |
| 190 | GrResourceKey::ResourceType t = GrResourceKey::GenerateResourceType(); |
| 191 | GrResourceKey scratchKey(GrCacheID(GrResourceKey::ScratchDomain(), keyData), t, 0); |
| 192 | GrResourceKey contentKey(GrCacheID(GrCacheID::GenerateDomain(), keyData), t, 0); |
| 193 | |
| 194 | // Create a scratch, a content, and a wrapped resource |
| 195 | TestResource* scratch = new TestResource(context->getGpu(), scratchKey); |
| 196 | scratch->setSize(10); |
| 197 | TestResource* content = new TestResource(context->getGpu()); |
| 198 | scratch->setSize(11); |
| 199 | REPORTER_ASSERT(reporter, content->cacheAccess().setContentKey(contentKey)); |
| 200 | TestResource* wrapped = new TestResource(context->getGpu(), true); |
| 201 | scratch->setSize(12); |
| 202 | |
| 203 | // Make sure we can't add a content key to the wrapped resource |
| 204 | keyData.fData8[0] = 1; |
| 205 | GrResourceKey contentKey2(GrCacheID(GrCacheID::GenerateDomain(), keyData), t, 0); |
| 206 | REPORTER_ASSERT(reporter, !wrapped->cacheAccess().setContentKey(contentKey2)); |
| 207 | REPORTER_ASSERT(reporter, NULL == cache2->findAndRefContentResource(contentKey2)); |
| 208 | |
| 209 | // Make sure sizes are as we expect |
| 210 | REPORTER_ASSERT(reporter, 3 == cache2->getResourceCount()); |
| 211 | REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + content->gpuMemorySize() + |
| 212 | wrapped->gpuMemorySize() == cache2->getResourceBytes()); |
| 213 | REPORTER_ASSERT(reporter, 2 == cache2->getBudgetedResourceCount()); |
| 214 | REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + content->gpuMemorySize() == |
| 215 | cache2->getBudgetedResourceBytes()); |
| 216 | |
| 217 | // Our refs mean that the resources are non purgable. |
| 218 | cache2->purgeAllUnlocked(); |
| 219 | REPORTER_ASSERT(reporter, 3 == cache2->getResourceCount()); |
| 220 | REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + content->gpuMemorySize() + |
| 221 | wrapped->gpuMemorySize() == cache2->getResourceBytes()); |
| 222 | REPORTER_ASSERT(reporter, 2 == cache2->getBudgetedResourceCount()); |
| 223 | REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + content->gpuMemorySize() == |
| 224 | cache2->getBudgetedResourceBytes()); |
| 225 | |
| 226 | // Unreffing the wrapped resource should free it right away. |
| 227 | wrapped->unref(); |
| 228 | REPORTER_ASSERT(reporter, 2 == cache2->getResourceCount()); |
| 229 | REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + content->gpuMemorySize() == |
| 230 | cache2->getResourceBytes()); |
| 231 | |
| 232 | // Now try freeing the other two resources first |
| 233 | wrapped = new TestResource(context->getGpu(), true); |
| 234 | scratch->setSize(12); |
| 235 | content->unref(); |
| 236 | cache2->purgeAllUnlocked(); |
| 237 | REPORTER_ASSERT(reporter, 2 == cache2->getResourceCount()); |
| 238 | REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + wrapped->gpuMemorySize() == |
| 239 | cache2->getResourceBytes()); |
| 240 | REPORTER_ASSERT(reporter, 1 == cache2->getBudgetedResourceCount()); |
| 241 | REPORTER_ASSERT(reporter, scratch->gpuMemorySize() == cache2->getBudgetedResourceBytes()); |
| 242 | |
| 243 | scratch->unref(); |
| 244 | cache2->purgeAllUnlocked(); |
| 245 | REPORTER_ASSERT(reporter, 1 == cache2->getResourceCount()); |
| 246 | REPORTER_ASSERT(reporter, wrapped->gpuMemorySize() == cache2->getResourceBytes()); |
| 247 | REPORTER_ASSERT(reporter, 0 == cache2->getBudgetedResourceCount()); |
| 248 | REPORTER_ASSERT(reporter, 0 == cache2->getBudgetedResourceBytes()); |
| 249 | |
| 250 | wrapped->unref(); |
| 251 | REPORTER_ASSERT(reporter, 0 == cache2->getResourceCount()); |
| 252 | REPORTER_ASSERT(reporter, 0 == cache2->getResourceBytes()); |
| 253 | } |
| 254 | |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 255 | static void test_duplicate_scratch_key(skiatest::Reporter* reporter) { |
| 256 | SkAutoTUnref<GrContext> context(GrContext::CreateMockContext()); |
| 257 | REPORTER_ASSERT(reporter, SkToBool(context)); |
| 258 | if (NULL == context) { |
| 259 | return; |
| 260 | } |
| 261 | context->setResourceCacheLimits(5, 30000); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 262 | GrResourceCache2* cache2 = context->getResourceCache2(); |
| 263 | cache2->purgeAllUnlocked(); |
| 264 | SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes()); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 265 | |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 266 | GrCacheID::Key keyData; |
bsalomon | 48ea202 | 2014-11-12 10:28:17 -0800 | [diff] [blame] | 267 | memset(&keyData, 0, sizeof(keyData)); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 268 | GrCacheID::Domain domain = GrResourceKey::ScratchDomain(); |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 269 | GrResourceKey::ResourceType t = GrResourceKey::GenerateResourceType(); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 270 | GrResourceKey scratchKey(GrCacheID(domain, keyData), t, 0); |
| 271 | |
| 272 | // Create two resources that have the same scratch key. |
| 273 | TestResource* a = new TestResource(context->getGpu(), scratchKey); |
| 274 | TestResource* b = new TestResource(context->getGpu(), scratchKey); |
| 275 | a->setSize(11); |
| 276 | b->setSize(12); |
| 277 | // Scratch resources are registered with GrResourceCache2 just by existing. There are 2. |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 278 | REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); |
| 279 | SkDEBUGCODE(REPORTER_ASSERT(reporter, 2 == cache2->countScratchEntriesForKey(scratchKey));) |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 280 | REPORTER_ASSERT(reporter, 2 == cache2->getResourceCount()); |
| 281 | REPORTER_ASSERT(reporter, a->gpuMemorySize() + b->gpuMemorySize() == |
| 282 | cache2->getResourceBytes()); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 283 | |
| 284 | // Our refs mean that the resources are non purgable. |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 285 | cache2->purgeAllUnlocked(); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 286 | REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 287 | REPORTER_ASSERT(reporter, 2 == cache2->getResourceCount()); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 288 | |
| 289 | // Unref but don't purge |
| 290 | a->unref(); |
| 291 | b->unref(); |
| 292 | REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); |
| 293 | SkDEBUGCODE(REPORTER_ASSERT(reporter, 2 == cache2->countScratchEntriesForKey(scratchKey));) |
| 294 | |
| 295 | // Purge again. This time resources should be purgable. |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 296 | cache2->purgeAllUnlocked(); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 297 | REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive()); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 298 | REPORTER_ASSERT(reporter, 0 == cache2->getResourceCount()); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 299 | SkDEBUGCODE(REPORTER_ASSERT(reporter, 0 == cache2->countScratchEntriesForKey(scratchKey));) |
| 300 | } |
| 301 | |
| 302 | static void test_duplicate_content_key(skiatest::Reporter* reporter) { |
| 303 | SkAutoTUnref<GrContext> context(GrContext::CreateMockContext()); |
| 304 | REPORTER_ASSERT(reporter, SkToBool(context)); |
| 305 | if (NULL == context) { |
| 306 | return; |
| 307 | } |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 308 | context->setResourceCacheLimits(5, 30000); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 309 | GrResourceCache2* cache2 = context->getResourceCache2(); |
| 310 | cache2->purgeAllUnlocked(); |
| 311 | SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes()); |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 312 | |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 313 | GrCacheID::Domain domain = GrCacheID::GenerateDomain(); |
| 314 | GrCacheID::Key keyData; |
| 315 | memset(&keyData, 0, sizeof(keyData)); |
| 316 | GrResourceKey::ResourceType t = GrResourceKey::GenerateResourceType(); |
| 317 | GrResourceKey key(GrCacheID(domain, keyData), t, 0); |
| 318 | |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 319 | // Create two resources that we will attempt to register with the same content key. |
bsalomon | c44be0e | 2014-07-25 07:32:33 -0700 | [diff] [blame] | 320 | TestResource* a = new TestResource(context->getGpu()); |
| 321 | TestResource* b = new TestResource(context->getGpu()); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 322 | a->setSize(11); |
| 323 | b->setSize(12); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 324 | |
| 325 | // Can't set the same content key on two resources. |
| 326 | REPORTER_ASSERT(reporter, a->cacheAccess().setContentKey(key)); |
| 327 | REPORTER_ASSERT(reporter, !b->cacheAccess().setContentKey(key)); |
| 328 | |
| 329 | // Still have two resources because b is still reffed. |
| 330 | REPORTER_ASSERT(reporter, 2 == cache2->getResourceCount()); |
| 331 | REPORTER_ASSERT(reporter, a->gpuMemorySize() + b->gpuMemorySize() == |
| 332 | cache2->getResourceBytes()); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 333 | REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); |
| 334 | |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 335 | b->unref(); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 336 | // Now b should be gone. |
| 337 | REPORTER_ASSERT(reporter, 1 == cache2->getResourceCount()); |
| 338 | REPORTER_ASSERT(reporter, a->gpuMemorySize() == cache2->getResourceBytes()); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 339 | REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive()); |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 340 | |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 341 | cache2->purgeAllUnlocked(); |
| 342 | REPORTER_ASSERT(reporter, 1 == cache2->getResourceCount()); |
| 343 | REPORTER_ASSERT(reporter, a->gpuMemorySize() == cache2->getResourceBytes()); |
| 344 | REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive()); |
| 345 | |
| 346 | // Drop the ref on a but it isn't immediately purged as it still has a valid scratch key. |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 347 | a->unref(); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 348 | REPORTER_ASSERT(reporter, 1 == cache2->getResourceCount()); |
| 349 | REPORTER_ASSERT(reporter, a->gpuMemorySize() == cache2->getResourceBytes()); |
| 350 | REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive()); |
| 351 | |
| 352 | cache2->purgeAllUnlocked(); |
| 353 | REPORTER_ASSERT(reporter, 0 == cache2->getResourceCount()); |
| 354 | REPORTER_ASSERT(reporter, 0 == cache2->getResourceBytes()); |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 355 | REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive()); |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 356 | } |
| 357 | |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 358 | static void test_purge_invalidated(skiatest::Reporter* reporter) { |
| 359 | SkAutoTUnref<GrContext> context(GrContext::CreateMockContext()); |
| 360 | REPORTER_ASSERT(reporter, SkToBool(context)); |
| 361 | if (NULL == context) { |
| 362 | return; |
| 363 | } |
| 364 | |
commit-bot@chromium.org | bd58feb | 2014-01-17 17:56:21 +0000 | [diff] [blame] | 365 | GrCacheID::Domain domain = GrCacheID::GenerateDomain(); |
| 366 | GrCacheID::Key keyData; |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 367 | memset(&keyData, 0, sizeof(keyData)); |
| 368 | |
commit-bot@chromium.org | bd58feb | 2014-01-17 17:56:21 +0000 | [diff] [blame] | 369 | GrResourceKey::ResourceType t = GrResourceKey::GenerateResourceType(); |
| 370 | |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 371 | keyData.fData64[0] = 1; |
| 372 | GrResourceKey key1(GrCacheID(domain, keyData), t, 0); |
| 373 | keyData.fData64[0] = 2; |
| 374 | GrResourceKey key2(GrCacheID(domain, keyData), t, 0); |
| 375 | keyData.fData64[0] = 3; |
| 376 | GrResourceKey key3(GrCacheID(domain, keyData), t, 0); |
| 377 | |
| 378 | context->setResourceCacheLimits(5, 30000); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 379 | GrResourceCache2* cache2 = context->getResourceCache2(); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 380 | cache2->purgeAllUnlocked(); |
| 381 | SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes()); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 382 | |
| 383 | // Add three resources to the cache. |
| 384 | TestResource* a = new TestResource(context->getGpu()); |
| 385 | TestResource* b = new TestResource(context->getGpu()); |
| 386 | TestResource* c = new TestResource(context->getGpu()); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 387 | a->cacheAccess().setContentKey(key1); |
| 388 | b->cacheAccess().setContentKey(key2); |
| 389 | c->cacheAccess().setContentKey(key3); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 390 | a->unref(); |
| 391 | b->unref(); |
| 392 | c->unref(); |
| 393 | |
| 394 | REPORTER_ASSERT(reporter, cache2->hasContentKey(key1)); |
| 395 | REPORTER_ASSERT(reporter, cache2->hasContentKey(key2)); |
| 396 | REPORTER_ASSERT(reporter, cache2->hasContentKey(key3)); |
| 397 | |
| 398 | // Invalidate two of the three, they should be purged and destroyed. |
| 399 | REPORTER_ASSERT(reporter, 3 == TestResource::NumAlive()); |
| 400 | const GrResourceInvalidatedMessage msg1 = { key1 }; |
| 401 | SkMessageBus<GrResourceInvalidatedMessage>::Post(msg1); |
| 402 | const GrResourceInvalidatedMessage msg2 = { key2 }; |
| 403 | SkMessageBus<GrResourceInvalidatedMessage>::Post(msg2); |
bsalomon | 6d4488c | 2014-11-11 07:27:16 -0800 | [diff] [blame] | 404 | #if 0 // Disabled until reimplemented in GrResourceCache2. |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 405 | cache2->purgeAsNeeded(); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 406 | REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive()); |
| 407 | REPORTER_ASSERT(reporter, !cache2->hasContentKey(key1)); |
| 408 | REPORTER_ASSERT(reporter, !cache2->hasContentKey(key2)); |
| 409 | REPORTER_ASSERT(reporter, cache2->hasContentKey(key3)); |
bsalomon | 6d4488c | 2014-11-11 07:27:16 -0800 | [diff] [blame] | 410 | #endif |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 411 | |
| 412 | // Invalidate the third. |
| 413 | const GrResourceInvalidatedMessage msg3 = { key3 }; |
| 414 | SkMessageBus<GrResourceInvalidatedMessage>::Post(msg3); |
bsalomon | 6d4488c | 2014-11-11 07:27:16 -0800 | [diff] [blame] | 415 | #if 0 // Disabled until reimplemented in GrResourceCache2. |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 416 | cache2->purgeAsNeeded(); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 417 | REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive()); |
| 418 | REPORTER_ASSERT(reporter, !cache2->hasContentKey(key3)); |
bsalomon | 6d4488c | 2014-11-11 07:27:16 -0800 | [diff] [blame] | 419 | #endif |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 420 | |
| 421 | cache2->purgeAllUnlocked(); |
| 422 | REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive()); |
| 423 | REPORTER_ASSERT(reporter, 0 == cache2->getResourceCount()); |
| 424 | REPORTER_ASSERT(reporter, 0 == cache2->getResourceBytes()); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 425 | } |
| 426 | |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 427 | static void test_cache_chained_purge(skiatest::Reporter* reporter) { |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 428 | SkAutoTUnref<GrContext> context(GrContext::CreateMockContext()); |
| 429 | REPORTER_ASSERT(reporter, SkToBool(context)); |
| 430 | if (NULL == context) { |
| 431 | return; |
| 432 | } |
| 433 | |
| 434 | GrCacheID::Domain domain = GrCacheID::GenerateDomain(); |
| 435 | GrCacheID::Key keyData; |
| 436 | memset(&keyData, 0, sizeof(keyData)); |
| 437 | GrResourceKey::ResourceType t = GrResourceKey::GenerateResourceType(); |
| 438 | |
| 439 | keyData.fData64[0] = 1; |
| 440 | GrResourceKey key1(GrCacheID(domain, keyData), t, 0); |
| 441 | |
| 442 | keyData.fData64[0] = 2; |
| 443 | GrResourceKey key2(GrCacheID(domain, keyData), t, 0); |
commit-bot@chromium.org | bd58feb | 2014-01-17 17:56:21 +0000 | [diff] [blame] | 444 | |
| 445 | { |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 446 | context->setResourceCacheLimits(3, 30000); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 447 | GrResourceCache2* cache2 = context->getResourceCache2(); |
| 448 | cache2->purgeAllUnlocked(); |
| 449 | SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes()); |
commit-bot@chromium.org | bd58feb | 2014-01-17 17:56:21 +0000 | [diff] [blame] | 450 | |
bsalomon | 820dd6c | 2014-11-05 12:09:45 -0800 | [diff] [blame] | 451 | TestResource* a = new TestResource(context->getGpu()); |
| 452 | TestResource* b = new TestResource(context->getGpu()); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 453 | a->cacheAccess().setContentKey(key1); |
| 454 | b->cacheAccess().setContentKey(key2); |
bsalomon | 820dd6c | 2014-11-05 12:09:45 -0800 | [diff] [blame] | 455 | |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 456 | // Make a cycle |
| 457 | a->setUnrefWhenDestroyed(b); |
| 458 | b->setUnrefWhenDestroyed(a); |
| 459 | |
| 460 | REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 461 | |
| 462 | a->unref(); |
| 463 | b->unref(); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 464 | |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 465 | REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 466 | |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 467 | cache2->purgeAllUnlocked(); |
| 468 | REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 469 | |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 470 | // Break the cycle |
| 471 | a->setUnrefWhenDestroyed(NULL); |
| 472 | REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 473 | |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 474 | cache2->purgeAllUnlocked(); |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 475 | REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive()); |
commit-bot@chromium.org | bd58feb | 2014-01-17 17:56:21 +0000 | [diff] [blame] | 476 | } |
| 477 | } |
| 478 | |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 479 | static void test_resource_size_changed(skiatest::Reporter* reporter) { |
| 480 | SkAutoTUnref<GrContext> context(GrContext::CreateMockContext()); |
| 481 | REPORTER_ASSERT(reporter, SkToBool(context)); |
| 482 | if (NULL == context) { |
| 483 | return; |
| 484 | } |
| 485 | |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 486 | GrCacheID::Domain domain = GrCacheID::GenerateDomain(); |
| 487 | GrResourceKey::ResourceType t = GrResourceKey::GenerateResourceType(); |
| 488 | |
| 489 | GrCacheID::Key key1Data; |
| 490 | key1Data.fData64[0] = 0; |
| 491 | key1Data.fData64[1] = 0; |
| 492 | GrResourceKey key1(GrCacheID(domain, key1Data), t, 0); |
| 493 | |
| 494 | GrCacheID::Key key2Data; |
| 495 | key2Data.fData64[0] = 1; |
| 496 | key2Data.fData64[1] = 0; |
| 497 | GrResourceKey key2(GrCacheID(domain, key2Data), t, 0); |
| 498 | |
| 499 | // Test changing resources sizes (both increase & decrease). |
| 500 | { |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 501 | context->setResourceCacheLimits(3, 30000); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 502 | GrResourceCache2* cache2 = context->getResourceCache2(); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 503 | cache2->purgeAllUnlocked(); |
| 504 | SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes()); |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 505 | |
bsalomon | c44be0e | 2014-07-25 07:32:33 -0700 | [diff] [blame] | 506 | TestResource* a = new TestResource(context->getGpu()); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 507 | a->cacheAccess().setContentKey(key1); |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 508 | a->unref(); |
| 509 | |
bsalomon | c44be0e | 2014-07-25 07:32:33 -0700 | [diff] [blame] | 510 | TestResource* b = new TestResource(context->getGpu()); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 511 | b->cacheAccess().setContentKey(key2); |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 512 | b->unref(); |
| 513 | |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 514 | REPORTER_ASSERT(reporter, 200 == cache2->getResourceBytes()); |
| 515 | REPORTER_ASSERT(reporter, 2 == cache2->getResourceCount()); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 516 | { |
| 517 | SkAutoTUnref<TestResource> find2(static_cast<TestResource*>(cache2->findAndRefContentResource(key2))); |
| 518 | find2->setSize(200); |
| 519 | SkAutoTUnref<TestResource> find1(static_cast<TestResource*>(cache2->findAndRefContentResource(key1))); |
| 520 | find1->setSize(50); |
| 521 | } |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 522 | |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 523 | REPORTER_ASSERT(reporter, 250 == cache2->getResourceBytes()); |
| 524 | REPORTER_ASSERT(reporter, 2 == cache2->getResourceCount()); |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 525 | } |
| 526 | |
| 527 | // Test increasing a resources size beyond the cache budget. |
| 528 | { |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 529 | context->setResourceCacheLimits(2, 300); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 530 | GrResourceCache2* cache2 = context->getResourceCache2(); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 531 | cache2->purgeAllUnlocked(); |
| 532 | SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes()); |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 533 | |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 534 | TestResource* a = new TestResource(context->getGpu()); |
| 535 | a->setSize(100); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 536 | a->cacheAccess().setContentKey(key1); |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 537 | a->unref(); |
| 538 | |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 539 | TestResource* b = new TestResource(context->getGpu()); |
| 540 | b->setSize(100); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 541 | b->cacheAccess().setContentKey(key2); |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 542 | b->unref(); |
| 543 | |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 544 | REPORTER_ASSERT(reporter, 200 == cache2->getResourceBytes()); |
| 545 | REPORTER_ASSERT(reporter, 2 == cache2->getResourceCount()); |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 546 | |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 547 | { |
| 548 | SkAutoTUnref<TestResource> find2(static_cast<TestResource*>(cache2->findAndRefContentResource(key2))); |
| 549 | find2->setSize(201); |
| 550 | } |
| 551 | REPORTER_ASSERT(reporter, !cache2->hasContentKey(key1)); |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 552 | |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 553 | REPORTER_ASSERT(reporter, 201 == cache2->getResourceBytes()); |
| 554 | REPORTER_ASSERT(reporter, 1 == cache2->getResourceCount()); |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 555 | } |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 556 | } |
| 557 | |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 558 | //////////////////////////////////////////////////////////////////////////////// |
tfarina@chromium.org | 4ee16bf | 2014-01-10 22:08:27 +0000 | [diff] [blame] | 559 | DEF_GPUTEST(ResourceCache, reporter, factory) { |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 560 | for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) { |
| 561 | GrContextFactory::GLContextType glType = static_cast<GrContextFactory::GLContextType>(type); |
| 562 | if (!GrContextFactory::IsRenderingGLContext(glType)) { |
| 563 | continue; |
| 564 | } |
| 565 | GrContext* context = factory->get(glType); |
bsalomon | fdcf2c0 | 2014-11-05 12:30:32 -0800 | [diff] [blame] | 566 | if (NULL == context) { |
| 567 | continue; |
| 568 | } |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 569 | GrSurfaceDesc desc; |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 570 | desc.fConfig = kSkia8888_GrPixelConfig; |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 571 | desc.fFlags = kRenderTarget_GrSurfaceFlag; |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 572 | desc.fWidth = gWidth; |
| 573 | desc.fHeight = gHeight; |
reed | 69f6f00 | 2014-09-18 06:09:44 -0700 | [diff] [blame] | 574 | SkImageInfo info = SkImageInfo::MakeN32Premul(gWidth, gHeight); |
reed | 4a8126e | 2014-09-22 07:29:03 -0700 | [diff] [blame] | 575 | SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(context, info)); |
reed | 69f6f00 | 2014-09-18 06:09:44 -0700 | [diff] [blame] | 576 | test_cache(reporter, context, surface->getCanvas()); |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 577 | } |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 578 | |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 579 | // The below tests create their own mock contexts. |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 580 | test_no_key(reporter); |
bsalomon | dace19e | 2014-11-17 07:34:06 -0800 | [diff] [blame^] | 581 | test_wrapped(reporter); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 582 | test_duplicate_content_key(reporter); |
| 583 | test_duplicate_scratch_key(reporter); |
| 584 | test_purge_invalidated(reporter); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 585 | test_cache_chained_purge(reporter); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 586 | test_resource_size_changed(reporter); |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 587 | } |
| 588 | |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 589 | #endif |