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" | |
15 | 14 |
16 static const int kCanvasSize = 1; | 15 static const int kCanvasSize = 1; |
17 static const int kBitmapSize = 16; | 16 static const int kBitmapSize = 16; |
18 static const int kScale = 8; | 17 static const int kScale = 8; |
19 | 18 |
20 static bool is_in_scaled_image_cache(const SkBitmap& orig, | 19 static bool is_in_scaled_image_cache(const SkBitmap& orig, |
21 SkScalar xScale, | 20 SkScalar xScale, |
22 SkScalar yScale) { | 21 SkScalar yScale) { |
23 SkBitmap scaled; | 22 SkBitmap scaled; |
24 float roundedImageWidth = SkScalarRoundToScalar(orig.width() * xScale); | 23 float roundedImageWidth = SkScalarRoundToScalar(orig.width() * xScale); |
25 float roundedImageHeight = SkScalarRoundToScalar(orig.height() * xScale); | 24 float roundedImageHeight = SkScalarRoundToScalar(orig.height() * xScale); |
26 return SkBitmapCache::Find(orig, roundedImageWidth, roundedImageHeight, &sca
led); | 25 return SkBitmapCache::Find(orig, roundedImageWidth, roundedImageHeight, &sca
led); |
27 } | 26 } |
28 | 27 |
29 // Draw a scaled bitmap, then return true iff it has been cached. | 28 // Draw a scaled bitmap, then return true iff it has been cached. |
30 static bool test_scaled_image_cache_useage() { | 29 static bool test_scaled_image_cache_useage() { |
31 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(kCanvasSize, k
CanvasSize)); | 30 SkAutoTUnref<SkCanvas> canvas( |
32 SkCanvas* canvas = surface->getCanvas(); | 31 SkCanvas::NewRasterN32(kCanvasSize, kCanvasSize)); |
33 SkBitmap bitmap; | 32 SkBitmap bitmap; |
34 bitmap.allocN32Pixels(kBitmapSize, kBitmapSize); | 33 bitmap.allocN32Pixels(kBitmapSize, kBitmapSize); |
35 bitmap.eraseColor(0xFFFFFFFF); | 34 bitmap.eraseColor(0xFFFFFFFF); |
36 SkScalar scale = SkIntToScalar(kScale); | 35 SkScalar scale = SkIntToScalar(kScale); |
37 SkScalar scaledSize = SkIntToScalar(kBitmapSize) * scale; | 36 SkScalar scaledSize = SkIntToScalar(kBitmapSize) * scale; |
38 canvas->clipRect(SkRect::MakeLTRB(0, 0, scaledSize, scaledSize)); | 37 canvas->clipRect(SkRect::MakeLTRB(0, 0, scaledSize, scaledSize)); |
39 SkPaint paint; | 38 SkPaint paint; |
40 paint.setFilterLevel(SkPaint::kHigh_FilterLevel); | 39 paint.setFilterLevel(SkPaint::kHigh_FilterLevel); |
41 | 40 |
42 canvas->drawBitmapRect(bitmap, | 41 canvas->drawBitmapRect(bitmap, |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 make_bitmap(&cachedBitmap, SkImageInfo::MakeN32Premul(5, 5), allocator); | 210 make_bitmap(&cachedBitmap, SkImageInfo::MakeN32Premul(5, 5), allocator); |
212 cachedBitmap.setImmutable(); | 211 cachedBitmap.setImmutable(); |
213 cachedBitmap.unlockPixels(); | 212 cachedBitmap.unlockPixels(); |
214 | 213 |
215 // We can add the bitmap back to the cache and find it again. | 214 // We can add the bitmap back to the cache and find it again. |
216 REPORTER_ASSERT(reporter, SkBitmapCache::Add(cachedBitmap.getGenerationID(),
rect, cachedBitmap, cache)); | 215 REPORTER_ASSERT(reporter, SkBitmapCache::Add(cachedBitmap.getGenerationID(),
rect, cachedBitmap, cache)); |
217 REPORTER_ASSERT(reporter, SkBitmapCache::Find(cachedBitmap.getGenerationID()
, rect, &bm, cache)); | 216 REPORTER_ASSERT(reporter, SkBitmapCache::Find(cachedBitmap.getGenerationID()
, rect, &bm, cache)); |
218 | 217 |
219 test_mipmapcache(reporter, cache); | 218 test_mipmapcache(reporter, cache); |
220 } | 219 } |
OLD | NEW |