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