diff options
Diffstat (limited to 'include')
29 files changed, 312 insertions, 236 deletions
diff --git a/include/binder/IInterface.h b/include/binder/IInterface.h index 5f9f69c..4ce3613 100644 --- a/include/binder/IInterface.h +++ b/include/binder/IInterface.h @@ -28,9 +28,9 @@ class IInterface : public virtual RefBase { public: IInterface(); - sp<IBinder> asBinder(); - sp<const IBinder> asBinder() const; - + static sp<IBinder> asBinder(const IInterface*); + static sp<IBinder> asBinder(const sp<IInterface>&); + protected: virtual ~IInterface(); virtual IBinder* onAsBinder() = 0; diff --git a/include/binder/IPCThreadState.h b/include/binder/IPCThreadState.h index 6e0c01b..60c2242 100644 --- a/include/binder/IPCThreadState.h +++ b/include/binder/IPCThreadState.h @@ -22,7 +22,7 @@ #include <binder/ProcessState.h> #include <utils/Vector.h> -#ifdef HAVE_WIN32_PROC +#if defined(_WIN32) typedef int uid_t; #endif @@ -39,8 +39,8 @@ public: status_t clearLastError(); - int getCallingPid() const; - int getCallingUid() const; + pid_t getCallingPid() const; + uid_t getCallingUid() const; void setStrictModePolicy(int32_t policy); int32_t getStrictModePolicy() const; diff --git a/include/binder/Parcel.h b/include/binder/Parcel.h index 6a69761..a52e044 100644 --- a/include/binder/Parcel.h +++ b/include/binder/Parcel.h @@ -94,6 +94,7 @@ public: void* writeInplace(size_t len); status_t writeUnpadded(const void* data, size_t len); status_t writeInt32(int32_t val); + status_t writeUint32(uint32_t val); status_t writeInt64(int64_t val); status_t writeFloat(float val); status_t writeDouble(double val); @@ -152,6 +153,8 @@ public: const void* readInplace(size_t len) const; int32_t readInt32() const; status_t readInt32(int32_t *pArg) const; + uint32_t readUint32() const; + status_t readUint32(uint32_t *pArg) const; int64_t readInt64() const; status_t readInt64(int64_t *pArg) const; float readFloat() const; diff --git a/include/gui/BufferItem.h b/include/gui/BufferItem.h index 01b6ff4..000ef0e 100644 --- a/include/gui/BufferItem.h +++ b/include/gui/BufferItem.h @@ -20,9 +20,10 @@ #include <EGL/egl.h> #include <EGL/eglext.h> -#include <gui/IGraphicBufferConsumer.h> - #include <ui/Rect.h> +#include <ui/Region.h> + +#include <system/graphics.h> #include <utils/Flattenable.h> #include <utils/StrongPointer.h> @@ -45,7 +46,6 @@ class BufferItem : public Flattenable<BufferItem> { enum { INVALID_BUFFER_SLOT = -1 }; BufferItem(); ~BufferItem(); - operator IGraphicBufferConsumer::BufferItem() const; static const char* scalingModeName(uint32_t scalingMode); @@ -78,11 +78,21 @@ class BufferItem : public Flattenable<BufferItem> { // automatically when the buffer was queued. bool mIsAutoTimestamp; + // mDataSpace is the current dataSpace value for this buffer slot. This gets + // set by queueBuffer each time this slot is queued. The meaning of the + // dataSpace is format-dependent. + android_dataspace mDataSpace; + // mFrameNumber is the number of the queued frame for this slot. uint64_t mFrameNumber; - // mSlot is the slot index of this buffer (default INVALID_BUFFER_SLOT). - int mSlot; + union { + // mSlot is the slot index of this buffer (default INVALID_BUFFER_SLOT). + int mSlot; + + // mBuf is the former name for mSlot + int mBuf; + }; // mIsDroppable whether this buffer was queued with the // property that it can be replaced by a new buffer for the purpose of @@ -97,6 +107,10 @@ class BufferItem : public Flattenable<BufferItem> { // Indicates this buffer must be transformed by the inverse transform of the screen // it is displayed onto. This is applied after mTransform. bool mTransformToDisplayInverse; + + // Describes the portion of the surface that has been modified since the + // previous frame + Region mSurfaceDamage; }; } // namespace android diff --git a/include/gui/BufferItemConsumer.h b/include/gui/BufferItemConsumer.h index 5494ff1..930fabf 100644 --- a/include/gui/BufferItemConsumer.h +++ b/include/gui/BufferItemConsumer.h @@ -42,8 +42,6 @@ class BufferItemConsumer: public ConsumerBase public: typedef ConsumerBase::FrameAvailableListener FrameAvailableListener; - typedef BufferQueue::BufferItem BufferItem; - enum { DEFAULT_MAX_BUFFERS = -1 }; enum { INVALID_BUFFER_SLOT = BufferQueue::INVALID_BUFFER_SLOT }; enum { NO_BUFFER_AVAILABLE = BufferQueue::NO_BUFFER_AVAILABLE }; @@ -76,8 +74,8 @@ class BufferItemConsumer: public ConsumerBase // // 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, nsecs_t presentWhen, - bool waitForFence = true); + status_t acquireBuffer(BufferItem* item, nsecs_t presentWhen, + 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 @@ -95,7 +93,14 @@ class BufferItemConsumer: public ConsumerBase // setDefaultBufferFormat allows the BufferQueue to create // GraphicBuffers of a defaultFormat if no format is specified // in dequeueBuffer - status_t setDefaultBufferFormat(uint32_t defaultFormat); + status_t setDefaultBufferFormat(PixelFormat defaultFormat); + + // setDefaultBufferDataSpace allows the BufferQueue to create + // GraphicBuffers of a defaultDataSpace if no data space is specified + // in queueBuffer. + // The initial default is HAL_DATASPACE_UNKNOWN + status_t setDefaultBufferDataSpace(android_dataspace defaultDataSpace); + }; } // namespace android diff --git a/include/gui/BufferQueue.h b/include/gui/BufferQueue.h index 1188837..721b218 100644 --- a/include/gui/BufferQueue.h +++ b/include/gui/BufferQueue.h @@ -17,6 +17,7 @@ #ifndef ANDROID_GUI_BUFFERQUEUE_H #define ANDROID_GUI_BUFFERQUEUE_H +#include <gui/BufferItem.h> #include <gui/BufferQueueDefs.h> #include <gui/IGraphicBufferConsumer.h> #include <gui/IGraphicBufferProducer.h> @@ -34,7 +35,7 @@ public: // Attempts at runtime to increase the number of buffers past this will fail. enum { NUM_BUFFER_SLOTS = BufferQueueDefs::NUM_BUFFER_SLOTS }; // Used as a placeholder slot# when the value isn't pointing to an existing buffer. - enum { INVALID_BUFFER_SLOT = IGraphicBufferConsumer::BufferItem::INVALID_BUFFER_SLOT }; + enum { INVALID_BUFFER_SLOT = BufferItem::INVALID_BUFFER_SLOT }; // Alias to <IGraphicBufferConsumer.h> -- please scope from there in future code! enum { NO_BUFFER_AVAILABLE = IGraphicBufferConsumer::NO_BUFFER_AVAILABLE, @@ -47,7 +48,6 @@ public: // for backward source compatibility typedef ::android::ConsumerListener ConsumerListener; - typedef IGraphicBufferConsumer::BufferItem BufferItem; // ProxyConsumerListener is a ConsumerListener implementation that keeps a weak // reference to the actual consumer object. It forwards all calls to that @@ -62,7 +62,7 @@ public: public: ProxyConsumerListener(const wp<ConsumerListener>& consumerListener); virtual ~ProxyConsumerListener(); - virtual void onFrameAvailable(const android::BufferItem& item); + virtual void onFrameAvailable(const BufferItem& item); virtual void onBuffersReleased(); virtual void onSidebandStreamChanged(); private: diff --git a/include/gui/BufferQueueConsumer.h b/include/gui/BufferQueueConsumer.h index 1912ed0..9c91fc7 100644 --- a/include/gui/BufferQueueConsumer.h +++ b/include/gui/BufferQueueConsumer.h @@ -125,9 +125,15 @@ public: // setDefaultBufferFormat allows the BufferQueue to create // GraphicBuffers of a defaultFormat if no format is specified - // in dequeueBuffer. Formats are enumerated in graphics.h; the - // initial default is HAL_PIXEL_FORMAT_RGBA_8888. - virtual status_t setDefaultBufferFormat(uint32_t defaultFormat); + // in dequeueBuffer. The initial default is HAL_PIXEL_FORMAT_RGBA_8888. + virtual status_t setDefaultBufferFormat(PixelFormat defaultFormat); + + // setDefaultBufferDataSpace allows the BufferQueue to create + // GraphicBuffers of a defaultDataSpace if no data space is specified + // in queueBuffer. + // The initial default is HAL_DATASPACE_UNKNOWN + virtual status_t setDefaultBufferDataSpace( + android_dataspace defaultDataSpace); // setConsumerUsageBits will turn on additional usage bits for dequeueBuffer. // These are merged with the bits passed to dequeueBuffer. The values are diff --git a/include/gui/BufferQueueCore.h b/include/gui/BufferQueueCore.h index 1050e3b..9a43516 100644 --- a/include/gui/BufferQueueCore.h +++ b/include/gui/BufferQueueCore.h @@ -17,6 +17,7 @@ #ifndef ANDROID_GUI_BUFFERQUEUECORE_H #define ANDROID_GUI_BUFFERQUEUECORE_H +#include <gui/BufferItem.h> #include <gui/BufferQueueDefs.h> #include <gui/BufferSlot.h> @@ -29,11 +30,14 @@ #include <utils/Trace.h> #include <utils/Vector.h> -#define BQ_LOGV(x, ...) ALOGV("[%s] "x, mConsumerName.string(), ##__VA_ARGS__) -#define BQ_LOGD(x, ...) ALOGD("[%s] "x, mConsumerName.string(), ##__VA_ARGS__) -#define BQ_LOGI(x, ...) ALOGI("[%s] "x, mConsumerName.string(), ##__VA_ARGS__) -#define BQ_LOGW(x, ...) ALOGW("[%s] "x, mConsumerName.string(), ##__VA_ARGS__) -#define BQ_LOGE(x, ...) ALOGE("[%s] "x, mConsumerName.string(), ##__VA_ARGS__) +#include <list> +#include <set> + +#define BQ_LOGV(x, ...) ALOGV("[%s] " x, mConsumerName.string(), ##__VA_ARGS__) +#define BQ_LOGD(x, ...) ALOGD("[%s] " x, mConsumerName.string(), ##__VA_ARGS__) +#define BQ_LOGI(x, ...) ALOGI("[%s] " x, mConsumerName.string(), ##__VA_ARGS__) +#define BQ_LOGW(x, ...) ALOGW("[%s] " x, mConsumerName.string(), ##__VA_ARGS__) +#define BQ_LOGE(x, ...) ALOGE("[%s] " x, mConsumerName.string(), ##__VA_ARGS__) #define ATRACE_BUFFER_INDEX(index) \ if (ATRACE_ENABLED()) { \ @@ -45,7 +49,6 @@ namespace android { -class BufferItem; class IConsumerListener; class IGraphicBufferAlloc; class IProducerListener; @@ -58,7 +61,7 @@ class BufferQueueCore : public virtual RefBase { public: // Used as a placeholder slot number when the value isn't pointing to an // existing buffer. - enum { INVALID_BUFFER_SLOT = -1 }; // TODO: Extract from IGBC::BufferItem + enum { INVALID_BUFFER_SLOT = BufferItem::INVALID_BUFFER_SLOT }; // We reserve two slots in order to guarantee that the producer and // consumer can run asynchronously. @@ -123,6 +126,10 @@ private: // waitWhileAllocatingLocked blocks until mIsAllocating is false. void waitWhileAllocatingLocked() const; + // validateConsistencyLocked ensures that the free lists are in sync with + // the information stored in mSlots + void validateConsistencyLocked() const; + // mAllocator is the connection to SurfaceFlinger that is used to allocate // new GraphicBuffer objects. sp<IGraphicBufferAlloc> mAllocator; @@ -177,6 +184,14 @@ private: // mQueue is a FIFO of queued buffers used in synchronous mode. Fifo mQueue; + // mFreeSlots contains all of the slots which are FREE and do not currently + // have a buffer attached + std::set<int> mFreeSlots; + + // mFreeBuffers contains all of the slots which are FREE and currently have + // a buffer attached + std::list<int> mFreeBuffers; + // mOverrideMaxBufferCount is the limit on the number of buffers that will // be allocated at one time. This value is set by the producer by calling // setBufferCount. The default is 0, which means that the producer doesn't @@ -199,15 +214,20 @@ private: // mDefaultBufferFormat can be set so it will override the buffer format // when it isn't specified in dequeueBuffer. - uint32_t mDefaultBufferFormat; + PixelFormat mDefaultBufferFormat; // mDefaultWidth holds the default width of allocated buffers. It is used // in dequeueBuffer if a width and height of 0 are specified. - int mDefaultWidth; + uint32_t mDefaultWidth; // mDefaultHeight holds the default height of allocated buffers. It is used // in dequeueBuffer if a width and height of 0 are specified. - int mDefaultHeight; + uint32_t mDefaultHeight; + + // mDefaultBufferDataSpace holds the default dataSpace of queued buffers. + // It is used in queueBuffer if a dataspace of 0 (HAL_DATASPACE_UNKNOWN) + // is specified. + android_dataspace mDefaultBufferDataSpace; // 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. @@ -246,6 +266,10 @@ private: // mIsAllocatingCondition is a condition variable used by producers to wait until mIsAllocating // becomes false. mutable Condition mIsAllocatingCondition; + + // mAllowAllocation determines whether dequeueBuffer is allowed to allocate + // new buffers + bool mAllowAllocation; }; // class BufferQueueCore } // namespace android diff --git a/include/gui/BufferQueueProducer.h b/include/gui/BufferQueueProducer.h index ed1056a..ed660fb 100644 --- a/include/gui/BufferQueueProducer.h +++ b/include/gui/BufferQueueProducer.h @@ -73,9 +73,7 @@ public: // updateTexImage() is called. If width and height are both zero, the // default values specified by setDefaultBufferSize() are used instead. // - // The pixel formats are enumerated in graphics.h, e.g. - // HAL_PIXEL_FORMAT_RGBA_8888. If the format is 0, the default format - // will be used. + // If the format is 0, the default format will be used. // // The usage argument specifies gralloc buffer usage flags. The values // are enumerated in gralloc.h, e.g. GRALLOC_USAGE_HW_RENDER. These @@ -93,8 +91,9 @@ public: // // In both cases, the producer will need to call requestBuffer to get a // GraphicBuffer handle for the returned slot. - virtual status_t dequeueBuffer(int *outSlot, sp<Fence>* outFence, bool async, - uint32_t width, uint32_t height, uint32_t format, uint32_t usage); + virtual status_t dequeueBuffer(int *outSlot, sp<Fence>* outFence, + bool async, uint32_t width, uint32_t height, PixelFormat format, + uint32_t usage); // See IGraphicBufferProducer::detachBuffer virtual status_t detachBuffer(int slot); @@ -171,7 +170,10 @@ public: // See IGraphicBufferProducer::allocateBuffers virtual void allocateBuffers(bool async, uint32_t width, uint32_t height, - uint32_t format, uint32_t usage); + PixelFormat format, uint32_t usage); + + // See IGraphicBufferProducer::allowAllocation + virtual status_t allowAllocation(bool allow); private: // This is required by the IBinder::DeathRecipient interface diff --git a/include/gui/ConsumerBase.h b/include/gui/ConsumerBase.h index f7ab5ac..d56fa89 100644 --- a/include/gui/ConsumerBase.h +++ b/include/gui/ConsumerBase.h @@ -76,6 +76,9 @@ public: // when a new frame becomes available. void setFrameAvailableListener(const wp<FrameAvailableListener>& listener); + // See IGraphicBufferConsumer::detachBuffer + status_t detachBuffer(int slot); + private: ConsumerBase(const ConsumerBase&); void operator=(const ConsumerBase&); @@ -153,8 +156,7 @@ protected: // 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(IGraphicBufferConsumer::BufferItem *item, - nsecs_t presentWhen); + virtual status_t acquireBufferLocked(BufferItem *item, nsecs_t presentWhen); // releaseBufferLocked relinquishes control over a buffer, returning that // control to the BufferQueue. diff --git a/include/gui/CpuConsumer.h b/include/gui/CpuConsumer.h index 4c6822a..c99ab29 100644 --- a/include/gui/CpuConsumer.h +++ b/include/gui/CpuConsumer.h @@ -53,6 +53,7 @@ class CpuConsumer : public ConsumerBase uint32_t transform; uint32_t scalingMode; int64_t timestamp; + android_dataspace dataSpace; uint64_t frameNumber; // this is the same as format, except for formats that are compatible with // a flexible format (e.g. HAL_PIXEL_FORMAT_YCbCr_420_888). In the latter @@ -71,7 +72,7 @@ class CpuConsumer : public ConsumerBase // Create a new CPU consumer. The maxLockedBuffers parameter specifies // how many buffers can be locked for user access at the same time. CpuConsumer(const sp<IGraphicBufferConsumer>& bq, - uint32_t maxLockedBuffers, bool controlledByApp = false); + size_t maxLockedBuffers, bool controlledByApp = false); virtual ~CpuConsumer(); @@ -86,10 +87,15 @@ class CpuConsumer : public ConsumerBase status_t setDefaultBufferSize(uint32_t width, uint32_t height); // setDefaultBufferFormat allows CpuConsumer's BufferQueue to create buffers - // of a defaultFormat if no format is specified by producer. Formats are - // enumerated in graphics.h; the initial default is - // HAL_PIXEL_FORMAT_RGBA_8888. - status_t setDefaultBufferFormat(uint32_t defaultFormat); + // of a defaultFormat if no format is specified by producer. + // The initial default is PIXEL_FORMAT_RGBA_8888. + status_t setDefaultBufferFormat(PixelFormat defaultFormat); + + // setDefaultBufferDataSpace allows the BufferQueue to create + // GraphicBuffers of a defaultDataSpace if no data space is specified + // in queueBuffer. + // The initial default is HAL_DATASPACE_UNKNOWN + status_t setDefaultBufferDataSpace(android_dataspace defaultDataSpace); // 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 @@ -110,9 +116,9 @@ class CpuConsumer : public ConsumerBase private: // Maximum number of buffers that can be locked at a time - uint32_t mMaxLockedBuffers; + size_t mMaxLockedBuffers; - status_t releaseAcquiredBufferLocked(int lockedIdx); + status_t releaseAcquiredBufferLocked(size_t lockedIdx); virtual void freeBufferLocked(int slotIndex); @@ -133,7 +139,7 @@ class CpuConsumer : public ConsumerBase Vector<AcquiredBuffer> mAcquiredBuffers; // Count of currently locked buffers - uint32_t mCurrentLockedBuffers; + size_t mCurrentLockedBuffers; }; diff --git a/include/gui/GLConsumer.h b/include/gui/GLConsumer.h index f91fe46..4912580 100644 --- a/include/gui/GLConsumer.h +++ b/include/gui/GLConsumer.h @@ -150,7 +150,7 @@ public: // // The frame number is an incrementing counter set to 0 at the creation of // the BufferQueue associated with this consumer. - int64_t getFrameNumber(); + uint64_t getFrameNumber(); // setDefaultBufferSize is used to set the size of buffers returned by // requestBuffers when a with and height of zero is requested. @@ -197,7 +197,8 @@ public: // These functions call the corresponding BufferQueue implementation // so the refactoring can proceed smoothly - status_t setDefaultBufferFormat(uint32_t defaultFormat); + status_t setDefaultBufferFormat(PixelFormat defaultFormat); + status_t setDefaultBufferDataSpace(android_dataspace defaultDataSpace); status_t setConsumerUsageBits(uint32_t usage); status_t setTransformHint(uint32_t hint); @@ -240,8 +241,7 @@ protected: // acquireBufferLocked overrides the ConsumerBase method to update the // mEglSlots array in addition to the ConsumerBase behavior. - virtual status_t acquireBufferLocked(BufferQueue::BufferItem *item, - nsecs_t presentWhen); + virtual status_t acquireBufferLocked(BufferItem *item, nsecs_t presentWhen); // releaseBufferLocked overrides the ConsumerBase method to update the // mEglSlots array in addition to the ConsumerBase. @@ -254,12 +254,12 @@ protected: return releaseBufferLocked(slot, graphicBuffer, mEglDisplay, eglFence); } - static bool isExternalFormat(uint32_t format); + static bool isExternalFormat(PixelFormat format); // This releases the buffer in the slot referenced by mCurrentTexture, // then updates state to refer to the BufferItem, which must be a // newly-acquired buffer. - status_t updateAndReleaseLocked(const BufferQueue::BufferItem& item); + status_t updateAndReleaseLocked(const BufferItem& item); // Binds mTexName and the current buffer to mTexTarget. Uses // mCurrentTexture if it's set, mCurrentTextureImage if not. If the @@ -391,7 +391,7 @@ private: // mCurrentFrameNumber is the frame counter for the current texture. // It gets set each time updateTexImage is called. - int64_t mCurrentFrameNumber; + uint64_t mCurrentFrameNumber; uint32_t mDefaultWidth, mDefaultHeight; diff --git a/include/gui/GraphicBufferAlloc.h b/include/gui/GraphicBufferAlloc.h index b08750c..69fe51e 100644 --- a/include/gui/GraphicBufferAlloc.h +++ b/include/gui/GraphicBufferAlloc.h @@ -33,8 +33,9 @@ class GraphicBufferAlloc : public BnGraphicBufferAlloc { public: GraphicBufferAlloc(); virtual ~GraphicBufferAlloc(); - virtual sp<GraphicBuffer> createGraphicBuffer(uint32_t w, uint32_t h, - PixelFormat format, uint32_t usage, status_t* error); + virtual sp<GraphicBuffer> createGraphicBuffer(uint32_t width, + uint32_t height, PixelFormat format, uint32_t usage, + status_t* error); }; diff --git a/include/gui/IGraphicBufferAlloc.h b/include/gui/IGraphicBufferAlloc.h index cee41d9..f3c46ec 100644 --- a/include/gui/IGraphicBufferAlloc.h +++ b/include/gui/IGraphicBufferAlloc.h @@ -45,10 +45,10 @@ public: class BnGraphicBufferAlloc : public BnInterface<IGraphicBufferAlloc> { 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/IGraphicBufferConsumer.h b/include/gui/IGraphicBufferConsumer.h index 15f51fe..8f31b55 100644 --- a/include/gui/IGraphicBufferConsumer.h +++ b/include/gui/IGraphicBufferConsumer.h @@ -25,6 +25,7 @@ #include <utils/Timers.h> #include <binder/IInterface.h> +#include <ui/PixelFormat.h> #include <ui/Rect.h> #include <EGL/egl.h> @@ -33,6 +34,7 @@ namespace android { // ---------------------------------------------------------------------------- +class BufferItem; class Fence; class GraphicBuffer; class IConsumerListener; @@ -41,71 +43,6 @@ class NativeHandle; class IGraphicBufferConsumer : public IInterface { public: - - // public facing structure for BufferSlot - class BufferItem : public Flattenable<BufferItem> { - friend class Flattenable<BufferItem>; - size_t getPodSize() const; - size_t getFlattenedSize() const; - size_t getFdCount() const; - status_t flatten(void*& buffer, size_t& size, int*& fds, size_t& count) const; - status_t unflatten(void const*& buffer, size_t& size, int const*& fds, size_t& count); - - public: - // The default value of mBuf, used to indicate this doesn't correspond to a slot. - enum { INVALID_BUFFER_SLOT = -1 }; - BufferItem(); - - // mGraphicBuffer points to the buffer allocated for this slot, or is NULL - // if the buffer in this slot has been acquired in the past (see - // BufferSlot.mAcquireCalled). - sp<GraphicBuffer> mGraphicBuffer; - - // mFence is a fence that will signal when the buffer is idle. - sp<Fence> mFence; - - // mCrop is the current crop rectangle for this buffer slot. - Rect mCrop; - - // mTransform is the current transform flags for this buffer slot. - // refer to NATIVE_WINDOW_TRANSFORM_* in <window.h> - uint32_t mTransform; - - // mScalingMode is the current scaling mode for this buffer slot. - // refer to NATIVE_WINDOW_SCALING_* in <window.h> - uint32_t mScalingMode; - - // mTimestamp is the current timestamp for this buffer slot. This gets - // to set by queueBuffer each time this slot is queued. This value - // is guaranteed to be monotonically increasing for each newly - // acquired buffer. - int64_t mTimestamp; - - // mIsAutoTimestamp indicates whether mTimestamp was generated - // automatically when the buffer was queued. - bool mIsAutoTimestamp; - - // mFrameNumber is the number of the queued frame for this slot. - uint64_t mFrameNumber; - - // mBuf is the slot index of this buffer (default INVALID_BUFFER_SLOT). - int mBuf; - - // mIsDroppable whether this buffer was queued with the - // property that it can be replaced by a new buffer for the purpose of - // making sure dequeueBuffer() won't block. - // i.e.: was the BufferQueue in "mDequeueBufferCannotBlock" when this buffer - // was queued. - bool mIsDroppable; - - // Indicates whether this buffer has been seen by a consumer yet - bool mAcquireCalled; - - // Indicates this buffer must be transformed by the inverse transform of the screen - // it is displayed onto. This is applied after mTransform. - bool mTransformToDisplayInverse; - }; - enum { // Returned by releaseBuffer, after which the consumer must // free any references to the just-released buffer that it might have. @@ -280,11 +217,19 @@ public: // setDefaultBufferFormat allows the BufferQueue to create // GraphicBuffers of a defaultFormat if no format is specified - // in dequeueBuffer. Formats are enumerated in graphics.h; the - // initial default is HAL_PIXEL_FORMAT_RGBA_8888. + // in dequeueBuffer. + // The initial default is PIXEL_FORMAT_RGBA_8888. + // + // Return of a value other than NO_ERROR means an unknown error has occurred. + virtual status_t setDefaultBufferFormat(PixelFormat defaultFormat) = 0; + + // setDefaultBufferDataSpace is a request to the producer to provide buffers + // of the indicated dataSpace. The producer may ignore this request. + // The initial default is HAL_DATASPACE_UNKNOWN. // // Return of a value other than NO_ERROR means an unknown error has occurred. - virtual status_t setDefaultBufferFormat(uint32_t defaultFormat) = 0; + virtual status_t setDefaultBufferDataSpace( + android_dataspace defaultDataSpace) = 0; // setConsumerUsageBits will turn on additional usage bits for dequeueBuffer. // These are merged with the bits passed to dequeueBuffer. The values are diff --git a/include/gui/IGraphicBufferProducer.h b/include/gui/IGraphicBufferProducer.h index 4e9e810..5c50b2b 100644 --- a/include/gui/IGraphicBufferProducer.h +++ b/include/gui/IGraphicBufferProducer.h @@ -28,6 +28,7 @@ #include <ui/Fence.h> #include <ui/GraphicBuffer.h> #include <ui/Rect.h> +#include <ui/Region.h> namespace android { // ---------------------------------------------------------------------------- @@ -134,9 +135,7 @@ public: // updateTexImage() is called. If width and height are both zero, the // default values specified by setDefaultBufferSize() are used instead. // - // The pixel formats are enumerated in <graphics.h>, e.g. - // HAL_PIXEL_FORMAT_RGBA_8888. If the format is 0, the default format - // will be used. + // If the format is 0, the default format will be used. // // The usage argument specifies gralloc buffer usage flags. The values // are enumerated in <gralloc.h>, e.g. GRALLOC_USAGE_HW_RENDER. These @@ -167,7 +166,7 @@ public: // All other negative values are an unknown error returned downstream // from the graphics allocator (typically errno). virtual status_t dequeueBuffer(int* slot, sp<Fence>* fence, bool async, - uint32_t w, uint32_t h, uint32_t format, uint32_t usage) = 0; + uint32_t w, uint32_t h, PixelFormat format, uint32_t usage) = 0; // detachBuffer attempts to remove all ownership of the buffer in the given // slot from the buffer queue. If this call succeeds, the slot will be @@ -267,6 +266,7 @@ public: inline QueueBufferInput(const Parcel& parcel); // timestamp - a monotonically increasing value in nanoseconds // isAutoTimestamp - if the timestamp was synthesized at queue time + // dataSpace - description of the contents, interpretation depends on format // crop - a crop rectangle that's used as a hint to the consumer // scalingMode - a set of flags from NATIVE_WINDOW_SCALING_* in <window.h> // transform - a set of flags from NATIVE_WINDOW_TRANSFORM_* in <window.h> @@ -276,17 +276,21 @@ public: // sticky - the sticky transform set in Surface (only used by the LEGACY // camera mode). inline QueueBufferInput(int64_t timestamp, bool isAutoTimestamp, - const Rect& crop, int scalingMode, uint32_t transform, bool async, - const sp<Fence>& fence, uint32_t sticky = 0) - : timestamp(timestamp), isAutoTimestamp(isAutoTimestamp), crop(crop), - scalingMode(scalingMode), transform(transform), stickyTransform(sticky), - async(async), fence(fence) { } + android_dataspace dataSpace, const Rect& crop, int scalingMode, + uint32_t transform, bool async, const sp<Fence>& fence, + uint32_t sticky = 0) + : timestamp(timestamp), isAutoTimestamp(isAutoTimestamp), + dataSpace(dataSpace), crop(crop), scalingMode(scalingMode), + transform(transform), stickyTransform(sticky), + async(async), fence(fence), surfaceDamage() { } inline void deflate(int64_t* outTimestamp, bool* outIsAutoTimestamp, - Rect* outCrop, int* outScalingMode, uint32_t* outTransform, - bool* outAsync, sp<Fence>* outFence, + android_dataspace* outDataSpace, + Rect* outCrop, int* outScalingMode, + uint32_t* outTransform, bool* outAsync, sp<Fence>* outFence, uint32_t* outStickyTransform = NULL) const { *outTimestamp = timestamp; *outIsAutoTimestamp = bool(isAutoTimestamp); + *outDataSpace = dataSpace; *outCrop = crop; *outScalingMode = scalingMode; *outTransform = transform; @@ -303,15 +307,20 @@ public: status_t flatten(void*& buffer, size_t& size, int*& fds, size_t& count) const; status_t unflatten(void const*& buffer, size_t& size, int const*& fds, size_t& count); + const Region& getSurfaceDamage() const { return surfaceDamage; } + void setSurfaceDamage(const Region& damage) { surfaceDamage = damage; } + private: int64_t timestamp; int isAutoTimestamp; + android_dataspace dataSpace; Rect crop; int scalingMode; uint32_t transform; uint32_t stickyTransform; int async; sp<Fence> fence; + Region surfaceDamage; }; // QueueBufferOutput must be a POD structure @@ -448,7 +457,19 @@ public: // dequeueBuffer. If there are already the maximum number of buffers // allocated, this function has no effect. virtual void allocateBuffers(bool async, uint32_t width, uint32_t height, - uint32_t format, uint32_t usage) = 0; + PixelFormat format, uint32_t usage) = 0; + + // Sets whether dequeueBuffer is allowed to allocate new buffers. + // + // Normally dequeueBuffer does not discriminate between free slots which + // already have an allocated buffer and those which do not, and will + // allocate a new buffer if the slot doesn't have a buffer or if the slot's + // buffer doesn't match the requested size, format, or usage. This method + // allows the producer to restrict the eligible slots to those which already + // have an allocated buffer of the correct size, format, and usage. If no + // eligible slot is available, dequeueBuffer will block or return an error + // as usual. + virtual status_t allowAllocation(bool allow) = 0; }; // ---------------------------------------------------------------------------- diff --git a/include/gui/ISurfaceComposer.h b/include/gui/ISurfaceComposer.h index 51717a4..8c3d49e 100644 --- a/include/gui/ISurfaceComposer.h +++ b/include/gui/ISurfaceComposer.h @@ -28,7 +28,6 @@ #include <binder/IInterface.h> #include <ui/FrameStats.h> -#include <ui/PixelFormat.h> #include <gui/IGraphicBufferAlloc.h> #include <gui/ISurfaceComposerClient.h> @@ -39,7 +38,7 @@ namespace android { class ComposerState; class DisplayState; struct DisplayInfo; -class DisplayStatInfo; +struct DisplayStatInfo; class IDisplayEventConnection; class IMemoryHeap; class Rect; diff --git a/include/gui/Sensor.h b/include/gui/Sensor.h index 28a08e2..27a215e 100644 --- a/include/gui/Sensor.h +++ b/include/gui/Sensor.h @@ -67,12 +67,12 @@ public: int32_t getMinDelay() const; nsecs_t getMinDelayNs() const; int32_t getVersion() const; - int32_t getFifoReservedEventCount() const; - int32_t getFifoMaxEventCount() const; + uint32_t getFifoReservedEventCount() const; + uint32_t getFifoMaxEventCount() const; const String8& getStringType() const; const String8& getRequiredPermission() const; int32_t getMaxDelay() const; - int32_t getFlags() const; + uint32_t getFlags() const; bool isWakeUpSensor() const; int32_t getReportingMode() const; @@ -93,12 +93,12 @@ private: float mPower; int32_t mMinDelay; int32_t mVersion; - int32_t mFifoReservedEventCount; - int32_t mFifoMaxEventCount; + uint32_t mFifoReservedEventCount; + uint32_t mFifoMaxEventCount; String8 mStringType; String8 mRequiredPermission; int32_t mMaxDelay; - int32_t mFlags; + uint32_t mFlags; static void flattenString8(void*& buffer, size_t& size, const String8& string8); static bool unflattenString8(void const*& buffer, size_t& size, String8& outputString8); }; diff --git a/include/gui/Surface.h b/include/gui/Surface.h index f2cf018..a9f78cf 100644 --- a/include/gui/Surface.h +++ b/include/gui/Surface.h @@ -146,6 +146,8 @@ private: int dispatchLock(va_list args); int dispatchUnlockAndPost(va_list args); int dispatchSetSidebandStream(va_list args); + int dispatchSetBuffersDataSpace(va_list args); + int dispatchSetSurfaceDamage(va_list args); protected: virtual int dequeueBuffer(ANativeWindowBuffer** buffer, int* fenceFd); @@ -160,20 +162,27 @@ protected: virtual int connect(int api); virtual int disconnect(int api); virtual int setBufferCount(int bufferCount); - virtual int setBuffersDimensions(int w, int h); - virtual int setBuffersUserDimensions(int w, int h); - virtual int setBuffersFormat(int format); + virtual int setBuffersDimensions(uint32_t width, uint32_t height); + virtual int setBuffersUserDimensions(uint32_t width, uint32_t height); + virtual int setBuffersFormat(PixelFormat format); virtual int setScalingMode(int mode); - virtual int setBuffersTransform(int transform); - virtual int setBuffersStickyTransform(int transform); + virtual int setBuffersTransform(uint32_t transform); + virtual int setBuffersStickyTransform(uint32_t transform); virtual int setBuffersTimestamp(int64_t timestamp); + virtual int setBuffersDataSpace(android_dataspace dataSpace); virtual int setCrop(Rect const* rect); virtual int setUsage(uint32_t reqUsage); + virtual void setSurfaceDamage(android_native_rect_t* rects, size_t numRects); public: virtual int lock(ANativeWindow_Buffer* outBuffer, ARect* inOutDirtyBounds); virtual int unlockAndPost(); + virtual int connect(int api, const sp<IProducerListener>& listener); + virtual int detachNextBuffer(ANativeWindowBuffer** outBuffer, + sp<Fence>* outFence); + virtual int attachBuffer(ANativeWindowBuffer*); + protected: enum { NUM_BUFFER_SLOTS = BufferQueue::NUM_BUFFER_SLOTS }; enum { DEFAULT_FORMAT = PIXEL_FORMAT_RGBA_8888 }; @@ -211,7 +220,7 @@ private: // mReqFormat is the buffer pixel format that will be requested at the next // deuque operation. It is initialized to PIXEL_FORMAT_RGBA_8888. - uint32_t mReqFormat; + PixelFormat mReqFormat; // mReqUsage is the set of buffer usage flags that will be requested // at the next deuque operation. It is initialized to 0. @@ -222,6 +231,11 @@ private: // a timestamp is auto-generated when queueBuffer is called. int64_t mTimestamp; + // mDataSpace is the buffer dataSpace that will be used for the next buffer + // queue operation. It defaults to HAL_DATASPACE_UNKNOWN, which + // means that the buffer contains some type of color data. + android_dataspace mDataSpace; + // mCrop is the crop rectangle that will be used for the next buffer // that gets queued. It is set by calling setCrop. Rect mCrop; @@ -240,23 +254,23 @@ private: // from being set by the compositor. uint32_t mStickyTransform; - // mDefaultWidth is default width of the buffers, regardless of the - // native_window_set_buffers_dimensions call. - uint32_t mDefaultWidth; + // mDefaultWidth is default width of the buffers, regardless of the + // native_window_set_buffers_dimensions call. + uint32_t mDefaultWidth; - // mDefaultHeight is default height of the buffers, regardless of the - // native_window_set_buffers_dimensions call. - uint32_t mDefaultHeight; + // mDefaultHeight is default height of the buffers, regardless of the + // native_window_set_buffers_dimensions call. + uint32_t mDefaultHeight; - // mUserWidth, if non-zero, is an application-specified override - // of mDefaultWidth. This is lower priority than the width set by - // native_window_set_buffers_dimensions. - uint32_t mUserWidth; + // mUserWidth, if non-zero, is an application-specified override + // of mDefaultWidth. This is lower priority than the width set by + // native_window_set_buffers_dimensions. + uint32_t mUserWidth; - // mUserHeight, if non-zero, is an application-specified override - // of mDefaultHeight. This is lower priority than the height set - // by native_window_set_buffers_dimensions. - uint32_t mUserHeight; + // mUserHeight, if non-zero, is an application-specified override + // of mDefaultHeight. This is lower priority than the height set + // by native_window_set_buffers_dimensions. + uint32_t mUserHeight; // mTransformHint is the transform probably applied to buffers of this // window. this is only a hint, actual transform may differ. @@ -284,7 +298,12 @@ private: sp<GraphicBuffer> mPostedBuffer; bool mConnectedToCpu; - // must be accessed from lock/unlock thread only + // When a CPU producer is attached, this reflects the region that the + // producer wished to update as well as whether the Surface was able to copy + // the previous buffer back to allow a partial update. + // + // When a non-CPU producer is attached, this reflects the surface damage + // (the change since the previous frame) passed in by the producer. Region mDirtyRegion; }; diff --git a/include/gui/SurfaceComposerClient.h b/include/gui/SurfaceComposerClient.h index 4cbfc09..37d953e 100644 --- a/include/gui/SurfaceComposerClient.h +++ b/include/gui/SurfaceComposerClient.h @@ -127,7 +127,7 @@ public: status_t show(const sp<IBinder>& id); status_t setFlags(const sp<IBinder>& id, uint32_t flags, uint32_t mask); status_t setTransparentRegionHint(const sp<IBinder>& id, const Region& transparent); - status_t setLayer(const sp<IBinder>& id, int32_t layer); + status_t setLayer(const sp<IBinder>& id, uint32_t layer); status_t setAlpha(const sp<IBinder>& id, float alpha=1.0f); status_t setMatrix(const sp<IBinder>& id, float dsdx, float dtdx, float dsdy, float dtdy); status_t setPosition(const sp<IBinder>& id, float x, float y); diff --git a/include/gui/SurfaceControl.h b/include/gui/SurfaceControl.h index 84fb9f9..9f62f7c 100644 --- a/include/gui/SurfaceControl.h +++ b/include/gui/SurfaceControl.h @@ -57,8 +57,8 @@ public: // release surface data from java void clear(); - status_t setLayerStack(int32_t layerStack); - status_t setLayer(int32_t layer); + status_t setLayerStack(uint32_t layerStack); + status_t setLayer(uint32_t layer); status_t setPosition(float x, float y); status_t setSize(uint32_t w, uint32_t h); status_t hide(); diff --git a/include/ui/Fence.h b/include/ui/Fence.h index 20466b6..b431bd5 100644 --- a/include/ui/Fence.h +++ b/include/ui/Fence.h @@ -65,7 +65,7 @@ public: // before the fence signals then -ETIME is returned. A timeout of // TIMEOUT_NEVER may be used to indicate that the call should wait // indefinitely for the fence to signal. - status_t wait(unsigned int timeout); + status_t wait(int timeout); // waitForever is a convenience function for waiting forever for a fence to // signal (just like wait(TIMEOUT_NEVER)), but issuing an error to the diff --git a/include/ui/FramebufferNativeWindow.h b/include/ui/FramebufferNativeWindow.h index 5cd8101..6b66d5f 100644 --- a/include/ui/FramebufferNativeWindow.h +++ b/include/ui/FramebufferNativeWindow.h @@ -14,11 +14,13 @@ * limitations under the License. */ +#ifndef INCLUDED_FROM_FRAMEBUFFER_NATIVE_WINDOW_CPP +#warning "FramebufferNativeWindow is deprecated" +#endif + #ifndef ANDROID_FRAMEBUFFER_NATIVE_WINDOW_H #define ANDROID_FRAMEBUFFER_NATIVE_WINDOW_H -#warning "FramebufferNativeWindow is deprecated" - #include <stdint.h> #include <sys/types.h> diff --git a/include/ui/GraphicBuffer.h b/include/ui/GraphicBuffer.h index 7630faa..f91d192 100644 --- a/include/ui/GraphicBuffer.h +++ b/include/ui/GraphicBuffer.h @@ -49,7 +49,7 @@ public: USAGE_SW_READ_RARELY = GRALLOC_USAGE_SW_READ_RARELY, USAGE_SW_READ_OFTEN = GRALLOC_USAGE_SW_READ_OFTEN, USAGE_SW_READ_MASK = GRALLOC_USAGE_SW_READ_MASK, - + USAGE_SW_WRITE_NEVER = GRALLOC_USAGE_SW_WRITE_NEVER, USAGE_SW_WRITE_RARELY = GRALLOC_USAGE_SW_WRITE_RARELY, USAGE_SW_WRITE_OFTEN = GRALLOC_USAGE_SW_WRITE_OFTEN, @@ -72,11 +72,13 @@ public: GraphicBuffer(); // creates w * h buffer - GraphicBuffer(uint32_t w, uint32_t h, PixelFormat format, uint32_t usage); + GraphicBuffer(uint32_t inWidth, uint32_t inHeight, PixelFormat inFormat, + uint32_t inUsage); // create a buffer from an existing handle - GraphicBuffer(uint32_t w, uint32_t h, PixelFormat format, uint32_t usage, - uint32_t stride, native_handle_t* handle, bool keepOwnership); + GraphicBuffer(uint32_t inWidth, uint32_t inHeight, PixelFormat inFormat, + uint32_t inUsage, uint32_t inStride, native_handle_t* inHandle, + bool keepOwnership); // create a buffer from an existing ANativeWindowBuffer GraphicBuffer(ANativeWindowBuffer* buffer, bool keepOwnership); @@ -84,26 +86,34 @@ public: // return status status_t initCheck() const; - uint32_t getWidth() const { return width; } - uint32_t getHeight() const { return height; } - uint32_t getStride() const { return stride; } - uint32_t getUsage() const { return usage; } + uint32_t getWidth() const { return static_cast<uint32_t>(width); } + uint32_t getHeight() const { return static_cast<uint32_t>(height); } + uint32_t getStride() const { return static_cast<uint32_t>(stride); } + uint32_t getUsage() const { return static_cast<uint32_t>(usage); } PixelFormat getPixelFormat() const { return format; } Rect getBounds() const { return Rect(width, height); } uint64_t getId() const { return mId; } - status_t reallocate(uint32_t w, uint32_t h, PixelFormat f, uint32_t usage); + status_t reallocate(uint32_t inWidth, uint32_t inHeight, + PixelFormat inFormat, uint32_t inUsage); + + bool needsReallocation(uint32_t inWidth, uint32_t inHeight, + PixelFormat inFormat, uint32_t inUsage); - status_t lock(uint32_t usage, void** vaddr); - status_t lock(uint32_t usage, const Rect& rect, void** vaddr); + status_t lock(uint32_t inUsage, void** vaddr); + status_t lock(uint32_t inUsage, const Rect& rect, void** vaddr); // For HAL_PIXEL_FORMAT_YCbCr_420_888 - status_t lockYCbCr(uint32_t usage, android_ycbcr *ycbcr); - status_t lockYCbCr(uint32_t usage, const Rect& rect, android_ycbcr *ycbcr); + status_t lockYCbCr(uint32_t inUsage, android_ycbcr *ycbcr); + status_t lockYCbCr(uint32_t inUsage, const Rect& rect, + android_ycbcr *ycbcr); status_t unlock(); - status_t lockAsync(uint32_t usage, void** vaddr, int fenceFd); - status_t lockAsync(uint32_t usage, const Rect& rect, void** vaddr, int fenceFd); - status_t lockAsyncYCbCr(uint32_t usage, android_ycbcr *ycbcr, int fenceFd); - status_t lockAsyncYCbCr(uint32_t usage, const Rect& rect, android_ycbcr *ycbcr, int fenceFd); + status_t lockAsync(uint32_t inUsage, void** vaddr, int fenceFd); + status_t lockAsync(uint32_t inUsage, const Rect& rect, void** vaddr, + int fenceFd); + status_t lockAsyncYCbCr(uint32_t inUsage, android_ycbcr *ycbcr, + int fenceFd); + status_t lockAsyncYCbCr(uint32_t inUsage, const Rect& rect, + android_ycbcr *ycbcr, int fenceFd); status_t unlockAsync(int *fenceFd); ANativeWindowBuffer* getNativeBuffer() const; @@ -143,8 +153,8 @@ private: GraphicBuffer& operator = (const GraphicBuffer& rhs); const GraphicBuffer& operator = (const GraphicBuffer& rhs) const; - status_t initSize(uint32_t w, uint32_t h, PixelFormat format, - uint32_t usage); + status_t initSize(uint32_t inWidth, uint32_t inHeight, PixelFormat inFormat, + uint32_t inUsage); void free_handle(); diff --git a/include/ui/GraphicBufferAllocator.h b/include/ui/GraphicBufferAllocator.h index dffa788..5443f09 100644 --- a/include/ui/GraphicBufferAllocator.h +++ b/include/ui/GraphicBufferAllocator.h @@ -1,17 +1,17 @@ -/* +/* ** ** Copyright 2009, 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 +** 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 +** 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 +** 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. */ @@ -45,14 +45,14 @@ public: USAGE_SW_READ_RARELY = GRALLOC_USAGE_SW_READ_RARELY, USAGE_SW_READ_OFTEN = GRALLOC_USAGE_SW_READ_OFTEN, USAGE_SW_READ_MASK = GRALLOC_USAGE_SW_READ_MASK, - + USAGE_SW_WRITE_NEVER = GRALLOC_USAGE_SW_WRITE_NEVER, USAGE_SW_WRITE_RARELY = GRALLOC_USAGE_SW_WRITE_RARELY, USAGE_SW_WRITE_OFTEN = GRALLOC_USAGE_SW_WRITE_OFTEN, USAGE_SW_WRITE_MASK = GRALLOC_USAGE_SW_WRITE_MASK, - + USAGE_SOFTWARE_MASK = USAGE_SW_READ_MASK|USAGE_SW_WRITE_MASK, - + USAGE_HW_TEXTURE = GRALLOC_USAGE_HW_TEXTURE, USAGE_HW_RENDER = GRALLOC_USAGE_HW_RENDER, USAGE_HW_2D = GRALLOC_USAGE_HW_2D, @@ -60,10 +60,9 @@ public: }; static inline GraphicBufferAllocator& get() { return getInstance(); } - - status_t alloc(uint32_t w, uint32_t h, PixelFormat format, int usage, - buffer_handle_t* handle, int32_t* stride); + status_t alloc(uint32_t w, uint32_t h, PixelFormat format, uint32_t usage, + buffer_handle_t* handle, uint32_t* stride); status_t free(buffer_handle_t handle); @@ -72,21 +71,21 @@ public: private: struct alloc_rec_t { - uint32_t w; - uint32_t h; - uint32_t s; + uint32_t width; + uint32_t height; + uint32_t stride; PixelFormat format; uint32_t usage; size_t size; }; - + static Mutex sLock; static KeyedVector<buffer_handle_t, alloc_rec_t> sAllocList; - + friend class Singleton<GraphicBufferAllocator>; GraphicBufferAllocator(); ~GraphicBufferAllocator(); - + alloc_device_t *mAllocDev; }; diff --git a/include/ui/GraphicBufferMapper.h b/include/ui/GraphicBufferMapper.h index 98fff0e..6099548 100644 --- a/include/ui/GraphicBufferMapper.h +++ b/include/ui/GraphicBufferMapper.h @@ -41,23 +41,24 @@ public: status_t registerBuffer(buffer_handle_t handle); status_t unregisterBuffer(buffer_handle_t handle); - + status_t lock(buffer_handle_t handle, - int usage, const Rect& bounds, void** vaddr); + uint32_t usage, const Rect& bounds, void** vaddr); status_t lockYCbCr(buffer_handle_t handle, - int usage, const Rect& bounds, android_ycbcr *ycbcr); + uint32_t usage, const Rect& bounds, android_ycbcr *ycbcr); status_t unlock(buffer_handle_t handle); status_t lockAsync(buffer_handle_t handle, - int usage, const Rect& bounds, void** vaddr, int fenceFd); + uint32_t usage, const Rect& bounds, void** vaddr, int fenceFd); status_t lockAsyncYCbCr(buffer_handle_t handle, - int usage, const Rect& bounds, android_ycbcr *ycbcr, int fenceFd); + uint32_t usage, const Rect& bounds, android_ycbcr *ycbcr, + int fenceFd); status_t unlockAsync(buffer_handle_t handle, int *fenceFd); - + // dumps information about the mapping of this handle void dump(buffer_handle_t handle); diff --git a/include/ui/PixelFormat.h b/include/ui/PixelFormat.h index 7e46945..f26fecb 100644 --- a/include/ui/PixelFormat.h +++ b/include/ui/PixelFormat.h @@ -25,9 +25,6 @@ #ifndef UI_PIXELFORMAT_H #define UI_PIXELFORMAT_H -#include <stdint.h> -#include <sys/types.h> -#include <utils/Errors.h> #include <hardware/hardware.h> namespace android { @@ -63,14 +60,12 @@ enum { PIXEL_FORMAT_BGRA_8888 = HAL_PIXEL_FORMAT_BGRA_8888, // 4x8-bit BGRA PIXEL_FORMAT_RGBA_5551 = 6, // 16-bit ARGB PIXEL_FORMAT_RGBA_4444 = 7, // 16-bit ARGB - PIXEL_FORMAT_sRGB_A_8888 = HAL_PIXEL_FORMAT_sRGB_A_8888, // 4x8-bit sRGB + A - PIXEL_FORMAT_sRGB_X_8888 = HAL_PIXEL_FORMAT_sRGB_X_8888, // 4x8-bit sRGB, no A }; typedef int32_t PixelFormat; -ssize_t bytesPerPixel(PixelFormat format); -ssize_t bitsPerPixel(PixelFormat format); +uint32_t bytesPerPixel(PixelFormat format); +uint32_t bitsPerPixel(PixelFormat format); }; // namespace android diff --git a/include/ui/Rect.h b/include/ui/Rect.h index 31e28d2..3886f93 100644 --- a/include/ui/Rect.h +++ b/include/ui/Rect.h @@ -18,6 +18,7 @@ #define ANDROID_UI_RECT #include <utils/Flattenable.h> +#include <utils/Log.h> #include <utils/TypeHelpers.h> #include <ui/Point.h> @@ -30,6 +31,8 @@ class Rect : public ARect, public LightFlattenablePod<Rect> public: typedef ARect::value_type value_type; + static const Rect INVALID_RECT; + // we don't provide copy-ctor and operator= on purpose // because we want the compiler generated versions @@ -43,6 +46,22 @@ public: bottom = h; } + inline Rect(uint32_t w, uint32_t h) { + if (w > INT32_MAX) { + ALOG(LOG_WARN, "Rect", + "Width %u too large for Rect class, clamping", w); + w = INT32_MAX; + } + if (h > INT32_MAX) { + ALOG(LOG_WARN, "Rect", + "Height %u too large for Rect class, clamping", h); + h = INT32_MAX; + } + left = top = 0; + right = w; + bottom = h; + } + inline Rect(int32_t l, int32_t t, int32_t r, int32_t b) { left = l; top = t; diff --git a/include/ui/Region.h b/include/ui/Region.h index 0d1c68c..2a14918 100644 --- a/include/ui/Region.h +++ b/include/ui/Region.h @@ -35,6 +35,8 @@ class String8; class Region : public LightFlattenable<Region> { public: + static const Region INVALID_REGION; + Region(); Region(const Region& rhs); explicit Region(const Rect& rhs); @@ -55,11 +57,12 @@ public: // the region becomes its bounds Region& makeBoundsSelf(); - + void clear(); void set(const Rect& r); + void set(int32_t w, int32_t h); void set(uint32_t w, uint32_t h); - + Region& orSelf(const Rect& rhs); Region& xorSelf(const Rect& rhs); Region& andSelf(const Rect& rhs); @@ -110,14 +113,14 @@ public: inline Region& operator -= (const Region& rhs); inline Region& operator += (const Point& pt); - + // returns true if the regions share the same underlying storage bool isTriviallyEqual(const Region& region) const; /* various ways to access the rectangle list */ - + // STL-like iterators typedef Rect const* const_iterator; const_iterator begin() const; @@ -133,7 +136,7 @@ public: 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); @@ -149,7 +152,7 @@ public: private: class rasterizer; friend class rasterizer; - + Region& operationSelf(const Rect& r, int op); Region& operationSelf(const Region& r, int op); Region& operationSelf(const Region& r, int dx, int dy, int op); @@ -172,7 +175,7 @@ private: static bool validate(const Region& reg, const char* name, bool silent = false); - + // 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 |