8package org.skia.jetskidemo;
10import androidx.annotation.NonNull;
16import android.view.SurfaceHolder;
21import android.widget.LinearLayout;
23import org.
skia.jetski.*;
24import org.skia.jetski.util.SkottieView;
25import org.skia.jetski.util.SurfaceRenderer;
28 private ImageView bitmapImage;
32 System.loadLibrary(
"jetski");
36 protected void onCreate(Bundle savedInstanceState) {
37 super.onCreate(savedInstanceState);
38 setContentView(
R.layout.activity_main);
41 p.setColor(
new Color(0, 1, 0, 1));
48 Bitmap.Config conf = Bitmap.Config.ARGB_8888;
49 Bitmap bmp = Bitmap.createBitmap(400, 400, conf);
55 float[]
m = {1, 0, 0, 100,
59 p.setColor(
new Color(0, 0, 1, 1));
73 }
catch (Exception
e) {
74 Log.e(
"JetSki Demo",
"Could not load Image resource: " +
R.raw.brickwork_texture);
76 bitmapImage = findViewById(
R.id.bitmapImage);
77 bitmapImage.setImageBitmap(bmp);
83 SurfaceView surfaceView = findViewById(
R.id.threadedSurface);
84 surfaceView.getHolder().addCallback(
new ThreadedSurfaceHandler());
90 SurfaceView runtimeEffectView = findViewById(
R.id.runtimeEffect);
97 skottieView.setLayoutParams(
new ViewGroup.LayoutParams(400, 400));
98 skottieView.setOnClickListener((View v) -> {
102 LinearLayout skottieContainer = findViewById(
R.id.skottie_container);
103 skottieContainer.addView(skottieView);
106 private class ThreadedSurfaceHandler
implements SurfaceHolder.
Callback {
108 public void surfaceCreated(@NonNull SurfaceHolder holder) {}
111 public void surfaceChanged(@NonNull SurfaceHolder holder,
int format,
int width,
int height) {
114 p.setColor(
new Color(1, 1, 0, 1));
115 p.setStrokeWidth(15);
123 p.setImageFilter(filter);
125 pathBuilder.
moveTo(20, 20);
126 pathBuilder.
quadTo(180, 60, 180, 180);
128 pathBuilder.
moveTo(180, 60);
129 pathBuilder.
quadTo(180, 180, 60, 180);
136 public void surfaceDestroyed(@NonNull SurfaceHolder holder) {}
142 private static final String SkSLShader =
143 "uniform half u_time; " +
144 "uniform half u_w; " +
145 "uniform half u_h; " +
147 "float f(vec3 p) { " +
148 " p.z -= u_time * 10.; " +
149 " float a = p.z * .1; " +
150 " p.xy *= mat2(cos(a), sin(a), -sin(a), cos(a)); " +
151 " return .1 - length(cos(p.xy) + sin(p.yz)); " +
154 "half4 main(vec2 fragcoord) { " +
155 " vec3 d = .5 - fragcoord.xy1 / u_h; " +
156 " vec3 p=vec3(0); " +
157 " for (int i = 0; i < 32; i++) p += f(p) * d; " +
158 " return ((sin(p) + vec3(2, 5, 9)) / length(p)).xyz1;" +
170 p.setShader(mBuilder.
setUniform(
"u_time", ms/1000.0f)
void drawImage(Image image, float x, float y)
void drawRect(float left, float top, float right, float bottom, Paint paint)
void drawPath(Path path, Paint paint)
static ImageFilter dropShadow(float dx, float dy, float sigmaX, float sigmaY, Color c, @Nullable ImageFilter input)
static Image fromStream(InputStream encodedStream)
void quadTo(float x1, float y1, float x2, float y2)
void moveTo(float x, float y)
RuntimeShaderBuilder setUniform(String name, float val)
static SamplingOptions CATMULLROM()
static Surface createThreadedSurface(android.view.Surface surface)
Image makeImageSnapshot()
void onRenderFrame(Canvas canvas, long ms)
void onSurfaceInitialized(Surface surface)
void onCreate(Bundle savedInstanceState)
uint32_t uint32_t * format
sk_sp< const SkImage > image
SK_API sk_sp< SkShader > Color(SkColor)
void Log(const char *format,...) SK_PRINTF_LIKE(1
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
std::function< void(MTLRenderPipelineDescriptor *)> Callback
SK_API sk_sp< PrecompileColorFilter > Matrix()