blob: 0175ba201dd1943662a57fa859f706e1339f8d7c [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 Inwooda570dee2018-08-17 14:56:00 +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;
John Reck32f140aa62018-10-04 15:08:24 -070026import android.graphics.RecordingCanvas;
Romain Guy6be3d552011-07-14 18:08:37 -070027import android.graphics.Rect;
Romain Guyaa6c24c2011-04-28 18:40:04 -070028import android.graphics.SurfaceTexture;
Chris Craik2e931ea2015-08-19 16:13:04 -070029import android.graphics.drawable.Drawable;
Romain Guyaa6c24c2011-04-28 18:40:04 -070030import android.util.AttributeSet;
31import android.util.Log;
32
33/**
34 * <p>A TextureView can be used to display a content stream. Such a content
35 * stream can for instance be a video or an OpenGL scene. The content stream
36 * can come from the application's process as well as a remote process.</p>
John Reck5ba09482015-05-18 15:13:30 -070037 *
Romain Guyaa6c24c2011-04-28 18:40:04 -070038 * <p>TextureView can only be used in a hardware accelerated window. When
39 * rendered in software, TextureView will draw nothing.</p>
John Reck5ba09482015-05-18 15:13:30 -070040 *
Romain Guyaa6c24c2011-04-28 18:40:04 -070041 * <p>Unlike {@link SurfaceView}, TextureView does not create a separate
42 * window but behaves as a regular View. This key difference allows a
43 * TextureView to be moved, transformed, animated, etc. For instance, you
44 * can make a TextureView semi-translucent by calling
45 * <code>myView.setAlpha(0.5f)</code>.</p>
John Reck5ba09482015-05-18 15:13:30 -070046 *
Romain Guyaa6c24c2011-04-28 18:40:04 -070047 * <p>Using a TextureView is simple: all you need to do is get its
48 * {@link SurfaceTexture}. The {@link SurfaceTexture} can then be used to
John Reck5ba09482015-05-18 15:13:30 -070049 * render content. The following example demonstrates how to render the
Romain Guyaa6c24c2011-04-28 18:40:04 -070050 * camera preview into a TextureView:</p>
John Reck5ba09482015-05-18 15:13:30 -070051 *
Romain Guyaa6c24c2011-04-28 18:40:04 -070052 * <pre>
53 * public class LiveCameraActivity extends Activity implements TextureView.SurfaceTextureListener {
54 * private Camera mCamera;
55 * private TextureView mTextureView;
56 *
Romain Guyaa6c24c2011-04-28 18:40:04 -070057 * protected void onCreate(Bundle savedInstanceState) {
58 * super.onCreate(savedInstanceState);
59 *
60 * mTextureView = new TextureView(this);
61 * mTextureView.setSurfaceTextureListener(this);
62 *
63 * setContentView(mTextureView);
64 * }
65 *
Romain Guy451ce442011-06-10 15:40:36 -070066 * public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
Romain Guyaa6c24c2011-04-28 18:40:04 -070067 * mCamera = Camera.open();
68 *
69 * try {
70 * mCamera.setPreviewTexture(surface);
71 * mCamera.startPreview();
72 * } catch (IOException ioe) {
73 * // Something bad happened
74 * }
75 * }
Grace Klobacf559372011-06-22 23:05:40 -070076 *
Romain Guy8f0095c2011-05-02 17:24:22 -070077 * public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
78 * // Ignored, Camera does all the work for us
79 * }
Grace Klobacf559372011-06-22 23:05:40 -070080 *
Grace Kloba402f0552011-08-09 18:47:17 -070081 * public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
Romain Guy451ce442011-06-10 15:40:36 -070082 * mCamera.stopPreview();
83 * mCamera.release();
Grace Kloba402f0552011-08-09 18:47:17 -070084 * return true;
Romain Guy451ce442011-06-10 15:40:36 -070085 * }
Grace Klobacf559372011-06-22 23:05:40 -070086 *
87 * public void onSurfaceTextureUpdated(SurfaceTexture surface) {
Romain Guy58f4edb2011-06-24 14:51:38 -070088 * // Invoked every time there's a new Camera preview frame
Grace Klobacf559372011-06-22 23:05:40 -070089 * }
Romain Guyaa6c24c2011-04-28 18:40:04 -070090 * }
91 * </pre>
John Reck5ba09482015-05-18 15:13:30 -070092 *
Romain Guyaa6c24c2011-04-28 18:40:04 -070093 * <p>A TextureView's SurfaceTexture can be obtained either by invoking
94 * {@link #getSurfaceTexture()} or by using a {@link SurfaceTextureListener}.
95 * It is important to know that a SurfaceTexture is available only after the
96 * TextureView is attached to a window (and {@link #onAttachedToWindow()} has
97 * been invoked.) It is therefore highly recommended you use a listener to
98 * be notified when the SurfaceTexture becomes available.</p>
John Reck5ba09482015-05-18 15:13:30 -070099 *
Romain Guy462785f2011-09-27 17:42:10 -0700100 * <p>It is important to note that only one producer can use the TextureView.
101 * For instance, if you use a TextureView to display the camera preview, you
102 * cannot use {@link #lockCanvas()} to draw onto the TextureView at the same
103 * time.</p>
John Reck5ba09482015-05-18 15:13:30 -0700104 *
Romain Guyaa6c24c2011-04-28 18:40:04 -0700105 * @see SurfaceView
106 * @see SurfaceTexture
107 */
108public class TextureView extends View {
Romain Guy77a81162011-06-14 16:45:55 -0700109 private static final String LOG_TAG = "TextureView";
110
Mathew Inwooda570dee2018-08-17 14:56:00 +0100111 @UnsupportedAppUsage
John Reck9d8d99d2018-02-21 12:55:41 -0800112 private TextureLayer mLayer;
Mathew Inwooda570dee2018-08-17 14:56:00 +0100113 @UnsupportedAppUsage
Romain Guyaa6c24c2011-04-28 18:40:04 -0700114 private SurfaceTexture mSurface;
115 private SurfaceTextureListener mListener;
Romain Guy67603c62013-06-27 10:58:10 -0700116 private boolean mHadSurface;
Romain Guyaa6c24c2011-04-28 18:40:04 -0700117
Mathew Inwooda570dee2018-08-17 14:56:00 +0100118 @UnsupportedAppUsage
Romain Guya9489272011-06-22 20:58:11 -0700119 private boolean mOpaque = true;
Romain Guyc989d862011-06-22 14:53:39 -0700120
Romain Guy302a9df2011-08-16 13:55:02 -0700121 private final Matrix mMatrix = new Matrix();
122 private boolean mMatrixChanged;
123
Romain Guy58f4edb2011-06-24 14:51:38 -0700124 private final Object[] mLock = new Object[0];
125 private boolean mUpdateLayer;
Mathew Inwooda570dee2018-08-17 14:56:00 +0100126 @UnsupportedAppUsage
Jamie Gennis2af35242012-04-05 11:44:30 -0700127 private boolean mUpdateSurface;
Romain Guy58f4edb2011-06-24 14:51:38 -0700128
Romain Guy6be3d552011-07-14 18:08:37 -0700129 private Canvas mCanvas;
130 private int mSaveCount;
131
132 private final Object[] mNativeWindowLock = new Object[0];
John Reck918ad522014-06-27 14:45:25 -0700133 // Set by native code, do not write!
Mathew Inwooda570dee2018-08-17 14:56:00 +0100134 @UnsupportedAppUsage
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000135 private long mNativeWindow;
Romain Guy6be3d552011-07-14 18:08:37 -0700136
Romain Guyaa6c24c2011-04-28 18:40:04 -0700137 /**
138 * Creates a new TextureView.
John Reck5ba09482015-05-18 15:13:30 -0700139 *
Romain Guyaa6c24c2011-04-28 18:40:04 -0700140 * @param context The context to associate this view with.
141 */
142 public TextureView(Context context) {
143 super(context);
Romain Guyaa6c24c2011-04-28 18:40:04 -0700144 }
145
146 /**
147 * Creates a new TextureView.
John Reck5ba09482015-05-18 15:13:30 -0700148 *
Romain Guyaa6c24c2011-04-28 18:40:04 -0700149 * @param context The context to associate this view with.
150 * @param attrs The attributes of the XML tag that is inflating the view.
151 */
Romain Guyaa6c24c2011-04-28 18:40:04 -0700152 public TextureView(Context context, AttributeSet attrs) {
153 super(context, attrs);
Romain Guyaa6c24c2011-04-28 18:40:04 -0700154 }
155
156 /**
157 * Creates a new TextureView.
John Reck5ba09482015-05-18 15:13:30 -0700158 *
Romain Guyaa6c24c2011-04-28 18:40:04 -0700159 * @param context The context to associate this view with.
160 * @param attrs The attributes of the XML tag that is inflating the view.
Alan Viverette617feb92013-09-09 18:09:13 -0700161 * @param defStyleAttr An attribute in the current theme that contains a
162 * reference to a style resource that supplies default values for
163 * the view. Can be 0 to not look for defaults.
Romain Guyaa6c24c2011-04-28 18:40:04 -0700164 */
Alan Viverette617feb92013-09-09 18:09:13 -0700165 public TextureView(Context context, AttributeSet attrs, int defStyleAttr) {
166 super(context, attrs, defStyleAttr);
Alan Viverette617feb92013-09-09 18:09:13 -0700167 }
168
169 /**
170 * Creates a new TextureView.
171 *
172 * @param context The context to associate this view with.
173 * @param attrs The attributes of the XML tag that is inflating the view.
174 * @param defStyleAttr An attribute in the current theme that contains a
175 * reference to a style resource that supplies default values for
176 * the view. Can be 0 to not look for defaults.
177 * @param defStyleRes A resource identifier of a style resource that
178 * supplies default values for the view, used only if
179 * defStyleAttr is 0 or can not be found in the theme. Can be 0
180 * to not look for defaults.
181 */
Alan Viverette617feb92013-09-09 18:09:13 -0700182 public TextureView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
183 super(context, attrs, defStyleAttr, defStyleRes);
Romain Guyaa6c24c2011-04-28 18:40:04 -0700184 }
185
Romain Guya9489272011-06-22 20:58:11 -0700186 /**
187 * {@inheritDoc}
188 */
189 @Override
190 public boolean isOpaque() {
191 return mOpaque;
192 }
193
194 /**
195 * Indicates whether the content of this TextureView is opaque. The
196 * content is assumed to be opaque by default.
John Reck5ba09482015-05-18 15:13:30 -0700197 *
Romain Guya9489272011-06-22 20:58:11 -0700198 * @param opaque True if the content of this TextureView is opaque,
199 * false otherwise
200 */
201 public void setOpaque(boolean opaque) {
202 if (opaque != mOpaque) {
203 mOpaque = opaque;
Romain Guya8a2f972012-04-12 16:33:44 -0700204 if (mLayer != null) {
Romain Guy88801b22012-10-05 14:58:33 -0700205 updateLayerAndInvalidate();
Romain Guya8a2f972012-04-12 16:33:44 -0700206 }
Romain Guya9489272011-06-22 20:58:11 -0700207 }
208 }
209
Romain Guyaa6c24c2011-04-28 18:40:04 -0700210 @Override
211 protected void onAttachedToWindow() {
212 super.onAttachedToWindow();
213
214 if (!isHardwareAccelerated()) {
Romain Guy77a81162011-06-14 16:45:55 -0700215 Log.w(LOG_TAG, "A TextureView or a subclass can only be "
Romain Guyaa6c24c2011-04-28 18:40:04 -0700216 + "used with hardware acceleration enabled.");
217 }
Romain Guy67603c62013-06-27 10:58:10 -0700218
219 if (mHadSurface) {
220 invalidate(true);
221 mHadSurface = false;
222 }
Romain Guyaa6c24c2011-04-28 18:40:04 -0700223 }
224
John Reckb14dfe22014-03-06 22:06:20 +0000225 /** @hide */
Romain Guy451ce442011-06-10 15:40:36 -0700226 @Override
Mathew Inwooda570dee2018-08-17 14:56:00 +0100227 @UnsupportedAppUsage
John Reckb14dfe22014-03-06 22:06:20 +0000228 protected void onDetachedFromWindowInternal() {
sergeyv1c16c372016-08-02 14:46:12 -0700229 destroyHardwareLayer();
230 releaseSurfaceTexture();
John Reckb14dfe22014-03-06 22:06:20 +0000231 super.onDetachedFromWindowInternal();
Romain Guy31f2c2e2011-11-21 10:55:41 -0800232 }
Romain Guy451ce442011-06-10 15:40:36 -0700233
sergeyv1c16c372016-08-02 14:46:12 -0700234 /**
235 * @hide
236 */
237 @Override
Mathew Inwooda570dee2018-08-17 14:56:00 +0100238 @UnsupportedAppUsage
sergeyv1c16c372016-08-02 14:46:12 -0700239 protected void destroyHardwareResources() {
sergeyv17dd01b2016-08-30 14:03:32 -0700240 super.destroyHardwareResources();
sergeyv1c16c372016-08-02 14:46:12 -0700241 destroyHardwareLayer();
sergeyv1c16c372016-08-02 14:46:12 -0700242 }
243
Mathew Inwooda570dee2018-08-17 14:56:00 +0100244 @UnsupportedAppUsage
sergeyv1c16c372016-08-02 14:46:12 -0700245 private void destroyHardwareLayer() {
Romain Guy80429c42011-06-24 17:20:32 -0700246 if (mLayer != null) {
John Reck918ad522014-06-27 14:45:25 -0700247 mLayer.detachSurfaceTexture();
Romain Guy6be3d552011-07-14 18:08:37 -0700248 mLayer.destroy();
Romain Guy451ce442011-06-10 15:40:36 -0700249 mLayer = null;
Doris Liu6b471992015-04-30 17:00:35 -0700250 mMatrixChanged = true;
Romain Guy451ce442011-06-10 15:40:36 -0700251 }
252 }
253
sergeyv1c16c372016-08-02 14:46:12 -0700254 private void releaseSurfaceTexture() {
John Reck3c2587f2016-08-04 07:55:38 -0700255 if (mSurface != null) {
256 boolean shouldRelease = true;
sergeyv1c16c372016-08-02 14:46:12 -0700257
John Reck3c2587f2016-08-04 07:55:38 -0700258 if (mListener != null) {
259 shouldRelease = mListener.onSurfaceTextureDestroyed(mSurface);
260 }
sergeyv1c16c372016-08-02 14:46:12 -0700261
John Reck3c2587f2016-08-04 07:55:38 -0700262 synchronized (mNativeWindowLock) {
263 nDestroyNativeWindow();
264 }
sergeyv1c16c372016-08-02 14:46:12 -0700265
John Reck3c2587f2016-08-04 07:55:38 -0700266 if (shouldRelease) {
267 mSurface.release();
268 }
269 mSurface = null;
270 mHadSurface = true;
sergeyv1c16c372016-08-02 14:46:12 -0700271 }
sergeyv1c16c372016-08-02 14:46:12 -0700272 }
273
Romain Guyaa6c24c2011-04-28 18:40:04 -0700274 /**
275 * The layer type of a TextureView is ignored since a TextureView is always
276 * considered to act as a hardware layer. The optional paint supplied to this
277 * method will however be taken into account when rendering the content of
278 * this TextureView.
John Reck5ba09482015-05-18 15:13:30 -0700279 *
sergeyv342a7e62016-03-24 16:06:46 -0700280 * @param layerType The type of layer to use with this view, must be one of
Romain Guyaa6c24c2011-04-28 18:40:04 -0700281 * {@link #LAYER_TYPE_NONE}, {@link #LAYER_TYPE_SOFTWARE} or
282 * {@link #LAYER_TYPE_HARDWARE}
283 * @param paint The paint used to compose the layer. This argument is optional
284 * and can be null. It is ignored when the layer type is
285 * {@link #LAYER_TYPE_NONE}
286 */
287 @Override
sergeyv342a7e62016-03-24 16:06:46 -0700288 public void setLayerType(int layerType, @Nullable Paint paint) {
289 setLayerPaint(paint);
Romain Guyaa6c24c2011-04-28 18:40:04 -0700290 }
291
John Reck25fbb3f2014-06-12 13:46:45 -0700292 @Override
sergeyv342a7e62016-03-24 16:06:46 -0700293 public void setLayerPaint(@Nullable Paint paint) {
294 if (paint != mLayerPaint) {
295 mLayerPaint = paint;
296 invalidate();
297 }
John Reck25fbb3f2014-06-12 13:46:45 -0700298 }
299
Romain Guyaa6c24c2011-04-28 18:40:04 -0700300 /**
301 * Always returns {@link #LAYER_TYPE_HARDWARE}.
302 */
303 @Override
304 public int getLayerType() {
305 return LAYER_TYPE_HARDWARE;
306 }
307
308 /**
309 * Calling this method has no effect.
310 */
311 @Override
312 public void buildLayer() {
313 }
314
Chris Craik2e931ea2015-08-19 16:13:04 -0700315 @Override
316 public void setForeground(Drawable foreground) {
Chris Craikb7244802016-01-04 15:47:19 -0800317 if (foreground != null && !sTextureViewIgnoresDrawableSetters) {
Chris Craik2e931ea2015-08-19 16:13:04 -0700318 throw new UnsupportedOperationException(
319 "TextureView doesn't support displaying a foreground drawable");
320 }
321 }
322
323 @Override
324 public void setBackgroundDrawable(Drawable background) {
Chris Craikb7244802016-01-04 15:47:19 -0800325 if (background != null && !sTextureViewIgnoresDrawableSetters) {
Chris Craik2e931ea2015-08-19 16:13:04 -0700326 throw new UnsupportedOperationException(
327 "TextureView doesn't support displaying a background drawable");
328 }
329 }
330
Romain Guyaa6c24c2011-04-28 18:40:04 -0700331 /**
332 * Subclasses of TextureView cannot do their own rendering
333 * with the {@link Canvas} object.
John Reck5ba09482015-05-18 15:13:30 -0700334 *
Romain Guyaa6c24c2011-04-28 18:40:04 -0700335 * @param canvas The Canvas to which the View is rendered.
336 */
337 @Override
338 public final void draw(Canvas canvas) {
Chris Craik3aadd602015-08-20 12:41:40 -0700339 // NOTE: Maintain this carefully (see View#draw)
Romain Guy52b307e2012-10-07 17:55:17 -0700340 mPrivateFlags = (mPrivateFlags & ~PFLAG_DIRTY_MASK) | PFLAG_DRAWN;
341
Chris Craik3aadd602015-08-20 12:41:40 -0700342 /* Simplify drawing to guarantee the layer is the only thing drawn - so e.g. no background,
343 scrolling, or fading edges. This guarantees all drawing is in the layer, so drawing
344 properties (alpha, layer paint) affect all of the content of a TextureView. */
345
346 if (canvas.isHardwareAccelerated()) {
John Reck32f140aa62018-10-04 15:08:24 -0700347 RecordingCanvas recordingCanvas = (RecordingCanvas) canvas;
Chris Craik3aadd602015-08-20 12:41:40 -0700348
John Reck9d8d99d2018-02-21 12:55:41 -0800349 TextureLayer layer = getTextureLayer();
Chris Craik3aadd602015-08-20 12:41:40 -0700350 if (layer != null) {
351 applyUpdate();
352 applyTransformMatrix();
353
354 mLayer.setLayerPaint(mLayerPaint); // ensure layer paint is up to date
John Reck32f140aa62018-10-04 15:08:24 -0700355 recordingCanvas.drawTextureLayer(layer);
Chris Craik3aadd602015-08-20 12:41:40 -0700356 }
357 }
Romain Guyaa6c24c2011-04-28 18:40:04 -0700358 }
359
360 /**
361 * Subclasses of TextureView cannot do their own rendering
362 * with the {@link Canvas} object.
John Reck5ba09482015-05-18 15:13:30 -0700363 *
Romain Guyaa6c24c2011-04-28 18:40:04 -0700364 * @param canvas The Canvas to which the View is rendered.
365 */
366 @Override
367 protected final void onDraw(Canvas canvas) {
368 }
369
370 @Override
Romain Guy8f0095c2011-05-02 17:24:22 -0700371 protected void onSizeChanged(int w, int h, int oldw, int oldh) {
372 super.onSizeChanged(w, h, oldw, oldh);
373 if (mSurface != null) {
Mathias Agopian52a9a102013-08-02 01:38:38 -0700374 mSurface.setDefaultBufferSize(getWidth(), getHeight());
Romain Guy88801b22012-10-05 14:58:33 -0700375 updateLayer();
Romain Guy451ce442011-06-10 15:40:36 -0700376 if (mListener != null) {
377 mListener.onSurfaceTextureSizeChanged(mSurface, getWidth(), getHeight());
378 }
Romain Guy8f0095c2011-05-02 17:24:22 -0700379 }
380 }
381
John Reck9d8d99d2018-02-21 12:55:41 -0800382 TextureLayer getTextureLayer() {
Romain Guyaa6c24c2011-04-28 18:40:04 -0700383 if (mLayer == null) {
Stan Iliev45faba52016-06-28 13:33:15 -0400384 if (mAttachInfo == null || mAttachInfo.mThreadedRenderer == null) {
Romain Guy58f4edb2011-06-24 14:51:38 -0700385 return null;
386 }
387
Stan Iliev45faba52016-06-28 13:33:15 -0400388 mLayer = mAttachInfo.mThreadedRenderer.createTextureLayer();
John Reck7e237182016-08-11 10:43:14 -0700389 boolean createNewSurface = (mSurface == null);
390 if (createNewSurface) {
Jamie Gennis8a34d682012-04-17 16:01:34 -0700391 // Create a new SurfaceTexture for the layer.
John Reck918ad522014-06-27 14:45:25 -0700392 mSurface = new SurfaceTexture(false);
sergeyv1c16c372016-08-02 14:46:12 -0700393 nCreateNativeWindow(mSurface);
Jamie Gennis2af35242012-04-05 11:44:30 -0700394 }
John Reck03df0832016-08-16 09:44:23 -0700395 mLayer.setSurfaceTexture(mSurface);
Mathias Agopian52a9a102013-08-02 01:38:38 -0700396 mSurface.setDefaultBufferSize(getWidth(), getHeight());
Jeff Brownc7282e52014-05-06 16:00:38 -0700397 mSurface.setOnFrameAvailableListener(mUpdateListener, mAttachInfo.mHandler);
Romain Guyaa6c24c2011-04-28 18:40:04 -0700398
John Reck7e237182016-08-11 10:43:14 -0700399 if (mListener != null && createNewSurface) {
Romain Guy451ce442011-06-10 15:40:36 -0700400 mListener.onSurfaceTextureAvailable(mSurface, getWidth(), getHeight());
Romain Guyaa6c24c2011-04-28 18:40:04 -0700401 }
Chet Haased15ebf22012-09-05 11:40:29 -0700402 mLayer.setLayerPaint(mLayerPaint);
Romain Guyaa6c24c2011-04-28 18:40:04 -0700403 }
404
Jamie Gennis2af35242012-04-05 11:44:30 -0700405 if (mUpdateSurface) {
406 // Someone has requested that we use a specific SurfaceTexture, so
407 // tell mLayer about it and set the SurfaceTexture to use the
408 // current view size.
409 mUpdateSurface = false;
Romain Guy51f7c6b2012-05-21 16:32:59 -0700410
411 // Since we are updating the layer, force an update to ensure its
412 // parameters are correct (width, height, transform, etc.)
Romain Guy88801b22012-10-05 14:58:33 -0700413 updateLayer();
Romain Guy51f7c6b2012-05-21 16:32:59 -0700414 mMatrixChanged = true;
415
John Reck04fc5832014-02-05 16:38:25 -0800416 mLayer.setSurfaceTexture(mSurface);
Mathias Agopian52a9a102013-08-02 01:38:38 -0700417 mSurface.setDefaultBufferSize(getWidth(), getHeight());
Jamie Gennis2af35242012-04-05 11:44:30 -0700418 }
419
Romain Guyaa6c24c2011-04-28 18:40:04 -0700420 return mLayer;
421 }
422
Romain Guy8f0095c2011-05-02 17:24:22 -0700423 @Override
424 protected void onVisibilityChanged(View changedView, int visibility) {
425 super.onVisibilityChanged(changedView, visibility);
426
427 if (mSurface != null) {
428 // When the view becomes invisible, stop updating it, it's a waste of CPU
429 // To cancel updates, the easiest thing to do is simply to remove the
430 // updates listener
431 if (visibility == VISIBLE) {
John Reck2dedafb2014-05-29 16:15:41 -0700432 if (mLayer != null) {
433 mSurface.setOnFrameAvailableListener(mUpdateListener, mAttachInfo.mHandler);
434 }
Romain Guy88801b22012-10-05 14:58:33 -0700435 updateLayerAndInvalidate();
Romain Guy8f0095c2011-05-02 17:24:22 -0700436 } else {
437 mSurface.setOnFrameAvailableListener(null);
438 }
439 }
440 }
441
Romain Guya9489272011-06-22 20:58:11 -0700442 private void updateLayer() {
Romain Guy88801b22012-10-05 14:58:33 -0700443 synchronized (mLock) {
444 mUpdateLayer = true;
445 }
446 }
447
448 private void updateLayerAndInvalidate() {
449 synchronized (mLock) {
450 mUpdateLayer = true;
451 }
Romain Guy58f4edb2011-06-24 14:51:38 -0700452 invalidate();
453 }
Jamie Gennis2af35242012-04-05 11:44:30 -0700454
Romain Guy58f4edb2011-06-24 14:51:38 -0700455 private void applyUpdate() {
456 if (mLayer == null) {
Romain Guya9489272011-06-22 20:58:11 -0700457 return;
458 }
459
Romain Guy58f4edb2011-06-24 14:51:38 -0700460 synchronized (mLock) {
461 if (mUpdateLayer) {
462 mUpdateLayer = false;
463 } else {
464 return;
465 }
466 }
John Reck5ba09482015-05-18 15:13:30 -0700467
John Reck04fc5832014-02-05 16:38:25 -0800468 mLayer.prepare(getWidth(), getHeight(), mOpaque);
469 mLayer.updateSurfaceTexture();
Romain Guya9489272011-06-22 20:58:11 -0700470
Grace Klobacf559372011-06-22 23:05:40 -0700471 if (mListener != null) {
472 mListener.onSurfaceTextureUpdated(mSurface);
473 }
Romain Guya9489272011-06-22 20:58:11 -0700474 }
475
Romain Guyaa6c24c2011-04-28 18:40:04 -0700476 /**
Romain Guy302a9df2011-08-16 13:55:02 -0700477 * <p>Sets the transform to associate with this texture view.
478 * The specified transform applies to the underlying surface
479 * texture and does not affect the size or position of the view
480 * itself, only of its content.</p>
John Reck5ba09482015-05-18 15:13:30 -0700481 *
Romain Guy302a9df2011-08-16 13:55:02 -0700482 * <p>Some transforms might prevent the content from drawing
483 * all the pixels contained within this view's bounds. In such
484 * situations, make sure this texture view is not marked opaque.</p>
John Reck5ba09482015-05-18 15:13:30 -0700485 *
Romain Guy302a9df2011-08-16 13:55:02 -0700486 * @param transform The transform to apply to the content of
487 * this view.
John Reck5ba09482015-05-18 15:13:30 -0700488 *
489 * @see #getTransform(android.graphics.Matrix)
490 * @see #isOpaque()
491 * @see #setOpaque(boolean)
Romain Guy302a9df2011-08-16 13:55:02 -0700492 */
493 public void setTransform(Matrix transform) {
494 mMatrix.set(transform);
495 mMatrixChanged = true;
Alexandre Eliasc01391f2011-08-19 16:03:16 -0700496 invalidateParentIfNeeded();
Romain Guy302a9df2011-08-16 13:55:02 -0700497 }
498
499 /**
500 * Returns the transform associated with this texture view.
John Reck5ba09482015-05-18 15:13:30 -0700501 *
Romain Guy302a9df2011-08-16 13:55:02 -0700502 * @param transform The {@link Matrix} in which to copy the current
503 * transform. Can be null.
John Reck5ba09482015-05-18 15:13:30 -0700504 *
Romain Guy302a9df2011-08-16 13:55:02 -0700505 * @return The specified matrix if not null or a new {@link Matrix}
506 * instance otherwise.
John Reck5ba09482015-05-18 15:13:30 -0700507 *
508 * @see #setTransform(android.graphics.Matrix)
Romain Guy302a9df2011-08-16 13:55:02 -0700509 */
510 public Matrix getTransform(Matrix transform) {
511 if (transform == null) {
512 transform = new Matrix();
513 }
514
515 transform.set(mMatrix);
516
517 return transform;
518 }
519
Alexandre Eliasc01391f2011-08-19 16:03:16 -0700520 private void applyTransformMatrix() {
Romain Guy51f7c6b2012-05-21 16:32:59 -0700521 if (mMatrixChanged && mLayer != null) {
Alexandre Eliasc01391f2011-08-19 16:03:16 -0700522 mLayer.setTransform(mMatrix);
523 mMatrixChanged = false;
524 }
525 }
526
Romain Guy302a9df2011-08-16 13:55:02 -0700527 /**
Romain Guy77a81162011-06-14 16:45:55 -0700528 * <p>Returns a {@link android.graphics.Bitmap} representation of the content
529 * of the associated surface texture. If the surface texture is not available,
530 * this method returns null.</p>
John Reck5ba09482015-05-18 15:13:30 -0700531 *
Romain Guy77a81162011-06-14 16:45:55 -0700532 * <p>The bitmap returned by this method uses the {@link Bitmap.Config#ARGB_8888}
533 * pixel format and its dimensions are the same as this view's.</p>
John Reck5ba09482015-05-18 15:13:30 -0700534 *
Romain Guy77a81162011-06-14 16:45:55 -0700535 * <p><strong>Do not</strong> invoke this method from a drawing method
536 * ({@link #onDraw(android.graphics.Canvas)} for instance).</p>
John Reck5ba09482015-05-18 15:13:30 -0700537 *
Romain Guyd6b2a002011-06-17 17:45:59 -0700538 * <p>If an error occurs during the copy, an empty bitmap will be returned.</p>
John Reck5ba09482015-05-18 15:13:30 -0700539 *
Romain Guy77a81162011-06-14 16:45:55 -0700540 * @return A valid {@link Bitmap.Config#ARGB_8888} bitmap, or null if the surface
541 * texture is not available or the width &lt;= 0 or the height &lt;= 0
John Reck5ba09482015-05-18 15:13:30 -0700542 *
543 * @see #isAvailable()
544 * @see #getBitmap(android.graphics.Bitmap)
545 * @see #getBitmap(int, int)
Romain Guy77a81162011-06-14 16:45:55 -0700546 */
547 public Bitmap getBitmap() {
548 return getBitmap(getWidth(), getHeight());
549 }
550
551 /**
552 * <p>Returns a {@link android.graphics.Bitmap} representation of the content
553 * of the associated surface texture. If the surface texture is not available,
554 * this method returns null.</p>
John Reck5ba09482015-05-18 15:13:30 -0700555 *
Romain Guy77a81162011-06-14 16:45:55 -0700556 * <p>The bitmap returned by this method uses the {@link Bitmap.Config#ARGB_8888}
557 * pixel format.</p>
John Reck5ba09482015-05-18 15:13:30 -0700558 *
Romain Guy77a81162011-06-14 16:45:55 -0700559 * <p><strong>Do not</strong> invoke this method from a drawing method
560 * ({@link #onDraw(android.graphics.Canvas)} for instance).</p>
John Reck5ba09482015-05-18 15:13:30 -0700561 *
Romain Guyd6b2a002011-06-17 17:45:59 -0700562 * <p>If an error occurs during the copy, an empty bitmap will be returned.</p>
John Reck5ba09482015-05-18 15:13:30 -0700563 *
Romain Guy77a81162011-06-14 16:45:55 -0700564 * @param width The width of the bitmap to create
565 * @param height The height of the bitmap to create
John Reck5ba09482015-05-18 15:13:30 -0700566 *
Romain Guy77a81162011-06-14 16:45:55 -0700567 * @return A valid {@link Bitmap.Config#ARGB_8888} bitmap, or null if the surface
568 * texture is not available or width is &lt;= 0 or height is &lt;= 0
John Reck5ba09482015-05-18 15:13:30 -0700569 *
570 * @see #isAvailable()
571 * @see #getBitmap(android.graphics.Bitmap)
572 * @see #getBitmap()
Romain Guy77a81162011-06-14 16:45:55 -0700573 */
574 public Bitmap getBitmap(int width, int height) {
575 if (isAvailable() && width > 0 && height > 0) {
Dianne Hackborndde331c2012-08-03 14:01:57 -0700576 return getBitmap(Bitmap.createBitmap(getResources().getDisplayMetrics(),
577 width, height, Bitmap.Config.ARGB_8888));
Romain Guy77a81162011-06-14 16:45:55 -0700578 }
579 return null;
580 }
581
582 /**
583 * <p>Copies the content of this view's surface texture into the specified
584 * bitmap. If the surface texture is not available, the copy is not executed.
585 * The content of the surface texture will be scaled to fit exactly inside
586 * the specified bitmap.</p>
John Reck5ba09482015-05-18 15:13:30 -0700587 *
Romain Guy77a81162011-06-14 16:45:55 -0700588 * <p><strong>Do not</strong> invoke this method from a drawing method
589 * ({@link #onDraw(android.graphics.Canvas)} for instance).</p>
John Reck5ba09482015-05-18 15:13:30 -0700590 *
Romain Guyd6b2a002011-06-17 17:45:59 -0700591 * <p>If an error occurs, the bitmap is left unchanged.</p>
John Reck5ba09482015-05-18 15:13:30 -0700592 *
Romain Guy77a81162011-06-14 16:45:55 -0700593 * @param bitmap The bitmap to copy the content of the surface texture into,
594 * cannot be null, all configurations are supported
John Reck5ba09482015-05-18 15:13:30 -0700595 *
Romain Guy77a81162011-06-14 16:45:55 -0700596 * @return The bitmap specified as a parameter
John Reck5ba09482015-05-18 15:13:30 -0700597 *
598 * @see #isAvailable()
599 * @see #getBitmap(int, int)
600 * @see #getBitmap()
601 *
Romain Guy589b0bb2011-10-10 13:57:47 -0700602 * @throws IllegalStateException if the hardware rendering context cannot be
603 * acquired to capture the bitmap
Romain Guy77a81162011-06-14 16:45:55 -0700604 */
605 public Bitmap getBitmap(Bitmap bitmap) {
606 if (bitmap != null && isAvailable()) {
Romain Guy589b0bb2011-10-10 13:57:47 -0700607 applyUpdate();
608 applyTransformMatrix();
609
Romain Guy78245f72012-05-11 10:01:42 -0700610 // This case can happen if the app invokes setSurfaceTexture() before
611 // we are able to create the hardware layer. We can safely initialize
612 // the layer here thanks to the validate() call at the beginning of
613 // this method
614 if (mLayer == null && mUpdateSurface) {
John Reck9d8d99d2018-02-21 12:55:41 -0800615 getTextureLayer();
Romain Guy78245f72012-05-11 10:01:42 -0700616 }
617
618 if (mLayer != null) {
619 mLayer.copyInto(bitmap);
620 }
Romain Guy77a81162011-06-14 16:45:55 -0700621 }
622 return bitmap;
623 }
624
625 /**
626 * Returns true if the {@link SurfaceTexture} associated with this
627 * TextureView is available for rendering. When this method returns
628 * true, {@link #getSurfaceTexture()} returns a valid surface texture.
629 */
630 public boolean isAvailable() {
631 return mSurface != null;
632 }
633
634 /**
Romain Guy6be3d552011-07-14 18:08:37 -0700635 * <p>Start editing the pixels in the surface. The returned Canvas can be used
636 * to draw into the surface's bitmap. A null is returned if the surface has
637 * not been created or otherwise cannot be edited. You will usually need
638 * to implement
639 * {@link SurfaceTextureListener#onSurfaceTextureAvailable(android.graphics.SurfaceTexture, int, int)}
640 * to find out when the Surface is available for use.</p>
John Reck5ba09482015-05-18 15:13:30 -0700641 *
Romain Guy6be3d552011-07-14 18:08:37 -0700642 * <p>The content of the Surface is never preserved between unlockCanvas()
643 * and lockCanvas(), for this reason, every pixel within the Surface area
644 * must be written. The only exception to this rule is when a dirty
645 * rectangle is specified, in which case, non-dirty pixels will be
646 * preserved.</p>
John Reck5ba09482015-05-18 15:13:30 -0700647 *
Romain Guy462785f2011-09-27 17:42:10 -0700648 * <p>This method can only be used if the underlying surface is not already
649 * owned by another producer. For instance, if the TextureView is being used
650 * to render the camera's preview you cannot invoke this method.</p>
John Reck5ba09482015-05-18 15:13:30 -0700651 *
Romain Guy6be3d552011-07-14 18:08:37 -0700652 * @return A Canvas used to draw into the surface.
John Reck5ba09482015-05-18 15:13:30 -0700653 *
654 * @see #lockCanvas(android.graphics.Rect)
655 * @see #unlockCanvasAndPost(android.graphics.Canvas)
Romain Guy6be3d552011-07-14 18:08:37 -0700656 */
657 public Canvas lockCanvas() {
658 return lockCanvas(null);
659 }
660
661 /**
662 * Just like {@link #lockCanvas()} but allows specification of a dirty
663 * rectangle. Every pixel within that rectangle must be written; however
664 * pixels outside the dirty rectangle will be preserved by the next call
665 * to lockCanvas().
Romain Guy53bacf52013-04-30 11:30:10 -0700666 *
667 * This method can return null if the underlying surface texture is not
668 * available (see {@link #isAvailable()} or if the surface texture is
669 * already connected to an image producer (for instance: the camera,
670 * OpenGL, a media player, etc.)
John Reck5ba09482015-05-18 15:13:30 -0700671 *
Romain Guy6be3d552011-07-14 18:08:37 -0700672 * @param dirty Area of the surface that will be modified.
673
674 * @return A Canvas used to draw into the surface.
John Reck5ba09482015-05-18 15:13:30 -0700675 *
676 * @see #lockCanvas()
Romain Guy53bacf52013-04-30 11:30:10 -0700677 * @see #unlockCanvasAndPost(android.graphics.Canvas)
678 * @see #isAvailable()
Romain Guy6be3d552011-07-14 18:08:37 -0700679 */
680 public Canvas lockCanvas(Rect dirty) {
681 if (!isAvailable()) return null;
682
683 if (mCanvas == null) {
684 mCanvas = new Canvas();
685 }
686
687 synchronized (mNativeWindowLock) {
Romain Guy53bacf52013-04-30 11:30:10 -0700688 if (!nLockCanvas(mNativeWindow, mCanvas, dirty)) {
689 return null;
690 }
Romain Guy6be3d552011-07-14 18:08:37 -0700691 }
692 mSaveCount = mCanvas.save();
693
694 return mCanvas;
695 }
696
697 /**
698 * Finish editing pixels in the surface. After this call, the surface's
699 * current pixels will be shown on the screen, but its content is lost,
700 * in particular there is no guarantee that the content of the Surface
701 * will remain unchanged when lockCanvas() is called again.
John Reck5ba09482015-05-18 15:13:30 -0700702 *
Romain Guy6be3d552011-07-14 18:08:37 -0700703 * @param canvas The Canvas previously returned by lockCanvas()
John Reck5ba09482015-05-18 15:13:30 -0700704 *
Romain Guy6be3d552011-07-14 18:08:37 -0700705 * @see #lockCanvas()
John Reck5ba09482015-05-18 15:13:30 -0700706 * @see #lockCanvas(android.graphics.Rect)
Romain Guy6be3d552011-07-14 18:08:37 -0700707 */
708 public void unlockCanvasAndPost(Canvas canvas) {
709 if (mCanvas != null && canvas == mCanvas) {
710 canvas.restoreToCount(mSaveCount);
711 mSaveCount = 0;
712
713 synchronized (mNativeWindowLock) {
714 nUnlockCanvasAndPost(mNativeWindow, mCanvas);
715 }
716 }
717 }
718
719 /**
Romain Guyaa6c24c2011-04-28 18:40:04 -0700720 * Returns the {@link SurfaceTexture} used by this view. This method
Romain Guy77a81162011-06-14 16:45:55 -0700721 * may return null if the view is not attached to a window or if the surface
722 * texture has not been initialized yet.
John Reck5ba09482015-05-18 15:13:30 -0700723 *
724 * @see #isAvailable()
Romain Guyaa6c24c2011-04-28 18:40:04 -0700725 */
726 public SurfaceTexture getSurfaceTexture() {
727 return mSurface;
728 }
729
730 /**
Jamie Gennis2af35242012-04-05 11:44:30 -0700731 * Set the {@link SurfaceTexture} for this view to use. If a {@link
732 * SurfaceTexture} is already being used by this view, it is immediately
Mark Lue8691d12016-08-30 17:38:42 -0700733 * released and not usable any more. The {@link
Jamie Gennis2af35242012-04-05 11:44:30 -0700734 * SurfaceTextureListener#onSurfaceTextureDestroyed} callback is <b>not</b>
Jamie Gennis8a34d682012-04-17 16:01:34 -0700735 * called for the previous {@link SurfaceTexture}. Similarly, the {@link
736 * SurfaceTextureListener#onSurfaceTextureAvailable} callback is <b>not</b>
737 * called for the {@link SurfaceTexture} passed to setSurfaceTexture.
Jamie Gennis2af35242012-04-05 11:44:30 -0700738 *
739 * The {@link SurfaceTexture} object must be detached from all OpenGL ES
740 * contexts prior to calling this method.
741 *
742 * @param surfaceTexture The {@link SurfaceTexture} that the view should use.
743 * @see SurfaceTexture#detachFromGLContext()
Jamie Gennis2af35242012-04-05 11:44:30 -0700744 */
745 public void setSurfaceTexture(SurfaceTexture surfaceTexture) {
746 if (surfaceTexture == null) {
747 throw new NullPointerException("surfaceTexture must not be null");
748 }
John Reck6d8371e2015-05-14 15:47:03 -0700749 if (surfaceTexture == mSurface) {
750 throw new IllegalArgumentException("Trying to setSurfaceTexture to " +
751 "the same SurfaceTexture that's already set.");
752 }
753 if (surfaceTexture.isReleased()) {
754 throw new IllegalArgumentException("Cannot setSurfaceTexture to a " +
755 "released SurfaceTexture");
756 }
Jamie Gennis2af35242012-04-05 11:44:30 -0700757 if (mSurface != null) {
John Reck7e237182016-08-11 10:43:14 -0700758 nDestroyNativeWindow();
Jamie Gennis2af35242012-04-05 11:44:30 -0700759 mSurface.release();
760 }
761 mSurface = surfaceTexture;
John Reck7e237182016-08-11 10:43:14 -0700762 nCreateNativeWindow(mSurface);
Naveen Kallafd69e2a2015-03-17 15:20:53 -0700763
John Reck8bc511e2015-05-18 15:11:52 -0700764 /*
765 * If the view is visible and we already made a layer, update the
766 * listener in the new surface to use the existing listener in the view.
767 * Otherwise this will be called when the view becomes visible or the
768 * layer is created
769 */
770 if (((mViewFlags & VISIBILITY_MASK) == VISIBLE) && mLayer != null) {
Naveen Kallafd69e2a2015-03-17 15:20:53 -0700771 mSurface.setOnFrameAvailableListener(mUpdateListener, mAttachInfo.mHandler);
772 }
Jamie Gennis2af35242012-04-05 11:44:30 -0700773 mUpdateSurface = true;
774 invalidateParentIfNeeded();
775 }
776
777 /**
Romain Guyaa6c24c2011-04-28 18:40:04 -0700778 * Returns the {@link SurfaceTextureListener} currently associated with this
779 * texture view.
John Reck5ba09482015-05-18 15:13:30 -0700780 *
781 * @see #setSurfaceTextureListener(android.view.TextureView.SurfaceTextureListener)
Romain Guyaa6c24c2011-04-28 18:40:04 -0700782 * @see SurfaceTextureListener
783 */
784 public SurfaceTextureListener getSurfaceTextureListener() {
785 return mListener;
786 }
787
788 /**
789 * Sets the {@link SurfaceTextureListener} used to listen to surface
790 * texture events.
John Reck5ba09482015-05-18 15:13:30 -0700791 *
792 * @see #getSurfaceTextureListener()
Romain Guyaa6c24c2011-04-28 18:40:04 -0700793 * @see SurfaceTextureListener
794 */
795 public void setSurfaceTextureListener(SurfaceTextureListener listener) {
796 mListener = listener;
797 }
798
Mathew Inwooda570dee2018-08-17 14:56:00 +0100799 @UnsupportedAppUsage
Jeff Brownc7282e52014-05-06 16:00:38 -0700800 private final SurfaceTexture.OnFrameAvailableListener mUpdateListener =
801 new SurfaceTexture.OnFrameAvailableListener() {
802 @Override
803 public void onFrameAvailable(SurfaceTexture surfaceTexture) {
804 updateLayer();
805 invalidate();
806 }
807 };
808
Romain Guyaa6c24c2011-04-28 18:40:04 -0700809 /**
810 * This listener can be used to be notified when the surface texture
811 * associated with this texture view is available.
812 */
813 public static interface SurfaceTextureListener {
814 /**
815 * Invoked when a {@link TextureView}'s SurfaceTexture is ready for use.
John Reck5ba09482015-05-18 15:13:30 -0700816 *
Romain Guyaa6c24c2011-04-28 18:40:04 -0700817 * @param surface The surface returned by
818 * {@link android.view.TextureView#getSurfaceTexture()}
Romain Guy451ce442011-06-10 15:40:36 -0700819 * @param width The width of the surface
820 * @param height The height of the surface
Romain Guyaa6c24c2011-04-28 18:40:04 -0700821 */
Romain Guy451ce442011-06-10 15:40:36 -0700822 public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height);
Romain Guy8f0095c2011-05-02 17:24:22 -0700823
824 /**
825 * Invoked when the {@link SurfaceTexture}'s buffers size changed.
John Reck5ba09482015-05-18 15:13:30 -0700826 *
Romain Guy8f0095c2011-05-02 17:24:22 -0700827 * @param surface The surface returned by
828 * {@link android.view.TextureView#getSurfaceTexture()}
829 * @param width The new width of the surface
830 * @param height The new height of the surface
831 */
832 public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height);
Romain Guy451ce442011-06-10 15:40:36 -0700833
834 /**
835 * Invoked when the specified {@link SurfaceTexture} is about to be destroyed.
Grace Kloba402f0552011-08-09 18:47:17 -0700836 * If returns true, no rendering should happen inside the surface texture after this method
837 * is invoked. If returns false, the client needs to call {@link SurfaceTexture#release()}.
Romain Guy52b307e2012-10-07 17:55:17 -0700838 * Most applications should return true.
John Reck5ba09482015-05-18 15:13:30 -0700839 *
Romain Guy451ce442011-06-10 15:40:36 -0700840 * @param surface The surface about to be destroyed
841 */
Grace Kloba402f0552011-08-09 18:47:17 -0700842 public boolean onSurfaceTextureDestroyed(SurfaceTexture surface);
Grace Klobacf559372011-06-22 23:05:40 -0700843
844 /**
845 * Invoked when the specified {@link SurfaceTexture} is updated through
846 * {@link SurfaceTexture#updateTexImage()}.
John Reck5ba09482015-05-18 15:13:30 -0700847 *
Grace Klobacf559372011-06-22 23:05:40 -0700848 * @param surface The surface just updated
849 */
850 public void onSurfaceTextureUpdated(SurfaceTexture surface);
Romain Guyaa6c24c2011-04-28 18:40:04 -0700851 }
Romain Guy8f0095c2011-05-02 17:24:22 -0700852
Mathew Inwooda570dee2018-08-17 14:56:00 +0100853 @UnsupportedAppUsage
Romain Guy6be3d552011-07-14 18:08:37 -0700854 private native void nCreateNativeWindow(SurfaceTexture surface);
Mathew Inwooda570dee2018-08-17 14:56:00 +0100855 @UnsupportedAppUsage
Romain Guy6be3d552011-07-14 18:08:37 -0700856 private native void nDestroyNativeWindow();
857
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000858 private static native boolean nLockCanvas(long nativeWindow, Canvas canvas, Rect dirty);
859 private static native void nUnlockCanvasAndPost(long nativeWindow, Canvas canvas);
Romain Guyaa6c24c2011-04-28 18:40:04 -0700860}