Ethan Nicholas | a70693b | 2019-03-04 13:07:36 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 Google LLC |
| 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" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 10 | #include "include/core/SkColorFilter.h" |
| 11 | #include "include/core/SkData.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "include/core/SkImage.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 13 | #include "include/core/SkPaint.h" |
| 14 | #include "include/core/SkRefCnt.h" |
| 15 | #include "include/core/SkSize.h" |
| 16 | #include "include/core/SkString.h" |
Brian Osman | ee426f2 | 2020-01-02 11:55:24 -0500 | [diff] [blame] | 17 | #include "include/effects/SkRuntimeEffect.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 18 | #include "tools/Resources.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 19 | |
| 20 | #include <stddef.h> |
| 21 | #include <utility> |
| 22 | |
Ethan Nicholas | a70693b | 2019-03-04 13:07:36 -0500 | [diff] [blame] | 23 | const char* SKSL_TEST_SRC = R"( |
Brian Osman | 9d10abe | 2019-12-13 16:31:40 -0500 | [diff] [blame] | 24 | uniform half b; |
Ethan Nicholas | a70693b | 2019-03-04 13:07:36 -0500 | [diff] [blame] | 25 | |
Mike Reed | 019458d | 2019-07-17 12:23:24 -0400 | [diff] [blame] | 26 | void main(inout half4 color) { |
Ethan Nicholas | 7e603db | 2019-05-03 12:57:47 -0400 | [diff] [blame] | 27 | color.a = color.r*0.3 + color.g*0.6 + color.b*0.1; |
| 28 | color.r = 0; |
| 29 | color.g = 0; |
| 30 | color.b = 0; |
Ethan Nicholas | a70693b | 2019-03-04 13:07:36 -0500 | [diff] [blame] | 31 | } |
| 32 | )"; |
| 33 | |
Brian Osman | 7b1678a | 2019-12-16 09:17:25 -0500 | [diff] [blame] | 34 | DEF_SIMPLE_GPU_GM(runtimecolorfilter, context, rtc, canvas, 512, 256) { |
Ethan Nicholas | a70693b | 2019-03-04 13:07:36 -0500 | [diff] [blame] | 35 | auto img = GetResourceAsImage("images/mandrill_256.png"); |
| 36 | canvas->drawImage(img, 0, 0, nullptr); |
| 37 | |
| 38 | float b = 0.75; |
Ethan Nicholas | 0e9401d | 2019-03-21 11:05:37 -0400 | [diff] [blame] | 39 | sk_sp<SkData> data = SkData::MakeWithCopy(&b, sizeof(b)); |
Brian Osman | 4ee6356 | 2020-01-02 08:03:40 -0500 | [diff] [blame] | 40 | static sk_sp<SkRuntimeEffect> effect = std::get<0>( |
| 41 | SkRuntimeEffect::Make(SkString(SKSL_TEST_SRC))); |
| 42 | |
| 43 | auto cf1 = effect->makeColorFilter(data); |
Ethan Nicholas | a70693b | 2019-03-04 13:07:36 -0500 | [diff] [blame] | 44 | SkPaint p; |
| 45 | p.setColorFilter(cf1); |
| 46 | canvas->drawImage(img, 256, 0, &p); |
Ethan Nicholas | a70693b | 2019-03-04 13:07:36 -0500 | [diff] [blame] | 47 | } |