OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "SkGradientShader.h" | 9 #include "SkGradientShader.h" |
10 #include "SkShader.h" | 10 #include "SkShader.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 } | 28 } |
29 | 29 |
30 protected: | 30 protected: |
31 void onOnceBeforeDraw() override { | 31 void onOnceBeforeDraw() override { |
32 const SkColor colors[] = { | 32 const SkColor colors[] = { |
33 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, | 33 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, |
34 SK_ColorMAGENTA, SK_ColorCYAN, SK_ColorYELLOW | 34 SK_ColorMAGENTA, SK_ColorCYAN, SK_ColorYELLOW |
35 }; | 35 }; |
36 SkMatrix local; | 36 SkMatrix local; |
37 local.setRotate(180); | 37 local.setRotate(180); |
38 SkShader* s = SkGradientShader::CreateSweep(0,0, colors, nullptr, | |
39 SK_ARRAY_COUNT(colors), 0, &
local); | |
40 | |
41 SkPaint paint; | 38 SkPaint paint; |
42 paint.setAntiAlias(true); | 39 paint.setAntiAlias(true); |
43 paint.setShader(s)->unref(); | 40 paint.setShader(SkGradientShader::MakeSweep(0, 0, colors, nullptr, SK_AR
RAY_COUNT(colors), |
| 41 0, &local)); |
44 | 42 |
45 SkTypeface* orig = sk_tool_utils::create_portable_typeface("serif", | 43 SkTypeface* orig = sk_tool_utils::create_portable_typeface("serif", SkTy
peface::kBold); |
46 SkTypeface::kBold); | |
47 if (nullptr == orig) { | 44 if (nullptr == orig) { |
48 orig = SkTypeface::RefDefault(); | 45 orig = SkTypeface::RefDefault(); |
49 } | 46 } |
50 fColorType = new SkGTypeface(orig, paint); | 47 fColorType = new SkGTypeface(orig, paint); |
51 orig->unref(); | 48 orig->unref(); |
52 | 49 |
53 fBG.installPixels(SkImageInfo::Make(2, 2, kARGB_4444_SkColorType, | 50 fBG.installPixels(SkImageInfo::Make(2, 2, kARGB_4444_SkColorType, |
54 kOpaque_SkAlphaType), gData, 4); | 51 kOpaque_SkAlphaType), gData, 4); |
55 } | 52 } |
56 | 53 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 { SkXfermode::kHue_Mode, "Hue" }, | 95 { SkXfermode::kHue_Mode, "Hue" }, |
99 { SkXfermode::kSaturation_Mode, "Saturation" }, | 96 { SkXfermode::kSaturation_Mode, "Saturation" }, |
100 { SkXfermode::kColor_Mode, "Color" }, | 97 { SkXfermode::kColor_Mode, "Color" }, |
101 { SkXfermode::kLuminosity_Mode, "Luminosity" }, | 98 { SkXfermode::kLuminosity_Mode, "Luminosity" }, |
102 }; | 99 }; |
103 | 100 |
104 const SkScalar w = SkIntToScalar(W); | 101 const SkScalar w = SkIntToScalar(W); |
105 const SkScalar h = SkIntToScalar(H); | 102 const SkScalar h = SkIntToScalar(H); |
106 SkMatrix m; | 103 SkMatrix m; |
107 m.setScale(SkIntToScalar(6), SkIntToScalar(6)); | 104 m.setScale(SkIntToScalar(6), SkIntToScalar(6)); |
108 SkShader* s = SkShader::CreateBitmapShader(fBG, | 105 auto s = SkShader::MakeBitmapShader(fBG, SkShader::kRepeat_TileMode, |
109 SkShader::kRepeat_TileMode, | 106 SkShader::kRepeat_TileMode, &m); |
110 SkShader::kRepeat_TileMode, | |
111 &m); | |
112 | 107 |
113 SkPaint labelP; | 108 SkPaint labelP; |
114 labelP.setAntiAlias(true); | 109 labelP.setAntiAlias(true); |
115 sk_tool_utils::set_portable_typeface(&labelP); | 110 sk_tool_utils::set_portable_typeface(&labelP); |
116 labelP.setTextAlign(SkPaint::kCenter_Align); | 111 labelP.setTextAlign(SkPaint::kCenter_Align); |
117 | 112 |
118 SkPaint textP; | 113 SkPaint textP; |
119 textP.setAntiAlias(true); | 114 textP.setAntiAlias(true); |
120 textP.setTypeface(fColorType); | 115 textP.setTypeface(fColorType); |
121 textP.setTextSize(SkIntToScalar(70)); | 116 textP.setTextSize(SkIntToScalar(70)); |
(...skipping 24 matching lines...) Expand all Loading... |
146 #if 1 | 141 #if 1 |
147 canvas->drawText(gModes[i].fLabel, strlen(gModes[i].fLabel), | 142 canvas->drawText(gModes[i].fLabel, strlen(gModes[i].fLabel), |
148 x + w/2, y - labelP.getTextSize()/2, labelP); | 143 x + w/2, y - labelP.getTextSize()/2, labelP); |
149 #endif | 144 #endif |
150 x += w + SkIntToScalar(10); | 145 x += w + SkIntToScalar(10); |
151 if ((i % W) == W - 1) { | 146 if ((i % W) == W - 1) { |
152 x = x0; | 147 x = x0; |
153 y += h + SkIntToScalar(30); | 148 y += h + SkIntToScalar(30); |
154 } | 149 } |
155 } | 150 } |
156 s->unref(); | |
157 } | 151 } |
158 | 152 |
159 private: | 153 private: |
160 SkBitmap fBG; | 154 SkBitmap fBG; |
161 SkTypeface* fColorType; | 155 SkTypeface* fColorType; |
162 | 156 |
163 typedef GM INHERITED; | 157 typedef GM INHERITED; |
164 }; | 158 }; |
165 | 159 |
166 ////////////////////////////////////////////////////////////////////////////// | 160 ////////////////////////////////////////////////////////////////////////////// |
167 | 161 |
168 static GM* MyFactory(void*) { return new ColorTypeXfermodeGM; } | 162 static GM* MyFactory(void*) { return new ColorTypeXfermodeGM; } |
169 static GMRegistry reg(MyFactory); | 163 static GMRegistry reg(MyFactory); |
170 | 164 |
171 } | 165 } |
OLD | NEW |