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 |
Brian Salomon | 5e15085 | 2017-03-22 14:53:13 -0400 | [diff] [blame] | 12 | #include <thread> |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 13 | #include "GrContext.h" |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 14 | #include "GrContextPriv.h" |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 15 | #include "GrContextFactory.h" |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 16 | #include "GrGpu.h" |
bsalomon | 3582d3e | 2015-02-13 14:20:05 -0800 | [diff] [blame] | 17 | #include "GrGpuResourceCacheAccess.h" |
| 18 | #include "GrGpuResourcePriv.h" |
Robert Phillips | c0192e3 | 2017-09-21 12:00:26 -0400 | [diff] [blame] | 19 | #include "GrRenderTargetPriv.h" |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 20 | #include "GrResourceCache.h" |
bsalomon | 473addf | 2015-10-02 07:49:05 -0700 | [diff] [blame] | 21 | #include "GrResourceProvider.h" |
bsalomon | 6dc6f5f | 2015-06-18 09:12:16 -0700 | [diff] [blame] | 22 | #include "GrTest.h" |
Robert Phillips | 646e429 | 2017-06-13 12:44:56 -0400 | [diff] [blame] | 23 | #include "GrTexture.h" |
| 24 | |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 25 | #include "SkCanvas.h" |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 26 | #include "SkGr.h" |
| 27 | #include "SkMessageBus.h" |
Robert Phillips | d6214d4 | 2016-11-07 08:23:48 -0500 | [diff] [blame] | 28 | #include "SkMipMap.h" |
reed | 69f6f00 | 2014-09-18 06:09:44 -0700 | [diff] [blame] | 29 | #include "SkSurface.h" |
tfarina@chromium.org | 4ee16bf | 2014-01-10 22:08:27 +0000 | [diff] [blame] | 30 | #include "Test.h" |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 31 | |
| 32 | static const int gWidth = 640; |
| 33 | static const int gHeight = 480; |
| 34 | |
| 35 | //////////////////////////////////////////////////////////////////////////////// |
bsalomon | 68d9134 | 2016-04-12 09:59:58 -0700 | [diff] [blame] | 36 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceCacheCache, reporter, ctxInfo) { |
bsalomon | 8b7451a | 2016-05-11 06:33:06 -0700 | [diff] [blame] | 37 | GrContext* context = ctxInfo.grContext(); |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 38 | GrSurfaceDesc desc; |
Brian Osman | 777b563 | 2016-10-14 09:16:21 -0400 | [diff] [blame] | 39 | desc.fConfig = kRGBA_8888_GrPixelConfig; |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 40 | desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 41 | desc.fWidth = gWidth; |
| 42 | desc.fHeight = gHeight; |
| 43 | SkImageInfo info = SkImageInfo::MakeN32Premul(gWidth, gHeight); |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 44 | auto surface(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info)); |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 45 | SkCanvas* canvas = surface->getCanvas(); |
| 46 | |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 47 | const SkIRect size = SkIRect::MakeWH(gWidth, gHeight); |
| 48 | |
| 49 | SkBitmap src; |
mike@reedtribe.org | deee496 | 2014-02-13 14:41:43 +0000 | [diff] [blame] | 50 | src.allocN32Pixels(size.width(), size.height()); |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 51 | src.eraseColor(SK_ColorBLACK); |
Mike Reed | f0ffb89 | 2017-10-03 14:47:21 -0400 | [diff] [blame] | 52 | size_t srcSize = src.computeByteSize(); |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 53 | |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 54 | size_t initialCacheSize; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 55 | context->getResourceCacheUsage(nullptr, &initialCacheSize); |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 56 | |
| 57 | int oldMaxNum; |
| 58 | size_t oldMaxBytes; |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 59 | context->getResourceCacheLimits(&oldMaxNum, &oldMaxBytes); |
skia.committer@gmail.com | 17f1ae6 | 2013-08-09 07:01:22 +0000 | [diff] [blame] | 60 | |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 61 | // Set the cache limits so we can fit 10 "src" images and the |
| 62 | // max number of textures doesn't matter |
| 63 | size_t maxCacheSize = initialCacheSize + 10*srcSize; |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 64 | context->setResourceCacheLimits(1000, maxCacheSize); |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 65 | |
| 66 | SkBitmap readback; |
mike@reedtribe.org | deee496 | 2014-02-13 14:41:43 +0000 | [diff] [blame] | 67 | readback.allocN32Pixels(size.width(), size.height()); |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 68 | |
| 69 | for (int i = 0; i < 100; ++i) { |
| 70 | canvas->drawBitmap(src, 0, 0); |
Mike Reed | f194219 | 2017-07-21 14:24:29 -0400 | [diff] [blame] | 71 | surface->readPixels(readback, 0, 0); |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 72 | |
| 73 | // "modify" the src texture |
| 74 | src.notifyPixelsChanged(); |
| 75 | |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 76 | size_t curCacheSize; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 77 | context->getResourceCacheUsage(nullptr, &curCacheSize); |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 78 | |
| 79 | // we should never go over the size limit |
| 80 | REPORTER_ASSERT(reporter, curCacheSize <= maxCacheSize); |
| 81 | } |
| 82 | |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 83 | context->setResourceCacheLimits(oldMaxNum, oldMaxBytes); |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 84 | } |
| 85 | |
bsalomon | 11abd8d | 2016-10-14 08:13:48 -0700 | [diff] [blame] | 86 | static bool is_rendering_and_not_angle_es3(sk_gpu_test::GrContextFactory::ContextType type) { |
| 87 | if (type == sk_gpu_test::GrContextFactory::kANGLE_D3D11_ES3_ContextType || |
| 88 | type == sk_gpu_test::GrContextFactory::kANGLE_GL_ES3_ContextType) { |
| 89 | return false; |
| 90 | } |
| 91 | return sk_gpu_test::GrContextFactory::IsRenderingContext(type); |
| 92 | } |
| 93 | |
Robert Phillips | c0192e3 | 2017-09-21 12:00:26 -0400 | [diff] [blame] | 94 | static GrStencilAttachment* get_SB(GrRenderTarget* rt) { |
| 95 | return rt->renderTargetPriv().getStencilAttachment(); |
| 96 | } |
| 97 | |
| 98 | static sk_sp<GrRenderTarget> create_RT_with_SB(GrResourceProvider* provider, |
| 99 | int size, int sampleCount, SkBudgeted budgeted) { |
| 100 | GrSurfaceDesc desc; |
| 101 | desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 102 | desc.fOrigin = kBottomLeft_GrSurfaceOrigin; |
| 103 | desc.fWidth = size; |
| 104 | desc.fHeight = size; |
| 105 | desc.fConfig = kRGBA_8888_GrPixelConfig; |
| 106 | desc.fSampleCnt = sampleCount; |
| 107 | |
| 108 | sk_sp<GrTexture> tex(provider->createTexture(desc, budgeted)); |
| 109 | if (!tex || !tex->asRenderTarget()) { |
| 110 | return nullptr; |
| 111 | } |
| 112 | |
| 113 | if (!provider->attachStencilAttachment(tex->asRenderTarget())) { |
| 114 | return nullptr; |
| 115 | } |
| 116 | SkASSERT(get_SB(tex->asRenderTarget())); |
| 117 | |
| 118 | return sk_ref_sp(tex->asRenderTarget()); |
| 119 | } |
| 120 | |
bsalomon | 11abd8d | 2016-10-14 08:13:48 -0700 | [diff] [blame] | 121 | // This currently fails on ES3 ANGLE contexts |
| 122 | DEF_GPUTEST_FOR_CONTEXTS(ResourceCacheStencilBuffers, &is_rendering_and_not_angle_es3, reporter, |
Robert Phillips | ec32534 | 2017-10-30 18:02:48 +0000 | [diff] [blame] | 123 | ctxInfo, nullptr) { |
bsalomon | 8b7451a | 2016-05-11 06:33:06 -0700 | [diff] [blame] | 124 | GrContext* context = ctxInfo.grContext(); |
Eric Karl | 5c77975 | 2017-05-08 12:02:07 -0700 | [diff] [blame] | 125 | if (context->caps()->avoidStencilBuffers()) { |
| 126 | return; |
| 127 | } |
Robert Phillips | c0192e3 | 2017-09-21 12:00:26 -0400 | [diff] [blame] | 128 | |
| 129 | GrResourceProvider* provider = context->resourceProvider(); |
| 130 | |
| 131 | sk_sp<GrRenderTarget> smallRT0 = create_RT_with_SB(provider, 4, 0, SkBudgeted::kYes); |
| 132 | REPORTER_ASSERT(reporter, smallRT0); |
| 133 | |
| 134 | { |
| 135 | // Two budgeted RTs with the same desc should share a stencil buffer. |
| 136 | sk_sp<GrRenderTarget> smallRT1 = create_RT_with_SB(provider, 4, 0, SkBudgeted::kYes); |
| 137 | REPORTER_ASSERT(reporter, smallRT1); |
| 138 | |
| 139 | REPORTER_ASSERT(reporter, get_SB(smallRT0.get()) == get_SB(smallRT1.get())); |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 140 | } |
| 141 | |
Robert Phillips | c0192e3 | 2017-09-21 12:00:26 -0400 | [diff] [blame] | 142 | { |
| 143 | // An unbudgeted RT with the same desc should also share. |
| 144 | sk_sp<GrRenderTarget> smallRT2 = create_RT_with_SB(provider, 4, 0, SkBudgeted::kNo); |
| 145 | REPORTER_ASSERT(reporter, smallRT2); |
| 146 | |
| 147 | REPORTER_ASSERT(reporter, get_SB(smallRT0.get()) == get_SB(smallRT2.get())); |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 148 | } |
| 149 | |
Robert Phillips | c0192e3 | 2017-09-21 12:00:26 -0400 | [diff] [blame] | 150 | { |
| 151 | // An RT with a much larger size should not share. |
| 152 | sk_sp<GrRenderTarget> bigRT = create_RT_with_SB(provider, 400, 0, SkBudgeted::kNo); |
| 153 | REPORTER_ASSERT(reporter, bigRT); |
bsalomon | 02a44a4 | 2015-02-19 09:09:00 -0800 | [diff] [blame] | 154 | |
Robert Phillips | c0192e3 | 2017-09-21 12:00:26 -0400 | [diff] [blame] | 155 | REPORTER_ASSERT(reporter, get_SB(smallRT0.get()) != get_SB(bigRT.get())); |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 156 | } |
bsalomon | 02a44a4 | 2015-02-19 09:09:00 -0800 | [diff] [blame] | 157 | |
Robert Phillips | c0192e3 | 2017-09-21 12:00:26 -0400 | [diff] [blame] | 158 | int smallSampleCount = context->caps()->getSampleCount(4, kRGBA_8888_GrPixelConfig); |
| 159 | if (smallSampleCount > 0) { |
mtklein | 5f939ab | 2016-03-16 10:28:35 -0700 | [diff] [blame] | 160 | // An RT with a different sample count should not share. |
Robert Phillips | c0192e3 | 2017-09-21 12:00:26 -0400 | [diff] [blame] | 161 | sk_sp<GrRenderTarget> smallMSAART0 = create_RT_with_SB(provider, 4, smallSampleCount, |
| 162 | SkBudgeted::kNo); |
bsalomon | b602d4d | 2015-02-19 12:05:58 -0800 | [diff] [blame] | 163 | #ifdef SK_BUILD_FOR_ANDROID |
| 164 | if (!smallMSAART0) { |
| 165 | // The nexus player seems to fail to create MSAA textures. |
| 166 | return; |
| 167 | } |
Robert Phillips | c0192e3 | 2017-09-21 12:00:26 -0400 | [diff] [blame] | 168 | #else |
| 169 | REPORTER_ASSERT(reporter, smallMSAART0); |
bsalomon | b602d4d | 2015-02-19 12:05:58 -0800 | [diff] [blame] | 170 | #endif |
Robert Phillips | c0192e3 | 2017-09-21 12:00:26 -0400 | [diff] [blame] | 171 | |
| 172 | REPORTER_ASSERT(reporter, get_SB(smallRT0.get()) != get_SB(smallMSAART0.get())); |
| 173 | |
| 174 | { |
| 175 | // A second MSAA RT should share with the first MSAA RT. |
| 176 | sk_sp<GrRenderTarget> smallMSAART1 = create_RT_with_SB(provider, 4, smallSampleCount, |
| 177 | SkBudgeted::kNo); |
| 178 | REPORTER_ASSERT(reporter, smallMSAART1); |
| 179 | |
| 180 | REPORTER_ASSERT(reporter, get_SB(smallMSAART0.get()) == get_SB(smallMSAART1.get())); |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 181 | } |
Robert Phillips | c0192e3 | 2017-09-21 12:00:26 -0400 | [diff] [blame] | 182 | |
bsalomon | 02a44a4 | 2015-02-19 09:09:00 -0800 | [diff] [blame] | 183 | // But not one with a larger sample count should not. (Also check that the request for 4 |
| 184 | // samples didn't get rounded up to >= 8 or else they could share.). |
Robert Phillips | c0192e3 | 2017-09-21 12:00:26 -0400 | [diff] [blame] | 185 | int bigSampleCount = context->caps()->getSampleCount(8, kRGBA_8888_GrPixelConfig); |
| 186 | if (bigSampleCount != smallSampleCount) { |
| 187 | sk_sp<GrRenderTarget> smallMSAART2 = create_RT_with_SB(provider, 4, bigSampleCount, |
| 188 | SkBudgeted::kNo); |
| 189 | REPORTER_ASSERT(reporter, smallMSAART2); |
| 190 | |
| 191 | REPORTER_ASSERT(reporter, get_SB(smallMSAART0.get()) != get_SB(smallMSAART2.get())); |
bsalomon | 02a44a4 | 2015-02-19 09:09:00 -0800 | [diff] [blame] | 192 | } |
| 193 | } |
| 194 | } |
| 195 | |
bsalomon | 68d9134 | 2016-04-12 09:59:58 -0700 | [diff] [blame] | 196 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceCacheWrappedResources, reporter, ctxInfo) { |
bsalomon | 8b7451a | 2016-05-11 06:33:06 -0700 | [diff] [blame] | 197 | GrContext* context = ctxInfo.grContext(); |
bsalomon | e63ffef | 2016-02-05 07:17:34 -0800 | [diff] [blame] | 198 | GrGpu* gpu = context->getGpu(); |
jvanverth | eeb8d99 | 2015-07-15 10:16:56 -0700 | [diff] [blame] | 199 | // this test is only valid for GL |
| 200 | if (!gpu || !gpu->glContextForTesting()) { |
bsalomon | 6dc6f5f | 2015-06-18 09:12:16 -0700 | [diff] [blame] | 201 | return; |
| 202 | } |
| 203 | |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 204 | GrBackendTexture backendTextures[2]; |
bsalomon | 6dc6f5f | 2015-06-18 09:12:16 -0700 | [diff] [blame] | 205 | static const int kW = 100; |
| 206 | static const int kH = 100; |
jvanverth | 672bb7f | 2015-07-13 07:19:57 -0700 | [diff] [blame] | 207 | |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 208 | backendTextures[0] = gpu->createTestingOnlyBackendTexture(nullptr, kW, kH, |
| 209 | kRGBA_8888_GrPixelConfig, |
| 210 | false, GrMipMapped::kNo); |
| 211 | backendTextures[1] = gpu->createTestingOnlyBackendTexture(nullptr, kW, kH, |
| 212 | kRGBA_8888_GrPixelConfig, |
| 213 | false, GrMipMapped::kNo); |
jvanverth | 672bb7f | 2015-07-13 07:19:57 -0700 | [diff] [blame] | 214 | |
bsalomon | 6dc6f5f | 2015-06-18 09:12:16 -0700 | [diff] [blame] | 215 | context->resetContext(); |
| 216 | |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 217 | sk_sp<GrTexture> borrowed(context->resourceProvider()->wrapBackendTexture( |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 218 | backendTextures[0], kBorrow_GrWrapOwnership)); |
bsalomon | 6dc6f5f | 2015-06-18 09:12:16 -0700 | [diff] [blame] | 219 | |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 220 | sk_sp<GrTexture> adopted(context->resourceProvider()->wrapBackendTexture( |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 221 | backendTextures[1], kAdopt_GrWrapOwnership)); |
bsalomon | 6dc6f5f | 2015-06-18 09:12:16 -0700 | [diff] [blame] | 222 | |
Brian Osman | 85d34b2 | 2017-05-10 12:06:26 -0400 | [diff] [blame] | 223 | REPORTER_ASSERT(reporter, borrowed != nullptr && adopted != nullptr); |
| 224 | if (!borrowed || !adopted) { |
bsalomon | 6dc6f5f | 2015-06-18 09:12:16 -0700 | [diff] [blame] | 225 | return; |
| 226 | } |
| 227 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 228 | borrowed.reset(nullptr); |
| 229 | adopted.reset(nullptr); |
bsalomon | 6dc6f5f | 2015-06-18 09:12:16 -0700 | [diff] [blame] | 230 | |
| 231 | context->flush(); |
| 232 | |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 233 | bool borrowedIsAlive = gpu->isTestingOnlyBackendTexture(backendTextures[0]); |
| 234 | bool adoptedIsAlive = gpu->isTestingOnlyBackendTexture(backendTextures[1]); |
bsalomon | 6dc6f5f | 2015-06-18 09:12:16 -0700 | [diff] [blame] | 235 | |
| 236 | REPORTER_ASSERT(reporter, borrowedIsAlive); |
| 237 | REPORTER_ASSERT(reporter, !adoptedIsAlive); |
| 238 | |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 239 | gpu->deleteTestingOnlyBackendTexture(&(backendTextures[0]), !borrowedIsAlive); |
| 240 | gpu->deleteTestingOnlyBackendTexture(&(backendTextures[1]), !adoptedIsAlive); |
bsalomon | 6dc6f5f | 2015-06-18 09:12:16 -0700 | [diff] [blame] | 241 | |
| 242 | context->resetContext(); |
| 243 | } |
| 244 | |
bsalomon | 6d3fe02 | 2014-07-25 08:35:45 -0700 | [diff] [blame] | 245 | class TestResource : public GrGpuResource { |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 246 | enum ScratchConstructor { kScratchConstructor }; |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 247 | public: |
robertphillips | 6e83ac7 | 2015-08-13 05:19:14 -0700 | [diff] [blame] | 248 | static const size_t kDefaultSize = 100; |
mtklein | 5f939ab | 2016-03-16 10:28:35 -0700 | [diff] [blame] | 249 | |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 250 | /** Property that distinctly categorizes the resource. |
| 251 | * For example, textures have width, height, ... */ |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 252 | enum SimulatedProperty { kA_SimulatedProperty, kB_SimulatedProperty }; |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 253 | |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 254 | TestResource(GrGpu* gpu, SkBudgeted budgeted = SkBudgeted::kYes, size_t size = kDefaultSize) |
| 255 | : INHERITED(gpu) |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 256 | , fToDelete(nullptr) |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 257 | , fSize(size) |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 258 | , fProperty(kA_SimulatedProperty) |
| 259 | , fIsScratch(false) { |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 260 | ++fNumAlive; |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 261 | this->registerWithCache(budgeted); |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 262 | } |
| 263 | |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 264 | static TestResource* CreateScratch(GrGpu* gpu, SkBudgeted budgeted, |
| 265 | SimulatedProperty property) { |
| 266 | return new TestResource(gpu, budgeted, property, kScratchConstructor); |
bsalomon | dace19e | 2014-11-17 07:34:06 -0800 | [diff] [blame] | 267 | } |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 268 | static TestResource* CreateWrapped(GrGpu* gpu, size_t size = kDefaultSize) { |
| 269 | return new TestResource(gpu, size); |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 270 | } |
| 271 | |
Brian Salomon | d3b6597 | 2017-03-22 12:05:03 -0400 | [diff] [blame] | 272 | ~TestResource() override { |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 273 | --fNumAlive; |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 274 | SkSafeUnref(fToDelete); |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 275 | } |
| 276 | |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 277 | void setSize(size_t size) { |
| 278 | fSize = size; |
| 279 | this->didChangeGpuMemorySize(); |
| 280 | } |
| 281 | |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 282 | static int NumAlive() { return fNumAlive; } |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 283 | |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 284 | void setUnrefWhenDestroyed(TestResource* resource) { |
| 285 | SkRefCnt_SafeAssign(fToDelete, resource); |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 286 | } |
| 287 | |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 288 | static void ComputeScratchKey(SimulatedProperty property, GrScratchKey* key) { |
| 289 | static GrScratchKey::ResourceType t = GrScratchKey::GenerateResourceType(); |
| 290 | GrScratchKey::Builder builder(key, t, kScratchKeyFieldCnt); |
bsalomon | 24db3b1 | 2015-01-23 04:24:04 -0800 | [diff] [blame] | 291 | for (int i = 0; i < kScratchKeyFieldCnt; ++i) { |
| 292 | builder[i] = static_cast<uint32_t>(i + property); |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 293 | } |
| 294 | } |
| 295 | |
| 296 | static size_t ExpectedScratchKeySize() { |
| 297 | return sizeof(uint32_t) * (kScratchKeyFieldCnt + GrScratchKey::kMetaDataCnt); |
| 298 | } |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 299 | private: |
bsalomon | 24db3b1 | 2015-01-23 04:24:04 -0800 | [diff] [blame] | 300 | static const int kScratchKeyFieldCnt = 6; |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 301 | |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 302 | TestResource(GrGpu* gpu, SkBudgeted budgeted, SimulatedProperty property, ScratchConstructor) |
| 303 | : INHERITED(gpu) |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 304 | , fToDelete(nullptr) |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 305 | , fSize(kDefaultSize) |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 306 | , fProperty(property) |
| 307 | , fIsScratch(true) { |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 308 | ++fNumAlive; |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 309 | this->registerWithCache(budgeted); |
| 310 | } |
| 311 | |
| 312 | // Constructor for simulating resources that wrap backend objects. |
| 313 | TestResource(GrGpu* gpu, size_t size) |
| 314 | : INHERITED(gpu) |
| 315 | , fToDelete(nullptr) |
| 316 | , fSize(size) |
| 317 | , fProperty(kA_SimulatedProperty) |
| 318 | , fIsScratch(false) { |
| 319 | ++fNumAlive; |
| 320 | this->registerWithCacheWrapped(); |
| 321 | } |
| 322 | |
| 323 | void computeScratchKey(GrScratchKey* key) const override { |
| 324 | if (fIsScratch) { |
| 325 | ComputeScratchKey(fProperty, key); |
| 326 | } |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 327 | } |
| 328 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 329 | size_t onGpuMemorySize() const override { return fSize; } |
bsalomon | 69ed47f | 2014-11-12 11:13:39 -0800 | [diff] [blame] | 330 | |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 331 | TestResource* fToDelete; |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 332 | size_t fSize; |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 333 | static int fNumAlive; |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 334 | SimulatedProperty fProperty; |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 335 | bool fIsScratch; |
bsalomon | 6d3fe02 | 2014-07-25 08:35:45 -0700 | [diff] [blame] | 336 | typedef GrGpuResource INHERITED; |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 337 | }; |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 338 | int TestResource::fNumAlive = 0; |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 339 | |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 340 | class Mock { |
| 341 | public: |
| 342 | Mock(int maxCnt, size_t maxBytes) { |
Greg Daniel | 02611d9 | 2017-07-25 10:05:01 -0400 | [diff] [blame] | 343 | fContext = GrContext::MakeMock(nullptr); |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 344 | SkASSERT(fContext); |
| 345 | fContext->setResourceCacheLimits(maxCnt, maxBytes); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 346 | GrResourceCache* cache = fContext->getResourceCache(); |
| 347 | cache->purgeAllUnlocked(); |
| 348 | SkASSERT(0 == cache->getResourceCount() && 0 == cache->getResourceBytes()); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 349 | } |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 350 | |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 351 | GrResourceCache* cache() { return fContext->getResourceCache(); } |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 352 | |
Hal Canary | 342b7ac | 2016-11-04 11:49:42 -0400 | [diff] [blame] | 353 | GrContext* context() { return fContext.get(); } |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 354 | |
| 355 | private: |
Hal Canary | 342b7ac | 2016-11-04 11:49:42 -0400 | [diff] [blame] | 356 | sk_sp<GrContext> fContext; |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 357 | }; |
| 358 | |
| 359 | static void test_no_key(skiatest::Reporter* reporter) { |
| 360 | Mock mock(10, 30000); |
| 361 | GrContext* context = mock.context(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 362 | GrResourceCache* cache = mock.cache(); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 363 | |
| 364 | // Create a bunch of resources with no keys |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 365 | TestResource* a = new TestResource(context->getGpu()); |
| 366 | TestResource* b = new TestResource(context->getGpu()); |
| 367 | TestResource* c = new TestResource(context->getGpu()); |
| 368 | TestResource* d = new TestResource(context->getGpu()); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 369 | a->setSize(11); |
| 370 | b->setSize(12); |
| 371 | c->setSize(13); |
| 372 | d->setSize(14); |
| 373 | |
| 374 | REPORTER_ASSERT(reporter, 4 == TestResource::NumAlive()); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 375 | REPORTER_ASSERT(reporter, 4 == cache->getResourceCount()); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 376 | REPORTER_ASSERT(reporter, a->gpuMemorySize() + b->gpuMemorySize() + c->gpuMemorySize() + |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 377 | d->gpuMemorySize() == cache->getResourceBytes()); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 378 | |
| 379 | // 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] | 380 | cache->purgeAllUnlocked(); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 381 | REPORTER_ASSERT(reporter, 4 == TestResource::NumAlive()); |
| 382 | |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 383 | // Since the resources have neither unique nor scratch keys, delete immediately upon unref. |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 384 | |
| 385 | a->unref(); |
| 386 | REPORTER_ASSERT(reporter, 3 == TestResource::NumAlive()); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 387 | REPORTER_ASSERT(reporter, 3 == cache->getResourceCount()); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 388 | REPORTER_ASSERT(reporter, b->gpuMemorySize() + c->gpuMemorySize() + d->gpuMemorySize() == |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 389 | cache->getResourceBytes()); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 390 | |
| 391 | c->unref(); |
| 392 | REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 393 | REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 394 | REPORTER_ASSERT(reporter, b->gpuMemorySize() + d->gpuMemorySize() == |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 395 | cache->getResourceBytes()); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 396 | |
| 397 | d->unref(); |
| 398 | REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive()); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 399 | REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); |
| 400 | REPORTER_ASSERT(reporter, b->gpuMemorySize() == cache->getResourceBytes()); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 401 | |
| 402 | b->unref(); |
| 403 | REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive()); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 404 | REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
| 405 | REPORTER_ASSERT(reporter, 0 == cache->getResourceBytes()); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 406 | } |
| 407 | |
bsalomon | 24db3b1 | 2015-01-23 04:24:04 -0800 | [diff] [blame] | 408 | // Each integer passed as a template param creates a new domain. |
Brian Salomon | 1090da6 | 2017-01-06 12:04:19 -0500 | [diff] [blame] | 409 | template <int> |
| 410 | static void make_unique_key(GrUniqueKey* key, int data, const char* tag = nullptr) { |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 411 | static GrUniqueKey::Domain d = GrUniqueKey::GenerateDomain(); |
Brian Salomon | 1090da6 | 2017-01-06 12:04:19 -0500 | [diff] [blame] | 412 | GrUniqueKey::Builder builder(key, d, 1, tag); |
bsalomon | 24db3b1 | 2015-01-23 04:24:04 -0800 | [diff] [blame] | 413 | builder[0] = data; |
| 414 | } |
| 415 | |
bsalomon | 84c8e62 | 2014-11-17 09:33:27 -0800 | [diff] [blame] | 416 | static void test_budgeting(skiatest::Reporter* reporter) { |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 417 | Mock mock(10, 300); |
| 418 | GrContext* context = mock.context(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 419 | GrResourceCache* cache = mock.cache(); |
bsalomon | dace19e | 2014-11-17 07:34:06 -0800 | [diff] [blame] | 420 | |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 421 | GrUniqueKey uniqueKey; |
| 422 | make_unique_key<0>(&uniqueKey, 0); |
bsalomon | dace19e | 2014-11-17 07:34:06 -0800 | [diff] [blame] | 423 | |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 424 | // Create a scratch, a unique, and a wrapped resource |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 425 | TestResource* scratch = |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 426 | TestResource::CreateScratch(context->getGpu(), SkBudgeted::kYes, TestResource::kB_SimulatedProperty); |
bsalomon | dace19e | 2014-11-17 07:34:06 -0800 | [diff] [blame] | 427 | scratch->setSize(10); |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 428 | TestResource* unique = new TestResource(context->getGpu()); |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 429 | unique->setSize(11); |
bsalomon | f99e961 | 2015-02-19 08:24:16 -0800 | [diff] [blame] | 430 | unique->resourcePriv().setUniqueKey(uniqueKey); |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 431 | TestResource* wrapped = TestResource::CreateWrapped(context->getGpu()); |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 432 | wrapped->setSize(12); |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 433 | TestResource* unbudgeted = |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 434 | new TestResource(context->getGpu(), SkBudgeted::kNo); |
bsalomon | 84c8e62 | 2014-11-17 09:33:27 -0800 | [diff] [blame] | 435 | unbudgeted->setSize(13); |
bsalomon | dace19e | 2014-11-17 07:34:06 -0800 | [diff] [blame] | 436 | |
Brian Osman | 0562eb9 | 2017-05-08 11:16:39 -0400 | [diff] [blame] | 437 | // Make sure we can add a unique key to the wrapped resource |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 438 | GrUniqueKey uniqueKey2; |
| 439 | make_unique_key<0>(&uniqueKey2, 1); |
bsalomon | f99e961 | 2015-02-19 08:24:16 -0800 | [diff] [blame] | 440 | wrapped->resourcePriv().setUniqueKey(uniqueKey2); |
Brian Osman | 0562eb9 | 2017-05-08 11:16:39 -0400 | [diff] [blame] | 441 | GrGpuResource* wrappedViaKey = cache->findAndRefUniqueResource(uniqueKey2); |
| 442 | REPORTER_ASSERT(reporter, wrappedViaKey != nullptr); |
| 443 | |
| 444 | // Remove the extra ref we just added. |
| 445 | wrappedViaKey->unref(); |
bsalomon | dace19e | 2014-11-17 07:34:06 -0800 | [diff] [blame] | 446 | |
| 447 | // Make sure sizes are as we expect |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 448 | REPORTER_ASSERT(reporter, 4 == cache->getResourceCount()); |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 449 | REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + unique->gpuMemorySize() + |
bsalomon | 84c8e62 | 2014-11-17 09:33:27 -0800 | [diff] [blame] | 450 | wrapped->gpuMemorySize() + unbudgeted->gpuMemorySize() == |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 451 | cache->getResourceBytes()); |
| 452 | REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount()); |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 453 | REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + unique->gpuMemorySize() == |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 454 | cache->getBudgetedResourceBytes()); |
Derek Sollenberger | ee47914 | 2017-05-24 11:41:33 -0400 | [diff] [blame] | 455 | REPORTER_ASSERT(reporter, 0 == cache->getPurgeableBytes()); |
bsalomon | dace19e | 2014-11-17 07:34:06 -0800 | [diff] [blame] | 456 | |
bsalomon | 63c992f | 2015-01-23 12:47:59 -0800 | [diff] [blame] | 457 | // Our refs mean that the resources are non purgeable. |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 458 | cache->purgeAllUnlocked(); |
| 459 | REPORTER_ASSERT(reporter, 4 == cache->getResourceCount()); |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 460 | REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + unique->gpuMemorySize() + |
bsalomon | 84c8e62 | 2014-11-17 09:33:27 -0800 | [diff] [blame] | 461 | wrapped->gpuMemorySize() + unbudgeted->gpuMemorySize() == |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 462 | cache->getResourceBytes()); |
| 463 | REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount()); |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 464 | REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + unique->gpuMemorySize() == |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 465 | cache->getBudgetedResourceBytes()); |
Derek Sollenberger | ee47914 | 2017-05-24 11:41:33 -0400 | [diff] [blame] | 466 | REPORTER_ASSERT(reporter, 0 == cache->getPurgeableBytes()); |
bsalomon | dace19e | 2014-11-17 07:34:06 -0800 | [diff] [blame] | 467 | |
| 468 | // Unreffing the wrapped resource should free it right away. |
| 469 | wrapped->unref(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 470 | REPORTER_ASSERT(reporter, 3 == cache->getResourceCount()); |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 471 | REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + unique->gpuMemorySize() + |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 472 | unbudgeted->gpuMemorySize() == cache->getResourceBytes()); |
Derek Sollenberger | ee47914 | 2017-05-24 11:41:33 -0400 | [diff] [blame] | 473 | REPORTER_ASSERT(reporter, 0 == cache->getPurgeableBytes()); |
bsalomon | dace19e | 2014-11-17 07:34:06 -0800 | [diff] [blame] | 474 | |
bsalomon | 84c8e62 | 2014-11-17 09:33:27 -0800 | [diff] [blame] | 475 | // Now try freeing the budgeted resources first |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 476 | wrapped = TestResource::CreateWrapped(context->getGpu()); |
bsalomon | dace19e | 2014-11-17 07:34:06 -0800 | [diff] [blame] | 477 | scratch->setSize(12); |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 478 | unique->unref(); |
Derek Sollenberger | ee47914 | 2017-05-24 11:41:33 -0400 | [diff] [blame] | 479 | REPORTER_ASSERT(reporter, 11 == cache->getPurgeableBytes()); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 480 | cache->purgeAllUnlocked(); |
| 481 | REPORTER_ASSERT(reporter, 3 == cache->getResourceCount()); |
bsalomon | 84c8e62 | 2014-11-17 09:33:27 -0800 | [diff] [blame] | 482 | REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + wrapped->gpuMemorySize() + |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 483 | unbudgeted->gpuMemorySize() == cache->getResourceBytes()); |
| 484 | REPORTER_ASSERT(reporter, 1 == cache->getBudgetedResourceCount()); |
| 485 | REPORTER_ASSERT(reporter, scratch->gpuMemorySize() == cache->getBudgetedResourceBytes()); |
Derek Sollenberger | ee47914 | 2017-05-24 11:41:33 -0400 | [diff] [blame] | 486 | REPORTER_ASSERT(reporter, 0 == cache->getPurgeableBytes()); |
bsalomon | dace19e | 2014-11-17 07:34:06 -0800 | [diff] [blame] | 487 | |
| 488 | scratch->unref(); |
Derek Sollenberger | ee47914 | 2017-05-24 11:41:33 -0400 | [diff] [blame] | 489 | REPORTER_ASSERT(reporter, 12 == cache->getPurgeableBytes()); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 490 | cache->purgeAllUnlocked(); |
| 491 | REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); |
bsalomon | 84c8e62 | 2014-11-17 09:33:27 -0800 | [diff] [blame] | 492 | REPORTER_ASSERT(reporter, unbudgeted->gpuMemorySize() + wrapped->gpuMemorySize() == |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 493 | cache->getResourceBytes()); |
| 494 | REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceCount()); |
| 495 | REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceBytes()); |
Derek Sollenberger | ee47914 | 2017-05-24 11:41:33 -0400 | [diff] [blame] | 496 | REPORTER_ASSERT(reporter, 0 == cache->getPurgeableBytes()); |
bsalomon | dace19e | 2014-11-17 07:34:06 -0800 | [diff] [blame] | 497 | |
| 498 | wrapped->unref(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 499 | REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); |
| 500 | REPORTER_ASSERT(reporter, unbudgeted->gpuMemorySize() == cache->getResourceBytes()); |
| 501 | REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceCount()); |
| 502 | REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceBytes()); |
Derek Sollenberger | ee47914 | 2017-05-24 11:41:33 -0400 | [diff] [blame] | 503 | REPORTER_ASSERT(reporter, 0 == cache->getPurgeableBytes()); |
bsalomon | 84c8e62 | 2014-11-17 09:33:27 -0800 | [diff] [blame] | 504 | |
| 505 | unbudgeted->unref(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 506 | REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
| 507 | REPORTER_ASSERT(reporter, 0 == cache->getResourceBytes()); |
| 508 | REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceCount()); |
| 509 | REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceBytes()); |
Derek Sollenberger | ee47914 | 2017-05-24 11:41:33 -0400 | [diff] [blame] | 510 | REPORTER_ASSERT(reporter, 0 == cache->getPurgeableBytes()); |
bsalomon | dace19e | 2014-11-17 07:34:06 -0800 | [diff] [blame] | 511 | } |
| 512 | |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 513 | static void test_unbudgeted(skiatest::Reporter* reporter) { |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 514 | Mock mock(10, 30000); |
| 515 | GrContext* context = mock.context(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 516 | GrResourceCache* cache = mock.cache(); |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 517 | |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 518 | GrUniqueKey uniqueKey; |
| 519 | make_unique_key<0>(&uniqueKey, 0); |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 520 | |
| 521 | TestResource* scratch; |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 522 | TestResource* unique; |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 523 | TestResource* wrapped; |
| 524 | TestResource* unbudgeted; |
| 525 | |
| 526 | // A large uncached or wrapped resource shouldn't evict anything. |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 527 | scratch = TestResource::CreateScratch(context->getGpu(), SkBudgeted::kYes, |
| 528 | TestResource::kB_SimulatedProperty); |
| 529 | |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 530 | scratch->setSize(10); |
| 531 | scratch->unref(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 532 | REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); |
| 533 | REPORTER_ASSERT(reporter, 10 == cache->getResourceBytes()); |
| 534 | REPORTER_ASSERT(reporter, 1 == cache->getBudgetedResourceCount()); |
| 535 | REPORTER_ASSERT(reporter, 10 == cache->getBudgetedResourceBytes()); |
Derek Sollenberger | ee47914 | 2017-05-24 11:41:33 -0400 | [diff] [blame] | 536 | REPORTER_ASSERT(reporter, 10 == cache->getPurgeableBytes()); |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 537 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 538 | unique = new TestResource(context->getGpu()); |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 539 | unique->setSize(11); |
bsalomon | f99e961 | 2015-02-19 08:24:16 -0800 | [diff] [blame] | 540 | unique->resourcePriv().setUniqueKey(uniqueKey); |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 541 | unique->unref(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 542 | REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); |
| 543 | REPORTER_ASSERT(reporter, 21 == cache->getResourceBytes()); |
| 544 | REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount()); |
| 545 | REPORTER_ASSERT(reporter, 21 == cache->getBudgetedResourceBytes()); |
Derek Sollenberger | ee47914 | 2017-05-24 11:41:33 -0400 | [diff] [blame] | 546 | REPORTER_ASSERT(reporter, 21 == cache->getPurgeableBytes()); |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 547 | |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 548 | size_t large = 2 * cache->getResourceBytes(); |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 549 | unbudgeted = new TestResource(context->getGpu(), SkBudgeted::kNo, large); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 550 | REPORTER_ASSERT(reporter, 3 == cache->getResourceCount()); |
| 551 | REPORTER_ASSERT(reporter, 21 + large == cache->getResourceBytes()); |
| 552 | REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount()); |
| 553 | REPORTER_ASSERT(reporter, 21 == cache->getBudgetedResourceBytes()); |
Derek Sollenberger | ee47914 | 2017-05-24 11:41:33 -0400 | [diff] [blame] | 554 | REPORTER_ASSERT(reporter, 21 == cache->getPurgeableBytes()); |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 555 | |
| 556 | unbudgeted->unref(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 557 | REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); |
| 558 | REPORTER_ASSERT(reporter, 21 == cache->getResourceBytes()); |
| 559 | REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount()); |
| 560 | REPORTER_ASSERT(reporter, 21 == cache->getBudgetedResourceBytes()); |
Derek Sollenberger | ee47914 | 2017-05-24 11:41:33 -0400 | [diff] [blame] | 561 | REPORTER_ASSERT(reporter, 21 == cache->getPurgeableBytes()); |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 562 | |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 563 | wrapped = TestResource::CreateWrapped(context->getGpu(), large); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 564 | REPORTER_ASSERT(reporter, 3 == cache->getResourceCount()); |
| 565 | REPORTER_ASSERT(reporter, 21 + large == cache->getResourceBytes()); |
| 566 | REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount()); |
| 567 | REPORTER_ASSERT(reporter, 21 == cache->getBudgetedResourceBytes()); |
Derek Sollenberger | ee47914 | 2017-05-24 11:41:33 -0400 | [diff] [blame] | 568 | REPORTER_ASSERT(reporter, 21 == cache->getPurgeableBytes()); |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 569 | |
| 570 | wrapped->unref(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 571 | REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); |
| 572 | REPORTER_ASSERT(reporter, 21 == cache->getResourceBytes()); |
| 573 | REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount()); |
| 574 | REPORTER_ASSERT(reporter, 21 == cache->getBudgetedResourceBytes()); |
Derek Sollenberger | ee47914 | 2017-05-24 11:41:33 -0400 | [diff] [blame] | 575 | REPORTER_ASSERT(reporter, 21 == cache->getPurgeableBytes()); |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 576 | |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 577 | cache->purgeAllUnlocked(); |
| 578 | REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
| 579 | REPORTER_ASSERT(reporter, 0 == cache->getResourceBytes()); |
| 580 | REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceCount()); |
| 581 | REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceBytes()); |
Derek Sollenberger | ee47914 | 2017-05-24 11:41:33 -0400 | [diff] [blame] | 582 | REPORTER_ASSERT(reporter, 0 == cache->getPurgeableBytes()); |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 583 | } |
| 584 | |
bsalomon | 3582d3e | 2015-02-13 14:20:05 -0800 | [diff] [blame] | 585 | // This method can't be static because it needs to friended in GrGpuResource::CacheAccess. |
| 586 | void test_unbudgeted_to_scratch(skiatest::Reporter* reporter); |
| 587 | /*static*/ void test_unbudgeted_to_scratch(skiatest::Reporter* reporter) { |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 588 | Mock mock(10, 300); |
| 589 | GrContext* context = mock.context(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 590 | GrResourceCache* cache = mock.cache(); |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 591 | |
| 592 | TestResource* resource = |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 593 | TestResource::CreateScratch(context->getGpu(), SkBudgeted::kNo, |
| 594 | TestResource::kA_SimulatedProperty); |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 595 | GrScratchKey key; |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 596 | TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &key); |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 597 | |
| 598 | size_t size = resource->gpuMemorySize(); |
| 599 | for (int i = 0; i < 2; ++i) { |
| 600 | // Since this resource is unbudgeted, it should not be reachable as scratch. |
bsalomon | 3582d3e | 2015-02-13 14:20:05 -0800 | [diff] [blame] | 601 | REPORTER_ASSERT(reporter, resource->resourcePriv().getScratchKey() == key); |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 602 | REPORTER_ASSERT(reporter, !resource->cacheAccess().isScratch()); |
bsalomon | 5ec26ae | 2016-02-25 08:33:02 -0800 | [diff] [blame] | 603 | REPORTER_ASSERT(reporter, SkBudgeted::kNo == resource->resourcePriv().isBudgeted()); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 604 | REPORTER_ASSERT(reporter, nullptr == cache->findAndRefScratchResource(key, TestResource::kDefaultSize, 0)); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 605 | REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); |
| 606 | REPORTER_ASSERT(reporter, size == cache->getResourceBytes()); |
| 607 | REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceCount()); |
| 608 | REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceBytes()); |
Derek Sollenberger | ee47914 | 2017-05-24 11:41:33 -0400 | [diff] [blame] | 609 | REPORTER_ASSERT(reporter, 0 == cache->getPurgeableBytes()); |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 610 | |
| 611 | // Once it is unrefed, it should become available as scratch. |
| 612 | resource->unref(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 613 | REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); |
| 614 | REPORTER_ASSERT(reporter, size == cache->getResourceBytes()); |
| 615 | REPORTER_ASSERT(reporter, 1 == cache->getBudgetedResourceCount()); |
| 616 | REPORTER_ASSERT(reporter, size == cache->getBudgetedResourceBytes()); |
Derek Sollenberger | ee47914 | 2017-05-24 11:41:33 -0400 | [diff] [blame] | 617 | REPORTER_ASSERT(reporter, size == cache->getPurgeableBytes()); |
robertphillips | 6e83ac7 | 2015-08-13 05:19:14 -0700 | [diff] [blame] | 618 | resource = static_cast<TestResource*>(cache->findAndRefScratchResource(key, TestResource::kDefaultSize, 0)); |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 619 | REPORTER_ASSERT(reporter, resource); |
bsalomon | 3582d3e | 2015-02-13 14:20:05 -0800 | [diff] [blame] | 620 | REPORTER_ASSERT(reporter, resource->resourcePriv().getScratchKey() == key); |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 621 | REPORTER_ASSERT(reporter, resource->cacheAccess().isScratch()); |
bsalomon | 5ec26ae | 2016-02-25 08:33:02 -0800 | [diff] [blame] | 622 | REPORTER_ASSERT(reporter, SkBudgeted::kYes == resource->resourcePriv().isBudgeted()); |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 623 | |
| 624 | if (0 == i) { |
mtklein | 5f939ab | 2016-03-16 10:28:35 -0700 | [diff] [blame] | 625 | // If made unbudgeted, it should return to original state: ref'ed and unbudgeted. Try |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 626 | // the above tests again. |
bsalomon | 3582d3e | 2015-02-13 14:20:05 -0800 | [diff] [blame] | 627 | resource->resourcePriv().makeUnbudgeted(); |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 628 | } else { |
| 629 | // After the second time around, try removing the scratch key |
bsalomon | 3582d3e | 2015-02-13 14:20:05 -0800 | [diff] [blame] | 630 | resource->resourcePriv().removeScratchKey(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 631 | REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); |
| 632 | REPORTER_ASSERT(reporter, size == cache->getResourceBytes()); |
| 633 | REPORTER_ASSERT(reporter, 1 == cache->getBudgetedResourceCount()); |
| 634 | REPORTER_ASSERT(reporter, size == cache->getBudgetedResourceBytes()); |
Derek Sollenberger | ee47914 | 2017-05-24 11:41:33 -0400 | [diff] [blame] | 635 | REPORTER_ASSERT(reporter, 0 == cache->getPurgeableBytes()); |
bsalomon | 3582d3e | 2015-02-13 14:20:05 -0800 | [diff] [blame] | 636 | REPORTER_ASSERT(reporter, !resource->resourcePriv().getScratchKey().isValid()); |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 637 | REPORTER_ASSERT(reporter, !resource->cacheAccess().isScratch()); |
bsalomon | 5ec26ae | 2016-02-25 08:33:02 -0800 | [diff] [blame] | 638 | REPORTER_ASSERT(reporter, SkBudgeted::kYes == resource->resourcePriv().isBudgeted()); |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 639 | |
| 640 | // now when it is unrefed it should die since it has no key. |
| 641 | resource->unref(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 642 | REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
| 643 | REPORTER_ASSERT(reporter, 0 == cache->getResourceBytes()); |
| 644 | REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceCount()); |
| 645 | REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceBytes()); |
Derek Sollenberger | ee47914 | 2017-05-24 11:41:33 -0400 | [diff] [blame] | 646 | REPORTER_ASSERT(reporter, 0 == cache->getPurgeableBytes()); |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 647 | } |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 648 | } |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 649 | } |
| 650 | |
| 651 | static void test_duplicate_scratch_key(skiatest::Reporter* reporter) { |
| 652 | Mock mock(5, 30000); |
| 653 | GrContext* context = mock.context(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 654 | GrResourceCache* cache = mock.cache(); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 655 | |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 656 | // Create two resources that have the same scratch key. |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 657 | TestResource* a = TestResource::CreateScratch(context->getGpu(), |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 658 | SkBudgeted::kYes, |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 659 | TestResource::kB_SimulatedProperty); |
| 660 | TestResource* b = TestResource::CreateScratch(context->getGpu(), |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 661 | SkBudgeted::kYes, |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 662 | TestResource::kB_SimulatedProperty); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 663 | a->setSize(11); |
| 664 | b->setSize(12); |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 665 | GrScratchKey scratchKey1; |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 666 | TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &scratchKey1); |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 667 | // Check for negative case consistency. (leaks upon test failure.) |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 668 | REPORTER_ASSERT(reporter, nullptr == cache->findAndRefScratchResource(scratchKey1, TestResource::kDefaultSize, 0)); |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 669 | |
| 670 | GrScratchKey scratchKey; |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 671 | TestResource::ComputeScratchKey(TestResource::kB_SimulatedProperty, &scratchKey); |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 672 | |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 673 | // Scratch resources are registered with GrResourceCache just by existing. There are 2. |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 674 | REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 675 | SkDEBUGCODE(REPORTER_ASSERT(reporter, 2 == cache->countScratchEntriesForKey(scratchKey));) |
| 676 | REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 677 | REPORTER_ASSERT(reporter, a->gpuMemorySize() + b->gpuMemorySize() == |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 678 | cache->getResourceBytes()); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 679 | |
bsalomon | 63c992f | 2015-01-23 12:47:59 -0800 | [diff] [blame] | 680 | // Our refs mean that the resources are non purgeable. |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 681 | cache->purgeAllUnlocked(); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 682 | REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 683 | REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 684 | |
| 685 | // Unref but don't purge |
| 686 | a->unref(); |
| 687 | b->unref(); |
| 688 | REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 689 | SkDEBUGCODE(REPORTER_ASSERT(reporter, 2 == cache->countScratchEntriesForKey(scratchKey));) |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 690 | |
bsalomon | 63c992f | 2015-01-23 12:47:59 -0800 | [diff] [blame] | 691 | // Purge again. This time resources should be purgeable. |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 692 | cache->purgeAllUnlocked(); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 693 | REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive()); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 694 | REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
| 695 | SkDEBUGCODE(REPORTER_ASSERT(reporter, 0 == cache->countScratchEntriesForKey(scratchKey));) |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 696 | } |
| 697 | |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 698 | static void test_remove_scratch_key(skiatest::Reporter* reporter) { |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 699 | Mock mock(5, 30000); |
| 700 | GrContext* context = mock.context(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 701 | GrResourceCache* cache = mock.cache(); |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 702 | |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 703 | // Create two resources that have the same scratch key. |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 704 | TestResource* a = TestResource::CreateScratch(context->getGpu(), SkBudgeted::kYes, |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 705 | TestResource::kB_SimulatedProperty); |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 706 | TestResource* b = TestResource::CreateScratch(context->getGpu(), SkBudgeted::kYes, |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 707 | TestResource::kB_SimulatedProperty); |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 708 | a->unref(); |
| 709 | b->unref(); |
| 710 | |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 711 | GrScratchKey scratchKey; |
| 712 | // Ensure that scratch key lookup is correct for negative case. |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 713 | TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &scratchKey); |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 714 | // (following leaks upon test failure). |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 715 | REPORTER_ASSERT(reporter, cache->findAndRefScratchResource(scratchKey, TestResource::kDefaultSize, 0) == nullptr); |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 716 | |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 717 | // Scratch resources are registered with GrResourceCache just by existing. There are 2. |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 718 | TestResource::ComputeScratchKey(TestResource::kB_SimulatedProperty, &scratchKey); |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 719 | REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 720 | SkDEBUGCODE(REPORTER_ASSERT(reporter, 2 == cache->countScratchEntriesForKey(scratchKey));) |
| 721 | REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 722 | |
| 723 | // Find the first resource and remove its scratch key |
| 724 | GrGpuResource* find; |
robertphillips | 6e83ac7 | 2015-08-13 05:19:14 -0700 | [diff] [blame] | 725 | find = cache->findAndRefScratchResource(scratchKey, TestResource::kDefaultSize, 0); |
bsalomon | 3582d3e | 2015-02-13 14:20:05 -0800 | [diff] [blame] | 726 | find->resourcePriv().removeScratchKey(); |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 727 | // It's still alive, but not cached by scratch key anymore |
| 728 | REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 729 | SkDEBUGCODE(REPORTER_ASSERT(reporter, 1 == cache->countScratchEntriesForKey(scratchKey));) |
| 730 | REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 731 | |
| 732 | // The cache should immediately delete it when it's unrefed since it isn't accessible. |
| 733 | find->unref(); |
| 734 | REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive()); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 735 | SkDEBUGCODE(REPORTER_ASSERT(reporter, 1 == cache->countScratchEntriesForKey(scratchKey));) |
| 736 | REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 737 | |
| 738 | // Repeat for the second resource. |
robertphillips | 6e83ac7 | 2015-08-13 05:19:14 -0700 | [diff] [blame] | 739 | find = cache->findAndRefScratchResource(scratchKey, TestResource::kDefaultSize, 0); |
bsalomon | 3582d3e | 2015-02-13 14:20:05 -0800 | [diff] [blame] | 740 | find->resourcePriv().removeScratchKey(); |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 741 | REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive()); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 742 | SkDEBUGCODE(REPORTER_ASSERT(reporter, 0 == cache->countScratchEntriesForKey(scratchKey));) |
| 743 | REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 744 | |
| 745 | // Should be able to call this multiple times with no problem. |
bsalomon | 3582d3e | 2015-02-13 14:20:05 -0800 | [diff] [blame] | 746 | find->resourcePriv().removeScratchKey(); |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 747 | REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive()); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 748 | SkDEBUGCODE(REPORTER_ASSERT(reporter, 0 == cache->countScratchEntriesForKey(scratchKey));) |
| 749 | REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 750 | |
| 751 | find->unref(); |
| 752 | REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive()); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 753 | SkDEBUGCODE(REPORTER_ASSERT(reporter, 0 == cache->countScratchEntriesForKey(scratchKey));) |
| 754 | REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 755 | } |
| 756 | |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 757 | static void test_scratch_key_consistency(skiatest::Reporter* reporter) { |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 758 | Mock mock(5, 30000); |
| 759 | GrContext* context = mock.context(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 760 | GrResourceCache* cache = mock.cache(); |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 761 | |
| 762 | // Create two resources that have the same scratch key. |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 763 | TestResource* a = TestResource::CreateScratch(context->getGpu(), SkBudgeted::kYes, |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 764 | TestResource::kB_SimulatedProperty); |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 765 | TestResource* b = TestResource::CreateScratch(context->getGpu(), SkBudgeted::kYes, |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 766 | TestResource::kB_SimulatedProperty); |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 767 | a->unref(); |
| 768 | b->unref(); |
| 769 | |
| 770 | GrScratchKey scratchKey; |
| 771 | // Ensure that scratch key comparison and assignment is consistent. |
| 772 | GrScratchKey scratchKey1; |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 773 | TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &scratchKey1); |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 774 | GrScratchKey scratchKey2; |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 775 | TestResource::ComputeScratchKey(TestResource::kB_SimulatedProperty, &scratchKey2); |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 776 | REPORTER_ASSERT(reporter, scratchKey1.size() == TestResource::ExpectedScratchKeySize()); |
| 777 | REPORTER_ASSERT(reporter, scratchKey1 != scratchKey2); |
| 778 | REPORTER_ASSERT(reporter, scratchKey2 != scratchKey1); |
| 779 | scratchKey = scratchKey1; |
| 780 | REPORTER_ASSERT(reporter, scratchKey.size() == TestResource::ExpectedScratchKeySize()); |
| 781 | REPORTER_ASSERT(reporter, scratchKey1 == scratchKey); |
| 782 | REPORTER_ASSERT(reporter, scratchKey == scratchKey1); |
| 783 | REPORTER_ASSERT(reporter, scratchKey2 != scratchKey); |
| 784 | REPORTER_ASSERT(reporter, scratchKey != scratchKey2); |
| 785 | scratchKey = scratchKey2; |
| 786 | REPORTER_ASSERT(reporter, scratchKey.size() == TestResource::ExpectedScratchKeySize()); |
| 787 | REPORTER_ASSERT(reporter, scratchKey1 != scratchKey); |
| 788 | REPORTER_ASSERT(reporter, scratchKey != scratchKey1); |
| 789 | REPORTER_ASSERT(reporter, scratchKey2 == scratchKey); |
| 790 | REPORTER_ASSERT(reporter, scratchKey == scratchKey2); |
| 791 | |
| 792 | // Ensure that scratch key lookup is correct for negative case. |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 793 | TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &scratchKey); |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 794 | // (following leaks upon test failure). |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 795 | REPORTER_ASSERT(reporter, cache->findAndRefScratchResource(scratchKey, TestResource::kDefaultSize, 0) == nullptr); |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 796 | |
| 797 | // 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] | 798 | TestResource::ComputeScratchKey(TestResource::kB_SimulatedProperty, &scratchKey); |
robertphillips | 6e83ac7 | 2015-08-13 05:19:14 -0700 | [diff] [blame] | 799 | GrGpuResource* find = cache->findAndRefScratchResource(scratchKey, TestResource::kDefaultSize, 0); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 800 | REPORTER_ASSERT(reporter, find != nullptr); |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 801 | find->unref(); |
| 802 | |
| 803 | scratchKey2 = scratchKey; |
robertphillips | 6e83ac7 | 2015-08-13 05:19:14 -0700 | [diff] [blame] | 804 | find = cache->findAndRefScratchResource(scratchKey2, TestResource::kDefaultSize, 0); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 805 | REPORTER_ASSERT(reporter, find != nullptr); |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 806 | REPORTER_ASSERT(reporter, find == a || find == b); |
| 807 | |
robertphillips | 6e83ac7 | 2015-08-13 05:19:14 -0700 | [diff] [blame] | 808 | GrGpuResource* find2 = cache->findAndRefScratchResource(scratchKey2, TestResource::kDefaultSize, 0); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 809 | REPORTER_ASSERT(reporter, find2 != nullptr); |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 810 | REPORTER_ASSERT(reporter, find2 == a || find2 == b); |
| 811 | REPORTER_ASSERT(reporter, find2 != find); |
| 812 | find2->unref(); |
| 813 | find->unref(); |
| 814 | } |
| 815 | |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 816 | static void test_duplicate_unique_key(skiatest::Reporter* reporter) { |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 817 | Mock mock(5, 30000); |
| 818 | GrContext* context = mock.context(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 819 | GrResourceCache* cache = mock.cache(); |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 820 | |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 821 | GrUniqueKey key; |
| 822 | make_unique_key<0>(&key, 0); |
mtklein | 5f939ab | 2016-03-16 10:28:35 -0700 | [diff] [blame] | 823 | |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 824 | // Create two resources that we will attempt to register with the same unique key. |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 825 | TestResource* a = new TestResource(context->getGpu()); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 826 | a->setSize(11); |
mtklein | 5f939ab | 2016-03-16 10:28:35 -0700 | [diff] [blame] | 827 | |
bsalomon | f99e961 | 2015-02-19 08:24:16 -0800 | [diff] [blame] | 828 | // Set key on resource a. |
| 829 | a->resourcePriv().setUniqueKey(key); |
| 830 | REPORTER_ASSERT(reporter, a == cache->findAndRefUniqueResource(key)); |
| 831 | a->unref(); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 832 | |
bsalomon | f99e961 | 2015-02-19 08:24:16 -0800 | [diff] [blame] | 833 | // Make sure that redundantly setting a's key works. |
| 834 | a->resourcePriv().setUniqueKey(key); |
| 835 | REPORTER_ASSERT(reporter, a == cache->findAndRefUniqueResource(key)); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 836 | a->unref(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 837 | REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); |
| 838 | REPORTER_ASSERT(reporter, a->gpuMemorySize() == cache->getResourceBytes()); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 839 | REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive()); |
| 840 | |
bsalomon | f99e961 | 2015-02-19 08:24:16 -0800 | [diff] [blame] | 841 | // Create resource b and set the same key. It should replace a's unique key cache entry. |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 842 | TestResource* b = new TestResource(context->getGpu()); |
bsalomon | f99e961 | 2015-02-19 08:24:16 -0800 | [diff] [blame] | 843 | b->setSize(12); |
| 844 | b->resourcePriv().setUniqueKey(key); |
| 845 | REPORTER_ASSERT(reporter, b == cache->findAndRefUniqueResource(key)); |
| 846 | b->unref(); |
| 847 | |
| 848 | // Still have two resources because a is still reffed. |
| 849 | REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); |
| 850 | REPORTER_ASSERT(reporter, a->gpuMemorySize() + b->gpuMemorySize() == cache->getResourceBytes()); |
| 851 | REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); |
| 852 | |
| 853 | a->unref(); |
| 854 | // Now a should be gone. |
| 855 | REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); |
| 856 | REPORTER_ASSERT(reporter, b->gpuMemorySize() == cache->getResourceBytes()); |
| 857 | REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive()); |
| 858 | |
| 859 | // Now replace b with c, but make sure c can start with one unique key and change it to b's key. |
| 860 | // Also make b be unreffed when replacement occurs. |
| 861 | b->unref(); |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 862 | TestResource* c = new TestResource(context->getGpu()); |
bsalomon | f99e961 | 2015-02-19 08:24:16 -0800 | [diff] [blame] | 863 | GrUniqueKey differentKey; |
| 864 | make_unique_key<0>(&differentKey, 1); |
| 865 | c->setSize(13); |
| 866 | c->resourcePriv().setUniqueKey(differentKey); |
| 867 | REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); |
| 868 | REPORTER_ASSERT(reporter, b->gpuMemorySize() + c->gpuMemorySize() == cache->getResourceBytes()); |
| 869 | REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); |
| 870 | // c replaces b and b should be immediately purged. |
| 871 | c->resourcePriv().setUniqueKey(key); |
| 872 | REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); |
| 873 | REPORTER_ASSERT(reporter, c->gpuMemorySize() == cache->getResourceBytes()); |
| 874 | REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive()); |
| 875 | |
| 876 | // c shouldn't be purged because it is ref'ed. |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 877 | cache->purgeAllUnlocked(); |
bsalomon | f99e961 | 2015-02-19 08:24:16 -0800 | [diff] [blame] | 878 | REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); |
| 879 | REPORTER_ASSERT(reporter, c->gpuMemorySize() == cache->getResourceBytes()); |
| 880 | REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive()); |
| 881 | |
| 882 | // Drop the ref on c, it should be kept alive because it has a unique key. |
| 883 | c->unref(); |
| 884 | REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); |
| 885 | REPORTER_ASSERT(reporter, c->gpuMemorySize() == cache->getResourceBytes()); |
| 886 | REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive()); |
| 887 | |
| 888 | // Verify that we can find c, then remove its unique key. It should get purged immediately. |
| 889 | REPORTER_ASSERT(reporter, c == cache->findAndRefUniqueResource(key)); |
| 890 | c->resourcePriv().removeUniqueKey(); |
| 891 | c->unref(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 892 | REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
| 893 | REPORTER_ASSERT(reporter, 0 == cache->getResourceBytes()); |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 894 | REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive()); |
senorblanco | 84cd621 | 2015-08-04 10:01:58 -0700 | [diff] [blame] | 895 | |
| 896 | { |
| 897 | GrUniqueKey key2; |
| 898 | make_unique_key<0>(&key2, 0); |
Hal Canary | 342b7ac | 2016-11-04 11:49:42 -0400 | [diff] [blame] | 899 | sk_sp<TestResource> d(new TestResource(context->getGpu())); |
senorblanco | 84cd621 | 2015-08-04 10:01:58 -0700 | [diff] [blame] | 900 | int foo = 4132; |
bungeman | 38d909e | 2016-08-02 14:40:46 -0700 | [diff] [blame] | 901 | key2.setCustomData(SkData::MakeWithCopy(&foo, sizeof(foo))); |
senorblanco | 84cd621 | 2015-08-04 10:01:58 -0700 | [diff] [blame] | 902 | d->resourcePriv().setUniqueKey(key2); |
| 903 | } |
| 904 | |
| 905 | GrUniqueKey key3; |
| 906 | make_unique_key<0>(&key3, 0); |
Hal Canary | 342b7ac | 2016-11-04 11:49:42 -0400 | [diff] [blame] | 907 | sk_sp<GrGpuResource> d2(cache->findAndRefUniqueResource(key3)); |
senorblanco | 84cd621 | 2015-08-04 10:01:58 -0700 | [diff] [blame] | 908 | REPORTER_ASSERT(reporter, *(int*) d2->getUniqueKey().getCustomData()->data() == 4132); |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 909 | } |
| 910 | |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 911 | static void test_purge_invalidated(skiatest::Reporter* reporter) { |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 912 | Mock mock(5, 30000); |
| 913 | GrContext* context = mock.context(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 914 | GrResourceCache* cache = mock.cache(); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 915 | |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 916 | GrUniqueKey key1, key2, key3; |
| 917 | make_unique_key<0>(&key1, 1); |
| 918 | make_unique_key<0>(&key2, 2); |
| 919 | make_unique_key<0>(&key3, 3); |
mtklein | 5f939ab | 2016-03-16 10:28:35 -0700 | [diff] [blame] | 920 | |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 921 | // Add three resources to the cache. Only c is usable as scratch. |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 922 | TestResource* a = new TestResource(context->getGpu()); |
| 923 | TestResource* b = new TestResource(context->getGpu()); |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 924 | TestResource* c = TestResource::CreateScratch(context->getGpu(), SkBudgeted::kYes, |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 925 | TestResource::kA_SimulatedProperty); |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 926 | a->resourcePriv().setUniqueKey(key1); |
| 927 | b->resourcePriv().setUniqueKey(key2); |
| 928 | c->resourcePriv().setUniqueKey(key3); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 929 | a->unref(); |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 930 | // hold b until *after* the message is sent. |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 931 | c->unref(); |
| 932 | |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 933 | REPORTER_ASSERT(reporter, cache->hasUniqueKey(key1)); |
| 934 | REPORTER_ASSERT(reporter, cache->hasUniqueKey(key2)); |
| 935 | REPORTER_ASSERT(reporter, cache->hasUniqueKey(key3)); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 936 | REPORTER_ASSERT(reporter, 3 == TestResource::NumAlive()); |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 937 | |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 938 | typedef GrUniqueKeyInvalidatedMessage Msg; |
| 939 | typedef SkMessageBus<GrUniqueKeyInvalidatedMessage> Bus; |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 940 | |
| 941 | // Invalidate two of the three, they should be purged and no longer accessible via their keys. |
| 942 | Bus::Post(Msg(key1)); |
| 943 | Bus::Post(Msg(key2)); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 944 | cache->purgeAsNeeded(); |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 945 | // a should be deleted now, but we still have a ref on b. |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 946 | REPORTER_ASSERT(reporter, !cache->hasUniqueKey(key1)); |
| 947 | REPORTER_ASSERT(reporter, !cache->hasUniqueKey(key2)); |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 948 | REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 949 | REPORTER_ASSERT(reporter, cache->hasUniqueKey(key3)); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 950 | |
| 951 | // Invalidate the third. |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 952 | Bus::Post(Msg(key3)); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 953 | cache->purgeAsNeeded(); |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 954 | // we still have a ref on b, c should be recycled as scratch. |
| 955 | REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 956 | REPORTER_ASSERT(reporter, !cache->hasUniqueKey(key3)); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 957 | |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 958 | // make b purgeable. It should be immediately deleted since it has no key. |
| 959 | b->unref(); |
| 960 | REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive()); |
| 961 | |
| 962 | // Make sure we actually get to c via it's scratch key, before we say goodbye. |
| 963 | GrScratchKey scratchKey; |
| 964 | TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &scratchKey); |
robertphillips | 6e83ac7 | 2015-08-13 05:19:14 -0700 | [diff] [blame] | 965 | GrGpuResource* scratch = cache->findAndRefScratchResource(scratchKey, TestResource::kDefaultSize, 0); |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 966 | REPORTER_ASSERT(reporter, scratch == c); |
| 967 | SkSafeUnref(scratch); |
| 968 | |
| 969 | // Get rid of c. |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 970 | cache->purgeAllUnlocked(); |
robertphillips | 6e83ac7 | 2015-08-13 05:19:14 -0700 | [diff] [blame] | 971 | scratch = cache->findAndRefScratchResource(scratchKey, TestResource::kDefaultSize, 0); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 972 | REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive()); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 973 | REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
| 974 | REPORTER_ASSERT(reporter, 0 == cache->getResourceBytes()); |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 975 | REPORTER_ASSERT(reporter, !scratch); |
| 976 | SkSafeUnref(scratch); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 977 | } |
| 978 | |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 979 | static void test_cache_chained_purge(skiatest::Reporter* reporter) { |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 980 | Mock mock(3, 30000); |
| 981 | GrContext* context = mock.context(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 982 | GrResourceCache* cache = mock.cache(); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 983 | |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 984 | GrUniqueKey key1, key2; |
| 985 | make_unique_key<0>(&key1, 1); |
| 986 | make_unique_key<0>(&key2, 2); |
commit-bot@chromium.org | bd58feb | 2014-01-17 17:56:21 +0000 | [diff] [blame] | 987 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 988 | TestResource* a = new TestResource(context->getGpu()); |
| 989 | TestResource* b = new TestResource(context->getGpu()); |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 990 | a->resourcePriv().setUniqueKey(key1); |
| 991 | b->resourcePriv().setUniqueKey(key2); |
bsalomon | 820dd6c | 2014-11-05 12:09:45 -0800 | [diff] [blame] | 992 | |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 993 | // Make a cycle |
| 994 | a->setUnrefWhenDestroyed(b); |
| 995 | b->setUnrefWhenDestroyed(a); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 996 | |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 997 | REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 998 | |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 999 | a->unref(); |
| 1000 | b->unref(); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 1001 | |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 1002 | REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 1003 | |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 1004 | cache->purgeAllUnlocked(); |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 1005 | REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 1006 | |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 1007 | // Break the cycle |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1008 | a->setUnrefWhenDestroyed(nullptr); |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 1009 | REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 1010 | |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 1011 | cache->purgeAllUnlocked(); |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 1012 | REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive()); |
commit-bot@chromium.org | bd58feb | 2014-01-17 17:56:21 +0000 | [diff] [blame] | 1013 | } |
| 1014 | |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 1015 | static void test_resource_size_changed(skiatest::Reporter* reporter) { |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 1016 | GrUniqueKey key1, key2; |
| 1017 | make_unique_key<0>(&key1, 1); |
| 1018 | make_unique_key<0>(&key2, 2); |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 1019 | |
| 1020 | // Test changing resources sizes (both increase & decrease). |
| 1021 | { |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 1022 | Mock mock(3, 30000); |
| 1023 | GrContext* context = mock.context(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 1024 | GrResourceCache* cache = mock.cache(); |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 1025 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 1026 | TestResource* a = new TestResource(context->getGpu()); |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 1027 | a->resourcePriv().setUniqueKey(key1); |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 1028 | a->unref(); |
| 1029 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 1030 | TestResource* b = new TestResource(context->getGpu()); |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 1031 | b->resourcePriv().setUniqueKey(key2); |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 1032 | b->unref(); |
| 1033 | |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 1034 | REPORTER_ASSERT(reporter, 200 == cache->getResourceBytes()); |
| 1035 | REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 1036 | { |
Hal Canary | 342b7ac | 2016-11-04 11:49:42 -0400 | [diff] [blame] | 1037 | sk_sp<TestResource> find2( |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 1038 | static_cast<TestResource*>(cache->findAndRefUniqueResource(key2))); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 1039 | find2->setSize(200); |
Hal Canary | 342b7ac | 2016-11-04 11:49:42 -0400 | [diff] [blame] | 1040 | sk_sp<TestResource> find1( |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 1041 | static_cast<TestResource*>(cache->findAndRefUniqueResource(key1))); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 1042 | find1->setSize(50); |
| 1043 | } |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 1044 | |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 1045 | REPORTER_ASSERT(reporter, 250 == cache->getResourceBytes()); |
| 1046 | REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 1047 | } |
| 1048 | |
| 1049 | // Test increasing a resources size beyond the cache budget. |
| 1050 | { |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 1051 | Mock mock(2, 300); |
| 1052 | GrContext* context = mock.context(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 1053 | GrResourceCache* cache = mock.cache(); |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 1054 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 1055 | TestResource* a = new TestResource(context->getGpu()); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 1056 | a->setSize(100); |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 1057 | a->resourcePriv().setUniqueKey(key1); |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 1058 | a->unref(); |
| 1059 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 1060 | TestResource* b = new TestResource(context->getGpu()); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 1061 | b->setSize(100); |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 1062 | b->resourcePriv().setUniqueKey(key2); |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 1063 | b->unref(); |
| 1064 | |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 1065 | REPORTER_ASSERT(reporter, 200 == cache->getResourceBytes()); |
| 1066 | REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 1067 | |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 1068 | { |
Hal Canary | 342b7ac | 2016-11-04 11:49:42 -0400 | [diff] [blame] | 1069 | sk_sp<TestResource> find2(static_cast<TestResource*>( |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 1070 | cache->findAndRefUniqueResource(key2))); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 1071 | find2->setSize(201); |
| 1072 | } |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 1073 | REPORTER_ASSERT(reporter, !cache->hasUniqueKey(key1)); |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 1074 | |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 1075 | REPORTER_ASSERT(reporter, 201 == cache->getResourceBytes()); |
| 1076 | REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 1077 | } |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 1078 | } |
| 1079 | |
bsalomon | ddf30e6 | 2015-02-19 11:38:44 -0800 | [diff] [blame] | 1080 | static void test_timestamp_wrap(skiatest::Reporter* reporter) { |
| 1081 | static const int kCount = 50; |
| 1082 | static const int kBudgetCnt = kCount / 2; |
| 1083 | static const int kLockedFreq = 8; |
| 1084 | static const int kBudgetSize = 0x80000000; |
| 1085 | |
| 1086 | SkRandom random; |
| 1087 | |
| 1088 | // Run the test 2*kCount times; |
| 1089 | for (int i = 0; i < 2 * kCount; ++i ) { |
| 1090 | Mock mock(kBudgetCnt, kBudgetSize); |
| 1091 | GrContext* context = mock.context(); |
| 1092 | GrResourceCache* cache = mock.cache(); |
| 1093 | |
| 1094 | // Pick a random number of resources to add before the timestamp will wrap. |
| 1095 | cache->changeTimestamp(SK_MaxU32 - random.nextULessThan(kCount + 1)); |
| 1096 | |
| 1097 | static const int kNumToPurge = kCount - kBudgetCnt; |
| 1098 | |
| 1099 | SkTDArray<int> shouldPurgeIdxs; |
| 1100 | int purgeableCnt = 0; |
| 1101 | SkTDArray<GrGpuResource*> resourcesToUnref; |
| 1102 | |
| 1103 | // Add kCount resources, holding onto resources at random so we have a mix of purgeable and |
| 1104 | // unpurgeable resources. |
| 1105 | for (int j = 0; j < kCount; ++j) { |
| 1106 | GrUniqueKey key; |
| 1107 | make_unique_key<0>(&key, j); |
| 1108 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 1109 | TestResource* r = new TestResource(context->getGpu()); |
bsalomon | ddf30e6 | 2015-02-19 11:38:44 -0800 | [diff] [blame] | 1110 | r->resourcePriv().setUniqueKey(key); |
| 1111 | if (random.nextU() % kLockedFreq) { |
| 1112 | // Make this is purgeable. |
| 1113 | r->unref(); |
| 1114 | ++purgeableCnt; |
| 1115 | if (purgeableCnt <= kNumToPurge) { |
| 1116 | *shouldPurgeIdxs.append() = j; |
| 1117 | } |
| 1118 | } else { |
| 1119 | *resourcesToUnref.append() = r; |
| 1120 | } |
| 1121 | } |
| 1122 | |
| 1123 | // Verify that the correct resources were purged. |
| 1124 | int currShouldPurgeIdx = 0; |
| 1125 | for (int j = 0; j < kCount; ++j) { |
| 1126 | GrUniqueKey key; |
| 1127 | make_unique_key<0>(&key, j); |
| 1128 | GrGpuResource* res = cache->findAndRefUniqueResource(key); |
| 1129 | if (currShouldPurgeIdx < shouldPurgeIdxs.count() && |
| 1130 | shouldPurgeIdxs[currShouldPurgeIdx] == j) { |
| 1131 | ++currShouldPurgeIdx; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1132 | REPORTER_ASSERT(reporter, nullptr == res); |
bsalomon | ddf30e6 | 2015-02-19 11:38:44 -0800 | [diff] [blame] | 1133 | } else { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1134 | REPORTER_ASSERT(reporter, nullptr != res); |
bsalomon | ddf30e6 | 2015-02-19 11:38:44 -0800 | [diff] [blame] | 1135 | } |
| 1136 | SkSafeUnref(res); |
| 1137 | } |
| 1138 | |
| 1139 | for (int j = 0; j < resourcesToUnref.count(); ++j) { |
| 1140 | resourcesToUnref[j]->unref(); |
| 1141 | } |
| 1142 | } |
| 1143 | } |
| 1144 | |
bsalomon | 3f32432 | 2015-04-08 11:01:54 -0700 | [diff] [blame] | 1145 | static void test_flush(skiatest::Reporter* reporter) { |
| 1146 | Mock mock(1000000, 1000000); |
| 1147 | GrContext* context = mock.context(); |
| 1148 | GrResourceCache* cache = mock.cache(); |
| 1149 | |
| 1150 | // The current cache impl will round the max flush count to the next power of 2. So we choose a |
| 1151 | // power of two here to keep things simpler. |
| 1152 | static const int kFlushCount = 16; |
| 1153 | cache->setLimits(1000000, 1000000, kFlushCount); |
| 1154 | |
| 1155 | { |
| 1156 | // Insert a resource and send a flush notification kFlushCount times. |
| 1157 | for (int i = 0; i < kFlushCount; ++i) { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 1158 | TestResource* r = new TestResource(context->getGpu()); |
bsalomon | 3f32432 | 2015-04-08 11:01:54 -0700 | [diff] [blame] | 1159 | GrUniqueKey k; |
| 1160 | make_unique_key<1>(&k, i); |
| 1161 | r->resourcePriv().setUniqueKey(k); |
| 1162 | r->unref(); |
bsalomon | b77a907 | 2016-09-07 10:02:04 -0700 | [diff] [blame] | 1163 | cache->notifyFlushOccurred(GrResourceCache::kExternal); |
bsalomon | 3f32432 | 2015-04-08 11:01:54 -0700 | [diff] [blame] | 1164 | } |
| 1165 | |
| 1166 | // Send flush notifications to the cache. Each flush should purge the oldest resource. |
bsalomon | e2e87f3 | 2016-09-22 12:42:11 -0700 | [diff] [blame] | 1167 | for (int i = 0; i < kFlushCount; ++i) { |
| 1168 | cache->notifyFlushOccurred(GrResourceCache::kExternal); |
bsalomon | 3f32432 | 2015-04-08 11:01:54 -0700 | [diff] [blame] | 1169 | REPORTER_ASSERT(reporter, kFlushCount - i - 1 == cache->getResourceCount()); |
| 1170 | for (int j = 0; j < i; ++j) { |
| 1171 | GrUniqueKey k; |
| 1172 | make_unique_key<1>(&k, j); |
| 1173 | GrGpuResource* r = cache->findAndRefUniqueResource(k); |
| 1174 | REPORTER_ASSERT(reporter, !SkToBool(r)); |
| 1175 | SkSafeUnref(r); |
| 1176 | } |
bsalomon | 3f32432 | 2015-04-08 11:01:54 -0700 | [diff] [blame] | 1177 | } |
| 1178 | |
| 1179 | REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
| 1180 | cache->purgeAllUnlocked(); |
| 1181 | } |
| 1182 | |
| 1183 | // Do a similar test but where we leave refs on some resources to prevent them from being |
| 1184 | // purged. |
| 1185 | { |
| 1186 | GrGpuResource* refedResources[kFlushCount >> 1]; |
| 1187 | for (int i = 0; i < kFlushCount; ++i) { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 1188 | TestResource* r = new TestResource(context->getGpu()); |
bsalomon | 3f32432 | 2015-04-08 11:01:54 -0700 | [diff] [blame] | 1189 | GrUniqueKey k; |
| 1190 | make_unique_key<1>(&k, i); |
| 1191 | r->resourcePriv().setUniqueKey(k); |
| 1192 | // Leave a ref on every other resource, beginning with the first. |
| 1193 | if (SkToBool(i & 0x1)) { |
| 1194 | refedResources[i/2] = r; |
| 1195 | } else { |
| 1196 | r->unref(); |
| 1197 | } |
bsalomon | b77a907 | 2016-09-07 10:02:04 -0700 | [diff] [blame] | 1198 | cache->notifyFlushOccurred(GrResourceCache::kExternal); |
bsalomon | 3f32432 | 2015-04-08 11:01:54 -0700 | [diff] [blame] | 1199 | } |
| 1200 | |
| 1201 | for (int i = 0; i < kFlushCount; ++i) { |
| 1202 | // Should get a resource purged every other flush. |
bsalomon | b77a907 | 2016-09-07 10:02:04 -0700 | [diff] [blame] | 1203 | cache->notifyFlushOccurred(GrResourceCache::kExternal); |
bsalomon | e2e87f3 | 2016-09-22 12:42:11 -0700 | [diff] [blame] | 1204 | REPORTER_ASSERT(reporter, kFlushCount - i/2 - 1 == cache->getResourceCount()); |
bsalomon | 3f32432 | 2015-04-08 11:01:54 -0700 | [diff] [blame] | 1205 | } |
| 1206 | |
| 1207 | // Unref all the resources that we kept refs on in the first loop. |
| 1208 | for (int i = 0; i < kFlushCount >> 1; ++i) { |
| 1209 | refedResources[i]->unref(); |
| 1210 | } |
| 1211 | |
bsalomon | e2e87f3 | 2016-09-22 12:42:11 -0700 | [diff] [blame] | 1212 | // After kFlushCount + 1 flushes they all will have sat in the purgeable queue for |
| 1213 | // kFlushCount full flushes. |
| 1214 | for (int i = 0; i < kFlushCount + 1; ++i) { |
bsalomon | 3f32432 | 2015-04-08 11:01:54 -0700 | [diff] [blame] | 1215 | REPORTER_ASSERT(reporter, kFlushCount >> 1 == cache->getResourceCount()); |
bsalomon | b77a907 | 2016-09-07 10:02:04 -0700 | [diff] [blame] | 1216 | cache->notifyFlushOccurred(GrResourceCache::kExternal); |
bsalomon | 3f32432 | 2015-04-08 11:01:54 -0700 | [diff] [blame] | 1217 | } |
| 1218 | REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
| 1219 | |
| 1220 | cache->purgeAllUnlocked(); |
| 1221 | } |
| 1222 | |
| 1223 | REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
bsalomon | dc43898 | 2016-08-31 11:53:49 -0700 | [diff] [blame] | 1224 | |
| 1225 | // Verify that calling flush() on a GrContext with nothing to do will not trigger resource |
| 1226 | // eviction. |
| 1227 | context->flush(); |
| 1228 | for (int i = 0; i < 10; ++i) { |
| 1229 | TestResource* r = new TestResource(context->getGpu()); |
| 1230 | GrUniqueKey k; |
| 1231 | make_unique_key<1>(&k, i); |
| 1232 | r->resourcePriv().setUniqueKey(k); |
| 1233 | r->unref(); |
| 1234 | } |
| 1235 | REPORTER_ASSERT(reporter, 10 == cache->getResourceCount()); |
| 1236 | for (int i = 0; i < 10 * kFlushCount; ++i) { |
| 1237 | context->flush(); |
| 1238 | } |
| 1239 | REPORTER_ASSERT(reporter, 10 == cache->getResourceCount()); |
bsalomon | 3f32432 | 2015-04-08 11:01:54 -0700 | [diff] [blame] | 1240 | } |
| 1241 | |
Brian Salomon | 5e15085 | 2017-03-22 14:53:13 -0400 | [diff] [blame] | 1242 | static void test_time_purge(skiatest::Reporter* reporter) { |
| 1243 | Mock mock(1000000, 1000000); |
| 1244 | GrContext* context = mock.context(); |
| 1245 | GrResourceCache* cache = mock.cache(); |
| 1246 | |
| 1247 | static constexpr int kCnts[] = {1, 10, 1024}; |
| 1248 | auto nowish = []() { |
| 1249 | // We sleep so that we ensure we get a value that is greater than the last call to |
| 1250 | // GrStdSteadyClock::now(). |
| 1251 | std::this_thread::sleep_for(GrStdSteadyClock::duration(5)); |
| 1252 | auto result = GrStdSteadyClock::now(); |
| 1253 | // Also sleep afterwards so we don't get this value again. |
| 1254 | std::this_thread::sleep_for(GrStdSteadyClock::duration(5)); |
| 1255 | return result; |
| 1256 | }; |
| 1257 | |
| 1258 | for (int cnt : kCnts) { |
| 1259 | std::unique_ptr<GrStdSteadyClock::time_point[]> timeStamps( |
| 1260 | new GrStdSteadyClock::time_point[cnt]); |
| 1261 | { |
| 1262 | // Insert resources and get time points between each addition. |
| 1263 | for (int i = 0; i < cnt; ++i) { |
| 1264 | TestResource* r = new TestResource(context->getGpu()); |
| 1265 | GrUniqueKey k; |
| 1266 | make_unique_key<1>(&k, i); |
| 1267 | r->resourcePriv().setUniqueKey(k); |
| 1268 | r->unref(); |
| 1269 | timeStamps.get()[i] = nowish(); |
| 1270 | } |
| 1271 | |
| 1272 | // Purge based on the time points between resource additions. Each purge should remove |
| 1273 | // the oldest resource. |
| 1274 | for (int i = 0; i < cnt; ++i) { |
| 1275 | cache->purgeResourcesNotUsedSince(timeStamps[i]); |
| 1276 | REPORTER_ASSERT(reporter, cnt - i - 1 == cache->getResourceCount()); |
| 1277 | for (int j = 0; j < i; ++j) { |
| 1278 | GrUniqueKey k; |
| 1279 | make_unique_key<1>(&k, j); |
| 1280 | GrGpuResource* r = cache->findAndRefUniqueResource(k); |
| 1281 | REPORTER_ASSERT(reporter, !SkToBool(r)); |
| 1282 | SkSafeUnref(r); |
| 1283 | } |
| 1284 | } |
| 1285 | |
| 1286 | REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
| 1287 | cache->purgeAllUnlocked(); |
| 1288 | } |
| 1289 | |
| 1290 | // Do a similar test but where we leave refs on some resources to prevent them from being |
| 1291 | // purged. |
| 1292 | { |
| 1293 | std::unique_ptr<GrGpuResource* []> refedResources(new GrGpuResource*[cnt / 2]); |
| 1294 | for (int i = 0; i < cnt; ++i) { |
| 1295 | TestResource* r = new TestResource(context->getGpu()); |
| 1296 | GrUniqueKey k; |
| 1297 | make_unique_key<1>(&k, i); |
| 1298 | r->resourcePriv().setUniqueKey(k); |
| 1299 | // Leave a ref on every other resource, beginning with the first. |
| 1300 | if (SkToBool(i & 0x1)) { |
| 1301 | refedResources.get()[i / 2] = r; |
| 1302 | } else { |
| 1303 | r->unref(); |
| 1304 | } |
| 1305 | timeStamps.get()[i] = nowish(); |
| 1306 | } |
| 1307 | |
| 1308 | for (int i = 0; i < cnt; ++i) { |
| 1309 | // Should get a resource purged every other frame. |
| 1310 | cache->purgeResourcesNotUsedSince(timeStamps[i]); |
| 1311 | REPORTER_ASSERT(reporter, cnt - i / 2 - 1 == cache->getResourceCount()); |
| 1312 | } |
| 1313 | |
| 1314 | // Unref all the resources that we kept refs on in the first loop. |
| 1315 | for (int i = 0; i < (cnt / 2); ++i) { |
| 1316 | refedResources.get()[i]->unref(); |
| 1317 | cache->purgeResourcesNotUsedSince(nowish()); |
| 1318 | REPORTER_ASSERT(reporter, cnt / 2 - i - 1 == cache->getResourceCount()); |
| 1319 | } |
| 1320 | |
| 1321 | cache->purgeAllUnlocked(); |
| 1322 | } |
| 1323 | |
| 1324 | REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
| 1325 | |
| 1326 | // Verify that calling flush() on a GrContext with nothing to do will not trigger resource |
| 1327 | // eviction |
| 1328 | context->flush(); |
| 1329 | for (int i = 0; i < 10; ++i) { |
| 1330 | TestResource* r = new TestResource(context->getGpu()); |
| 1331 | GrUniqueKey k; |
| 1332 | make_unique_key<1>(&k, i); |
| 1333 | r->resourcePriv().setUniqueKey(k); |
| 1334 | r->unref(); |
| 1335 | } |
| 1336 | REPORTER_ASSERT(reporter, 10 == cache->getResourceCount()); |
| 1337 | context->flush(); |
| 1338 | REPORTER_ASSERT(reporter, 10 == cache->getResourceCount()); |
| 1339 | cache->purgeResourcesNotUsedSince(nowish()); |
| 1340 | REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
| 1341 | } |
| 1342 | } |
| 1343 | |
Derek Sollenberger | 5480a18 | 2017-05-25 16:43:59 -0400 | [diff] [blame] | 1344 | static void test_partial_purge(skiatest::Reporter* reporter) { |
| 1345 | Mock mock(6, 100); |
| 1346 | GrContext* context = mock.context(); |
| 1347 | GrResourceCache* cache = mock.cache(); |
| 1348 | |
| 1349 | enum TestsCase { |
| 1350 | kOnlyScratch_TestCase = 0, |
| 1351 | kPartialScratch_TestCase = 1, |
| 1352 | kAllScratch_TestCase = 2, |
| 1353 | kPartial_TestCase = 3, |
| 1354 | kAll_TestCase = 4, |
| 1355 | kNone_TestCase = 5, |
| 1356 | kEndTests_TestCase = kNone_TestCase + 1 |
| 1357 | }; |
| 1358 | |
| 1359 | for (int testCase = 0; testCase < kEndTests_TestCase; testCase++) { |
| 1360 | |
| 1361 | GrUniqueKey key1, key2, key3; |
| 1362 | make_unique_key<0>(&key1, 1); |
| 1363 | make_unique_key<0>(&key2, 2); |
| 1364 | make_unique_key<0>(&key3, 3); |
| 1365 | |
| 1366 | // Add three unique resources to the cache. |
| 1367 | TestResource *unique1 = new TestResource(context->getGpu()); |
| 1368 | TestResource *unique2 = new TestResource(context->getGpu()); |
| 1369 | TestResource *unique3 = new TestResource(context->getGpu()); |
| 1370 | |
| 1371 | unique1->resourcePriv().setUniqueKey(key1); |
| 1372 | unique2->resourcePriv().setUniqueKey(key2); |
| 1373 | unique3->resourcePriv().setUniqueKey(key3); |
| 1374 | |
| 1375 | unique1->setSize(10); |
| 1376 | unique2->setSize(11); |
| 1377 | unique3->setSize(12); |
| 1378 | |
| 1379 | // Add two scratch resources to the cache. |
| 1380 | TestResource *scratch1 = TestResource::CreateScratch(context->getGpu(), SkBudgeted::kYes, |
| 1381 | TestResource::kA_SimulatedProperty); |
| 1382 | TestResource *scratch2 = TestResource::CreateScratch(context->getGpu(), SkBudgeted::kYes, |
| 1383 | TestResource::kB_SimulatedProperty); |
| 1384 | scratch1->setSize(13); |
| 1385 | scratch2->setSize(14); |
| 1386 | |
| 1387 | |
| 1388 | REPORTER_ASSERT(reporter, 5 == cache->getBudgetedResourceCount()); |
| 1389 | REPORTER_ASSERT(reporter, 60 == cache->getBudgetedResourceBytes()); |
| 1390 | REPORTER_ASSERT(reporter, 0 == cache->getPurgeableBytes()); |
| 1391 | |
| 1392 | // Add resources to the purgeable queue |
| 1393 | unique1->unref(); |
| 1394 | scratch1->unref(); |
| 1395 | unique2->unref(); |
| 1396 | scratch2->unref(); |
| 1397 | unique3->unref(); |
| 1398 | |
| 1399 | REPORTER_ASSERT(reporter, 5 == cache->getBudgetedResourceCount()); |
| 1400 | REPORTER_ASSERT(reporter, 60 == cache->getBudgetedResourceBytes()); |
| 1401 | REPORTER_ASSERT(reporter, 60 == cache->getPurgeableBytes()); |
| 1402 | |
| 1403 | switch(testCase) { |
| 1404 | case kOnlyScratch_TestCase: { |
| 1405 | context->purgeUnlockedResources(14, true); |
| 1406 | REPORTER_ASSERT(reporter, 3 == cache->getBudgetedResourceCount()); |
| 1407 | REPORTER_ASSERT(reporter, 33 == cache->getBudgetedResourceBytes()); |
| 1408 | break; |
| 1409 | } |
| 1410 | case kPartialScratch_TestCase: { |
| 1411 | context->purgeUnlockedResources(3, true); |
| 1412 | REPORTER_ASSERT(reporter, 4 == cache->getBudgetedResourceCount()); |
| 1413 | REPORTER_ASSERT(reporter, 47 == cache->getBudgetedResourceBytes()); |
| 1414 | break; |
| 1415 | } |
| 1416 | case kAllScratch_TestCase: { |
| 1417 | context->purgeUnlockedResources(50, true); |
| 1418 | REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceCount()); |
| 1419 | REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceBytes()); |
| 1420 | break; |
| 1421 | } |
| 1422 | case kPartial_TestCase: { |
| 1423 | context->purgeUnlockedResources(13, false); |
| 1424 | REPORTER_ASSERT(reporter, 3 == cache->getBudgetedResourceCount()); |
| 1425 | REPORTER_ASSERT(reporter, 37 == cache->getBudgetedResourceBytes()); |
| 1426 | break; |
| 1427 | } |
| 1428 | case kAll_TestCase: { |
| 1429 | context->purgeUnlockedResources(50, false); |
| 1430 | REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceCount()); |
| 1431 | REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceBytes()); |
| 1432 | break; |
| 1433 | } |
| 1434 | case kNone_TestCase: { |
| 1435 | context->purgeUnlockedResources(0, true); |
| 1436 | context->purgeUnlockedResources(0, false); |
| 1437 | REPORTER_ASSERT(reporter, 5 == cache->getBudgetedResourceCount()); |
| 1438 | REPORTER_ASSERT(reporter, 60 == cache->getBudgetedResourceBytes()); |
| 1439 | REPORTER_ASSERT(reporter, 60 == cache->getPurgeableBytes()); |
| 1440 | break; |
| 1441 | } |
| 1442 | }; |
| 1443 | |
| 1444 | // ensure all are purged before the next |
| 1445 | context->purgeAllUnlockedResources(); |
| 1446 | REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceCount()); |
| 1447 | REPORTER_ASSERT(reporter, 0 == cache->getPurgeableBytes()); |
| 1448 | |
| 1449 | } |
| 1450 | } |
| 1451 | |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 1452 | static void test_large_resource_count(skiatest::Reporter* reporter) { |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 1453 | // Set the cache size to double the resource count because we're going to create 2x that number |
| 1454 | // resources, using two different key domains. Add a little slop to the bytes because we resize |
| 1455 | // down to 1 byte after creating the resource. |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 1456 | static const int kResourceCnt = 2000; |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 1457 | |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 1458 | Mock mock(2 * kResourceCnt, 2 * kResourceCnt + 1000); |
| 1459 | GrContext* context = mock.context(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 1460 | GrResourceCache* cache = mock.cache(); |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 1461 | |
| 1462 | for (int i = 0; i < kResourceCnt; ++i) { |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 1463 | GrUniqueKey key1, key2; |
| 1464 | make_unique_key<1>(&key1, i); |
| 1465 | make_unique_key<2>(&key2, i); |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 1466 | |
bsalomon | 24db3b1 | 2015-01-23 04:24:04 -0800 | [diff] [blame] | 1467 | TestResource* resource; |
| 1468 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 1469 | resource = new TestResource(context->getGpu()); |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 1470 | resource->resourcePriv().setUniqueKey(key1); |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 1471 | resource->setSize(1); |
| 1472 | resource->unref(); |
| 1473 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 1474 | resource = new TestResource(context->getGpu()); |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 1475 | resource->resourcePriv().setUniqueKey(key2); |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 1476 | resource->setSize(1); |
| 1477 | resource->unref(); |
| 1478 | } |
| 1479 | |
| 1480 | REPORTER_ASSERT(reporter, TestResource::NumAlive() == 2 * kResourceCnt); |
Derek Sollenberger | ee47914 | 2017-05-24 11:41:33 -0400 | [diff] [blame] | 1481 | REPORTER_ASSERT(reporter, cache->getPurgeableBytes() == 2 * kResourceCnt); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 1482 | REPORTER_ASSERT(reporter, cache->getBudgetedResourceBytes() == 2 * kResourceCnt); |
| 1483 | REPORTER_ASSERT(reporter, cache->getBudgetedResourceCount() == 2 * kResourceCnt); |
| 1484 | REPORTER_ASSERT(reporter, cache->getResourceBytes() == 2 * kResourceCnt); |
| 1485 | REPORTER_ASSERT(reporter, cache->getResourceCount() == 2 * kResourceCnt); |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 1486 | for (int i = 0; i < kResourceCnt; ++i) { |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 1487 | GrUniqueKey key1, key2; |
| 1488 | make_unique_key<1>(&key1, i); |
| 1489 | make_unique_key<2>(&key2, i); |
bsalomon | 24db3b1 | 2015-01-23 04:24:04 -0800 | [diff] [blame] | 1490 | |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 1491 | REPORTER_ASSERT(reporter, cache->hasUniqueKey(key1)); |
| 1492 | REPORTER_ASSERT(reporter, cache->hasUniqueKey(key2)); |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 1493 | } |
| 1494 | |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 1495 | cache->purgeAllUnlocked(); |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 1496 | REPORTER_ASSERT(reporter, TestResource::NumAlive() == 0); |
Derek Sollenberger | ee47914 | 2017-05-24 11:41:33 -0400 | [diff] [blame] | 1497 | REPORTER_ASSERT(reporter, cache->getPurgeableBytes() == 0); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 1498 | REPORTER_ASSERT(reporter, cache->getBudgetedResourceBytes() == 0); |
| 1499 | REPORTER_ASSERT(reporter, cache->getBudgetedResourceCount() == 0); |
| 1500 | REPORTER_ASSERT(reporter, cache->getResourceBytes() == 0); |
| 1501 | REPORTER_ASSERT(reporter, cache->getResourceCount() == 0); |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 1502 | |
| 1503 | for (int i = 0; i < kResourceCnt; ++i) { |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 1504 | GrUniqueKey key1, key2; |
| 1505 | make_unique_key<1>(&key1, i); |
| 1506 | make_unique_key<2>(&key2, i); |
bsalomon | 24db3b1 | 2015-01-23 04:24:04 -0800 | [diff] [blame] | 1507 | |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 1508 | REPORTER_ASSERT(reporter, !cache->hasUniqueKey(key1)); |
| 1509 | REPORTER_ASSERT(reporter, !cache->hasUniqueKey(key2)); |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 1510 | } |
| 1511 | } |
| 1512 | |
senorblanco | 84cd621 | 2015-08-04 10:01:58 -0700 | [diff] [blame] | 1513 | static void test_custom_data(skiatest::Reporter* reporter) { |
| 1514 | GrUniqueKey key1, key2; |
| 1515 | make_unique_key<0>(&key1, 1); |
| 1516 | make_unique_key<0>(&key2, 2); |
| 1517 | int foo = 4132; |
bungeman | 38d909e | 2016-08-02 14:40:46 -0700 | [diff] [blame] | 1518 | key1.setCustomData(SkData::MakeWithCopy(&foo, sizeof(foo))); |
senorblanco | 84cd621 | 2015-08-04 10:01:58 -0700 | [diff] [blame] | 1519 | REPORTER_ASSERT(reporter, *(int*) key1.getCustomData()->data() == 4132); |
| 1520 | REPORTER_ASSERT(reporter, key2.getCustomData() == nullptr); |
| 1521 | |
| 1522 | // Test that copying a key also takes a ref on its custom data. |
| 1523 | GrUniqueKey key3 = key1; |
| 1524 | REPORTER_ASSERT(reporter, *(int*) key3.getCustomData()->data() == 4132); |
| 1525 | } |
| 1526 | |
bsalomon | c6363ef | 2015-09-24 07:07:40 -0700 | [diff] [blame] | 1527 | static void test_abandoned(skiatest::Reporter* reporter) { |
| 1528 | Mock mock(10, 300); |
| 1529 | GrContext* context = mock.context(); |
Hal Canary | 342b7ac | 2016-11-04 11:49:42 -0400 | [diff] [blame] | 1530 | sk_sp<GrGpuResource> resource(new TestResource(context->getGpu())); |
bsalomon | c6363ef | 2015-09-24 07:07:40 -0700 | [diff] [blame] | 1531 | context->abandonContext(); |
| 1532 | |
| 1533 | REPORTER_ASSERT(reporter, resource->wasDestroyed()); |
| 1534 | |
| 1535 | // Call all the public methods on resource in the abandoned state. They shouldn't crash. |
| 1536 | |
robertphillips | 8abb370 | 2016-08-31 14:04:06 -0700 | [diff] [blame] | 1537 | resource->uniqueID(); |
bsalomon | c6363ef | 2015-09-24 07:07:40 -0700 | [diff] [blame] | 1538 | resource->getUniqueKey(); |
| 1539 | resource->wasDestroyed(); |
| 1540 | resource->gpuMemorySize(); |
| 1541 | resource->getContext(); |
| 1542 | |
| 1543 | resource->abandon(); |
| 1544 | resource->resourcePriv().getScratchKey(); |
| 1545 | resource->resourcePriv().isBudgeted(); |
| 1546 | resource->resourcePriv().makeBudgeted(); |
| 1547 | resource->resourcePriv().makeUnbudgeted(); |
| 1548 | resource->resourcePriv().removeScratchKey(); |
| 1549 | GrUniqueKey key; |
| 1550 | make_unique_key<0>(&key, 1); |
| 1551 | resource->resourcePriv().setUniqueKey(key); |
| 1552 | resource->resourcePriv().removeUniqueKey(); |
| 1553 | } |
| 1554 | |
Brian Salomon | 1090da6 | 2017-01-06 12:04:19 -0500 | [diff] [blame] | 1555 | static void test_tags(skiatest::Reporter* reporter) { |
| 1556 | #ifdef SK_DEBUG |
| 1557 | // We will insert 1 resource with tag "tag1", 2 with "tag2", and so on, up through kLastTagIdx. |
| 1558 | static constexpr int kLastTagIdx = 10; |
| 1559 | static constexpr int kNumResources = kLastTagIdx * (kLastTagIdx + 1) / 2; |
| 1560 | |
| 1561 | Mock mock(kNumResources, kNumResources * TestResource::kDefaultSize); |
| 1562 | GrContext* context = mock.context(); |
| 1563 | GrResourceCache* cache = mock.cache(); |
| 1564 | |
| 1565 | SkString tagStr; |
| 1566 | int tagIdx = 0; |
| 1567 | int currTagCnt = 0; |
| 1568 | |
| 1569 | for (int i = 0; i < kNumResources; ++i, ++currTagCnt) { |
| 1570 | sk_sp<GrGpuResource> resource(new TestResource(context->getGpu())); |
| 1571 | GrUniqueKey key; |
| 1572 | if (currTagCnt == tagIdx) { |
| 1573 | tagIdx += 1; |
| 1574 | currTagCnt = 0; |
| 1575 | tagStr.printf("tag%d", tagIdx); |
| 1576 | } |
| 1577 | make_unique_key<1>(&key, i, tagStr.c_str()); |
| 1578 | resource->resourcePriv().setUniqueKey(key); |
| 1579 | } |
| 1580 | SkASSERT(kLastTagIdx == tagIdx); |
| 1581 | SkASSERT(currTagCnt == kLastTagIdx); |
| 1582 | |
| 1583 | // Test i = 0 to exercise unused tag string. |
| 1584 | for (int i = 0; i <= kLastTagIdx; ++i) { |
| 1585 | tagStr.printf("tag%d", i); |
| 1586 | REPORTER_ASSERT(reporter, cache->countUniqueKeysWithTag(tagStr.c_str()) == i); |
| 1587 | } |
| 1588 | #endif |
| 1589 | } |
| 1590 | |
Brian Salomon | dcfca43 | 2017-11-15 15:48:03 -0500 | [diff] [blame] | 1591 | DEF_GPUTEST(ResourceCacheMisc, reporter, /* options */) { |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 1592 | // The below tests create their own mock contexts. |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 1593 | test_no_key(reporter); |
bsalomon | 84c8e62 | 2014-11-17 09:33:27 -0800 | [diff] [blame] | 1594 | test_budgeting(reporter); |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 1595 | test_unbudgeted(reporter); |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 1596 | test_unbudgeted_to_scratch(reporter); |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 1597 | test_duplicate_unique_key(reporter); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 1598 | test_duplicate_scratch_key(reporter); |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 1599 | test_remove_scratch_key(reporter); |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 1600 | test_scratch_key_consistency(reporter); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 1601 | test_purge_invalidated(reporter); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 1602 | test_cache_chained_purge(reporter); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 1603 | test_resource_size_changed(reporter); |
bsalomon | ddf30e6 | 2015-02-19 11:38:44 -0800 | [diff] [blame] | 1604 | test_timestamp_wrap(reporter); |
bsalomon | 3f32432 | 2015-04-08 11:01:54 -0700 | [diff] [blame] | 1605 | test_flush(reporter); |
Brian Salomon | 5e15085 | 2017-03-22 14:53:13 -0400 | [diff] [blame] | 1606 | test_time_purge(reporter); |
Derek Sollenberger | 5480a18 | 2017-05-25 16:43:59 -0400 | [diff] [blame] | 1607 | test_partial_purge(reporter); |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 1608 | test_large_resource_count(reporter); |
senorblanco | 84cd621 | 2015-08-04 10:01:58 -0700 | [diff] [blame] | 1609 | test_custom_data(reporter); |
bsalomon | c6363ef | 2015-09-24 07:07:40 -0700 | [diff] [blame] | 1610 | test_abandoned(reporter); |
Brian Salomon | 1090da6 | 2017-01-06 12:04:19 -0500 | [diff] [blame] | 1611 | test_tags(reporter); |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 1612 | } |
| 1613 | |
Robert Phillips | d6214d4 | 2016-11-07 08:23:48 -0500 | [diff] [blame] | 1614 | //////////////////////////////////////////////////////////////////////////////// |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 1615 | static sk_sp<GrTexture> make_normal_texture(GrResourceProvider* provider, |
Robert Phillips | d6214d4 | 2016-11-07 08:23:48 -0500 | [diff] [blame] | 1616 | GrSurfaceFlags flags, |
| 1617 | int width, int height, |
| 1618 | int sampleCnt) { |
| 1619 | GrSurfaceDesc desc; |
| 1620 | desc.fFlags = flags; |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 1621 | desc.fOrigin = kTopLeft_GrSurfaceOrigin; |
Robert Phillips | d6214d4 | 2016-11-07 08:23:48 -0500 | [diff] [blame] | 1622 | desc.fWidth = width; |
| 1623 | desc.fHeight = height; |
| 1624 | desc.fConfig = kRGBA_8888_GrPixelConfig; |
| 1625 | desc.fSampleCnt = sampleCnt; |
| 1626 | |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 1627 | return provider->createTexture(desc, SkBudgeted::kYes); |
Robert Phillips | d6214d4 | 2016-11-07 08:23:48 -0500 | [diff] [blame] | 1628 | } |
| 1629 | |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 1630 | static sk_sp<GrTextureProxy> make_mipmap_proxy(GrResourceProvider* provider, |
| 1631 | GrSurfaceFlags flags, |
| 1632 | int width, int height, |
| 1633 | int sampleCnt) { |
Robert Phillips | d6214d4 | 2016-11-07 08:23:48 -0500 | [diff] [blame] | 1634 | SkBitmap bm; |
| 1635 | |
| 1636 | bm.allocN32Pixels(width, height, true); |
| 1637 | bm.eraseColor(SK_ColorBLUE); |
| 1638 | |
Brian Osman | 7b8400d | 2016-11-08 17:08:54 -0500 | [diff] [blame] | 1639 | sk_sp<SkMipMap> mipmaps(SkMipMap::Build(bm, SkDestinationSurfaceColorMode::kLegacy, nullptr)); |
Robert Phillips | d6214d4 | 2016-11-07 08:23:48 -0500 | [diff] [blame] | 1640 | SkASSERT(mipmaps); |
| 1641 | SkASSERT(mipmaps->countLevels() > 1); |
| 1642 | |
| 1643 | int mipLevelCount = mipmaps->countLevels() + 1; |
| 1644 | |
| 1645 | std::unique_ptr<GrMipLevel[]> texels(new GrMipLevel[mipLevelCount]); |
| 1646 | |
| 1647 | texels[0].fPixels = bm.getPixels(); |
| 1648 | texels[0].fRowBytes = bm.rowBytes(); |
| 1649 | |
| 1650 | for (int i = 1; i < mipLevelCount; ++i) { |
| 1651 | SkMipMap::Level generatedMipLevel; |
| 1652 | mipmaps->getLevel(i - 1, &generatedMipLevel); |
| 1653 | texels[i].fPixels = generatedMipLevel.fPixmap.addr(); |
| 1654 | texels[i].fRowBytes = generatedMipLevel.fPixmap.rowBytes(); |
| 1655 | } |
| 1656 | |
| 1657 | GrSurfaceDesc desc; |
| 1658 | desc.fFlags = flags; |
Robert Phillips | e44ef10 | 2017-07-21 15:37:19 -0400 | [diff] [blame] | 1659 | desc.fOrigin = (flags & kRenderTarget_GrSurfaceFlag) ? kBottomLeft_GrSurfaceOrigin |
| 1660 | : kTopLeft_GrSurfaceOrigin; |
Robert Phillips | d6214d4 | 2016-11-07 08:23:48 -0500 | [diff] [blame] | 1661 | desc.fWidth = width; |
| 1662 | desc.fHeight = height; |
| 1663 | desc.fConfig = kRGBA_8888_GrPixelConfig; |
| 1664 | desc.fSampleCnt = sampleCnt; |
Robert Phillips | d6214d4 | 2016-11-07 08:23:48 -0500 | [diff] [blame] | 1665 | |
Robert Phillips | 8e8c755 | 2017-07-10 12:06:05 -0400 | [diff] [blame] | 1666 | return GrSurfaceProxy::MakeDeferredMipMap(provider, desc, SkBudgeted::kYes, |
| 1667 | texels.get(), mipLevelCount); |
Robert Phillips | d6214d4 | 2016-11-07 08:23:48 -0500 | [diff] [blame] | 1668 | } |
| 1669 | |
| 1670 | // Exercise GrSurface::gpuMemorySize for different combos of MSAA, RT-only, |
| 1671 | // Texture-only, both-RT-and-Texture and MIPmapped |
| 1672 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GPUMemorySize, reporter, ctxInfo) { |
| 1673 | GrContext* context = ctxInfo.grContext(); |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 1674 | GrResourceProvider* provider = context->resourceProvider(); |
Robert Phillips | d6214d4 | 2016-11-07 08:23:48 -0500 | [diff] [blame] | 1675 | |
Robert Phillips | d6214d4 | 2016-11-07 08:23:48 -0500 | [diff] [blame] | 1676 | static const int kSize = 64; |
| 1677 | |
Robert Phillips | d6214d4 | 2016-11-07 08:23:48 -0500 | [diff] [blame] | 1678 | // Normal versions |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 1679 | { |
| 1680 | sk_sp<GrTexture> tex; |
Robert Phillips | d6214d4 | 2016-11-07 08:23:48 -0500 | [diff] [blame] | 1681 | |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 1682 | tex = make_normal_texture(provider, kRenderTarget_GrSurfaceFlag, kSize, kSize, 0); |
| 1683 | size_t size = tex->gpuMemorySize(); |
| 1684 | REPORTER_ASSERT(reporter, kSize*kSize*4 == size); |
| 1685 | |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 1686 | size_t sampleCount = (size_t)context->caps()->getSampleCount(4, kRGBA_8888_GrPixelConfig); |
| 1687 | if (sampleCount >= 4) { |
| 1688 | tex = make_normal_texture(provider, kRenderTarget_GrSurfaceFlag, kSize, kSize, |
| 1689 | sampleCount); |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 1690 | size = tex->gpuMemorySize(); |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 1691 | REPORTER_ASSERT(reporter, |
| 1692 | kSize*kSize*4 == size || // msaa4 failed |
| 1693 | kSize*kSize*4*sampleCount == size || // auto-resolving |
| 1694 | kSize*kSize*4*(sampleCount+1) == size); // explicit resolve buffer |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 1695 | } |
| 1696 | |
| 1697 | tex = make_normal_texture(provider, kNone_GrSurfaceFlags, kSize, kSize, 0); |
Robert Phillips | d6214d4 | 2016-11-07 08:23:48 -0500 | [diff] [blame] | 1698 | size = tex->gpuMemorySize(); |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 1699 | REPORTER_ASSERT(reporter, kSize*kSize*4 == size); |
Robert Phillips | d6214d4 | 2016-11-07 08:23:48 -0500 | [diff] [blame] | 1700 | } |
| 1701 | |
Robert Phillips | d6214d4 | 2016-11-07 08:23:48 -0500 | [diff] [blame] | 1702 | |
| 1703 | // Mipmapped versions |
Brian Osman | 48c9919 | 2017-06-02 08:45:06 -0400 | [diff] [blame] | 1704 | if (context->caps()->mipMapSupport()) { |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 1705 | sk_sp<GrTextureProxy> proxy; |
Robert Phillips | d6214d4 | 2016-11-07 08:23:48 -0500 | [diff] [blame] | 1706 | |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 1707 | proxy = make_mipmap_proxy(provider, kRenderTarget_GrSurfaceFlag, kSize, kSize, 0); |
| 1708 | size_t size = proxy->gpuMemorySize(); |
| 1709 | REPORTER_ASSERT(reporter, kSize*kSize*4+(kSize*kSize*4)/3 == size); |
| 1710 | |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 1711 | size_t sampleCount = (size_t)context->caps()->getSampleCount(4, kRGBA_8888_GrPixelConfig); |
| 1712 | if (sampleCount >= 4) { |
| 1713 | proxy = make_mipmap_proxy(provider, kRenderTarget_GrSurfaceFlag, kSize, kSize, |
| 1714 | sampleCount); |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 1715 | size = proxy->gpuMemorySize(); |
| 1716 | REPORTER_ASSERT(reporter, |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 1717 | kSize*kSize*4+(kSize*kSize*4)/3 == size || // msaa4 failed |
| 1718 | kSize*kSize*4*sampleCount+(kSize*kSize*4)/3 == size || // auto-resolving |
| 1719 | kSize*kSize*4*(sampleCount+1)+(kSize*kSize*4)/3 == size); // explicit resolve buffer |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 1720 | } |
Robert Phillips | 1b35256 | 2017-04-05 18:56:21 +0000 | [diff] [blame] | 1721 | |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 1722 | proxy = make_mipmap_proxy(provider, kNone_GrSurfaceFlags, kSize, kSize, 0); |
| 1723 | size = proxy->gpuMemorySize(); |
| 1724 | REPORTER_ASSERT(reporter, kSize*kSize*4+(kSize*kSize*4)/3 == size); |
| 1725 | } |
Robert Phillips | d6214d4 | 2016-11-07 08:23:48 -0500 | [diff] [blame] | 1726 | } |
| 1727 | |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 1728 | #endif |