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

Side by Side Diff: gm/imagefiltersstroked.cpp

Issue 1323573004: Add a GM for image filters applied to stroked primitives. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Use DEF_GM Created 5 years, 3 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 | 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
(Empty)
1 /*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "sk_tool_utils.h"
9 #include "SkBlurImageFilter.h"
10 #include "SkColor.h"
11 #include "SkDropShadowImageFilter.h"
12 #include "SkOffsetImageFilter.h"
13 #include "SkScalar.h"
14 #include "gm.h"
15
16 #define RESIZE_FACTOR_X SkIntToScalar(2)
17 #define RESIZE_FACTOR_Y SkIntToScalar(5)
18
19 namespace skiagm {
20
21 class ImageFiltersStrokedGM : public GM {
22 public:
23 ImageFiltersStrokedGM() {
24 this->setBGColor(0x00000000);
25 }
26
27 protected:
28
29 SkString onShortName() override {
30 return SkString("imagefiltersstroked");
31 }
32
33 SkISize onISize() override {
34 return SkISize::Make(860, 500);
35 }
36
37 static void draw_circle(SkCanvas* canvas, const SkRect& r, const SkPaint& pa int) {
38 canvas->drawCircle(r.centerX(), r.centerY(),
39 r.width() * 2 / 5, paint);
40 }
41
42 static void draw_line(SkCanvas* canvas, const SkRect& r, const SkPaint& pain t) {
43 canvas->drawLine(r.fLeft, r.fBottom, r.fRight, r.fTop, paint);
44 }
45
46 static void draw_rect(SkCanvas* canvas, const SkRect& r, const SkPaint& pain t) {
47 canvas->drawRect(r, paint);
48 }
49
50 static void draw_text(SkCanvas* canvas, const SkRect& r, const SkPaint& pain t) {
51 canvas->drawText("A", 1, r.centerX(), r.centerY(), paint);
reed1 2015/08/28 19:41:38 Cary will bark loudly if we draw fonts just to dra
Stephen White 2015/08/28 19:46:20 Removed.
52 }
53
54 void onDraw(SkCanvas* canvas) override {
55 void (*drawProc[])(SkCanvas*, const SkRect&, const SkPaint&) = {
56 draw_line, draw_rect, draw_circle, draw_text,
57 };
58
59 canvas->clear(SK_ColorBLACK);
60
61 SkMatrix resizeMatrix;
62 resizeMatrix.setScale(RESIZE_FACTOR_X, RESIZE_FACTOR_Y);
63
64 SkImageFilter* filters[] = {
65 SkBlurImageFilter::Create(SkIntToScalar(5), SkIntToScalar(5)),
66 SkDropShadowImageFilter::Create(SkIntToScalar(10), SkIntToScalar(10) ,
67 SkIntToScalar(3), SkIntToScalar(3), SK_ColorGREEN,
68 SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode),
69 SkOffsetImageFilter::Create(SkIntToScalar(-16), SkIntToScalar(32)),
70 SkImageFilter::CreateMatrixFilter(resizeMatrix, kNone_SkFilterQualit y),
71 };
72
73 SkRect r = SkRect::MakeWH(SkIntToScalar(64), SkIntToScalar(64));
reed1 2015/08/28 19:41:38 nits: for literals, you don't need SkIntToScalar()
Stephen White 2015/08/28 19:46:20 Removed.
74 SkScalar margin = SkIntToScalar(32);
75 SkPaint paint;
76 paint.setColor(SK_ColorWHITE);
77 paint.setAntiAlias(true);
78 paint.setStrokeWidth(SkIntToScalar(10));
79 paint.setStyle(SkPaint::kStroke_Style);
80 paint.setTextSize(SkIntToScalar(48));
81 paint.setTextAlign(SkPaint::kCenter_Align);
82
83 for (size_t i = 0; i < SK_ARRAY_COUNT(drawProc); ++i) {
84 canvas->translate(0, margin);
85 canvas->save();
86 for (size_t j = 0; j < SK_ARRAY_COUNT(filters); ++j) {
87 canvas->translate(margin, 0);
88 canvas->save();
89 if (2 == j) {
90 canvas->translate(SkIntToScalar(16), SkIntToScalar(-32));
91 } else if (3 == j) {
92 canvas->scale(SkScalarInvert(RESIZE_FACTOR_X),
93 SkScalarInvert(RESIZE_FACTOR_Y));
94 }
95 paint.setImageFilter(filters[j]);
96 drawProc[i](canvas, r, paint);
97 canvas->restore();
98 canvas->translate(r.width() + margin, 0);
99 }
100 canvas->restore();
101 canvas->translate(0, r.height());
102 }
103
104 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) {
105 SkSafeUnref(filters[i]);
106 }
107 }
108
109 private:
110 typedef GM INHERITED;
111 };
112
113 //////////////////////////////////////////////////////////////////////////////
114
115 DEF_GM(return new ImageFiltersStrokedGM;)
116
117 }
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