OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "SamplePipeControllers.h" | 8 #include "SamplePipeControllers.h" |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
11 #include "SkGPipe.h" | 11 #include "SkGPipe.h" |
12 #include "SkPaint.h" | 12 #include "SkPaint.h" |
13 #include "SkShader.h" | 13 #include "SkShader.h" |
14 #include "Test.h" | 14 #include "Test.h" |
15 | 15 |
16 // Ensures that the pipe gracefully handles drawing an invalid bitmap. | 16 // Ensures that the pipe gracefully handles drawing an invalid bitmap. |
17 static void testDrawingBadBitmap(SkCanvas* pipeCanvas) { | 17 static void testDrawingBadBitmap(SkCanvas* pipeCanvas) { |
18 SkBitmap badBitmap; | 18 SkBitmap badBitmap; |
19 badBitmap.setConfig(SkBitmap::kNo_Config, 5, 5); | 19 badBitmap.setConfig(SkImageInfo::Make(5, 5, kUnknown_SkColorType, |
| 20 kPremul_SkAlphaType)); |
20 pipeCanvas->drawBitmap(badBitmap, 0, 0); | 21 pipeCanvas->drawBitmap(badBitmap, 0, 0); |
21 } | 22 } |
22 | 23 |
23 // Ensure that pipe gracefully handles attempting to draw after endRecording is
called on the | 24 // Ensure that pipe gracefully handles attempting to draw after endRecording is
called on the |
24 // SkGPipeWriter. | 25 // SkGPipeWriter. |
25 static void testDrawingAfterEndRecording(SkCanvas* canvas) { | 26 static void testDrawingAfterEndRecording(SkCanvas* canvas) { |
26 PipeController pc(canvas); | 27 PipeController pc(canvas); |
27 SkGPipeWriter writer; | 28 SkGPipeWriter writer; |
28 SkCanvas* pipeCanvas = writer.startRecording(&pc, SkGPipeWriter::kCrossProce
ss_Flag); | 29 SkCanvas* pipeCanvas = writer.startRecording(&pc, SkGPipeWriter::kCrossProce
ss_Flag); |
29 writer.endRecording(); | 30 writer.endRecording(); |
30 | 31 |
31 SkBitmap bm; | 32 SkBitmap bm; |
32 bm.setConfig(SkBitmap::kARGB_8888_Config, 2, 2); | 33 bm.allocN32Pixels(2, 2); |
33 bm.allocPixels(); | |
34 bm.eraseColor(SK_ColorTRANSPARENT); | 34 bm.eraseColor(SK_ColorTRANSPARENT); |
35 | 35 |
36 SkShader* shader = SkShader::CreateBitmapShader(bm, SkShader::kClamp_TileMod
e, | 36 SkShader* shader = SkShader::CreateBitmapShader(bm, SkShader::kClamp_TileMod
e, |
37 SkShader::kClamp_TileMode); | 37 SkShader::kClamp_TileMode); |
38 SkPaint paint; | 38 SkPaint paint; |
39 paint.setShader(shader)->unref(); | 39 paint.setShader(shader)->unref(); |
40 pipeCanvas->drawPaint(paint); | 40 pipeCanvas->drawPaint(paint); |
41 | 41 |
42 pipeCanvas->drawBitmap(bm, 0, 0); | 42 pipeCanvas->drawBitmap(bm, 0, 0); |
43 } | 43 } |
44 | 44 |
45 DEF_TEST(Pipe, reporter) { | 45 DEF_TEST(Pipe, reporter) { |
46 SkBitmap bitmap; | 46 SkBitmap bitmap; |
47 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 64, 64); | 47 bitmap.setConfig(SkImageInfo::MakeN32Premul(64, 64)); |
48 SkCanvas canvas(bitmap); | 48 SkCanvas canvas(bitmap); |
49 | 49 |
50 PipeController pipeController(&canvas); | 50 PipeController pipeController(&canvas); |
51 SkGPipeWriter writer; | 51 SkGPipeWriter writer; |
52 SkCanvas* pipeCanvas = writer.startRecording(&pipeController); | 52 SkCanvas* pipeCanvas = writer.startRecording(&pipeController); |
53 testDrawingBadBitmap(pipeCanvas); | 53 testDrawingBadBitmap(pipeCanvas); |
54 writer.endRecording(); | 54 writer.endRecording(); |
55 | 55 |
56 testDrawingAfterEndRecording(&canvas); | 56 testDrawingAfterEndRecording(&canvas); |
57 } | 57 } |
OLD | NEW |