| 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 */ |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 paint.setTextSize(rec[i].fTextSize); | 119 paint.setTextSize(rec[i].fTextSize); |
| 120 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()); |
| 121 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); |
| 122 } | 122 } |
| 123 } | 123 } |
| 124 | 124 |
| 125 private: | 125 private: |
| 126 typedef skiagm::GM INHERITED; | 126 typedef skiagm::GM INHERITED; |
| 127 }; | 127 }; |
| 128 | 128 |
| 129 // ensure that we respect the SkPixelGeometry in SurfaceProps | |
| 130 class LcdTextProps : public skiagm::GM { | |
| 131 static void DrawText(SkCanvas* canvas) { | |
| 132 canvas->drawColor(SK_ColorWHITE); | |
| 133 SkPaint paint; | |
| 134 paint.setAntiAlias(true); | |
| 135 paint.setLCDRenderText(true); | |
| 136 paint.setTextSize(30); | |
| 137 canvas->drawText("Base", 4, 4, 30, paint); | |
| 138 canvas->saveLayer(NULL, NULL); | |
| 139 canvas->drawText("Layer", 5, 4, 70, paint); | |
| 140 canvas->restore(); | |
| 141 } | |
| 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 | |
| 154 protected: | |
| 155 SkString onShortName() SK_OVERRIDE { | |
| 156 return SkString("lcdtextprops"); | |
| 157 } | |
| 158 | |
| 159 SkISize onISize() SK_OVERRIDE { return SkISize::Make(230, 230); } | |
| 160 | |
| 161 void onOnceBeforeDraw() SK_OVERRIDE { | |
| 162 fInfo = SkImageInfo::MakeN32Premul(100, 100); | |
| 163 SkPictureRecorder recorder; | |
| 164 DrawText(recorder.beginRecording(SkIntToScalar(fInfo.width()), | |
| 165 SkIntToScalar(fInfo.height()))); | |
| 166 SkAutoTUnref<SkPicture> pic(recorder.endRecording()); | |
| 167 SkAutoTUnref<SkImageFilter> filter(SkPictureImageFilter::Create(pic.get(
))); | |
| 168 fFilterPaint.setImageFilter(filter.get()); | |
| 169 } | |
| 170 | |
| 171 void onDraw(SkCanvas* canvas) SK_OVERRIDE { | |
| 172 const SkPixelGeometry geos[] = { | |
| 173 kRGB_H_SkPixelGeometry, | |
| 174 kUnknown_SkPixelGeometry, | |
| 175 }; | |
| 176 | |
| 177 for (size_t i = 0; i < SK_ARRAY_COUNT(geos); ++i) { | |
| 178 SkAutoTUnref<SkSurface> surf(MakeSurface(canvas, fInfo, geos[i])); | |
| 179 DrawText(surf->getCanvas()); | |
| 180 surf->draw(canvas, SkIntToScalar(i * (fInfo.width() + 10)), 0, NULL)
; | |
| 181 } | |
| 182 | |
| 183 for (size_t i = 0; i < SK_ARRAY_COUNT(geos); ++i) { | |
| 184 SkAutoTUnref<SkSurface> surf(MakeSurface(canvas, fInfo, geos[i])); | |
| 185 surf->getCanvas()->saveLayer(NULL, &fFilterPaint); | |
| 186 surf->getCanvas()->restore(); | |
| 187 surf->draw(canvas, | |
| 188 SkIntToScalar(i * (fInfo.width() + 10)), | |
| 189 SkIntToScalar(fInfo.height() + 10), | |
| 190 NULL); | |
| 191 } | |
| 192 } | |
| 193 | |
| 194 private: | |
| 195 SkPaint fFilterPaint; | |
| 196 SkImageInfo fInfo; | |
| 197 | |
| 198 typedef skiagm::GM INHERITED; | |
| 199 }; | |
| 200 | |
| 201 /////////////////////////////////////////////////////////////////////////////// | |
| 202 | |
| 203 DEF_GM( return new LcdTextGM; ) | 129 DEF_GM( return new LcdTextGM; ) |
| 204 DEF_GM( return new LcdTextSizeGM; ) | 130 DEF_GM( return new LcdTextSizeGM; ) |
| 205 // Temporarily disabled (dftext interference) | |
| 206 // DEF_GM( return new LcdTextProps; ) | |
| OLD | NEW |