Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package android.view; |
| 18 | |
John Reck | 582f6bd | 2019-10-30 10:04:37 -0700 | [diff] [blame] | 19 | import android.annotation.NonNull; |
sergeyv | 342a7e6 | 2016-03-24 16:06:46 -0700 | [diff] [blame] | 20 | import android.annotation.Nullable; |
Artur Satayev | ad9254c | 2019-12-10 17:47:54 +0000 | [diff] [blame] | 21 | import android.compat.annotation.UnsupportedAppUsage; |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 22 | import android.content.Context; |
Romain Guy | 77a8116 | 2011-06-14 16:45:55 -0700 | [diff] [blame] | 23 | import android.graphics.Bitmap; |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 24 | import android.graphics.Canvas; |
Romain Guy | 302a9df | 2011-08-16 13:55:02 -0700 | [diff] [blame] | 25 | import android.graphics.Matrix; |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 26 | import android.graphics.Paint; |
John Reck | 32f140aa6 | 2018-10-04 15:08:24 -0700 | [diff] [blame] | 27 | import android.graphics.RecordingCanvas; |
Romain Guy | 6be3d55 | 2011-07-14 18:08:37 -0700 | [diff] [blame] | 28 | import android.graphics.Rect; |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 29 | import android.graphics.SurfaceTexture; |
Chris Craik | 2e931ea | 2015-08-19 16:13:04 -0700 | [diff] [blame] | 30 | import android.graphics.drawable.Drawable; |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 31 | import android.util.AttributeSet; |
| 32 | import android.util.Log; |
| 33 | |
| 34 | /** |
| 35 | * <p>A TextureView can be used to display a content stream. Such a content |
| 36 | * stream can for instance be a video or an OpenGL scene. The content stream |
| 37 | * can come from the application's process as well as a remote process.</p> |
John Reck | 5ba0948 | 2015-05-18 15:13:30 -0700 | [diff] [blame] | 38 | * |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 39 | * <p>TextureView can only be used in a hardware accelerated window. When |
| 40 | * rendered in software, TextureView will draw nothing.</p> |
John Reck | 5ba0948 | 2015-05-18 15:13:30 -0700 | [diff] [blame] | 41 | * |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 42 | * <p>Unlike {@link SurfaceView}, TextureView does not create a separate |
| 43 | * window but behaves as a regular View. This key difference allows a |
| 44 | * TextureView to be moved, transformed, animated, etc. For instance, you |
| 45 | * can make a TextureView semi-translucent by calling |
| 46 | * <code>myView.setAlpha(0.5f)</code>.</p> |
John Reck | 5ba0948 | 2015-05-18 15:13:30 -0700 | [diff] [blame] | 47 | * |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 48 | * <p>Using a TextureView is simple: all you need to do is get its |
| 49 | * {@link SurfaceTexture}. The {@link SurfaceTexture} can then be used to |
John Reck | 5ba0948 | 2015-05-18 15:13:30 -0700 | [diff] [blame] | 50 | * render content. The following example demonstrates how to render the |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 51 | * camera preview into a TextureView:</p> |
John Reck | 5ba0948 | 2015-05-18 15:13:30 -0700 | [diff] [blame] | 52 | * |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 53 | * <pre> |
| 54 | * public class LiveCameraActivity extends Activity implements TextureView.SurfaceTextureListener { |
| 55 | * private Camera mCamera; |
| 56 | * private TextureView mTextureView; |
| 57 | * |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 58 | * protected void onCreate(Bundle savedInstanceState) { |
| 59 | * super.onCreate(savedInstanceState); |
| 60 | * |
| 61 | * mTextureView = new TextureView(this); |
| 62 | * mTextureView.setSurfaceTextureListener(this); |
| 63 | * |
| 64 | * setContentView(mTextureView); |
| 65 | * } |
| 66 | * |
Romain Guy | 451ce44 | 2011-06-10 15:40:36 -0700 | [diff] [blame] | 67 | * public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) { |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 68 | * mCamera = Camera.open(); |
| 69 | * |
| 70 | * try { |
| 71 | * mCamera.setPreviewTexture(surface); |
| 72 | * mCamera.startPreview(); |
| 73 | * } catch (IOException ioe) { |
| 74 | * // Something bad happened |
| 75 | * } |
| 76 | * } |
Grace Kloba | cf55937 | 2011-06-22 23:05:40 -0700 | [diff] [blame] | 77 | * |
Romain Guy | 8f0095c | 2011-05-02 17:24:22 -0700 | [diff] [blame] | 78 | * public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) { |
| 79 | * // Ignored, Camera does all the work for us |
| 80 | * } |
Grace Kloba | cf55937 | 2011-06-22 23:05:40 -0700 | [diff] [blame] | 81 | * |
Grace Kloba | 402f055 | 2011-08-09 18:47:17 -0700 | [diff] [blame] | 82 | * public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) { |
Romain Guy | 451ce44 | 2011-06-10 15:40:36 -0700 | [diff] [blame] | 83 | * mCamera.stopPreview(); |
| 84 | * mCamera.release(); |
Grace Kloba | 402f055 | 2011-08-09 18:47:17 -0700 | [diff] [blame] | 85 | * return true; |
Romain Guy | 451ce44 | 2011-06-10 15:40:36 -0700 | [diff] [blame] | 86 | * } |
Grace Kloba | cf55937 | 2011-06-22 23:05:40 -0700 | [diff] [blame] | 87 | * |
| 88 | * public void onSurfaceTextureUpdated(SurfaceTexture surface) { |
Romain Guy | 58f4edb | 2011-06-24 14:51:38 -0700 | [diff] [blame] | 89 | * // Invoked every time there's a new Camera preview frame |
Grace Kloba | cf55937 | 2011-06-22 23:05:40 -0700 | [diff] [blame] | 90 | * } |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 91 | * } |
| 92 | * </pre> |
John Reck | 5ba0948 | 2015-05-18 15:13:30 -0700 | [diff] [blame] | 93 | * |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 94 | * <p>A TextureView's SurfaceTexture can be obtained either by invoking |
| 95 | * {@link #getSurfaceTexture()} or by using a {@link SurfaceTextureListener}. |
| 96 | * It is important to know that a SurfaceTexture is available only after the |
| 97 | * TextureView is attached to a window (and {@link #onAttachedToWindow()} has |
| 98 | * been invoked.) It is therefore highly recommended you use a listener to |
| 99 | * be notified when the SurfaceTexture becomes available.</p> |
John Reck | 5ba0948 | 2015-05-18 15:13:30 -0700 | [diff] [blame] | 100 | * |
Romain Guy | 462785f | 2011-09-27 17:42:10 -0700 | [diff] [blame] | 101 | * <p>It is important to note that only one producer can use the TextureView. |
| 102 | * For instance, if you use a TextureView to display the camera preview, you |
| 103 | * cannot use {@link #lockCanvas()} to draw onto the TextureView at the same |
| 104 | * time.</p> |
John Reck | 5ba0948 | 2015-05-18 15:13:30 -0700 | [diff] [blame] | 105 | * |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 106 | * @see SurfaceView |
| 107 | * @see SurfaceTexture |
| 108 | */ |
| 109 | public class TextureView extends View { |
Romain Guy | 77a8116 | 2011-06-14 16:45:55 -0700 | [diff] [blame] | 110 | private static final String LOG_TAG = "TextureView"; |
| 111 | |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 112 | @UnsupportedAppUsage |
John Reck | 9d8d99d | 2018-02-21 12:55:41 -0800 | [diff] [blame] | 113 | private TextureLayer mLayer; |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 114 | @UnsupportedAppUsage |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 115 | private SurfaceTexture mSurface; |
| 116 | private SurfaceTextureListener mListener; |
Romain Guy | 67603c6 | 2013-06-27 10:58:10 -0700 | [diff] [blame] | 117 | private boolean mHadSurface; |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 118 | |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 119 | @UnsupportedAppUsage |
Romain Guy | a948927 | 2011-06-22 20:58:11 -0700 | [diff] [blame] | 120 | private boolean mOpaque = true; |
Romain Guy | c989d86 | 2011-06-22 14:53:39 -0700 | [diff] [blame] | 121 | |
Romain Guy | 302a9df | 2011-08-16 13:55:02 -0700 | [diff] [blame] | 122 | private final Matrix mMatrix = new Matrix(); |
| 123 | private boolean mMatrixChanged; |
| 124 | |
Romain Guy | 58f4edb | 2011-06-24 14:51:38 -0700 | [diff] [blame] | 125 | private final Object[] mLock = new Object[0]; |
| 126 | private boolean mUpdateLayer; |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 127 | @UnsupportedAppUsage |
Jamie Gennis | 2af3524 | 2012-04-05 11:44:30 -0700 | [diff] [blame] | 128 | private boolean mUpdateSurface; |
Romain Guy | 58f4edb | 2011-06-24 14:51:38 -0700 | [diff] [blame] | 129 | |
Romain Guy | 6be3d55 | 2011-07-14 18:08:37 -0700 | [diff] [blame] | 130 | private Canvas mCanvas; |
| 131 | private int mSaveCount; |
| 132 | |
| 133 | private final Object[] mNativeWindowLock = new Object[0]; |
John Reck | 918ad52 | 2014-06-27 14:45:25 -0700 | [diff] [blame] | 134 | // Set by native code, do not write! |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 135 | @UnsupportedAppUsage |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 136 | private long mNativeWindow; |
Romain Guy | 6be3d55 | 2011-07-14 18:08:37 -0700 | [diff] [blame] | 137 | |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 138 | /** |
| 139 | * Creates a new TextureView. |
John Reck | 5ba0948 | 2015-05-18 15:13:30 -0700 | [diff] [blame] | 140 | * |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 141 | * @param context The context to associate this view with. |
| 142 | */ |
John Reck | 582f6bd | 2019-10-30 10:04:37 -0700 | [diff] [blame] | 143 | public TextureView(@NonNull Context context) { |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 144 | super(context); |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | /** |
| 148 | * Creates a new TextureView. |
John Reck | 5ba0948 | 2015-05-18 15:13:30 -0700 | [diff] [blame] | 149 | * |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 150 | * @param context The context to associate this view with. |
| 151 | * @param attrs The attributes of the XML tag that is inflating the view. |
| 152 | */ |
John Reck | 582f6bd | 2019-10-30 10:04:37 -0700 | [diff] [blame] | 153 | public TextureView(@NonNull Context context, @Nullable AttributeSet attrs) { |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 154 | super(context, attrs); |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | /** |
| 158 | * Creates a new TextureView. |
John Reck | 5ba0948 | 2015-05-18 15:13:30 -0700 | [diff] [blame] | 159 | * |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 160 | * @param context The context to associate this view with. |
| 161 | * @param attrs The attributes of the XML tag that is inflating the view. |
Alan Viverette | 617feb9 | 2013-09-09 18:09:13 -0700 | [diff] [blame] | 162 | * @param defStyleAttr An attribute in the current theme that contains a |
| 163 | * reference to a style resource that supplies default values for |
| 164 | * the view. Can be 0 to not look for defaults. |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 165 | */ |
John Reck | 582f6bd | 2019-10-30 10:04:37 -0700 | [diff] [blame] | 166 | public TextureView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { |
Alan Viverette | 617feb9 | 2013-09-09 18:09:13 -0700 | [diff] [blame] | 167 | super(context, attrs, defStyleAttr); |
Alan Viverette | 617feb9 | 2013-09-09 18:09:13 -0700 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | /** |
| 171 | * Creates a new TextureView. |
| 172 | * |
| 173 | * @param context The context to associate this view with. |
| 174 | * @param attrs The attributes of the XML tag that is inflating the view. |
| 175 | * @param defStyleAttr An attribute in the current theme that contains a |
| 176 | * reference to a style resource that supplies default values for |
| 177 | * the view. Can be 0 to not look for defaults. |
| 178 | * @param defStyleRes A resource identifier of a style resource that |
| 179 | * supplies default values for the view, used only if |
| 180 | * defStyleAttr is 0 or can not be found in the theme. Can be 0 |
| 181 | * to not look for defaults. |
| 182 | */ |
John Reck | 582f6bd | 2019-10-30 10:04:37 -0700 | [diff] [blame] | 183 | public TextureView(@NonNull Context context, @Nullable AttributeSet attrs, |
| 184 | int defStyleAttr, int defStyleRes) { |
Alan Viverette | 617feb9 | 2013-09-09 18:09:13 -0700 | [diff] [blame] | 185 | super(context, attrs, defStyleAttr, defStyleRes); |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 186 | } |
| 187 | |
Romain Guy | a948927 | 2011-06-22 20:58:11 -0700 | [diff] [blame] | 188 | /** |
| 189 | * {@inheritDoc} |
| 190 | */ |
| 191 | @Override |
| 192 | public boolean isOpaque() { |
| 193 | return mOpaque; |
| 194 | } |
| 195 | |
| 196 | /** |
| 197 | * Indicates whether the content of this TextureView is opaque. The |
| 198 | * content is assumed to be opaque by default. |
John Reck | 5ba0948 | 2015-05-18 15:13:30 -0700 | [diff] [blame] | 199 | * |
Romain Guy | a948927 | 2011-06-22 20:58:11 -0700 | [diff] [blame] | 200 | * @param opaque True if the content of this TextureView is opaque, |
| 201 | * false otherwise |
| 202 | */ |
| 203 | public void setOpaque(boolean opaque) { |
| 204 | if (opaque != mOpaque) { |
| 205 | mOpaque = opaque; |
Romain Guy | a8a2f97 | 2012-04-12 16:33:44 -0700 | [diff] [blame] | 206 | if (mLayer != null) { |
Romain Guy | 88801b2 | 2012-10-05 14:58:33 -0700 | [diff] [blame] | 207 | updateLayerAndInvalidate(); |
Romain Guy | a8a2f97 | 2012-04-12 16:33:44 -0700 | [diff] [blame] | 208 | } |
Romain Guy | a948927 | 2011-06-22 20:58:11 -0700 | [diff] [blame] | 209 | } |
| 210 | } |
| 211 | |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 212 | @Override |
| 213 | protected void onAttachedToWindow() { |
| 214 | super.onAttachedToWindow(); |
| 215 | |
| 216 | if (!isHardwareAccelerated()) { |
Romain Guy | 77a8116 | 2011-06-14 16:45:55 -0700 | [diff] [blame] | 217 | Log.w(LOG_TAG, "A TextureView or a subclass can only be " |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 218 | + "used with hardware acceleration enabled."); |
| 219 | } |
Romain Guy | 67603c6 | 2013-06-27 10:58:10 -0700 | [diff] [blame] | 220 | |
| 221 | if (mHadSurface) { |
| 222 | invalidate(true); |
| 223 | mHadSurface = false; |
| 224 | } |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 225 | } |
| 226 | |
John Reck | b14dfe2 | 2014-03-06 22:06:20 +0000 | [diff] [blame] | 227 | /** @hide */ |
Romain Guy | 451ce44 | 2011-06-10 15:40:36 -0700 | [diff] [blame] | 228 | @Override |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 229 | @UnsupportedAppUsage |
John Reck | b14dfe2 | 2014-03-06 22:06:20 +0000 | [diff] [blame] | 230 | protected void onDetachedFromWindowInternal() { |
sergeyv | 1c16c37 | 2016-08-02 14:46:12 -0700 | [diff] [blame] | 231 | destroyHardwareLayer(); |
| 232 | releaseSurfaceTexture(); |
John Reck | b14dfe2 | 2014-03-06 22:06:20 +0000 | [diff] [blame] | 233 | super.onDetachedFromWindowInternal(); |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 234 | } |
Romain Guy | 451ce44 | 2011-06-10 15:40:36 -0700 | [diff] [blame] | 235 | |
sergeyv | 1c16c37 | 2016-08-02 14:46:12 -0700 | [diff] [blame] | 236 | /** |
| 237 | * @hide |
| 238 | */ |
| 239 | @Override |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 240 | @UnsupportedAppUsage |
sergeyv | 1c16c37 | 2016-08-02 14:46:12 -0700 | [diff] [blame] | 241 | protected void destroyHardwareResources() { |
sergeyv | 17dd01b | 2016-08-30 14:03:32 -0700 | [diff] [blame] | 242 | super.destroyHardwareResources(); |
sergeyv | 1c16c37 | 2016-08-02 14:46:12 -0700 | [diff] [blame] | 243 | destroyHardwareLayer(); |
sergeyv | 1c16c37 | 2016-08-02 14:46:12 -0700 | [diff] [blame] | 244 | } |
| 245 | |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 246 | @UnsupportedAppUsage |
sergeyv | 1c16c37 | 2016-08-02 14:46:12 -0700 | [diff] [blame] | 247 | private void destroyHardwareLayer() { |
Romain Guy | 80429c4 | 2011-06-24 17:20:32 -0700 | [diff] [blame] | 248 | if (mLayer != null) { |
John Reck | 918ad52 | 2014-06-27 14:45:25 -0700 | [diff] [blame] | 249 | mLayer.detachSurfaceTexture(); |
Romain Guy | 6be3d55 | 2011-07-14 18:08:37 -0700 | [diff] [blame] | 250 | mLayer.destroy(); |
Romain Guy | 451ce44 | 2011-06-10 15:40:36 -0700 | [diff] [blame] | 251 | mLayer = null; |
Doris Liu | 6b47199 | 2015-04-30 17:00:35 -0700 | [diff] [blame] | 252 | mMatrixChanged = true; |
Romain Guy | 451ce44 | 2011-06-10 15:40:36 -0700 | [diff] [blame] | 253 | } |
| 254 | } |
| 255 | |
sergeyv | 1c16c37 | 2016-08-02 14:46:12 -0700 | [diff] [blame] | 256 | private void releaseSurfaceTexture() { |
John Reck | 3c2587f | 2016-08-04 07:55:38 -0700 | [diff] [blame] | 257 | if (mSurface != null) { |
| 258 | boolean shouldRelease = true; |
sergeyv | 1c16c37 | 2016-08-02 14:46:12 -0700 | [diff] [blame] | 259 | |
John Reck | 3c2587f | 2016-08-04 07:55:38 -0700 | [diff] [blame] | 260 | if (mListener != null) { |
| 261 | shouldRelease = mListener.onSurfaceTextureDestroyed(mSurface); |
| 262 | } |
sergeyv | 1c16c37 | 2016-08-02 14:46:12 -0700 | [diff] [blame] | 263 | |
John Reck | 3c2587f | 2016-08-04 07:55:38 -0700 | [diff] [blame] | 264 | synchronized (mNativeWindowLock) { |
| 265 | nDestroyNativeWindow(); |
| 266 | } |
sergeyv | 1c16c37 | 2016-08-02 14:46:12 -0700 | [diff] [blame] | 267 | |
John Reck | 3c2587f | 2016-08-04 07:55:38 -0700 | [diff] [blame] | 268 | if (shouldRelease) { |
| 269 | mSurface.release(); |
| 270 | } |
| 271 | mSurface = null; |
| 272 | mHadSurface = true; |
sergeyv | 1c16c37 | 2016-08-02 14:46:12 -0700 | [diff] [blame] | 273 | } |
sergeyv | 1c16c37 | 2016-08-02 14:46:12 -0700 | [diff] [blame] | 274 | } |
| 275 | |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 276 | /** |
| 277 | * The layer type of a TextureView is ignored since a TextureView is always |
| 278 | * considered to act as a hardware layer. The optional paint supplied to this |
| 279 | * method will however be taken into account when rendering the content of |
| 280 | * this TextureView. |
John Reck | 5ba0948 | 2015-05-18 15:13:30 -0700 | [diff] [blame] | 281 | * |
sergeyv | 342a7e6 | 2016-03-24 16:06:46 -0700 | [diff] [blame] | 282 | * @param layerType The type of layer to use with this view, must be one of |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 283 | * {@link #LAYER_TYPE_NONE}, {@link #LAYER_TYPE_SOFTWARE} or |
| 284 | * {@link #LAYER_TYPE_HARDWARE} |
| 285 | * @param paint The paint used to compose the layer. This argument is optional |
| 286 | * and can be null. It is ignored when the layer type is |
| 287 | * {@link #LAYER_TYPE_NONE} |
| 288 | */ |
| 289 | @Override |
sergeyv | 342a7e6 | 2016-03-24 16:06:46 -0700 | [diff] [blame] | 290 | public void setLayerType(int layerType, @Nullable Paint paint) { |
| 291 | setLayerPaint(paint); |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 292 | } |
| 293 | |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 294 | @Override |
sergeyv | 342a7e6 | 2016-03-24 16:06:46 -0700 | [diff] [blame] | 295 | public void setLayerPaint(@Nullable Paint paint) { |
| 296 | if (paint != mLayerPaint) { |
| 297 | mLayerPaint = paint; |
| 298 | invalidate(); |
| 299 | } |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 300 | } |
| 301 | |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 302 | /** |
| 303 | * Always returns {@link #LAYER_TYPE_HARDWARE}. |
| 304 | */ |
| 305 | @Override |
| 306 | public int getLayerType() { |
| 307 | return LAYER_TYPE_HARDWARE; |
| 308 | } |
| 309 | |
| 310 | /** |
| 311 | * Calling this method has no effect. |
| 312 | */ |
| 313 | @Override |
| 314 | public void buildLayer() { |
| 315 | } |
| 316 | |
Chris Craik | 2e931ea | 2015-08-19 16:13:04 -0700 | [diff] [blame] | 317 | @Override |
| 318 | public void setForeground(Drawable foreground) { |
Chris Craik | b724480 | 2016-01-04 15:47:19 -0800 | [diff] [blame] | 319 | if (foreground != null && !sTextureViewIgnoresDrawableSetters) { |
Chris Craik | 2e931ea | 2015-08-19 16:13:04 -0700 | [diff] [blame] | 320 | throw new UnsupportedOperationException( |
| 321 | "TextureView doesn't support displaying a foreground drawable"); |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | @Override |
| 326 | public void setBackgroundDrawable(Drawable background) { |
Chris Craik | b724480 | 2016-01-04 15:47:19 -0800 | [diff] [blame] | 327 | if (background != null && !sTextureViewIgnoresDrawableSetters) { |
Chris Craik | 2e931ea | 2015-08-19 16:13:04 -0700 | [diff] [blame] | 328 | throw new UnsupportedOperationException( |
| 329 | "TextureView doesn't support displaying a background drawable"); |
| 330 | } |
| 331 | } |
| 332 | |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 333 | /** |
| 334 | * Subclasses of TextureView cannot do their own rendering |
| 335 | * with the {@link Canvas} object. |
John Reck | 5ba0948 | 2015-05-18 15:13:30 -0700 | [diff] [blame] | 336 | * |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 337 | * @param canvas The Canvas to which the View is rendered. |
| 338 | */ |
| 339 | @Override |
| 340 | public final void draw(Canvas canvas) { |
Chris Craik | 3aadd60 | 2015-08-20 12:41:40 -0700 | [diff] [blame] | 341 | // NOTE: Maintain this carefully (see View#draw) |
Romain Guy | 52b307e | 2012-10-07 17:55:17 -0700 | [diff] [blame] | 342 | mPrivateFlags = (mPrivateFlags & ~PFLAG_DIRTY_MASK) | PFLAG_DRAWN; |
| 343 | |
Chris Craik | 3aadd60 | 2015-08-20 12:41:40 -0700 | [diff] [blame] | 344 | /* Simplify drawing to guarantee the layer is the only thing drawn - so e.g. no background, |
| 345 | scrolling, or fading edges. This guarantees all drawing is in the layer, so drawing |
| 346 | properties (alpha, layer paint) affect all of the content of a TextureView. */ |
| 347 | |
| 348 | if (canvas.isHardwareAccelerated()) { |
John Reck | 32f140aa6 | 2018-10-04 15:08:24 -0700 | [diff] [blame] | 349 | RecordingCanvas recordingCanvas = (RecordingCanvas) canvas; |
Chris Craik | 3aadd60 | 2015-08-20 12:41:40 -0700 | [diff] [blame] | 350 | |
John Reck | 9d8d99d | 2018-02-21 12:55:41 -0800 | [diff] [blame] | 351 | TextureLayer layer = getTextureLayer(); |
Chris Craik | 3aadd60 | 2015-08-20 12:41:40 -0700 | [diff] [blame] | 352 | if (layer != null) { |
| 353 | applyUpdate(); |
| 354 | applyTransformMatrix(); |
| 355 | |
| 356 | mLayer.setLayerPaint(mLayerPaint); // ensure layer paint is up to date |
John Reck | 32f140aa6 | 2018-10-04 15:08:24 -0700 | [diff] [blame] | 357 | recordingCanvas.drawTextureLayer(layer); |
Chris Craik | 3aadd60 | 2015-08-20 12:41:40 -0700 | [diff] [blame] | 358 | } |
| 359 | } |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | /** |
| 363 | * Subclasses of TextureView cannot do their own rendering |
| 364 | * with the {@link Canvas} object. |
John Reck | 5ba0948 | 2015-05-18 15:13:30 -0700 | [diff] [blame] | 365 | * |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 366 | * @param canvas The Canvas to which the View is rendered. |
| 367 | */ |
| 368 | @Override |
| 369 | protected final void onDraw(Canvas canvas) { |
| 370 | } |
| 371 | |
| 372 | @Override |
Romain Guy | 8f0095c | 2011-05-02 17:24:22 -0700 | [diff] [blame] | 373 | protected void onSizeChanged(int w, int h, int oldw, int oldh) { |
| 374 | super.onSizeChanged(w, h, oldw, oldh); |
| 375 | if (mSurface != null) { |
Mathias Agopian | 52a9a10 | 2013-08-02 01:38:38 -0700 | [diff] [blame] | 376 | mSurface.setDefaultBufferSize(getWidth(), getHeight()); |
Romain Guy | 88801b2 | 2012-10-05 14:58:33 -0700 | [diff] [blame] | 377 | updateLayer(); |
Romain Guy | 451ce44 | 2011-06-10 15:40:36 -0700 | [diff] [blame] | 378 | if (mListener != null) { |
| 379 | mListener.onSurfaceTextureSizeChanged(mSurface, getWidth(), getHeight()); |
| 380 | } |
Romain Guy | 8f0095c | 2011-05-02 17:24:22 -0700 | [diff] [blame] | 381 | } |
| 382 | } |
| 383 | |
John Reck | 9d8d99d | 2018-02-21 12:55:41 -0800 | [diff] [blame] | 384 | TextureLayer getTextureLayer() { |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 385 | if (mLayer == null) { |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 386 | if (mAttachInfo == null || mAttachInfo.mThreadedRenderer == null) { |
Romain Guy | 58f4edb | 2011-06-24 14:51:38 -0700 | [diff] [blame] | 387 | return null; |
| 388 | } |
| 389 | |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 390 | mLayer = mAttachInfo.mThreadedRenderer.createTextureLayer(); |
John Reck | 7e23718 | 2016-08-11 10:43:14 -0700 | [diff] [blame] | 391 | boolean createNewSurface = (mSurface == null); |
| 392 | if (createNewSurface) { |
Jamie Gennis | 8a34d68 | 2012-04-17 16:01:34 -0700 | [diff] [blame] | 393 | // Create a new SurfaceTexture for the layer. |
John Reck | 918ad52 | 2014-06-27 14:45:25 -0700 | [diff] [blame] | 394 | mSurface = new SurfaceTexture(false); |
sergeyv | 1c16c37 | 2016-08-02 14:46:12 -0700 | [diff] [blame] | 395 | nCreateNativeWindow(mSurface); |
Jamie Gennis | 2af3524 | 2012-04-05 11:44:30 -0700 | [diff] [blame] | 396 | } |
John Reck | 03df083 | 2016-08-16 09:44:23 -0700 | [diff] [blame] | 397 | mLayer.setSurfaceTexture(mSurface); |
Mathias Agopian | 52a9a10 | 2013-08-02 01:38:38 -0700 | [diff] [blame] | 398 | mSurface.setDefaultBufferSize(getWidth(), getHeight()); |
Jeff Brown | c7282e5 | 2014-05-06 16:00:38 -0700 | [diff] [blame] | 399 | mSurface.setOnFrameAvailableListener(mUpdateListener, mAttachInfo.mHandler); |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 400 | |
John Reck | 7e23718 | 2016-08-11 10:43:14 -0700 | [diff] [blame] | 401 | if (mListener != null && createNewSurface) { |
Romain Guy | 451ce44 | 2011-06-10 15:40:36 -0700 | [diff] [blame] | 402 | mListener.onSurfaceTextureAvailable(mSurface, getWidth(), getHeight()); |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 403 | } |
Chet Haase | d15ebf2 | 2012-09-05 11:40:29 -0700 | [diff] [blame] | 404 | mLayer.setLayerPaint(mLayerPaint); |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 405 | } |
| 406 | |
Jamie Gennis | 2af3524 | 2012-04-05 11:44:30 -0700 | [diff] [blame] | 407 | if (mUpdateSurface) { |
| 408 | // Someone has requested that we use a specific SurfaceTexture, so |
| 409 | // tell mLayer about it and set the SurfaceTexture to use the |
| 410 | // current view size. |
| 411 | mUpdateSurface = false; |
Romain Guy | 51f7c6b | 2012-05-21 16:32:59 -0700 | [diff] [blame] | 412 | |
| 413 | // Since we are updating the layer, force an update to ensure its |
| 414 | // parameters are correct (width, height, transform, etc.) |
Romain Guy | 88801b2 | 2012-10-05 14:58:33 -0700 | [diff] [blame] | 415 | updateLayer(); |
Romain Guy | 51f7c6b | 2012-05-21 16:32:59 -0700 | [diff] [blame] | 416 | mMatrixChanged = true; |
| 417 | |
John Reck | 04fc583 | 2014-02-05 16:38:25 -0800 | [diff] [blame] | 418 | mLayer.setSurfaceTexture(mSurface); |
Mathias Agopian | 52a9a10 | 2013-08-02 01:38:38 -0700 | [diff] [blame] | 419 | mSurface.setDefaultBufferSize(getWidth(), getHeight()); |
Jamie Gennis | 2af3524 | 2012-04-05 11:44:30 -0700 | [diff] [blame] | 420 | } |
| 421 | |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 422 | return mLayer; |
| 423 | } |
| 424 | |
Romain Guy | 8f0095c | 2011-05-02 17:24:22 -0700 | [diff] [blame] | 425 | @Override |
| 426 | protected void onVisibilityChanged(View changedView, int visibility) { |
| 427 | super.onVisibilityChanged(changedView, visibility); |
| 428 | |
| 429 | if (mSurface != null) { |
| 430 | // When the view becomes invisible, stop updating it, it's a waste of CPU |
| 431 | // To cancel updates, the easiest thing to do is simply to remove the |
| 432 | // updates listener |
| 433 | if (visibility == VISIBLE) { |
John Reck | 2dedafb | 2014-05-29 16:15:41 -0700 | [diff] [blame] | 434 | if (mLayer != null) { |
| 435 | mSurface.setOnFrameAvailableListener(mUpdateListener, mAttachInfo.mHandler); |
| 436 | } |
Romain Guy | 88801b2 | 2012-10-05 14:58:33 -0700 | [diff] [blame] | 437 | updateLayerAndInvalidate(); |
Romain Guy | 8f0095c | 2011-05-02 17:24:22 -0700 | [diff] [blame] | 438 | } else { |
| 439 | mSurface.setOnFrameAvailableListener(null); |
| 440 | } |
| 441 | } |
| 442 | } |
| 443 | |
Romain Guy | a948927 | 2011-06-22 20:58:11 -0700 | [diff] [blame] | 444 | private void updateLayer() { |
Romain Guy | 88801b2 | 2012-10-05 14:58:33 -0700 | [diff] [blame] | 445 | synchronized (mLock) { |
| 446 | mUpdateLayer = true; |
| 447 | } |
| 448 | } |
| 449 | |
| 450 | private void updateLayerAndInvalidate() { |
| 451 | synchronized (mLock) { |
| 452 | mUpdateLayer = true; |
| 453 | } |
Romain Guy | 58f4edb | 2011-06-24 14:51:38 -0700 | [diff] [blame] | 454 | invalidate(); |
| 455 | } |
Jamie Gennis | 2af3524 | 2012-04-05 11:44:30 -0700 | [diff] [blame] | 456 | |
Romain Guy | 58f4edb | 2011-06-24 14:51:38 -0700 | [diff] [blame] | 457 | private void applyUpdate() { |
| 458 | if (mLayer == null) { |
Romain Guy | a948927 | 2011-06-22 20:58:11 -0700 | [diff] [blame] | 459 | return; |
| 460 | } |
| 461 | |
Romain Guy | 58f4edb | 2011-06-24 14:51:38 -0700 | [diff] [blame] | 462 | synchronized (mLock) { |
| 463 | if (mUpdateLayer) { |
| 464 | mUpdateLayer = false; |
| 465 | } else { |
| 466 | return; |
| 467 | } |
| 468 | } |
John Reck | 5ba0948 | 2015-05-18 15:13:30 -0700 | [diff] [blame] | 469 | |
John Reck | 04fc583 | 2014-02-05 16:38:25 -0800 | [diff] [blame] | 470 | mLayer.prepare(getWidth(), getHeight(), mOpaque); |
| 471 | mLayer.updateSurfaceTexture(); |
Romain Guy | a948927 | 2011-06-22 20:58:11 -0700 | [diff] [blame] | 472 | |
Grace Kloba | cf55937 | 2011-06-22 23:05:40 -0700 | [diff] [blame] | 473 | if (mListener != null) { |
| 474 | mListener.onSurfaceTextureUpdated(mSurface); |
| 475 | } |
Romain Guy | a948927 | 2011-06-22 20:58:11 -0700 | [diff] [blame] | 476 | } |
| 477 | |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 478 | /** |
Romain Guy | 302a9df | 2011-08-16 13:55:02 -0700 | [diff] [blame] | 479 | * <p>Sets the transform to associate with this texture view. |
| 480 | * The specified transform applies to the underlying surface |
| 481 | * texture and does not affect the size or position of the view |
| 482 | * itself, only of its content.</p> |
John Reck | 5ba0948 | 2015-05-18 15:13:30 -0700 | [diff] [blame] | 483 | * |
Romain Guy | 302a9df | 2011-08-16 13:55:02 -0700 | [diff] [blame] | 484 | * <p>Some transforms might prevent the content from drawing |
| 485 | * all the pixels contained within this view's bounds. In such |
| 486 | * situations, make sure this texture view is not marked opaque.</p> |
John Reck | 5ba0948 | 2015-05-18 15:13:30 -0700 | [diff] [blame] | 487 | * |
Romain Guy | 302a9df | 2011-08-16 13:55:02 -0700 | [diff] [blame] | 488 | * @param transform The transform to apply to the content of |
John Reck | 582f6bd | 2019-10-30 10:04:37 -0700 | [diff] [blame] | 489 | * this view. If null the transform will be set to identity. |
John Reck | 5ba0948 | 2015-05-18 15:13:30 -0700 | [diff] [blame] | 490 | * |
| 491 | * @see #getTransform(android.graphics.Matrix) |
| 492 | * @see #isOpaque() |
| 493 | * @see #setOpaque(boolean) |
Romain Guy | 302a9df | 2011-08-16 13:55:02 -0700 | [diff] [blame] | 494 | */ |
John Reck | 582f6bd | 2019-10-30 10:04:37 -0700 | [diff] [blame] | 495 | public void setTransform(@Nullable Matrix transform) { |
Romain Guy | 302a9df | 2011-08-16 13:55:02 -0700 | [diff] [blame] | 496 | mMatrix.set(transform); |
| 497 | mMatrixChanged = true; |
Alexandre Elias | c01391f | 2011-08-19 16:03:16 -0700 | [diff] [blame] | 498 | invalidateParentIfNeeded(); |
Romain Guy | 302a9df | 2011-08-16 13:55:02 -0700 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | /** |
| 502 | * Returns the transform associated with this texture view. |
John Reck | 5ba0948 | 2015-05-18 15:13:30 -0700 | [diff] [blame] | 503 | * |
Romain Guy | 302a9df | 2011-08-16 13:55:02 -0700 | [diff] [blame] | 504 | * @param transform The {@link Matrix} in which to copy the current |
| 505 | * transform. Can be null. |
John Reck | 5ba0948 | 2015-05-18 15:13:30 -0700 | [diff] [blame] | 506 | * |
Romain Guy | 302a9df | 2011-08-16 13:55:02 -0700 | [diff] [blame] | 507 | * @return The specified matrix if not null or a new {@link Matrix} |
| 508 | * instance otherwise. |
John Reck | 5ba0948 | 2015-05-18 15:13:30 -0700 | [diff] [blame] | 509 | * |
| 510 | * @see #setTransform(android.graphics.Matrix) |
Romain Guy | 302a9df | 2011-08-16 13:55:02 -0700 | [diff] [blame] | 511 | */ |
John Reck | 582f6bd | 2019-10-30 10:04:37 -0700 | [diff] [blame] | 512 | public @NonNull Matrix getTransform(@Nullable Matrix transform) { |
Romain Guy | 302a9df | 2011-08-16 13:55:02 -0700 | [diff] [blame] | 513 | if (transform == null) { |
| 514 | transform = new Matrix(); |
| 515 | } |
| 516 | |
| 517 | transform.set(mMatrix); |
| 518 | |
| 519 | return transform; |
| 520 | } |
| 521 | |
Alexandre Elias | c01391f | 2011-08-19 16:03:16 -0700 | [diff] [blame] | 522 | private void applyTransformMatrix() { |
Romain Guy | 51f7c6b | 2012-05-21 16:32:59 -0700 | [diff] [blame] | 523 | if (mMatrixChanged && mLayer != null) { |
Alexandre Elias | c01391f | 2011-08-19 16:03:16 -0700 | [diff] [blame] | 524 | mLayer.setTransform(mMatrix); |
| 525 | mMatrixChanged = false; |
| 526 | } |
| 527 | } |
| 528 | |
Romain Guy | 302a9df | 2011-08-16 13:55:02 -0700 | [diff] [blame] | 529 | /** |
Romain Guy | 77a8116 | 2011-06-14 16:45:55 -0700 | [diff] [blame] | 530 | * <p>Returns a {@link android.graphics.Bitmap} representation of the content |
| 531 | * of the associated surface texture. If the surface texture is not available, |
| 532 | * this method returns null.</p> |
John Reck | 5ba0948 | 2015-05-18 15:13:30 -0700 | [diff] [blame] | 533 | * |
Romain Guy | 77a8116 | 2011-06-14 16:45:55 -0700 | [diff] [blame] | 534 | * <p>The bitmap returned by this method uses the {@link Bitmap.Config#ARGB_8888} |
| 535 | * pixel format and its dimensions are the same as this view's.</p> |
John Reck | 5ba0948 | 2015-05-18 15:13:30 -0700 | [diff] [blame] | 536 | * |
Romain Guy | 77a8116 | 2011-06-14 16:45:55 -0700 | [diff] [blame] | 537 | * <p><strong>Do not</strong> invoke this method from a drawing method |
| 538 | * ({@link #onDraw(android.graphics.Canvas)} for instance).</p> |
John Reck | 5ba0948 | 2015-05-18 15:13:30 -0700 | [diff] [blame] | 539 | * |
Romain Guy | d6b2a00 | 2011-06-17 17:45:59 -0700 | [diff] [blame] | 540 | * <p>If an error occurs during the copy, an empty bitmap will be returned.</p> |
John Reck | 5ba0948 | 2015-05-18 15:13:30 -0700 | [diff] [blame] | 541 | * |
Romain Guy | 77a8116 | 2011-06-14 16:45:55 -0700 | [diff] [blame] | 542 | * @return A valid {@link Bitmap.Config#ARGB_8888} bitmap, or null if the surface |
| 543 | * texture is not available or the width <= 0 or the height <= 0 |
John Reck | 5ba0948 | 2015-05-18 15:13:30 -0700 | [diff] [blame] | 544 | * |
| 545 | * @see #isAvailable() |
| 546 | * @see #getBitmap(android.graphics.Bitmap) |
| 547 | * @see #getBitmap(int, int) |
Romain Guy | 77a8116 | 2011-06-14 16:45:55 -0700 | [diff] [blame] | 548 | */ |
John Reck | 582f6bd | 2019-10-30 10:04:37 -0700 | [diff] [blame] | 549 | public @Nullable Bitmap getBitmap() { |
Romain Guy | 77a8116 | 2011-06-14 16:45:55 -0700 | [diff] [blame] | 550 | return getBitmap(getWidth(), getHeight()); |
| 551 | } |
| 552 | |
| 553 | /** |
| 554 | * <p>Returns a {@link android.graphics.Bitmap} representation of the content |
| 555 | * of the associated surface texture. If the surface texture is not available, |
| 556 | * this method returns null.</p> |
John Reck | 5ba0948 | 2015-05-18 15:13:30 -0700 | [diff] [blame] | 557 | * |
Romain Guy | 77a8116 | 2011-06-14 16:45:55 -0700 | [diff] [blame] | 558 | * <p>The bitmap returned by this method uses the {@link Bitmap.Config#ARGB_8888} |
| 559 | * pixel format.</p> |
John Reck | 5ba0948 | 2015-05-18 15:13:30 -0700 | [diff] [blame] | 560 | * |
Romain Guy | 77a8116 | 2011-06-14 16:45:55 -0700 | [diff] [blame] | 561 | * <p><strong>Do not</strong> invoke this method from a drawing method |
| 562 | * ({@link #onDraw(android.graphics.Canvas)} for instance).</p> |
John Reck | 5ba0948 | 2015-05-18 15:13:30 -0700 | [diff] [blame] | 563 | * |
Romain Guy | d6b2a00 | 2011-06-17 17:45:59 -0700 | [diff] [blame] | 564 | * <p>If an error occurs during the copy, an empty bitmap will be returned.</p> |
John Reck | 5ba0948 | 2015-05-18 15:13:30 -0700 | [diff] [blame] | 565 | * |
Romain Guy | 77a8116 | 2011-06-14 16:45:55 -0700 | [diff] [blame] | 566 | * @param width The width of the bitmap to create |
| 567 | * @param height The height of the bitmap to create |
John Reck | 5ba0948 | 2015-05-18 15:13:30 -0700 | [diff] [blame] | 568 | * |
Romain Guy | 77a8116 | 2011-06-14 16:45:55 -0700 | [diff] [blame] | 569 | * @return A valid {@link Bitmap.Config#ARGB_8888} bitmap, or null if the surface |
| 570 | * texture is not available or width is <= 0 or height is <= 0 |
John Reck | 5ba0948 | 2015-05-18 15:13:30 -0700 | [diff] [blame] | 571 | * |
| 572 | * @see #isAvailable() |
| 573 | * @see #getBitmap(android.graphics.Bitmap) |
| 574 | * @see #getBitmap() |
Romain Guy | 77a8116 | 2011-06-14 16:45:55 -0700 | [diff] [blame] | 575 | */ |
John Reck | 582f6bd | 2019-10-30 10:04:37 -0700 | [diff] [blame] | 576 | public @Nullable Bitmap getBitmap(int width, int height) { |
Romain Guy | 77a8116 | 2011-06-14 16:45:55 -0700 | [diff] [blame] | 577 | if (isAvailable() && width > 0 && height > 0) { |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 578 | return getBitmap(Bitmap.createBitmap(getResources().getDisplayMetrics(), |
| 579 | width, height, Bitmap.Config.ARGB_8888)); |
Romain Guy | 77a8116 | 2011-06-14 16:45:55 -0700 | [diff] [blame] | 580 | } |
| 581 | return null; |
| 582 | } |
| 583 | |
| 584 | /** |
| 585 | * <p>Copies the content of this view's surface texture into the specified |
| 586 | * bitmap. If the surface texture is not available, the copy is not executed. |
| 587 | * The content of the surface texture will be scaled to fit exactly inside |
| 588 | * the specified bitmap.</p> |
John Reck | 5ba0948 | 2015-05-18 15:13:30 -0700 | [diff] [blame] | 589 | * |
Romain Guy | 77a8116 | 2011-06-14 16:45:55 -0700 | [diff] [blame] | 590 | * <p><strong>Do not</strong> invoke this method from a drawing method |
| 591 | * ({@link #onDraw(android.graphics.Canvas)} for instance).</p> |
John Reck | 5ba0948 | 2015-05-18 15:13:30 -0700 | [diff] [blame] | 592 | * |
Romain Guy | d6b2a00 | 2011-06-17 17:45:59 -0700 | [diff] [blame] | 593 | * <p>If an error occurs, the bitmap is left unchanged.</p> |
John Reck | 5ba0948 | 2015-05-18 15:13:30 -0700 | [diff] [blame] | 594 | * |
Romain Guy | 77a8116 | 2011-06-14 16:45:55 -0700 | [diff] [blame] | 595 | * @param bitmap The bitmap to copy the content of the surface texture into, |
| 596 | * cannot be null, all configurations are supported |
John Reck | 5ba0948 | 2015-05-18 15:13:30 -0700 | [diff] [blame] | 597 | * |
Romain Guy | 77a8116 | 2011-06-14 16:45:55 -0700 | [diff] [blame] | 598 | * @return The bitmap specified as a parameter |
John Reck | 5ba0948 | 2015-05-18 15:13:30 -0700 | [diff] [blame] | 599 | * |
| 600 | * @see #isAvailable() |
| 601 | * @see #getBitmap(int, int) |
| 602 | * @see #getBitmap() |
| 603 | * |
Romain Guy | 589b0bb | 2011-10-10 13:57:47 -0700 | [diff] [blame] | 604 | * @throws IllegalStateException if the hardware rendering context cannot be |
| 605 | * acquired to capture the bitmap |
Romain Guy | 77a8116 | 2011-06-14 16:45:55 -0700 | [diff] [blame] | 606 | */ |
John Reck | 582f6bd | 2019-10-30 10:04:37 -0700 | [diff] [blame] | 607 | public @NonNull Bitmap getBitmap(@NonNull Bitmap bitmap) { |
Romain Guy | 77a8116 | 2011-06-14 16:45:55 -0700 | [diff] [blame] | 608 | if (bitmap != null && isAvailable()) { |
Romain Guy | 589b0bb | 2011-10-10 13:57:47 -0700 | [diff] [blame] | 609 | applyUpdate(); |
| 610 | applyTransformMatrix(); |
| 611 | |
Romain Guy | 78245f7 | 2012-05-11 10:01:42 -0700 | [diff] [blame] | 612 | // This case can happen if the app invokes setSurfaceTexture() before |
| 613 | // we are able to create the hardware layer. We can safely initialize |
| 614 | // the layer here thanks to the validate() call at the beginning of |
| 615 | // this method |
| 616 | if (mLayer == null && mUpdateSurface) { |
John Reck | 9d8d99d | 2018-02-21 12:55:41 -0800 | [diff] [blame] | 617 | getTextureLayer(); |
Romain Guy | 78245f7 | 2012-05-11 10:01:42 -0700 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | if (mLayer != null) { |
| 621 | mLayer.copyInto(bitmap); |
| 622 | } |
Romain Guy | 77a8116 | 2011-06-14 16:45:55 -0700 | [diff] [blame] | 623 | } |
| 624 | return bitmap; |
| 625 | } |
| 626 | |
| 627 | /** |
| 628 | * Returns true if the {@link SurfaceTexture} associated with this |
| 629 | * TextureView is available for rendering. When this method returns |
| 630 | * true, {@link #getSurfaceTexture()} returns a valid surface texture. |
| 631 | */ |
| 632 | public boolean isAvailable() { |
| 633 | return mSurface != null; |
| 634 | } |
| 635 | |
| 636 | /** |
Romain Guy | 6be3d55 | 2011-07-14 18:08:37 -0700 | [diff] [blame] | 637 | * <p>Start editing the pixels in the surface. The returned Canvas can be used |
| 638 | * to draw into the surface's bitmap. A null is returned if the surface has |
| 639 | * not been created or otherwise cannot be edited. You will usually need |
| 640 | * to implement |
| 641 | * {@link SurfaceTextureListener#onSurfaceTextureAvailable(android.graphics.SurfaceTexture, int, int)} |
| 642 | * to find out when the Surface is available for use.</p> |
John Reck | 5ba0948 | 2015-05-18 15:13:30 -0700 | [diff] [blame] | 643 | * |
Romain Guy | 6be3d55 | 2011-07-14 18:08:37 -0700 | [diff] [blame] | 644 | * <p>The content of the Surface is never preserved between unlockCanvas() |
| 645 | * and lockCanvas(), for this reason, every pixel within the Surface area |
| 646 | * must be written. The only exception to this rule is when a dirty |
| 647 | * rectangle is specified, in which case, non-dirty pixels will be |
| 648 | * preserved.</p> |
John Reck | 5ba0948 | 2015-05-18 15:13:30 -0700 | [diff] [blame] | 649 | * |
Romain Guy | 462785f | 2011-09-27 17:42:10 -0700 | [diff] [blame] | 650 | * <p>This method can only be used if the underlying surface is not already |
| 651 | * owned by another producer. For instance, if the TextureView is being used |
| 652 | * to render the camera's preview you cannot invoke this method.</p> |
John Reck | 5ba0948 | 2015-05-18 15:13:30 -0700 | [diff] [blame] | 653 | * |
John Reck | 582f6bd | 2019-10-30 10:04:37 -0700 | [diff] [blame] | 654 | * @return A Canvas used to draw into the surface, or null if the surface cannot be locked for |
| 655 | * drawing (see {@link #isAvailable()}). |
John Reck | 5ba0948 | 2015-05-18 15:13:30 -0700 | [diff] [blame] | 656 | * |
| 657 | * @see #lockCanvas(android.graphics.Rect) |
| 658 | * @see #unlockCanvasAndPost(android.graphics.Canvas) |
Romain Guy | 6be3d55 | 2011-07-14 18:08:37 -0700 | [diff] [blame] | 659 | */ |
John Reck | 582f6bd | 2019-10-30 10:04:37 -0700 | [diff] [blame] | 660 | public @Nullable Canvas lockCanvas() { |
Romain Guy | 6be3d55 | 2011-07-14 18:08:37 -0700 | [diff] [blame] | 661 | return lockCanvas(null); |
| 662 | } |
| 663 | |
| 664 | /** |
| 665 | * Just like {@link #lockCanvas()} but allows specification of a dirty |
| 666 | * rectangle. Every pixel within that rectangle must be written; however |
| 667 | * pixels outside the dirty rectangle will be preserved by the next call |
| 668 | * to lockCanvas(). |
Romain Guy | 53bacf5 | 2013-04-30 11:30:10 -0700 | [diff] [blame] | 669 | * |
| 670 | * This method can return null if the underlying surface texture is not |
| 671 | * available (see {@link #isAvailable()} or if the surface texture is |
| 672 | * already connected to an image producer (for instance: the camera, |
| 673 | * OpenGL, a media player, etc.) |
John Reck | 5ba0948 | 2015-05-18 15:13:30 -0700 | [diff] [blame] | 674 | * |
John Reck | 582f6bd | 2019-10-30 10:04:37 -0700 | [diff] [blame] | 675 | * @param dirty Area of the surface that will be modified. If null the area of the entire |
| 676 | * surface is used. |
Romain Guy | 6be3d55 | 2011-07-14 18:08:37 -0700 | [diff] [blame] | 677 | |
John Reck | 582f6bd | 2019-10-30 10:04:37 -0700 | [diff] [blame] | 678 | * @return A Canvas used to draw into the surface, or null if the surface cannot be locked for |
| 679 | * drawing (see {@link #isAvailable()}). |
John Reck | 5ba0948 | 2015-05-18 15:13:30 -0700 | [diff] [blame] | 680 | * |
| 681 | * @see #lockCanvas() |
Romain Guy | 53bacf5 | 2013-04-30 11:30:10 -0700 | [diff] [blame] | 682 | * @see #unlockCanvasAndPost(android.graphics.Canvas) |
| 683 | * @see #isAvailable() |
Romain Guy | 6be3d55 | 2011-07-14 18:08:37 -0700 | [diff] [blame] | 684 | */ |
John Reck | 582f6bd | 2019-10-30 10:04:37 -0700 | [diff] [blame] | 685 | public @Nullable Canvas lockCanvas(@Nullable Rect dirty) { |
Romain Guy | 6be3d55 | 2011-07-14 18:08:37 -0700 | [diff] [blame] | 686 | if (!isAvailable()) return null; |
| 687 | |
| 688 | if (mCanvas == null) { |
| 689 | mCanvas = new Canvas(); |
| 690 | } |
| 691 | |
| 692 | synchronized (mNativeWindowLock) { |
Romain Guy | 53bacf5 | 2013-04-30 11:30:10 -0700 | [diff] [blame] | 693 | if (!nLockCanvas(mNativeWindow, mCanvas, dirty)) { |
| 694 | return null; |
| 695 | } |
Romain Guy | 6be3d55 | 2011-07-14 18:08:37 -0700 | [diff] [blame] | 696 | } |
| 697 | mSaveCount = mCanvas.save(); |
| 698 | |
| 699 | return mCanvas; |
| 700 | } |
| 701 | |
| 702 | /** |
| 703 | * Finish editing pixels in the surface. After this call, the surface's |
| 704 | * current pixels will be shown on the screen, but its content is lost, |
| 705 | * in particular there is no guarantee that the content of the Surface |
| 706 | * will remain unchanged when lockCanvas() is called again. |
John Reck | 5ba0948 | 2015-05-18 15:13:30 -0700 | [diff] [blame] | 707 | * |
Romain Guy | 6be3d55 | 2011-07-14 18:08:37 -0700 | [diff] [blame] | 708 | * @param canvas The Canvas previously returned by lockCanvas() |
John Reck | 5ba0948 | 2015-05-18 15:13:30 -0700 | [diff] [blame] | 709 | * |
Romain Guy | 6be3d55 | 2011-07-14 18:08:37 -0700 | [diff] [blame] | 710 | * @see #lockCanvas() |
John Reck | 5ba0948 | 2015-05-18 15:13:30 -0700 | [diff] [blame] | 711 | * @see #lockCanvas(android.graphics.Rect) |
Romain Guy | 6be3d55 | 2011-07-14 18:08:37 -0700 | [diff] [blame] | 712 | */ |
John Reck | 582f6bd | 2019-10-30 10:04:37 -0700 | [diff] [blame] | 713 | public void unlockCanvasAndPost(@NonNull Canvas canvas) { |
Romain Guy | 6be3d55 | 2011-07-14 18:08:37 -0700 | [diff] [blame] | 714 | if (mCanvas != null && canvas == mCanvas) { |
| 715 | canvas.restoreToCount(mSaveCount); |
| 716 | mSaveCount = 0; |
| 717 | |
| 718 | synchronized (mNativeWindowLock) { |
| 719 | nUnlockCanvasAndPost(mNativeWindow, mCanvas); |
| 720 | } |
| 721 | } |
| 722 | } |
| 723 | |
| 724 | /** |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 725 | * Returns the {@link SurfaceTexture} used by this view. This method |
Romain Guy | 77a8116 | 2011-06-14 16:45:55 -0700 | [diff] [blame] | 726 | * may return null if the view is not attached to a window or if the surface |
| 727 | * texture has not been initialized yet. |
John Reck | 5ba0948 | 2015-05-18 15:13:30 -0700 | [diff] [blame] | 728 | * |
| 729 | * @see #isAvailable() |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 730 | */ |
John Reck | 582f6bd | 2019-10-30 10:04:37 -0700 | [diff] [blame] | 731 | public @Nullable SurfaceTexture getSurfaceTexture() { |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 732 | return mSurface; |
| 733 | } |
| 734 | |
| 735 | /** |
Jamie Gennis | 2af3524 | 2012-04-05 11:44:30 -0700 | [diff] [blame] | 736 | * Set the {@link SurfaceTexture} for this view to use. If a {@link |
| 737 | * SurfaceTexture} is already being used by this view, it is immediately |
Mark Lu | e8691d1 | 2016-08-30 17:38:42 -0700 | [diff] [blame] | 738 | * released and not usable any more. The {@link |
Jamie Gennis | 2af3524 | 2012-04-05 11:44:30 -0700 | [diff] [blame] | 739 | * SurfaceTextureListener#onSurfaceTextureDestroyed} callback is <b>not</b> |
Jamie Gennis | 8a34d68 | 2012-04-17 16:01:34 -0700 | [diff] [blame] | 740 | * called for the previous {@link SurfaceTexture}. Similarly, the {@link |
| 741 | * SurfaceTextureListener#onSurfaceTextureAvailable} callback is <b>not</b> |
| 742 | * called for the {@link SurfaceTexture} passed to setSurfaceTexture. |
Jamie Gennis | 2af3524 | 2012-04-05 11:44:30 -0700 | [diff] [blame] | 743 | * |
| 744 | * The {@link SurfaceTexture} object must be detached from all OpenGL ES |
| 745 | * contexts prior to calling this method. |
| 746 | * |
| 747 | * @param surfaceTexture The {@link SurfaceTexture} that the view should use. |
| 748 | * @see SurfaceTexture#detachFromGLContext() |
Jamie Gennis | 2af3524 | 2012-04-05 11:44:30 -0700 | [diff] [blame] | 749 | */ |
John Reck | 582f6bd | 2019-10-30 10:04:37 -0700 | [diff] [blame] | 750 | public void setSurfaceTexture(@NonNull SurfaceTexture surfaceTexture) { |
Jamie Gennis | 2af3524 | 2012-04-05 11:44:30 -0700 | [diff] [blame] | 751 | if (surfaceTexture == null) { |
| 752 | throw new NullPointerException("surfaceTexture must not be null"); |
| 753 | } |
John Reck | 6d8371e | 2015-05-14 15:47:03 -0700 | [diff] [blame] | 754 | if (surfaceTexture == mSurface) { |
| 755 | throw new IllegalArgumentException("Trying to setSurfaceTexture to " + |
| 756 | "the same SurfaceTexture that's already set."); |
| 757 | } |
| 758 | if (surfaceTexture.isReleased()) { |
| 759 | throw new IllegalArgumentException("Cannot setSurfaceTexture to a " + |
| 760 | "released SurfaceTexture"); |
| 761 | } |
Jamie Gennis | 2af3524 | 2012-04-05 11:44:30 -0700 | [diff] [blame] | 762 | if (mSurface != null) { |
John Reck | 7e23718 | 2016-08-11 10:43:14 -0700 | [diff] [blame] | 763 | nDestroyNativeWindow(); |
Jamie Gennis | 2af3524 | 2012-04-05 11:44:30 -0700 | [diff] [blame] | 764 | mSurface.release(); |
| 765 | } |
| 766 | mSurface = surfaceTexture; |
John Reck | 7e23718 | 2016-08-11 10:43:14 -0700 | [diff] [blame] | 767 | nCreateNativeWindow(mSurface); |
Naveen Kalla | fd69e2a | 2015-03-17 15:20:53 -0700 | [diff] [blame] | 768 | |
John Reck | 8bc511e | 2015-05-18 15:11:52 -0700 | [diff] [blame] | 769 | /* |
| 770 | * If the view is visible and we already made a layer, update the |
| 771 | * listener in the new surface to use the existing listener in the view. |
| 772 | * Otherwise this will be called when the view becomes visible or the |
| 773 | * layer is created |
| 774 | */ |
| 775 | if (((mViewFlags & VISIBILITY_MASK) == VISIBLE) && mLayer != null) { |
Naveen Kalla | fd69e2a | 2015-03-17 15:20:53 -0700 | [diff] [blame] | 776 | mSurface.setOnFrameAvailableListener(mUpdateListener, mAttachInfo.mHandler); |
| 777 | } |
Jamie Gennis | 2af3524 | 2012-04-05 11:44:30 -0700 | [diff] [blame] | 778 | mUpdateSurface = true; |
| 779 | invalidateParentIfNeeded(); |
| 780 | } |
| 781 | |
| 782 | /** |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 783 | * Returns the {@link SurfaceTextureListener} currently associated with this |
| 784 | * texture view. |
John Reck | 5ba0948 | 2015-05-18 15:13:30 -0700 | [diff] [blame] | 785 | * |
| 786 | * @see #setSurfaceTextureListener(android.view.TextureView.SurfaceTextureListener) |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 787 | * @see SurfaceTextureListener |
| 788 | */ |
John Reck | 582f6bd | 2019-10-30 10:04:37 -0700 | [diff] [blame] | 789 | public @Nullable SurfaceTextureListener getSurfaceTextureListener() { |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 790 | return mListener; |
| 791 | } |
| 792 | |
| 793 | /** |
| 794 | * Sets the {@link SurfaceTextureListener} used to listen to surface |
| 795 | * texture events. |
John Reck | 5ba0948 | 2015-05-18 15:13:30 -0700 | [diff] [blame] | 796 | * |
| 797 | * @see #getSurfaceTextureListener() |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 798 | * @see SurfaceTextureListener |
| 799 | */ |
John Reck | 582f6bd | 2019-10-30 10:04:37 -0700 | [diff] [blame] | 800 | public void setSurfaceTextureListener(@Nullable SurfaceTextureListener listener) { |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 801 | mListener = listener; |
| 802 | } |
| 803 | |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 804 | @UnsupportedAppUsage |
Jeff Brown | c7282e5 | 2014-05-06 16:00:38 -0700 | [diff] [blame] | 805 | private final SurfaceTexture.OnFrameAvailableListener mUpdateListener = |
John Reck | 582f6bd | 2019-10-30 10:04:37 -0700 | [diff] [blame] | 806 | surfaceTexture -> { |
| 807 | updateLayer(); |
| 808 | invalidate(); |
| 809 | }; |
Jeff Brown | c7282e5 | 2014-05-06 16:00:38 -0700 | [diff] [blame] | 810 | |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 811 | /** |
| 812 | * This listener can be used to be notified when the surface texture |
| 813 | * associated with this texture view is available. |
| 814 | */ |
John Reck | 582f6bd | 2019-10-30 10:04:37 -0700 | [diff] [blame] | 815 | public interface SurfaceTextureListener { |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 816 | /** |
| 817 | * Invoked when a {@link TextureView}'s SurfaceTexture is ready for use. |
John Reck | 5ba0948 | 2015-05-18 15:13:30 -0700 | [diff] [blame] | 818 | * |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 819 | * @param surface The surface returned by |
| 820 | * {@link android.view.TextureView#getSurfaceTexture()} |
Romain Guy | 451ce44 | 2011-06-10 15:40:36 -0700 | [diff] [blame] | 821 | * @param width The width of the surface |
| 822 | * @param height The height of the surface |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 823 | */ |
John Reck | 582f6bd | 2019-10-30 10:04:37 -0700 | [diff] [blame] | 824 | void onSurfaceTextureAvailable(@NonNull SurfaceTexture surface, int width, int height); |
Romain Guy | 8f0095c | 2011-05-02 17:24:22 -0700 | [diff] [blame] | 825 | |
| 826 | /** |
| 827 | * Invoked when the {@link SurfaceTexture}'s buffers size changed. |
John Reck | 5ba0948 | 2015-05-18 15:13:30 -0700 | [diff] [blame] | 828 | * |
Romain Guy | 8f0095c | 2011-05-02 17:24:22 -0700 | [diff] [blame] | 829 | * @param surface The surface returned by |
| 830 | * {@link android.view.TextureView#getSurfaceTexture()} |
| 831 | * @param width The new width of the surface |
| 832 | * @param height The new height of the surface |
| 833 | */ |
John Reck | 582f6bd | 2019-10-30 10:04:37 -0700 | [diff] [blame] | 834 | void onSurfaceTextureSizeChanged(@NonNull SurfaceTexture surface, int width, int height); |
Romain Guy | 451ce44 | 2011-06-10 15:40:36 -0700 | [diff] [blame] | 835 | |
| 836 | /** |
| 837 | * Invoked when the specified {@link SurfaceTexture} is about to be destroyed. |
Grace Kloba | 402f055 | 2011-08-09 18:47:17 -0700 | [diff] [blame] | 838 | * If returns true, no rendering should happen inside the surface texture after this method |
| 839 | * is invoked. If returns false, the client needs to call {@link SurfaceTexture#release()}. |
Romain Guy | 52b307e | 2012-10-07 17:55:17 -0700 | [diff] [blame] | 840 | * Most applications should return true. |
John Reck | 5ba0948 | 2015-05-18 15:13:30 -0700 | [diff] [blame] | 841 | * |
Romain Guy | 451ce44 | 2011-06-10 15:40:36 -0700 | [diff] [blame] | 842 | * @param surface The surface about to be destroyed |
| 843 | */ |
John Reck | 582f6bd | 2019-10-30 10:04:37 -0700 | [diff] [blame] | 844 | boolean onSurfaceTextureDestroyed(@NonNull SurfaceTexture surface); |
Grace Kloba | cf55937 | 2011-06-22 23:05:40 -0700 | [diff] [blame] | 845 | |
| 846 | /** |
| 847 | * Invoked when the specified {@link SurfaceTexture} is updated through |
| 848 | * {@link SurfaceTexture#updateTexImage()}. |
John Reck | 5ba0948 | 2015-05-18 15:13:30 -0700 | [diff] [blame] | 849 | * |
Grace Kloba | cf55937 | 2011-06-22 23:05:40 -0700 | [diff] [blame] | 850 | * @param surface The surface just updated |
| 851 | */ |
John Reck | 582f6bd | 2019-10-30 10:04:37 -0700 | [diff] [blame] | 852 | void onSurfaceTextureUpdated(@NonNull SurfaceTexture surface); |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 853 | } |
Romain Guy | 8f0095c | 2011-05-02 17:24:22 -0700 | [diff] [blame] | 854 | |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 855 | @UnsupportedAppUsage |
Romain Guy | 6be3d55 | 2011-07-14 18:08:37 -0700 | [diff] [blame] | 856 | private native void nCreateNativeWindow(SurfaceTexture surface); |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 857 | @UnsupportedAppUsage |
Romain Guy | 6be3d55 | 2011-07-14 18:08:37 -0700 | [diff] [blame] | 858 | private native void nDestroyNativeWindow(); |
| 859 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 860 | private static native boolean nLockCanvas(long nativeWindow, Canvas canvas, Rect dirty); |
| 861 | private static native void nUnlockCanvasAndPost(long nativeWindow, Canvas canvas); |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 862 | } |