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

Side by Side Diff: gm/aaxfermodes.cpp

Issue 1832223002: switch xfermodes over to sk_sp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase 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 2015 Google Inc. 2 * Copyright 2015 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 #include "gm.h" 7 #include "gm.h"
8 #include "SkArithmeticMode.h" 8 #include "SkArithmeticMode.h"
9 #include "SkPath.h" 9 #include "SkPath.h"
10 #include "SkShader.h" 10 #include "SkShader.h"
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 if (mode == SkXfermode::kPlus_Mode) { 203 if (mode == SkXfermode::kPlus_Mode) {
204 // Check for overflow, otherwise we might get confusing AA artifacts . 204 // Check for overflow, otherwise we might get confusing AA artifacts .
205 int maxSum = SkTMax(SkTMax(SkColorGetA(kBGColor) + SkColorGetA(color ), 205 int maxSum = SkTMax(SkTMax(SkColorGetA(kBGColor) + SkColorGetA(color ),
206 SkColorGetR(kBGColor) + SkColorGetR(color )), 206 SkColorGetR(kBGColor) + SkColorGetR(color )),
207 SkTMax(SkColorGetG(kBGColor) + SkColorGetG(color ), 207 SkTMax(SkColorGetG(kBGColor) + SkColorGetG(color ),
208 SkColorGetB(kBGColor) + SkColorGetB(color ))); 208 SkColorGetB(kBGColor) + SkColorGetB(color )));
209 209
210 if (maxSum > 255) { 210 if (maxSum > 255) {
211 SkPaint dimPaint; 211 SkPaint dimPaint;
212 dimPaint.setAntiAlias(false); 212 dimPaint.setAntiAlias(false);
213 dimPaint.setXfermode(SkXfermode::Create(SkXfermode::kDstIn_Mode) ); 213 dimPaint.setXfermode(SkXfermode::Make(SkXfermode::kDstIn_Mode));
214 if (255 != paint->getAlpha()) { 214 if (255 != paint->getAlpha()) {
215 // Dim the src and dst colors. 215 // Dim the src and dst colors.
216 dimPaint.setARGB(255 * 255 / maxSum, 0, 0, 0); 216 dimPaint.setARGB(255 * 255 / maxSum, 0, 0, 0);
217 paint->setAlpha(255 * paint->getAlpha() / maxSum); 217 paint->setAlpha(255 * paint->getAlpha() / maxSum);
218 } else { 218 } else {
219 // Just clear the dst, we need to preserve the paint's opaci ty. 219 // Just clear the dst, we need to preserve the paint's opaci ty.
220 dimPaint.setARGB(0, 0, 0, 0); 220 dimPaint.setARGB(0, 0, 0, 0);
221 } 221 }
222 canvas->drawRectCoords(-kShapeSpacing/2, -kShapeSpacing/2, 222 canvas->drawRectCoords(-kShapeSpacing/2, -kShapeSpacing/2,
223 kShapeSpacing/2 + 3 * kShapeTypeSpacing, 223 kShapeSpacing/2 + 3 * kShapeTypeSpacing,
224 kShapeSpacing/2, dimPaint); 224 kShapeSpacing/2, dimPaint);
225 } 225 }
226 } 226 }
227 } 227 }
228 228
229 void drawShape(SkCanvas* canvas, Shape shape, const SkPaint& paint, SkXfermo de::Mode mode) { 229 void drawShape(SkCanvas* canvas, Shape shape, const SkPaint& paint, SkXfermo de::Mode mode) {
230 SkPaint shapePaint(paint); 230 SkPaint shapePaint(paint);
231 shapePaint.setAntiAlias(kSquare_Shape != shape); 231 shapePaint.setAntiAlias(kSquare_Shape != shape);
232 232
233 SkAutoTUnref<SkXfermode> xfermode; 233 sk_sp<SkXfermode> xfermode;
234 if (mode <= SkXfermode::kLastMode) { 234 if (mode <= SkXfermode::kLastMode) {
235 xfermode.reset(SkXfermode::Create(mode)); 235 xfermode = SkXfermode::Make(mode);
236 } else { 236 } else {
237 xfermode.reset(SkArithmeticMode::Create(+1.0f, +0.25f, -0.5f, +0.1f) ); 237 xfermode = SkArithmeticMode::Make(+1.0f, +0.25f, -0.5f, +0.1f);
238 } 238 }
239 shapePaint.setXfermode(xfermode); 239 shapePaint.setXfermode(std::move(xfermode));
240 240
241 switch (shape) { 241 switch (shape) {
242 case kSquare_Shape: 242 case kSquare_Shape:
243 canvas->drawRectCoords(-kShapeSize/2, -kShapeSize/2, kShapeSize/ 2, kShapeSize/2, 243 canvas->drawRectCoords(-kShapeSize/2, -kShapeSize/2, kShapeSize/ 2, kShapeSize/2,
244 shapePaint); 244 shapePaint);
245 break; 245 break;
246 246
247 case kDiamond_Shape: 247 case kDiamond_Shape:
248 canvas->save(); 248 canvas->save();
249 canvas->rotate(45); 249 canvas->rotate(45);
(...skipping 25 matching lines...) Expand all
275 275
276 typedef GM INHERITED; 276 typedef GM INHERITED;
277 }; 277 };
278 278
279 ////////////////////////////////////////////////////////////////////////////// 279 //////////////////////////////////////////////////////////////////////////////
280 280
281 static GM* MyFactory(void*) { return new AAXfermodesGM; } 281 static GM* MyFactory(void*) { return new AAXfermodesGM; }
282 static GMRegistry reg(MyFactory); 282 static GMRegistry reg(MyFactory);
283 283
284 } 284 }
OLDNEW
« no previous file with comments | « gm/aarectmodes.cpp ('k') | gm/arithmode.cpp » ('j') | include/effects/SkXfermodeImageFilter.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698