Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef ANDROID_GUI_SURFACETEXTURE_H |
| 18 | #define ANDROID_GUI_SURFACETEXTURE_H |
| 19 | |
| 20 | #include <EGL/egl.h> |
| 21 | #include <EGL/eglext.h> |
| 22 | #include <GLES2/gl2.h> |
| 23 | |
| 24 | #include <gui/ISurfaceTexture.h> |
| 25 | |
| 26 | #include <ui/GraphicBuffer.h> |
| 27 | |
| 28 | #include <utils/threads.h> |
Jamie Gennis | 9a78c90 | 2011-01-12 18:30:40 -0800 | [diff] [blame] | 29 | #include <utils/Vector.h> |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 30 | |
| 31 | #define ANDROID_GRAPHICS_SURFACETEXTURE_JNI_ID "mSurfaceTexture" |
| 32 | |
| 33 | namespace android { |
| 34 | // ---------------------------------------------------------------------------- |
| 35 | |
Jamie Gennis | 9a78c90 | 2011-01-12 18:30:40 -0800 | [diff] [blame] | 36 | class IGraphicBufferAlloc; |
Mathias Agopian | 68c7794 | 2011-05-09 19:08:33 -0700 | [diff] [blame] | 37 | class String8; |
Jamie Gennis | 9a78c90 | 2011-01-12 18:30:40 -0800 | [diff] [blame] | 38 | |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 39 | class SurfaceTexture : public BnSurfaceTexture { |
| 40 | public: |
Jamie Gennis | 9d4d6c1 | 2011-02-27 14:10:20 -0800 | [diff] [blame] | 41 | enum { MIN_UNDEQUEUED_BUFFERS = 2 }; |
Mathias Agopian | 8072711 | 2011-05-02 19:51:12 -0700 | [diff] [blame] | 42 | enum { |
| 43 | MIN_ASYNC_BUFFER_SLOTS = MIN_UNDEQUEUED_BUFFERS + 1, |
| 44 | MIN_SYNC_BUFFER_SLOTS = MIN_UNDEQUEUED_BUFFERS |
| 45 | }; |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 46 | enum { NUM_BUFFER_SLOTS = 32 }; |
Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame^] | 47 | enum { NO_CONNECTED_API = 0 }; |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 48 | |
Jamie Gennis | c4d4aea | 2011-01-13 14:43:36 -0800 | [diff] [blame] | 49 | struct FrameAvailableListener : public virtual RefBase { |
Jamie Gennis | 3d8063b | 2011-06-26 18:27:47 -0700 | [diff] [blame] | 50 | // onFrameAvailable() is called from queueBuffer() each time an |
| 51 | // additional frame becomes available for consumption. This means that |
| 52 | // frames that are queued while in asynchronous mode only trigger the |
| 53 | // callback if no previous frames are pending. Frames queued while in |
| 54 | // synchronous mode always trigger the callback. |
| 55 | // |
| 56 | // This is called without any lock held and can be called concurrently |
| 57 | // by multiple threads. |
Jamie Gennis | c4d4aea | 2011-01-13 14:43:36 -0800 | [diff] [blame] | 58 | virtual void onFrameAvailable() = 0; |
| 59 | }; |
| 60 | |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 61 | // tex indicates the name OpenGL texture to which images are to be streamed. |
| 62 | // This texture name cannot be changed once the SurfaceTexture is created. |
Grace Kloba | 14a0e58 | 2011-06-23 21:21:47 -0700 | [diff] [blame] | 63 | SurfaceTexture(GLuint tex, bool allowSynchronousMode = true); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 64 | |
| 65 | virtual ~SurfaceTexture(); |
| 66 | |
| 67 | // setBufferCount updates the number of available buffer slots. After |
| 68 | // calling this all buffer slots are both unallocated and owned by the |
| 69 | // SurfaceTexture object (i.e. they are not owned by the client). |
| 70 | virtual status_t setBufferCount(int bufferCount); |
| 71 | |
Mathias Agopian | c04f153 | 2011-04-25 20:22:14 -0700 | [diff] [blame] | 72 | virtual sp<GraphicBuffer> requestBuffer(int buf); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 73 | |
| 74 | // dequeueBuffer gets the next buffer slot index for the client to use. If a |
| 75 | // buffer slot is available then that slot index is written to the location |
| 76 | // pointed to by the buf argument and a status of OK is returned. If no |
| 77 | // slot is available then a status of -EBUSY is returned and buf is |
| 78 | // unmodified. |
Mathias Agopian | c04f153 | 2011-04-25 20:22:14 -0700 | [diff] [blame] | 79 | virtual status_t dequeueBuffer(int *buf, uint32_t w, uint32_t h, |
| 80 | uint32_t format, uint32_t usage); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 81 | |
Eino-Ville Talvala | 1d01a12 | 2011-02-18 11:02:42 -0800 | [diff] [blame] | 82 | // queueBuffer returns a filled buffer to the SurfaceTexture. In addition, a |
| 83 | // timestamp must be provided for the buffer. The timestamp is in |
| 84 | // nanoseconds, and must be monotonically increasing. Its other semantics |
| 85 | // (zero point, etc) are client-dependent and should be documented by the |
| 86 | // client. |
| 87 | virtual status_t queueBuffer(int buf, int64_t timestamp); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 88 | virtual void cancelBuffer(int buf); |
| 89 | virtual status_t setCrop(const Rect& reg); |
| 90 | virtual status_t setTransform(uint32_t transform); |
| 91 | |
Mathias Agopian | eafabcd | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 92 | virtual int query(int what, int* value); |
| 93 | |
Mathias Agopian | 8072711 | 2011-05-02 19:51:12 -0700 | [diff] [blame] | 94 | // setSynchronousMode set whether dequeueBuffer is synchronous or |
| 95 | // asynchronous. In synchronous mode, dequeueBuffer blocks until |
| 96 | // a buffer is available, the currently bound buffer can be dequeued and |
| 97 | // queued buffers will be retired in order. |
| 98 | // The default mode is asynchronous. |
| 99 | virtual status_t setSynchronousMode(bool enabled); |
| 100 | |
Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame^] | 101 | // connect attempts to connect a client API to the SurfaceTexture. This |
| 102 | // must be called before any other ISurfaceTexture methods are called except |
| 103 | // for getAllocator. |
| 104 | // |
| 105 | // This method will fail if the connect was previously called on the |
| 106 | // SurfaceTexture and no corresponding disconnect call was made. |
| 107 | virtual status_t connect(int api); |
| 108 | |
| 109 | // disconnect attempts to disconnect a client API from the SurfaceTexture. |
| 110 | // Calling this method will cause any subsequent calls to other |
| 111 | // ISurfaceTexture methods to fail except for getAllocator and connect. |
| 112 | // Successfully calling connect after this will allow the other methods to |
| 113 | // succeed again. |
| 114 | // |
| 115 | // This method will fail if the the SurfaceTexture is not currently |
| 116 | // connected to the specified client API. |
| 117 | virtual status_t disconnect(int api); |
| 118 | |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 119 | // updateTexImage sets the image contents of the target texture to that of |
| 120 | // the most recently queued buffer. |
| 121 | // |
| 122 | // This call may only be made while the OpenGL ES context to which the |
| 123 | // target texture belongs is bound to the calling thread. |
| 124 | status_t updateTexImage(); |
| 125 | |
Mathias Agopian | 8072711 | 2011-05-02 19:51:12 -0700 | [diff] [blame] | 126 | // setBufferCountServer set the buffer count. If the client has requested |
| 127 | // a buffer count using setBufferCount, the server-buffer count will |
| 128 | // take effect once the client sets the count back to zero. |
| 129 | status_t setBufferCountServer(int bufferCount); |
| 130 | |
Jamie Gennis | f238e28 | 2011-01-09 16:33:17 -0800 | [diff] [blame] | 131 | // getTransformMatrix retrieves the 4x4 texture coordinate transform matrix |
| 132 | // associated with the texture image set by the most recent call to |
| 133 | // updateTexImage. |
| 134 | // |
| 135 | // This transform matrix maps 2D homogeneous texture coordinates of the form |
| 136 | // (s, t, 0, 1) with s and t in the inclusive range [0, 1] to the texture |
| 137 | // coordinate that should be used to sample that location from the texture. |
| 138 | // Sampling the texture outside of the range of this transform is undefined. |
| 139 | // |
| 140 | // This transform is necessary to compensate for transforms that the stream |
| 141 | // content producer may implicitly apply to the content. By forcing users of |
| 142 | // a SurfaceTexture to apply this transform we avoid performing an extra |
| 143 | // copy of the data that would be needed to hide the transform from the |
| 144 | // user. |
| 145 | // |
| 146 | // The matrix is stored in column-major order so that it may be passed |
| 147 | // directly to OpenGL ES via the glLoadMatrixf or glUniformMatrix4fv |
| 148 | // functions. |
| 149 | void getTransformMatrix(float mtx[16]); |
| 150 | |
Eino-Ville Talvala | 1d01a12 | 2011-02-18 11:02:42 -0800 | [diff] [blame] | 151 | // getTimestamp retrieves the timestamp associated with the texture image |
| 152 | // set by the most recent call to updateTexImage. |
| 153 | // |
| 154 | // The timestamp is in nanoseconds, and is monotonically increasing. Its |
| 155 | // other semantics (zero point, etc) are source-dependent and should be |
| 156 | // documented by the source. |
| 157 | int64_t getTimestamp(); |
| 158 | |
Jamie Gennis | c4d4aea | 2011-01-13 14:43:36 -0800 | [diff] [blame] | 159 | // setFrameAvailableListener sets the listener object that will be notified |
| 160 | // when a new frame becomes available. |
Pannag Sanketi | 292a31a | 2011-06-24 09:56:27 -0700 | [diff] [blame] | 161 | void setFrameAvailableListener(const sp<FrameAvailableListener>& listener); |
Jamie Gennis | c4d4aea | 2011-01-13 14:43:36 -0800 | [diff] [blame] | 162 | |
Jamie Gennis | 1b20cde | 2011-02-02 15:31:47 -0800 | [diff] [blame] | 163 | // getAllocator retrieves the binder object that must be referenced as long |
| 164 | // as the GraphicBuffers dequeued from this SurfaceTexture are referenced. |
| 165 | // Holding this binder reference prevents SurfaceFlinger from freeing the |
| 166 | // buffers before the client is done with them. |
| 167 | sp<IBinder> getAllocator(); |
| 168 | |
Mathias Agopian | a5c75c0 | 2011-03-31 19:10:24 -0700 | [diff] [blame] | 169 | // setDefaultBufferSize is used to set the size of buffers returned by |
| 170 | // requestBuffers when a with and height of zero is requested. |
| 171 | // A call to setDefaultBufferSize() may trigger requestBuffers() to |
| 172 | // be called from the client. |
| 173 | status_t setDefaultBufferSize(uint32_t w, uint32_t h); |
| 174 | |
Mathias Agopian | 7a042bf | 2011-04-11 21:19:55 -0700 | [diff] [blame] | 175 | // getCurrentBuffer returns the buffer associated with the current image. |
| 176 | sp<GraphicBuffer> getCurrentBuffer() const; |
| 177 | |
| 178 | // getCurrentTextureTarget returns the texture target of the current |
| 179 | // texture as returned by updateTexImage(). |
| 180 | GLenum getCurrentTextureTarget() const; |
| 181 | |
| 182 | // getCurrentCrop returns the cropping rectangle of the current buffer |
| 183 | Rect getCurrentCrop() const; |
| 184 | |
| 185 | // getCurrentTransform returns the transform of the current buffer |
| 186 | uint32_t getCurrentTransform() const; |
| 187 | |
Mathias Agopian | 68c7794 | 2011-05-09 19:08:33 -0700 | [diff] [blame] | 188 | // dump our state in a String |
| 189 | void dump(String8& result) const; |
| 190 | void dump(String8& result, const char* prefix, char* buffer, size_t SIZE) const; |
| 191 | |
Mathias Agopian | 7a042bf | 2011-04-11 21:19:55 -0700 | [diff] [blame] | 192 | protected: |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 193 | |
| 194 | // freeAllBuffers frees the resources (both GraphicBuffer and EGLImage) for |
| 195 | // all slots. |
| 196 | void freeAllBuffers(); |
Mathias Agopian | 7a042bf | 2011-04-11 21:19:55 -0700 | [diff] [blame] | 197 | static bool isExternalFormat(uint32_t format); |
| 198 | static GLenum getTextureTarget(uint32_t format); |
| 199 | |
| 200 | private: |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 201 | |
| 202 | // createImage creates a new EGLImage from a GraphicBuffer. |
| 203 | EGLImageKHR createImage(EGLDisplay dpy, |
| 204 | const sp<GraphicBuffer>& graphicBuffer); |
| 205 | |
Mathias Agopian | 8072711 | 2011-05-02 19:51:12 -0700 | [diff] [blame] | 206 | status_t setBufferCountServerLocked(int bufferCount); |
| 207 | |
Jamie Gennis | 736aa95 | 2011-06-12 17:03:06 -0700 | [diff] [blame] | 208 | // computeCurrentTransformMatrix computes the transform matrix for the |
| 209 | // current texture. It uses mCurrentTransform and the current GraphicBuffer |
| 210 | // to compute this matrix and stores it in mCurrentTransformMatrix. |
| 211 | void computeCurrentTransformMatrix(); |
| 212 | |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 213 | enum { INVALID_BUFFER_SLOT = -1 }; |
| 214 | |
| 215 | struct BufferSlot { |
Mathias Agopian | b3e518c | 2011-04-21 18:52:51 -0700 | [diff] [blame] | 216 | |
| 217 | BufferSlot() |
| 218 | : mEglImage(EGL_NO_IMAGE_KHR), |
| 219 | mEglDisplay(EGL_NO_DISPLAY), |
| 220 | mBufferState(BufferSlot::FREE), |
| 221 | mRequestBufferCalled(false), |
Jamie Gennis | 8cd5ba4 | 2011-05-19 13:33:00 -0700 | [diff] [blame] | 222 | mTransform(0), |
| 223 | mTimestamp(0) { |
| 224 | mCrop.makeInvalid(); |
Mathias Agopian | b3e518c | 2011-04-21 18:52:51 -0700 | [diff] [blame] | 225 | } |
| 226 | |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 227 | // mGraphicBuffer points to the buffer allocated for this slot or is NULL |
| 228 | // if no buffer has been allocated. |
| 229 | sp<GraphicBuffer> mGraphicBuffer; |
| 230 | |
| 231 | // mEglImage is the EGLImage created from mGraphicBuffer. |
| 232 | EGLImageKHR mEglImage; |
| 233 | |
| 234 | // mEglDisplay is the EGLDisplay used to create mEglImage. |
| 235 | EGLDisplay mEglDisplay; |
| 236 | |
Jamie Gennis | 8cd5ba4 | 2011-05-19 13:33:00 -0700 | [diff] [blame] | 237 | // BufferState represents the different states in which a buffer slot |
| 238 | // can be. |
| 239 | enum BufferState { |
| 240 | // FREE indicates that the buffer is not currently being used and |
| 241 | // will not be used in the future until it gets dequeued and |
| 242 | // subseqently queued by the client. |
| 243 | FREE = 0, |
Mathias Agopian | b3e518c | 2011-04-21 18:52:51 -0700 | [diff] [blame] | 244 | |
Jamie Gennis | 8cd5ba4 | 2011-05-19 13:33:00 -0700 | [diff] [blame] | 245 | // DEQUEUED indicates that the buffer has been dequeued by the |
| 246 | // client, but has not yet been queued or canceled. The buffer is |
| 247 | // considered 'owned' by the client, and the server should not use |
| 248 | // it for anything. |
| 249 | // |
| 250 | // Note that when in synchronous-mode (mSynchronousMode == true), |
| 251 | // the buffer that's currently attached to the texture may be |
| 252 | // dequeued by the client. That means that the current buffer can |
| 253 | // be in either the DEQUEUED or QUEUED state. In asynchronous mode, |
| 254 | // however, the current buffer is always in the QUEUED state. |
| 255 | DEQUEUED = 1, |
| 256 | |
| 257 | // QUEUED indicates that the buffer has been queued by the client, |
| 258 | // and has not since been made available for the client to dequeue. |
| 259 | // Attaching the buffer to the texture does NOT transition the |
| 260 | // buffer away from the QUEUED state. However, in Synchronous mode |
| 261 | // the current buffer may be dequeued by the client under some |
| 262 | // circumstances. See the note about the current buffer in the |
| 263 | // documentation for DEQUEUED. |
| 264 | QUEUED = 2, |
| 265 | }; |
| 266 | |
| 267 | // mBufferState is the current state of this buffer slot. |
| 268 | BufferState mBufferState; |
Mathias Agopian | b3e518c | 2011-04-21 18:52:51 -0700 | [diff] [blame] | 269 | |
| 270 | // mRequestBufferCalled is used for validating that the client did |
| 271 | // call requestBuffer() when told to do so. Technically this is not |
| 272 | // needed but useful for debugging and catching client bugs. |
| 273 | bool mRequestBufferCalled; |
| 274 | |
Jamie Gennis | 8cd5ba4 | 2011-05-19 13:33:00 -0700 | [diff] [blame] | 275 | // mCrop is the current crop rectangle for this buffer slot. This gets |
| 276 | // set to mNextCrop each time queueBuffer gets called for this buffer. |
| 277 | Rect mCrop; |
Mathias Agopian | b3e518c | 2011-04-21 18:52:51 -0700 | [diff] [blame] | 278 | |
Jamie Gennis | 8cd5ba4 | 2011-05-19 13:33:00 -0700 | [diff] [blame] | 279 | // mTransform is the current transform flags for this buffer slot. This |
| 280 | // gets set to mNextTransform each time queueBuffer gets called for this |
| 281 | // slot. |
| 282 | uint32_t mTransform; |
Mathias Agopian | b3e518c | 2011-04-21 18:52:51 -0700 | [diff] [blame] | 283 | |
Jamie Gennis | 8cd5ba4 | 2011-05-19 13:33:00 -0700 | [diff] [blame] | 284 | // mTimestamp is the current timestamp for this buffer slot. This gets |
| 285 | // to set by queueBuffer each time this slot is queued. |
| 286 | int64_t mTimestamp; |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 287 | }; |
| 288 | |
| 289 | // mSlots is the array of buffer slots that must be mirrored on the client |
| 290 | // side. This allows buffer ownership to be transferred between the client |
| 291 | // and server without sending a GraphicBuffer over binder. The entire array |
| 292 | // is initialized to NULL at construction time, and buffers are allocated |
| 293 | // for a slot when requestBuffer is called with that slot's index. |
| 294 | BufferSlot mSlots[NUM_BUFFER_SLOTS]; |
| 295 | |
Mathias Agopian | a5c75c0 | 2011-03-31 19:10:24 -0700 | [diff] [blame] | 296 | // mDefaultWidth holds the default width of allocated buffers. It is used |
| 297 | // in requestBuffers() if a width and height of zero is specified. |
| 298 | uint32_t mDefaultWidth; |
| 299 | |
| 300 | // mDefaultHeight holds the default height of allocated buffers. It is used |
| 301 | // in requestBuffers() if a width and height of zero is specified. |
| 302 | uint32_t mDefaultHeight; |
| 303 | |
| 304 | // mPixelFormat holds the pixel format of allocated buffers. It is used |
| 305 | // in requestBuffers() if a format of zero is specified. |
| 306 | uint32_t mPixelFormat; |
| 307 | |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 308 | // mBufferCount is the number of buffer slots that the client and server |
Mathias Agopian | 8072711 | 2011-05-02 19:51:12 -0700 | [diff] [blame] | 309 | // must maintain. It defaults to MIN_ASYNC_BUFFER_SLOTS and can be changed |
| 310 | // by calling setBufferCount or setBufferCountServer |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 311 | int mBufferCount; |
| 312 | |
Jamie Gennis | ae468f4 | 2011-06-12 14:11:39 -0700 | [diff] [blame] | 313 | // mClientBufferCount is the number of buffer slots requested by the client. |
| 314 | // The default is zero, which means the client doesn't care how many buffers |
| 315 | // there is. |
Mathias Agopian | 8072711 | 2011-05-02 19:51:12 -0700 | [diff] [blame] | 316 | int mClientBufferCount; |
| 317 | |
| 318 | // mServerBufferCount buffer count requested by the server-side |
| 319 | int mServerBufferCount; |
| 320 | |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 321 | // mCurrentTexture is the buffer slot index of the buffer that is currently |
Jamie Gennis | 67eedd7 | 2011-01-09 13:25:39 -0800 | [diff] [blame] | 322 | // bound to the OpenGL texture. It is initialized to INVALID_BUFFER_SLOT, |
| 323 | // indicating that no buffer slot is currently bound to the texture. Note, |
| 324 | // however, that a value of INVALID_BUFFER_SLOT does not necessarily mean |
| 325 | // that no buffer is bound to the texture. A call to setBufferCount will |
| 326 | // reset mCurrentTexture to INVALID_BUFFER_SLOT. |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 327 | int mCurrentTexture; |
| 328 | |
Mathias Agopian | 7a042bf | 2011-04-11 21:19:55 -0700 | [diff] [blame] | 329 | // mCurrentTextureTarget is the GLES texture target to be used with the |
| 330 | // current texture. |
| 331 | GLenum mCurrentTextureTarget; |
| 332 | |
Jamie Gennis | 9a78c90 | 2011-01-12 18:30:40 -0800 | [diff] [blame] | 333 | // mCurrentTextureBuf is the graphic buffer of the current texture. It's |
| 334 | // possible that this buffer is not associated with any buffer slot, so we |
| 335 | // must track it separately in order to properly use |
| 336 | // IGraphicBufferAlloc::freeAllGraphicBuffersExcept. |
| 337 | sp<GraphicBuffer> mCurrentTextureBuf; |
| 338 | |
Jamie Gennis | f238e28 | 2011-01-09 16:33:17 -0800 | [diff] [blame] | 339 | // mCurrentCrop is the crop rectangle that applies to the current texture. |
| 340 | // It gets set to mLastQueuedCrop each time updateTexImage is called. |
| 341 | Rect mCurrentCrop; |
| 342 | |
| 343 | // mCurrentTransform is the transform identifier for the current texture. It |
| 344 | // gets set to mLastQueuedTransform each time updateTexImage is called. |
| 345 | uint32_t mCurrentTransform; |
| 346 | |
Jamie Gennis | 736aa95 | 2011-06-12 17:03:06 -0700 | [diff] [blame] | 347 | // mCurrentTransformMatrix is the transform matrix for the current texture. |
| 348 | // It gets computed by computeTransformMatrix each time updateTexImage is |
| 349 | // called. |
| 350 | float mCurrentTransformMatrix[16]; |
| 351 | |
Eino-Ville Talvala | 1d01a12 | 2011-02-18 11:02:42 -0800 | [diff] [blame] | 352 | // mCurrentTimestamp is the timestamp for the current texture. It |
| 353 | // gets set to mLastQueuedTimestamp each time updateTexImage is called. |
| 354 | int64_t mCurrentTimestamp; |
| 355 | |
Jamie Gennis | f238e28 | 2011-01-09 16:33:17 -0800 | [diff] [blame] | 356 | // mNextCrop is the crop rectangle that will be used for the next buffer |
| 357 | // that gets queued. It is set by calling setCrop. |
| 358 | Rect mNextCrop; |
| 359 | |
| 360 | // mNextTransform is the transform identifier that will be used for the next |
| 361 | // buffer that gets queued. It is set by calling setTransform. |
| 362 | uint32_t mNextTransform; |
| 363 | |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 364 | // mTexName is the name of the OpenGL texture to which streamed images will |
Pannag Sanketi | 292a31a | 2011-06-24 09:56:27 -0700 | [diff] [blame] | 365 | // be bound when updateTexImage is called. It is set at construction time |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 366 | // changed with a call to setTexName. |
| 367 | const GLuint mTexName; |
| 368 | |
Jamie Gennis | 9a78c90 | 2011-01-12 18:30:40 -0800 | [diff] [blame] | 369 | // mGraphicBufferAlloc is the connection to SurfaceFlinger that is used to |
| 370 | // allocate new GraphicBuffer objects. |
| 371 | sp<IGraphicBufferAlloc> mGraphicBufferAlloc; |
| 372 | |
Jamie Gennis | c4d4aea | 2011-01-13 14:43:36 -0800 | [diff] [blame] | 373 | // mFrameAvailableListener is the listener object that will be called when a |
| 374 | // new frame becomes available. If it is not NULL it will be called from |
| 375 | // queueBuffer. |
| 376 | sp<FrameAvailableListener> mFrameAvailableListener; |
| 377 | |
Mathias Agopian | b3e518c | 2011-04-21 18:52:51 -0700 | [diff] [blame] | 378 | // mSynchronousMode whether we're in synchronous mode or not |
| 379 | bool mSynchronousMode; |
| 380 | |
Grace Kloba | 14a0e58 | 2011-06-23 21:21:47 -0700 | [diff] [blame] | 381 | // mAllowSynchronousMode whether we allow synchronous mode or not |
| 382 | const bool mAllowSynchronousMode; |
| 383 | |
Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame^] | 384 | // mConnectedApi indicates the API that is currently connected to this |
| 385 | // SurfaceTexture. It defaults to NO_CONNECTED_API (= 0), and gets updated |
| 386 | // by the connect and disconnect methods. |
| 387 | int mConnectedApi; |
| 388 | |
Mathias Agopian | b3e518c | 2011-04-21 18:52:51 -0700 | [diff] [blame] | 389 | // mDequeueCondition condition used for dequeueBuffer in synchronous mode |
| 390 | mutable Condition mDequeueCondition; |
| 391 | |
| 392 | // mQueue is a FIFO of queued buffers used in synchronous mode |
| 393 | typedef Vector<int> Fifo; |
| 394 | Fifo mQueue; |
| 395 | |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 396 | // mMutex is the mutex used to prevent concurrent access to the member |
| 397 | // variables of SurfaceTexture objects. It must be locked whenever the |
| 398 | // member variables are accessed. |
Mathias Agopian | 7a042bf | 2011-04-11 21:19:55 -0700 | [diff] [blame] | 399 | mutable Mutex mMutex; |
Jamie Gennis | 736aa95 | 2011-06-12 17:03:06 -0700 | [diff] [blame] | 400 | |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 401 | }; |
| 402 | |
| 403 | // ---------------------------------------------------------------------------- |
| 404 | }; // namespace android |
| 405 | |
| 406 | #endif // ANDROID_GUI_SURFACETEXTURE_H |