OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
| 8 #include "SkCanvas.h" |
8 #include "SkPicture.h" | 9 #include "SkPicture.h" |
9 #include "SkPictureRecorder.h" | 10 #include "SkPictureRecorder.h" |
10 #include "SkShader.h" | 11 #include "SkShader.h" |
11 #include "Test.h" | 12 #include "Test.h" |
12 | 13 |
13 // Test that attempting to create a picture shader with a NULL picture or | 14 // Test that attempting to create a picture shader with a NULL picture or |
14 // empty picture returns NULL. | 15 // empty picture returns a shader that draws nothing. |
15 DEF_TEST(PictureShader_empty, reporter) { | 16 DEF_TEST(PictureShader_empty, reporter) { |
16 SkShader* shader = SkShader::CreatePictureShader(NULL, | 17 SkPaint paint; |
17 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode, NULL, NULL); | 18 |
18 REPORTER_ASSERT(reporter, NULL == shader); | 19 SkBitmap bitmap; |
| 20 bitmap.allocN32Pixels(1,1); |
| 21 |
| 22 SkCanvas canvas(bitmap); |
| 23 canvas.clear(SK_ColorGREEN); |
| 24 |
| 25 SkShader* shader = SkShader::CreatePictureShader( |
| 26 NULL, SkShader::kClamp_TileMode, SkShader::kClamp_TileMode, NULL, NU
LL); |
| 27 paint.setShader(shader)->unref(); |
| 28 |
| 29 canvas.drawRect(SkRect::MakeWH(1,1), paint); |
| 30 REPORTER_ASSERT(reporter, *bitmap.getAddr32(0,0) == SK_ColorGREEN); |
| 31 |
19 | 32 |
20 SkPictureRecorder factory; | 33 SkPictureRecorder factory; |
21 factory.beginRecording(0, 0, NULL, 0); | 34 factory.beginRecording(0, 0, NULL, 0); |
22 SkAutoTUnref<SkPicture> picture(factory.endRecording()); | 35 SkAutoTUnref<SkPicture> picture(factory.endRecording()); |
23 shader = SkShader::CreatePictureShader(picture.get(), | 36 shader = SkShader::CreatePictureShader( |
24 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode, NULL, NULL); | 37 picture.get(), SkShader::kClamp_TileMode, SkShader::kClamp_TileMode,
NULL, NULL); |
25 REPORTER_ASSERT(reporter, NULL == shader); | 38 paint.setShader(shader)->unref(); |
| 39 |
| 40 canvas.drawRect(SkRect::MakeWH(1,1), paint); |
| 41 REPORTER_ASSERT(reporter, *bitmap.getAddr32(0,0) == SK_ColorGREEN); |
26 } | 42 } |
OLD | NEW |