Flutter Engine
The Flutter Engine
Canvas.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.jetski;
9
10import androidx.annotation.Nullable;
11
12public class Canvas {
13 private long mNativeInstance;
14 private Surface mSurface;
15
16 public int getWidth() {
17 return nGetWidth(mNativeInstance);
18 }
19
20 public int getHeight() {
21 return nGetHeight(mNativeInstance);
22 }
23
24 public int save() {
25 return nSave(mNativeInstance);
26 }
27
28 public void restore() {
29 nRestore(mNativeInstance);
30 }
31
32 public void restoreToCount(int count) {
33 nRestoreToCount(mNativeInstance, count);
34 }
35
36 public int saveLayer(@Nullable Paint paint) {
37 long nativePaint = 0;
38 if (paint != null) {
39 nativePaint = paint.getNativeInstance();
40 }
41 return nSaveLayer(mNativeInstance, nativePaint);
42 }
43
45 long native_matrix = nGetLocalToDevice(mNativeInstance);
46 return new Matrix(native_matrix);
47 }
48
49 public void concat(Matrix m) {
50 nConcat(mNativeInstance, m.getNativeInstance());
51 }
52
53 public void concat(float[] rowMajorMatrix) {
54 if (rowMajorMatrix.length != 16) {
55 throw new java.lang.IllegalArgumentException("Expecting a 16 float array.");
56 }
57
58 nConcat16f(mNativeInstance, rowMajorMatrix);
59 }
60
61 public void translate(float tx, float ty, float tz) {
62 nTranslate(mNativeInstance, tx ,ty, tz);
63 }
64
65 public void translate(float tx, float ty) {
66 nTranslate(mNativeInstance, tx ,ty, 0);
67 }
68
69 public void scale(float sx, float sy, float sz) {
70 nScale(mNativeInstance, sx ,sy, sz);
71 }
72
73 public void scale(float sx, float sy) {
74 nScale(mNativeInstance, sx ,sy, 1);
75 }
76
77 public void clipPath(Path path, ClipOp op, boolean antiAliasing) {
78 nClipPath(mNativeInstance, path.getNativeInstance(), op.mNativeInt, antiAliasing);
79 }
80
81 public void clipRect(float left, float top, float right, float bottom,
82 ClipOp op, boolean antiAliasing) {
83 nClipRect(mNativeInstance, left, top, right, bottom, op.mNativeInt, antiAliasing);
84 }
85
86 public void clipRRect(float left, float top, float right, float bottom, float xRad, float yRad,
87 ClipOp op, boolean antiAliasing) {
88 nClipRRect(mNativeInstance, left, top, right, bottom, xRad, yRad, op.mNativeInt, antiAliasing);
89 }
90
91 public void clipShader(Shader shader, ClipOp op) {
92 nClipShader(mNativeInstance, shader.getNativeInstance(), op.mNativeInt);
93 }
94
95 public void drawRect(float left, float top, float right, float bottom, Paint paint) {
96 nDrawRect(mNativeInstance, left, top, right, bottom, paint.getNativeInstance());
97 }
98
99 public void drawColor(Color c) {
100 nDrawColor(mNativeInstance, c.r(), c.g(), c.b(), c.a());
101 }
102
103 public void drawColor(float r, float g, float b, float a) {
104 nDrawColor(mNativeInstance, r, g, b, a);
105 }
106
107 public void drawColor(int icolor) {
108 nDrawColor(mNativeInstance,
109 (float)((icolor >> 16) & 0xff) / 255,
110 (float)((icolor >> 8) & 0xff) / 255,
111 (float)((icolor >> 0) & 0xff) / 255,
112 (float)((icolor >> 24) & 0xff) / 255
113 );
114 }
115
116 public void drawImage(Image image, float x, float y) {
118 }
119
120 public void drawImage(Image image, float x, float y, SamplingOptions sampling) {
121 nDrawImage(mNativeInstance, image.getNativeInstance(), x, y,
122 sampling.getNativeDesc(), sampling.getCubicCoeffB(), sampling.getCubicCoeffC());
123 }
124
125 public void drawPath(Path path, Paint paint) {
126 nDrawPath(mNativeInstance, path.getNativeInstance(), paint.getNativeInstance());
127 }
128
129 // package private
130 Canvas(Surface surface, long native_instance) {
131 mNativeInstance = native_instance;
132 mSurface = surface;
133 }
134
135 // package private
136 long getNativeInstance() { return mNativeInstance; }
137
138 private static native int nGetWidth(long nativeInstance);
139 private static native int nGetHeight(long nativeInstance);
140 private static native int nSave(long nativeInstance);
141 private static native void nRestore(long nativeInstance);
142 private static native void nRestoreToCount(long nativeInstance, int count);
143 private static native int nSaveLayer(long nativeInstance, long nativePaint);
144 private static native long nGetLocalToDevice(long mNativeInstance);
145 private static native void nConcat(long nativeInstance, long nativeMatrix);
146 private static native void nConcat16f(long nativeInstance, float[] floatMatrix);
147 private static native void nTranslate(long nativeInstance, float tx, float ty, float tz);
148 private static native void nScale(long nativeInstance, float sx, float sy, float sz);
149
150 private static native void nClipPath(long nativeInstance, long nativePath, int clipOp,
151 boolean doAA);
152 private static native void nClipRect(long nativeInstance, float left, float top, float right,
153 float bottom, int clipOp, boolean doAA);
154 private static native void nClipRRect(long nativeInstance, float left, float top, float right,
155 float bottom, float xRad, float yRad,
156 int clipOp, boolean doAA);
157 private static native void nClipShader(long nativeInstance, long nativeShader, int clipOp);
158
159
160 private static native void nDrawColor(long nativeInstance, float r, float g, float b, float a);
161
162 private static native void nDrawRect(long nativeInstance,
163 float left, float top, float right, float bottom,
164 long nativePaint);
165 private static native void nDrawImage(long nativeInstance, long nativeImage, float x, float y,
166 int samplingDesc,
167 float samplingCoeffB, float samplingCoeffC);
168 private static native void nDrawPath(long nativeInstance, long nativePath, long nativePaint);
169 private static native void nDrawGlyphs(long nativeInstance, char[] glyphs, float[] positions,
170 float originX, float originY, long nativeFont, long nativePaint);
171}
uint16_t glyphs[5]
Definition: FontMgrTest.cpp:46
int count
Definition: FontMgrTest.cpp:50
void clipShader(Shader shader, ClipOp op)
Definition: Canvas.java:91
void drawImage(Image image, float x, float y)
Definition: Canvas.java:116
void drawImage(Image image, float x, float y, SamplingOptions sampling)
Definition: Canvas.java:120
void drawColor(int icolor)
Definition: Canvas.java:107
void clipPath(Path path, ClipOp op, boolean antiAliasing)
Definition: Canvas.java:77
void drawRect(float left, float top, float right, float bottom, Paint paint)
Definition: Canvas.java:95
void clipRRect(float left, float top, float right, float bottom, float xRad, float yRad, ClipOp op, boolean antiAliasing)
Definition: Canvas.java:86
void translate(float tx, float ty)
Definition: Canvas.java:65
void translate(float tx, float ty, float tz)
Definition: Canvas.java:61
void drawColor(float r, float g, float b, float a)
Definition: Canvas.java:103
Canvas(Surface surface, long native_instance)
Definition: Canvas.java:130
void clipRect(float left, float top, float right, float bottom, ClipOp op, boolean antiAliasing)
Definition: Canvas.java:81
int saveLayer(@Nullable Paint paint)
Definition: Canvas.java:36
void scale(float sx, float sy, float sz)
Definition: Canvas.java:69
void concat(Matrix m)
Definition: Canvas.java:49
void scale(float sx, float sy)
Definition: Canvas.java:73
Matrix getLocalToDevice()
Definition: Canvas.java:44
void drawColor(Color c)
Definition: Canvas.java:99
void drawPath(Path path, Paint paint)
Definition: Canvas.java:125
void restoreToCount(int count)
Definition: Canvas.java:32
void concat(float[] rowMajorMatrix)
Definition: Canvas.java:53
long getNativeInstance()
Definition: Shader.java:31
const Paint & paint
Definition: color_source.cc:38
VkSurfaceKHR surface
Definition: main.cc:49
static bool b
struct MyStruct a[10]
double y
double x
sk_sp< const SkImage > image
Definition: SkRecords.h:269
SkSamplingOptions sampling
Definition: SkRecords.h:337
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
Definition: switches.h:57
SkSamplingOptions SamplingOptions(jint desc, jfloat coeffB, jfloat coeffC)
Definition: Utils.cpp:13
SK_API sk_sp< PrecompileColorFilter > Matrix()