SurfaceTexture.h revision 86edf4f6470ee0f108bf40d3c1d23bf0a78c9c38
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> 23fb1b5a2f333800574b0da435d1200cf9b13d723fJamie Gennis#include <GLES2/gl2ext.h> 248ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 258ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis#include <gui/ISurfaceTexture.h> 268ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 278ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis#include <ui/GraphicBuffer.h> 288ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 29fa28c35c21d1bf8b38f541758c291bc17a2d7270Jamie Gennis#include <utils/String8.h> 309a78c90cd46b2a3bd637b056873149d3b94384b4Jamie Gennis#include <utils/Vector.h> 31fa28c35c21d1bf8b38f541758c291bc17a2d7270Jamie Gennis#include <utils/threads.h> 328ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 338ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis#define ANDROID_GRAPHICS_SURFACETEXTURE_JNI_ID "mSurfaceTexture" 348ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 358ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennisnamespace android { 368ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis// ---------------------------------------------------------------------------- 378ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 389a78c90cd46b2a3bd637b056873149d3b94384b4Jamie Gennisclass IGraphicBufferAlloc; 3968c7794183a7dbfe3b20d4ce832f8eb79c2c619aMathias Agopianclass String8; 409a78c90cd46b2a3bd637b056873149d3b94384b4Jamie Gennis 418ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennisclass SurfaceTexture : public BnSurfaceTexture { 428ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennispublic: 439d4d6c101d90d4a1d1ca9413cf3eb89d1f1898d6Jamie Gennis enum { MIN_UNDEQUEUED_BUFFERS = 2 }; 448072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian enum { 458072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian MIN_ASYNC_BUFFER_SLOTS = MIN_UNDEQUEUED_BUFFERS + 1, 468072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian MIN_SYNC_BUFFER_SLOTS = MIN_UNDEQUEUED_BUFFERS 478072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian }; 488ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis enum { NUM_BUFFER_SLOTS = 32 }; 49fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis enum { NO_CONNECTED_API = 0 }; 508ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 51c4d4aeab52435c177ded6abdd578fec8191f0f5dJamie Gennis struct FrameAvailableListener : public virtual RefBase { 523d8063b02e06020c8062addcc9ec49048d3bdb9aJamie Gennis // onFrameAvailable() is called from queueBuffer() each time an 533d8063b02e06020c8062addcc9ec49048d3bdb9aJamie Gennis // additional frame becomes available for consumption. This means that 543d8063b02e06020c8062addcc9ec49048d3bdb9aJamie Gennis // frames that are queued while in asynchronous mode only trigger the 553d8063b02e06020c8062addcc9ec49048d3bdb9aJamie Gennis // callback if no previous frames are pending. Frames queued while in 563d8063b02e06020c8062addcc9ec49048d3bdb9aJamie Gennis // synchronous mode always trigger the callback. 573d8063b02e06020c8062addcc9ec49048d3bdb9aJamie Gennis // 583d8063b02e06020c8062addcc9ec49048d3bdb9aJamie Gennis // This is called without any lock held and can be called concurrently 593d8063b02e06020c8062addcc9ec49048d3bdb9aJamie Gennis // by multiple threads. 60c4d4aeab52435c177ded6abdd578fec8191f0f5dJamie Gennis virtual void onFrameAvailable() = 0; 61c4d4aeab52435c177ded6abdd578fec8191f0f5dJamie Gennis }; 62c4d4aeab52435c177ded6abdd578fec8191f0f5dJamie Gennis 6386edf4f6470ee0f108bf40d3c1d23bf0a78c9c38Jamie Gennis // SurfaceTexture constructs a new SurfaceTexture object. tex indicates the 6486edf4f6470ee0f108bf40d3c1d23bf0a78c9c38Jamie Gennis // name of the OpenGL ES texture to which images are to be streamed. This 6586edf4f6470ee0f108bf40d3c1d23bf0a78c9c38Jamie Gennis // texture name cannot be changed once the SurfaceTexture is created. 6686edf4f6470ee0f108bf40d3c1d23bf0a78c9c38Jamie Gennis // allowSynchronousMode specifies whether or not synchronous mode can be 6786edf4f6470ee0f108bf40d3c1d23bf0a78c9c38Jamie Gennis // enabled. texTarget specifies the OpenGL ES texture target to which the 6886edf4f6470ee0f108bf40d3c1d23bf0a78c9c38Jamie Gennis // texture will be bound in updateTexImage. useFenceSync specifies whether 6986edf4f6470ee0f108bf40d3c1d23bf0a78c9c38Jamie Gennis // fences should be used to synchronize access to buffers if that behavior 7086edf4f6470ee0f108bf40d3c1d23bf0a78c9c38Jamie Gennis // is enabled at compile-time. 71fb1b5a2f333800574b0da435d1200cf9b13d723fJamie Gennis SurfaceTexture(GLuint tex, bool allowSynchronousMode = true, 7286edf4f6470ee0f108bf40d3c1d23bf0a78c9c38Jamie Gennis GLenum texTarget = GL_TEXTURE_EXTERNAL_OES, bool useFenceSync = true); 738ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 748ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis virtual ~SurfaceTexture(); 758ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 768ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis // setBufferCount updates the number of available buffer slots. After 778ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis // calling this all buffer slots are both unallocated and owned by the 788ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis // SurfaceTexture object (i.e. they are not owned by the client). 798ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis virtual status_t setBufferCount(int bufferCount); 808ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 817b305fffc39d0fe0926e7fd2d7f6a524fbce62b7Jamie Gennis virtual status_t requestBuffer(int slot, sp<GraphicBuffer>* buf); 828ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 838ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis // dequeueBuffer gets the next buffer slot index for the client to use. If a 848ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis // buffer slot is available then that slot index is written to the location 858ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis // pointed to by the buf argument and a status of OK is returned. If no 868ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis // slot is available then a status of -EBUSY is returned and buf is 878ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis // unmodified. 88194c76c0477189700fda068e19b953b1d9af201aMathias Agopian // The width and height parameters must be no greater than the minimum of 89194c76c0477189700fda068e19b953b1d9af201aMathias Agopian // GL_MAX_VIEWPORT_DIMS and GL_MAX_TEXTURE_SIZE (see: glGetIntegerv). 90194c76c0477189700fda068e19b953b1d9af201aMathias Agopian // An error due to invalid dimensions might not be reported until 91194c76c0477189700fda068e19b953b1d9af201aMathias Agopian // updateTexImage() is called. 92194c76c0477189700fda068e19b953b1d9af201aMathias Agopian virtual status_t dequeueBuffer(int *buf, uint32_t width, uint32_t height, 93c04f153353cdb0d291297d10452239f791d3fd2bMathias Agopian uint32_t format, uint32_t usage); 948ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 951d01a12e7150be569557b64da9b8663c62c13594Eino-Ville Talvala // queueBuffer returns a filled buffer to the SurfaceTexture. In addition, a 961d01a12e7150be569557b64da9b8663c62c13594Eino-Ville Talvala // timestamp must be provided for the buffer. The timestamp is in 971d01a12e7150be569557b64da9b8663c62c13594Eino-Ville Talvala // nanoseconds, and must be monotonically increasing. Its other semantics 981d01a12e7150be569557b64da9b8663c62c13594Eino-Ville Talvala // (zero point, etc) are client-dependent and should be documented by the 991d01a12e7150be569557b64da9b8663c62c13594Eino-Ville Talvala // client. 10097c602c5af5f3ffd69009bf496d86347b71a2b4cMathias Agopian virtual status_t queueBuffer(int buf, int64_t timestamp, 10197c602c5af5f3ffd69009bf496d86347b71a2b4cMathias Agopian uint32_t* outWidth, uint32_t* outHeight, uint32_t* outTransform); 1028ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis virtual void cancelBuffer(int buf); 1038ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis virtual status_t setCrop(const Rect& reg); 1048ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis virtual status_t setTransform(uint32_t transform); 1057734ebfe47f42f980c1b44c1f284a91d8ad1d6c7Mathias Agopian virtual status_t setScalingMode(int mode); 1068ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 107eafabcdc1639fb96062d9e3c39b0ae27b0238ae1Mathias Agopian virtual int query(int what, int* value); 108eafabcdc1639fb96062d9e3c39b0ae27b0238ae1Mathias Agopian 1098072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian // setSynchronousMode set whether dequeueBuffer is synchronous or 1108072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian // asynchronous. In synchronous mode, dequeueBuffer blocks until 1118072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian // a buffer is available, the currently bound buffer can be dequeued and 1128072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian // queued buffers will be retired in order. 1138072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian // The default mode is asynchronous. 1148072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian virtual status_t setSynchronousMode(bool enabled); 1158072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian 116fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis // connect attempts to connect a client API to the SurfaceTexture. This 117fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis // must be called before any other ISurfaceTexture methods are called except 118fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis // for getAllocator. 119fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis // 120fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis // This method will fail if the connect was previously called on the 121fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis // SurfaceTexture and no corresponding disconnect call was made. 1225bfc24515bb5c8ea7975f72d538df37753733a2fMathias Agopian virtual status_t connect(int api, 1235bfc24515bb5c8ea7975f72d538df37753733a2fMathias Agopian uint32_t* outWidth, uint32_t* outHeight, uint32_t* outTransform); 124fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis 125fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis // disconnect attempts to disconnect a client API from the SurfaceTexture. 126fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis // Calling this method will cause any subsequent calls to other 127fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis // ISurfaceTexture methods to fail except for getAllocator and connect. 128fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis // Successfully calling connect after this will allow the other methods to 129fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis // succeed again. 130fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis // 131fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis // This method will fail if the the SurfaceTexture is not currently 132fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis // connected to the specified client API. 133fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis virtual status_t disconnect(int api); 134fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis 1358ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis // updateTexImage sets the image contents of the target texture to that of 1368ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis // the most recently queued buffer. 1378ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis // 1388ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis // This call may only be made while the OpenGL ES context to which the 1398ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis // target texture belongs is bound to the calling thread. 1408ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis status_t updateTexImage(); 1418ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 1428072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian // setBufferCountServer set the buffer count. If the client has requested 1438072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian // a buffer count using setBufferCount, the server-buffer count will 1448072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian // take effect once the client sets the count back to zero. 1458072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian status_t setBufferCountServer(int bufferCount); 1468072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian 147f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis // getTransformMatrix retrieves the 4x4 texture coordinate transform matrix 148f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis // associated with the texture image set by the most recent call to 149f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis // updateTexImage. 150f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis // 151f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis // This transform matrix maps 2D homogeneous texture coordinates of the form 152f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis // (s, t, 0, 1) with s and t in the inclusive range [0, 1] to the texture 153f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis // coordinate that should be used to sample that location from the texture. 154f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis // Sampling the texture outside of the range of this transform is undefined. 155f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis // 156f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis // This transform is necessary to compensate for transforms that the stream 157f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis // content producer may implicitly apply to the content. By forcing users of 158f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis // a SurfaceTexture to apply this transform we avoid performing an extra 159f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis // copy of the data that would be needed to hide the transform from the 160f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis // user. 161f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis // 162f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis // The matrix is stored in column-major order so that it may be passed 163f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis // directly to OpenGL ES via the glLoadMatrixf or glUniformMatrix4fv 164f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis // functions. 165f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis void getTransformMatrix(float mtx[16]); 166f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis 1671d01a12e7150be569557b64da9b8663c62c13594Eino-Ville Talvala // getTimestamp retrieves the timestamp associated with the texture image 1681d01a12e7150be569557b64da9b8663c62c13594Eino-Ville Talvala // set by the most recent call to updateTexImage. 1691d01a12e7150be569557b64da9b8663c62c13594Eino-Ville Talvala // 1701d01a12e7150be569557b64da9b8663c62c13594Eino-Ville Talvala // The timestamp is in nanoseconds, and is monotonically increasing. Its 1711d01a12e7150be569557b64da9b8663c62c13594Eino-Ville Talvala // other semantics (zero point, etc) are source-dependent and should be 1721d01a12e7150be569557b64da9b8663c62c13594Eino-Ville Talvala // documented by the source. 1731d01a12e7150be569557b64da9b8663c62c13594Eino-Ville Talvala int64_t getTimestamp(); 1741d01a12e7150be569557b64da9b8663c62c13594Eino-Ville Talvala 175c4d4aeab52435c177ded6abdd578fec8191f0f5dJamie Gennis // setFrameAvailableListener sets the listener object that will be notified 176c4d4aeab52435c177ded6abdd578fec8191f0f5dJamie Gennis // when a new frame becomes available. 177292a31a4c2ae2f6faf134e8e4a726583017dad06Pannag Sanketi void setFrameAvailableListener(const sp<FrameAvailableListener>& listener); 178c4d4aeab52435c177ded6abdd578fec8191f0f5dJamie Gennis 1791b20cde313b5ef8acdace742328df867956d24cbJamie Gennis // getAllocator retrieves the binder object that must be referenced as long 1801b20cde313b5ef8acdace742328df867956d24cbJamie Gennis // as the GraphicBuffers dequeued from this SurfaceTexture are referenced. 1811b20cde313b5ef8acdace742328df867956d24cbJamie Gennis // Holding this binder reference prevents SurfaceFlinger from freeing the 1821b20cde313b5ef8acdace742328df867956d24cbJamie Gennis // buffers before the client is done with them. 1831b20cde313b5ef8acdace742328df867956d24cbJamie Gennis sp<IBinder> getAllocator(); 1841b20cde313b5ef8acdace742328df867956d24cbJamie Gennis 185a5c75c01620179ce00812354778a29a80d76e71fMathias Agopian // setDefaultBufferSize is used to set the size of buffers returned by 186a5c75c01620179ce00812354778a29a80d76e71fMathias Agopian // requestBuffers when a with and height of zero is requested. 187a5c75c01620179ce00812354778a29a80d76e71fMathias Agopian // A call to setDefaultBufferSize() may trigger requestBuffers() to 188a5c75c01620179ce00812354778a29a80d76e71fMathias Agopian // be called from the client. 189194c76c0477189700fda068e19b953b1d9af201aMathias Agopian // The width and height parameters must be no greater than the minimum of 190194c76c0477189700fda068e19b953b1d9af201aMathias Agopian // GL_MAX_VIEWPORT_DIMS and GL_MAX_TEXTURE_SIZE (see: glGetIntegerv). 191194c76c0477189700fda068e19b953b1d9af201aMathias Agopian // An error due to invalid dimensions might not be reported until 192194c76c0477189700fda068e19b953b1d9af201aMathias Agopian // updateTexImage() is called. 193194c76c0477189700fda068e19b953b1d9af201aMathias Agopian status_t setDefaultBufferSize(uint32_t width, uint32_t height); 194a5c75c01620179ce00812354778a29a80d76e71fMathias Agopian 1957a042bf324fe3f3d5d4085fda21fe50dc0c362b4Mathias Agopian // getCurrentBuffer returns the buffer associated with the current image. 1967a042bf324fe3f3d5d4085fda21fe50dc0c362b4Mathias Agopian sp<GraphicBuffer> getCurrentBuffer() const; 1977a042bf324fe3f3d5d4085fda21fe50dc0c362b4Mathias Agopian 1987a042bf324fe3f3d5d4085fda21fe50dc0c362b4Mathias Agopian // getCurrentTextureTarget returns the texture target of the current 1997a042bf324fe3f3d5d4085fda21fe50dc0c362b4Mathias Agopian // texture as returned by updateTexImage(). 2007a042bf324fe3f3d5d4085fda21fe50dc0c362b4Mathias Agopian GLenum getCurrentTextureTarget() const; 2017a042bf324fe3f3d5d4085fda21fe50dc0c362b4Mathias Agopian 2027a042bf324fe3f3d5d4085fda21fe50dc0c362b4Mathias Agopian // getCurrentCrop returns the cropping rectangle of the current buffer 2037a042bf324fe3f3d5d4085fda21fe50dc0c362b4Mathias Agopian Rect getCurrentCrop() const; 2047a042bf324fe3f3d5d4085fda21fe50dc0c362b4Mathias Agopian 2057a042bf324fe3f3d5d4085fda21fe50dc0c362b4Mathias Agopian // getCurrentTransform returns the transform of the current buffer 2067a042bf324fe3f3d5d4085fda21fe50dc0c362b4Mathias Agopian uint32_t getCurrentTransform() const; 2077a042bf324fe3f3d5d4085fda21fe50dc0c362b4Mathias Agopian 2087734ebfe47f42f980c1b44c1f284a91d8ad1d6c7Mathias Agopian // getCurrentScalingMode returns the scaling mode of the current buffer 2097734ebfe47f42f980c1b44c1f284a91d8ad1d6c7Mathias Agopian uint32_t getCurrentScalingMode() const; 2107734ebfe47f42f980c1b44c1f284a91d8ad1d6c7Mathias Agopian 21159769469e4b9b2d8b12c020eb44b030b3927a50bJamie Gennis // isSynchronousMode returns whether the SurfaceTexture is currently in 21259769469e4b9b2d8b12c020eb44b030b3927a50bJamie Gennis // synchronous mode. 21359769469e4b9b2d8b12c020eb44b030b3927a50bJamie Gennis bool isSynchronousMode() const; 21459769469e4b9b2d8b12c020eb44b030b3927a50bJamie Gennis 2157b305fffc39d0fe0926e7fd2d7f6a524fbce62b7Jamie Gennis // abandon frees all the buffers and puts the SurfaceTexture into the 2167b305fffc39d0fe0926e7fd2d7f6a524fbce62b7Jamie Gennis // 'abandoned' state. Once put in this state the SurfaceTexture can never 2177b305fffc39d0fe0926e7fd2d7f6a524fbce62b7Jamie Gennis // leave it. When in the 'abandoned' state, all methods of the 2187b305fffc39d0fe0926e7fd2d7f6a524fbce62b7Jamie Gennis // ISurfaceTexture interface will fail with the NO_INIT error. 2197b305fffc39d0fe0926e7fd2d7f6a524fbce62b7Jamie Gennis // 2207b305fffc39d0fe0926e7fd2d7f6a524fbce62b7Jamie Gennis // Note that while calling this method causes all the buffers to be freed 2217b305fffc39d0fe0926e7fd2d7f6a524fbce62b7Jamie Gennis // from the perspective of the the SurfaceTexture, if there are additional 2227b305fffc39d0fe0926e7fd2d7f6a524fbce62b7Jamie Gennis // references on the buffers (e.g. if a buffer is referenced by a client or 2237b305fffc39d0fe0926e7fd2d7f6a524fbce62b7Jamie Gennis // by OpenGL ES as a texture) then those buffer will remain allocated. 2247b305fffc39d0fe0926e7fd2d7f6a524fbce62b7Jamie Gennis void abandon(); 2257b305fffc39d0fe0926e7fd2d7f6a524fbce62b7Jamie Gennis 226fa28c35c21d1bf8b38f541758c291bc17a2d7270Jamie Gennis // set the name of the SurfaceTexture that will be used to identify it in 227fa28c35c21d1bf8b38f541758c291bc17a2d7270Jamie Gennis // log messages. 228fa28c35c21d1bf8b38f541758c291bc17a2d7270Jamie Gennis void setName(const String8& name); 229fa28c35c21d1bf8b38f541758c291bc17a2d7270Jamie Gennis 23068c7794183a7dbfe3b20d4ce832f8eb79c2c619aMathias Agopian // dump our state in a String 23168c7794183a7dbfe3b20d4ce832f8eb79c2c619aMathias Agopian void dump(String8& result) const; 23268c7794183a7dbfe3b20d4ce832f8eb79c2c619aMathias Agopian void dump(String8& result, const char* prefix, char* buffer, size_t SIZE) const; 23368c7794183a7dbfe3b20d4ce832f8eb79c2c619aMathias Agopian 2347a042bf324fe3f3d5d4085fda21fe50dc0c362b4Mathias Agopianprotected: 2358ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 2368e19c2e97e11505ee2ecf336275fd956f2ccfa22Mathias Agopian // freeBufferLocked frees the resources (both GraphicBuffer and EGLImage) 2378e19c2e97e11505ee2ecf336275fd956f2ccfa22Mathias Agopian // for the given slot. 2388e19c2e97e11505ee2ecf336275fd956f2ccfa22Mathias Agopian void freeBufferLocked(int index); 2398e19c2e97e11505ee2ecf336275fd956f2ccfa22Mathias Agopian 2408e19c2e97e11505ee2ecf336275fd956f2ccfa22Mathias Agopian // freeAllBuffersLocked frees the resources (both GraphicBuffer and 2418e19c2e97e11505ee2ecf336275fd956f2ccfa22Mathias Agopian // EGLImage) for all slots. 242ef51b992192adf4fc432686ab346f5fc7a13bc95Mathias Agopian void freeAllBuffersLocked(); 2432560d14ce8e38984032d999e3fdf8da9a47baf3cMathias Agopian 2448e19c2e97e11505ee2ecf336275fd956f2ccfa22Mathias Agopian // freeAllBuffersExceptHeadLocked frees the resources (both GraphicBuffer 2458e19c2e97e11505ee2ecf336275fd956f2ccfa22Mathias Agopian // and EGLImage) for all slots except the head of mQueue 2468e19c2e97e11505ee2ecf336275fd956f2ccfa22Mathias Agopian void freeAllBuffersExceptHeadLocked(); 2478e19c2e97e11505ee2ecf336275fd956f2ccfa22Mathias Agopian 2482560d14ce8e38984032d999e3fdf8da9a47baf3cMathias Agopian // drainQueueLocked drains the buffer queue if we're in synchronous mode 2498e19c2e97e11505ee2ecf336275fd956f2ccfa22Mathias Agopian // returns immediately otherwise. return NO_INIT if SurfaceTexture 2508e19c2e97e11505ee2ecf336275fd956f2ccfa22Mathias Agopian // became abandoned or disconnected during this call. 2518e19c2e97e11505ee2ecf336275fd956f2ccfa22Mathias Agopian status_t drainQueueLocked(); 2528e19c2e97e11505ee2ecf336275fd956f2ccfa22Mathias Agopian 2538e19c2e97e11505ee2ecf336275fd956f2ccfa22Mathias Agopian // drainQueueAndFreeBuffersLocked drains the buffer queue if we're in 2548e19c2e97e11505ee2ecf336275fd956f2ccfa22Mathias Agopian // synchronous mode and free all buffers. In asynchronous mode, all buffers 2558e19c2e97e11505ee2ecf336275fd956f2ccfa22Mathias Agopian // are freed except the current buffer. 2568e19c2e97e11505ee2ecf336275fd956f2ccfa22Mathias Agopian status_t drainQueueAndFreeBuffersLocked(); 2572560d14ce8e38984032d999e3fdf8da9a47baf3cMathias Agopian 2587a042bf324fe3f3d5d4085fda21fe50dc0c362b4Mathias Agopian static bool isExternalFormat(uint32_t format); 2597a042bf324fe3f3d5d4085fda21fe50dc0c362b4Mathias Agopian 2607a042bf324fe3f3d5d4085fda21fe50dc0c362b4Mathias Agopianprivate: 2618ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 2628ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis // createImage creates a new EGLImage from a GraphicBuffer. 2638ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis EGLImageKHR createImage(EGLDisplay dpy, 2648ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis const sp<GraphicBuffer>& graphicBuffer); 2658ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 2668072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian status_t setBufferCountServerLocked(int bufferCount); 2678072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian 268736aa9573bb7b78f9c315f396c104491b3639426Jamie Gennis // computeCurrentTransformMatrix computes the transform matrix for the 269736aa9573bb7b78f9c315f396c104491b3639426Jamie Gennis // current texture. It uses mCurrentTransform and the current GraphicBuffer 270736aa9573bb7b78f9c315f396c104491b3639426Jamie Gennis // to compute this matrix and stores it in mCurrentTransformMatrix. 271736aa9573bb7b78f9c315f396c104491b3639426Jamie Gennis void computeCurrentTransformMatrix(); 272736aa9573bb7b78f9c315f396c104491b3639426Jamie Gennis 2738ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis enum { INVALID_BUFFER_SLOT = -1 }; 2748ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 2758ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis struct BufferSlot { 276b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian 277b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian BufferSlot() 278b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian : mEglImage(EGL_NO_IMAGE_KHR), 279b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian mEglDisplay(EGL_NO_DISPLAY), 280b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian mBufferState(BufferSlot::FREE), 281b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian mRequestBufferCalled(false), 2828cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis mTransform(0), 2837734ebfe47f42f980c1b44c1f284a91d8ad1d6c7Mathias Agopian mScalingMode(NATIVE_WINDOW_SCALING_MODE_FREEZE), 284a929748ddb67cbece3337c7fda7877fdeb973aa4Sunita Nadampalli mTimestamp(0), 28586edf4f6470ee0f108bf40d3c1d23bf0a78c9c38Jamie Gennis mFrameNumber(0), 28686edf4f6470ee0f108bf40d3c1d23bf0a78c9c38Jamie Gennis mFence(EGL_NO_SYNC_KHR) { 2878cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis mCrop.makeInvalid(); 288b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian } 289b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian 2908ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis // mGraphicBuffer points to the buffer allocated for this slot or is NULL 2918ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis // if no buffer has been allocated. 2928ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis sp<GraphicBuffer> mGraphicBuffer; 2938ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 2948ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis // mEglImage is the EGLImage created from mGraphicBuffer. 2958ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis EGLImageKHR mEglImage; 2968ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 2978ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis // mEglDisplay is the EGLDisplay used to create mEglImage. 2988ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis EGLDisplay mEglDisplay; 2998ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 3008cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis // BufferState represents the different states in which a buffer slot 3018cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis // can be. 3028cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis enum BufferState { 3038cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis // FREE indicates that the buffer is not currently being used and 3048cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis // will not be used in the future until it gets dequeued and 30529b5762efc359022168e5099c1d17925444d3147Mathias Agopian // subsequently queued by the client. 3068cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis FREE = 0, 3078cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis 3088cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis // DEQUEUED indicates that the buffer has been dequeued by the 3098cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis // client, but has not yet been queued or canceled. The buffer is 3108cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis // considered 'owned' by the client, and the server should not use 3118cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis // it for anything. 3128cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis // 3138cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis // Note that when in synchronous-mode (mSynchronousMode == true), 3148cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis // the buffer that's currently attached to the texture may be 3158cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis // dequeued by the client. That means that the current buffer can 3168cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis // be in either the DEQUEUED or QUEUED state. In asynchronous mode, 3178cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis // however, the current buffer is always in the QUEUED state. 3188cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis DEQUEUED = 1, 3198cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis 3208cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis // QUEUED indicates that the buffer has been queued by the client, 3218cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis // and has not since been made available for the client to dequeue. 3228cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis // Attaching the buffer to the texture does NOT transition the 3238cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis // buffer away from the QUEUED state. However, in Synchronous mode 3248cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis // the current buffer may be dequeued by the client under some 3258cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis // circumstances. See the note about the current buffer in the 3268cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis // documentation for DEQUEUED. 3278cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis QUEUED = 2, 3288cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis }; 3298cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis 3308cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis // mBufferState is the current state of this buffer slot. 3318cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis BufferState mBufferState; 332b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian 333b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian // mRequestBufferCalled is used for validating that the client did 334b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian // call requestBuffer() when told to do so. Technically this is not 335b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian // needed but useful for debugging and catching client bugs. 336b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian bool mRequestBufferCalled; 337b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian 3388cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis // mCrop is the current crop rectangle for this buffer slot. This gets 3398cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis // set to mNextCrop each time queueBuffer gets called for this buffer. 3408cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis Rect mCrop; 341b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian 3428cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis // mTransform is the current transform flags for this buffer slot. This 3438cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis // gets set to mNextTransform each time queueBuffer gets called for this 3448cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis // slot. 3458cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis uint32_t mTransform; 346b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian 3477734ebfe47f42f980c1b44c1f284a91d8ad1d6c7Mathias Agopian // mScalingMode is the current scaling mode for this buffer slot. This 3487734ebfe47f42f980c1b44c1f284a91d8ad1d6c7Mathias Agopian // gets set to mNextScalingMode each time queueBuffer gets called for 3497734ebfe47f42f980c1b44c1f284a91d8ad1d6c7Mathias Agopian // this slot. 3507734ebfe47f42f980c1b44c1f284a91d8ad1d6c7Mathias Agopian uint32_t mScalingMode; 3517734ebfe47f42f980c1b44c1f284a91d8ad1d6c7Mathias Agopian 3528cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis // mTimestamp is the current timestamp for this buffer slot. This gets 3538cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis // to set by queueBuffer each time this slot is queued. 3548cd5ba4b7f01d3a54a8f8bc6d1793aa5fc8e09efJamie Gennis int64_t mTimestamp; 355a929748ddb67cbece3337c7fda7877fdeb973aa4Sunita Nadampalli 356a929748ddb67cbece3337c7fda7877fdeb973aa4Sunita Nadampalli // mFrameNumber is the number of the queued frame for this slot. 357a929748ddb67cbece3337c7fda7877fdeb973aa4Sunita Nadampalli uint64_t mFrameNumber; 358a929748ddb67cbece3337c7fda7877fdeb973aa4Sunita Nadampalli 35986edf4f6470ee0f108bf40d3c1d23bf0a78c9c38Jamie Gennis // mFence is the EGL sync object that must signal before the buffer 36086edf4f6470ee0f108bf40d3c1d23bf0a78c9c38Jamie Gennis // associated with this buffer slot may be dequeued. It is initialized 36186edf4f6470ee0f108bf40d3c1d23bf0a78c9c38Jamie Gennis // to EGL_NO_SYNC_KHR when the buffer is created and (optionally, based 36286edf4f6470ee0f108bf40d3c1d23bf0a78c9c38Jamie Gennis // on a compile-time option) set to a new sync object in updateTexImage. 36386edf4f6470ee0f108bf40d3c1d23bf0a78c9c38Jamie Gennis EGLSyncKHR mFence; 3648ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis }; 3658ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 3668ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis // mSlots is the array of buffer slots that must be mirrored on the client 3678ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis // side. This allows buffer ownership to be transferred between the client 3688ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis // and server without sending a GraphicBuffer over binder. The entire array 3698ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis // is initialized to NULL at construction time, and buffers are allocated 3708ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis // for a slot when requestBuffer is called with that slot's index. 3718ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis BufferSlot mSlots[NUM_BUFFER_SLOTS]; 3728ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 373a5c75c01620179ce00812354778a29a80d76e71fMathias Agopian // mDefaultWidth holds the default width of allocated buffers. It is used 374a5c75c01620179ce00812354778a29a80d76e71fMathias Agopian // in requestBuffers() if a width and height of zero is specified. 375a5c75c01620179ce00812354778a29a80d76e71fMathias Agopian uint32_t mDefaultWidth; 376a5c75c01620179ce00812354778a29a80d76e71fMathias Agopian 377a5c75c01620179ce00812354778a29a80d76e71fMathias Agopian // mDefaultHeight holds the default height of allocated buffers. It is used 378a5c75c01620179ce00812354778a29a80d76e71fMathias Agopian // in requestBuffers() if a width and height of zero is specified. 379a5c75c01620179ce00812354778a29a80d76e71fMathias Agopian uint32_t mDefaultHeight; 380a5c75c01620179ce00812354778a29a80d76e71fMathias Agopian 381a5c75c01620179ce00812354778a29a80d76e71fMathias Agopian // mPixelFormat holds the pixel format of allocated buffers. It is used 382a5c75c01620179ce00812354778a29a80d76e71fMathias Agopian // in requestBuffers() if a format of zero is specified. 383a5c75c01620179ce00812354778a29a80d76e71fMathias Agopian uint32_t mPixelFormat; 384a5c75c01620179ce00812354778a29a80d76e71fMathias Agopian 3858ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis // mBufferCount is the number of buffer slots that the client and server 3868072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian // must maintain. It defaults to MIN_ASYNC_BUFFER_SLOTS and can be changed 3878072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian // by calling setBufferCount or setBufferCountServer 3888ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis int mBufferCount; 3898ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 390ae468f43418c3cbae74c7f546283f6bb4e4df690Jamie Gennis // mClientBufferCount is the number of buffer slots requested by the client. 391ae468f43418c3cbae74c7f546283f6bb4e4df690Jamie Gennis // The default is zero, which means the client doesn't care how many buffers 392ae468f43418c3cbae74c7f546283f6bb4e4df690Jamie Gennis // there is. 3938072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian int mClientBufferCount; 3948072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian 3958072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian // mServerBufferCount buffer count requested by the server-side 3968072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian int mServerBufferCount; 3978072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian 3988ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis // mCurrentTexture is the buffer slot index of the buffer that is currently 39967eedd74ab78c2bfed9fcdc74947b97289254ca4Jamie Gennis // bound to the OpenGL texture. It is initialized to INVALID_BUFFER_SLOT, 40067eedd74ab78c2bfed9fcdc74947b97289254ca4Jamie Gennis // indicating that no buffer slot is currently bound to the texture. Note, 40167eedd74ab78c2bfed9fcdc74947b97289254ca4Jamie Gennis // however, that a value of INVALID_BUFFER_SLOT does not necessarily mean 40267eedd74ab78c2bfed9fcdc74947b97289254ca4Jamie Gennis // that no buffer is bound to the texture. A call to setBufferCount will 40367eedd74ab78c2bfed9fcdc74947b97289254ca4Jamie Gennis // reset mCurrentTexture to INVALID_BUFFER_SLOT. 4048ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis int mCurrentTexture; 4058ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 4069a78c90cd46b2a3bd637b056873149d3b94384b4Jamie Gennis // mCurrentTextureBuf is the graphic buffer of the current texture. It's 4079a78c90cd46b2a3bd637b056873149d3b94384b4Jamie Gennis // possible that this buffer is not associated with any buffer slot, so we 40829c870271e8d3f8c40c356283650ba54fe71a16bJamie Gennis // must track it separately in order to support the getCurrentBuffer method. 4099a78c90cd46b2a3bd637b056873149d3b94384b4Jamie Gennis sp<GraphicBuffer> mCurrentTextureBuf; 4109a78c90cd46b2a3bd637b056873149d3b94384b4Jamie Gennis 411f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis // mCurrentCrop is the crop rectangle that applies to the current texture. 4127734ebfe47f42f980c1b44c1f284a91d8ad1d6c7Mathias Agopian // It gets set each time updateTexImage is called. 413f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis Rect mCurrentCrop; 414f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis 415f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis // mCurrentTransform is the transform identifier for the current texture. It 4167734ebfe47f42f980c1b44c1f284a91d8ad1d6c7Mathias Agopian // gets set each time updateTexImage is called. 417f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis uint32_t mCurrentTransform; 418f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis 4197734ebfe47f42f980c1b44c1f284a91d8ad1d6c7Mathias Agopian // mCurrentScalingMode is the scaling mode for the current texture. It gets 4207734ebfe47f42f980c1b44c1f284a91d8ad1d6c7Mathias Agopian // set to each time updateTexImage is called. 4217734ebfe47f42f980c1b44c1f284a91d8ad1d6c7Mathias Agopian uint32_t mCurrentScalingMode; 4227734ebfe47f42f980c1b44c1f284a91d8ad1d6c7Mathias Agopian 423736aa9573bb7b78f9c315f396c104491b3639426Jamie Gennis // mCurrentTransformMatrix is the transform matrix for the current texture. 424736aa9573bb7b78f9c315f396c104491b3639426Jamie Gennis // It gets computed by computeTransformMatrix each time updateTexImage is 425736aa9573bb7b78f9c315f396c104491b3639426Jamie Gennis // called. 426736aa9573bb7b78f9c315f396c104491b3639426Jamie Gennis float mCurrentTransformMatrix[16]; 427736aa9573bb7b78f9c315f396c104491b3639426Jamie Gennis 4281d01a12e7150be569557b64da9b8663c62c13594Eino-Ville Talvala // mCurrentTimestamp is the timestamp for the current texture. It 4297734ebfe47f42f980c1b44c1f284a91d8ad1d6c7Mathias Agopian // gets set each time updateTexImage is called. 4301d01a12e7150be569557b64da9b8663c62c13594Eino-Ville Talvala int64_t mCurrentTimestamp; 4311d01a12e7150be569557b64da9b8663c62c13594Eino-Ville Talvala 432f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis // mNextCrop is the crop rectangle that will be used for the next buffer 433f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis // that gets queued. It is set by calling setCrop. 434f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis Rect mNextCrop; 435f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis 436f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis // mNextTransform is the transform identifier that will be used for the next 437f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis // buffer that gets queued. It is set by calling setTransform. 438f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis uint32_t mNextTransform; 439f238e28500ca756fbd9e323f728ce7c8dda59475Jamie Gennis 4407734ebfe47f42f980c1b44c1f284a91d8ad1d6c7Mathias Agopian // mNextScalingMode is the scaling mode that will be used for the next 4417734ebfe47f42f980c1b44c1f284a91d8ad1d6c7Mathias Agopian // buffers that get queued. It is set by calling setScalingMode. 4427734ebfe47f42f980c1b44c1f284a91d8ad1d6c7Mathias Agopian int mNextScalingMode; 4437734ebfe47f42f980c1b44c1f284a91d8ad1d6c7Mathias Agopian 4448ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis // mTexName is the name of the OpenGL texture to which streamed images will 445292a31a4c2ae2f6faf134e8e4a726583017dad06Pannag Sanketi // be bound when updateTexImage is called. It is set at construction time 4468ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis // changed with a call to setTexName. 4478ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis const GLuint mTexName; 4488ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 4499a78c90cd46b2a3bd637b056873149d3b94384b4Jamie Gennis // mGraphicBufferAlloc is the connection to SurfaceFlinger that is used to 4509a78c90cd46b2a3bd637b056873149d3b94384b4Jamie Gennis // allocate new GraphicBuffer objects. 4519a78c90cd46b2a3bd637b056873149d3b94384b4Jamie Gennis sp<IGraphicBufferAlloc> mGraphicBufferAlloc; 4529a78c90cd46b2a3bd637b056873149d3b94384b4Jamie Gennis 453c4d4aeab52435c177ded6abdd578fec8191f0f5dJamie Gennis // mFrameAvailableListener is the listener object that will be called when a 454c4d4aeab52435c177ded6abdd578fec8191f0f5dJamie Gennis // new frame becomes available. If it is not NULL it will be called from 455c4d4aeab52435c177ded6abdd578fec8191f0f5dJamie Gennis // queueBuffer. 456c4d4aeab52435c177ded6abdd578fec8191f0f5dJamie Gennis sp<FrameAvailableListener> mFrameAvailableListener; 457c4d4aeab52435c177ded6abdd578fec8191f0f5dJamie Gennis 458b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian // mSynchronousMode whether we're in synchronous mode or not 459b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian bool mSynchronousMode; 460b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian 46114a0e58074f2698829b6554f578e6762c377caa3Grace Kloba // mAllowSynchronousMode whether we allow synchronous mode or not 46214a0e58074f2698829b6554f578e6762c377caa3Grace Kloba const bool mAllowSynchronousMode; 46314a0e58074f2698829b6554f578e6762c377caa3Grace Kloba 464fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis // mConnectedApi indicates the API that is currently connected to this 465fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis // SurfaceTexture. It defaults to NO_CONNECTED_API (= 0), and gets updated 466fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis // by the connect and disconnect methods. 467fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis int mConnectedApi; 468fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis 469b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian // mDequeueCondition condition used for dequeueBuffer in synchronous mode 470b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian mutable Condition mDequeueCondition; 471b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian 472b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian // mQueue is a FIFO of queued buffers used in synchronous mode 473b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian typedef Vector<int> Fifo; 474b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian Fifo mQueue; 475b3e518c820c7dbe35587bd45c510e4e5e7cfd9c9Mathias Agopian 4767b305fffc39d0fe0926e7fd2d7f6a524fbce62b7Jamie Gennis // mAbandoned indicates that the SurfaceTexture will no longer be used to 4777b305fffc39d0fe0926e7fd2d7f6a524fbce62b7Jamie Gennis // consume images buffers pushed to it using the ISurfaceTexture interface. 4787b305fffc39d0fe0926e7fd2d7f6a524fbce62b7Jamie Gennis // It is initialized to false, and set to true in the abandon method. A 4797b305fffc39d0fe0926e7fd2d7f6a524fbce62b7Jamie Gennis // SurfaceTexture that has been abandoned will return the NO_INIT error from 4807b305fffc39d0fe0926e7fd2d7f6a524fbce62b7Jamie Gennis // all ISurfaceTexture methods capable of returning an error. 4817b305fffc39d0fe0926e7fd2d7f6a524fbce62b7Jamie Gennis bool mAbandoned; 4827b305fffc39d0fe0926e7fd2d7f6a524fbce62b7Jamie Gennis 483fa28c35c21d1bf8b38f541758c291bc17a2d7270Jamie Gennis // mName is a string used to identify the SurfaceTexture in log messages. 484fa28c35c21d1bf8b38f541758c291bc17a2d7270Jamie Gennis // It is set by the setName method. 485fa28c35c21d1bf8b38f541758c291bc17a2d7270Jamie Gennis String8 mName; 486fa28c35c21d1bf8b38f541758c291bc17a2d7270Jamie Gennis 48786edf4f6470ee0f108bf40d3c1d23bf0a78c9c38Jamie Gennis // mUseFenceSync indicates whether creation of the EGL_KHR_fence_sync 48886edf4f6470ee0f108bf40d3c1d23bf0a78c9c38Jamie Gennis // extension should be used to prevent buffers from being dequeued before 48986edf4f6470ee0f108bf40d3c1d23bf0a78c9c38Jamie Gennis // it's safe for them to be written. It gets set at construction time and 49086edf4f6470ee0f108bf40d3c1d23bf0a78c9c38Jamie Gennis // never changes. 49186edf4f6470ee0f108bf40d3c1d23bf0a78c9c38Jamie Gennis const bool mUseFenceSync; 49286edf4f6470ee0f108bf40d3c1d23bf0a78c9c38Jamie Gennis 4938ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis // mMutex is the mutex used to prevent concurrent access to the member 4948ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis // variables of SurfaceTexture objects. It must be locked whenever the 4958ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis // member variables are accessed. 4967a042bf324fe3f3d5d4085fda21fe50dc0c362b4Mathias Agopian mutable Mutex mMutex; 497736aa9573bb7b78f9c315f396c104491b3639426Jamie Gennis 498fb1b5a2f333800574b0da435d1200cf9b13d723fJamie Gennis // mTexTarget is the GL texture target with which the GL texture object is 499fb1b5a2f333800574b0da435d1200cf9b13d723fJamie Gennis // associated. It is set in the constructor and never changed. It is 500fb1b5a2f333800574b0da435d1200cf9b13d723fJamie Gennis // almost always GL_TEXTURE_EXTERNAL_OES except for one use case in Android 501fb1b5a2f333800574b0da435d1200cf9b13d723fJamie Gennis // Browser. In that case it is set to GL_TEXTURE_2D to allow 502fb1b5a2f333800574b0da435d1200cf9b13d723fJamie Gennis // glCopyTexSubImage to read from the texture. This is a hack to work 503fb1b5a2f333800574b0da435d1200cf9b13d723fJamie Gennis // around a GL driver limitation on the number of FBO attachments, which the 504fb1b5a2f333800574b0da435d1200cf9b13d723fJamie Gennis // browser's tile cache exceeds. 505fb1b5a2f333800574b0da435d1200cf9b13d723fJamie Gennis const GLenum mTexTarget; 506a929748ddb67cbece3337c7fda7877fdeb973aa4Sunita Nadampalli 507a929748ddb67cbece3337c7fda7877fdeb973aa4Sunita Nadampalli // mFrameCounter is the free running counter, incremented for every buffer queued 508a929748ddb67cbece3337c7fda7877fdeb973aa4Sunita Nadampalli // with the surface Texture. 509a929748ddb67cbece3337c7fda7877fdeb973aa4Sunita Nadampalli uint64_t mFrameCounter; 510a929748ddb67cbece3337c7fda7877fdeb973aa4Sunita Nadampalli 511a929748ddb67cbece3337c7fda7877fdeb973aa4Sunita Nadampalli 5128ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis}; 5138ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 5148ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis// ---------------------------------------------------------------------------- 5158ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis}; // namespace android 5168ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 5178ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis#endif // ANDROID_GUI_SURFACETEXTURE_H 518