2010-12-20 19:27:26 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef ANDROID_GUI_SURFACETEXTURECLIENT_H
|
|
|
|
#define ANDROID_GUI_SURFACETEXTURECLIENT_H
|
|
|
|
|
2012-12-18 17:49:45 +00:00
|
|
|
#include <gui/IGraphicBufferProducer.h>
|
|
|
|
#include <gui/GLConsumer.h>
|
2012-02-23 22:35:13 +00:00
|
|
|
#include <gui/BufferQueue.h>
|
2010-12-20 19:27:26 +00:00
|
|
|
|
2012-02-25 02:25:41 +00:00
|
|
|
#include <ui/ANativeObjectBase.h>
|
2011-07-14 00:39:11 +00:00
|
|
|
#include <ui/Region.h>
|
2010-12-20 19:27:26 +00:00
|
|
|
|
|
|
|
#include <utils/RefBase.h>
|
|
|
|
#include <utils/threads.h>
|
2012-04-12 23:32:37 +00:00
|
|
|
#include <utils/KeyedVector.h>
|
2010-12-20 19:27:26 +00:00
|
|
|
|
2012-03-23 21:15:44 +00:00
|
|
|
struct ANativeWindow_Buffer;
|
|
|
|
|
2010-12-20 19:27:26 +00:00
|
|
|
namespace android {
|
|
|
|
|
2011-04-12 04:19:55 +00:00
|
|
|
class Surface;
|
|
|
|
|
2012-12-13 01:10:08 +00:00
|
|
|
/*
|
2013-01-09 00:06:15 +00:00
|
|
|
* An implementation of ANativeWindow that feeds graphics buffers into a
|
|
|
|
* BufferQueue.
|
2012-12-13 01:10:08 +00:00
|
|
|
*
|
|
|
|
* This is typically used by programs that want to render frames through
|
|
|
|
* some means (maybe OpenGL, a software renderer, or a hardware decoder)
|
|
|
|
* and have the frames they create forwarded to SurfaceFlinger for
|
|
|
|
* compositing. For example, a video decoder could render a frame and call
|
|
|
|
* eglSwapBuffers(), which invokes ANativeWindow callbacks defined by
|
2013-01-09 00:06:15 +00:00
|
|
|
* SurfaceTextureClient. STC then forwards the buffers through Binder IPC
|
|
|
|
* to the BufferQueue's producer interface, providing the new frame to a
|
|
|
|
* consumer such as GLConsumer.
|
2012-12-13 01:10:08 +00:00
|
|
|
*
|
2013-01-09 00:06:15 +00:00
|
|
|
* TODO: rename to Surface after merging or renaming the existing Surface
|
|
|
|
* class.
|
2012-12-13 01:10:08 +00:00
|
|
|
*/
|
2010-12-20 19:27:26 +00:00
|
|
|
class SurfaceTextureClient
|
2012-02-25 02:25:41 +00:00
|
|
|
: public ANativeObjectBase<ANativeWindow, SurfaceTextureClient, RefBase>
|
2010-12-20 19:27:26 +00:00
|
|
|
{
|
|
|
|
public:
|
2012-02-23 22:35:13 +00:00
|
|
|
|
2012-12-18 17:49:45 +00:00
|
|
|
SurfaceTextureClient(const sp<IGraphicBufferProducer>& bufferProducer);
|
2010-12-20 19:27:26 +00:00
|
|
|
|
2012-12-18 17:49:45 +00:00
|
|
|
sp<IGraphicBufferProducer> getISurfaceTexture() const; // TODO: rename
|
2011-03-14 22:08:53 +00:00
|
|
|
|
2011-07-14 00:39:11 +00:00
|
|
|
protected:
|
|
|
|
SurfaceTextureClient();
|
2011-11-18 02:46:09 +00:00
|
|
|
virtual ~SurfaceTextureClient();
|
2012-12-18 17:49:45 +00:00
|
|
|
void setISurfaceTexture(const sp<IGraphicBufferProducer>& bufferProducer);
|
2010-12-20 19:27:26 +00:00
|
|
|
|
2011-07-14 00:39:11 +00:00
|
|
|
private:
|
2010-12-20 19:27:26 +00:00
|
|
|
// can't be copied
|
|
|
|
SurfaceTextureClient& operator = (const SurfaceTextureClient& rhs);
|
|
|
|
SurfaceTextureClient(const SurfaceTextureClient& rhs);
|
2011-07-14 00:39:11 +00:00
|
|
|
void init();
|
2010-12-20 19:27:26 +00:00
|
|
|
|
|
|
|
// ANativeWindow hooks
|
2012-06-13 23:32:25 +00:00
|
|
|
static int hook_cancelBuffer(ANativeWindow* window,
|
|
|
|
ANativeWindowBuffer* buffer, int fenceFd);
|
|
|
|
static int hook_dequeueBuffer(ANativeWindow* window,
|
|
|
|
ANativeWindowBuffer** buffer, int* fenceFd);
|
2011-07-14 00:39:11 +00:00
|
|
|
static int hook_perform(ANativeWindow* window, int operation, ...);
|
|
|
|
static int hook_query(const ANativeWindow* window, int what, int* value);
|
2012-06-13 23:32:25 +00:00
|
|
|
static int hook_queueBuffer(ANativeWindow* window,
|
|
|
|
ANativeWindowBuffer* buffer, int fenceFd);
|
2011-07-14 00:39:11 +00:00
|
|
|
static int hook_setSwapInterval(ANativeWindow* window, int interval);
|
2010-12-20 19:27:26 +00:00
|
|
|
|
2012-06-13 23:32:25 +00:00
|
|
|
static int hook_cancelBuffer_DEPRECATED(ANativeWindow* window,
|
|
|
|
ANativeWindowBuffer* buffer);
|
|
|
|
static int hook_dequeueBuffer_DEPRECATED(ANativeWindow* window,
|
|
|
|
ANativeWindowBuffer** buffer);
|
|
|
|
static int hook_lockBuffer_DEPRECATED(ANativeWindow* window,
|
|
|
|
ANativeWindowBuffer* buffer);
|
|
|
|
static int hook_queueBuffer_DEPRECATED(ANativeWindow* window,
|
|
|
|
ANativeWindowBuffer* buffer);
|
|
|
|
|
2010-12-20 19:27:26 +00:00
|
|
|
int dispatchConnect(va_list args);
|
|
|
|
int dispatchDisconnect(va_list args);
|
|
|
|
int dispatchSetBufferCount(va_list args);
|
|
|
|
int dispatchSetBuffersGeometry(va_list args);
|
2011-07-01 20:12:07 +00:00
|
|
|
int dispatchSetBuffersDimensions(va_list args);
|
2012-04-10 02:46:29 +00:00
|
|
|
int dispatchSetBuffersUserDimensions(va_list args);
|
2011-07-01 20:12:07 +00:00
|
|
|
int dispatchSetBuffersFormat(va_list args);
|
2011-07-13 22:24:42 +00:00
|
|
|
int dispatchSetScalingMode(va_list args);
|
2010-12-20 19:27:26 +00:00
|
|
|
int dispatchSetBuffersTransform(va_list args);
|
2011-02-18 19:02:42 +00:00
|
|
|
int dispatchSetBuffersTimestamp(va_list args);
|
2011-02-27 22:10:20 +00:00
|
|
|
int dispatchSetCrop(va_list args);
|
2012-05-07 20:50:11 +00:00
|
|
|
int dispatchSetPostTransformCrop(va_list args);
|
2011-02-27 22:10:20 +00:00
|
|
|
int dispatchSetUsage(va_list args);
|
2011-07-14 00:39:11 +00:00
|
|
|
int dispatchLock(va_list args);
|
|
|
|
int dispatchUnlockAndPost(va_list args);
|
|
|
|
|
|
|
|
protected:
|
2012-06-13 23:32:25 +00:00
|
|
|
virtual int dequeueBuffer(ANativeWindowBuffer** buffer, int* fenceFd);
|
|
|
|
virtual int cancelBuffer(ANativeWindowBuffer* buffer, int fenceFd);
|
|
|
|
virtual int queueBuffer(ANativeWindowBuffer* buffer, int fenceFd);
|
2011-07-14 00:39:11 +00:00
|
|
|
virtual int perform(int operation, va_list args);
|
|
|
|
virtual int query(int what, int* value) const;
|
|
|
|
virtual int setSwapInterval(int interval);
|
|
|
|
|
2012-06-13 23:32:25 +00:00
|
|
|
virtual int lockBuffer_DEPRECATED(ANativeWindowBuffer* buffer);
|
|
|
|
|
2011-07-14 00:39:11 +00:00
|
|
|
virtual int connect(int api);
|
|
|
|
virtual int disconnect(int api);
|
|
|
|
virtual int setBufferCount(int bufferCount);
|
|
|
|
virtual int setBuffersDimensions(int w, int h);
|
2012-04-10 02:46:29 +00:00
|
|
|
virtual int setBuffersUserDimensions(int w, int h);
|
2011-07-14 00:39:11 +00:00
|
|
|
virtual int setBuffersFormat(int format);
|
2011-07-13 22:24:42 +00:00
|
|
|
virtual int setScalingMode(int mode);
|
2011-07-14 00:39:11 +00:00
|
|
|
virtual int setBuffersTransform(int transform);
|
|
|
|
virtual int setBuffersTimestamp(int64_t timestamp);
|
|
|
|
virtual int setCrop(Rect const* rect);
|
|
|
|
virtual int setUsage(uint32_t reqUsage);
|
|
|
|
virtual int lock(ANativeWindow_Buffer* outBuffer, ARect* inOutDirtyBounds);
|
|
|
|
virtual int unlockAndPost();
|
2011-04-12 04:19:55 +00:00
|
|
|
|
2012-02-23 22:35:13 +00:00
|
|
|
enum { NUM_BUFFER_SLOTS = BufferQueue::NUM_BUFFER_SLOTS };
|
2010-12-20 19:27:26 +00:00
|
|
|
enum { DEFAULT_FORMAT = PIXEL_FORMAT_RGBA_8888 };
|
|
|
|
|
2011-07-14 00:39:11 +00:00
|
|
|
private:
|
|
|
|
void freeAllBuffers();
|
|
|
|
int getSlotFromBufferLocked(android_native_buffer_t* buffer) const;
|
|
|
|
|
2012-04-12 23:32:37 +00:00
|
|
|
struct BufferSlot {
|
|
|
|
sp<GraphicBuffer> buffer;
|
|
|
|
Region dirtyRegion;
|
|
|
|
};
|
|
|
|
|
2010-12-20 19:27:26 +00:00
|
|
|
// mSurfaceTexture is the interface to the surface texture server. All
|
|
|
|
// operations on the surface texture client ultimately translate into
|
|
|
|
// interactions with the server using this interface.
|
2012-12-18 17:49:45 +00:00
|
|
|
// TODO: rename to mBufferProducer
|
|
|
|
sp<IGraphicBufferProducer> mSurfaceTexture;
|
2010-12-20 19:27:26 +00:00
|
|
|
|
|
|
|
// mSlots stores the buffers that have been allocated for each buffer slot.
|
|
|
|
// It is initialized to null pointers, and gets filled in with the result of
|
2012-12-18 17:49:45 +00:00
|
|
|
// IGraphicBufferProducer::requestBuffer when the client dequeues a buffer from a
|
2010-12-20 19:27:26 +00:00
|
|
|
// slot that has not yet been used. The buffer allocated to a slot will also
|
|
|
|
// be replaced if the requested buffer usage or geometry differs from that
|
|
|
|
// of the buffer allocated to a slot.
|
2012-04-12 23:32:37 +00:00
|
|
|
BufferSlot mSlots[NUM_BUFFER_SLOTS];
|
2010-12-20 19:27:26 +00:00
|
|
|
|
|
|
|
// mReqWidth is the buffer width that will be requested at the next dequeue
|
|
|
|
// operation. It is initialized to 1.
|
|
|
|
uint32_t mReqWidth;
|
|
|
|
|
2012-03-30 00:10:08 +00:00
|
|
|
// mReqHeight is the buffer height that will be requested at the next
|
|
|
|
// dequeue operation. It is initialized to 1.
|
2010-12-20 19:27:26 +00:00
|
|
|
uint32_t mReqHeight;
|
|
|
|
|
|
|
|
// mReqFormat is the buffer pixel format that will be requested at the next
|
|
|
|
// deuque operation. It is initialized to PIXEL_FORMAT_RGBA_8888.
|
|
|
|
uint32_t mReqFormat;
|
|
|
|
|
|
|
|
// mReqUsage is the set of buffer usage flags that will be requested
|
|
|
|
// at the next deuque operation. It is initialized to 0.
|
|
|
|
uint32_t mReqUsage;
|
|
|
|
|
2011-02-18 19:02:42 +00:00
|
|
|
// mTimestamp is the timestamp that will be used for the next buffer queue
|
|
|
|
// operation. It defaults to NATIVE_WINDOW_TIMESTAMP_AUTO, which means that
|
|
|
|
// a timestamp is auto-generated when queueBuffer is called.
|
|
|
|
int64_t mTimestamp;
|
|
|
|
|
2012-03-30 00:10:08 +00:00
|
|
|
// mCrop is the crop rectangle that will be used for the next buffer
|
|
|
|
// that gets queued. It is set by calling setCrop.
|
|
|
|
Rect mCrop;
|
|
|
|
|
|
|
|
// mScalingMode is the scaling mode that will be used for the next
|
|
|
|
// buffers that get queued. It is set by calling setScalingMode.
|
|
|
|
int mScalingMode;
|
|
|
|
|
|
|
|
// mTransform is the transform identifier that will be used for the next
|
|
|
|
// buffer that gets queued. It is set by calling setTransform.
|
|
|
|
uint32_t mTransform;
|
|
|
|
|
2012-04-10 02:46:29 +00:00
|
|
|
// mDefaultWidth is default width of the buffers, regardless of the
|
|
|
|
// native_window_set_buffers_dimensions call.
|
|
|
|
uint32_t mDefaultWidth;
|
2011-07-19 22:24:46 +00:00
|
|
|
|
2012-04-10 02:46:29 +00:00
|
|
|
// mDefaultHeight is default height of the buffers, regardless of the
|
|
|
|
// native_window_set_buffers_dimensions call.
|
|
|
|
uint32_t mDefaultHeight;
|
|
|
|
|
|
|
|
// mUserWidth, if non-zero, is an application-specified override
|
|
|
|
// of mDefaultWidth. This is lower priority than the width set by
|
|
|
|
// native_window_set_buffers_dimensions.
|
|
|
|
uint32_t mUserWidth;
|
|
|
|
|
|
|
|
// mUserHeight, if non-zero, is an application-specified override
|
|
|
|
// of mDefaultHeight. This is lower priority than the height set
|
|
|
|
// by native_window_set_buffers_dimensions.
|
|
|
|
uint32_t mUserHeight;
|
2011-07-19 22:24:46 +00:00
|
|
|
|
|
|
|
// mTransformHint is the transform probably applied to buffers of this
|
|
|
|
// window. this is only a hint, actual transform may differ.
|
|
|
|
uint32_t mTransformHint;
|
|
|
|
|
2012-04-21 00:19:28 +00:00
|
|
|
// mConsumerRunningBehind whether the consumer is running more than
|
|
|
|
// one buffer behind the producer.
|
|
|
|
mutable bool mConsumerRunningBehind;
|
|
|
|
|
2010-12-20 19:27:26 +00:00
|
|
|
// mMutex is the mutex used to prevent concurrent access to the member
|
2012-12-18 17:49:45 +00:00
|
|
|
// variables of SurfaceTextureClient objects. It must be locked whenever the
|
2010-12-20 19:27:26 +00:00
|
|
|
// member variables are accessed.
|
2011-04-12 04:19:55 +00:00
|
|
|
mutable Mutex mMutex;
|
2011-07-14 00:39:11 +00:00
|
|
|
|
|
|
|
// must be used from the lock/unlock thread
|
|
|
|
sp<GraphicBuffer> mLockedBuffer;
|
|
|
|
sp<GraphicBuffer> mPostedBuffer;
|
|
|
|
bool mConnectedToCpu;
|
2012-04-12 23:32:37 +00:00
|
|
|
|
|
|
|
// must be accessed from lock/unlock thread only
|
|
|
|
Region mDirtyRegion;
|
2010-12-20 19:27:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}; // namespace android
|
|
|
|
|
|
|
|
#endif // ANDROID_GUI_SURFACETEXTURECLIENT_H
|