commit-bot@chromium.org | 855e88e | 2014-04-21 19:33:12 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 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 | |
mtklein | cfa90a1 | 2015-05-18 13:44:35 -0700 | [diff] [blame] | 8 | #include "SkCanvas.h" |
commit-bot@chromium.org | 855e88e | 2014-04-21 19:33:12 +0000 | [diff] [blame] | 9 | #include "SkPicture.h" |
| 10 | #include "SkPictureRecorder.h" |
| 11 | #include "SkShader.h" |
| 12 | #include "Test.h" |
| 13 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 14 | // Test that attempting to create a picture shader with a nullptr picture or |
mtklein | cfa90a1 | 2015-05-18 13:44:35 -0700 | [diff] [blame] | 15 | // empty picture returns a shader that draws nothing. |
commit-bot@chromium.org | 855e88e | 2014-04-21 19:33:12 +0000 | [diff] [blame] | 16 | DEF_TEST(PictureShader_empty, reporter) { |
mtklein | cfa90a1 | 2015-05-18 13:44:35 -0700 | [diff] [blame] | 17 | SkPaint paint; |
| 18 | |
| 19 | SkBitmap bitmap; |
| 20 | bitmap.allocN32Pixels(1,1); |
| 21 | |
| 22 | SkCanvas canvas(bitmap); |
| 23 | canvas.clear(SK_ColorGREEN); |
| 24 | |
reed | 1a9b964 | 2016-03-13 14:13:58 -0700 | [diff] [blame^] | 25 | paint.setShader(SkShader::MakePictureShader( |
| 26 | nullptr, SkShader::kClamp_TileMode, SkShader::kClamp_TileMode, nullptr, nullptr)); |
mtklein | cfa90a1 | 2015-05-18 13:44:35 -0700 | [diff] [blame] | 27 | |
| 28 | canvas.drawRect(SkRect::MakeWH(1,1), paint); |
| 29 | REPORTER_ASSERT(reporter, *bitmap.getAddr32(0,0) == SK_ColorGREEN); |
| 30 | |
commit-bot@chromium.org | 855e88e | 2014-04-21 19:33:12 +0000 | [diff] [blame] | 31 | |
| 32 | SkPictureRecorder factory; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 33 | factory.beginRecording(0, 0, nullptr, 0); |
reed | 1a9b964 | 2016-03-13 14:13:58 -0700 | [diff] [blame^] | 34 | sk_sp<SkPicture> picture(factory.endRecording()); |
| 35 | paint.setShader(SkShader::MakePictureShader(std::move(picture), SkShader::kClamp_TileMode, |
| 36 | SkShader::kClamp_TileMode, nullptr, nullptr)); |
mtklein | cfa90a1 | 2015-05-18 13:44:35 -0700 | [diff] [blame] | 37 | |
| 38 | canvas.drawRect(SkRect::MakeWH(1,1), paint); |
| 39 | REPORTER_ASSERT(reporter, *bitmap.getAddr32(0,0) == SK_ColorGREEN); |
commit-bot@chromium.org | 855e88e | 2014-04-21 19:33:12 +0000 | [diff] [blame] | 40 | } |