OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 "SkCanvas.h" |
9 #include "SkGradientShader.h" | 9 #include "SkGradientShader.h" |
10 #include "SkPaintImageFilter.h" | 10 #include "SkPaintImageFilter.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 | 23 |
24 paintResult.allocN32Pixels(w, h); | 24 paintResult.allocN32Pixels(w, h); |
25 SkCanvas canvasPaint(paintResult); | 25 SkCanvas canvasPaint(paintResult); |
26 canvasPaint.clear(0x00000000); | 26 canvasPaint.clear(0x00000000); |
27 | 27 |
28 SkPoint center = SkPoint::Make(SkIntToScalar(5), SkIntToScalar(5)); | 28 SkPoint center = SkPoint::Make(SkIntToScalar(5), SkIntToScalar(5)); |
29 SkColor colors[] = {SK_ColorBLUE, SK_ColorRED, SK_ColorGREEN}; | 29 SkColor colors[] = {SK_ColorBLUE, SK_ColorRED, SK_ColorGREEN}; |
30 SkScalar pos[] = {0, SK_ScalarHalf, SK_Scalar1}; | 30 SkScalar pos[] = {0, SK_ScalarHalf, SK_Scalar1}; |
31 SkScalar radius = SkIntToScalar(5); | 31 SkScalar radius = SkIntToScalar(5); |
32 | 32 |
33 SkAutoTUnref<SkShader> s(SkGradientShader::CreateRadial( | 33 SkPaint gradientPaint; |
| 34 gradientPaint.setShader(SkGradientShader::MakeRadial( |
34 center, radius, colors, pos, SK_ARRAY_COUNT(colors), SkShader::kClamp_Ti
leMode)); | 35 center, radius, colors, pos, SK_ARRAY_COUNT(colors), SkShader::kClamp_Ti
leMode)); |
35 SkPaint gradientPaint; | |
36 gradientPaint.setShader(s); | |
37 | 36 |
38 // Test using the image filter | 37 // Test using the image filter |
39 { | 38 { |
40 SkPaint paint; | 39 SkPaint paint; |
41 SkImageFilter::CropRect cr(r); | 40 SkImageFilter::CropRect cr(r); |
42 paint.setImageFilter(SkPaintImageFilter::Create(gradientPaint, &cr))->un
ref(); | 41 paint.setImageFilter(SkPaintImageFilter::Create(gradientPaint, &cr))->un
ref(); |
43 canvasFilter.drawRect(r, paint); | 42 canvasFilter.drawRect(r, paint); |
44 } | 43 } |
45 | 44 |
46 // Test using the paint directly | 45 // Test using the paint directly |
(...skipping 23 matching lines...) Expand all Loading... |
70 | 69 |
71 paintResult.allocN32Pixels(w, h); | 70 paintResult.allocN32Pixels(w, h); |
72 SkCanvas canvasPaint(paintResult); | 71 SkCanvas canvasPaint(paintResult); |
73 canvasPaint.clear(0x00000000); | 72 canvasPaint.clear(0x00000000); |
74 | 73 |
75 SkPoint center = SkPoint::Make(SkIntToScalar(5), SkIntToScalar(5)); | 74 SkPoint center = SkPoint::Make(SkIntToScalar(5), SkIntToScalar(5)); |
76 SkColor colors[] = {SK_ColorBLUE, SK_ColorRED, SK_ColorGREEN}; | 75 SkColor colors[] = {SK_ColorBLUE, SK_ColorRED, SK_ColorGREEN}; |
77 SkScalar pos[] = {0, SK_ScalarHalf, SK_Scalar1}; | 76 SkScalar pos[] = {0, SK_ScalarHalf, SK_Scalar1}; |
78 SkScalar radius = SkIntToScalar(5); | 77 SkScalar radius = SkIntToScalar(5); |
79 | 78 |
80 SkAutoTUnref<SkShader> s(SkGradientShader::CreateRadial( | 79 SkPaint gradientPaint; |
| 80 gradientPaint.setShader(SkGradientShader::MakeRadial( |
81 center, radius, colors, pos, SK_ARRAY_COUNT(colors), SkShader::kClamp_Ti
leMode)); | 81 center, radius, colors, pos, SK_ARRAY_COUNT(colors), SkShader::kClamp_Ti
leMode)); |
82 SkPaint gradientPaint; | |
83 gradientPaint.setShader(s); | |
84 | 82 |
85 // Test using the image filter | 83 // Test using the image filter |
86 { | 84 { |
87 SkPaint paint; | 85 SkPaint paint; |
88 SkImageFilter::CropRect cr(r); | 86 SkImageFilter::CropRect cr(r); |
89 paint.setImageFilter(SkPaintImageFilter::Create(gradientPaint, &cr))->un
ref(); | 87 paint.setImageFilter(SkPaintImageFilter::Create(gradientPaint, &cr))->un
ref(); |
90 canvasFilter.scale(SkIntToScalar(2), SkIntToScalar(2)); | 88 canvasFilter.scale(SkIntToScalar(2), SkIntToScalar(2)); |
91 canvasFilter.drawRect(r, paint); | 89 canvasFilter.drawRect(r, paint); |
92 } | 90 } |
93 | 91 |
(...skipping 10 matching lines...) Expand all Loading... |
104 for (int x = 0; x < r.width(); ++x, ++filterPtr, ++paintPtr) { | 102 for (int x = 0; x < r.width(); ++x, ++filterPtr, ++paintPtr) { |
105 REPORTER_ASSERT(reporter, *filterPtr == *paintPtr); | 103 REPORTER_ASSERT(reporter, *filterPtr == *paintPtr); |
106 } | 104 } |
107 } | 105 } |
108 } | 106 } |
109 | 107 |
110 DEF_TEST(PaintImageFilter, reporter) { | 108 DEF_TEST(PaintImageFilter, reporter) { |
111 test_unscaled(reporter); | 109 test_unscaled(reporter); |
112 test_scaled(reporter); | 110 test_scaled(reporter); |
113 } | 111 } |
OLD | NEW |