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 |
(...skipping 13 matching lines...) Expand all Loading... |
33 return SkGradientShader::MakeLinear(pts, colors, nullptr, SK_ARRAY_COUNT(col
ors), | 33 return SkGradientShader::MakeLinear(pts, colors, nullptr, SK_ARRAY_COUNT(col
ors), |
34 SkShader::kRepeat_TileMode); | 34 SkShader::kRepeat_TileMode); |
35 } | 35 } |
36 | 36 |
37 class LcdBlendGM : public skiagm::GM { | 37 class LcdBlendGM : public skiagm::GM { |
38 public: | 38 public: |
39 LcdBlendGM() { | 39 LcdBlendGM() { |
40 const int kPointSize = 25; | 40 const int kPointSize = 25; |
41 fTextHeight = SkIntToScalar(kPointSize); | 41 fTextHeight = SkIntToScalar(kPointSize); |
42 } | 42 } |
43 | 43 |
44 protected: | 44 protected: |
45 SkString onShortName() override { | 45 SkString onShortName() override { |
46 return SkString("lcdblendmodes"); | 46 return SkString("lcdblendmodes"); |
47 } | 47 } |
48 | 48 |
49 void onOnceBeforeDraw() override { | 49 void onOnceBeforeDraw() override { |
50 fCheckerboard = sk_tool_utils::create_checkerboard_shader(SK_ColorBLACK,
SK_ColorWHITE, 4); | 50 fCheckerboard = sk_tool_utils::create_checkerboard_shader(SK_ColorBLACK,
SK_ColorWHITE, 4); |
51 } | 51 } |
52 | 52 |
53 SkISize onISize() override { return SkISize::Make(kWidth, kHeight); } | 53 SkISize onISize() override { return SkISize::Make(kWidth, kHeight); } |
54 | 54 |
55 void onDraw(SkCanvas* canvas) override { | 55 void onDraw(SkCanvas* canvas) override { |
56 SkPaint p; | 56 SkPaint p; |
57 p.setAntiAlias(false); | 57 p.setAntiAlias(false); |
58 p.setStyle(SkPaint::kFill_Style); | 58 p.setStyle(SkPaint::kFill_Style); |
59 p.setShader(fCheckerboard); | 59 p.setShader(fCheckerboard); |
60 SkRect r = SkRect::MakeWH(SkIntToScalar(kWidth), SkIntToScalar(kHeight))
; | 60 SkRect r = SkRect::MakeWH(SkIntToScalar(kWidth), SkIntToScalar(kHeight))
; |
61 canvas->drawRect(r, p); | 61 canvas->drawRect(r, p); |
62 | 62 |
63 SkImageInfo info = SkImageInfo::MakeN32Premul(kWidth, kHeight); | 63 SkImageInfo info = SkImageInfo::MakeN32Premul(kWidth, kHeight); |
64 auto surface(canvas->makeSurface(info)); | 64 auto surface(canvas->makeSurface(info)); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 if (useGrad) { | 135 if (useGrad) { |
136 SkRect r; | 136 SkRect r; |
137 r.setXYWH(0, y - fTextHeight, SkIntToScalar(kColWidth), fTextHei
ght); | 137 r.setXYWH(0, y - fTextHeight, SkIntToScalar(kColWidth), fTextHei
ght); |
138 paint.setShader(make_shader(r)); | 138 paint.setShader(make_shader(r)); |
139 } | 139 } |
140 SkString string(gModes[m].fLabel); | 140 SkString string(gModes[m].fLabel); |
141 canvas->drawText(gModes[m].fLabel, string.size(), 0, y, paint); | 141 canvas->drawText(gModes[m].fLabel, string.size(), 0, y, paint); |
142 y+=fTextHeight; | 142 y+=fTextHeight; |
143 } | 143 } |
144 } | 144 } |
145 | 145 |
146 private: | 146 private: |
147 SkScalar fTextHeight; | 147 SkScalar fTextHeight; |
148 sk_sp<SkShader> fCheckerboard; | 148 sk_sp<SkShader> fCheckerboard; |
149 typedef skiagm::GM INHERITED; | 149 typedef skiagm::GM INHERITED; |
150 }; | 150 }; |
151 | 151 |
152 ////////////////////////////////////////////////////////////////////////////// | 152 ////////////////////////////////////////////////////////////////////////////// |
153 | 153 |
154 DEF_GM( return new LcdBlendGM; ) | 154 DEF_GM( return new LcdBlendGM; ) |
155 } | 155 } |
OLD | NEW |