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

Side by Side Diff: gm/imagefilterstransformed.cpp

Issue 1028663002: Add a new GM to show problems with shear/rotate CTM w/ image filters. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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 | gyp/gmslides.gypi » ('j') | 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 "SkBitmapSource.h"
10 #include "SkBlurImageFilter.h"
11 #include "SkColor.h"
12 #include "SkDisplacementMapEffect.h"
13 #include "SkDropShadowImageFilter.h"
14 #include "SkGradientShader.h"
15 #include "SkMorphologyImageFilter.h"
16 #include "SkScalar.h"
17 #include "gm.h"
18
19 namespace skiagm {
20
21 // This GM draws image filters with a CTM containing shearing / rotation.
22 // It checks that the scale portion of the CTM is correctly extracted
23 // and applied to the image inputs separately from the non-scale portion.
24
25 class ImageFiltersTransformedGM : public GM {
26 public:
27 ImageFiltersTransformedGM() {
28 this->setBGColor(SK_ColorBLACK);
29 }
30
31 protected:
32
33 SkString onShortName() SK_OVERRIDE { return SkString("imagefilterstransforme d"); }
34
35 SkISize onISize() SK_OVERRIDE { return SkISize::Make(420, 240); }
36
37 void makeGradientCircle(int width, int height) {
38 SkScalar x = SkIntToScalar(width / 2);
39 SkScalar y = SkIntToScalar(height / 2);
40 SkScalar radius = SkMinScalar(x, y) * 0.8f;
41 fGradientCircle.allocN32Pixels(width, height);
42 SkCanvas canvas(fGradientCircle);
43 canvas.clear(0x00000000);
44 SkColor colors[2];
45 colors[0] = SK_ColorWHITE;
46 colors[1] = SK_ColorBLACK;
47 SkAutoTUnref<SkShader> shader(
48 SkGradientShader::CreateRadial(SkPoint::Make(x, y), radius, colors, NULL, 2,
49 SkShader::kClamp_TileMode)
50 );
51 SkPaint paint;
52 paint.setShader(shader);
53 canvas.drawCircle(x, y, radius, paint);
54 }
55
56 void onOnceBeforeDraw() SK_OVERRIDE {
57 fCheckerboard.allocN32Pixels(64, 64);
58 SkCanvas checkerboardCanvas(fCheckerboard);
59 sk_tool_utils::draw_checkerboard(&checkerboardCanvas, 0xFFA0A0A0, 0xFF40 4040, 8);
60
61 this->makeGradientCircle(64, 64);
62 }
63
64 void onDraw(SkCanvas* canvas) SK_OVERRIDE {
robertphillips 2015/03/20 14:35:40 Is this necessary - given the setting of the backg
65 canvas->clear(SK_ColorBLACK);
66
67 SkAutoTUnref<SkImageFilter> gradient(SkBitmapSource::Create(fGradientCir cle));
68 SkAutoTUnref<SkImageFilter> checkerboard(SkBitmapSource::Create(fChecker board));
69 SkImageFilter* filters[] = {
70 SkBlurImageFilter::Create(12, 0),
71 SkDropShadowImageFilter::Create(0, 15, 8, 0, SK_ColorGREEN,
72 SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode),
73 SkDisplacementMapEffect::Create(SkDisplacementMapEffect::kR_ChannelS electorType,
74 SkDisplacementMapEffect::kR_ChannelS electorType,
75 12,
76 gradient.get(),
77 checkerboard.get()),
78 SkDilateImageFilter::Create(2, 2, checkerboard.get()),
79 SkErodeImageFilter::Create(2, 2, checkerboard.get()),
80 };
81
82 const SkScalar margin = SkIntToScalar(20);
83 const SkScalar size = SkIntToScalar(60);
84
85 for (size_t j = 0; j < 3; j++) {
86 canvas->save();
87 canvas->translate(margin, 0);
88 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) {
89 SkPaint paint;
90 paint.setColor(SK_ColorWHITE);
91 paint.setImageFilter(filters[i]);
92 paint.setAntiAlias(true);
93 canvas->save();
94 canvas->translate(size * 0.5, size * 0.5);
95 canvas->scale(0.8, 0.8);
96 if (j == 1) {
97 canvas->rotate(SkIntToScalar(45));
98 } else if (j == 2) {
99 canvas->skew(0.5, 0.2);
100 }
101 canvas->translate(-size * 0.5, -size * 0.5);
102 canvas->drawOval(SkRect::MakeXYWH(0, size * 0.1, size, size * 0. 6), paint);
103 canvas->restore();
104 canvas->translate(size + margin, 0);
105 }
106 canvas->restore();
107 canvas->translate(0, size + margin);
108 }
109
110 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) {
111 SkSafeUnref(filters[i]);
112 }
113 }
114
115 private:
116 SkBitmap fCheckerboard;
117 SkBitmap fGradientCircle;
118 typedef GM INHERITED;
119 };
120
121 //////////////////////////////////////////////////////////////////////////////
122
123 DEF_GM( return new ImageFiltersTransformedGM; )
124
125 }
OLDNEW
« no previous file with comments | « no previous file | gyp/gmslides.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698