SurfaceTexture.h revision 5bfc24515bb5c8ea7975f72d538df37753733a2f
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. 2138ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis void freeAllBuffers(); 2147a042bf324fe3f3d5d4085fda21fe50dc0c362b4Mathias Agopian static bool isExternalFormat(uint32_t format); 2157a042bf324fe3f3d5d4085fda21fe50dc0c362b4Mathias Agopian 2167a042bf324fe3f3d5d4085fda21fe50dc0c362b4Mathias Agopianprivate: 2178ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 2188ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis // createImage creates a new EGLImage from a GraphicBuffer. 2198ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis EGLImageKHR createImage(EGLDisplay dpy, 2208ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis const sp<GraphicBuffer>& graphicBuffer); 2218ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 2228072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian status_t setBufferCountServerLocked(int bufferCount); 2238072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian 224736aa9573bb7b78f9c315f396c104491b3639426Jamie Gennis // computeCurrentTransformMatrix computes the transform matrix for the 225736aa9573bb7b78f9c315f396c104491b3639426Jamie Gennis // current texture. It uses mCurrentTransform and the current GraphicBuffer 226736aa9573bb7b78f9c315f396c104491b3639426Jamie Gennis // to compute this matrix and stores it in mCurrentTransformMatrix. 227736aa9573bb7b78f9c315f396c104491b3639426Jamie Gennis void computeCurrentTransformMatrix(); 228736aa9573bb7b78f9c315f396c104491b3639426Jamie Gennis 2298ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis enum { INVALID_BUFFER_SLOT = -1 }; 2308ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 2318ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis struct BufferSlot { 232b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian 233b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian BufferSlot() 234b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian : mEglImage(EGL_NO_IMAGE_KHR), 235b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian mEglDisplay(EGL_NO_DISPLAY), 236b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian mBufferState(BufferSlot::FREE), 237b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian mRequestBufferCalled(false), 2388cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis mTransform(0), 2397734ebfe47f42f980c1b44c1f284a91d8ad1d6c7Mathias Agopian mScalingMode(NATIVE_WINDOW_SCALING_MODE_FREEZE), 2408cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis mTimestamp(0) { 2418cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis mCrop.makeInvalid(); 242b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian } 243b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian 2448ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis // mGraphicBuffer points to the buffer allocated for this slot or is NULL 2458ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis // if no buffer has been allocated. 2468ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis sp<GraphicBuffer> mGraphicBuffer; 2478ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 2488ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis // mEglImage is the EGLImage created from mGraphicBuffer. 2498ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis EGLImageKHR mEglImage; 2508ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 2518ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis // mEglDisplay is the EGLDisplay used to create mEglImage. 2528ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis EGLDisplay mEglDisplay; 2538ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 2548cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis // BufferState represents the different states in which a buffer slot 2558cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis // can be. 2568cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis enum BufferState { 2578cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis // FREE indicates that the buffer is not currently being used and 2588cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis // will not be used in the future until it gets dequeued and 2598cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis // subseqently queued by the client. 2608cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis FREE = 0, 2618cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis 2628cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis // DEQUEUED indicates that the buffer has been dequeued by the 2638cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis // client, but has not yet been queued or canceled. The buffer is 2648cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis // considered 'owned' by the client, and the server should not use 2658cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis // it for anything. 2668cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis // 2678cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis // Note that when in synchronous-mode (mSynchronousMode == true), 2688cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis // the buffer that's currently attached to the texture may be 2698cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis // dequeued by the client. That means that the current buffer can 2708cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis // be in either the DEQUEUED or QUEUED state. In asynchronous mode, 2718cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis // however, the current buffer is always in the QUEUED state. 2728cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis DEQUEUED = 1, 2738cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis 2748cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis // QUEUED indicates that the buffer has been queued by the client, 2758cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis // and has not since been made available for the client to dequeue. 2768cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis // Attaching the buffer to the texture does NOT transition the 2778cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis // buffer away from the QUEUED state. However, in Synchronous mode 2788cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis // the current buffer may be dequeued by the client under some 2798cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis // circumstances. See the note about the current buffer in the 2808cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis // documentation for DEQUEUED. 2818cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis QUEUED = 2, 2828cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis }; 2838cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis 2848cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis // mBufferState is the current state of this buffer slot. 2858cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis BufferState mBufferState; 286b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian 287b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian // mRequestBufferCalled is used for validating that the client did 288b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian // call requestBuffer() when told to do so. Technically this is not 289b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian // needed but useful for debugging and catching client bugs. 290b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian bool mRequestBufferCalled; 291b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian 2928cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis // mCrop is the current crop rectangle for this buffer slot. This gets 2938cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis // set to mNextCrop each time queueBuffer gets called for this buffer. 2948cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis Rect mCrop; 295b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian 2968cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis // mTransform is the current transform flags for this buffer slot. This 2978cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis // gets set to mNextTransform each time queueBuffer gets called for this 2988cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis // slot. 2998cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis uint32_t mTransform; 300b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian 3017734ebfe47f42f980c1b44c1f284a91d8ad1d6c7Mathias Agopian // mScalingMode is the current scaling mode for this buffer slot. This 3027734ebfe47f42f980c1b44c1f284a91d8ad1d6c7Mathias Agopian // gets set to mNextScalingMode each time queueBuffer gets called for 3037734ebfe47f42f980c1b44c1f284a91d8ad1d6c7Mathias Agopian // this slot. 3047734ebfe47f42f980c1b44c1f284a91d8ad1d6c7Mathias Agopian uint32_t mScalingMode; 3057734ebfe47f42f980c1b44c1f284a91d8ad1d6c7Mathias Agopian 3068cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis // mTimestamp is the current timestamp for this buffer slot. This gets 3078cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis // to set by queueBuffer each time this slot is queued. 3088cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis int64_t mTimestamp; 3098ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis }; 3108ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 3118ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis // mSlots is the array of buffer slots that must be mirrored on the client 3128ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis // side. This allows buffer ownership to be transferred between the client 3138ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis // and server without sending a GraphicBuffer over binder. The entire array 3148ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis // is initialized to NULL at construction time, and buffers are allocated 3158ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis // for a slot when requestBuffer is called with that slot's index. 3168ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis BufferSlot mSlots[NUM_BUFFER_SLOTS]; 3178ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 318a5c75c01620179ce00812354778a29a80d76e71fMathias Agopian // mDefaultWidth holds the default width of allocated buffers. It is used 319a5c75c01620179ce00812354778a29a80d76e71fMathias Agopian // in requestBuffers() if a width and height of zero is specified. 320a5c75c01620179ce00812354778a29a80d76e71fMathias Agopian uint32_t mDefaultWidth; 321a5c75c01620179ce00812354778a29a80d76e71fMathias Agopian 322a5c75c01620179ce00812354778a29a80d76e71fMathias Agopian // mDefaultHeight holds the default height of allocated buffers. It is used 323a5c75c01620179ce00812354778a29a80d76e71fMathias Agopian // in requestBuffers() if a width and height of zero is specified. 324a5c75c01620179ce00812354778a29a80d76e71fMathias Agopian uint32_t mDefaultHeight; 325a5c75c01620179ce00812354778a29a80d76e71fMathias Agopian 326a5c75c01620179ce00812354778a29a80d76e71fMathias Agopian // mPixelFormat holds the pixel format of allocated buffers. It is used 327a5c75c01620179ce00812354778a29a80d76e71fMathias Agopian // in requestBuffers() if a format of zero is specified. 328a5c75c01620179ce00812354778a29a80d76e71fMathias Agopian uint32_t mPixelFormat; 329a5c75c01620179ce00812354778a29a80d76e71fMathias Agopian 3308ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis // mBufferCount is the number of buffer slots that the client and server 3318072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian // must maintain. It defaults to MIN_ASYNC_BUFFER_SLOTS and can be changed 3328072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian // by calling setBufferCount or setBufferCountServer 3338ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis int mBufferCount; 3348ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 335ae468f43418c3cbae74c7f546283f6bb4e4df690Jamie Gennis // mClientBufferCount is the number of buffer slots requested by the client. 336ae468f43418c3cbae74c7f546283f6bb4e4df690Jamie Gennis // The default is zero, which means the client doesn't care how many buffers 337ae468f43418c3cbae74c7f546283f6bb4e4df690Jamie Gennis // there is. 3388072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian int mClientBufferCount; 3398072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian 3408072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian // mServerBufferCount buffer count requested by the server-side 3418072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian int mServerBufferCount; 3428072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian 3438ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis // mCurrentTexture is the buffer slot index of the buffer that is currently 34467eedd74ab78c2bfed9fcdc74947b97289254ca4Jamie Gennis // bound to the OpenGL texture. It is initialized to INVALID_BUFFER_SLOT, 34567eedd74ab78c2bfed9fcdc74947b97289254ca4Jamie Gennis // indicating that no buffer slot is currently bound to the texture. Note, 34667eedd74ab78c2bfed9fcdc74947b97289254ca4Jamie Gennis // however, that a value of INVALID_BUFFER_SLOT does not necessarily mean 34767eedd74ab78c2bfed9fcdc74947b97289254ca4Jamie Gennis // that no buffer is bound to the texture. A call to setBufferCount will 34867eedd74ab78c2bfed9fcdc74947b97289254ca4Jamie Gennis // reset mCurrentTexture to INVALID_BUFFER_SLOT. 3498ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis int mCurrentTexture; 3508ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 3519a78c90cd46b2a3bd637b056873149d3b94384b4Jamie Gennis // mCurrentTextureBuf is the graphic buffer of the current texture. It's 3529a78c90cd46b2a3bd637b056873149d3b94384b4Jamie Gennis // possible that this buffer is not associated with any buffer slot, so we 35329c870271e8d3f8c40c356283650ba54fe71a16bJamie Gennis // must track it separately in order to support the getCurrentBuffer method. 3549a78c90cd46b2a3bd637b056873149d3b94384b4Jamie Gennis sp<GraphicBuffer> mCurrentTextureBuf; 3559a78c90cd46b2a3bd637b056873149d3b94384b4Jamie Gennis 356f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis // mCurrentCrop is the crop rectangle that applies to the current texture. 3577734ebfe47f42f980c1b44c1f284a91d8ad1d6c7Mathias Agopian // It gets set each time updateTexImage is called. 358f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis Rect mCurrentCrop; 359f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis 360f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis // mCurrentTransform is the transform identifier for the current texture. It 3617734ebfe47f42f980c1b44c1f284a91d8ad1d6c7Mathias Agopian // gets set each time updateTexImage is called. 362f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis uint32_t mCurrentTransform; 363f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis 3647734ebfe47f42f980c1b44c1f284a91d8ad1d6c7Mathias Agopian // mCurrentScalingMode is the scaling mode for the current texture. It gets 3657734ebfe47f42f980c1b44c1f284a91d8ad1d6c7Mathias Agopian // set to each time updateTexImage is called. 3667734ebfe47f42f980c1b44c1f284a91d8ad1d6c7Mathias Agopian uint32_t mCurrentScalingMode; 3677734ebfe47f42f980c1b44c1f284a91d8ad1d6c7Mathias Agopian 368736aa9573bb7b78f9c315f396c104491b3639426Jamie Gennis // mCurrentTransformMatrix is the transform matrix for the current texture. 369736aa9573bb7b78f9c315f396c104491b3639426Jamie Gennis // It gets computed by computeTransformMatrix each time updateTexImage is 370736aa9573bb7b78f9c315f396c104491b3639426Jamie Gennis // called. 371736aa9573bb7b78f9c315f396c104491b3639426Jamie Gennis float mCurrentTransformMatrix[16]; 372736aa9573bb7b78f9c315f396c104491b3639426Jamie Gennis 3731d01a12e7150be569557b64da9b8663c62c13594Eino-Ville Talvala // mCurrentTimestamp is the timestamp for the current texture. It 3747734ebfe47f42f980c1b44c1f284a91d8ad1d6c7Mathias Agopian // gets set each time updateTexImage is called. 3751d01a12e7150be569557b64da9b8663c62c13594Eino-Ville Talvala int64_t mCurrentTimestamp; 3761d01a12e7150be569557b64da9b8663c62c13594Eino-Ville Talvala 377f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis // mNextCrop is the crop rectangle that will be used for the next buffer 378f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis // that gets queued. It is set by calling setCrop. 379f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis Rect mNextCrop; 380f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis 381f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis // mNextTransform is the transform identifier that will be used for the next 382f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis // buffer that gets queued. It is set by calling setTransform. 383f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis uint32_t mNextTransform; 384f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis 3857734ebfe47f42f980c1b44c1f284a91d8ad1d6c7Mathias Agopian // mNextScalingMode is the scaling mode that will be used for the next 3867734ebfe47f42f980c1b44c1f284a91d8ad1d6c7Mathias Agopian // buffers that get queued. It is set by calling setScalingMode. 3877734ebfe47f42f980c1b44c1f284a91d8ad1d6c7Mathias Agopian int mNextScalingMode; 3887734ebfe47f42f980c1b44c1f284a91d8ad1d6c7Mathias Agopian 3898ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis // mTexName is the name of the OpenGL texture to which streamed images will 390292a31a4c2ae2f6faf134e8e4a726583017dad06Pannag Sanketi // be bound when updateTexImage is called. It is set at construction time 3918ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis // changed with a call to setTexName. 3928ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis const GLuint mTexName; 3938ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 3949a78c90cd46b2a3bd637b056873149d3b94384b4Jamie Gennis // mGraphicBufferAlloc is the connection to SurfaceFlinger that is used to 3959a78c90cd46b2a3bd637b056873149d3b94384b4Jamie Gennis // allocate new GraphicBuffer objects. 3969a78c90cd46b2a3bd637b056873149d3b94384b4Jamie Gennis sp<IGraphicBufferAlloc> mGraphicBufferAlloc; 3979a78c90cd46b2a3bd637b056873149d3b94384b4Jamie Gennis 398c4d4aeab52435c177ded6abdd578fec8191f0f5dJamie Gennis // mFrameAvailableListener is the listener object that will be called when a 399c4d4aeab52435c177ded6abdd578fec8191f0f5dJamie Gennis // new frame becomes available. If it is not NULL it will be called from 400c4d4aeab52435c177ded6abdd578fec8191f0f5dJamie Gennis // queueBuffer. 401c4d4aeab52435c177ded6abdd578fec8191f0f5dJamie Gennis sp<FrameAvailableListener> mFrameAvailableListener; 402c4d4aeab52435c177ded6abdd578fec8191f0f5dJamie Gennis 403b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian // mSynchronousMode whether we're in synchronous mode or not 404b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian bool mSynchronousMode; 405b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian 40614a0e58074f2698829b6554f578e6762c377caa3Grace Kloba // mAllowSynchronousMode whether we allow synchronous mode or not 40714a0e58074f2698829b6554f578e6762c377caa3Grace Kloba const bool mAllowSynchronousMode; 40814a0e58074f2698829b6554f578e6762c377caa3Grace Kloba 409fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis // mConnectedApi indicates the API that is currently connected to this 410fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis // SurfaceTexture. It defaults to NO_CONNECTED_API (= 0), and gets updated 411fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis // by the connect and disconnect methods. 412fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis int mConnectedApi; 413fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis 414b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian // mDequeueCondition condition used for dequeueBuffer in synchronous mode 415b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian mutable Condition mDequeueCondition; 416b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian 417b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian // mQueue is a FIFO of queued buffers used in synchronous mode 418b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian typedef Vector<int> Fifo; 419b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian Fifo mQueue; 420b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian 4217b305fffc39d0fe0926e7fd2d7f6a524fbce62b7Jamie Gennis // mAbandoned indicates that the SurfaceTexture will no longer be used to 4227b305fffc39d0fe0926e7fd2d7f6a524fbce62b7Jamie Gennis // consume images buffers pushed to it using the ISurfaceTexture interface. 4237b305fffc39d0fe0926e7fd2d7f6a524fbce62b7Jamie Gennis // It is initialized to false, and set to true in the abandon method. A 4247b305fffc39d0fe0926e7fd2d7f6a524fbce62b7Jamie Gennis // SurfaceTexture that has been abandoned will return the NO_INIT error from 4257b305fffc39d0fe0926e7fd2d7f6a524fbce62b7Jamie Gennis // all ISurfaceTexture methods capable of returning an error. 4267b305fffc39d0fe0926e7fd2d7f6a524fbce62b7Jamie Gennis bool mAbandoned; 4277b305fffc39d0fe0926e7fd2d7f6a524fbce62b7Jamie Gennis 4288ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis // mMutex is the mutex used to prevent concurrent access to the member 4298ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis // variables of SurfaceTexture objects. It must be locked whenever the 4308ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis // member variables are accessed. 4317a042bf324fe3f3d5d4085fda21fe50dc0c362b4Mathias Agopian mutable Mutex mMutex; 432736aa9573bb7b78f9c315f396c104491b3639426Jamie Gennis 4338ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis}; 4348ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 4358ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis// ---------------------------------------------------------------------------- 4368ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis}; // namespace android 4378ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 4388ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis#endif // ANDROID_GUI_SURFACETEXTURE_H 439