| 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     float roundedImageWidth = SkScalarRoundToScalar(orig.width() * xScale); | 20     return SkBitmapCache::Find(orig, SkScalarInvert(xScale), SkScalarInvert(ySca
    le), &scaled); | 
| 21     float roundedImageHeight = SkScalarRoundToScalar(orig.height() * xScale); |  | 
| 22     return SkBitmapCache::Find(orig, roundedImageWidth, roundedImageHeight, &sca
    led); |  | 
| 23 } | 21 } | 
| 24 | 22 | 
| 25 // 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. | 
| 26 static bool test_scaled_image_cache_useage() { | 24 static bool test_scaled_image_cache_useage() { | 
| 27     SkAutoTUnref<SkCanvas> canvas( | 25     SkAutoTUnref<SkCanvas> canvas( | 
| 28             SkCanvas::NewRasterN32(kCanvasSize, kCanvasSize)); | 26             SkCanvas::NewRasterN32(kCanvasSize, kCanvasSize)); | 
| 29     SkBitmap bitmap; | 27     SkBitmap bitmap; | 
| 30     SkAssertResult(bitmap.allocN32Pixels(kBitmapSize, kBitmapSize)); | 28     SkAssertResult(bitmap.allocN32Pixels(kBitmapSize, kBitmapSize)); | 
| 31     bitmap.eraseColor(0xFFFFFFFF); | 29     bitmap.eraseColor(0xFFFFFFFF); | 
| 32     SkScalar scale = SkIntToScalar(kScale); | 30     SkScalar scale = SkIntToScalar(kScale); | 
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 65 | 63 | 
| 66     SkGraphics::SetImageCacheTotalByteLimit(0);  // clear cache | 64     SkGraphics::SetImageCacheTotalByteLimit(0);  // clear cache | 
| 67     SkGraphics::SetImageCacheTotalByteLimit(2 * size); | 65     SkGraphics::SetImageCacheTotalByteLimit(2 * size); | 
| 68     SkGraphics::SetImageCacheSingleAllocationByteLimit(size / 2);  // too small | 66     SkGraphics::SetImageCacheSingleAllocationByteLimit(size / 2);  // too small | 
| 69 | 67 | 
| 70     REPORTER_ASSERT(reporter, !test_scaled_image_cache_useage()); | 68     REPORTER_ASSERT(reporter, !test_scaled_image_cache_useage()); | 
| 71 | 69 | 
| 72     SkGraphics::SetImageCacheSingleAllocationByteLimit(originalAllocationLimit); | 70     SkGraphics::SetImageCacheSingleAllocationByteLimit(originalAllocationLimit); | 
| 73     SkGraphics::SetImageCacheTotalByteLimit(originalByteLimit); | 71     SkGraphics::SetImageCacheTotalByteLimit(originalByteLimit); | 
| 74 } | 72 } | 
| OLD | NEW | 
|---|