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