Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(206)

Unified Diff: tests/ScaledImageCache.cpp

Issue 401833002: Make ScaledImageCache unit test less dependent on global state. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/ScaledImageCache.cpp
diff --git a/tests/ScaledImageCache.cpp b/tests/ScaledImageCache.cpp
index 9515e134e4d683238717d14029cccbbb9efe5e1c..d0b6c1182b256e47cdab3d43d302b42c01f4f0f4 100644
--- a/tests/ScaledImageCache.cpp
+++ b/tests/ScaledImageCache.cpp
@@ -5,28 +5,44 @@
* found in the LICENSE file.
*/
#include "Test.h"
-#include "SkGraphics.h"
#include "SkCanvas.h"
+#include "SkGraphics.h"
+#include "SkScaledImageCache.h"
static const int kCanvasSize = 1;
static const int kBitmapSize = 16;
static const int kScale = 8;
-static size_t test_scaled_image_cache_useage() {
+static bool is_in_scaled_image_cache(const SkBitmap& orig,
+ SkScalar xScale,
+ SkScalar yScale) {
+ SkBitmap scaled;
+ SkScaledImageCache::ID* id = SkScaledImageCache::FindAndLock(
+ orig, SkScalarInvert(xScale), SkScalarInvert(yScale), &scaled);
+ if (id) {
+ SkScaledImageCache::Unlock(id);
+ }
+ return id != NULL;
+}
+
+static bool test_scaled_image_cache_useage() {
tomhudson 2014/07/18 15:02:44 Nit: if we're cutting the comment in line 44 (see
hal.canary 2014/07/18 16:06:52 Done.
SkAutoTUnref<SkCanvas> canvas(
SkCanvas::NewRasterN32(kCanvasSize, kCanvasSize));
SkBitmap bitmap;
SkAssertResult(bitmap.allocN32Pixels(kBitmapSize, kBitmapSize));
bitmap.eraseColor(0xFFFFFFFF);
- SkScalar scaledSize = SkIntToScalar(kScale * kBitmapSize);
+ SkScalar scale = SkIntToScalar(kScale);
+ SkScalar scaledSize = SkIntToScalar(kBitmapSize) * scale;
canvas->clipRect(SkRect::MakeLTRB(0, 0, scaledSize, scaledSize));
SkPaint paint;
paint.setFilterLevel(SkPaint::kHigh_FilterLevel);
- size_t bytesUsed = SkGraphics::GetImageCacheBytesUsed();
+
canvas->drawBitmapRect(bitmap,
SkRect::MakeLTRB(0, 0, scaledSize, scaledSize),
&paint);
- return SkGraphics::GetImageCacheBytesUsed() - bytesUsed;
+
+ // Check to see that the scaled bitmap is to be found in the cache.
tomhudson 2014/07/18 15:02:44 Nit: unnecessary comment? (I love comments, but th
hal.canary 2014/07/18 16:06:52 The comment predated the splitting out of the func
+ return is_in_scaled_image_cache(bitmap, scale, scale);
}
// http://crbug.com/389439
@@ -42,19 +58,19 @@ DEF_TEST(ScaledImageCache_SingleAllocationByteLimit, reporter) {
SkGraphics::SetImageCacheByteLimit(2 * size);
SkGraphics::SetImageCacheSingleAllocationByteLimit(0);
- REPORTER_ASSERT(reporter, size == test_scaled_image_cache_useage());
+ REPORTER_ASSERT(reporter, test_scaled_image_cache_useage());
SkGraphics::SetImageCacheByteLimit(0); // clear cache
SkGraphics::SetImageCacheByteLimit(2 * size);
SkGraphics::SetImageCacheSingleAllocationByteLimit(size * 2);
- REPORTER_ASSERT(reporter, size == test_scaled_image_cache_useage());
+ REPORTER_ASSERT(reporter, test_scaled_image_cache_useage());
SkGraphics::SetImageCacheByteLimit(0); // clear cache
SkGraphics::SetImageCacheByteLimit(2 * size);
SkGraphics::SetImageCacheSingleAllocationByteLimit(size / 2);
- REPORTER_ASSERT(reporter, 0 == test_scaled_image_cache_useage());
+ REPORTER_ASSERT(reporter, !test_scaled_image_cache_useage());
SkGraphics::SetImageCacheSingleAllocationByteLimit(originalAllocationLimit);
SkGraphics::SetImageCacheByteLimit(originalByteLimit);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698