Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(356)

Side by Side Diff: gm/lcdtext.cpp

Issue 741433003: Add an image filter row to GM:lcdtextprops (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 14
15 #include "SkPicture.h"
16 #include "SkPictureImageFilter.h"
17 #include "SkPictureRecorder.h"
18
15 class LcdTextGM : public skiagm::GM { 19 class LcdTextGM : public skiagm::GM {
16 public: 20 public:
17 LcdTextGM() { 21 LcdTextGM() {
18 const int pointSize = 36; 22 const int pointSize = 36;
19 textHeight = SkIntToScalar(pointSize); 23 textHeight = SkIntToScalar(pointSize);
20 } 24 }
21 25
22 protected: 26 protected:
23 27
24 SkString onShortName() { 28 SkString onShortName() {
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 SkPaint paint; 134 SkPaint paint;
131 paint.setAntiAlias(true); 135 paint.setAntiAlias(true);
132 paint.setLCDRenderText(true); 136 paint.setLCDRenderText(true);
133 paint.setTextSize(30); 137 paint.setTextSize(30);
134 canvas->drawText("Base", 4, 4, 30, paint); 138 canvas->drawText("Base", 4, 4, 30, paint);
135 canvas->saveLayer(NULL, NULL); 139 canvas->saveLayer(NULL, NULL);
136 canvas->drawText("Layer", 5, 4, 70, paint); 140 canvas->drawText("Layer", 5, 4, 70, paint);
137 canvas->restore(); 141 canvas->restore();
138 } 142 }
139 143
144 static SkSurface* MakeSurface(SkCanvas* canvas, const SkImageInfo& info, SkP ixelGeometry geo) {
145 SkSurfaceProps props = SkSurfaceProps(0, geo);
146 SkSurface* surface = canvas->newSurface(info, &props);
147
148 if (!surface) {
149 surface = SkSurface::NewRaster(info, &props);
150 }
151
152 return surface;
153 }
154
140 protected: 155 protected:
141 SkString onShortName() SK_OVERRIDE { 156 SkString onShortName() SK_OVERRIDE {
142 return SkString("lcdtextprops"); 157 return SkString("lcdtextprops");
143 } 158 }
144 159
145 SkISize onISize() SK_OVERRIDE { return SkISize::Make(230, 120); } 160 SkISize onISize() SK_OVERRIDE { return SkISize::Make(230, 120); }
146 161
147 uint32_t onGetFlags() const SK_OVERRIDE { 162 uint32_t onGetFlags() const SK_OVERRIDE {
148 return kSkip565_Flag; 163 return kSkip565_Flag;
149 } 164 }
150 165
151 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { 166 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
152 const SkPixelGeometry geos[] = { 167 const SkPixelGeometry geos[] = {
153 kRGB_H_SkPixelGeometry, 168 kRGB_H_SkPixelGeometry,
154 kUnknown_SkPixelGeometry, 169 kUnknown_SkPixelGeometry,
155 }; 170 };
156 171
157 const SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100); 172 const SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100);
173 SkPictureRecorder recorder;
reed1 2014/11/19 16:39:24 maybe we can move this building-the-paint into the
f(malita) 2014/11/19 17:08:59 Done.
174 DrawText(recorder.beginRecording(SkIntToScalar(info.width()),
175 SkIntToScalar(info.height())));
176 SkAutoTUnref<SkPicture> pic(recorder.endRecording());
177 SkAutoTUnref<SkImageFilter> filter(SkPictureImageFilter::Create(pic.get( )));
178 SkPaint filterPaint;
179 filterPaint.setImageFilter(filter.get());
180
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, info, 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 * (info.width() + 10)), 0, NULL);
166 } 185 }
186
187 for (size_t i = 0; i < SK_ARRAY_COUNT(geos); ++i) {
188 SkAutoTUnref<SkSurface> surf(MakeSurface(canvas, info, geos[i]));
189 surf->getCanvas()->saveLayer(NULL, &filterPaint);
190 surf->getCanvas()->restore();
191 surf->draw(canvas,
192 SkIntToScalar(i * (info.width() + 10)),
193 SkIntToScalar(info.height() + 10),
194 NULL);
195 }
167 } 196 }
168 }; 197 };
169 198
170 /////////////////////////////////////////////////////////////////////////////// 199 ///////////////////////////////////////////////////////////////////////////////
171 200
172 DEF_GM( return new LcdTextGM; ) 201 DEF_GM( return new LcdTextGM; )
173 DEF_GM( return new LcdTextSizeGM; ) 202 DEF_GM( return new LcdTextSizeGM; )
174 // Temporarily disabled (dftext interference) 203 // Temporarily disabled (dftext interference)
175 // DEF_GM( return new LcdTextProps; ) 204 // DEF_GM( return new LcdTextProps; )
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698