blob: ed797a78cc9554facffd2c44d938440d88686caa [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
Brian Osman5240e182020-08-12 10:22:34 -040023const char* gLumaSrc = R"(
Mike Reed019458d2019-07-17 12:23:24 -040024 void main(inout half4 color) {
Ethan Nicholas7e603db2019-05-03 12:57:47 -040025 color.a = color.r*0.3 + color.g*0.6 + color.b*0.1;
26 color.r = 0;
27 color.g = 0;
28 color.b = 0;
Ethan Nicholasa70693b2019-03-04 13:07:36 -050029 }
30)";
31
Brian Osman5240e182020-08-12 10:22:34 -040032const char* gLumaSrcWithCoords = R"(
33 void main(float2 p, inout half4 color) {
34 color.a = color.r*0.3 + color.g*0.6 + color.b*0.1;
35 color.r = 0;
36 color.g = 0;
37 color.b = 0;
38 }
39)";
40
41DEF_SIMPLE_GM(runtimecolorfilter, canvas, 256 * 3, 256) {
Ethan Nicholasa70693b2019-03-04 13:07:36 -050042 auto img = GetResourceAsImage("images/mandrill_256.png");
43 canvas->drawImage(img, 0, 0, nullptr);
44
Brian Osman5240e182020-08-12 10:22:34 -040045 for (auto src : { gLumaSrc, gLumaSrcWithCoords }) {
46 sk_sp<SkRuntimeEffect> effect = std::get<0>(SkRuntimeEffect::Make(SkString(src)));
Ethan Nicholas63d7ee32020-08-17 10:57:12 -040047 SkASSERT(effect);
Brian Osman5240e182020-08-12 10:22:34 -040048 SkPaint p;
49 p.setColorFilter(effect->makeColorFilter(nullptr));
50 canvas->translate(256, 0);
51 canvas->drawImage(img, 0, 0, &p);
52 }
Ethan Nicholasa70693b2019-03-04 13:07:36 -050053}