blob: 57398f2f3eb9ef85d456c0439a74203ed0d076dc [file] [log] [blame]
Ethan Nicholasa70693b2019-03-04 13:07:36 -05001/*
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 Kleinc0bd9f92019-04-23 12:05:21 -05008#include "gm/gm.h"
9#include "include/core/SkCanvas.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040010#include "include/core/SkColorFilter.h"
11#include "include/core/SkData.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#include "include/core/SkImage.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040013#include "include/core/SkPaint.h"
14#include "include/core/SkRefCnt.h"
15#include "include/core/SkSize.h"
16#include "include/core/SkString.h"
Brian Osmanee426f22020-01-02 11:55:24 -050017#include "include/effects/SkRuntimeEffect.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050018#include "tools/Resources.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040019
20#include <stddef.h>
21#include <utility>
22
Ethan Nicholasa70693b2019-03-04 13:07:36 -050023const char* SKSL_TEST_SRC = R"(
Brian Osman9d10abe2019-12-13 16:31:40 -050024 uniform half b;
Ethan Nicholasa70693b2019-03-04 13:07:36 -050025
Mike Reed019458d2019-07-17 12:23:24 -040026 void main(inout half4 color) {
Ethan Nicholas7e603db2019-05-03 12:57:47 -040027 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 Nicholasa70693b2019-03-04 13:07:36 -050031 }
32)";
33
Brian Osman7b1678a2019-12-16 09:17:25 -050034DEF_SIMPLE_GPU_GM(runtimecolorfilter, context, rtc, canvas, 512, 256) {
Ethan Nicholasa70693b2019-03-04 13:07:36 -050035 auto img = GetResourceAsImage("images/mandrill_256.png");
36 canvas->drawImage(img, 0, 0, nullptr);
37
38 float b = 0.75;
Ethan Nicholas0e9401d2019-03-21 11:05:37 -040039 sk_sp<SkData> data = SkData::MakeWithCopy(&b, sizeof(b));
Brian Osman4ee63562020-01-02 08:03:40 -050040 static sk_sp<SkRuntimeEffect> effect = std::get<0>(
41 SkRuntimeEffect::Make(SkString(SKSL_TEST_SRC)));
42
43 auto cf1 = effect->makeColorFilter(data);
Ethan Nicholasa70693b2019-03-04 13:07:36 -050044 SkPaint p;
45 p.setColorFilter(cf1);
46 canvas->drawImage(img, 256, 0, &p);
Ethan Nicholasa70693b2019-03-04 13:07:36 -050047}