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

Side by Side Diff: gm/imagefilterscropexpand.cpp

Issue 1842193002: Update SkOffsetImageFilter to sk_sp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: update to ToT Created 4 years, 8 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 | « gm/imagefiltersclipped.cpp ('k') | gm/imagefilterscropped.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 2014 Google Inc. 2 * Copyright 2014 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 SkImageFilter::CropRect cropRect( 43 SkImageFilter::CropRect cropRect(
44 SkRect::Make(SkIRect::MakeXYWH(10, 10, 44, 44)), 44 SkRect::Make(SkIRect::MakeXYWH(10, 10, 44, 44)),
45 SkImageFilter::CropRect::kHasAll_CropEdge); 45 SkImageFilter::CropRect::kHasAll_CropEdge);
46 46
47 sk_sp<SkImage> gradientCircle(MakeGradientCircle(64, 64)); 47 sk_sp<SkImage> gradientCircle(MakeGradientCircle(64, 64));
48 SkBitmap checkerboard; 48 SkBitmap checkerboard;
49 MakeCheckerboard(&checkerboard); 49 MakeCheckerboard(&checkerboard);
50 50
51 SkAutoTUnref<SkImageFilter> gradientCircleSource( 51 SkAutoTUnref<SkImageFilter> gradientCircleSource(
52 SkImageSource::Create(gradientCircle.get())); 52 SkImageSource::Create(gradientCircle.get()));
53 SkAutoTUnref<SkImageFilter> noopCropped( 53 sk_sp<SkImageFilter> noopCropped(SkOffsetImageFilter::Make(0, 0, nullptr , &cropRect));
54 SkOffsetImageFilter::Create(0, 0, nullptr, &cropRect));
55 SkScalar sk255 = SkIntToScalar(255); 54 SkScalar sk255 = SkIntToScalar(255);
56 SkScalar matrix[20] = { 1, 0, 0, 0, 0, 55 SkScalar matrix[20] = { 1, 0, 0, 0, 0,
57 0, 1, 0, 0, sk255, 56 0, 1, 0, 0, sk255,
58 0, 0, 1, 0, 0, 57 0, 0, 1, 0, 0,
59 0, 0, 0, 0, sk255 }; 58 0, 0, 0, 0, sk255 };
60 auto cfAlphaTrans(SkColorFilter::MakeMatrixFilterRowMajor255(matrix)); 59 auto cfAlphaTrans(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
61 60
62 SkRect r = SkRect::MakeWH(SkIntToScalar(64), SkIntToScalar(64)); 61 SkRect r = SkRect::MakeWH(SkIntToScalar(64), SkIntToScalar(64));
63 SkScalar MARGIN = SkIntToScalar(12); 62 SkScalar MARGIN = SkIntToScalar(12);
64 63
65 SkPoint3 pointLocation = SkPoint3::Make(0, 0, SkIntToScalar(10)); 64 SkPoint3 pointLocation = SkPoint3::Make(0, 0, SkIntToScalar(10));
66 SkScalar kd = SkIntToScalar(2); 65 SkScalar kd = SkIntToScalar(2);
67 SkScalar surfaceScale = SkIntToScalar(1); 66 SkScalar surfaceScale = SkIntToScalar(1);
68 SkIRect bounds; 67 SkIRect bounds;
69 r.roundOut(&bounds); 68 r.roundOut(&bounds);
70 69
71 SkPaint paint; 70 SkPaint paint;
72 canvas->translate(MARGIN, MARGIN); 71 canvas->translate(MARGIN, MARGIN);
73 for (int outset = -15; outset <= 20; outset += 5) { 72 for (int outset = -15; outset <= 20; outset += 5) {
74 canvas->save(); 73 canvas->save();
75 SkRect rect = cropRect.rect(); 74 SkRect rect = cropRect.rect();
76 rect.outset(SkIntToScalar(outset), 75 rect.outset(SkIntToScalar(outset),
77 SkIntToScalar(outset)); 76 SkIntToScalar(outset));
78 SkImageFilter::CropRect bigRect(rect, SkImageFilter::CropRect::kHasA ll_CropEdge); 77 SkImageFilter::CropRect bigRect(rect, SkImageFilter::CropRect::kHasA ll_CropEdge);
79 78
80 Draw(canvas, checkerboard, rect, SkColorFilterImageFilter::Create( 79 Draw(canvas, checkerboard, rect,
81 cfAlphaTrans.get(), noopCropped.get(), &bigRect)); 80 sk_sp<SkImageFilter>(SkColorFilterImageFilter::Create(cfAlphaTr ans.get(),
82 81 noopCropp ed.get(),
83 Draw(canvas, checkerboard, rect, SkBlurImageFilter::Create( 82 &bigRect) ));
84 0.3f, 0.3f, noopCropped.get(), &bigRect));
85
86 Draw(canvas, checkerboard, rect, SkBlurImageFilter::Create(
87 8.0f, 8.0f, noopCropped.get(), &bigRect));
88
89 Draw(canvas, checkerboard, rect, SkDilateImageFilter::Create(
90 2, 2, noopCropped.get(), &bigRect));
91
92 Draw(canvas, checkerboard, rect, SkErodeImageFilter::Create(
93 2, 2, noopCropped.get(), &bigRect));
94
95 Draw(canvas, checkerboard, rect, SkDropShadowImageFilter::Create(
96 SkIntToScalar(10), SkIntToScalar(10), SkIntToScalar(3), SkIntToS calar(3),
97 SK_ColorBLUE, SkDropShadowImageFilter::kDrawShadowAndForeground_ ShadowMode,
98 noopCropped.get(), &bigRect));
99
100 Draw(canvas, checkerboard, rect, SkDisplacementMapEffect::Create(
101 SkDisplacementMapEffect::kR_ChannelSelectorType,
102 SkDisplacementMapEffect::kR_ChannelSelectorType,
103 SkIntToScalar(12),
104 gradientCircleSource.get(),
105 noopCropped.get(),
106 &bigRect));
107
108 Draw(canvas, checkerboard, rect, SkOffsetImageFilter::Create(
109 SkIntToScalar(-8), SkIntToScalar(16), noopCropped.get(), &bigRec t));
110 83
111 Draw(canvas, checkerboard, rect, 84 Draw(canvas, checkerboard, rect,
112 SkLightingImageFilter::CreatePointLitDiffuse(pointLocation, SK_C olorWHITE, 85 sk_sp<SkImageFilter>(SkBlurImageFilter::Create(0.3f, 0.3f,
113 surfaceScale, kd, noopCropped.get(), &bigRect)); 86 noopCropped.get( ),
87 &bigRect)));
88
89 Draw(canvas, checkerboard, rect,
90 sk_sp<SkImageFilter>(SkBlurImageFilter::Create(8.0f, 8.0f,
91 noopCropped.get( ),
92 &bigRect)));
93
94 Draw(canvas, checkerboard, rect,
95 sk_sp<SkImageFilter>(SkDilateImageFilter::Create(2, 2,
96 noopCropped.ge t(),
97 &bigRect)));
98
99 Draw(canvas, checkerboard, rect,
100 sk_sp<SkImageFilter>(SkErodeImageFilter::Create(2, 2,
101 noopCropped.get (),
102 &bigRect)));
103
104 Draw(canvas, checkerboard, rect,
105 sk_sp<SkImageFilter>(SkDropShadowImageFilter::Create(
106 SkIntToScalar(10),
107 SkIntToScalar(10),
108 SkIntToScalar(3),
109 SkIntToScalar(3),
110 SK_ColorBLUE,
111 SkDropShadowImageFilter::kDrawShadowAndForeg round_ShadowMode,
112 noopCropped.get(),
113 &bigRect)));
114
115 Draw(canvas, checkerboard, rect,
116 sk_sp<SkImageFilter>(SkDisplacementMapEffect::Create(
117 SkDisplacementMapEffect::kR_Chan nelSelectorType,
118 SkDisplacementMapEffect::kR_Chan nelSelectorType,
119 SkIntToScalar(12),
120 gradientCircleSource.get(),
121 noopCropped.get(),
122 &bigRect)));
123
124 Draw(canvas, checkerboard, rect,
125 SkOffsetImageFilter::Make(SkIntToScalar(-8), SkIntToScalar(16),
126 noopCropped,
127 &bigRect));
128
129 Draw(canvas, checkerboard, rect,
130 sk_sp<SkImageFilter>(SkLightingImageFilter::CreatePointLitDiffu se(pointLocation,
131 SK_ColorWHITE,
132 surfaceScale,
133 kd,
134 noopCropped.get(),
135 &bigRect)));
114 136
115 canvas->restore(); 137 canvas->restore();
116 canvas->translate(0, SkIntToScalar(80)); 138 canvas->translate(0, SkIntToScalar(80));
117 } 139 }
118 } 140 }
119 141
120 private: 142 private:
121 static void MakeCheckerboard(SkBitmap* bitmap) { 143 static void MakeCheckerboard(SkBitmap* bitmap) {
122 bitmap->allocN32Pixels(64, 64); 144 bitmap->allocN32Pixels(64, 64);
123 SkCanvas canvas(*bitmap); 145 SkCanvas canvas(*bitmap);
(...skipping 26 matching lines...) Expand all
150 colors[0] = SK_ColorWHITE; 172 colors[0] = SK_ColorWHITE;
151 colors[1] = SK_ColorBLACK; 173 colors[1] = SK_ColorBLACK;
152 SkPaint paint; 174 SkPaint paint;
153 paint.setShader(SkGradientShader::MakeRadial(SkPoint::Make(x, y), radius , colors, nullptr, 175 paint.setShader(SkGradientShader::MakeRadial(SkPoint::Make(x, y), radius , colors, nullptr,
154 2, SkShader::kClamp_TileMod e)); 176 2, SkShader::kClamp_TileMod e));
155 canvas->drawCircle(x, y, radius, paint); 177 canvas->drawCircle(x, y, radius, paint);
156 178
157 return surface->makeImageSnapshot(); 179 return surface->makeImageSnapshot();
158 } 180 }
159 181
160 static void Draw(SkCanvas* canvas, const SkBitmap& bitmap, const SkRect& rec t, SkImageFilter* filter) { 182 static void Draw(SkCanvas* canvas, const SkBitmap& bitmap, const SkRect& rec t,
183 sk_sp<SkImageFilter> filter) {
161 SkPaint paint; 184 SkPaint paint;
162 paint.setImageFilter(filter)->unref(); 185 paint.setImageFilter(std::move(filter));
163 canvas->saveLayer(&rect, &paint); 186 canvas->saveLayer(&rect, &paint);
164 canvas->drawBitmap(bitmap, 0, 0); 187 canvas->drawBitmap(bitmap, 0, 0);
165 canvas->restore(); 188 canvas->restore();
166 189
167 SkPaint strokePaint; 190 SkPaint strokePaint;
168 strokePaint.setColor(0xFFFF0000); 191 strokePaint.setColor(0xFFFF0000);
169 strokePaint.setStyle(SkPaint::kStroke_Style); 192 strokePaint.setStyle(SkPaint::kStroke_Style);
170 canvas->drawRect(rect, strokePaint); 193 canvas->drawRect(rect, strokePaint);
171 194
172 canvas->translate(SkIntToScalar(80), 0); 195 canvas->translate(SkIntToScalar(80), 0);
173 } 196 }
174 197
175 typedef GM INHERITED; 198 typedef GM INHERITED;
176 }; 199 };
177 200
178 /////////////////////////////////////////////////////////////////////////////// 201 ///////////////////////////////////////////////////////////////////////////////
179 202
180 DEF_GM( return new ImageFiltersCropExpandGM; ) 203 DEF_GM( return new ImageFiltersCropExpandGM; )
OLDNEW
« no previous file with comments | « gm/imagefiltersclipped.cpp ('k') | gm/imagefilterscropped.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698