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

Side by Side Diff: gm/xfermodeimagefilter.cpp

Issue 2396953002: Revert[8] "replace SkXfermode obj with SkBlendMode enum in paints" (Closed)
Patch Set: add tmp virtual to unroll legacy arithmodes Created 4 years, 2 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/verylargebitmap.cpp ('k') | gm/xfermodes.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 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 "SkImage.h" 10 #include "SkImage.h"
(...skipping 30 matching lines...) Expand all
41 sk_tool_utils::color_to_56 5(0xFFA0A0A0), 41 sk_tool_utils::color_to_56 5(0xFFA0A0A0),
42 sk_tool_utils::color_to_56 5(0xFF404040), 42 sk_tool_utils::color_to_56 5(0xFF404040),
43 8)); 43 8));
44 } 44 }
45 45
46 void onDraw(SkCanvas* canvas) override { 46 void onDraw(SkCanvas* canvas) override {
47 canvas->clear(SK_ColorBLACK); 47 canvas->clear(SK_ColorBLACK);
48 SkPaint paint; 48 SkPaint paint;
49 49
50 const struct { 50 const struct {
51 SkXfermode::Mode fMode; 51 SkBlendMode fMode;
52 const char* fLabel; 52 const char* fLabel;
53 } gModes[] = { 53 } gModes[] = {
54 { SkXfermode::kClear_Mode, "Clear" }, 54 { SkBlendMode::kClear, "Clear" },
55 { SkXfermode::kSrc_Mode, "Src" }, 55 { SkBlendMode::kSrc, "Src" },
56 { SkXfermode::kDst_Mode, "Dst" }, 56 { SkBlendMode::kDst, "Dst" },
57 { SkXfermode::kSrcOver_Mode, "SrcOver" }, 57 { SkBlendMode::kSrcOver, "SrcOver" },
58 { SkXfermode::kDstOver_Mode, "DstOver" }, 58 { SkBlendMode::kDstOver, "DstOver" },
59 { SkXfermode::kSrcIn_Mode, "SrcIn" }, 59 { SkBlendMode::kSrcIn, "SrcIn" },
60 { SkXfermode::kDstIn_Mode, "DstIn" }, 60 { SkBlendMode::kDstIn, "DstIn" },
61 { SkXfermode::kSrcOut_Mode, "SrcOut" }, 61 { SkBlendMode::kSrcOut, "SrcOut" },
62 { SkXfermode::kDstOut_Mode, "DstOut" }, 62 { SkBlendMode::kDstOut, "DstOut" },
63 { SkXfermode::kSrcATop_Mode, "SrcATop" }, 63 { SkBlendMode::kSrcATop, "SrcATop" },
64 { SkXfermode::kDstATop_Mode, "DstATop" }, 64 { SkBlendMode::kDstATop, "DstATop" },
65 { SkXfermode::kXor_Mode, "Xor" }, 65 { SkBlendMode::kXor, "Xor" },
66 66
67 { SkXfermode::kPlus_Mode, "Plus" }, 67 { SkBlendMode::kPlus, "Plus" },
68 { SkXfermode::kModulate_Mode, "Modulate" }, 68 { SkBlendMode::kModulate, "Modulate" },
69 { SkXfermode::kScreen_Mode, "Screen" }, 69 { SkBlendMode::kScreen, "Screen" },
70 { SkXfermode::kOverlay_Mode, "Overlay" }, 70 { SkBlendMode::kOverlay, "Overlay" },
71 { SkXfermode::kDarken_Mode, "Darken" }, 71 { SkBlendMode::kDarken, "Darken" },
72 { SkXfermode::kLighten_Mode, "Lighten" }, 72 { SkBlendMode::kLighten, "Lighten" },
73 { SkXfermode::kColorDodge_Mode, "ColorDodge" }, 73 { SkBlendMode::kColorDodge, "ColorDodge" },
74 { SkXfermode::kColorBurn_Mode, "ColorBurn" }, 74 { SkBlendMode::kColorBurn, "ColorBurn" },
75 { SkXfermode::kHardLight_Mode, "HardLight" }, 75 { SkBlendMode::kHardLight, "HardLight" },
76 { SkXfermode::kSoftLight_Mode, "SoftLight" }, 76 { SkBlendMode::kSoftLight, "SoftLight" },
77 { SkXfermode::kDifference_Mode, "Difference" }, 77 { SkBlendMode::kDifference, "Difference" },
78 { SkXfermode::kExclusion_Mode, "Exclusion" }, 78 { SkBlendMode::kExclusion, "Exclusion" },
79 { SkXfermode::kMultiply_Mode, "Multiply" }, 79 { SkBlendMode::kMultiply, "Multiply" },
80 { SkXfermode::kHue_Mode, "Hue" }, 80 { SkBlendMode::kHue, "Hue" },
81 { SkXfermode::kSaturation_Mode, "Saturation" }, 81 { SkBlendMode::kSaturation, "Saturation" },
82 { SkXfermode::kColor_Mode, "Color" }, 82 { SkBlendMode::kColor, "Color" },
83 { SkXfermode::kLuminosity_Mode, "Luminosity" }, 83 { SkBlendMode::kLuminosity, "Luminosity" },
84 }; 84 };
85 85
86 int x = 0, y = 0; 86 int x = 0, y = 0;
87 sk_sp<SkImageFilter> background(SkImageSource::Make(fCheckerboard)); 87 sk_sp<SkImageFilter> background(SkImageSource::Make(fCheckerboard));
88 for (size_t i = 0; i < SK_ARRAY_COUNT(gModes); i++) { 88 for (size_t i = 0; i < SK_ARRAY_COUNT(gModes); i++) {
89 paint.setImageFilter(SkXfermodeImageFilter::Make(SkXfermode::Make(gM odes[i].fMode), 89 paint.setImageFilter(SkXfermodeImageFilter::Make(gModes[i].fMode, ba ckground));
90 background));
91 DrawClippedBitmap(canvas, fBitmap, paint, x, y); 90 DrawClippedBitmap(canvas, fBitmap, paint, x, y);
92 x += fBitmap.width() + MARGIN; 91 x += fBitmap.width() + MARGIN;
93 if (x + fBitmap.width() > WIDTH) { 92 if (x + fBitmap.width() > WIDTH) {
94 x = 0; 93 x = 0;
95 y += fBitmap.height() + MARGIN; 94 y += fBitmap.height() + MARGIN;
96 } 95 }
97 } 96 }
98 // Test arithmetic mode as image filter 97 // Test arithmetic mode as image filter
99 paint.setImageFilter(SkXfermodeImageFilter::MakeArithmetic(0, 1, 1, 0, t rue, background)); 98 paint.setImageFilter(SkXfermodeImageFilter::MakeArithmetic(0, 1, 1, 0, t rue, background));
100 DrawClippedBitmap(canvas, fBitmap, paint, x, y); 99 DrawClippedBitmap(canvas, fBitmap, paint, x, y);
101 x += fBitmap.width() + MARGIN; 100 x += fBitmap.width() + MARGIN;
102 if (x + fBitmap.width() > WIDTH) { 101 if (x + fBitmap.width() > WIDTH) {
103 x = 0; 102 x = 0;
104 y += fBitmap.height() + MARGIN; 103 y += fBitmap.height() + MARGIN;
105 } 104 }
106 // Test nullptr mode 105 // Test nullptr mode
107 paint.setImageFilter(SkXfermodeImageFilter::Make(nullptr, background)); 106 paint.setImageFilter(SkXfermodeImageFilter::Make(SkBlendMode::kSrcOver, background));
108 DrawClippedBitmap(canvas, fBitmap, paint, x, y); 107 DrawClippedBitmap(canvas, fBitmap, paint, x, y);
109 x += fBitmap.width() + MARGIN; 108 x += fBitmap.width() + MARGIN;
110 if (x + fBitmap.width() > WIDTH) { 109 if (x + fBitmap.width() > WIDTH) {
111 x = 0; 110 x = 0;
112 y += fBitmap.height() + MARGIN; 111 y += fBitmap.height() + MARGIN;
113 } 112 }
114 SkRect clipRect = SkRect::MakeWH(SkIntToScalar(fBitmap.width() + 4), 113 SkRect clipRect = SkRect::MakeWH(SkIntToScalar(fBitmap.width() + 4),
115 SkIntToScalar(fBitmap.height() + 4)); 114 SkIntToScalar(fBitmap.height() + 4));
116 // Test offsets on SrcMode (uses fixed-function blend) 115 // Test offsets on SrcMode (uses fixed-function blend)
117 sk_sp<SkImage> bitmapImage(SkImage::MakeFromBitmap(fBitmap)); 116 sk_sp<SkImage> bitmapImage(SkImage::MakeFromBitmap(fBitmap));
118 sk_sp<SkImageFilter> foreground(SkImageSource::Make(std::move(bitmapImag e))); 117 sk_sp<SkImageFilter> foreground(SkImageSource::Make(std::move(bitmapImag e)));
119 sk_sp<SkImageFilter> offsetForeground(SkOffsetImageFilter::Make(SkIntToS calar(4), 118 sk_sp<SkImageFilter> offsetForeground(SkOffsetImageFilter::Make(SkIntToS calar(4),
120 SkIntToS calar(-4), 119 SkIntToS calar(-4),
121 foregrou nd)); 120 foregrou nd));
122 sk_sp<SkImageFilter> offsetBackground(SkOffsetImageFilter::Make(SkIntToS calar(4), 121 sk_sp<SkImageFilter> offsetBackground(SkOffsetImageFilter::Make(SkIntToS calar(4),
123 SkIntToS calar(4), 122 SkIntToS calar(4),
124 backgrou nd)); 123 backgrou nd));
125 paint.setImageFilter(SkXfermodeImageFilter::Make( 124 paint.setImageFilter(SkXfermodeImageFilter::Make(SkBlendMode::kSrcOver,
126 SkXfermode::Make(SkXfermode ::kSrcOver_Mode), 125 offsetBackground,
127 offsetBackground, 126 offsetForeground,
128 offsetForeground, 127 nullptr));
129 nullptr));
130 DrawClippedPaint(canvas, clipRect, paint, x, y); 128 DrawClippedPaint(canvas, clipRect, paint, x, y);
131 x += fBitmap.width() + MARGIN; 129 x += fBitmap.width() + MARGIN;
132 if (x + fBitmap.width() > WIDTH) { 130 if (x + fBitmap.width() > WIDTH) {
133 x = 0; 131 x = 0;
134 y += fBitmap.height() + MARGIN; 132 y += fBitmap.height() + MARGIN;
135 } 133 }
136 // Test offsets on Darken (uses shader blend) 134 // Test offsets on Darken (uses shader blend)
137 paint.setImageFilter(SkXfermodeImageFilter::Make(SkXfermode::Make(SkXfer mode::kDarken_Mode), 135 paint.setImageFilter(SkXfermodeImageFilter::Make(SkBlendMode::kDarken,
138 offsetBackground, 136 offsetBackground,
139 offsetForeground, 137 offsetForeground,
140 nullptr)); 138 nullptr));
141 DrawClippedPaint(canvas, clipRect, paint, x, y); 139 DrawClippedPaint(canvas, clipRect, paint, x, y);
142 x += fBitmap.width() + MARGIN; 140 x += fBitmap.width() + MARGIN;
143 if (x + fBitmap.width() > WIDTH) { 141 if (x + fBitmap.width() > WIDTH) {
144 x = 0; 142 x = 0;
145 y += fBitmap.height() + MARGIN; 143 y += fBitmap.height() + MARGIN;
146 } 144 }
147 // Test cropping 145 // Test cropping
148 constexpr size_t nbSamples = 3; 146 constexpr size_t nbSamples = 3;
149 SkXfermode::Mode sampledModes[nbSamples] = {SkXfermode::kOverlay_Mode, 147 const SkBlendMode sampledModes[nbSamples] = {
150 SkXfermode::kSrcOver_Mode, 148 SkBlendMode::kOverlay, SkBlendMode::kSrcOver, SkBlendMode::kPlus
151 SkXfermode::kPlus_Mode}; 149 };
152 int offsets[nbSamples][4] = {{ 10, 10, -16, -16}, 150 int offsets[nbSamples][4] = {{ 10, 10, -16, -16},
153 { 10, 10, 10, 10}, 151 { 10, 10, 10, 10},
154 {-10, -10, -6, -6}}; 152 {-10, -10, -6, -6}};
155 for (size_t i = 0; i < nbSamples; ++i) { 153 for (size_t i = 0; i < nbSamples; ++i) {
156 SkIRect cropRect = SkIRect::MakeXYWH(offsets[i][0], 154 SkIRect cropRect = SkIRect::MakeXYWH(offsets[i][0],
157 offsets[i][1], 155 offsets[i][1],
158 fBitmap.width() + offsets[i][2 ], 156 fBitmap.width() + offsets[i][2 ],
159 fBitmap.height() + offsets[i][3 ]); 157 fBitmap.height() + offsets[i][3 ]);
160 SkImageFilter::CropRect rect(SkRect::Make(cropRect)); 158 SkImageFilter::CropRect rect(SkRect::Make(cropRect));
161 paint.setImageFilter(SkXfermodeImageFilter::Make(SkXfermode::Make(sa mpledModes[i]), 159 paint.setImageFilter(SkXfermodeImageFilter::Make(sampledModes[i],
162 offsetBackground, 160 offsetBackground,
163 offsetForeground, 161 offsetForeground,
164 &rect)); 162 &rect));
165 DrawClippedPaint(canvas, clipRect, paint, x, y); 163 DrawClippedPaint(canvas, clipRect, paint, x, y);
166 x += fBitmap.width() + MARGIN; 164 x += fBitmap.width() + MARGIN;
167 if (x + fBitmap.width() > WIDTH) { 165 if (x + fBitmap.width() > WIDTH) {
168 x = 0; 166 x = 0;
169 y += fBitmap.height() + MARGIN; 167 y += fBitmap.height() + MARGIN;
170 } 168 }
171 } 169 }
172 // Test small bg, large fg with Screen (uses shader blend) 170 // Test small bg, large fg with Screen (uses shader blend)
173 auto mode = SkXfermode::Make(SkXfermode::kScreen_Mode); 171 SkBlendMode mode = SkBlendMode::kScreen;
174 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(10, 10, 60, 60)); 172 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(10, 10, 60, 60));
175 sk_sp<SkImageFilter> cropped(SkOffsetImageFilter::Make(0, 0, foreground, &cropRect)); 173 sk_sp<SkImageFilter> cropped(SkOffsetImageFilter::Make(0, 0, foreground, &cropRect));
176 paint.setImageFilter(SkXfermodeImageFilter::Make(mode, cropped, backgrou nd, nullptr)); 174 paint.setImageFilter(SkXfermodeImageFilter::Make(mode, cropped, backgrou nd, nullptr));
177 DrawClippedPaint(canvas, clipRect, paint, x, y); 175 DrawClippedPaint(canvas, clipRect, paint, x, y);
178 x += fBitmap.width() + MARGIN; 176 x += fBitmap.width() + MARGIN;
179 if (x + fBitmap.width() > WIDTH) { 177 if (x + fBitmap.width() > WIDTH) {
180 x = 0; 178 x = 0;
181 y += fBitmap.height() + MARGIN; 179 y += fBitmap.height() + MARGIN;
182 } 180 }
183 // Test small fg, large bg with Screen (uses shader blend) 181 // Test small fg, large bg with Screen (uses shader blend)
184 paint.setImageFilter(SkXfermodeImageFilter::Make(mode, background, cropp ed, nullptr)); 182 paint.setImageFilter(SkXfermodeImageFilter::Make(mode, background, cropp ed, nullptr));
185 DrawClippedPaint(canvas, clipRect, paint, x, y); 183 DrawClippedPaint(canvas, clipRect, paint, x, y);
186 x += fBitmap.width() + MARGIN; 184 x += fBitmap.width() + MARGIN;
187 if (x + fBitmap.width() > WIDTH) { 185 if (x + fBitmap.width() > WIDTH) {
188 x = 0; 186 x = 0;
189 y += fBitmap.height() + MARGIN; 187 y += fBitmap.height() + MARGIN;
190 } 188 }
191 // Test small fg, large bg with SrcIn with a crop that forces it to full size. 189 // Test small fg, large bg with SrcIn with a crop that forces it to full size.
192 // This tests that SkXfermodeImageFilter correctly applies the compositi ng mode to 190 // This tests that SkXfermodeImageFilter correctly applies the compositi ng mode to
193 // the region outside the foreground. 191 // the region outside the foreground.
194 mode = SkXfermode::Make(SkXfermode::kSrcIn_Mode); 192 mode = SkBlendMode::kSrcIn;
195 SkImageFilter::CropRect cropRectFull(SkRect::MakeXYWH(0, 0, 80, 80)); 193 SkImageFilter::CropRect cropRectFull(SkRect::MakeXYWH(0, 0, 80, 80));
196 paint.setImageFilter(SkXfermodeImageFilter::Make(mode, background, 194 paint.setImageFilter(SkXfermodeImageFilter::Make(mode, background,
197 cropped, &cropRectFull) ); 195 cropped, &cropRectFull) );
198 DrawClippedPaint(canvas, clipRect, paint, x, y); 196 DrawClippedPaint(canvas, clipRect, paint, x, y);
199 x += fBitmap.width() + MARGIN; 197 x += fBitmap.width() + MARGIN;
200 if (x + fBitmap.width() > WIDTH) { 198 if (x + fBitmap.width() > WIDTH) {
201 x = 0; 199 x = 0;
202 y += fBitmap.height() + MARGIN; 200 y += fBitmap.height() + MARGIN;
203 } 201 }
204 } 202 }
(...skipping 22 matching lines...) Expand all
227 sk_sp<SkImage> fCheckerboard; 225 sk_sp<SkImage> fCheckerboard;
228 226
229 typedef GM INHERITED; 227 typedef GM INHERITED;
230 }; 228 };
231 229
232 ////////////////////////////////////////////////////////////////////////////// 230 //////////////////////////////////////////////////////////////////////////////
233 231
234 DEF_GM( return new XfermodeImageFilterGM; ); 232 DEF_GM( return new XfermodeImageFilterGM; );
235 233
236 } 234 }
OLDNEW
« no previous file with comments | « gm/verylargebitmap.cpp ('k') | gm/xfermodes.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698