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; |
commit-bot@chromium.org | a3264e5 | 2014-05-30 13:26:10 +0000 | [diff] [blame] | 19 | badBitmap.setInfo(SkImageInfo::MakeUnknown(5, 5)); |
scroggo@google.com | 10dccde | 2012-08-08 20:43:22 +0000 | [diff] [blame] | 20 | pipeCanvas->drawBitmap(badBitmap, 0, 0); |
| 21 | } |
| 22 | |
scroggo@google.com | d5d158b | 2012-08-14 20:38:28 +0000 | [diff] [blame] | 23 | // Ensure that pipe gracefully handles attempting to draw after endRecording is called on the |
| 24 | // SkGPipeWriter. |
| 25 | static void testDrawingAfterEndRecording(SkCanvas* canvas) { |
| 26 | PipeController pc(canvas); |
| 27 | SkGPipeWriter writer; |
| 28 | SkCanvas* pipeCanvas = writer.startRecording(&pc, SkGPipeWriter::kCrossProcess_Flag); |
| 29 | writer.endRecording(); |
| 30 | |
| 31 | SkBitmap bm; |
mike@reedtribe.org | deee496 | 2014-02-13 14:41:43 +0000 | [diff] [blame] | 32 | bm.allocN32Pixels(2, 2); |
junov@google.com | dbfac8a | 2012-12-06 21:47:40 +0000 | [diff] [blame] | 33 | bm.eraseColor(SK_ColorTRANSPARENT); |
scroggo@google.com | d5d158b | 2012-08-14 20:38:28 +0000 | [diff] [blame] | 34 | |
| 35 | SkShader* shader = SkShader::CreateBitmapShader(bm, SkShader::kClamp_TileMode, |
| 36 | SkShader::kClamp_TileMode); |
| 37 | SkPaint paint; |
| 38 | paint.setShader(shader)->unref(); |
| 39 | pipeCanvas->drawPaint(paint); |
| 40 | |
| 41 | pipeCanvas->drawBitmap(bm, 0, 0); |
| 42 | } |
| 43 | |
tfarina@chromium.org | e4fafb1 | 2013-12-12 21:11:12 +0000 | [diff] [blame] | 44 | DEF_TEST(Pipe, reporter) { |
scroggo@google.com | 10dccde | 2012-08-08 20:43:22 +0000 | [diff] [blame] | 45 | SkBitmap bitmap; |
commit-bot@chromium.org | a3264e5 | 2014-05-30 13:26:10 +0000 | [diff] [blame] | 46 | bitmap.setInfo(SkImageInfo::MakeN32Premul(64, 64)); |
scroggo@google.com | 10dccde | 2012-08-08 20:43:22 +0000 | [diff] [blame] | 47 | SkCanvas canvas(bitmap); |
| 48 | |
| 49 | PipeController pipeController(&canvas); |
| 50 | SkGPipeWriter writer; |
| 51 | SkCanvas* pipeCanvas = writer.startRecording(&pipeController); |
scroggo@google.com | d5d158b | 2012-08-14 20:38:28 +0000 | [diff] [blame] | 52 | testDrawingBadBitmap(pipeCanvas); |
scroggo@google.com | 10dccde | 2012-08-08 20:43:22 +0000 | [diff] [blame] | 53 | writer.endRecording(); |
scroggo@google.com | d5d158b | 2012-08-14 20:38:28 +0000 | [diff] [blame] | 54 | |
| 55 | testDrawingAfterEndRecording(&canvas); |
scroggo@google.com | 10dccde | 2012-08-08 20:43:22 +0000 | [diff] [blame] | 56 | } |