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

Side by Side Diff: gm/xfermodes.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 2011 Google Inc. 2 * Copyright 2011 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 "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkShader.h" 10 #include "SkShader.h"
11 #include "SkXfermode.h" 11 #include "SkXfermode.h"
12 #include "SkPM4f.h" 12 #include "SkPM4f.h"
13 13
14 #include "SkArithmeticMode.h" 14 #include "SkArithmeticMode.h"
15 #include "SkPixelXorXfermode.h" 15 #include "SkPixelXorXfermode.h"
16 #include "SkAvoidXfermode.h" 16 #include "SkAvoidXfermode.h"
17 17
18 #define kCustomShift 16 18 #define kCustomShift 16
19 #define kCustomMask (~0xFFFF) 19 #define kCustomMask (~0xFFFF)
20 20
21 enum CustomModes { 21 enum CustomModes {
22 kArithmetic_CustomMode = 1 << kCustomShift, 22 kArithmetic_CustomMode = 1 << kCustomShift,
23 kPixelXor_CustomMode = 2 << kCustomShift, 23 kPixelXor_CustomMode = 2 << kCustomShift,
24 kAvoid_CustomMode = 3 << kCustomShift, 24 kAvoid_CustomMode = 3 << kCustomShift,
25 }; 25 };
26 26
27 static SkXfermode* make_custom(int customMode) { 27 static sk_sp<SkXfermode> make_custom(int customMode) {
28 switch (customMode) { 28 switch (customMode) {
29 case kArithmetic_CustomMode: { 29 case kArithmetic_CustomMode: {
30 const SkScalar k1 = 0.25; 30 const SkScalar k1 = 0.25;
31 const SkScalar k2 = 0.75; 31 const SkScalar k2 = 0.75;
32 const SkScalar k3 = 0.75; 32 const SkScalar k3 = 0.75;
33 const SkScalar k4 = -0.25; 33 const SkScalar k4 = -0.25;
34 return SkArithmeticMode::Create(k1, k2, k3, k4); 34 return SkArithmeticMode::Make(k1, k2, k3, k4);
35 } 35 }
36 case kPixelXor_CustomMode: 36 case kPixelXor_CustomMode:
37 return SkPixelXorXfermode::Create(0xFF88CC44); 37 return SkPixelXorXfermode::Make(0xFF88CC44);
38 case kAvoid_CustomMode: 38 case kAvoid_CustomMode:
39 return SkAvoidXfermode::Create(0xFFFF0000, 0x44, SkAvoidXfermode::kA voidColor_Mode); 39 return SkAvoidXfermode::Make(0xFFFF0000, 0x44, SkAvoidXfermode::kAvo idColor_Mode);
40 default: 40 default:
41 break; 41 break;
42 } 42 }
43 SkASSERT(false); 43 SkASSERT(false);
44 return nullptr; 44 return nullptr;
45 } 45 }
46 46
47 enum SrcType { 47 enum SrcType {
48 //! A WxH image with a rectangle in the lower right. 48 //! A WxH image with a rectangle in the lower right.
49 kRectangleImage_SrcType = 0x01, 49 kRectangleImage_SrcType = 0x01,
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 static uint16_t gData[] = { 0xFFFF, 0xCCCF, 0xCCCF, 0xFFFF }; 148 static uint16_t gData[] = { 0xFFFF, 0xCCCF, 0xCCCF, 0xFFFF };
149 149
150 class XfermodesGM : public skiagm::GM { 150 class XfermodesGM : public skiagm::GM {
151 SkBitmap fBG; 151 SkBitmap fBG;
152 SkBitmap fSrcB, fDstB, fTransparent; 152 SkBitmap fSrcB, fDstB, fTransparent;
153 153
154 /* The srcType argument indicates what to draw for the source part. Skia 154 /* The srcType argument indicates what to draw for the source part. Skia
155 * uses the implied shape of the drawing command and these modes 155 * uses the implied shape of the drawing command and these modes
156 * demonstrate that. 156 * demonstrate that.
157 */ 157 */
158 void draw_mode(SkCanvas* canvas, SkXfermode* mode, SrcType srcType, 158 void draw_mode(SkCanvas* canvas, sk_sp<SkXfermode> mode, SrcType srcType,
159 SkScalar x, SkScalar y) { 159 SkScalar x, SkScalar y) {
160 SkPaint p; 160 SkPaint p;
161 SkMatrix m; 161 SkMatrix m;
162 bool restoreNeeded = false; 162 bool restoreNeeded = false;
163 m.setTranslate(x, y); 163 m.setTranslate(x, y);
164 164
165 canvas->drawBitmap(fSrcB, x, y, &p); 165 canvas->drawBitmap(fSrcB, x, y, &p);
166 p.setXfermode(mode); 166 p.setXfermode(std::move(mode));
167 switch (srcType) { 167 switch (srcType) {
168 case kSmallTransparentImage_SrcType: { 168 case kSmallTransparentImage_SrcType: {
169 m.postScale(SK_ScalarHalf, SK_ScalarHalf, x, y); 169 m.postScale(SK_ScalarHalf, SK_ScalarHalf, x, y);
170 170
171 SkAutoCanvasRestore acr(canvas, true); 171 SkAutoCanvasRestore acr(canvas, true);
172 canvas->concat(m); 172 canvas->concat(m);
173 canvas->drawBitmap(fTransparent, 0, 0, &p); 173 canvas->drawBitmap(fTransparent, 0, 0, &p);
174 break; 174 break;
175 } 175 }
176 case kQuarterClearInLayer_SrcType: { 176 case kQuarterClearInLayer_SrcType: {
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 const int W = 5; 272 const int W = 5;
273 273
274 SkScalar x0 = 0; 274 SkScalar x0 = 0;
275 SkScalar y0 = 0; 275 SkScalar y0 = 0;
276 for (int sourceType = 1; sourceType & kAll_SrcType; sourceType <<= 1) { 276 for (int sourceType = 1; sourceType & kAll_SrcType; sourceType <<= 1) {
277 SkScalar x = x0, y = y0; 277 SkScalar x = x0, y = y0;
278 for (size_t i = 0; i < SK_ARRAY_COUNT(gModes); i++) { 278 for (size_t i = 0; i < SK_ARRAY_COUNT(gModes); i++) {
279 if ((gModes[i].fSourceTypeMask & sourceType) == 0) { 279 if ((gModes[i].fSourceTypeMask & sourceType) == 0) {
280 continue; 280 continue;
281 } 281 }
282 SkAutoTUnref<SkXfermode> mode; 282 sk_sp<SkXfermode> mode;
283 if (gModes[i].fSourceTypeMask & kCustomMask) { 283 if (gModes[i].fSourceTypeMask & kCustomMask) {
284 mode.reset(make_custom(gModes[i].fSourceTypeMask & kCustomMa sk)); 284 mode = make_custom(gModes[i].fSourceTypeMask & kCustomMask);
285 } else { 285 } else {
286 mode.reset(SkXfermode::Create(gModes[i].fMode)); 286 mode = SkXfermode::Make(gModes[i].fMode);
287 } 287 }
288 SkRect r; 288 SkRect r;
289 r.set(x, y, x+w, y+h); 289 r.set(x, y, x+w, y+h);
290 290
291 SkPaint p; 291 SkPaint p;
292 p.setStyle(SkPaint::kFill_Style); 292 p.setStyle(SkPaint::kFill_Style);
293 p.setShader(s); 293 p.setShader(s);
294 canvas->drawRect(r, p); 294 canvas->drawRect(r, p);
295 295
296 canvas->saveLayer(&r, nullptr); 296 canvas->saveLayer(&r, nullptr);
297 draw_mode(canvas, mode, static_cast<SrcType>(sourceType), 297 draw_mode(canvas, std::move(mode), static_cast<SrcType>(sourceTy pe),
298 r.fLeft, r.fTop); 298 r.fLeft, r.fTop);
299 canvas->restore(); 299 canvas->restore();
300 300
301 r.inset(-SK_ScalarHalf, -SK_ScalarHalf); 301 r.inset(-SK_ScalarHalf, -SK_ScalarHalf);
302 p.setStyle(SkPaint::kStroke_Style); 302 p.setStyle(SkPaint::kStroke_Style);
303 p.setShader(nullptr); 303 p.setShader(nullptr);
304 canvas->drawRect(r, p); 304 canvas->drawRect(r, p);
305 305
306 #if 1 306 #if 1
307 canvas->drawText(gModes[i].fLabel, strlen(gModes[i].fLabel), 307 canvas->drawText(gModes[i].fLabel, strlen(gModes[i].fLabel),
(...skipping 14 matching lines...) Expand all
322 x0 += SkIntToScalar(400); 322 x0 += SkIntToScalar(400);
323 y0 = 0; 323 y0 = 0;
324 } 324 }
325 } 325 }
326 } 326 }
327 327
328 private: 328 private:
329 typedef GM INHERITED; 329 typedef GM INHERITED;
330 }; 330 };
331 DEF_GM( return new XfermodesGM; ) 331 DEF_GM( return new XfermodesGM; )
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698