PipeTest.cpp revision d0f824cfbd8951bb948b19d7ff5dce028ce557a5
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. 17static void testDrawingBadBitmap(SkCanvas* pipeCanvas) { 18 SkBitmap badBitmap; 19 badBitmap.setConfig(SkImageInfo::Make(5, 5, kUnknown_SkColorType, 20 kPremul_SkAlphaType)); 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. 26static 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.allocN32Pixels(2, 2); 34 bm.eraseColor(SK_ColorTRANSPARENT); 35 36 SkShader* shader = SkShader::CreateBitmapShader(bm, SkShader::kClamp_TileMode, 37 SkShader::kClamp_TileMode); 38 SkPaint paint; 39 paint.setShader(shader)->unref(); 40 pipeCanvas->drawPaint(paint); 41 42 pipeCanvas->drawBitmap(bm, 0, 0); 43} 44 45DEF_TEST(Pipe, reporter) { 46 SkBitmap bitmap; 47 bitmap.setConfig(SkImageInfo::MakeN32Premul(64, 64)); 48 SkCanvas canvas(bitmap); 49 50 PipeController pipeController(&canvas); 51 SkGPipeWriter writer; 52 SkCanvas* pipeCanvas = writer.startRecording(&pipeController); 53 testDrawingBadBitmap(pipeCanvas); 54 writer.endRecording(); 55 56 testDrawingAfterEndRecording(&canvas); 57} 58