OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 | 8 |
9 /* | 9 /* |
10 * Tests text rendering with LCD and the various blend modes. | 10 * Tests text rendering with LCD and the various blend modes. |
11 */ | 11 */ |
12 | 12 |
13 #include "gm.h" | 13 #include "gm.h" |
14 #include "SkCanvas.h" | 14 #include "SkCanvas.h" |
15 #include "SkGradientShader.h" | 15 #include "SkGradientShader.h" |
16 #include "SkSurface.h" | 16 #include "SkSurface.h" |
17 | 17 |
18 namespace skiagm { | 18 namespace skiagm { |
19 | 19 |
20 static const int kColWidth = 180; | 20 static const int kColWidth = 180; |
21 static const int kNumCols = 4; | 21 static const int kNumCols = 4; |
22 static const int kWidth = kColWidth * kNumCols; | 22 static const int kWidth = kColWidth * kNumCols; |
23 static const int kHeight = 750; | 23 static const int kHeight = 750; |
24 | 24 |
25 static sk_sp<SkShader> make_shader(const SkRect& bounds) { | 25 static SkShader* make_shader(const SkRect& bounds) { |
26 const SkPoint pts[] = { | 26 const SkPoint pts[] = { |
27 { bounds.left(), bounds.top() }, | 27 { bounds.left(), bounds.top() }, |
28 { bounds.right(), bounds.bottom() }, | 28 { bounds.right(), bounds.bottom() }, |
29 }; | 29 }; |
30 const SkColor colors[] = { | 30 const SkColor colors[] = { |
31 SK_ColorRED, SK_ColorGREEN, | 31 SK_ColorRED, SK_ColorGREEN, |
32 }; | 32 }; |
33 return SkGradientShader::MakeLinear(pts, colors, nullptr, SK_ARRAY_COUNT(col
ors), | 33 return SkGradientShader::CreateLinear(pts, |
34 SkShader::kRepeat_TileMode); | 34 colors, nullptr, SK_ARRAY_COUNT(colors
), |
| 35 SkShader::kRepeat_TileMode); |
35 } | 36 } |
36 | 37 |
37 class LcdBlendGM : public skiagm::GM { | 38 class LcdBlendGM : public skiagm::GM { |
38 public: | 39 public: |
39 LcdBlendGM() { | 40 LcdBlendGM() { |
40 const int kPointSize = 25; | 41 const int kPointSize = 25; |
41 fTextHeight = SkIntToScalar(kPointSize); | 42 fTextHeight = SkIntToScalar(kPointSize); |
42 } | 43 } |
43 | 44 |
44 protected: | 45 protected: |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 paint.setColor(textColor); | 129 paint.setColor(textColor); |
129 paint.setAntiAlias(true); | 130 paint.setAntiAlias(true); |
130 paint.setSubpixelText(true); | 131 paint.setSubpixelText(true); |
131 paint.setLCDRenderText(true); | 132 paint.setLCDRenderText(true); |
132 paint.setTextSize(fTextHeight); | 133 paint.setTextSize(fTextHeight); |
133 paint.setXfermode(xfermode); | 134 paint.setXfermode(xfermode); |
134 sk_tool_utils::set_portable_typeface(&paint); | 135 sk_tool_utils::set_portable_typeface(&paint); |
135 if (useGrad) { | 136 if (useGrad) { |
136 SkRect r; | 137 SkRect r; |
137 r.setXYWH(0, y - fTextHeight, SkIntToScalar(kColWidth), fTextHei
ght); | 138 r.setXYWH(0, y - fTextHeight, SkIntToScalar(kColWidth), fTextHei
ght); |
138 paint.setShader(make_shader(r)); | 139 paint.setShader(make_shader(r))->unref(); |
139 } | 140 } |
140 SkString string(gModes[m].fLabel); | 141 SkString string(gModes[m].fLabel); |
141 canvas->drawText(gModes[m].fLabel, string.size(), 0, y, paint); | 142 canvas->drawText(gModes[m].fLabel, string.size(), 0, y, paint); |
142 y+=fTextHeight; | 143 y+=fTextHeight; |
143 } | 144 } |
144 } | 145 } |
145 | 146 |
146 private: | 147 private: |
147 SkScalar fTextHeight; | 148 SkScalar fTextHeight; |
148 sk_sp<SkShader> fCheckerboard; | 149 sk_sp<SkShader> fCheckerboard; |
149 typedef skiagm::GM INHERITED; | 150 typedef skiagm::GM INHERITED; |
150 }; | 151 }; |
151 | 152 |
152 ////////////////////////////////////////////////////////////////////////////// | 153 ////////////////////////////////////////////////////////////////////////////// |
153 | 154 |
154 DEF_GM( return new LcdBlendGM; ) | 155 DEF_GM( return new LcdBlendGM; ) |
155 } | 156 } |
OLD | NEW |