blob: 926eb9a82c17c1af9db84b339e09ffd68281cd02 [file] [log] [blame]
Jamie Gennis8ba32fa2010-12-20 11:27:26 -08001/*
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
Jamie Gennisfa28c352011-09-16 17:30:26 -070028#include <utils/String8.h>
Jamie Gennis9a78c902011-01-12 18:30:40 -080029#include <utils/Vector.h>
Jamie Gennisfa28c352011-09-16 17:30:26 -070030#include <utils/threads.h>
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080031
32#define ANDROID_GRAPHICS_SURFACETEXTURE_JNI_ID "mSurfaceTexture"
33
34namespace android {
35// ----------------------------------------------------------------------------
36
Jamie Gennis9a78c902011-01-12 18:30:40 -080037class IGraphicBufferAlloc;
Mathias Agopian68c77942011-05-09 19:08:33 -070038class String8;
Jamie Gennis9a78c902011-01-12 18:30:40 -080039
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080040class SurfaceTexture : public BnSurfaceTexture {
41public:
Jamie Gennis9d4d6c12011-02-27 14:10:20 -080042 enum { MIN_UNDEQUEUED_BUFFERS = 2 };
Mathias Agopian80727112011-05-02 19:51:12 -070043 enum {
44 MIN_ASYNC_BUFFER_SLOTS = MIN_UNDEQUEUED_BUFFERS + 1,
45 MIN_SYNC_BUFFER_SLOTS = MIN_UNDEQUEUED_BUFFERS
46 };
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080047 enum { NUM_BUFFER_SLOTS = 32 };
Jamie Gennisfe0a87b2011-07-13 19:12:20 -070048 enum { NO_CONNECTED_API = 0 };
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080049
Jamie Gennisc4d4aea2011-01-13 14:43:36 -080050 struct FrameAvailableListener : public virtual RefBase {
Jamie Gennis3d8063b2011-06-26 18:27:47 -070051 // onFrameAvailable() is called from queueBuffer() each time an
52 // additional frame becomes available for consumption. This means that
53 // frames that are queued while in asynchronous mode only trigger the
54 // callback if no previous frames are pending. Frames queued while in
55 // synchronous mode always trigger the callback.
56 //
57 // This is called without any lock held and can be called concurrently
58 // by multiple threads.
Jamie Gennisc4d4aea2011-01-13 14:43:36 -080059 virtual void onFrameAvailable() = 0;
60 };
61
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080062 // tex indicates the name OpenGL texture to which images are to be streamed.
63 // This texture name cannot be changed once the SurfaceTexture is created.
Grace Kloba14a0e582011-06-23 21:21:47 -070064 SurfaceTexture(GLuint tex, bool allowSynchronousMode = true);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080065
66 virtual ~SurfaceTexture();
67
68 // setBufferCount updates the number of available buffer slots. After
69 // calling this all buffer slots are both unallocated and owned by the
70 // SurfaceTexture object (i.e. they are not owned by the client).
71 virtual status_t setBufferCount(int bufferCount);
72
Jamie Gennis7b305ff2011-07-19 12:08:33 -070073 virtual status_t requestBuffer(int slot, sp<GraphicBuffer>* buf);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080074
75 // dequeueBuffer gets the next buffer slot index for the client to use. If a
76 // buffer slot is available then that slot index is written to the location
77 // pointed to by the buf argument and a status of OK is returned. If no
78 // slot is available then a status of -EBUSY is returned and buf is
79 // unmodified.
Mathias Agopianc04f1532011-04-25 20:22:14 -070080 virtual status_t dequeueBuffer(int *buf, uint32_t w, uint32_t h,
81 uint32_t format, uint32_t usage);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080082
Eino-Ville Talvala1d01a122011-02-18 11:02:42 -080083 // queueBuffer returns a filled buffer to the SurfaceTexture. In addition, a
84 // timestamp must be provided for the buffer. The timestamp is in
85 // nanoseconds, and must be monotonically increasing. Its other semantics
86 // (zero point, etc) are client-dependent and should be documented by the
87 // client.
Mathias Agopian97c602c2011-07-19 15:24:46 -070088 virtual status_t queueBuffer(int buf, int64_t timestamp,
89 uint32_t* outWidth, uint32_t* outHeight, uint32_t* outTransform);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080090 virtual void cancelBuffer(int buf);
91 virtual status_t setCrop(const Rect& reg);
92 virtual status_t setTransform(uint32_t transform);
Mathias Agopian7734ebf2011-07-13 15:24:42 -070093 virtual status_t setScalingMode(int mode);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080094
Mathias Agopianeafabcd2011-04-20 14:20:59 -070095 virtual int query(int what, int* value);
96
Mathias Agopian80727112011-05-02 19:51:12 -070097 // setSynchronousMode set whether dequeueBuffer is synchronous or
98 // asynchronous. In synchronous mode, dequeueBuffer blocks until
99 // a buffer is available, the currently bound buffer can be dequeued and
100 // queued buffers will be retired in order.
101 // The default mode is asynchronous.
102 virtual status_t setSynchronousMode(bool enabled);
103
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700104 // connect attempts to connect a client API to the SurfaceTexture. This
105 // must be called before any other ISurfaceTexture methods are called except
106 // for getAllocator.
107 //
108 // This method will fail if the connect was previously called on the
109 // SurfaceTexture and no corresponding disconnect call was made.
Mathias Agopian5bfc2452011-08-08 19:14:03 -0700110 virtual status_t connect(int api,
111 uint32_t* outWidth, uint32_t* outHeight, uint32_t* outTransform);
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700112
113 // disconnect attempts to disconnect a client API from the SurfaceTexture.
114 // Calling this method will cause any subsequent calls to other
115 // ISurfaceTexture methods to fail except for getAllocator and connect.
116 // Successfully calling connect after this will allow the other methods to
117 // succeed again.
118 //
119 // This method will fail if the the SurfaceTexture is not currently
120 // connected to the specified client API.
121 virtual status_t disconnect(int api);
122
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800123 // updateTexImage sets the image contents of the target texture to that of
124 // the most recently queued buffer.
125 //
126 // This call may only be made while the OpenGL ES context to which the
127 // target texture belongs is bound to the calling thread.
128 status_t updateTexImage();
129
Mathias Agopian80727112011-05-02 19:51:12 -0700130 // setBufferCountServer set the buffer count. If the client has requested
131 // a buffer count using setBufferCount, the server-buffer count will
132 // take effect once the client sets the count back to zero.
133 status_t setBufferCountServer(int bufferCount);
134
Jamie Gennisf238e282011-01-09 16:33:17 -0800135 // getTransformMatrix retrieves the 4x4 texture coordinate transform matrix
136 // associated with the texture image set by the most recent call to
137 // updateTexImage.
138 //
139 // This transform matrix maps 2D homogeneous texture coordinates of the form
140 // (s, t, 0, 1) with s and t in the inclusive range [0, 1] to the texture
141 // coordinate that should be used to sample that location from the texture.
142 // Sampling the texture outside of the range of this transform is undefined.
143 //
144 // This transform is necessary to compensate for transforms that the stream
145 // content producer may implicitly apply to the content. By forcing users of
146 // a SurfaceTexture to apply this transform we avoid performing an extra
147 // copy of the data that would be needed to hide the transform from the
148 // user.
149 //
150 // The matrix is stored in column-major order so that it may be passed
151 // directly to OpenGL ES via the glLoadMatrixf or glUniformMatrix4fv
152 // functions.
153 void getTransformMatrix(float mtx[16]);
154
Eino-Ville Talvala1d01a122011-02-18 11:02:42 -0800155 // getTimestamp retrieves the timestamp associated with the texture image
156 // set by the most recent call to updateTexImage.
157 //
158 // The timestamp is in nanoseconds, and is monotonically increasing. Its
159 // other semantics (zero point, etc) are source-dependent and should be
160 // documented by the source.
161 int64_t getTimestamp();
162
Jamie Gennisc4d4aea2011-01-13 14:43:36 -0800163 // setFrameAvailableListener sets the listener object that will be notified
164 // when a new frame becomes available.
Pannag Sanketi292a31a2011-06-24 09:56:27 -0700165 void setFrameAvailableListener(const sp<FrameAvailableListener>& listener);
Jamie Gennisc4d4aea2011-01-13 14:43:36 -0800166
Jamie Gennis1b20cde2011-02-02 15:31:47 -0800167 // getAllocator retrieves the binder object that must be referenced as long
168 // as the GraphicBuffers dequeued from this SurfaceTexture are referenced.
169 // Holding this binder reference prevents SurfaceFlinger from freeing the
170 // buffers before the client is done with them.
171 sp<IBinder> getAllocator();
172
Mathias Agopiana5c75c02011-03-31 19:10:24 -0700173 // setDefaultBufferSize is used to set the size of buffers returned by
174 // requestBuffers when a with and height of zero is requested.
175 // A call to setDefaultBufferSize() may trigger requestBuffers() to
176 // be called from the client.
177 status_t setDefaultBufferSize(uint32_t w, uint32_t h);
178
Mathias Agopian7a042bf2011-04-11 21:19:55 -0700179 // getCurrentBuffer returns the buffer associated with the current image.
180 sp<GraphicBuffer> getCurrentBuffer() const;
181
182 // getCurrentTextureTarget returns the texture target of the current
183 // texture as returned by updateTexImage().
184 GLenum getCurrentTextureTarget() const;
185
186 // getCurrentCrop returns the cropping rectangle of the current buffer
187 Rect getCurrentCrop() const;
188
189 // getCurrentTransform returns the transform of the current buffer
190 uint32_t getCurrentTransform() const;
191
Mathias Agopian7734ebf2011-07-13 15:24:42 -0700192 // getCurrentScalingMode returns the scaling mode of the current buffer
193 uint32_t getCurrentScalingMode() const;
194
Jamie Gennis7b305ff2011-07-19 12:08:33 -0700195 // abandon frees all the buffers and puts the SurfaceTexture into the
196 // 'abandoned' state. Once put in this state the SurfaceTexture can never
197 // leave it. When in the 'abandoned' state, all methods of the
198 // ISurfaceTexture interface will fail with the NO_INIT error.
199 //
200 // Note that while calling this method causes all the buffers to be freed
201 // from the perspective of the the SurfaceTexture, if there are additional
202 // references on the buffers (e.g. if a buffer is referenced by a client or
203 // by OpenGL ES as a texture) then those buffer will remain allocated.
204 void abandon();
205
Jamie Gennisfa28c352011-09-16 17:30:26 -0700206 // set the name of the SurfaceTexture that will be used to identify it in
207 // log messages.
208 void setName(const String8& name);
209
Mathias Agopian68c77942011-05-09 19:08:33 -0700210 // dump our state in a String
211 void dump(String8& result) const;
212 void dump(String8& result, const char* prefix, char* buffer, size_t SIZE) const;
213
Mathias Agopian7a042bf2011-04-11 21:19:55 -0700214protected:
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800215
Mathias Agopian8e19c2e2011-08-10 17:35:09 -0700216 // freeBufferLocked frees the resources (both GraphicBuffer and EGLImage)
217 // for the given slot.
218 void freeBufferLocked(int index);
219
220 // freeAllBuffersLocked frees the resources (both GraphicBuffer and
221 // EGLImage) for all slots.
Mathias Agopianef51b992011-08-10 15:28:58 -0700222 void freeAllBuffersLocked();
Mathias Agopian2560d142011-08-10 16:33:23 -0700223
Mathias Agopian8e19c2e2011-08-10 17:35:09 -0700224 // freeAllBuffersExceptHeadLocked frees the resources (both GraphicBuffer
225 // and EGLImage) for all slots except the head of mQueue
226 void freeAllBuffersExceptHeadLocked();
227
Mathias Agopian2560d142011-08-10 16:33:23 -0700228 // drainQueueLocked drains the buffer queue if we're in synchronous mode
Mathias Agopian8e19c2e2011-08-10 17:35:09 -0700229 // returns immediately otherwise. return NO_INIT if SurfaceTexture
230 // became abandoned or disconnected during this call.
231 status_t drainQueueLocked();
232
233 // drainQueueAndFreeBuffersLocked drains the buffer queue if we're in
234 // synchronous mode and free all buffers. In asynchronous mode, all buffers
235 // are freed except the current buffer.
236 status_t drainQueueAndFreeBuffersLocked();
Mathias Agopian2560d142011-08-10 16:33:23 -0700237
Mathias Agopian7a042bf2011-04-11 21:19:55 -0700238 static bool isExternalFormat(uint32_t format);
Mathias Agopian7a042bf2011-04-11 21:19:55 -0700239
240private:
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800241
242 // createImage creates a new EGLImage from a GraphicBuffer.
243 EGLImageKHR createImage(EGLDisplay dpy,
244 const sp<GraphicBuffer>& graphicBuffer);
245
Mathias Agopian80727112011-05-02 19:51:12 -0700246 status_t setBufferCountServerLocked(int bufferCount);
247
Jamie Gennis736aa952011-06-12 17:03:06 -0700248 // computeCurrentTransformMatrix computes the transform matrix for the
249 // current texture. It uses mCurrentTransform and the current GraphicBuffer
250 // to compute this matrix and stores it in mCurrentTransformMatrix.
251 void computeCurrentTransformMatrix();
252
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800253 enum { INVALID_BUFFER_SLOT = -1 };
254
255 struct BufferSlot {
Mathias Agopianb3e518c2011-04-21 18:52:51 -0700256
257 BufferSlot()
258 : mEglImage(EGL_NO_IMAGE_KHR),
259 mEglDisplay(EGL_NO_DISPLAY),
260 mBufferState(BufferSlot::FREE),
261 mRequestBufferCalled(false),
Jamie Gennis8cd5ba42011-05-19 13:33:00 -0700262 mTransform(0),
Mathias Agopian7734ebf2011-07-13 15:24:42 -0700263 mScalingMode(NATIVE_WINDOW_SCALING_MODE_FREEZE),
Jamie Gennis8cd5ba42011-05-19 13:33:00 -0700264 mTimestamp(0) {
265 mCrop.makeInvalid();
Mathias Agopianb3e518c2011-04-21 18:52:51 -0700266 }
267
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800268 // mGraphicBuffer points to the buffer allocated for this slot or is NULL
269 // if no buffer has been allocated.
270 sp<GraphicBuffer> mGraphicBuffer;
271
272 // mEglImage is the EGLImage created from mGraphicBuffer.
273 EGLImageKHR mEglImage;
274
275 // mEglDisplay is the EGLDisplay used to create mEglImage.
276 EGLDisplay mEglDisplay;
277
Jamie Gennis8cd5ba42011-05-19 13:33:00 -0700278 // BufferState represents the different states in which a buffer slot
279 // can be.
280 enum BufferState {
281 // FREE indicates that the buffer is not currently being used and
282 // will not be used in the future until it gets dequeued and
Mathias Agopian29b57622011-08-17 15:42:04 -0700283 // subsequently queued by the client.
Jamie Gennis8cd5ba42011-05-19 13:33:00 -0700284 FREE = 0,
Mathias Agopianb3e518c2011-04-21 18:52:51 -0700285
Jamie Gennis8cd5ba42011-05-19 13:33:00 -0700286 // DEQUEUED indicates that the buffer has been dequeued by the
287 // client, but has not yet been queued or canceled. The buffer is
288 // considered 'owned' by the client, and the server should not use
289 // it for anything.
290 //
291 // Note that when in synchronous-mode (mSynchronousMode == true),
292 // the buffer that's currently attached to the texture may be
293 // dequeued by the client. That means that the current buffer can
294 // be in either the DEQUEUED or QUEUED state. In asynchronous mode,
295 // however, the current buffer is always in the QUEUED state.
296 DEQUEUED = 1,
297
298 // QUEUED indicates that the buffer has been queued by the client,
299 // and has not since been made available for the client to dequeue.
300 // Attaching the buffer to the texture does NOT transition the
301 // buffer away from the QUEUED state. However, in Synchronous mode
302 // the current buffer may be dequeued by the client under some
303 // circumstances. See the note about the current buffer in the
304 // documentation for DEQUEUED.
305 QUEUED = 2,
306 };
307
308 // mBufferState is the current state of this buffer slot.
309 BufferState mBufferState;
Mathias Agopianb3e518c2011-04-21 18:52:51 -0700310
311 // mRequestBufferCalled is used for validating that the client did
312 // call requestBuffer() when told to do so. Technically this is not
313 // needed but useful for debugging and catching client bugs.
314 bool mRequestBufferCalled;
315
Jamie Gennis8cd5ba42011-05-19 13:33:00 -0700316 // mCrop is the current crop rectangle for this buffer slot. This gets
317 // set to mNextCrop each time queueBuffer gets called for this buffer.
318 Rect mCrop;
Mathias Agopianb3e518c2011-04-21 18:52:51 -0700319
Jamie Gennis8cd5ba42011-05-19 13:33:00 -0700320 // mTransform is the current transform flags for this buffer slot. This
321 // gets set to mNextTransform each time queueBuffer gets called for this
322 // slot.
323 uint32_t mTransform;
Mathias Agopianb3e518c2011-04-21 18:52:51 -0700324
Mathias Agopian7734ebf2011-07-13 15:24:42 -0700325 // mScalingMode is the current scaling mode for this buffer slot. This
326 // gets set to mNextScalingMode each time queueBuffer gets called for
327 // this slot.
328 uint32_t mScalingMode;
329
Jamie Gennis8cd5ba42011-05-19 13:33:00 -0700330 // mTimestamp is the current timestamp for this buffer slot. This gets
331 // to set by queueBuffer each time this slot is queued.
332 int64_t mTimestamp;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800333 };
334
335 // mSlots is the array of buffer slots that must be mirrored on the client
336 // side. This allows buffer ownership to be transferred between the client
337 // and server without sending a GraphicBuffer over binder. The entire array
338 // is initialized to NULL at construction time, and buffers are allocated
339 // for a slot when requestBuffer is called with that slot's index.
340 BufferSlot mSlots[NUM_BUFFER_SLOTS];
341
Mathias Agopiana5c75c02011-03-31 19:10:24 -0700342 // mDefaultWidth holds the default width of allocated buffers. It is used
343 // in requestBuffers() if a width and height of zero is specified.
344 uint32_t mDefaultWidth;
345
346 // mDefaultHeight holds the default height of allocated buffers. It is used
347 // in requestBuffers() if a width and height of zero is specified.
348 uint32_t mDefaultHeight;
349
350 // mPixelFormat holds the pixel format of allocated buffers. It is used
351 // in requestBuffers() if a format of zero is specified.
352 uint32_t mPixelFormat;
353
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800354 // mBufferCount is the number of buffer slots that the client and server
Mathias Agopian80727112011-05-02 19:51:12 -0700355 // must maintain. It defaults to MIN_ASYNC_BUFFER_SLOTS and can be changed
356 // by calling setBufferCount or setBufferCountServer
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800357 int mBufferCount;
358
Jamie Gennisae468f42011-06-12 14:11:39 -0700359 // mClientBufferCount is the number of buffer slots requested by the client.
360 // The default is zero, which means the client doesn't care how many buffers
361 // there is.
Mathias Agopian80727112011-05-02 19:51:12 -0700362 int mClientBufferCount;
363
364 // mServerBufferCount buffer count requested by the server-side
365 int mServerBufferCount;
366
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800367 // mCurrentTexture is the buffer slot index of the buffer that is currently
Jamie Gennis67eedd72011-01-09 13:25:39 -0800368 // bound to the OpenGL texture. It is initialized to INVALID_BUFFER_SLOT,
369 // indicating that no buffer slot is currently bound to the texture. Note,
370 // however, that a value of INVALID_BUFFER_SLOT does not necessarily mean
371 // that no buffer is bound to the texture. A call to setBufferCount will
372 // reset mCurrentTexture to INVALID_BUFFER_SLOT.
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800373 int mCurrentTexture;
374
Jamie Gennis9a78c902011-01-12 18:30:40 -0800375 // mCurrentTextureBuf is the graphic buffer of the current texture. It's
376 // possible that this buffer is not associated with any buffer slot, so we
Jamie Gennis29c87022011-07-19 12:11:52 -0700377 // must track it separately in order to support the getCurrentBuffer method.
Jamie Gennis9a78c902011-01-12 18:30:40 -0800378 sp<GraphicBuffer> mCurrentTextureBuf;
379
Jamie Gennisf238e282011-01-09 16:33:17 -0800380 // mCurrentCrop is the crop rectangle that applies to the current texture.
Mathias Agopian7734ebf2011-07-13 15:24:42 -0700381 // It gets set each time updateTexImage is called.
Jamie Gennisf238e282011-01-09 16:33:17 -0800382 Rect mCurrentCrop;
383
384 // mCurrentTransform is the transform identifier for the current texture. It
Mathias Agopian7734ebf2011-07-13 15:24:42 -0700385 // gets set each time updateTexImage is called.
Jamie Gennisf238e282011-01-09 16:33:17 -0800386 uint32_t mCurrentTransform;
387
Mathias Agopian7734ebf2011-07-13 15:24:42 -0700388 // mCurrentScalingMode is the scaling mode for the current texture. It gets
389 // set to each time updateTexImage is called.
390 uint32_t mCurrentScalingMode;
391
Jamie Gennis736aa952011-06-12 17:03:06 -0700392 // mCurrentTransformMatrix is the transform matrix for the current texture.
393 // It gets computed by computeTransformMatrix each time updateTexImage is
394 // called.
395 float mCurrentTransformMatrix[16];
396
Eino-Ville Talvala1d01a122011-02-18 11:02:42 -0800397 // mCurrentTimestamp is the timestamp for the current texture. It
Mathias Agopian7734ebf2011-07-13 15:24:42 -0700398 // gets set each time updateTexImage is called.
Eino-Ville Talvala1d01a122011-02-18 11:02:42 -0800399 int64_t mCurrentTimestamp;
400
Jamie Gennisf238e282011-01-09 16:33:17 -0800401 // mNextCrop is the crop rectangle that will be used for the next buffer
402 // that gets queued. It is set by calling setCrop.
403 Rect mNextCrop;
404
405 // mNextTransform is the transform identifier that will be used for the next
406 // buffer that gets queued. It is set by calling setTransform.
407 uint32_t mNextTransform;
408
Mathias Agopian7734ebf2011-07-13 15:24:42 -0700409 // mNextScalingMode is the scaling mode that will be used for the next
410 // buffers that get queued. It is set by calling setScalingMode.
411 int mNextScalingMode;
412
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800413 // mTexName is the name of the OpenGL texture to which streamed images will
Pannag Sanketi292a31a2011-06-24 09:56:27 -0700414 // be bound when updateTexImage is called. It is set at construction time
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800415 // changed with a call to setTexName.
416 const GLuint mTexName;
417
Jamie Gennis9a78c902011-01-12 18:30:40 -0800418 // mGraphicBufferAlloc is the connection to SurfaceFlinger that is used to
419 // allocate new GraphicBuffer objects.
420 sp<IGraphicBufferAlloc> mGraphicBufferAlloc;
421
Jamie Gennisc4d4aea2011-01-13 14:43:36 -0800422 // mFrameAvailableListener is the listener object that will be called when a
423 // new frame becomes available. If it is not NULL it will be called from
424 // queueBuffer.
425 sp<FrameAvailableListener> mFrameAvailableListener;
426
Mathias Agopianb3e518c2011-04-21 18:52:51 -0700427 // mSynchronousMode whether we're in synchronous mode or not
428 bool mSynchronousMode;
429
Grace Kloba14a0e582011-06-23 21:21:47 -0700430 // mAllowSynchronousMode whether we allow synchronous mode or not
431 const bool mAllowSynchronousMode;
432
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700433 // mConnectedApi indicates the API that is currently connected to this
434 // SurfaceTexture. It defaults to NO_CONNECTED_API (= 0), and gets updated
435 // by the connect and disconnect methods.
436 int mConnectedApi;
437
Mathias Agopianb3e518c2011-04-21 18:52:51 -0700438 // mDequeueCondition condition used for dequeueBuffer in synchronous mode
439 mutable Condition mDequeueCondition;
440
441 // mQueue is a FIFO of queued buffers used in synchronous mode
442 typedef Vector<int> Fifo;
443 Fifo mQueue;
444
Jamie Gennis7b305ff2011-07-19 12:08:33 -0700445 // mAbandoned indicates that the SurfaceTexture will no longer be used to
446 // consume images buffers pushed to it using the ISurfaceTexture interface.
447 // It is initialized to false, and set to true in the abandon method. A
448 // SurfaceTexture that has been abandoned will return the NO_INIT error from
449 // all ISurfaceTexture methods capable of returning an error.
450 bool mAbandoned;
451
Jamie Gennisfa28c352011-09-16 17:30:26 -0700452 // mName is a string used to identify the SurfaceTexture in log messages.
453 // It is set by the setName method.
454 String8 mName;
455
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800456 // mMutex is the mutex used to prevent concurrent access to the member
457 // variables of SurfaceTexture objects. It must be locked whenever the
458 // member variables are accessed.
Mathias Agopian7a042bf2011-04-11 21:19:55 -0700459 mutable Mutex mMutex;
Jamie Gennis736aa952011-06-12 17:03:06 -0700460
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800461};
462
463// ----------------------------------------------------------------------------
464}; // namespace android
465
466#endif // ANDROID_GUI_SURFACETEXTURE_H