OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkPath.h" | 10 #include "SkPath.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 memset(fTypefacesToUnref, 0, sizeof(fTypefacesToUnref)); | 24 memset(fTypefacesToUnref, 0, sizeof(fTypefacesToUnref)); |
25 } | 25 } |
26 | 26 |
27 ~VariedTextGM() { | 27 ~VariedTextGM() { |
28 for (size_t i = 0; i < SK_ARRAY_COUNT(fTypefacesToUnref); ++i) { | 28 for (size_t i = 0; i < SK_ARRAY_COUNT(fTypefacesToUnref); ++i) { |
29 SkSafeUnref(fTypefacesToUnref[i]); | 29 SkSafeUnref(fTypefacesToUnref[i]); |
30 } | 30 } |
31 } | 31 } |
32 | 32 |
33 protected: | 33 protected: |
34 virtual SkString onShortName() SK_OVERRIDE { | 34 SkString onShortName() SK_OVERRIDE { |
35 SkString name("varied_text"); | 35 SkString name("varied_text"); |
36 if (fEffectiveClip) { | 36 if (fEffectiveClip) { |
37 name.append("_clipped"); | 37 name.append("_clipped"); |
38 } else { | 38 } else { |
39 name.append("_ignorable_clip"); | 39 name.append("_ignorable_clip"); |
40 } | 40 } |
41 if (fLCD) { | 41 if (fLCD) { |
42 name.append("_lcd"); | 42 name.append("_lcd"); |
43 } else { | 43 } else { |
44 name.append("_no_lcd"); | 44 name.append("_no_lcd"); |
45 } | 45 } |
46 return name; | 46 return name; |
47 } | 47 } |
48 | 48 |
49 virtual SkISize onISize() SK_OVERRIDE { | 49 SkISize onISize() SK_OVERRIDE { |
50 return SkISize::Make(640, 480); | 50 return SkISize::Make(640, 480); |
51 } | 51 } |
52 | 52 |
53 virtual void onOnceBeforeDraw() SK_OVERRIDE { | 53 void onOnceBeforeDraw() SK_OVERRIDE { |
54 fPaint.setAntiAlias(true); | 54 fPaint.setAntiAlias(true); |
55 fPaint.setLCDRenderText(fLCD); | 55 fPaint.setLCDRenderText(fLCD); |
56 | 56 |
57 SkISize size = this->getISize(); | 57 SkISize size = this->getISize(); |
58 SkScalar w = SkIntToScalar(size.fWidth); | 58 SkScalar w = SkIntToScalar(size.fWidth); |
59 SkScalar h = SkIntToScalar(size.fHeight); | 59 SkScalar h = SkIntToScalar(size.fHeight); |
60 | 60 |
61 SK_COMPILE_ASSERT(4 == SK_ARRAY_COUNT(fTypefacesToUnref), typeface_cnt); | 61 SK_COMPILE_ASSERT(4 == SK_ARRAY_COUNT(fTypefacesToUnref), typeface_cnt); |
62 fTypefacesToUnref[0] = sk_tool_utils::create_portable_typeface("sans-ser
if", SkTypeface::kNormal); | 62 fTypefacesToUnref[0] = sk_tool_utils::create_portable_typeface("sans-ser
if", SkTypeface::kNormal); |
63 fTypefacesToUnref[1] = sk_tool_utils::create_portable_typeface("sans-ser
if", SkTypeface::kBold); | 63 fTypefacesToUnref[1] = sk_tool_utils::create_portable_typeface("sans-ser
if", SkTypeface::kBold); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 fClipRects[i] = r; | 104 fClipRects[i] = r; |
105 fClipRects[i].offset(fPositions[i].fX, fPositions[i].fY); | 105 fClipRects[i].offset(fPositions[i].fX, fPositions[i].fY); |
106 fClipRects[i].outset(2.f, 2.f); | 106 fClipRects[i].outset(2.f, 2.f); |
107 | 107 |
108 if (fEffectiveClip) { | 108 if (fEffectiveClip) { |
109 fClipRects[i].fRight -= 0.25f * fClipRects[i].width(); | 109 fClipRects[i].fRight -= 0.25f * fClipRects[i].width(); |
110 } | 110 } |
111 } | 111 } |
112 } | 112 } |
113 | 113 |
114 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 114 void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
115 for (int i = 0; i < kCnt; ++i) { | 115 for (int i = 0; i < kCnt; ++i) { |
116 fPaint.setColor(fColors[i]); | 116 fPaint.setColor(fColors[i]); |
117 fPaint.setTextSize(fPtSizes[i]); | 117 fPaint.setTextSize(fPtSizes[i]); |
118 fPaint.setTypeface(fTypefaces[i]); | 118 fPaint.setTypeface(fTypefaces[i]); |
119 | 119 |
120 canvas->save(); | 120 canvas->save(); |
121 canvas->clipRect(fClipRects[i]); | 121 canvas->clipRect(fClipRects[i]); |
122 canvas->translate(fPositions[i].fX, fPositions[i].fY); | 122 canvas->translate(fPositions[i].fX, fPositions[i].fY); |
123 canvas->drawText(fStrings[i].c_str(), fStrings[i].size(), 0, 0,
fPaint); | 123 canvas->drawText(fStrings[i].c_str(), fStrings[i].size(), 0, 0,
fPaint); |
124 canvas->restore(); | 124 canvas->restore(); |
125 } | 125 } |
126 | 126 |
127 // Visualize the clips, but not in bench mode. | 127 // Visualize the clips, but not in bench mode. |
128 if (kBench_Mode != this->getMode()) { | 128 if (kBench_Mode != this->getMode()) { |
129 SkPaint wirePaint; | 129 SkPaint wirePaint; |
130 wirePaint.setAntiAlias(true); | 130 wirePaint.setAntiAlias(true); |
131 wirePaint.setStrokeWidth(0); | 131 wirePaint.setStrokeWidth(0); |
132 wirePaint.setStyle(SkPaint::kStroke_Style); | 132 wirePaint.setStyle(SkPaint::kStroke_Style); |
133 for (int i = 0; i < kCnt; ++i) { | 133 for (int i = 0; i < kCnt; ++i) { |
134 canvas->drawRect(fClipRects[i], wirePaint); | 134 canvas->drawRect(fClipRects[i], wirePaint); |
135 } | 135 } |
136 } | 136 } |
137 } | 137 } |
138 | 138 |
139 virtual uint32_t onGetFlags() const SK_OVERRIDE { | 139 uint32_t onGetFlags() const SK_OVERRIDE { |
140 // The aa hairline stroked rects used to visualize the clip draw slightl
y differently in | 140 // The aa hairline stroked rects used to visualize the clip draw slightl
y differently in |
141 // quilt mode in dm. | 141 // quilt mode in dm. |
142 return kAsBench_Flag | kSkipTiled_Flag; | 142 return kAsBench_Flag | kSkipTiled_Flag; |
143 } | 143 } |
144 | 144 |
145 private: | 145 private: |
146 static const int kCnt = 30; | 146 static const int kCnt = 30; |
147 static const int kMinLength = 15; | 147 static const int kMinLength = 15; |
148 static const int kMaxLength = 40; | 148 static const int kMaxLength = 40; |
149 | 149 |
(...skipping 10 matching lines...) Expand all Loading... |
160 SkPoint fPositions[kCnt]; | 160 SkPoint fPositions[kCnt]; |
161 SkRect fClipRects[kCnt]; | 161 SkRect fClipRects[kCnt]; |
162 | 162 |
163 typedef skiagm::GM INHERITED; | 163 typedef skiagm::GM INHERITED; |
164 }; | 164 }; |
165 | 165 |
166 DEF_GM( return SkNEW(VariedTextGM(false, false)); ) | 166 DEF_GM( return SkNEW(VariedTextGM(false, false)); ) |
167 DEF_GM( return SkNEW(VariedTextGM(true, false)); ) | 167 DEF_GM( return SkNEW(VariedTextGM(true, false)); ) |
168 DEF_GM( return SkNEW(VariedTextGM(false, true)); ) | 168 DEF_GM( return SkNEW(VariedTextGM(false, true)); ) |
169 DEF_GM( return SkNEW(VariedTextGM(true, true)); ) | 169 DEF_GM( return SkNEW(VariedTextGM(true, true)); ) |
OLD | NEW |