Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(255)

Side by Side Diff: tests/SkResourceCacheTest.cpp

Issue 510423005: make allocPixels throw on failure (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tests/SerializationTest.cpp ('k') | tests/TextureCompressionTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 float roundedImageWidth = SkScalarRoundToScalar(orig.width() * xScale);
21 float roundedImageHeight = SkScalarRoundToScalar(orig.height() * xScale); 21 float roundedImageHeight = SkScalarRoundToScalar(orig.height() * xScale);
22 return SkBitmapCache::Find(orig, roundedImageWidth, roundedImageHeight, &sca led); 22 return SkBitmapCache::Find(orig, roundedImageWidth, roundedImageHeight, &sca led);
23 } 23 }
24 24
25 // Draw a scaled bitmap, then return true iff it has been cached. 25 // Draw a scaled bitmap, then return true iff it has been cached.
26 static bool test_scaled_image_cache_useage() { 26 static bool test_scaled_image_cache_useage() {
27 SkAutoTUnref<SkCanvas> canvas( 27 SkAutoTUnref<SkCanvas> canvas(
28 SkCanvas::NewRasterN32(kCanvasSize, kCanvasSize)); 28 SkCanvas::NewRasterN32(kCanvasSize, kCanvasSize));
29 SkBitmap bitmap; 29 SkBitmap bitmap;
30 SkAssertResult(bitmap.allocN32Pixels(kBitmapSize, kBitmapSize)); 30 bitmap.allocN32Pixels(kBitmapSize, kBitmapSize);
31 bitmap.eraseColor(0xFFFFFFFF); 31 bitmap.eraseColor(0xFFFFFFFF);
32 SkScalar scale = SkIntToScalar(kScale); 32 SkScalar scale = SkIntToScalar(kScale);
33 SkScalar scaledSize = SkIntToScalar(kBitmapSize) * scale; 33 SkScalar scaledSize = SkIntToScalar(kBitmapSize) * scale;
34 canvas->clipRect(SkRect::MakeLTRB(0, 0, scaledSize, scaledSize)); 34 canvas->clipRect(SkRect::MakeLTRB(0, 0, scaledSize, scaledSize));
35 SkPaint paint; 35 SkPaint paint;
36 paint.setFilterLevel(SkPaint::kHigh_FilterLevel); 36 paint.setFilterLevel(SkPaint::kHigh_FilterLevel);
37 37
38 canvas->drawBitmapRect(bitmap, 38 canvas->drawBitmapRect(bitmap,
39 SkRect::MakeLTRB(0, 0, scaledSize, scaledSize), 39 SkRect::MakeLTRB(0, 0, scaledSize, scaledSize),
40 &paint); 40 &paint);
(...skipping 24 matching lines...) Expand all
65 65
66 SkGraphics::SetResourceCacheTotalByteLimit(0); // clear cache 66 SkGraphics::SetResourceCacheTotalByteLimit(0); // clear cache
67 SkGraphics::SetResourceCacheTotalByteLimit(2 * size); 67 SkGraphics::SetResourceCacheTotalByteLimit(2 * size);
68 SkGraphics::SetResourceCacheSingleAllocationByteLimit(size / 2); // too sma ll 68 SkGraphics::SetResourceCacheSingleAllocationByteLimit(size / 2); // too sma ll
69 69
70 REPORTER_ASSERT(reporter, !test_scaled_image_cache_useage()); 70 REPORTER_ASSERT(reporter, !test_scaled_image_cache_useage());
71 71
72 SkGraphics::SetResourceCacheSingleAllocationByteLimit(originalAllocationLimi t); 72 SkGraphics::SetResourceCacheSingleAllocationByteLimit(originalAllocationLimi t);
73 SkGraphics::SetResourceCacheTotalByteLimit(originalByteLimit); 73 SkGraphics::SetResourceCacheTotalByteLimit(originalByteLimit);
74 } 74 }
OLDNEW
« no previous file with comments | « tests/SerializationTest.cpp ('k') | tests/TextureCompressionTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698