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