blob: acf288ae8df0981fc36e442454bbbecde4e51a47 [file] [log] [blame]
scroggo@google.com10dccde2012-08-08 20:43:22 +00001
2/*
3 * Copyright 2012 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9#include "SamplePipeControllers.h"
10#include "SkBitmap.h"
11#include "SkCanvas.h"
12#include "SkGPipe.h"
scroggo@google.comd5d158b2012-08-14 20:38:28 +000013#include "SkPaint.h"
14#include "SkShader.h"
scroggo@google.com10dccde2012-08-08 20:43:22 +000015#include "Test.h"
16
17// Ensures that the pipe gracefully handles drawing an invalid bitmap.
scroggo@google.comd5d158b2012-08-14 20:38:28 +000018static void testDrawingBadBitmap(SkCanvas* pipeCanvas) {
scroggo@google.com10dccde2012-08-08 20:43:22 +000019 SkBitmap badBitmap;
20 badBitmap.setConfig(SkBitmap::kNo_Config, 5, 5);
21 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;
33 bm.setConfig(SkBitmap::kARGB_8888_Config, 2, 2);
34 bm.allocPixels();
junov@google.comdbfac8a2012-12-06 21:47:40 +000035 bm.eraseColor(SK_ColorTRANSPARENT);
scroggo@google.comd5d158b2012-08-14 20:38:28 +000036
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
46static void test_pipeTests(skiatest::Reporter*) {
scroggo@google.com10dccde2012-08-08 20:43:22 +000047 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);
scroggo@google.comd5d158b2012-08-14 20:38:28 +000054 testDrawingBadBitmap(pipeCanvas);
scroggo@google.com10dccde2012-08-08 20:43:22 +000055 writer.endRecording();
scroggo@google.comd5d158b2012-08-14 20:38:28 +000056
57 testDrawingAfterEndRecording(&canvas);
scroggo@google.com10dccde2012-08-08 20:43:22 +000058}
59
60#include "TestClassDef.h"
61DEFINE_TESTCLASS("PipeTest", PipeTestClass, test_pipeTests)