OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "SkColorShader.h" | 8 #include "SkColorShader.h" |
9 #include "SkGradientShader.h" | 9 #include "SkGradientShader.h" |
10 #include "SkShader.h" | 10 #include "SkShader.h" |
11 #include "Test.h" | 11 #include "Test.h" |
12 | 12 |
13 static void test_bitmap(skiatest::Reporter* reporter) { | 13 static void test_bitmap(skiatest::Reporter* reporter) { |
| 14 SkImageInfo info = SkImageInfo::MakeN32Premul(2, 2); |
| 15 |
14 SkBitmap bmp; | 16 SkBitmap bmp; |
15 bmp.setConfig(SkBitmap::kARGB_8888_Config, 2, 2); | 17 bmp.setConfig(info); |
16 | 18 |
17 // test 1: bitmap without pixel data | 19 // test 1: bitmap without pixel data |
18 SkShader* shader = SkShader::CreateBitmapShader(bmp, | 20 SkShader* shader = SkShader::CreateBitmapShader(bmp, |
19 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode); | 21 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode); |
20 REPORTER_ASSERT(reporter, shader); | 22 REPORTER_ASSERT(reporter, shader); |
21 REPORTER_ASSERT(reporter, !shader->isOpaque()); | 23 REPORTER_ASSERT(reporter, !shader->isOpaque()); |
22 shader->unref(); | 24 shader->unref(); |
23 | 25 |
24 // From this point on, we have pixels | 26 // From this point on, we have pixels |
25 bmp.allocPixels(); | 27 bmp.allocPixels(info); |
26 | 28 |
27 // test 2: not opaque by default | 29 // test 2: not opaque by default |
28 shader = SkShader::CreateBitmapShader(bmp, | 30 shader = SkShader::CreateBitmapShader(bmp, |
29 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode); | 31 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode); |
30 REPORTER_ASSERT(reporter, shader); | 32 REPORTER_ASSERT(reporter, shader); |
31 REPORTER_ASSERT(reporter, !shader->isOpaque()); | 33 REPORTER_ASSERT(reporter, !shader->isOpaque()); |
32 shader->unref(); | 34 shader->unref(); |
33 | 35 |
34 // test 3: explicitly opaque | 36 // test 3: explicitly opaque |
35 bmp.setAlphaType(kOpaque_SkAlphaType); | 37 bmp.setAlphaType(kOpaque_SkAlphaType); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 // since lack of opacity will depend solely on the paint | 108 // since lack of opacity will depend solely on the paint |
107 SkColorShader colorShader4; | 109 SkColorShader colorShader4; |
108 REPORTER_ASSERT(reporter, colorShader4.isOpaque()); | 110 REPORTER_ASSERT(reporter, colorShader4.isOpaque()); |
109 } | 111 } |
110 | 112 |
111 DEF_TEST(ShaderOpacity, reporter) { | 113 DEF_TEST(ShaderOpacity, reporter) { |
112 test_gradient(reporter); | 114 test_gradient(reporter); |
113 test_color(reporter); | 115 test_color(reporter); |
114 test_bitmap(reporter); | 116 test_bitmap(reporter); |
115 } | 117 } |
OLD | NEW |