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

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

Powered by Google App Engine
This is Rietveld 408576698