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

Side by Side Diff: gm/imagefiltersbase.cpp

Issue 1002603003: disable LCD for layers w/ filters (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: update gm Created 5 years, 9 months 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 | src/core/SkCanvas.cpp » ('j') | 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 #include "gm.h" 8 #include "gm.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkColorFilter.h" 10 #include "SkColorFilter.h"
(...skipping 18 matching lines...) Expand all
29 static FailImageFilter* Create() { 29 static FailImageFilter* Create() {
30 return SkNEW(FailImageFilter); 30 return SkNEW(FailImageFilter);
31 } 31 }
32 32
33 SK_TO_STRING_OVERRIDE() 33 SK_TO_STRING_OVERRIDE()
34 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(FailImageFilter) 34 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(FailImageFilter)
35 35
36 protected: 36 protected:
37 FailImageFilter() : INHERITED(0, NULL) {} 37 FailImageFilter() : INHERITED(0, NULL) {}
38 38
39 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, 39 bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
40 SkBitmap* result, SkIPoint* offset) const SK_OVER RIDE { 40 SkBitmap* result, SkIPoint* offset) const SK_OVERRIDE {
41 return false; 41 return false;
42 } 42 }
43 43
44 private: 44 private:
45 typedef SkImageFilter INHERITED; 45 typedef SkImageFilter INHERITED;
46 }; 46 };
47 47
48 static FailImageFilter::Registrar gReg0; 48 static FailImageFilter::Registrar gReg0;
49 49
50 SkFlattenable* FailImageFilter::CreateProc(SkReadBuffer& buffer) { 50 SkFlattenable* FailImageFilter::CreateProc(SkReadBuffer& buffer) {
(...skipping 20 matching lines...) Expand all
71 }; 71 };
72 static IdentityImageFilter* Create(SkImageFilter* input = NULL) { 72 static IdentityImageFilter* Create(SkImageFilter* input = NULL) {
73 return SkNEW_ARGS(IdentityImageFilter, (input)); 73 return SkNEW_ARGS(IdentityImageFilter, (input));
74 } 74 }
75 75
76 SK_TO_STRING_OVERRIDE() 76 SK_TO_STRING_OVERRIDE()
77 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(IdentityImageFilter) 77 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(IdentityImageFilter)
78 protected: 78 protected:
79 IdentityImageFilter(SkImageFilter* input) : INHERITED(1, &input) {} 79 IdentityImageFilter(SkImageFilter* input) : INHERITED(1, &input) {}
80 80
81 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, 81 bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
82 SkBitmap* result, SkIPoint* offset) const SK_OVER RIDE { 82 SkBitmap* result, SkIPoint* offset) const SK_OVERRIDE {
83 *result = src; 83 *result = src;
84 offset->set(0, 0); 84 offset->set(0, 0);
85 return true; 85 return true;
86 } 86 }
87 87
88 private: 88 private:
89 typedef SkImageFilter INHERITED; 89 typedef SkImageFilter INHERITED;
90 }; 90 };
91 91
92 static IdentityImageFilter::Registrar gReg1; 92 static IdentityImageFilter::Registrar gReg1;
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 &paint); 187 &paint);
188 } 188 }
189 189
190 /////////////////////////////////////////////////////////////////////////////// 190 ///////////////////////////////////////////////////////////////////////////////
191 191
192 class ImageFiltersBaseGM : public skiagm::GM { 192 class ImageFiltersBaseGM : public skiagm::GM {
193 public: 193 public:
194 ImageFiltersBaseGM () {} 194 ImageFiltersBaseGM () {}
195 195
196 protected: 196 protected:
197 virtual SkString onShortName() { 197 SkString onShortName() SK_OVERRIDE {
198 return SkString("imagefiltersbase"); 198 return SkString("imagefiltersbase");
199 } 199 }
200 200
201 virtual SkISize onISize() { return SkISize::Make(700, 500); } 201 SkISize onISize() SK_OVERRIDE { return SkISize::Make(700, 500); }
202 202
203 void draw_frame(SkCanvas* canvas, const SkRect& r) { 203 void draw_frame(SkCanvas* canvas, const SkRect& r) {
204 SkPaint paint; 204 SkPaint paint;
205 paint.setStyle(SkPaint::kStroke_Style); 205 paint.setStyle(SkPaint::kStroke_Style);
206 paint.setColor(SK_ColorRED); 206 paint.setColor(SK_ColorRED);
207 canvas->drawRect(r, paint); 207 canvas->drawRect(r, paint);
208 } 208 }
209 209
210 virtual void onDraw(SkCanvas* canvas) { 210 void onDraw(SkCanvas* canvas) SK_OVERRIDE {
211 void (*drawProc[])(SkCanvas*, const SkRect&, SkImageFilter*) = { 211 void (*drawProc[])(SkCanvas*, const SkRect&, SkImageFilter*) = {
212 draw_paint, 212 draw_paint,
213 draw_line, draw_rect, draw_path, draw_text, 213 draw_line, draw_rect, draw_path, draw_text,
214 draw_bitmap, 214 draw_bitmap,
215 draw_sprite 215 draw_sprite
216 }; 216 };
217 217
218 SkColorFilter* cf = SkColorFilter::CreateModeFilter(SK_ColorRED, 218 SkColorFilter* cf = SkColorFilter::CreateModeFilter(SK_ColorRED,
219 SkXfermode::kSrcIn_Mode); 219 SkXfermode::kSrcIn_Mode);
220 SkImageFilter* filters[] = { 220 SkImageFilter* filters[] = {
(...skipping 26 matching lines...) Expand all
247 } 247 }
248 248
249 for(size_t j = 0; j < SK_ARRAY_COUNT(filters); ++j) { 249 for(size_t j = 0; j < SK_ARRAY_COUNT(filters); ++j) {
250 SkSafeUnref(filters[j]); 250 SkSafeUnref(filters[j]);
251 } 251 }
252 } 252 }
253 253
254 private: 254 private:
255 typedef GM INHERITED; 255 typedef GM INHERITED;
256 }; 256 };
257 DEF_GM( return new ImageFiltersBaseGM; )
258
259 ///////////////////////////////////////////////////////////////////////////////
260
261 /*
262 * Want to test combos of filter and LCD text, to be sure we disable LCD in the presence of
263 * a filter.
264 */
265 class ImageFiltersTextBaseGM : public skiagm::GM {
266 SkString fSuffix;
267 public:
268 ImageFiltersTextBaseGM(const char suffix[]) : fSuffix(suffix) {}
269
270 protected:
271 SkString onShortName() SK_OVERRIDE {
272 SkString name;
273 name.printf("%s_%s", "textfilter", fSuffix.c_str());
274 return name;
275 }
276
277 SkISize onISize() SK_OVERRIDE { return SkISize::Make(512, 342); }
278
279 void drawWaterfall(SkCanvas* canvas, const SkPaint& origPaint) {
280 const uint32_t flags[] = {
281 0,
282 SkPaint::kAntiAlias_Flag,
283 SkPaint::kAntiAlias_Flag | SkPaint::kLCDRenderText_Flag,
284 };
285 SkPaint paint(origPaint);
286 paint.setTextSize(30);
287
288 SkAutoCanvasRestore acr(canvas, true);
289 for (size_t i = 0; i < SK_ARRAY_COUNT(flags); ++i) {
290 paint.setFlags(flags[i]);
291 canvas->drawText("Hamburgefons", 11, 0, 0, paint);
292 canvas->translate(0, 40);
293 }
294 }
295
296 virtual void installFilter(SkPaint* paint) = 0;
297
298 void onDraw(SkCanvas* canvas) SK_OVERRIDE {
299 SkPaint paint;
300
301 canvas->translate(20, 40);
302
303 for (int doSaveLayer = 0; doSaveLayer <= 1; ++doSaveLayer) {
304 SkAutoCanvasRestore acr(canvas, true);
305 for (int useFilter = 0; useFilter <= 1; ++useFilter) {
306 SkAutoCanvasRestore acr2(canvas, true);
307
308 SkPaint paint;
309 if (useFilter) {
310 this->installFilter(&paint);
311 }
312 if (doSaveLayer) {
313 canvas->saveLayer(NULL, &paint);
314 paint.setImageFilter(NULL);
315 }
316 this->drawWaterfall(canvas, paint);
317
318 acr2.restore();
319 canvas->translate(250, 0);
320 }
321 acr.restore();
322 canvas->translate(0, 200);
323 }
324 }
325
326 private:
327 typedef GM INHERITED;
328 };
257 329
258 /////////////////////////////////////////////////////////////////////////////// 330 class ImageFiltersText_IF : public ImageFiltersTextBaseGM {
331 public:
332 ImageFiltersText_IF() : ImageFiltersTextBaseGM("image") {}
259 333
260 static skiagm::GM* MyFactory(void*) { return new ImageFiltersBaseGM; } 334 void installFilter(SkPaint* paint) SK_OVERRIDE {
261 static skiagm::GMRegistry reg(MyFactory); 335 paint->setImageFilter(SkBlurImageFilter::Create(1.5f, 1.5f))->unref();
336 }
robertphillips 2015/03/20 12:30:17 private: typedef ImageFiltersTextBaseGM INHERI
337 };
338 DEF_GM( return new ImageFiltersText_IF; )
339
340 class ImageFiltersText_CF : public ImageFiltersTextBaseGM {
341 public:
342 ImageFiltersText_CF() : ImageFiltersTextBaseGM("color") {}
343
344 void installFilter(SkPaint* paint) SK_OVERRIDE {
345 paint->setColorFilter(SkColorFilter::CreateModeFilter(SK_ColorBLUE, SkXf ermode::kSrcIn_Mode))->unref();
346 }
robertphillips 2015/03/20 12:30:17 private: typedef ImageFiltersTextBaseGM INHERI
347 };
348 DEF_GM( return new ImageFiltersText_CF; )
349
OLDNEW
« no previous file with comments | « no previous file | src/core/SkCanvas.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698