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

Side by Side Diff: gm/xfermodeimagefilter.cpp

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