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

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: rebase one last time 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
« no previous file with comments | « tests/DiscardableMemoryPool.cpp ('k') | tools/LazyDecodeBitmap.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 /* 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 };
41 } // namespace
33 42
34 // crbug.com/295895 43 // crbug.com/295895
35 // Crashing in skia when a pixelref fails in lockPixels 44 // Crashing in skia when a pixelref fails in lockPixels
36 // 45 //
37 static void test_faulty_pixelref(skiatest::Reporter* reporter) { 46 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 47 // need a cache, but don't expect to use it, so the budget is not critical
39 SkLruImageCache cache(10 * 1000); 48 SkAutoTUnref<SkDiscardableMemoryPool> pool(SkNEW_ARGS(SkDiscardableMemoryPoo l,
40 // construct a garbage data represent "bad" encoded data. 49 (10 * 1000, NULL)));
41 SkAutoDataUnref data(SkData::NewFromMalloc(malloc(1000), 1000));
42 SkAutoTUnref<SkPixelRef> pr(new SkLazyPixelRef(data, FailureDecoder, &cache) );
43
44 SkBitmap bm; 50 SkBitmap bm;
45 bm.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); 51 bool installSuccess = SkDiscardablePixelRef::Install(SkNEW(FailureImageGener ator), &bm, pool);
46 bm.setPixelRef(pr); 52 REPORTER_ASSERT(reporter, installSuccess);
47 // now our bitmap has a pixelref, but we know it will fail to lock 53 // now our bitmap has a pixelref, but we know it will fail to lock
48 54
49 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(200, 200)); 55 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(200, 200));
50 SkCanvas* canvas = surface->getCanvas(); 56 SkCanvas* canvas = surface->getCanvas();
51 57
52 const SkPaint::FilterLevel levels[] = { 58 const SkPaint::FilterLevel levels[] = {
53 SkPaint::kNone_FilterLevel, 59 SkPaint::kNone_FilterLevel,
54 SkPaint::kLow_FilterLevel, 60 SkPaint::kLow_FilterLevel,
55 SkPaint::kMedium_FilterLevel, 61 SkPaint::kMedium_FilterLevel,
56 SkPaint::kHigh_FilterLevel, 62 SkPaint::kHigh_FilterLevel,
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 326
321 test_nan_antihair(); 327 test_nan_antihair();
322 test_giantrepeat_crbug118018(reporter); 328 test_giantrepeat_crbug118018(reporter);
323 329
324 test_treatAsSprite(reporter); 330 test_treatAsSprite(reporter);
325 test_faulty_pixelref(reporter); 331 test_faulty_pixelref(reporter);
326 } 332 }
327 333
328 #include "TestClassDef.h" 334 #include "TestClassDef.h"
329 DEFINE_TESTCLASS("DrawBitmapRect", TestDrawBitmapRectClass, TestDrawBitmapRect) 335 DEFINE_TESTCLASS("DrawBitmapRect", TestDrawBitmapRectClass, TestDrawBitmapRect)
OLDNEW
« no previous file with comments | « tests/DiscardableMemoryPool.cpp ('k') | tools/LazyDecodeBitmap.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698