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

Side by Side Diff: gm/xfermodeimagefilter.cpp

Issue 1852123002: Update SkXfermodeImageFilter to sk_sp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Overload Make methods 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/imagefiltersgraph.cpp ('k') | include/effects/SkXfermodeImageFilter.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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 sk_sp<SkImageFilter> background(SkImageSource::Make(fCheckerboard)); 88 sk_sp<SkImageFilter> background(SkImageSource::Make(fCheckerboard));
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.get())); 91 background));
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.get())); 101 SkArithmeticMode::Make(0, SK_Scalar1, SK_Scalar1, 0),
102 background));
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.get ())); 110 paint.setImageFilter(SkXfermodeImageFilter::Make(nullptr, background));
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 sk_sp<SkImageFilter> foreground(SkImageSource::Make(std::move(bitmapImag e))); 121 sk_sp<SkImageFilter> foreground(SkImageSource::Make(std::move(bitmapImag e)));
121 sk_sp<SkImageFilter> offsetForeground(SkOffsetImageFilter::Make(SkIntToS calar(4), 122 sk_sp<SkImageFilter> offsetForeground(SkOffsetImageFilter::Make(SkIntToS calar(4),
122 SkIntToS calar(-4), 123 SkIntToS calar(-4),
123 foregrou nd)); 124 foregrou nd));
124 sk_sp<SkImageFilter> offsetBackground(SkOffsetImageFilter::Make(SkIntToS calar(4), 125 sk_sp<SkImageFilter> offsetBackground(SkOffsetImageFilter::Make(SkIntToS calar(4),
125 SkIntToS calar(4), 126 SkIntToS calar(4),
126 backgrou nd)); 127 backgrou nd));
127 paint.setImageFilter(SkXfermodeImageFilter::Make( 128 paint.setImageFilter(SkXfermodeImageFilter::Make(
128 SkXfermode::Make(SkXfermode ::kSrcOver_Mode), 129 SkXfermode::Make(SkXfermode ::kSrcOver_Mode),
129 offsetBackground.get(), 130 offsetBackground,
130 offsetForeground.get(), 131 offsetForeground,
131 nullptr)); 132 nullptr));
132 DrawClippedPaint(canvas, clipRect, paint, x, y); 133 DrawClippedPaint(canvas, clipRect, paint, x, y);
133 x += fBitmap.width() + MARGIN; 134 x += fBitmap.width() + MARGIN;
134 if (x + fBitmap.width() > WIDTH) { 135 if (x + fBitmap.width() > WIDTH) {
135 x = 0; 136 x = 0;
136 y += fBitmap.height() + MARGIN; 137 y += fBitmap.height() + MARGIN;
137 } 138 }
138 // Test offsets on Darken (uses shader blend) 139 // Test offsets on Darken (uses shader blend)
139 paint.setImageFilter(SkXfermodeImageFilter::Make(SkXfermode::Make(SkXfer mode::kDarken_Mode), 140 paint.setImageFilter(SkXfermodeImageFilter::Make(SkXfermode::Make(SkXfer mode::kDarken_Mode),
140 offsetBackground.get(), 141 offsetBackground,
141 offsetForeground.get(), 142 offsetForeground,
142 nullptr)); 143 nullptr));
143 DrawClippedPaint(canvas, clipRect, paint, x, y); 144 DrawClippedPaint(canvas, clipRect, paint, x, y);
144 x += fBitmap.width() + MARGIN; 145 x += fBitmap.width() + MARGIN;
145 if (x + fBitmap.width() > WIDTH) { 146 if (x + fBitmap.width() > WIDTH) {
146 x = 0; 147 x = 0;
147 y += fBitmap.height() + MARGIN; 148 y += fBitmap.height() + MARGIN;
148 } 149 }
149 // Test cropping 150 // Test cropping
150 static const size_t nbSamples = 3; 151 static const size_t nbSamples = 3;
151 SkXfermode::Mode sampledModes[nbSamples] = {SkXfermode::kOverlay_Mode, 152 SkXfermode::Mode sampledModes[nbSamples] = {SkXfermode::kOverlay_Mode,
152 SkXfermode::kSrcOver_Mode, 153 SkXfermode::kSrcOver_Mode,
153 SkXfermode::kPlus_Mode}; 154 SkXfermode::kPlus_Mode};
154 int offsets[nbSamples][4] = {{ 10, 10, -16, -16}, 155 int offsets[nbSamples][4] = {{ 10, 10, -16, -16},
155 { 10, 10, 10, 10}, 156 { 10, 10, 10, 10},
156 {-10, -10, -6, -6}}; 157 {-10, -10, -6, -6}};
157 for (size_t i = 0; i < nbSamples; ++i) { 158 for (size_t i = 0; i < nbSamples; ++i) {
158 SkIRect cropRect = SkIRect::MakeXYWH(offsets[i][0], 159 SkIRect cropRect = SkIRect::MakeXYWH(offsets[i][0],
159 offsets[i][1], 160 offsets[i][1],
160 fBitmap.width() + offsets[i][2 ], 161 fBitmap.width() + offsets[i][2 ],
161 fBitmap.height() + offsets[i][3 ]); 162 fBitmap.height() + offsets[i][3 ]);
162 SkImageFilter::CropRect rect(SkRect::Make(cropRect)); 163 SkImageFilter::CropRect rect(SkRect::Make(cropRect));
163 paint.setImageFilter(SkXfermodeImageFilter::Make(SkXfermode::Make(sa mpledModes[i]), 164 paint.setImageFilter(SkXfermodeImageFilter::Make(SkXfermode::Make(sa mpledModes[i]),
164 offsetBackground.ge t(), 165 offsetBackground,
165 offsetForeground.ge t(), 166 offsetForeground,
166 &rect)); 167 &rect));
167 DrawClippedPaint(canvas, clipRect, paint, x, y); 168 DrawClippedPaint(canvas, clipRect, paint, x, y);
168 x += fBitmap.width() + MARGIN; 169 x += fBitmap.width() + MARGIN;
169 if (x + fBitmap.width() > WIDTH) { 170 if (x + fBitmap.width() > WIDTH) {
170 x = 0; 171 x = 0;
171 y += fBitmap.height() + MARGIN; 172 y += fBitmap.height() + MARGIN;
172 } 173 }
173 } 174 }
174 // Test small bg, large fg with Screen (uses shader blend) 175 // Test small bg, large fg with Screen (uses shader blend)
175 auto mode = SkXfermode::Make(SkXfermode::kScreen_Mode); 176 auto mode = SkXfermode::Make(SkXfermode::kScreen_Mode);
176 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(10, 10, 60, 60)); 177 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(10, 10, 60, 60));
177 sk_sp<SkImageFilter> cropped(SkOffsetImageFilter::Make(0, 0, foreground, &cropRect)); 178 sk_sp<SkImageFilter> cropped(SkOffsetImageFilter::Make(0, 0, foreground, &cropRect));
178 paint.setImageFilter(SkXfermodeImageFilter::Make(mode, cropped.get(), 179 paint.setImageFilter(SkXfermodeImageFilter::Make(mode, cropped, backgrou nd, nullptr));
179 background.get(), nullp tr));
180 DrawClippedPaint(canvas, clipRect, paint, x, y); 180 DrawClippedPaint(canvas, clipRect, paint, x, y);
181 x += fBitmap.width() + MARGIN; 181 x += fBitmap.width() + MARGIN;
182 if (x + fBitmap.width() > WIDTH) { 182 if (x + fBitmap.width() > WIDTH) {
183 x = 0; 183 x = 0;
184 y += fBitmap.height() + MARGIN; 184 y += fBitmap.height() + MARGIN;
185 } 185 }
186 // Test small fg, large bg with Screen (uses shader blend) 186 // Test small fg, large bg with Screen (uses shader blend)
187 paint.setImageFilter(SkXfermodeImageFilter::Make(mode, background.get(), 187 paint.setImageFilter(SkXfermodeImageFilter::Make(mode, background, cropp ed, nullptr));
188 cropped.get(), nullptr) );
189 DrawClippedPaint(canvas, clipRect, paint, x, y); 188 DrawClippedPaint(canvas, clipRect, paint, x, y);
190 x += fBitmap.width() + MARGIN; 189 x += fBitmap.width() + MARGIN;
191 if (x + fBitmap.width() > WIDTH) { 190 if (x + fBitmap.width() > WIDTH) {
192 x = 0; 191 x = 0;
193 y += fBitmap.height() + MARGIN; 192 y += fBitmap.height() + MARGIN;
194 } 193 }
195 // Test small fg, large bg with SrcIn with a crop that forces it to full size. 194 // Test small fg, large bg with SrcIn with a crop that forces it to full size.
196 // This tests that SkXfermodeImageFilter correctly applies the compositi ng mode to 195 // This tests that SkXfermodeImageFilter correctly applies the compositi ng mode to
197 // the region outside the foreground. 196 // the region outside the foreground.
198 mode = SkXfermode::Make(SkXfermode::kSrcIn_Mode); 197 mode = SkXfermode::Make(SkXfermode::kSrcIn_Mode);
199 SkImageFilter::CropRect cropRectFull(SkRect::MakeXYWH(0, 0, 80, 80)); 198 SkImageFilter::CropRect cropRectFull(SkRect::MakeXYWH(0, 0, 80, 80));
200 paint.setImageFilter(SkXfermodeImageFilter::Make(mode, background.get(), 199 paint.setImageFilter(SkXfermodeImageFilter::Make(mode, background,
201 cropped.get(), &cropRec tFull)); 200 cropped, &cropRectFull) );
202 DrawClippedPaint(canvas, clipRect, paint, x, y); 201 DrawClippedPaint(canvas, clipRect, paint, x, y);
203 x += fBitmap.width() + MARGIN; 202 x += fBitmap.width() + MARGIN;
204 if (x + fBitmap.width() > WIDTH) { 203 if (x + fBitmap.width() > WIDTH) {
205 x = 0; 204 x = 0;
206 y += fBitmap.height() + MARGIN; 205 y += fBitmap.height() + MARGIN;
207 } 206 }
208 } 207 }
209 208
210 private: 209 private:
211 static void DrawClippedBitmap(SkCanvas* canvas, const SkBitmap& bitmap, cons t SkPaint& paint, 210 static void DrawClippedBitmap(SkCanvas* canvas, const SkBitmap& bitmap, cons t SkPaint& paint,
(...skipping 19 matching lines...) Expand all
231 sk_sp<SkImage> fCheckerboard; 230 sk_sp<SkImage> fCheckerboard;
232 231
233 typedef GM INHERITED; 232 typedef GM INHERITED;
234 }; 233 };
235 234
236 ////////////////////////////////////////////////////////////////////////////// 235 //////////////////////////////////////////////////////////////////////////////
237 236
238 DEF_GM( return new XfermodeImageFilterGM; ); 237 DEF_GM( return new XfermodeImageFilterGM; );
239 238
240 } 239 }
OLDNEW
« no previous file with comments | « gm/imagefiltersgraph.cpp ('k') | include/effects/SkXfermodeImageFilter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698