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" |
11 #include "SkXfermode.h" | 11 #include "SkXfermode.h" |
12 #include "../src/fonts/SkGScalerContext.h" | 12 #include "../src/fonts/SkGScalerContext.h" |
13 | 13 |
14 namespace skiagm { | 14 namespace skiagm { |
15 | 15 |
16 static uint16_t gData[] = { 0xFFFF, 0xCCCF, 0xCCCF, 0xFFFF }; | 16 static uint16_t gData[] = { 0xFFFF, 0xCCCF, 0xCCCF, 0xFFFF }; |
17 | 17 |
18 class ColorTypeXfermodeGM : public GM { | 18 class ColorTypeXfermodeGM : public GM { |
19 public: | 19 public: |
20 const static int W = 64; | 20 const static int W = 64; |
21 const static int H = 64; | 21 const static int H = 64; |
22 ColorTypeXfermodeGM() {} | 22 ColorTypeXfermodeGM() |
| 23 : fColorType(nullptr) { |
| 24 } |
| 25 |
| 26 virtual ~ColorTypeXfermodeGM() { |
| 27 SkSafeUnref(fColorType); |
| 28 } |
23 | 29 |
24 protected: | 30 protected: |
25 void onOnceBeforeDraw() override { | 31 void onOnceBeforeDraw() override { |
26 const SkColor colors[] = { | 32 const SkColor colors[] = { |
27 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, | 33 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, |
28 SK_ColorMAGENTA, SK_ColorCYAN, SK_ColorYELLOW | 34 SK_ColorMAGENTA, SK_ColorCYAN, SK_ColorYELLOW |
29 }; | 35 }; |
30 SkMatrix local; | 36 SkMatrix local; |
31 local.setRotate(180); | 37 local.setRotate(180); |
32 SkPaint paint; | 38 SkPaint paint; |
33 paint.setAntiAlias(true); | 39 paint.setAntiAlias(true); |
34 paint.setShader(SkGradientShader::MakeSweep(0, 0, colors, nullptr, SK_AR
RAY_COUNT(colors), | 40 paint.setShader(SkGradientShader::MakeSweep(0, 0, colors, nullptr, SK_AR
RAY_COUNT(colors), |
35 0, &local)); | 41 0, &local)); |
36 | 42 |
37 sk_sp<SkTypeface> orig(sk_tool_utils::create_portable_typeface("serif",
SkTypeface::kBold)); | 43 SkTypeface* orig = sk_tool_utils::create_portable_typeface("serif", SkTy
peface::kBold); |
38 if (nullptr == orig) { | 44 if (nullptr == orig) { |
39 orig = SkTypeface::MakeDefault(); | 45 orig = SkTypeface::RefDefault(); |
40 } | 46 } |
41 fColorType = sk_make_sp<SkGTypeface>(orig, paint); | 47 fColorType = new SkGTypeface(orig, paint); |
| 48 orig->unref(); |
42 | 49 |
43 fBG.installPixels(SkImageInfo::Make(2, 2, kARGB_4444_SkColorType, | 50 fBG.installPixels(SkImageInfo::Make(2, 2, kARGB_4444_SkColorType, |
44 kOpaque_SkAlphaType), gData, 4); | 51 kOpaque_SkAlphaType), gData, 4); |
45 } | 52 } |
46 | 53 |
47 virtual SkString onShortName() override { | 54 virtual SkString onShortName() override { |
48 return SkString("colortype_xfermodes"); | 55 return SkString("colortype_xfermodes"); |
49 } | 56 } |
50 | 57 |
51 virtual SkISize onISize() override { | 58 virtual SkISize onISize() override { |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 #endif | 142 #endif |
136 x += w + SkIntToScalar(10); | 143 x += w + SkIntToScalar(10); |
137 if ((i % W) == W - 1) { | 144 if ((i % W) == W - 1) { |
138 x = x0; | 145 x = x0; |
139 y += h + SkIntToScalar(30); | 146 y += h + SkIntToScalar(30); |
140 } | 147 } |
141 } | 148 } |
142 } | 149 } |
143 | 150 |
144 private: | 151 private: |
145 SkBitmap fBG; | 152 SkBitmap fBG; |
146 sk_sp<SkTypeface> fColorType; | 153 SkTypeface* fColorType; |
147 | 154 |
148 typedef GM INHERITED; | 155 typedef GM INHERITED; |
149 }; | 156 }; |
150 | 157 |
151 ////////////////////////////////////////////////////////////////////////////// | 158 ////////////////////////////////////////////////////////////////////////////// |
152 | 159 |
153 static GM* MyFactory(void*) { return new ColorTypeXfermodeGM; } | 160 static GM* MyFactory(void*) { return new ColorTypeXfermodeGM; } |
154 static GMRegistry reg(MyFactory); | 161 static GMRegistry reg(MyFactory); |
155 | 162 |
156 } | 163 } |
OLD | NEW |