1 /*
2  * Copyright 2012 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #include "SamplePipeControllers.h"
9 #include "SkBitmap.h"
10 #include "SkCanvas.h"
11 #include "SkGPipe.h"
12 #include "SkPaint.h"
13 #include "SkShader.h"
14 #include "Test.h"
15 
16 // Ensures that the pipe gracefully handles drawing an invalid bitmap.
testDrawingBadBitmap(SkCanvas * pipeCanvas)17 static void testDrawingBadBitmap(SkCanvas* pipeCanvas) {
18     SkBitmap badBitmap;
19     badBitmap.setInfo(SkImageInfo::MakeUnknown(5, 5));
20     pipeCanvas->drawBitmap(badBitmap, 0, 0);
21 }
22 
23 // Ensure that pipe gracefully handles attempting to draw after endRecording is called on the
24 // SkGPipeWriter.
testDrawingAfterEndRecording(SkCanvas * canvas)25 static void testDrawingAfterEndRecording(SkCanvas* canvas) {
26     PipeController pc(canvas);
27     SkGPipeWriter writer;
28     SkCanvas* pipeCanvas = writer.startRecording(&pc, SkGPipeWriter::kCrossProcess_Flag);
29     writer.endRecording();
30 
31     SkBitmap bm;
32     bm.allocN32Pixels(2, 2);
33     bm.eraseColor(SK_ColorTRANSPARENT);
34 
35     SkShader* shader = SkShader::CreateBitmapShader(bm, SkShader::kClamp_TileMode,
36                                                     SkShader::kClamp_TileMode);
37     SkPaint paint;
38     paint.setShader(shader)->unref();
39     pipeCanvas->drawPaint(paint);
40 
41     pipeCanvas->drawBitmap(bm, 0, 0);
42 }
43 
DEF_TEST(Pipe,reporter)44 DEF_TEST(Pipe, reporter) {
45     SkBitmap bitmap;
46     bitmap.setInfo(SkImageInfo::MakeN32Premul(64, 64));
47     SkCanvas canvas(bitmap);
48 
49     PipeController pipeController(&canvas);
50     SkGPipeWriter writer;
51     SkCanvas* pipeCanvas = writer.startRecording(&pipeController);
52     testDrawingBadBitmap(pipeCanvas);
53     writer.endRecording();
54 
55     testDrawingAfterEndRecording(&canvas);
56 }
57