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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "gm/gm.h" |
| 9 | #include "include/core/SkBitmap.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 10 | #include "include/core/SkBlendMode.h" |
| 11 | #include "include/core/SkCanvas.h" |
| 12 | #include "include/core/SkColor.h" |
| 13 | #include "include/core/SkFont.h" |
| 14 | #include "include/core/SkImageInfo.h" |
| 15 | #include "include/core/SkMatrix.h" |
| 16 | #include "include/core/SkPaint.h" |
| 17 | #include "include/core/SkRect.h" |
| 18 | #include "include/core/SkScalar.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 19 | #include "include/core/SkShader.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 20 | #include "include/core/SkSize.h" |
| 21 | #include "include/core/SkString.h" |
| 22 | #include "include/core/SkTileMode.h" |
| 23 | #include "include/core/SkTypeface.h" |
| 24 | #include "include/core/SkTypes.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 25 | #include "include/utils/SkTextUtils.h" |
| 26 | #include "tools/ToolUtils.h" |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 27 | |
reed | e712532 | 2016-02-09 11:59:24 -0800 | [diff] [blame] | 28 | enum SrcType { |
| 29 | //! A WxH image with a rectangle in the lower right. |
| 30 | kRectangleImage_SrcType = 0x01, |
| 31 | //! kRectangleImage_SrcType with an alpha of 34.5%. |
| 32 | kRectangleImageWithAlpha_SrcType = 0x02, |
| 33 | //! kRectnagleImageWithAlpha_SrcType scaled down by half. |
| 34 | kSmallRectangleImageWithAlpha_SrcType = 0x04, |
| 35 | //! kRectangleImage_SrcType drawn directly instead in an image. |
| 36 | kRectangle_SrcType = 0x08, |
| 37 | //! Two rectangles, first on the right half, second on the bottom half. |
| 38 | kQuarterClear_SrcType = 0x10, |
| 39 | //! kQuarterClear_SrcType in a layer. |
| 40 | kQuarterClearInLayer_SrcType = 0x20, |
| 41 | //! A W/2xH/2 transparent image. |
| 42 | kSmallTransparentImage_SrcType = 0x40, |
| 43 | //! kRectangleImage_SrcType drawn directly with a mask. |
| 44 | kRectangleWithMask_SrcType = 0x80, |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 45 | |
reed | e712532 | 2016-02-09 11:59:24 -0800 | [diff] [blame] | 46 | kAll_SrcType = 0xFF, //!< All the source types. |
| 47 | kBasic_SrcType = 0x03, //!< Just basic source types. |
| 48 | }; |
| 49 | |
| 50 | const struct { |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 51 | SkBlendMode fMode; |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 52 | int fSourceTypeMask; // The source types to use this |
reed | e712532 | 2016-02-09 11:59:24 -0800 | [diff] [blame] | 53 | // mode with. See draw_mode for |
| 54 | // an explanation of each type. |
| 55 | // PDF has to play some tricks |
| 56 | // to support the base modes, |
| 57 | // test those more extensively. |
| 58 | } gModes[] = { |
Brian Osman | d1e67e7 | 2017-03-15 12:19:37 -0400 | [diff] [blame] | 59 | { SkBlendMode::kClear, kAll_SrcType }, |
| 60 | { SkBlendMode::kSrc, kAll_SrcType }, |
| 61 | { SkBlendMode::kDst, kAll_SrcType }, |
| 62 | { SkBlendMode::kSrcOver, kAll_SrcType }, |
| 63 | { SkBlendMode::kDstOver, kAll_SrcType }, |
| 64 | { SkBlendMode::kSrcIn, kAll_SrcType }, |
| 65 | { SkBlendMode::kDstIn, kAll_SrcType }, |
| 66 | { SkBlendMode::kSrcOut, kAll_SrcType }, |
| 67 | { SkBlendMode::kDstOut, kAll_SrcType }, |
| 68 | { SkBlendMode::kSrcATop, kAll_SrcType }, |
| 69 | { SkBlendMode::kDstATop, kAll_SrcType }, |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 70 | |
Brian Osman | d1e67e7 | 2017-03-15 12:19:37 -0400 | [diff] [blame] | 71 | { SkBlendMode::kXor, kBasic_SrcType }, |
| 72 | { SkBlendMode::kPlus, kBasic_SrcType }, |
| 73 | { SkBlendMode::kModulate, kAll_SrcType }, |
| 74 | { SkBlendMode::kScreen, kBasic_SrcType }, |
| 75 | { SkBlendMode::kOverlay, kBasic_SrcType }, |
| 76 | { SkBlendMode::kDarken, kBasic_SrcType }, |
| 77 | { SkBlendMode::kLighten, kBasic_SrcType }, |
| 78 | { SkBlendMode::kColorDodge, kBasic_SrcType }, |
| 79 | { SkBlendMode::kColorBurn, kBasic_SrcType }, |
| 80 | { SkBlendMode::kHardLight, kBasic_SrcType }, |
| 81 | { SkBlendMode::kSoftLight, kBasic_SrcType }, |
| 82 | { SkBlendMode::kDifference, kBasic_SrcType }, |
| 83 | { SkBlendMode::kExclusion, kBasic_SrcType }, |
| 84 | { SkBlendMode::kMultiply, kAll_SrcType }, |
| 85 | { SkBlendMode::kHue, kBasic_SrcType }, |
| 86 | { SkBlendMode::kSaturation, kBasic_SrcType }, |
| 87 | { SkBlendMode::kColor, kBasic_SrcType }, |
| 88 | { SkBlendMode::kLuminosity, kBasic_SrcType }, |
reed | e712532 | 2016-02-09 11:59:24 -0800 | [diff] [blame] | 89 | }; |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 90 | |
commit-bot@chromium.org | 7542dc8 | 2013-12-03 21:08:46 +0000 | [diff] [blame] | 91 | static void make_bitmaps(int w, int h, SkBitmap* src, SkBitmap* dst, |
| 92 | SkBitmap* transparent) { |
reed@google.com | eb9a46c | 2014-01-25 16:46:20 +0000 | [diff] [blame] | 93 | src->allocN32Pixels(w, h); |
junov@google.com | dbfac8a | 2012-12-06 21:47:40 +0000 | [diff] [blame] | 94 | src->eraseColor(SK_ColorTRANSPARENT); |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 95 | |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 96 | SkPaint p; |
mike@reedtribe.org | 3bd2173 | 2012-09-26 02:45:10 +0000 | [diff] [blame] | 97 | p.setAntiAlias(true); |
| 98 | |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 99 | SkRect r; |
| 100 | SkScalar ww = SkIntToScalar(w); |
| 101 | SkScalar hh = SkIntToScalar(h); |
| 102 | |
mike@reedtribe.org | 3bd2173 | 2012-09-26 02:45:10 +0000 | [diff] [blame] | 103 | { |
| 104 | SkCanvas c(*src); |
Mike Klein | ea3f014 | 2019-03-20 11:12:10 -0500 | [diff] [blame] | 105 | p.setColor(ToolUtils::color_to_565(0xFFFFCC44)); |
Mike Reed | 92b3335 | 2019-08-24 19:39:13 -0400 | [diff] [blame] | 106 | r.setWH(ww*3/4, hh*3/4); |
mike@reedtribe.org | 3bd2173 | 2012-09-26 02:45:10 +0000 | [diff] [blame] | 107 | c.drawOval(r, p); |
| 108 | } |
tomhudson@google.com | 86bf5c9 | 2011-04-26 18:15:03 +0000 | [diff] [blame] | 109 | |
commit-bot@chromium.org | dac5225 | 2014-02-17 21:21:46 +0000 | [diff] [blame] | 110 | dst->allocN32Pixels(w, h); |
junov@google.com | dbfac8a | 2012-12-06 21:47:40 +0000 | [diff] [blame] | 111 | dst->eraseColor(SK_ColorTRANSPARENT); |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 112 | |
mike@reedtribe.org | 3bd2173 | 2012-09-26 02:45:10 +0000 | [diff] [blame] | 113 | { |
| 114 | SkCanvas c(*dst); |
Mike Klein | ea3f014 | 2019-03-20 11:12:10 -0500 | [diff] [blame] | 115 | p.setColor(ToolUtils::color_to_565(0xFF66AAFF)); |
Mike Reed | 92b3335 | 2019-08-24 19:39:13 -0400 | [diff] [blame] | 116 | r.setLTRB(ww/3, hh/3, ww*19/20, hh*19/20); |
mike@reedtribe.org | 3bd2173 | 2012-09-26 02:45:10 +0000 | [diff] [blame] | 117 | c.drawRect(r, p); |
| 118 | } |
commit-bot@chromium.org | 7542dc8 | 2013-12-03 21:08:46 +0000 | [diff] [blame] | 119 | |
commit-bot@chromium.org | dac5225 | 2014-02-17 21:21:46 +0000 | [diff] [blame] | 120 | transparent->allocN32Pixels(w, h); |
commit-bot@chromium.org | 7542dc8 | 2013-12-03 21:08:46 +0000 | [diff] [blame] | 121 | transparent->eraseColor(SK_ColorTRANSPARENT); |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 122 | } |
| 123 | |
scroggo@google.com | 7312a18 | 2013-01-28 21:14:21 +0000 | [diff] [blame] | 124 | static uint16_t gData[] = { 0xFFFF, 0xCCCF, 0xCCCF, 0xFFFF }; |
| 125 | |
reed | e712532 | 2016-02-09 11:59:24 -0800 | [diff] [blame] | 126 | class XfermodesGM : public skiagm::GM { |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 127 | SkBitmap fBG; |
commit-bot@chromium.org | 7542dc8 | 2013-12-03 21:08:46 +0000 | [diff] [blame] | 128 | SkBitmap fSrcB, fDstB, fTransparent; |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 129 | |
vandebo@chromium.org | 3b41621 | 2013-10-30 20:48:05 +0000 | [diff] [blame] | 130 | /* The srcType argument indicates what to draw for the source part. Skia |
| 131 | * uses the implied shape of the drawing command and these modes |
| 132 | * demonstrate that. |
| 133 | */ |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 134 | void draw_mode(SkCanvas* canvas, SkBlendMode mode, SrcType srcType, SkScalar x, SkScalar y) { |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 135 | SkPaint p; |
vandebo@chromium.org | 3b41621 | 2013-10-30 20:48:05 +0000 | [diff] [blame] | 136 | SkMatrix m; |
| 137 | bool restoreNeeded = false; |
| 138 | m.setTranslate(x, y); |
tomhudson@google.com | 86bf5c9 | 2011-04-26 18:15:03 +0000 | [diff] [blame] | 139 | |
Florin Malita | c54d8db | 2014-12-10 12:02:16 -0500 | [diff] [blame] | 140 | canvas->drawBitmap(fSrcB, x, y, &p); |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 141 | p.setBlendMode(mode); |
vandebo@chromium.org | 3b41621 | 2013-10-30 20:48:05 +0000 | [diff] [blame] | 142 | switch (srcType) { |
Florin Malita | c54d8db | 2014-12-10 12:02:16 -0500 | [diff] [blame] | 143 | case kSmallTransparentImage_SrcType: { |
commit-bot@chromium.org | 7542dc8 | 2013-12-03 21:08:46 +0000 | [diff] [blame] | 144 | m.postScale(SK_ScalarHalf, SK_ScalarHalf, x, y); |
Florin Malita | c54d8db | 2014-12-10 12:02:16 -0500 | [diff] [blame] | 145 | |
| 146 | SkAutoCanvasRestore acr(canvas, true); |
| 147 | canvas->concat(m); |
| 148 | canvas->drawBitmap(fTransparent, 0, 0, &p); |
commit-bot@chromium.org | 7542dc8 | 2013-12-03 21:08:46 +0000 | [diff] [blame] | 149 | break; |
Florin Malita | c54d8db | 2014-12-10 12:02:16 -0500 | [diff] [blame] | 150 | } |
vandebo@chromium.org | 3b41621 | 2013-10-30 20:48:05 +0000 | [diff] [blame] | 151 | case kQuarterClearInLayer_SrcType: { |
vandebo@chromium.org | f5747da | 2013-10-30 21:29:47 +0000 | [diff] [blame] | 152 | SkRect bounds = SkRect::MakeXYWH(x, y, SkIntToScalar(W), |
| 153 | SkIntToScalar(H)); |
vandebo@chromium.org | 3b41621 | 2013-10-30 20:48:05 +0000 | [diff] [blame] | 154 | canvas->saveLayer(&bounds, &p); |
| 155 | restoreNeeded = true; |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 156 | p.setBlendMode(SkBlendMode::kSrcOver); |
vandebo@chromium.org | 3b41621 | 2013-10-30 20:48:05 +0000 | [diff] [blame] | 157 | // Fall through. |
| 158 | } |
| 159 | case kQuarterClear_SrcType: { |
| 160 | SkScalar halfW = SkIntToScalar(W) / 2; |
| 161 | SkScalar halfH = SkIntToScalar(H) / 2; |
Mike Klein | ea3f014 | 2019-03-20 11:12:10 -0500 | [diff] [blame] | 162 | p.setColor(ToolUtils::color_to_565(0xFF66AAFF)); |
vandebo@chromium.org | f5747da | 2013-10-30 21:29:47 +0000 | [diff] [blame] | 163 | SkRect r = SkRect::MakeXYWH(x + halfW, y, halfW, |
| 164 | SkIntToScalar(H)); |
vandebo@chromium.org | 3b41621 | 2013-10-30 20:48:05 +0000 | [diff] [blame] | 165 | canvas->drawRect(r, p); |
Mike Klein | ea3f014 | 2019-03-20 11:12:10 -0500 | [diff] [blame] | 166 | p.setColor(ToolUtils::color_to_565(0xFFAA66FF)); |
vandebo@chromium.org | f5747da | 2013-10-30 21:29:47 +0000 | [diff] [blame] | 167 | r = SkRect::MakeXYWH(x, y + halfH, SkIntToScalar(W), halfH); |
vandebo@chromium.org | 3b41621 | 2013-10-30 20:48:05 +0000 | [diff] [blame] | 168 | canvas->drawRect(r, p); |
| 169 | break; |
| 170 | } |
commit-bot@chromium.org | 4e8f1e5 | 2013-12-17 23:38:28 +0000 | [diff] [blame] | 171 | case kRectangleWithMask_SrcType: { |
commit-bot@chromium.org | 091a594 | 2014-04-18 14:19:31 +0000 | [diff] [blame] | 172 | canvas->save(); |
commit-bot@chromium.org | 4e8f1e5 | 2013-12-17 23:38:28 +0000 | [diff] [blame] | 173 | restoreNeeded = true; |
| 174 | SkScalar w = SkIntToScalar(W); |
| 175 | SkScalar h = SkIntToScalar(H); |
| 176 | SkRect r = SkRect::MakeXYWH(x, y + h / 4, w, h * 23 / 60); |
| 177 | canvas->clipRect(r); |
| 178 | // Fall through. |
| 179 | } |
vandebo@chromium.org | 3b41621 | 2013-10-30 20:48:05 +0000 | [diff] [blame] | 180 | case kRectangle_SrcType: { |
| 181 | SkScalar w = SkIntToScalar(W); |
| 182 | SkScalar h = SkIntToScalar(H); |
| 183 | SkRect r = SkRect::MakeXYWH(x + w / 3, y + h / 3, |
| 184 | w * 37 / 60, h * 37 / 60); |
Mike Klein | ea3f014 | 2019-03-20 11:12:10 -0500 | [diff] [blame] | 185 | p.setColor(ToolUtils::color_to_565(0xFF66AAFF)); |
vandebo@chromium.org | 3b41621 | 2013-10-30 20:48:05 +0000 | [diff] [blame] | 186 | canvas->drawRect(r, p); |
| 187 | break; |
| 188 | } |
| 189 | case kSmallRectangleImageWithAlpha_SrcType: |
| 190 | m.postScale(SK_ScalarHalf, SK_ScalarHalf, x, y); |
| 191 | // Fall through. |
| 192 | case kRectangleImageWithAlpha_SrcType: |
| 193 | p.setAlpha(0x88); |
| 194 | // Fall through. |
Florin Malita | c54d8db | 2014-12-10 12:02:16 -0500 | [diff] [blame] | 195 | case kRectangleImage_SrcType: { |
| 196 | SkAutoCanvasRestore acr(canvas, true); |
| 197 | canvas->concat(m); |
| 198 | canvas->drawBitmap(fDstB, 0, 0, &p); |
vandebo@chromium.org | 3b41621 | 2013-10-30 20:48:05 +0000 | [diff] [blame] | 199 | break; |
Florin Malita | c54d8db | 2014-12-10 12:02:16 -0500 | [diff] [blame] | 200 | } |
vandebo@chromium.org | 3b41621 | 2013-10-30 20:48:05 +0000 | [diff] [blame] | 201 | default: |
| 202 | break; |
| 203 | } |
| 204 | |
| 205 | if (restoreNeeded) { |
| 206 | canvas->restore(); |
| 207 | } |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 208 | } |
tomhudson@google.com | 86bf5c9 | 2011-04-26 18:15:03 +0000 | [diff] [blame] | 209 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 210 | void onOnceBeforeDraw() override { |
commit-bot@chromium.org | dac5225 | 2014-02-17 21:21:46 +0000 | [diff] [blame] | 211 | fBG.installPixels(SkImageInfo::Make(2, 2, kARGB_4444_SkColorType, |
| 212 | kOpaque_SkAlphaType), |
| 213 | gData, 4); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 214 | |
commit-bot@chromium.org | 7542dc8 | 2013-12-03 21:08:46 +0000 | [diff] [blame] | 215 | make_bitmaps(W, H, &fSrcB, &fDstB, &fTransparent); |
reed@google.com | 5213c04 | 2011-12-20 13:41:09 +0000 | [diff] [blame] | 216 | } |
| 217 | |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 218 | public: |
reed@google.com | f3c1cc9 | 2010-12-23 16:45:33 +0000 | [diff] [blame] | 219 | const static int W = 64; |
| 220 | const static int H = 64; |
scroggo@google.com | 7312a18 | 2013-01-28 21:14:21 +0000 | [diff] [blame] | 221 | XfermodesGM() {} |
tomhudson@google.com | 86bf5c9 | 2011-04-26 18:15:03 +0000 | [diff] [blame] | 222 | |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 223 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 224 | SkString onShortName() override { |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 225 | return SkString("xfermodes"); |
| 226 | } |
| 227 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 228 | SkISize onISize() override { |
Mike Reed | 403d154 | 2016-09-26 18:51:24 -0400 | [diff] [blame] | 229 | return SkISize::Make(1990, 570); |
reed@android.com | 048522d | 2009-06-23 12:19:41 +0000 | [diff] [blame] | 230 | } |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 231 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 232 | void onDraw(SkCanvas* canvas) override { |
reed@google.com | f3c1cc9 | 2010-12-23 16:45:33 +0000 | [diff] [blame] | 233 | canvas->translate(SkIntToScalar(10), SkIntToScalar(20)); |
tomhudson@google.com | 86bf5c9 | 2011-04-26 18:15:03 +0000 | [diff] [blame] | 234 | |
reed@google.com | f3c1cc9 | 2010-12-23 16:45:33 +0000 | [diff] [blame] | 235 | const SkScalar w = SkIntToScalar(W); |
| 236 | const SkScalar h = SkIntToScalar(H); |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 237 | SkMatrix m; |
| 238 | m.setScale(SkIntToScalar(6), SkIntToScalar(6)); |
Mike Reed | 50acf8f | 2019-04-08 13:20:23 -0400 | [diff] [blame] | 239 | auto s = fBG.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, &m); |
tomhudson@google.com | 86bf5c9 | 2011-04-26 18:15:03 +0000 | [diff] [blame] | 240 | |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 241 | SkPaint labelP; |
| 242 | labelP.setAntiAlias(true); |
Mike Reed | b579f07 | 2019-01-03 15:45:53 -0500 | [diff] [blame] | 243 | |
Mike Klein | ea3f014 | 2019-03-20 11:12:10 -0500 | [diff] [blame] | 244 | SkFont font(ToolUtils::create_portable_typeface()); |
tomhudson@google.com | 86bf5c9 | 2011-04-26 18:15:03 +0000 | [diff] [blame] | 245 | |
reed@android.com | c9c6422 | 2009-06-23 00:09:12 +0000 | [diff] [blame] | 246 | const int W = 5; |
tomhudson@google.com | 86bf5c9 | 2011-04-26 18:15:03 +0000 | [diff] [blame] | 247 | |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 248 | SkScalar x0 = 0; |
vandebo@chromium.org | 3b41621 | 2013-10-30 20:48:05 +0000 | [diff] [blame] | 249 | SkScalar y0 = 0; |
| 250 | for (int sourceType = 1; sourceType & kAll_SrcType; sourceType <<= 1) { |
| 251 | SkScalar x = x0, y = y0; |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 252 | for (size_t i = 0; i < SK_ARRAY_COUNT(gModes); i++) { |
vandebo@chromium.org | 3b41621 | 2013-10-30 20:48:05 +0000 | [diff] [blame] | 253 | if ((gModes[i].fSourceTypeMask & sourceType) == 0) { |
| 254 | continue; |
| 255 | } |
Mike Reed | 403d154 | 2016-09-26 18:51:24 -0400 | [diff] [blame] | 256 | SkRect r{ x, y, x+w, y+h }; |
tomhudson@google.com | 86bf5c9 | 2011-04-26 18:15:03 +0000 | [diff] [blame] | 257 | |
reed@google.com | f3c1cc9 | 2010-12-23 16:45:33 +0000 | [diff] [blame] | 258 | SkPaint p; |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 259 | p.setStyle(SkPaint::kFill_Style); |
| 260 | p.setShader(s); |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 261 | canvas->drawRect(r, p); |
tomhudson@google.com | 86bf5c9 | 2011-04-26 18:15:03 +0000 | [diff] [blame] | 262 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 263 | canvas->saveLayer(&r, nullptr); |
Mike Reed | 403d154 | 2016-09-26 18:51:24 -0400 | [diff] [blame] | 264 | draw_mode(canvas, gModes[i].fMode, static_cast<SrcType>(sourceType), |
vandebo@chromium.org | 3b41621 | 2013-10-30 20:48:05 +0000 | [diff] [blame] | 265 | r.fLeft, r.fTop); |
reed@google.com | f3c1cc9 | 2010-12-23 16:45:33 +0000 | [diff] [blame] | 266 | canvas->restore(); |
tomhudson@google.com | 86bf5c9 | 2011-04-26 18:15:03 +0000 | [diff] [blame] | 267 | |
reed@google.com | f3c1cc9 | 2010-12-23 16:45:33 +0000 | [diff] [blame] | 268 | r.inset(-SK_ScalarHalf, -SK_ScalarHalf); |
| 269 | p.setStyle(SkPaint::kStroke_Style); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 270 | p.setShader(nullptr); |
reed@google.com | f3c1cc9 | 2010-12-23 16:45:33 +0000 | [diff] [blame] | 271 | canvas->drawRect(r, p); |
tomhudson@google.com | 86bf5c9 | 2011-04-26 18:15:03 +0000 | [diff] [blame] | 272 | |
reed@google.com | f3c1cc9 | 2010-12-23 16:45:33 +0000 | [diff] [blame] | 273 | #if 1 |
Brian Osman | d1e67e7 | 2017-03-15 12:19:37 -0400 | [diff] [blame] | 274 | const char* label = SkBlendMode_Name(gModes[i].fMode); |
Mike Reed | b579f07 | 2019-01-03 15:45:53 -0500 | [diff] [blame] | 275 | SkTextUtils::DrawString(canvas, label, x + w/2, y - font.getSize()/2, |
| 276 | font, labelP, SkTextUtils::kCenter_Align); |
reed@google.com | f3c1cc9 | 2010-12-23 16:45:33 +0000 | [diff] [blame] | 277 | #endif |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 278 | x += w + SkIntToScalar(10); |
reed@android.com | c9c6422 | 2009-06-23 00:09:12 +0000 | [diff] [blame] | 279 | if ((i % W) == W - 1) { |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 280 | x = x0; |
| 281 | y += h + SkIntToScalar(30); |
| 282 | } |
| 283 | } |
vandebo@chromium.org | 3b41621 | 2013-10-30 20:48:05 +0000 | [diff] [blame] | 284 | if (y < 320) { |
| 285 | if (x > x0) { |
| 286 | y += h + SkIntToScalar(30); |
| 287 | } |
| 288 | y0 = y; |
| 289 | } else { |
| 290 | x0 += SkIntToScalar(400); |
| 291 | y0 = 0; |
| 292 | } |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 293 | } |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | private: |
| 297 | typedef GM INHERITED; |
| 298 | }; |
reed | e712532 | 2016-02-09 11:59:24 -0800 | [diff] [blame] | 299 | DEF_GM( return new XfermodesGM; ) |