diff options
Diffstat (limited to 'include')
35 files changed, 299 insertions, 1134 deletions
diff --git a/include/binder/BinderService.h b/include/binder/BinderService.h index 5ac36d9..ef703bd 100644 --- a/include/binder/BinderService.h +++ b/include/binder/BinderService.h @@ -42,19 +42,20 @@ public: } static void publishAndJoinThreadPool(bool allowIsolated = false) { - sp<IServiceManager> sm(defaultServiceManager()); - sm->addService( - String16(SERVICE::getServiceName()), - new SERVICE(), allowIsolated); - ProcessState::self()->startThreadPool(); - ProcessState::self()->giveThreadPoolName(); - IPCThreadState::self()->joinThreadPool(); + publish(allowIsolated); + joinThreadPool(); } static void instantiate() { publish(); } - static status_t shutdown() { - return NO_ERROR; + static status_t shutdown() { return NO_ERROR; } + +private: + static void joinThreadPool() { + sp<ProcessState> ps(ProcessState::self()); + ps->startThreadPool(); + ps->giveThreadPoolName(); + IPCThreadState::self()->joinThreadPool(); } }; diff --git a/include/utils/BufferedTextOutput.h b/include/binder/BufferedTextOutput.h index 69c6240..adf3c32 100644 --- a/include/utils/BufferedTextOutput.h +++ b/include/binder/BufferedTextOutput.h @@ -17,7 +17,7 @@ #ifndef ANDROID_BUFFEREDTEXTOUTPUT_H #define ANDROID_BUFFEREDTEXTOUTPUT_H -#include <utils/TextOutput.h> +#include <binder/TextOutput.h> #include <utils/threads.h> #include <cutils/uio.h> diff --git a/include/binder/Debug.h b/include/binder/Debug.h new file mode 100644 index 0000000..f6a3355 --- /dev/null +++ b/include/binder/Debug.h @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2005 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_BINDER_DEBUG_H +#define ANDROID_BINDER_DEBUG_H + +#include <stdint.h> +#include <sys/types.h> + +namespace android { +// --------------------------------------------------------------------------- + +#ifdef __cplusplus +extern "C" { +#endif + +const char* stringForIndent(int32_t indentLevel); + +typedef void (*debugPrintFunc)(void* cookie, const char* txt); + +void printTypeCode(uint32_t typeCode, + debugPrintFunc func = 0, void* cookie = 0); + +void printHexData(int32_t indent, const void *buf, size_t length, + size_t bytesPerLine=16, int32_t singleLineBytesCutoff=16, + size_t alignment=0, bool cArrayStyle=false, + debugPrintFunc func = 0, void* cookie = 0); + +#ifdef __cplusplus +} +#endif + +// --------------------------------------------------------------------------- +}; // namespace android + +#endif // ANDROID_BINDER_DEBUG_H diff --git a/include/utils/TextOutput.h b/include/binder/TextOutput.h index de2fbbe..974a194 100644 --- a/include/utils/TextOutput.h +++ b/include/binder/TextOutput.h @@ -25,6 +25,9 @@ // --------------------------------------------------------------------------- namespace android { +class String8; +class String16; + class TextOutput { public: @@ -76,6 +79,8 @@ TextOutput& operator<<(TextOutput& to, float); TextOutput& operator<<(TextOutput& to, double); TextOutput& operator<<(TextOutput& to, TextOutputManipFunc func); TextOutput& operator<<(TextOutput& to, const void*); +TextOutput& operator<<(TextOutput& to, const String8& val); +TextOutput& operator<<(TextOutput& to, const String16& val); class TypeCode { diff --git a/include/gui/BufferQueue.h b/include/gui/BufferQueue.h index 6c1b691..766fa0f 100644 --- a/include/gui/BufferQueue.h +++ b/include/gui/BufferQueue.h @@ -229,7 +229,7 @@ public: // 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; + virtual void dump(String8& result, const char* prefix) const; // public facing structure for BufferSlot struct BufferItem { @@ -240,7 +240,8 @@ public: mScalingMode(NATIVE_WINDOW_SCALING_MODE_FREEZE), mTimestamp(0), mFrameNumber(0), - mBuf(INVALID_BUFFER_SLOT) { + mBuf(INVALID_BUFFER_SLOT), + mAcquireCalled(false) { mCrop.makeInvalid(); } // mGraphicBuffer points to the buffer allocated for this slot, or is NULL @@ -269,6 +270,9 @@ public: // mFence is a fence that will signal when the buffer is idle. sp<Fence> mFence; + + // Indicates whether this buffer has been seen by a consumer yet + bool mAcquireCalled; }; // The following public functions are the consumer-facing interface @@ -285,7 +289,7 @@ public: // releaseBuffer releases a buffer slot from the consumer back to the // BufferQueue. This may be done while the buffer's contents are still // being accessed. The fence will signal when the buffer is no longer - // in use. + // in use. frameNumber is used to indentify the exact buffer returned. // // If releaseBuffer returns STALE_BUFFER_SLOT, then the consumer must free // any references to the just-released buffer that it might have, as if it @@ -294,7 +298,8 @@ public: // // Note that the dependencies on EGL will be removed once we switch to using // the Android HW Sync HAL. - status_t releaseBuffer(int buf, EGLDisplay display, EGLSyncKHR fence, + status_t releaseBuffer(int buf, uint64_t frameNumber, + EGLDisplay display, EGLSyncKHR fence, const sp<Fence>& releaseFence); // consumerConnect connects a consumer to the BufferQueue. Only one @@ -368,10 +373,6 @@ private: // all slots. void freeAllBuffersLocked(); - // freeAllBuffersExceptHeadLocked frees the GraphicBuffer and sync - // resources for all slots except the head of mQueue. - void freeAllBuffersExceptHeadLocked(); - // drainQueueLocked waits for the buffer queue to empty if we're in // synchronous mode, or returns immediately otherwise. It returns NO_INIT // if the BufferQueue is abandoned (consumer disconnected) or disconnected @@ -410,20 +411,20 @@ private: // connected, mDequeueCondition must be broadcast. int getMaxBufferCountLocked() const; + // stillTracking returns true iff the buffer item is still being tracked + // in one of the slots. + bool stillTracking(const BufferItem *item) const; + struct BufferSlot { BufferSlot() : mEglDisplay(EGL_NO_DISPLAY), mBufferState(BufferSlot::FREE), mRequestBufferCalled(false), - mTransform(0), - mScalingMode(NATIVE_WINDOW_SCALING_MODE_FREEZE), - mTimestamp(0), mFrameNumber(0), mEglFence(EGL_NO_SYNC_KHR), mAcquireCalled(false), mNeedsCleanupOnRelease(false) { - mCrop.makeInvalid(); } // mGraphicBuffer points to the buffer allocated for this slot or is NULL @@ -482,21 +483,6 @@ private: // needed but useful for debugging and catching producer bugs. bool mRequestBufferCalled; - // mCrop is the current crop rectangle for this buffer slot. - Rect mCrop; - - // mTransform is the current transform flags for this buffer slot. - // (example: NATIVE_WINDOW_TRANSFORM_ROT_90) - uint32_t mTransform; - - // mScalingMode is the current scaling mode for this buffer slot. - // (example: NATIVE_WINDOW_SCALING_MODE_FREEZE) - uint32_t mScalingMode; - - // mTimestamp is the current timestamp for this buffer slot. This gets - // to set by queueBuffer each time this slot is queued. - int64_t mTimestamp; - // mFrameNumber is the number of the queued frame for this slot. This // is used to dequeue buffers in LRU order (useful because buffers // may be released before their release fence is signaled). @@ -592,7 +578,7 @@ private: mutable Condition mDequeueCondition; // mQueue is a FIFO of queued buffers used in synchronous mode - typedef Vector<int> Fifo; + typedef Vector<BufferItem> Fifo; Fifo mQueue; // mAbandoned indicates that the BufferQueue will no longer be used to @@ -613,7 +599,7 @@ private: mutable Mutex mMutex; // mFrameCounter is the free running counter, incremented on every - // successful queueBuffer call. + // successful queueBuffer call, and buffer allocation. uint64_t mFrameCounter; // mBufferHasBeenQueued is true once a buffer has been queued. It is diff --git a/include/gui/ConsumerBase.h b/include/gui/ConsumerBase.h index 8a7545d..1d51bc9 100644 --- a/include/gui/ConsumerBase.h +++ b/include/gui/ConsumerBase.h @@ -73,7 +73,7 @@ public: // their state to the dump by overriding the dumpLocked method, which is // called by these methods after locking the mutex. void dump(String8& result) const; - void dump(String8& result, const char* prefix, char* buffer, size_t SIZE) const; + void dump(String8& result, const char* prefix) const; // setFrameAvailableListener sets the listener object that will be notified // when a new frame becomes available. @@ -143,8 +143,7 @@ protected: // 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; + virtual void dumpLocked(String8& result, const char* prefix) const; // acquireBufferLocked fetches the next buffer from the BufferQueue and // updates the buffer slot for the buffer returned. @@ -161,17 +160,23 @@ protected: // Derived classes should override this method to perform any cleanup that // must take place when a buffer is released back to the BufferQueue. If // it is overridden the derived class's implementation must call - // ConsumerBase::releaseBufferLocked. - virtual status_t releaseBufferLocked(int buf, EGLDisplay display, - EGLSyncKHR eglFence); + // ConsumerBase::releaseBufferLocked.e + virtual status_t releaseBufferLocked(int slot, + const sp<GraphicBuffer> graphicBuffer, + EGLDisplay display, EGLSyncKHR eglFence); + + // returns true iff the slot still has the graphicBuffer in it. + bool stillTracking(int slot, const sp<GraphicBuffer> graphicBuffer); // addReleaseFence* adds the sync points associated with a fence to the set // of sync points that must be reached before the buffer in the given slot // may be used after the slot has been released. This should be called by // derived classes each time some asynchronous work is kicked off that // references the buffer. - status_t addReleaseFence(int slot, const sp<Fence>& fence); - status_t addReleaseFenceLocked(int slot, const sp<Fence>& fence); + status_t addReleaseFence(int slot, + const sp<GraphicBuffer> graphicBuffer, const sp<Fence>& fence); + status_t addReleaseFenceLocked(int slot, + const sp<GraphicBuffer> graphicBuffer, const sp<Fence>& fence); // Slot contains the information and object references that // ConsumerBase maintains about a BufferQueue buffer slot. @@ -185,6 +190,9 @@ protected: // overwritten. The buffer can be dequeued before the fence signals; // the producer is responsible for delaying writes until it signals. sp<Fence> mFence; + + // the frame number of the last acquired frame for this slot + uint64_t mFrameNumber; }; // mSlots stores the buffers that have been allocated by the BufferQueue diff --git a/include/gui/CpuConsumer.h b/include/gui/CpuConsumer.h index bf9918e..3c178ef 100644 --- a/include/gui/CpuConsumer.h +++ b/include/gui/CpuConsumer.h @@ -25,7 +25,6 @@ #include <utils/Vector.h> #include <utils/threads.h> -#define ANDROID_GRAPHICS_CPUCONSUMER_JNI_ID "mCpuConsumer" namespace android { @@ -73,6 +72,18 @@ class CpuConsumer : public ConsumerBase // log messages. void setName(const String8& name); + // setDefaultBufferSize is used to set the size of buffers returned by + // requestBuffers when a width and height of zero is requested. + // A call to setDefaultBufferSize() may trigger requestBuffers() to + // be called from the client. Default size is 1x1. + 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); + // Gets the next graphics buffer from the producer and locks it for CPU use, // filling out the passed-in locked buffer structure with the native pointer // and metadata. Returns BAD_VALUE if no new buffer is available, and diff --git a/include/gui/GLConsumer.h b/include/gui/GLConsumer.h index f0a75dc..031684e 100644 --- a/include/gui/GLConsumer.h +++ b/include/gui/GLConsumer.h @@ -233,8 +233,7 @@ protected: // dumpLocked overrides the ConsumerBase method to dump GLConsumer- // specific info in addition to the ConsumerBase behavior. - virtual void dumpLocked(String8& result, const char* prefix, char* buffer, - size_t size) const; + virtual void dumpLocked(String8& result, const char* prefix) const; // acquireBufferLocked overrides the ConsumerBase method to update the // mEglSlots array in addition to the ConsumerBase behavior. @@ -242,11 +241,13 @@ protected: // 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); + virtual status_t releaseBufferLocked(int slot, + const sp<GraphicBuffer> graphicBuffer, + EGLDisplay display, EGLSyncKHR eglFence); - status_t releaseBufferLocked(int buf, EGLSyncKHR eglFence) { - return releaseBufferLocked(buf, mEglDisplay, eglFence); + status_t releaseBufferLocked(int slot, + const sp<GraphicBuffer> graphicBuffer, EGLSyncKHR eglFence) { + return releaseBufferLocked(slot, graphicBuffer, mEglDisplay, eglFence); } static bool isExternalFormat(uint32_t format); diff --git a/include/media/hardware/HDCPAPI.h b/include/media/hardware/HDCPAPI.h index 147448e..b3f4222 100644 --- a/include/media/hardware/HDCPAPI.h +++ b/include/media/hardware/HDCPAPI.h @@ -19,6 +19,7 @@ #define HDCP_API_H_ #include <utils/Errors.h> +#include <system/window.h> namespace android { @@ -90,6 +91,20 @@ struct HDCPModule { return INVALID_OPERATION; } + // Encrypt data according to the HDCP spec. "size" bytes of data starting + // at location "offset" are available in "buffer" (buffer handle). "size" + // may not be a multiple of 128 bits (16 bytes). An equal number of + // encrypted bytes should be written to the buffer at "outData" (virtual + // address). 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 encryptNative( + buffer_handle_t buffer, size_t offset, size_t size, + uint32_t streamCTR, uint64_t *outInputCTR, void *outData) { + return INVALID_OPERATION; + } // DECRYPTION only: // Decrypt data according to the HDCP spec. // "size" bytes of encrypted data are available at "inData" diff --git a/include/media/hardware/HardwareAPI.h b/include/media/hardware/HardwareAPI.h index cc43bf6..a6a849d 100644 --- a/include/media/hardware/HardwareAPI.h +++ b/include/media/hardware/HardwareAPI.h @@ -18,7 +18,8 @@ #define HARDWARE_API_H_ -#include <OMXPluginBase.h> +#include <media/hardware/OMXPluginBase.h> +#include <media/hardware/MetadataBufferType.h> #include <system/window.h> #include <utils/RefBase.h> @@ -73,6 +74,13 @@ struct StoreMetaDataInBuffersParams { OMX_BOOL bStoreMetaData; }; +// Meta data buffer layout used to transport output frames to the decoder for +// dynamic buffer handling. +struct VideoDecoderOutputMetaData { + MetadataBufferType eType; + buffer_handle_t pHandle; +}; + // A pointer to this struct is passed to OMX_SetParameter when the extension // index for the 'OMX.google.android.index.useAndroidNativeBuffer' extension is // given. This call will only be performed if a prior call was made with the diff --git a/include/media/openmax/OMX_IVCommon.h b/include/media/openmax/OMX_IVCommon.h index 85bf00d..96a4396 100644 --- a/include/media/openmax/OMX_IVCommon.h +++ b/include/media/openmax/OMX_IVCommon.h @@ -161,6 +161,7 @@ typedef enum OMX_COLOR_FORMATTYPE { OMX_QCOM_COLOR_FormatYVU420SemiPlanar = 0x7FA30C00, OMX_QCOM_COLOR_FormatYUV420PackedSemiPlanar64x32Tile2m8ka = 0x7FA30C03, OMX_SEC_COLOR_FormatNV12Tiled = 0x7FC00002, + OMX_QCOM_COLOR_FormatYUV420PackedSemiPlanar32m = 0x7FA30C04, OMX_COLOR_FormatMax = 0x7FFFFFFF } OMX_COLOR_FORMATTYPE; diff --git a/include/media/openmax/OMX_Video.h b/include/media/openmax/OMX_Video.h index 4f8485d..4441a7a 100644 --- a/include/media/openmax/OMX_Video.h +++ b/include/media/openmax/OMX_Video.h @@ -85,7 +85,8 @@ typedef enum OMX_VIDEO_CODINGTYPE { OMX_VIDEO_CodingRV, /**< all versions of Real Video */ OMX_VIDEO_CodingAVC, /**< H.264/AVC */ OMX_VIDEO_CodingMJPEG, /**< Motion JPEG */ - OMX_VIDEO_CodingVPX, /**< Google VPX, formerly known as On2 VP8 */ + OMX_VIDEO_CodingVP8, /**< Google VP8, formerly known as On2 VP8 */ + OMX_VIDEO_CodingVP9, /**< Google VP9 */ OMX_VIDEO_CodingKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */ OMX_VIDEO_CodingVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */ OMX_VIDEO_CodingMax = 0x7FFFFFFF diff --git a/include/media/openmax/OMX_VideoExt.h b/include/media/openmax/OMX_VideoExt.h index 5e79b47..fa24168 100644 --- a/include/media/openmax/OMX_VideoExt.h +++ b/include/media/openmax/OMX_VideoExt.h @@ -58,12 +58,6 @@ typedef struct OMX_NALSTREAMFORMATTYPE{ OMX_NALUFORMATSTYPE eNaluFormat; } OMX_NALSTREAMFORMATTYPE; -/** Enum for standard video codingtype extensions */ -typedef enum OMX_VIDEO_CODINGEXTTYPE { - OMX_VIDEO_ExtCodingUnused = OMX_VIDEO_CodingKhronosExtensions, - OMX_VIDEO_CodingVP8, /**< VP8/WebM */ -} OMX_VIDEO_CODINGEXTTYPE; - /** VP8 profiles */ typedef enum OMX_VIDEO_VP8PROFILETYPE { OMX_VIDEO_VP8ProfileMain = 0x01, diff --git a/include/powermanager/IPowerManager.h b/include/powermanager/IPowerManager.h index 1723f04..e21e6a8 100644 --- a/include/powermanager/IPowerManager.h +++ b/include/powermanager/IPowerManager.h @@ -30,7 +30,8 @@ class IPowerManager : public IInterface public: DECLARE_META_INTERFACE(PowerManager); - virtual status_t acquireWakeLock(int flags, const sp<IBinder>& lock, const String16& tag) = 0; + virtual status_t acquireWakeLock(int flags, const sp<IBinder>& lock, const String16& tag, + const String16& packageName) = 0; virtual status_t releaseWakeLock(const sp<IBinder>& lock, int flags) = 0; }; diff --git a/include/private/binder/Static.h b/include/private/binder/Static.h index 5b0f9fc..6a03594 100644 --- a/include/private/binder/Static.h +++ b/include/private/binder/Static.h @@ -27,6 +27,9 @@ namespace android { +// For TextStream.cpp +extern Vector<int32_t> gTextBuffers; + // For ProcessState.cpp extern Mutex gProcessMutex; extern sp<ProcessState> gProcess; diff --git a/include/private/utils/Static.h b/include/private/utils/Static.h deleted file mode 100644 index d95ae0d..0000000 --- a/include/private/utils/Static.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2008 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. - */ - -// All static variables go here, to control initialization and -// destruction order in the library. - -#include <utils/threads.h> -#include <utils/KeyedVector.h> - -namespace android { -// For TextStream.cpp -extern Vector<int32_t> gTextBuffers; - -// For String8.cpp -extern void initialize_string8(); -extern void terminate_string8(); - -// For String16.cpp -extern void initialize_string16(); -extern void terminate_string16(); - -} // namespace android diff --git a/include/ui/Rect.h b/include/ui/Rect.h index 47d37b6..6cf64eb 100644 --- a/include/ui/Rect.h +++ b/include/ui/Rect.h @@ -35,14 +35,25 @@ public: inline Rect() { } + inline Rect(int32_t w, int32_t h) { - left = top = 0; right = w; bottom = h; + 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; right = r; bottom = b; + left = l; + top = t; + right = r; + bottom = b; } + inline Rect(const Point& lt, const Point& rb) { - left = lt.x; top = lt.y; right = rb.x; bottom = rb.y; + left = lt.x; + top = lt.y; + right = rb.x; + bottom = rb.y; } void makeInvalid(); @@ -53,43 +64,36 @@ public: // a valid rectangle has a non negative width and height inline bool isValid() const { - return (width()>=0) && (height()>=0); + return (getWidth() >= 0) && (getHeight() >= 0); } // an empty rect has a zero width or height, or is invalid inline bool isEmpty() const { - return (width()<=0) || (height()<=0); - } - - inline void set(const Rect& rhs) { - operator = (rhs); + return (getWidth() <= 0) || (getHeight() <= 0); } // rectangle's width inline int32_t getWidth() const { - return right-left; + return right - left; } - + // rectangle's height inline int32_t getHeight() const { - return bottom-top; + return bottom - top; } inline Rect getBounds() const { - return Rect(right-left, bottom-top); + return Rect(right - left, bottom - top); } - inline int32_t width() const { return getWidth(); } - inline int32_t height() const { return getHeight(); } - void setLeftTop(const Point& lt) { left = lt.x; - top = lt.y; + top = lt.y; } void setRightBottom(const Point& rb) { right = rb.x; - bottom = rb.y; + bottom = rb.y; } // the following 4 functions return the 4 corners of the rect as Point @@ -120,6 +124,16 @@ public: // vectors. bool operator < (const Rect& rhs) const; + const Rect operator + (const Point& rhs) const; + const Rect operator - (const Point& rhs) const; + + Rect& operator += (const Point& rhs) { + return offsetBy(rhs.x, rhs.y); + } + Rect& operator -= (const Point& rhs) { + return offsetBy(-rhs.x, -rhs.y); + } + Rect& offsetToOrigin() { right -= left; bottom -= top; @@ -132,22 +146,11 @@ public: Rect& offsetBy(const Point& dp) { return offsetBy(dp.x, dp.y); } - Rect& operator += (const Point& rhs) { - return offsetBy(rhs.x, rhs.y); - } - Rect& operator -= (const Point& rhs) { - return offsetBy(-rhs.x, -rhs.y); - } - const Rect operator + (const Point& rhs) const; - const Rect operator - (const Point& rhs) const; - void translate(int32_t dx, int32_t dy) { // legacy, don't use. - offsetBy(dx, dy); - } + Rect& offsetTo(int32_t x, int32_t y); + Rect& offsetBy(int32_t x, int32_t y); - Rect& offsetTo(int32_t x, int32_t y); - Rect& offsetBy(int32_t x, int32_t y); - bool intersect(const Rect& with, Rect* result) const; + bool intersect(const Rect& with, Rect* result) const; // Create a new Rect by transforming this one using a graphics HAL // transform. This rectangle is defined in a coordinate space starting at @@ -156,6 +159,15 @@ public: // (height, width). Otherwise the output rectangle is in the same space as // the input. Rect transform(uint32_t xform, int32_t width, int32_t height) const; + + // this calculates (Region(*this) - exclude).bounds() efficiently + Rect reduce(const Rect& exclude) const; + + + // for backward compatibility + inline int32_t width() const { return getWidth(); } + inline int32_t height() const { return getHeight(); } + inline void set(const Rect& rhs) { operator = (rhs); } }; ANDROID_BASIC_TYPES_TRAITS(Rect) diff --git a/include/utils/BitSet.h b/include/utils/BitSet.h index e189d0c..19c03d1 100644 --- a/include/utils/BitSet.h +++ b/include/utils/BitSet.h @@ -101,6 +101,20 @@ struct BitSet32 { inline bool operator== (const BitSet32& other) const { return value == other.value; } inline bool operator!= (const BitSet32& other) const { return value != other.value; } + inline BitSet32 operator& (const BitSet32& other) const { + return BitSet32(value & other.value); + } + inline BitSet32& operator&= (const BitSet32& other) { + value &= other.value; + return *this; + } + inline BitSet32 operator| (const BitSet32& other) const { + return BitSet32(value | other.value); + } + inline BitSet32& operator|= (const BitSet32& other) { + value |= other.value; + return *this; + } }; ANDROID_BASIC_TYPES_TRAITS(BitSet32) diff --git a/include/utils/Debug.h b/include/utils/Debug.h index d9ed32d..08893bd 100644 --- a/include/utils/Debug.h +++ b/include/utils/Debug.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef ANDROID_DEBUG_H -#define ANDROID_DEBUG_H +#ifndef ANDROID_UTILS_DEBUG_H +#define ANDROID_UTILS_DEBUG_H #include <stdint.h> #include <sys/types.h> @@ -43,28 +43,6 @@ struct CompileTimeIfElse<false, LHS, RHS> { typedef RHS TYPE; }; #endif // --------------------------------------------------------------------------- - -#ifdef __cplusplus -extern "C" { -#endif - -const char* stringForIndent(int32_t indentLevel); - -typedef void (*debugPrintFunc)(void* cookie, const char* txt); - -void printTypeCode(uint32_t typeCode, - debugPrintFunc func = 0, void* cookie = 0); - -void printHexData(int32_t indent, const void *buf, size_t length, - size_t bytesPerLine=16, int32_t singleLineBytesCutoff=16, - size_t alignment=0, bool cArrayStyle=false, - debugPrintFunc func = 0, void* cookie = 0); - -#ifdef __cplusplus -} -#endif - -// --------------------------------------------------------------------------- }; // namespace android -#endif // ANDROID_DEBUG_H +#endif // ANDROID_UTILS_DEBUG_H diff --git a/include/utils/GenerationCache.h b/include/utils/GenerationCache.h deleted file mode 100644 index 40722d1..0000000 --- a/include/utils/GenerationCache.h +++ /dev/null @@ -1,247 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef ANDROID_UTILS_GENERATION_CACHE_H -#define ANDROID_UTILS_GENERATION_CACHE_H - -#include <utils/KeyedVector.h> -#include <utils/RefBase.h> - -namespace android { - -/** - * GenerationCache callback used when an item is removed - */ -template<typename EntryKey, typename EntryValue> -class OnEntryRemoved { -public: - virtual ~OnEntryRemoved() { }; - virtual void operator()(EntryKey& key, EntryValue& value) = 0; -}; // class OnEntryRemoved - -template<typename EntryKey, typename EntryValue> -struct Entry: public LightRefBase<Entry<EntryKey, EntryValue> > { - Entry(const Entry<EntryKey, EntryValue>& e) : - key(e.key), value(e.value), - parent(e.parent), child(e.child) { } - Entry(const EntryKey& key, const EntryValue& value) : - key(key), value(value) { } - - EntryKey key; - EntryValue value; - - sp<Entry<EntryKey, EntryValue> > parent; // next older entry - sp<Entry<EntryKey, EntryValue> > child; // next younger entry -}; // struct Entry - -/** - * A LRU type cache - */ -template<typename K, typename V> -class GenerationCache { -public: - GenerationCache(uint32_t maxCapacity); - virtual ~GenerationCache(); - - enum Capacity { - kUnlimitedCapacity, - }; - - void setOnEntryRemovedListener(OnEntryRemoved<K, V>* listener); - - size_t size() const; - - void clear(); - - bool contains(const K& key) const; - const K& getKeyAt(size_t index) const; - const V& getValueAt(size_t index) const; - - const V& get(const K& key); - bool put(const K& key, const V& value); - - void removeAt(ssize_t index); - bool remove(const K& key); - bool removeOldest(); - -private: - KeyedVector<K, sp<Entry<K, V> > > mCache; - uint32_t mMaxCapacity; - - OnEntryRemoved<K, V>* mListener; - - sp<Entry<K, V> > mOldest; - sp<Entry<K, V> > mYoungest; - - void attachToCache(const sp<Entry<K, V> >& entry); - void detachFromCache(const sp<Entry<K, V> >& entry); - - const V mNullValue; -}; // class GenerationCache - -template<typename K, typename V> -GenerationCache<K, V>::GenerationCache(uint32_t maxCapacity): mMaxCapacity(maxCapacity), - mListener(NULL), mNullValue(NULL) { -}; - -template<typename K, typename V> -GenerationCache<K, V>::~GenerationCache() { - clear(); -}; - -template<typename K, typename V> -uint32_t GenerationCache<K, V>::size() const { - return mCache.size(); -} - -/** - * Should be set by the user of the Cache so that the callback is called whenever an item is - * removed from the cache - */ -template<typename K, typename V> -void GenerationCache<K, V>::setOnEntryRemovedListener(OnEntryRemoved<K, V>* listener) { - mListener = listener; -} - -template<typename K, typename V> -void GenerationCache<K, V>::clear() { - if (mListener) { - for (uint32_t i = 0; i < mCache.size(); i++) { - sp<Entry<K, V> > entry = mCache.valueAt(i); - if (mListener) { - (*mListener)(entry->key, entry->value); - } - } - } - mCache.clear(); - mYoungest.clear(); - mOldest.clear(); -} - -template<typename K, typename V> -bool GenerationCache<K, V>::contains(const K& key) const { - return mCache.indexOfKey(key) >= 0; -} - -template<typename K, typename V> -const K& GenerationCache<K, V>::getKeyAt(size_t index) const { - return mCache.keyAt(index); -} - -template<typename K, typename V> -const V& GenerationCache<K, V>::getValueAt(size_t index) const { - return mCache.valueAt(index)->value; -} - -template<typename K, typename V> -const V& GenerationCache<K, V>::get(const K& key) { - ssize_t index = mCache.indexOfKey(key); - if (index >= 0) { - const sp<Entry<K, V> >& entry = mCache.valueAt(index); - detachFromCache(entry); - attachToCache(entry); - return entry->value; - } - - return mNullValue; -} - -template<typename K, typename V> -bool GenerationCache<K, V>::put(const K& key, const V& value) { - if (mMaxCapacity != kUnlimitedCapacity && mCache.size() >= mMaxCapacity) { - removeOldest(); - } - - ssize_t index = mCache.indexOfKey(key); - if (index < 0) { - sp<Entry<K, V> > entry = new Entry<K, V>(key, value); - mCache.add(key, entry); - attachToCache(entry); - return true; - } - - return false; -} - -template<typename K, typename V> -bool GenerationCache<K, V>::remove(const K& key) { - ssize_t index = mCache.indexOfKey(key); - if (index >= 0) { - removeAt(index); - return true; - } - - return false; -} - -template<typename K, typename V> -void GenerationCache<K, V>::removeAt(ssize_t index) { - sp<Entry<K, V> > entry = mCache.valueAt(index); - if (mListener) { - (*mListener)(entry->key, entry->value); - } - mCache.removeItemsAt(index, 1); - detachFromCache(entry); -} - -template<typename K, typename V> -bool GenerationCache<K, V>::removeOldest() { - if (mOldest.get()) { - ssize_t index = mCache.indexOfKey(mOldest->key); - if (index >= 0) { - removeAt(index); - return true; - } - ALOGE("GenerationCache: removeOldest failed to find the item in the cache " - "with the given key, but we know it must be in there. " - "Is the key comparator kaput?"); - } - - return false; -} - -template<typename K, typename V> -void GenerationCache<K, V>::attachToCache(const sp<Entry<K, V> >& entry) { - if (!mYoungest.get()) { - mYoungest = mOldest = entry; - } else { - entry->parent = mYoungest; - mYoungest->child = entry; - mYoungest = entry; - } -} - -template<typename K, typename V> -void GenerationCache<K, V>::detachFromCache(const sp<Entry<K, V> >& entry) { - if (entry->parent.get()) { - entry->parent->child = entry->child; - } else { - mOldest = entry->child; - } - - if (entry->child.get()) { - entry->child->parent = entry->parent; - } else { - mYoungest = entry->parent; - } - - entry->parent.clear(); - entry->child.clear(); -} - -}; // namespace android - -#endif // ANDROID_UTILS_GENERATION_CACHE_H diff --git a/include/utils/Looper.h b/include/utils/Looper.h index d4a0067..2e0651a 100644 --- a/include/utils/Looper.h +++ b/include/utils/Looper.h @@ -297,6 +297,13 @@ public: void removeMessages(const sp<MessageHandler>& handler, int what); /** + * Return whether this looper's thread is currently idling -- that is, whether it + * stopped waiting for more work to do. Note that this is intrinsically racy, since + * its state can change before you get the result back. + */ + bool isIdling() const; + + /** * Prepares a looper associated with the calling thread, and returns it. * If the thread already has a looper, it is returned. Otherwise, a new * one is created, associated with the thread, and returned. @@ -353,6 +360,10 @@ private: Vector<MessageEnvelope> mMessageEnvelopes; // guarded by mLock bool mSendingMessage; // guarded by mLock + // Whether we are currently waiting for work. Not protected by a lock, + // any use of it is racy anyway. + volatile bool mIdling; + int mEpollFd; // immutable // Locked list of file descriptor monitoring requests. diff --git a/include/utils/LruCache.h b/include/utils/LruCache.h index 302b929..053bfaf 100644 --- a/include/utils/LruCache.h +++ b/include/utils/LruCache.h @@ -18,12 +18,19 @@ #define ANDROID_UTILS_LRU_CACHE_H #include <utils/BasicHashtable.h> -#include <utils/GenerationCache.h> #include <utils/UniquePtr.h> namespace android { -// OnEntryRemoved is defined in GenerationCache.h, but maybe should move here. +/** + * GenerationCache callback used when an item is removed + */ +template<typename EntryKey, typename EntryValue> +class OnEntryRemoved { +public: + virtual ~OnEntryRemoved() { }; + virtual void operator()(EntryKey& key, EntryValue& value) = 0; +}; // class OnEntryRemoved template <typename TKey, typename TValue> class LruCache { diff --git a/include/utils/String16.h b/include/utils/String16.h index fe06c57..d131bfc 100644 --- a/include/utils/String16.h +++ b/include/utils/String16.h @@ -41,7 +41,16 @@ class TextOutput; class String16 { public: + /* use String16(StaticLinkage) if you're statically linking against + * libutils and declaring an empty static String16, e.g.: + * + * static String16 sAStaticEmptyString(String16::kEmptyString); + * static String16 sAnotherStaticEmptyString(sAStaticEmptyString); + */ + enum StaticLinkage { kEmptyString }; + String16(); + explicit String16(StaticLinkage); String16(const String16& o); String16(const String16& o, size_t len, @@ -117,8 +126,6 @@ private: // require any change to the underlying SharedBuffer contents or reference count. ANDROID_TRIVIAL_MOVE_TRAIT(String16) -TextOutput& operator<<(TextOutput& to, const String16& val); - // --------------------------------------------------------------------------- // No user servicable parts below. diff --git a/include/utils/String8.h b/include/utils/String8.h index 335e7f1..ef59470 100644 --- a/include/utils/String8.h +++ b/include/utils/String8.h @@ -37,7 +37,16 @@ class TextOutput; class String8 { public: + /* use String8(StaticLinkage) if you're statically linking against + * libutils and declaring an empty static String8, e.g.: + * + * static String8 sAStaticEmptyString(String8::kEmptyString); + * static String8 sAnotherStaticEmptyString(sAStaticEmptyString); + */ + enum StaticLinkage { kEmptyString }; + String8(); + explicit String8(StaticLinkage); String8(const String8& o); explicit String8(const char* o); explicit String8(const char* o, size_t numChars); @@ -224,8 +233,6 @@ private: // require any change to the underlying SharedBuffer contents or reference count. ANDROID_TRIVIAL_MOVE_TRAIT(String8) -TextOutput& operator<<(TextOutput& to, const String16& val); - // --------------------------------------------------------------------------- // No user servicable parts below. diff --git a/include/utils/StringArray.h b/include/utils/StringArray.h deleted file mode 100644 index c244587..0000000 --- a/include/utils/StringArray.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (C) 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 - * - * 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. - */ - -// -// Sortable array of strings. STL-ish, but STL-free. -// -#ifndef _LIBS_UTILS_STRING_ARRAY_H -#define _LIBS_UTILS_STRING_ARRAY_H - -#include <stdlib.h> -#include <string.h> - -namespace android { - -// -// An expanding array of strings. Add, get, sort, delete. -// -class StringArray { -public: - StringArray(); - virtual ~StringArray(); - - // - // Add a string. A copy of the string is made. - // - bool push_back(const char* str); - - // - // Delete an entry. - // - void erase(int idx); - - // - // Sort the array. - // - void sort(int (*compare)(const void*, const void*)); - - // - // Pass this to the sort routine to do an ascending alphabetical sort. - // - static int cmpAscendingAlpha(const void* pstr1, const void* pstr2); - - // - // Get the #of items in the array. - // - inline int size(void) const { return mCurrent; } - - // - // Return entry N. - // [should use operator[] here] - // - const char* getEntry(int idx) const { - return (unsigned(idx) >= unsigned(mCurrent)) ? NULL : mArray[idx]; - } - - // - // Set entry N to specified string. - // [should use operator[] here] - // - void setEntry(int idx, const char* str); - -private: - int mMax; - int mCurrent; - char** mArray; -}; - -}; // namespace android - -#endif // _LIBS_UTILS_STRING_ARRAY_H diff --git a/include/utils/StrongPointer.h b/include/utils/StrongPointer.h index 49fa3a8..aba9577 100644 --- a/include/utils/StrongPointer.h +++ b/include/utils/StrongPointer.h @@ -26,9 +26,6 @@ // --------------------------------------------------------------------------- namespace android { -class TextOutput; -TextOutput& printStrongPointer(TextOutput& to, const void* val); - template<typename T> class wp; // --------------------------------------------------------------------------- @@ -58,9 +55,8 @@ inline bool operator _op_ (const wp<U>& o) const { \ // --------------------------------------------------------------------------- -template <typename T> -class sp -{ +template<typename T> +class sp { public: inline sp() : m_ptr(0) { } @@ -110,92 +106,93 @@ private: #undef COMPARE -template <typename T> -TextOutput& operator<<(TextOutput& to, const sp<T>& val); - // --------------------------------------------------------------------------- // No user serviceable parts below here. template<typename T> sp<T>::sp(T* other) -: m_ptr(other) - { - if (other) other->incStrong(this); - } + : m_ptr(other) { + if (other) + other->incStrong(this); +} template<typename T> sp<T>::sp(const sp<T>& other) -: m_ptr(other.m_ptr) - { - if (m_ptr) m_ptr->incStrong(this); - } + : m_ptr(other.m_ptr) { + if (m_ptr) + m_ptr->incStrong(this); +} template<typename T> template<typename U> -sp<T>::sp(U* other) : m_ptr(other) -{ - if (other) ((T*)other)->incStrong(this); +sp<T>::sp(U* other) + : m_ptr(other) { + if (other) + ((T*) other)->incStrong(this); } template<typename T> template<typename U> sp<T>::sp(const sp<U>& other) -: m_ptr(other.m_ptr) - { - if (m_ptr) m_ptr->incStrong(this); - } + : m_ptr(other.m_ptr) { + if (m_ptr) + m_ptr->incStrong(this); +} template<typename T> -sp<T>::~sp() -{ - if (m_ptr) m_ptr->decStrong(this); +sp<T>::~sp() { + if (m_ptr) + m_ptr->decStrong(this); } template<typename T> -sp<T>& sp<T>::operator = (const sp<T>& other) { +sp<T>& sp<T>::operator =(const sp<T>& other) { T* otherPtr(other.m_ptr); - if (otherPtr) otherPtr->incStrong(this); - if (m_ptr) m_ptr->decStrong(this); + if (otherPtr) + otherPtr->incStrong(this); + if (m_ptr) + m_ptr->decStrong(this); m_ptr = otherPtr; return *this; } template<typename T> -sp<T>& sp<T>::operator = (T* other) -{ - if (other) other->incStrong(this); - if (m_ptr) m_ptr->decStrong(this); +sp<T>& sp<T>::operator =(T* other) { + if (other) + other->incStrong(this); + if (m_ptr) + m_ptr->decStrong(this); m_ptr = other; return *this; } template<typename T> template<typename U> -sp<T>& sp<T>::operator = (const sp<U>& other) -{ +sp<T>& sp<T>::operator =(const sp<U>& other) { T* otherPtr(other.m_ptr); - if (otherPtr) otherPtr->incStrong(this); - if (m_ptr) m_ptr->decStrong(this); + if (otherPtr) + otherPtr->incStrong(this); + if (m_ptr) + m_ptr->decStrong(this); m_ptr = otherPtr; return *this; } template<typename T> template<typename U> -sp<T>& sp<T>::operator = (U* other) -{ - if (other) ((T*)other)->incStrong(this); - if (m_ptr) m_ptr->decStrong(this); +sp<T>& sp<T>::operator =(U* other) { + if (other) + ((T*) other)->incStrong(this); + if (m_ptr) + m_ptr->decStrong(this); m_ptr = other; return *this; } -template<typename T> -void sp<T>::force_set(T* other) -{ +template<typename T> +void sp<T>::force_set(T* other) { other->forceIncStrong(this); m_ptr = other; } template<typename T> -void sp<T>::clear() -{ +void sp<T>::clear() { if (m_ptr) { m_ptr->decStrong(this); m_ptr = 0; @@ -207,12 +204,6 @@ void sp<T>::set_pointer(T* ptr) { m_ptr = ptr; } -template <typename T> -inline TextOutput& operator<<(TextOutput& to, const sp<T>& val) -{ - return printStrongPointer(to, val.get()); -} - }; // namespace android // --------------------------------------------------------------------------- diff --git a/include/utils/SystemClock.h b/include/utils/SystemClock.h index d75264c..01db340 100644 --- a/include/utils/SystemClock.h +++ b/include/utils/SystemClock.h @@ -22,7 +22,6 @@ namespace android { -int setCurrentTimeMillis(int64_t millis); int64_t uptimeMillis(); int64_t elapsedRealtime(); int64_t elapsedRealtimeNano(); diff --git a/include/utils/Timers.h b/include/utils/Timers.h index 92f66c9..d015421 100644 --- a/include/utils/Timers.h +++ b/include/utils/Timers.h @@ -103,43 +103,4 @@ int toMillisecondTimeoutDelay(nsecs_t referenceTime, nsecs_t timeoutTime); } // extern "C" #endif -// ------------------------------------------------------------------ -// C++ API - -#ifdef __cplusplus - -namespace android { -/* - * Time the duration of something. - * - * Includes some timeval manipulation functions. - */ -class DurationTimer { -public: - DurationTimer() {} - ~DurationTimer() {} - - // Start the timer. - void start(); - // Stop the timer. - void stop(); - // Get the duration in microseconds. - long long durationUsecs() const; - - // Subtract two timevals. Returns the difference (ptv1-ptv2) in - // microseconds. - static long long subtractTimevals(const struct timeval* ptv1, - const struct timeval* ptv2); - - // Add the specified amount of time to the timeval. - static void addToTimeval(struct timeval* ptv, long usec); - -private: - struct timeval mStartWhen; - struct timeval mStopWhen; -}; - -}; // android -#endif // def __cplusplus - #endif // _LIBS_UTILS_TIMERS_H diff --git a/include/utils/Trace.h b/include/utils/Trace.h index 49578c4..6ee343d 100644 --- a/include/utils/Trace.h +++ b/include/utils/Trace.h @@ -17,6 +17,8 @@ #ifndef ANDROID_TRACE_H #define ANDROID_TRACE_H +#ifdef HAVE_ANDROID_OS + #include <fcntl.h> #include <stdint.h> #include <stdio.h> @@ -57,4 +59,11 @@ private: }; // namespace android +#else // HAVE_ANDROID_OS + +#define ATRACE_NAME(...) +#define ATRACE_CALL() + +#endif // HAVE_ANDROID_OS + #endif // ANDROID_TRACE_H diff --git a/include/utils/VectorImpl.h b/include/utils/VectorImpl.h index 9bc50e6..21ad71c 100644 --- a/include/utils/VectorImpl.h +++ b/include/utils/VectorImpl.h @@ -105,16 +105,6 @@ protected: virtual void do_splat(void* dest, const void* item, size_t num) const = 0; virtual void do_move_forward(void* dest, const void* from, size_t num) const = 0; virtual void do_move_backward(void* dest, const void* from, size_t num) const = 0; - - // take care of FBC... - virtual void reservedVectorImpl1(); - virtual void reservedVectorImpl2(); - virtual void reservedVectorImpl3(); - virtual void reservedVectorImpl4(); - virtual void reservedVectorImpl5(); - virtual void reservedVectorImpl6(); - virtual void reservedVectorImpl7(); - virtual void reservedVectorImpl8(); private: void* _grow(size_t where, size_t amount); @@ -166,16 +156,6 @@ public: protected: virtual int do_compare(const void* lhs, const void* rhs) const = 0; - // take care of FBC... - virtual void reservedSortedVectorImpl1(); - virtual void reservedSortedVectorImpl2(); - virtual void reservedSortedVectorImpl3(); - virtual void reservedSortedVectorImpl4(); - virtual void reservedSortedVectorImpl5(); - virtual void reservedSortedVectorImpl6(); - virtual void reservedSortedVectorImpl7(); - virtual void reservedSortedVectorImpl8(); - private: ssize_t _indexOrderOf(const void* item, size_t* order = 0) const; diff --git a/include/utils/WorkQueue.h b/include/utils/WorkQueue.h deleted file mode 100644 index e3c75b2..0000000 --- a/include/utils/WorkQueue.h +++ /dev/null @@ -1,119 +0,0 @@ -/*] - * 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 _LIBS_UTILS_WORK_QUEUE_H -#define _LIBS_UTILS_WORK_QUEUE_H - -#include <utils/Errors.h> -#include <utils/Vector.h> -#include <utils/threads.h> - -namespace android { - -/* - * A threaded work queue. - * - * This class is designed to make it easy to run a bunch of isolated work - * units in parallel, using up to the specified number of threads. - * To use it, write a loop to post work units to the work queue, then synchronize - * on the queue at the end. - */ -class WorkQueue { -public: - class WorkUnit { - public: - WorkUnit() { } - virtual ~WorkUnit() { } - - /* - * Runs the work unit. - * If the result is 'true' then the work queue continues scheduling work as usual. - * If the result is 'false' then the work queue is canceled. - */ - virtual bool run() = 0; - }; - - /* Creates a work queue with the specified maximum number of work threads. */ - WorkQueue(size_t maxThreads, bool canCallJava = true); - - /* Destroys the work queue. - * Cancels pending work and waits for all remaining threads to complete. - */ - ~WorkQueue(); - - /* Posts a work unit to run later. - * If the work queue has been canceled or is already finished, returns INVALID_OPERATION - * and does not take ownership of the work unit (caller must destroy it itself). - * Otherwise, returns OK and takes ownership of the work unit (the work queue will - * destroy it automatically). - * - * For flow control, this method blocks when the size of the pending work queue is more - * 'backlog' times the number of threads. This condition reduces the rate of entry into - * the pending work queue and prevents it from growing much more rapidly than the - * work threads can actually handle. - * - * If 'backlog' is 0, then no throttle is applied. - */ - status_t schedule(WorkUnit* workUnit, size_t backlog = 2); - - /* Cancels all pending work. - * If the work queue is already finished, returns INVALID_OPERATION. - * If the work queue is already canceled, returns OK and does nothing else. - * Otherwise, returns OK, discards all pending work units and prevents additional - * work units from being scheduled. - * - * Call finish() after cancel() to wait for all remaining work to complete. - */ - status_t cancel(); - - /* Waits for all work to complete. - * If the work queue is already finished, returns INVALID_OPERATION. - * Otherwise, waits for all work to complete and returns OK. - */ - status_t finish(); - -private: - class WorkThread : public Thread { - public: - WorkThread(WorkQueue* workQueue, bool canCallJava); - virtual ~WorkThread(); - - private: - virtual bool threadLoop(); - - WorkQueue* const mWorkQueue; - }; - - status_t cancelLocked(); - bool threadLoop(); // called from each work thread - - const size_t mMaxThreads; - const bool mCanCallJava; - - Mutex mLock; - Condition mWorkChangedCondition; - Condition mWorkDequeuedCondition; - - bool mCanceled; - bool mFinished; - size_t mIdleThreads; - Vector<sp<WorkThread> > mWorkThreads; - Vector<WorkUnit*> mWorkUnits; -}; - -}; // namespace android - -#endif // _LIBS_UTILS_WORK_QUEUE_H diff --git a/include/utils/ZipFileCRO.h b/include/utils/ZipFileCRO.h deleted file mode 100644 index 3e42a95..0000000 --- a/include/utils/ZipFileCRO.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (C) 2008 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. - */ - -// -// C API for ead-only access to Zip archives, with minimal heap allocation. -// -#ifndef __LIBS_ZIPFILECRO_H -#define __LIBS_ZIPFILECRO_H - -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> - -#include <utils/Compat.h> - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * Trivial typedef to ensure that ZipFileCRO is not treated as a simple integer. - */ -typedef void* ZipFileCRO; - -/* - * Trivial typedef to ensure that ZipEntryCRO is not treated as a simple - * integer. We use NULL to indicate an invalid value. - */ -typedef void* ZipEntryCRO; - -extern ZipFileCRO ZipFileXRO_open(const char* path); - -extern void ZipFileCRO_destroy(ZipFileCRO zip); - -extern ZipEntryCRO ZipFileCRO_findEntryByName(ZipFileCRO zip, - const char* fileName); - -extern bool ZipFileCRO_getEntryInfo(ZipFileCRO zip, ZipEntryCRO entry, - int* pMethod, size_t* pUncompLen, - size_t* pCompLen, off64_t* pOffset, long* pModWhen, long* pCrc32); - -extern bool ZipFileCRO_uncompressEntry(ZipFileCRO zip, ZipEntryCRO entry, int fd); - -#ifdef __cplusplus -} -#endif - -#endif /*__LIBS_ZIPFILECRO_H*/ diff --git a/include/utils/ZipFileRO.h b/include/utils/ZipFileRO.h deleted file mode 100644 index 547e36a..0000000 --- a/include/utils/ZipFileRO.h +++ /dev/null @@ -1,262 +0,0 @@ -/* - * Copyright (C) 2007 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. - */ - -/* - * Read-only access to Zip archives, with minimal heap allocation. - * - * This is similar to the more-complete ZipFile class, but no attempt - * has been made to make them interchangeable. This class operates under - * a very different set of assumptions and constraints. - * - * One such assumption is that if you're getting file descriptors for - * use with this class as a child of a fork() operation, you must be on - * a pread() to guarantee correct operation. This is because pread() can - * atomically read at a file offset without worrying about a lock around an - * lseek() + read() pair. - */ -#ifndef __LIBS_ZIPFILERO_H -#define __LIBS_ZIPFILERO_H - -#include <utils/Compat.h> -#include <utils/Errors.h> -#include <utils/FileMap.h> -#include <utils/threads.h> - -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <time.h> - -namespace android { - -/* - * Trivial typedef to ensure that ZipEntryRO is not treated as a simple - * integer. We use NULL to indicate an invalid value. - */ -typedef void* ZipEntryRO; - -/* - * Open a Zip archive for reading. - * - * We want "open" and "find entry by name" to be fast operations, and we - * want to use as little memory as possible. We memory-map the file, - * and load a hash table with pointers to the filenames (which aren't - * null-terminated). The other fields are at a fixed offset from the - * filename, so we don't need to extract those (but we do need to byte-read - * and endian-swap them every time we want them). - * - * To speed comparisons when doing a lookup by name, we could make the mapping - * "private" (copy-on-write) and null-terminate the filenames after verifying - * the record structure. However, this requires a private mapping of - * every page that the Central Directory touches. Easier to tuck a copy - * of the string length into the hash table entry. - * - * NOTE: If this is used on file descriptors inherited from a fork() operation, - * you must be on a platform that implements pread() to guarantee correctness - * on the shared file descriptors. - */ -class ZipFileRO { -public: - ZipFileRO() - : mFd(-1), mFileName(NULL), mFileLength(-1), - mDirectoryMap(NULL), - mNumEntries(-1), mDirectoryOffset(-1), - mHashTableSize(-1), mHashTable(NULL) - {} - - ~ZipFileRO(); - - /* - * Open an archive. - */ - status_t open(const char* zipFileName); - - /* - * Find an entry, by name. Returns the entry identifier, or NULL if - * not found. - * - * If two entries have the same name, one will be chosen at semi-random. - */ - ZipEntryRO findEntryByName(const char* fileName) const; - - /* - * Return the #of entries in the Zip archive. - */ - int getNumEntries(void) const { - return mNumEntries; - } - - /* - * Return the Nth entry. Zip file entries are not stored in sorted - * order, and updated entries may appear at the end, so anyone walking - * the archive needs to avoid making ordering assumptions. We take - * that further by returning the Nth non-empty entry in the hash table - * rather than the Nth entry in the archive. - * - * Valid values are [0..numEntries). - * - * [This is currently O(n). If it needs to be fast we can allocate an - * additional data structure or provide an iterator interface.] - */ - ZipEntryRO findEntryByIndex(int idx) const; - - /* - * Copy the filename into the supplied buffer. Returns 0 on success, - * -1 if "entry" is invalid, or the filename length if it didn't fit. The - * length, and the returned string, include the null-termination. - */ - int getEntryFileName(ZipEntryRO entry, char* buffer, int bufLen) const; - - /* - * Get the vital stats for an entry. Pass in NULL pointers for anything - * you don't need. - * - * "*pOffset" holds the Zip file offset of the entry's data. - * - * Returns "false" if "entry" is bogus or if the data in the Zip file - * appears to be bad. - */ - bool getEntryInfo(ZipEntryRO entry, int* pMethod, size_t* pUncompLen, - size_t* pCompLen, off64_t* pOffset, long* pModWhen, long* pCrc32) const; - - /* - * Create a new FileMap object that maps a subset of the archive. For - * an uncompressed entry this effectively provides a pointer to the - * actual data, for a compressed entry this provides the input buffer - * for inflate(). - */ - FileMap* createEntryFileMap(ZipEntryRO entry) const; - - /* - * Uncompress the data into a buffer. Depending on the compression - * format, this is either an "inflate" operation or a memcpy. - * - * Use "uncompLen" from getEntryInfo() to determine the required - * buffer size. - * - * Returns "true" on success. - */ - bool uncompressEntry(ZipEntryRO entry, void* buffer) const; - - /* - * Uncompress the data to an open file descriptor. - */ - bool uncompressEntry(ZipEntryRO entry, int fd) const; - - /* Zip compression methods we support */ - enum { - kCompressStored = 0, // no compression - kCompressDeflated = 8, // standard deflate - }; - - /* - * Utility function: uncompress deflated data, buffer to buffer. - */ - static bool inflateBuffer(void* outBuf, const void* inBuf, - size_t uncompLen, size_t compLen); - - /* - * Utility function: uncompress deflated data, buffer to fd. - */ - static bool inflateBuffer(int fd, const void* inBuf, - size_t uncompLen, size_t compLen); - - /* - * Utility function to convert ZIP's time format to a timespec struct. - */ - static inline void zipTimeToTimespec(long when, struct tm* timespec) { - const long date = when >> 16; - timespec->tm_year = ((date >> 9) & 0x7F) + 80; // Zip is years since 1980 - timespec->tm_mon = (date >> 5) & 0x0F; - timespec->tm_mday = date & 0x1F; - - timespec->tm_hour = (when >> 11) & 0x1F; - timespec->tm_min = (when >> 5) & 0x3F; - timespec->tm_sec = (when & 0x1F) << 1; - } - - /* - * Some basic functions for raw data manipulation. "LE" means - * Little Endian. - */ - static inline unsigned short get2LE(const unsigned char* buf) { - return buf[0] | (buf[1] << 8); - } - static inline unsigned long get4LE(const unsigned char* buf) { - return buf[0] | (buf[1] << 8) | (buf[2] << 16) | (buf[3] << 24); - } - -private: - /* these are private and not defined */ - ZipFileRO(const ZipFileRO& src); - ZipFileRO& operator=(const ZipFileRO& src); - - /* locate and parse the central directory */ - bool mapCentralDirectory(void); - - /* parse the archive, prepping internal structures */ - bool parseZipArchive(void); - - /* add a new entry to the hash table */ - void addToHash(const char* str, int strLen, unsigned int hash); - - /* compute string hash code */ - static unsigned int computeHash(const char* str, int len); - - /* convert a ZipEntryRO back to a hash table index */ - int entryToIndex(const ZipEntryRO entry) const; - - /* - * One entry in the hash table. - */ - typedef struct HashEntry { - const char* name; - unsigned short nameLen; - //unsigned int hash; - } HashEntry; - - /* open Zip archive */ - int mFd; - - /* Lock for handling the file descriptor (seeks, etc) */ - mutable Mutex mFdLock; - - /* zip file name */ - char* mFileName; - - /* length of file */ - size_t mFileLength; - - /* mapped file */ - FileMap* mDirectoryMap; - - /* number of entries in the Zip archive */ - int mNumEntries; - - /* CD directory offset in the Zip archive */ - off64_t mDirectoryOffset; - - /* - * We know how many entries are in the Zip archive, so we have a - * fixed-size hash table. We probe for an empty slot. - */ - int mHashTableSize; - HashEntry* mHashTable; -}; - -}; // namespace android - -#endif /*__LIBS_ZIPFILERO_H*/ diff --git a/include/utils/ZipUtils.h b/include/utils/ZipUtils.h deleted file mode 100644 index 42c42b6..0000000 --- a/include/utils/ZipUtils.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (C) 2007 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. - */ - -// -// Miscellaneous zip/gzip utility functions. -// -#ifndef __LIBS_ZIPUTILS_H -#define __LIBS_ZIPUTILS_H - -#include <stdio.h> - -namespace android { - -/* - * Container class for utility functions, primarily for namespace reasons. - */ -class ZipUtils { -public: - /* - * General utility function for uncompressing "deflate" data from a file - * to a buffer. - */ - static bool inflateToBuffer(int fd, void* buf, long uncompressedLen, - long compressedLen); - static bool inflateToBuffer(FILE* fp, void* buf, long uncompressedLen, - long compressedLen); - - /* - * Someday we might want to make this generic and handle bzip2 ".bz2" - * files too. - * - * We could declare gzip to be a sub-class of zip that has exactly - * one always-compressed entry, but we currently want to treat Zip - * and gzip as distinct, so there's no value. - * - * The zlib library has some gzip utilities, but it has no interface - * for extracting the uncompressed length of the file (you do *not* - * want to gzseek to the end). - * - * Pass in a seeked file pointer for the gzip file. If this is a gzip - * file, we set our return values appropriately and return "true" with - * the file seeked to the start of the compressed data. - */ - static bool examineGzip(FILE* fp, int* pCompressionMethod, - long* pUncompressedLen, long* pCompressedLen, unsigned long* pCRC32); - -private: - ZipUtils() {} - ~ZipUtils() {} -}; - -}; // namespace android - -#endif /*__LIBS_ZIPUTILS_H*/ diff --git a/include/utils/misc.h b/include/utils/misc.h index f1aa432..6cccec3 100644 --- a/include/utils/misc.h +++ b/include/utils/misc.h @@ -20,7 +20,6 @@ #ifndef _LIBS_UTILS_MISC_H #define _LIBS_UTILS_MISC_H -#include <sys/time.h> #include <utils/Endian.h> /* get #of elements in a static array */ @@ -30,26 +29,6 @@ namespace android { -/* - * Some utility functions for working with files. These could be made - * part of a "File" class. - */ -typedef enum FileType { - kFileTypeUnknown = 0, - kFileTypeNonexistent, // i.e. ENOENT - kFileTypeRegular, - kFileTypeDirectory, - kFileTypeCharDev, - kFileTypeBlockDev, - kFileTypeFifo, - kFileTypeSymlink, - kFileTypeSocket, -} FileType; -/* get the file's type; follows symlinks */ -FileType getFileType(const char* fileName); -/* get the file's modification date; returns -1 w/errno set on failure */ -time_t getFileModDate(const char* fileName); - typedef void (*sysprop_change_callback)(void); void add_sysprop_change_callback(sysprop_change_callback cb, int priority); void report_sysprop_change(); |