| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 // Include here to ensure SK_SUPPORT_GPU is set correctly before it is examined. | 8 // Include here to ensure SK_SUPPORT_GPU is set correctly before it is examined. |
| 9 #include "SkTypes.h" | 9 #include "SkTypes.h" |
| 10 | 10 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 #include "SkCanvas.h" | 23 #include "SkCanvas.h" |
| 24 #include "SkGr.h" | 24 #include "SkGr.h" |
| 25 #include "SkMessageBus.h" | 25 #include "SkMessageBus.h" |
| 26 #include "SkSurface.h" | 26 #include "SkSurface.h" |
| 27 #include "Test.h" | 27 #include "Test.h" |
| 28 | 28 |
| 29 static const int gWidth = 640; | 29 static const int gWidth = 640; |
| 30 static const int gHeight = 480; | 30 static const int gHeight = 480; |
| 31 | 31 |
| 32 //////////////////////////////////////////////////////////////////////////////// | 32 //////////////////////////////////////////////////////////////////////////////// |
| 33 static void test_cache(skiatest::Reporter* reporter, GrContext* context, SkCanva
s* canvas) { | 33 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceCacheCache, reporter, context) { |
| 34 GrSurfaceDesc desc; |
| 35 desc.fConfig = kSkia8888_GrPixelConfig; |
| 36 desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 37 desc.fWidth = gWidth; |
| 38 desc.fHeight = gHeight; |
| 39 SkImageInfo info = SkImageInfo::MakeN32Premul(gWidth, gHeight); |
| 40 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(context, |
| 41 SkSurface::kNo_Bu
dgeted, info)); |
| 42 SkCanvas* canvas = surface->getCanvas(); |
| 43 |
| 34 const SkIRect size = SkIRect::MakeWH(gWidth, gHeight); | 44 const SkIRect size = SkIRect::MakeWH(gWidth, gHeight); |
| 35 | 45 |
| 36 SkBitmap src; | 46 SkBitmap src; |
| 37 src.allocN32Pixels(size.width(), size.height()); | 47 src.allocN32Pixels(size.width(), size.height()); |
| 38 src.eraseColor(SK_ColorBLACK); | 48 src.eraseColor(SK_ColorBLACK); |
| 39 size_t srcSize = src.getSize(); | 49 size_t srcSize = src.getSize(); |
| 40 | 50 |
| 41 size_t initialCacheSize; | 51 size_t initialCacheSize; |
| 42 context->getResourceCacheUsage(nullptr, &initialCacheSize); | 52 context->getResourceCacheUsage(nullptr, &initialCacheSize); |
| 43 | 53 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 63 size_t curCacheSize; | 73 size_t curCacheSize; |
| 64 context->getResourceCacheUsage(nullptr, &curCacheSize); | 74 context->getResourceCacheUsage(nullptr, &curCacheSize); |
| 65 | 75 |
| 66 // we should never go over the size limit | 76 // we should never go over the size limit |
| 67 REPORTER_ASSERT(reporter, curCacheSize <= maxCacheSize); | 77 REPORTER_ASSERT(reporter, curCacheSize <= maxCacheSize); |
| 68 } | 78 } |
| 69 | 79 |
| 70 context->setResourceCacheLimits(oldMaxNum, oldMaxBytes); | 80 context->setResourceCacheLimits(oldMaxNum, oldMaxBytes); |
| 71 } | 81 } |
| 72 | 82 |
| 73 static void test_stencil_buffers(skiatest::Reporter* reporter, GrContext* contex
t) { | 83 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceCacheStencilBuffers, reporter, contex
t) { |
| 74 GrSurfaceDesc smallDesc; | 84 GrSurfaceDesc smallDesc; |
| 75 smallDesc.fFlags = kRenderTarget_GrSurfaceFlag; | 85 smallDesc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 76 smallDesc.fConfig = kSkia8888_GrPixelConfig; | 86 smallDesc.fConfig = kSkia8888_GrPixelConfig; |
| 77 smallDesc.fWidth = 4; | 87 smallDesc.fWidth = 4; |
| 78 smallDesc.fHeight = 4; | 88 smallDesc.fHeight = 4; |
| 79 smallDesc.fSampleCnt = 0; | 89 smallDesc.fSampleCnt = 0; |
| 80 | 90 |
| 81 GrTextureProvider* cache = context->textureProvider(); | 91 GrTextureProvider* cache = context->textureProvider(); |
| 82 GrResourceProvider* resourceProvider = context->resourceProvider(); | 92 GrResourceProvider* resourceProvider = context->resourceProvider(); |
| 83 // Test that two budgeted RTs with the same desc share a stencil buffer. | 93 // Test that two budgeted RTs with the same desc share a stencil buffer. |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 REPORTER_ASSERT(reporter, | 179 REPORTER_ASSERT(reporter, |
| 170 smallMSAART0 && smallMSAART1 && | 180 smallMSAART0 && smallMSAART1 && |
| 171 smallMSAART0->asRenderTarget() && | 181 smallMSAART0->asRenderTarget() && |
| 172 smallMSAART1->asRenderTarget() && | 182 smallMSAART1->asRenderTarget() && |
| 173 resourceProvider->attachStencilAttachment(smallMSAART0->
asRenderTarget()) != | 183 resourceProvider->attachStencilAttachment(smallMSAART0->
asRenderTarget()) != |
| 174 resourceProvider->attachStencilAttachment(smallMSAART1->
asRenderTarget())); | 184 resourceProvider->attachStencilAttachment(smallMSAART1->
asRenderTarget())); |
| 175 } | 185 } |
| 176 } | 186 } |
| 177 } | 187 } |
| 178 | 188 |
| 179 static void test_wrapped_resources(skiatest::Reporter* reporter, GrContext* cont
ext) { | 189 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceCacheWrappedResources, reporter, cont
ext) { |
| 180 const GrGpu* gpu = context->getGpu(); | 190 const GrGpu* gpu = context->getGpu(); |
| 181 // this test is only valid for GL | 191 // this test is only valid for GL |
| 182 if (!gpu || !gpu->glContextForTesting()) { | 192 if (!gpu || !gpu->glContextForTesting()) { |
| 183 return; | 193 return; |
| 184 } | 194 } |
| 185 | 195 |
| 186 GrBackendObject texHandles[2]; | 196 GrBackendObject texHandles[2]; |
| 187 static const int kW = 100; | 197 static const int kW = 100; |
| 188 static const int kH = 100; | 198 static const int kH = 100; |
| 189 | 199 |
| (...skipping 1087 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1277 resource->resourcePriv().isBudgeted(); | 1287 resource->resourcePriv().isBudgeted(); |
| 1278 resource->resourcePriv().makeBudgeted(); | 1288 resource->resourcePriv().makeBudgeted(); |
| 1279 resource->resourcePriv().makeUnbudgeted(); | 1289 resource->resourcePriv().makeUnbudgeted(); |
| 1280 resource->resourcePriv().removeScratchKey(); | 1290 resource->resourcePriv().removeScratchKey(); |
| 1281 GrUniqueKey key; | 1291 GrUniqueKey key; |
| 1282 make_unique_key<0>(&key, 1); | 1292 make_unique_key<0>(&key, 1); |
| 1283 resource->resourcePriv().setUniqueKey(key); | 1293 resource->resourcePriv().setUniqueKey(key); |
| 1284 resource->resourcePriv().removeUniqueKey(); | 1294 resource->resourcePriv().removeUniqueKey(); |
| 1285 } | 1295 } |
| 1286 | 1296 |
| 1287 //////////////////////////////////////////////////////////////////////////////// | 1297 DEF_GPUTEST(ResourceCacheMisc, reporter, factory) { |
| 1288 DEF_GPUTEST(ResourceCache, reporter, factory) { | |
| 1289 for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) { | |
| 1290 GrContextFactory::GLContextType glType = static_cast<GrContextFactory::G
LContextType>(type); | |
| 1291 if (!GrContextFactory::IsRenderingGLContext(glType)) { | |
| 1292 continue; | |
| 1293 } | |
| 1294 GrContext* context = factory->get(glType); | |
| 1295 if (nullptr == context) { | |
| 1296 continue; | |
| 1297 } | |
| 1298 GrSurfaceDesc desc; | |
| 1299 desc.fConfig = kSkia8888_GrPixelConfig; | |
| 1300 desc.fFlags = kRenderTarget_GrSurfaceFlag; | |
| 1301 desc.fWidth = gWidth; | |
| 1302 desc.fHeight = gHeight; | |
| 1303 SkImageInfo info = SkImageInfo::MakeN32Premul(gWidth, gHeight); | |
| 1304 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(context, | |
| 1305 SkSurface::kN
o_Budgeted, info)); | |
| 1306 test_cache(reporter, context, surface->getCanvas()); | |
| 1307 test_stencil_buffers(reporter, context); | |
| 1308 test_wrapped_resources(reporter, context); | |
| 1309 } | |
| 1310 | |
| 1311 // The below tests create their own mock contexts. | 1298 // The below tests create their own mock contexts. |
| 1312 test_no_key(reporter); | 1299 test_no_key(reporter); |
| 1313 test_budgeting(reporter); | 1300 test_budgeting(reporter); |
| 1314 test_unbudgeted(reporter); | 1301 test_unbudgeted(reporter); |
| 1315 test_unbudgeted_to_scratch(reporter); | 1302 test_unbudgeted_to_scratch(reporter); |
| 1316 test_duplicate_unique_key(reporter); | 1303 test_duplicate_unique_key(reporter); |
| 1317 test_duplicate_scratch_key(reporter); | 1304 test_duplicate_scratch_key(reporter); |
| 1318 test_remove_scratch_key(reporter); | 1305 test_remove_scratch_key(reporter); |
| 1319 test_scratch_key_consistency(reporter); | 1306 test_scratch_key_consistency(reporter); |
| 1320 test_purge_invalidated(reporter); | 1307 test_purge_invalidated(reporter); |
| 1321 test_cache_chained_purge(reporter); | 1308 test_cache_chained_purge(reporter); |
| 1322 test_resource_size_changed(reporter); | 1309 test_resource_size_changed(reporter); |
| 1323 test_timestamp_wrap(reporter); | 1310 test_timestamp_wrap(reporter); |
| 1324 test_flush(reporter); | 1311 test_flush(reporter); |
| 1325 test_large_resource_count(reporter); | 1312 test_large_resource_count(reporter); |
| 1326 test_custom_data(reporter); | 1313 test_custom_data(reporter); |
| 1327 test_abandoned(reporter); | 1314 test_abandoned(reporter); |
| 1328 } | 1315 } |
| 1329 | 1316 |
| 1330 #endif | 1317 #endif |
| OLD | NEW |