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

Side by Side Diff: gm/xfermodeimagefilter.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/testimagefilters.cpp ('k') | include/effects/SkOffsetImageFilter.h » ('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 2013 Google Inc. 2 * Copyright 2013 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 "sk_tool_utils.h" 9 #include "sk_tool_utils.h"
10 #include "SkArithmeticMode.h" 10 #include "SkArithmeticMode.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 { SkXfermode::kDifference_Mode, "Difference" }, 78 { SkXfermode::kDifference_Mode, "Difference" },
79 { SkXfermode::kExclusion_Mode, "Exclusion" }, 79 { SkXfermode::kExclusion_Mode, "Exclusion" },
80 { SkXfermode::kMultiply_Mode, "Multiply" }, 80 { SkXfermode::kMultiply_Mode, "Multiply" },
81 { SkXfermode::kHue_Mode, "Hue" }, 81 { SkXfermode::kHue_Mode, "Hue" },
82 { SkXfermode::kSaturation_Mode, "Saturation" }, 82 { SkXfermode::kSaturation_Mode, "Saturation" },
83 { SkXfermode::kColor_Mode, "Color" }, 83 { SkXfermode::kColor_Mode, "Color" },
84 { SkXfermode::kLuminosity_Mode, "Luminosity" }, 84 { SkXfermode::kLuminosity_Mode, "Luminosity" },
85 }; 85 };
86 86
87 int x = 0, y = 0; 87 int x = 0, y = 0;
88 SkAutoTUnref<SkImageFilter> background(SkImageSource::Create(fCheckerboa rd.get())); 88 sk_sp<SkImageFilter> background(SkImageSource::Create(fCheckerboard.get( )));
89 for (size_t i = 0; i < SK_ARRAY_COUNT(gModes); i++) { 89 for (size_t i = 0; i < SK_ARRAY_COUNT(gModes); i++) {
90 paint.setImageFilter(SkXfermodeImageFilter::Make(SkXfermode::Make(gM odes[i].fMode), 90 paint.setImageFilter(SkXfermodeImageFilter::Make(SkXfermode::Make(gM odes[i].fMode),
91 background)); 91 background.get()));
92 DrawClippedBitmap(canvas, fBitmap, paint, x, y); 92 DrawClippedBitmap(canvas, fBitmap, paint, x, y);
93 x += fBitmap.width() + MARGIN; 93 x += fBitmap.width() + MARGIN;
94 if (x + fBitmap.width() > WIDTH) { 94 if (x + fBitmap.width() > WIDTH) {
95 x = 0; 95 x = 0;
96 y += fBitmap.height() + MARGIN; 96 y += fBitmap.height() + MARGIN;
97 } 97 }
98 } 98 }
99 // Test arithmetic mode as image filter 99 // Test arithmetic mode as image filter
100 paint.setImageFilter(SkXfermodeImageFilter::Make( 100 paint.setImageFilter(SkXfermodeImageFilter::Make(
101 SkArithmeticMode::Make(0, SK_Scalar1, SK_Scalar1, 0), b ackground)); 101 SkArithmeticMode::Make(0, SK_Scalar1, SK_Scalar1, 0),
102 background.get()));
102 DrawClippedBitmap(canvas, fBitmap, paint, x, y); 103 DrawClippedBitmap(canvas, fBitmap, paint, x, y);
103 x += fBitmap.width() + MARGIN; 104 x += fBitmap.width() + MARGIN;
104 if (x + fBitmap.width() > WIDTH) { 105 if (x + fBitmap.width() > WIDTH) {
105 x = 0; 106 x = 0;
106 y += fBitmap.height() + MARGIN; 107 y += fBitmap.height() + MARGIN;
107 } 108 }
108 // Test nullptr mode 109 // Test nullptr mode
109 paint.setImageFilter(SkXfermodeImageFilter::Make(nullptr, background)); 110 paint.setImageFilter(SkXfermodeImageFilter::Make(nullptr, background.get ()));
110 DrawClippedBitmap(canvas, fBitmap, paint, x, y); 111 DrawClippedBitmap(canvas, fBitmap, paint, x, y);
111 x += fBitmap.width() + MARGIN; 112 x += fBitmap.width() + MARGIN;
112 if (x + fBitmap.width() > WIDTH) { 113 if (x + fBitmap.width() > WIDTH) {
113 x = 0; 114 x = 0;
114 y += fBitmap.height() + MARGIN; 115 y += fBitmap.height() + MARGIN;
115 } 116 }
116 SkRect clipRect = SkRect::MakeWH(SkIntToScalar(fBitmap.width() + 4), 117 SkRect clipRect = SkRect::MakeWH(SkIntToScalar(fBitmap.width() + 4),
117 SkIntToScalar(fBitmap.height() + 4)); 118 SkIntToScalar(fBitmap.height() + 4));
118 // Test offsets on SrcMode (uses fixed-function blend) 119 // Test offsets on SrcMode (uses fixed-function blend)
119 sk_sp<SkImage> bitmapImage(SkImage::MakeFromBitmap(fBitmap)); 120 sk_sp<SkImage> bitmapImage(SkImage::MakeFromBitmap(fBitmap));
120 SkAutoTUnref<SkImageFilter> foreground(SkImageSource::Create(bitmapImage .get())); 121 sk_sp<SkImageFilter> foreground(SkImageSource::Create(bitmapImage.get()) );
121 SkAutoTUnref<SkImageFilter> offsetForeground(SkOffsetImageFilter::Create ( 122 sk_sp<SkImageFilter> offsetForeground(SkOffsetImageFilter::Make(SkIntToS calar(4),
122 SkIntToScalar(4), SkIntToScalar(-4), foreground)); 123 SkIntToS calar(-4),
123 SkAutoTUnref<SkImageFilter> offsetBackground(SkOffsetImageFilter::Create ( 124 foregrou nd));
124 SkIntToScalar(4), SkIntToScalar(4), background)); 125 sk_sp<SkImageFilter> offsetBackground(SkOffsetImageFilter::Make(SkIntToS calar(4),
126 SkIntToS calar(4),
127 backgrou nd));
125 paint.setImageFilter(SkXfermodeImageFilter::Make( 128 paint.setImageFilter(SkXfermodeImageFilter::Make(
126 SkXfermode::Make(SkXfermode::kSrcOver_Mode), offsetBackground, 129 SkXfermode::Make(SkXfermode ::kSrcOver_Mode),
127 offsetForeground, nullptr)); 130 offsetBackground.get(),
131 offsetForeground.get(),
132 nullptr));
128 DrawClippedPaint(canvas, clipRect, paint, x, y); 133 DrawClippedPaint(canvas, clipRect, paint, x, y);
129 x += fBitmap.width() + MARGIN; 134 x += fBitmap.width() + MARGIN;
130 if (x + fBitmap.width() > WIDTH) { 135 if (x + fBitmap.width() > WIDTH) {
131 x = 0; 136 x = 0;
132 y += fBitmap.height() + MARGIN; 137 y += fBitmap.height() + MARGIN;
133 } 138 }
134 // Test offsets on Darken (uses shader blend) 139 // Test offsets on Darken (uses shader blend)
135 paint.setImageFilter(SkXfermodeImageFilter::Make(SkXfermode::Make(SkXfer mode::kDarken_Mode), 140 paint.setImageFilter(SkXfermodeImageFilter::Make(SkXfermode::Make(SkXfer mode::kDarken_Mode),
136 offsetBackground, offsetFor eground, nullptr)); 141 offsetBackground.get(),
142 offsetForeground.get(),
143 nullptr));
137 DrawClippedPaint(canvas, clipRect, paint, x, y); 144 DrawClippedPaint(canvas, clipRect, paint, x, y);
138 x += fBitmap.width() + MARGIN; 145 x += fBitmap.width() + MARGIN;
139 if (x + fBitmap.width() > WIDTH) { 146 if (x + fBitmap.width() > WIDTH) {
140 x = 0; 147 x = 0;
141 y += fBitmap.height() + MARGIN; 148 y += fBitmap.height() + MARGIN;
142 } 149 }
143 // Test cropping 150 // Test cropping
144 static const size_t nbSamples = 3; 151 static const size_t nbSamples = 3;
145 SkXfermode::Mode sampledModes[nbSamples] = {SkXfermode::kOverlay_Mode, 152 SkXfermode::Mode sampledModes[nbSamples] = {SkXfermode::kOverlay_Mode,
146 SkXfermode::kSrcOver_Mode, 153 SkXfermode::kSrcOver_Mode,
147 SkXfermode::kPlus_Mode}; 154 SkXfermode::kPlus_Mode};
148 int offsets[nbSamples][4] = {{ 10, 10, -16, -16}, 155 int offsets[nbSamples][4] = {{ 10, 10, -16, -16},
149 { 10, 10, 10, 10}, 156 { 10, 10, 10, 10},
150 {-10, -10, -6, -6}}; 157 {-10, -10, -6, -6}};
151 for (size_t i = 0; i < nbSamples; ++i) { 158 for (size_t i = 0; i < nbSamples; ++i) {
152 SkIRect cropRect = SkIRect::MakeXYWH(offsets[i][0], 159 SkIRect cropRect = SkIRect::MakeXYWH(offsets[i][0],
153 offsets[i][1], 160 offsets[i][1],
154 fBitmap.width() + offsets[i][2 ], 161 fBitmap.width() + offsets[i][2 ],
155 fBitmap.height() + offsets[i][3 ]); 162 fBitmap.height() + offsets[i][3 ]);
156 SkImageFilter::CropRect rect(SkRect::Make(cropRect)); 163 SkImageFilter::CropRect rect(SkRect::Make(cropRect));
157 paint.setImageFilter(SkXfermodeImageFilter::Make( 164 paint.setImageFilter(SkXfermodeImageFilter::Make(SkXfermode::Make(sa mpledModes[i]),
158 SkXfermode::Make(sampledModes[i]), offsetBackground, offsetF oreground, &rect)); 165 offsetBackground.ge t(),
166 offsetForeground.ge t(),
167 &rect));
159 DrawClippedPaint(canvas, clipRect, paint, x, y); 168 DrawClippedPaint(canvas, clipRect, paint, x, y);
160 x += fBitmap.width() + MARGIN; 169 x += fBitmap.width() + MARGIN;
161 if (x + fBitmap.width() > WIDTH) { 170 if (x + fBitmap.width() > WIDTH) {
162 x = 0; 171 x = 0;
163 y += fBitmap.height() + MARGIN; 172 y += fBitmap.height() + MARGIN;
164 } 173 }
165 } 174 }
166 // Test small bg, large fg with Screen (uses shader blend) 175 // Test small bg, large fg with Screen (uses shader blend)
167 auto mode = SkXfermode::Make(SkXfermode::kScreen_Mode); 176 auto mode = SkXfermode::Make(SkXfermode::kScreen_Mode);
168 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(10, 10, 60, 60)); 177 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(10, 10, 60, 60));
169 SkAutoTUnref<SkImageFilter> cropped( 178 sk_sp<SkImageFilter> cropped(SkOffsetImageFilter::Make(0, 0, foreground, &cropRect));
170 SkOffsetImageFilter::Create(0, 0, foreground, &cropRect)); 179 paint.setImageFilter(SkXfermodeImageFilter::Make(mode, cropped.get(),
171 paint.setImageFilter(SkXfermodeImageFilter::Make(mode, cropped, backgrou nd, nullptr)); 180 background.get(), nullp tr));
172 DrawClippedPaint(canvas, clipRect, paint, x, y); 181 DrawClippedPaint(canvas, clipRect, paint, x, y);
173 x += fBitmap.width() + MARGIN; 182 x += fBitmap.width() + MARGIN;
174 if (x + fBitmap.width() > WIDTH) { 183 if (x + fBitmap.width() > WIDTH) {
175 x = 0; 184 x = 0;
176 y += fBitmap.height() + MARGIN; 185 y += fBitmap.height() + MARGIN;
177 } 186 }
178 // Test small fg, large bg with Screen (uses shader blend) 187 // Test small fg, large bg with Screen (uses shader blend)
179 paint.setImageFilter(SkXfermodeImageFilter::Make(mode, background, cropp ed, nullptr)); 188 paint.setImageFilter(SkXfermodeImageFilter::Make(mode, background.get(),
189 cropped.get(), nullptr) );
180 DrawClippedPaint(canvas, clipRect, paint, x, y); 190 DrawClippedPaint(canvas, clipRect, paint, x, y);
181 x += fBitmap.width() + MARGIN; 191 x += fBitmap.width() + MARGIN;
182 if (x + fBitmap.width() > WIDTH) { 192 if (x + fBitmap.width() > WIDTH) {
183 x = 0; 193 x = 0;
184 y += fBitmap.height() + MARGIN; 194 y += fBitmap.height() + MARGIN;
185 } 195 }
186 // Test small fg, large bg with SrcIn with a crop that forces it to full size. 196 // Test small fg, large bg with SrcIn with a crop that forces it to full size.
187 // This tests that SkXfermodeImageFilter correctly applies the compositi ng mode to 197 // This tests that SkXfermodeImageFilter correctly applies the compositi ng mode to
188 // the region outside the foreground. 198 // the region outside the foreground.
189 mode = SkXfermode::Make(SkXfermode::kSrcIn_Mode); 199 mode = SkXfermode::Make(SkXfermode::kSrcIn_Mode);
190 SkImageFilter::CropRect cropRectFull(SkRect::MakeXYWH(0, 0, 80, 80)); 200 SkImageFilter::CropRect cropRectFull(SkRect::MakeXYWH(0, 0, 80, 80));
191 paint.setImageFilter(SkXfermodeImageFilter::Make(mode, background, cropp ed, &cropRectFull)); 201 paint.setImageFilter(SkXfermodeImageFilter::Make(mode, background.get(),
202 cropped.get(), &cropRec tFull));
192 DrawClippedPaint(canvas, clipRect, paint, x, y); 203 DrawClippedPaint(canvas, clipRect, paint, x, y);
193 x += fBitmap.width() + MARGIN; 204 x += fBitmap.width() + MARGIN;
194 if (x + fBitmap.width() > WIDTH) { 205 if (x + fBitmap.width() > WIDTH) {
195 x = 0; 206 x = 0;
196 y += fBitmap.height() + MARGIN; 207 y += fBitmap.height() + MARGIN;
197 } 208 }
198 } 209 }
199 210
200 private: 211 private:
201 static void DrawClippedBitmap(SkCanvas* canvas, const SkBitmap& bitmap, cons t SkPaint& paint, 212 static void DrawClippedBitmap(SkCanvas* canvas, const SkBitmap& bitmap, cons t SkPaint& paint,
(...skipping 19 matching lines...) Expand all
221 sk_sp<SkImage> fCheckerboard; 232 sk_sp<SkImage> fCheckerboard;
222 233
223 typedef GM INHERITED; 234 typedef GM INHERITED;
224 }; 235 };
225 236
226 ////////////////////////////////////////////////////////////////////////////// 237 //////////////////////////////////////////////////////////////////////////////
227 238
228 DEF_GM( return new XfermodeImageFilterGM; ); 239 DEF_GM( return new XfermodeImageFilterGM; );
229 240
230 } 241 }
OLDNEW
« no previous file with comments | « gm/testimagefilters.cpp ('k') | include/effects/SkOffsetImageFilter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698