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