110dccde54a769b8d472bccf8c1993034b93ef58dscroggo@google.com/* 210dccde54a769b8d472bccf8c1993034b93ef58dscroggo@google.com * Copyright 2012 Google Inc. 310dccde54a769b8d472bccf8c1993034b93ef58dscroggo@google.com * 410dccde54a769b8d472bccf8c1993034b93ef58dscroggo@google.com * Use of this source code is governed by a BSD-style license that can be 510dccde54a769b8d472bccf8c1993034b93ef58dscroggo@google.com * found in the LICENSE file. 610dccde54a769b8d472bccf8c1993034b93ef58dscroggo@google.com */ 710dccde54a769b8d472bccf8c1993034b93ef58dscroggo@google.com 810dccde54a769b8d472bccf8c1993034b93ef58dscroggo@google.com#include "SamplePipeControllers.h" 910dccde54a769b8d472bccf8c1993034b93ef58dscroggo@google.com#include "SkBitmap.h" 1010dccde54a769b8d472bccf8c1993034b93ef58dscroggo@google.com#include "SkCanvas.h" 1110dccde54a769b8d472bccf8c1993034b93ef58dscroggo@google.com#include "SkGPipe.h" 12d5d158b325f05902ac845f2f7c8c65ffe6074257scroggo@google.com#include "SkPaint.h" 13d5d158b325f05902ac845f2f7c8c65ffe6074257scroggo@google.com#include "SkShader.h" 148f6884aab8aecd7657cf3f9cdbc682f0deca29c5tfarina@chromium.org#include "Test.h" 1510dccde54a769b8d472bccf8c1993034b93ef58dscroggo@google.com 1610dccde54a769b8d472bccf8c1993034b93ef58dscroggo@google.com// Ensures that the pipe gracefully handles drawing an invalid bitmap. 17d5d158b325f05902ac845f2f7c8c65ffe6074257scroggo@google.comstatic void testDrawingBadBitmap(SkCanvas* pipeCanvas) { 1810dccde54a769b8d472bccf8c1993034b93ef58dscroggo@google.com SkBitmap badBitmap; 19a3264e53ee3f3c5d6a2c813df7e44b5b96d207f2commit-bot@chromium.org badBitmap.setInfo(SkImageInfo::MakeUnknown(5, 5)); 2010dccde54a769b8d472bccf8c1993034b93ef58dscroggo@google.com pipeCanvas->drawBitmap(badBitmap, 0, 0); 2110dccde54a769b8d472bccf8c1993034b93ef58dscroggo@google.com} 2210dccde54a769b8d472bccf8c1993034b93ef58dscroggo@google.com 23d5d158b325f05902ac845f2f7c8c65ffe6074257scroggo@google.com// Ensure that pipe gracefully handles attempting to draw after endRecording is called on the 24d5d158b325f05902ac845f2f7c8c65ffe6074257scroggo@google.com// SkGPipeWriter. 25d5d158b325f05902ac845f2f7c8c65ffe6074257scroggo@google.comstatic void testDrawingAfterEndRecording(SkCanvas* canvas) { 26d5d158b325f05902ac845f2f7c8c65ffe6074257scroggo@google.com PipeController pc(canvas); 27d5d158b325f05902ac845f2f7c8c65ffe6074257scroggo@google.com SkGPipeWriter writer; 28d5d158b325f05902ac845f2f7c8c65ffe6074257scroggo@google.com SkCanvas* pipeCanvas = writer.startRecording(&pc, SkGPipeWriter::kCrossProcess_Flag); 29d5d158b325f05902ac845f2f7c8c65ffe6074257scroggo@google.com writer.endRecording(); 30d5d158b325f05902ac845f2f7c8c65ffe6074257scroggo@google.com 31d5d158b325f05902ac845f2f7c8c65ffe6074257scroggo@google.com SkBitmap bm; 32deee496cd30070e52556dcb538c2e5eb39b66b81mike@reedtribe.org bm.allocN32Pixels(2, 2); 33dbfac8a72393eaf01670aeb3244de0e18d8faf98junov@google.com bm.eraseColor(SK_ColorTRANSPARENT); 34d5d158b325f05902ac845f2f7c8c65ffe6074257scroggo@google.com 35d5d158b325f05902ac845f2f7c8c65ffe6074257scroggo@google.com SkShader* shader = SkShader::CreateBitmapShader(bm, SkShader::kClamp_TileMode, 36d5d158b325f05902ac845f2f7c8c65ffe6074257scroggo@google.com SkShader::kClamp_TileMode); 37d5d158b325f05902ac845f2f7c8c65ffe6074257scroggo@google.com SkPaint paint; 38d5d158b325f05902ac845f2f7c8c65ffe6074257scroggo@google.com paint.setShader(shader)->unref(); 39d5d158b325f05902ac845f2f7c8c65ffe6074257scroggo@google.com pipeCanvas->drawPaint(paint); 40d5d158b325f05902ac845f2f7c8c65ffe6074257scroggo@google.com 41d5d158b325f05902ac845f2f7c8c65ffe6074257scroggo@google.com pipeCanvas->drawBitmap(bm, 0, 0); 42d5d158b325f05902ac845f2f7c8c65ffe6074257scroggo@google.com} 43d5d158b325f05902ac845f2f7c8c65ffe6074257scroggo@google.com 44e4fafb146e85cdfcf9d5418597b6818aa0754adatfarina@chromium.orgDEF_TEST(Pipe, reporter) { 4510dccde54a769b8d472bccf8c1993034b93ef58dscroggo@google.com SkBitmap bitmap; 46a3264e53ee3f3c5d6a2c813df7e44b5b96d207f2commit-bot@chromium.org bitmap.setInfo(SkImageInfo::MakeN32Premul(64, 64)); 4710dccde54a769b8d472bccf8c1993034b93ef58dscroggo@google.com SkCanvas canvas(bitmap); 4810dccde54a769b8d472bccf8c1993034b93ef58dscroggo@google.com 4910dccde54a769b8d472bccf8c1993034b93ef58dscroggo@google.com PipeController pipeController(&canvas); 5010dccde54a769b8d472bccf8c1993034b93ef58dscroggo@google.com SkGPipeWriter writer; 5110dccde54a769b8d472bccf8c1993034b93ef58dscroggo@google.com SkCanvas* pipeCanvas = writer.startRecording(&pipeController); 52d5d158b325f05902ac845f2f7c8c65ffe6074257scroggo@google.com testDrawingBadBitmap(pipeCanvas); 5310dccde54a769b8d472bccf8c1993034b93ef58dscroggo@google.com writer.endRecording(); 54d5d158b325f05902ac845f2f7c8c65ffe6074257scroggo@google.com 55d5d158b325f05902ac845f2f7c8c65ffe6074257scroggo@google.com testDrawingAfterEndRecording(&canvas); 5610dccde54a769b8d472bccf8c1993034b93ef58dscroggo@google.com} 57