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 | 7 |
8 #include "Test.h" | 8 #include "Test.h" |
9 #include "SkBitmapCache.h" | 9 #include "SkBitmapCache.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
11 #include "SkDiscardableMemoryPool.h" | 11 #include "SkDiscardableMemoryPool.h" |
12 #include "SkGraphics.h" | 12 #include "SkGraphics.h" |
13 #include "SkResourceCache.h" | 13 #include "SkResourceCache.h" |
14 #include "SkSurface.h" | 14 #include "SkSurface.h" |
15 | 15 |
16 static const int kCanvasSize = 1; | 16 static const int kCanvasSize = 1; |
17 static const int kBitmapSize = 16; | 17 static const int kBitmapSize = 16; |
18 static const int kScale = 8; | 18 static const int kScale = 8; |
19 | 19 |
20 static bool is_in_scaled_image_cache(const SkBitmap& orig, | 20 static bool is_in_scaled_image_cache(const SkBitmap& orig, |
21 SkScalar xScale, | 21 SkScalar xScale, |
22 SkScalar yScale) { | 22 SkScalar yScale) { |
23 SkBitmap scaled; | 23 SkBitmap scaled; |
24 float roundedImageWidth = SkScalarRoundToScalar(orig.width() * xScale); | 24 int width = SkScalarRoundToInt(orig.width() * xScale); |
25 float roundedImageHeight = SkScalarRoundToScalar(orig.height() * yScale); | 25 int height = SkScalarRoundToInt(orig.height() * yScale); |
26 return SkBitmapCache::Find(orig, roundedImageWidth, roundedImageHeight, &sca
led); | 26 return SkBitmapCache::FindWH(orig, width, height, &scaled); |
27 } | 27 } |
28 | 28 |
29 // Draw a scaled bitmap, then return true if it has been cached. | 29 // Draw a scaled bitmap, then return true if it has been cached. |
30 static bool test_scaled_image_cache_usage() { | 30 static bool test_scaled_image_cache_usage() { |
31 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(kCanvasSize, k
CanvasSize)); | 31 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(kCanvasSize, k
CanvasSize)); |
32 SkCanvas* canvas = surface->getCanvas(); | 32 SkCanvas* canvas = surface->getCanvas(); |
33 SkBitmap bitmap; | 33 SkBitmap bitmap; |
34 bitmap.allocN32Pixels(kBitmapSize, kBitmapSize); | 34 bitmap.allocN32Pixels(kBitmapSize, kBitmapSize); |
35 bitmap.eraseColor(0xFFFFFFFF); | 35 bitmap.eraseColor(0xFFFFFFFF); |
36 SkScalar xScale = SkIntToScalar(kScale); | 36 SkScalar xScale = SkIntToScalar(kScale); |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 cachedBitmap.unlockPixels(); | 279 cachedBitmap.unlockPixels(); |
280 | 280 |
281 // We can add the bitmap back to the cache and find it again. | 281 // We can add the bitmap back to the cache and find it again. |
282 REPORTER_ASSERT(reporter, SkBitmapCache::Add(cachedBitmap.pixelRef(), rect,
cachedBitmap, cache)); | 282 REPORTER_ASSERT(reporter, SkBitmapCache::Add(cachedBitmap.pixelRef(), rect,
cachedBitmap, cache)); |
283 REPORTER_ASSERT(reporter, SkBitmapCache::Find(cachedBitmap.getGenerationID()
, rect, &bm, cache)); | 283 REPORTER_ASSERT(reporter, SkBitmapCache::Find(cachedBitmap.getGenerationID()
, rect, &bm, cache)); |
284 | 284 |
285 test_mipmapcache(reporter, cache); | 285 test_mipmapcache(reporter, cache); |
286 test_bitmap_notify(reporter, cache); | 286 test_bitmap_notify(reporter, cache); |
287 test_mipmap_notify(reporter, cache); | 287 test_mipmap_notify(reporter, cache); |
288 } | 288 } |
OLD | NEW |