summaryrefslogtreecommitdiffstats
path: root/libs/ui
diff options
context:
space:
mode:
Diffstat (limited to 'libs/ui')
-rw-r--r--libs/ui/Android.mk48
-rw-r--r--libs/ui/FramebufferNativeWindow.cpp345
-rw-r--r--libs/ui/GraphicBuffer.cpp278
-rw-r--r--libs/ui/GraphicBufferAllocator.cpp150
-rw-r--r--libs/ui/GraphicBufferMapper.cpp99
-rw-r--r--libs/ui/MODULE_LICENSE_APACHE20
-rw-r--r--libs/ui/NOTICE190
-rw-r--r--libs/ui/PixelFormat.cpp146
-rw-r--r--libs/ui/Rect.cpp95
-rw-r--r--libs/ui/Region.cpp679
-rw-r--r--libs/ui/tests/Android.mk6
-rw-r--r--libs/ui/tests/region/Android.mk16
-rw-r--r--libs/ui/tests/region/region.cpp69
13 files changed, 0 insertions, 2121 deletions
diff --git a/libs/ui/Android.mk b/libs/ui/Android.mk
deleted file mode 100644
index 5aff7a4..0000000
--- a/libs/ui/Android.mk
+++ /dev/null
@@ -1,48 +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.
-
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES:= \
- FramebufferNativeWindow.cpp \
- GraphicBuffer.cpp \
- GraphicBufferAllocator.cpp \
- GraphicBufferMapper.cpp \
- PixelFormat.cpp \
- Rect.cpp \
- Region.cpp
-
-LOCAL_SHARED_LIBRARIES := \
- libcutils \
- libutils \
- libhardware
-
-ifneq ($(BOARD_FRAMEBUFFER_FORCE_FORMAT),)
-LOCAL_CFLAGS += -DFRAMEBUFFER_FORCE_FORMAT=$(BOARD_FRAMEBUFFER_FORCE_FORMAT)
-endif
-
-LOCAL_MODULE:= libui
-
-include $(BUILD_SHARED_LIBRARY)
-
-
-# Include subdirectory makefiles
-# ============================================================
-
-# If we're building with ONE_SHOT_MAKEFILE (mm, mmm), then what the framework
-# team really wants is to build the stuff defined by this makefile.
-ifeq (,$(ONE_SHOT_MAKEFILE))
-include $(call first-makefiles-under,$(LOCAL_PATH))
-endif
diff --git a/libs/ui/FramebufferNativeWindow.cpp b/libs/ui/FramebufferNativeWindow.cpp
deleted file mode 100644
index dec99b6..0000000
--- a/libs/ui/FramebufferNativeWindow.cpp
+++ /dev/null
@@ -1,345 +0,0 @@
-/*
-**
-** Copyright 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.
-*/
-
-#define LOG_TAG "FramebufferNativeWindow"
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-
-#include <cutils/log.h>
-#include <cutils/atomic.h>
-#include <utils/threads.h>
-#include <utils/RefBase.h>
-
-#include <ui/ANativeObjectBase.h>
-#include <ui/FramebufferNativeWindow.h>
-#include <ui/Rect.h>
-
-#include <EGL/egl.h>
-
-#include <hardware/hardware.h>
-#include <hardware/gralloc.h>
-
-// ----------------------------------------------------------------------------
-namespace android {
-// ----------------------------------------------------------------------------
-
-class NativeBuffer
- : public ANativeObjectBase<
- ANativeWindowBuffer,
- NativeBuffer,
- LightRefBase<NativeBuffer> >
-{
-public:
- NativeBuffer(int w, int h, int f, int u) : BASE() {
- ANativeWindowBuffer::width = w;
- ANativeWindowBuffer::height = h;
- ANativeWindowBuffer::format = f;
- ANativeWindowBuffer::usage = u;
- }
-private:
- friend class LightRefBase<NativeBuffer>;
- ~NativeBuffer() { }; // this class cannot be overloaded
-};
-
-
-/*
- * This implements the (main) framebuffer management. This class is used
- * mostly by SurfaceFlinger, but also by command line GL application.
- *
- * In fact this is an implementation of ANativeWindow on top of
- * the framebuffer.
- *
- * Currently it is pretty simple, it manages only two buffers (the front and
- * back buffer).
- *
- */
-
-FramebufferNativeWindow::FramebufferNativeWindow()
- : BASE(), fbDev(0), grDev(0), mUpdateOnDemand(false)
-{
- hw_module_t const* module;
- if (hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module) == 0) {
- int stride;
- int err;
- int i;
- err = framebuffer_open(module, &fbDev);
- ALOGE_IF(err, "couldn't open framebuffer HAL (%s)", strerror(-err));
-
- err = gralloc_open(module, &grDev);
- ALOGE_IF(err, "couldn't open gralloc HAL (%s)", strerror(-err));
-
- // bail out if we can't initialize the modules
- if (!fbDev || !grDev)
- return;
-
- mUpdateOnDemand = (fbDev->setUpdateRect != 0);
-
- // initialize the buffer FIFO
- mNumBuffers = NUM_FRAME_BUFFERS;
- mNumFreeBuffers = NUM_FRAME_BUFFERS;
- mBufferHead = mNumBuffers-1;
-
- /*
- * This does not actually change the framebuffer format. It merely
- * fakes this format to surfaceflinger so that when it creates
- * framebuffer surfaces it will use this format. It's really a giant
- * HACK to allow interworking with buggy gralloc+GPU driver
- * implementations. You should *NEVER* need to set this for shipping
- * devices.
- */
-#ifdef FRAMEBUFFER_FORCE_FORMAT
- *((uint32_t *)&fbDev->format) = FRAMEBUFFER_FORCE_FORMAT;
-#endif
-
- for (i = 0; i < mNumBuffers; i++)
- {
- buffers[i] = new NativeBuffer(
- fbDev->width, fbDev->height, fbDev->format, GRALLOC_USAGE_HW_FB);
- }
-
- for (i = 0; i < mNumBuffers; i++)
- {
- err = grDev->alloc(grDev,
- fbDev->width, fbDev->height, fbDev->format,
- GRALLOC_USAGE_HW_FB, &buffers[i]->handle, &buffers[i]->stride);
-
- ALOGE_IF(err, "fb buffer %d allocation failed w=%d, h=%d, err=%s",
- i, fbDev->width, fbDev->height, strerror(-err));
-
- if (err)
- {
- mNumBuffers = i;
- mNumFreeBuffers = i;
- mBufferHead = mNumBuffers-1;
- break;
- }
- }
-
- const_cast<uint32_t&>(ANativeWindow::flags) = fbDev->flags;
- const_cast<float&>(ANativeWindow::xdpi) = fbDev->xdpi;
- const_cast<float&>(ANativeWindow::ydpi) = fbDev->ydpi;
- const_cast<int&>(ANativeWindow::minSwapInterval) =
- fbDev->minSwapInterval;
- const_cast<int&>(ANativeWindow::maxSwapInterval) =
- fbDev->maxSwapInterval;
- } else {
- ALOGE("Couldn't get gralloc module");
- }
-
- ANativeWindow::setSwapInterval = setSwapInterval;
- ANativeWindow::dequeueBuffer = dequeueBuffer;
- ANativeWindow::lockBuffer = lockBuffer;
- ANativeWindow::queueBuffer = queueBuffer;
- ANativeWindow::query = query;
- ANativeWindow::perform = perform;
-}
-
-FramebufferNativeWindow::~FramebufferNativeWindow()
-{
- if (grDev) {
- if (buffers[0] != NULL)
- grDev->free(grDev, buffers[0]->handle);
- if (buffers[1] != NULL)
- grDev->free(grDev, buffers[1]->handle);
- gralloc_close(grDev);
- }
-
- if (fbDev) {
- framebuffer_close(fbDev);
- }
-}
-
-status_t FramebufferNativeWindow::setUpdateRectangle(const Rect& r)
-{
- if (!mUpdateOnDemand) {
- return INVALID_OPERATION;
- }
- return fbDev->setUpdateRect(fbDev, r.left, r.top, r.width(), r.height());
-}
-
-status_t FramebufferNativeWindow::compositionComplete()
-{
- if (fbDev->compositionComplete) {
- return fbDev->compositionComplete(fbDev);
- }
- return INVALID_OPERATION;
-}
-
-int FramebufferNativeWindow::setSwapInterval(
- ANativeWindow* window, int interval)
-{
- framebuffer_device_t* fb = getSelf(window)->fbDev;
- return fb->setSwapInterval(fb, interval);
-}
-
-void FramebufferNativeWindow::dump(String8& result) {
- if (fbDev->common.version >= 1 && fbDev->dump) {
- const size_t SIZE = 4096;
- char buffer[SIZE];
-
- fbDev->dump(fbDev, buffer, SIZE);
- result.append(buffer);
- }
-}
-
-// only for debugging / logging
-int FramebufferNativeWindow::getCurrentBufferIndex() const
-{
- Mutex::Autolock _l(mutex);
- const int index = mCurrentBufferIndex;
- return index;
-}
-
-int FramebufferNativeWindow::dequeueBuffer(ANativeWindow* window,
- ANativeWindowBuffer** buffer)
-{
- FramebufferNativeWindow* self = getSelf(window);
- Mutex::Autolock _l(self->mutex);
- framebuffer_device_t* fb = self->fbDev;
-
- int index = self->mBufferHead++;
- if (self->mBufferHead >= self->mNumBuffers)
- self->mBufferHead = 0;
-
- // wait for a free buffer
- while (!self->mNumFreeBuffers) {
- self->mCondition.wait(self->mutex);
- }
- // get this buffer
- self->mNumFreeBuffers--;
- self->mCurrentBufferIndex = index;
-
- *buffer = self->buffers[index].get();
-
- return 0;
-}
-
-int FramebufferNativeWindow::lockBuffer(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,
- ANativeWindowBuffer* buffer)
-{
- FramebufferNativeWindow* self = getSelf(window);
- Mutex::Autolock _l(self->mutex);
- framebuffer_device_t* fb = self->fbDev;
- buffer_handle_t handle = static_cast<NativeBuffer*>(buffer)->handle;
-
- const int index = self->mCurrentBufferIndex;
- int res = fb->post(fb, handle);
- self->front = static_cast<NativeBuffer*>(buffer);
- self->mNumFreeBuffers++;
- self->mCondition.broadcast();
- return res;
-}
-
-int FramebufferNativeWindow::query(const ANativeWindow* window,
- int what, int* value)
-{
- const FramebufferNativeWindow* self = getSelf(window);
- Mutex::Autolock _l(self->mutex);
- framebuffer_device_t* fb = self->fbDev;
- switch (what) {
- case NATIVE_WINDOW_WIDTH:
- *value = fb->width;
- return NO_ERROR;
- case NATIVE_WINDOW_HEIGHT:
- *value = fb->height;
- return NO_ERROR;
- case NATIVE_WINDOW_FORMAT:
- *value = fb->format;
- return NO_ERROR;
- case NATIVE_WINDOW_CONCRETE_TYPE:
- *value = NATIVE_WINDOW_FRAMEBUFFER;
- return NO_ERROR;
- case NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER:
- *value = 0;
- return NO_ERROR;
- case NATIVE_WINDOW_DEFAULT_WIDTH:
- *value = fb->width;
- return NO_ERROR;
- case NATIVE_WINDOW_DEFAULT_HEIGHT:
- *value = fb->height;
- return NO_ERROR;
- case NATIVE_WINDOW_TRANSFORM_HINT:
- *value = 0;
- return NO_ERROR;
- }
- *value = 0;
- return BAD_VALUE;
-}
-
-int FramebufferNativeWindow::perform(ANativeWindow* window,
- int operation, ...)
-{
- switch (operation) {
- case NATIVE_WINDOW_CONNECT:
- case NATIVE_WINDOW_DISCONNECT:
- case NATIVE_WINDOW_SET_USAGE:
- case NATIVE_WINDOW_SET_BUFFERS_GEOMETRY:
- case NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS:
- case NATIVE_WINDOW_SET_BUFFERS_FORMAT:
- case NATIVE_WINDOW_SET_BUFFERS_TRANSFORM:
- case NATIVE_WINDOW_API_CONNECT:
- case NATIVE_WINDOW_API_DISCONNECT:
- // TODO: we should implement these
- return NO_ERROR;
-
- case NATIVE_WINDOW_LOCK:
- case NATIVE_WINDOW_UNLOCK_AND_POST:
- case NATIVE_WINDOW_SET_CROP:
- case NATIVE_WINDOW_SET_BUFFER_COUNT:
- case NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP:
- case NATIVE_WINDOW_SET_SCALING_MODE:
- return INVALID_OPERATION;
- }
- return NAME_NOT_FOUND;
-}
-
-// ----------------------------------------------------------------------------
-}; // namespace android
-// ----------------------------------------------------------------------------
-
-using namespace android;
-
-EGLNativeWindowType android_createDisplaySurface(void)
-{
- FramebufferNativeWindow* w;
- w = new FramebufferNativeWindow();
- if (w->getDevice() == NULL) {
- // get a ref so it can be destroyed when we exit this block
- sp<FramebufferNativeWindow> ref(w);
- return NULL;
- }
- return (EGLNativeWindowType)w;
-}
diff --git a/libs/ui/GraphicBuffer.cpp b/libs/ui/GraphicBuffer.cpp
deleted file mode 100644
index 57063e5..0000000
--- a/libs/ui/GraphicBuffer.cpp
+++ /dev/null
@@ -1,278 +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.
- */
-
-#define LOG_TAG "GraphicBuffer"
-
-#include <stdlib.h>
-#include <stdint.h>
-#include <sys/types.h>
-
-#include <utils/Errors.h>
-#include <utils/Log.h>
-
-#include <ui/GraphicBuffer.h>
-#include <ui/GraphicBufferAllocator.h>
-#include <ui/GraphicBufferMapper.h>
-#include <ui/PixelFormat.h>
-
-namespace android {
-
-// ===========================================================================
-// Buffer and implementation of ANativeWindowBuffer
-// ===========================================================================
-
-GraphicBuffer::GraphicBuffer()
- : BASE(), mOwner(ownData), mBufferMapper(GraphicBufferMapper::get()),
- mInitCheck(NO_ERROR), mIndex(-1)
-{
- width =
- height =
- stride =
- format =
- usage = 0;
- handle = NULL;
-}
-
-GraphicBuffer::GraphicBuffer(uint32_t w, uint32_t h,
- PixelFormat reqFormat, uint32_t reqUsage)
- : BASE(), mOwner(ownData), mBufferMapper(GraphicBufferMapper::get()),
- mInitCheck(NO_ERROR), mIndex(-1)
-{
- width =
- height =
- stride =
- format =
- usage = 0;
- handle = NULL;
- mInitCheck = initSize(w, h, reqFormat, reqUsage);
-}
-
-GraphicBuffer::GraphicBuffer(uint32_t w, uint32_t h,
- PixelFormat inFormat, uint32_t inUsage,
- uint32_t inStride, native_handle_t* inHandle, bool keepOwnership)
- : BASE(), mOwner(keepOwnership ? ownHandle : ownNone),
- mBufferMapper(GraphicBufferMapper::get()),
- mInitCheck(NO_ERROR), mIndex(-1)
-{
- width = w;
- height = h;
- stride = inStride;
- format = inFormat;
- usage = inUsage;
- handle = inHandle;
-}
-
-GraphicBuffer::GraphicBuffer(ANativeWindowBuffer* buffer, bool keepOwnership)
- : BASE(), mOwner(keepOwnership ? ownHandle : ownNone),
- mBufferMapper(GraphicBufferMapper::get()),
- mInitCheck(NO_ERROR), mIndex(-1), mWrappedBuffer(buffer)
-{
- width = buffer->width;
- height = buffer->height;
- stride = buffer->stride;
- format = buffer->format;
- usage = buffer->usage;
- handle = buffer->handle;
-}
-
-GraphicBuffer::~GraphicBuffer()
-{
- if (handle) {
- free_handle();
- }
-}
-
-void GraphicBuffer::free_handle()
-{
- if (mOwner == ownHandle) {
- mBufferMapper.unregisterBuffer(handle);
- native_handle_close(handle);
- native_handle_delete(const_cast<native_handle*>(handle));
- } else if (mOwner == ownData) {
- GraphicBufferAllocator& allocator(GraphicBufferAllocator::get());
- allocator.free(handle);
- }
- mWrappedBuffer = 0;
-}
-
-status_t GraphicBuffer::initCheck() const {
- return mInitCheck;
-}
-
-void GraphicBuffer::dumpAllocationsToSystemLog()
-{
- GraphicBufferAllocator::dumpToSystemLog();
-}
-
-ANativeWindowBuffer* GraphicBuffer::getNativeBuffer() const
-{
- return static_cast<ANativeWindowBuffer*>(
- const_cast<GraphicBuffer*>(this));
-}
-
-status_t GraphicBuffer::reallocate(uint32_t w, uint32_t h, PixelFormat f,
- uint32_t reqUsage)
-{
- if (mOwner != ownData)
- return INVALID_OPERATION;
-
- if (handle && w==width && h==height && f==format && reqUsage==usage)
- return NO_ERROR;
-
- if (handle) {
- GraphicBufferAllocator& allocator(GraphicBufferAllocator::get());
- allocator.free(handle);
- handle = 0;
- }
- return initSize(w, h, f, reqUsage);
-}
-
-status_t GraphicBuffer::initSize(uint32_t w, uint32_t h, PixelFormat format,
- uint32_t reqUsage)
-{
- GraphicBufferAllocator& allocator = GraphicBufferAllocator::get();
- status_t err = allocator.alloc(w, h, format, reqUsage, &handle, &stride);
- if (err == NO_ERROR) {
- this->width = w;
- this->height = h;
- this->format = format;
- this->usage = reqUsage;
- }
- return err;
-}
-
-status_t GraphicBuffer::lock(uint32_t usage, void** vaddr)
-{
- const Rect lockBounds(width, height);
- status_t res = lock(usage, lockBounds, vaddr);
- return res;
-}
-
-status_t GraphicBuffer::lock(uint32_t usage, const Rect& rect, void** vaddr)
-{
- if (rect.left < 0 || rect.right > this->width ||
- rect.top < 0 || rect.bottom > this->height) {
- ALOGE("locking pixels (%d,%d,%d,%d) outside of buffer (w=%d, h=%d)",
- rect.left, rect.top, rect.right, rect.bottom,
- this->width, this->height);
- return BAD_VALUE;
- }
- status_t res = getBufferMapper().lock(handle, usage, rect, vaddr);
- return res;
-}
-
-status_t GraphicBuffer::unlock()
-{
- status_t res = getBufferMapper().unlock(handle);
- return res;
-}
-
-size_t GraphicBuffer::getFlattenedSize() const {
- return (8 + (handle ? handle->numInts : 0))*sizeof(int);
-}
-
-size_t GraphicBuffer::getFdCount() const {
- return handle ? handle->numFds : 0;
-}
-
-status_t GraphicBuffer::flatten(void* buffer, size_t size,
- int fds[], size_t count) const
-{
- size_t sizeNeeded = GraphicBuffer::getFlattenedSize();
- if (size < sizeNeeded) return NO_MEMORY;
-
- size_t fdCountNeeded = GraphicBuffer::getFdCount();
- if (count < fdCountNeeded) return NO_MEMORY;
-
- int* buf = static_cast<int*>(buffer);
- buf[0] = 'GBFR';
- buf[1] = width;
- buf[2] = height;
- buf[3] = stride;
- buf[4] = format;
- buf[5] = usage;
- buf[6] = 0;
- buf[7] = 0;
-
- if (handle) {
- buf[6] = handle->numFds;
- buf[7] = handle->numInts;
- native_handle_t const* const h = handle;
- memcpy(fds, h->data, h->numFds*sizeof(int));
- memcpy(&buf[8], h->data + h->numFds, h->numInts*sizeof(int));
- }
-
- return NO_ERROR;
-}
-
-status_t GraphicBuffer::unflatten(void const* buffer, size_t size,
- int fds[], size_t count)
-{
- if (size < 8*sizeof(int)) return NO_MEMORY;
-
- int const* buf = static_cast<int const*>(buffer);
- if (buf[0] != 'GBFR') return BAD_TYPE;
-
- const size_t numFds = buf[6];
- const size_t numInts = buf[7];
-
- const size_t sizeNeeded = (8 + numInts) * sizeof(int);
- if (size < sizeNeeded) return NO_MEMORY;
-
- size_t fdCountNeeded = 0;
- if (count < fdCountNeeded) return NO_MEMORY;
-
- if (handle) {
- // free previous handle if any
- free_handle();
- }
-
- if (numFds || numInts) {
- width = buf[1];
- height = buf[2];
- stride = buf[3];
- format = buf[4];
- usage = buf[5];
- native_handle* h = native_handle_create(numFds, numInts);
- memcpy(h->data, fds, numFds*sizeof(int));
- memcpy(h->data + numFds, &buf[8], numInts*sizeof(int));
- handle = h;
- } else {
- width = height = stride = format = usage = 0;
- handle = NULL;
- }
-
- mOwner = ownHandle;
-
- if (handle != 0) {
- mBufferMapper.registerBuffer(handle);
- }
-
- return NO_ERROR;
-}
-
-
-void GraphicBuffer::setIndex(int index) {
- mIndex = index;
-}
-
-int GraphicBuffer::getIndex() const {
- return mIndex;
-}
-
-// ---------------------------------------------------------------------------
-
-}; // namespace android
diff --git a/libs/ui/GraphicBufferAllocator.cpp b/libs/ui/GraphicBufferAllocator.cpp
deleted file mode 100644
index ff550d9..0000000
--- a/libs/ui/GraphicBufferAllocator.cpp
+++ /dev/null
@@ -1,150 +0,0 @@
-/*
-**
-** 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
-**
-** 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 "GraphicBufferAllocator"
-#define ATRACE_TAG ATRACE_TAG_GRAPHICS
-
-#include <cutils/log.h>
-
-#include <utils/Singleton.h>
-#include <utils/String8.h>
-#include <utils/Trace.h>
-
-#include <ui/GraphicBufferAllocator.h>
-
-namespace android {
-// ---------------------------------------------------------------------------
-
-ANDROID_SINGLETON_STATIC_INSTANCE( GraphicBufferAllocator )
-
-Mutex GraphicBufferAllocator::sLock;
-KeyedVector<buffer_handle_t,
- GraphicBufferAllocator::alloc_rec_t> GraphicBufferAllocator::sAllocList;
-
-GraphicBufferAllocator::GraphicBufferAllocator()
- : mAllocDev(0)
-{
- hw_module_t const* module;
- int err = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module);
- ALOGE_IF(err, "FATAL: can't find the %s module", GRALLOC_HARDWARE_MODULE_ID);
- if (err == 0) {
- gralloc_open(module, &mAllocDev);
- }
-}
-
-GraphicBufferAllocator::~GraphicBufferAllocator()
-{
- gralloc_close(mAllocDev);
-}
-
-void GraphicBufferAllocator::dump(String8& result) const
-{
- Mutex::Autolock _l(sLock);
- KeyedVector<buffer_handle_t, alloc_rec_t>& list(sAllocList);
- size_t total = 0;
- const size_t SIZE = 4096;
- char buffer[SIZE];
- snprintf(buffer, SIZE, "Allocated buffers:\n");
- result.append(buffer);
- const size_t c = list.size();
- for (size_t i=0 ; i<c ; i++) {
- const alloc_rec_t& rec(list.valueAt(i));
- if (rec.size) {
- snprintf(buffer, SIZE, "%10p: %7.2f KiB | %4u (%4u) x %4u | %8X | 0x%08x\n",
- list.keyAt(i), rec.size/1024.0f,
- rec.w, rec.s, rec.h, rec.format, rec.usage);
- } else {
- snprintf(buffer, SIZE, "%10p: unknown | %4u (%4u) x %4u | %8X | 0x%08x\n",
- list.keyAt(i),
- rec.w, rec.s, rec.h, rec.format, rec.usage);
- }
- result.append(buffer);
- total += rec.size;
- }
- snprintf(buffer, SIZE, "Total allocated (estimate): %.2f KB\n", total/1024.0f);
- result.append(buffer);
- if (mAllocDev->common.version >= 1 && mAllocDev->dump) {
- mAllocDev->dump(mAllocDev, buffer, SIZE);
- result.append(buffer);
- }
-}
-
-void GraphicBufferAllocator::dumpToSystemLog()
-{
- String8 s;
- GraphicBufferAllocator::getInstance().dump(s);
- ALOGD("%s", s.string());
-}
-
-status_t GraphicBufferAllocator::alloc(uint32_t w, uint32_t h, PixelFormat format,
- int usage, buffer_handle_t* handle, int32_t* stride)
-{
- ATRACE_CALL();
- // make sure to not allocate a N x 0 or 0 x N buffer, since this is
- // allowed from an API stand-point allocate a 1x1 buffer instead.
- if (!w || !h)
- w = h = 1;
-
- // we have a h/w allocator and h/w buffer is requested
- status_t err;
-
- 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);
- int bpp = bytesPerPixel(format);
- if (bpp < 0) {
- // probably a HAL custom format. in any case, we don't know
- // what its pixel size is.
- bpp = 0;
- }
- alloc_rec_t rec;
- rec.w = w;
- rec.h = h;
- rec.s = *stride;
- rec.format = format;
- rec.usage = usage;
- rec.size = h * stride[0] * bpp;
- list.add(*handle, rec);
- }
-
- 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;
-}
-
-// ---------------------------------------------------------------------------
-}; // namespace android
diff --git a/libs/ui/GraphicBufferMapper.cpp b/libs/ui/GraphicBufferMapper.cpp
deleted file mode 100644
index 967da98..0000000
--- a/libs/ui/GraphicBufferMapper.cpp
+++ /dev/null
@@ -1,99 +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.
- */
-
-#define LOG_TAG "GraphicBufferMapper"
-#define ATRACE_TAG ATRACE_TAG_GRAPHICS
-
-#include <stdint.h>
-#include <errno.h>
-
-#include <utils/Errors.h>
-#include <utils/Log.h>
-#include <utils/Trace.h>
-
-#include <ui/GraphicBufferMapper.h>
-#include <ui/Rect.h>
-
-#include <hardware/gralloc.h>
-
-
-namespace android {
-// ---------------------------------------------------------------------------
-
-ANDROID_SINGLETON_STATIC_INSTANCE( GraphicBufferMapper )
-
-GraphicBufferMapper::GraphicBufferMapper()
- : mAllocMod(0)
-{
- hw_module_t const* module;
- int err = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module);
- ALOGE_IF(err, "FATAL: can't find the %s module", GRALLOC_HARDWARE_MODULE_ID);
- if (err == 0) {
- mAllocMod = (gralloc_module_t const *)module;
- }
-}
-
-status_t GraphicBufferMapper::registerBuffer(buffer_handle_t handle)
-{
- ATRACE_CALL();
- status_t err;
-
- err = mAllocMod->registerBuffer(mAllocMod, handle);
-
- ALOGW_IF(err, "registerBuffer(%p) failed %d (%s)",
- handle, err, strerror(-err));
- return err;
-}
-
-status_t GraphicBufferMapper::unregisterBuffer(buffer_handle_t handle)
-{
- ATRACE_CALL();
- status_t err;
-
- err = mAllocMod->unregisterBuffer(mAllocMod, handle);
-
- ALOGW_IF(err, "unregisterBuffer(%p) failed %d (%s)",
- handle, err, strerror(-err));
- return err;
-}
-
-status_t GraphicBufferMapper::lock(buffer_handle_t handle,
- int usage, const Rect& bounds, void** vaddr)
-{
- ATRACE_CALL();
- status_t err;
-
- err = mAllocMod->lock(mAllocMod, handle, usage,
- bounds.left, bounds.top, bounds.width(), bounds.height(),
- vaddr);
-
- ALOGW_IF(err, "lock(...) failed %d (%s)", err, strerror(-err));
- return err;
-}
-
-status_t GraphicBufferMapper::unlock(buffer_handle_t handle)
-{
- ATRACE_CALL();
- status_t err;
-
- err = mAllocMod->unlock(mAllocMod, handle);
-
- ALOGW_IF(err, "unlock(...) failed %d (%s)", err, strerror(-err));
- return err;
-}
-
-// ---------------------------------------------------------------------------
-}; // namespace android
diff --git a/libs/ui/MODULE_LICENSE_APACHE2 b/libs/ui/MODULE_LICENSE_APACHE2
deleted file mode 100644
index e69de29..0000000
--- a/libs/ui/MODULE_LICENSE_APACHE2
+++ /dev/null
diff --git a/libs/ui/NOTICE b/libs/ui/NOTICE
deleted file mode 100644
index c5b1efa..0000000
--- a/libs/ui/NOTICE
+++ /dev/null
@@ -1,190 +0,0 @@
-
- Copyright (c) 2005-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.
-
- 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.
-
-
- Apache License
- Version 2.0, January 2004
- http://www.apache.org/licenses/
-
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
- 1. Definitions.
-
- "License" shall mean the terms and conditions for use, reproduction,
- and distribution as defined by Sections 1 through 9 of this document.
-
- "Licensor" shall mean the copyright owner or entity authorized by
- the copyright owner that is granting the License.
-
- "Legal Entity" shall mean the union of the acting entity and all
- other entities that control, are controlled by, or are under common
- control with that entity. For the purposes of this definition,
- "control" means (i) the power, direct or indirect, to cause the
- direction or management of such entity, whether by contract or
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
- outstanding shares, or (iii) beneficial ownership of such entity.
-
- "You" (or "Your") shall mean an individual or Legal Entity
- exercising permissions granted by this License.
-
- "Source" form shall mean the preferred form for making modifications,
- including but not limited to software source code, documentation
- source, and configuration files.
-
- "Object" form shall mean any form resulting from mechanical
- transformation or translation of a Source form, including but
- not limited to compiled object code, generated documentation,
- and conversions to other media types.
-
- "Work" shall mean the work of authorship, whether in Source or
- Object form, made available under the License, as indicated by a
- copyright notice that is included in or attached to the work
- (an example is provided in the Appendix below).
-
- "Derivative Works" shall mean any work, whether in Source or Object
- form, that is based on (or derived from) the Work and for which the
- editorial revisions, annotations, elaborations, or other modifications
- represent, as a whole, an original work of authorship. For the purposes
- of this License, Derivative Works shall not include works that remain
- separable from, or merely link (or bind by name) to the interfaces of,
- the Work and Derivative Works thereof.
-
- "Contribution" shall mean any work of authorship, including
- the original version of the Work and any modifications or additions
- to that Work or Derivative Works thereof, that is intentionally
- submitted to Licensor for inclusion in the Work by the copyright owner
- or by an individual or Legal Entity authorized to submit on behalf of
- the copyright owner. For the purposes of this definition, "submitted"
- means any form of electronic, verbal, or written communication sent
- to the Licensor or its representatives, including but not limited to
- communication on electronic mailing lists, source code control systems,
- and issue tracking systems that are managed by, or on behalf of, the
- Licensor for the purpose of discussing and improving the Work, but
- excluding communication that is conspicuously marked or otherwise
- designated in writing by the copyright owner as "Not a Contribution."
-
- "Contributor" shall mean Licensor and any individual or Legal Entity
- on behalf of whom a Contribution has been received by Licensor and
- subsequently incorporated within the Work.
-
- 2. Grant of Copyright License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- copyright license to reproduce, prepare Derivative Works of,
- publicly display, publicly perform, sublicense, and distribute the
- Work and such Derivative Works in Source or Object form.
-
- 3. Grant of Patent License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- (except as stated in this section) patent license to make, have made,
- use, offer to sell, sell, import, and otherwise transfer the Work,
- where such license applies only to those patent claims licensable
- by such Contributor that are necessarily infringed by their
- Contribution(s) alone or by combination of their Contribution(s)
- with the Work to which such Contribution(s) was submitted. If You
- institute patent litigation against any entity (including a
- cross-claim or counterclaim in a lawsuit) alleging that the Work
- or a Contribution incorporated within the Work constitutes direct
- or contributory patent infringement, then any patent licenses
- granted to You under this License for that Work shall terminate
- as of the date such litigation is filed.
-
- 4. Redistribution. You may reproduce and distribute copies of the
- Work or Derivative Works thereof in any medium, with or without
- modifications, and in Source or Object form, provided that You
- meet the following conditions:
-
- (a) You must give any other recipients of the Work or
- Derivative Works a copy of this License; and
-
- (b) You must cause any modified files to carry prominent notices
- stating that You changed the files; and
-
- (c) You must retain, in the Source form of any Derivative Works
- that You distribute, all copyright, patent, trademark, and
- attribution notices from the Source form of the Work,
- excluding those notices that do not pertain to any part of
- the Derivative Works; and
-
- (d) If the Work includes a "NOTICE" text file as part of its
- distribution, then any Derivative Works that You distribute must
- include a readable copy of the attribution notices contained
- within such NOTICE file, excluding those notices that do not
- pertain to any part of the Derivative Works, in at least one
- of the following places: within a NOTICE text file distributed
- as part of the Derivative Works; within the Source form or
- documentation, if provided along with the Derivative Works; or,
- within a display generated by the Derivative Works, if and
- wherever such third-party notices normally appear. The contents
- of the NOTICE file are for informational purposes only and
- do not modify the License. You may add Your own attribution
- notices within Derivative Works that You distribute, alongside
- or as an addendum to the NOTICE text from the Work, provided
- that such additional attribution notices cannot be construed
- as modifying the License.
-
- You may add Your own copyright statement to Your modifications and
- may provide additional or different license terms and conditions
- for use, reproduction, or distribution of Your modifications, or
- for any such Derivative Works as a whole, provided Your use,
- reproduction, and distribution of the Work otherwise complies with
- the conditions stated in this License.
-
- 5. Submission of Contributions. Unless You explicitly state otherwise,
- any Contribution intentionally submitted for inclusion in the Work
- by You to the Licensor shall be under the terms and conditions of
- this License, without any additional terms or conditions.
- Notwithstanding the above, nothing herein shall supersede or modify
- the terms of any separate license agreement you may have executed
- with Licensor regarding such Contributions.
-
- 6. Trademarks. This License does not grant permission to use the trade
- names, trademarks, service marks, or product names of the Licensor,
- except as required for reasonable and customary use in describing the
- origin of the Work and reproducing the content of the NOTICE file.
-
- 7. Disclaimer of Warranty. Unless required by applicable law or
- agreed to in writing, Licensor provides the Work (and each
- Contributor provides its Contributions) on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied, including, without limitation, any warranties or conditions
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
- PARTICULAR PURPOSE. You are solely responsible for determining the
- appropriateness of using or redistributing the Work and assume any
- risks associated with Your exercise of permissions under this License.
-
- 8. Limitation of Liability. In no event and under no legal theory,
- whether in tort (including negligence), contract, or otherwise,
- unless required by applicable law (such as deliberate and grossly
- negligent acts) or agreed to in writing, shall any Contributor be
- liable to You for damages, including any direct, indirect, special,
- incidental, or consequential damages of any character arising as a
- result of this License or out of the use or inability to use the
- Work (including but not limited to damages for loss of goodwill,
- work stoppage, computer failure or malfunction, or any and all
- other commercial damages or losses), even if such Contributor
- has been advised of the possibility of such damages.
-
- 9. Accepting Warranty or Additional Liability. While redistributing
- the Work or Derivative Works thereof, You may choose to offer,
- and charge a fee for, acceptance of support, warranty, indemnity,
- or other liability obligations and/or rights consistent with this
- License. However, in accepting such obligations, You may act only
- on Your own behalf and on Your sole responsibility, not on behalf
- of any other Contributor, and only if You agree to indemnify,
- defend, and hold each Contributor harmless for any liability
- incurred by, or claims asserted against, such Contributor by reason
- of your accepting any such warranty or additional liability.
-
- END OF TERMS AND CONDITIONS
-
diff --git a/libs/ui/PixelFormat.cpp b/libs/ui/PixelFormat.cpp
deleted file mode 100644
index fc1d3c2..0000000
--- a/libs/ui/PixelFormat.cpp
+++ /dev/null
@@ -1,146 +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.
- */
-
-#include <ui/PixelFormat.h>
-#include <hardware/hardware.h>
-
-// ----------------------------------------------------------------------------
-namespace android {
-// ----------------------------------------------------------------------------
-
-static const int COMPONENT_YUV = 0xFF;
-
-struct Info {
- size_t size;
- size_t bitsPerPixel;
- struct {
- uint8_t ah;
- uint8_t al;
- uint8_t rh;
- uint8_t rl;
- uint8_t gh;
- uint8_t gl;
- uint8_t bh;
- uint8_t bl;
- };
- uint8_t components;
-};
-
-static Info const sPixelFormatInfos[] = {
- { 0, 0, { 0, 0, 0, 0, 0, 0, 0, 0 }, 0 },
- { 4, 32, {32,24, 8, 0, 16, 8, 24,16 }, PixelFormatInfo::RGBA },
- { 4, 24, { 0, 0, 8, 0, 16, 8, 24,16 }, PixelFormatInfo::RGB },
- { 3, 24, { 0, 0, 8, 0, 16, 8, 24,16 }, PixelFormatInfo::RGB },
- { 2, 16, { 0, 0, 16,11, 11, 5, 5, 0 }, PixelFormatInfo::RGB },
- { 4, 32, {32,24, 24,16, 16, 8, 8, 0 }, PixelFormatInfo::RGBA },
- { 2, 16, { 1, 0, 16,11, 11, 6, 6, 1 }, PixelFormatInfo::RGBA },
- { 2, 16, { 4, 0, 16,12, 12, 8, 8, 4 }, PixelFormatInfo::RGBA },
- { 1, 8, { 8, 0, 0, 0, 0, 0, 0, 0 }, PixelFormatInfo::ALPHA},
- { 1, 8, { 0, 0, 8, 0, 8, 0, 8, 0 }, PixelFormatInfo::L },
- { 2, 16, {16, 8, 8, 0, 8, 0, 8, 0 }, PixelFormatInfo::LA },
- { 1, 8, { 0, 0, 8, 5, 5, 2, 2, 0 }, PixelFormatInfo::RGB },
-};
-
-static const Info* gGetPixelFormatTable(size_t* numEntries) {
- if (numEntries) {
- *numEntries = sizeof(sPixelFormatInfos)/sizeof(Info);
- }
- return sPixelFormatInfos;
-}
-
-// ----------------------------------------------------------------------------
-
-size_t PixelFormatInfo::getScanlineSize(unsigned int width) const
-{
- size_t size;
- if (components == COMPONENT_YUV) {
- // YCbCr formats are different.
- size = (width * bitsPerPixel)>>3;
- } else {
- size = width * bytesPerPixel;
- }
- return size;
-}
-
-ssize_t bytesPerPixel(PixelFormat format)
-{
- PixelFormatInfo info;
- status_t err = getPixelFormatInfo(format, &info);
- return (err < 0) ? err : info.bytesPerPixel;
-}
-
-ssize_t bitsPerPixel(PixelFormat format)
-{
- PixelFormatInfo info;
- status_t err = getPixelFormatInfo(format, &info);
- return (err < 0) ? err : info.bitsPerPixel;
-}
-
-status_t getPixelFormatInfo(PixelFormat format, PixelFormatInfo* info)
-{
- if (format < 0)
- return BAD_VALUE;
-
- if (info->version != sizeof(PixelFormatInfo))
- return INVALID_OPERATION;
-
- // YUV format from the HAL are handled here
- switch (format) {
- case HAL_PIXEL_FORMAT_YCbCr_422_SP:
- case HAL_PIXEL_FORMAT_YCbCr_422_I:
- info->bitsPerPixel = 16;
- goto done;
- case HAL_PIXEL_FORMAT_YCrCb_420_SP:
- case HAL_PIXEL_FORMAT_YV12:
- info->bitsPerPixel = 12;
- done:
- info->format = format;
- info->components = COMPONENT_YUV;
- info->bytesPerPixel = 1;
- info->h_alpha = 0;
- info->l_alpha = 0;
- info->h_red = info->h_green = info->h_blue = 8;
- info->l_red = info->l_green = info->l_blue = 0;
- return NO_ERROR;
- }
-
- size_t numEntries;
- const Info *i = gGetPixelFormatTable(&numEntries) + format;
- bool valid = uint32_t(format) < numEntries;
- if (!valid) {
- return BAD_INDEX;
- }
-
- info->format = format;
- info->bytesPerPixel = i->size;
- info->bitsPerPixel = i->bitsPerPixel;
- info->h_alpha = i->ah;
- info->l_alpha = i->al;
- info->h_red = i->rh;
- info->l_red = i->rl;
- info->h_green = i->gh;
- info->l_green = i->gl;
- info->h_blue = i->bh;
- info->l_blue = i->bl;
- info->components = i->components;
-
- return NO_ERROR;
-}
-
-// ----------------------------------------------------------------------------
-}; // namespace android
-// ----------------------------------------------------------------------------
-
diff --git a/libs/ui/Rect.cpp b/libs/ui/Rect.cpp
deleted file mode 100644
index 5694e00..0000000
--- a/libs/ui/Rect.cpp
+++ /dev/null
@@ -1,95 +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.
- */
-
-#include <ui/Rect.h>
-
-namespace android {
-
-static inline int32_t min(int32_t a, int32_t b) {
- return (a<b) ? a : b;
-}
-
-static inline int32_t max(int32_t a, int32_t b) {
- return (a>b) ? a : b;
-}
-
-void Rect::makeInvalid() {
- left = 0;
- top = 0;
- right = -1;
- bottom = -1;
-}
-
-bool Rect::operator < (const Rect& rhs) const
-{
- if (top<rhs.top) {
- return true;
- } else if (top == rhs.top) {
- if (left < rhs.left) {
- return true;
- } else if (left == rhs.left) {
- if (bottom<rhs.bottom) {
- return true;
- } else if (bottom == rhs.bottom) {
- if (right<rhs.right) {
- return true;
- }
- }
- }
- }
- return false;
-}
-
-Rect& Rect::offsetTo(int32_t x, int32_t y)
-{
- right -= left - x;
- bottom -= top - y;
- left = x;
- top = y;
- return *this;
-}
-
-Rect& Rect::offsetBy(int32_t x, int32_t y)
-{
- left += x;
- top += y;
- right+= x;
- bottom+=y;
- return *this;
-}
-
-const Rect Rect::operator + (const Point& rhs) const
-{
- const Rect result(left+rhs.x, top+rhs.y, right+rhs.x, bottom+rhs.y);
- return result;
-}
-
-const Rect Rect::operator - (const Point& rhs) const
-{
- const Rect result(left-rhs.x, top-rhs.y, right-rhs.x, bottom-rhs.y);
- return result;
-}
-
-bool Rect::intersect(const Rect& with, Rect* result) const
-{
- result->left = max(left, with.left);
- result->top = max(top, with.top);
- result->right = min(right, with.right);
- result->bottom = min(bottom, with.bottom);
- return !(result->isEmpty());
-}
-
-}; // namespace android
diff --git a/libs/ui/Region.cpp b/libs/ui/Region.cpp
deleted file mode 100644
index 6e2e731..0000000
--- a/libs/ui/Region.cpp
+++ /dev/null
@@ -1,679 +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.
- */
-
-#define LOG_TAG "Region"
-
-#include <limits.h>
-
-#include <utils/Log.h>
-#include <utils/String8.h>
-
-#include <ui/Rect.h>
-#include <ui/Region.h>
-#include <ui/Point.h>
-
-#include <private/ui/RegionHelper.h>
-
-// ----------------------------------------------------------------------------
-#define VALIDATE_REGIONS (false)
-#define VALIDATE_WITH_CORECG (false)
-// ----------------------------------------------------------------------------
-
-#if VALIDATE_WITH_CORECG
-#include <core/SkRegion.h>
-#endif
-
-namespace android {
-// ----------------------------------------------------------------------------
-
-enum {
- op_nand = region_operator<Rect>::op_nand,
- op_and = region_operator<Rect>::op_and,
- op_or = region_operator<Rect>::op_or,
- op_xor = region_operator<Rect>::op_xor
-};
-
-// ----------------------------------------------------------------------------
-
-Region::Region()
- : mBounds(0,0)
-{
-}
-
-Region::Region(const Region& rhs)
- : mBounds(rhs.mBounds), 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()
-{
-}
-
-Region& Region::operator = (const Region& rhs)
-{
-#if VALIDATE_REGIONS
- validate(*this, "this->operator=");
- validate(rhs, "rhs.operator=");
-#endif
- mBounds = rhs.mBounds;
- mStorage = rhs.mStorage;
- return *this;
-}
-
-Region& Region::makeBoundsSelf()
-{
- mStorage.clear();
- return *this;
-}
-
-void Region::clear()
-{
- mBounds.clear();
- mStorage.clear();
-}
-
-void Region::set(const Rect& r)
-{
- mBounds = r;
- mStorage.clear();
-}
-
-void Region::set(uint32_t w, uint32_t h)
-{
- mBounds = Rect(int(w), int(h));
- mStorage.clear();
-}
-
-// ----------------------------------------------------------------------------
-
-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
-}
-
-// ----------------------------------------------------------------------------
-
-Region& Region::orSelf(const Rect& r) {
- return operationSelf(r, op_or);
-}
-Region& Region::xorSelf(const Rect& r) {
- return operationSelf(r, op_xor);
-}
-Region& Region::andSelf(const Rect& r) {
- return operationSelf(r, op_and);
-}
-Region& Region::subtractSelf(const Rect& r) {
- return operationSelf(r, op_nand);
-}
-Region& Region::operationSelf(const Rect& r, int op) {
- Region lhs(*this);
- boolean_operation(op, *this, lhs, r);
- return *this;
-}
-
-// ----------------------------------------------------------------------------
-
-Region& Region::orSelf(const Region& rhs) {
- return operationSelf(rhs, op_or);
-}
-Region& Region::xorSelf(const Region& rhs) {
- return operationSelf(rhs, op_xor);
-}
-Region& Region::andSelf(const Region& rhs) {
- return operationSelf(rhs, op_and);
-}
-Region& Region::subtractSelf(const Region& rhs) {
- return operationSelf(rhs, op_nand);
-}
-Region& Region::operationSelf(const Region& rhs, int op) {
- Region lhs(*this);
- boolean_operation(op, *this, lhs, rhs);
- return *this;
-}
-
-Region& Region::translateSelf(int x, int y) {
- if (x|y) translate(*this, x, y);
- return *this;
-}
-
-// ----------------------------------------------------------------------------
-
-const Region Region::merge(const Rect& rhs) const {
- return operation(rhs, op_or);
-}
-const Region Region::mergeExclusive(const Rect& rhs) const {
- return operation(rhs, op_xor);
-}
-const Region Region::intersect(const Rect& rhs) const {
- return operation(rhs, op_and);
-}
-const Region Region::subtract(const Rect& rhs) const {
- return operation(rhs, op_nand);
-}
-const Region Region::operation(const Rect& rhs, int op) const {
- Region result;
- boolean_operation(op, result, *this, rhs);
- return result;
-}
-
-// ----------------------------------------------------------------------------
-
-const Region Region::merge(const Region& rhs) const {
- return operation(rhs, op_or);
-}
-const Region Region::mergeExclusive(const Region& rhs) const {
- return operation(rhs, op_xor);
-}
-const Region Region::intersect(const Region& rhs) const {
- return operation(rhs, op_and);
-}
-const Region Region::subtract(const Region& rhs) const {
- return operation(rhs, op_nand);
-}
-const Region Region::operation(const Region& rhs, int op) const {
- Region result;
- boolean_operation(op, result, *this, rhs);
- return result;
-}
-
-const Region Region::translate(int x, int y) const {
- Region result;
- translate(result, *this, x, y);
- return result;
-}
-
-// ----------------------------------------------------------------------------
-
-Region& Region::orSelf(const Region& rhs, int dx, int dy) {
- return operationSelf(rhs, dx, dy, op_or);
-}
-Region& Region::xorSelf(const Region& rhs, int dx, int dy) {
- return operationSelf(rhs, dx, dy, op_xor);
-}
-Region& Region::andSelf(const Region& rhs, int dx, int dy) {
- return operationSelf(rhs, dx, dy, op_and);
-}
-Region& Region::subtractSelf(const Region& rhs, int dx, int dy) {
- return operationSelf(rhs, dx, dy, op_nand);
-}
-Region& Region::operationSelf(const Region& rhs, int dx, int dy, int op) {
- Region lhs(*this);
- boolean_operation(op, *this, lhs, rhs, dx, dy);
- return *this;
-}
-
-// ----------------------------------------------------------------------------
-
-const Region Region::merge(const Region& rhs, int dx, int dy) const {
- return operation(rhs, dx, dy, op_or);
-}
-const Region Region::mergeExclusive(const Region& rhs, int dx, int dy) const {
- return operation(rhs, dx, dy, op_xor);
-}
-const Region Region::intersect(const Region& rhs, int dx, int dy) const {
- return operation(rhs, dx, dy, op_and);
-}
-const Region Region::subtract(const Region& rhs, int dx, int dy) const {
- return operation(rhs, dx, dy, op_nand);
-}
-const Region Region::operation(const Region& rhs, int dx, int dy, int op) const {
- Region result;
- boolean_operation(op, result, *this, rhs, dx, dy);
- return result;
-}
-
-// ----------------------------------------------------------------------------
-
-// This is our region rasterizer, which merges rects and spans together
-// to obtain an optimal region.
-class Region::rasterizer : public region_operator<Rect>::region_rasterizer
-{
- Rect& bounds;
- Vector<Rect>& storage;
- Rect* head;
- Rect* tail;
- Vector<Rect> span;
- 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;
- storage.clear();
- }
-
- ~rasterizer() {
- if (span.size()) {
- flushSpan();
- }
- if (storage.size()) {
- bounds.top = storage.itemAt(0).top;
- bounds.bottom = storage.top().bottom;
- if (storage.size() == 1) {
- storage.clear();
- }
- } else {
- bounds.left = 0;
- bounds.right = 0;
- }
- }
-
- virtual void operator()(const Rect& rect) {
- //ALOGD(">>> %3d, %3d, %3d, %3d",
- // rect.left, rect.top, rect.right, rect.bottom);
- if (span.size()) {
- if (cur->top != rect.top) {
- flushSpan();
- } else if (cur->right == rect.left) {
- cur->right = rect.right;
- return;
- }
- }
- span.add(rect);
- cur = span.editArray() + (span.size() - 1);
- }
-private:
- template<typename T>
- static inline T min(T rhs, T lhs) { return rhs < lhs ? rhs : lhs; }
- template<typename T>
- static inline T max(T rhs, T lhs) { return rhs > lhs ? rhs : lhs; }
- void flushSpan() {
- bool merge = false;
- if (tail-head == ssize_t(span.size())) {
- Rect const* p = span.editArray();
- Rect const* q = head;
- if (p->top == q->bottom) {
- merge = true;
- while (q != tail) {
- if ((p->left != q->left) || (p->right != q->right)) {
- merge = false;
- break;
- }
- p++, q++;
- }
- }
- }
- if (merge) {
- const int bottom = span[0].bottom;
- Rect* r = head;
- while (r != tail) {
- r->bottom = bottom;
- r++;
- }
- } else {
- bounds.left = min(span.itemAt(0).left, bounds.left);
- bounds.right = max(span.top().right, bounds.right);
- storage.appendVector(span);
- tail = storage.editArray() + storage.size();
- head = tail - span.size();
- }
- span.clear();
- }
-};
-
-bool Region::validate(const Region& reg, const char* name)
-{
- bool result = true;
- const_iterator cur = reg.begin();
- const_iterator const tail = reg.end();
- 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);
- result = false;
- } else if (cur->left < prev->right) {
- ALOGE("%s: spans overlap horizontally 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;
- cur++;
- }
- if (b != reg.getBounds()) {
- result = false;
- ALOGE("%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) {
- reg.dump(name);
- }
- return result;
-}
-
-void Region::boolean_operation(int op, Region& dst,
- const Region& lhs,
- const Region& rhs, int dx, int dy)
-{
-#if VALIDATE_REGIONS
- validate(lhs, "boolean_operation (before): lhs");
- validate(rhs, "boolean_operation (before): rhs");
- validate(dst, "boolean_operation (before): dst");
-#endif
-
- size_t lhs_count;
- Rect const * const lhs_rects = lhs.getArray(&lhs_count);
-
- size_t rhs_count;
- Rect const * const rhs_rects = rhs.getArray(&rhs_count);
-
- region_operator<Rect>::region lhs_region(lhs_rects, lhs_count);
- region_operator<Rect>::region rhs_region(rhs_rects, rhs_count, dx, dy);
- region_operator<Rect> operation(op, lhs_region, rhs_region);
- { // scope for rasterizer (dtor has side effects)
- rasterizer r(dst);
- operation(r);
- }
-
-#if VALIDATE_REGIONS
- validate(lhs, "boolean_operation: lhs");
- validate(rhs, "boolean_operation: rhs");
- validate(dst, "boolean_operation: dst");
-#endif
-
-#if VALIDATE_WITH_CORECG
- SkRegion sk_lhs;
- SkRegion sk_rhs;
- SkRegion sk_dst;
-
- for (size_t i=0 ; i<lhs_count ; i++)
- sk_lhs.op(
- lhs_rects[i].left + dx,
- lhs_rects[i].top + dy,
- lhs_rects[i].right + dx,
- lhs_rects[i].bottom + dy,
- SkRegion::kUnion_Op);
-
- for (size_t i=0 ; i<rhs_count ; i++)
- sk_rhs.op(
- rhs_rects[i].left + dx,
- rhs_rects[i].top + dy,
- rhs_rects[i].right + dx,
- rhs_rects[i].bottom + dy,
- SkRegion::kUnion_Op);
-
- const char* name = "---";
- SkRegion::Op sk_op;
- switch (op) {
- case op_or: sk_op = SkRegion::kUnion_Op; name="OR"; break;
- case op_xor: sk_op = SkRegion::kUnion_XOR; name="XOR"; break;
- case op_and: sk_op = SkRegion::kIntersect_Op; name="AND"; break;
- case op_nand: sk_op = SkRegion::kDifference_Op; name="NAND"; break;
- }
- sk_dst.op(sk_lhs, sk_rhs, sk_op);
-
- if (sk_dst.isEmpty() && dst.isEmpty())
- return;
-
- bool same = true;
- Region::const_iterator head = dst.begin();
- Region::const_iterator const tail = dst.end();
- SkRegion::Iterator it(sk_dst);
- while (!it.done()) {
- if (head != tail) {
- if (
- head->left != it.rect().fLeft ||
- head->top != it.rect().fTop ||
- head->right != it.rect().fRight ||
- head->bottom != it.rect().fBottom
- ) {
- same = false;
- break;
- }
- } else {
- same = false;
- break;
- }
- head++;
- it.next();
- }
-
- if (head != tail) {
- same = false;
- }
-
- if(!same) {
- ALOGD("---\nregion boolean %s failed", name);
- lhs.dump("lhs");
- rhs.dump("rhs");
- dst.dump("dst");
- ALOGD("should be");
- SkRegion::Iterator it(sk_dst);
- while (!it.done()) {
- ALOGD(" [%3d, %3d, %3d, %3d]",
- it.rect().fLeft,
- it.rect().fTop,
- it.rect().fRight,
- it.rect().fBottom);
- it.next();
- }
- }
-#endif
-}
-
-void Region::boolean_operation(int op, Region& dst,
- const Region& lhs,
- const Rect& rhs, int dx, int dy)
-{
- if (!rhs.isValid()) {
- ALOGE("Region::boolean_operation(op=%d) invalid Rect={%d,%d,%d,%d}",
- op, rhs.left, rhs.top, rhs.right, rhs.bottom);
- return;
- }
-
-#if VALIDATE_WITH_CORECG || VALIDATE_REGIONS
- boolean_operation(op, dst, lhs, Region(rhs), dx, dy);
-#else
- size_t lhs_count;
- Rect const * const lhs_rects = lhs.getArray(&lhs_count);
-
- region_operator<Rect>::region lhs_region(lhs_rects, lhs_count);
- region_operator<Rect>::region rhs_region(&rhs, 1, dx, dy);
- region_operator<Rect> operation(op, lhs_region, rhs_region);
- { // scope for rasterizer (dtor has side effects)
- rasterizer r(dst);
- operation(r);
- }
-
-#endif
-}
-
-void Region::boolean_operation(int op, Region& dst,
- const Region& lhs, const Region& rhs)
-{
- boolean_operation(op, dst, lhs, rhs, 0, 0);
-}
-
-void Region::boolean_operation(int op, Region& dst,
- const Region& lhs, const Rect& rhs)
-{
- boolean_operation(op, dst, lhs, rhs, 0, 0);
-}
-
-void Region::translate(Region& reg, int dx, int dy)
-{
- if (!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) {
- rects->translate(dx, dy);
- rects++;
- count--;
- }
-#if VALIDATE_REGIONS
- validate(reg, "translate (after)");
-#endif
- }
-}
-
-void Region::translate(Region& dst, const Region& reg, int dx, int dy)
-{
- dst = reg;
- translate(dst, dx, dy);
-}
-
-// ----------------------------------------------------------------------------
-
-ssize_t Region::write(void* buffer, size_t size) const
-{
-#if VALIDATE_REGIONS
- validate(*this, "write(buffer)");
-#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);
-}
-
-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));
- }
-#if VALIDATE_REGIONS
- validate(*this, "read(buffer)");
-#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();
-}
-
-// ----------------------------------------------------------------------------
-
-Region::const_iterator Region::begin() const {
- return isRect() ? &mBounds : mStorage.array();
-}
-
-Region::const_iterator Region::end() const {
- return isRect() ? ((&mBounds) + 1) : (mStorage.array() + mStorage.size());
-}
-
-Rect const* Region::getArray(size_t* count) const {
- const_iterator const b(begin());
- const_iterator const e(end());
- if (count) *count = e-b;
- return b;
-}
-
-size_t Region::getRects(Vector<Rect>& rectList) const
-{
- rectList = mStorage;
- if (rectList.isEmpty()) {
- rectList.clear();
- rectList.add(mBounds);
- }
- return rectList.size();
-}
-
-// ----------------------------------------------------------------------------
-
-void Region::dump(String8& out, const char* what, uint32_t flags) const
-{
- (void)flags;
- const_iterator head = begin();
- const_iterator const tail = end();
-
- size_t SIZE = 256;
- char buffer[SIZE];
-
- snprintf(buffer, SIZE, " Region %s (this=%p, count=%d)\n",
- what, this, tail-head);
- out.append(buffer);
- while (head != tail) {
- snprintf(buffer, SIZE, " [%3d, %3d, %3d, %3d]\n",
- head->left, head->top, head->right, head->bottom);
- out.append(buffer);
- head++;
- }
-}
-
-void Region::dump(const char* what, uint32_t flags) const
-{
- (void)flags;
- const_iterator head = begin();
- const_iterator const tail = end();
- ALOGD(" Region %s (this=%p, count=%d)\n", what, this, tail-head);
- while (head != tail) {
- ALOGD(" [%3d, %3d, %3d, %3d]\n",
- head->left, head->top, head->right, head->bottom);
- head++;
- }
-}
-
-// ----------------------------------------------------------------------------
-
-}; // namespace android
diff --git a/libs/ui/tests/Android.mk b/libs/ui/tests/Android.mk
deleted file mode 100644
index 50cad36..0000000
--- a/libs/ui/tests/Android.mk
+++ /dev/null
@@ -1,6 +0,0 @@
-# Build the unit tests.
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-# Build the manual test programs.
-include $(call all-makefiles-under, $(LOCAL_PATH))
diff --git a/libs/ui/tests/region/Android.mk b/libs/ui/tests/region/Android.mk
deleted file mode 100644
index 6cc4a5a..0000000
--- a/libs/ui/tests/region/Android.mk
+++ /dev/null
@@ -1,16 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES:= \
- region.cpp
-
-LOCAL_SHARED_LIBRARIES := \
- libcutils \
- libutils \
- libui
-
-LOCAL_MODULE:= test-region
-
-LOCAL_MODULE_TAGS := tests
-
-include $(BUILD_EXECUTABLE)
diff --git a/libs/ui/tests/region/region.cpp b/libs/ui/tests/region/region.cpp
deleted file mode 100644
index 6347294..0000000
--- a/libs/ui/tests/region/region.cpp
+++ /dev/null
@@ -1,69 +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.
- */
-
-#define LOG_TAG "Region"
-
-#include <stdio.h>
-#include <utils/Debug.h>
-#include <ui/Rect.h>
-#include <ui/Region.h>
-
-using namespace android;
-
-int main()
-{
- Region empty;
- Region reg0( Rect( 0, 0, 100, 100 ) );
- Region reg1 = reg0;
- Region reg2, reg3;
-
- Region reg4 = empty | reg1;
- Region reg5 = reg1 | empty;
-
- reg4.dump("reg4");
- reg5.dump("reg5");
-
- reg0.dump("reg0");
- reg1.dump("reg1");
-
- reg0 = reg0 | reg0.translate(150, 0);
- reg0.dump("reg0");
- reg1.dump("reg1");
-
- reg0 = reg0 | reg0.translate(300, 0);
- reg0.dump("reg0");
- reg1.dump("reg1");
-
- //reg2 = reg0 | reg0.translate(0, 100);
- //reg0.dump("reg0");
- //reg1.dump("reg1");
- //reg2.dump("reg2");
-
- //reg3 = reg0 | reg0.translate(0, 150);
- //reg0.dump("reg0");
- //reg1.dump("reg1");
- //reg2.dump("reg2");
- //reg3.dump("reg3");
-
- ALOGD("---");
- reg2 = reg0 | reg0.translate(100, 0);
- reg0.dump("reg0");
- reg1.dump("reg1");
- reg2.dump("reg2");
-
- return 0;
-}
-