blob: d7dd4d6cb41e81bc4afcf431ff0162d7f6f1962c [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>
Jamie Gennisfb1b5a22011-09-28 12:13:31 -070023#include <GLES2/gl2ext.h>
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080024
25#include <gui/ISurfaceTexture.h>
26
27#include <ui/GraphicBuffer.h>
28
Jamie Gennisfa28c352011-09-16 17:30:26 -070029#include <utils/String8.h>
Jamie Gennis9a78c902011-01-12 18:30:40 -080030#include <utils/Vector.h>
Jamie Gennisfa28c352011-09-16 17:30:26 -070031#include <utils/threads.h>
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080032
33#define ANDROID_GRAPHICS_SURFACETEXTURE_JNI_ID "mSurfaceTexture"
34
35namespace android {
36// ----------------------------------------------------------------------------
37
Jamie Gennis9a78c902011-01-12 18:30:40 -080038class IGraphicBufferAlloc;
Mathias Agopian68c77942011-05-09 19:08:33 -070039class String8;
Jamie Gennis9a78c902011-01-12 18:30:40 -080040
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080041class SurfaceTexture : public BnSurfaceTexture {
42public:
Jamie Gennis9d4d6c12011-02-27 14:10:20 -080043 enum { MIN_UNDEQUEUED_BUFFERS = 2 };
Mathias Agopian80727112011-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 Gennis8ba32fa2010-12-20 11:27:26 -080048 enum { NUM_BUFFER_SLOTS = 32 };
Jamie Gennisfe0a87b2011-07-13 19:12:20 -070049 enum { NO_CONNECTED_API = 0 };
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080050
Jamie Gennisc4d4aea2011-01-13 14:43:36 -080051 struct FrameAvailableListener : public virtual RefBase {
Jamie Gennis3d8063b2011-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 Gennisc4d4aea2011-01-13 14:43:36 -080060 virtual void onFrameAvailable() = 0;
61 };
62
Jamie Gennis8ba32fa2010-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 Gennisfb1b5a22011-09-28 12:13:31 -070065 SurfaceTexture(GLuint tex, bool allowSynchronousMode = true,
66 GLenum texTarget = GL_TEXTURE_EXTERNAL_OES);
Jamie Gennis8ba32fa2010-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 Gennis7b305ff2011-07-19 12:08:33 -070075 virtual status_t requestBuffer(int slot, sp<GraphicBuffer>* buf);
Jamie Gennis8ba32fa2010-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 Agopian194c76c2011-11-10 14:34:26 -080082 // The width and height parameters must be no greater than the minimum of
83 // GL_MAX_VIEWPORT_DIMS and GL_MAX_TEXTURE_SIZE (see: glGetIntegerv).
84 // An error due to invalid dimensions might not be reported until
85 // updateTexImage() is called.
86 virtual status_t dequeueBuffer(int *buf, uint32_t width, uint32_t height,
Mathias Agopianc04f1532011-04-25 20:22:14 -070087 uint32_t format, uint32_t usage);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080088
Eino-Ville Talvala1d01a122011-02-18 11:02:42 -080089 // queueBuffer returns a filled buffer to the SurfaceTexture. In addition, a
90 // timestamp must be provided for the buffer. The timestamp is in
91 // nanoseconds, and must be monotonically increasing. Its other semantics
92 // (zero point, etc) are client-dependent and should be documented by the
93 // client.
Mathias Agopian97c602c2011-07-19 15:24:46 -070094 virtual status_t queueBuffer(int buf, int64_t timestamp,
95 uint32_t* outWidth, uint32_t* outHeight, uint32_t* outTransform);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080096 virtual void cancelBuffer(int buf);
97 virtual status_t setCrop(const Rect& reg);
98 virtual status_t setTransform(uint32_t transform);
Mathias Agopian7734ebf2011-07-13 15:24:42 -070099 virtual status_t setScalingMode(int mode);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800100
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700101 virtual int query(int what, int* value);
102
Mathias Agopian80727112011-05-02 19:51:12 -0700103 // setSynchronousMode set whether dequeueBuffer is synchronous or
104 // asynchronous. In synchronous mode, dequeueBuffer blocks until
105 // a buffer is available, the currently bound buffer can be dequeued and
106 // queued buffers will be retired in order.
107 // The default mode is asynchronous.
108 virtual status_t setSynchronousMode(bool enabled);
109
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700110 // connect attempts to connect a client API to the SurfaceTexture. This
111 // must be called before any other ISurfaceTexture methods are called except
112 // for getAllocator.
113 //
114 // This method will fail if the connect was previously called on the
115 // SurfaceTexture and no corresponding disconnect call was made.
Mathias Agopian5bfc2452011-08-08 19:14:03 -0700116 virtual status_t connect(int api,
117 uint32_t* outWidth, uint32_t* outHeight, uint32_t* outTransform);
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700118
119 // disconnect attempts to disconnect a client API from the SurfaceTexture.
120 // Calling this method will cause any subsequent calls to other
121 // ISurfaceTexture methods to fail except for getAllocator and connect.
122 // Successfully calling connect after this will allow the other methods to
123 // succeed again.
124 //
125 // This method will fail if the the SurfaceTexture is not currently
126 // connected to the specified client API.
127 virtual status_t disconnect(int api);
128
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800129 // updateTexImage sets the image contents of the target texture to that of
130 // the most recently queued buffer.
131 //
132 // This call may only be made while the OpenGL ES context to which the
133 // target texture belongs is bound to the calling thread.
134 status_t updateTexImage();
135
Mathias Agopian80727112011-05-02 19:51:12 -0700136 // setBufferCountServer set the buffer count. If the client has requested
137 // a buffer count using setBufferCount, the server-buffer count will
138 // take effect once the client sets the count back to zero.
139 status_t setBufferCountServer(int bufferCount);
140
Jamie Gennisf238e282011-01-09 16:33:17 -0800141 // getTransformMatrix retrieves the 4x4 texture coordinate transform matrix
142 // associated with the texture image set by the most recent call to
143 // updateTexImage.
144 //
145 // This transform matrix maps 2D homogeneous texture coordinates of the form
146 // (s, t, 0, 1) with s and t in the inclusive range [0, 1] to the texture
147 // coordinate that should be used to sample that location from the texture.
148 // Sampling the texture outside of the range of this transform is undefined.
149 //
150 // This transform is necessary to compensate for transforms that the stream
151 // content producer may implicitly apply to the content. By forcing users of
152 // a SurfaceTexture to apply this transform we avoid performing an extra
153 // copy of the data that would be needed to hide the transform from the
154 // user.
155 //
156 // The matrix is stored in column-major order so that it may be passed
157 // directly to OpenGL ES via the glLoadMatrixf or glUniformMatrix4fv
158 // functions.
159 void getTransformMatrix(float mtx[16]);
160
Eino-Ville Talvala1d01a122011-02-18 11:02:42 -0800161 // getTimestamp retrieves the timestamp associated with the texture image
162 // set by the most recent call to updateTexImage.
163 //
164 // The timestamp is in nanoseconds, and is monotonically increasing. Its
165 // other semantics (zero point, etc) are source-dependent and should be
166 // documented by the source.
167 int64_t getTimestamp();
168
Jamie Gennisc4d4aea2011-01-13 14:43:36 -0800169 // setFrameAvailableListener sets the listener object that will be notified
170 // when a new frame becomes available.
Pannag Sanketi292a31a2011-06-24 09:56:27 -0700171 void setFrameAvailableListener(const sp<FrameAvailableListener>& listener);
Jamie Gennisc4d4aea2011-01-13 14:43:36 -0800172
Jamie Gennis1b20cde2011-02-02 15:31:47 -0800173 // getAllocator retrieves the binder object that must be referenced as long
174 // as the GraphicBuffers dequeued from this SurfaceTexture are referenced.
175 // Holding this binder reference prevents SurfaceFlinger from freeing the
176 // buffers before the client is done with them.
177 sp<IBinder> getAllocator();
178
Mathias Agopiana5c75c02011-03-31 19:10:24 -0700179 // setDefaultBufferSize is used to set the size of buffers returned by
180 // requestBuffers when a with and height of zero is requested.
181 // A call to setDefaultBufferSize() may trigger requestBuffers() to
182 // be called from the client.
Mathias Agopian194c76c2011-11-10 14:34:26 -0800183 // The width and height parameters must be no greater than the minimum of
184 // GL_MAX_VIEWPORT_DIMS and GL_MAX_TEXTURE_SIZE (see: glGetIntegerv).
185 // An error due to invalid dimensions might not be reported until
186 // updateTexImage() is called.
187 status_t setDefaultBufferSize(uint32_t width, uint32_t height);
Mathias Agopiana5c75c02011-03-31 19:10:24 -0700188
Mathias Agopian7a042bf2011-04-11 21:19:55 -0700189 // getCurrentBuffer returns the buffer associated with the current image.
190 sp<GraphicBuffer> getCurrentBuffer() const;
191
192 // getCurrentTextureTarget returns the texture target of the current
193 // texture as returned by updateTexImage().
194 GLenum getCurrentTextureTarget() const;
195
196 // getCurrentCrop returns the cropping rectangle of the current buffer
197 Rect getCurrentCrop() const;
198
199 // getCurrentTransform returns the transform of the current buffer
200 uint32_t getCurrentTransform() const;
201
Mathias Agopian7734ebf2011-07-13 15:24:42 -0700202 // getCurrentScalingMode returns the scaling mode of the current buffer
203 uint32_t getCurrentScalingMode() const;
204
Jamie Gennis7b305ff2011-07-19 12:08:33 -0700205 // abandon frees all the buffers and puts the SurfaceTexture into the
206 // 'abandoned' state. Once put in this state the SurfaceTexture can never
207 // leave it. When in the 'abandoned' state, all methods of the
208 // ISurfaceTexture interface will fail with the NO_INIT error.
209 //
210 // Note that while calling this method causes all the buffers to be freed
211 // from the perspective of the the SurfaceTexture, if there are additional
212 // references on the buffers (e.g. if a buffer is referenced by a client or
213 // by OpenGL ES as a texture) then those buffer will remain allocated.
214 void abandon();
215
Jamie Gennisfa28c352011-09-16 17:30:26 -0700216 // set the name of the SurfaceTexture that will be used to identify it in
217 // log messages.
218 void setName(const String8& name);
219
Mathias Agopian68c77942011-05-09 19:08:33 -0700220 // dump our state in a String
221 void dump(String8& result) const;
222 void dump(String8& result, const char* prefix, char* buffer, size_t SIZE) const;
223
Mathias Agopian7a042bf2011-04-11 21:19:55 -0700224protected:
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800225
Mathias Agopian8e19c2e2011-08-10 17:35:09 -0700226 // freeBufferLocked frees the resources (both GraphicBuffer and EGLImage)
227 // for the given slot.
228 void freeBufferLocked(int index);
229
230 // freeAllBuffersLocked frees the resources (both GraphicBuffer and
231 // EGLImage) for all slots.
Mathias Agopianef51b992011-08-10 15:28:58 -0700232 void freeAllBuffersLocked();
Mathias Agopian2560d142011-08-10 16:33:23 -0700233
Mathias Agopian8e19c2e2011-08-10 17:35:09 -0700234 // freeAllBuffersExceptHeadLocked frees the resources (both GraphicBuffer
235 // and EGLImage) for all slots except the head of mQueue
236 void freeAllBuffersExceptHeadLocked();
237
Mathias Agopian2560d142011-08-10 16:33:23 -0700238 // drainQueueLocked drains the buffer queue if we're in synchronous mode
Mathias Agopian8e19c2e2011-08-10 17:35:09 -0700239 // returns immediately otherwise. return NO_INIT if SurfaceTexture
240 // became abandoned or disconnected during this call.
241 status_t drainQueueLocked();
242
243 // drainQueueAndFreeBuffersLocked drains the buffer queue if we're in
244 // synchronous mode and free all buffers. In asynchronous mode, all buffers
245 // are freed except the current buffer.
246 status_t drainQueueAndFreeBuffersLocked();
Mathias Agopian2560d142011-08-10 16:33:23 -0700247
Mathias Agopian7a042bf2011-04-11 21:19:55 -0700248 static bool isExternalFormat(uint32_t format);
Mathias Agopian7a042bf2011-04-11 21:19:55 -0700249
250private:
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800251
252 // createImage creates a new EGLImage from a GraphicBuffer.
253 EGLImageKHR createImage(EGLDisplay dpy,
254 const sp<GraphicBuffer>& graphicBuffer);
255
Mathias Agopian80727112011-05-02 19:51:12 -0700256 status_t setBufferCountServerLocked(int bufferCount);
257
Jamie Gennis736aa952011-06-12 17:03:06 -0700258 // computeCurrentTransformMatrix computes the transform matrix for the
259 // current texture. It uses mCurrentTransform and the current GraphicBuffer
260 // to compute this matrix and stores it in mCurrentTransformMatrix.
261 void computeCurrentTransformMatrix();
262
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800263 enum { INVALID_BUFFER_SLOT = -1 };
264
265 struct BufferSlot {
Mathias Agopianb3e518c2011-04-21 18:52:51 -0700266
267 BufferSlot()
268 : mEglImage(EGL_NO_IMAGE_KHR),
269 mEglDisplay(EGL_NO_DISPLAY),
270 mBufferState(BufferSlot::FREE),
271 mRequestBufferCalled(false),
Jamie Gennis8cd5ba42011-05-19 13:33:00 -0700272 mTransform(0),
Mathias Agopian7734ebf2011-07-13 15:24:42 -0700273 mScalingMode(NATIVE_WINDOW_SCALING_MODE_FREEZE),
Jamie Gennis8cd5ba42011-05-19 13:33:00 -0700274 mTimestamp(0) {
275 mCrop.makeInvalid();
Mathias Agopianb3e518c2011-04-21 18:52:51 -0700276 }
277
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800278 // mGraphicBuffer points to the buffer allocated for this slot or is NULL
279 // if no buffer has been allocated.
280 sp<GraphicBuffer> mGraphicBuffer;
281
282 // mEglImage is the EGLImage created from mGraphicBuffer.
283 EGLImageKHR mEglImage;
284
285 // mEglDisplay is the EGLDisplay used to create mEglImage.
286 EGLDisplay mEglDisplay;
287
Jamie Gennis8cd5ba42011-05-19 13:33:00 -0700288 // BufferState represents the different states in which a buffer slot
289 // can be.
290 enum BufferState {
291 // FREE indicates that the buffer is not currently being used and
292 // will not be used in the future until it gets dequeued and
Mathias Agopian29b57622011-08-17 15:42:04 -0700293 // subsequently queued by the client.
Jamie Gennis8cd5ba42011-05-19 13:33:00 -0700294 FREE = 0,
Mathias Agopianb3e518c2011-04-21 18:52:51 -0700295
Jamie Gennis8cd5ba42011-05-19 13:33:00 -0700296 // DEQUEUED indicates that the buffer has been dequeued by the
297 // client, but has not yet been queued or canceled. The buffer is
298 // considered 'owned' by the client, and the server should not use
299 // it for anything.
300 //
301 // Note that when in synchronous-mode (mSynchronousMode == true),
302 // the buffer that's currently attached to the texture may be
303 // dequeued by the client. That means that the current buffer can
304 // be in either the DEQUEUED or QUEUED state. In asynchronous mode,
305 // however, the current buffer is always in the QUEUED state.
306 DEQUEUED = 1,
307
308 // QUEUED indicates that the buffer has been queued by the client,
309 // and has not since been made available for the client to dequeue.
310 // Attaching the buffer to the texture does NOT transition the
311 // buffer away from the QUEUED state. However, in Synchronous mode
312 // the current buffer may be dequeued by the client under some
313 // circumstances. See the note about the current buffer in the
314 // documentation for DEQUEUED.
315 QUEUED = 2,
316 };
317
318 // mBufferState is the current state of this buffer slot.
319 BufferState mBufferState;
Mathias Agopianb3e518c2011-04-21 18:52:51 -0700320
321 // mRequestBufferCalled is used for validating that the client did
322 // call requestBuffer() when told to do so. Technically this is not
323 // needed but useful for debugging and catching client bugs.
324 bool mRequestBufferCalled;
325
Jamie Gennis8cd5ba42011-05-19 13:33:00 -0700326 // mCrop is the current crop rectangle for this buffer slot. This gets
327 // set to mNextCrop each time queueBuffer gets called for this buffer.
328 Rect mCrop;
Mathias Agopianb3e518c2011-04-21 18:52:51 -0700329
Jamie Gennis8cd5ba42011-05-19 13:33:00 -0700330 // mTransform is the current transform flags for this buffer slot. This
331 // gets set to mNextTransform each time queueBuffer gets called for this
332 // slot.
333 uint32_t mTransform;
Mathias Agopianb3e518c2011-04-21 18:52:51 -0700334
Mathias Agopian7734ebf2011-07-13 15:24:42 -0700335 // mScalingMode is the current scaling mode for this buffer slot. This
336 // gets set to mNextScalingMode each time queueBuffer gets called for
337 // this slot.
338 uint32_t mScalingMode;
339
Jamie Gennis8cd5ba42011-05-19 13:33:00 -0700340 // mTimestamp is the current timestamp for this buffer slot. This gets
341 // to set by queueBuffer each time this slot is queued.
342 int64_t mTimestamp;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800343 };
344
345 // mSlots is the array of buffer slots that must be mirrored on the client
346 // side. This allows buffer ownership to be transferred between the client
347 // and server without sending a GraphicBuffer over binder. The entire array
348 // is initialized to NULL at construction time, and buffers are allocated
349 // for a slot when requestBuffer is called with that slot's index.
350 BufferSlot mSlots[NUM_BUFFER_SLOTS];
351
Mathias Agopiana5c75c02011-03-31 19:10:24 -0700352 // mDefaultWidth holds the default width of allocated buffers. It is used
353 // in requestBuffers() if a width and height of zero is specified.
354 uint32_t mDefaultWidth;
355
356 // mDefaultHeight holds the default height of allocated buffers. It is used
357 // in requestBuffers() if a width and height of zero is specified.
358 uint32_t mDefaultHeight;
359
360 // mPixelFormat holds the pixel format of allocated buffers. It is used
361 // in requestBuffers() if a format of zero is specified.
362 uint32_t mPixelFormat;
363
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800364 // mBufferCount is the number of buffer slots that the client and server
Mathias Agopian80727112011-05-02 19:51:12 -0700365 // must maintain. It defaults to MIN_ASYNC_BUFFER_SLOTS and can be changed
366 // by calling setBufferCount or setBufferCountServer
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800367 int mBufferCount;
368
Jamie Gennisae468f42011-06-12 14:11:39 -0700369 // mClientBufferCount is the number of buffer slots requested by the client.
370 // The default is zero, which means the client doesn't care how many buffers
371 // there is.
Mathias Agopian80727112011-05-02 19:51:12 -0700372 int mClientBufferCount;
373
374 // mServerBufferCount buffer count requested by the server-side
375 int mServerBufferCount;
376
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800377 // mCurrentTexture is the buffer slot index of the buffer that is currently
Jamie Gennis67eedd72011-01-09 13:25:39 -0800378 // bound to the OpenGL texture. It is initialized to INVALID_BUFFER_SLOT,
379 // indicating that no buffer slot is currently bound to the texture. Note,
380 // however, that a value of INVALID_BUFFER_SLOT does not necessarily mean
381 // that no buffer is bound to the texture. A call to setBufferCount will
382 // reset mCurrentTexture to INVALID_BUFFER_SLOT.
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800383 int mCurrentTexture;
384
Jamie Gennis9a78c902011-01-12 18:30:40 -0800385 // mCurrentTextureBuf is the graphic buffer of the current texture. It's
386 // possible that this buffer is not associated with any buffer slot, so we
Jamie Gennis29c87022011-07-19 12:11:52 -0700387 // must track it separately in order to support the getCurrentBuffer method.
Jamie Gennis9a78c902011-01-12 18:30:40 -0800388 sp<GraphicBuffer> mCurrentTextureBuf;
389
Jamie Gennisf238e282011-01-09 16:33:17 -0800390 // mCurrentCrop is the crop rectangle that applies to the current texture.
Mathias Agopian7734ebf2011-07-13 15:24:42 -0700391 // It gets set each time updateTexImage is called.
Jamie Gennisf238e282011-01-09 16:33:17 -0800392 Rect mCurrentCrop;
393
394 // mCurrentTransform is the transform identifier for the current texture. It
Mathias Agopian7734ebf2011-07-13 15:24:42 -0700395 // gets set each time updateTexImage is called.
Jamie Gennisf238e282011-01-09 16:33:17 -0800396 uint32_t mCurrentTransform;
397
Mathias Agopian7734ebf2011-07-13 15:24:42 -0700398 // mCurrentScalingMode is the scaling mode for the current texture. It gets
399 // set to each time updateTexImage is called.
400 uint32_t mCurrentScalingMode;
401
Jamie Gennis736aa952011-06-12 17:03:06 -0700402 // mCurrentTransformMatrix is the transform matrix for the current texture.
403 // It gets computed by computeTransformMatrix each time updateTexImage is
404 // called.
405 float mCurrentTransformMatrix[16];
406
Eino-Ville Talvala1d01a122011-02-18 11:02:42 -0800407 // mCurrentTimestamp is the timestamp for the current texture. It
Mathias Agopian7734ebf2011-07-13 15:24:42 -0700408 // gets set each time updateTexImage is called.
Eino-Ville Talvala1d01a122011-02-18 11:02:42 -0800409 int64_t mCurrentTimestamp;
410
Jamie Gennisf238e282011-01-09 16:33:17 -0800411 // mNextCrop is the crop rectangle that will be used for the next buffer
412 // that gets queued. It is set by calling setCrop.
413 Rect mNextCrop;
414
415 // mNextTransform is the transform identifier that will be used for the next
416 // buffer that gets queued. It is set by calling setTransform.
417 uint32_t mNextTransform;
418
Mathias Agopian7734ebf2011-07-13 15:24:42 -0700419 // mNextScalingMode is the scaling mode that will be used for the next
420 // buffers that get queued. It is set by calling setScalingMode.
421 int mNextScalingMode;
422
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800423 // mTexName is the name of the OpenGL texture to which streamed images will
Pannag Sanketi292a31a2011-06-24 09:56:27 -0700424 // be bound when updateTexImage is called. It is set at construction time
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800425 // changed with a call to setTexName.
426 const GLuint mTexName;
427
Jamie Gennis9a78c902011-01-12 18:30:40 -0800428 // mGraphicBufferAlloc is the connection to SurfaceFlinger that is used to
429 // allocate new GraphicBuffer objects.
430 sp<IGraphicBufferAlloc> mGraphicBufferAlloc;
431
Jamie Gennisc4d4aea2011-01-13 14:43:36 -0800432 // mFrameAvailableListener is the listener object that will be called when a
433 // new frame becomes available. If it is not NULL it will be called from
434 // queueBuffer.
435 sp<FrameAvailableListener> mFrameAvailableListener;
436
Mathias Agopianb3e518c2011-04-21 18:52:51 -0700437 // mSynchronousMode whether we're in synchronous mode or not
438 bool mSynchronousMode;
439
Grace Kloba14a0e582011-06-23 21:21:47 -0700440 // mAllowSynchronousMode whether we allow synchronous mode or not
441 const bool mAllowSynchronousMode;
442
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700443 // mConnectedApi indicates the API that is currently connected to this
444 // SurfaceTexture. It defaults to NO_CONNECTED_API (= 0), and gets updated
445 // by the connect and disconnect methods.
446 int mConnectedApi;
447
Mathias Agopianb3e518c2011-04-21 18:52:51 -0700448 // mDequeueCondition condition used for dequeueBuffer in synchronous mode
449 mutable Condition mDequeueCondition;
450
451 // mQueue is a FIFO of queued buffers used in synchronous mode
452 typedef Vector<int> Fifo;
453 Fifo mQueue;
454
Jamie Gennis7b305ff2011-07-19 12:08:33 -0700455 // mAbandoned indicates that the SurfaceTexture will no longer be used to
456 // consume images buffers pushed to it using the ISurfaceTexture interface.
457 // It is initialized to false, and set to true in the abandon method. A
458 // SurfaceTexture that has been abandoned will return the NO_INIT error from
459 // all ISurfaceTexture methods capable of returning an error.
460 bool mAbandoned;
461
Jamie Gennisfa28c352011-09-16 17:30:26 -0700462 // mName is a string used to identify the SurfaceTexture in log messages.
463 // It is set by the setName method.
464 String8 mName;
465
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800466 // mMutex is the mutex used to prevent concurrent access to the member
467 // variables of SurfaceTexture objects. It must be locked whenever the
468 // member variables are accessed.
Mathias Agopian7a042bf2011-04-11 21:19:55 -0700469 mutable Mutex mMutex;
Jamie Gennis736aa952011-06-12 17:03:06 -0700470
Jamie Gennisfb1b5a22011-09-28 12:13:31 -0700471 // mTexTarget is the GL texture target with which the GL texture object is
472 // associated. It is set in the constructor and never changed. It is
473 // almost always GL_TEXTURE_EXTERNAL_OES except for one use case in Android
474 // Browser. In that case it is set to GL_TEXTURE_2D to allow
475 // glCopyTexSubImage to read from the texture. This is a hack to work
476 // around a GL driver limitation on the number of FBO attachments, which the
477 // browser's tile cache exceeds.
478 const GLenum mTexTarget;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800479};
480
481// ----------------------------------------------------------------------------
482}; // namespace android
483
484#endif // ANDROID_GUI_SURFACETEXTURE_H