OLD | NEW |
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 Loading... |
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 Loading... |
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); |
OLD | NEW |