OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 #include "gm.h" | 7 #include "gm.h" |
8 #include "SkBitmap.h" | 8 #include "SkBitmap.h" |
9 #include "SkShader.h" | 9 #include "SkShader.h" |
10 #include "SkXfermode.h" | 10 #include "SkXfermode.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 SkPaint labelP; | 34 SkPaint labelP; |
35 labelP.setAntiAlias(true); | 35 labelP.setAntiAlias(true); |
36 sk_tool_utils::set_portable_typeface(&labelP); | 36 sk_tool_utils::set_portable_typeface(&labelP); |
37 labelP.setTextAlign(SkPaint::kCenter_Align); | 37 labelP.setTextAlign(SkPaint::kCenter_Align); |
38 | 38 |
39 const int W = 6; | 39 const int W = 6; |
40 | 40 |
41 SkScalar x = 0, y = 0; | 41 SkScalar x = 0, y = 0; |
42 for (size_t m = 0; m <= SkXfermode::kLastMode; m++) { | 42 for (size_t m = 0; m <= SkXfermode::kLastMode; m++) { |
43 SkXfermode::Mode mode = static_cast<SkXfermode::Mode>(m); | 43 SkXfermode::Mode mode = static_cast<SkXfermode::Mode>(m); |
44 SkXfermode* xm = SkXfermode::Create(mode); | |
45 SkAutoUnref aur(xm); | |
46 | 44 |
47 canvas->save(); | 45 canvas->save(); |
48 | 46 |
49 canvas->translate(x, y); | 47 canvas->translate(x, y); |
50 SkPaint p; | 48 SkPaint p; |
51 p.setAntiAlias(false); | 49 p.setAntiAlias(false); |
52 p.setStyle(SkPaint::kFill_Style); | 50 p.setStyle(SkPaint::kFill_Style); |
53 p.setShader(fBG); | 51 p.setShader(fBG); |
54 SkRect r = SkRect::MakeWH(w, h); | 52 SkRect r = SkRect::MakeWH(w, h); |
55 canvas->drawRect(r, p); | 53 canvas->drawRect(r, p); |
56 | 54 |
57 canvas->saveLayer(&r, nullptr); | 55 canvas->saveLayer(&r, nullptr); |
58 | 56 |
59 p.setShader(fDst); | 57 p.setShader(fDst); |
60 canvas->drawRect(r, p); | 58 canvas->drawRect(r, p); |
61 p.setShader(fSrc); | 59 p.setShader(fSrc); |
62 p.setXfermode(xm); | 60 p.setXfermode(SkXfermode::Make(mode)); |
63 canvas->drawRect(r, p); | 61 canvas->drawRect(r, p); |
64 | 62 |
65 canvas->restore(); | 63 canvas->restore(); |
66 | 64 |
67 r.inset(-SK_ScalarHalf, -SK_ScalarHalf); | 65 r.inset(-SK_ScalarHalf, -SK_ScalarHalf); |
68 p.setStyle(SkPaint::kStroke_Style); | 66 p.setStyle(SkPaint::kStroke_Style); |
69 p.setShader(nullptr); | 67 p.setShader(nullptr); |
70 p.setXfermode(nullptr); | 68 p.setXfermode(nullptr); |
71 canvas->drawRect(r, p); | 69 canvas->drawRect(r, p); |
72 | 70 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 | 138 |
141 typedef GM INHERITED; | 139 typedef GM INHERITED; |
142 }; | 140 }; |
143 | 141 |
144 ////////////////////////////////////////////////////////////////////////////// | 142 ////////////////////////////////////////////////////////////////////////////// |
145 | 143 |
146 static GM* MyFactory(void*) { return new Xfermodes2GM; } | 144 static GM* MyFactory(void*) { return new Xfermodes2GM; } |
147 static GMRegistry reg(MyFactory); | 145 static GMRegistry reg(MyFactory); |
148 | 146 |
149 } | 147 } |
OLD | NEW |