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

Side by Side Diff: gm/xfermodeimagefilter.cpp

Issue 1842243002: Update SkImageSource to sk_sp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: clean up 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
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::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), b ackground)); 101 SkArithmeticMode::Make(0, SK_Scalar1, SK_Scalar1, 0), b ackground.get()));
102 DrawClippedBitmap(canvas, fBitmap, paint, x, y); 102 DrawClippedBitmap(canvas, fBitmap, paint, x, y);
103 x += fBitmap.width() + MARGIN; 103 x += fBitmap.width() + MARGIN;
104 if (x + fBitmap.width() > WIDTH) { 104 if (x + fBitmap.width() > WIDTH) {
105 x = 0; 105 x = 0;
106 y += fBitmap.height() + MARGIN; 106 y += fBitmap.height() + MARGIN;
107 } 107 }
108 // Test nullptr mode 108 // Test nullptr mode
109 paint.setImageFilter(SkXfermodeImageFilter::Make(nullptr, background)); 109 paint.setImageFilter(SkXfermodeImageFilter::Make(nullptr, background.get ()));
110 DrawClippedBitmap(canvas, fBitmap, paint, x, y); 110 DrawClippedBitmap(canvas, fBitmap, paint, x, y);
111 x += fBitmap.width() + MARGIN; 111 x += fBitmap.width() + MARGIN;
112 if (x + fBitmap.width() > WIDTH) { 112 if (x + fBitmap.width() > WIDTH) {
113 x = 0; 113 x = 0;
114 y += fBitmap.height() + MARGIN; 114 y += fBitmap.height() + MARGIN;
115 } 115 }
116 SkRect clipRect = SkRect::MakeWH(SkIntToScalar(fBitmap.width() + 4), 116 SkRect clipRect = SkRect::MakeWH(SkIntToScalar(fBitmap.width() + 4),
117 SkIntToScalar(fBitmap.height() + 4)); 117 SkIntToScalar(fBitmap.height() + 4));
118 // Test offsets on SrcMode (uses fixed-function blend) 118 // Test offsets on SrcMode (uses fixed-function blend)
119 sk_sp<SkImage> bitmapImage(SkImage::MakeFromBitmap(fBitmap)); 119 sk_sp<SkImage> bitmapImage(SkImage::MakeFromBitmap(fBitmap));
120 SkAutoTUnref<SkImageFilter> foreground(SkImageSource::Create(bitmapImage .get())); 120 sk_sp<SkImageFilter> foreground(SkImageSource::Make(std::move(bitmapImag e)));
121 SkAutoTUnref<SkImageFilter> offsetForeground(SkOffsetImageFilter::Create ( 121 SkAutoTUnref<SkImageFilter> offsetForeground(SkOffsetImageFilter::Create (
122 SkIntToScalar(4), SkIntToScalar(-4), foreground)); 122 SkIntToScalar(4), SkIntToScalar(-4), foreground.get()));
123 SkAutoTUnref<SkImageFilter> offsetBackground(SkOffsetImageFilter::Create ( 123 SkAutoTUnref<SkImageFilter> offsetBackground(SkOffsetImageFilter::Create (
124 SkIntToScalar(4), SkIntToScalar(4), background)); 124 SkIntToScalar(4), SkIntToScalar(4), background.get()));
125 paint.setImageFilter(SkXfermodeImageFilter::Make( 125 paint.setImageFilter(SkXfermodeImageFilter::Make(
126 SkXfermode::Make(SkXfermode::kSrcOver_Mode), offsetBackground, 126 SkXfermode::Make(SkXfermode::kSrcOver_Mode), offsetBackground,
127 offsetForeground, nullptr)); 127 offsetForeground, nullptr));
128 DrawClippedPaint(canvas, clipRect, paint, x, y); 128 DrawClippedPaint(canvas, clipRect, paint, x, y);
129 x += fBitmap.width() + MARGIN; 129 x += fBitmap.width() + MARGIN;
130 if (x + fBitmap.width() > WIDTH) { 130 if (x + fBitmap.width() > WIDTH) {
131 x = 0; 131 x = 0;
132 y += fBitmap.height() + MARGIN; 132 y += fBitmap.height() + MARGIN;
133 } 133 }
134 // Test offsets on Darken (uses shader blend) 134 // Test offsets on Darken (uses shader blend)
(...skipping 24 matching lines...) Expand all
159 DrawClippedPaint(canvas, clipRect, paint, x, y); 159 DrawClippedPaint(canvas, clipRect, paint, x, y);
160 x += fBitmap.width() + MARGIN; 160 x += fBitmap.width() + MARGIN;
161 if (x + fBitmap.width() > WIDTH) { 161 if (x + fBitmap.width() > WIDTH) {
162 x = 0; 162 x = 0;
163 y += fBitmap.height() + MARGIN; 163 y += fBitmap.height() + MARGIN;
164 } 164 }
165 } 165 }
166 // Test small bg, large fg with Screen (uses shader blend) 166 // Test small bg, large fg with Screen (uses shader blend)
167 auto mode = SkXfermode::Make(SkXfermode::kScreen_Mode); 167 auto mode = SkXfermode::Make(SkXfermode::kScreen_Mode);
168 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(10, 10, 60, 60)); 168 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(10, 10, 60, 60));
169 SkAutoTUnref<SkImageFilter> cropped( 169 sk_sp<SkImageFilter> cropped(
170 SkOffsetImageFilter::Create(0, 0, foreground, &cropRect)); 170 SkOffsetImageFilter::Create(0, 0, foreground.get(), &cropRect));
171 paint.setImageFilter(SkXfermodeImageFilter::Make(mode, cropped, backgrou nd, nullptr)); 171 paint.setImageFilter(SkXfermodeImageFilter::Make(mode, cropped.get(),
172 background.get(), nullp tr));
172 DrawClippedPaint(canvas, clipRect, paint, x, y); 173 DrawClippedPaint(canvas, clipRect, paint, x, y);
173 x += fBitmap.width() + MARGIN; 174 x += fBitmap.width() + MARGIN;
174 if (x + fBitmap.width() > WIDTH) { 175 if (x + fBitmap.width() > WIDTH) {
175 x = 0; 176 x = 0;
176 y += fBitmap.height() + MARGIN; 177 y += fBitmap.height() + MARGIN;
177 } 178 }
178 // Test small fg, large bg with Screen (uses shader blend) 179 // Test small fg, large bg with Screen (uses shader blend)
179 paint.setImageFilter(SkXfermodeImageFilter::Make(mode, background, cropp ed, nullptr)); 180 paint.setImageFilter(SkXfermodeImageFilter::Make(mode, background.get(),
181 cropped.get(), nullptr) );
180 DrawClippedPaint(canvas, clipRect, paint, x, y); 182 DrawClippedPaint(canvas, clipRect, paint, x, y);
181 x += fBitmap.width() + MARGIN; 183 x += fBitmap.width() + MARGIN;
182 if (x + fBitmap.width() > WIDTH) { 184 if (x + fBitmap.width() > WIDTH) {
183 x = 0; 185 x = 0;
184 y += fBitmap.height() + MARGIN; 186 y += fBitmap.height() + MARGIN;
185 } 187 }
186 } 188 }
187 189
188 private: 190 private:
189 static void DrawClippedBitmap(SkCanvas* canvas, const SkBitmap& bitmap, cons t SkPaint& paint, 191 static void DrawClippedBitmap(SkCanvas* canvas, const SkBitmap& bitmap, cons t SkPaint& paint,
(...skipping 19 matching lines...) Expand all
209 sk_sp<SkImage> fCheckerboard; 211 sk_sp<SkImage> fCheckerboard;
210 212
211 typedef GM INHERITED; 213 typedef GM INHERITED;
212 }; 214 };
213 215
214 ////////////////////////////////////////////////////////////////////////////// 216 //////////////////////////////////////////////////////////////////////////////
215 217
216 DEF_GM( return new XfermodeImageFilterGM; ); 218 DEF_GM( return new XfermodeImageFilterGM; );
217 219
218 } 220 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698