| 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 SkScaledImageCache::ID* id = SkBitmapCache::FindAndLock( | 20 return SkBitmapCache::Find(orig, SkScalarInvert(xScale), SkScalarInvert(ySca
le), &scaled); |
| 21 orig, SkScalarInvert(xScale), SkScalarInvert(yScale), &scaled); | |
| 22 if (id) { | |
| 23 SkScaledImageCache::Unlock(id); | |
| 24 } | |
| 25 return id != NULL; | |
| 26 } | 21 } |
| 27 | 22 |
| 28 // Draw a scaled bitmap, then return true iff it has been cached. | 23 // Draw a scaled bitmap, then return true iff it has been cached. |
| 29 static bool test_scaled_image_cache_useage() { | 24 static bool test_scaled_image_cache_useage() { |
| 30 SkAutoTUnref<SkCanvas> canvas( | 25 SkAutoTUnref<SkCanvas> canvas( |
| 31 SkCanvas::NewRasterN32(kCanvasSize, kCanvasSize)); | 26 SkCanvas::NewRasterN32(kCanvasSize, kCanvasSize)); |
| 32 SkBitmap bitmap; | 27 SkBitmap bitmap; |
| 33 SkAssertResult(bitmap.allocN32Pixels(kBitmapSize, kBitmapSize)); | 28 SkAssertResult(bitmap.allocN32Pixels(kBitmapSize, kBitmapSize)); |
| 34 bitmap.eraseColor(0xFFFFFFFF); | 29 bitmap.eraseColor(0xFFFFFFFF); |
| 35 SkScalar scale = SkIntToScalar(kScale); | 30 SkScalar scale = SkIntToScalar(kScale); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 | 63 |
| 69 SkGraphics::SetImageCacheTotalByteLimit(0); // clear cache | 64 SkGraphics::SetImageCacheTotalByteLimit(0); // clear cache |
| 70 SkGraphics::SetImageCacheTotalByteLimit(2 * size); | 65 SkGraphics::SetImageCacheTotalByteLimit(2 * size); |
| 71 SkGraphics::SetImageCacheSingleAllocationByteLimit(size / 2); // too small | 66 SkGraphics::SetImageCacheSingleAllocationByteLimit(size / 2); // too small |
| 72 | 67 |
| 73 REPORTER_ASSERT(reporter, !test_scaled_image_cache_useage()); | 68 REPORTER_ASSERT(reporter, !test_scaled_image_cache_useage()); |
| 74 | 69 |
| 75 SkGraphics::SetImageCacheSingleAllocationByteLimit(originalAllocationLimit); | 70 SkGraphics::SetImageCacheSingleAllocationByteLimit(originalAllocationLimit); |
| 76 SkGraphics::SetImageCacheTotalByteLimit(originalByteLimit); | 71 SkGraphics::SetImageCacheTotalByteLimit(originalByteLimit); |
| 77 } | 72 } |
| OLD | NEW |