Hal Canary | 6c8422c | 2020-01-10 15:22:09 -0500 | [diff] [blame] | 1 | // Copyright 2020 Google LLC. |
| 2 | // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. |
| 3 | #include "tools/fiddle/examples.h" |
| 4 | REG_FIDDLE(color_filter_vs_colorFilterImageFilter_saveLayer, 256, 128, false, 3) { |
| 5 | sk_sp<SkColorFilter> saturate() { |
| 6 | SkScalar colorMatrix[20] = {1.75, 0, 0, 0, 0, |
| 7 | 0, 1.75, 0, 0, 0, |
| 8 | 0, 0, 1.75, 0, 0, |
| 9 | 0, 0, 0, 1, 0}; |
| 10 | return SkColorFilters::Matrix(colorMatrix); |
| 11 | } |
| 12 | |
| 13 | void draw(SkCanvas* canvas) { |
| 14 | SkPaint paint; |
| 15 | paint.setColorFilter(saturate()); |
| 16 | canvas->drawImageRect(image, {0, 0, 128, 128}, &paint); |
| 17 | |
| 18 | SkPaint paint2; |
| 19 | paint2.setImageFilter(SkColorFilterImageFilter::Make(saturate(), nullptr)); |
| 20 | SkAutoCanvasRestore autoCanvasRestore(canvas, false); |
| 21 | canvas->saveLayer(nullptr, &paint2); |
| 22 | canvas->drawImageRect(image, {128, 0, 256, 128}, nullptr); |
| 23 | } |
| 24 | } // END FIDDLE |