| 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 SkBitmap fBG; | |
| 20 | |
| 21 void onOnceBeforeDraw() override { | |
| 22 fBG.installPixels(SkImageInfo::Make(2, 2, kARGB_4444_SkColorType, | |
| 23 kOpaque_SkAlphaType), gData, 4); | |
| 24 } | |
| 25 | |
| 26 public: | 19 public: |
| 27 const static int W = 64; | 20 const static int W = 64; |
| 28 const static int H = 64; | 21 const static int H = 64; |
| 29 ColorTypeXfermodeGM() { | 22 ColorTypeXfermodeGM() |
| 23 : fColorType(NULL) { |
| 24 } |
| 25 |
| 26 virtual ~ColorTypeXfermodeGM() { |
| 27 SkSafeUnref(fColorType); |
| 28 } |
| 29 |
| 30 protected: |
| 31 void onOnceBeforeDraw() override { |
| 30 const SkColor colors[] = { | 32 const SkColor colors[] = { |
| 31 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, | 33 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, |
| 32 SK_ColorMAGENTA, SK_ColorCYAN, SK_ColorYELLOW | 34 SK_ColorMAGENTA, SK_ColorCYAN, SK_ColorYELLOW |
| 33 }; | 35 }; |
| 34 SkMatrix local; | 36 SkMatrix local; |
| 35 local.setRotate(180); | 37 local.setRotate(180); |
| 36 SkShader* s = SkGradientShader::CreateSweep(0,0, colors, NULL, | 38 SkShader* s = SkGradientShader::CreateSweep(0,0, colors, NULL, |
| 37 SK_ARRAY_COUNT(colors), 0, &
local); | 39 SK_ARRAY_COUNT(colors), 0, &
local); |
| 38 | 40 |
| 39 SkPaint paint; | 41 SkPaint paint; |
| 40 paint.setAntiAlias(true); | 42 paint.setAntiAlias(true); |
| 41 paint.setShader(s)->unref(); | 43 paint.setShader(s)->unref(); |
| 42 | 44 |
| 43 SkTypeface* orig = sk_tool_utils::create_portable_typeface("Times", | 45 SkTypeface* orig = sk_tool_utils::create_portable_typeface("Times", |
| 44 SkTypeface::kBold); | 46 SkTypeface::kBold); |
| 45 if (NULL == orig) { | 47 if (NULL == orig) { |
| 46 orig = SkTypeface::RefDefault(); | 48 orig = SkTypeface::RefDefault(); |
| 47 } | 49 } |
| 48 fColorType = SkNEW_ARGS(SkGTypeface, (orig, paint)); | 50 fColorType = SkNEW_ARGS(SkGTypeface, (orig, paint)); |
| 49 orig->unref(); | 51 orig->unref(); |
| 52 |
| 53 fBG.installPixels(SkImageInfo::Make(2, 2, kARGB_4444_SkColorType, |
| 54 kOpaque_SkAlphaType), gData, 4); |
| 50 } | 55 } |
| 51 | 56 |
| 52 virtual ~ColorTypeXfermodeGM() { | |
| 53 fColorType->unref(); | |
| 54 } | |
| 55 | |
| 56 protected: | |
| 57 virtual SkString onShortName() override { | 57 virtual SkString onShortName() override { |
| 58 return SkString("colortype_xfermodes"); | 58 return SkString("colortype_xfermodes"); |
| 59 } | 59 } |
| 60 | 60 |
| 61 virtual SkISize onISize() override { | 61 virtual SkISize onISize() override { |
| 62 return SkISize::Make(400, 640); | 62 return SkISize::Make(400, 640); |
| 63 } | 63 } |
| 64 | 64 |
| 65 virtual void onDraw(SkCanvas* canvas) override { | 65 virtual void onDraw(SkCanvas* canvas) override { |
| 66 canvas->translate(SkIntToScalar(10), SkIntToScalar(20)); | 66 canvas->translate(SkIntToScalar(10), SkIntToScalar(20)); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 x += w + SkIntToScalar(10); | 150 x += w + SkIntToScalar(10); |
| 151 if ((i % W) == W - 1) { | 151 if ((i % W) == W - 1) { |
| 152 x = x0; | 152 x = x0; |
| 153 y += h + SkIntToScalar(30); | 153 y += h + SkIntToScalar(30); |
| 154 } | 154 } |
| 155 } | 155 } |
| 156 s->unref(); | 156 s->unref(); |
| 157 } | 157 } |
| 158 | 158 |
| 159 private: | 159 private: |
| 160 SkBitmap fBG; |
| 160 SkTypeface* fColorType; | 161 SkTypeface* fColorType; |
| 161 | 162 |
| 162 typedef GM INHERITED; | 163 typedef GM INHERITED; |
| 163 }; | 164 }; |
| 164 | 165 |
| 165 ////////////////////////////////////////////////////////////////////////////// | 166 ////////////////////////////////////////////////////////////////////////////// |
| 166 | 167 |
| 167 static GM* MyFactory(void*) { return new ColorTypeXfermodeGM; } | 168 static GM* MyFactory(void*) { return new ColorTypeXfermodeGM; } |
| 168 static GMRegistry reg(MyFactory); | 169 static GMRegistry reg(MyFactory); |
| 169 | 170 |
| 170 } | 171 } |
| OLD | NEW |