Flutter Engine
The Flutter Engine
RuntimeSample.java
Go to the documentation of this file.
1/*
2 * Copyright 2021 Google Inc.
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
8package org.skia.jetskidemo.samples;
9
10import android.content.res.Resources;
11
12import java.io.InputStream;
13
14import org.skia.jetski.Canvas;
15import org.skia.jetski.Matrix;
16import org.skia.jetski.Paint;
17import org.skia.jetski.RuntimeShaderBuilder;
18
19public class RuntimeSample implements Sample {
20 private RuntimeShaderBuilder mShaderBuilder;
21
22 public RuntimeSample(Resources res, int resId) {
23 String sksl = "";
24 try {
25 InputStream is = res.openRawResource(resId);
26 byte[] data = new byte[is.available()];
27 is.read(data);
28
29 sksl = new String(data);
30 } catch (Exception e) {}
31
32 mShaderBuilder = new RuntimeShaderBuilder(sksl);
33 }
34
35 public void render(Canvas canvas, long ms, float left, float top, float right, float bottom) {
36 mShaderBuilder.setUniform("u_time", ms / 1000.0f)
37 .setUniform("u_w", right - left)
38 .setUniform("u_h", bottom - top);
39
40 Paint paint = new Paint().setShader(mShaderBuilder.makeShader());
41
42 canvas.save();
43 canvas.concat(new Matrix().translate(left, top));
44 canvas.drawRect(0, 0, right - left, bottom - top, paint);
45 canvas.restore();
46 }
47}
void drawRect(float left, float top, float right, float bottom, Paint paint)
Definition: Canvas.java:95
void concat(Matrix m)
Definition: Canvas.java:49
Paint setShader(@Nullable Shader shader)
Definition: Paint.java:34
RuntimeShaderBuilder setUniform(String name, float val)
void render(Canvas canvas, long ms, float left, float top, float right, float bottom)
RuntimeSample(Resources res, int resId)
const Paint & paint
Definition: color_source.cc:38
SK_API sk_sp< PrecompileColorFilter > Matrix()
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63