blob: 1fbc0cd79ddf018bb11277f0eedcf3f8b9f9b1dc [file] [log] [blame]
Hal Canary6c8422c2020-01-10 15:22:09 -05001// 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"
4REG_FIDDLE(color_filter_vs_colorFilterImageFilter_saveLayer, 256, 128, false, 3) {
5sk_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
13void draw(SkCanvas* canvas) {
14 SkPaint paint;
15 paint.setColorFilter(saturate());
Mike Reedb339d052021-01-28 11:20:41 -050016 canvas->drawImageRect(image, {0, 0, 128, 128}, SkSamplingOptions(), &paint);
Hal Canary6c8422c2020-01-10 15:22:09 -050017
18 SkPaint paint2;
Michael Ludwiged552f82021-01-22 13:01:26 -050019 paint2.setImageFilter(SkImageFilters::ColorFilter(saturate(), nullptr));
Hal Canary6c8422c2020-01-10 15:22:09 -050020 SkAutoCanvasRestore autoCanvasRestore(canvas, false);
21 canvas->saveLayer(nullptr, &paint2);
Mike Reedb339d052021-01-28 11:20:41 -050022 canvas->drawImageRect(image, {128, 0, 256, 128}, SkSamplingOptions());
Hal Canary6c8422c2020-01-10 15:22:09 -050023}
24} // END FIDDLE