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.setInfo(SkImageInfo::MakeUnknown(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.allocN32Pixels(2, 2); | 33 bm.allocN32Pixels(2, 2); |
33 bm.eraseColor(SK_ColorTRANSPARENT); | 34 bm.eraseColor(SK_ColorTRANSPARENT); |
34 | 35 |
35 SkShader* shader = SkShader::CreateBitmapShader(bm, SkShader::kClamp_TileMod
e, | 36 SkShader* shader = SkShader::CreateBitmapShader(bm, SkShader::kClamp_TileMod
e, |
36 SkShader::kClamp_TileMode); | 37 SkShader::kClamp_TileMode); |
37 SkPaint paint; | 38 SkPaint paint; |
38 paint.setShader(shader)->unref(); | 39 paint.setShader(shader)->unref(); |
39 pipeCanvas->drawPaint(paint); | 40 pipeCanvas->drawPaint(paint); |
40 | 41 |
41 pipeCanvas->drawBitmap(bm, 0, 0); | 42 pipeCanvas->drawBitmap(bm, 0, 0); |
42 } | 43 } |
43 | 44 |
44 DEF_TEST(Pipe, reporter) { | 45 DEF_TEST(Pipe, reporter) { |
45 SkBitmap bitmap; | 46 SkBitmap bitmap; |
46 bitmap.setInfo(SkImageInfo::MakeN32Premul(64, 64)); | 47 bitmap.setConfig(SkImageInfo::MakeN32Premul(64, 64)); |
47 SkCanvas canvas(bitmap); | 48 SkCanvas canvas(bitmap); |
48 | 49 |
49 PipeController pipeController(&canvas); | 50 PipeController pipeController(&canvas); |
50 SkGPipeWriter writer; | 51 SkGPipeWriter writer; |
51 SkCanvas* pipeCanvas = writer.startRecording(&pipeController); | 52 SkCanvas* pipeCanvas = writer.startRecording(&pipeController); |
52 testDrawingBadBitmap(pipeCanvas); | 53 testDrawingBadBitmap(pipeCanvas); |
53 writer.endRecording(); | 54 writer.endRecording(); |
54 | 55 |
55 testDrawingAfterEndRecording(&canvas); | 56 testDrawingAfterEndRecording(&canvas); |
56 } | 57 } |
OLD | NEW |