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

Side by Side Diff: samplecode/SampleHairModes.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 "SampleCode.h" 8 #include "SampleCode.h"
9 #include "SkView.h" 9 #include "SkView.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 17 matching lines...) Expand all
28 { SkXfermode::kSrcATop_Mode, "SrcATop" }, 28 { SkXfermode::kSrcATop_Mode, "SrcATop" },
29 { SkXfermode::kDstATop_Mode, "DstATop" }, 29 { SkXfermode::kDstATop_Mode, "DstATop" },
30 { SkXfermode::kXor_Mode, "Xor" }, 30 { SkXfermode::kXor_Mode, "Xor" },
31 }; 31 };
32 32
33 const int gWidth = 64; 33 const int gWidth = 64;
34 const int gHeight = 64; 34 const int gHeight = 64;
35 const SkScalar W = SkIntToScalar(gWidth); 35 const SkScalar W = SkIntToScalar(gWidth);
36 const SkScalar H = SkIntToScalar(gHeight); 36 const SkScalar H = SkIntToScalar(gHeight);
37 37
38 static SkScalar drawCell(SkCanvas* canvas, SkXfermode* mode, SkAlpha a0, SkAlpha a1) { 38 static SkScalar drawCell(SkCanvas* canvas, sk_sp<SkXfermode> mode, SkAlpha a0, S kAlpha a1) {
39
40 SkPaint paint; 39 SkPaint paint;
41 paint.setAntiAlias(true); 40 paint.setAntiAlias(true);
42 41
43 SkRect r = SkRect::MakeWH(W, H); 42 SkRect r = SkRect::MakeWH(W, H);
44 r.inset(W/10, H/10); 43 r.inset(W/10, H/10);
45 44
46 paint.setColor(SK_ColorBLUE); 45 paint.setColor(SK_ColorBLUE);
47 paint.setAlpha(a0); 46 paint.setAlpha(a0);
48 canvas->drawOval(r, paint); 47 canvas->drawOval(r, paint);
49 48
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 97
99 for (int alpha = 0; alpha < 4; ++alpha) { 98 for (int alpha = 0; alpha < 4; ++alpha) {
100 canvas->save(); 99 canvas->save();
101 canvas->save(); 100 canvas->save();
102 for (size_t i = 0; i < SK_ARRAY_COUNT(gModes); ++i) { 101 for (size_t i = 0; i < SK_ARRAY_COUNT(gModes); ++i) {
103 if (6 == i) { 102 if (6 == i) {
104 canvas->restore(); 103 canvas->restore();
105 canvas->translate(W * 5, 0); 104 canvas->translate(W * 5, 0);
106 canvas->save(); 105 canvas->save();
107 } 106 }
108 SkXfermode* mode = SkXfermode::Create(gModes[i].fMode);
109
110 canvas->drawRect(bounds, fBGPaint); 107 canvas->drawRect(bounds, fBGPaint);
111 canvas->saveLayer(&bounds, nullptr); 108 canvas->saveLayer(&bounds, nullptr);
112 SkScalar dy = drawCell(canvas, mode, 109 SkScalar dy = drawCell(canvas, SkXfermode::Make(gModes[i].fMode) ,
113 gAlphaValue[alpha & 1], 110 gAlphaValue[alpha & 1],
114 gAlphaValue[alpha & 2]); 111 gAlphaValue[alpha & 2]);
115 canvas->restore(); 112 canvas->restore();
116 113
117 canvas->translate(0, dy * 5 / 4); 114 canvas->translate(0, dy * 5 / 4);
118 SkSafeUnref(mode);
119 } 115 }
120 canvas->restore(); 116 canvas->restore();
121 canvas->restore(); 117 canvas->restore();
122 canvas->translate(W * 5 / 4, 0); 118 canvas->translate(W * 5 / 4, 0);
123 } 119 }
124 } 120 }
125 121
126 private: 122 private:
127 typedef SampleView INHERITED; 123 typedef SampleView INHERITED;
128 }; 124 };
129 125
130 /////////////////////////////////////////////////////////////////////////////// 126 ///////////////////////////////////////////////////////////////////////////////
131 127
132 static SkView* MyFactory() { return new HairModesView; } 128 static SkView* MyFactory() { return new HairModesView; }
133 static SkViewRegister reg(MyFactory); 129 static SkViewRegister reg(MyFactory);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698