senorblanco@chromium.org | 8d21f6c | 2012-10-12 19:14:06 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 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 | */ |
| 7 | |
| 8 | #include "gm.h" |
| 9 | #include "SkCanvas.h" |
| 10 | #include "SkColorMatrixFilter.h" |
| 11 | #include "SkColorPriv.h" |
Mike Reed | c723b70 | 2019-03-12 11:49:00 -0400 | [diff] [blame] | 12 | #include "SkMixer.h" |
senorblanco@chromium.org | 8d21f6c | 2012-10-12 19:14:06 +0000 | [diff] [blame] | 13 | #include "SkShader.h" |
| 14 | |
| 15 | #include "SkBlurImageFilter.h" |
| 16 | #include "SkColorFilterImageFilter.h" |
Mike Klein | 33d2055 | 2017-03-22 13:47:51 -0400 | [diff] [blame] | 17 | #include "SkTDArray.h" |
senorblanco@chromium.org | 8d21f6c | 2012-10-12 19:14:06 +0000 | [diff] [blame] | 18 | |
| 19 | #define FILTER_WIDTH SkIntToScalar(30) |
| 20 | #define FILTER_HEIGHT SkIntToScalar(30) |
| 21 | #define MARGIN SkIntToScalar(10) |
| 22 | |
reed | d053ce9 | 2016-03-22 10:17:23 -0700 | [diff] [blame] | 23 | static sk_sp<SkColorFilter> cf_make_brightness(float brightness) { |
Mike Reed | df85c38 | 2017-02-14 10:59:19 -0500 | [diff] [blame] | 24 | SkScalar amount255 = brightness * 255; |
reed | 3061af4 | 2016-01-07 15:47:29 -0800 | [diff] [blame] | 25 | SkScalar matrix[20] = { |
| 26 | 1, 0, 0, 0, amount255, |
| 27 | 0, 1, 0, 0, amount255, |
| 28 | 0, 0, 1, 0, amount255, |
| 29 | 0, 0, 0, 1, 0 }; |
reed | d053ce9 | 2016-03-22 10:17:23 -0700 | [diff] [blame] | 30 | return SkColorFilter::MakeMatrixFilterRowMajor255(matrix); |
senorblanco@chromium.org | 8d21f6c | 2012-10-12 19:14:06 +0000 | [diff] [blame] | 31 | } |
| 32 | |
reed | d053ce9 | 2016-03-22 10:17:23 -0700 | [diff] [blame] | 33 | static sk_sp<SkColorFilter> cf_make_grayscale() { |
senorblanco@chromium.org | 8d21f6c | 2012-10-12 19:14:06 +0000 | [diff] [blame] | 34 | SkScalar matrix[20]; |
| 35 | memset(matrix, 0, 20 * sizeof(SkScalar)); |
commit-bot@chromium.org | 4b413c8 | 2013-11-25 19:44:07 +0000 | [diff] [blame] | 36 | matrix[0] = matrix[5] = matrix[10] = 0.2126f; |
| 37 | matrix[1] = matrix[6] = matrix[11] = 0.7152f; |
| 38 | matrix[2] = matrix[7] = matrix[12] = 0.0722f; |
| 39 | matrix[18] = 1.0f; |
reed | d053ce9 | 2016-03-22 10:17:23 -0700 | [diff] [blame] | 40 | return SkColorFilter::MakeMatrixFilterRowMajor255(matrix); |
reed | 3061af4 | 2016-01-07 15:47:29 -0800 | [diff] [blame] | 41 | } |
| 42 | |
reed | d053ce9 | 2016-03-22 10:17:23 -0700 | [diff] [blame] | 43 | static sk_sp<SkColorFilter> cf_make_colorize(SkColor color) { |
Mike Reed | 7d954ad | 2016-10-28 15:42:34 -0400 | [diff] [blame] | 44 | return SkColorFilter::MakeModeFilter(color, SkBlendMode::kSrc); |
reed | 3061af4 | 2016-01-07 15:47:29 -0800 | [diff] [blame] | 45 | } |
| 46 | |
reed | d053ce9 | 2016-03-22 10:17:23 -0700 | [diff] [blame] | 47 | static void sk_gm_get_colorfilters(SkTArray<sk_sp<SkColorFilter>>* array) { |
| 48 | array->push_back(cf_make_brightness(0.5f)); |
| 49 | array->push_back(cf_make_grayscale()); |
| 50 | array->push_back(cf_make_colorize(SK_ColorBLUE)); |
reed | 3061af4 | 2016-01-07 15:47:29 -0800 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
Hal Canary | 8a00144 | 2018-09-19 11:31:27 -0400 | [diff] [blame] | 54 | |
reed | 3061af4 | 2016-01-07 15:47:29 -0800 | [diff] [blame] | 55 | #include "SkGradientShader.h" |
| 56 | #include "SkImage.h" |
| 57 | #include "Resources.h" |
| 58 | |
reed | 2ad1aa6 | 2016-03-09 09:50:50 -0800 | [diff] [blame] | 59 | static sk_sp<SkShader> sh_make_lineargradient0() { |
reed | 3061af4 | 2016-01-07 15:47:29 -0800 | [diff] [blame] | 60 | const SkPoint pts[] = { { 0, 0 }, { 100, 100 } }; |
| 61 | const SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE }; |
Mike Reed | fae8fce | 2019-04-03 10:27:45 -0400 | [diff] [blame^] | 62 | return SkGradientShader::MakeLinear(pts, colors, nullptr, 3, SkTileMode::kRepeat); |
reed | 3061af4 | 2016-01-07 15:47:29 -0800 | [diff] [blame] | 63 | } |
| 64 | |
reed | 2ad1aa6 | 2016-03-09 09:50:50 -0800 | [diff] [blame] | 65 | static sk_sp<SkShader> sh_make_lineargradient1() { |
reed | 3061af4 | 2016-01-07 15:47:29 -0800 | [diff] [blame] | 66 | const SkPoint pts[] = { { 0, 0 }, { 100, 100 } }; |
| 67 | const SkColor colors[] = { SK_ColorRED, 0x0000FF00, SK_ColorBLUE }; |
Mike Reed | fae8fce | 2019-04-03 10:27:45 -0400 | [diff] [blame^] | 68 | return SkGradientShader::MakeLinear(pts, colors, nullptr, 3, SkTileMode::kRepeat); |
reed | 3061af4 | 2016-01-07 15:47:29 -0800 | [diff] [blame] | 69 | } |
| 70 | |
reed | 2ad1aa6 | 2016-03-09 09:50:50 -0800 | [diff] [blame] | 71 | static sk_sp<SkShader> sh_make_image() { |
Hal Canary | c465d13 | 2017-12-08 10:21:31 -0500 | [diff] [blame] | 72 | sk_sp<SkImage> image(GetResourceAsImage("images/mandrill_128.png")); |
bsalomon | dfe3e50 | 2016-01-21 06:44:08 -0800 | [diff] [blame] | 73 | if (!image) { |
| 74 | return nullptr; |
| 75 | } |
Mike Reed | fae8fce | 2019-04-03 10:27:45 -0400 | [diff] [blame^] | 76 | return image->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat); |
reed | 3061af4 | 2016-01-07 15:47:29 -0800 | [diff] [blame] | 77 | } |
| 78 | |
reed | 57fa241 | 2016-01-07 17:56:33 -0800 | [diff] [blame] | 79 | static void sk_gm_get_shaders(SkTDArray<SkShader*>* array) { |
reed | 2ad1aa6 | 2016-03-09 09:50:50 -0800 | [diff] [blame] | 80 | if (auto shader = sh_make_lineargradient0()) { |
| 81 | *array->append() = shader.release(); |
bsalomon | dfe3e50 | 2016-01-21 06:44:08 -0800 | [diff] [blame] | 82 | } |
reed | 2ad1aa6 | 2016-03-09 09:50:50 -0800 | [diff] [blame] | 83 | if (auto shader = sh_make_lineargradient1()) { |
| 84 | *array->append() = shader.release(); |
bsalomon | dfe3e50 | 2016-01-21 06:44:08 -0800 | [diff] [blame] | 85 | } |
reed | 2ad1aa6 | 2016-03-09 09:50:50 -0800 | [diff] [blame] | 86 | if (auto shader = sh_make_image()) { |
| 87 | *array->append() = shader.release(); |
bsalomon | dfe3e50 | 2016-01-21 06:44:08 -0800 | [diff] [blame] | 88 | } |
reed | 3061af4 | 2016-01-07 15:47:29 -0800 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 92 | |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 93 | static sk_sp<SkImageFilter> make_blur(float amount, sk_sp<SkImageFilter> input) { |
| 94 | return SkBlurImageFilter::Make(amount, amount, std::move(input)); |
reed | 3061af4 | 2016-01-07 15:47:29 -0800 | [diff] [blame] | 95 | } |
| 96 | |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 97 | static sk_sp<SkImageFilter> make_brightness(float amount, sk_sp<SkImageFilter> input) { |
robertphillips | 5605b56 | 2016-04-05 11:50:42 -0700 | [diff] [blame] | 98 | return SkColorFilterImageFilter::Make(cf_make_brightness(amount), std::move(input)); |
reed | 3061af4 | 2016-01-07 15:47:29 -0800 | [diff] [blame] | 99 | } |
| 100 | |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 101 | static sk_sp<SkImageFilter> make_grayscale(sk_sp<SkImageFilter> input) { |
robertphillips | 5605b56 | 2016-04-05 11:50:42 -0700 | [diff] [blame] | 102 | return SkColorFilterImageFilter::Make(cf_make_grayscale(), std::move(input)); |
senorblanco@chromium.org | 8d21f6c | 2012-10-12 19:14:06 +0000 | [diff] [blame] | 103 | } |
| 104 | |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 105 | static sk_sp<SkImageFilter> make_mode_blue(sk_sp<SkImageFilter> input) { |
robertphillips | 5605b56 | 2016-04-05 11:50:42 -0700 | [diff] [blame] | 106 | return SkColorFilterImageFilter::Make(cf_make_colorize(SK_ColorBLUE), std::move(input)); |
senorblanco@chromium.org | 8d21f6c | 2012-10-12 19:14:06 +0000 | [diff] [blame] | 107 | } |
| 108 | |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 109 | static void draw_clipped_rect(SkCanvas* canvas, |
| 110 | const SkRect& r, |
| 111 | const SkPaint& paint, |
| 112 | float outset = 0.0f) { |
robertphillips | 5605b56 | 2016-04-05 11:50:42 -0700 | [diff] [blame] | 113 | canvas->save(); |
| 114 | SkRect clip(r); |
| 115 | clip.outset(outset, outset); |
| 116 | canvas->clipRect(clip); |
| 117 | canvas->drawRect(r, paint); |
| 118 | canvas->restore(); |
halcanary | 2a24338 | 2015-09-09 08:16:41 -0700 | [diff] [blame] | 119 | } |
senorblanco@chromium.org | 8d21f6c | 2012-10-12 19:14:06 +0000 | [diff] [blame] | 120 | |
halcanary | 2a24338 | 2015-09-09 08:16:41 -0700 | [diff] [blame] | 121 | DEF_SIMPLE_GM(colorfilterimagefilter, canvas, 400, 100){ |
senorblanco@chromium.org | 8d21f6c | 2012-10-12 19:14:06 +0000 | [diff] [blame] | 122 | SkRect r = SkRect::MakeWH(FILTER_WIDTH, FILTER_HEIGHT); |
| 123 | SkPaint paint; |
| 124 | paint.setColor(SK_ColorRED); |
| 125 | canvas->save(); |
| 126 | for (float brightness = -1.0f; brightness <= 1.0f; brightness += 0.2f) { |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 127 | sk_sp<SkImageFilter> dim(make_brightness(-brightness, nullptr)); |
| 128 | sk_sp<SkImageFilter> bright(make_brightness(brightness, std::move(dim))); |
| 129 | paint.setImageFilter(std::move(bright)); |
| 130 | draw_clipped_rect(canvas, r, paint); |
senorblanco@chromium.org | 8d21f6c | 2012-10-12 19:14:06 +0000 | [diff] [blame] | 131 | canvas->translate(FILTER_WIDTH + MARGIN, 0); |
| 132 | } |
| 133 | canvas->restore(); |
| 134 | canvas->translate(0, FILTER_HEIGHT + MARGIN); |
| 135 | { |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 136 | sk_sp<SkImageFilter> brightness(make_brightness(0.9f, nullptr)); |
| 137 | sk_sp<SkImageFilter> grayscale(make_grayscale(std::move(brightness))); |
| 138 | paint.setImageFilter(std::move(grayscale)); |
| 139 | draw_clipped_rect(canvas, r, paint); |
senorblanco@chromium.org | 8d21f6c | 2012-10-12 19:14:06 +0000 | [diff] [blame] | 140 | canvas->translate(FILTER_WIDTH + MARGIN, 0); |
| 141 | } |
| 142 | { |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 143 | sk_sp<SkImageFilter> grayscale(make_grayscale(nullptr)); |
| 144 | sk_sp<SkImageFilter> brightness(make_brightness(0.9f, std::move(grayscale))); |
| 145 | paint.setImageFilter(std::move(brightness)); |
| 146 | draw_clipped_rect(canvas, r, paint); |
senorblanco@chromium.org | 8d21f6c | 2012-10-12 19:14:06 +0000 | [diff] [blame] | 147 | canvas->translate(FILTER_WIDTH + MARGIN, 0); |
| 148 | } |
| 149 | { |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 150 | sk_sp<SkImageFilter> blue(make_mode_blue(nullptr)); |
| 151 | sk_sp<SkImageFilter> brightness(make_brightness(1.0f, std::move(blue))); |
| 152 | paint.setImageFilter(std::move(brightness)); |
| 153 | draw_clipped_rect(canvas, r, paint); |
senorblanco@chromium.org | 8d21f6c | 2012-10-12 19:14:06 +0000 | [diff] [blame] | 154 | canvas->translate(FILTER_WIDTH + MARGIN, 0); |
| 155 | } |
| 156 | { |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 157 | sk_sp<SkImageFilter> brightness(make_brightness(1.0f, nullptr)); |
| 158 | sk_sp<SkImageFilter> blue(make_mode_blue(std::move(brightness))); |
| 159 | paint.setImageFilter(std::move(blue)); |
| 160 | draw_clipped_rect(canvas, r, paint); |
senorblanco@chromium.org | 8d21f6c | 2012-10-12 19:14:06 +0000 | [diff] [blame] | 161 | canvas->translate(FILTER_WIDTH + MARGIN, 0); |
| 162 | } |
| 163 | { |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 164 | sk_sp<SkImageFilter> blur(make_blur(3.0f, nullptr)); |
| 165 | sk_sp<SkImageFilter> brightness(make_brightness(0.5f, std::move(blur))); |
| 166 | paint.setImageFilter(std::move(brightness)); |
| 167 | draw_clipped_rect(canvas, r, paint, 3); |
senorblanco@chromium.org | 8d21f6c | 2012-10-12 19:14:06 +0000 | [diff] [blame] | 168 | canvas->translate(FILTER_WIDTH + MARGIN, 0); |
| 169 | } |
senorblanco | 0abdf76 | 2015-08-20 11:10:41 -0700 | [diff] [blame] | 170 | { |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 171 | sk_sp<SkImageFilter> blue(make_mode_blue(nullptr)); |
| 172 | paint.setImageFilter(std::move(blue)); |
| 173 | draw_clipped_rect(canvas, r, paint, 5); |
senorblanco | 0abdf76 | 2015-08-20 11:10:41 -0700 | [diff] [blame] | 174 | canvas->translate(FILTER_WIDTH + MARGIN, 0); |
| 175 | } |
halcanary | 2a24338 | 2015-09-09 08:16:41 -0700 | [diff] [blame] | 176 | } |
halcanary | 287d22d | 2015-09-24 10:20:05 -0700 | [diff] [blame] | 177 | |
| 178 | DEF_SIMPLE_GM(colorfilterimagefilter_layer, canvas, 32, 32) { |
| 179 | SkAutoCanvasRestore autoCanvasRestore(canvas, false); |
| 180 | SkColorMatrix cm; |
| 181 | cm.setSaturation(0.0f); |
robertphillips | 5605b56 | 2016-04-05 11:50:42 -0700 | [diff] [blame] | 182 | sk_sp<SkColorFilter> cf(SkColorFilter::MakeMatrixFilterRowMajor255(cm.fMat)); |
halcanary | 287d22d | 2015-09-24 10:20:05 -0700 | [diff] [blame] | 183 | SkPaint p; |
robertphillips | 5605b56 | 2016-04-05 11:50:42 -0700 | [diff] [blame] | 184 | p.setImageFilter(SkColorFilterImageFilter::Make(std::move(cf), nullptr)); |
Ben Wagner | a93a14a | 2017-08-28 10:34:05 -0400 | [diff] [blame] | 185 | canvas->saveLayer(nullptr, &p); |
halcanary | 287d22d | 2015-09-24 10:20:05 -0700 | [diff] [blame] | 186 | canvas->clear(SK_ColorRED); |
| 187 | } |
reed | 3061af4 | 2016-01-07 15:47:29 -0800 | [diff] [blame] | 188 | |
| 189 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 190 | |
Mike Reed | a03d407 | 2017-06-01 09:37:57 -0400 | [diff] [blame] | 191 | #include "SkGradientShader.h" |
Hal Canary | 8a00144 | 2018-09-19 11:31:27 -0400 | [diff] [blame] | 192 | |
reed | 57fa241 | 2016-01-07 17:56:33 -0800 | [diff] [blame] | 193 | template <typename T> class SkTRefArray : public SkTDArray<T> { |
| 194 | public: |
| 195 | ~SkTRefArray() { this->unrefAll(); } |
| 196 | }; |
| 197 | |
Mike Reed | a03d407 | 2017-06-01 09:37:57 -0400 | [diff] [blame] | 198 | DEF_SIMPLE_GM(colorfiltershader, canvas, 610, 610) { |
reed | d053ce9 | 2016-03-22 10:17:23 -0700 | [diff] [blame] | 199 | SkTArray<sk_sp<SkColorFilter>> filters; |
reed | 57fa241 | 2016-01-07 17:56:33 -0800 | [diff] [blame] | 200 | sk_gm_get_colorfilters(&filters); |
| 201 | |
| 202 | SkTRefArray<SkShader*> shaders; |
| 203 | sk_gm_get_shaders(&shaders); |
reed | 3061af4 | 2016-01-07 15:47:29 -0800 | [diff] [blame] | 204 | |
Mike Reed | a03d407 | 2017-06-01 09:37:57 -0400 | [diff] [blame] | 205 | const SkColor colors[] = { SK_ColorRED, SK_ColorBLUE }; |
| 206 | *shaders.append() = SkGradientShader::MakeTwoPointConical({0, 0}, 50, {0, 0}, 150, |
| 207 | colors, nullptr, 2, |
Mike Reed | fae8fce | 2019-04-03 10:27:45 -0400 | [diff] [blame^] | 208 | SkTileMode::kClamp).release(); |
Mike Reed | a03d407 | 2017-06-01 09:37:57 -0400 | [diff] [blame] | 209 | |
reed | 3061af4 | 2016-01-07 15:47:29 -0800 | [diff] [blame] | 210 | SkPaint paint; |
| 211 | SkRect r = SkRect::MakeWH(120, 120); |
| 212 | |
| 213 | canvas->translate(20, 20); |
| 214 | for (int y = 0; y < shaders.count(); ++y) { |
| 215 | SkShader* shader = shaders[y]; |
bsalomon | dfe3e50 | 2016-01-21 06:44:08 -0800 | [diff] [blame] | 216 | |
reed | 3061af4 | 2016-01-07 15:47:29 -0800 | [diff] [blame] | 217 | canvas->save(); |
| 218 | for (int x = -1; x < filters.count(); ++x) { |
reed | d053ce9 | 2016-03-22 10:17:23 -0700 | [diff] [blame] | 219 | sk_sp<SkColorFilter> filter = x >= 0 ? filters[x] : nullptr; |
reed | 3061af4 | 2016-01-07 15:47:29 -0800 | [diff] [blame] | 220 | |
reed | 150835e | 2016-03-10 06:36:49 -0800 | [diff] [blame] | 221 | paint.setShader(shader->makeWithColorFilter(filter)); |
reed | 3061af4 | 2016-01-07 15:47:29 -0800 | [diff] [blame] | 222 | canvas->drawRect(r, paint); |
| 223 | canvas->translate(150, 0); |
| 224 | } |
| 225 | canvas->restore(); |
| 226 | canvas->translate(0, 150); |
| 227 | } |
| 228 | } |
Mike Reed | 01b2b83 | 2017-06-09 10:51:52 -0400 | [diff] [blame] | 229 | |
Mike Reed | c723b70 | 2019-03-12 11:49:00 -0400 | [diff] [blame] | 230 | template <typename Maker> void do_mixershader(SkCanvas* canvas, Maker&& maker) { |
Mike Reed | fae8fce | 2019-04-03 10:27:45 -0400 | [diff] [blame^] | 231 | auto shaderA = GetResourceAsImage("images/mandrill_128.png")->makeShader(SkTileMode::kClamp, |
| 232 | SkTileMode::kClamp); |
Mike Reed | 01b2b83 | 2017-06-09 10:51:52 -0400 | [diff] [blame] | 233 | const SkColor colors[] = { SK_ColorGREEN, 0 }; |
| 234 | auto shaderB = SkGradientShader::MakeRadial({60, 60}, 55, colors, nullptr, 2, |
Mike Reed | fae8fce | 2019-04-03 10:27:45 -0400 | [diff] [blame^] | 235 | SkTileMode::kClamp, |
Mike Reed | 01b2b83 | 2017-06-09 10:51:52 -0400 | [diff] [blame] | 236 | SkGradientShader::kInterpolateColorsInPremul_Flag, |
| 237 | nullptr); |
| 238 | const SkBlendMode modes[] = { |
| 239 | SkBlendMode::kSrc, SkBlendMode::kModulate, SkBlendMode::kColorBurn, SkBlendMode::kPlus, |
| 240 | SkBlendMode::kDstATop, |
| 241 | }; |
| 242 | SkPaint paint; |
| 243 | SkRect r = SkRect::MakeWH(120, 120); |
| 244 | |
| 245 | canvas->translate(10, 10); |
| 246 | for (auto mode : modes) { |
| 247 | canvas->save(); |
| 248 | const int count = 6; |
| 249 | for (int x = 0; x < count; ++x) { |
| 250 | const float t = x * 1.0f / (count - 1); |
Mike Reed | c723b70 | 2019-03-12 11:49:00 -0400 | [diff] [blame] | 251 | paint.setShader(maker(shaderA, shaderB, mode, t)); |
Mike Reed | 01b2b83 | 2017-06-09 10:51:52 -0400 | [diff] [blame] | 252 | canvas->drawRect(r, paint); |
| 253 | canvas->translate(r.width() + 10, 0); |
| 254 | } |
| 255 | canvas->restore(); |
| 256 | canvas->translate(0, r.height() + 20); |
| 257 | } |
| 258 | } |
Mike Reed | c723b70 | 2019-03-12 11:49:00 -0400 | [diff] [blame] | 259 | |
| 260 | DEF_SIMPLE_GM(mixershader, canvas, 800, 700) { |
| 261 | do_mixershader(canvas, [](sk_sp<SkShader> a, sk_sp<SkShader> b, SkBlendMode mode, float t) { |
Mike Reed | 9b2c4e9 | 2019-04-02 09:54:14 -0400 | [diff] [blame] | 262 | auto sh = SkShader::MakeBlend(mode, a, b); |
| 263 | return SkShader::MakeLerp(t, a, sh); |
Mike Reed | c723b70 | 2019-03-12 11:49:00 -0400 | [diff] [blame] | 264 | }); |
| 265 | } |
| 266 | |
| 267 | #include "SkMixerBase.h" |
| 268 | |
Mike Reed | 376d812 | 2019-03-14 11:39:02 -0400 | [diff] [blame] | 269 | DEF_SIMPLE_GM(mixershader2, canvas, 800, 700) { |
Mike Reed | c723b70 | 2019-03-12 11:49:00 -0400 | [diff] [blame] | 270 | do_mixershader(canvas, [](sk_sp<SkShader> a, sk_sp<SkShader> b, SkBlendMode mode, float t) { |
| 271 | // Use mixers to simulate MakeCompose(a, b, mode, t) |
| 272 | auto blender = SkMixer::MakeBlend(mode); |
Mike Reed | 79a7542 | 2019-03-15 15:45:09 -0400 | [diff] [blame] | 273 | auto mx = SkMixer::MakeLerp(t)->makeMerge(SkMixer::MakeFirst(), blender); |
Mike Reed | c723b70 | 2019-03-12 11:49:00 -0400 | [diff] [blame] | 274 | if (true) { |
| 275 | auto data = mx->serialize(); |
| 276 | mx = SkMixerBase::Deserialize(data->data(), data->size()); |
| 277 | } |
| 278 | return SkShader::MakeMixer(a, b, mx); |
| 279 | }); |
| 280 | } |