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

Side by Side Diff: tests/DrawBitmapRectTest.cpp

Issue 103033002: Big Cleanup: SkBitmapFactory, SkLazyPixelRef, SkImageCache (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 "SkCanvas.h" 10 #include "SkCanvas.h"
11 #include "SkData.h" 11 #include "SkData.h"
12 #include "SkDiscardableMemoryPool.h"
13 #include "SkDiscardablePixelRef.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" 20 namespace {
19 #include "SkLruImageCache.h"
20
21 // A BitmapFactory that always fails when asked to return pixels. 21 // A BitmapFactory that always fails when asked to return pixels.
22 static bool FailureDecoder(const void* data, size_t length, SkImageInfo* info, 22 class FailureImageGenerator : public SkImageGenerator {
23 const SkBitmapFactory::Target* target) { 23 public:
24 if (info) { 24 FailureImageGenerator() { }
25 info->fWidth = info->fHeight = 100; 25 virtual ~FailureImageGenerator() { }
26 info->fColorType = kRGBA_8888_SkColorType; 26 virtual bool getInfo(SkImageInfo* info) {
27 info->fWidth = 100;
28 info->fHeight = 100;
29 info->fColorType = kPMColor_SkColorType;
27 info->fAlphaType = kPremul_SkAlphaType; 30 info->fAlphaType = kPremul_SkAlphaType;
31 return true;
28 } 32 }
29 // this will deliberately return false if they are asking us to decode 33 virtual bool getPixels(const SkImageInfo& info,
30 // into pixels. 34 void* pixels,
31 return NULL == target; 35 size_t rowBytes) SK_OVERRIDE {
32 } 36 // this will deliberately return false if they are asking us
37 // to decode into pixels.
38 return false;
39 }
40 private:
41 SkData* fData;
42 };
43 } // namespace
33 44
34 // crbug.com/295895 45 // crbug.com/295895
35 // Crashing in skia when a pixelref fails in lockPixels 46 // Crashing in skia when a pixelref fails in lockPixels
36 // 47 //
37 static void test_faulty_pixelref(skiatest::Reporter* reporter) { 48 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 49 // need a cache, but don't expect to use it, so the budget is not critical
39 SkLruImageCache cache(10 * 1000); 50 SkAutoTUnref<SkDiscardableMemoryPool> pool(SkNEW_ARGS(SkDiscardableMemoryPoo l,
40 // construct a garbage data represent "bad" encoded data. 51 (10 * 1000, NULL)));
41 SkAutoDataUnref data(SkData::NewFromMalloc(malloc(1000), 1000));
42 SkAutoTUnref<SkPixelRef> pr(new SkLazyPixelRef(data, FailureDecoder, &cache) );
43
44 SkBitmap bm; 52 SkBitmap bm;
45 bm.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); 53 bool installSuccess = SkDiscardablePixelRef::Install(SkNEW(FailureImageGener ator), &bm, pool);
46 bm.setPixelRef(pr); 54 REPORTER_ASSERT(reporter, installSuccess);
47 // now our bitmap has a pixelref, but we know it will fail to lock 55 // now our bitmap has a pixelref, but we know it will fail to lock
48 56
49 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(200, 200)); 57 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(200, 200));
50 SkCanvas* canvas = surface->getCanvas(); 58 SkCanvas* canvas = surface->getCanvas();
51 59
52 const SkPaint::FilterLevel levels[] = { 60 const SkPaint::FilterLevel levels[] = {
53 SkPaint::kNone_FilterLevel, 61 SkPaint::kNone_FilterLevel,
54 SkPaint::kLow_FilterLevel, 62 SkPaint::kLow_FilterLevel,
55 SkPaint::kMedium_FilterLevel, 63 SkPaint::kMedium_FilterLevel,
56 SkPaint::kHigh_FilterLevel, 64 SkPaint::kHigh_FilterLevel,
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 328
321 test_nan_antihair(); 329 test_nan_antihair();
322 test_giantrepeat_crbug118018(reporter); 330 test_giantrepeat_crbug118018(reporter);
323 331
324 test_treatAsSprite(reporter); 332 test_treatAsSprite(reporter);
325 test_faulty_pixelref(reporter); 333 test_faulty_pixelref(reporter);
326 } 334 }
327 335
328 #include "TestClassDef.h" 336 #include "TestClassDef.h"
329 DEFINE_TESTCLASS("DrawBitmapRect", TestDrawBitmapRectClass, TestDrawBitmapRect) 337 DEFINE_TESTCLASS("DrawBitmapRect", TestDrawBitmapRectClass, TestDrawBitmapRect)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698