Flutter Engine
The Flutter Engine
Surface.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 android.graphics.Bitmap;
11import android.os.Build;
12import androidx.annotation.RequiresApi;
13
14public class Surface {
15 private long mNativeInstance;
16
17 /**
18 * Create a Surface backed by the provided Bitmap.
19 *
20 * The Bitmap must be mutable and its pixels are locked for the lifetime of the Surface.
21 */
22 public Surface(Bitmap bitmap) {
23 this(CreateBitmapInstance(bitmap));
24 }
25
26 @RequiresApi(Build.VERSION_CODES.N)
28 return new Surface(nCreateVKSurface(surface));
29 }
30
31 static public Surface CreateGL(android.view.Surface surface) {
32 return new Surface(nCreateGLSurface(surface));
33 }
34
35 /**
36 * Create a Surface backed by the provided Android Surface (android.view.Surface).
37 * JetSki handles thread management. Assumes OpenGL backend.
38 */
39 static public Surface createThreadedSurface(android.view.Surface surface) {
40 return new Surface(nCreateThreadedSurface(surface));
41 }
42
43 /**
44 * The Canvas associated with this Surface.
45 */
46 public Canvas getCanvas() {
47 // TODO: given that canvases are now ephemeral, it would make sense to be more explicit
48 // e.g. lockCanvas/unlockCanvasAndPost?
49 return new Canvas(this, nGetNativeCanvas(mNativeInstance));
50 }
51
52
53 /**
54 * Returns an Image capturing the Surface contents.
55 * Subsequent drawing to Surface contents are not captured.
56 */
58 return new Image(nMakeImageSnapshot(mNativeInstance));
59 }
60
61 /***
62 * Triggers the immediate execution of all pending draw operations.
63 *
64 * Additionaly, if the backing device is multi-buffered, submits the current
65 * buffer to be displayed.
66 */
67 public void flushAndSubmit() {
68 nFlushAndSubmit(mNativeInstance);
69 }
70
71 public int getWidth() {
72 return nGetWidth(mNativeInstance);
73 }
74
75 public int getHeight() {
76 return nGetHeight(mNativeInstance);
77 }
78
79 /**
80 * Releases any resources associated with this Surface.
81 */
82 public void release() {
83 nRelease(mNativeInstance);
84 mNativeInstance = 0;
85 }
86
87 @Override
88 protected void finalize() throws Throwable
89 {
90 release();
91 }
92
93 private Surface(long native_instance) {
94 mNativeInstance = native_instance;
95 }
96
97 private static long CreateBitmapInstance(Bitmap bitmap) {
98 if (!bitmap.isMutable()) {
99 throw new IllegalStateException("Immutable bitmap passed to Surface constructor");
100 }
101 return nCreateBitmap(bitmap);
102 }
103
104 private static native long nCreateBitmap(Bitmap bitmap);
105 private static native long nCreateThreadedSurface(android.view.Surface surface);
106 private static native long nCreateVKSurface(android.view.Surface surface);
107 private static native long nCreateGLSurface(android.view.Surface surface);
108
109 private static native void nRelease(long nativeInstance);
110 private static native long nGetNativeCanvas(long nativeInstance);
111 private static native void nFlushAndSubmit(long nativeInstance);
112 private static native int nGetWidth(long nativeInstance);
113 private static native int nGetHeight(long nativeInstance);
114 private static native long nMakeImageSnapshot(long nativeInstance);
115}
static Surface CreateGL(android.view.Surface surface)
Definition: Surface.java:31
static Surface createThreadedSurface(android.view.Surface surface)
Definition: Surface.java:39
Surface(Bitmap bitmap)
Definition: Surface.java:22
static Surface CreateVulkan(android.view.Surface surface)
Definition: Surface.java:27
VkSurfaceKHR surface
Definition: main.cc:49
Definition: bitmap.py:1
def Build(configs, env, options)
Definition: build.py:232
CanvasImage Image
Definition: dart_ui.cc:55