OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "gm.h" | 8 #include "gm.h" |
9 | 9 |
10 #include "Sk2DPathEffect.h" | 10 #include "Sk2DPathEffect.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 static const int kWidth = 1250; | 23 static const int kWidth = 1250; |
24 static const int kHeight = 700; | 24 static const int kHeight = 700; |
25 | 25 |
26 // Unlike the variant in sk_tool_utils, this version positions the glyphs on a d
iagonal | 26 // Unlike the variant in sk_tool_utils, this version positions the glyphs on a d
iagonal |
27 static void add_to_text_blob(SkTextBlobBuilder* builder, const char* text, const
SkPaint& origPaint, | 27 static void add_to_text_blob(SkTextBlobBuilder* builder, const char* text, const
SkPaint& origPaint, |
28 SkScalar x, SkScalar y) { | 28 SkScalar x, SkScalar y) { |
29 SkPaint paint(origPaint); | 29 SkPaint paint(origPaint); |
30 SkTDArray<uint16_t> glyphs; | 30 SkTDArray<uint16_t> glyphs; |
31 | 31 |
32 size_t len = strlen(text); | 32 size_t len = strlen(text); |
33 glyphs.append(paint.textToGlyphs(text, len, NULL)); | 33 glyphs.append(paint.textToGlyphs(text, len, nullptr)); |
34 paint.textToGlyphs(text, len, glyphs.begin()); | 34 paint.textToGlyphs(text, len, glyphs.begin()); |
35 | 35 |
36 const SkScalar advanceX = paint.getTextSize() * 0.85f; | 36 const SkScalar advanceX = paint.getTextSize() * 0.85f; |
37 const SkScalar advanceY = paint.getTextSize() * 1.5f; | 37 const SkScalar advanceY = paint.getTextSize() * 1.5f; |
38 | 38 |
39 SkTDArray<SkScalar> pos; | 39 SkTDArray<SkScalar> pos; |
40 for (unsigned i = 0; i < len; ++i) { | 40 for (unsigned i = 0; i < len; ++i) { |
41 *pos.append() = x + i * advanceX; | 41 *pos.append() = x + i * advanceX; |
42 *pos.append() = y + i * (advanceY / len); | 42 *pos.append() = y + i * (advanceY / len); |
43 } | 43 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 static SkShader* make_shader(const SkRect& bounds) { | 83 static SkShader* make_shader(const SkRect& bounds) { |
84 const SkPoint pts[] = { | 84 const SkPoint pts[] = { |
85 { bounds.left(), bounds.top() }, | 85 { bounds.left(), bounds.top() }, |
86 { bounds.right(), bounds.bottom() }, | 86 { bounds.right(), bounds.bottom() }, |
87 }; | 87 }; |
88 const SkColor colors[] = { | 88 const SkColor colors[] = { |
89 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorBLACK, | 89 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorBLACK, |
90 SK_ColorCYAN, SK_ColorMAGENTA, SK_ColorYELLOW, | 90 SK_ColorCYAN, SK_ColorMAGENTA, SK_ColorYELLOW, |
91 }; | 91 }; |
92 return SkGradientShader::CreateLinear(pts, | 92 return SkGradientShader::CreateLinear(pts, |
93 colors, NULL, SK_ARRAY_COUNT(colors), | 93 colors, nullptr, SK_ARRAY_COUNT(colors
), |
94 SkShader::kClamp_TileMode); | 94 SkShader::kClamp_TileMode); |
95 } | 95 } |
96 | 96 |
97 static void color_filter(SkPaint* paint) { | 97 static void color_filter(SkPaint* paint) { |
98 SkRect r; | 98 SkRect r; |
99 r.setWH(SkIntToScalar(kWidth), 50); | 99 r.setWH(SkIntToScalar(kWidth), 50); |
100 paint->setShader(make_shader(r))->unref(); | 100 paint->setShader(make_shader(r))->unref(); |
101 paint->setColorFilter(SkColorFilter::CreateLightingFilter(0xF0F0F0, 0))->unr
ef(); | 101 paint->setColorFilter(SkColorFilter::CreateLightingFilter(0xF0F0F0, 0))->unr
ef(); |
102 } | 102 } |
103 | 103 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 SkLayerDrawLooper::kXfermode_Bit,
&path_effect, | 195 SkLayerDrawLooper::kXfermode_Bit,
&path_effect, |
196 looperSandwhich, SK_ARRAY_COUNT(l
ooperSandwhich))); | 196 looperSandwhich, SK_ARRAY_COUNT(l
ooperSandwhich))); |
197 fLoopers.push_back().reset(setupLooper(SkLayerDrawLooper::kShader_Bit | | 197 fLoopers.push_back().reset(setupLooper(SkLayerDrawLooper::kShader_Bit | |
198 SkLayerDrawLooper::kColorFilter_B
it | | 198 SkLayerDrawLooper::kColorFilter_B
it | |
199 SkLayerDrawLooper::kXfermode_Bit,
&color_filter, | 199 SkLayerDrawLooper::kXfermode_Bit,
&color_filter, |
200 looperSandwhich, SK_ARRAY_COUNT(l
ooperSandwhich))); | 200 looperSandwhich, SK_ARRAY_COUNT(l
ooperSandwhich))); |
201 fLoopers.push_back().reset(setupLooper(SkLayerDrawLooper::kShader_Bit | | 201 fLoopers.push_back().reset(setupLooper(SkLayerDrawLooper::kShader_Bit | |
202 SkLayerDrawLooper::kColorFilter_B
it | | 202 SkLayerDrawLooper::kColorFilter_B
it | |
203 SkLayerDrawLooper::kXfermode_Bit,
&color_filter, | 203 SkLayerDrawLooper::kXfermode_Bit,
&color_filter, |
204 xfermode, SK_ARRAY_COUNT(xfermode
))); | 204 xfermode, SK_ARRAY_COUNT(xfermode
))); |
205 fLoopers.push_back().reset(setupLooper(0, NULL, skew, SK_ARRAY_COUNT(ske
w))); | 205 fLoopers.push_back().reset(setupLooper(0, nullptr, skew, SK_ARRAY_COUNT(
skew))); |
206 fLoopers.push_back().reset(setupLooper(SkLayerDrawLooper::kMaskFilter_Bi
t | | 206 fLoopers.push_back().reset(setupLooper(SkLayerDrawLooper::kMaskFilter_Bi
t | |
207 SkLayerDrawLooper::kShader_Bit | | 207 SkLayerDrawLooper::kShader_Bit | |
208 SkLayerDrawLooper::kColorFilter_B
it | | 208 SkLayerDrawLooper::kColorFilter_B
it | |
209 SkLayerDrawLooper::kPathEffect_Bi
t | | 209 SkLayerDrawLooper::kPathEffect_Bi
t | |
210 SkLayerDrawLooper::kStyle_Bit | | 210 SkLayerDrawLooper::kStyle_Bit | |
211 SkLayerDrawLooper::kXfermode_Bit,
&kitchen_sink, | 211 SkLayerDrawLooper::kXfermode_Bit,
&kitchen_sink, |
212 kitchenSink, SK_ARRAY_COUNT(kitch
enSink))); | 212 kitchenSink, SK_ARRAY_COUNT(kitch
enSink))); |
213 | 213 |
214 // Test we respect overrides | 214 // Test we respect overrides |
215 fLoopers.push_back().reset(setupLooper(0, &kitchen_sink, | 215 fLoopers.push_back().reset(setupLooper(0, &kitchen_sink, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 SkAutoTUnref<const SkTextBlob> fBlob; | 250 SkAutoTUnref<const SkTextBlob> fBlob; |
251 SkTArray<SkAutoTUnref<SkLayerDrawLooper>, true> fLoopers; | 251 SkTArray<SkAutoTUnref<SkLayerDrawLooper>, true> fLoopers; |
252 | 252 |
253 typedef GM INHERITED; | 253 typedef GM INHERITED; |
254 }; | 254 }; |
255 | 255 |
256 ////////////////////////////////////////////////////////////////////////////// | 256 ////////////////////////////////////////////////////////////////////////////// |
257 | 257 |
258 DEF_GM(return new TextBlobLooperGM;) | 258 DEF_GM(return new TextBlobLooperGM;) |
259 } | 259 } |
OLD | NEW |