aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/PipeTest.cpp
blob: 00a1a3f201b39195199fbff329e6e1d70d3894f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
 * Copyright 2012 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "SamplePipeControllers.h"
#include "SkBitmap.h"
#include "SkCanvas.h"
#include "SkGPipe.h"
#include "SkPaint.h"
#include "SkShader.h"
#include "Test.h"

// Ensures that the pipe gracefully handles drawing an invalid bitmap.
static void testDrawingBadBitmap(SkCanvas* pipeCanvas) {
    SkBitmap badBitmap;
    badBitmap.setInfo(SkImageInfo::MakeUnknown(5, 5));
    pipeCanvas->drawBitmap(badBitmap, 0, 0);
}

// Ensure that pipe gracefully handles attempting to draw after endRecording is called on the
// SkGPipeWriter.
static void testDrawingAfterEndRecording(SkCanvas* canvas) {
    PipeController pc(canvas);
    SkGPipeWriter writer;
    SkCanvas* pipeCanvas = writer.startRecording(&pc, SkGPipeWriter::kCrossProcess_Flag);
    writer.endRecording();

    SkBitmap bm;
    bm.allocN32Pixels(2, 2);
    bm.eraseColor(SK_ColorTRANSPARENT);

    SkShader* shader = SkShader::CreateBitmapShader(bm, SkShader::kClamp_TileMode,
                                                    SkShader::kClamp_TileMode);
    SkPaint paint;
    paint.setShader(shader)->unref();
    pipeCanvas->drawPaint(paint);

    pipeCanvas->drawBitmap(bm, 0, 0);
}

DEF_TEST(Pipe, reporter) {
    SkBitmap bitmap;
    bitmap.setInfo(SkImageInfo::MakeN32Premul(64, 64));
    SkCanvas canvas(bitmap);

    PipeController pipeController(&canvas);
    SkGPipeWriter writer;
    SkCanvas* pipeCanvas = writer.startRecording(&pipeController);
    testDrawingBadBitmap(pipeCanvas);
    writer.endRecording();

    testDrawingAfterEndRecording(&canvas);
}