scroggo@google.com | 10dccde | 2012-08-08 20:43:22 +0000 | [diff] [blame] | 1 | |
| 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.com | d5d158b | 2012-08-14 20:38:28 +0000 | [diff] [blame] | 13 | #include "SkPaint.h" |
| 14 | #include "SkShader.h" |
scroggo@google.com | 10dccde | 2012-08-08 20:43:22 +0000 | [diff] [blame] | 15 | #include "Test.h" |
| 16 | |
| 17 | // Ensures that the pipe gracefully handles drawing an invalid bitmap. |
scroggo@google.com | d5d158b | 2012-08-14 20:38:28 +0000 | [diff] [blame] | 18 | static void testDrawingBadBitmap(SkCanvas* pipeCanvas) { |
scroggo@google.com | 10dccde | 2012-08-08 20:43:22 +0000 | [diff] [blame] | 19 | SkBitmap badBitmap; |
| 20 | badBitmap.setConfig(SkBitmap::kNo_Config, 5, 5); |
| 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; |
| 33 | bm.setConfig(SkBitmap::kARGB_8888_Config, 2, 2); |
| 34 | bm.allocPixels(); |
| 35 | bm.eraseColor(0); |
| 36 | |
| 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 | |
| 46 | static void test_pipeTests(skiatest::Reporter*) { |
scroggo@google.com | 10dccde | 2012-08-08 20:43:22 +0000 | [diff] [blame] | 47 | 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.com | d5d158b | 2012-08-14 20:38:28 +0000 | [diff] [blame] | 54 | testDrawingBadBitmap(pipeCanvas); |
scroggo@google.com | 10dccde | 2012-08-08 20:43:22 +0000 | [diff] [blame] | 55 | writer.endRecording(); |
scroggo@google.com | d5d158b | 2012-08-14 20:38:28 +0000 | [diff] [blame] | 56 | |
| 57 | testDrawingAfterEndRecording(&canvas); |
scroggo@google.com | 10dccde | 2012-08-08 20:43:22 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | #include "TestClassDef.h" |
| 61 | DEFINE_TESTCLASS("PipeTest", PipeTestClass, test_pipeTests) |