OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright 2011 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 "SkCanvas.h" | |
9 #include "SkGradientShader.h" | |
10 #include "SkRectShaderImageFilter.h" | |
11 #include "SkShader.h" | |
12 #include "Test.h" | |
13 | |
14 DEF_TEST(ShaderImageFilter, reporter) { | |
15 int w = 10, h = 10; | |
16 SkRect r = SkRect::MakeWH(SkIntToScalar(w), SkIntToScalar(h)); // Make small
10x10 gradient | |
17 | |
18 SkBitmap filterResult, shaderResult; | |
19 | |
20 filterResult.allocN32Pixels(w, h); | |
21 SkCanvas canvasFilter(filterResult); | |
22 canvasFilter.clear(0x00000000); | |
23 | |
24 shaderResult.allocN32Pixels(w, h); | |
25 SkCanvas canvasShader(shaderResult); | |
26 canvasShader.clear(0x00000000); | |
27 | |
28 SkPoint center = SkPoint::Make(SkIntToScalar(5), SkIntToScalar(5)); | |
29 SkColor colors[] = {SK_ColorBLUE, SK_ColorRED, SK_ColorGREEN}; | |
30 SkScalar pos[] = {0, SK_ScalarHalf, SK_Scalar1}; | |
31 SkScalar radius = SkIntToScalar(5); | |
32 | |
33 // Test using the image filter | |
34 { | |
35 SkShader* s = SkGradientShader::CreateRadial( | |
36 center, radius, colors, pos, SK_ARRAY_COUNT(colors), SkShader::kClam
p_TileMode); | |
37 SkPaint paint; | |
38 SkImageFilter::CropRect cr(r); | |
39 paint.setImageFilter(SkRectShaderImageFilter::Create(s, &cr))->unref(); | |
40 canvasFilter.drawRect(r, paint); | |
41 s->unref(); | |
42 } | |
43 | |
44 // Test using the shader directly | |
45 { | |
46 SkShader* s = SkGradientShader::CreateRadial( | |
47 center, radius, colors, pos, SK_ARRAY_COUNT(colors), SkShader::kClam
p_TileMode); | |
48 SkPaint paint; | |
49 paint.setShader(s)->unref(); | |
50 canvasShader.drawRect(r, paint); | |
51 } | |
52 | |
53 // Assert that both paths yielded the same result | |
54 for (int y = 0; y < r.height(); ++y) { | |
55 const SkPMColor* filterPtr = filterResult.getAddr32(0, y); | |
56 const SkPMColor* shaderPtr = shaderResult.getAddr32(0, y); | |
57 for (int x = 0; x < r.width(); ++x, ++filterPtr, ++shaderPtr) { | |
58 REPORTER_ASSERT(reporter, *filterPtr == *shaderPtr); | |
59 } | |
60 } | |
61 } | |
OLD | NEW |