scroggo@google.com | 10dccde | 2012-08-08 20:43:22 +0000 | [diff] [blame] | 1 | /* |
| 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.com | d5d158b | 2012-08-14 20:38:28 +0000 | [diff] [blame] | 12 | #include "SkPaint.h" |
| 13 | #include "SkShader.h" |
tfarina@chromium.org | 8f6884a | 2014-01-24 20:56:26 +0000 | [diff] [blame] | 14 | #include "Test.h" |
scroggo@google.com | 10dccde | 2012-08-08 20:43:22 +0000 | [diff] [blame] | 15 | |
| 16 | // Ensures that the pipe gracefully handles drawing an invalid bitmap. |
scroggo@google.com | d5d158b | 2012-08-14 20:38:28 +0000 | [diff] [blame] | 17 | static void testDrawingBadBitmap(SkCanvas* pipeCanvas) { |
scroggo@google.com | 10dccde | 2012-08-08 20:43:22 +0000 | [diff] [blame] | 18 | SkBitmap badBitmap; |
mike@reedtribe.org | deee496 | 2014-02-13 14:41:43 +0000 | [diff] [blame] | 19 | badBitmap.setConfig(SkImageInfo::Make(5, 5, kUnknown_SkColorType, |
| 20 | kPremul_SkAlphaType)); |
scroggo@google.com | 10dccde | 2012-08-08 20:43:22 +0000 | [diff] [blame] | 21 | pipeCanvas->drawBitmap(badBitmap, 0, 0); |
| 22 | } |
| 23 | |
scroggo@google.com | d5d158b | 2012-08-14 20:38:28 +0000 | [diff] [blame] | 24 | // Ensure that pipe gracefully handles attempting to draw after endRecording is called on the |
| 25 | // SkGPipeWriter. |
| 26 | static 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.org | deee496 | 2014-02-13 14:41:43 +0000 | [diff] [blame] | 33 | bm.allocN32Pixels(2, 2); |
junov@google.com | dbfac8a | 2012-12-06 21:47:40 +0000 | [diff] [blame] | 34 | bm.eraseColor(SK_ColorTRANSPARENT); |
scroggo@google.com | d5d158b | 2012-08-14 20:38:28 +0000 | [diff] [blame] | 35 | |
| 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.org | e4fafb1 | 2013-12-12 21:11:12 +0000 | [diff] [blame] | 45 | DEF_TEST(Pipe, reporter) { |
scroggo@google.com | 10dccde | 2012-08-08 20:43:22 +0000 | [diff] [blame] | 46 | SkBitmap bitmap; |
mike@reedtribe.org | deee496 | 2014-02-13 14:41:43 +0000 | [diff] [blame] | 47 | bitmap.setConfig(SkImageInfo::MakeN32Premul(64, 64)); |
scroggo@google.com | 10dccde | 2012-08-08 20:43:22 +0000 | [diff] [blame] | 48 | SkCanvas canvas(bitmap); |
| 49 | |
| 50 | PipeController pipeController(&canvas); |
| 51 | SkGPipeWriter writer; |
| 52 | SkCanvas* pipeCanvas = writer.startRecording(&pipeController); |
scroggo@google.com | d5d158b | 2012-08-14 20:38:28 +0000 | [diff] [blame] | 53 | testDrawingBadBitmap(pipeCanvas); |
scroggo@google.com | 10dccde | 2012-08-08 20:43:22 +0000 | [diff] [blame] | 54 | writer.endRecording(); |
scroggo@google.com | d5d158b | 2012-08-14 20:38:28 +0000 | [diff] [blame] | 55 | |
| 56 | testDrawingAfterEndRecording(&canvas); |
scroggo@google.com | 10dccde | 2012-08-08 20:43:22 +0000 | [diff] [blame] | 57 | } |