blob: 997e48fe61ac6eec2e8b7b67ce8d9a9f9ef31ae0 [file] [log] [blame]
Romain Guyaa6c24c2011-04-28 18:40:04 -07001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.view;
18
sergeyv342a7e62016-03-24 16:06:46 -070019import android.annotation.Nullable;
Mathew Inwoode5ad5982018-08-17 15:07:52 +010020import android.annotation.UnsupportedAppUsage;
Romain Guyaa6c24c2011-04-28 18:40:04 -070021import android.content.Context;
Romain Guy77a81162011-06-14 16:45:55 -070022import android.graphics.Bitmap;
Romain Guyaa6c24c2011-04-28 18:40:04 -070023import android.graphics.Canvas;
Romain Guy302a9df2011-08-16 13:55:02 -070024import android.graphics.Matrix;
Romain Guyaa6c24c2011-04-28 18:40:04 -070025import android.graphics.Paint;
Romain Guy6be3d552011-07-14 18:08:37 -070026import android.graphics.Rect;
Romain Guyaa6c24c2011-04-28 18:40:04 -070027import android.graphics.SurfaceTexture;
Chris Craik2e931ea2015-08-19 16:13:04 -070028import android.graphics.drawable.Drawable;
Romain Guyaa6c24c2011-04-28 18:40:04 -070029import android.util.AttributeSet;
30import android.util.Log;
31
32/**
33 * <p>A TextureView can be used to display a content stream. Such a content
34 * stream can for instance be a video or an OpenGL scene. The content stream
35 * can come from the application's process as well as a remote process.</p>
John Reck5ba09482015-05-18 15:13:30 -070036 *
Romain Guyaa6c24c2011-04-28 18:40:04 -070037 * <p>TextureView can only be used in a hardware accelerated window. When
38 * rendered in software, TextureView will draw nothing.</p>
John Reck5ba09482015-05-18 15:13:30 -070039 *
Romain Guyaa6c24c2011-04-28 18:40:04 -070040 * <p>Unlike {@link SurfaceView}, TextureView does not create a separate
41 * window but behaves as a regular View. This key difference allows a
42 * TextureView to be moved, transformed, animated, etc. For instance, you
43 * can make a TextureView semi-translucent by calling
44 * <code>myView.setAlpha(0.5f)</code>.</p>
John Reck5ba09482015-05-18 15:13:30 -070045 *
Romain Guyaa6c24c2011-04-28 18:40:04 -070046 * <p>Using a TextureView is simple: all you need to do is get its
47 * {@link SurfaceTexture}. The {@link SurfaceTexture} can then be used to
John Reck5ba09482015-05-18 15:13:30 -070048 * render content. The following example demonstrates how to render the
Romain Guyaa6c24c2011-04-28 18:40:04 -070049 * camera preview into a TextureView:</p>
John Reck5ba09482015-05-18 15:13:30 -070050 *
Romain Guyaa6c24c2011-04-28 18:40:04 -070051 * <pre>
52 * public class LiveCameraActivity extends Activity implements TextureView.SurfaceTextureListener {
53 * private Camera mCamera;
54 * private TextureView mTextureView;
55 *
Romain Guyaa6c24c2011-04-28 18:40:04 -070056 * protected void onCreate(Bundle savedInstanceState) {
57 * super.onCreate(savedInstanceState);
58 *
59 * mTextureView = new TextureView(this);
60 * mTextureView.setSurfaceTextureListener(this);
61 *
62 * setContentView(mTextureView);
63 * }
64 *
Romain Guy451ce442011-06-10 15:40:36 -070065 * public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
Romain Guyaa6c24c2011-04-28 18:40:04 -070066 * mCamera = Camera.open();
67 *
68 * try {
69 * mCamera.setPreviewTexture(surface);
70 * mCamera.startPreview();
71 * } catch (IOException ioe) {
72 * // Something bad happened
73 * }
74 * }
Grace Klobacf559372011-06-22 23:05:40 -070075 *
Romain Guy8f0095c2011-05-02 17:24:22 -070076 * public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
77 * // Ignored, Camera does all the work for us
78 * }
Grace Klobacf559372011-06-22 23:05:40 -070079 *
Grace Kloba402f0552011-08-09 18:47:17 -070080 * public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
Romain Guy451ce442011-06-10 15:40:36 -070081 * mCamera.stopPreview();
82 * mCamera.release();
Grace Kloba402f0552011-08-09 18:47:17 -070083 * return true;
Romain Guy451ce442011-06-10 15:40:36 -070084 * }
Grace Klobacf559372011-06-22 23:05:40 -070085 *
86 * public void onSurfaceTextureUpdated(SurfaceTexture surface) {
Romain Guy58f4edb2011-06-24 14:51:38 -070087 * // Invoked every time there's a new Camera preview frame
Grace Klobacf559372011-06-22 23:05:40 -070088 * }
Romain Guyaa6c24c2011-04-28 18:40:04 -070089 * }
90 * </pre>
John Reck5ba09482015-05-18 15:13:30 -070091 *
Romain Guyaa6c24c2011-04-28 18:40:04 -070092 * <p>A TextureView's SurfaceTexture can be obtained either by invoking
93 * {@link #getSurfaceTexture()} or by using a {@link SurfaceTextureListener}.
94 * It is important to know that a SurfaceTexture is available only after the
95 * TextureView is attached to a window (and {@link #onAttachedToWindow()} has
96 * been invoked.) It is therefore highly recommended you use a listener to
97 * be notified when the SurfaceTexture becomes available.</p>
John Reck5ba09482015-05-18 15:13:30 -070098 *
Romain Guy462785f2011-09-27 17:42:10 -070099 * <p>It is important to note that only one producer can use the TextureView.
100 * For instance, if you use a TextureView to display the camera preview, you
101 * cannot use {@link #lockCanvas()} to draw onto the TextureView at the same
102 * time.</p>
John Reck5ba09482015-05-18 15:13:30 -0700103 *
Romain Guyaa6c24c2011-04-28 18:40:04 -0700104 * @see SurfaceView
105 * @see SurfaceTexture
106 */
107public class TextureView extends View {
Romain Guy77a81162011-06-14 16:45:55 -0700108 private static final String LOG_TAG = "TextureView";
109
Mathew Inwoode5ad5982018-08-17 15:07:52 +0100110 @UnsupportedAppUsage
John Reck9d8d99d2018-02-21 12:55:41 -0800111 private TextureLayer mLayer;
Mathew Inwoode5ad5982018-08-17 15:07:52 +0100112 @UnsupportedAppUsage
Romain Guyaa6c24c2011-04-28 18:40:04 -0700113 private SurfaceTexture mSurface;
114 private SurfaceTextureListener mListener;
Romain Guy67603c62013-06-27 10:58:10 -0700115 private boolean mHadSurface;
Romain Guyaa6c24c2011-04-28 18:40:04 -0700116
Mathew Inwoode5ad5982018-08-17 15:07:52 +0100117 @UnsupportedAppUsage
Romain Guya9489272011-06-22 20:58:11 -0700118 private boolean mOpaque = true;
Romain Guyc989d862011-06-22 14:53:39 -0700119
Romain Guy302a9df2011-08-16 13:55:02 -0700120 private final Matrix mMatrix = new Matrix();
121 private boolean mMatrixChanged;
122
Romain Guy58f4edb2011-06-24 14:51:38 -0700123 private final Object[] mLock = new Object[0];
124 private boolean mUpdateLayer;
Mathew Inwoode5ad5982018-08-17 15:07:52 +0100125 @UnsupportedAppUsage
Jamie Gennis2af35242012-04-05 11:44:30 -0700126 private boolean mUpdateSurface;
Romain Guy58f4edb2011-06-24 14:51:38 -0700127
Romain Guy6be3d552011-07-14 18:08:37 -0700128 private Canvas mCanvas;
129 private int mSaveCount;
130
131 private final Object[] mNativeWindowLock = new Object[0];
John Reck918ad522014-06-27 14:45:25 -0700132 // Set by native code, do not write!
Mathew Inwoode5ad5982018-08-17 15:07:52 +0100133 @UnsupportedAppUsage
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000134 private long mNativeWindow;
Romain Guy6be3d552011-07-14 18:08:37 -0700135
Romain Guyaa6c24c2011-04-28 18:40:04 -0700136 /**
137 * Creates a new TextureView.
John Reck5ba09482015-05-18 15:13:30 -0700138 *
Romain Guyaa6c24c2011-04-28 18:40:04 -0700139 * @param context The context to associate this view with.
140 */
141 public TextureView(Context context) {
142 super(context);
Romain Guyaa6c24c2011-04-28 18:40:04 -0700143 }
144
145 /**
146 * Creates a new TextureView.
John Reck5ba09482015-05-18 15:13:30 -0700147 *
Romain Guyaa6c24c2011-04-28 18:40:04 -0700148 * @param context The context to associate this view with.
149 * @param attrs The attributes of the XML tag that is inflating the view.
150 */
Romain Guyaa6c24c2011-04-28 18:40:04 -0700151 public TextureView(Context context, AttributeSet attrs) {
152 super(context, attrs);
Romain Guyaa6c24c2011-04-28 18:40:04 -0700153 }
154
155 /**
156 * Creates a new TextureView.
John Reck5ba09482015-05-18 15:13:30 -0700157 *
Romain Guyaa6c24c2011-04-28 18:40:04 -0700158 * @param context The context to associate this view with.
159 * @param attrs The attributes of the XML tag that is inflating the view.
Alan Viverette617feb92013-09-09 18:09:13 -0700160 * @param defStyleAttr An attribute in the current theme that contains a
161 * reference to a style resource that supplies default values for
162 * the view. Can be 0 to not look for defaults.
Romain Guyaa6c24c2011-04-28 18:40:04 -0700163 */
Alan Viverette617feb92013-09-09 18:09:13 -0700164 public TextureView(Context context, AttributeSet attrs, int defStyleAttr) {
165 super(context, attrs, defStyleAttr);
Alan Viverette617feb92013-09-09 18:09:13 -0700166 }
167
168 /**
169 * Creates a new TextureView.
170 *
171 * @param context The context to associate this view with.
172 * @param attrs The attributes of the XML tag that is inflating the view.
173 * @param defStyleAttr An attribute in the current theme that contains a
174 * reference to a style resource that supplies default values for
175 * the view. Can be 0 to not look for defaults.
176 * @param defStyleRes A resource identifier of a style resource that
177 * supplies default values for the view, used only if
178 * defStyleAttr is 0 or can not be found in the theme. Can be 0
179 * to not look for defaults.
180 */
Alan Viverette617feb92013-09-09 18:09:13 -0700181 public TextureView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
182 super(context, attrs, defStyleAttr, defStyleRes);
Romain Guyaa6c24c2011-04-28 18:40:04 -0700183 }
184
Romain Guya9489272011-06-22 20:58:11 -0700185 /**
186 * {@inheritDoc}
187 */
188 @Override
189 public boolean isOpaque() {
190 return mOpaque;
191 }
192
193 /**
194 * Indicates whether the content of this TextureView is opaque. The
195 * content is assumed to be opaque by default.
John Reck5ba09482015-05-18 15:13:30 -0700196 *
Romain Guya9489272011-06-22 20:58:11 -0700197 * @param opaque True if the content of this TextureView is opaque,
198 * false otherwise
199 */
200 public void setOpaque(boolean opaque) {
201 if (opaque != mOpaque) {
202 mOpaque = opaque;
Romain Guya8a2f972012-04-12 16:33:44 -0700203 if (mLayer != null) {
Romain Guy88801b22012-10-05 14:58:33 -0700204 updateLayerAndInvalidate();
Romain Guya8a2f972012-04-12 16:33:44 -0700205 }
Romain Guya9489272011-06-22 20:58:11 -0700206 }
207 }
208
Romain Guyaa6c24c2011-04-28 18:40:04 -0700209 @Override
210 protected void onAttachedToWindow() {
211 super.onAttachedToWindow();
212
213 if (!isHardwareAccelerated()) {
Romain Guy77a81162011-06-14 16:45:55 -0700214 Log.w(LOG_TAG, "A TextureView or a subclass can only be "
Romain Guyaa6c24c2011-04-28 18:40:04 -0700215 + "used with hardware acceleration enabled.");
216 }
Romain Guy67603c62013-06-27 10:58:10 -0700217
218 if (mHadSurface) {
219 invalidate(true);
220 mHadSurface = false;
221 }
Romain Guyaa6c24c2011-04-28 18:40:04 -0700222 }
223
John Reckb14dfe22014-03-06 22:06:20 +0000224 /** @hide */
Romain Guy451ce442011-06-10 15:40:36 -0700225 @Override
Mathew Inwoode5ad5982018-08-17 15:07:52 +0100226 @UnsupportedAppUsage
John Reckb14dfe22014-03-06 22:06:20 +0000227 protected void onDetachedFromWindowInternal() {
sergeyv1c16c372016-08-02 14:46:12 -0700228 destroyHardwareLayer();
229 releaseSurfaceTexture();
John Reckb14dfe22014-03-06 22:06:20 +0000230 super.onDetachedFromWindowInternal();
Romain Guy31f2c2e2011-11-21 10:55:41 -0800231 }
Romain Guy451ce442011-06-10 15:40:36 -0700232
sergeyv1c16c372016-08-02 14:46:12 -0700233 /**
234 * @hide
235 */
236 @Override
Mathew Inwoode5ad5982018-08-17 15:07:52 +0100237 @UnsupportedAppUsage
sergeyv1c16c372016-08-02 14:46:12 -0700238 protected void destroyHardwareResources() {
sergeyv17dd01b2016-08-30 14:03:32 -0700239 super.destroyHardwareResources();
sergeyv1c16c372016-08-02 14:46:12 -0700240 destroyHardwareLayer();
sergeyv1c16c372016-08-02 14:46:12 -0700241 }
242
Mathew Inwoode5ad5982018-08-17 15:07:52 +0100243 @UnsupportedAppUsage
sergeyv1c16c372016-08-02 14:46:12 -0700244 private void destroyHardwareLayer() {
Romain Guy80429c42011-06-24 17:20:32 -0700245 if (mLayer != null) {
John Reck918ad522014-06-27 14:45:25 -0700246 mLayer.detachSurfaceTexture();
Romain Guy6be3d552011-07-14 18:08:37 -0700247 mLayer.destroy();
Romain Guy451ce442011-06-10 15:40:36 -0700248 mLayer = null;
Doris Liu6b471992015-04-30 17:00:35 -0700249 mMatrixChanged = true;
Romain Guy451ce442011-06-10 15:40:36 -0700250 }
251 }
252
sergeyv1c16c372016-08-02 14:46:12 -0700253 private void releaseSurfaceTexture() {
John Reck3c2587f2016-08-04 07:55:38 -0700254 if (mSurface != null) {
255 boolean shouldRelease = true;
sergeyv1c16c372016-08-02 14:46:12 -0700256
John Reck3c2587f2016-08-04 07:55:38 -0700257 if (mListener != null) {
258 shouldRelease = mListener.onSurfaceTextureDestroyed(mSurface);
259 }
sergeyv1c16c372016-08-02 14:46:12 -0700260
John Reck3c2587f2016-08-04 07:55:38 -0700261 synchronized (mNativeWindowLock) {
262 nDestroyNativeWindow();
263 }
sergeyv1c16c372016-08-02 14:46:12 -0700264
John Reck3c2587f2016-08-04 07:55:38 -0700265 if (shouldRelease) {
266 mSurface.release();
267 }
268 mSurface = null;
269 mHadSurface = true;
sergeyv1c16c372016-08-02 14:46:12 -0700270 }
sergeyv1c16c372016-08-02 14:46:12 -0700271 }
272
Romain Guyaa6c24c2011-04-28 18:40:04 -0700273 /**
274 * The layer type of a TextureView is ignored since a TextureView is always
275 * considered to act as a hardware layer. The optional paint supplied to this
276 * method will however be taken into account when rendering the content of
277 * this TextureView.
John Reck5ba09482015-05-18 15:13:30 -0700278 *
sergeyv342a7e62016-03-24 16:06:46 -0700279 * @param layerType The type of layer to use with this view, must be one of
Romain Guyaa6c24c2011-04-28 18:40:04 -0700280 * {@link #LAYER_TYPE_NONE}, {@link #LAYER_TYPE_SOFTWARE} or
281 * {@link #LAYER_TYPE_HARDWARE}
282 * @param paint The paint used to compose the layer. This argument is optional
283 * and can be null. It is ignored when the layer type is
284 * {@link #LAYER_TYPE_NONE}
285 */
286 @Override
sergeyv342a7e62016-03-24 16:06:46 -0700287 public void setLayerType(int layerType, @Nullable Paint paint) {
288 setLayerPaint(paint);
Romain Guyaa6c24c2011-04-28 18:40:04 -0700289 }
290
John Reck25fbb3f2014-06-12 13:46:45 -0700291 @Override
sergeyv342a7e62016-03-24 16:06:46 -0700292 public void setLayerPaint(@Nullable Paint paint) {
293 if (paint != mLayerPaint) {
294 mLayerPaint = paint;
295 invalidate();
296 }
John Reck25fbb3f2014-06-12 13:46:45 -0700297 }
298
Romain Guyaa6c24c2011-04-28 18:40:04 -0700299 /**
300 * Always returns {@link #LAYER_TYPE_HARDWARE}.
301 */
302 @Override
303 public int getLayerType() {
304 return LAYER_TYPE_HARDWARE;
305 }
306
307 /**
308 * Calling this method has no effect.
309 */
310 @Override
311 public void buildLayer() {
312 }
313
Chris Craik2e931ea2015-08-19 16:13:04 -0700314 @Override
315 public void setForeground(Drawable foreground) {
Chris Craikb7244802016-01-04 15:47:19 -0800316 if (foreground != null && !sTextureViewIgnoresDrawableSetters) {
Chris Craik2e931ea2015-08-19 16:13:04 -0700317 throw new UnsupportedOperationException(
318 "TextureView doesn't support displaying a foreground drawable");
319 }
320 }
321
322 @Override
323 public void setBackgroundDrawable(Drawable background) {
Chris Craikb7244802016-01-04 15:47:19 -0800324 if (background != null && !sTextureViewIgnoresDrawableSetters) {
Chris Craik2e931ea2015-08-19 16:13:04 -0700325 throw new UnsupportedOperationException(
326 "TextureView doesn't support displaying a background drawable");
327 }
328 }
329
Romain Guyaa6c24c2011-04-28 18:40:04 -0700330 /**
331 * Subclasses of TextureView cannot do their own rendering
332 * with the {@link Canvas} object.
John Reck5ba09482015-05-18 15:13:30 -0700333 *
Romain Guyaa6c24c2011-04-28 18:40:04 -0700334 * @param canvas The Canvas to which the View is rendered.
335 */
336 @Override
337 public final void draw(Canvas canvas) {
Chris Craik3aadd602015-08-20 12:41:40 -0700338 // NOTE: Maintain this carefully (see View#draw)
Romain Guy52b307e2012-10-07 17:55:17 -0700339 mPrivateFlags = (mPrivateFlags & ~PFLAG_DIRTY_MASK) | PFLAG_DRAWN;
340
Chris Craik3aadd602015-08-20 12:41:40 -0700341 /* Simplify drawing to guarantee the layer is the only thing drawn - so e.g. no background,
342 scrolling, or fading edges. This guarantees all drawing is in the layer, so drawing
343 properties (alpha, layer paint) affect all of the content of a TextureView. */
344
345 if (canvas.isHardwareAccelerated()) {
346 DisplayListCanvas displayListCanvas = (DisplayListCanvas) canvas;
347
John Reck9d8d99d2018-02-21 12:55:41 -0800348 TextureLayer layer = getTextureLayer();
Chris Craik3aadd602015-08-20 12:41:40 -0700349 if (layer != null) {
350 applyUpdate();
351 applyTransformMatrix();
352
353 mLayer.setLayerPaint(mLayerPaint); // ensure layer paint is up to date
John Reck9d8d99d2018-02-21 12:55:41 -0800354 displayListCanvas.drawTextureLayer(layer);
Chris Craik3aadd602015-08-20 12:41:40 -0700355 }
356 }
Romain Guyaa6c24c2011-04-28 18:40:04 -0700357 }
358
359 /**
360 * Subclasses of TextureView cannot do their own rendering
361 * with the {@link Canvas} object.
John Reck5ba09482015-05-18 15:13:30 -0700362 *
Romain Guyaa6c24c2011-04-28 18:40:04 -0700363 * @param canvas The Canvas to which the View is rendered.
364 */
365 @Override
366 protected final void onDraw(Canvas canvas) {
367 }
368
369 @Override
Romain Guy8f0095c2011-05-02 17:24:22 -0700370 protected void onSizeChanged(int w, int h, int oldw, int oldh) {
371 super.onSizeChanged(w, h, oldw, oldh);
372 if (mSurface != null) {
Mathias Agopian52a9a102013-08-02 01:38:38 -0700373 mSurface.setDefaultBufferSize(getWidth(), getHeight());
Romain Guy88801b22012-10-05 14:58:33 -0700374 updateLayer();
Romain Guy451ce442011-06-10 15:40:36 -0700375 if (mListener != null) {
376 mListener.onSurfaceTextureSizeChanged(mSurface, getWidth(), getHeight());
377 }
Romain Guy8f0095c2011-05-02 17:24:22 -0700378 }
379 }
380
John Reck9d8d99d2018-02-21 12:55:41 -0800381 TextureLayer getTextureLayer() {
Romain Guyaa6c24c2011-04-28 18:40:04 -0700382 if (mLayer == null) {
Stan Iliev45faba52016-06-28 13:33:15 -0400383 if (mAttachInfo == null || mAttachInfo.mThreadedRenderer == null) {
Romain Guy58f4edb2011-06-24 14:51:38 -0700384 return null;
385 }
386
Stan Iliev45faba52016-06-28 13:33:15 -0400387 mLayer = mAttachInfo.mThreadedRenderer.createTextureLayer();
John Reck7e237182016-08-11 10:43:14 -0700388 boolean createNewSurface = (mSurface == null);
389 if (createNewSurface) {
Jamie Gennis8a34d682012-04-17 16:01:34 -0700390 // Create a new SurfaceTexture for the layer.
John Reck918ad522014-06-27 14:45:25 -0700391 mSurface = new SurfaceTexture(false);
sergeyv1c16c372016-08-02 14:46:12 -0700392 nCreateNativeWindow(mSurface);
Jamie Gennis2af35242012-04-05 11:44:30 -0700393 }
John Reck03df0832016-08-16 09:44:23 -0700394 mLayer.setSurfaceTexture(mSurface);
Mathias Agopian52a9a102013-08-02 01:38:38 -0700395 mSurface.setDefaultBufferSize(getWidth(), getHeight());
Jeff Brownc7282e52014-05-06 16:00:38 -0700396 mSurface.setOnFrameAvailableListener(mUpdateListener, mAttachInfo.mHandler);
Romain Guyaa6c24c2011-04-28 18:40:04 -0700397
John Reck7e237182016-08-11 10:43:14 -0700398 if (mListener != null && createNewSurface) {
Romain Guy451ce442011-06-10 15:40:36 -0700399 mListener.onSurfaceTextureAvailable(mSurface, getWidth(), getHeight());
Romain Guyaa6c24c2011-04-28 18:40:04 -0700400 }
Chet Haased15ebf22012-09-05 11:40:29 -0700401 mLayer.setLayerPaint(mLayerPaint);
Romain Guyaa6c24c2011-04-28 18:40:04 -0700402 }
403
Jamie Gennis2af35242012-04-05 11:44:30 -0700404 if (mUpdateSurface) {
405 // Someone has requested that we use a specific SurfaceTexture, so
406 // tell mLayer about it and set the SurfaceTexture to use the
407 // current view size.
408 mUpdateSurface = false;
Romain Guy51f7c6b2012-05-21 16:32:59 -0700409
410 // Since we are updating the layer, force an update to ensure its
411 // parameters are correct (width, height, transform, etc.)
Romain Guy88801b22012-10-05 14:58:33 -0700412 updateLayer();
Romain Guy51f7c6b2012-05-21 16:32:59 -0700413 mMatrixChanged = true;
414
John Reck04fc5832014-02-05 16:38:25 -0800415 mLayer.setSurfaceTexture(mSurface);
Mathias Agopian52a9a102013-08-02 01:38:38 -0700416 mSurface.setDefaultBufferSize(getWidth(), getHeight());
Jamie Gennis2af35242012-04-05 11:44:30 -0700417 }
418
Romain Guyaa6c24c2011-04-28 18:40:04 -0700419 return mLayer;
420 }
421
Romain Guy8f0095c2011-05-02 17:24:22 -0700422 @Override
423 protected void onVisibilityChanged(View changedView, int visibility) {
424 super.onVisibilityChanged(changedView, visibility);
425
426 if (mSurface != null) {
427 // When the view becomes invisible, stop updating it, it's a waste of CPU
428 // To cancel updates, the easiest thing to do is simply to remove the
429 // updates listener
430 if (visibility == VISIBLE) {
John Reck2dedafb2014-05-29 16:15:41 -0700431 if (mLayer != null) {
432 mSurface.setOnFrameAvailableListener(mUpdateListener, mAttachInfo.mHandler);
433 }
Romain Guy88801b22012-10-05 14:58:33 -0700434 updateLayerAndInvalidate();
Romain Guy8f0095c2011-05-02 17:24:22 -0700435 } else {
436 mSurface.setOnFrameAvailableListener(null);
437 }
438 }
439 }
440
Romain Guya9489272011-06-22 20:58:11 -0700441 private void updateLayer() {
Romain Guy88801b22012-10-05 14:58:33 -0700442 synchronized (mLock) {
443 mUpdateLayer = true;
444 }
445 }
446
447 private void updateLayerAndInvalidate() {
448 synchronized (mLock) {
449 mUpdateLayer = true;
450 }
Romain Guy58f4edb2011-06-24 14:51:38 -0700451 invalidate();
452 }
Jamie Gennis2af35242012-04-05 11:44:30 -0700453
Romain Guy58f4edb2011-06-24 14:51:38 -0700454 private void applyUpdate() {
455 if (mLayer == null) {
Romain Guya9489272011-06-22 20:58:11 -0700456 return;
457 }
458
Romain Guy58f4edb2011-06-24 14:51:38 -0700459 synchronized (mLock) {
460 if (mUpdateLayer) {
461 mUpdateLayer = false;
462 } else {
463 return;
464 }
465 }
John Reck5ba09482015-05-18 15:13:30 -0700466
John Reck04fc5832014-02-05 16:38:25 -0800467 mLayer.prepare(getWidth(), getHeight(), mOpaque);
468 mLayer.updateSurfaceTexture();
Romain Guya9489272011-06-22 20:58:11 -0700469
Grace Klobacf559372011-06-22 23:05:40 -0700470 if (mListener != null) {
471 mListener.onSurfaceTextureUpdated(mSurface);
472 }
Romain Guya9489272011-06-22 20:58:11 -0700473 }
474
Romain Guyaa6c24c2011-04-28 18:40:04 -0700475 /**
Romain Guy302a9df2011-08-16 13:55:02 -0700476 * <p>Sets the transform to associate with this texture view.
477 * The specified transform applies to the underlying surface
478 * texture and does not affect the size or position of the view
479 * itself, only of its content.</p>
John Reck5ba09482015-05-18 15:13:30 -0700480 *
Romain Guy302a9df2011-08-16 13:55:02 -0700481 * <p>Some transforms might prevent the content from drawing
482 * all the pixels contained within this view's bounds. In such
483 * situations, make sure this texture view is not marked opaque.</p>
John Reck5ba09482015-05-18 15:13:30 -0700484 *
Romain Guy302a9df2011-08-16 13:55:02 -0700485 * @param transform The transform to apply to the content of
486 * this view.
John Reck5ba09482015-05-18 15:13:30 -0700487 *
488 * @see #getTransform(android.graphics.Matrix)
489 * @see #isOpaque()
490 * @see #setOpaque(boolean)
Romain Guy302a9df2011-08-16 13:55:02 -0700491 */
492 public void setTransform(Matrix transform) {
493 mMatrix.set(transform);
494 mMatrixChanged = true;
Alexandre Eliasc01391f2011-08-19 16:03:16 -0700495 invalidateParentIfNeeded();
Romain Guy302a9df2011-08-16 13:55:02 -0700496 }
497
498 /**
499 * Returns the transform associated with this texture view.
John Reck5ba09482015-05-18 15:13:30 -0700500 *
Romain Guy302a9df2011-08-16 13:55:02 -0700501 * @param transform The {@link Matrix} in which to copy the current
502 * transform. Can be null.
John Reck5ba09482015-05-18 15:13:30 -0700503 *
Romain Guy302a9df2011-08-16 13:55:02 -0700504 * @return The specified matrix if not null or a new {@link Matrix}
505 * instance otherwise.
John Reck5ba09482015-05-18 15:13:30 -0700506 *
507 * @see #setTransform(android.graphics.Matrix)
Romain Guy302a9df2011-08-16 13:55:02 -0700508 */
509 public Matrix getTransform(Matrix transform) {
510 if (transform == null) {
511 transform = new Matrix();
512 }
513
514 transform.set(mMatrix);
515
516 return transform;
517 }
518
Alexandre Eliasc01391f2011-08-19 16:03:16 -0700519 private void applyTransformMatrix() {
Romain Guy51f7c6b2012-05-21 16:32:59 -0700520 if (mMatrixChanged && mLayer != null) {
Alexandre Eliasc01391f2011-08-19 16:03:16 -0700521 mLayer.setTransform(mMatrix);
522 mMatrixChanged = false;
523 }
524 }
525
Romain Guy302a9df2011-08-16 13:55:02 -0700526 /**
Romain Guy77a81162011-06-14 16:45:55 -0700527 * <p>Returns a {@link android.graphics.Bitmap} representation of the content
528 * of the associated surface texture. If the surface texture is not available,
529 * this method returns null.</p>
John Reck5ba09482015-05-18 15:13:30 -0700530 *
Romain Guy77a81162011-06-14 16:45:55 -0700531 * <p>The bitmap returned by this method uses the {@link Bitmap.Config#ARGB_8888}
532 * pixel format and its dimensions are the same as this view's.</p>
John Reck5ba09482015-05-18 15:13:30 -0700533 *
Romain Guy77a81162011-06-14 16:45:55 -0700534 * <p><strong>Do not</strong> invoke this method from a drawing method
535 * ({@link #onDraw(android.graphics.Canvas)} for instance).</p>
John Reck5ba09482015-05-18 15:13:30 -0700536 *
Romain Guyd6b2a002011-06-17 17:45:59 -0700537 * <p>If an error occurs during the copy, an empty bitmap will be returned.</p>
John Reck5ba09482015-05-18 15:13:30 -0700538 *
Romain Guy77a81162011-06-14 16:45:55 -0700539 * @return A valid {@link Bitmap.Config#ARGB_8888} bitmap, or null if the surface
540 * texture is not available or the width &lt;= 0 or the height &lt;= 0
John Reck5ba09482015-05-18 15:13:30 -0700541 *
542 * @see #isAvailable()
543 * @see #getBitmap(android.graphics.Bitmap)
544 * @see #getBitmap(int, int)
Romain Guy77a81162011-06-14 16:45:55 -0700545 */
546 public Bitmap getBitmap() {
547 return getBitmap(getWidth(), getHeight());
548 }
549
550 /**
551 * <p>Returns a {@link android.graphics.Bitmap} representation of the content
552 * of the associated surface texture. If the surface texture is not available,
553 * this method returns null.</p>
John Reck5ba09482015-05-18 15:13:30 -0700554 *
Romain Guy77a81162011-06-14 16:45:55 -0700555 * <p>The bitmap returned by this method uses the {@link Bitmap.Config#ARGB_8888}
556 * pixel format.</p>
John Reck5ba09482015-05-18 15:13:30 -0700557 *
Romain Guy77a81162011-06-14 16:45:55 -0700558 * <p><strong>Do not</strong> invoke this method from a drawing method
559 * ({@link #onDraw(android.graphics.Canvas)} for instance).</p>
John Reck5ba09482015-05-18 15:13:30 -0700560 *
Romain Guyd6b2a002011-06-17 17:45:59 -0700561 * <p>If an error occurs during the copy, an empty bitmap will be returned.</p>
John Reck5ba09482015-05-18 15:13:30 -0700562 *
Romain Guy77a81162011-06-14 16:45:55 -0700563 * @param width The width of the bitmap to create
564 * @param height The height of the bitmap to create
John Reck5ba09482015-05-18 15:13:30 -0700565 *
Romain Guy77a81162011-06-14 16:45:55 -0700566 * @return A valid {@link Bitmap.Config#ARGB_8888} bitmap, or null if the surface
567 * texture is not available or width is &lt;= 0 or height is &lt;= 0
John Reck5ba09482015-05-18 15:13:30 -0700568 *
569 * @see #isAvailable()
570 * @see #getBitmap(android.graphics.Bitmap)
571 * @see #getBitmap()
Romain Guy77a81162011-06-14 16:45:55 -0700572 */
573 public Bitmap getBitmap(int width, int height) {
574 if (isAvailable() && width > 0 && height > 0) {
Dianne Hackborndde331c2012-08-03 14:01:57 -0700575 return getBitmap(Bitmap.createBitmap(getResources().getDisplayMetrics(),
576 width, height, Bitmap.Config.ARGB_8888));
Romain Guy77a81162011-06-14 16:45:55 -0700577 }
578 return null;
579 }
580
581 /**
582 * <p>Copies the content of this view's surface texture into the specified
583 * bitmap. If the surface texture is not available, the copy is not executed.
584 * The content of the surface texture will be scaled to fit exactly inside
585 * the specified bitmap.</p>
John Reck5ba09482015-05-18 15:13:30 -0700586 *
Romain Guy77a81162011-06-14 16:45:55 -0700587 * <p><strong>Do not</strong> invoke this method from a drawing method
588 * ({@link #onDraw(android.graphics.Canvas)} for instance).</p>
John Reck5ba09482015-05-18 15:13:30 -0700589 *
Romain Guyd6b2a002011-06-17 17:45:59 -0700590 * <p>If an error occurs, the bitmap is left unchanged.</p>
John Reck5ba09482015-05-18 15:13:30 -0700591 *
Romain Guy77a81162011-06-14 16:45:55 -0700592 * @param bitmap The bitmap to copy the content of the surface texture into,
593 * cannot be null, all configurations are supported
John Reck5ba09482015-05-18 15:13:30 -0700594 *
Romain Guy77a81162011-06-14 16:45:55 -0700595 * @return The bitmap specified as a parameter
John Reck5ba09482015-05-18 15:13:30 -0700596 *
597 * @see #isAvailable()
598 * @see #getBitmap(int, int)
599 * @see #getBitmap()
600 *
Romain Guy589b0bb2011-10-10 13:57:47 -0700601 * @throws IllegalStateException if the hardware rendering context cannot be
602 * acquired to capture the bitmap
Romain Guy77a81162011-06-14 16:45:55 -0700603 */
604 public Bitmap getBitmap(Bitmap bitmap) {
605 if (bitmap != null && isAvailable()) {
Romain Guy589b0bb2011-10-10 13:57:47 -0700606 applyUpdate();
607 applyTransformMatrix();
608
Romain Guy78245f72012-05-11 10:01:42 -0700609 // This case can happen if the app invokes setSurfaceTexture() before
610 // we are able to create the hardware layer. We can safely initialize
611 // the layer here thanks to the validate() call at the beginning of
612 // this method
613 if (mLayer == null && mUpdateSurface) {
John Reck9d8d99d2018-02-21 12:55:41 -0800614 getTextureLayer();
Romain Guy78245f72012-05-11 10:01:42 -0700615 }
616
617 if (mLayer != null) {
618 mLayer.copyInto(bitmap);
619 }
Romain Guy77a81162011-06-14 16:45:55 -0700620 }
621 return bitmap;
622 }
623
624 /**
625 * Returns true if the {@link SurfaceTexture} associated with this
626 * TextureView is available for rendering. When this method returns
627 * true, {@link #getSurfaceTexture()} returns a valid surface texture.
628 */
629 public boolean isAvailable() {
630 return mSurface != null;
631 }
632
633 /**
Romain Guy6be3d552011-07-14 18:08:37 -0700634 * <p>Start editing the pixels in the surface. The returned Canvas can be used
635 * to draw into the surface's bitmap. A null is returned if the surface has
636 * not been created or otherwise cannot be edited. You will usually need
637 * to implement
638 * {@link SurfaceTextureListener#onSurfaceTextureAvailable(android.graphics.SurfaceTexture, int, int)}
639 * to find out when the Surface is available for use.</p>
John Reck5ba09482015-05-18 15:13:30 -0700640 *
Romain Guy6be3d552011-07-14 18:08:37 -0700641 * <p>The content of the Surface is never preserved between unlockCanvas()
642 * and lockCanvas(), for this reason, every pixel within the Surface area
643 * must be written. The only exception to this rule is when a dirty
644 * rectangle is specified, in which case, non-dirty pixels will be
645 * preserved.</p>
John Reck5ba09482015-05-18 15:13:30 -0700646 *
Romain Guy462785f2011-09-27 17:42:10 -0700647 * <p>This method can only be used if the underlying surface is not already
648 * owned by another producer. For instance, if the TextureView is being used
649 * to render the camera's preview you cannot invoke this method.</p>
John Reck5ba09482015-05-18 15:13:30 -0700650 *
Romain Guy6be3d552011-07-14 18:08:37 -0700651 * @return A Canvas used to draw into the surface.
John Reck5ba09482015-05-18 15:13:30 -0700652 *
653 * @see #lockCanvas(android.graphics.Rect)
654 * @see #unlockCanvasAndPost(android.graphics.Canvas)
Romain Guy6be3d552011-07-14 18:08:37 -0700655 */
656 public Canvas lockCanvas() {
657 return lockCanvas(null);
658 }
659
660 /**
661 * Just like {@link #lockCanvas()} but allows specification of a dirty
662 * rectangle. Every pixel within that rectangle must be written; however
663 * pixels outside the dirty rectangle will be preserved by the next call
664 * to lockCanvas().
Romain Guy53bacf52013-04-30 11:30:10 -0700665 *
666 * This method can return null if the underlying surface texture is not
667 * available (see {@link #isAvailable()} or if the surface texture is
668 * already connected to an image producer (for instance: the camera,
669 * OpenGL, a media player, etc.)
John Reck5ba09482015-05-18 15:13:30 -0700670 *
Romain Guy6be3d552011-07-14 18:08:37 -0700671 * @param dirty Area of the surface that will be modified.
672
673 * @return A Canvas used to draw into the surface.
John Reck5ba09482015-05-18 15:13:30 -0700674 *
675 * @see #lockCanvas()
Romain Guy53bacf52013-04-30 11:30:10 -0700676 * @see #unlockCanvasAndPost(android.graphics.Canvas)
677 * @see #isAvailable()
Romain Guy6be3d552011-07-14 18:08:37 -0700678 */
679 public Canvas lockCanvas(Rect dirty) {
680 if (!isAvailable()) return null;
681
682 if (mCanvas == null) {
683 mCanvas = new Canvas();
684 }
685
686 synchronized (mNativeWindowLock) {
Romain Guy53bacf52013-04-30 11:30:10 -0700687 if (!nLockCanvas(mNativeWindow, mCanvas, dirty)) {
688 return null;
689 }
Romain Guy6be3d552011-07-14 18:08:37 -0700690 }
691 mSaveCount = mCanvas.save();
692
693 return mCanvas;
694 }
695
696 /**
697 * Finish editing pixels in the surface. After this call, the surface's
698 * current pixels will be shown on the screen, but its content is lost,
699 * in particular there is no guarantee that the content of the Surface
700 * will remain unchanged when lockCanvas() is called again.
John Reck5ba09482015-05-18 15:13:30 -0700701 *
Romain Guy6be3d552011-07-14 18:08:37 -0700702 * @param canvas The Canvas previously returned by lockCanvas()
John Reck5ba09482015-05-18 15:13:30 -0700703 *
Romain Guy6be3d552011-07-14 18:08:37 -0700704 * @see #lockCanvas()
John Reck5ba09482015-05-18 15:13:30 -0700705 * @see #lockCanvas(android.graphics.Rect)
Romain Guy6be3d552011-07-14 18:08:37 -0700706 */
707 public void unlockCanvasAndPost(Canvas canvas) {
708 if (mCanvas != null && canvas == mCanvas) {
709 canvas.restoreToCount(mSaveCount);
710 mSaveCount = 0;
711
712 synchronized (mNativeWindowLock) {
713 nUnlockCanvasAndPost(mNativeWindow, mCanvas);
714 }
715 }
716 }
717
718 /**
Romain Guyaa6c24c2011-04-28 18:40:04 -0700719 * Returns the {@link SurfaceTexture} used by this view. This method
Romain Guy77a81162011-06-14 16:45:55 -0700720 * may return null if the view is not attached to a window or if the surface
721 * texture has not been initialized yet.
John Reck5ba09482015-05-18 15:13:30 -0700722 *
723 * @see #isAvailable()
Romain Guyaa6c24c2011-04-28 18:40:04 -0700724 */
725 public SurfaceTexture getSurfaceTexture() {
726 return mSurface;
727 }
728
729 /**
Jamie Gennis2af35242012-04-05 11:44:30 -0700730 * Set the {@link SurfaceTexture} for this view to use. If a {@link
731 * SurfaceTexture} is already being used by this view, it is immediately
Mark Lue8691d12016-08-30 17:38:42 -0700732 * released and not usable any more. The {@link
Jamie Gennis2af35242012-04-05 11:44:30 -0700733 * SurfaceTextureListener#onSurfaceTextureDestroyed} callback is <b>not</b>
Jamie Gennis8a34d682012-04-17 16:01:34 -0700734 * called for the previous {@link SurfaceTexture}. Similarly, the {@link
735 * SurfaceTextureListener#onSurfaceTextureAvailable} callback is <b>not</b>
736 * called for the {@link SurfaceTexture} passed to setSurfaceTexture.
Jamie Gennis2af35242012-04-05 11:44:30 -0700737 *
738 * The {@link SurfaceTexture} object must be detached from all OpenGL ES
739 * contexts prior to calling this method.
740 *
741 * @param surfaceTexture The {@link SurfaceTexture} that the view should use.
742 * @see SurfaceTexture#detachFromGLContext()
Jamie Gennis2af35242012-04-05 11:44:30 -0700743 */
744 public void setSurfaceTexture(SurfaceTexture surfaceTexture) {
745 if (surfaceTexture == null) {
746 throw new NullPointerException("surfaceTexture must not be null");
747 }
John Reck6d8371e2015-05-14 15:47:03 -0700748 if (surfaceTexture == mSurface) {
749 throw new IllegalArgumentException("Trying to setSurfaceTexture to " +
750 "the same SurfaceTexture that's already set.");
751 }
752 if (surfaceTexture.isReleased()) {
753 throw new IllegalArgumentException("Cannot setSurfaceTexture to a " +
754 "released SurfaceTexture");
755 }
Jamie Gennis2af35242012-04-05 11:44:30 -0700756 if (mSurface != null) {
John Reck7e237182016-08-11 10:43:14 -0700757 nDestroyNativeWindow();
Jamie Gennis2af35242012-04-05 11:44:30 -0700758 mSurface.release();
759 }
760 mSurface = surfaceTexture;
John Reck7e237182016-08-11 10:43:14 -0700761 nCreateNativeWindow(mSurface);
Naveen Kallafd69e2a2015-03-17 15:20:53 -0700762
John Reck8bc511e2015-05-18 15:11:52 -0700763 /*
764 * If the view is visible and we already made a layer, update the
765 * listener in the new surface to use the existing listener in the view.
766 * Otherwise this will be called when the view becomes visible or the
767 * layer is created
768 */
769 if (((mViewFlags & VISIBILITY_MASK) == VISIBLE) && mLayer != null) {
Naveen Kallafd69e2a2015-03-17 15:20:53 -0700770 mSurface.setOnFrameAvailableListener(mUpdateListener, mAttachInfo.mHandler);
771 }
Jamie Gennis2af35242012-04-05 11:44:30 -0700772 mUpdateSurface = true;
773 invalidateParentIfNeeded();
774 }
775
776 /**
Romain Guyaa6c24c2011-04-28 18:40:04 -0700777 * Returns the {@link SurfaceTextureListener} currently associated with this
778 * texture view.
John Reck5ba09482015-05-18 15:13:30 -0700779 *
780 * @see #setSurfaceTextureListener(android.view.TextureView.SurfaceTextureListener)
Romain Guyaa6c24c2011-04-28 18:40:04 -0700781 * @see SurfaceTextureListener
782 */
783 public SurfaceTextureListener getSurfaceTextureListener() {
784 return mListener;
785 }
786
787 /**
788 * Sets the {@link SurfaceTextureListener} used to listen to surface
789 * texture events.
John Reck5ba09482015-05-18 15:13:30 -0700790 *
791 * @see #getSurfaceTextureListener()
Romain Guyaa6c24c2011-04-28 18:40:04 -0700792 * @see SurfaceTextureListener
793 */
794 public void setSurfaceTextureListener(SurfaceTextureListener listener) {
795 mListener = listener;
796 }
797
Mathew Inwoode5ad5982018-08-17 15:07:52 +0100798 @UnsupportedAppUsage
Jeff Brownc7282e52014-05-06 16:00:38 -0700799 private final SurfaceTexture.OnFrameAvailableListener mUpdateListener =
800 new SurfaceTexture.OnFrameAvailableListener() {
801 @Override
802 public void onFrameAvailable(SurfaceTexture surfaceTexture) {
803 updateLayer();
804 invalidate();
805 }
806 };
807
Romain Guyaa6c24c2011-04-28 18:40:04 -0700808 /**
809 * This listener can be used to be notified when the surface texture
810 * associated with this texture view is available.
811 */
812 public static interface SurfaceTextureListener {
813 /**
814 * Invoked when a {@link TextureView}'s SurfaceTexture is ready for use.
John Reck5ba09482015-05-18 15:13:30 -0700815 *
Romain Guyaa6c24c2011-04-28 18:40:04 -0700816 * @param surface The surface returned by
817 * {@link android.view.TextureView#getSurfaceTexture()}
Romain Guy451ce442011-06-10 15:40:36 -0700818 * @param width The width of the surface
819 * @param height The height of the surface
Romain Guyaa6c24c2011-04-28 18:40:04 -0700820 */
Romain Guy451ce442011-06-10 15:40:36 -0700821 public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height);
Romain Guy8f0095c2011-05-02 17:24:22 -0700822
823 /**
824 * Invoked when the {@link SurfaceTexture}'s buffers size changed.
John Reck5ba09482015-05-18 15:13:30 -0700825 *
Romain Guy8f0095c2011-05-02 17:24:22 -0700826 * @param surface The surface returned by
827 * {@link android.view.TextureView#getSurfaceTexture()}
828 * @param width The new width of the surface
829 * @param height The new height of the surface
830 */
831 public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height);
Romain Guy451ce442011-06-10 15:40:36 -0700832
833 /**
834 * Invoked when the specified {@link SurfaceTexture} is about to be destroyed.
Grace Kloba402f0552011-08-09 18:47:17 -0700835 * If returns true, no rendering should happen inside the surface texture after this method
836 * is invoked. If returns false, the client needs to call {@link SurfaceTexture#release()}.
Romain Guy52b307e2012-10-07 17:55:17 -0700837 * Most applications should return true.
John Reck5ba09482015-05-18 15:13:30 -0700838 *
Romain Guy451ce442011-06-10 15:40:36 -0700839 * @param surface The surface about to be destroyed
840 */
Grace Kloba402f0552011-08-09 18:47:17 -0700841 public boolean onSurfaceTextureDestroyed(SurfaceTexture surface);
Grace Klobacf559372011-06-22 23:05:40 -0700842
843 /**
844 * Invoked when the specified {@link SurfaceTexture} is updated through
845 * {@link SurfaceTexture#updateTexImage()}.
John Reck5ba09482015-05-18 15:13:30 -0700846 *
Grace Klobacf559372011-06-22 23:05:40 -0700847 * @param surface The surface just updated
848 */
849 public void onSurfaceTextureUpdated(SurfaceTexture surface);
Romain Guyaa6c24c2011-04-28 18:40:04 -0700850 }
Romain Guy8f0095c2011-05-02 17:24:22 -0700851
Mathew Inwoode5ad5982018-08-17 15:07:52 +0100852 @UnsupportedAppUsage
Romain Guy6be3d552011-07-14 18:08:37 -0700853 private native void nCreateNativeWindow(SurfaceTexture surface);
Mathew Inwoode5ad5982018-08-17 15:07:52 +0100854 @UnsupportedAppUsage
Romain Guy6be3d552011-07-14 18:08:37 -0700855 private native void nDestroyNativeWindow();
856
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000857 private static native boolean nLockCanvas(long nativeWindow, Canvas canvas, Rect dirty);
858 private static native void nUnlockCanvasAndPost(long nativeWindow, Canvas canvas);
Romain Guyaa6c24c2011-04-28 18:40:04 -0700859}