OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
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 | 12 |
13 namespace skiagm { | 13 namespace skiagm { |
14 | 14 |
15 static void make_bitmaps(int w, int h, SkBitmap* src, SkBitmap* dst, | 15 static void make_bitmaps(int w, int h, SkBitmap* src, SkBitmap* dst, |
16 SkBitmap* transparent) { | 16 SkBitmap* transparent) { |
17 src->allocN32Pixels(w, h); | 17 src->allocN32Pixels(w, h); |
18 src->eraseColor(SK_ColorTRANSPARENT); | 18 src->eraseColor(SK_ColorTRANSPARENT); |
19 | 19 |
20 SkPaint p; | 20 SkPaint p; |
21 p.setAntiAlias(true); | 21 p.setAntiAlias(true); |
22 | 22 |
23 SkRect r; | 23 SkRect r; |
24 SkScalar ww = SkIntToScalar(w); | 24 SkScalar ww = SkIntToScalar(w); |
25 SkScalar hh = SkIntToScalar(h); | 25 SkScalar hh = SkIntToScalar(h); |
26 | 26 |
27 { | 27 { |
28 SkCanvas c(*src); | 28 SkCanvas c(*src); |
29 p.setColor(0xFFFFCC44); | 29 p.setColor(sk_tool_utils::color_to_565(0xFFFFCC44)); |
30 r.set(0, 0, ww*3/4, hh*3/4); | 30 r.set(0, 0, ww*3/4, hh*3/4); |
31 c.drawOval(r, p); | 31 c.drawOval(r, p); |
32 } | 32 } |
33 | 33 |
34 dst->allocN32Pixels(w, h); | 34 dst->allocN32Pixels(w, h); |
35 dst->eraseColor(SK_ColorTRANSPARENT); | 35 dst->eraseColor(SK_ColorTRANSPARENT); |
36 | 36 |
37 { | 37 { |
38 SkCanvas c(*dst); | 38 SkCanvas c(*dst); |
39 p.setColor(0xFF66AAFF); | 39 p.setColor(sk_tool_utils::color_to_565(0xFF66AAFF)); |
40 r.set(ww/3, hh/3, ww*19/20, hh*19/20); | 40 r.set(ww/3, hh/3, ww*19/20, hh*19/20); |
41 c.drawRect(r, p); | 41 c.drawRect(r, p); |
42 } | 42 } |
43 | 43 |
44 transparent->allocN32Pixels(w, h); | 44 transparent->allocN32Pixels(w, h); |
45 transparent->eraseColor(SK_ColorTRANSPARENT); | 45 transparent->eraseColor(SK_ColorTRANSPARENT); |
46 } | 46 } |
47 | 47 |
48 static uint16_t gData[] = { 0xFFFF, 0xCCCF, 0xCCCF, 0xFFFF }; | 48 static uint16_t gData[] = { 0xFFFF, 0xCCCF, 0xCCCF, 0xFFFF }; |
49 | 49 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 SkRect bounds = SkRect::MakeXYWH(x, y, SkIntToScalar(W), | 99 SkRect bounds = SkRect::MakeXYWH(x, y, SkIntToScalar(W), |
100 SkIntToScalar(H)); | 100 SkIntToScalar(H)); |
101 canvas->saveLayer(&bounds, &p); | 101 canvas->saveLayer(&bounds, &p); |
102 restoreNeeded = true; | 102 restoreNeeded = true; |
103 p.setXfermodeMode(SkXfermode::kSrcOver_Mode); | 103 p.setXfermodeMode(SkXfermode::kSrcOver_Mode); |
104 // Fall through. | 104 // Fall through. |
105 } | 105 } |
106 case kQuarterClear_SrcType: { | 106 case kQuarterClear_SrcType: { |
107 SkScalar halfW = SkIntToScalar(W) / 2; | 107 SkScalar halfW = SkIntToScalar(W) / 2; |
108 SkScalar halfH = SkIntToScalar(H) / 2; | 108 SkScalar halfH = SkIntToScalar(H) / 2; |
109 p.setColor(0xFF66AAFF); | 109 p.setColor(sk_tool_utils::color_to_565(0xFF66AAFF)); |
110 SkRect r = SkRect::MakeXYWH(x + halfW, y, halfW, | 110 SkRect r = SkRect::MakeXYWH(x + halfW, y, halfW, |
111 SkIntToScalar(H)); | 111 SkIntToScalar(H)); |
112 canvas->drawRect(r, p); | 112 canvas->drawRect(r, p); |
113 p.setColor(0xFFAA66FF); | 113 p.setColor(sk_tool_utils::color_to_565(0xFFAA66FF)); |
114 r = SkRect::MakeXYWH(x, y + halfH, SkIntToScalar(W), halfH); | 114 r = SkRect::MakeXYWH(x, y + halfH, SkIntToScalar(W), halfH); |
115 canvas->drawRect(r, p); | 115 canvas->drawRect(r, p); |
116 break; | 116 break; |
117 } | 117 } |
118 case kRectangleWithMask_SrcType: { | 118 case kRectangleWithMask_SrcType: { |
119 canvas->save(); | 119 canvas->save(); |
120 restoreNeeded = true; | 120 restoreNeeded = true; |
121 SkScalar w = SkIntToScalar(W); | 121 SkScalar w = SkIntToScalar(W); |
122 SkScalar h = SkIntToScalar(H); | 122 SkScalar h = SkIntToScalar(H); |
123 SkRect r = SkRect::MakeXYWH(x, y + h / 4, w, h * 23 / 60); | 123 SkRect r = SkRect::MakeXYWH(x, y + h / 4, w, h * 23 / 60); |
124 canvas->clipRect(r); | 124 canvas->clipRect(r); |
125 // Fall through. | 125 // Fall through. |
126 } | 126 } |
127 case kRectangle_SrcType: { | 127 case kRectangle_SrcType: { |
128 SkScalar w = SkIntToScalar(W); | 128 SkScalar w = SkIntToScalar(W); |
129 SkScalar h = SkIntToScalar(H); | 129 SkScalar h = SkIntToScalar(H); |
130 SkRect r = SkRect::MakeXYWH(x + w / 3, y + h / 3, | 130 SkRect r = SkRect::MakeXYWH(x + w / 3, y + h / 3, |
131 w * 37 / 60, h * 37 / 60); | 131 w * 37 / 60, h * 37 / 60); |
132 p.setColor(0xFF66AAFF); | 132 p.setColor(sk_tool_utils::color_to_565(0xFF66AAFF)); |
133 canvas->drawRect(r, p); | 133 canvas->drawRect(r, p); |
134 break; | 134 break; |
135 } | 135 } |
136 case kSmallRectangleImageWithAlpha_SrcType: | 136 case kSmallRectangleImageWithAlpha_SrcType: |
137 m.postScale(SK_ScalarHalf, SK_ScalarHalf, x, y); | 137 m.postScale(SK_ScalarHalf, SK_ScalarHalf, x, y); |
138 // Fall through. | 138 // Fall through. |
139 case kRectangleImageWithAlpha_SrcType: | 139 case kRectangleImageWithAlpha_SrcType: |
140 p.setAlpha(0x88); | 140 p.setAlpha(0x88); |
141 // Fall through. | 141 // Fall through. |
142 case kRectangleImage_SrcType: { | 142 case kRectangleImage_SrcType: { |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 const SkScalar h = SkIntToScalar(H); | 225 const SkScalar h = SkIntToScalar(H); |
226 SkMatrix m; | 226 SkMatrix m; |
227 m.setScale(SkIntToScalar(6), SkIntToScalar(6)); | 227 m.setScale(SkIntToScalar(6), SkIntToScalar(6)); |
228 SkShader* s = SkShader::CreateBitmapShader(fBG, | 228 SkShader* s = SkShader::CreateBitmapShader(fBG, |
229 SkShader::kRepeat_TileMode, | 229 SkShader::kRepeat_TileMode, |
230 SkShader::kRepeat_TileMode, | 230 SkShader::kRepeat_TileMode, |
231 &m); | 231 &m); |
232 | 232 |
233 SkPaint labelP; | 233 SkPaint labelP; |
234 labelP.setAntiAlias(true); | 234 labelP.setAntiAlias(true); |
235 sk_tool_utils::set_portable_typeface(&labelP); | 235 sk_tool_utils::set_portable_typeface_always(&labelP); |
236 labelP.setTextAlign(SkPaint::kCenter_Align); | 236 labelP.setTextAlign(SkPaint::kCenter_Align); |
237 | 237 |
238 const int W = 5; | 238 const int W = 5; |
239 | 239 |
240 SkScalar x0 = 0; | 240 SkScalar x0 = 0; |
241 SkScalar y0 = 0; | 241 SkScalar y0 = 0; |
242 for (int sourceType = 1; sourceType & kAll_SrcType; sourceType <<= 1) { | 242 for (int sourceType = 1; sourceType & kAll_SrcType; sourceType <<= 1) { |
243 SkScalar x = x0, y = y0; | 243 SkScalar x = x0, y = y0; |
244 for (size_t i = 0; i < SK_ARRAY_COUNT(gModes); i++) { | 244 for (size_t i = 0; i < SK_ARRAY_COUNT(gModes); i++) { |
245 if ((gModes[i].fSourceTypeMask & sourceType) == 0) { | 245 if ((gModes[i].fSourceTypeMask & sourceType) == 0) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 private: | 291 private: |
292 typedef GM INHERITED; | 292 typedef GM INHERITED; |
293 }; | 293 }; |
294 | 294 |
295 ////////////////////////////////////////////////////////////////////////////// | 295 ////////////////////////////////////////////////////////////////////////////// |
296 | 296 |
297 static GM* MyFactory(void*) { return new XfermodesGM; } | 297 static GM* MyFactory(void*) { return new XfermodesGM; } |
298 static GMRegistry reg(MyFactory); | 298 static GMRegistry reg(MyFactory); |
299 | 299 |
300 } | 300 } |
OLD | NEW |