Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
runtimefunctions.cpp
Go to the documentation of this file.
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
8#include "gm/gm.h"
10#include "include/core/SkData.h"
13#include "include/core/SkSize.h"
16
17static const char* RUNTIME_FUNCTIONS_SRC = R"(
18// Source: @notargs https://twitter.com/notargs/status/1250468645030858753
19uniform half4 iResolution;
20const float iTime = 0;
21
22float f(vec3 p) {
23 p.z -= iTime * 10.;
24 float a = p.z * .1;
25 p.xy *= mat2(cos(a), sin(a), -sin(a), cos(a));
26 return .1 - length(cos(p.xy) + sin(p.yz));
27}
28
29half4 main(vec2 fragcoord) {
30 vec3 d = .5 - fragcoord.xy1 / iResolution.y;
31 vec3 p=vec3(0);
32 for (int i = 0; i < 32; i++) {
33 p += f(p) * d;
34 }
35 return ((sin(p) + vec3(2, 5, 9)) / length(p)).xyz1;
36}
37)";
38
40 bool runAsBench() const override { return true; }
41
42 SkString getName() const override { return SkString("runtimefunctions"); }
43
44 SkISize getISize() override { return {256, 256}; }
45
46 void onDraw(SkCanvas* canvas) override {
49 SkASSERTF(result.effect, "%s", result.errorText.c_str());
50
51 SkMatrix localM;
52 localM.setRotate(90, 128, 128);
53
54 SkV4 iResolution = { 255, 255, 0, 0 };
55 auto shader = result.effect->makeShader(
56 SkData::MakeWithCopy(&iResolution, sizeof(iResolution)), nullptr, 0, &localM);
57 SkPaint p;
58 p.setShader(std::move(shader));
59 canvas->drawRect({0, 0, 256, 256}, p);
60 }
61};
62
63DEF_GM(return new RuntimeFunctions;)
#define SkASSERTF(cond, fmt,...)
Definition SkAssert.h:117
SkISize getISize() override
SkString getName() const override
bool runAsBench() const override
void onDraw(SkCanvas *canvas) override
void drawRect(const SkRect &rect, const SkPaint &paint)
static sk_sp< SkData > MakeWithCopy(const void *data, size_t length)
Definition SkData.cpp:111
SkMatrix & setRotate(SkScalar degrees, SkScalar px, SkScalar py)
Definition SkMatrix.cpp:452
static Result MakeForShader(SkString sksl, const Options &)
GAsyncResult * result
#define DEF_GM(CODE)
Definition gm.h:40
static const char * RUNTIME_FUNCTIONS_SRC
Definition SkM44.h:98