SurfaceTexture.h revision 2560d14ce8e38984032d999e3fdf8da9a47baf3c
18ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis/*
28ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis * Copyright (C) 2010 The Android Open Source Project
38ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis *
48ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis * Licensed under the Apache License, Version 2.0 (the "License");
58ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis * you may not use this file except in compliance with the License.
68ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis * You may obtain a copy of the License at
78ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis *
88ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis *      http://www.apache.org/licenses/LICENSE-2.0
98ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis *
108ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis * Unless required by applicable law or agreed to in writing, software
118ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis * distributed under the License is distributed on an "AS IS" BASIS,
128ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
138ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis * See the License for the specific language governing permissions and
148ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis * limitations under the License.
158ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis */
168ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis
178ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis#ifndef ANDROID_GUI_SURFACETEXTURE_H
188ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis#define ANDROID_GUI_SURFACETEXTURE_H
198ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis
208ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis#include <EGL/egl.h>
218ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis#include <EGL/eglext.h>
228ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis#include <GLES2/gl2.h>
238ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis
248ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis#include <gui/ISurfaceTexture.h>
258ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis
268ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis#include <ui/GraphicBuffer.h>
278ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis
288ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis#include <utils/threads.h>
299a78c90cd46b2a3bd637b056873149d3b94384b4Jamie Gennis#include <utils/Vector.h>
308ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis
318ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis#define ANDROID_GRAPHICS_SURFACETEXTURE_JNI_ID "mSurfaceTexture"
328ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis
338ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennisnamespace android {
348ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis// ----------------------------------------------------------------------------
358ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis
369a78c90cd46b2a3bd637b056873149d3b94384b4Jamie Gennisclass IGraphicBufferAlloc;
3768c7794183a7dbfe3b20d4ce832f8eb79c2c619aMathias Agopianclass String8;
389a78c90cd46b2a3bd637b056873149d3b94384b4Jamie Gennis
398ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennisclass SurfaceTexture : public BnSurfaceTexture {
408ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennispublic:
419d4d6c101d90d4a1d1ca9413cf3eb89d1f1898d6Jamie Gennis    enum { MIN_UNDEQUEUED_BUFFERS = 2 };
428072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian    enum {
438072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian        MIN_ASYNC_BUFFER_SLOTS = MIN_UNDEQUEUED_BUFFERS + 1,
448072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian        MIN_SYNC_BUFFER_SLOTS  = MIN_UNDEQUEUED_BUFFERS
458072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian    };
468ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    enum { NUM_BUFFER_SLOTS = 32 };
47fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis    enum { NO_CONNECTED_API = 0 };
488ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis
49c4d4aeab52435c177ded6abdd578fec8191f0f5dJamie Gennis    struct FrameAvailableListener : public virtual RefBase {
503d8063b02e06020c8062addcc9ec49048d3bdb9aJamie Gennis        // onFrameAvailable() is called from queueBuffer() each time an
513d8063b02e06020c8062addcc9ec49048d3bdb9aJamie Gennis        // additional frame becomes available for consumption. This means that
523d8063b02e06020c8062addcc9ec49048d3bdb9aJamie Gennis        // frames that are queued while in asynchronous mode only trigger the
533d8063b02e06020c8062addcc9ec49048d3bdb9aJamie Gennis        // callback if no previous frames are pending. Frames queued while in
543d8063b02e06020c8062addcc9ec49048d3bdb9aJamie Gennis        // synchronous mode always trigger the callback.
553d8063b02e06020c8062addcc9ec49048d3bdb9aJamie Gennis        //
563d8063b02e06020c8062addcc9ec49048d3bdb9aJamie Gennis        // This is called without any lock held and can be called concurrently
573d8063b02e06020c8062addcc9ec49048d3bdb9aJamie Gennis        // by multiple threads.
58c4d4aeab52435c177ded6abdd578fec8191f0f5dJamie Gennis        virtual void onFrameAvailable() = 0;
59c4d4aeab52435c177ded6abdd578fec8191f0f5dJamie Gennis    };
60c4d4aeab52435c177ded6abdd578fec8191f0f5dJamie Gennis
618ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    // tex indicates the name OpenGL texture to which images are to be streamed.
628ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    // This texture name cannot be changed once the SurfaceTexture is created.
6314a0e58074f2698829b6554f578e6762c377caa3Grace Kloba    SurfaceTexture(GLuint tex, bool allowSynchronousMode = true);
648ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis
658ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    virtual ~SurfaceTexture();
668ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis
678ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    // setBufferCount updates the number of available buffer slots.  After
688ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    // calling this all buffer slots are both unallocated and owned by the
698ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    // SurfaceTexture object (i.e. they are not owned by the client).
708ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    virtual status_t setBufferCount(int bufferCount);
718ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis
727b305fffc39d0fe0926e7fd2d7f6a524fbce62b7Jamie Gennis    virtual status_t requestBuffer(int slot, sp<GraphicBuffer>* buf);
738ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis
748ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    // dequeueBuffer gets the next buffer slot index for the client to use. If a
758ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    // buffer slot is available then that slot index is written to the location
768ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    // pointed to by the buf argument and a status of OK is returned.  If no
778ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    // slot is available then a status of -EBUSY is returned and buf is
788ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    // unmodified.
79c04f153353cdb0d291297d10452239f791d3fd2bMathias Agopian    virtual status_t dequeueBuffer(int *buf, uint32_t w, uint32_t h,
80c04f153353cdb0d291297d10452239f791d3fd2bMathias Agopian            uint32_t format, uint32_t usage);
818ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis
821d01a12e7150be569557b64da9b8663c62c13594Eino-Ville Talvala    // queueBuffer returns a filled buffer to the SurfaceTexture. In addition, a
831d01a12e7150be569557b64da9b8663c62c13594Eino-Ville Talvala    // timestamp must be provided for the buffer. The timestamp is in
841d01a12e7150be569557b64da9b8663c62c13594Eino-Ville Talvala    // nanoseconds, and must be monotonically increasing. Its other semantics
851d01a12e7150be569557b64da9b8663c62c13594Eino-Ville Talvala    // (zero point, etc) are client-dependent and should be documented by the
861d01a12e7150be569557b64da9b8663c62c13594Eino-Ville Talvala    // client.
8797c602c5af5f3ffd69009bf496d86347b71a2b4cMathias Agopian    virtual status_t queueBuffer(int buf, int64_t timestamp,
8897c602c5af5f3ffd69009bf496d86347b71a2b4cMathias Agopian            uint32_t* outWidth, uint32_t* outHeight, uint32_t* outTransform);
898ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    virtual void cancelBuffer(int buf);
908ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    virtual status_t setCrop(const Rect& reg);
918ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    virtual status_t setTransform(uint32_t transform);
927734ebfe47f42f980c1b44c1f284a91d8ad1d6c7Mathias Agopian    virtual status_t setScalingMode(int mode);
938ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis
94eafabcdc1639fb96062d9e3c39b0ae27b0238ae1Mathias Agopian    virtual int query(int what, int* value);
95eafabcdc1639fb96062d9e3c39b0ae27b0238ae1Mathias Agopian
968072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian    // setSynchronousMode set whether dequeueBuffer is synchronous or
978072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian    // asynchronous. In synchronous mode, dequeueBuffer blocks until
988072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian    // a buffer is available, the currently bound buffer can be dequeued and
998072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian    // queued buffers will be retired in order.
1008072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian    // The default mode is asynchronous.
1018072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian    virtual status_t setSynchronousMode(bool enabled);
1028072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian
103fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis    // connect attempts to connect a client API to the SurfaceTexture.  This
104fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis    // must be called before any other ISurfaceTexture methods are called except
105fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis    // for getAllocator.
106fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis    //
107fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis    // This method will fail if the connect was previously called on the
108fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis    // SurfaceTexture and no corresponding disconnect call was made.
1095bfc24515bb5c8ea7975f72d538df37753733a2fMathias Agopian    virtual status_t connect(int api,
1105bfc24515bb5c8ea7975f72d538df37753733a2fMathias Agopian            uint32_t* outWidth, uint32_t* outHeight, uint32_t* outTransform);
111fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis
112fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis    // disconnect attempts to disconnect a client API from the SurfaceTexture.
113fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis    // Calling this method will cause any subsequent calls to other
114fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis    // ISurfaceTexture methods to fail except for getAllocator and connect.
115fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis    // Successfully calling connect after this will allow the other methods to
116fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis    // succeed again.
117fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis    //
118fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis    // This method will fail if the the SurfaceTexture is not currently
119fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis    // connected to the specified client API.
120fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis    virtual status_t disconnect(int api);
121fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis
1228ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    // updateTexImage sets the image contents of the target texture to that of
1238ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    // the most recently queued buffer.
1248ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    //
1258ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    // This call may only be made while the OpenGL ES context to which the
1268ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    // target texture belongs is bound to the calling thread.
1278ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    status_t updateTexImage();
1288ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis
1298072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian    // setBufferCountServer set the buffer count. If the client has requested
1308072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian    // a buffer count using setBufferCount, the server-buffer count will
1318072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian    // take effect once the client sets the count back to zero.
1328072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian    status_t setBufferCountServer(int bufferCount);
1338072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian
134f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis    // getTransformMatrix retrieves the 4x4 texture coordinate transform matrix
135f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis    // associated with the texture image set by the most recent call to
136f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis    // updateTexImage.
137f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis    //
138f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis    // This transform matrix maps 2D homogeneous texture coordinates of the form
139f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis    // (s, t, 0, 1) with s and t in the inclusive range [0, 1] to the texture
140f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis    // coordinate that should be used to sample that location from the texture.
141f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis    // Sampling the texture outside of the range of this transform is undefined.
142f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis    //
143f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis    // This transform is necessary to compensate for transforms that the stream
144f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis    // content producer may implicitly apply to the content. By forcing users of
145f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis    // a SurfaceTexture to apply this transform we avoid performing an extra
146f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis    // copy of the data that would be needed to hide the transform from the
147f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis    // user.
148f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis    //
149f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis    // The matrix is stored in column-major order so that it may be passed
150f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis    // directly to OpenGL ES via the glLoadMatrixf or glUniformMatrix4fv
151f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis    // functions.
152f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis    void getTransformMatrix(float mtx[16]);
153f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis
1541d01a12e7150be569557b64da9b8663c62c13594Eino-Ville Talvala    // getTimestamp retrieves the timestamp associated with the texture image
1551d01a12e7150be569557b64da9b8663c62c13594Eino-Ville Talvala    // set by the most recent call to updateTexImage.
1561d01a12e7150be569557b64da9b8663c62c13594Eino-Ville Talvala    //
1571d01a12e7150be569557b64da9b8663c62c13594Eino-Ville Talvala    // The timestamp is in nanoseconds, and is monotonically increasing. Its
1581d01a12e7150be569557b64da9b8663c62c13594Eino-Ville Talvala    // other semantics (zero point, etc) are source-dependent and should be
1591d01a12e7150be569557b64da9b8663c62c13594Eino-Ville Talvala    // documented by the source.
1601d01a12e7150be569557b64da9b8663c62c13594Eino-Ville Talvala    int64_t getTimestamp();
1611d01a12e7150be569557b64da9b8663c62c13594Eino-Ville Talvala
162c4d4aeab52435c177ded6abdd578fec8191f0f5dJamie Gennis    // setFrameAvailableListener sets the listener object that will be notified
163c4d4aeab52435c177ded6abdd578fec8191f0f5dJamie Gennis    // when a new frame becomes available.
164292a31a4c2ae2f6faf134e8e4a726583017dad06Pannag Sanketi    void setFrameAvailableListener(const sp<FrameAvailableListener>& listener);
165c4d4aeab52435c177ded6abdd578fec8191f0f5dJamie Gennis
1661b20cde313b5ef8acdace742328df867956d24cbJamie Gennis    // getAllocator retrieves the binder object that must be referenced as long
1671b20cde313b5ef8acdace742328df867956d24cbJamie Gennis    // as the GraphicBuffers dequeued from this SurfaceTexture are referenced.
1681b20cde313b5ef8acdace742328df867956d24cbJamie Gennis    // Holding this binder reference prevents SurfaceFlinger from freeing the
1691b20cde313b5ef8acdace742328df867956d24cbJamie Gennis    // buffers before the client is done with them.
1701b20cde313b5ef8acdace742328df867956d24cbJamie Gennis    sp<IBinder> getAllocator();
1711b20cde313b5ef8acdace742328df867956d24cbJamie Gennis
172a5c75c01620179ce00812354778a29a80d76e71fMathias Agopian    // setDefaultBufferSize is used to set the size of buffers returned by
173a5c75c01620179ce00812354778a29a80d76e71fMathias Agopian    // requestBuffers when a with and height of zero is requested.
174a5c75c01620179ce00812354778a29a80d76e71fMathias Agopian    // A call to setDefaultBufferSize() may trigger requestBuffers() to
175a5c75c01620179ce00812354778a29a80d76e71fMathias Agopian    // be called from the client.
176a5c75c01620179ce00812354778a29a80d76e71fMathias Agopian    status_t setDefaultBufferSize(uint32_t w, uint32_t h);
177a5c75c01620179ce00812354778a29a80d76e71fMathias Agopian
1787a042bf324fe3f3d5d4085fda21fe50dc0c362b4Mathias Agopian    // getCurrentBuffer returns the buffer associated with the current image.
1797a042bf324fe3f3d5d4085fda21fe50dc0c362b4Mathias Agopian    sp<GraphicBuffer> getCurrentBuffer() const;
1807a042bf324fe3f3d5d4085fda21fe50dc0c362b4Mathias Agopian
1817a042bf324fe3f3d5d4085fda21fe50dc0c362b4Mathias Agopian    // getCurrentTextureTarget returns the texture target of the current
1827a042bf324fe3f3d5d4085fda21fe50dc0c362b4Mathias Agopian    // texture as returned by updateTexImage().
1837a042bf324fe3f3d5d4085fda21fe50dc0c362b4Mathias Agopian    GLenum getCurrentTextureTarget() const;
1847a042bf324fe3f3d5d4085fda21fe50dc0c362b4Mathias Agopian
1857a042bf324fe3f3d5d4085fda21fe50dc0c362b4Mathias Agopian    // getCurrentCrop returns the cropping rectangle of the current buffer
1867a042bf324fe3f3d5d4085fda21fe50dc0c362b4Mathias Agopian    Rect getCurrentCrop() const;
1877a042bf324fe3f3d5d4085fda21fe50dc0c362b4Mathias Agopian
1887a042bf324fe3f3d5d4085fda21fe50dc0c362b4Mathias Agopian    // getCurrentTransform returns the transform of the current buffer
1897a042bf324fe3f3d5d4085fda21fe50dc0c362b4Mathias Agopian    uint32_t getCurrentTransform() const;
1907a042bf324fe3f3d5d4085fda21fe50dc0c362b4Mathias Agopian
1917734ebfe47f42f980c1b44c1f284a91d8ad1d6c7Mathias Agopian    // getCurrentScalingMode returns the scaling mode of the current buffer
1927734ebfe47f42f980c1b44c1f284a91d8ad1d6c7Mathias Agopian    uint32_t getCurrentScalingMode() const;
1937734ebfe47f42f980c1b44c1f284a91d8ad1d6c7Mathias Agopian
1947b305fffc39d0fe0926e7fd2d7f6a524fbce62b7Jamie Gennis    // abandon frees all the buffers and puts the SurfaceTexture into the
1957b305fffc39d0fe0926e7fd2d7f6a524fbce62b7Jamie Gennis    // 'abandoned' state.  Once put in this state the SurfaceTexture can never
1967b305fffc39d0fe0926e7fd2d7f6a524fbce62b7Jamie Gennis    // leave it.  When in the 'abandoned' state, all methods of the
1977b305fffc39d0fe0926e7fd2d7f6a524fbce62b7Jamie Gennis    // ISurfaceTexture interface will fail with the NO_INIT error.
1987b305fffc39d0fe0926e7fd2d7f6a524fbce62b7Jamie Gennis    //
1997b305fffc39d0fe0926e7fd2d7f6a524fbce62b7Jamie Gennis    // Note that while calling this method causes all the buffers to be freed
2007b305fffc39d0fe0926e7fd2d7f6a524fbce62b7Jamie Gennis    // from the perspective of the the SurfaceTexture, if there are additional
2017b305fffc39d0fe0926e7fd2d7f6a524fbce62b7Jamie Gennis    // references on the buffers (e.g. if a buffer is referenced by a client or
2027b305fffc39d0fe0926e7fd2d7f6a524fbce62b7Jamie Gennis    // by OpenGL ES as a texture) then those buffer will remain allocated.
2037b305fffc39d0fe0926e7fd2d7f6a524fbce62b7Jamie Gennis    void abandon();
2047b305fffc39d0fe0926e7fd2d7f6a524fbce62b7Jamie Gennis
20568c7794183a7dbfe3b20d4ce832f8eb79c2c619aMathias Agopian    // dump our state in a String
20668c7794183a7dbfe3b20d4ce832f8eb79c2c619aMathias Agopian    void dump(String8& result) const;
20768c7794183a7dbfe3b20d4ce832f8eb79c2c619aMathias Agopian    void dump(String8& result, const char* prefix, char* buffer, size_t SIZE) const;
20868c7794183a7dbfe3b20d4ce832f8eb79c2c619aMathias Agopian
2097a042bf324fe3f3d5d4085fda21fe50dc0c362b4Mathias Agopianprotected:
2108ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis
2118ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    // freeAllBuffers frees the resources (both GraphicBuffer and EGLImage) for
2128ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    // all slots.
213ef51b992192adf4fc432686ab346f5fc7a13bc95Mathias Agopian    void freeAllBuffersLocked();
2142560d14ce8e38984032d999e3fdf8da9a47baf3cMathias Agopian
2152560d14ce8e38984032d999e3fdf8da9a47baf3cMathias Agopian    // drainQueueLocked drains the buffer queue if we're in synchronous mode
2162560d14ce8e38984032d999e3fdf8da9a47baf3cMathias Agopian    // returns immediately otherwise.
2172560d14ce8e38984032d999e3fdf8da9a47baf3cMathias Agopian    void drainQueueLocked();
2182560d14ce8e38984032d999e3fdf8da9a47baf3cMathias Agopian
2197a042bf324fe3f3d5d4085fda21fe50dc0c362b4Mathias Agopian    static bool isExternalFormat(uint32_t format);
2207a042bf324fe3f3d5d4085fda21fe50dc0c362b4Mathias Agopian
2217a042bf324fe3f3d5d4085fda21fe50dc0c362b4Mathias Agopianprivate:
2228ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis
2238ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    // createImage creates a new EGLImage from a GraphicBuffer.
2248ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    EGLImageKHR createImage(EGLDisplay dpy,
2258ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis            const sp<GraphicBuffer>& graphicBuffer);
2268ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis
2278072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian    status_t setBufferCountServerLocked(int bufferCount);
2288072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian
229736aa9573bb7b78f9c315f396c104491b3639426Jamie Gennis    // computeCurrentTransformMatrix computes the transform matrix for the
230736aa9573bb7b78f9c315f396c104491b3639426Jamie Gennis    // current texture.  It uses mCurrentTransform and the current GraphicBuffer
231736aa9573bb7b78f9c315f396c104491b3639426Jamie Gennis    // to compute this matrix and stores it in mCurrentTransformMatrix.
232736aa9573bb7b78f9c315f396c104491b3639426Jamie Gennis    void computeCurrentTransformMatrix();
233736aa9573bb7b78f9c315f396c104491b3639426Jamie Gennis
2348ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    enum { INVALID_BUFFER_SLOT = -1 };
2358ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis
2368ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    struct BufferSlot {
237b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian
238b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian        BufferSlot()
239b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian            : mEglImage(EGL_NO_IMAGE_KHR),
240b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian              mEglDisplay(EGL_NO_DISPLAY),
241b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian              mBufferState(BufferSlot::FREE),
242b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian              mRequestBufferCalled(false),
2438cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis              mTransform(0),
2447734ebfe47f42f980c1b44c1f284a91d8ad1d6c7Mathias Agopian              mScalingMode(NATIVE_WINDOW_SCALING_MODE_FREEZE),
2458cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis              mTimestamp(0) {
2468cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis            mCrop.makeInvalid();
247b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian        }
248b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian
2498ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis        // mGraphicBuffer points to the buffer allocated for this slot or is NULL
2508ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis        // if no buffer has been allocated.
2518ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis        sp<GraphicBuffer> mGraphicBuffer;
2528ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis
2538ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis        // mEglImage is the EGLImage created from mGraphicBuffer.
2548ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis        EGLImageKHR mEglImage;
2558ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis
2568ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis        // mEglDisplay is the EGLDisplay used to create mEglImage.
2578ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis        EGLDisplay mEglDisplay;
2588ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis
2598cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis        // BufferState represents the different states in which a buffer slot
2608cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis        // can be.
2618cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis        enum BufferState {
2628cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis            // FREE indicates that the buffer is not currently being used and
2638cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis            // will not be used in the future until it gets dequeued and
2648cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis            // subseqently queued by the client.
2658cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis            FREE = 0,
2668cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis
2678cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis            // DEQUEUED indicates that the buffer has been dequeued by the
2688cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis            // client, but has not yet been queued or canceled. The buffer is
2698cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis            // considered 'owned' by the client, and the server should not use
2708cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis            // it for anything.
2718cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis            //
2728cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis            // Note that when in synchronous-mode (mSynchronousMode == true),
2738cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis            // the buffer that's currently attached to the texture may be
2748cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis            // dequeued by the client.  That means that the current buffer can
2758cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis            // be in either the DEQUEUED or QUEUED state.  In asynchronous mode,
2768cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis            // however, the current buffer is always in the QUEUED state.
2778cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis            DEQUEUED = 1,
2788cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis
2798cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis            // QUEUED indicates that the buffer has been queued by the client,
2808cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis            // and has not since been made available for the client to dequeue.
2818cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis            // Attaching the buffer to the texture does NOT transition the
2828cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis            // buffer away from the QUEUED state. However, in Synchronous mode
2838cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis            // the current buffer may be dequeued by the client under some
2848cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis            // circumstances. See the note about the current buffer in the
2858cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis            // documentation for DEQUEUED.
2868cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis            QUEUED = 2,
2878cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis        };
2888cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis
2898cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis        // mBufferState is the current state of this buffer slot.
2908cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis        BufferState mBufferState;
291b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian
292b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian        // mRequestBufferCalled is used for validating that the client did
293b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian        // call requestBuffer() when told to do so. Technically this is not
294b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian        // needed but useful for debugging and catching client bugs.
295b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian        bool mRequestBufferCalled;
296b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian
2978cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis        // mCrop is the current crop rectangle for this buffer slot. This gets
2988cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis        // set to mNextCrop each time queueBuffer gets called for this buffer.
2998cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis        Rect mCrop;
300b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian
3018cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis        // mTransform is the current transform flags for this buffer slot. This
3028cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis        // gets set to mNextTransform each time queueBuffer gets called for this
3038cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis        // slot.
3048cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis        uint32_t mTransform;
305b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian
3067734ebfe47f42f980c1b44c1f284a91d8ad1d6c7Mathias Agopian        // mScalingMode is the current scaling mode for this buffer slot. This
3077734ebfe47f42f980c1b44c1f284a91d8ad1d6c7Mathias Agopian        // gets set to mNextScalingMode each time queueBuffer gets called for
3087734ebfe47f42f980c1b44c1f284a91d8ad1d6c7Mathias Agopian        // this slot.
3097734ebfe47f42f980c1b44c1f284a91d8ad1d6c7Mathias Agopian        uint32_t mScalingMode;
3107734ebfe47f42f980c1b44c1f284a91d8ad1d6c7Mathias Agopian
3118cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis        // mTimestamp is the current timestamp for this buffer slot. This gets
3128cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis        // to set by queueBuffer each time this slot is queued.
3138cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis        int64_t mTimestamp;
3148ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    };
3158ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis
3168ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    // mSlots is the array of buffer slots that must be mirrored on the client
3178ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    // side. This allows buffer ownership to be transferred between the client
3188ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    // and server without sending a GraphicBuffer over binder. The entire array
3198ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    // is initialized to NULL at construction time, and buffers are allocated
3208ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    // for a slot when requestBuffer is called with that slot's index.
3218ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    BufferSlot mSlots[NUM_BUFFER_SLOTS];
3228ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis
323a5c75c01620179ce00812354778a29a80d76e71fMathias Agopian    // mDefaultWidth holds the default width of allocated buffers. It is used
324a5c75c01620179ce00812354778a29a80d76e71fMathias Agopian    // in requestBuffers() if a width and height of zero is specified.
325a5c75c01620179ce00812354778a29a80d76e71fMathias Agopian    uint32_t mDefaultWidth;
326a5c75c01620179ce00812354778a29a80d76e71fMathias Agopian
327a5c75c01620179ce00812354778a29a80d76e71fMathias Agopian    // mDefaultHeight holds the default height of allocated buffers. It is used
328a5c75c01620179ce00812354778a29a80d76e71fMathias Agopian    // in requestBuffers() if a width and height of zero is specified.
329a5c75c01620179ce00812354778a29a80d76e71fMathias Agopian    uint32_t mDefaultHeight;
330a5c75c01620179ce00812354778a29a80d76e71fMathias Agopian
331a5c75c01620179ce00812354778a29a80d76e71fMathias Agopian    // mPixelFormat holds the pixel format of allocated buffers. It is used
332a5c75c01620179ce00812354778a29a80d76e71fMathias Agopian    // in requestBuffers() if a format of zero is specified.
333a5c75c01620179ce00812354778a29a80d76e71fMathias Agopian    uint32_t mPixelFormat;
334a5c75c01620179ce00812354778a29a80d76e71fMathias Agopian
3358ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    // mBufferCount is the number of buffer slots that the client and server
3368072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian    // must maintain. It defaults to MIN_ASYNC_BUFFER_SLOTS and can be changed
3378072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian    // by calling setBufferCount or setBufferCountServer
3388ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    int mBufferCount;
3398ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis
340ae468f43418c3cbae74c7f546283f6bb4e4df690Jamie Gennis    // mClientBufferCount is the number of buffer slots requested by the client.
341ae468f43418c3cbae74c7f546283f6bb4e4df690Jamie Gennis    // The default is zero, which means the client doesn't care how many buffers
342ae468f43418c3cbae74c7f546283f6bb4e4df690Jamie Gennis    // there is.
3438072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian    int mClientBufferCount;
3448072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian
3458072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian    // mServerBufferCount buffer count requested by the server-side
3468072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian    int mServerBufferCount;
3478072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian
3488ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    // mCurrentTexture is the buffer slot index of the buffer that is currently
34967eedd74ab78c2bfed9fcdc74947b97289254ca4Jamie Gennis    // bound to the OpenGL texture. It is initialized to INVALID_BUFFER_SLOT,
35067eedd74ab78c2bfed9fcdc74947b97289254ca4Jamie Gennis    // indicating that no buffer slot is currently bound to the texture. Note,
35167eedd74ab78c2bfed9fcdc74947b97289254ca4Jamie Gennis    // however, that a value of INVALID_BUFFER_SLOT does not necessarily mean
35267eedd74ab78c2bfed9fcdc74947b97289254ca4Jamie Gennis    // that no buffer is bound to the texture. A call to setBufferCount will
35367eedd74ab78c2bfed9fcdc74947b97289254ca4Jamie Gennis    // reset mCurrentTexture to INVALID_BUFFER_SLOT.
3548ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    int mCurrentTexture;
3558ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis
3569a78c90cd46b2a3bd637b056873149d3b94384b4Jamie Gennis    // mCurrentTextureBuf is the graphic buffer of the current texture. It's
3579a78c90cd46b2a3bd637b056873149d3b94384b4Jamie Gennis    // possible that this buffer is not associated with any buffer slot, so we
35829c870271e8d3f8c40c356283650ba54fe71a16bJamie Gennis    // must track it separately in order to support the getCurrentBuffer method.
3599a78c90cd46b2a3bd637b056873149d3b94384b4Jamie Gennis    sp<GraphicBuffer> mCurrentTextureBuf;
3609a78c90cd46b2a3bd637b056873149d3b94384b4Jamie Gennis
361f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis    // mCurrentCrop is the crop rectangle that applies to the current texture.
3627734ebfe47f42f980c1b44c1f284a91d8ad1d6c7Mathias Agopian    // It gets set each time updateTexImage is called.
363f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis    Rect mCurrentCrop;
364f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis
365f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis    // mCurrentTransform is the transform identifier for the current texture. It
3667734ebfe47f42f980c1b44c1f284a91d8ad1d6c7Mathias Agopian    // gets set each time updateTexImage is called.
367f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis    uint32_t mCurrentTransform;
368f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis
3697734ebfe47f42f980c1b44c1f284a91d8ad1d6c7Mathias Agopian    // mCurrentScalingMode is the scaling mode for the current texture. It gets
3707734ebfe47f42f980c1b44c1f284a91d8ad1d6c7Mathias Agopian    // set to each time updateTexImage is called.
3717734ebfe47f42f980c1b44c1f284a91d8ad1d6c7Mathias Agopian    uint32_t mCurrentScalingMode;
3727734ebfe47f42f980c1b44c1f284a91d8ad1d6c7Mathias Agopian
373736aa9573bb7b78f9c315f396c104491b3639426Jamie Gennis    // mCurrentTransformMatrix is the transform matrix for the current texture.
374736aa9573bb7b78f9c315f396c104491b3639426Jamie Gennis    // It gets computed by computeTransformMatrix each time updateTexImage is
375736aa9573bb7b78f9c315f396c104491b3639426Jamie Gennis    // called.
376736aa9573bb7b78f9c315f396c104491b3639426Jamie Gennis    float mCurrentTransformMatrix[16];
377736aa9573bb7b78f9c315f396c104491b3639426Jamie Gennis
3781d01a12e7150be569557b64da9b8663c62c13594Eino-Ville Talvala    // mCurrentTimestamp is the timestamp for the current texture. It
3797734ebfe47f42f980c1b44c1f284a91d8ad1d6c7Mathias Agopian    // gets set each time updateTexImage is called.
3801d01a12e7150be569557b64da9b8663c62c13594Eino-Ville Talvala    int64_t mCurrentTimestamp;
3811d01a12e7150be569557b64da9b8663c62c13594Eino-Ville Talvala
382f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis    // mNextCrop is the crop rectangle that will be used for the next buffer
383f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis    // that gets queued. It is set by calling setCrop.
384f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis    Rect mNextCrop;
385f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis
386f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis    // mNextTransform is the transform identifier that will be used for the next
387f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis    // buffer that gets queued. It is set by calling setTransform.
388f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis    uint32_t mNextTransform;
389f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis
3907734ebfe47f42f980c1b44c1f284a91d8ad1d6c7Mathias Agopian    // mNextScalingMode is the scaling mode that will be used for the next
3917734ebfe47f42f980c1b44c1f284a91d8ad1d6c7Mathias Agopian    // buffers that get queued. It is set by calling setScalingMode.
3927734ebfe47f42f980c1b44c1f284a91d8ad1d6c7Mathias Agopian    int mNextScalingMode;
3937734ebfe47f42f980c1b44c1f284a91d8ad1d6c7Mathias Agopian
3948ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    // mTexName is the name of the OpenGL texture to which streamed images will
395292a31a4c2ae2f6faf134e8e4a726583017dad06Pannag Sanketi    // be bound when updateTexImage is called. It is set at construction time
3968ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    // changed with a call to setTexName.
3978ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    const GLuint mTexName;
3988ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis
3999a78c90cd46b2a3bd637b056873149d3b94384b4Jamie Gennis    // mGraphicBufferAlloc is the connection to SurfaceFlinger that is used to
4009a78c90cd46b2a3bd637b056873149d3b94384b4Jamie Gennis    // allocate new GraphicBuffer objects.
4019a78c90cd46b2a3bd637b056873149d3b94384b4Jamie Gennis    sp<IGraphicBufferAlloc> mGraphicBufferAlloc;
4029a78c90cd46b2a3bd637b056873149d3b94384b4Jamie Gennis
403c4d4aeab52435c177ded6abdd578fec8191f0f5dJamie Gennis    // mFrameAvailableListener is the listener object that will be called when a
404c4d4aeab52435c177ded6abdd578fec8191f0f5dJamie Gennis    // new frame becomes available. If it is not NULL it will be called from
405c4d4aeab52435c177ded6abdd578fec8191f0f5dJamie Gennis    // queueBuffer.
406c4d4aeab52435c177ded6abdd578fec8191f0f5dJamie Gennis    sp<FrameAvailableListener> mFrameAvailableListener;
407c4d4aeab52435c177ded6abdd578fec8191f0f5dJamie Gennis
408b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian    // mSynchronousMode whether we're in synchronous mode or not
409b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian    bool mSynchronousMode;
410b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian
41114a0e58074f2698829b6554f578e6762c377caa3Grace Kloba    // mAllowSynchronousMode whether we allow synchronous mode or not
41214a0e58074f2698829b6554f578e6762c377caa3Grace Kloba    const bool mAllowSynchronousMode;
41314a0e58074f2698829b6554f578e6762c377caa3Grace Kloba
414fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis    // mConnectedApi indicates the API that is currently connected to this
415fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis    // SurfaceTexture.  It defaults to NO_CONNECTED_API (= 0), and gets updated
416fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis    // by the connect and disconnect methods.
417fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis    int mConnectedApi;
418fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis
419b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian    // mDequeueCondition condition used for dequeueBuffer in synchronous mode
420b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian    mutable Condition mDequeueCondition;
421b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian
422b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian    // mQueue is a FIFO of queued buffers used in synchronous mode
423b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian    typedef Vector<int> Fifo;
424b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian    Fifo mQueue;
425b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian
4267b305fffc39d0fe0926e7fd2d7f6a524fbce62b7Jamie Gennis    // mAbandoned indicates that the SurfaceTexture will no longer be used to
4277b305fffc39d0fe0926e7fd2d7f6a524fbce62b7Jamie Gennis    // consume images buffers pushed to it using the ISurfaceTexture interface.
4287b305fffc39d0fe0926e7fd2d7f6a524fbce62b7Jamie Gennis    // It is initialized to false, and set to true in the abandon method.  A
4297b305fffc39d0fe0926e7fd2d7f6a524fbce62b7Jamie Gennis    // SurfaceTexture that has been abandoned will return the NO_INIT error from
4307b305fffc39d0fe0926e7fd2d7f6a524fbce62b7Jamie Gennis    // all ISurfaceTexture methods capable of returning an error.
4317b305fffc39d0fe0926e7fd2d7f6a524fbce62b7Jamie Gennis    bool mAbandoned;
4327b305fffc39d0fe0926e7fd2d7f6a524fbce62b7Jamie Gennis
4338ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    // mMutex is the mutex used to prevent concurrent access to the member
4348ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    // variables of SurfaceTexture objects. It must be locked whenever the
4358ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    // member variables are accessed.
4367a042bf324fe3f3d5d4085fda21fe50dc0c362b4Mathias Agopian    mutable Mutex mMutex;
437736aa9573bb7b78f9c315f396c104491b3639426Jamie Gennis
4388ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis};
4398ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis
4408ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis// ----------------------------------------------------------------------------
4418ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis}; // namespace android
4428ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis
4438ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis#endif // ANDROID_GUI_SURFACETEXTURE_H
444