TextureView.java revision 7e52caf6db5feef2b847cfaa3d13690257122c3a
1aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy/*
2aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy * Copyright (C) 2011 The Android Open Source Project
3aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy *
4aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy * Licensed under the Apache License, Version 2.0 (the "License");
5aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy * you may not use this file except in compliance with the License.
6aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy * You may obtain a copy of the License at
7aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy *
8aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy *      http://www.apache.org/licenses/LICENSE-2.0
9aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy *
10aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy * Unless required by applicable law or agreed to in writing, software
11aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy * distributed under the License is distributed on an "AS IS" BASIS,
12aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy * See the License for the specific language governing permissions and
14aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy * limitations under the License.
15aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy */
16aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy
17aa6c24c21c727a196451332448d4e3b11a80be69Romain Guypackage android.view;
18aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy
19aa6c24c21c727a196451332448d4e3b11a80be69Romain Guyimport android.content.Context;
2077a811610f99e21da7f88dafef60d09f345d0506Romain Guyimport android.graphics.Bitmap;
21aa6c24c21c727a196451332448d4e3b11a80be69Romain Guyimport android.graphics.Canvas;
22302a9df1d50373c82923bb84ff665dfce584fb22Romain Guyimport android.graphics.Matrix;
23aa6c24c21c727a196451332448d4e3b11a80be69Romain Guyimport android.graphics.Paint;
246be3d5561cbeccf0a8257a4acb155657f868e548Romain Guyimport android.graphics.Rect;
25aa6c24c21c727a196451332448d4e3b11a80be69Romain Guyimport android.graphics.SurfaceTexture;
26aa6c24c21c727a196451332448d4e3b11a80be69Romain Guyimport android.util.AttributeSet;
27aa6c24c21c727a196451332448d4e3b11a80be69Romain Guyimport android.util.Log;
28aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy
29aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy/**
30aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy * <p>A TextureView can be used to display a content stream. Such a content
31aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy * stream can for instance be a video or an OpenGL scene. The content stream
32aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy * can come from the application's process as well as a remote process.</p>
33aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy *
34aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy * <p>TextureView can only be used in a hardware accelerated window. When
35aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy * rendered in software, TextureView will draw nothing.</p>
36aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy *
37aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy * <p>Unlike {@link SurfaceView}, TextureView does not create a separate
38aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy * window but behaves as a regular View. This key difference allows a
39aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy * TextureView to be moved, transformed, animated, etc. For instance, you
40aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy * can make a TextureView semi-translucent by calling
41aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy * <code>myView.setAlpha(0.5f)</code>.</p>
42aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy *
43aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy * <p>Using a TextureView is simple: all you need to do is get its
44aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy * {@link SurfaceTexture}. The {@link SurfaceTexture} can then be used to
45aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy * render content. The following example demonstrates how to render the
46aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy * camera preview into a TextureView:</p>
47aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy *
48aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy * <pre>
49aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy *  public class LiveCameraActivity extends Activity implements TextureView.SurfaceTextureListener {
50aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy *      private Camera mCamera;
51aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy *      private TextureView mTextureView;
52aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy *
53aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy *      protected void onCreate(Bundle savedInstanceState) {
54aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy *          super.onCreate(savedInstanceState);
55aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy *
56aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy *          mTextureView = new TextureView(this);
57aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy *          mTextureView.setSurfaceTextureListener(this);
58aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy *
59aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy *          setContentView(mTextureView);
60aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy *      }
61aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy *
62451ce44a18e4c48f8a43aa250957f76967a35d31Romain Guy *      public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
63aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy *          mCamera = Camera.open();
64aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy *
65aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy *          try {
66aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy *              mCamera.setPreviewTexture(surface);
67aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy *              mCamera.startPreview();
68aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy *          } catch (IOException ioe) {
69aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy *              // Something bad happened
70aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy *          }
71aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy *      }
72cf559377b750271472aa0a717bf3b7d34abc0b39Grace Kloba *
738f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy *      public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
748f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy *          // Ignored, Camera does all the work for us
758f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy *      }
76cf559377b750271472aa0a717bf3b7d34abc0b39Grace Kloba *
77402f05530352f34d5320c2d23be43c274d97c4e2Grace Kloba *      public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
78451ce44a18e4c48f8a43aa250957f76967a35d31Romain Guy *          mCamera.stopPreview();
79451ce44a18e4c48f8a43aa250957f76967a35d31Romain Guy *          mCamera.release();
80402f05530352f34d5320c2d23be43c274d97c4e2Grace Kloba *          return true;
81451ce44a18e4c48f8a43aa250957f76967a35d31Romain Guy *      }
82cf559377b750271472aa0a717bf3b7d34abc0b39Grace Kloba *
83cf559377b750271472aa0a717bf3b7d34abc0b39Grace Kloba *      public void onSurfaceTextureUpdated(SurfaceTexture surface) {
8458f4edb7701bf20925468fa5fd1a06a461ff085bRomain Guy *          // Invoked every time there's a new Camera preview frame
85cf559377b750271472aa0a717bf3b7d34abc0b39Grace Kloba *      }
86aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy *  }
87aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy * </pre>
88aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy *
89aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy * <p>A TextureView's SurfaceTexture can be obtained either by invoking
90aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy * {@link #getSurfaceTexture()} or by using a {@link SurfaceTextureListener}.
91aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy * It is important to know that a SurfaceTexture is available only after the
92aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy * TextureView is attached to a window (and {@link #onAttachedToWindow()} has
93aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy * been invoked.) It is therefore highly recommended you use a listener to
94aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy * be notified when the SurfaceTexture becomes available.</p>
95aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy *
96462785fa257671fe4905d1d3e6ca27e4a61ee946Romain Guy * <p>It is important to note that only one producer can use the TextureView.
97462785fa257671fe4905d1d3e6ca27e4a61ee946Romain Guy * For instance, if you use a TextureView to display the camera preview, you
98462785fa257671fe4905d1d3e6ca27e4a61ee946Romain Guy * cannot use {@link #lockCanvas()} to draw onto the TextureView at the same
99462785fa257671fe4905d1d3e6ca27e4a61ee946Romain Guy * time.</p>
100462785fa257671fe4905d1d3e6ca27e4a61ee946Romain Guy *
101aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy * @see SurfaceView
102aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy * @see SurfaceTexture
103aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy */
104aa6c24c21c727a196451332448d4e3b11a80be69Romain Guypublic class TextureView extends View {
10577a811610f99e21da7f88dafef60d09f345d0506Romain Guy    private static final String LOG_TAG = "TextureView";
10677a811610f99e21da7f88dafef60d09f345d0506Romain Guy
107aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    private HardwareLayer mLayer;
108aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    private SurfaceTexture mSurface;
109aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    private SurfaceTextureListener mListener;
110aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy
111a9489274d67b540804aafb587a226f7c2ae4464dRomain Guy    private boolean mOpaque = true;
112c989d867f2580a99cde25fab0e49e445aea33f2fRomain Guy
113302a9df1d50373c82923bb84ff665dfce584fb22Romain Guy    private final Matrix mMatrix = new Matrix();
114302a9df1d50373c82923bb84ff665dfce584fb22Romain Guy    private boolean mMatrixChanged;
115302a9df1d50373c82923bb84ff665dfce584fb22Romain Guy
11658f4edb7701bf20925468fa5fd1a06a461ff085bRomain Guy    private final Object[] mLock = new Object[0];
11758f4edb7701bf20925468fa5fd1a06a461ff085bRomain Guy    private boolean mUpdateLayer;
11858f4edb7701bf20925468fa5fd1a06a461ff085bRomain Guy
1198f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy    private SurfaceTexture.OnFrameAvailableListener mUpdateListener;
120aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy
1216be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy    private Canvas mCanvas;
1226be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy    private int mSaveCount;
1236be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy
1246be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy    private final Object[] mNativeWindowLock = new Object[0];
1256be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy    // Used from native code, do not write!
1266be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy    @SuppressWarnings({"UnusedDeclaration"})
1276be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy    private int mNativeWindow;
1286be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy
129aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    /**
130aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     * Creates a new TextureView.
131aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     *
132aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     * @param context The context to associate this view with.
133aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     */
134aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    public TextureView(Context context) {
135aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy        super(context);
136aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy        init();
137aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    }
138aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy
139aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    /**
140aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     * Creates a new TextureView.
141aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     *
142aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     * @param context The context to associate this view with.
143aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     * @param attrs The attributes of the XML tag that is inflating the view.
144aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     */
145aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    @SuppressWarnings({"UnusedDeclaration"})
146aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    public TextureView(Context context, AttributeSet attrs) {
147aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy        super(context, attrs);
148aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy        init();
149aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    }
150aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy
151aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    /**
152aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     * Creates a new TextureView.
153aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     *
154aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     * @param context The context to associate this view with.
155aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     * @param attrs The attributes of the XML tag that is inflating the view.
156aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     * @param defStyle The default style to apply to this view. If 0, no style
157aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     *        will be applied (beyond what is included in the theme). This may
158aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     *        either be an attribute resource, whose value will be retrieved
159aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     *        from the current theme, or an explicit style resource.
160aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     */
161aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    @SuppressWarnings({"UnusedDeclaration"})
162aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    public TextureView(Context context, AttributeSet attrs, int defStyle) {
163aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy        super(context, attrs, defStyle);
164aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy        init();
165aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    }
166aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy
167aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    private void init() {
168aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy        mLayerPaint = new Paint();
169aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    }
170aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy
171a9489274d67b540804aafb587a226f7c2ae4464dRomain Guy    /**
172a9489274d67b540804aafb587a226f7c2ae4464dRomain Guy     * {@inheritDoc}
173a9489274d67b540804aafb587a226f7c2ae4464dRomain Guy     */
174a9489274d67b540804aafb587a226f7c2ae4464dRomain Guy    @Override
175a9489274d67b540804aafb587a226f7c2ae4464dRomain Guy    public boolean isOpaque() {
176a9489274d67b540804aafb587a226f7c2ae4464dRomain Guy        return mOpaque;
177a9489274d67b540804aafb587a226f7c2ae4464dRomain Guy    }
178a9489274d67b540804aafb587a226f7c2ae4464dRomain Guy
179a9489274d67b540804aafb587a226f7c2ae4464dRomain Guy    /**
180a9489274d67b540804aafb587a226f7c2ae4464dRomain Guy     * Indicates whether the content of this TextureView is opaque. The
181a9489274d67b540804aafb587a226f7c2ae4464dRomain Guy     * content is assumed to be opaque by default.
182a9489274d67b540804aafb587a226f7c2ae4464dRomain Guy     *
183a9489274d67b540804aafb587a226f7c2ae4464dRomain Guy     * @param opaque True if the content of this TextureView is opaque,
184a9489274d67b540804aafb587a226f7c2ae4464dRomain Guy     *               false otherwise
185a9489274d67b540804aafb587a226f7c2ae4464dRomain Guy     */
186a9489274d67b540804aafb587a226f7c2ae4464dRomain Guy    public void setOpaque(boolean opaque) {
187a9489274d67b540804aafb587a226f7c2ae4464dRomain Guy        if (opaque != mOpaque) {
188a9489274d67b540804aafb587a226f7c2ae4464dRomain Guy            mOpaque = opaque;
18958f4edb7701bf20925468fa5fd1a06a461ff085bRomain Guy            updateLayer();
190a9489274d67b540804aafb587a226f7c2ae4464dRomain Guy        }
191a9489274d67b540804aafb587a226f7c2ae4464dRomain Guy    }
192a9489274d67b540804aafb587a226f7c2ae4464dRomain Guy
193aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    @Override
194aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    protected void onAttachedToWindow() {
195aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy        super.onAttachedToWindow();
196aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy
197aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy        if (!isHardwareAccelerated()) {
19877a811610f99e21da7f88dafef60d09f345d0506Romain Guy            Log.w(LOG_TAG, "A TextureView or a subclass can only be "
199aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy                    + "used with hardware acceleration enabled.");
200aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy        }
201aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    }
202aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy
203451ce44a18e4c48f8a43aa250957f76967a35d31Romain Guy    @Override
204451ce44a18e4c48f8a43aa250957f76967a35d31Romain Guy    protected void onDetachedFromWindow() {
205451ce44a18e4c48f8a43aa250957f76967a35d31Romain Guy        super.onDetachedFromWindow();
20631f2c2e94656530fbf6282803e62edb47e9a894dRomain Guy        destroySurface();
20731f2c2e94656530fbf6282803e62edb47e9a894dRomain Guy    }
208451ce44a18e4c48f8a43aa250957f76967a35d31Romain Guy
20931f2c2e94656530fbf6282803e62edb47e9a894dRomain Guy    private void destroySurface() {
21080429c458506485904715180d10584092a5cd082Romain Guy        if (mLayer != null) {
211402f05530352f34d5320c2d23be43c274d97c4e2Grace Kloba            boolean shouldRelease = true;
212451ce44a18e4c48f8a43aa250957f76967a35d31Romain Guy            if (mListener != null) {
213402f05530352f34d5320c2d23be43c274d97c4e2Grace Kloba                shouldRelease = mListener.onSurfaceTextureDestroyed(mSurface);
214451ce44a18e4c48f8a43aa250957f76967a35d31Romain Guy            }
215451ce44a18e4c48f8a43aa250957f76967a35d31Romain Guy
2166be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy            synchronized (mNativeWindowLock) {
2176be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy                nDestroyNativeWindow();
2186be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy            }
2196be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy
2206be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy            mLayer.destroy();
221402f05530352f34d5320c2d23be43c274d97c4e2Grace Kloba            if (shouldRelease) mSurface.release();
222451ce44a18e4c48f8a43aa250957f76967a35d31Romain Guy            mSurface = null;
223451ce44a18e4c48f8a43aa250957f76967a35d31Romain Guy            mLayer = null;
224451ce44a18e4c48f8a43aa250957f76967a35d31Romain Guy        }
225451ce44a18e4c48f8a43aa250957f76967a35d31Romain Guy    }
226451ce44a18e4c48f8a43aa250957f76967a35d31Romain Guy
227aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    /**
228aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     * The layer type of a TextureView is ignored since a TextureView is always
229aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     * considered to act as a hardware layer. The optional paint supplied to this
230aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     * method will however be taken into account when rendering the content of
231aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     * this TextureView.
232aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     *
233aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     * @param layerType The ype of layer to use with this view, must be one of
234aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     *        {@link #LAYER_TYPE_NONE}, {@link #LAYER_TYPE_SOFTWARE} or
235aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     *        {@link #LAYER_TYPE_HARDWARE}
236aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     * @param paint The paint used to compose the layer. This argument is optional
237aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     *        and can be null. It is ignored when the layer type is
238aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     *        {@link #LAYER_TYPE_NONE}
239aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     */
240aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    @Override
241aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    public void setLayerType(int layerType, Paint paint) {
242aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy        if (paint != mLayerPaint) {
243aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy            mLayerPaint = paint;
244aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy            invalidate();
245aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy        }
246aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    }
247aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy
248aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    /**
249aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     * Always returns {@link #LAYER_TYPE_HARDWARE}.
250aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     */
251aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    @Override
252aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    public int getLayerType() {
253aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy        return LAYER_TYPE_HARDWARE;
254aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    }
255aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy
25659c7f80dd20258cefa1fc4bdd3c9a709a8dd53b8Romain Guy    @Override
25759c7f80dd20258cefa1fc4bdd3c9a709a8dd53b8Romain Guy    boolean hasStaticLayer() {
25859c7f80dd20258cefa1fc4bdd3c9a709a8dd53b8Romain Guy        return true;
25959c7f80dd20258cefa1fc4bdd3c9a709a8dd53b8Romain Guy    }
26059c7f80dd20258cefa1fc4bdd3c9a709a8dd53b8Romain Guy
261aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    /**
262aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     * Calling this method has no effect.
263aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     */
264aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    @Override
265aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    public void buildLayer() {
266aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    }
267aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy
268aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    /**
269aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     * Subclasses of TextureView cannot do their own rendering
270aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     * with the {@link Canvas} object.
271aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     *
272aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     * @param canvas The Canvas to which the View is rendered.
273aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     */
274aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    @Override
275aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    public final void draw(Canvas canvas) {
27658f4edb7701bf20925468fa5fd1a06a461ff085bRomain Guy        applyUpdate();
277c01391fb4eb0eef33d142e89e060eac7e75de39dAlexandre Elias        applyTransformMatrix();
278aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    }
279aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy
280aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    /**
281aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     * Subclasses of TextureView cannot do their own rendering
282aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     * with the {@link Canvas} object.
283aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     *
284aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     * @param canvas The Canvas to which the View is rendered.
285aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     */
286aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    @Override
287aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    protected final void onDraw(Canvas canvas) {
288aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    }
289aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy
290aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    @Override
2918f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
2928f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy        super.onSizeChanged(w, h, oldw, oldh);
2938f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy        if (mSurface != null) {
294e5e0c50f7dfaccc220725c5595080e921ffda1e4Romain Guy            nSetDefaultBufferSize(mSurface, getWidth(), getHeight());
295451ce44a18e4c48f8a43aa250957f76967a35d31Romain Guy            if (mListener != null) {
296451ce44a18e4c48f8a43aa250957f76967a35d31Romain Guy                mListener.onSurfaceTextureSizeChanged(mSurface, getWidth(), getHeight());
297451ce44a18e4c48f8a43aa250957f76967a35d31Romain Guy            }
2988f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy        }
2998f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy    }
3008f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy
3018f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy    @Override
30216260e73f6c1c9dc94acf0d328a3c564426b8711Romain Guy    boolean destroyLayer() {
30316260e73f6c1c9dc94acf0d328a3c564426b8711Romain Guy        return false;
30416260e73f6c1c9dc94acf0d328a3c564426b8711Romain Guy    }
30516260e73f6c1c9dc94acf0d328a3c564426b8711Romain Guy
3061766b0e25de5a66f9d0f6e73a2c342272fcadc71Romain Guy    /**
3071766b0e25de5a66f9d0f6e73a2c342272fcadc71Romain Guy     * @hide
3081766b0e25de5a66f9d0f6e73a2c342272fcadc71Romain Guy     */
30916260e73f6c1c9dc94acf0d328a3c564426b8711Romain Guy    @Override
31031f2c2e94656530fbf6282803e62edb47e9a894dRomain Guy    protected void destroyHardwareResources() {
31131f2c2e94656530fbf6282803e62edb47e9a894dRomain Guy        super.destroyHardwareResources();
31231f2c2e94656530fbf6282803e62edb47e9a894dRomain Guy        destroySurface();
31331f2c2e94656530fbf6282803e62edb47e9a894dRomain Guy        invalidateParentCaches();
31431f2c2e94656530fbf6282803e62edb47e9a894dRomain Guy        invalidate(true);
31531f2c2e94656530fbf6282803e62edb47e9a894dRomain Guy    }
31631f2c2e94656530fbf6282803e62edb47e9a894dRomain Guy
31731f2c2e94656530fbf6282803e62edb47e9a894dRomain Guy    @Override
3187e52caf6db5feef2b847cfaa3d13690257122c3aMichael Jurka    HardwareLayer getHardwareLayer() {
319aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy        if (mLayer == null) {
32058f4edb7701bf20925468fa5fd1a06a461ff085bRomain Guy            if (mAttachInfo == null || mAttachInfo.mHardwareRenderer == null) {
32158f4edb7701bf20925468fa5fd1a06a461ff085bRomain Guy                return null;
32258f4edb7701bf20925468fa5fd1a06a461ff085bRomain Guy            }
32358f4edb7701bf20925468fa5fd1a06a461ff085bRomain Guy
324a9489274d67b540804aafb587a226f7c2ae4464dRomain Guy            mLayer = mAttachInfo.mHardwareRenderer.createHardwareLayer(mOpaque);
325e5e0c50f7dfaccc220725c5595080e921ffda1e4Romain Guy            mSurface = mAttachInfo.mHardwareRenderer.createSurfaceTexture(mLayer);
326e5e0c50f7dfaccc220725c5595080e921ffda1e4Romain Guy            nSetDefaultBufferSize(mSurface, getWidth(), getHeight());
3276be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy            nCreateNativeWindow(mSurface);
328aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy
3298f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy            mUpdateListener = new SurfaceTexture.OnFrameAvailableListener() {
330aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy                @Override
331aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy                public void onFrameAvailable(SurfaceTexture surfaceTexture) {
332aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy                    // Per SurfaceTexture's documentation, the callback may be invoked
333aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy                    // from an arbitrary thread
33458f4edb7701bf20925468fa5fd1a06a461ff085bRomain Guy                    synchronized (mLock) {
33558f4edb7701bf20925468fa5fd1a06a461ff085bRomain Guy                        mUpdateLayer = true;
33658f4edb7701bf20925468fa5fd1a06a461ff085bRomain Guy                    }
3376cb7b46c56449e84434b11eb12f9b8977fcd0398Jeff Brown                    postInvalidate();
338aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy                }
3398f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy            };
3408f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy            mSurface.setOnFrameAvailableListener(mUpdateListener);
341aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy
342aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy            if (mListener != null) {
343451ce44a18e4c48f8a43aa250957f76967a35d31Romain Guy                mListener.onSurfaceTextureAvailable(mSurface, getWidth(), getHeight());
344aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy            }
345aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy        }
346aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy
34758f4edb7701bf20925468fa5fd1a06a461ff085bRomain Guy        applyUpdate();
348c01391fb4eb0eef33d142e89e060eac7e75de39dAlexandre Elias        applyTransformMatrix();
349302a9df1d50373c82923bb84ff665dfce584fb22Romain Guy
350aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy        return mLayer;
351aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    }
352aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy
3538f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy    @Override
3548f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy    protected void onVisibilityChanged(View changedView, int visibility) {
3558f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy        super.onVisibilityChanged(changedView, visibility);
3568f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy
3578f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy        if (mSurface != null) {
3588f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy            // When the view becomes invisible, stop updating it, it's a waste of CPU
3598f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy            // To cancel updates, the easiest thing to do is simply to remove the
3608f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy            // updates listener
3618f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy            if (visibility == VISIBLE) {
3628f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy                mSurface.setOnFrameAvailableListener(mUpdateListener);
363a9489274d67b540804aafb587a226f7c2ae4464dRomain Guy                updateLayer();
3648f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy            } else {
3658f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy                mSurface.setOnFrameAvailableListener(null);
3668f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy            }
3678f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy        }
3688f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy    }
3698f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy
370a9489274d67b540804aafb587a226f7c2ae4464dRomain Guy    private void updateLayer() {
37158f4edb7701bf20925468fa5fd1a06a461ff085bRomain Guy        mUpdateLayer = true;
37258f4edb7701bf20925468fa5fd1a06a461ff085bRomain Guy        invalidate();
37358f4edb7701bf20925468fa5fd1a06a461ff085bRomain Guy    }
37458f4edb7701bf20925468fa5fd1a06a461ff085bRomain Guy
37558f4edb7701bf20925468fa5fd1a06a461ff085bRomain Guy    private void applyUpdate() {
37658f4edb7701bf20925468fa5fd1a06a461ff085bRomain Guy        if (mLayer == null) {
377a9489274d67b540804aafb587a226f7c2ae4464dRomain Guy            return;
378a9489274d67b540804aafb587a226f7c2ae4464dRomain Guy        }
379a9489274d67b540804aafb587a226f7c2ae4464dRomain Guy
38058f4edb7701bf20925468fa5fd1a06a461ff085bRomain Guy        synchronized (mLock) {
38158f4edb7701bf20925468fa5fd1a06a461ff085bRomain Guy            if (mUpdateLayer) {
38258f4edb7701bf20925468fa5fd1a06a461ff085bRomain Guy                mUpdateLayer = false;
38358f4edb7701bf20925468fa5fd1a06a461ff085bRomain Guy            } else {
38458f4edb7701bf20925468fa5fd1a06a461ff085bRomain Guy                return;
38558f4edb7701bf20925468fa5fd1a06a461ff085bRomain Guy            }
38658f4edb7701bf20925468fa5fd1a06a461ff085bRomain Guy        }
38758f4edb7701bf20925468fa5fd1a06a461ff085bRomain Guy
38802ccac69fd1c0a03c24c5f3ace0ad4bed337b1fdRomain Guy        mLayer.update(getWidth(), getHeight(), mOpaque);
389a9489274d67b540804aafb587a226f7c2ae4464dRomain Guy
390cf559377b750271472aa0a717bf3b7d34abc0b39Grace Kloba        if (mListener != null) {
391cf559377b750271472aa0a717bf3b7d34abc0b39Grace Kloba            mListener.onSurfaceTextureUpdated(mSurface);
392cf559377b750271472aa0a717bf3b7d34abc0b39Grace Kloba        }
393a9489274d67b540804aafb587a226f7c2ae4464dRomain Guy    }
394a9489274d67b540804aafb587a226f7c2ae4464dRomain Guy
395aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    /**
396302a9df1d50373c82923bb84ff665dfce584fb22Romain Guy     * <p>Sets the transform to associate with this texture view.
397302a9df1d50373c82923bb84ff665dfce584fb22Romain Guy     * The specified transform applies to the underlying surface
398302a9df1d50373c82923bb84ff665dfce584fb22Romain Guy     * texture and does not affect the size or position of the view
399302a9df1d50373c82923bb84ff665dfce584fb22Romain Guy     * itself, only of its content.</p>
400302a9df1d50373c82923bb84ff665dfce584fb22Romain Guy     *
401302a9df1d50373c82923bb84ff665dfce584fb22Romain Guy     * <p>Some transforms might prevent the content from drawing
402302a9df1d50373c82923bb84ff665dfce584fb22Romain Guy     * all the pixels contained within this view's bounds. In such
403302a9df1d50373c82923bb84ff665dfce584fb22Romain Guy     * situations, make sure this texture view is not marked opaque.</p>
404302a9df1d50373c82923bb84ff665dfce584fb22Romain Guy     *
405302a9df1d50373c82923bb84ff665dfce584fb22Romain Guy     * @param transform The transform to apply to the content of
406302a9df1d50373c82923bb84ff665dfce584fb22Romain Guy     *        this view.
407302a9df1d50373c82923bb84ff665dfce584fb22Romain Guy     *
408302a9df1d50373c82923bb84ff665dfce584fb22Romain Guy     * @see #getTransform(android.graphics.Matrix)
409302a9df1d50373c82923bb84ff665dfce584fb22Romain Guy     * @see #isOpaque()
410302a9df1d50373c82923bb84ff665dfce584fb22Romain Guy     * @see #setOpaque(boolean)
411302a9df1d50373c82923bb84ff665dfce584fb22Romain Guy     */
412302a9df1d50373c82923bb84ff665dfce584fb22Romain Guy    public void setTransform(Matrix transform) {
413302a9df1d50373c82923bb84ff665dfce584fb22Romain Guy        mMatrix.set(transform);
414302a9df1d50373c82923bb84ff665dfce584fb22Romain Guy        mMatrixChanged = true;
415c01391fb4eb0eef33d142e89e060eac7e75de39dAlexandre Elias        invalidateParentIfNeeded();
416302a9df1d50373c82923bb84ff665dfce584fb22Romain Guy    }
417302a9df1d50373c82923bb84ff665dfce584fb22Romain Guy
418302a9df1d50373c82923bb84ff665dfce584fb22Romain Guy    /**
419302a9df1d50373c82923bb84ff665dfce584fb22Romain Guy     * Returns the transform associated with this texture view.
420302a9df1d50373c82923bb84ff665dfce584fb22Romain Guy     *
421302a9df1d50373c82923bb84ff665dfce584fb22Romain Guy     * @param transform The {@link Matrix} in which to copy the current
422302a9df1d50373c82923bb84ff665dfce584fb22Romain Guy     *        transform. Can be null.
423302a9df1d50373c82923bb84ff665dfce584fb22Romain Guy     *
424302a9df1d50373c82923bb84ff665dfce584fb22Romain Guy     * @return The specified matrix if not null or a new {@link Matrix}
425302a9df1d50373c82923bb84ff665dfce584fb22Romain Guy     *         instance otherwise.
426302a9df1d50373c82923bb84ff665dfce584fb22Romain Guy     *
427302a9df1d50373c82923bb84ff665dfce584fb22Romain Guy     * @see #setTransform(android.graphics.Matrix)
428302a9df1d50373c82923bb84ff665dfce584fb22Romain Guy     */
429302a9df1d50373c82923bb84ff665dfce584fb22Romain Guy    public Matrix getTransform(Matrix transform) {
430302a9df1d50373c82923bb84ff665dfce584fb22Romain Guy        if (transform == null) {
431302a9df1d50373c82923bb84ff665dfce584fb22Romain Guy            transform = new Matrix();
432302a9df1d50373c82923bb84ff665dfce584fb22Romain Guy        }
433302a9df1d50373c82923bb84ff665dfce584fb22Romain Guy
434302a9df1d50373c82923bb84ff665dfce584fb22Romain Guy        transform.set(mMatrix);
435302a9df1d50373c82923bb84ff665dfce584fb22Romain Guy
436302a9df1d50373c82923bb84ff665dfce584fb22Romain Guy        return transform;
437302a9df1d50373c82923bb84ff665dfce584fb22Romain Guy    }
438302a9df1d50373c82923bb84ff665dfce584fb22Romain Guy
439c01391fb4eb0eef33d142e89e060eac7e75de39dAlexandre Elias    private void applyTransformMatrix() {
440c01391fb4eb0eef33d142e89e060eac7e75de39dAlexandre Elias        if (mMatrixChanged) {
441c01391fb4eb0eef33d142e89e060eac7e75de39dAlexandre Elias            mLayer.setTransform(mMatrix);
442c01391fb4eb0eef33d142e89e060eac7e75de39dAlexandre Elias            mMatrixChanged = false;
443c01391fb4eb0eef33d142e89e060eac7e75de39dAlexandre Elias        }
444c01391fb4eb0eef33d142e89e060eac7e75de39dAlexandre Elias    }
445c01391fb4eb0eef33d142e89e060eac7e75de39dAlexandre Elias
446302a9df1d50373c82923bb84ff665dfce584fb22Romain Guy    /**
44777a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * <p>Returns a {@link android.graphics.Bitmap} representation of the content
44877a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * of the associated surface texture. If the surface texture is not available,
44977a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * this method returns null.</p>
45077a811610f99e21da7f88dafef60d09f345d0506Romain Guy     *
45177a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * <p>The bitmap returned by this method uses the {@link Bitmap.Config#ARGB_8888}
45277a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * pixel format and its dimensions are the same as this view's.</p>
45377a811610f99e21da7f88dafef60d09f345d0506Romain Guy     *
45477a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * <p><strong>Do not</strong> invoke this method from a drawing method
45577a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * ({@link #onDraw(android.graphics.Canvas)} for instance).</p>
45677a811610f99e21da7f88dafef60d09f345d0506Romain Guy     *
457d6b2a00dd43257d1498b09175bff63663f6cb861Romain Guy     * <p>If an error occurs during the copy, an empty bitmap will be returned.</p>
458d6b2a00dd43257d1498b09175bff63663f6cb861Romain Guy     *
45977a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * @return A valid {@link Bitmap.Config#ARGB_8888} bitmap, or null if the surface
46077a811610f99e21da7f88dafef60d09f345d0506Romain Guy     *         texture is not available or the width &lt;= 0 or the height &lt;= 0
46177a811610f99e21da7f88dafef60d09f345d0506Romain Guy     *
46277a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * @see #isAvailable()
46377a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * @see #getBitmap(android.graphics.Bitmap)
46477a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * @see #getBitmap(int, int)
46577a811610f99e21da7f88dafef60d09f345d0506Romain Guy     */
46677a811610f99e21da7f88dafef60d09f345d0506Romain Guy    public Bitmap getBitmap() {
46777a811610f99e21da7f88dafef60d09f345d0506Romain Guy        return getBitmap(getWidth(), getHeight());
46877a811610f99e21da7f88dafef60d09f345d0506Romain Guy    }
46977a811610f99e21da7f88dafef60d09f345d0506Romain Guy
47077a811610f99e21da7f88dafef60d09f345d0506Romain Guy    /**
47177a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * <p>Returns a {@link android.graphics.Bitmap} representation of the content
47277a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * of the associated surface texture. If the surface texture is not available,
47377a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * this method returns null.</p>
47477a811610f99e21da7f88dafef60d09f345d0506Romain Guy     *
47577a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * <p>The bitmap returned by this method uses the {@link Bitmap.Config#ARGB_8888}
47677a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * pixel format.</p>
47777a811610f99e21da7f88dafef60d09f345d0506Romain Guy     *
47877a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * <p><strong>Do not</strong> invoke this method from a drawing method
47977a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * ({@link #onDraw(android.graphics.Canvas)} for instance).</p>
48077a811610f99e21da7f88dafef60d09f345d0506Romain Guy     *
481d6b2a00dd43257d1498b09175bff63663f6cb861Romain Guy     * <p>If an error occurs during the copy, an empty bitmap will be returned.</p>
482d6b2a00dd43257d1498b09175bff63663f6cb861Romain Guy     *
48377a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * @param width The width of the bitmap to create
48477a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * @param height The height of the bitmap to create
48577a811610f99e21da7f88dafef60d09f345d0506Romain Guy     *
48677a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * @return A valid {@link Bitmap.Config#ARGB_8888} bitmap, or null if the surface
48777a811610f99e21da7f88dafef60d09f345d0506Romain Guy     *         texture is not available or width is &lt;= 0 or height is &lt;= 0
48877a811610f99e21da7f88dafef60d09f345d0506Romain Guy     *
48977a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * @see #isAvailable()
49077a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * @see #getBitmap(android.graphics.Bitmap)
49177a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * @see #getBitmap()
49277a811610f99e21da7f88dafef60d09f345d0506Romain Guy     */
49377a811610f99e21da7f88dafef60d09f345d0506Romain Guy    public Bitmap getBitmap(int width, int height) {
49477a811610f99e21da7f88dafef60d09f345d0506Romain Guy        if (isAvailable() && width > 0 && height > 0) {
49577a811610f99e21da7f88dafef60d09f345d0506Romain Guy            return getBitmap(Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888));
49677a811610f99e21da7f88dafef60d09f345d0506Romain Guy        }
49777a811610f99e21da7f88dafef60d09f345d0506Romain Guy        return null;
49877a811610f99e21da7f88dafef60d09f345d0506Romain Guy    }
49977a811610f99e21da7f88dafef60d09f345d0506Romain Guy
50077a811610f99e21da7f88dafef60d09f345d0506Romain Guy    /**
50177a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * <p>Copies the content of this view's surface texture into the specified
50277a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * bitmap. If the surface texture is not available, the copy is not executed.
50377a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * The content of the surface texture will be scaled to fit exactly inside
50477a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * the specified bitmap.</p>
50577a811610f99e21da7f88dafef60d09f345d0506Romain Guy     *
50677a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * <p><strong>Do not</strong> invoke this method from a drawing method
50777a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * ({@link #onDraw(android.graphics.Canvas)} for instance).</p>
50877a811610f99e21da7f88dafef60d09f345d0506Romain Guy     *
509d6b2a00dd43257d1498b09175bff63663f6cb861Romain Guy     * <p>If an error occurs, the bitmap is left unchanged.</p>
510d6b2a00dd43257d1498b09175bff63663f6cb861Romain Guy     *
51177a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * @param bitmap The bitmap to copy the content of the surface texture into,
51277a811610f99e21da7f88dafef60d09f345d0506Romain Guy     *               cannot be null, all configurations are supported
51377a811610f99e21da7f88dafef60d09f345d0506Romain Guy     *
51477a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * @return The bitmap specified as a parameter
51577a811610f99e21da7f88dafef60d09f345d0506Romain Guy     *
51677a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * @see #isAvailable()
51777a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * @see #getBitmap(int, int)
51877a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * @see #getBitmap()
519589b0bb6ab81657ba201cbc441a49f85305170bcRomain Guy     *
520589b0bb6ab81657ba201cbc441a49f85305170bcRomain Guy     * @throws IllegalStateException if the hardware rendering context cannot be
521589b0bb6ab81657ba201cbc441a49f85305170bcRomain Guy     *         acquired to capture the bitmap
52277a811610f99e21da7f88dafef60d09f345d0506Romain Guy     */
52377a811610f99e21da7f88dafef60d09f345d0506Romain Guy    public Bitmap getBitmap(Bitmap bitmap) {
52477a811610f99e21da7f88dafef60d09f345d0506Romain Guy        if (bitmap != null && isAvailable()) {
525589b0bb6ab81657ba201cbc441a49f85305170bcRomain Guy            AttachInfo info = mAttachInfo;
526589b0bb6ab81657ba201cbc441a49f85305170bcRomain Guy            if (info != null && info.mHardwareRenderer != null &&
527589b0bb6ab81657ba201cbc441a49f85305170bcRomain Guy                    info.mHardwareRenderer.isEnabled()) {
528589b0bb6ab81657ba201cbc441a49f85305170bcRomain Guy                if (!info.mHardwareRenderer.validate()) {
529589b0bb6ab81657ba201cbc441a49f85305170bcRomain Guy                    throw new IllegalStateException("Could not acquire hardware rendering context");
530589b0bb6ab81657ba201cbc441a49f85305170bcRomain Guy                }
531589b0bb6ab81657ba201cbc441a49f85305170bcRomain Guy            }
532589b0bb6ab81657ba201cbc441a49f85305170bcRomain Guy
533589b0bb6ab81657ba201cbc441a49f85305170bcRomain Guy            applyUpdate();
534589b0bb6ab81657ba201cbc441a49f85305170bcRomain Guy            applyTransformMatrix();
535589b0bb6ab81657ba201cbc441a49f85305170bcRomain Guy
53602ccac69fd1c0a03c24c5f3ace0ad4bed337b1fdRomain Guy            mLayer.copyInto(bitmap);
53777a811610f99e21da7f88dafef60d09f345d0506Romain Guy        }
53877a811610f99e21da7f88dafef60d09f345d0506Romain Guy        return bitmap;
53977a811610f99e21da7f88dafef60d09f345d0506Romain Guy    }
54077a811610f99e21da7f88dafef60d09f345d0506Romain Guy
54177a811610f99e21da7f88dafef60d09f345d0506Romain Guy    /**
54277a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * Returns true if the {@link SurfaceTexture} associated with this
54377a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * TextureView is available for rendering. When this method returns
54477a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * true, {@link #getSurfaceTexture()} returns a valid surface texture.
54577a811610f99e21da7f88dafef60d09f345d0506Romain Guy     */
54677a811610f99e21da7f88dafef60d09f345d0506Romain Guy    public boolean isAvailable() {
54777a811610f99e21da7f88dafef60d09f345d0506Romain Guy        return mSurface != null;
54877a811610f99e21da7f88dafef60d09f345d0506Romain Guy    }
54977a811610f99e21da7f88dafef60d09f345d0506Romain Guy
55077a811610f99e21da7f88dafef60d09f345d0506Romain Guy    /**
5516be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy     * <p>Start editing the pixels in the surface.  The returned Canvas can be used
5526be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy     * to draw into the surface's bitmap.  A null is returned if the surface has
5536be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy     * not been created or otherwise cannot be edited. You will usually need
5546be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy     * to implement
5556be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy     * {@link SurfaceTextureListener#onSurfaceTextureAvailable(android.graphics.SurfaceTexture, int, int)}
5566be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy     * to find out when the Surface is available for use.</p>
5576be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy     *
5586be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy     * <p>The content of the Surface is never preserved between unlockCanvas()
5596be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy     * and lockCanvas(), for this reason, every pixel within the Surface area
5606be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy     * must be written. The only exception to this rule is when a dirty
5616be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy     * rectangle is specified, in which case, non-dirty pixels will be
5626be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy     * preserved.</p>
563462785fa257671fe4905d1d3e6ca27e4a61ee946Romain Guy     *
564462785fa257671fe4905d1d3e6ca27e4a61ee946Romain Guy     * <p>This method can only be used if the underlying surface is not already
565462785fa257671fe4905d1d3e6ca27e4a61ee946Romain Guy     * owned by another producer. For instance, if the TextureView is being used
566462785fa257671fe4905d1d3e6ca27e4a61ee946Romain Guy     * to render the camera's preview you cannot invoke this method.</p>
5676be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy     *
5686be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy     * @return A Canvas used to draw into the surface.
5696be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy     *
5706be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy     * @see #lockCanvas(android.graphics.Rect)
5716be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy     * @see #unlockCanvasAndPost(android.graphics.Canvas)
5726be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy     */
5736be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy    public Canvas lockCanvas() {
5746be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy        return lockCanvas(null);
5756be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy    }
5766be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy
5776be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy    /**
5786be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy     * Just like {@link #lockCanvas()} but allows specification of a dirty
5796be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy     * rectangle. Every pixel within that rectangle must be written; however
5806be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy     * pixels outside the dirty rectangle will be preserved by the next call
5816be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy     * to lockCanvas().
5826be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy     *
5836be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy     * @param dirty Area of the surface that will be modified.
5846be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy
5856be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy     * @return A Canvas used to draw into the surface.
5866be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy     *
5876be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy     * @see #lockCanvas()
5886be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy     * @see #unlockCanvasAndPost(android.graphics.Canvas)
5896be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy     */
5906be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy    public Canvas lockCanvas(Rect dirty) {
5916be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy        if (!isAvailable()) return null;
5926be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy
5936be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy        if (mCanvas == null) {
5946be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy            mCanvas = new Canvas();
5956be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy        }
5966be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy
5976be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy        synchronized (mNativeWindowLock) {
5986be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy            nLockCanvas(mNativeWindow, mCanvas, dirty);
5996be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy        }
6006be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy        mSaveCount = mCanvas.save();
6016be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy
6026be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy        return mCanvas;
6036be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy    }
6046be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy
6056be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy    /**
6066be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy     * Finish editing pixels in the surface. After this call, the surface's
6076be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy     * current pixels will be shown on the screen, but its content is lost,
6086be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy     * in particular there is no guarantee that the content of the Surface
6096be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy     * will remain unchanged when lockCanvas() is called again.
6106be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy     *
6116be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy     * @param canvas The Canvas previously returned by lockCanvas()
6126be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy     *
6136be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy     * @see #lockCanvas()
6146be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy     * @see #lockCanvas(android.graphics.Rect)
6156be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy     */
6166be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy    public void unlockCanvasAndPost(Canvas canvas) {
6176be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy        if (mCanvas != null && canvas == mCanvas) {
6186be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy            canvas.restoreToCount(mSaveCount);
6196be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy            mSaveCount = 0;
6206be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy
6216be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy            synchronized (mNativeWindowLock) {
6226be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy                nUnlockCanvasAndPost(mNativeWindow, mCanvas);
6236be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy            }
6246be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy        }
6256be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy    }
6266be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy
6276be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy    /**
628aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     * Returns the {@link SurfaceTexture} used by this view. This method
62977a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * may return null if the view is not attached to a window or if the surface
63077a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * texture has not been initialized yet.
63177a811610f99e21da7f88dafef60d09f345d0506Romain Guy     *
63277a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * @see #isAvailable()
633aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     */
634aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    public SurfaceTexture getSurfaceTexture() {
635aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy        return mSurface;
636aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    }
637aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy
638aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    /**
639aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     * Returns the {@link SurfaceTextureListener} currently associated with this
640aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     * texture view.
641aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     *
642aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     * @see #setSurfaceTextureListener(android.view.TextureView.SurfaceTextureListener)
643aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     * @see SurfaceTextureListener
644aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     */
645aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    public SurfaceTextureListener getSurfaceTextureListener() {
646aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy        return mListener;
647aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    }
648aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy
649aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    /**
650aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     * Sets the {@link SurfaceTextureListener} used to listen to surface
651aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     * texture events.
652aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     *
653aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     * @see #getSurfaceTextureListener()
654aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     * @see SurfaceTextureListener
655aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     */
656aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    public void setSurfaceTextureListener(SurfaceTextureListener listener) {
657aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy        mListener = listener;
658aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    }
659aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy
660aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    /**
661aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     * This listener can be used to be notified when the surface texture
662aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     * associated with this texture view is available.
663aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     */
664aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    public static interface SurfaceTextureListener {
665aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy        /**
666aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy         * Invoked when a {@link TextureView}'s SurfaceTexture is ready for use.
667aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy         *
668aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy         * @param surface The surface returned by
669aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy         *                {@link android.view.TextureView#getSurfaceTexture()}
670451ce44a18e4c48f8a43aa250957f76967a35d31Romain Guy         * @param width The width of the surface
671451ce44a18e4c48f8a43aa250957f76967a35d31Romain Guy         * @param height The height of the surface
672aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy         */
673451ce44a18e4c48f8a43aa250957f76967a35d31Romain Guy        public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height);
6748f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy
6758f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy        /**
6768f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy         * Invoked when the {@link SurfaceTexture}'s buffers size changed.
6778f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy         *
6788f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy         * @param surface The surface returned by
6798f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy         *                {@link android.view.TextureView#getSurfaceTexture()}
6808f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy         * @param width The new width of the surface
6818f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy         * @param height The new height of the surface
6828f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy         */
6838f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy        public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height);
684451ce44a18e4c48f8a43aa250957f76967a35d31Romain Guy
685451ce44a18e4c48f8a43aa250957f76967a35d31Romain Guy        /**
686451ce44a18e4c48f8a43aa250957f76967a35d31Romain Guy         * Invoked when the specified {@link SurfaceTexture} is about to be destroyed.
687402f05530352f34d5320c2d23be43c274d97c4e2Grace Kloba         * If returns true, no rendering should happen inside the surface texture after this method
688402f05530352f34d5320c2d23be43c274d97c4e2Grace Kloba         * is invoked. If returns false, the client needs to call {@link SurfaceTexture#release()}.
689451ce44a18e4c48f8a43aa250957f76967a35d31Romain Guy         *
690451ce44a18e4c48f8a43aa250957f76967a35d31Romain Guy         * @param surface The surface about to be destroyed
691451ce44a18e4c48f8a43aa250957f76967a35d31Romain Guy         */
692402f05530352f34d5320c2d23be43c274d97c4e2Grace Kloba        public boolean onSurfaceTextureDestroyed(SurfaceTexture surface);
693cf559377b750271472aa0a717bf3b7d34abc0b39Grace Kloba
694cf559377b750271472aa0a717bf3b7d34abc0b39Grace Kloba        /**
695cf559377b750271472aa0a717bf3b7d34abc0b39Grace Kloba         * Invoked when the specified {@link SurfaceTexture} is updated through
696cf559377b750271472aa0a717bf3b7d34abc0b39Grace Kloba         * {@link SurfaceTexture#updateTexImage()}.
697cf559377b750271472aa0a717bf3b7d34abc0b39Grace Kloba         *
698cf559377b750271472aa0a717bf3b7d34abc0b39Grace Kloba         * @param surface The surface just updated
699cf559377b750271472aa0a717bf3b7d34abc0b39Grace Kloba         */
700cf559377b750271472aa0a717bf3b7d34abc0b39Grace Kloba        public void onSurfaceTextureUpdated(SurfaceTexture surface);
701aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    }
7028f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy
7036be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy    private native void nCreateNativeWindow(SurfaceTexture surface);
7046be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy    private native void nDestroyNativeWindow();
7056be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy
706d6b2a00dd43257d1498b09175bff63663f6cb861Romain Guy    private static native void nSetDefaultBufferSize(SurfaceTexture surfaceTexture,
707d6b2a00dd43257d1498b09175bff63663f6cb861Romain Guy            int width, int height);
7086be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy
7096be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy    private static native void nLockCanvas(int nativeWindow, Canvas canvas, Rect dirty);
7106be3d5561cbeccf0a8257a4acb155657f868e548Romain Guy    private static native void nUnlockCanvasAndPost(int nativeWindow, Canvas canvas);
711aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy}
712