Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
AnimationActivity.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;
9
10import android.app.Activity;
11import android.os.Bundle;
12import android.view.SurfaceView;
13import org.skia.jetski.*;
14import org.skia.jetski.util.*;
15
16class AnimationRenderer extends SurfaceRenderer {
17 private Shader mLinearGradient,
18 mRadialGradient,
19 mConicalGradient,
20 mSweepGradient;
21 private ColorFilter mColorFilter = new MatrixColorFilter(new float[]{
22 0.75f, 0, 0, 0, 0,
23 0, 1, 0, 0, 0.5f,
24 0, 0, 1, 0, 0,
25 0, 0, 0, 1, 0,
26 });
27
28 @Override
30 float sw = surface.getWidth(),
31 sh = surface.getHeight();
32
33 float[] colors1 = {
34 1,0,0,1,
35 0,1,0,1,
36 0,0,1,1
37 };
38 int[] colors2 = {
39 0xffffff00,
40 0xff00ffff,
41 0xffff00ff
42 };
43
44 float[] pos = {0, 0.5f, 1};
45
46 mLinearGradient = new LinearGradient(0, 0, sw/4, 0,
47 colors1, pos, TileMode.REPEAT);
48 mRadialGradient = new RadialGradient(sw/2, sh/4, Math.min(sw, sh)/2,
49 colors2, pos, TileMode.REPEAT);
50 mConicalGradient = new TwoPointConicalGradient(sw/4, sh/2, sw/4,
51 sw/2, sh/2, sw/2,
52 colors1, pos, TileMode.MIRROR);
53 mSweepGradient = new SweepGradient(sw/2, sh/4, 0, 90, colors2, pos, TileMode.REPEAT);
54 }
55
56 @Override
57 protected void onRenderFrame(Canvas canvas, long ms) {
58 final float kWidth = 400,
59 kHeight = 200,
60 kSpeed = 4;
61
62 canvas.drawColor(0xffffffe0);
63
64 float cw = canvas.getWidth(),
65 ch = canvas.getHeight(),
66 osc1 = (float)(java.lang.Math.cos(ms * kSpeed / 1000)),
67 osc2 = (float)(java.lang.Math.sin(ms * kSpeed / 1000));
68
69 drawRect(canvas, (1 + osc1)*cw/2, ch/2, mLinearGradient);
70 drawRect(canvas, (1 - osc1)*cw/2, ch/2, mConicalGradient);
71 drawRect(canvas, cw/2, (1 + osc2)*ch/2, mRadialGradient);
72 drawRect(canvas, cw/2, (1 - osc2)*ch/2, mSweepGradient);
73 }
74
75 private void drawRect(Canvas canvas, float cx, float cy, Shader shader) {
76 final float kWidth = 400,
77 kHeight = 200;
78
79 canvas.drawRect(cx - kWidth/2, cy - kHeight/2, cx + kWidth/2, cy + kHeight/2,
80 new Paint().setShader(shader).setColorFilter(mColorFilter));
81 }
82}
83
84public class AnimationActivity extends Activity {
85 static {
86 System.loadLibrary("jetski");
87 }
88
89 @Override
90 protected void onCreate(Bundle savedInstanceState) {
91 super.onCreate(savedInstanceState);
92 setContentView(R.layout.activity_animation);
93
94 SurfaceView sv = findViewById(R.id.surfaceView);
95 sv.getHolder().addCallback(new AnimationRenderer());
96 }
97}
SkPoint pos
void onCreate(Bundle savedInstanceState)
void onRenderFrame(Canvas canvas, long ms)
VkSurfaceKHR surface
Definition main.cc:49
#define R(r)
constexpr size_t kHeight
constexpr size_t kWidth