2012-08-08 20:43:22 +00:00
|
|
|
/*
|
|
|
|
* 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"
|
2012-08-14 20:38:28 +00:00
|
|
|
#include "SkPaint.h"
|
|
|
|
#include "SkShader.h"
|
2014-01-24 20:56:26 +00:00
|
|
|
#include "Test.h"
|
2012-08-08 20:43:22 +00:00
|
|
|
|
|
|
|
// Ensures that the pipe gracefully handles drawing an invalid bitmap.
|
2012-08-14 20:38:28 +00:00
|
|
|
static void testDrawingBadBitmap(SkCanvas* pipeCanvas) {
|
2012-08-08 20:43:22 +00:00
|
|
|
SkBitmap badBitmap;
|
2014-05-29 21:10:32 +00:00
|
|
|
badBitmap.setConfig(SkImageInfo::Make(5, 5, kUnknown_SkColorType,
|
|
|
|
kPremul_SkAlphaType));
|
2012-08-08 20:43:22 +00:00
|
|
|
pipeCanvas->drawBitmap(badBitmap, 0, 0);
|
|
|
|
}
|
|
|
|
|
2012-08-14 20:38:28 +00:00
|
|
|
// 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;
|
2014-02-13 14:41:43 +00:00
|
|
|
bm.allocN32Pixels(2, 2);
|
2012-12-06 21:47:40 +00:00
|
|
|
bm.eraseColor(SK_ColorTRANSPARENT);
|
2012-08-14 20:38:28 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2013-12-12 21:11:12 +00:00
|
|
|
DEF_TEST(Pipe, reporter) {
|
2012-08-08 20:43:22 +00:00
|
|
|
SkBitmap bitmap;
|
2014-05-29 21:10:32 +00:00
|
|
|
bitmap.setConfig(SkImageInfo::MakeN32Premul(64, 64));
|
2012-08-08 20:43:22 +00:00
|
|
|
SkCanvas canvas(bitmap);
|
|
|
|
|
|
|
|
PipeController pipeController(&canvas);
|
|
|
|
SkGPipeWriter writer;
|
|
|
|
SkCanvas* pipeCanvas = writer.startRecording(&pipeController);
|
2012-08-14 20:38:28 +00:00
|
|
|
testDrawingBadBitmap(pipeCanvas);
|
2012-08-08 20:43:22 +00:00
|
|
|
writer.endRecording();
|
2012-08-14 20:38:28 +00:00
|
|
|
|
|
|
|
testDrawingAfterEndRecording(&canvas);
|
2012-08-08 20:43:22 +00:00
|
|
|
}
|