blob: fd98fca7ef8afe3251b45392cf7a83ac268a153c [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;
mike@reedtribe.orgdeee4962014-02-13 14:41:43 +000019 badBitmap.setConfig(SkImageInfo::Make(5, 5, kUnknown_SkColorType,
20 kPremul_SkAlphaType));
scroggo@google.com10dccde2012-08-08 20:43:22 +000021 pipeCanvas->drawBitmap(badBitmap, 0, 0);
22}
23
scroggo@google.comd5d158b2012-08-14 20:38:28 +000024// 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;
mike@reedtribe.orgdeee4962014-02-13 14:41:43 +000033 bm.allocN32Pixels(2, 2);
junov@google.comdbfac8a2012-12-06 21:47:40 +000034 bm.eraseColor(SK_ColorTRANSPARENT);
scroggo@google.comd5d158b2012-08-14 20:38:28 +000035
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
tfarina@chromium.orge4fafb12013-12-12 21:11:12 +000045DEF_TEST(Pipe, reporter) {
scroggo@google.com10dccde2012-08-08 20:43:22 +000046 SkBitmap bitmap;
mike@reedtribe.orgdeee4962014-02-13 14:41:43 +000047 bitmap.setConfig(SkImageInfo::MakeN32Premul(64, 64));
scroggo@google.com10dccde2012-08-08 20:43:22 +000048 SkCanvas canvas(bitmap);
49
50 PipeController pipeController(&canvas);
51 SkGPipeWriter writer;
52 SkCanvas* pipeCanvas = writer.startRecording(&pipeController);
scroggo@google.comd5d158b2012-08-14 20:38:28 +000053 testDrawingBadBitmap(pipeCanvas);
scroggo@google.com10dccde2012-08-08 20:43:22 +000054 writer.endRecording();
scroggo@google.comd5d158b2012-08-14 20:38:28 +000055
56 testDrawingAfterEndRecording(&canvas);
scroggo@google.com10dccde2012-08-08 20:43:22 +000057}