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, | 38 static SkScalar drawCell(SkCanvas* canvas, const sk_sp<SkXfermode>& mode, SkAlph
a a0, SkAlpha a1) { |
39 SkAlpha a0, SkAlpha a1) { | |
40 | |
41 SkPaint paint; | 39 SkPaint paint; |
42 paint.setAntiAlias(true); | 40 paint.setAntiAlias(true); |
43 | 41 |
44 SkRect r = SkRect::MakeWH(W, H); | 42 SkRect r = SkRect::MakeWH(W, H); |
45 r.inset(W/10, H/10); | 43 r.inset(W/10, H/10); |
46 | 44 |
47 paint.setColor(SK_ColorBLUE); | 45 paint.setColor(SK_ColorBLUE); |
48 paint.setAlpha(a0); | 46 paint.setAlpha(a0); |
49 canvas->drawOval(r, paint); | 47 canvas->drawOval(r, paint); |
50 | 48 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 | 100 |
103 for (int alpha = 0; alpha < 4; ++alpha) { | 101 for (int alpha = 0; alpha < 4; ++alpha) { |
104 canvas->save(); | 102 canvas->save(); |
105 canvas->save(); | 103 canvas->save(); |
106 for (size_t i = 0; i < SK_ARRAY_COUNT(gModes); ++i) { | 104 for (size_t i = 0; i < SK_ARRAY_COUNT(gModes); ++i) { |
107 if (6 == i) { | 105 if (6 == i) { |
108 canvas->restore(); | 106 canvas->restore(); |
109 canvas->translate(W * 5, 0); | 107 canvas->translate(W * 5, 0); |
110 canvas->save(); | 108 canvas->save(); |
111 } | 109 } |
112 SkXfermode* mode = SkXfermode::Create(gModes[i].fMode); | 110 sk_sp<SkXfermode> mode = SkXfermode::Make(gModes[i].fMode); |
113 | 111 |
114 canvas->drawRect(bounds, fBGPaint); | 112 canvas->drawRect(bounds, fBGPaint); |
115 canvas->saveLayer(&bounds, nullptr); | 113 canvas->saveLayer(&bounds, nullptr); |
116 SkScalar dy = drawCell(canvas, mode, | 114 SkScalar dy = drawCell(canvas, mode, gAlphaValue[alpha & 1], |
117 gAlphaValue[alpha & 1], | |
118 gAlphaValue[alpha & 2]); | 115 gAlphaValue[alpha & 2]); |
119 canvas->restore(); | 116 canvas->restore(); |
120 | 117 |
121 canvas->translate(0, dy * 5 / 4); | 118 canvas->translate(0, dy * 5 / 4); |
122 SkSafeUnref(mode); | |
123 } | 119 } |
124 canvas->restore(); | 120 canvas->restore(); |
125 canvas->restore(); | 121 canvas->restore(); |
126 canvas->translate(W * 5 / 4, 0); | 122 canvas->translate(W * 5 / 4, 0); |
127 } | 123 } |
128 } | 124 } |
129 | 125 |
130 private: | 126 private: |
131 typedef SampleView INHERITED; | 127 typedef SampleView INHERITED; |
132 }; | 128 }; |
133 | 129 |
134 /////////////////////////////////////////////////////////////////////////////// | 130 /////////////////////////////////////////////////////////////////////////////// |
135 | 131 |
136 static SkView* MyFactory() { return new AARectsModesView; } | 132 static SkView* MyFactory() { return new AARectsModesView; } |
137 static SkViewRegister reg(MyFactory); | 133 static SkViewRegister reg(MyFactory); |
OLD | NEW |