summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/binder/IPCThreadState.h2
-rw-r--r--include/binder/Parcel.h49
-rw-r--r--include/gui/BufferItemConsumer.h91
-rw-r--r--include/gui/BufferQueue.h90
-rw-r--r--include/gui/ConsumerBase.h77
-rw-r--r--include/gui/CpuConsumer.h51
-rw-r--r--include/gui/ISurfaceComposer.h16
-rw-r--r--include/gui/ISurfaceComposerClient.h7
-rw-r--r--include/gui/Sensor.h16
-rw-r--r--include/gui/Surface.h3
-rw-r--r--include/gui/SurfaceComposerClient.h35
-rw-r--r--include/gui/SurfaceTexture.h123
-rw-r--r--include/media/hardware/HDCPAPI.h85
-rw-r--r--include/private/gui/LayerState.h8
-rw-r--r--include/ui/Fence.h3
-rw-r--r--include/ui/Point.h3
-rw-r--r--include/ui/Rect.h3
-rw-r--r--include/ui/Region.h48
-rw-r--r--include/utils/Flattenable.h72
-rw-r--r--include/utils/Log.h38
-rw-r--r--include/utils/SharedBuffer.h27
-rw-r--r--include/utils/Singleton.h4
-rw-r--r--include/utils/SortedVector.h11
-rw-r--r--include/utils/Vector.h11
24 files changed, 556 insertions, 317 deletions
diff --git a/include/binder/IPCThreadState.h b/include/binder/IPCThreadState.h
index 691ba2f..3378d97 100644
--- a/include/binder/IPCThreadState.h
+++ b/include/binder/IPCThreadState.h
@@ -41,7 +41,6 @@ public:
int getCallingPid();
int getCallingUid();
- int getOrigCallingUid();
void setStrictModePolicy(int32_t policy);
int32_t getStrictModePolicy() const;
@@ -117,7 +116,6 @@ private:
status_t mLastError;
pid_t mCallingPid;
uid_t mCallingUid;
- uid_t mOrigCallingUid;
int32_t mStrictModePolicy;
int32_t mLastTransactionBinderFlags;
};
diff --git a/include/binder/Parcel.h b/include/binder/Parcel.h
index 33b2f00..3ff95d2 100644
--- a/include/binder/Parcel.h
+++ b/include/binder/Parcel.h
@@ -22,10 +22,12 @@
#include <utils/RefBase.h>
#include <utils/String16.h>
#include <utils/Vector.h>
+#include <utils/Flattenable.h>
// ---------------------------------------------------------------------------
namespace android {
+template <typename T> class LightFlattenable;
class Flattenable;
class IBinder;
class IPCThreadState;
@@ -102,6 +104,10 @@ public:
status_t writeWeakBinder(const wp<IBinder>& val);
status_t write(const Flattenable& val);
+ template<typename T>
+ status_t write(const LightFlattenable<T>& val);
+
+
// Place a native_handle into the parcel (the native_handle's file-
// descriptors are dup'ed, so it is safe to delete the native_handle
// when this function returns).
@@ -153,6 +159,9 @@ public:
wp<IBinder> readWeakBinder() const;
status_t read(Flattenable& val) const;
+ template<typename T>
+ status_t read(LightFlattenable<T>& val) const;
+
// Like Parcel.java's readExceptionCode(). Reads the first int32
// off of a Parcel's header, returning 0 or the negative error
// code on exceptions, but also deals with skipping over rich
@@ -267,6 +276,46 @@ public:
// ---------------------------------------------------------------------------
+template<typename T>
+status_t Parcel::write(const LightFlattenable<T>& val) {
+ size_t size(val.getSize());
+ if (!val.isFixedSize()) {
+ status_t err = writeInt32(size);
+ if (err != NO_ERROR) {
+ return err;
+ }
+ }
+ if (size) {
+ void* buffer = writeInplace(size);
+ return buffer == NULL ? NO_MEMORY :
+ val.flatten(buffer);
+ }
+ return NO_ERROR;
+}
+
+template<typename T>
+status_t Parcel::read(LightFlattenable<T>& val) const {
+ size_t size;
+ if (val.isFixedSize()) {
+ size = val.getSize();
+ } else {
+ int32_t s;
+ status_t err = readInt32(&s);
+ if (err != NO_ERROR) {
+ return err;
+ }
+ size = s;
+ }
+ if (size) {
+ void const* buffer = readInplace(size);
+ return buffer == NULL ? NO_MEMORY :
+ val.unflatten(buffer, size);
+ }
+ return NO_ERROR;
+}
+
+// ---------------------------------------------------------------------------
+
inline TextOutput& operator<<(TextOutput& to, const Parcel& parcel)
{
parcel.print(to);
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 85d8fb6..0a95bb3 100644
--- a/include/gui/BufferQueue.h
+++ b/include/gui/BufferQueue.h
@@ -92,13 +92,11 @@ 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 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,
- int bufferCount = MIN_UNDEQUEUED_BUFFERS,
const sp<IGraphicBufferAlloc>& allocator = NULL);
virtual ~BufferQueue();
@@ -252,10 +250,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.
@@ -298,7 +301,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 {
@@ -422,30 +449,27 @@ private:
// in requestBuffers() if a width and height of zero is specified.
uint32_t mDefaultHeight;
- // 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
index d2bf0f6..a0ddca8 100644
--- a/include/gui/ConsumerBase.h
+++ b/include/gui/ConsumerBase.h
@@ -86,42 +86,25 @@ private:
protected:
- // TODO: Fix this comment
- // ConsumerBase constructs a new ConsumerBase object. tex indicates the
- // name of the OpenGL ES texture to which images are to be streamed.
- // allowSynchronousMode specifies whether or not synchronous mode can be
- // enabled. texTarget specifies the OpenGL ES texture target to which the
- // texture will be bound in updateTexImage. useFenceSync specifies whether
- // fences should be used to synchronize access to buffers if that behavior
- // is enabled at compile-time. A custom bufferQueue can be specified
- // if behavior for queue/dequeue/connect etc needs to be customized.
- // Otherwise a default BufferQueue will be created and used.
- //
- // For legacy reasons, the ConsumerBase is created in a state where it is
- // considered attached to an OpenGL ES context for the purposes of the
- // attachToContext and detachFromContext methods. However, despite being
- // considered "attached" to a context, the specific OpenGL ES context
- // doesn't get latched until the first call to updateTexImage. After that
- // point, all calls to updateTexImage must be made with the same OpenGL ES
- // context current.
- //
- // A ConsumerBase may be detached from one OpenGL ES context and then
- // attached to a different context using the detachFromContext and
- // attachToContext methods, respectively. The intention of these methods is
- // purely to allow a ConsumerBase to be transferred from one consumer
- // context to another. If such a transfer is not needed there is no
- // requirement that either of these methods be called.
+ // 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.
+ // 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 and destroy the EGLImage in that slot. Otherwise it has no effect.
+ // 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);
@@ -131,18 +114,43 @@ protected:
// 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;
+ 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::acquireBufferLocked.
virtual status_t releaseBufferLocked(int buf, EGLDisplay display,
EGLSyncKHR eglFence, const sp<Fence>& fence);
@@ -189,17 +197,12 @@ protected:
// if none is supplied
sp<BufferQueue> mBufferQueue;
- // mAttached indicates whether the ConsumerBase is currently attached to
- // an OpenGL ES context. For legacy reasons, this is initialized to true,
- // 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 ConsumerBase objects. It must be locked whenever the
- // member variables are accessed.
+ // 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;
};
diff --git a/include/gui/CpuConsumer.h b/include/gui/CpuConsumer.h
index a50a1de..807a4b5 100644
--- a/include/gui/CpuConsumer.h
+++ b/include/gui/CpuConsumer.h
@@ -17,7 +17,7 @@
#ifndef ANDROID_GUI_CPUCONSUMER_H
#define ANDROID_GUI_CPUCONSUMER_H
-#include <gui/BufferQueue.h>
+#include <gui/ConsumerBase.h>
#include <ui/GraphicBuffer.h>
@@ -37,19 +37,10 @@ namespace android {
* This queue is synchronous by default.
*/
-class CpuConsumer: public virtual RefBase,
- protected BufferQueue::ConsumerListener
+class CpuConsumer: public ConsumerBase
{
public:
- struct FrameAvailableListener : public virtual RefBase {
- // onFrameAvailable() is called each time an additional frame becomes
- // available for consumption. A new frame queued will always trigger the
- // callback, whether the queue is empty or not.
- //
- // This is called without any lock held and can be called concurrently
- // by multiple threads.
- virtual void onFrameAvailable() = 0;
- };
+ typedef ConsumerBase::FrameAvailableListener FrameAvailableListener;
struct LockedBuffer {
uint8_t *data;
@@ -91,50 +82,20 @@ class CpuConsumer: public virtual RefBase,
// lockNextBuffer.
status_t unlockBuffer(const LockedBuffer &nativeBuffer);
- // setFrameAvailableListener sets the listener object that will be notified
- // when a new frame becomes available.
- void setFrameAvailableListener(const sp<FrameAvailableListener>& listener);
-
- sp<ISurfaceTexture> getProducerInterface() const { return mBufferQueue; }
- protected:
-
- // Implementation of the BufferQueue::ConsumerListener interface. These
- // calls are used to notify the CpuConsumer of asynchronous events in the
- // BufferQueue.
- virtual void onFrameAvailable();
- virtual void onBuffersReleased();
+ sp<ISurfaceTexture> getProducerInterface() const { return getBufferQueue(); }
private:
- // Free local buffer state
- status_t freeBufferLocked(int buf);
-
// Maximum number of buffers that can be locked at a time
uint32_t mMaxLockedBuffers;
- // 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;
-
- // Underlying buffer queue
- sp<BufferQueue> mBufferQueue;
+ virtual void freeBufferLocked(int slotIndex);
- // Array for caching buffers from the buffer queue
- sp<GraphicBuffer> mBufferSlot[BufferQueue::NUM_BUFFER_SLOTS];
// Array for tracking pointers passed to the consumer, matching the
- // mBufferSlot indexing
+ // mSlots indexing
void *mBufferPointers[BufferQueue::NUM_BUFFER_SLOTS];
// Count of currently locked buffers
uint32_t mCurrentLockedBuffers;
- // mMutex is the mutex used to prevent concurrent access to the member
- // variables of CpuConsumer objects. It must be locked whenever the
- // member variables are accessed.
- mutable Mutex mMutex;
};
} // namespace android
diff --git a/include/gui/ISurfaceComposer.h b/include/gui/ISurfaceComposer.h
index 9ab35b1..f4af705 100644
--- a/include/gui/ISurfaceComposer.h
+++ b/include/gui/ISurfaceComposer.h
@@ -65,7 +65,7 @@ public:
/* return an IDisplayEventConnection */
virtual sp<IDisplayEventConnection> createDisplayEventConnection() = 0;
- /* create a display with given id.
+ /* create a display
* requires ACCESS_SURFACE_FLINGER permission.
*/
virtual sp<IBinder> createDisplay() = 0;
@@ -92,10 +92,10 @@ public:
/* 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;
+ uint32_t reqWidth, uint32_t reqHeight,
+ uint32_t minLayerZ, uint32_t maxLayerZ) = 0;
/* triggers screen off and waits for it to complete */
@@ -104,12 +104,12 @@ public:
/* triggers screen on and waits for it to complete */
virtual void unblank() = 0;
- /* returns information about a physical screen. This is intended to be
- * used by low-level native tests */
- virtual status_t getDisplayInfo(DisplayID dpy, DisplayInfo* info) = 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;
/* connects to an external display */
- virtual void connectDisplay(const sp<ISurfaceTexture> display) = 0;
+ virtual void connectDisplay(const sp<ISurfaceTexture>& display) = 0;
};
// ----------------------------------------------------------------------------
diff --git a/include/gui/ISurfaceComposerClient.h b/include/gui/ISurfaceComposerClient.h
index 259c1df..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
@@ -70,7 +65,7 @@ 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,
+ const String8& name, uint32_t w, uint32_t h,
PixelFormat format, uint32_t flags) = 0;
/*
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 7b8873a..2288fe7 100644
--- a/include/gui/Surface.h
+++ b/include/gui/Surface.h
@@ -60,11 +60,12 @@ 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 show();
status_t setFlags(uint32_t flags, uint32_t mask);
status_t setTransparentRegionHint(const Region& transparent);
status_t setAlpha(float alpha=1.0f);
diff --git a/include/gui/SurfaceComposerClient.h b/include/gui/SurfaceComposerClient.h
index 5776038..a143d81 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;
// ---------------------------------------------------------------------------
@@ -64,7 +65,12 @@ public:
void* cookie = NULL, uint32_t flags = 0);
// Get information about a display
- static status_t getDisplayInfo(DisplayID dpy, DisplayInfo* info);
+ static status_t getDisplayInfo(const sp<IBinder>& display, DisplayInfo* info);
+
+ // TODO: Remove me. Do not use.
+ // This is a compatibility shim for one product whose drivers are depending on
+ // this legacy function (when they shouldn't).
+ static status_t getDisplayInfo(int32_t displayId, DisplayInfo* info);
// ------------------------------------------------------------------------
// surface creation / destruction
@@ -72,23 +78,19 @@ public:
//! 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();
+ //! 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
@@ -102,11 +104,8 @@ public:
//! Close a composer transaction on all active SurfaceComposerClients.
static void closeGlobalTransaction(bool synchronous = false);
- //! Set the orientation of the given display
- static int setOrientation(DisplayID dpy, int orientation, uint32_t flags);
-
status_t hide(SurfaceID id);
- status_t show(SurfaceID id, int32_t layer = -1);
+ 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);
@@ -150,9 +149,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 66c390a..2570cd9 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,8 +72,6 @@ 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.
//
@@ -99,10 +87,10 @@ public:
// when finished with it.
void setReleaseFence(int fenceFd);
- // 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);
+ // 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
@@ -132,16 +120,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
@@ -180,17 +158,6 @@ public:
// 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);
@@ -204,7 +171,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
@@ -233,17 +202,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, const sp<Fence>& fence);
static bool isExternalFormat(uint32_t format);
@@ -271,7 +248,7 @@ 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
// current texture. It uses mCurrentTransform and the current GraphicBuffer
@@ -351,11 +328,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;
@@ -363,14 +338,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;
-
- // mReleaseFence 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> mReleaseFence;
+ EGLSyncKHR mEglFence;
};
// mEglDisplay is the EGLDisplay with which this SurfaceTexture is currently
@@ -392,23 +360,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,
@@ -418,22 +370,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/media/hardware/HDCPAPI.h b/include/media/hardware/HDCPAPI.h
new file mode 100644
index 0000000..bb91540
--- /dev/null
+++ b/include/media/hardware/HDCPAPI.h
@@ -0,0 +1,85 @@
+/*
+ * 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 HDCP_API_H_
+
+#define HDCP_API_H_
+
+#include <utils/Errors.h>
+
+namespace android {
+
+struct HDCPModule {
+ typedef void (*ObserverFunc)(int msg, int ext1, int ext2);
+
+ // The msg argument in calls to the observer notification function.
+ enum {
+ // Sent in response to a call to "HDCPModule::initAsync" once
+ // initialization has either been successfully completed,
+ // i.e. the HDCP session is now fully setup (AKE, Locality Check,
+ // SKE and any authentication with repeaters completed) or failed.
+ // ext1 should be a suitable error code (status_t), ext2 is
+ // unused.
+ HDCP_INITIALIZATION_COMPLETE,
+
+ // Sent upon completion of a call to "HDCPModule::shutdownAsync".
+ // ext1 should be a suitable error code, ext2 is unused.
+ HDCP_SHUTDOWN_COMPLETE,
+ };
+
+ // Module can call the notification function to signal completion/failure
+ // of asynchronous operations (such as initialization) or out of band
+ // events.
+ HDCPModule(ObserverFunc observerNotify);
+
+ virtual ~HDCPModule();
+
+ // Request to setup an HDCP session with the specified host listening
+ // on the specified port.
+ virtual status_t initAsync(const char *host, unsigned port) = 0;
+
+ // Request to shutdown the active HDCP session.
+ virtual status_t shutdownAsync() = 0;
+
+ // Encrypt a data according to the HDCP spec. The data is to be
+ // encrypted in-place, only size bytes of data should be read/write,
+ // even if the size is not a multiple of 128 bit (16 bytes).
+ // This operation is to be synchronous, i.e. this call does not return
+ // until outData contains size bytes of encrypted data.
+ // streamCTR will be assigned by the caller (to 0 for the first PES stream,
+ // 1 for the second and so on)
+ // inputCTR will be maintained by the callee for each PES stream.
+ virtual status_t encrypt(
+ const void *inData, size_t size, uint32_t streamCTR,
+ uint64_t *outInputCTR, void *outData) = 0;
+
+private:
+ HDCPModule(const HDCPModule &);
+ HDCPModule &operator=(const HDCPModule &);
+};
+
+} // namespace android
+
+// A shared library exporting the following method should be included to
+// support HDCP functionality. The shared library must be called
+// "libstagefright_hdcp.so", it will be dynamically loaded into the
+// mediaserver process.
+extern "C" {
+ extern android::HDCPModule *createHDCPModule();
+}
+
+#endif // HDCP_API_H_
+
diff --git a/include/private/gui/LayerState.h b/include/private/gui/LayerState.h
index 9765e28..65d9eb3 100644
--- a/include/private/gui/LayerState.h
+++ b/include/private/gui/LayerState.h
@@ -107,9 +107,11 @@ struct DisplayState {
};
enum {
- eSurfaceChanged = 0x1,
- eLayerStackChanged = 0x2,
- eTransformChanged = 0x4
+ eSurfaceChanged = 0x01,
+ eLayerStackChanged = 0x02,
+ eOrientationChanged = 0x04,
+ eViewportChanged = 0x08,
+ eFrameChanged = 0x10
};
uint32_t what;
diff --git a/include/ui/Fence.h b/include/ui/Fence.h
index 17cb018..b516a22 100644
--- a/include/ui/Fence.h
+++ b/include/ui/Fence.h
@@ -18,7 +18,6 @@
#define ANDROID_FENCE_H
#include <stdint.h>
-#include <limits.h>
#include <sys/types.h>
#include <ui/ANativeObjectBase.h>
@@ -65,7 +64,7 @@ public:
// TIMEOUT_NEVER may be passed to the wait method to indicate that it
// should wait indefinitely for the fence to signal.
- enum { TIMEOUT_NEVER = UINT_MAX };
+ enum { TIMEOUT_NEVER = -1 };
// merge combines two Fence objects, creating a new Fence object that
// becomes signaled when both f1 and f2 are signaled (even if f1 or f2 is
diff --git a/include/ui/Point.h b/include/ui/Point.h
index 1653120..1d7f64d 100644
--- a/include/ui/Point.h
+++ b/include/ui/Point.h
@@ -17,11 +17,12 @@
#ifndef ANDROID_UI_POINT
#define ANDROID_UI_POINT
+#include <utils/Flattenable.h>
#include <utils/TypeHelpers.h>
namespace android {
-class Point
+class Point : public LightFlattenablePod<Point>
{
public:
int x;
diff --git a/include/ui/Rect.h b/include/ui/Rect.h
index c2c2675..47d37b6 100644
--- a/include/ui/Rect.h
+++ b/include/ui/Rect.h
@@ -17,6 +17,7 @@
#ifndef ANDROID_UI_RECT
#define ANDROID_UI_RECT
+#include <utils/Flattenable.h>
#include <utils/TypeHelpers.h>
#include <ui/Point.h>
@@ -24,7 +25,7 @@
namespace android {
-class Rect : public ARect
+class Rect : public ARect, public LightFlattenablePod<Rect>
{
public:
typedef ARect::value_type value_type;
diff --git a/include/ui/Region.h b/include/ui/Region.h
index f242f18..0049fde 100644
--- a/include/ui/Region.h
+++ b/include/ui/Region.h
@@ -23,28 +23,29 @@
#include <utils/Vector.h>
#include <ui/Rect.h>
+#include <utils/Flattenable.h>
namespace android {
// ---------------------------------------------------------------------------
+class SharedBuffer;
class String8;
// ---------------------------------------------------------------------------
-class Region
+class Region : public LightFlattenable<Region>
{
public:
Region();
Region(const Region& rhs);
explicit Region(const Rect& rhs);
- explicit Region(const void* buffer);
~Region();
Region& operator = (const Region& rhs);
- inline bool isEmpty() const { return mBounds.isEmpty(); }
- inline bool isRect() const { return mStorage.isEmpty(); }
+ inline bool isEmpty() const { return getBounds().isEmpty(); }
+ inline bool isRect() const { return mStorage.size() == 1; }
- inline Rect getBounds() const { return mBounds; }
+ inline Rect getBounds() const { return mStorage[mStorage.size() - 1]; }
inline Rect bounds() const { return getBounds(); }
// the region becomes its bounds
@@ -106,28 +107,32 @@ public:
/* various ways to access the rectangle list */
+
+ // STL-like iterators
typedef Rect const* const_iterator;
-
- const_iterator begin() const;
- const_iterator end() const;
+ const_iterator begin() const;
+ const_iterator end() const;
- /* no user serviceable parts here... */
-
- size_t getRects(Vector<Rect>& rectList) const;
- Rect const* getArray(size_t* count) const;
+ // returns an array of rect which has the same life-time has this
+ // Region object.
+ Rect const* getArray(size_t* count) const;
+ // returns a SharedBuffer as well as the number of rects.
+ // ownership is transfered to the caller.
+ // the caller must call SharedBuffer::release() to free the memory.
+ SharedBuffer const* getSharedBuffer(size_t* count) const;
+
+ /* no user serviceable parts here... */
// add a rectangle to the internal list. This rectangle must
// be sorted in Y and X and must not make the region invalid.
void addRectUnchecked(int l, int t, int r, int b);
- // flatten/unflatten a region to/from a raw buffer
- ssize_t write(void* buffer, size_t size) const;
- static ssize_t writeEmpty(void* buffer, size_t size);
-
- ssize_t read(const void* buffer);
- static bool isEmpty(void* buffer);
+ 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);
void dump(String8& out, const char* what, uint32_t flags=0) const;
void dump(const char* what, uint32_t flags=0) const;
@@ -158,8 +163,11 @@ private:
static bool validate(const Region& reg, const char* name);
- Rect mBounds;
- Vector<Rect> mStorage;
+ // mStorage is a (manually) sorted array of Rects describing the region
+ // with an extra Rect as the last element which is set to the
+ // bounds of the region. However, if the region is
+ // a simple Rect then mStorage contains only that rect.
+ Vector<Rect> mStorage;
};
diff --git a/include/utils/Flattenable.h b/include/utils/Flattenable.h
index 852be3b..e40d289 100644
--- a/include/utils/Flattenable.h
+++ b/include/utils/Flattenable.h
@@ -24,6 +24,11 @@
namespace android {
+/*
+ * The Flattenable interface allows an object to serialize itself out
+ * to a byte-buffer and an array of file descriptors.
+ */
+
class Flattenable
{
public:
@@ -56,6 +61,73 @@ protected:
};
+/*
+ * LightFlattenable is a protocol allowing object to serialize themselves out
+ * to a byte-buffer.
+ *
+ * LightFlattenable objects must implement this protocol.
+ *
+ * LightFlattenable doesn't require the object to be virtual.
+ */
+template <typename T>
+class LightFlattenable {
+public:
+ // returns whether this object always flatten into the same size.
+ // for efficiency, this should always be inline.
+ inline bool isFixedSize() const;
+
+ // returns size in bytes of the flattened object. must be a constant.
+ inline size_t getSize() const;
+
+ // flattens the object into buffer.
+ inline status_t flatten(void* buffer) const;
+
+ // unflattens the object from buffer of given size.
+ inline status_t unflatten(void const* buffer, size_t size);
+};
+
+template <typename T>
+inline bool LightFlattenable<T>::isFixedSize() const {
+ return static_cast<T const*>(this)->T::isFixedSize();
+}
+template <typename T>
+inline size_t LightFlattenable<T>::getSize() const {
+ return static_cast<T const*>(this)->T::getSize();
+}
+template <typename T>
+inline status_t LightFlattenable<T>::flatten(void* buffer) const {
+ return static_cast<T const*>(this)->T::flatten(buffer);
+}
+template <typename T>
+inline status_t LightFlattenable<T>::unflatten(void const* buffer, size_t size) {
+ return static_cast<T*>(this)->T::unflatten(buffer, size);
+}
+
+/*
+ * LightFlattenablePod is an implementation of the LightFlattenable protocol
+ * for POD (plain-old-data) objects.
+ */
+template <typename T>
+class LightFlattenablePod : public LightFlattenable<T> {
+public:
+ inline bool isFixedSize() const {
+ return true;
+ }
+
+ inline size_t getSize() const {
+ return sizeof(T);
+ }
+ inline status_t flatten(void* buffer) const {
+ *reinterpret_cast<T*>(buffer) = *static_cast<T const*>(this);
+ return NO_ERROR;
+ }
+ inline status_t unflatten(void const* buffer, size_t) {
+ *static_cast<T*>(this) = *reinterpret_cast<T const*>(buffer);
+ return NO_ERROR;
+ }
+};
+
+
}; // namespace android
diff --git a/include/utils/Log.h b/include/utils/Log.h
index 3c6cc8b..98c441c 100644
--- a/include/utils/Log.h
+++ b/include/utils/Log.h
@@ -29,5 +29,43 @@
#define _LIBS_UTILS_LOG_H
#include <cutils/log.h>
+#include <sys/types.h>
+
+#ifdef __cplusplus
+
+namespace android {
+
+/*
+ * A very simple utility that yells in the log when an operation takes too long.
+ */
+class LogIfSlow {
+public:
+ LogIfSlow(const char* tag, android_LogPriority priority,
+ int timeoutMillis, const char* message);
+ ~LogIfSlow();
+
+private:
+ const char* const mTag;
+ const android_LogPriority mPriority;
+ const int mTimeoutMillis;
+ const char* const mMessage;
+ const int64_t mStart;
+};
+
+/*
+ * Writes the specified debug log message if this block takes longer than the
+ * specified number of milliseconds to run. Includes the time actually taken.
+ *
+ * {
+ * ALOGD_IF_SLOW(50, "Excessive delay doing something.");
+ * doSomething();
+ * }
+ */
+#define ALOGD_IF_SLOW(timeoutMillis, message) \
+ LogIfSlow _logIfSlow(LOG_TAG, ANDROID_LOG_DEBUG, timeoutMillis, message);
+
+} // namespace android
+
+#endif // __cplusplus
#endif // _LIBS_UTILS_LOG_H
diff --git a/include/utils/SharedBuffer.h b/include/utils/SharedBuffer.h
index 24508b0..b670953 100644
--- a/include/utils/SharedBuffer.h
+++ b/include/utils/SharedBuffer.h
@@ -44,9 +44,6 @@ public:
* users.
*/
static ssize_t dealloc(const SharedBuffer* released);
-
- //! get the SharedBuffer from the data pointer
- static inline const SharedBuffer* sharedBuffer(const void* data);
//! access the data for read
inline const void* data() const;
@@ -94,9 +91,10 @@ public:
private:
inline SharedBuffer() { }
inline ~SharedBuffer() { }
- inline SharedBuffer(const SharedBuffer&);
+ SharedBuffer(const SharedBuffer&);
+ SharedBuffer& operator = (const SharedBuffer&);
- // 16 bytes. must be sized to preserve correct alingment.
+ // 16 bytes. must be sized to preserve correct alignment.
mutable int32_t mRefs;
size_t mSize;
uint32_t mReserved[2];
@@ -104,10 +102,6 @@ private:
// ---------------------------------------------------------------------------
-const SharedBuffer* SharedBuffer::sharedBuffer(const void* data) {
- return data ? reinterpret_cast<const SharedBuffer *>(data)-1 : 0;
-}
-
const void* SharedBuffer::data() const {
return this + 1;
}
@@ -120,19 +114,16 @@ size_t SharedBuffer::size() const {
return mSize;
}
-SharedBuffer* SharedBuffer::bufferFromData(void* data)
-{
- return ((SharedBuffer*)data)-1;
+SharedBuffer* SharedBuffer::bufferFromData(void* data) {
+ return data ? static_cast<SharedBuffer *>(data)-1 : 0;
}
-const SharedBuffer* SharedBuffer::bufferFromData(const void* data)
-{
- return ((const SharedBuffer*)data)-1;
+const SharedBuffer* SharedBuffer::bufferFromData(const void* data) {
+ return data ? static_cast<const SharedBuffer *>(data)-1 : 0;
}
-size_t SharedBuffer::sizeFromData(const void* data)
-{
- return (((const SharedBuffer*)data)-1)->mSize;
+size_t SharedBuffer::sizeFromData(const void* data) {
+ return data ? bufferFromData(data)->mSize : 0;
}
bool SharedBuffer::onlyOwner() const {
diff --git a/include/utils/Singleton.h b/include/utils/Singleton.h
index a42ce21..c60680e 100644
--- a/include/utils/Singleton.h
+++ b/include/utils/Singleton.h
@@ -65,9 +65,9 @@ private:
*/
#define ANDROID_SINGLETON_STATIC_INSTANCE(TYPE) \
- template class Singleton< TYPE >; \
template<> Mutex Singleton< TYPE >::sLock(Mutex::PRIVATE); \
- template<> TYPE* Singleton< TYPE >::sInstance(0);
+ template<> TYPE* Singleton< TYPE >::sInstance(0); \
+ template class Singleton< TYPE >;
// ---------------------------------------------------------------------------
diff --git a/include/utils/SortedVector.h b/include/utils/SortedVector.h
index fd1cb82..2d3e82a 100644
--- a/include/utils/SortedVector.h
+++ b/include/utils/SortedVector.h
@@ -98,8 +98,6 @@ public:
inline const TYPE& itemAt(size_t index) const;
//! stack-usage of the vector. returns the top of the stack (last element)
const TYPE& top() const;
- //! same as operator [], but allows to access the vector backward (from the end) with a negative index
- const TYPE& mirrorItemAt(ssize_t index) const;
/*!
* modifying the array
@@ -200,15 +198,6 @@ const TYPE& SortedVector<TYPE>::itemAt(size_t index) const {
}
template<class TYPE> inline
-const TYPE& SortedVector<TYPE>::mirrorItemAt(ssize_t index) const {
- const size_t i = index>0 ? index : -index;
- LOG_FATAL_IF(index>=size(),
- "%s: index=%u out of range (%u)", __PRETTY_FUNCTION__,
- int(index), int(size()));
- return *(array() + i);
-}
-
-template<class TYPE> inline
const TYPE& SortedVector<TYPE>::top() const {
return *(array() + size() - 1);
}
diff --git a/include/utils/Vector.h b/include/utils/Vector.h
index 506acae..7927328 100644
--- a/include/utils/Vector.h
+++ b/include/utils/Vector.h
@@ -99,8 +99,6 @@ public:
inline const TYPE& itemAt(size_t index) const;
//! stack-usage of the vector. returns the top of the stack (last element)
const TYPE& top() const;
- //! same as operator [], but allows to access the vector backward (from the end) with a negative index
- const TYPE& mirrorItemAt(ssize_t index) const;
/*!
* modifying the array
@@ -284,15 +282,6 @@ const TYPE& Vector<TYPE>::itemAt(size_t index) const {
}
template<class TYPE> inline
-const TYPE& Vector<TYPE>::mirrorItemAt(ssize_t index) const {
- const size_t i = index>0 ? index : -index;
- LOG_FATAL_IF(index>=size(),
- "%s: index=%u out of range (%u)", __PRETTY_FUNCTION__,
- int(index), int(size()));
- return *(array() + i);
-}
-
-template<class TYPE> inline
const TYPE& Vector<TYPE>::top() const {
return *(array() + size() - 1);
}