epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
reed | dd9ffea | 2016-02-18 12:39:14 -0800 | [diff] [blame] | 7 | |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 8 | #include "gm.h" |
| 9 | #include "SkBitmap.h" |
| 10 | #include "SkShader.h" |
| 11 | #include "SkXfermode.h" |
reed | dd9ffea | 2016-02-18 12:39:14 -0800 | [diff] [blame] | 12 | #include "SkPM4f.h" |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 13 | |
reed | 8516dc1 | 2016-02-24 08:18:42 -0800 | [diff] [blame] | 14 | #include "SkArithmeticMode.h" |
reed | 8516dc1 | 2016-02-24 08:18:42 -0800 | [diff] [blame] | 15 | |
| 16 | #define kCustomShift 16 |
| 17 | #define kCustomMask (~0xFFFF) |
| 18 | |
| 19 | enum CustomModes { |
| 20 | kArithmetic_CustomMode = 1 << kCustomShift, |
reed | 8516dc1 | 2016-02-24 08:18:42 -0800 | [diff] [blame] | 21 | }; |
| 22 | |
reed | cfb6bdf | 2016-03-29 11:32:50 -0700 | [diff] [blame] | 23 | static sk_sp<SkXfermode> make_custom(int customMode) { |
reed | 8516dc1 | 2016-02-24 08:18:42 -0800 | [diff] [blame] | 24 | switch (customMode) { |
| 25 | case kArithmetic_CustomMode: { |
| 26 | const SkScalar k1 = 0.25; |
| 27 | const SkScalar k2 = 0.75; |
| 28 | const SkScalar k3 = 0.75; |
| 29 | const SkScalar k4 = -0.25; |
reed | cfb6bdf | 2016-03-29 11:32:50 -0700 | [diff] [blame] | 30 | return SkArithmeticMode::Make(k1, k2, k3, k4); |
reed | 8516dc1 | 2016-02-24 08:18:42 -0800 | [diff] [blame] | 31 | } |
reed | 8516dc1 | 2016-02-24 08:18:42 -0800 | [diff] [blame] | 32 | default: |
| 33 | break; |
| 34 | } |
| 35 | SkASSERT(false); |
| 36 | return nullptr; |
| 37 | } |
| 38 | |
reed | e712532 | 2016-02-09 11:59:24 -0800 | [diff] [blame] | 39 | enum SrcType { |
| 40 | //! A WxH image with a rectangle in the lower right. |
| 41 | kRectangleImage_SrcType = 0x01, |
| 42 | //! kRectangleImage_SrcType with an alpha of 34.5%. |
| 43 | kRectangleImageWithAlpha_SrcType = 0x02, |
| 44 | //! kRectnagleImageWithAlpha_SrcType scaled down by half. |
| 45 | kSmallRectangleImageWithAlpha_SrcType = 0x04, |
| 46 | //! kRectangleImage_SrcType drawn directly instead in an image. |
| 47 | kRectangle_SrcType = 0x08, |
| 48 | //! Two rectangles, first on the right half, second on the bottom half. |
| 49 | kQuarterClear_SrcType = 0x10, |
| 50 | //! kQuarterClear_SrcType in a layer. |
| 51 | kQuarterClearInLayer_SrcType = 0x20, |
| 52 | //! A W/2xH/2 transparent image. |
| 53 | kSmallTransparentImage_SrcType = 0x40, |
| 54 | //! kRectangleImage_SrcType drawn directly with a mask. |
| 55 | kRectangleWithMask_SrcType = 0x80, |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 56 | |
reed | e712532 | 2016-02-09 11:59:24 -0800 | [diff] [blame] | 57 | kAll_SrcType = 0xFF, //!< All the source types. |
| 58 | kBasic_SrcType = 0x03, //!< Just basic source types. |
| 59 | }; |
| 60 | |
| 61 | const struct { |
| 62 | SkXfermode::Mode fMode; |
| 63 | const char* fLabel; |
| 64 | int fSourceTypeMask; // The source types to use this |
| 65 | // mode with. See draw_mode for |
| 66 | // an explanation of each type. |
| 67 | // PDF has to play some tricks |
| 68 | // to support the base modes, |
| 69 | // test those more extensively. |
| 70 | } gModes[] = { |
| 71 | { SkXfermode::kClear_Mode, "Clear", kAll_SrcType }, |
| 72 | { SkXfermode::kSrc_Mode, "Src", kAll_SrcType }, |
| 73 | { SkXfermode::kDst_Mode, "Dst", kAll_SrcType }, |
| 74 | { SkXfermode::kSrcOver_Mode, "SrcOver", kAll_SrcType }, |
| 75 | { SkXfermode::kDstOver_Mode, "DstOver", kAll_SrcType }, |
| 76 | { SkXfermode::kSrcIn_Mode, "SrcIn", kAll_SrcType }, |
| 77 | { SkXfermode::kDstIn_Mode, "DstIn", kAll_SrcType }, |
| 78 | { SkXfermode::kSrcOut_Mode, "SrcOut", kAll_SrcType }, |
| 79 | { SkXfermode::kDstOut_Mode, "DstOut", kAll_SrcType }, |
| 80 | { SkXfermode::kSrcATop_Mode, "SrcATop", kAll_SrcType }, |
| 81 | { SkXfermode::kDstATop_Mode, "DstATop", kAll_SrcType }, |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 82 | |
reed | e712532 | 2016-02-09 11:59:24 -0800 | [diff] [blame] | 83 | { SkXfermode::kXor_Mode, "Xor", kBasic_SrcType }, |
| 84 | { SkXfermode::kPlus_Mode, "Plus", kBasic_SrcType }, |
| 85 | { SkXfermode::kModulate_Mode, "Modulate", kAll_SrcType }, |
| 86 | { SkXfermode::kScreen_Mode, "Screen", kBasic_SrcType }, |
| 87 | { SkXfermode::kOverlay_Mode, "Overlay", kBasic_SrcType }, |
| 88 | { SkXfermode::kDarken_Mode, "Darken", kBasic_SrcType }, |
| 89 | { SkXfermode::kLighten_Mode, "Lighten", kBasic_SrcType }, |
| 90 | { SkXfermode::kColorDodge_Mode, "ColorDodge", kBasic_SrcType }, |
| 91 | { SkXfermode::kColorBurn_Mode, "ColorBurn", kBasic_SrcType }, |
| 92 | { SkXfermode::kHardLight_Mode, "HardLight", kBasic_SrcType }, |
| 93 | { SkXfermode::kSoftLight_Mode, "SoftLight", kBasic_SrcType }, |
| 94 | { SkXfermode::kDifference_Mode, "Difference", kBasic_SrcType }, |
| 95 | { SkXfermode::kExclusion_Mode, "Exclusion", kBasic_SrcType }, |
| 96 | { SkXfermode::kMultiply_Mode, "Multiply", kAll_SrcType }, |
| 97 | { SkXfermode::kHue_Mode, "Hue", kBasic_SrcType }, |
| 98 | { SkXfermode::kSaturation_Mode, "Saturation", kBasic_SrcType }, |
| 99 | { SkXfermode::kColor_Mode, "Color", kBasic_SrcType }, |
| 100 | { SkXfermode::kLuminosity_Mode, "Luminosity", kBasic_SrcType }, |
reed | 8516dc1 | 2016-02-24 08:18:42 -0800 | [diff] [blame] | 101 | |
| 102 | { SkXfermode::Mode(0xFFFF), "Arithmetic", kBasic_SrcType + kArithmetic_CustomMode }, |
reed | e712532 | 2016-02-09 11:59:24 -0800 | [diff] [blame] | 103 | }; |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 104 | |
commit-bot@chromium.org | 7542dc8 | 2013-12-03 21:08:46 +0000 | [diff] [blame] | 105 | static void make_bitmaps(int w, int h, SkBitmap* src, SkBitmap* dst, |
| 106 | SkBitmap* transparent) { |
reed@google.com | eb9a46c | 2014-01-25 16:46:20 +0000 | [diff] [blame] | 107 | src->allocN32Pixels(w, h); |
junov@google.com | dbfac8a | 2012-12-06 21:47:40 +0000 | [diff] [blame] | 108 | src->eraseColor(SK_ColorTRANSPARENT); |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 109 | |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 110 | SkPaint p; |
mike@reedtribe.org | 3bd2173 | 2012-09-26 02:45:10 +0000 | [diff] [blame] | 111 | p.setAntiAlias(true); |
| 112 | |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 113 | SkRect r; |
| 114 | SkScalar ww = SkIntToScalar(w); |
| 115 | SkScalar hh = SkIntToScalar(h); |
| 116 | |
mike@reedtribe.org | 3bd2173 | 2012-09-26 02:45:10 +0000 | [diff] [blame] | 117 | { |
| 118 | SkCanvas c(*src); |
caryclark | 4ec1ac6 | 2015-07-21 07:42:45 -0700 | [diff] [blame] | 119 | p.setColor(sk_tool_utils::color_to_565(0xFFFFCC44)); |
mike@reedtribe.org | 3bd2173 | 2012-09-26 02:45:10 +0000 | [diff] [blame] | 120 | r.set(0, 0, ww*3/4, hh*3/4); |
| 121 | c.drawOval(r, p); |
| 122 | } |
tomhudson@google.com | 86bf5c9 | 2011-04-26 18:15:03 +0000 | [diff] [blame] | 123 | |
commit-bot@chromium.org | dac5225 | 2014-02-17 21:21:46 +0000 | [diff] [blame] | 124 | dst->allocN32Pixels(w, h); |
junov@google.com | dbfac8a | 2012-12-06 21:47:40 +0000 | [diff] [blame] | 125 | dst->eraseColor(SK_ColorTRANSPARENT); |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 126 | |
mike@reedtribe.org | 3bd2173 | 2012-09-26 02:45:10 +0000 | [diff] [blame] | 127 | { |
| 128 | SkCanvas c(*dst); |
caryclark | 4ec1ac6 | 2015-07-21 07:42:45 -0700 | [diff] [blame] | 129 | p.setColor(sk_tool_utils::color_to_565(0xFF66AAFF)); |
mike@reedtribe.org | 3bd2173 | 2012-09-26 02:45:10 +0000 | [diff] [blame] | 130 | r.set(ww/3, hh/3, ww*19/20, hh*19/20); |
| 131 | c.drawRect(r, p); |
| 132 | } |
commit-bot@chromium.org | 7542dc8 | 2013-12-03 21:08:46 +0000 | [diff] [blame] | 133 | |
commit-bot@chromium.org | dac5225 | 2014-02-17 21:21:46 +0000 | [diff] [blame] | 134 | transparent->allocN32Pixels(w, h); |
commit-bot@chromium.org | 7542dc8 | 2013-12-03 21:08:46 +0000 | [diff] [blame] | 135 | transparent->eraseColor(SK_ColorTRANSPARENT); |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 136 | } |
| 137 | |
scroggo@google.com | 7312a18 | 2013-01-28 21:14:21 +0000 | [diff] [blame] | 138 | static uint16_t gData[] = { 0xFFFF, 0xCCCF, 0xCCCF, 0xFFFF }; |
| 139 | |
reed | e712532 | 2016-02-09 11:59:24 -0800 | [diff] [blame] | 140 | class XfermodesGM : public skiagm::GM { |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 141 | SkBitmap fBG; |
commit-bot@chromium.org | 7542dc8 | 2013-12-03 21:08:46 +0000 | [diff] [blame] | 142 | SkBitmap fSrcB, fDstB, fTransparent; |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 143 | |
vandebo@chromium.org | 3b41621 | 2013-10-30 20:48:05 +0000 | [diff] [blame] | 144 | /* The srcType argument indicates what to draw for the source part. Skia |
| 145 | * uses the implied shape of the drawing command and these modes |
| 146 | * demonstrate that. |
| 147 | */ |
reed | cfb6bdf | 2016-03-29 11:32:50 -0700 | [diff] [blame] | 148 | void draw_mode(SkCanvas* canvas, sk_sp<SkXfermode> mode, SrcType srcType, |
reed@google.com | f3c1cc9 | 2010-12-23 16:45:33 +0000 | [diff] [blame] | 149 | SkScalar x, SkScalar y) { |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 150 | SkPaint p; |
vandebo@chromium.org | 3b41621 | 2013-10-30 20:48:05 +0000 | [diff] [blame] | 151 | SkMatrix m; |
| 152 | bool restoreNeeded = false; |
| 153 | m.setTranslate(x, y); |
tomhudson@google.com | 86bf5c9 | 2011-04-26 18:15:03 +0000 | [diff] [blame] | 154 | |
Florin Malita | c54d8db | 2014-12-10 12:02:16 -0500 | [diff] [blame] | 155 | canvas->drawBitmap(fSrcB, x, y, &p); |
reed | cfb6bdf | 2016-03-29 11:32:50 -0700 | [diff] [blame] | 156 | p.setXfermode(std::move(mode)); |
vandebo@chromium.org | 3b41621 | 2013-10-30 20:48:05 +0000 | [diff] [blame] | 157 | switch (srcType) { |
Florin Malita | c54d8db | 2014-12-10 12:02:16 -0500 | [diff] [blame] | 158 | case kSmallTransparentImage_SrcType: { |
commit-bot@chromium.org | 7542dc8 | 2013-12-03 21:08:46 +0000 | [diff] [blame] | 159 | m.postScale(SK_ScalarHalf, SK_ScalarHalf, x, y); |
Florin Malita | c54d8db | 2014-12-10 12:02:16 -0500 | [diff] [blame] | 160 | |
| 161 | SkAutoCanvasRestore acr(canvas, true); |
| 162 | canvas->concat(m); |
| 163 | canvas->drawBitmap(fTransparent, 0, 0, &p); |
commit-bot@chromium.org | 7542dc8 | 2013-12-03 21:08:46 +0000 | [diff] [blame] | 164 | break; |
Florin Malita | c54d8db | 2014-12-10 12:02:16 -0500 | [diff] [blame] | 165 | } |
vandebo@chromium.org | 3b41621 | 2013-10-30 20:48:05 +0000 | [diff] [blame] | 166 | case kQuarterClearInLayer_SrcType: { |
vandebo@chromium.org | f5747da | 2013-10-30 21:29:47 +0000 | [diff] [blame] | 167 | SkRect bounds = SkRect::MakeXYWH(x, y, SkIntToScalar(W), |
| 168 | SkIntToScalar(H)); |
vandebo@chromium.org | 3b41621 | 2013-10-30 20:48:05 +0000 | [diff] [blame] | 169 | canvas->saveLayer(&bounds, &p); |
| 170 | restoreNeeded = true; |
| 171 | p.setXfermodeMode(SkXfermode::kSrcOver_Mode); |
| 172 | // Fall through. |
| 173 | } |
| 174 | case kQuarterClear_SrcType: { |
| 175 | SkScalar halfW = SkIntToScalar(W) / 2; |
| 176 | SkScalar halfH = SkIntToScalar(H) / 2; |
caryclark | 4ec1ac6 | 2015-07-21 07:42:45 -0700 | [diff] [blame] | 177 | p.setColor(sk_tool_utils::color_to_565(0xFF66AAFF)); |
vandebo@chromium.org | f5747da | 2013-10-30 21:29:47 +0000 | [diff] [blame] | 178 | SkRect r = SkRect::MakeXYWH(x + halfW, y, halfW, |
| 179 | SkIntToScalar(H)); |
vandebo@chromium.org | 3b41621 | 2013-10-30 20:48:05 +0000 | [diff] [blame] | 180 | canvas->drawRect(r, p); |
caryclark | 4ec1ac6 | 2015-07-21 07:42:45 -0700 | [diff] [blame] | 181 | p.setColor(sk_tool_utils::color_to_565(0xFFAA66FF)); |
vandebo@chromium.org | f5747da | 2013-10-30 21:29:47 +0000 | [diff] [blame] | 182 | r = SkRect::MakeXYWH(x, y + halfH, SkIntToScalar(W), halfH); |
vandebo@chromium.org | 3b41621 | 2013-10-30 20:48:05 +0000 | [diff] [blame] | 183 | canvas->drawRect(r, p); |
| 184 | break; |
| 185 | } |
commit-bot@chromium.org | 4e8f1e5 | 2013-12-17 23:38:28 +0000 | [diff] [blame] | 186 | case kRectangleWithMask_SrcType: { |
commit-bot@chromium.org | 091a594 | 2014-04-18 14:19:31 +0000 | [diff] [blame] | 187 | canvas->save(); |
commit-bot@chromium.org | 4e8f1e5 | 2013-12-17 23:38:28 +0000 | [diff] [blame] | 188 | restoreNeeded = true; |
| 189 | SkScalar w = SkIntToScalar(W); |
| 190 | SkScalar h = SkIntToScalar(H); |
| 191 | SkRect r = SkRect::MakeXYWH(x, y + h / 4, w, h * 23 / 60); |
| 192 | canvas->clipRect(r); |
| 193 | // Fall through. |
| 194 | } |
vandebo@chromium.org | 3b41621 | 2013-10-30 20:48:05 +0000 | [diff] [blame] | 195 | case kRectangle_SrcType: { |
| 196 | SkScalar w = SkIntToScalar(W); |
| 197 | SkScalar h = SkIntToScalar(H); |
| 198 | SkRect r = SkRect::MakeXYWH(x + w / 3, y + h / 3, |
| 199 | w * 37 / 60, h * 37 / 60); |
caryclark | 4ec1ac6 | 2015-07-21 07:42:45 -0700 | [diff] [blame] | 200 | p.setColor(sk_tool_utils::color_to_565(0xFF66AAFF)); |
vandebo@chromium.org | 3b41621 | 2013-10-30 20:48:05 +0000 | [diff] [blame] | 201 | canvas->drawRect(r, p); |
| 202 | break; |
| 203 | } |
| 204 | case kSmallRectangleImageWithAlpha_SrcType: |
| 205 | m.postScale(SK_ScalarHalf, SK_ScalarHalf, x, y); |
| 206 | // Fall through. |
| 207 | case kRectangleImageWithAlpha_SrcType: |
| 208 | p.setAlpha(0x88); |
| 209 | // Fall through. |
Florin Malita | c54d8db | 2014-12-10 12:02:16 -0500 | [diff] [blame] | 210 | case kRectangleImage_SrcType: { |
| 211 | SkAutoCanvasRestore acr(canvas, true); |
| 212 | canvas->concat(m); |
| 213 | canvas->drawBitmap(fDstB, 0, 0, &p); |
vandebo@chromium.org | 3b41621 | 2013-10-30 20:48:05 +0000 | [diff] [blame] | 214 | break; |
Florin Malita | c54d8db | 2014-12-10 12:02:16 -0500 | [diff] [blame] | 215 | } |
vandebo@chromium.org | 3b41621 | 2013-10-30 20:48:05 +0000 | [diff] [blame] | 216 | default: |
| 217 | break; |
| 218 | } |
| 219 | |
| 220 | if (restoreNeeded) { |
| 221 | canvas->restore(); |
| 222 | } |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 223 | } |
tomhudson@google.com | 86bf5c9 | 2011-04-26 18:15:03 +0000 | [diff] [blame] | 224 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 225 | void onOnceBeforeDraw() override { |
commit-bot@chromium.org | dac5225 | 2014-02-17 21:21:46 +0000 | [diff] [blame] | 226 | fBG.installPixels(SkImageInfo::Make(2, 2, kARGB_4444_SkColorType, |
| 227 | kOpaque_SkAlphaType), |
| 228 | gData, 4); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 229 | |
commit-bot@chromium.org | 7542dc8 | 2013-12-03 21:08:46 +0000 | [diff] [blame] | 230 | make_bitmaps(W, H, &fSrcB, &fDstB, &fTransparent); |
reed@google.com | 5213c04 | 2011-12-20 13:41:09 +0000 | [diff] [blame] | 231 | } |
| 232 | |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 233 | public: |
reed@google.com | f3c1cc9 | 2010-12-23 16:45:33 +0000 | [diff] [blame] | 234 | const static int W = 64; |
| 235 | const static int H = 64; |
scroggo@google.com | 7312a18 | 2013-01-28 21:14:21 +0000 | [diff] [blame] | 236 | XfermodesGM() {} |
tomhudson@google.com | 86bf5c9 | 2011-04-26 18:15:03 +0000 | [diff] [blame] | 237 | |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 238 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 239 | SkString onShortName() override { |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 240 | return SkString("xfermodes"); |
| 241 | } |
| 242 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 243 | SkISize onISize() override { |
reed | 8516dc1 | 2016-02-24 08:18:42 -0800 | [diff] [blame] | 244 | return SkISize::Make(1990, 660); |
reed@android.com | 048522d | 2009-06-23 12:19:41 +0000 | [diff] [blame] | 245 | } |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 246 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 247 | void onDraw(SkCanvas* canvas) override { |
reed@google.com | f3c1cc9 | 2010-12-23 16:45:33 +0000 | [diff] [blame] | 248 | canvas->translate(SkIntToScalar(10), SkIntToScalar(20)); |
tomhudson@google.com | 86bf5c9 | 2011-04-26 18:15:03 +0000 | [diff] [blame] | 249 | |
reed@google.com | f3c1cc9 | 2010-12-23 16:45:33 +0000 | [diff] [blame] | 250 | const SkScalar w = SkIntToScalar(W); |
| 251 | const SkScalar h = SkIntToScalar(H); |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 252 | SkMatrix m; |
| 253 | m.setScale(SkIntToScalar(6), SkIntToScalar(6)); |
reed | 1a9b964 | 2016-03-13 14:13:58 -0700 | [diff] [blame] | 254 | auto s = SkShader::MakeBitmapShader(fBG, SkShader::kRepeat_TileMode, |
| 255 | SkShader::kRepeat_TileMode, &m); |
tomhudson@google.com | 86bf5c9 | 2011-04-26 18:15:03 +0000 | [diff] [blame] | 256 | |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 257 | SkPaint labelP; |
| 258 | labelP.setAntiAlias(true); |
caryclark | 1818acb | 2015-07-24 12:09:25 -0700 | [diff] [blame] | 259 | sk_tool_utils::set_portable_typeface(&labelP); |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 260 | labelP.setTextAlign(SkPaint::kCenter_Align); |
tomhudson@google.com | 86bf5c9 | 2011-04-26 18:15:03 +0000 | [diff] [blame] | 261 | |
reed@android.com | c9c6422 | 2009-06-23 00:09:12 +0000 | [diff] [blame] | 262 | const int W = 5; |
tomhudson@google.com | 86bf5c9 | 2011-04-26 18:15:03 +0000 | [diff] [blame] | 263 | |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 264 | SkScalar x0 = 0; |
vandebo@chromium.org | 3b41621 | 2013-10-30 20:48:05 +0000 | [diff] [blame] | 265 | SkScalar y0 = 0; |
| 266 | for (int sourceType = 1; sourceType & kAll_SrcType; sourceType <<= 1) { |
| 267 | SkScalar x = x0, y = y0; |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 268 | for (size_t i = 0; i < SK_ARRAY_COUNT(gModes); i++) { |
vandebo@chromium.org | 3b41621 | 2013-10-30 20:48:05 +0000 | [diff] [blame] | 269 | if ((gModes[i].fSourceTypeMask & sourceType) == 0) { |
| 270 | continue; |
| 271 | } |
reed | cfb6bdf | 2016-03-29 11:32:50 -0700 | [diff] [blame] | 272 | sk_sp<SkXfermode> mode; |
reed | 8516dc1 | 2016-02-24 08:18:42 -0800 | [diff] [blame] | 273 | if (gModes[i].fSourceTypeMask & kCustomMask) { |
reed | cfb6bdf | 2016-03-29 11:32:50 -0700 | [diff] [blame] | 274 | mode = make_custom(gModes[i].fSourceTypeMask & kCustomMask); |
reed | 8516dc1 | 2016-02-24 08:18:42 -0800 | [diff] [blame] | 275 | } else { |
reed | cfb6bdf | 2016-03-29 11:32:50 -0700 | [diff] [blame] | 276 | mode = SkXfermode::Make(gModes[i].fMode); |
reed | 8516dc1 | 2016-02-24 08:18:42 -0800 | [diff] [blame] | 277 | } |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 278 | SkRect r; |
| 279 | r.set(x, y, x+w, y+h); |
tomhudson@google.com | 86bf5c9 | 2011-04-26 18:15:03 +0000 | [diff] [blame] | 280 | |
reed@google.com | f3c1cc9 | 2010-12-23 16:45:33 +0000 | [diff] [blame] | 281 | SkPaint p; |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 282 | p.setStyle(SkPaint::kFill_Style); |
| 283 | p.setShader(s); |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 284 | canvas->drawRect(r, p); |
tomhudson@google.com | 86bf5c9 | 2011-04-26 18:15:03 +0000 | [diff] [blame] | 285 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 286 | canvas->saveLayer(&r, nullptr); |
reed | cfb6bdf | 2016-03-29 11:32:50 -0700 | [diff] [blame] | 287 | draw_mode(canvas, std::move(mode), static_cast<SrcType>(sourceType), |
vandebo@chromium.org | 3b41621 | 2013-10-30 20:48:05 +0000 | [diff] [blame] | 288 | r.fLeft, r.fTop); |
reed@google.com | f3c1cc9 | 2010-12-23 16:45:33 +0000 | [diff] [blame] | 289 | canvas->restore(); |
tomhudson@google.com | 86bf5c9 | 2011-04-26 18:15:03 +0000 | [diff] [blame] | 290 | |
reed@google.com | f3c1cc9 | 2010-12-23 16:45:33 +0000 | [diff] [blame] | 291 | r.inset(-SK_ScalarHalf, -SK_ScalarHalf); |
| 292 | p.setStyle(SkPaint::kStroke_Style); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 293 | p.setShader(nullptr); |
reed@google.com | f3c1cc9 | 2010-12-23 16:45:33 +0000 | [diff] [blame] | 294 | canvas->drawRect(r, p); |
tomhudson@google.com | 86bf5c9 | 2011-04-26 18:15:03 +0000 | [diff] [blame] | 295 | |
reed@google.com | f3c1cc9 | 2010-12-23 16:45:33 +0000 | [diff] [blame] | 296 | #if 1 |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 297 | canvas->drawText(gModes[i].fLabel, strlen(gModes[i].fLabel), |
| 298 | x + w/2, y - labelP.getTextSize()/2, labelP); |
reed@google.com | f3c1cc9 | 2010-12-23 16:45:33 +0000 | [diff] [blame] | 299 | #endif |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 300 | x += w + SkIntToScalar(10); |
reed@android.com | c9c6422 | 2009-06-23 00:09:12 +0000 | [diff] [blame] | 301 | if ((i % W) == W - 1) { |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 302 | x = x0; |
| 303 | y += h + SkIntToScalar(30); |
| 304 | } |
| 305 | } |
vandebo@chromium.org | 3b41621 | 2013-10-30 20:48:05 +0000 | [diff] [blame] | 306 | if (y < 320) { |
| 307 | if (x > x0) { |
| 308 | y += h + SkIntToScalar(30); |
| 309 | } |
| 310 | y0 = y; |
| 311 | } else { |
| 312 | x0 += SkIntToScalar(400); |
| 313 | y0 = 0; |
| 314 | } |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 315 | } |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | private: |
| 319 | typedef GM INHERITED; |
| 320 | }; |
reed | e712532 | 2016-02-09 11:59:24 -0800 | [diff] [blame] | 321 | DEF_GM( return new XfermodesGM; ) |