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

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: Fixes per review comments 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 void onDraw(SkCanvas* canvas) override {
51 void (*drawProc[])(SkCanvas*, const SkRect&, const SkPaint&) = {
52 draw_line, draw_rect, draw_circle,
53 };
54
55 canvas->clear(SK_ColorBLACK);
56
57 SkMatrix resizeMatrix;
58 resizeMatrix.setScale(RESIZE_FACTOR_X, RESIZE_FACTOR_Y);
59
60 SkImageFilter* filters[] = {
61 SkBlurImageFilter::Create(5, 5),
62 SkDropShadowImageFilter::Create(10, 10, 3, 3, SK_ColorGREEN,
63 SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode),
64 SkOffsetImageFilter::Create(-16, 32),
65 SkImageFilter::CreateMatrixFilter(resizeMatrix, kNone_SkFilterQualit y),
66 };
67
68 SkRect r = SkRect::MakeWH(64, 64);
69 SkScalar margin = 32;
70 SkPaint paint;
71 paint.setColor(SK_ColorWHITE);
72 paint.setAntiAlias(true);
73 paint.setStrokeWidth(10);
74 paint.setStyle(SkPaint::kStroke_Style);
75 paint.setTextSize(48);
76 paint.setTextAlign(SkPaint::kCenter_Align);
77
78 for (size_t i = 0; i < SK_ARRAY_COUNT(drawProc); ++i) {
79 canvas->translate(0, margin);
80 canvas->save();
81 for (size_t j = 0; j < SK_ARRAY_COUNT(filters); ++j) {
82 canvas->translate(margin, 0);
83 canvas->save();
84 if (2 == j) {
85 canvas->translate(16, -32);
86 } else if (3 == j) {
87 canvas->scale(SkScalarInvert(RESIZE_FACTOR_X),
88 SkScalarInvert(RESIZE_FACTOR_Y));
89 }
90 paint.setImageFilter(filters[j]);
91 drawProc[i](canvas, r, paint);
92 canvas->restore();
93 canvas->translate(r.width() + margin, 0);
94 }
95 canvas->restore();
96 canvas->translate(0, r.height());
97 }
98
99 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) {
100 SkSafeUnref(filters[i]);
101 }
102 }
103
104 private:
105 typedef GM INHERITED;
106 };
107
108 //////////////////////////////////////////////////////////////////////////////
109
110 DEF_GM(return new ImageFiltersStrokedGM;)
111
112 }
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