From 83787d0ff0a2b2f839a4a3ce6dadd033f83fe643 Mon Sep 17 00:00:00 2001 From: reed Date: Wed, 25 Feb 2015 07:17:11 -0800 Subject: only notify bitmaps that have been added to the cache old code: - calls=2677 hit-rate=3.51139% new code: - calls=94 hit-rate=97.8723% BUG=skia: Review URL: https://codereview.chromium.org/960563002 --- tests/SkResourceCacheTest.cpp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'tests/SkResourceCacheTest.cpp') diff --git a/tests/SkResourceCacheTest.cpp b/tests/SkResourceCacheTest.cpp index 626c837361..fae0816305 100644 --- a/tests/SkResourceCacheTest.cpp +++ b/tests/SkResourceCacheTest.cpp @@ -108,20 +108,22 @@ DEF_TEST(BitmapCache_add_rect, reporter) { SkBitmap bm; SkIRect rect = SkIRect::MakeWH(5, 5); + uint32_t cachedID = cachedBitmap.getGenerationID(); + SkPixelRef* cachedPR = cachedBitmap.pixelRef(); // Wrong subset size - REPORTER_ASSERT(reporter, !SkBitmapCache::Add(cachedBitmap.getGenerationID(), SkIRect::MakeWH(4, 6), cachedBitmap, cache)); - REPORTER_ASSERT(reporter, !SkBitmapCache::Find(cachedBitmap.getGenerationID(), rect, &bm, cache)); + REPORTER_ASSERT(reporter, !SkBitmapCache::Add(cachedPR, SkIRect::MakeWH(4, 6), cachedBitmap, cache)); + REPORTER_ASSERT(reporter, !SkBitmapCache::Find(cachedID, rect, &bm, cache)); // Wrong offset value - REPORTER_ASSERT(reporter, !SkBitmapCache::Add(cachedBitmap.getGenerationID(), SkIRect::MakeXYWH(-1, 0, 5, 5), cachedBitmap, cache)); - REPORTER_ASSERT(reporter, !SkBitmapCache::Find(cachedBitmap.getGenerationID(), rect, &bm, cache)); + REPORTER_ASSERT(reporter, !SkBitmapCache::Add(cachedPR, SkIRect::MakeXYWH(-1, 0, 5, 5), cachedBitmap, cache)); + REPORTER_ASSERT(reporter, !SkBitmapCache::Find(cachedID, rect, &bm, cache)); // Should not be in the cache - REPORTER_ASSERT(reporter, !SkBitmapCache::Find(cachedBitmap.getGenerationID(), rect, &bm, cache)); + REPORTER_ASSERT(reporter, !SkBitmapCache::Find(cachedID, rect, &bm, cache)); - REPORTER_ASSERT(reporter, SkBitmapCache::Add(cachedBitmap.getGenerationID(), rect, cachedBitmap, cache)); + REPORTER_ASSERT(reporter, SkBitmapCache::Add(cachedPR, rect, cachedBitmap, cache)); // Should be in the cache, we just added it - REPORTER_ASSERT(reporter, SkBitmapCache::Find(cachedBitmap.getGenerationID(), rect, &bm, cache)); + REPORTER_ASSERT(reporter, SkBitmapCache::Find(cachedID, rect, &bm, cache)); } #include "SkMipMap.h" @@ -215,7 +217,7 @@ static void test_bitmap_notify(skiatest::Reporter* reporter, SkResourceCache* ca src[i].setImmutable(); dst[i].allocN32Pixels(5, 5); dst[i].setImmutable(); - SkBitmapCache::Add(src[i].getGenerationID(), subset, dst[i], cache); + SkBitmapCache::Add(src[i].pixelRef(), subset, dst[i], cache); } for (int i = 0; i < N; ++i) { @@ -255,7 +257,7 @@ DEF_TEST(BitmapCache_discarded_bitmap, reporter) { SkIRect rect = SkIRect::MakeWH(5, 5); // Add a bitmap to the cache. - REPORTER_ASSERT(reporter, SkBitmapCache::Add(cachedBitmap.getGenerationID(), rect, cachedBitmap, cache)); + REPORTER_ASSERT(reporter, SkBitmapCache::Add(cachedBitmap.pixelRef(), rect, cachedBitmap, cache)); REPORTER_ASSERT(reporter, SkBitmapCache::Find(cachedBitmap.getGenerationID(), rect, &bm, cache)); // Finding more than once works fine. @@ -277,7 +279,7 @@ DEF_TEST(BitmapCache_discarded_bitmap, reporter) { cachedBitmap.unlockPixels(); // We can add the bitmap back to the cache and find it again. - REPORTER_ASSERT(reporter, SkBitmapCache::Add(cachedBitmap.getGenerationID(), rect, cachedBitmap, cache)); + REPORTER_ASSERT(reporter, SkBitmapCache::Add(cachedBitmap.pixelRef(), rect, cachedBitmap, cache)); REPORTER_ASSERT(reporter, SkBitmapCache::Find(cachedBitmap.getGenerationID(), rect, &bm, cache)); test_mipmapcache(reporter, cache); -- cgit v1.2.3