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

Side by Side Diff: tests/DrawBitmapRectTest.cpp

Issue 84783002: SkDiscardableMemory::Factory class (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years 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 | Annotate | Revision Log
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 #include "Test.h" 8 #include "Test.h"
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkBitmapFactory.h"
10 #include "SkCanvas.h" 11 #include "SkCanvas.h"
11 #include "SkData.h" 12 #include "SkData.h"
13 #include "SkLruImageCache.h"
12 #include "SkPaint.h" 14 #include "SkPaint.h"
13 #include "SkShader.h" 15 #include "SkShader.h"
14 #include "SkSurface.h" 16 #include "SkSurface.h"
15 #include "SkRandom.h" 17 #include "SkRandom.h"
16 #include "SkMatrixUtils.h" 18 #include "SkMatrixUtils.h"
17 19
18 #include "SkLazyPixelRef.h"
19 #include "SkLruImageCache.h"
20
21 // A BitmapFactory that always fails when asked to return pixels. 20 // A BitmapFactory that always fails when asked to return pixels.
22 static bool FailureDecoder(const void* data, size_t length, SkImageInfo* info, 21 static bool FailureDecoder(const void* data, size_t length, SkImageInfo* info,
23 const SkBitmapFactory::Target* target) { 22 const SkBitmapFactory::Target* target) {
24 if (info) { 23 if (info) {
25 info->fWidth = info->fHeight = 100; 24 info->fWidth = info->fHeight = 100;
26 info->fColorType = kRGBA_8888_SkColorType; 25 info->fColorType = kPMColor_SkColorType;
scroggo 2013/12/02 19:00:09 Is this a separate bug?
27 info->fAlphaType = kPremul_SkAlphaType; 26 info->fAlphaType = kPremul_SkAlphaType;
28 } 27 }
29 // this will deliberately return false if they are asking us to decode 28 // this will deliberately return false if they are asking us to decode
30 // into pixels. 29 // into pixels.
31 return NULL == target; 30 return NULL == target;
32 } 31 }
33 32
34 // crbug.com/295895 33 // crbug.com/295895
35 // Crashing in skia when a pixelref fails in lockPixels 34 // Crashing in skia when a pixelref fails in lockPixels
36 // 35 //
37 static void test_faulty_pixelref(skiatest::Reporter* reporter) { 36 static void test_faulty_pixelref(skiatest::Reporter* reporter) {
38 // need a cache, but don't expect to use it, so the budget is not critical 37 // need a cache, but don't expect to use it, so the budget is not critical
39 SkLruImageCache cache(10 * 1000); 38 SkLruImageCache cache(10 * 1000);
40 // construct a garbage data represent "bad" encoded data. 39 // construct a garbage data represent "bad" encoded data.
41 SkAutoDataUnref data(SkData::NewFromMalloc(malloc(1000), 1000)); 40 SkAutoDataUnref data(SkData::NewFromMalloc(malloc(1000), 1000));
42 SkAutoTUnref<SkPixelRef> pr(new SkLazyPixelRef(data, FailureDecoder, &cache) );
43 41
42 SkBitmapFactory bitmapFactory(FailureDecoder);
43 bitmapFactory.setImageCache(&cache);
44 SkBitmap bm; 44 SkBitmap bm;
45 bm.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); 45 bool success = bitmapFactory.installPixelRef(data, &bm);
46 bm.setPixelRef(pr); 46 REPORTER_ASSERT(reporter, success);
47 if (!success) {
48 return;
49 }
47 // now our bitmap has a pixelref, but we know it will fail to lock 50 // now our bitmap has a pixelref, but we know it will fail to lock
48 51
49 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(200, 200)); 52 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(200, 200));
50 SkCanvas* canvas = surface->getCanvas(); 53 SkCanvas* canvas = surface->getCanvas();
51 54
52 const SkPaint::FilterLevel levels[] = { 55 const SkPaint::FilterLevel levels[] = {
53 SkPaint::kNone_FilterLevel, 56 SkPaint::kNone_FilterLevel,
54 SkPaint::kLow_FilterLevel, 57 SkPaint::kLow_FilterLevel,
55 SkPaint::kMedium_FilterLevel, 58 SkPaint::kMedium_FilterLevel,
56 SkPaint::kHigh_FilterLevel, 59 SkPaint::kHigh_FilterLevel,
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 323
321 test_nan_antihair(); 324 test_nan_antihair();
322 test_giantrepeat_crbug118018(reporter); 325 test_giantrepeat_crbug118018(reporter);
323 326
324 test_treatAsSprite(reporter); 327 test_treatAsSprite(reporter);
325 test_faulty_pixelref(reporter); 328 test_faulty_pixelref(reporter);
326 } 329 }
327 330
328 #include "TestClassDef.h" 331 #include "TestClassDef.h"
329 DEFINE_TESTCLASS("DrawBitmapRect", TestDrawBitmapRectClass, TestDrawBitmapRect) 332 DEFINE_TESTCLASS("DrawBitmapRect", TestDrawBitmapRectClass, TestDrawBitmapRect)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698