OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 /* Tests text rendering with LCD and subpixel rendering turned on and off. | 9 /* Tests text rendering with LCD and subpixel rendering turned on and off. |
10 */ | 10 */ |
11 | 11 |
12 #include "gm.h" | 12 #include "gm.h" |
13 #include "SkCanvas.h" | 13 #include "SkCanvas.h" |
14 #include "SkPicture.h" | 14 #include "SkPicture.h" |
15 #include "SkPictureImageFilter.h" | 15 #include "SkPictureImageFilter.h" |
16 #include "SkPictureRecorder.h" | 16 #include "SkPictureRecorder.h" |
17 #include "SkSurface.h" | 17 #include "SkSurface.h" |
18 | 18 |
19 | 19 |
20 class LcdTextGM : public skiagm::GM { | 20 class LcdTextGM : public skiagm::GM { |
21 public: | 21 public: |
22 LcdTextGM() { | 22 LcdTextGM() { |
23 const int pointSize = 36; | 23 const int pointSize = 36; |
24 textHeight = SkIntToScalar(pointSize); | 24 textHeight = SkIntToScalar(pointSize); |
25 } | 25 } |
26 | 26 |
27 protected: | 27 protected: |
28 | 28 |
29 SkString onShortName() { | 29 SkString onShortName() { |
30 SkString name("lcdtext"); | 30 SkString name("lcdtext"); |
31 name.append(sk_tool_utils::major_platform_os_name()); | 31 name.append(sk_tool_utils::major_platform_os_name()); |
32 return name; | 32 return name; |
33 } | 33 } |
34 | 34 |
35 SkISize onISize() { return SkISize::Make(640, 480); } | 35 SkISize onISize() { return SkISize::Make(640, 480); } |
36 | 36 |
37 virtual void onDraw(SkCanvas* canvas) { | 37 virtual void onDraw(SkCanvas* canvas) { |
38 | 38 |
39 y = textHeight; | 39 y = textHeight; |
40 drawText(canvas, SkString("TEXT: SubpixelTrue LCDRenderTrue"), | 40 drawText(canvas, SkString("TEXT: SubpixelTrue LCDRenderTrue"), |
41 true, true); | 41 true, true); |
42 drawText(canvas, SkString("TEXT: SubpixelTrue LCDRenderFalse"), | 42 drawText(canvas, SkString("TEXT: SubpixelTrue LCDRenderFalse"), |
43 true, false); | 43 true, false); |
44 drawText(canvas, SkString("TEXT: SubpixelFalse LCDRenderTrue"), | 44 drawText(canvas, SkString("TEXT: SubpixelFalse LCDRenderTrue"), |
45 false, true); | 45 false, true); |
46 drawText(canvas, SkString("TEXT: SubpixelFalse LCDRenderFalse"), | 46 drawText(canvas, SkString("TEXT: SubpixelFalse LCDRenderFalse"), |
47 false, false); | 47 false, false); |
48 } | 48 } |
49 | 49 |
50 void drawText(SkCanvas* canvas, const SkString& string, | 50 void drawText(SkCanvas* canvas, const SkString& string, |
51 bool subpixelTextEnabled, bool lcdRenderTextEnabled) { | 51 bool subpixelTextEnabled, bool lcdRenderTextEnabled) { |
52 SkPaint paint; | 52 SkPaint paint; |
53 paint.setColor(SK_ColorBLACK); | 53 paint.setColor(SK_ColorBLACK); |
54 paint.setDither(true); | 54 paint.setDither(true); |
55 paint.setAntiAlias(true); | 55 paint.setAntiAlias(true); |
56 paint.setSubpixelText(subpixelTextEnabled); | 56 paint.setSubpixelText(subpixelTextEnabled); |
57 paint.setLCDRenderText(lcdRenderTextEnabled); | 57 paint.setLCDRenderText(lcdRenderTextEnabled); |
58 paint.setTextSize(textHeight); | 58 paint.setTextSize(textHeight); |
59 | 59 |
60 canvas->drawText(string.c_str(), string.size(), 0, y, paint); | 60 canvas->drawText(string.c_str(), string.size(), 0, y, paint); |
61 y += textHeight; | 61 y += textHeight; |
62 } | 62 } |
63 | 63 |
64 private: | 64 private: |
65 typedef skiagm::GM INHERITED; | 65 typedef skiagm::GM INHERITED; |
66 SkScalar y, textHeight; | 66 SkScalar y, textHeight; |
67 }; | 67 }; |
68 | 68 |
69 /* | 69 /* |
70 * Skia will automatically disable LCD requests if the total size exceeds some
limit | 70 * Skia will automatically disable LCD requests if the total size exceeds some
limit |
71 * (hard coded in this test for now, as it is now avaiable as an API) | 71 * (hard coded in this test for now, as it is now avaiable as an API) |
72 * | 72 * |
73 * Test this both by changing "textsize" and by changing the computed size (tex
tsize * CTM) | 73 * Test this both by changing "textsize" and by changing the computed size (tex
tsize * CTM) |
74 */ | 74 */ |
75 class LcdTextSizeGM : public skiagm::GM { | 75 class LcdTextSizeGM : public skiagm::GM { |
76 enum { | 76 enum { |
77 kLCDTextSizeLimit = 48 | 77 kLCDTextSizeLimit = 48 |
78 }; | 78 }; |
79 | 79 |
80 static void ScaleAbout(SkCanvas* canvas, SkScalar sx, SkScalar sy, SkScalar
px, SkScalar py) { | 80 static void ScaleAbout(SkCanvas* canvas, SkScalar sx, SkScalar sy, SkScalar
px, SkScalar py) { |
81 SkMatrix m; | 81 SkMatrix m; |
82 m.setScale(sx, sy, px, py); | 82 m.setScale(sx, sy, px, py); |
83 canvas->concat(m); | 83 canvas->concat(m); |
84 } | 84 } |
85 | 85 |
86 public: | 86 public: |
87 LcdTextSizeGM() {} | 87 LcdTextSizeGM() {} |
88 | 88 |
89 protected: | 89 protected: |
90 SkString onShortName() { | 90 SkString onShortName() { |
91 return SkString("lcdtextsize"); | 91 return SkString("lcdtextsize"); |
92 } | 92 } |
93 | 93 |
94 SkISize onISize() { return SkISize::Make(320, 120); } | 94 SkISize onISize() { return SkISize::Make(320, 120); } |
95 | 95 |
96 virtual void onDraw(SkCanvas* canvas) { | 96 virtual void onDraw(SkCanvas* canvas) { |
97 const char* lcd_text = "LCD"; | 97 const char* lcd_text = "LCD"; |
98 const char* gray_text = "GRAY"; | 98 const char* gray_text = "GRAY"; |
99 | 99 |
100 SkPaint paint; | 100 SkPaint paint; |
101 paint.setAntiAlias(true); | 101 paint.setAntiAlias(true); |
102 paint.setLCDRenderText(true); | 102 paint.setLCDRenderText(true); |
103 | 103 |
104 const struct { | 104 const struct { |
105 SkPoint fLoc; | 105 SkPoint fLoc; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 | 155 |
156 SkPaint p; | 156 SkPaint p; |
157 p.setColor(0xFFCCCCCC); | 157 p.setColor(0xFFCCCCCC); |
158 canvas->drawRect(SkRect::MakeLTRB(25, 70, 200, 100), p); | 158 canvas->drawRect(SkRect::MakeLTRB(25, 70, 200, 100), p); |
159 canvas->drawText("Hamburgefons", 12, 30, 90, paint); | 159 canvas->drawText("Hamburgefons", 12, 30, 90, paint); |
160 | 160 |
161 canvas->restore(); | 161 canvas->restore(); |
162 canvas->translate(0, 80); | 162 canvas->translate(0, 80); |
163 } | 163 } |
164 } | 164 } |
OLD | NEW |