summaryrefslogtreecommitdiffstats
path: root/include/gui
diff options
context:
space:
mode:
Diffstat (limited to 'include/gui')
-rw-r--r--include/gui/BufferItemConsumer.h91
-rw-r--r--include/gui/BufferQueue.h143
-rw-r--r--include/gui/ConsumerBase.h220
-rw-r--r--include/gui/CpuConsumer.h103
-rw-r--r--include/gui/DisplayEventReceiver.h9
-rw-r--r--include/gui/GLConsumer.h46
-rw-r--r--include/gui/GuiConfig.h29
-rw-r--r--include/gui/ISurfaceComposer.h127
-rw-r--r--include/gui/ISurfaceComposerClient.h47
-rw-r--r--include/gui/ISurfaceTexture.h38
-rw-r--r--include/gui/Sensor.h16
-rw-r--r--include/gui/Surface.h9
-rw-r--r--include/gui/SurfaceComposerClient.h95
-rw-r--r--include/gui/SurfaceTexture.h154
-rw-r--r--include/gui/SurfaceTextureClient.h28
15 files changed, 845 insertions, 310 deletions
diff --git a/include/gui/BufferItemConsumer.h b/include/gui/BufferItemConsumer.h
new file mode 100644
index 0000000..cd4df25
--- /dev/null
+++ b/include/gui/BufferItemConsumer.h
@@ -0,0 +1,91 @@
+/*
+ * Copyright (C) 2012 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_BUFFERITEMCONSUMER_H
+#define ANDROID_GUI_BUFFERITEMCONSUMER_H
+
+#include <gui/ConsumerBase.h>
+
+#include <ui/GraphicBuffer.h>
+
+#include <utils/String8.h>
+#include <utils/Vector.h>
+#include <utils/threads.h>
+
+#define ANDROID_GRAPHICS_BUFFERITEMCONSUMER_JNI_ID "mBufferItemConsumer"
+
+namespace android {
+
+/**
+ * BufferItemConsumer is a BufferQueue consumer endpoint that allows clients
+ * access to the whole BufferItem entry from BufferQueue. Multiple buffers may
+ * be acquired at once, to be used concurrently by the client. This consumer can
+ * operate either in synchronous or asynchronous mode.
+ */
+class BufferItemConsumer: public ConsumerBase
+{
+ public:
+ typedef ConsumerBase::FrameAvailableListener FrameAvailableListener;
+
+ typedef BufferQueue::BufferItem BufferItem;
+
+ enum { INVALID_BUFFER_SLOT = BufferQueue::INVALID_BUFFER_SLOT };
+ enum { NO_BUFFER_AVAILABLE = BufferQueue::NO_BUFFER_AVAILABLE };
+
+ // Create a new buffer item consumer. The consumerUsage parameter determines
+ // the consumer usage flags passed to the graphics allocator. The
+ // bufferCount parameter specifies how many buffers can be locked for user
+ // access at the same time.
+ BufferItemConsumer(uint32_t consumerUsage,
+ int bufferCount = BufferQueue::MIN_UNDEQUEUED_BUFFERS,
+ bool synchronousMode = false);
+
+ virtual ~BufferItemConsumer();
+
+ // set the name of the BufferItemConsumer that will be used to identify it in
+ // log messages.
+ void setName(const String8& name);
+
+ // Gets the next graphics buffer from the producer, filling out the
+ // passed-in BufferItem structure. Returns NO_BUFFER_AVAILABLE if the queue
+ // of buffers is empty, and INVALID_OPERATION if the maximum number of
+ // buffers is already acquired.
+ //
+ // Only a fixed number of buffers can be acquired at a time, determined by
+ // the construction-time bufferCount parameter. If INVALID_OPERATION is
+ // returned by acquireBuffer, then old buffers must be returned to the
+ // queue by calling releaseBuffer before more buffers can be acquired.
+ //
+ // If waitForFence is true, and the acquired BufferItem has a valid fence object,
+ // acquireBuffer will wait on the fence with no timeout before returning.
+ status_t acquireBuffer(BufferItem *item, bool waitForFence = true);
+
+ // Returns an acquired buffer to the queue, allowing it to be reused. Since
+ // only a fixed number of buffers may be acquired at a time, old buffers
+ // must be released by calling releaseBuffer to ensure new buffers can be
+ // acquired by acquireBuffer. Once a BufferItem is released, the caller must
+ // not access any members of the BufferItem, and should immediately remove
+ // all of its references to the BufferItem itself.
+ status_t releaseBuffer(const BufferItem &item,
+ const sp<Fence>& releaseFence = Fence::NO_FENCE);
+
+ sp<ISurfaceTexture> getProducerInterface() const { return getBufferQueue(); }
+
+};
+
+} // namespace android
+
+#endif // ANDROID_GUI_CPUCONSUMER_H
diff --git a/include/gui/BufferQueue.h b/include/gui/BufferQueue.h
index 1c80d0c..9e265ba 100644
--- a/include/gui/BufferQueue.h
+++ b/include/gui/BufferQueue.h
@@ -23,6 +23,7 @@
#include <gui/IGraphicBufferAlloc.h>
#include <gui/ISurfaceTexture.h>
+#include <ui/Fence.h>
#include <ui/GraphicBuffer.h>
#include <utils/String8.h>
@@ -40,6 +41,10 @@ public:
enum { INVALID_BUFFER_SLOT = -1 };
enum { STALE_BUFFER_SLOT = 1, NO_BUFFER_AVAILABLE };
+ // When in async mode we reserve two slots in order to guarantee that the
+ // producer and consumer can run asynchronously.
+ enum { MAX_MAX_ACQUIRED_BUFFERS = NUM_BUFFER_SLOTS - 2 };
+
// ConsumerListener is the interface through which the BufferQueue notifies
// the consumer of events that the consumer may wish to react to. Because
// the consumer will generally have a mutex that is locked during calls from
@@ -91,12 +96,12 @@ public:
};
- // BufferQueue manages a pool of gralloc memory slots to be used
- // by producers and consumers.
- // allowSynchronousMode specifies whether or not synchronous mode can be
- // enabled.
- // bufferCount sets the minimum number of undequeued buffers for this queue
- BufferQueue( bool allowSynchronousMode = true, int bufferCount = MIN_UNDEQUEUED_BUFFERS);
+ // BufferQueue manages a pool of gralloc memory slots to be used by
+ // producers and consumers. allowSynchronousMode specifies whether or not
+ // synchronous mode can be enabled by the producer. allocator is used to
+ // allocate all the needed gralloc buffers.
+ BufferQueue(bool allowSynchronousMode = true,
+ const sp<IGraphicBufferAlloc>& allocator = NULL);
virtual ~BufferQueue();
virtual int query(int what, int* value);
@@ -113,12 +118,18 @@ public:
// pointed to by the buf argument and a status of OK is returned. If no
// slot is available then a status of -EBUSY is returned and buf is
// unmodified.
+ //
+ // The fence parameter will be updated to hold the fence associated with
+ // the buffer. The contents of the buffer must not be overwritten until the
+ // fence signals. If the fence is NULL, the buffer may be written
+ // immediately.
+ //
// The width and height parameters must be no greater than the minimum of
// GL_MAX_VIEWPORT_DIMS and GL_MAX_TEXTURE_SIZE (see: glGetIntegerv).
// An error due to invalid dimensions might not be reported until
// updateTexImage() is called.
- virtual status_t dequeueBuffer(int *buf, uint32_t width, uint32_t height,
- uint32_t format, uint32_t usage);
+ virtual status_t dequeueBuffer(int *buf, sp<Fence>& fence,
+ uint32_t width, uint32_t height, uint32_t format, uint32_t usage);
// queueBuffer returns a filled buffer to the BufferQueue. In addition, a
// timestamp must be provided for the buffer. The timestamp is in
@@ -128,7 +139,7 @@ public:
virtual status_t queueBuffer(int buf,
const QueueBufferInput& input, QueueBufferOutput* output);
- virtual void cancelBuffer(int buf);
+ virtual void cancelBuffer(int buf, sp<Fence> fence);
// setSynchronousMode set whether dequeueBuffer is synchronous or
// asynchronous. In synchronous mode, dequeueBuffer blocks until
@@ -193,6 +204,9 @@ public:
// mBuf is the slot index of this buffer
int mBuf;
+
+ // mFence is a fence that will signal when the buffer is idle.
+ sp<Fence> mFence;
};
// The following public functions is the consumer facing interface
@@ -209,9 +223,15 @@ public:
// releaseBuffer releases a buffer slot from the consumer back to the
// BufferQueue pending a fence sync.
//
+ // If releaseBuffer returns STALE_BUFFER_SLOT, then the consumer must free
+ // any references to the just-released buffer that it might have, as if it
+ // had received a onBuffersReleased() call with a mask set for the released
+ // buffer.
+ //
// Note that the dependencies on EGL will be removed once we switch to using
// the Android HW Sync HAL.
- status_t releaseBuffer(int buf, EGLDisplay display, EGLSyncKHR fence);
+ status_t releaseBuffer(int buf, EGLDisplay display, EGLSyncKHR fence,
+ const sp<Fence>& releaseFence);
// consumerConnect connects a consumer to the BufferQueue. Only one
// consumer may be connected, and when that consumer disconnects the
@@ -234,10 +254,15 @@ public:
// requestBuffers when a with and height of zero is requested.
status_t setDefaultBufferSize(uint32_t w, uint32_t h);
- // setBufferCountServer set the buffer count. If the client has requested
+ // setDefaultBufferCount set the buffer count. If the client has requested
// a buffer count using setBufferCount, the server-buffer count will
// take effect once the client sets the count back to zero.
- status_t setBufferCountServer(int bufferCount);
+ status_t setDefaultMaxBufferCount(int bufferCount);
+
+ // setMaxAcquiredBufferCount sets the maximum number of buffers that can
+ // be acquired by the consumer at one time. This call will fail if a
+ // producer is connected to the BufferQueue.
+ status_t setMaxAcquiredBufferCount(int maxAcquiredBuffers);
// isSynchronousMode returns whether the SurfaceTexture is currently in
// synchronous mode.
@@ -280,7 +305,31 @@ private:
// are freed except the current buffer.
status_t drainQueueAndFreeBuffersLocked();
- status_t setBufferCountServerLocked(int bufferCount);
+ // setDefaultMaxBufferCountLocked sets the maximum number of buffer slots
+ // that will be used if the producer does not override the buffer slot
+ // count.
+ status_t setDefaultMaxBufferCountLocked(int count);
+
+ // getMinBufferCountLocked returns the minimum number of buffers allowed
+ // given the current BufferQueue state.
+ int getMinMaxBufferCountLocked() const;
+
+ // getMinUndequeuedBufferCountLocked returns the minimum number of buffers
+ // that must remain in a state other than DEQUEUED.
+ int getMinUndequeuedBufferCountLocked() const;
+
+ // getMaxBufferCountLocked returns the maximum number of buffers that can
+ // be allocated at once. This value depends upon the following member
+ // variables:
+ //
+ // mSynchronousMode
+ // mMaxAcquiredBufferCount
+ // mDefaultMaxBufferCount
+ // mOverrideMaxBufferCount
+ //
+ // Any time one of these member variables is changed while a producer is
+ // connected, mDequeueCondition must be broadcast.
+ int getMaxBufferCountLocked() const;
struct BufferSlot {
@@ -292,7 +341,7 @@ private:
mScalingMode(NATIVE_WINDOW_SCALING_MODE_FREEZE),
mTimestamp(0),
mFrameNumber(0),
- mFence(EGL_NO_SYNC_KHR),
+ mEglFence(EGL_NO_SYNC_KHR),
mAcquireCalled(false),
mNeedsCleanupOnRelease(false) {
mCrop.makeInvalid();
@@ -353,9 +402,11 @@ private:
Rect mCrop;
// mTransform is the current transform flags for this buffer slot.
+ // (example: NATIVE_WINDOW_TRANSFORM_ROT_90)
uint32_t mTransform;
// mScalingMode is the current scaling mode for this buffer slot.
+ // (example: NATIVE_WINDOW_SCALING_MODE_FREEZE)
uint32_t mScalingMode;
// mTimestamp is the current timestamp for this buffer slot. This gets
@@ -365,11 +416,22 @@ private:
// mFrameNumber is the number of the queued frame for this slot.
uint64_t mFrameNumber;
- // mFence is the EGL sync object that must signal before the buffer
+ // mEglFence is the EGL sync object that must signal before the buffer
// associated with this buffer slot may be dequeued. It is initialized
// to EGL_NO_SYNC_KHR when the buffer is created and (optionally, based
// on a compile-time option) set to a new sync object in updateTexImage.
- EGLSyncKHR mFence;
+ EGLSyncKHR mEglFence;
+
+ // mFence is a fence which will signal when work initiated by the
+ // previous owner of the buffer is finished. When the buffer is FREE,
+ // the fence indicates when the consumer has finished reading
+ // from the buffer, or when the producer has finished writing if it
+ // called cancelBuffer after queueing some writes. When the buffer is
+ // QUEUED, it indicates when the producer has finished filling the
+ // buffer. When the buffer is DEQUEUED or ACQUIRED, the fence has been
+ // passed to the consumer or producer along with ownership of the
+ // buffer, and mFence is empty.
+ sp<Fence> mFence;
// Indicates whether this buffer has been seen by a consumer yet
bool mAcquireCalled;
@@ -393,34 +455,27 @@ private:
// in requestBuffers() if a width and height of zero is specified.
uint32_t mDefaultHeight;
- // mPixelFormat holds the pixel format of allocated buffers. It is used
- // in requestBuffers() if a format of zero is specified.
- uint32_t mPixelFormat;
-
- // mMinUndequeuedBuffers is a constraint on the number of buffers
- // not dequeued at any time
- int mMinUndequeuedBuffers;
-
- // mMinAsyncBufferSlots is a constraint on the minimum mBufferCount
- // when this BufferQueue is in asynchronous mode
- int mMinAsyncBufferSlots;
-
- // mMinSyncBufferSlots is a constraint on the minimum mBufferCount
- // when this BufferQueue is in synchronous mode
- int mMinSyncBufferSlots;
-
- // mBufferCount is the number of buffer slots that the client and server
- // must maintain. It defaults to MIN_ASYNC_BUFFER_SLOTS and can be changed
- // by calling setBufferCount or setBufferCountServer
- int mBufferCount;
-
- // mClientBufferCount is the number of buffer slots requested by the client.
- // The default is zero, which means the client doesn't care how many buffers
- // there is.
- int mClientBufferCount;
-
- // mServerBufferCount buffer count requested by the server-side
- int mServerBufferCount;
+ // mMaxAcquiredBufferCount is the number of buffers that the consumer may
+ // acquire at one time. It defaults to 1 and can be changed by the
+ // consumer via the setMaxAcquiredBufferCount method, but this may only be
+ // done when no producer is connected to the BufferQueue.
+ //
+ // This value is used to derive the value returned for the
+ // MIN_UNDEQUEUED_BUFFERS query by the producer.
+ int mMaxAcquiredBufferCount;
+
+ // mDefaultMaxBufferCount is the default limit on the number of buffers
+ // that will be allocated at one time. This default limit is set by the
+ // consumer. The limit (as opposed to the default limit) may be
+ // overridden by the producer.
+ int mDefaultMaxBufferCount;
+
+ // mOverrideMaxBufferCount is the limit on the number of buffers that will
+ // be allocated at one time. This value is set by the image producer by
+ // calling setBufferCount. The default is zero, which means the producer
+ // doesn't care about the number of buffers in the pool. In that case
+ // mDefaultMaxBufferCount is used as the limit.
+ int mOverrideMaxBufferCount;
// mGraphicBufferAlloc is the connection to SurfaceFlinger that is used to
// allocate new GraphicBuffer objects.
diff --git a/include/gui/ConsumerBase.h b/include/gui/ConsumerBase.h
new file mode 100644
index 0000000..ee5cb29
--- /dev/null
+++ b/include/gui/ConsumerBase.h
@@ -0,0 +1,220 @@
+/*
+ * 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_CONSUMERBASE_H
+#define ANDROID_GUI_CONSUMERBASE_H
+
+#include <gui/BufferQueue.h>
+
+#include <ui/GraphicBuffer.h>
+
+#include <utils/String8.h>
+#include <utils/Vector.h>
+#include <utils/threads.h>
+
+namespace android {
+// ----------------------------------------------------------------------------
+
+class String8;
+
+// ConsumerBase is a base class for BufferQueue consumer end-points. It
+// handles common tasks like management of the connection to the BufferQueue
+// and the buffer pool.
+class ConsumerBase : public virtual RefBase,
+ protected BufferQueue::ConsumerListener {
+public:
+ struct FrameAvailableListener : public virtual RefBase {
+ // onFrameAvailable() is called each time an additional frame becomes
+ // available for consumption. This means that frames that are queued
+ // while in asynchronous mode only trigger the callback if no previous
+ // frames are pending. Frames queued while in synchronous mode always
+ // trigger the callback.
+ //
+ // This is called without any lock held and can be called concurrently
+ // by multiple threads.
+ virtual void onFrameAvailable() = 0;
+ };
+
+ virtual ~ConsumerBase();
+
+ // abandon frees all the buffers and puts the ConsumerBase into the
+ // 'abandoned' state. Once put in this state the ConsumerBase can never
+ // leave it. When in the 'abandoned' state, all methods of the
+ // ISurfaceTexture interface will fail with the NO_INIT error.
+ //
+ // Note that while calling this method causes all the buffers to be freed
+ // from the perspective of the the ConsumerBase, if there are additional
+ // references on the buffers (e.g. if a buffer is referenced by a client
+ // or by OpenGL ES as a texture) then those buffer will remain allocated.
+ void abandon();
+
+ // set the name of the ConsumerBase that will be used to identify it in
+ // log messages.
+ void setName(const String8& name);
+
+ // getBufferQueue returns the BufferQueue object to which this
+ // ConsumerBase is connected.
+ sp<BufferQueue> getBufferQueue() const;
+
+ // dump writes the current state to a string. These methods should NOT be
+ // overridden by child classes. Instead they should override the
+ // dumpLocked method, which is called by these methods after locking the
+ // mutex.
+ void dump(String8& result) const;
+ void dump(String8& result, const char* prefix, char* buffer, size_t SIZE) const;
+
+ // setFrameAvailableListener sets the listener object that will be notified
+ // when a new frame becomes available.
+ void setFrameAvailableListener(const sp<FrameAvailableListener>& listener);
+
+private:
+ ConsumerBase(const ConsumerBase&);
+ void operator=(const ConsumerBase&);
+
+protected:
+
+ // ConsumerBase constructs a new ConsumerBase object to consume image
+ // buffers from the given BufferQueue.
+ ConsumerBase(const sp<BufferQueue> &bufferQueue);
+
+ // Implementation of the BufferQueue::ConsumerListener interface. These
+ // calls are used to notify the ConsumerBase of asynchronous events in the
+ // BufferQueue. These methods should not need to be overridden by derived
+ // classes, but if they are overridden the ConsumerBase implementation
+ // must be called from the derived class.
+ virtual void onFrameAvailable();
+ virtual void onBuffersReleased();
+
+ // freeBufferLocked frees up the given buffer slot. If the slot has been
+ // initialized this will release the reference to the GraphicBuffer in that
+ // slot. Otherwise it has no effect.
+ //
+ // Derived classes should override this method to clean up any state they
+ // keep per slot. If it is overridden, the derived class's implementation
+ // must call ConsumerBase::freeBufferLocked.
+ //
+ // This method must be called with mMutex locked.
+ virtual void freeBufferLocked(int slotIndex);
+
+ // abandonLocked puts the BufferQueue into the abandoned state, causing
+ // all future operations on it to fail. This method rather than the public
+ // abandon method should be overridden by child classes to add abandon-
+ // time behavior.
+ //
+ // Derived classes should override this method to clean up any object
+ // state they keep (as opposed to per-slot state). If it is overridden,
+ // the derived class's implementation must call ConsumerBase::abandonLocked.
+ //
+ // This method must be called with mMutex locked.
+ virtual void abandonLocked();
+
+ // dumpLocked dumps the current state of the ConsumerBase object to the
+ // result string. Each line is prefixed with the string pointed to by the
+ // prefix argument. The buffer argument points to a buffer that may be
+ // used for intermediate formatting data, and the size of that buffer is
+ // indicated by the size argument.
+ //
+ // Derived classes should override this method to dump their internal
+ // state. If this method is overridden the derived class's implementation
+ // should call ConsumerBase::dumpLocked.
+ //
+ // This method must be called with mMutex locked.
+ virtual void dumpLocked(String8& result, const char* prefix, char* buffer,
+ size_t size) const;
+
+ // acquireBufferLocked fetches the next buffer from the BufferQueue and
+ // updates the buffer slot for the buffer returned.
+ //
+ // Derived classes should override this method to perform any
+ // initialization that must take place the first time a buffer is assigned
+ // to a slot. If it is overridden the derived class's implementation must
+ // call ConsumerBase::acquireBufferLocked.
+ virtual status_t acquireBufferLocked(BufferQueue::BufferItem *item);
+
+ // releaseBufferLocked relinquishes control over a buffer, returning that
+ // control to the BufferQueue.
+ //
+ // Derived classes should override this method to perform any cleanup that
+ // must take place when a buffer is released back to the BufferQueue. If
+ // it is overridden the derived class's implementation must call
+ // ConsumerBase::releaseBufferLocked.
+ virtual status_t releaseBufferLocked(int buf, EGLDisplay display,
+ EGLSyncKHR eglFence);
+
+ // addReleaseFence* adds the sync points associated with a fence to the set
+ // of sync points that must be reached before the buffer in the given slot
+ // may be used after the slot has been released. This should be called by
+ // derived classes each time some asynchronous work is kicked off that
+ // references the buffer.
+ status_t addReleaseFence(int slot, const sp<Fence>& fence);
+ status_t addReleaseFenceLocked(int slot, const sp<Fence>& fence);
+
+ // Slot contains the information and object references that
+ // ConsumerBase maintains about a BufferQueue buffer slot.
+ struct Slot {
+ // mGraphicBuffer is the Gralloc buffer store in the slot or NULL if
+ // no Gralloc buffer is in the slot.
+ sp<GraphicBuffer> mGraphicBuffer;
+
+ // mFence is a fence which will signal when the buffer associated with
+ // this buffer slot is no longer being used by the consumer and can be
+ // overwritten. The buffer can be dequeued before the fence signals;
+ // the producer is responsible for delaying writes until it signals.
+ sp<Fence> mFence;
+ };
+
+ // mSlots stores the buffers that have been allocated by the BufferQueue
+ // for each buffer slot. It is initialized to null pointers, and gets
+ // filled in with the result of BufferQueue::acquire when the
+ // client dequeues a buffer from a
+ // 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.
+ Slot mSlots[BufferQueue::NUM_BUFFER_SLOTS];
+
+ // mAbandoned indicates that the BufferQueue will no longer be used to
+ // consume images buffers pushed to it using the ISurfaceTexture
+ // interface. It is initialized to false, and set to true in the abandon
+ // method. A BufferQueue that has been abandoned will return the NO_INIT
+ // error from all IConsumerBase methods capable of returning an error.
+ bool mAbandoned;
+
+ // mName is a string used to identify the ConsumerBase in log messages.
+ // It can be set by the setName method.
+ String8 mName;
+
+ // mFrameAvailableListener is the listener object that will be called when a
+ // new frame becomes available. If it is not NULL it will be called from
+ // queueBuffer.
+ sp<FrameAvailableListener> mFrameAvailableListener;
+
+ // The ConsumerBase has-a BufferQueue and is responsible for creating this object
+ // if none is supplied
+ sp<BufferQueue> mBufferQueue;
+
+ // mMutex is the mutex used to prevent concurrent access to the member
+ // variables of ConsumerBase objects. It must be locked whenever the
+ // member variables are accessed or when any of the *Locked methods are
+ // called.
+ //
+ // This mutex is intended to be locked by derived classes.
+ mutable Mutex mMutex;
+};
+
+// ----------------------------------------------------------------------------
+}; // namespace android
+
+#endif // ANDROID_GUI_CONSUMERBASE_H
diff --git a/include/gui/CpuConsumer.h b/include/gui/CpuConsumer.h
new file mode 100644
index 0000000..807a4b5
--- /dev/null
+++ b/include/gui/CpuConsumer.h
@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) 2012 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_CPUCONSUMER_H
+#define ANDROID_GUI_CPUCONSUMER_H
+
+#include <gui/ConsumerBase.h>
+
+#include <ui/GraphicBuffer.h>
+
+#include <utils/String8.h>
+#include <utils/Vector.h>
+#include <utils/threads.h>
+
+#define ANDROID_GRAPHICS_CPUCONSUMER_JNI_ID "mCpuConsumer"
+
+namespace android {
+
+/**
+ * CpuConsumer is a BufferQueue consumer endpoint that allows direct CPU
+ * access to the underlying gralloc buffers provided by BufferQueue. Multiple
+ * buffers may be acquired by it at once, to be used concurrently by the
+ * CpuConsumer owner. Sets gralloc usage flags to be software-read-only.
+ * This queue is synchronous by default.
+ */
+
+class CpuConsumer: public ConsumerBase
+{
+ public:
+ typedef ConsumerBase::FrameAvailableListener FrameAvailableListener;
+
+ struct LockedBuffer {
+ uint8_t *data;
+ uint32_t width;
+ uint32_t height;
+ PixelFormat format;
+ uint32_t stride;
+ Rect crop;
+ uint32_t transform;
+ uint32_t scalingMode;
+ int64_t timestamp;
+ uint64_t frameNumber;
+ };
+
+ // Create a new CPU consumer. The maxLockedBuffers parameter specifies
+ // how many buffers can be locked for user access at the same time.
+ CpuConsumer(uint32_t maxLockedBuffers);
+
+ virtual ~CpuConsumer();
+
+ // set the name of the CpuConsumer that will be used to identify it in
+ // log messages.
+ void setName(const String8& name);
+
+ // Gets the next graphics buffer from the producer and locks it for CPU use,
+ // filling out the passed-in locked buffer structure with the native pointer
+ // and metadata. Returns BAD_VALUE if no new buffer is available, and
+ // INVALID_OPERATION if the maximum number of buffers is already locked.
+ //
+ // Only a fixed number of buffers can be locked at a time, determined by the
+ // construction-time maxLockedBuffers parameter. If INVALID_OPERATION is
+ // returned by lockNextBuffer, then old buffers must be returned to the queue
+ // by calling unlockBuffer before more buffers can be acquired.
+ status_t lockNextBuffer(LockedBuffer *nativeBuffer);
+
+ // Returns a locked buffer to the queue, allowing it to be reused. Since
+ // only a fixed number of buffers may be locked at a time, old buffers must
+ // be released by calling unlockBuffer to ensure new buffers can be acquired by
+ // lockNextBuffer.
+ status_t unlockBuffer(const LockedBuffer &nativeBuffer);
+
+ sp<ISurfaceTexture> getProducerInterface() const { return getBufferQueue(); }
+
+ private:
+ // Maximum number of buffers that can be locked at a time
+ uint32_t mMaxLockedBuffers;
+
+ virtual void freeBufferLocked(int slotIndex);
+
+ // Array for tracking pointers passed to the consumer, matching the
+ // mSlots indexing
+ void *mBufferPointers[BufferQueue::NUM_BUFFER_SLOTS];
+ // Count of currently locked buffers
+ uint32_t mCurrentLockedBuffers;
+
+};
+
+} // namespace android
+
+#endif // ANDROID_GUI_CPUCONSUMER_H
diff --git a/include/gui/DisplayEventReceiver.h b/include/gui/DisplayEventReceiver.h
index e631cca..f8267bf 100644
--- a/include/gui/DisplayEventReceiver.h
+++ b/include/gui/DisplayEventReceiver.h
@@ -40,13 +40,15 @@ class IDisplayEventConnection;
class DisplayEventReceiver {
public:
enum {
- DISPLAY_EVENT_VSYNC = 'vsyn'
+ DISPLAY_EVENT_VSYNC = 'vsyn',
+ DISPLAY_EVENT_HOTPLUG = 'plug'
};
struct Event {
struct Header {
uint32_t type;
+ uint32_t id;
nsecs_t timestamp;
};
@@ -54,9 +56,14 @@ public:
uint32_t count;
};
+ struct Hotplug {
+ bool connected;
+ };
+
Header header;
union {
VSync vsync;
+ Hotplug hotplug;
};
};
diff --git a/include/gui/GLConsumer.h b/include/gui/GLConsumer.h
new file mode 100644
index 0000000..d53b04a
--- /dev/null
+++ b/include/gui/GLConsumer.h
@@ -0,0 +1,46 @@
+/*
+ * 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_CONSUMER_H
+#define ANDROID_GUI_CONSUMER_H
+
+#include <gui/BufferQueue.h>
+#include <gui/ConsumerBase.h>
+#include <gui/ISurfaceTexture.h>
+
+namespace android {
+
+class GLConsumer : public ConsumerBase {
+public:
+ GLConsumer(GLuint, bool = false, GLenum = 0, bool = false, const sp<BufferQueue>& = 0) :
+ ConsumerBase(0) {}
+ void incStrong(const void*) const {}
+ void decStrong(const void*) const {}
+ status_t updateTexImage() { return 0; }
+ void abandon() {}
+ sp<ISurfaceTexture> getBufferQueue() const { return 0; }
+ GLenum getCurrentTextureTarget() const { return 0; }
+ status_t setSynchronousMode(bool) { return 0; }
+ void getTransformMatrix(float[16]) {}
+ int64_t getTimestamp() {}
+ void setFrameAvailableListener(const wp<FrameAvailableListener>&) {}
+ sp<GraphicBuffer> getCurrentBuffer() const { return 0; }
+};
+
+}; // namespace android
+
+#endif // ANDROID_GUI_CONSUMER_H
+
diff --git a/include/gui/GuiConfig.h b/include/gui/GuiConfig.h
new file mode 100644
index 0000000..b020ed9
--- /dev/null
+++ b/include/gui/GuiConfig.h
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2012 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_CONFIG_H
+#define ANDROID_GUI_CONFIG_H
+
+#include <utils/String8.h>
+
+namespace android {
+
+// Append the libgui configuration details to configStr.
+void appendGuiConfigString(String8& configStr);
+
+}; // namespace android
+
+#endif /*ANDROID_GUI_CONFIG_H*/
diff --git a/include/gui/ISurfaceComposer.h b/include/gui/ISurfaceComposer.h
index 09e7771..6500ad5 100644
--- a/include/gui/ISurfaceComposer.h
+++ b/include/gui/ISurfaceComposer.h
@@ -34,70 +34,24 @@ namespace android {
// ----------------------------------------------------------------------------
class ComposerState;
+class DisplayState;
+class DisplayInfo;
class IDisplayEventConnection;
class IMemoryHeap;
-class ISurfaceComposer : public IInterface
-{
+class ISurfaceComposer: public IInterface {
public:
DECLARE_META_INTERFACE(SurfaceComposer);
- enum { // (keep in sync with Surface.java)
- eHidden = 0x00000004,
- eDestroyBackbuffer = 0x00000020,
- eSecure = 0x00000080,
- eNonPremultiplied = 0x00000100,
- eOpaque = 0x00000400,
- eProtectedByApp = 0x00000800,
- eProtectedByDRM = 0x00001000,
-
- eFXSurfaceNormal = 0x00000000,
- eFXSurfaceBlur = 0x00010000,
- eFXSurfaceDim = 0x00020000,
- eFXSurfaceScreenshot= 0x00030000,
- eFXSurfaceMask = 0x000F0000,
- };
-
- enum {
- ePositionChanged = 0x00000001,
- eLayerChanged = 0x00000002,
- eSizeChanged = 0x00000004,
- eAlphaChanged = 0x00000008,
- eMatrixChanged = 0x00000010,
- eTransparentRegionChanged = 0x00000020,
- eVisibilityChanged = 0x00000040,
- eFreezeTintChanged = 0x00000080,
- eCropChanged = 0x00000100,
- };
-
- enum {
- eLayerHidden = 0x01,
- eLayerFrozen = 0x02,
- eLayerDither = 0x04,
- eLayerFilter = 0x08,
- eLayerBlurFreeze = 0x10
- };
-
- enum {
- eOrientationDefault = 0,
- eOrientation90 = 1,
- eOrientation180 = 2,
- eOrientation270 = 3,
- eOrientationUnchanged = 4,
- eOrientationSwapMask = 0x01
- };
-
- enum {
- eSynchronous = 0x01,
- };
-
+ // flags for setTransactionState()
enum {
- eElectronBeamAnimationOn = 0x01,
- eElectronBeamAnimationOff = 0x10
+ eSynchronous = 0x01,
+ eAnimation = 0x02,
};
enum {
- eDisplayIdMain = 0
+ eDisplayIdMain = 0,
+ eDisplayIdHdmi = 1
};
/* create connection with surface flinger, requires
@@ -109,46 +63,57 @@ public:
*/
virtual sp<IGraphicBufferAlloc> createGraphicBufferAlloc() = 0;
- /* retrieve the control block */
- virtual sp<IMemoryHeap> getCblk() const = 0;
+ /* return an IDisplayEventConnection */
+ virtual sp<IDisplayEventConnection> createDisplayEventConnection() = 0;
+
+ /* create a display
+ * requires ACCESS_SURFACE_FLINGER permission.
+ */
+ virtual sp<IBinder> createDisplay(const String8& displayName,
+ bool secure) = 0;
+
+ /* get the token for the existing default displays. possible values
+ * for id are eDisplayIdMain and eDisplayIdHdmi.
+ */
+ virtual sp<IBinder> getBuiltInDisplay(int32_t id) = 0;
/* open/close transactions. requires ACCESS_SURFACE_FLINGER permission */
virtual void setTransactionState(const Vector<ComposerState>& state,
- int orientation, uint32_t flags) = 0;
+ const Vector<DisplayState>& displays, uint32_t flags) = 0;
/* signal that we're done booting.
* Requires ACCESS_SURFACE_FLINGER permission
*/
virtual void bootFinished() = 0;
+ /* verify that an ISurfaceTexture was created by SurfaceFlinger.
+ */
+ virtual bool authenticateSurfaceTexture(
+ const sp<ISurfaceTexture>& surface) const = 0;
+
/* Capture the specified screen. requires READ_FRAME_BUFFER permission
* This function will fail if there is a secure window on screen.
*/
- virtual status_t captureScreen(DisplayID dpy,
- sp<IMemoryHeap>* heap,
+ virtual status_t captureScreen(const sp<IBinder>& display, sp<IMemoryHeap>* heap,
uint32_t* width, uint32_t* height, PixelFormat* format,
uint32_t reqWidth, uint32_t reqHeight,
uint32_t minLayerZ, uint32_t maxLayerZ) = 0;
- /* triggers screen off animation */
- virtual status_t turnElectronBeamOff(int32_t mode) = 0;
- /* triggers screen on animation */
- virtual status_t turnElectronBeamOn(int32_t mode) = 0;
+ /* triggers screen off and waits for it to complete */
+ virtual void blank(const sp<IBinder>& display) = 0;
- /* verify that an ISurfaceTexture was created by SurfaceFlinger.
- */
- virtual bool authenticateSurfaceTexture(
- const sp<ISurfaceTexture>& surface) const = 0;
+ /* triggers screen on and waits for it to complete */
+ virtual void unblank(const sp<IBinder>& display) = 0;
- /* return an IDisplayEventConnection */
- virtual sp<IDisplayEventConnection> createDisplayEventConnection() = 0;
+ /* returns information about a display
+ * intended to be used to get information about built-in displays */
+ virtual status_t getDisplayInfo(const sp<IBinder>& display, DisplayInfo* info) = 0;
};
// ----------------------------------------------------------------------------
-class BnSurfaceComposer : public BnInterface<ISurfaceComposer>
-{
+class BnSurfaceComposer: public BnInterface<ISurfaceComposer> {
public:
enum {
// Note: BOOT_FINISHED must remain this value, it is called from
@@ -156,20 +121,20 @@ public:
BOOT_FINISHED = IBinder::FIRST_CALL_TRANSACTION,
CREATE_CONNECTION,
CREATE_GRAPHIC_BUFFER_ALLOC,
- GET_CBLK,
+ CREATE_DISPLAY_EVENT_CONNECTION,
+ CREATE_DISPLAY,
+ GET_BUILT_IN_DISPLAY,
SET_TRANSACTION_STATE,
- SET_ORIENTATION,
- CAPTURE_SCREEN,
- TURN_ELECTRON_BEAM_OFF,
- TURN_ELECTRON_BEAM_ON,
AUTHENTICATE_SURFACE,
- CREATE_DISPLAY_EVENT_CONNECTION,
+ CAPTURE_SCREEN,
+ BLANK,
+ UNBLANK,
+ GET_DISPLAY_INFO,
+ CONNECT_DISPLAY,
};
- virtual status_t onTransact( uint32_t code,
- const Parcel& data,
- Parcel* reply,
- uint32_t flags = 0);
+ virtual status_t onTransact(uint32_t code, const Parcel& data,
+ Parcel* reply, uint32_t flags = 0);
};
// ----------------------------------------------------------------------------
diff --git a/include/gui/ISurfaceComposerClient.h b/include/gui/ISurfaceComposerClient.h
index c793933..e256e33 100644
--- a/include/gui/ISurfaceComposerClient.h
+++ b/include/gui/ISurfaceComposerClient.h
@@ -30,11 +30,6 @@
#include <gui/ISurface.h>
namespace android {
-
-// ----------------------------------------------------------------------------
-
-typedef int32_t DisplayID;
-
// ----------------------------------------------------------------------------
class ISurfaceComposerClient : public IInterface
@@ -42,9 +37,26 @@ class ISurfaceComposerClient : public IInterface
public:
DECLARE_META_INTERFACE(SurfaceComposerClient);
+ // flags for createSurface()
+ enum { // (keep in sync with Surface.java)
+ eHidden = 0x00000004,
+ eDestroyBackbuffer = 0x00000020,
+ eSecure = 0x00000080,
+ eNonPremultiplied = 0x00000100,
+ eOpaque = 0x00000400,
+ eProtectedByApp = 0x00000800,
+ eProtectedByDRM = 0x00001000,
+
+ eFXSurfaceNormal = 0x00000000,
+ eFXSurfaceBlur = 0x00010000, // deprecated, same as Dim
+ eFXSurfaceDim = 0x00020000,
+ eFXSurfaceScreenshot= 0x00030000,
+ eFXSurfaceMask = 0x000F0000,
+ };
+
struct surface_data_t {
- int32_t token;
- int32_t identity;
+ int32_t token;
+ int32_t identity;
status_t readFromParcel(const Parcel& parcel);
status_t writeToParcel(Parcel* parcel) const;
};
@@ -52,29 +64,22 @@ public:
/*
* Requires ACCESS_SURFACE_FLINGER permission
*/
- virtual sp<ISurface> createSurface( surface_data_t* data,
- const String8& name,
- DisplayID display,
- uint32_t w,
- uint32_t h,
- PixelFormat format,
- uint32_t flags) = 0;
+ virtual sp<ISurface> createSurface(surface_data_t* data,
+ const String8& name, uint32_t w, uint32_t h,
+ PixelFormat format, uint32_t flags) = 0;
/*
* Requires ACCESS_SURFACE_FLINGER permission
*/
- virtual status_t destroySurface(SurfaceID sid) = 0;
+ virtual status_t destroySurface(SurfaceID sid) = 0;
};
// ----------------------------------------------------------------------------
-class BnSurfaceComposerClient : public BnInterface<ISurfaceComposerClient>
-{
+class BnSurfaceComposerClient: public BnInterface<ISurfaceComposerClient> {
public:
- virtual status_t onTransact( uint32_t code,
- const Parcel& data,
- Parcel* reply,
- uint32_t flags = 0);
+ virtual status_t onTransact(uint32_t code, const Parcel& data,
+ Parcel* reply, uint32_t flags = 0);
};
// ----------------------------------------------------------------------------
diff --git a/include/gui/ISurfaceTexture.h b/include/gui/ISurfaceTexture.h
index 1e33764..ae7c5c2 100644
--- a/include/gui/ISurfaceTexture.h
+++ b/include/gui/ISurfaceTexture.h
@@ -25,6 +25,7 @@
#include <binder/IInterface.h>
+#include <ui/Fence.h>
#include <ui/GraphicBuffer.h>
#include <ui/Rect.h>
@@ -38,9 +39,6 @@ class ISurfaceTexture : public IInterface
public:
DECLARE_META_INTERFACE(SurfaceTexture);
-protected:
- friend class SurfaceTextureClient;
-
enum {
BUFFER_NEEDS_REALLOCATION = 0x1,
RELEASE_ALL_BUFFERS = 0x2,
@@ -67,8 +65,13 @@ protected:
// in the contents of its associated buffer contents and call queueBuffer.
// If dequeueBuffer return BUFFER_NEEDS_REALLOCATION, the client is
// expected to call requestBuffer immediately.
- virtual status_t dequeueBuffer(int *slot, uint32_t w, uint32_t h,
- uint32_t format, uint32_t usage) = 0;
+ //
+ // The fence parameter will be updated to hold the fence associated with
+ // the buffer. The contents of the buffer must not be overwritten until the
+ // fence signals. If the fence is NULL, the buffer may be written
+ // immediately.
+ virtual status_t dequeueBuffer(int *slot, sp<Fence>& fence,
+ uint32_t w, uint32_t h, uint32_t format, uint32_t usage) = 0;
// queueBuffer indicates that the client has finished filling in the
// contents of the buffer associated with slot and transfers ownership of
@@ -83,24 +86,37 @@ protected:
// and height of the window and current transform applied to buffers,
// respectively.
- // QueueBufferInput must be a POD structure
- struct QueueBufferInput {
+ struct QueueBufferInput : public Flattenable {
+ inline QueueBufferInput(const Parcel& parcel);
inline QueueBufferInput(int64_t timestamp,
- const Rect& crop, int scalingMode, uint32_t transform)
+ const Rect& crop, int scalingMode, uint32_t transform,
+ sp<Fence> fence)
: timestamp(timestamp), crop(crop), scalingMode(scalingMode),
- transform(transform) { }
+ transform(transform), fence(fence) { }
inline void deflate(int64_t* outTimestamp, Rect* outCrop,
- int* outScalingMode, uint32_t* outTransform) const {
+ int* outScalingMode, uint32_t* outTransform,
+ sp<Fence>* outFence) const {
*outTimestamp = timestamp;
*outCrop = crop;
*outScalingMode = scalingMode;
*outTransform = transform;
+ *outFence = fence;
}
+
+ // Flattenable interface
+ virtual size_t getFlattenedSize() const;
+ virtual size_t getFdCount() const;
+ virtual status_t flatten(void* buffer, size_t size,
+ int fds[], size_t count) const;
+ virtual status_t unflatten(void const* buffer, size_t size,
+ int fds[], size_t count);
+
private:
int64_t timestamp;
Rect crop;
int scalingMode;
uint32_t transform;
+ sp<Fence> fence;
};
// QueueBufferOutput must be a POD structure
@@ -135,7 +151,7 @@ protected:
// cancelBuffer indicates that the client does not wish to fill in the
// buffer associated with slot and transfers ownership of the slot back to
// the server.
- virtual void cancelBuffer(int slot) = 0;
+ virtual void cancelBuffer(int slot, sp<Fence> fence) = 0;
// query retrieves some information for this surface
// 'what' tokens allowed are that of android_natives.h
diff --git a/include/gui/Sensor.h b/include/gui/Sensor.h
index e59757a..2af2307 100644
--- a/include/gui/Sensor.h
+++ b/include/gui/Sensor.h
@@ -41,7 +41,7 @@ class Parcel;
// ----------------------------------------------------------------------------
-class Sensor : public ASensor, public Flattenable
+class Sensor : public ASensor, public LightFlattenable<Sensor>
{
public:
enum {
@@ -54,7 +54,7 @@ public:
Sensor();
Sensor(struct sensor_t const* hwSensor);
- virtual ~Sensor();
+ ~Sensor();
const String8& getName() const;
const String8& getVendor() const;
@@ -68,13 +68,11 @@ public:
nsecs_t getMinDelayNs() const;
int32_t getVersion() const;
- // Flattenable interface
- virtual size_t getFlattenedSize() const;
- virtual size_t getFdCount() const;
- virtual status_t flatten(void* buffer, size_t size,
- int fds[], size_t count) const;
- virtual status_t unflatten(void const* buffer, size_t size,
- int fds[], size_t count);
+ // LightFlattenable protocol
+ inline bool isFixedSize() const { return false; }
+ size_t getSize() const;
+ status_t flatten(void* buffer) const;
+ status_t unflatten(void const* buffer, size_t size);
private:
String8 mName;
diff --git a/include/gui/Surface.h b/include/gui/Surface.h
index 50bdf71..3411f0a 100644
--- a/include/gui/Surface.h
+++ b/include/gui/Surface.h
@@ -60,18 +60,16 @@ public:
// release surface data from java
void clear();
+ status_t setLayerStack(int32_t layerStack);
status_t setLayer(int32_t layer);
status_t setPosition(int32_t x, int32_t y);
status_t setSize(uint32_t w, uint32_t h);
status_t hide();
- status_t show(int32_t layer = -1);
- status_t freeze();
- status_t unfreeze();
+ status_t show();
status_t setFlags(uint32_t flags, uint32_t mask);
status_t setTransparentRegionHint(const Region& transparent);
status_t setAlpha(float alpha=1.0f);
status_t setMatrix(float dsdx, float dtdx, float dsdy, float dtdy);
- status_t setFreezeTint(uint32_t tint);
status_t setCrop(const Rect& crop);
static status_t writeSurfaceToParcel(
@@ -123,6 +121,8 @@ public:
explicit Surface(const sp<ISurfaceTexture>& st);
+ Surface (sp<BufferQueue>&) {}
+
static status_t writeToParcel(const sp<Surface>& control, Parcel* parcel);
static sp<Surface> readFromParcel(const Parcel& data);
@@ -136,6 +136,7 @@ public:
// the lock/unlock APIs must be used from the same thread
status_t lock(SurfaceInfo* info, Region* dirty = NULL);
+ int lock(ANativeWindow_Buffer*, ARect*) { return 0; }
status_t unlockAndPost();
sp<IBinder> asBinder() const;
diff --git a/include/gui/SurfaceComposerClient.h b/include/gui/SurfaceComposerClient.h
index 295bc02..ae5d69a 100644
--- a/include/gui/SurfaceComposerClient.h
+++ b/include/gui/SurfaceComposerClient.h
@@ -39,6 +39,7 @@ class DisplayInfo;
class Composer;
class IMemoryHeap;
class ISurfaceComposerClient;
+class ISurfaceTexture;
class Region;
// ---------------------------------------------------------------------------
@@ -59,85 +60,87 @@ public:
// Forcibly remove connection before all references have gone away.
void dispose();
+ // callback when the composer is dies
+ status_t linkToComposerDeath(const sp<IBinder::DeathRecipient>& recipient,
+ void* cookie = NULL, uint32_t flags = 0);
+
+ // Get information about a display
+ static status_t getDisplayInfo(const sp<IBinder>& display, DisplayInfo* info);
+
+ /* triggers screen off and waits for it to complete */
+ static void blankDisplay(const sp<IBinder>& display);
+
+ /* triggers screen on and waits for it to complete */
+ static void unblankDisplay(const sp<IBinder>& display);
+
// ------------------------------------------------------------------------
// surface creation / destruction
//! Create a surface
sp<SurfaceControl> createSurface(
const String8& name,// name of the surface
- DisplayID display, // Display to create this surface on
uint32_t w, // width in pixel
uint32_t h, // height in pixel
PixelFormat format, // pixel-format desired
uint32_t flags = 0 // usage flags
);
- sp<SurfaceControl> createSurface(
- DisplayID display, // Display to create this surface on
- uint32_t w, // width in pixel
- uint32_t h, // height in pixel
- PixelFormat format, // pixel-format desired
- uint32_t flags = 0 // usage flags
- );
+ //! Create a display
+ static sp<IBinder> createDisplay(const String8& displayName, bool secure);
+ //! Get the token for the existing default displays.
+ //! Possible values for id are eDisplayIdMain and eDisplayIdHdmi.
+ static sp<IBinder> getBuiltInDisplay(int32_t id);
// ------------------------------------------------------------------------
// Composer parameters
// All composer parameters must be changed within a transaction
// several surfaces can be updated in one transaction, all changes are
// committed at once when the transaction is closed.
- // closeGlobalTransaction() usually requires an IPC with the server.
+ // closeGlobalTransaction() requires an IPC with the server.
//! Open a composer transaction on all active SurfaceComposerClients.
static void openGlobalTransaction();
-
+
//! Close a composer transaction on all active SurfaceComposerClients.
static void closeGlobalTransaction(bool synchronous = false);
-
- //! Freeze the specified display but not transactions.
- static status_t freezeDisplay(DisplayID dpy, uint32_t flags = 0);
-
- //! Resume updates on the specified display.
- static status_t unfreezeDisplay(DisplayID dpy, uint32_t flags = 0);
-
- //! Set the orientation of the given display
- static int setOrientation(DisplayID dpy, int orientation, uint32_t flags);
-
- // Query the number of displays
- static ssize_t getNumberOfDisplays();
-
- // Get information about a display
- static status_t getDisplayInfo(DisplayID dpy, DisplayInfo* info);
- static ssize_t getDisplayWidth(DisplayID dpy);
- static ssize_t getDisplayHeight(DisplayID dpy);
- static ssize_t getDisplayOrientation(DisplayID dpy);
-
- static inline sp<IBinder> getBuiltInDisplay(int32_t dpy) {
- return NULL;
- }
-
- static inline status_t getDisplayInfo(const sp<IBinder>& dpy, DisplayInfo* info) {
- return getDisplayInfo(0, info);
- }
- status_t linkToComposerDeath(const sp<IBinder::DeathRecipient>& recipient,
- void* cookie = NULL, uint32_t flags = 0);
+ //! Flag the currently open transaction as an animation transaction.
+ static void setAnimationTransaction();
status_t hide(SurfaceID id);
- status_t show(SurfaceID id, int32_t layer = -1);
- status_t freeze(SurfaceID id);
- status_t unfreeze(SurfaceID id);
+ status_t show(SurfaceID id);
status_t setFlags(SurfaceID id, uint32_t flags, uint32_t mask);
status_t setTransparentRegionHint(SurfaceID id, const Region& transparent);
status_t setLayer(SurfaceID id, int32_t layer);
status_t setAlpha(SurfaceID id, float alpha=1.0f);
- status_t setFreezeTint(SurfaceID id, uint32_t tint);
status_t setMatrix(SurfaceID id, float dsdx, float dtdx, float dsdy, float dtdy);
status_t setPosition(SurfaceID id, float x, float y);
status_t setSize(SurfaceID id, uint32_t w, uint32_t h);
status_t setCrop(SurfaceID id, const Rect& crop);
+ status_t setLayerStack(SurfaceID id, uint32_t layerStack);
status_t destroySurface(SurfaceID sid);
+ static void setDisplaySurface(const sp<IBinder>& token,
+ const sp<ISurfaceTexture>& surface);
+ static void setDisplayLayerStack(const sp<IBinder>& token,
+ uint32_t layerStack);
+
+ /* setDisplayProjection() defines the projection of layer stacks
+ * to a given display.
+ *
+ * - orientation defines the display's orientation.
+ * - layerStackRect defines which area of the window manager coordinate
+ * space will be used.
+ * - displayRect defines where on the display will layerStackRect be
+ * mapped to. displayRect is specified post-orientation, that is
+ * it uses the orientation seen by the end-user.
+ */
+ static void setDisplayProjection(const sp<IBinder>& token,
+ uint32_t orientation,
+ const Rect& layerStackRect,
+ const Rect& displayRect);
+
private:
virtual void onFirstRef();
Composer& getComposer();
@@ -160,9 +163,11 @@ public:
ScreenshotClient();
// frees the previous screenshot and capture a new one
- status_t update();
- status_t update(uint32_t reqWidth, uint32_t reqHeight);
- status_t update(uint32_t reqWidth, uint32_t reqHeight,
+ status_t update(const sp<IBinder>& display);
+ status_t update(const sp<IBinder>& display,
+ uint32_t reqWidth, uint32_t reqHeight);
+ status_t update(const sp<IBinder>& display,
+ uint32_t reqWidth, uint32_t reqHeight,
uint32_t minLayerZ, uint32_t maxLayerZ);
// release memory occupied by the screenshot
diff --git a/include/gui/SurfaceTexture.h b/include/gui/SurfaceTexture.h
index 2635e2f..7c519ae 100644
--- a/include/gui/SurfaceTexture.h
+++ b/include/gui/SurfaceTexture.h
@@ -24,6 +24,7 @@
#include <gui/ISurfaceTexture.h>
#include <gui/BufferQueue.h>
+#include <gui/ConsumerBase.h>
#include <ui/GraphicBuffer.h>
@@ -39,20 +40,9 @@ namespace android {
class String8;
-class SurfaceTexture : public virtual RefBase,
- protected BufferQueue::ConsumerListener {
+class SurfaceTexture : public ConsumerBase {
public:
- struct FrameAvailableListener : public virtual RefBase {
- // onFrameAvailable() is called each time an additional frame becomes
- // available for consumption. This means that frames that are queued
- // while in asynchronous mode only trigger the callback if no previous
- // frames are pending. Frames queued while in synchronous mode always
- // trigger the callback.
- //
- // This is called without any lock held and can be called concurrently
- // by multiple threads.
- virtual void onFrameAvailable() = 0;
- };
+ typedef ConsumerBase::FrameAvailableListener FrameAvailableListener;
// SurfaceTexture constructs a new SurfaceTexture object. tex indicates the
// name of the OpenGL ES texture to which images are to be streamed.
@@ -82,19 +72,28 @@ public:
GLenum texTarget = GL_TEXTURE_EXTERNAL_OES, bool useFenceSync = true,
const sp<BufferQueue> &bufferQueue = 0);
- virtual ~SurfaceTexture();
-
// updateTexImage sets the image contents of the target texture to that of
// the most recently queued buffer.
//
// This call may only be made while the OpenGL ES context to which the
// target texture belongs is bound to the calling thread.
+ //
+ // After calling this method the doGLFenceWait method must be called
+ // before issuing OpenGL ES commands that access the texture contents.
status_t updateTexImage();
- // setBufferCountServer set the buffer count. If the client has requested
- // a buffer count using setBufferCount, the server-buffer count will
- // take effect once the client sets the count back to zero.
- status_t setBufferCountServer(int bufferCount);
+ // setReleaseFence stores a fence file descriptor that will signal when the
+ // current buffer is no longer being read. This fence will be returned to
+ // the producer when the current buffer is released by updateTexImage().
+ // Multiple fences can be set for a given buffer; they will be merged into
+ // a single union fence. The SurfaceTexture will close the file descriptor
+ // when finished with it.
+ void setReleaseFence(int fenceFd);
+
+ // setDefaultMaxBufferCount sets the default limit on the maximum number
+ // of buffers that will be allocated at one time. The image producer may
+ // override the limit.
+ status_t setDefaultMaxBufferCount(int bufferCount);
// getTransformMatrix retrieves the 4x4 texture coordinate transform matrix
// associated with the texture image set by the most recent call to
@@ -124,16 +123,6 @@ public:
// documented by the source.
int64_t getTimestamp();
- // setFrameAvailableListener sets the listener object that will be notified
- // when a new frame becomes available.
- void setFrameAvailableListener(const sp<FrameAvailableListener>& listener);
-
- // getAllocator retrieves the binder object that must be referenced as long
- // as the GraphicBuffers dequeued from this SurfaceTexture are referenced.
- // Holding this binder reference prevents SurfaceFlinger from freeing the
- // buffers before the client is done with them.
- sp<IBinder> getAllocator();
-
// setDefaultBufferSize is used to set the size of buffers returned by
// requestBuffers when a with and height of zero is requested.
// A call to setDefaultBufferSize() may trigger requestBuffers() to
@@ -164,21 +153,20 @@ public:
// getCurrentScalingMode returns the scaling mode of the current buffer.
uint32_t getCurrentScalingMode() const;
+ // getCurrentFence returns the fence indicating when the current buffer is
+ // ready to be read from.
+ sp<Fence> getCurrentFence() const;
+
+ // doGLFenceWait inserts a wait command into the OpenGL ES command stream
+ // to ensure that it is safe for future OpenGL ES commands to access the
+ // current texture buffer. This must be called each time updateTexImage
+ // is called before issuing OpenGL ES commands that access the texture.
+ status_t doGLFenceWait() const;
+
// isSynchronousMode returns whether the SurfaceTexture is currently in
// synchronous mode.
bool isSynchronousMode() const;
- // abandon frees all the buffers and puts the SurfaceTexture into the
- // 'abandoned' state. Once put in this state the SurfaceTexture can never
- // leave it. When in the 'abandoned' state, all methods of the
- // ISurfaceTexture interface will fail with the NO_INIT error.
- //
- // Note that while calling this method causes all the buffers to be freed
- // from the perspective of the the SurfaceTexture, if there are additional
- // references on the buffers (e.g. if a buffer is referenced by a client or
- // by OpenGL ES as a texture) then those buffer will remain allocated.
- void abandon();
-
// set the name of the SurfaceTexture that will be used to identify it in
// log messages.
void setName(const String8& name);
@@ -192,7 +180,9 @@ public:
// getBufferQueue returns the BufferQueue object to which this
// SurfaceTexture is connected.
- sp<BufferQueue> getBufferQueue() const;
+ sp<BufferQueue> getBufferQueue() const {
+ return mBufferQueue;
+ }
// detachFromContext detaches the SurfaceTexture from the calling thread's
// current OpenGL ES context. This context must be the same as the context
@@ -221,17 +211,25 @@ public:
// current at the time of the last call to detachFromContext.
status_t attachToContext(GLuint tex);
- // dump our state in a String
- virtual void dump(String8& result) const;
- virtual void dump(String8& result, const char* prefix, char* buffer, size_t SIZE) const;
-
protected:
- // Implementation of the BufferQueue::ConsumerListener interface. These
- // calls are used to notify the SurfaceTexture of asynchronous events in the
- // BufferQueue.
- virtual void onFrameAvailable();
- virtual void onBuffersReleased();
+ // abandonLocked overrides the ConsumerBase method to clear
+ // mCurrentTextureBuf in addition to the ConsumerBase behavior.
+ virtual void abandonLocked();
+
+ // dumpLocked overrides the ConsumerBase method to dump SurfaceTexture-
+ // specific info in addition to the ConsumerBase behavior.
+ virtual void dumpLocked(String8& result, const char* prefix, char* buffer,
+ size_t size) const;
+
+ // acquireBufferLocked overrides the ConsumerBase method to update the
+ // mEglSlots array in addition to the ConsumerBase behavior.
+ virtual status_t acquireBufferLocked(BufferQueue::BufferItem *item);
+
+ // releaseBufferLocked overrides the ConsumerBase method to update the
+ // mEglSlots array in addition to the ConsumerBase.
+ virtual status_t releaseBufferLocked(int buf, EGLDisplay display,
+ EGLSyncKHR eglFence);
static bool isExternalFormat(uint32_t format);
@@ -248,7 +246,7 @@ private:
virtual ~BufferRejecter() { }
};
friend class Layer;
- status_t updateTexImage(BufferRejecter* rejecter);
+ status_t updateTexImage(BufferRejecter* rejecter, bool skipSync);
// createImage creates a new EGLImage from a GraphicBuffer.
EGLImageKHR createImage(EGLDisplay dpy,
@@ -259,12 +257,20 @@ private:
// slot and destroy the EGLImage in that slot. Otherwise it has no effect.
//
// This method must be called with mMutex locked.
- void freeBufferLocked(int slotIndex);
+ virtual void freeBufferLocked(int slotIndex);
- // computeCurrentTransformMatrix computes the transform matrix for the
+ // computeCurrentTransformMatrixLocked computes the transform matrix for the
// current texture. It uses mCurrentTransform and the current GraphicBuffer
// to compute this matrix and stores it in mCurrentTransformMatrix.
- void computeCurrentTransformMatrix();
+ // mCurrentTextureBuf must not be NULL.
+ void computeCurrentTransformMatrixLocked();
+
+ // doGLFenceWaitLocked inserts a wait command into the OpenGL ES command
+ // stream to ensure that it is safe for future OpenGL ES commands to
+ // access the current texture buffer. This must be called each time
+ // updateTexImage is called before issuing OpenGL ES commands that access
+ // the texture.
+ status_t doGLFenceWaitLocked() const;
// syncForReleaseLocked performs the synchronization needed to release the
// current slot from an OpenGL ES context. If needed it will set the
@@ -295,6 +301,9 @@ private:
// set to each time updateTexImage is called.
uint32_t mCurrentScalingMode;
+ // mCurrentFence is the fence received from BufferQueue in updateTexImage.
+ sp<Fence> mCurrentFence;
+
// mCurrentTransformMatrix is the transform matrix for the current texture.
// It gets computed by computeTransformMatrix each time updateTexImage is
// called.
@@ -336,11 +345,9 @@ private:
struct EGLSlot {
EGLSlot()
: mEglImage(EGL_NO_IMAGE_KHR),
- mFence(EGL_NO_SYNC_KHR) {
+ mEglFence(EGL_NO_SYNC_KHR) {
}
- sp<GraphicBuffer> mGraphicBuffer;
-
// mEglImage is the EGLImage created from mGraphicBuffer.
EGLImageKHR mEglImage;
@@ -348,7 +355,7 @@ private:
// associated with this buffer slot may be dequeued. It is initialized
// to EGL_NO_SYNC_KHR when the buffer is created and (optionally, based
// on a compile-time option) set to a new sync object in updateTexImage.
- EGLSyncKHR mFence;
+ EGLSyncKHR mEglFence;
};
// mEglDisplay is the EGLDisplay with which this SurfaceTexture is currently
@@ -370,23 +377,7 @@ private:
// 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.
- EGLSlot mEGLSlots[BufferQueue::NUM_BUFFER_SLOTS];
-
- // mAbandoned indicates that the BufferQueue will no longer be used to
- // consume images buffers pushed to it using the ISurfaceTexture interface.
- // It is initialized to false, and set to true in the abandon method. A
- // BufferQueue that has been abandoned will return the NO_INIT error from
- // all ISurfaceTexture methods capable of returning an error.
- bool mAbandoned;
-
- // mName is a string used to identify the SurfaceTexture in log messages.
- // It can be set by the setName method.
- String8 mName;
-
- // mFrameAvailableListener is the listener object that will be called when a
- // new frame becomes available. If it is not NULL it will be called from
- // queueBuffer.
- sp<FrameAvailableListener> mFrameAvailableListener;
+ EGLSlot mEglSlots[BufferQueue::NUM_BUFFER_SLOTS];
// mCurrentTexture is the buffer slot index of the buffer that is currently
// bound to the OpenGL texture. It is initialized to INVALID_BUFFER_SLOT,
@@ -396,22 +387,13 @@ private:
// reset mCurrentTexture to INVALID_BUFFER_SLOT.
int mCurrentTexture;
- // The SurfaceTexture has-a BufferQueue and is responsible for creating this object
- // if none is supplied
- sp<BufferQueue> mBufferQueue;
-
- // mAttached indicates whether the SurfaceTexture is currently attached to
+ // mAttached indicates whether the ConsumerBase is currently attached to
// an OpenGL ES context. For legacy reasons, this is initialized to true,
- // indicating that the SurfaceTexture is considered to be attached to
+ // indicating that the ConsumerBase is considered to be attached to
// whatever context is current at the time of the first updateTexImage call.
// It is set to false by detachFromContext, and then set to true again by
// attachToContext.
bool mAttached;
-
- // mMutex is the mutex used to prevent concurrent access to the member
- // variables of SurfaceTexture objects. It must be locked whenever the
- // member variables are accessed.
- mutable Mutex mMutex;
};
// ----------------------------------------------------------------------------
diff --git a/include/gui/SurfaceTextureClient.h b/include/gui/SurfaceTextureClient.h
index 8fa85b6..50fd1ba 100644
--- a/include/gui/SurfaceTextureClient.h
+++ b/include/gui/SurfaceTextureClient.h
@@ -61,14 +61,25 @@ private:
void init();
// ANativeWindow hooks
- static int hook_cancelBuffer(ANativeWindow* window, ANativeWindowBuffer* buffer);
- static int hook_dequeueBuffer(ANativeWindow* window, ANativeWindowBuffer** buffer);
- static int hook_lockBuffer(ANativeWindow* window, ANativeWindowBuffer* buffer);
+ static int hook_cancelBuffer(ANativeWindow* window,
+ ANativeWindowBuffer* buffer, int fenceFd);
+ static int hook_dequeueBuffer(ANativeWindow* window,
+ ANativeWindowBuffer** buffer, int* fenceFd);
static int hook_perform(ANativeWindow* window, int operation, ...);
static int hook_query(const ANativeWindow* window, int what, int* value);
- static int hook_queueBuffer(ANativeWindow* window, ANativeWindowBuffer* buffer);
+ static int hook_queueBuffer(ANativeWindow* window,
+ ANativeWindowBuffer* buffer, int fenceFd);
static int hook_setSwapInterval(ANativeWindow* window, int interval);
+ 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);
+
int dispatchConnect(va_list args);
int dispatchDisconnect(va_list args);
int dispatchSetBufferCount(va_list args);
@@ -86,14 +97,15 @@ private:
int dispatchUnlockAndPost(va_list args);
protected:
- virtual int cancelBuffer(ANativeWindowBuffer* buffer);
- virtual int dequeueBuffer(ANativeWindowBuffer** buffer);
- virtual int lockBuffer(ANativeWindowBuffer* buffer);
+ virtual int dequeueBuffer(ANativeWindowBuffer** buffer, int* fenceFd);
+ virtual int cancelBuffer(ANativeWindowBuffer* buffer, int fenceFd);
+ virtual int queueBuffer(ANativeWindowBuffer* buffer, int fenceFd);
virtual int perform(int operation, va_list args);
virtual int query(int what, int* value) const;
- virtual int queueBuffer(ANativeWindowBuffer* buffer);
virtual int setSwapInterval(int interval);
+ virtual int lockBuffer_DEPRECATED(ANativeWindowBuffer* buffer);
+
virtual int connect(int api);
virtual int disconnect(int api);
virtual int setBufferCount(int bufferCount);