blob: e2d6179ef046446391c527f8f00e382b61942b9f [file] [log] [blame]
Jamie Gennis68e4a7a2010-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>
Jamie Gennis8606fef2011-09-28 12:13:31 -070023#include <GLES2/gl2ext.h>
Jamie Gennis68e4a7a2010-12-20 11:27:26 -080024
25#include <gui/ISurfaceTexture.h>
26
27#include <ui/GraphicBuffer.h>
28
Jamie Gennis44a05222011-09-16 17:30:26 -070029#include <utils/String8.h>
Jamie Gennisf7acf162011-01-12 18:30:40 -080030#include <utils/Vector.h>
Jamie Gennis44a05222011-09-16 17:30:26 -070031#include <utils/threads.h>
Jamie Gennis68e4a7a2010-12-20 11:27:26 -080032
33#define ANDROID_GRAPHICS_SURFACETEXTURE_JNI_ID "mSurfaceTexture"
34
35namespace android {
36// ----------------------------------------------------------------------------
37
Jamie Gennisf7acf162011-01-12 18:30:40 -080038class IGraphicBufferAlloc;
Mathias Agopian7f3289c2011-05-09 19:08:33 -070039class String8;
Jamie Gennisf7acf162011-01-12 18:30:40 -080040
Jamie Gennis68e4a7a2010-12-20 11:27:26 -080041class SurfaceTexture : public BnSurfaceTexture {
42public:
Jamie Gennis96dcc972011-02-27 14:10:20 -080043 enum { MIN_UNDEQUEUED_BUFFERS = 2 };
Mathias Agopian402ff242011-05-02 19:51:12 -070044 enum {
45 MIN_ASYNC_BUFFER_SLOTS = MIN_UNDEQUEUED_BUFFERS + 1,
46 MIN_SYNC_BUFFER_SLOTS = MIN_UNDEQUEUED_BUFFERS
47 };
Jamie Gennis68e4a7a2010-12-20 11:27:26 -080048 enum { NUM_BUFFER_SLOTS = 32 };
Jamie Gennis97096872011-07-13 19:12:20 -070049 enum { NO_CONNECTED_API = 0 };
Jamie Gennis68e4a7a2010-12-20 11:27:26 -080050
Jamie Gennis376590d2011-01-13 14:43:36 -080051 struct FrameAvailableListener : public virtual RefBase {
Jamie Gennisbd5404d2011-06-26 18:27:47 -070052 // onFrameAvailable() is called from queueBuffer() each time an
53 // additional frame becomes available for consumption. This means that
54 // frames that are queued while in asynchronous mode only trigger the
55 // callback if no previous frames are pending. Frames queued while in
56 // synchronous mode always trigger the callback.
57 //
58 // This is called without any lock held and can be called concurrently
59 // by multiple threads.
Jamie Gennis376590d2011-01-13 14:43:36 -080060 virtual void onFrameAvailable() = 0;
61 };
62
Jamie Gennis68e4a7a2010-12-20 11:27:26 -080063 // tex indicates the name OpenGL texture to which images are to be streamed.
64 // This texture name cannot be changed once the SurfaceTexture is created.
Jamie Gennis8606fef2011-09-28 12:13:31 -070065 SurfaceTexture(GLuint tex, bool allowSynchronousMode = true,
66 GLenum texTarget = GL_TEXTURE_EXTERNAL_OES);
Jamie Gennis68e4a7a2010-12-20 11:27:26 -080067
68 virtual ~SurfaceTexture();
69
70 // setBufferCount updates the number of available buffer slots. After
71 // calling this all buffer slots are both unallocated and owned by the
72 // SurfaceTexture object (i.e. they are not owned by the client).
73 virtual status_t setBufferCount(int bufferCount);
74
Jamie Gennis5ef59bc2011-07-19 12:08:33 -070075 virtual status_t requestBuffer(int slot, sp<GraphicBuffer>* buf);
Jamie Gennis68e4a7a2010-12-20 11:27:26 -080076
77 // dequeueBuffer gets the next buffer slot index for the client to use. If a
78 // buffer slot is available then that slot index is written to the location
79 // pointed to by the buf argument and a status of OK is returned. If no
80 // slot is available then a status of -EBUSY is returned and buf is
81 // unmodified.
Mathias Agopian0297dca2011-04-25 20:22:14 -070082 virtual status_t dequeueBuffer(int *buf, uint32_t w, uint32_t h,
83 uint32_t format, uint32_t usage);
Jamie Gennis68e4a7a2010-12-20 11:27:26 -080084
Eino-Ville Talvalac5f94d82011-02-18 11:02:42 -080085 // queueBuffer returns a filled buffer to the SurfaceTexture. In addition, a
86 // timestamp must be provided for the buffer. The timestamp is in
87 // nanoseconds, and must be monotonically increasing. Its other semantics
88 // (zero point, etc) are client-dependent and should be documented by the
89 // client.
Mathias Agopianf07b8a32011-07-19 15:24:46 -070090 virtual status_t queueBuffer(int buf, int64_t timestamp,
91 uint32_t* outWidth, uint32_t* outHeight, uint32_t* outTransform);
Jamie Gennis68e4a7a2010-12-20 11:27:26 -080092 virtual void cancelBuffer(int buf);
93 virtual status_t setCrop(const Rect& reg);
94 virtual status_t setTransform(uint32_t transform);
Mathias Agopian09d7ed72011-07-13 15:24:42 -070095 virtual status_t setScalingMode(int mode);
Jamie Gennis68e4a7a2010-12-20 11:27:26 -080096
Mathias Agopianed3894c2011-04-20 14:20:59 -070097 virtual int query(int what, int* value);
98
Mathias Agopian402ff242011-05-02 19:51:12 -070099 // setSynchronousMode set whether dequeueBuffer is synchronous or
100 // asynchronous. In synchronous mode, dequeueBuffer blocks until
101 // a buffer is available, the currently bound buffer can be dequeued and
102 // queued buffers will be retired in order.
103 // The default mode is asynchronous.
104 virtual status_t setSynchronousMode(bool enabled);
105
Jamie Gennis97096872011-07-13 19:12:20 -0700106 // connect attempts to connect a client API to the SurfaceTexture. This
107 // must be called before any other ISurfaceTexture methods are called except
108 // for getAllocator.
109 //
110 // This method will fail if the connect was previously called on the
111 // SurfaceTexture and no corresponding disconnect call was made.
Mathias Agopian053b02d2011-08-08 19:14:03 -0700112 virtual status_t connect(int api,
113 uint32_t* outWidth, uint32_t* outHeight, uint32_t* outTransform);
Jamie Gennis97096872011-07-13 19:12:20 -0700114
115 // disconnect attempts to disconnect a client API from the SurfaceTexture.
116 // Calling this method will cause any subsequent calls to other
117 // ISurfaceTexture methods to fail except for getAllocator and connect.
118 // Successfully calling connect after this will allow the other methods to
119 // succeed again.
120 //
121 // This method will fail if the the SurfaceTexture is not currently
122 // connected to the specified client API.
123 virtual status_t disconnect(int api);
124
Jamie Gennis68e4a7a2010-12-20 11:27:26 -0800125 // updateTexImage sets the image contents of the target texture to that of
126 // the most recently queued buffer.
127 //
128 // This call may only be made while the OpenGL ES context to which the
129 // target texture belongs is bound to the calling thread.
130 status_t updateTexImage();
131
Mathias Agopian402ff242011-05-02 19:51:12 -0700132 // setBufferCountServer set the buffer count. If the client has requested
133 // a buffer count using setBufferCount, the server-buffer count will
134 // take effect once the client sets the count back to zero.
135 status_t setBufferCountServer(int bufferCount);
136
Jamie Gennisb598fb92011-01-09 16:33:17 -0800137 // getTransformMatrix retrieves the 4x4 texture coordinate transform matrix
138 // associated with the texture image set by the most recent call to
139 // updateTexImage.
140 //
141 // This transform matrix maps 2D homogeneous texture coordinates of the form
142 // (s, t, 0, 1) with s and t in the inclusive range [0, 1] to the texture
143 // coordinate that should be used to sample that location from the texture.
144 // Sampling the texture outside of the range of this transform is undefined.
145 //
146 // This transform is necessary to compensate for transforms that the stream
147 // content producer may implicitly apply to the content. By forcing users of
148 // a SurfaceTexture to apply this transform we avoid performing an extra
149 // copy of the data that would be needed to hide the transform from the
150 // user.
151 //
152 // The matrix is stored in column-major order so that it may be passed
153 // directly to OpenGL ES via the glLoadMatrixf or glUniformMatrix4fv
154 // functions.
155 void getTransformMatrix(float mtx[16]);
156
Eino-Ville Talvalac5f94d82011-02-18 11:02:42 -0800157 // getTimestamp retrieves the timestamp associated with the texture image
158 // set by the most recent call to updateTexImage.
159 //
160 // The timestamp is in nanoseconds, and is monotonically increasing. Its
161 // other semantics (zero point, etc) are source-dependent and should be
162 // documented by the source.
163 int64_t getTimestamp();
164
Jamie Gennis376590d2011-01-13 14:43:36 -0800165 // setFrameAvailableListener sets the listener object that will be notified
166 // when a new frame becomes available.
Pannag Sanketic9ec69e2011-06-24 09:56:27 -0700167 void setFrameAvailableListener(const sp<FrameAvailableListener>& listener);
Jamie Gennis376590d2011-01-13 14:43:36 -0800168
Jamie Gennis83bac212011-02-02 15:31:47 -0800169 // getAllocator retrieves the binder object that must be referenced as long
170 // as the GraphicBuffers dequeued from this SurfaceTexture are referenced.
171 // Holding this binder reference prevents SurfaceFlinger from freeing the
172 // buffers before the client is done with them.
173 sp<IBinder> getAllocator();
174
Mathias Agopiane5a1bff2011-03-31 19:10:24 -0700175 // setDefaultBufferSize is used to set the size of buffers returned by
176 // requestBuffers when a with and height of zero is requested.
177 // A call to setDefaultBufferSize() may trigger requestBuffers() to
178 // be called from the client.
179 status_t setDefaultBufferSize(uint32_t w, uint32_t h);
180
Mathias Agopian27cd07c2011-04-11 21:19:55 -0700181 // getCurrentBuffer returns the buffer associated with the current image.
182 sp<GraphicBuffer> getCurrentBuffer() const;
183
184 // getCurrentTextureTarget returns the texture target of the current
185 // texture as returned by updateTexImage().
186 GLenum getCurrentTextureTarget() const;
187
188 // getCurrentCrop returns the cropping rectangle of the current buffer
189 Rect getCurrentCrop() const;
190
191 // getCurrentTransform returns the transform of the current buffer
192 uint32_t getCurrentTransform() const;
193
Mathias Agopian09d7ed72011-07-13 15:24:42 -0700194 // getCurrentScalingMode returns the scaling mode of the current buffer
195 uint32_t getCurrentScalingMode() const;
196
Jamie Gennis5ef59bc2011-07-19 12:08:33 -0700197 // abandon frees all the buffers and puts the SurfaceTexture into the
198 // 'abandoned' state. Once put in this state the SurfaceTexture can never
199 // leave it. When in the 'abandoned' state, all methods of the
200 // ISurfaceTexture interface will fail with the NO_INIT error.
201 //
202 // Note that while calling this method causes all the buffers to be freed
203 // from the perspective of the the SurfaceTexture, if there are additional
204 // references on the buffers (e.g. if a buffer is referenced by a client or
205 // by OpenGL ES as a texture) then those buffer will remain allocated.
206 void abandon();
207
Jamie Gennis44a05222011-09-16 17:30:26 -0700208 // set the name of the SurfaceTexture that will be used to identify it in
209 // log messages.
210 void setName(const String8& name);
211
Mathias Agopian7f3289c2011-05-09 19:08:33 -0700212 // dump our state in a String
213 void dump(String8& result) const;
214 void dump(String8& result, const char* prefix, char* buffer, size_t SIZE) const;
215
Mathias Agopian27cd07c2011-04-11 21:19:55 -0700216protected:
Jamie Gennis68e4a7a2010-12-20 11:27:26 -0800217
Mathias Agopian5c715752011-08-10 17:35:09 -0700218 // freeBufferLocked frees the resources (both GraphicBuffer and EGLImage)
219 // for the given slot.
220 void freeBufferLocked(int index);
221
222 // freeAllBuffersLocked frees the resources (both GraphicBuffer and
223 // EGLImage) for all slots.
Mathias Agopiana04cda92011-08-10 15:28:58 -0700224 void freeAllBuffersLocked();
Mathias Agopian71fd1212011-08-10 16:33:23 -0700225
Mathias Agopian5c715752011-08-10 17:35:09 -0700226 // freeAllBuffersExceptHeadLocked frees the resources (both GraphicBuffer
227 // and EGLImage) for all slots except the head of mQueue
228 void freeAllBuffersExceptHeadLocked();
229
Mathias Agopian71fd1212011-08-10 16:33:23 -0700230 // drainQueueLocked drains the buffer queue if we're in synchronous mode
Mathias Agopian5c715752011-08-10 17:35:09 -0700231 // returns immediately otherwise. return NO_INIT if SurfaceTexture
232 // became abandoned or disconnected during this call.
233 status_t drainQueueLocked();
234
235 // drainQueueAndFreeBuffersLocked drains the buffer queue if we're in
236 // synchronous mode and free all buffers. In asynchronous mode, all buffers
237 // are freed except the current buffer.
238 status_t drainQueueAndFreeBuffersLocked();
Mathias Agopian71fd1212011-08-10 16:33:23 -0700239
Mathias Agopian27cd07c2011-04-11 21:19:55 -0700240 static bool isExternalFormat(uint32_t format);
Mathias Agopian27cd07c2011-04-11 21:19:55 -0700241
242private:
Jamie Gennis68e4a7a2010-12-20 11:27:26 -0800243
244 // createImage creates a new EGLImage from a GraphicBuffer.
245 EGLImageKHR createImage(EGLDisplay dpy,
246 const sp<GraphicBuffer>& graphicBuffer);
247
Mathias Agopian402ff242011-05-02 19:51:12 -0700248 status_t setBufferCountServerLocked(int bufferCount);
249
Jamie Genniseadfb672011-06-12 17:03:06 -0700250 // computeCurrentTransformMatrix computes the transform matrix for the
251 // current texture. It uses mCurrentTransform and the current GraphicBuffer
252 // to compute this matrix and stores it in mCurrentTransformMatrix.
253 void computeCurrentTransformMatrix();
254
Jamie Gennis68e4a7a2010-12-20 11:27:26 -0800255 enum { INVALID_BUFFER_SLOT = -1 };
256
257 struct BufferSlot {
Mathias Agopian5bbb1cf2011-04-21 18:52:51 -0700258
259 BufferSlot()
260 : mEglImage(EGL_NO_IMAGE_KHR),
261 mEglDisplay(EGL_NO_DISPLAY),
262 mBufferState(BufferSlot::FREE),
263 mRequestBufferCalled(false),
Jamie Gennisa2187152011-05-19 13:33:00 -0700264 mTransform(0),
Mathias Agopian09d7ed72011-07-13 15:24:42 -0700265 mScalingMode(NATIVE_WINDOW_SCALING_MODE_FREEZE),
Jamie Gennisa2187152011-05-19 13:33:00 -0700266 mTimestamp(0) {
267 mCrop.makeInvalid();
Mathias Agopian5bbb1cf2011-04-21 18:52:51 -0700268 }
269
Jamie Gennis68e4a7a2010-12-20 11:27:26 -0800270 // mGraphicBuffer points to the buffer allocated for this slot or is NULL
271 // if no buffer has been allocated.
272 sp<GraphicBuffer> mGraphicBuffer;
273
274 // mEglImage is the EGLImage created from mGraphicBuffer.
275 EGLImageKHR mEglImage;
276
277 // mEglDisplay is the EGLDisplay used to create mEglImage.
278 EGLDisplay mEglDisplay;
279
Jamie Gennisa2187152011-05-19 13:33:00 -0700280 // BufferState represents the different states in which a buffer slot
281 // can be.
282 enum BufferState {
283 // FREE indicates that the buffer is not currently being used and
284 // will not be used in the future until it gets dequeued and
Mathias Agopian8618ebc2011-08-17 15:42:04 -0700285 // subsequently queued by the client.
Jamie Gennisa2187152011-05-19 13:33:00 -0700286 FREE = 0,
Mathias Agopian5bbb1cf2011-04-21 18:52:51 -0700287
Jamie Gennisa2187152011-05-19 13:33:00 -0700288 // DEQUEUED indicates that the buffer has been dequeued by the
289 // client, but has not yet been queued or canceled. The buffer is
290 // considered 'owned' by the client, and the server should not use
291 // it for anything.
292 //
293 // Note that when in synchronous-mode (mSynchronousMode == true),
294 // the buffer that's currently attached to the texture may be
295 // dequeued by the client. That means that the current buffer can
296 // be in either the DEQUEUED or QUEUED state. In asynchronous mode,
297 // however, the current buffer is always in the QUEUED state.
298 DEQUEUED = 1,
299
300 // QUEUED indicates that the buffer has been queued by the client,
301 // and has not since been made available for the client to dequeue.
302 // Attaching the buffer to the texture does NOT transition the
303 // buffer away from the QUEUED state. However, in Synchronous mode
304 // the current buffer may be dequeued by the client under some
305 // circumstances. See the note about the current buffer in the
306 // documentation for DEQUEUED.
307 QUEUED = 2,
308 };
309
310 // mBufferState is the current state of this buffer slot.
311 BufferState mBufferState;
Mathias Agopian5bbb1cf2011-04-21 18:52:51 -0700312
313 // mRequestBufferCalled is used for validating that the client did
314 // call requestBuffer() when told to do so. Technically this is not
315 // needed but useful for debugging and catching client bugs.
316 bool mRequestBufferCalled;
317
Jamie Gennisa2187152011-05-19 13:33:00 -0700318 // mCrop is the current crop rectangle for this buffer slot. This gets
319 // set to mNextCrop each time queueBuffer gets called for this buffer.
320 Rect mCrop;
Mathias Agopian5bbb1cf2011-04-21 18:52:51 -0700321
Jamie Gennisa2187152011-05-19 13:33:00 -0700322 // mTransform is the current transform flags for this buffer slot. This
323 // gets set to mNextTransform each time queueBuffer gets called for this
324 // slot.
325 uint32_t mTransform;
Mathias Agopian5bbb1cf2011-04-21 18:52:51 -0700326
Mathias Agopian09d7ed72011-07-13 15:24:42 -0700327 // mScalingMode is the current scaling mode for this buffer slot. This
328 // gets set to mNextScalingMode each time queueBuffer gets called for
329 // this slot.
330 uint32_t mScalingMode;
331
Jamie Gennisa2187152011-05-19 13:33:00 -0700332 // mTimestamp is the current timestamp for this buffer slot. This gets
333 // to set by queueBuffer each time this slot is queued.
334 int64_t mTimestamp;
Jamie Gennis68e4a7a2010-12-20 11:27:26 -0800335 };
336
337 // mSlots is the array of buffer slots that must be mirrored on the client
338 // side. This allows buffer ownership to be transferred between the client
339 // and server without sending a GraphicBuffer over binder. The entire array
340 // is initialized to NULL at construction time, and buffers are allocated
341 // for a slot when requestBuffer is called with that slot's index.
342 BufferSlot mSlots[NUM_BUFFER_SLOTS];
343
Mathias Agopiane5a1bff2011-03-31 19:10:24 -0700344 // mDefaultWidth holds the default width of allocated buffers. It is used
345 // in requestBuffers() if a width and height of zero is specified.
346 uint32_t mDefaultWidth;
347
348 // mDefaultHeight holds the default height of allocated buffers. It is used
349 // in requestBuffers() if a width and height of zero is specified.
350 uint32_t mDefaultHeight;
351
352 // mPixelFormat holds the pixel format of allocated buffers. It is used
353 // in requestBuffers() if a format of zero is specified.
354 uint32_t mPixelFormat;
355
Jamie Gennis68e4a7a2010-12-20 11:27:26 -0800356 // mBufferCount is the number of buffer slots that the client and server
Mathias Agopian402ff242011-05-02 19:51:12 -0700357 // must maintain. It defaults to MIN_ASYNC_BUFFER_SLOTS and can be changed
358 // by calling setBufferCount or setBufferCountServer
Jamie Gennis68e4a7a2010-12-20 11:27:26 -0800359 int mBufferCount;
360
Jamie Gennis4e03d322011-06-12 14:11:39 -0700361 // mClientBufferCount is the number of buffer slots requested by the client.
362 // The default is zero, which means the client doesn't care how many buffers
363 // there is.
Mathias Agopian402ff242011-05-02 19:51:12 -0700364 int mClientBufferCount;
365
366 // mServerBufferCount buffer count requested by the server-side
367 int mServerBufferCount;
368
Jamie Gennis68e4a7a2010-12-20 11:27:26 -0800369 // mCurrentTexture is the buffer slot index of the buffer that is currently
Jamie Gennisd369dc42011-01-09 13:25:39 -0800370 // bound to the OpenGL texture. It is initialized to INVALID_BUFFER_SLOT,
371 // indicating that no buffer slot is currently bound to the texture. Note,
372 // however, that a value of INVALID_BUFFER_SLOT does not necessarily mean
373 // that no buffer is bound to the texture. A call to setBufferCount will
374 // reset mCurrentTexture to INVALID_BUFFER_SLOT.
Jamie Gennis68e4a7a2010-12-20 11:27:26 -0800375 int mCurrentTexture;
376
Jamie Gennisf7acf162011-01-12 18:30:40 -0800377 // mCurrentTextureBuf is the graphic buffer of the current texture. It's
378 // possible that this buffer is not associated with any buffer slot, so we
Jamie Gennis075db952011-07-19 12:11:52 -0700379 // must track it separately in order to support the getCurrentBuffer method.
Jamie Gennisf7acf162011-01-12 18:30:40 -0800380 sp<GraphicBuffer> mCurrentTextureBuf;
381
Jamie Gennisb598fb92011-01-09 16:33:17 -0800382 // mCurrentCrop is the crop rectangle that applies to the current texture.
Mathias Agopian09d7ed72011-07-13 15:24:42 -0700383 // It gets set each time updateTexImage is called.
Jamie Gennisb598fb92011-01-09 16:33:17 -0800384 Rect mCurrentCrop;
385
386 // mCurrentTransform is the transform identifier for the current texture. It
Mathias Agopian09d7ed72011-07-13 15:24:42 -0700387 // gets set each time updateTexImage is called.
Jamie Gennisb598fb92011-01-09 16:33:17 -0800388 uint32_t mCurrentTransform;
389
Mathias Agopian09d7ed72011-07-13 15:24:42 -0700390 // mCurrentScalingMode is the scaling mode for the current texture. It gets
391 // set to each time updateTexImage is called.
392 uint32_t mCurrentScalingMode;
393
Jamie Genniseadfb672011-06-12 17:03:06 -0700394 // mCurrentTransformMatrix is the transform matrix for the current texture.
395 // It gets computed by computeTransformMatrix each time updateTexImage is
396 // called.
397 float mCurrentTransformMatrix[16];
398
Eino-Ville Talvalac5f94d82011-02-18 11:02:42 -0800399 // mCurrentTimestamp is the timestamp for the current texture. It
Mathias Agopian09d7ed72011-07-13 15:24:42 -0700400 // gets set each time updateTexImage is called.
Eino-Ville Talvalac5f94d82011-02-18 11:02:42 -0800401 int64_t mCurrentTimestamp;
402
Jamie Gennisb598fb92011-01-09 16:33:17 -0800403 // mNextCrop is the crop rectangle that will be used for the next buffer
404 // that gets queued. It is set by calling setCrop.
405 Rect mNextCrop;
406
407 // mNextTransform is the transform identifier that will be used for the next
408 // buffer that gets queued. It is set by calling setTransform.
409 uint32_t mNextTransform;
410
Mathias Agopian09d7ed72011-07-13 15:24:42 -0700411 // mNextScalingMode is the scaling mode that will be used for the next
412 // buffers that get queued. It is set by calling setScalingMode.
413 int mNextScalingMode;
414
Jamie Gennis68e4a7a2010-12-20 11:27:26 -0800415 // mTexName is the name of the OpenGL texture to which streamed images will
Pannag Sanketic9ec69e2011-06-24 09:56:27 -0700416 // be bound when updateTexImage is called. It is set at construction time
Jamie Gennis68e4a7a2010-12-20 11:27:26 -0800417 // changed with a call to setTexName.
418 const GLuint mTexName;
419
Jamie Gennisf7acf162011-01-12 18:30:40 -0800420 // mGraphicBufferAlloc is the connection to SurfaceFlinger that is used to
421 // allocate new GraphicBuffer objects.
422 sp<IGraphicBufferAlloc> mGraphicBufferAlloc;
423
Jamie Gennis376590d2011-01-13 14:43:36 -0800424 // mFrameAvailableListener is the listener object that will be called when a
425 // new frame becomes available. If it is not NULL it will be called from
426 // queueBuffer.
427 sp<FrameAvailableListener> mFrameAvailableListener;
428
Mathias Agopian5bbb1cf2011-04-21 18:52:51 -0700429 // mSynchronousMode whether we're in synchronous mode or not
430 bool mSynchronousMode;
431
Grace Kloba0904d0a2011-06-23 21:21:47 -0700432 // mAllowSynchronousMode whether we allow synchronous mode or not
433 const bool mAllowSynchronousMode;
434
Jamie Gennis97096872011-07-13 19:12:20 -0700435 // mConnectedApi indicates the API that is currently connected to this
436 // SurfaceTexture. It defaults to NO_CONNECTED_API (= 0), and gets updated
437 // by the connect and disconnect methods.
438 int mConnectedApi;
439
Mathias Agopian5bbb1cf2011-04-21 18:52:51 -0700440 // mDequeueCondition condition used for dequeueBuffer in synchronous mode
441 mutable Condition mDequeueCondition;
442
443 // mQueue is a FIFO of queued buffers used in synchronous mode
444 typedef Vector<int> Fifo;
445 Fifo mQueue;
446
Jamie Gennis5ef59bc2011-07-19 12:08:33 -0700447 // mAbandoned indicates that the SurfaceTexture will no longer be used to
448 // consume images buffers pushed to it using the ISurfaceTexture interface.
449 // It is initialized to false, and set to true in the abandon method. A
450 // SurfaceTexture that has been abandoned will return the NO_INIT error from
451 // all ISurfaceTexture methods capable of returning an error.
452 bool mAbandoned;
453
Jamie Gennis44a05222011-09-16 17:30:26 -0700454 // mName is a string used to identify the SurfaceTexture in log messages.
455 // It is set by the setName method.
456 String8 mName;
457
Jamie Gennis68e4a7a2010-12-20 11:27:26 -0800458 // mMutex is the mutex used to prevent concurrent access to the member
459 // variables of SurfaceTexture objects. It must be locked whenever the
460 // member variables are accessed.
Mathias Agopian27cd07c2011-04-11 21:19:55 -0700461 mutable Mutex mMutex;
Jamie Genniseadfb672011-06-12 17:03:06 -0700462
Jamie Gennis8606fef2011-09-28 12:13:31 -0700463 // mTexTarget is the GL texture target with which the GL texture object is
464 // associated. It is set in the constructor and never changed. It is
465 // almost always GL_TEXTURE_EXTERNAL_OES except for one use case in Android
466 // Browser. In that case it is set to GL_TEXTURE_2D to allow
467 // glCopyTexSubImage to read from the texture. This is a hack to work
468 // around a GL driver limitation on the number of FBO attachments, which the
469 // browser's tile cache exceeds.
470 const GLenum mTexTarget;
Jamie Gennis68e4a7a2010-12-20 11:27:26 -0800471};
472
473// ----------------------------------------------------------------------------
474}; // namespace android
475
476#endif // ANDROID_GUI_SURFACETEXTURE_H