74 {
76
77 wgpu::Device
device = wgpu::Device::Acquire(emscripten_webgpu_get_device());
79 if (!context) {
80 SkDebugf(
"Could not create GrDirectContext\n");
81 return false;
82 }
83
84 const char* sksl =
85 "uniform float2 iResolution;"
86 "uniform float iTime;"
87 "vec2 d;"
88 "float b(float a) {"
89 " return step(max(d.x, d.y), a);"
90 "}"
91 "half4 main(float2 C) {"
92 " vec4 O = vec4(0);"
93 " C.y = iResolution.y - C.y;"
94 " for (float i = 0; i < 3; ++i) {"
95 " vec2 U = C.yx / iResolution.yx;"
96 " U.y -= .5;"
97 " U.x = U.x * .4 + U.y * U.y;"
98 " U.y += U.x * sin(-iTime * 9. + i * 2. + U.x * 25.) * .2;"
99 " U.x -= asin(sin(U.y * 34.))/20.;"
100 " d = abs(U);"
101 " O += .3 * vec4(.8 * b(.3) + b(.2), b(.2), b(.1), -1.);"
102 " }"
103 " return O.xyz1;"
104 "}";
105
107 if (!effect) {
108 SkDebugf(
"Failed to compile SkSL: %s\n", err.c_str());
109 return false;
110 }
111
115 fContext = context;
116 fEffect = effect;
117
118 return true;
119 }
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
static wgpu::SwapChain getSwapChainForCanvas(wgpu::Device device, std::string canvasSelector, int width, int height)
static Result MakeForShader(SkString sksl, const Options &)
SK_API std::unique_ptr< Context > MakeDawn(const DawnBackendContext &, const ContextOptions &)