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

Unified Diff: tests/ScaledImageCache.cpp

Issue 394003003: Set maximum output size for scaled-image-cache images (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: AnotherPatchSet 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 | « tests/ImageCacheTest.cpp ('k') | 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
new file mode 100644
index 0000000000000000000000000000000000000000..2040afea27fa03b4278a1f6eaec0f1ab09a1204e
--- /dev/null
+++ b/tests/ScaledImageCache.cpp
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2014 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+#include "Test.h"
+#include "SkGraphics.h"
+#include "SkCanvas.h"
+
+static const int kCanvasSize = 1;
+static const int kBitmapSize = 16;
+static const int kScale = 8;
+
+static size_t test_scaled_image_cache_useage() {
+ SkAutoTUnref<SkCanvas> canvas(
+ SkCanvas::NewRasterN32(kCanvasSize, kCanvasSize));
+ SkBitmap bitmap;
+ SkAssertResult(bitmap.allocN32Pixels(kBitmapSize, kBitmapSize));
+ SkScalar scaledSize = SkIntToScalar(kScale * kBitmapSize);
+ 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;
+}
+
+// http://crbug.com/389439
+DEF_TEST(ScaledImageCache_SingleAllocationByteLimit, reporter) {
+ size_t originalByteLimit = SkGraphics::GetImageCacheByteLimit();
+ size_t originalAllocationLimit =
+ SkGraphics::GetImageCacheSingleAllocationByteLimit();
+
+ size_t size = kBitmapSize * kScale * kBitmapSize * kScale
+ * SkColorTypeBytesPerPixel(kN32_SkColorType);
+
+ SkGraphics::SetImageCacheByteLimit(0); // clear cache
+ SkGraphics::SetImageCacheByteLimit(2 * size);
+ SkGraphics::SetImageCacheSingleAllocationByteLimit(0);
+
+ REPORTER_ASSERT(reporter, size == 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());
+
+ SkGraphics::SetImageCacheByteLimit(0); // clear cache
+ SkGraphics::SetImageCacheByteLimit(2 * size);
+ SkGraphics::SetImageCacheSingleAllocationByteLimit(size / 2);
+
+ REPORTER_ASSERT(reporter, 0 == test_scaled_image_cache_useage());
+
+ SkGraphics::SetImageCacheSingleAllocationByteLimit(originalAllocationLimit);
+ SkGraphics::SetImageCacheByteLimit(originalByteLimit);
+}
« no previous file with comments | « tests/ImageCacheTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698