Flutter Engine
The Flutter Engine
TextureRegistry.java
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5package io.flutter.view;
6
7import android.graphics.SurfaceTexture;
8import android.media.Image;
9import android.view.Surface;
10import androidx.annotation.Keep;
11import androidx.annotation.NonNull;
12import androidx.annotation.Nullable;
13
14// TODO(mattcarroll): re-evalute docs in this class and add nullability annotations.
15/**
16 * Registry of backend textures used with a single {@link FlutterView} instance. Entries may be
17 * embedded into the Flutter view using the <a
18 * href="https://api.flutter.dev/flutter/widgets/Texture-class.html">Texture</a> widget.
19 */
20public interface TextureRegistry {
21 /**
22 * Creates and registers a SurfaceProducer texture managed by the Flutter engine.
23 *
24 * @return A SurfaceProducer.
25 */
26 @NonNull
28
29 /**
30 * Creates and registers a SurfaceTexture managed by the Flutter engine.
31 *
32 * @return A SurfaceTextureEntry.
33 */
34 @NonNull
36
37 /**
38 * Registers a SurfaceTexture managed by the Flutter engine.
39 *
40 * @return A SurfaceTextureEntry.
41 */
42 @NonNull
43 SurfaceTextureEntry registerSurfaceTexture(@NonNull SurfaceTexture surfaceTexture);
44
45 /**
46 * Creates and registers a texture managed by the Flutter engine.
47 *
48 * @return a ImageTextureEntry.
49 */
50 @NonNull
52
53 /**
54 * Callback invoked when memory is low.
55 *
56 * <p>Invoke this from {@link android.app.Activity#onTrimMemory(int)}.
57 */
58 default void onTrimMemory(int level) {}
59
60 /** An entry in the texture registry. */
61 interface TextureEntry {
62 /** @return The identity of this texture. */
63 long id();
64
65 /** Deregisters and releases all resources . */
66 void release();
67 }
68
69 /** Uses a Surface to populate the texture. */
70 @Keep
71 interface SurfaceProducer extends TextureEntry {
72 /** Specify the size of this texture in physical pixels */
73 void setSize(int width, int height);
74
75 /** @return The currently specified width (physical pixels) */
76 int getWidth();
77
78 /** @return The currently specified height (physical pixels) */
79 int getHeight();
80
81 /**
82 * Get a Surface that can be used to update the texture contents.
83 *
84 * <p>NOTE: You should not cache the returned surface but instead invoke getSurface each time
85 * you need to draw. The surface may change when the texture is resized or has its format
86 * changed.
87 *
88 * @return a Surface to use for a drawing target for various APIs.
89 */
90 Surface getSurface();
91
93 };
94
95 /** A registry entry for a managed SurfaceTexture. */
96 @Keep
98 /** @return The managed SurfaceTexture. */
99 @NonNull
100 SurfaceTexture surfaceTexture();
101
102 /** Set a listener that will be notified when the most recent image has been consumed. */
103 default void setOnFrameConsumedListener(@Nullable OnFrameConsumedListener listener) {}
104
105 /** Set a listener that will be notified when a memory pressure warning was forward. */
106 default void setOnTrimMemoryListener(@Nullable OnTrimMemoryListener listener) {}
107 }
108
109 @Keep
110 interface ImageTextureEntry extends TextureEntry {
111 /**
112 * Next paint will update texture to use the contents of image.
113 *
114 * <p>NOTE: Caller should not call Image.close() on the pushed image.
115 *
116 * <p>NOTE: In the case that multiple calls to PushFrame occur before the next paint only the
117 * last frame pushed will be used (dropping the missed frames).
118 */
120 }
121
122 /** Listener invoked when the most recent image has been consumed. */
124 /**
125 * This method will to be invoked when the most recent image from the image stream has been
126 * consumed.
127 */
129 }
130
131 /** Listener invoked when a memory pressure warning was forward. */
133 /** This method will be invoked when a memory pressure warning was forward. */
135 }
136
137 @Keep
138 interface ImageConsumer {
139 /**
140 * Retrieve the last Image produced. Drops all previously produced images.
141 *
142 * <p>NOTE: Caller must call Image.close() on returned image.
143 *
144 * @return Image or null.
145 */
146 @Nullable
148 }
149
150 @Keep
152 /**
153 * Retrieve the last GL texture produced.
154 *
155 * @return SurfaceTexture.
156 */
157 @NonNull
158 public SurfaceTexture getSurfaceTexture();
159 }
160}
default void setOnFrameConsumedListener(@Nullable OnFrameConsumedListener listener)
default void setOnTrimMemoryListener(@Nullable OnTrimMemoryListener listener)
SurfaceTextureEntry createSurfaceTexture()
SurfaceProducer createSurfaceProducer()
default void onTrimMemory(int level)
SurfaceTextureEntry registerSurfaceTexture(@NonNull SurfaceTexture surfaceTexture)
ImageTextureEntry createImageTexture()
sk_sp< const SkImage > image
Definition: SkRecords.h:269
CanvasImage Image
Definition: dart_ui.cc:55
int32_t height
int32_t width