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

Side by Side Diff: tests/ScaledImageCache.cpp

Issue 462993003: Set maximum output size for scaled-image-cache images (Closed) Base URL: https://skia.googlesource.com/skia.git@m37_2062
Patch Set: Created 6 years, 4 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 unified diff | Download patch
« no previous file with comments | « tests/ImageCacheTest.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2014 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 #include "Test.h"
8 #include "SkGraphics.h"
9 #include "SkCanvas.h"
10
11 static const int kCanvasSize = 1;
12 static const int kBitmapSize = 16;
13 static const int kScale = 8;
14
15 static size_t test_scaled_image_cache_useage() {
16 SkAutoTUnref<SkCanvas> canvas(
17 SkCanvas::NewRasterN32(kCanvasSize, kCanvasSize));
18 SkBitmap bitmap;
19 SkAssertResult(bitmap.allocN32Pixels(kBitmapSize, kBitmapSize));
20 SkScalar scaledSize = SkIntToScalar(kScale * kBitmapSize);
21 canvas->clipRect(SkRect::MakeLTRB(0, 0, scaledSize, scaledSize));
22 SkPaint paint;
23 paint.setFilterLevel(SkPaint::kHigh_FilterLevel);
24 size_t bytesUsed = SkGraphics::GetImageCacheBytesUsed();
25 canvas->drawBitmapRect(bitmap,
26 SkRect::MakeLTRB(0, 0, scaledSize, scaledSize),
27 &paint);
28 return SkGraphics::GetImageCacheBytesUsed() - bytesUsed;
29 }
30
31 // http://crbug.com/389439
32 DEF_TEST(ScaledImageCache_SingleAllocationByteLimit, reporter) {
33 size_t originalByteLimit = SkGraphics::GetImageCacheByteLimit();
34 size_t originalAllocationLimit =
35 SkGraphics::GetImageCacheSingleAllocationByteLimit();
36
37 size_t size = kBitmapSize * kScale * kBitmapSize * kScale
38 * SkColorTypeBytesPerPixel(kN32_SkColorType);
39
40 SkGraphics::SetImageCacheByteLimit(0); // clear cache
41 SkGraphics::SetImageCacheByteLimit(2 * size);
42 SkGraphics::SetImageCacheSingleAllocationByteLimit(0);
43
44 REPORTER_ASSERT(reporter, size == test_scaled_image_cache_useage());
45
46 SkGraphics::SetImageCacheByteLimit(0); // clear cache
47 SkGraphics::SetImageCacheByteLimit(2 * size);
48 SkGraphics::SetImageCacheSingleAllocationByteLimit(size * 2);
49
50 REPORTER_ASSERT(reporter, size == test_scaled_image_cache_useage());
51
52 SkGraphics::SetImageCacheByteLimit(0); // clear cache
53 SkGraphics::SetImageCacheByteLimit(2 * size);
54 SkGraphics::SetImageCacheSingleAllocationByteLimit(size / 2);
55
56 REPORTER_ASSERT(reporter, 0 == test_scaled_image_cache_useage());
57
58 SkGraphics::SetImageCacheSingleAllocationByteLimit(originalAllocationLimit);
59 SkGraphics::SetImageCacheByteLimit(originalByteLimit);
60 }
OLDNEW
« 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