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 | |
bsalomon | 3f32432 | 2015-04-08 11:01:54 -0700 | [diff] [blame] | 8 | // Include here to ensure SK_SUPPORT_GPU is set correctly before it is examined. |
| 9 | #include "SkTypes.h" |
| 10 | |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 11 | #if SK_SUPPORT_GPU |
tfarina@chromium.org | 4ee16bf | 2014-01-10 22:08:27 +0000 | [diff] [blame] | 12 | |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 13 | #include "GrContext.h" |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 14 | #include "GrContextFactory.h" |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 15 | #include "GrGpu.h" |
bsalomon | 3582d3e | 2015-02-13 14:20:05 -0800 | [diff] [blame] | 16 | #include "GrGpuResourceCacheAccess.h" |
| 17 | #include "GrGpuResourcePriv.h" |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 18 | #include "GrRenderTarget.h" |
| 19 | #include "GrRenderTargetPriv.h" |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 20 | #include "GrResourceCache.h" |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 21 | #include "SkCanvas.h" |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 22 | #include "SkGr.h" |
| 23 | #include "SkMessageBus.h" |
reed | 69f6f00 | 2014-09-18 06:09:44 -0700 | [diff] [blame] | 24 | #include "SkSurface.h" |
tfarina@chromium.org | 4ee16bf | 2014-01-10 22:08:27 +0000 | [diff] [blame] | 25 | #include "Test.h" |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 26 | |
| 27 | static const int gWidth = 640; |
| 28 | static const int gHeight = 480; |
| 29 | |
| 30 | //////////////////////////////////////////////////////////////////////////////// |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 31 | 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] | 32 | const SkIRect size = SkIRect::MakeWH(gWidth, gHeight); |
| 33 | |
| 34 | SkBitmap src; |
mike@reedtribe.org | deee496 | 2014-02-13 14:41:43 +0000 | [diff] [blame] | 35 | src.allocN32Pixels(size.width(), size.height()); |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 36 | src.eraseColor(SK_ColorBLACK); |
| 37 | size_t srcSize = src.getSize(); |
| 38 | |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 39 | size_t initialCacheSize; |
| 40 | context->getResourceCacheUsage(NULL, &initialCacheSize); |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 41 | |
| 42 | int oldMaxNum; |
| 43 | size_t oldMaxBytes; |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 44 | context->getResourceCacheLimits(&oldMaxNum, &oldMaxBytes); |
skia.committer@gmail.com | 17f1ae6 | 2013-08-09 07:01:22 +0000 | [diff] [blame] | 45 | |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 46 | // Set the cache limits so we can fit 10 "src" images and the |
| 47 | // max number of textures doesn't matter |
| 48 | size_t maxCacheSize = initialCacheSize + 10*srcSize; |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 49 | context->setResourceCacheLimits(1000, maxCacheSize); |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 50 | |
| 51 | SkBitmap readback; |
mike@reedtribe.org | deee496 | 2014-02-13 14:41:43 +0000 | [diff] [blame] | 52 | readback.allocN32Pixels(size.width(), size.height()); |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 53 | |
| 54 | for (int i = 0; i < 100; ++i) { |
| 55 | canvas->drawBitmap(src, 0, 0); |
| 56 | canvas->readPixels(size, &readback); |
| 57 | |
| 58 | // "modify" the src texture |
| 59 | src.notifyPixelsChanged(); |
| 60 | |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 61 | size_t curCacheSize; |
| 62 | context->getResourceCacheUsage(NULL, &curCacheSize); |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 63 | |
| 64 | // we should never go over the size limit |
| 65 | REPORTER_ASSERT(reporter, curCacheSize <= maxCacheSize); |
| 66 | } |
| 67 | |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 68 | context->setResourceCacheLimits(oldMaxNum, oldMaxBytes); |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 69 | } |
| 70 | |
bsalomon | 02a44a4 | 2015-02-19 09:09:00 -0800 | [diff] [blame] | 71 | static void test_stencil_buffers(skiatest::Reporter* reporter, GrContext* context) { |
| 72 | GrSurfaceDesc smallDesc; |
| 73 | smallDesc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 74 | smallDesc.fConfig = kSkia8888_GrPixelConfig; |
| 75 | smallDesc.fWidth = 4; |
| 76 | smallDesc.fHeight = 4; |
| 77 | smallDesc.fSampleCnt = 0; |
| 78 | |
| 79 | // Test that two budgeted RTs with the same desc share a stencil buffer. |
| 80 | SkAutoTUnref<GrTexture> smallRT0(context->createTexture(smallDesc, true)); |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 81 | if (smallRT0 && smallRT0->asRenderTarget()) { |
| 82 | smallRT0->asRenderTarget()->renderTargetPriv().attachStencilBuffer(); |
| 83 | } |
| 84 | |
bsalomon | 02a44a4 | 2015-02-19 09:09:00 -0800 | [diff] [blame] | 85 | SkAutoTUnref<GrTexture> smallRT1(context->createTexture(smallDesc, true)); |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 86 | if (smallRT1 && smallRT1->asRenderTarget()) { |
| 87 | smallRT1->asRenderTarget()->renderTargetPriv().attachStencilBuffer(); |
| 88 | } |
| 89 | |
bsalomon | 02a44a4 | 2015-02-19 09:09:00 -0800 | [diff] [blame] | 90 | REPORTER_ASSERT(reporter, smallRT0 && smallRT1 && |
| 91 | smallRT0->asRenderTarget() && smallRT1->asRenderTarget() && |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 92 | smallRT0->asRenderTarget()->renderTargetPriv().getStencilBuffer() == |
| 93 | smallRT1->asRenderTarget()->renderTargetPriv().getStencilBuffer()); |
bsalomon | 02a44a4 | 2015-02-19 09:09:00 -0800 | [diff] [blame] | 94 | |
| 95 | // An unbudgeted RT with the same desc should also share. |
| 96 | SkAutoTUnref<GrTexture> smallRT2(context->createTexture(smallDesc, false)); |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 97 | if (smallRT2 && smallRT2->asRenderTarget()) { |
| 98 | smallRT2->asRenderTarget()->renderTargetPriv().attachStencilBuffer(); |
| 99 | } |
bsalomon | 02a44a4 | 2015-02-19 09:09:00 -0800 | [diff] [blame] | 100 | REPORTER_ASSERT(reporter, smallRT0 && smallRT2 && |
| 101 | smallRT0->asRenderTarget() && smallRT2->asRenderTarget() && |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 102 | smallRT0->asRenderTarget()->renderTargetPriv().getStencilBuffer() == |
| 103 | smallRT2->asRenderTarget()->renderTargetPriv().getStencilBuffer()); |
bsalomon | 02a44a4 | 2015-02-19 09:09:00 -0800 | [diff] [blame] | 104 | |
| 105 | // An RT with a much larger size should not share. |
| 106 | GrSurfaceDesc bigDesc; |
| 107 | bigDesc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 108 | bigDesc.fConfig = kSkia8888_GrPixelConfig; |
| 109 | bigDesc.fWidth = 400; |
| 110 | bigDesc.fHeight = 200; |
| 111 | bigDesc.fSampleCnt = 0; |
| 112 | SkAutoTUnref<GrTexture> bigRT(context->createTexture(bigDesc, false)); |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 113 | if (bigRT && bigRT->asRenderTarget()) { |
| 114 | bigRT->asRenderTarget()->renderTargetPriv().attachStencilBuffer(); |
| 115 | } |
bsalomon | 02a44a4 | 2015-02-19 09:09:00 -0800 | [diff] [blame] | 116 | REPORTER_ASSERT(reporter, smallRT0 && bigRT && |
| 117 | smallRT0->asRenderTarget() && bigRT->asRenderTarget() && |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 118 | smallRT0->asRenderTarget()->renderTargetPriv().getStencilBuffer() != |
| 119 | bigRT->asRenderTarget()->renderTargetPriv().getStencilBuffer()); |
bsalomon | 02a44a4 | 2015-02-19 09:09:00 -0800 | [diff] [blame] | 120 | |
| 121 | if (context->getMaxSampleCount() >= 4) { |
| 122 | // An RT with a different sample count should not share. |
| 123 | GrSurfaceDesc smallMSAADesc = smallDesc; |
| 124 | smallMSAADesc.fSampleCnt = 4; |
| 125 | SkAutoTUnref<GrTexture> smallMSAART0(context->createTexture(smallMSAADesc, false)); |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 126 | if (smallMSAART0 && smallMSAART0->asRenderTarget()) { |
| 127 | smallMSAART0->asRenderTarget()->renderTargetPriv().attachStencilBuffer(); |
| 128 | } |
bsalomon | b602d4d | 2015-02-19 12:05:58 -0800 | [diff] [blame] | 129 | #ifdef SK_BUILD_FOR_ANDROID |
| 130 | if (!smallMSAART0) { |
| 131 | // The nexus player seems to fail to create MSAA textures. |
| 132 | return; |
| 133 | } |
| 134 | #endif |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 135 | REPORTER_ASSERT(reporter, |
| 136 | smallRT0 && smallMSAART0 && |
| 137 | smallRT0->asRenderTarget() && smallMSAART0->asRenderTarget() && |
| 138 | smallRT0->asRenderTarget()->renderTargetPriv().getStencilBuffer() != |
| 139 | smallMSAART0->asRenderTarget()->renderTargetPriv().getStencilBuffer()); |
bsalomon | 02a44a4 | 2015-02-19 09:09:00 -0800 | [diff] [blame] | 140 | // A second MSAA RT should share with the first MSAA RT. |
| 141 | SkAutoTUnref<GrTexture> smallMSAART1(context->createTexture(smallMSAADesc, false)); |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 142 | if (smallMSAART1 && smallMSAART1->asRenderTarget()) { |
| 143 | smallMSAART1->asRenderTarget()->renderTargetPriv().attachStencilBuffer(); |
| 144 | } |
| 145 | REPORTER_ASSERT(reporter, |
| 146 | smallMSAART0 && smallMSAART1 && |
| 147 | smallMSAART0->asRenderTarget() && |
| 148 | smallMSAART1->asRenderTarget() && |
| 149 | smallMSAART0->asRenderTarget()->renderTargetPriv().getStencilBuffer() == |
| 150 | smallMSAART1->asRenderTarget()->renderTargetPriv().getStencilBuffer()); |
bsalomon | 02a44a4 | 2015-02-19 09:09:00 -0800 | [diff] [blame] | 151 | // But not one with a larger sample count should not. (Also check that the request for 4 |
| 152 | // samples didn't get rounded up to >= 8 or else they could share.). |
| 153 | if (context->getMaxSampleCount() >= 8 && smallMSAART0 && smallMSAART0->asRenderTarget() && |
| 154 | smallMSAART0->asRenderTarget()->numSamples() < 8) { |
| 155 | smallMSAADesc.fSampleCnt = 8; |
| 156 | smallMSAART1.reset(context->createTexture(smallMSAADesc, false)); |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 157 | SkAutoTUnref<GrTexture> smallMSAART1(context->createTexture(smallMSAADesc, false)); |
| 158 | if (smallMSAART1 && smallMSAART1->asRenderTarget()) { |
| 159 | smallMSAART1->asRenderTarget()->renderTargetPriv().attachStencilBuffer(); |
| 160 | } |
| 161 | REPORTER_ASSERT(reporter, |
| 162 | smallMSAART0 && smallMSAART1 && |
| 163 | smallMSAART0->asRenderTarget() && |
| 164 | smallMSAART1->asRenderTarget() && |
| 165 | smallMSAART0->asRenderTarget()->renderTargetPriv().getStencilBuffer() != |
| 166 | smallMSAART1->asRenderTarget()->renderTargetPriv().getStencilBuffer()); |
bsalomon | 02a44a4 | 2015-02-19 09:09:00 -0800 | [diff] [blame] | 167 | } |
| 168 | } |
| 169 | } |
| 170 | |
bsalomon | 6d3fe02 | 2014-07-25 08:35:45 -0700 | [diff] [blame] | 171 | class TestResource : public GrGpuResource { |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 172 | static const size_t kDefaultSize = 100; |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 173 | enum ScratchConstructor { kScratchConstructor }; |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 174 | public: |
| 175 | SK_DECLARE_INST_COUNT(TestResource); |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 176 | /** Property that distinctly categorizes the resource. |
| 177 | * For example, textures have width, height, ... */ |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 178 | enum SimulatedProperty { kA_SimulatedProperty, kB_SimulatedProperty }; |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 179 | |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 180 | TestResource(GrGpu* gpu, size_t size, GrGpuResource::LifeCycle lifeCycle) |
| 181 | : INHERITED(gpu, lifeCycle) |
| 182 | , fToDelete(NULL) |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 183 | , fSize(size) |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 184 | , fProperty(kA_SimulatedProperty) { |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 185 | ++fNumAlive; |
| 186 | this->registerWithCache(); |
| 187 | } |
| 188 | |
| 189 | TestResource(GrGpu* gpu, GrGpuResource::LifeCycle lifeCycle) |
| 190 | : INHERITED(gpu, lifeCycle) |
bsalomon | dace19e | 2014-11-17 07:34:06 -0800 | [diff] [blame] | 191 | , fToDelete(NULL) |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 192 | , fSize(kDefaultSize) |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 193 | , fProperty(kA_SimulatedProperty) { |
bsalomon | dace19e | 2014-11-17 07:34:06 -0800 | [diff] [blame] | 194 | ++fNumAlive; |
| 195 | this->registerWithCache(); |
| 196 | } |
| 197 | |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 198 | TestResource(GrGpu* gpu) |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 199 | : INHERITED(gpu, kCached_LifeCycle) |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 200 | , fToDelete(NULL) |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 201 | , fSize(kDefaultSize) |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 202 | , fProperty(kA_SimulatedProperty) { |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 203 | ++fNumAlive; |
| 204 | this->registerWithCache(); |
| 205 | } |
| 206 | |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 207 | static TestResource* CreateScratch(GrGpu* gpu, SimulatedProperty property, bool cached = true) { |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 208 | return SkNEW_ARGS(TestResource, (gpu, property, cached, kScratchConstructor)); |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | ~TestResource() { |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 212 | --fNumAlive; |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 213 | SkSafeUnref(fToDelete); |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 214 | } |
| 215 | |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 216 | void setSize(size_t size) { |
| 217 | fSize = size; |
| 218 | this->didChangeGpuMemorySize(); |
| 219 | } |
| 220 | |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 221 | static int NumAlive() { return fNumAlive; } |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 222 | |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 223 | void setUnrefWhenDestroyed(TestResource* resource) { |
| 224 | SkRefCnt_SafeAssign(fToDelete, resource); |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 225 | } |
| 226 | |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 227 | static void ComputeScratchKey(SimulatedProperty property, GrScratchKey* key) { |
| 228 | static GrScratchKey::ResourceType t = GrScratchKey::GenerateResourceType(); |
| 229 | GrScratchKey::Builder builder(key, t, kScratchKeyFieldCnt); |
bsalomon | 24db3b1 | 2015-01-23 04:24:04 -0800 | [diff] [blame] | 230 | for (int i = 0; i < kScratchKeyFieldCnt; ++i) { |
| 231 | builder[i] = static_cast<uint32_t>(i + property); |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 232 | } |
| 233 | } |
| 234 | |
| 235 | static size_t ExpectedScratchKeySize() { |
| 236 | return sizeof(uint32_t) * (kScratchKeyFieldCnt + GrScratchKey::kMetaDataCnt); |
| 237 | } |
| 238 | |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 239 | private: |
bsalomon | 24db3b1 | 2015-01-23 04:24:04 -0800 | [diff] [blame] | 240 | static const int kScratchKeyFieldCnt = 6; |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 241 | |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 242 | TestResource(GrGpu* gpu, SimulatedProperty property, bool cached, ScratchConstructor) |
| 243 | : INHERITED(gpu, cached ? kCached_LifeCycle : kUncached_LifeCycle) |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 244 | , fToDelete(NULL) |
| 245 | , fSize(kDefaultSize) |
| 246 | , fProperty(property) { |
| 247 | GrScratchKey scratchKey; |
| 248 | ComputeScratchKey(fProperty, &scratchKey); |
| 249 | this->setScratchKey(scratchKey); |
| 250 | ++fNumAlive; |
| 251 | this->registerWithCache(); |
| 252 | } |
| 253 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 254 | size_t onGpuMemorySize() const override { return fSize; } |
bsalomon | 69ed47f | 2014-11-12 11:13:39 -0800 | [diff] [blame] | 255 | |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 256 | TestResource* fToDelete; |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 257 | size_t fSize; |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 258 | static int fNumAlive; |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 259 | SimulatedProperty fProperty; |
bsalomon | 6d3fe02 | 2014-07-25 08:35:45 -0700 | [diff] [blame] | 260 | typedef GrGpuResource INHERITED; |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 261 | }; |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 262 | int TestResource::fNumAlive = 0; |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 263 | |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 264 | class Mock { |
| 265 | public: |
| 266 | Mock(int maxCnt, size_t maxBytes) { |
| 267 | fContext.reset(GrContext::CreateMockContext()); |
| 268 | SkASSERT(fContext); |
| 269 | fContext->setResourceCacheLimits(maxCnt, maxBytes); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 270 | GrResourceCache* cache = fContext->getResourceCache(); |
| 271 | cache->purgeAllUnlocked(); |
| 272 | SkASSERT(0 == cache->getResourceCount() && 0 == cache->getResourceBytes()); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 273 | } |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 274 | |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 275 | GrResourceCache* cache() { return fContext->getResourceCache(); } |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 276 | |
| 277 | GrContext* context() { return fContext; } |
| 278 | |
| 279 | private: |
| 280 | SkAutoTUnref<GrContext> fContext; |
| 281 | }; |
| 282 | |
| 283 | static void test_no_key(skiatest::Reporter* reporter) { |
| 284 | Mock mock(10, 30000); |
| 285 | GrContext* context = mock.context(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 286 | GrResourceCache* cache = mock.cache(); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 287 | |
| 288 | // Create a bunch of resources with no keys |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 289 | TestResource* a = SkNEW_ARGS(TestResource, (context->getGpu())); |
| 290 | TestResource* b = SkNEW_ARGS(TestResource, (context->getGpu())); |
| 291 | TestResource* c = SkNEW_ARGS(TestResource, (context->getGpu())); |
| 292 | TestResource* d = SkNEW_ARGS(TestResource, (context->getGpu())); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 293 | a->setSize(11); |
| 294 | b->setSize(12); |
| 295 | c->setSize(13); |
| 296 | d->setSize(14); |
| 297 | |
| 298 | REPORTER_ASSERT(reporter, 4 == TestResource::NumAlive()); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 299 | REPORTER_ASSERT(reporter, 4 == cache->getResourceCount()); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 300 | REPORTER_ASSERT(reporter, a->gpuMemorySize() + b->gpuMemorySize() + c->gpuMemorySize() + |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 301 | d->gpuMemorySize() == cache->getResourceBytes()); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 302 | |
| 303 | // Should be safe to purge without deleting the resources since we still have refs. |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 304 | cache->purgeAllUnlocked(); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 305 | REPORTER_ASSERT(reporter, 4 == TestResource::NumAlive()); |
| 306 | |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 307 | // Since the resources have neither unique nor scratch keys, delete immediately upon unref. |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 308 | |
| 309 | a->unref(); |
| 310 | REPORTER_ASSERT(reporter, 3 == TestResource::NumAlive()); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 311 | REPORTER_ASSERT(reporter, 3 == cache->getResourceCount()); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 312 | REPORTER_ASSERT(reporter, b->gpuMemorySize() + c->gpuMemorySize() + d->gpuMemorySize() == |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 313 | cache->getResourceBytes()); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 314 | |
| 315 | c->unref(); |
| 316 | REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 317 | REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 318 | REPORTER_ASSERT(reporter, b->gpuMemorySize() + d->gpuMemorySize() == |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 319 | cache->getResourceBytes()); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 320 | |
| 321 | d->unref(); |
| 322 | REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive()); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 323 | REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); |
| 324 | REPORTER_ASSERT(reporter, b->gpuMemorySize() == cache->getResourceBytes()); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 325 | |
| 326 | b->unref(); |
| 327 | REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive()); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 328 | REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
| 329 | REPORTER_ASSERT(reporter, 0 == cache->getResourceBytes()); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 330 | } |
| 331 | |
bsalomon | 24db3b1 | 2015-01-23 04:24:04 -0800 | [diff] [blame] | 332 | // Each integer passed as a template param creates a new domain. |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 333 | template <int> static void make_unique_key(GrUniqueKey* key, int data) { |
| 334 | static GrUniqueKey::Domain d = GrUniqueKey::GenerateDomain(); |
| 335 | GrUniqueKey::Builder builder(key, d, 1); |
bsalomon | 24db3b1 | 2015-01-23 04:24:04 -0800 | [diff] [blame] | 336 | builder[0] = data; |
| 337 | } |
| 338 | |
bsalomon | 84c8e62 | 2014-11-17 09:33:27 -0800 | [diff] [blame] | 339 | static void test_budgeting(skiatest::Reporter* reporter) { |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 340 | Mock mock(10, 300); |
| 341 | GrContext* context = mock.context(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 342 | GrResourceCache* cache = mock.cache(); |
bsalomon | dace19e | 2014-11-17 07:34:06 -0800 | [diff] [blame] | 343 | |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 344 | GrUniqueKey uniqueKey; |
| 345 | make_unique_key<0>(&uniqueKey, 0); |
bsalomon | dace19e | 2014-11-17 07:34:06 -0800 | [diff] [blame] | 346 | |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 347 | // Create a scratch, a unique, and a wrapped resource |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 348 | TestResource* scratch = |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 349 | TestResource::CreateScratch(context->getGpu(), TestResource::kB_SimulatedProperty); |
bsalomon | dace19e | 2014-11-17 07:34:06 -0800 | [diff] [blame] | 350 | scratch->setSize(10); |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 351 | TestResource* unique = SkNEW_ARGS(TestResource, (context->getGpu())); |
| 352 | unique->setSize(11); |
bsalomon | f99e961 | 2015-02-19 08:24:16 -0800 | [diff] [blame] | 353 | unique->resourcePriv().setUniqueKey(uniqueKey); |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 354 | TestResource* wrapped = SkNEW_ARGS(TestResource, |
| 355 | (context->getGpu(), GrGpuResource::kWrapped_LifeCycle)); |
| 356 | wrapped->setSize(12); |
| 357 | TestResource* unbudgeted = SkNEW_ARGS(TestResource, |
| 358 | (context->getGpu(), GrGpuResource::kUncached_LifeCycle)); |
bsalomon | 84c8e62 | 2014-11-17 09:33:27 -0800 | [diff] [blame] | 359 | unbudgeted->setSize(13); |
bsalomon | dace19e | 2014-11-17 07:34:06 -0800 | [diff] [blame] | 360 | |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 361 | // Make sure we can't add a unique key to the wrapped resource |
| 362 | GrUniqueKey uniqueKey2; |
| 363 | make_unique_key<0>(&uniqueKey2, 1); |
bsalomon | f99e961 | 2015-02-19 08:24:16 -0800 | [diff] [blame] | 364 | wrapped->resourcePriv().setUniqueKey(uniqueKey2); |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 365 | REPORTER_ASSERT(reporter, NULL == cache->findAndRefUniqueResource(uniqueKey2)); |
bsalomon | dace19e | 2014-11-17 07:34:06 -0800 | [diff] [blame] | 366 | |
| 367 | // Make sure sizes are as we expect |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 368 | REPORTER_ASSERT(reporter, 4 == cache->getResourceCount()); |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 369 | REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + unique->gpuMemorySize() + |
bsalomon | 84c8e62 | 2014-11-17 09:33:27 -0800 | [diff] [blame] | 370 | wrapped->gpuMemorySize() + unbudgeted->gpuMemorySize() == |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 371 | cache->getResourceBytes()); |
| 372 | REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount()); |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 373 | REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + unique->gpuMemorySize() == |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 374 | cache->getBudgetedResourceBytes()); |
bsalomon | dace19e | 2014-11-17 07:34:06 -0800 | [diff] [blame] | 375 | |
bsalomon | 63c992f | 2015-01-23 12:47:59 -0800 | [diff] [blame] | 376 | // Our refs mean that the resources are non purgeable. |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 377 | cache->purgeAllUnlocked(); |
| 378 | REPORTER_ASSERT(reporter, 4 == cache->getResourceCount()); |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 379 | REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + unique->gpuMemorySize() + |
bsalomon | 84c8e62 | 2014-11-17 09:33:27 -0800 | [diff] [blame] | 380 | wrapped->gpuMemorySize() + unbudgeted->gpuMemorySize() == |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 381 | cache->getResourceBytes()); |
| 382 | REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount()); |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 383 | REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + unique->gpuMemorySize() == |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 384 | cache->getBudgetedResourceBytes()); |
bsalomon | dace19e | 2014-11-17 07:34:06 -0800 | [diff] [blame] | 385 | |
| 386 | // Unreffing the wrapped resource should free it right away. |
| 387 | wrapped->unref(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 388 | REPORTER_ASSERT(reporter, 3 == cache->getResourceCount()); |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 389 | REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + unique->gpuMemorySize() + |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 390 | unbudgeted->gpuMemorySize() == cache->getResourceBytes()); |
bsalomon | dace19e | 2014-11-17 07:34:06 -0800 | [diff] [blame] | 391 | |
bsalomon | 84c8e62 | 2014-11-17 09:33:27 -0800 | [diff] [blame] | 392 | // Now try freeing the budgeted resources first |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 393 | wrapped = SkNEW_ARGS(TestResource, (context->getGpu(), GrGpuResource::kWrapped_LifeCycle)); |
bsalomon | dace19e | 2014-11-17 07:34:06 -0800 | [diff] [blame] | 394 | scratch->setSize(12); |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 395 | unique->unref(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 396 | cache->purgeAllUnlocked(); |
| 397 | REPORTER_ASSERT(reporter, 3 == cache->getResourceCount()); |
bsalomon | 84c8e62 | 2014-11-17 09:33:27 -0800 | [diff] [blame] | 398 | REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + wrapped->gpuMemorySize() + |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 399 | unbudgeted->gpuMemorySize() == cache->getResourceBytes()); |
| 400 | REPORTER_ASSERT(reporter, 1 == cache->getBudgetedResourceCount()); |
| 401 | REPORTER_ASSERT(reporter, scratch->gpuMemorySize() == cache->getBudgetedResourceBytes()); |
bsalomon | dace19e | 2014-11-17 07:34:06 -0800 | [diff] [blame] | 402 | |
| 403 | scratch->unref(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 404 | cache->purgeAllUnlocked(); |
| 405 | REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); |
bsalomon | 84c8e62 | 2014-11-17 09:33:27 -0800 | [diff] [blame] | 406 | REPORTER_ASSERT(reporter, unbudgeted->gpuMemorySize() + wrapped->gpuMemorySize() == |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 407 | cache->getResourceBytes()); |
| 408 | REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceCount()); |
| 409 | REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceBytes()); |
bsalomon | dace19e | 2014-11-17 07:34:06 -0800 | [diff] [blame] | 410 | |
| 411 | wrapped->unref(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 412 | REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); |
| 413 | REPORTER_ASSERT(reporter, unbudgeted->gpuMemorySize() == cache->getResourceBytes()); |
| 414 | REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceCount()); |
| 415 | REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceBytes()); |
bsalomon | 84c8e62 | 2014-11-17 09:33:27 -0800 | [diff] [blame] | 416 | |
| 417 | unbudgeted->unref(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 418 | REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
| 419 | REPORTER_ASSERT(reporter, 0 == cache->getResourceBytes()); |
| 420 | REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceCount()); |
| 421 | REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceBytes()); |
bsalomon | dace19e | 2014-11-17 07:34:06 -0800 | [diff] [blame] | 422 | } |
| 423 | |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 424 | static void test_unbudgeted(skiatest::Reporter* reporter) { |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 425 | Mock mock(10, 30000); |
| 426 | GrContext* context = mock.context(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 427 | GrResourceCache* cache = mock.cache(); |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 428 | |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 429 | GrUniqueKey uniqueKey; |
| 430 | make_unique_key<0>(&uniqueKey, 0); |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 431 | |
| 432 | TestResource* scratch; |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 433 | TestResource* unique; |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 434 | TestResource* wrapped; |
| 435 | TestResource* unbudgeted; |
| 436 | |
| 437 | // A large uncached or wrapped resource shouldn't evict anything. |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 438 | scratch = TestResource::CreateScratch(context->getGpu(), TestResource::kB_SimulatedProperty); |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 439 | scratch->setSize(10); |
| 440 | scratch->unref(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 441 | REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); |
| 442 | REPORTER_ASSERT(reporter, 10 == cache->getResourceBytes()); |
| 443 | REPORTER_ASSERT(reporter, 1 == cache->getBudgetedResourceCount()); |
| 444 | REPORTER_ASSERT(reporter, 10 == cache->getBudgetedResourceBytes()); |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 445 | |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 446 | unique = SkNEW_ARGS(TestResource, (context->getGpu())); |
| 447 | unique->setSize(11); |
bsalomon | f99e961 | 2015-02-19 08:24:16 -0800 | [diff] [blame] | 448 | unique->resourcePriv().setUniqueKey(uniqueKey); |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 449 | unique->unref(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 450 | REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); |
| 451 | REPORTER_ASSERT(reporter, 21 == cache->getResourceBytes()); |
| 452 | REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount()); |
| 453 | REPORTER_ASSERT(reporter, 21 == cache->getBudgetedResourceBytes()); |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 454 | |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 455 | size_t large = 2 * cache->getResourceBytes(); |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 456 | unbudgeted = SkNEW_ARGS(TestResource, |
| 457 | (context->getGpu(), large, GrGpuResource::kUncached_LifeCycle)); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 458 | REPORTER_ASSERT(reporter, 3 == cache->getResourceCount()); |
| 459 | REPORTER_ASSERT(reporter, 21 + large == cache->getResourceBytes()); |
| 460 | REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount()); |
| 461 | REPORTER_ASSERT(reporter, 21 == cache->getBudgetedResourceBytes()); |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 462 | |
| 463 | unbudgeted->unref(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 464 | REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); |
| 465 | REPORTER_ASSERT(reporter, 21 == cache->getResourceBytes()); |
| 466 | REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount()); |
| 467 | REPORTER_ASSERT(reporter, 21 == cache->getBudgetedResourceBytes()); |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 468 | |
| 469 | wrapped = SkNEW_ARGS(TestResource, |
| 470 | (context->getGpu(), large, GrGpuResource::kWrapped_LifeCycle)); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 471 | REPORTER_ASSERT(reporter, 3 == cache->getResourceCount()); |
| 472 | REPORTER_ASSERT(reporter, 21 + large == cache->getResourceBytes()); |
| 473 | REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount()); |
| 474 | REPORTER_ASSERT(reporter, 21 == cache->getBudgetedResourceBytes()); |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 475 | |
| 476 | wrapped->unref(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 477 | REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); |
| 478 | REPORTER_ASSERT(reporter, 21 == cache->getResourceBytes()); |
| 479 | REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount()); |
| 480 | REPORTER_ASSERT(reporter, 21 == cache->getBudgetedResourceBytes()); |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 481 | |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 482 | cache->purgeAllUnlocked(); |
| 483 | REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
| 484 | REPORTER_ASSERT(reporter, 0 == cache->getResourceBytes()); |
| 485 | REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceCount()); |
| 486 | REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceBytes()); |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 487 | } |
| 488 | |
bsalomon | 3582d3e | 2015-02-13 14:20:05 -0800 | [diff] [blame] | 489 | // This method can't be static because it needs to friended in GrGpuResource::CacheAccess. |
| 490 | void test_unbudgeted_to_scratch(skiatest::Reporter* reporter); |
| 491 | /*static*/ void test_unbudgeted_to_scratch(skiatest::Reporter* reporter) { |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 492 | Mock mock(10, 300); |
| 493 | GrContext* context = mock.context(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 494 | GrResourceCache* cache = mock.cache(); |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 495 | |
| 496 | TestResource* resource = |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 497 | TestResource::CreateScratch(context->getGpu(), TestResource::kA_SimulatedProperty, false); |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 498 | GrScratchKey key; |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 499 | TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &key); |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 500 | |
| 501 | size_t size = resource->gpuMemorySize(); |
| 502 | for (int i = 0; i < 2; ++i) { |
| 503 | // Since this resource is unbudgeted, it should not be reachable as scratch. |
bsalomon | 3582d3e | 2015-02-13 14:20:05 -0800 | [diff] [blame] | 504 | REPORTER_ASSERT(reporter, resource->resourcePriv().getScratchKey() == key); |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 505 | REPORTER_ASSERT(reporter, !resource->cacheAccess().isScratch()); |
bsalomon | 3582d3e | 2015-02-13 14:20:05 -0800 | [diff] [blame] | 506 | REPORTER_ASSERT(reporter, !resource->resourcePriv().isBudgeted()); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 507 | REPORTER_ASSERT(reporter, NULL == cache->findAndRefScratchResource(key)); |
| 508 | REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); |
| 509 | REPORTER_ASSERT(reporter, size == cache->getResourceBytes()); |
| 510 | REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceCount()); |
| 511 | REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceBytes()); |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 512 | |
| 513 | // Once it is unrefed, it should become available as scratch. |
| 514 | resource->unref(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 515 | REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); |
| 516 | REPORTER_ASSERT(reporter, size == cache->getResourceBytes()); |
| 517 | REPORTER_ASSERT(reporter, 1 == cache->getBudgetedResourceCount()); |
| 518 | REPORTER_ASSERT(reporter, size == cache->getBudgetedResourceBytes()); |
| 519 | resource = static_cast<TestResource*>(cache->findAndRefScratchResource(key)); |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 520 | REPORTER_ASSERT(reporter, resource); |
bsalomon | 3582d3e | 2015-02-13 14:20:05 -0800 | [diff] [blame] | 521 | REPORTER_ASSERT(reporter, resource->resourcePriv().getScratchKey() == key); |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 522 | REPORTER_ASSERT(reporter, resource->cacheAccess().isScratch()); |
bsalomon | 3582d3e | 2015-02-13 14:20:05 -0800 | [diff] [blame] | 523 | REPORTER_ASSERT(reporter, resource->resourcePriv().isBudgeted()); |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 524 | |
| 525 | if (0 == i) { |
| 526 | // If made unbudgeted, it should return to original state: ref'ed and unbudgeted. Try |
| 527 | // the above tests again. |
bsalomon | 3582d3e | 2015-02-13 14:20:05 -0800 | [diff] [blame] | 528 | resource->resourcePriv().makeUnbudgeted(); |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 529 | } else { |
| 530 | // After the second time around, try removing the scratch key |
bsalomon | 3582d3e | 2015-02-13 14:20:05 -0800 | [diff] [blame] | 531 | resource->resourcePriv().removeScratchKey(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 532 | REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); |
| 533 | REPORTER_ASSERT(reporter, size == cache->getResourceBytes()); |
| 534 | REPORTER_ASSERT(reporter, 1 == cache->getBudgetedResourceCount()); |
| 535 | REPORTER_ASSERT(reporter, size == cache->getBudgetedResourceBytes()); |
bsalomon | 3582d3e | 2015-02-13 14:20:05 -0800 | [diff] [blame] | 536 | REPORTER_ASSERT(reporter, !resource->resourcePriv().getScratchKey().isValid()); |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 537 | REPORTER_ASSERT(reporter, !resource->cacheAccess().isScratch()); |
bsalomon | 3582d3e | 2015-02-13 14:20:05 -0800 | [diff] [blame] | 538 | REPORTER_ASSERT(reporter, resource->resourcePriv().isBudgeted()); |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 539 | |
| 540 | // now when it is unrefed it should die since it has no key. |
| 541 | resource->unref(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 542 | REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
| 543 | REPORTER_ASSERT(reporter, 0 == cache->getResourceBytes()); |
| 544 | REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceCount()); |
| 545 | REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceBytes()); |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 546 | } |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 547 | } |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | static void test_duplicate_scratch_key(skiatest::Reporter* reporter) { |
| 551 | Mock mock(5, 30000); |
| 552 | GrContext* context = mock.context(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 553 | GrResourceCache* cache = mock.cache(); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 554 | |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 555 | // Create two resources that have the same scratch key. |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 556 | TestResource* a = TestResource::CreateScratch(context->getGpu(), |
| 557 | TestResource::kB_SimulatedProperty); |
| 558 | TestResource* b = TestResource::CreateScratch(context->getGpu(), |
| 559 | TestResource::kB_SimulatedProperty); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 560 | a->setSize(11); |
| 561 | b->setSize(12); |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 562 | GrScratchKey scratchKey1; |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 563 | TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &scratchKey1); |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 564 | // Check for negative case consistency. (leaks upon test failure.) |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 565 | REPORTER_ASSERT(reporter, NULL == cache->findAndRefScratchResource(scratchKey1)); |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 566 | |
| 567 | GrScratchKey scratchKey; |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 568 | TestResource::ComputeScratchKey(TestResource::kB_SimulatedProperty, &scratchKey); |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 569 | |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 570 | // Scratch resources are registered with GrResourceCache just by existing. There are 2. |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 571 | REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 572 | SkDEBUGCODE(REPORTER_ASSERT(reporter, 2 == cache->countScratchEntriesForKey(scratchKey));) |
| 573 | REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 574 | REPORTER_ASSERT(reporter, a->gpuMemorySize() + b->gpuMemorySize() == |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 575 | cache->getResourceBytes()); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 576 | |
bsalomon | 63c992f | 2015-01-23 12:47:59 -0800 | [diff] [blame] | 577 | // Our refs mean that the resources are non purgeable. |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 578 | cache->purgeAllUnlocked(); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 579 | REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 580 | REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 581 | |
| 582 | // Unref but don't purge |
| 583 | a->unref(); |
| 584 | b->unref(); |
| 585 | REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 586 | SkDEBUGCODE(REPORTER_ASSERT(reporter, 2 == cache->countScratchEntriesForKey(scratchKey));) |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 587 | |
bsalomon | 63c992f | 2015-01-23 12:47:59 -0800 | [diff] [blame] | 588 | // Purge again. This time resources should be purgeable. |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 589 | cache->purgeAllUnlocked(); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 590 | REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive()); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 591 | REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
| 592 | SkDEBUGCODE(REPORTER_ASSERT(reporter, 0 == cache->countScratchEntriesForKey(scratchKey));) |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 593 | } |
| 594 | |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 595 | static void test_remove_scratch_key(skiatest::Reporter* reporter) { |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 596 | Mock mock(5, 30000); |
| 597 | GrContext* context = mock.context(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 598 | GrResourceCache* cache = mock.cache(); |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 599 | |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 600 | // Create two resources that have the same scratch key. |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 601 | TestResource* a = TestResource::CreateScratch(context->getGpu(), |
| 602 | TestResource::kB_SimulatedProperty); |
| 603 | TestResource* b = TestResource::CreateScratch(context->getGpu(), |
| 604 | TestResource::kB_SimulatedProperty); |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 605 | a->unref(); |
| 606 | b->unref(); |
| 607 | |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 608 | GrScratchKey scratchKey; |
| 609 | // Ensure that scratch key lookup is correct for negative case. |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 610 | TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &scratchKey); |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 611 | // (following leaks upon test failure). |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 612 | REPORTER_ASSERT(reporter, cache->findAndRefScratchResource(scratchKey) == NULL); |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 613 | |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 614 | // Scratch resources are registered with GrResourceCache just by existing. There are 2. |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 615 | TestResource::ComputeScratchKey(TestResource::kB_SimulatedProperty, &scratchKey); |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 616 | REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 617 | SkDEBUGCODE(REPORTER_ASSERT(reporter, 2 == cache->countScratchEntriesForKey(scratchKey));) |
| 618 | REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 619 | |
| 620 | // Find the first resource and remove its scratch key |
| 621 | GrGpuResource* find; |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 622 | find = cache->findAndRefScratchResource(scratchKey); |
bsalomon | 3582d3e | 2015-02-13 14:20:05 -0800 | [diff] [blame] | 623 | find->resourcePriv().removeScratchKey(); |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 624 | // It's still alive, but not cached by scratch key anymore |
| 625 | REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 626 | SkDEBUGCODE(REPORTER_ASSERT(reporter, 1 == cache->countScratchEntriesForKey(scratchKey));) |
| 627 | REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 628 | |
| 629 | // The cache should immediately delete it when it's unrefed since it isn't accessible. |
| 630 | find->unref(); |
| 631 | REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive()); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 632 | SkDEBUGCODE(REPORTER_ASSERT(reporter, 1 == cache->countScratchEntriesForKey(scratchKey));) |
| 633 | REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 634 | |
| 635 | // Repeat for the second resource. |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 636 | find = cache->findAndRefScratchResource(scratchKey); |
bsalomon | 3582d3e | 2015-02-13 14:20:05 -0800 | [diff] [blame] | 637 | find->resourcePriv().removeScratchKey(); |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 638 | REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive()); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 639 | SkDEBUGCODE(REPORTER_ASSERT(reporter, 0 == cache->countScratchEntriesForKey(scratchKey));) |
| 640 | REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 641 | |
| 642 | // Should be able to call this multiple times with no problem. |
bsalomon | 3582d3e | 2015-02-13 14:20:05 -0800 | [diff] [blame] | 643 | find->resourcePriv().removeScratchKey(); |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 644 | REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive()); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 645 | SkDEBUGCODE(REPORTER_ASSERT(reporter, 0 == cache->countScratchEntriesForKey(scratchKey));) |
| 646 | REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 647 | |
| 648 | find->unref(); |
| 649 | REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive()); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 650 | SkDEBUGCODE(REPORTER_ASSERT(reporter, 0 == cache->countScratchEntriesForKey(scratchKey));) |
| 651 | REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 652 | } |
| 653 | |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 654 | static void test_scratch_key_consistency(skiatest::Reporter* reporter) { |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 655 | Mock mock(5, 30000); |
| 656 | GrContext* context = mock.context(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 657 | GrResourceCache* cache = mock.cache(); |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 658 | |
| 659 | // Create two resources that have the same scratch key. |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 660 | TestResource* a = TestResource::CreateScratch(context->getGpu(), |
| 661 | TestResource::kB_SimulatedProperty); |
| 662 | TestResource* b = TestResource::CreateScratch(context->getGpu(), |
| 663 | TestResource::kB_SimulatedProperty); |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 664 | a->unref(); |
| 665 | b->unref(); |
| 666 | |
| 667 | GrScratchKey scratchKey; |
| 668 | // Ensure that scratch key comparison and assignment is consistent. |
| 669 | GrScratchKey scratchKey1; |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 670 | TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &scratchKey1); |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 671 | GrScratchKey scratchKey2; |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 672 | TestResource::ComputeScratchKey(TestResource::kB_SimulatedProperty, &scratchKey2); |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 673 | REPORTER_ASSERT(reporter, scratchKey1.size() == TestResource::ExpectedScratchKeySize()); |
| 674 | REPORTER_ASSERT(reporter, scratchKey1 != scratchKey2); |
| 675 | REPORTER_ASSERT(reporter, scratchKey2 != scratchKey1); |
| 676 | scratchKey = scratchKey1; |
| 677 | REPORTER_ASSERT(reporter, scratchKey.size() == TestResource::ExpectedScratchKeySize()); |
| 678 | REPORTER_ASSERT(reporter, scratchKey1 == scratchKey); |
| 679 | REPORTER_ASSERT(reporter, scratchKey == scratchKey1); |
| 680 | REPORTER_ASSERT(reporter, scratchKey2 != scratchKey); |
| 681 | REPORTER_ASSERT(reporter, scratchKey != scratchKey2); |
| 682 | scratchKey = scratchKey2; |
| 683 | REPORTER_ASSERT(reporter, scratchKey.size() == TestResource::ExpectedScratchKeySize()); |
| 684 | REPORTER_ASSERT(reporter, scratchKey1 != scratchKey); |
| 685 | REPORTER_ASSERT(reporter, scratchKey != scratchKey1); |
| 686 | REPORTER_ASSERT(reporter, scratchKey2 == scratchKey); |
| 687 | REPORTER_ASSERT(reporter, scratchKey == scratchKey2); |
| 688 | |
| 689 | // Ensure that scratch key lookup is correct for negative case. |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 690 | TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &scratchKey); |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 691 | // (following leaks upon test failure). |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 692 | REPORTER_ASSERT(reporter, cache->findAndRefScratchResource(scratchKey) == NULL); |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 693 | |
| 694 | // Find the first resource with a scratch key and a copy of a scratch key. |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 695 | TestResource::ComputeScratchKey(TestResource::kB_SimulatedProperty, &scratchKey); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 696 | GrGpuResource* find = cache->findAndRefScratchResource(scratchKey); |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 697 | REPORTER_ASSERT(reporter, find != NULL); |
| 698 | find->unref(); |
| 699 | |
| 700 | scratchKey2 = scratchKey; |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 701 | find = cache->findAndRefScratchResource(scratchKey2); |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 702 | REPORTER_ASSERT(reporter, find != NULL); |
| 703 | REPORTER_ASSERT(reporter, find == a || find == b); |
| 704 | |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 705 | GrGpuResource* find2 = cache->findAndRefScratchResource(scratchKey2); |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 706 | REPORTER_ASSERT(reporter, find2 != NULL); |
| 707 | REPORTER_ASSERT(reporter, find2 == a || find2 == b); |
| 708 | REPORTER_ASSERT(reporter, find2 != find); |
| 709 | find2->unref(); |
| 710 | find->unref(); |
| 711 | } |
| 712 | |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 713 | static void test_duplicate_unique_key(skiatest::Reporter* reporter) { |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 714 | Mock mock(5, 30000); |
| 715 | GrContext* context = mock.context(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 716 | GrResourceCache* cache = mock.cache(); |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 717 | |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 718 | GrUniqueKey key; |
| 719 | make_unique_key<0>(&key, 0); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 720 | |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 721 | // Create two resources that we will attempt to register with the same unique key. |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 722 | TestResource* a = SkNEW_ARGS(TestResource, (context->getGpu())); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 723 | a->setSize(11); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 724 | |
bsalomon | f99e961 | 2015-02-19 08:24:16 -0800 | [diff] [blame] | 725 | // Set key on resource a. |
| 726 | a->resourcePriv().setUniqueKey(key); |
| 727 | REPORTER_ASSERT(reporter, a == cache->findAndRefUniqueResource(key)); |
| 728 | a->unref(); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 729 | |
bsalomon | f99e961 | 2015-02-19 08:24:16 -0800 | [diff] [blame] | 730 | // Make sure that redundantly setting a's key works. |
| 731 | a->resourcePriv().setUniqueKey(key); |
| 732 | REPORTER_ASSERT(reporter, a == cache->findAndRefUniqueResource(key)); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 733 | a->unref(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 734 | REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); |
| 735 | REPORTER_ASSERT(reporter, a->gpuMemorySize() == cache->getResourceBytes()); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 736 | REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive()); |
| 737 | |
bsalomon | f99e961 | 2015-02-19 08:24:16 -0800 | [diff] [blame] | 738 | // Create resource b and set the same key. It should replace a's unique key cache entry. |
| 739 | TestResource* b = SkNEW_ARGS(TestResource, (context->getGpu())); |
| 740 | b->setSize(12); |
| 741 | b->resourcePriv().setUniqueKey(key); |
| 742 | REPORTER_ASSERT(reporter, b == cache->findAndRefUniqueResource(key)); |
| 743 | b->unref(); |
| 744 | |
| 745 | // Still have two resources because a is still reffed. |
| 746 | REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); |
| 747 | REPORTER_ASSERT(reporter, a->gpuMemorySize() + b->gpuMemorySize() == cache->getResourceBytes()); |
| 748 | REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); |
| 749 | |
| 750 | a->unref(); |
| 751 | // Now a should be gone. |
| 752 | REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); |
| 753 | REPORTER_ASSERT(reporter, b->gpuMemorySize() == cache->getResourceBytes()); |
| 754 | REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive()); |
| 755 | |
| 756 | // Now replace b with c, but make sure c can start with one unique key and change it to b's key. |
| 757 | // Also make b be unreffed when replacement occurs. |
| 758 | b->unref(); |
| 759 | TestResource* c = SkNEW_ARGS(TestResource, (context->getGpu())); |
| 760 | GrUniqueKey differentKey; |
| 761 | make_unique_key<0>(&differentKey, 1); |
| 762 | c->setSize(13); |
| 763 | c->resourcePriv().setUniqueKey(differentKey); |
| 764 | REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); |
| 765 | REPORTER_ASSERT(reporter, b->gpuMemorySize() + c->gpuMemorySize() == cache->getResourceBytes()); |
| 766 | REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); |
| 767 | // c replaces b and b should be immediately purged. |
| 768 | c->resourcePriv().setUniqueKey(key); |
| 769 | REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); |
| 770 | REPORTER_ASSERT(reporter, c->gpuMemorySize() == cache->getResourceBytes()); |
| 771 | REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive()); |
| 772 | |
| 773 | // c shouldn't be purged because it is ref'ed. |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 774 | cache->purgeAllUnlocked(); |
bsalomon | f99e961 | 2015-02-19 08:24:16 -0800 | [diff] [blame] | 775 | REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); |
| 776 | REPORTER_ASSERT(reporter, c->gpuMemorySize() == cache->getResourceBytes()); |
| 777 | REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive()); |
| 778 | |
| 779 | // Drop the ref on c, it should be kept alive because it has a unique key. |
| 780 | c->unref(); |
| 781 | REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); |
| 782 | REPORTER_ASSERT(reporter, c->gpuMemorySize() == cache->getResourceBytes()); |
| 783 | REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive()); |
| 784 | |
| 785 | // Verify that we can find c, then remove its unique key. It should get purged immediately. |
| 786 | REPORTER_ASSERT(reporter, c == cache->findAndRefUniqueResource(key)); |
| 787 | c->resourcePriv().removeUniqueKey(); |
| 788 | c->unref(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 789 | REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
| 790 | REPORTER_ASSERT(reporter, 0 == cache->getResourceBytes()); |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 791 | REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive()); |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 792 | } |
| 793 | |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 794 | static void test_purge_invalidated(skiatest::Reporter* reporter) { |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 795 | Mock mock(5, 30000); |
| 796 | GrContext* context = mock.context(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 797 | GrResourceCache* cache = mock.cache(); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 798 | |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 799 | GrUniqueKey key1, key2, key3; |
| 800 | make_unique_key<0>(&key1, 1); |
| 801 | make_unique_key<0>(&key2, 2); |
| 802 | make_unique_key<0>(&key3, 3); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 803 | |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 804 | // Add three resources to the cache. Only c is usable as scratch. |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 805 | TestResource* a = SkNEW_ARGS(TestResource, (context->getGpu())); |
| 806 | TestResource* b = SkNEW_ARGS(TestResource, (context->getGpu())); |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 807 | TestResource* c = TestResource::CreateScratch(context->getGpu(), |
| 808 | TestResource::kA_SimulatedProperty); |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 809 | a->resourcePriv().setUniqueKey(key1); |
| 810 | b->resourcePriv().setUniqueKey(key2); |
| 811 | c->resourcePriv().setUniqueKey(key3); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 812 | a->unref(); |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 813 | // hold b until *after* the message is sent. |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 814 | c->unref(); |
| 815 | |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 816 | REPORTER_ASSERT(reporter, cache->hasUniqueKey(key1)); |
| 817 | REPORTER_ASSERT(reporter, cache->hasUniqueKey(key2)); |
| 818 | REPORTER_ASSERT(reporter, cache->hasUniqueKey(key3)); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 819 | REPORTER_ASSERT(reporter, 3 == TestResource::NumAlive()); |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 820 | |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 821 | typedef GrUniqueKeyInvalidatedMessage Msg; |
| 822 | typedef SkMessageBus<GrUniqueKeyInvalidatedMessage> Bus; |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 823 | |
| 824 | // Invalidate two of the three, they should be purged and no longer accessible via their keys. |
| 825 | Bus::Post(Msg(key1)); |
| 826 | Bus::Post(Msg(key2)); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 827 | cache->purgeAsNeeded(); |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 828 | // a should be deleted now, but we still have a ref on b. |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 829 | REPORTER_ASSERT(reporter, !cache->hasUniqueKey(key1)); |
| 830 | REPORTER_ASSERT(reporter, !cache->hasUniqueKey(key2)); |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 831 | REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 832 | REPORTER_ASSERT(reporter, cache->hasUniqueKey(key3)); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 833 | |
| 834 | // Invalidate the third. |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 835 | Bus::Post(Msg(key3)); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 836 | cache->purgeAsNeeded(); |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 837 | // we still have a ref on b, c should be recycled as scratch. |
| 838 | REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 839 | REPORTER_ASSERT(reporter, !cache->hasUniqueKey(key3)); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 840 | |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 841 | // make b purgeable. It should be immediately deleted since it has no key. |
| 842 | b->unref(); |
| 843 | REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive()); |
| 844 | |
| 845 | // Make sure we actually get to c via it's scratch key, before we say goodbye. |
| 846 | GrScratchKey scratchKey; |
| 847 | TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &scratchKey); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 848 | GrGpuResource* scratch = cache->findAndRefScratchResource(scratchKey); |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 849 | REPORTER_ASSERT(reporter, scratch == c); |
| 850 | SkSafeUnref(scratch); |
| 851 | |
| 852 | // Get rid of c. |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 853 | cache->purgeAllUnlocked(); |
| 854 | scratch = cache->findAndRefScratchResource(scratchKey); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 855 | REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive()); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 856 | REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
| 857 | REPORTER_ASSERT(reporter, 0 == cache->getResourceBytes()); |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 858 | REPORTER_ASSERT(reporter, !scratch); |
| 859 | SkSafeUnref(scratch); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 860 | } |
| 861 | |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 862 | static void test_cache_chained_purge(skiatest::Reporter* reporter) { |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 863 | Mock mock(3, 30000); |
| 864 | GrContext* context = mock.context(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 865 | GrResourceCache* cache = mock.cache(); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 866 | |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 867 | GrUniqueKey key1, key2; |
| 868 | make_unique_key<0>(&key1, 1); |
| 869 | make_unique_key<0>(&key2, 2); |
commit-bot@chromium.org | bd58feb | 2014-01-17 17:56:21 +0000 | [diff] [blame] | 870 | |
commit-bot@chromium.org | bd58feb | 2014-01-17 17:56:21 +0000 | [diff] [blame] | 871 | |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 872 | TestResource* a = SkNEW_ARGS(TestResource, (context->getGpu())); |
| 873 | TestResource* b = SkNEW_ARGS(TestResource, (context->getGpu())); |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 874 | a->resourcePriv().setUniqueKey(key1); |
| 875 | b->resourcePriv().setUniqueKey(key2); |
bsalomon | 820dd6c | 2014-11-05 12:09:45 -0800 | [diff] [blame] | 876 | |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 877 | // Make a cycle |
| 878 | a->setUnrefWhenDestroyed(b); |
| 879 | b->setUnrefWhenDestroyed(a); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 880 | |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 881 | REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 882 | |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 883 | a->unref(); |
| 884 | b->unref(); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 885 | |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 886 | REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 887 | |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 888 | cache->purgeAllUnlocked(); |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 889 | REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 890 | |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 891 | // Break the cycle |
| 892 | a->setUnrefWhenDestroyed(NULL); |
| 893 | REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 894 | |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 895 | cache->purgeAllUnlocked(); |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 896 | REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive()); |
commit-bot@chromium.org | bd58feb | 2014-01-17 17:56:21 +0000 | [diff] [blame] | 897 | } |
| 898 | |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 899 | static void test_resource_size_changed(skiatest::Reporter* reporter) { |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 900 | GrUniqueKey key1, key2; |
| 901 | make_unique_key<0>(&key1, 1); |
| 902 | make_unique_key<0>(&key2, 2); |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 903 | |
| 904 | // Test changing resources sizes (both increase & decrease). |
| 905 | { |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 906 | Mock mock(3, 30000); |
| 907 | GrContext* context = mock.context(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 908 | GrResourceCache* cache = mock.cache(); |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 909 | |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 910 | TestResource* a = SkNEW_ARGS(TestResource, (context->getGpu())); |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 911 | a->resourcePriv().setUniqueKey(key1); |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 912 | a->unref(); |
| 913 | |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 914 | TestResource* b = SkNEW_ARGS(TestResource, (context->getGpu())); |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 915 | b->resourcePriv().setUniqueKey(key2); |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 916 | b->unref(); |
| 917 | |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 918 | REPORTER_ASSERT(reporter, 200 == cache->getResourceBytes()); |
| 919 | REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 920 | { |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 921 | SkAutoTUnref<TestResource> find2( |
| 922 | static_cast<TestResource*>(cache->findAndRefUniqueResource(key2))); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 923 | find2->setSize(200); |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 924 | SkAutoTUnref<TestResource> find1( |
| 925 | static_cast<TestResource*>(cache->findAndRefUniqueResource(key1))); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 926 | find1->setSize(50); |
| 927 | } |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 928 | |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 929 | REPORTER_ASSERT(reporter, 250 == cache->getResourceBytes()); |
| 930 | REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 931 | } |
| 932 | |
| 933 | // Test increasing a resources size beyond the cache budget. |
| 934 | { |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 935 | Mock mock(2, 300); |
| 936 | GrContext* context = mock.context(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 937 | GrResourceCache* cache = mock.cache(); |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 938 | |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 939 | TestResource* a = SkNEW_ARGS(TestResource, (context->getGpu())); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 940 | a->setSize(100); |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 941 | a->resourcePriv().setUniqueKey(key1); |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 942 | a->unref(); |
| 943 | |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 944 | TestResource* b = SkNEW_ARGS(TestResource, (context->getGpu())); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 945 | b->setSize(100); |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 946 | b->resourcePriv().setUniqueKey(key2); |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 947 | b->unref(); |
| 948 | |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 949 | REPORTER_ASSERT(reporter, 200 == cache->getResourceBytes()); |
| 950 | REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 951 | |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 952 | { |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 953 | SkAutoTUnref<TestResource> find2(static_cast<TestResource*>( |
| 954 | cache->findAndRefUniqueResource(key2))); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 955 | find2->setSize(201); |
| 956 | } |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 957 | REPORTER_ASSERT(reporter, !cache->hasUniqueKey(key1)); |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 958 | |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 959 | REPORTER_ASSERT(reporter, 201 == cache->getResourceBytes()); |
| 960 | REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 961 | } |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 962 | } |
| 963 | |
bsalomon | ddf30e6 | 2015-02-19 11:38:44 -0800 | [diff] [blame] | 964 | static void test_timestamp_wrap(skiatest::Reporter* reporter) { |
| 965 | static const int kCount = 50; |
| 966 | static const int kBudgetCnt = kCount / 2; |
| 967 | static const int kLockedFreq = 8; |
| 968 | static const int kBudgetSize = 0x80000000; |
| 969 | |
| 970 | SkRandom random; |
| 971 | |
| 972 | // Run the test 2*kCount times; |
| 973 | for (int i = 0; i < 2 * kCount; ++i ) { |
| 974 | Mock mock(kBudgetCnt, kBudgetSize); |
| 975 | GrContext* context = mock.context(); |
| 976 | GrResourceCache* cache = mock.cache(); |
| 977 | |
| 978 | // Pick a random number of resources to add before the timestamp will wrap. |
| 979 | cache->changeTimestamp(SK_MaxU32 - random.nextULessThan(kCount + 1)); |
| 980 | |
| 981 | static const int kNumToPurge = kCount - kBudgetCnt; |
| 982 | |
| 983 | SkTDArray<int> shouldPurgeIdxs; |
| 984 | int purgeableCnt = 0; |
| 985 | SkTDArray<GrGpuResource*> resourcesToUnref; |
| 986 | |
| 987 | // Add kCount resources, holding onto resources at random so we have a mix of purgeable and |
| 988 | // unpurgeable resources. |
| 989 | for (int j = 0; j < kCount; ++j) { |
| 990 | GrUniqueKey key; |
| 991 | make_unique_key<0>(&key, j); |
| 992 | |
| 993 | TestResource* r = SkNEW_ARGS(TestResource, (context->getGpu())); |
| 994 | r->resourcePriv().setUniqueKey(key); |
| 995 | if (random.nextU() % kLockedFreq) { |
| 996 | // Make this is purgeable. |
| 997 | r->unref(); |
| 998 | ++purgeableCnt; |
| 999 | if (purgeableCnt <= kNumToPurge) { |
| 1000 | *shouldPurgeIdxs.append() = j; |
| 1001 | } |
| 1002 | } else { |
| 1003 | *resourcesToUnref.append() = r; |
| 1004 | } |
| 1005 | } |
| 1006 | |
| 1007 | // Verify that the correct resources were purged. |
| 1008 | int currShouldPurgeIdx = 0; |
| 1009 | for (int j = 0; j < kCount; ++j) { |
| 1010 | GrUniqueKey key; |
| 1011 | make_unique_key<0>(&key, j); |
| 1012 | GrGpuResource* res = cache->findAndRefUniqueResource(key); |
| 1013 | if (currShouldPurgeIdx < shouldPurgeIdxs.count() && |
| 1014 | shouldPurgeIdxs[currShouldPurgeIdx] == j) { |
| 1015 | ++currShouldPurgeIdx; |
| 1016 | REPORTER_ASSERT(reporter, NULL == res); |
| 1017 | } else { |
| 1018 | REPORTER_ASSERT(reporter, NULL != res); |
| 1019 | } |
| 1020 | SkSafeUnref(res); |
| 1021 | } |
| 1022 | |
| 1023 | for (int j = 0; j < resourcesToUnref.count(); ++j) { |
| 1024 | resourcesToUnref[j]->unref(); |
| 1025 | } |
| 1026 | } |
| 1027 | } |
| 1028 | |
bsalomon | 3f32432 | 2015-04-08 11:01:54 -0700 | [diff] [blame] | 1029 | static void test_flush(skiatest::Reporter* reporter) { |
| 1030 | Mock mock(1000000, 1000000); |
| 1031 | GrContext* context = mock.context(); |
| 1032 | GrResourceCache* cache = mock.cache(); |
| 1033 | |
| 1034 | // The current cache impl will round the max flush count to the next power of 2. So we choose a |
| 1035 | // power of two here to keep things simpler. |
| 1036 | static const int kFlushCount = 16; |
| 1037 | cache->setLimits(1000000, 1000000, kFlushCount); |
| 1038 | |
| 1039 | { |
| 1040 | // Insert a resource and send a flush notification kFlushCount times. |
| 1041 | for (int i = 0; i < kFlushCount; ++i) { |
| 1042 | TestResource* r = SkNEW_ARGS(TestResource, (context->getGpu())); |
| 1043 | GrUniqueKey k; |
| 1044 | make_unique_key<1>(&k, i); |
| 1045 | r->resourcePriv().setUniqueKey(k); |
| 1046 | r->unref(); |
| 1047 | cache->notifyFlushOccurred(); |
| 1048 | } |
| 1049 | |
| 1050 | // Send flush notifications to the cache. Each flush should purge the oldest resource. |
| 1051 | for (int i = 0; i < kFlushCount - 1; ++i) { |
| 1052 | // The first resource was purged after the last flush in the initial loop, hence the -1. |
| 1053 | REPORTER_ASSERT(reporter, kFlushCount - i - 1 == cache->getResourceCount()); |
| 1054 | for (int j = 0; j < i; ++j) { |
| 1055 | GrUniqueKey k; |
| 1056 | make_unique_key<1>(&k, j); |
| 1057 | GrGpuResource* r = cache->findAndRefUniqueResource(k); |
| 1058 | REPORTER_ASSERT(reporter, !SkToBool(r)); |
| 1059 | SkSafeUnref(r); |
| 1060 | } |
| 1061 | cache->notifyFlushOccurred(); |
| 1062 | } |
| 1063 | |
| 1064 | REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
| 1065 | cache->purgeAllUnlocked(); |
| 1066 | } |
| 1067 | |
| 1068 | // Do a similar test but where we leave refs on some resources to prevent them from being |
| 1069 | // purged. |
| 1070 | { |
| 1071 | GrGpuResource* refedResources[kFlushCount >> 1]; |
| 1072 | for (int i = 0; i < kFlushCount; ++i) { |
| 1073 | TestResource* r = SkNEW_ARGS(TestResource, (context->getGpu())); |
| 1074 | GrUniqueKey k; |
| 1075 | make_unique_key<1>(&k, i); |
| 1076 | r->resourcePriv().setUniqueKey(k); |
| 1077 | // Leave a ref on every other resource, beginning with the first. |
| 1078 | if (SkToBool(i & 0x1)) { |
| 1079 | refedResources[i/2] = r; |
| 1080 | } else { |
| 1081 | r->unref(); |
| 1082 | } |
| 1083 | cache->notifyFlushOccurred(); |
| 1084 | } |
| 1085 | |
| 1086 | for (int i = 0; i < kFlushCount; ++i) { |
| 1087 | // Should get a resource purged every other flush. |
| 1088 | REPORTER_ASSERT(reporter, kFlushCount - i/2 - 1 == cache->getResourceCount()); |
| 1089 | cache->notifyFlushOccurred(); |
| 1090 | } |
| 1091 | |
| 1092 | // Unref all the resources that we kept refs on in the first loop. |
| 1093 | for (int i = 0; i < kFlushCount >> 1; ++i) { |
| 1094 | refedResources[i]->unref(); |
| 1095 | } |
| 1096 | |
| 1097 | // When we unref'ed them their timestamps got updated. So nothing should be purged until we |
| 1098 | // get kFlushCount additional flushes. Then everything should be purged. |
| 1099 | for (int i = 0; i < kFlushCount; ++i) { |
| 1100 | REPORTER_ASSERT(reporter, kFlushCount >> 1 == cache->getResourceCount()); |
| 1101 | cache->notifyFlushOccurred(); |
| 1102 | } |
| 1103 | REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
| 1104 | |
| 1105 | cache->purgeAllUnlocked(); |
| 1106 | } |
| 1107 | |
| 1108 | REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
| 1109 | } |
| 1110 | |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 1111 | static void test_large_resource_count(skiatest::Reporter* reporter) { |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 1112 | // Set the cache size to double the resource count because we're going to create 2x that number |
| 1113 | // resources, using two different key domains. Add a little slop to the bytes because we resize |
| 1114 | // down to 1 byte after creating the resource. |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 1115 | static const int kResourceCnt = 2000; |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 1116 | |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 1117 | Mock mock(2 * kResourceCnt, 2 * kResourceCnt + 1000); |
| 1118 | GrContext* context = mock.context(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 1119 | GrResourceCache* cache = mock.cache(); |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 1120 | |
| 1121 | for (int i = 0; i < kResourceCnt; ++i) { |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 1122 | GrUniqueKey key1, key2; |
| 1123 | make_unique_key<1>(&key1, i); |
| 1124 | make_unique_key<2>(&key2, i); |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 1125 | |
bsalomon | 24db3b1 | 2015-01-23 04:24:04 -0800 | [diff] [blame] | 1126 | TestResource* resource; |
| 1127 | |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 1128 | resource = SkNEW_ARGS(TestResource, (context->getGpu())); |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 1129 | resource->resourcePriv().setUniqueKey(key1); |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 1130 | resource->setSize(1); |
| 1131 | resource->unref(); |
| 1132 | |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 1133 | resource = SkNEW_ARGS(TestResource, (context->getGpu())); |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 1134 | resource->resourcePriv().setUniqueKey(key2); |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 1135 | resource->setSize(1); |
| 1136 | resource->unref(); |
| 1137 | } |
| 1138 | |
| 1139 | REPORTER_ASSERT(reporter, TestResource::NumAlive() == 2 * kResourceCnt); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 1140 | REPORTER_ASSERT(reporter, cache->getBudgetedResourceBytes() == 2 * kResourceCnt); |
| 1141 | REPORTER_ASSERT(reporter, cache->getBudgetedResourceCount() == 2 * kResourceCnt); |
| 1142 | REPORTER_ASSERT(reporter, cache->getResourceBytes() == 2 * kResourceCnt); |
| 1143 | REPORTER_ASSERT(reporter, cache->getResourceCount() == 2 * kResourceCnt); |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 1144 | for (int i = 0; i < kResourceCnt; ++i) { |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 1145 | GrUniqueKey key1, key2; |
| 1146 | make_unique_key<1>(&key1, i); |
| 1147 | make_unique_key<2>(&key2, i); |
bsalomon | 24db3b1 | 2015-01-23 04:24:04 -0800 | [diff] [blame] | 1148 | |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 1149 | REPORTER_ASSERT(reporter, cache->hasUniqueKey(key1)); |
| 1150 | REPORTER_ASSERT(reporter, cache->hasUniqueKey(key2)); |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 1151 | } |
| 1152 | |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 1153 | cache->purgeAllUnlocked(); |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 1154 | REPORTER_ASSERT(reporter, TestResource::NumAlive() == 0); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 1155 | REPORTER_ASSERT(reporter, cache->getBudgetedResourceBytes() == 0); |
| 1156 | REPORTER_ASSERT(reporter, cache->getBudgetedResourceCount() == 0); |
| 1157 | REPORTER_ASSERT(reporter, cache->getResourceBytes() == 0); |
| 1158 | REPORTER_ASSERT(reporter, cache->getResourceCount() == 0); |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 1159 | |
| 1160 | for (int i = 0; i < kResourceCnt; ++i) { |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 1161 | GrUniqueKey key1, key2; |
| 1162 | make_unique_key<1>(&key1, i); |
| 1163 | make_unique_key<2>(&key2, i); |
bsalomon | 24db3b1 | 2015-01-23 04:24:04 -0800 | [diff] [blame] | 1164 | |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 1165 | REPORTER_ASSERT(reporter, !cache->hasUniqueKey(key1)); |
| 1166 | REPORTER_ASSERT(reporter, !cache->hasUniqueKey(key2)); |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 1167 | } |
| 1168 | } |
| 1169 | |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 1170 | //////////////////////////////////////////////////////////////////////////////// |
tfarina@chromium.org | 4ee16bf | 2014-01-10 22:08:27 +0000 | [diff] [blame] | 1171 | DEF_GPUTEST(ResourceCache, reporter, factory) { |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 1172 | for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) { |
| 1173 | GrContextFactory::GLContextType glType = static_cast<GrContextFactory::GLContextType>(type); |
| 1174 | if (!GrContextFactory::IsRenderingGLContext(glType)) { |
| 1175 | continue; |
| 1176 | } |
| 1177 | GrContext* context = factory->get(glType); |
bsalomon | fdcf2c0 | 2014-11-05 12:30:32 -0800 | [diff] [blame] | 1178 | if (NULL == context) { |
| 1179 | continue; |
| 1180 | } |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 1181 | GrSurfaceDesc desc; |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 1182 | desc.fConfig = kSkia8888_GrPixelConfig; |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 1183 | desc.fFlags = kRenderTarget_GrSurfaceFlag; |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 1184 | desc.fWidth = gWidth; |
| 1185 | desc.fHeight = gHeight; |
reed | 69f6f00 | 2014-09-18 06:09:44 -0700 | [diff] [blame] | 1186 | SkImageInfo info = SkImageInfo::MakeN32Premul(gWidth, gHeight); |
bsalomon | afe3005 | 2015-01-16 07:32:33 -0800 | [diff] [blame] | 1187 | SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(context, |
| 1188 | SkSurface::kNo_Budgeted, info)); |
reed | 69f6f00 | 2014-09-18 06:09:44 -0700 | [diff] [blame] | 1189 | test_cache(reporter, context, surface->getCanvas()); |
bsalomon | 02a44a4 | 2015-02-19 09:09:00 -0800 | [diff] [blame] | 1190 | test_stencil_buffers(reporter, context); |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 1191 | } |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 1192 | |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 1193 | // The below tests create their own mock contexts. |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 1194 | test_no_key(reporter); |
bsalomon | 84c8e62 | 2014-11-17 09:33:27 -0800 | [diff] [blame] | 1195 | test_budgeting(reporter); |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 1196 | test_unbudgeted(reporter); |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 1197 | test_unbudgeted_to_scratch(reporter); |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 1198 | test_duplicate_unique_key(reporter); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 1199 | test_duplicate_scratch_key(reporter); |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 1200 | test_remove_scratch_key(reporter); |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 1201 | test_scratch_key_consistency(reporter); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 1202 | test_purge_invalidated(reporter); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 1203 | test_cache_chained_purge(reporter); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 1204 | test_resource_size_changed(reporter); |
bsalomon | ddf30e6 | 2015-02-19 11:38:44 -0800 | [diff] [blame] | 1205 | test_timestamp_wrap(reporter); |
bsalomon | 3f32432 | 2015-04-08 11:01:54 -0700 | [diff] [blame] | 1206 | test_flush(reporter); |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 1207 | test_large_resource_count(reporter); |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 1208 | } |
| 1209 | |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 1210 | #endif |