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" |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 13 | #include "GrResourceCache.h" |
bsalomon | 820dd6c | 2014-11-05 12:09:45 -0800 | [diff] [blame^] | 14 | #include "GrResourceCache2.h" |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 15 | #include "SkCanvas.h" |
reed | 69f6f00 | 2014-09-18 06:09:44 -0700 | [diff] [blame] | 16 | #include "SkSurface.h" |
tfarina@chromium.org | 4ee16bf | 2014-01-10 22:08:27 +0000 | [diff] [blame] | 17 | #include "Test.h" |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 18 | |
| 19 | static const int gWidth = 640; |
| 20 | static const int gHeight = 480; |
| 21 | |
| 22 | //////////////////////////////////////////////////////////////////////////////// |
bsalomon | 820dd6c | 2014-11-05 12:09:45 -0800 | [diff] [blame^] | 23 | 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] | 24 | const SkIRect size = SkIRect::MakeWH(gWidth, gHeight); |
| 25 | |
| 26 | SkBitmap src; |
mike@reedtribe.org | deee496 | 2014-02-13 14:41:43 +0000 | [diff] [blame] | 27 | src.allocN32Pixels(size.width(), size.height()); |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 28 | src.eraseColor(SK_ColorBLACK); |
| 29 | size_t srcSize = src.getSize(); |
| 30 | |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 31 | size_t initialCacheSize; |
| 32 | context->getResourceCacheUsage(NULL, &initialCacheSize); |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 33 | |
| 34 | int oldMaxNum; |
| 35 | size_t oldMaxBytes; |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 36 | context->getResourceCacheLimits(&oldMaxNum, &oldMaxBytes); |
skia.committer@gmail.com | 17f1ae6 | 2013-08-09 07:01:22 +0000 | [diff] [blame] | 37 | |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 38 | // Set the cache limits so we can fit 10 "src" images and the |
| 39 | // max number of textures doesn't matter |
| 40 | size_t maxCacheSize = initialCacheSize + 10*srcSize; |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 41 | context->setResourceCacheLimits(1000, maxCacheSize); |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 42 | |
| 43 | SkBitmap readback; |
mike@reedtribe.org | deee496 | 2014-02-13 14:41:43 +0000 | [diff] [blame] | 44 | readback.allocN32Pixels(size.width(), size.height()); |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 45 | |
| 46 | for (int i = 0; i < 100; ++i) { |
| 47 | canvas->drawBitmap(src, 0, 0); |
| 48 | canvas->readPixels(size, &readback); |
| 49 | |
| 50 | // "modify" the src texture |
| 51 | src.notifyPixelsChanged(); |
| 52 | |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 53 | size_t curCacheSize; |
| 54 | context->getResourceCacheUsage(NULL, &curCacheSize); |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 55 | |
| 56 | // we should never go over the size limit |
| 57 | REPORTER_ASSERT(reporter, curCacheSize <= maxCacheSize); |
| 58 | } |
| 59 | |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 60 | context->setResourceCacheLimits(oldMaxNum, oldMaxBytes); |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 61 | } |
| 62 | |
bsalomon | 6d3fe02 | 2014-07-25 08:35:45 -0700 | [diff] [blame] | 63 | class TestResource : public GrGpuResource { |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 64 | static const size_t kDefaultSize = 100; |
| 65 | |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 66 | public: |
| 67 | SK_DECLARE_INST_COUNT(TestResource); |
bsalomon | c44be0e | 2014-07-25 07:32:33 -0700 | [diff] [blame] | 68 | TestResource(GrGpu* gpu, size_t size = kDefaultSize) |
| 69 | : INHERITED(gpu, false) |
| 70 | , fCache(NULL) |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 71 | , fToDelete(NULL) |
| 72 | , fSize(size) { |
bsalomon | 820dd6c | 2014-11-05 12:09:45 -0800 | [diff] [blame^] | 73 | ++fNumAlive; |
bsalomon | 1696126 | 2014-08-26 14:01:07 -0700 | [diff] [blame] | 74 | this->registerWithCache(); |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | ~TestResource() { |
bsalomon | 820dd6c | 2014-11-05 12:09:45 -0800 | [diff] [blame^] | 78 | --fNumAlive; |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 79 | if (fToDelete) { |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 80 | // Breaks our little 2-element cycle below. |
| 81 | fToDelete->setDeleteWhenDestroyed(NULL, NULL); |
| 82 | fCache->deleteResource(fToDelete->getCacheEntry()); |
| 83 | } |
bsalomon | c44be0e | 2014-07-25 07:32:33 -0700 | [diff] [blame] | 84 | this->release(); |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 85 | } |
| 86 | |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 87 | void setSize(size_t size) { |
| 88 | fSize = size; |
| 89 | this->didChangeGpuMemorySize(); |
| 90 | } |
| 91 | |
| 92 | size_t gpuMemorySize() const SK_OVERRIDE { return fSize; } |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 93 | |
bsalomon | 820dd6c | 2014-11-05 12:09:45 -0800 | [diff] [blame^] | 94 | static int NumAlive() { return fNumAlive; } |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 95 | |
| 96 | void setDeleteWhenDestroyed(GrResourceCache* cache, TestResource* resource) { |
| 97 | fCache = cache; |
| 98 | fToDelete = resource; |
| 99 | } |
| 100 | |
| 101 | private: |
| 102 | GrResourceCache* fCache; |
| 103 | TestResource* fToDelete; |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 104 | size_t fSize; |
bsalomon | 820dd6c | 2014-11-05 12:09:45 -0800 | [diff] [blame^] | 105 | static int fNumAlive; |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 106 | |
bsalomon | 6d3fe02 | 2014-07-25 08:35:45 -0700 | [diff] [blame] | 107 | typedef GrGpuResource INHERITED; |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 108 | }; |
bsalomon | 820dd6c | 2014-11-05 12:09:45 -0800 | [diff] [blame^] | 109 | int TestResource::fNumAlive = 0; |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 110 | |
| 111 | static void test_purge_invalidated(skiatest::Reporter* reporter, GrContext* context) { |
| 112 | GrCacheID::Domain domain = GrCacheID::GenerateDomain(); |
| 113 | GrCacheID::Key keyData; |
| 114 | keyData.fData64[0] = 5; |
| 115 | keyData.fData64[1] = 18; |
| 116 | GrResourceKey::ResourceType t = GrResourceKey::GenerateResourceType(); |
| 117 | GrResourceKey key(GrCacheID(domain, keyData), t, 0); |
bsalomon | 820dd6c | 2014-11-05 12:09:45 -0800 | [diff] [blame^] | 118 | |
| 119 | context->setResourceCacheLimits(5, 30000); |
| 120 | GrResourceCache* cache = context->getResourceCache(); |
| 121 | cache->purgeAllUnlocked(); |
| 122 | SkASSERT(0 == cache->getCachedResourceCount() && 0 == cache->getCachedResourceBytes()); |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 123 | |
| 124 | // Add two resources with the same key that delete each other from the cache when destroyed. |
bsalomon | c44be0e | 2014-07-25 07:32:33 -0700 | [diff] [blame] | 125 | TestResource* a = new TestResource(context->getGpu()); |
| 126 | TestResource* b = new TestResource(context->getGpu()); |
bsalomon | 820dd6c | 2014-11-05 12:09:45 -0800 | [diff] [blame^] | 127 | cache->addResource(key, a); |
| 128 | cache->addResource(key, b); |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 129 | // Circle back. |
bsalomon | 820dd6c | 2014-11-05 12:09:45 -0800 | [diff] [blame^] | 130 | a->setDeleteWhenDestroyed(cache, b); |
| 131 | b->setDeleteWhenDestroyed(cache, a); |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 132 | a->unref(); |
| 133 | b->unref(); |
| 134 | |
| 135 | // Add a third independent resource also with the same key. |
bsalomon | 6d3fe02 | 2014-07-25 08:35:45 -0700 | [diff] [blame] | 136 | GrGpuResource* r = new TestResource(context->getGpu()); |
bsalomon | 820dd6c | 2014-11-05 12:09:45 -0800 | [diff] [blame^] | 137 | cache->addResource(key, r); |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 138 | r->unref(); |
| 139 | |
| 140 | // Invalidate all three, all three should be purged and destroyed. |
bsalomon | 820dd6c | 2014-11-05 12:09:45 -0800 | [diff] [blame^] | 141 | REPORTER_ASSERT(reporter, 3 == TestResource::NumAlive()); |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 142 | const GrResourceInvalidatedMessage msg = { key }; |
| 143 | SkMessageBus<GrResourceInvalidatedMessage>::Post(msg); |
bsalomon | 820dd6c | 2014-11-05 12:09:45 -0800 | [diff] [blame^] | 144 | cache->purgeAsNeeded(); |
| 145 | REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive()); |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 146 | } |
| 147 | |
commit-bot@chromium.org | bd58feb | 2014-01-17 17:56:21 +0000 | [diff] [blame] | 148 | static void test_cache_delete_on_destruction(skiatest::Reporter* reporter, |
| 149 | GrContext* context) { |
| 150 | GrCacheID::Domain domain = GrCacheID::GenerateDomain(); |
| 151 | GrCacheID::Key keyData; |
| 152 | keyData.fData64[0] = 5; |
| 153 | keyData.fData64[1] = 0; |
| 154 | GrResourceKey::ResourceType t = GrResourceKey::GenerateResourceType(); |
| 155 | |
| 156 | GrResourceKey key(GrCacheID(domain, keyData), t, 0); |
| 157 | |
| 158 | { |
bsalomon | 820dd6c | 2014-11-05 12:09:45 -0800 | [diff] [blame^] | 159 | context->setResourceCacheLimits(3, 30000); |
| 160 | GrResourceCache* cache = context->getResourceCache(); |
| 161 | cache->purgeAllUnlocked(); |
| 162 | SkASSERT(0 == cache->getCachedResourceCount() && 0 == cache->getCachedResourceBytes()); |
commit-bot@chromium.org | bd58feb | 2014-01-17 17:56:21 +0000 | [diff] [blame] | 163 | |
bsalomon | c44be0e | 2014-07-25 07:32:33 -0700 | [diff] [blame] | 164 | TestResource* a = new TestResource(context->getGpu()); |
| 165 | TestResource* b = new TestResource(context->getGpu()); |
bsalomon | 820dd6c | 2014-11-05 12:09:45 -0800 | [diff] [blame^] | 166 | cache->addResource(key, a); |
| 167 | cache->addResource(key, b); |
commit-bot@chromium.org | bd58feb | 2014-01-17 17:56:21 +0000 | [diff] [blame] | 168 | |
bsalomon | 820dd6c | 2014-11-05 12:09:45 -0800 | [diff] [blame^] | 169 | a->setDeleteWhenDestroyed(cache, b); |
| 170 | b->setDeleteWhenDestroyed(cache, a); |
| 171 | |
| 172 | a->unref(); |
| 173 | b->unref(); |
| 174 | REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); |
| 175 | cache->purgeAllUnlocked(); |
| 176 | REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive()); |
| 177 | } |
| 178 | { |
| 179 | context->setResourceCacheLimits(3, 30000); |
| 180 | GrResourceCache* cache = context->getResourceCache(); |
| 181 | cache->purgeAllUnlocked(); |
| 182 | SkASSERT(0 == cache->getCachedResourceCount() && 0 == cache->getCachedResourceBytes()); |
| 183 | TestResource* a = new TestResource(context->getGpu()); |
| 184 | TestResource* b = new TestResource(context->getGpu()); |
| 185 | cache->addResource(key, a); |
| 186 | cache->addResource(key, b); |
| 187 | |
| 188 | a->setDeleteWhenDestroyed(cache, b); |
| 189 | b->setDeleteWhenDestroyed(cache, a); |
commit-bot@chromium.org | bd58feb | 2014-01-17 17:56:21 +0000 | [diff] [blame] | 190 | |
| 191 | a->unref(); |
| 192 | b->unref(); |
| 193 | |
bsalomon | 820dd6c | 2014-11-05 12:09:45 -0800 | [diff] [blame^] | 194 | cache->deleteResource(a->getCacheEntry()); |
commit-bot@chromium.org | bd58feb | 2014-01-17 17:56:21 +0000 | [diff] [blame] | 195 | |
bsalomon | 820dd6c | 2014-11-05 12:09:45 -0800 | [diff] [blame^] | 196 | REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive()); |
commit-bot@chromium.org | bd58feb | 2014-01-17 17:56:21 +0000 | [diff] [blame] | 197 | } |
| 198 | } |
| 199 | |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 200 | static void test_resource_size_changed(skiatest::Reporter* reporter, |
| 201 | GrContext* context) { |
| 202 | GrCacheID::Domain domain = GrCacheID::GenerateDomain(); |
| 203 | GrResourceKey::ResourceType t = GrResourceKey::GenerateResourceType(); |
| 204 | |
| 205 | GrCacheID::Key key1Data; |
| 206 | key1Data.fData64[0] = 0; |
| 207 | key1Data.fData64[1] = 0; |
| 208 | GrResourceKey key1(GrCacheID(domain, key1Data), t, 0); |
| 209 | |
| 210 | GrCacheID::Key key2Data; |
| 211 | key2Data.fData64[0] = 1; |
| 212 | key2Data.fData64[1] = 0; |
| 213 | GrResourceKey key2(GrCacheID(domain, key2Data), t, 0); |
| 214 | |
| 215 | // Test changing resources sizes (both increase & decrease). |
| 216 | { |
bsalomon | 820dd6c | 2014-11-05 12:09:45 -0800 | [diff] [blame^] | 217 | context->setResourceCacheLimits(3, 30000); |
| 218 | GrResourceCache* cache = context->getResourceCache(); |
| 219 | cache->purgeAllUnlocked(); |
| 220 | SkASSERT(0 == cache->getCachedResourceCount() && 0 == cache->getCachedResourceBytes()); |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 221 | |
bsalomon | c44be0e | 2014-07-25 07:32:33 -0700 | [diff] [blame] | 222 | TestResource* a = new TestResource(context->getGpu()); |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 223 | a->setSize(100); // Test didChangeGpuMemorySize() when not in the cache. |
bsalomon | 820dd6c | 2014-11-05 12:09:45 -0800 | [diff] [blame^] | 224 | cache->addResource(key1, a); |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 225 | a->unref(); |
| 226 | |
bsalomon | c44be0e | 2014-07-25 07:32:33 -0700 | [diff] [blame] | 227 | TestResource* b = new TestResource(context->getGpu()); |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 228 | b->setSize(100); |
bsalomon | 820dd6c | 2014-11-05 12:09:45 -0800 | [diff] [blame^] | 229 | cache->addResource(key2, b); |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 230 | b->unref(); |
| 231 | |
bsalomon | 820dd6c | 2014-11-05 12:09:45 -0800 | [diff] [blame^] | 232 | REPORTER_ASSERT(reporter, 200 == cache->getCachedResourceBytes()); |
| 233 | REPORTER_ASSERT(reporter, 2 == cache->getCachedResourceCount()); |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 234 | |
bsalomon | 820dd6c | 2014-11-05 12:09:45 -0800 | [diff] [blame^] | 235 | static_cast<TestResource*>(cache->find(key2))->setSize(200); |
| 236 | static_cast<TestResource*>(cache->find(key1))->setSize(50); |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 237 | |
bsalomon | 820dd6c | 2014-11-05 12:09:45 -0800 | [diff] [blame^] | 238 | REPORTER_ASSERT(reporter, 250 == cache->getCachedResourceBytes()); |
| 239 | REPORTER_ASSERT(reporter, 2 == cache->getCachedResourceCount()); |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | // Test increasing a resources size beyond the cache budget. |
| 243 | { |
bsalomon | 820dd6c | 2014-11-05 12:09:45 -0800 | [diff] [blame^] | 244 | context->setResourceCacheLimits(2, 300); |
| 245 | GrResourceCache* cache = context->getResourceCache(); |
| 246 | cache->purgeAllUnlocked(); |
| 247 | SkASSERT(0 == cache->getCachedResourceCount() && 0 == cache->getCachedResourceBytes()); |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 248 | |
bsalomon | c44be0e | 2014-07-25 07:32:33 -0700 | [diff] [blame] | 249 | TestResource* a = new TestResource(context->getGpu(), 100); |
bsalomon | 820dd6c | 2014-11-05 12:09:45 -0800 | [diff] [blame^] | 250 | cache->addResource(key1, a); |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 251 | a->unref(); |
| 252 | |
bsalomon | c44be0e | 2014-07-25 07:32:33 -0700 | [diff] [blame] | 253 | TestResource* b = new TestResource(context->getGpu(), 100); |
bsalomon | 820dd6c | 2014-11-05 12:09:45 -0800 | [diff] [blame^] | 254 | cache->addResource(key2, b); |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 255 | b->unref(); |
| 256 | |
bsalomon | 820dd6c | 2014-11-05 12:09:45 -0800 | [diff] [blame^] | 257 | REPORTER_ASSERT(reporter, 200 == cache->getCachedResourceBytes()); |
| 258 | REPORTER_ASSERT(reporter, 2 == cache->getCachedResourceCount()); |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 259 | |
bsalomon | 820dd6c | 2014-11-05 12:09:45 -0800 | [diff] [blame^] | 260 | static_cast<TestResource*>(cache->find(key2))->setSize(201); |
| 261 | REPORTER_ASSERT(reporter, !cache->hasKey(key1)); |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 262 | |
bsalomon | 820dd6c | 2014-11-05 12:09:45 -0800 | [diff] [blame^] | 263 | REPORTER_ASSERT(reporter, 201 == cache->getCachedResourceBytes()); |
| 264 | REPORTER_ASSERT(reporter, 1 == cache->getCachedResourceCount()); |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 265 | } |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 266 | } |
| 267 | |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 268 | //////////////////////////////////////////////////////////////////////////////// |
tfarina@chromium.org | 4ee16bf | 2014-01-10 22:08:27 +0000 | [diff] [blame] | 269 | DEF_GPUTEST(ResourceCache, reporter, factory) { |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 270 | for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) { |
| 271 | GrContextFactory::GLContextType glType = static_cast<GrContextFactory::GLContextType>(type); |
| 272 | if (!GrContextFactory::IsRenderingGLContext(glType)) { |
| 273 | continue; |
| 274 | } |
| 275 | GrContext* context = factory->get(glType); |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 276 | GrSurfaceDesc desc; |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 277 | desc.fConfig = kSkia8888_GrPixelConfig; |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 278 | desc.fFlags = kRenderTarget_GrSurfaceFlag; |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 279 | desc.fWidth = gWidth; |
| 280 | desc.fHeight = gHeight; |
reed | 69f6f00 | 2014-09-18 06:09:44 -0700 | [diff] [blame] | 281 | SkImageInfo info = SkImageInfo::MakeN32Premul(gWidth, gHeight); |
reed | 4a8126e | 2014-09-22 07:29:03 -0700 | [diff] [blame] | 282 | SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(context, info)); |
reed | 69f6f00 | 2014-09-18 06:09:44 -0700 | [diff] [blame] | 283 | test_cache(reporter, context, surface->getCanvas()); |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 284 | } |
bsalomon | 820dd6c | 2014-11-05 12:09:45 -0800 | [diff] [blame^] | 285 | |
| 286 | // The below tests use a mock context. |
| 287 | SkAutoTUnref<GrContext> context(GrContext::CreateMockContext()); |
| 288 | REPORTER_ASSERT(reporter, SkToBool(context)); |
| 289 | if (NULL == context) { |
| 290 | return; |
| 291 | } |
| 292 | |
| 293 | test_purge_invalidated(reporter, context); |
| 294 | test_cache_delete_on_destruction(reporter, context); |
| 295 | test_resource_size_changed(reporter, context); |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 296 | } |
| 297 | |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 298 | #endif |