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" |
| 15 #include "SkPictureImageFilter.h" |
| 16 #include "SkPictureRecorder.h" |
| 17 #include "SkSurface.h" |
| 18 |
14 | 19 |
15 class LcdTextGM : public skiagm::GM { | 20 class LcdTextGM : public skiagm::GM { |
16 public: | 21 public: |
17 LcdTextGM() { | 22 LcdTextGM() { |
18 const int pointSize = 36; | 23 const int pointSize = 36; |
19 textHeight = SkIntToScalar(pointSize); | 24 textHeight = SkIntToScalar(pointSize); |
20 } | 25 } |
21 | 26 |
22 protected: | 27 protected: |
23 | 28 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 paint.setTextSize(rec[i].fTextSize); | 119 paint.setTextSize(rec[i].fTextSize); |
115 ScaleAbout(canvas, rec[i].fScale, rec[i].fScale, loc.x(), loc.y()); | 120 ScaleAbout(canvas, rec[i].fScale, rec[i].fScale, loc.x(), loc.y()); |
116 canvas->drawText(rec[i].fText, strlen(rec[i].fText), loc.x(), loc.y(
), paint); | 121 canvas->drawText(rec[i].fText, strlen(rec[i].fText), loc.x(), loc.y(
), paint); |
117 } | 122 } |
118 } | 123 } |
119 | 124 |
120 private: | 125 private: |
121 typedef skiagm::GM INHERITED; | 126 typedef skiagm::GM INHERITED; |
122 }; | 127 }; |
123 | 128 |
124 #include "SkSurface.h" | |
125 | |
126 // ensure that we respect the SkPixelGeometry in SurfaceProps | 129 // ensure that we respect the SkPixelGeometry in SurfaceProps |
127 class LcdTextProps : public skiagm::GM { | 130 class LcdTextProps : public skiagm::GM { |
128 static void DrawText(SkCanvas* canvas) { | 131 static void DrawText(SkCanvas* canvas) { |
129 canvas->drawColor(SK_ColorWHITE); | 132 canvas->drawColor(SK_ColorWHITE); |
130 SkPaint paint; | 133 SkPaint paint; |
131 paint.setAntiAlias(true); | 134 paint.setAntiAlias(true); |
132 paint.setLCDRenderText(true); | 135 paint.setLCDRenderText(true); |
133 paint.setTextSize(30); | 136 paint.setTextSize(30); |
134 canvas->drawText("Base", 4, 4, 30, paint); | 137 canvas->drawText("Base", 4, 4, 30, paint); |
135 canvas->saveLayer(NULL, NULL); | 138 canvas->saveLayer(NULL, NULL); |
136 canvas->drawText("Layer", 5, 4, 70, paint); | 139 canvas->drawText("Layer", 5, 4, 70, paint); |
137 canvas->restore(); | 140 canvas->restore(); |
138 } | 141 } |
139 | 142 |
| 143 static SkSurface* MakeSurface(SkCanvas* canvas, const SkImageInfo& info, SkP
ixelGeometry geo) { |
| 144 SkSurfaceProps props = SkSurfaceProps(0, geo); |
| 145 SkSurface* surface = canvas->newSurface(info, &props); |
| 146 |
| 147 if (!surface) { |
| 148 surface = SkSurface::NewRaster(info, &props); |
| 149 } |
| 150 |
| 151 return surface; |
| 152 } |
| 153 |
140 protected: | 154 protected: |
141 SkString onShortName() SK_OVERRIDE { | 155 SkString onShortName() SK_OVERRIDE { |
142 return SkString("lcdtextprops"); | 156 return SkString("lcdtextprops"); |
143 } | 157 } |
144 | 158 |
145 SkISize onISize() SK_OVERRIDE { return SkISize::Make(230, 120); } | 159 SkISize onISize() SK_OVERRIDE { return SkISize::Make(230, 230); } |
146 | 160 |
147 uint32_t onGetFlags() const SK_OVERRIDE { | 161 uint32_t onGetFlags() const SK_OVERRIDE { |
148 return kSkip565_Flag; | 162 return kSkip565_Flag; |
149 } | 163 } |
150 | 164 |
| 165 virtual void onOnceBeforeDraw() SK_OVERRIDE { |
| 166 fInfo = SkImageInfo::MakeN32Premul(100, 100); |
| 167 SkPictureRecorder recorder; |
| 168 DrawText(recorder.beginRecording(SkIntToScalar(fInfo.width()), |
| 169 SkIntToScalar(fInfo.height()))); |
| 170 SkAutoTUnref<SkPicture> pic(recorder.endRecording()); |
| 171 SkAutoTUnref<SkImageFilter> filter(SkPictureImageFilter::Create(pic.get(
))); |
| 172 fFilterPaint.setImageFilter(filter.get()); |
| 173 } |
| 174 |
151 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 175 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
152 const SkPixelGeometry geos[] = { | 176 const SkPixelGeometry geos[] = { |
153 kRGB_H_SkPixelGeometry, | 177 kRGB_H_SkPixelGeometry, |
154 kUnknown_SkPixelGeometry, | 178 kUnknown_SkPixelGeometry, |
155 }; | 179 }; |
156 | 180 |
157 const SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100); | |
158 for (size_t i = 0; i < SK_ARRAY_COUNT(geos); ++i) { | 181 for (size_t i = 0; i < SK_ARRAY_COUNT(geos); ++i) { |
159 SkSurfaceProps props = SkSurfaceProps(0, geos[i]); | 182 SkAutoTUnref<SkSurface> surf(MakeSurface(canvas, fInfo, geos[i])); |
160 SkAutoTUnref<SkSurface> surf(canvas->newSurface(info, &props)); | |
161 if (!surf) { | |
162 surf.reset(SkSurface::NewRaster(info, &props)); | |
163 } | |
164 DrawText(surf->getCanvas()); | 183 DrawText(surf->getCanvas()); |
165 surf->draw(canvas, SkIntToScalar(i * (info.width() + 10)), 0, NULL); | 184 surf->draw(canvas, SkIntToScalar(i * (fInfo.width() + 10)), 0, NULL)
; |
| 185 } |
| 186 |
| 187 for (size_t i = 0; i < SK_ARRAY_COUNT(geos); ++i) { |
| 188 SkAutoTUnref<SkSurface> surf(MakeSurface(canvas, fInfo, geos[i])); |
| 189 surf->getCanvas()->saveLayer(NULL, &fFilterPaint); |
| 190 surf->getCanvas()->restore(); |
| 191 surf->draw(canvas, |
| 192 SkIntToScalar(i * (fInfo.width() + 10)), |
| 193 SkIntToScalar(fInfo.height() + 10), |
| 194 NULL); |
166 } | 195 } |
167 } | 196 } |
| 197 |
| 198 private: |
| 199 SkPaint fFilterPaint; |
| 200 SkImageInfo fInfo; |
| 201 |
| 202 typedef skiagm::GM INHERITED; |
168 }; | 203 }; |
169 | 204 |
170 /////////////////////////////////////////////////////////////////////////////// | 205 /////////////////////////////////////////////////////////////////////////////// |
171 | 206 |
172 DEF_GM( return new LcdTextGM; ) | 207 DEF_GM( return new LcdTextGM; ) |
173 DEF_GM( return new LcdTextSizeGM; ) | 208 DEF_GM( return new LcdTextSizeGM; ) |
174 // Temporarily disabled (dftext interference) | 209 // Temporarily disabled (dftext interference) |
175 // DEF_GM( return new LcdTextProps; ) | 210 // DEF_GM( return new LcdTextProps; ) |
OLD | NEW |