OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 #include "Test.h" | 7 #include "Test.h" |
8 #include "SkCanvas.h" | 8 #include "SkCanvas.h" |
9 #include "SkGraphics.h" | 9 #include "SkGraphics.h" |
10 #include "SkBitmapCache.h" | 10 #include "SkBitmapCache.h" |
11 | 11 |
12 static const int kCanvasSize = 1; | 12 static const int kCanvasSize = 1; |
13 static const int kBitmapSize = 16; | 13 static const int kBitmapSize = 16; |
14 static const int kScale = 8; | 14 static const int kScale = 8; |
15 | 15 |
16 static bool is_in_scaled_image_cache(const SkBitmap& orig, | 16 static bool is_in_scaled_image_cache(const SkBitmap& orig, |
17 SkScalar xScale, | 17 SkScalar xScale, |
18 SkScalar yScale) { | 18 SkScalar yScale) { |
19 SkBitmap scaled; | 19 SkBitmap scaled; |
20 return SkBitmapCache::Find(orig, SkScalarInvert(xScale), SkScalarInvert(ySca
le), &scaled); | 20 float roundedImageWidth = SkScalarRoundToScalar(orig.width() * xScale); |
| 21 float roundedImageHeight = SkScalarRoundToScalar(orig.height() * xScale); |
| 22 return SkBitmapCache::Find(orig, roundedImageWidth, roundedImageHeight, &sca
led); |
21 } | 23 } |
22 | 24 |
23 // Draw a scaled bitmap, then return true iff it has been cached. | 25 // Draw a scaled bitmap, then return true iff it has been cached. |
24 static bool test_scaled_image_cache_useage() { | 26 static bool test_scaled_image_cache_useage() { |
25 SkAutoTUnref<SkCanvas> canvas( | 27 SkAutoTUnref<SkCanvas> canvas( |
26 SkCanvas::NewRasterN32(kCanvasSize, kCanvasSize)); | 28 SkCanvas::NewRasterN32(kCanvasSize, kCanvasSize)); |
27 SkBitmap bitmap; | 29 SkBitmap bitmap; |
28 SkAssertResult(bitmap.allocN32Pixels(kBitmapSize, kBitmapSize)); | 30 SkAssertResult(bitmap.allocN32Pixels(kBitmapSize, kBitmapSize)); |
29 bitmap.eraseColor(0xFFFFFFFF); | 31 bitmap.eraseColor(0xFFFFFFFF); |
30 SkScalar scale = SkIntToScalar(kScale); | 32 SkScalar scale = SkIntToScalar(kScale); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 | 65 |
64 SkGraphics::SetImageCacheTotalByteLimit(0); // clear cache | 66 SkGraphics::SetImageCacheTotalByteLimit(0); // clear cache |
65 SkGraphics::SetImageCacheTotalByteLimit(2 * size); | 67 SkGraphics::SetImageCacheTotalByteLimit(2 * size); |
66 SkGraphics::SetImageCacheSingleAllocationByteLimit(size / 2); // too small | 68 SkGraphics::SetImageCacheSingleAllocationByteLimit(size / 2); // too small |
67 | 69 |
68 REPORTER_ASSERT(reporter, !test_scaled_image_cache_useage()); | 70 REPORTER_ASSERT(reporter, !test_scaled_image_cache_useage()); |
69 | 71 |
70 SkGraphics::SetImageCacheSingleAllocationByteLimit(originalAllocationLimit); | 72 SkGraphics::SetImageCacheSingleAllocationByteLimit(originalAllocationLimit); |
71 SkGraphics::SetImageCacheTotalByteLimit(originalByteLimit); | 73 SkGraphics::SetImageCacheTotalByteLimit(originalByteLimit); |
72 } | 74 } |
OLD | NEW |