summaryrefslogtreecommitdiffstats
path: root/libs/ui
diff options
context:
space:
mode:
Diffstat (limited to 'libs/ui')
-rw-r--r--libs/ui/Android.mk9
-rw-r--r--libs/ui/Fence.cpp121
-rw-r--r--libs/ui/FramebufferNativeWindow.cpp71
-rw-r--r--libs/ui/GraphicBuffer.cpp7
-rw-r--r--libs/ui/GraphicBufferAllocator.cpp132
-rw-r--r--libs/ui/Region.cpp213
-rw-r--r--libs/ui/UiConfig.cpp36
7 files changed, 442 insertions, 147 deletions
diff --git a/libs/ui/Android.mk b/libs/ui/Android.mk
index 5aff7a4..0d2e44c 100644
--- a/libs/ui/Android.mk
+++ b/libs/ui/Android.mk
@@ -16,18 +16,21 @@ LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES:= \
+ Fence.cpp \
FramebufferNativeWindow.cpp \
GraphicBuffer.cpp \
GraphicBufferAllocator.cpp \
GraphicBufferMapper.cpp \
PixelFormat.cpp \
Rect.cpp \
- Region.cpp
+ Region.cpp \
+ UiConfig.cpp
LOCAL_SHARED_LIBRARIES := \
libcutils \
- libutils \
- libhardware
+ libhardware \
+ libsync \
+ libutils
ifneq ($(BOARD_FRAMEBUFFER_FORCE_FORMAT),)
LOCAL_CFLAGS += -DFRAMEBUFFER_FORCE_FORMAT=$(BOARD_FRAMEBUFFER_FORCE_FORMAT)
diff --git a/libs/ui/Fence.cpp b/libs/ui/Fence.cpp
new file mode 100644
index 0000000..d214b97
--- /dev/null
+++ b/libs/ui/Fence.cpp
@@ -0,0 +1,121 @@
+/*
+ * 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.
+ */
+
+#define LOG_TAG "Fence"
+#define ATRACE_TAG ATRACE_TAG_GRAPHICS
+//#define LOG_NDEBUG 0
+
+#include <sync/sync.h>
+#include <ui/Fence.h>
+#include <unistd.h>
+#include <utils/Log.h>
+#include <utils/Trace.h>
+
+namespace android {
+
+const sp<Fence> Fence::NO_FENCE = sp<Fence>();
+
+Fence::Fence() :
+ mFenceFd(-1) {
+}
+
+Fence::Fence(int fenceFd) :
+ mFenceFd(fenceFd) {
+}
+
+Fence::~Fence() {
+ if (mFenceFd != -1) {
+ close(mFenceFd);
+ }
+}
+
+status_t Fence::wait(unsigned int timeout) {
+ ATRACE_CALL();
+ if (mFenceFd == -1) {
+ return NO_ERROR;
+ }
+ int err = sync_wait(mFenceFd, timeout);
+ return err < 0 ? -errno : status_t(NO_ERROR);
+}
+
+status_t Fence::waitForever(unsigned int warningTimeout, const char* logname) {
+ ATRACE_CALL();
+ if (mFenceFd == -1) {
+ return NO_ERROR;
+ }
+ int err = sync_wait(mFenceFd, warningTimeout);
+ if (err < 0 && errno == ETIME) {
+ ALOGE("%s: fence %d didn't signal in %u ms", logname, mFenceFd,
+ warningTimeout);
+ err = sync_wait(mFenceFd, TIMEOUT_NEVER);
+ }
+ return err < 0 ? -errno : status_t(NO_ERROR);
+}
+
+sp<Fence> Fence::merge(const String8& name, const sp<Fence>& f1,
+ const sp<Fence>& f2) {
+ ATRACE_CALL();
+ int result = sync_merge(name.string(), f1->mFenceFd, f2->mFenceFd);
+ if (result == -1) {
+ status_t err = -errno;
+ ALOGE("merge: sync_merge(\"%s\", %d, %d) returned an error: %s (%d)",
+ name.string(), f1->mFenceFd, f2->mFenceFd,
+ strerror(-err), err);
+ return NO_FENCE;
+ }
+ return sp<Fence>(new Fence(result));
+}
+
+int Fence::dup() const {
+ if (mFenceFd == -1) {
+ return -1;
+ }
+ return ::dup(mFenceFd);
+}
+
+size_t Fence::getFlattenedSize() const {
+ return 0;
+}
+
+size_t Fence::getFdCount() const {
+ return 1;
+}
+
+status_t Fence::flatten(void* buffer, size_t size, int fds[],
+ size_t count) const {
+ if (size != 0 || count != 1) {
+ return BAD_VALUE;
+ }
+
+ fds[0] = mFenceFd;
+ return NO_ERROR;
+}
+
+status_t Fence::unflatten(void const* buffer, size_t size, int fds[],
+ size_t count) {
+ if (size != 0 || count != 1) {
+ return BAD_VALUE;
+ }
+ if (mFenceFd != -1) {
+ // Don't unflatten if we already have a valid fd.
+ return INVALID_OPERATION;
+ }
+
+ mFenceFd = fds[0];
+ return NO_ERROR;
+}
+
+} // namespace android
diff --git a/libs/ui/FramebufferNativeWindow.cpp b/libs/ui/FramebufferNativeWindow.cpp
index dec99b6..31a69b2 100644
--- a/libs/ui/FramebufferNativeWindow.cpp
+++ b/libs/ui/FramebufferNativeWindow.cpp
@@ -28,6 +28,7 @@
#include <utils/RefBase.h>
#include <ui/ANativeObjectBase.h>
+#include <ui/Fence.h>
#include <ui/FramebufferNativeWindow.h>
#include <ui/Rect.h>
@@ -92,8 +93,13 @@ FramebufferNativeWindow::FramebufferNativeWindow()
mUpdateOnDemand = (fbDev->setUpdateRect != 0);
// initialize the buffer FIFO
- mNumBuffers = NUM_FRAME_BUFFERS;
- mNumFreeBuffers = NUM_FRAME_BUFFERS;
+ if(fbDev->numFramebuffers >= MIN_NUM_FRAME_BUFFERS &&
+ fbDev->numFramebuffers <= MAX_NUM_FRAME_BUFFERS){
+ mNumBuffers = fbDev->numFramebuffers;
+ } else {
+ mNumBuffers = MIN_NUM_FRAME_BUFFERS;
+ }
+ mNumFreeBuffers = mNumBuffers;
mBufferHead = mNumBuffers-1;
/*
@@ -145,19 +151,23 @@ FramebufferNativeWindow::FramebufferNativeWindow()
ANativeWindow::setSwapInterval = setSwapInterval;
ANativeWindow::dequeueBuffer = dequeueBuffer;
- ANativeWindow::lockBuffer = lockBuffer;
ANativeWindow::queueBuffer = queueBuffer;
ANativeWindow::query = query;
ANativeWindow::perform = perform;
+
+ ANativeWindow::dequeueBuffer_DEPRECATED = dequeueBuffer_DEPRECATED;
+ ANativeWindow::lockBuffer_DEPRECATED = lockBuffer_DEPRECATED;
+ ANativeWindow::queueBuffer_DEPRECATED = queueBuffer_DEPRECATED;
}
FramebufferNativeWindow::~FramebufferNativeWindow()
{
if (grDev) {
- if (buffers[0] != NULL)
- grDev->free(grDev, buffers[0]->handle);
- if (buffers[1] != NULL)
- grDev->free(grDev, buffers[1]->handle);
+ for(int i = 0; i < mNumBuffers; i++) {
+ if (buffers[i] != NULL) {
+ grDev->free(grDev, buffers[i]->handle);
+ }
+ }
gralloc_close(grDev);
}
@@ -207,9 +217,24 @@ int FramebufferNativeWindow::getCurrentBufferIndex() const
return index;
}
-int FramebufferNativeWindow::dequeueBuffer(ANativeWindow* window,
+int FramebufferNativeWindow::dequeueBuffer_DEPRECATED(ANativeWindow* window,
ANativeWindowBuffer** buffer)
{
+ int fenceFd = -1;
+ int result = dequeueBuffer(window, buffer, &fenceFd);
+ sp<Fence> fence(new Fence(fenceFd));
+ int waitResult = fence->wait(Fence::TIMEOUT_NEVER);
+ if (waitResult != OK) {
+ ALOGE("dequeueBuffer_DEPRECATED: Fence::wait returned an "
+ "error: %d", waitResult);
+ return waitResult;
+ }
+ return result;
+}
+
+int FramebufferNativeWindow::dequeueBuffer(ANativeWindow* window,
+ ANativeWindowBuffer** buffer, int* fenceFd)
+{
FramebufferNativeWindow* self = getSelf(window);
Mutex::Autolock _l(self->mutex);
framebuffer_device_t* fb = self->fbDev;
@@ -218,43 +243,45 @@ int FramebufferNativeWindow::dequeueBuffer(ANativeWindow* window,
if (self->mBufferHead >= self->mNumBuffers)
self->mBufferHead = 0;
- // wait for a free buffer
- while (!self->mNumFreeBuffers) {
+ // wait for a free non-front buffer
+ while (self->mNumFreeBuffers < 2) {
self->mCondition.wait(self->mutex);
}
+ ALOG_ASSERT(self->buffers[index] != self->front);
+
// get this buffer
self->mNumFreeBuffers--;
self->mCurrentBufferIndex = index;
*buffer = self->buffers[index].get();
+ *fenceFd = -1;
return 0;
}
-int FramebufferNativeWindow::lockBuffer(ANativeWindow* window,
+int FramebufferNativeWindow::lockBuffer_DEPRECATED(ANativeWindow* window,
ANativeWindowBuffer* buffer)
{
- FramebufferNativeWindow* self = getSelf(window);
- Mutex::Autolock _l(self->mutex);
-
- const int index = self->mCurrentBufferIndex;
-
- // wait that the buffer we're locking is not front anymore
- while (self->front == buffer) {
- self->mCondition.wait(self->mutex);
- }
-
return NO_ERROR;
}
-int FramebufferNativeWindow::queueBuffer(ANativeWindow* window,
+int FramebufferNativeWindow::queueBuffer_DEPRECATED(ANativeWindow* window,
ANativeWindowBuffer* buffer)
{
+ return queueBuffer(window, buffer, -1);
+}
+
+int FramebufferNativeWindow::queueBuffer(ANativeWindow* window,
+ ANativeWindowBuffer* buffer, int fenceFd)
+{
FramebufferNativeWindow* self = getSelf(window);
Mutex::Autolock _l(self->mutex);
framebuffer_device_t* fb = self->fbDev;
buffer_handle_t handle = static_cast<NativeBuffer*>(buffer)->handle;
+ sp<Fence> fence(new Fence(fenceFd));
+ fence->wait(Fence::TIMEOUT_NEVER);
+
const int index = self->mCurrentBufferIndex;
int res = fb->post(fb, handle);
self->front = static_cast<NativeBuffer*>(buffer);
diff --git a/libs/ui/GraphicBuffer.cpp b/libs/ui/GraphicBuffer.cpp
index 57063e5..b9cab85 100644
--- a/libs/ui/GraphicBuffer.cpp
+++ b/libs/ui/GraphicBuffer.cpp
@@ -258,7 +258,12 @@ status_t GraphicBuffer::unflatten(void const* buffer, size_t size,
mOwner = ownHandle;
if (handle != 0) {
- mBufferMapper.registerBuffer(handle);
+ status_t err = mBufferMapper.registerBuffer(handle);
+ if (err != NO_ERROR) {
+ ALOGE("unflatten: registerBuffer failed: %s (%d)",
+ strerror(-err), err);
+ return err;
+ }
}
return NO_ERROR;
diff --git a/libs/ui/GraphicBufferAllocator.cpp b/libs/ui/GraphicBufferAllocator.cpp
index ff550d9..fb43410 100644
--- a/libs/ui/GraphicBufferAllocator.cpp
+++ b/libs/ui/GraphicBufferAllocator.cpp
@@ -90,6 +90,105 @@ void GraphicBufferAllocator::dumpToSystemLog()
ALOGD("%s", s.string());
}
+class BufferLiberatorThread : public Thread {
+public:
+
+ static void queueCaptiveBuffer(buffer_handle_t handle) {
+ size_t queueSize;
+ {
+ Mutex::Autolock lock(sMutex);
+ if (sThread == NULL) {
+ sThread = new BufferLiberatorThread;
+ sThread->run("BufferLiberator");
+ }
+
+ sThread->mQueue.push_back(handle);
+ sThread->mQueuedCondition.signal();
+ queueSize = sThread->mQueue.size();
+ }
+ }
+
+ static void waitForLiberation() {
+ Mutex::Autolock lock(sMutex);
+
+ waitForLiberationLocked();
+ }
+
+ static void maybeWaitForLiberation() {
+ Mutex::Autolock lock(sMutex);
+ if (sThread != NULL) {
+ if (sThread->mQueue.size() > 8) {
+ waitForLiberationLocked();
+ }
+ }
+ }
+
+private:
+
+ BufferLiberatorThread() {}
+
+ virtual bool threadLoop() {
+ buffer_handle_t handle;
+ { // Scope for mutex
+ Mutex::Autolock lock(sMutex);
+ while (mQueue.isEmpty()) {
+ mQueuedCondition.wait(sMutex);
+ }
+ handle = mQueue[0];
+ }
+
+ status_t err;
+ GraphicBufferAllocator& gba(GraphicBufferAllocator::get());
+ { // Scope for tracing
+ ATRACE_NAME("gralloc::free");
+ err = gba.mAllocDev->free(gba.mAllocDev, handle);
+ }
+ ALOGW_IF(err, "free(...) failed %d (%s)", err, strerror(-err));
+
+ if (err == NO_ERROR) {
+ Mutex::Autolock _l(GraphicBufferAllocator::sLock);
+ KeyedVector<buffer_handle_t, GraphicBufferAllocator::alloc_rec_t>&
+ list(GraphicBufferAllocator::sAllocList);
+ list.removeItem(handle);
+ }
+
+ { // Scope for mutex
+ Mutex::Autolock lock(sMutex);
+ mQueue.removeAt(0);
+ mFreedCondition.broadcast();
+ }
+
+ return true;
+ }
+
+ static void waitForLiberationLocked() {
+ if (sThread == NULL) {
+ return;
+ }
+
+ const nsecs_t timeout = 500 * 1000 * 1000;
+ nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC);
+ nsecs_t timeToStop = now + timeout;
+ while (!sThread->mQueue.isEmpty() && now < timeToStop) {
+ sThread->mFreedCondition.waitRelative(sMutex, timeToStop - now);
+ now = systemTime(SYSTEM_TIME_MONOTONIC);
+ }
+
+ if (!sThread->mQueue.isEmpty()) {
+ ALOGW("waitForLiberationLocked timed out");
+ }
+ }
+
+ static Mutex sMutex;
+ static sp<BufferLiberatorThread> sThread;
+ Vector<buffer_handle_t> mQueue;
+ Condition mQueuedCondition;
+ Condition mFreedCondition;
+};
+
+Mutex BufferLiberatorThread::sMutex;
+sp<BufferLiberatorThread> BufferLiberatorThread::sThread;
+
status_t GraphicBufferAllocator::alloc(uint32_t w, uint32_t h, PixelFormat format,
int usage, buffer_handle_t* handle, int32_t* stride)
{
@@ -100,13 +199,24 @@ status_t GraphicBufferAllocator::alloc(uint32_t w, uint32_t h, PixelFormat forma
w = h = 1;
// we have a h/w allocator and h/w buffer is requested
- status_t err;
-
+ status_t err;
+
+ // If too many async frees are queued up then wait for some of them to
+ // complete before attempting to allocate more memory. This is exercised
+ // by the android.opengl.cts.GLSurfaceViewTest CTS test.
+ BufferLiberatorThread::maybeWaitForLiberation();
+
err = mAllocDev->alloc(mAllocDev, w, h, format, usage, handle, stride);
+ if (err != NO_ERROR) {
+ ALOGW("WOW! gralloc alloc failed, waiting for pending frees!");
+ BufferLiberatorThread::waitForLiberation();
+ err = mAllocDev->alloc(mAllocDev, w, h, format, usage, handle, stride);
+ }
+
ALOGW_IF(err, "alloc(%u, %u, %d, %08x, ...) failed %d (%s)",
w, h, format, usage, err, strerror(-err));
-
+
if (err == NO_ERROR) {
Mutex::Autolock _l(sLock);
KeyedVector<buffer_handle_t, alloc_rec_t>& list(sAllocList);
@@ -129,21 +239,11 @@ status_t GraphicBufferAllocator::alloc(uint32_t w, uint32_t h, PixelFormat forma
return err;
}
+
status_t GraphicBufferAllocator::free(buffer_handle_t handle)
{
- ATRACE_CALL();
- status_t err;
-
- err = mAllocDev->free(mAllocDev, handle);
-
- ALOGW_IF(err, "free(...) failed %d (%s)", err, strerror(-err));
- if (err == NO_ERROR) {
- Mutex::Autolock _l(sLock);
- KeyedVector<buffer_handle_t, alloc_rec_t>& list(sAllocList);
- list.removeItem(handle);
- }
-
- return err;
+ BufferLiberatorThread::queueCaptiveBuffer(handle);
+ return NO_ERROR;
}
// ---------------------------------------------------------------------------
diff --git a/libs/ui/Region.cpp b/libs/ui/Region.cpp
index 2c7cdf0..932ef68 100644
--- a/libs/ui/Region.cpp
+++ b/libs/ui/Region.cpp
@@ -20,6 +20,7 @@
#include <utils/Log.h>
#include <utils/String8.h>
+#include <utils/CallStack.h>
#include <ui/Rect.h>
#include <ui/Region.h>
@@ -48,28 +49,20 @@ enum {
// ----------------------------------------------------------------------------
-Region::Region()
- : mBounds(0,0)
-{
+Region::Region() {
+ mStorage.add(Rect(0,0));
}
Region::Region(const Region& rhs)
- : mBounds(rhs.mBounds), mStorage(rhs.mStorage)
+ : mStorage(rhs.mStorage)
{
#if VALIDATE_REGIONS
validate(rhs, "rhs copy-ctor");
#endif
}
-Region::Region(const Rect& rhs)
- : mBounds(rhs)
-{
-}
-
-Region::Region(const void* buffer)
-{
- status_t err = read(buffer);
- ALOGE_IF(err<0, "error %s reading Region from buffer", strerror(err));
+Region::Region(const Rect& rhs) {
+ mStorage.add(rhs);
}
Region::~Region()
@@ -82,43 +75,45 @@ Region& Region::operator = (const Region& rhs)
validate(*this, "this->operator=");
validate(rhs, "rhs.operator=");
#endif
- mBounds = rhs.mBounds;
mStorage = rhs.mStorage;
return *this;
}
Region& Region::makeBoundsSelf()
{
- mStorage.clear();
+ if (mStorage.size() >= 2) {
+ const Rect bounds(getBounds());
+ mStorage.clear();
+ mStorage.add(bounds);
+ }
return *this;
}
void Region::clear()
{
- mBounds.clear();
mStorage.clear();
+ mStorage.add(Rect(0,0));
}
void Region::set(const Rect& r)
{
- mBounds = r;
mStorage.clear();
+ mStorage.add(r);
}
void Region::set(uint32_t w, uint32_t h)
{
- mBounds = Rect(int(w), int(h));
mStorage.clear();
+ mStorage.add(Rect(w,h));
}
// ----------------------------------------------------------------------------
void Region::addRectUnchecked(int l, int t, int r, int b)
{
- mStorage.add(Rect(l,t,r,b));
-#if VALIDATE_REGIONS
- validate(*this, "addRectUnchecked");
-#endif
+ Rect rect(l,t,r,b);
+ size_t where = mStorage.size() - 1;
+ mStorage.insertAt(rect, where, 1);
}
// ----------------------------------------------------------------------------
@@ -258,7 +253,7 @@ const Region Region::operation(const Region& rhs, int dx, int dy, int op) const
// to obtain an optimal region.
class Region::rasterizer : public region_operator<Rect>::region_rasterizer
{
- Rect& bounds;
+ Rect bounds;
Vector<Rect>& storage;
Rect* head;
Rect* tail;
@@ -266,10 +261,7 @@ class Region::rasterizer : public region_operator<Rect>::region_rasterizer
Rect* cur;
public:
rasterizer(Region& reg)
- : bounds(reg.mBounds), storage(reg.mStorage), head(), tail(), cur() {
- bounds.top = bounds.bottom = 0;
- bounds.left = INT_MAX;
- bounds.right = INT_MIN;
+ : bounds(INT_MAX, 0, INT_MIN, 0), storage(reg.mStorage), head(), tail(), cur() {
storage.clear();
}
@@ -287,6 +279,7 @@ public:
bounds.left = 0;
bounds.right = 0;
}
+ storage.add(bounds);
}
virtual void operator()(const Rect& rect) {
@@ -342,44 +335,72 @@ private:
}
};
-bool Region::validate(const Region& reg, const char* name)
+bool Region::validate(const Region& reg, const char* name, bool silent)
{
bool result = true;
const_iterator cur = reg.begin();
const_iterator const tail = reg.end();
- const_iterator prev = cur++;
+ const_iterator prev = cur;
Rect b(*prev);
while (cur != tail) {
- b.left = b.left < cur->left ? b.left : cur->left;
- b.top = b.top < cur->top ? b.top : cur->top;
- b.right = b.right > cur->right ? b.right : cur->right;
- b.bottom = b.bottom > cur->bottom ? b.bottom : cur->bottom;
- if (cur->top == prev->top) {
- if (cur->bottom != prev->bottom) {
- ALOGE("%s: invalid span %p", name, cur);
+ if (cur->isValid() == false) {
+ ALOGE_IF(!silent, "%s: region contains an invalid Rect", name);
+ result = false;
+ }
+ if (cur->right > region_operator<Rect>::max_value) {
+ ALOGE_IF(!silent, "%s: rect->right > max_value", name);
+ result = false;
+ }
+ if (cur->bottom > region_operator<Rect>::max_value) {
+ ALOGE_IF(!silent, "%s: rect->right > max_value", name);
+ result = false;
+ }
+ if (prev != cur) {
+ b.left = b.left < cur->left ? b.left : cur->left;
+ b.top = b.top < cur->top ? b.top : cur->top;
+ b.right = b.right > cur->right ? b.right : cur->right;
+ b.bottom = b.bottom > cur->bottom ? b.bottom : cur->bottom;
+ if ((*prev < *cur) == false) {
+ ALOGE_IF(!silent, "%s: region's Rects not sorted", name);
result = false;
- } else if (cur->left < prev->right) {
- ALOGE("%s: spans overlap horizontally prev=%p, cur=%p",
+ }
+ if (cur->top == prev->top) {
+ if (cur->bottom != prev->bottom) {
+ ALOGE_IF(!silent, "%s: invalid span %p", name, cur);
+ result = false;
+ } else if (cur->left < prev->right) {
+ ALOGE_IF(!silent,
+ "%s: spans overlap horizontally prev=%p, cur=%p",
+ name, prev, cur);
+ result = false;
+ }
+ } else if (cur->top < prev->bottom) {
+ ALOGE_IF(!silent,
+ "%s: spans overlap vertically prev=%p, cur=%p",
name, prev, cur);
result = false;
}
- } else if (cur->top < prev->bottom) {
- ALOGE("%s: spans overlap vertically prev=%p, cur=%p",
- name, prev, cur);
- result = false;
+ prev = cur;
}
- prev = cur;
cur++;
}
if (b != reg.getBounds()) {
result = false;
- ALOGE("%s: invalid bounds [%d,%d,%d,%d] vs. [%d,%d,%d,%d]", name,
+ ALOGE_IF(!silent,
+ "%s: invalid bounds [%d,%d,%d,%d] vs. [%d,%d,%d,%d]", name,
b.left, b.top, b.right, b.bottom,
reg.getBounds().left, reg.getBounds().top,
reg.getBounds().right, reg.getBounds().bottom);
}
- if (result == false) {
+ if (reg.mStorage.size() == 2) {
+ result = false;
+ ALOGE_IF(!silent, "%s: mStorage size is 2, which is never valid", name);
+ }
+ if (result == false && !silent) {
reg.dump(name);
+ CallStack stack;
+ stack.update();
+ stack.dump("");
}
return result;
}
@@ -535,11 +556,10 @@ void Region::boolean_operation(int op, Region& dst,
void Region::translate(Region& reg, int dx, int dy)
{
- if (!reg.isEmpty()) {
+ if ((dx || dy) && !reg.isEmpty()) {
#if VALIDATE_REGIONS
validate(reg, "translate (before)");
#endif
- reg.mBounds.translate(dx, dy);
size_t count = reg.mStorage.size();
Rect* rects = reg.mStorage.editArray();
while (count) {
@@ -561,73 +581,54 @@ void Region::translate(Region& dst, const Region& reg, int dx, int dy)
// ----------------------------------------------------------------------------
-ssize_t Region::write(void* buffer, size_t size) const
-{
+size_t Region::getSize() const {
+ return mStorage.size() * sizeof(Rect);
+}
+
+status_t Region::flatten(void* buffer) const {
#if VALIDATE_REGIONS
- validate(*this, "write(buffer)");
+ validate(*this, "Region::flatten");
#endif
- const size_t count = mStorage.size();
- const size_t sizeNeeded = sizeof(int32_t) + (1+count)*sizeof(Rect);
- if (buffer != NULL) {
- if (sizeNeeded > size) return NO_MEMORY;
- int32_t* const p = static_cast<int32_t*>(buffer);
- *p = count;
- memcpy(p+1, &mBounds, sizeof(Rect));
- if (count) {
- memcpy(p+5, mStorage.array(), count*sizeof(Rect));
- }
- }
- return ssize_t(sizeNeeded);
+ Rect* rects = reinterpret_cast<Rect*>(buffer);
+ memcpy(rects, mStorage.array(), mStorage.size() * sizeof(Rect));
+ return NO_ERROR;
}
-ssize_t Region::read(const void* buffer)
-{
- int32_t const* const p = static_cast<int32_t const*>(buffer);
- const size_t count = *p;
- memcpy(&mBounds, p+1, sizeof(Rect));
- mStorage.clear();
- if (count) {
- mStorage.insertAt(0, count);
- memcpy(mStorage.editArray(), p+5, count*sizeof(Rect));
+status_t Region::unflatten(void const* buffer, size_t size) {
+ Region result;
+ if (size >= sizeof(Rect)) {
+ Rect const* rects = reinterpret_cast<Rect const*>(buffer);
+ size_t count = size / sizeof(Rect);
+ if (count > 0) {
+ result.mStorage.clear();
+ ssize_t err = result.mStorage.insertAt(0, count);
+ if (err < 0) {
+ return status_t(err);
+ }
+ memcpy(result.mStorage.editArray(), rects, count*sizeof(Rect));
+ }
}
#if VALIDATE_REGIONS
- validate(*this, "read(buffer)");
+ validate(result, "Region::unflatten");
#endif
- return ssize_t(sizeof(int32_t) + (1+count)*sizeof(Rect));
-}
-ssize_t Region::writeEmpty(void* buffer, size_t size)
-{
- const size_t sizeNeeded = sizeof(int32_t) + sizeof(Rect);
- if (sizeNeeded > size) return NO_MEMORY;
- int32_t* const p = static_cast<int32_t*>(buffer);
- memset(p, 0, sizeNeeded);
- return ssize_t(sizeNeeded);
-}
-
-bool Region::isEmpty(void* buffer)
-{
- int32_t const* const p = static_cast<int32_t const*>(buffer);
- Rect const* const b = reinterpret_cast<Rect const *>(p+1);
- return b->isEmpty();
+ if (!result.validate(result, "Region::unflatten", true)) {
+ ALOGE("Region::unflatten() failed, invalid region");
+ return BAD_VALUE;
+ }
+ mStorage = result.mStorage;
+ return NO_ERROR;
}
// ----------------------------------------------------------------------------
Region::const_iterator Region::begin() const {
- return isRect() ? &mBounds : mStorage.array();
+ return mStorage.array();
}
Region::const_iterator Region::end() const {
- if (isRect()) {
- if (isEmpty()) {
- return &mBounds;
- } else {
- return &mBounds + 1;
- }
- } else {
- return mStorage.array() + mStorage.size();
- }
+ size_t numRects = isRect() ? 1 : mStorage.size() - 1;
+ return mStorage.array() + numRects;
}
Rect const* Region::getArray(size_t* count) const {
@@ -637,14 +638,16 @@ Rect const* Region::getArray(size_t* count) const {
return b;
}
-size_t Region::getRects(Vector<Rect>& rectList) const
-{
- rectList = mStorage;
- if (rectList.isEmpty()) {
- rectList.clear();
- rectList.add(mBounds);
+SharedBuffer const* Region::getSharedBuffer(size_t* count) const {
+ // We can get to the SharedBuffer of a Vector<Rect> because Rect has
+ // a trivial destructor.
+ SharedBuffer const* sb = SharedBuffer::bufferFromData(mStorage.array());
+ if (count) {
+ size_t numRects = isRect() ? 1 : mStorage.size() - 1;
+ count[0] = numRects;
}
- return rectList.size();
+ sb->acquire();
+ return sb;
}
// ----------------------------------------------------------------------------
diff --git a/libs/ui/UiConfig.cpp b/libs/ui/UiConfig.cpp
new file mode 100644
index 0000000..8b2130e
--- /dev/null
+++ b/libs/ui/UiConfig.cpp
@@ -0,0 +1,36 @@
+/*
+ * 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.
+ */
+
+#include <ui/UiConfig.h>
+
+namespace android {
+
+#define STRINGIFY(x) #x
+#define TOSTRING(x) STRINGIFY(x)
+
+void appendUiConfigString(String8& configStr)
+{
+ static const char* config =
+ " [libui"
+#ifdef FRAMEBUFFER_FORCE_FORMAT
+ " FRAMEBUFFER_FORCE_FORMAT=" TOSTRING(FRAMEBUFFER_FORCE_FORMAT)
+#endif
+ "]";
+ configStr.append(config);
+}
+
+
+}; // namespace android