blob: 00a1a3f201b39195199fbff329e6e1d70d3894f8 [file] [log] [blame]
scroggo@google.com10dccde2012-08-08 20:43:22 +00001/*
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"
scroggo@google.comd5d158b2012-08-14 20:38:28 +000012#include "SkPaint.h"
13#include "SkShader.h"
tfarina@chromium.org8f6884a2014-01-24 20:56:26 +000014#include "Test.h"
scroggo@google.com10dccde2012-08-08 20:43:22 +000015
16// Ensures that the pipe gracefully handles drawing an invalid bitmap.
scroggo@google.comd5d158b2012-08-14 20:38:28 +000017static void testDrawingBadBitmap(SkCanvas* pipeCanvas) {
scroggo@google.com10dccde2012-08-08 20:43:22 +000018 SkBitmap badBitmap;
commit-bot@chromium.orga3264e52014-05-30 13:26:10 +000019 badBitmap.setInfo(SkImageInfo::MakeUnknown(5, 5));
scroggo@google.com10dccde2012-08-08 20:43:22 +000020 pipeCanvas->drawBitmap(badBitmap, 0, 0);
21}
22
scroggo@google.comd5d158b2012-08-14 20:38:28 +000023// Ensure that pipe gracefully handles attempting to draw after endRecording is called on the
24// SkGPipeWriter.
25static 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;
mike@reedtribe.orgdeee4962014-02-13 14:41:43 +000032 bm.allocN32Pixels(2, 2);
junov@google.comdbfac8a2012-12-06 21:47:40 +000033 bm.eraseColor(SK_ColorTRANSPARENT);
scroggo@google.comd5d158b2012-08-14 20:38:28 +000034
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
tfarina@chromium.orge4fafb12013-12-12 21:11:12 +000044DEF_TEST(Pipe, reporter) {
scroggo@google.com10dccde2012-08-08 20:43:22 +000045 SkBitmap bitmap;
commit-bot@chromium.orga3264e52014-05-30 13:26:10 +000046 bitmap.setInfo(SkImageInfo::MakeN32Premul(64, 64));
scroggo@google.com10dccde2012-08-08 20:43:22 +000047 SkCanvas canvas(bitmap);
48
49 PipeController pipeController(&canvas);
50 SkGPipeWriter writer;
51 SkCanvas* pipeCanvas = writer.startRecording(&pipeController);
scroggo@google.comd5d158b2012-08-14 20:38:28 +000052 testDrawingBadBitmap(pipeCanvas);
scroggo@google.com10dccde2012-08-08 20:43:22 +000053 writer.endRecording();
scroggo@google.comd5d158b2012-08-14 20:38:28 +000054
55 testDrawingAfterEndRecording(&canvas);
scroggo@google.com10dccde2012-08-08 20:43:22 +000056}