Merge "libui: Enable -Weverything and -Werror"

This commit is contained in:
Dan Albert 2014-12-05 17:48:10 +00:00 committed by Gerrit Code Review
commit 35df753169
15 changed files with 377 additions and 326 deletions

View File

@ -65,7 +65,7 @@ public:
// before the fence signals then -ETIME is returned. A timeout of
// TIMEOUT_NEVER may be used to indicate that the call should wait
// indefinitely for the fence to signal.
status_t wait(unsigned int timeout);
status_t wait(int timeout);
// waitForever is a convenience function for waiting forever for a fence to
// signal (just like wait(TIMEOUT_NEVER)), but issuing an error to the

View File

@ -49,7 +49,7 @@ public:
USAGE_SW_READ_RARELY = GRALLOC_USAGE_SW_READ_RARELY,
USAGE_SW_READ_OFTEN = GRALLOC_USAGE_SW_READ_OFTEN,
USAGE_SW_READ_MASK = GRALLOC_USAGE_SW_READ_MASK,
USAGE_SW_WRITE_NEVER = GRALLOC_USAGE_SW_WRITE_NEVER,
USAGE_SW_WRITE_RARELY = GRALLOC_USAGE_SW_WRITE_RARELY,
USAGE_SW_WRITE_OFTEN = GRALLOC_USAGE_SW_WRITE_OFTEN,
@ -72,11 +72,13 @@ public:
GraphicBuffer();
// creates w * h buffer
GraphicBuffer(int w, int h, PixelFormat format, int usage);
GraphicBuffer(uint32_t inWidth, uint32_t inHeight, PixelFormat inFormat,
uint32_t inUsage);
// create a buffer from an existing handle
GraphicBuffer(int w, int h, PixelFormat format, int usage,
int stride, native_handle_t* handle, bool keepOwnership);
GraphicBuffer(uint32_t inWidth, uint32_t inHeight, PixelFormat inFormat,
uint32_t inUsage, uint32_t inStride, native_handle_t* inHandle,
bool keepOwnership);
// create a buffer from an existing ANativeWindowBuffer
GraphicBuffer(ANativeWindowBuffer* buffer, bool keepOwnership);
@ -84,26 +86,31 @@ public:
// return status
status_t initCheck() const;
int getWidth() const { return width; }
int getHeight() const { return height; }
int getStride() const { return stride; }
int getUsage() const { return usage; }
uint32_t getWidth() const { return static_cast<uint32_t>(width); }
uint32_t getHeight() const { return static_cast<uint32_t>(height); }
uint32_t getStride() const { return static_cast<uint32_t>(stride); }
uint32_t getUsage() const { return static_cast<uint32_t>(usage); }
PixelFormat getPixelFormat() const { return format; }
Rect getBounds() const { return Rect(width, height); }
uint64_t getId() const { return mId; }
status_t reallocate(int w, int h, PixelFormat f, int usage);
status_t reallocate(uint32_t inWidth, uint32_t inHeight,
PixelFormat inFormat, uint32_t inUsage);
status_t lock(uint32_t usage, void** vaddr);
status_t lock(uint32_t usage, const Rect& rect, void** vaddr);
status_t lock(uint32_t inUsage, void** vaddr);
status_t lock(uint32_t inUsage, const Rect& rect, void** vaddr);
// For HAL_PIXEL_FORMAT_YCbCr_420_888
status_t lockYCbCr(uint32_t usage, android_ycbcr *ycbcr);
status_t lockYCbCr(uint32_t usage, const Rect& rect, android_ycbcr *ycbcr);
status_t lockYCbCr(uint32_t inUsage, android_ycbcr *ycbcr);
status_t lockYCbCr(uint32_t inUsage, const Rect& rect,
android_ycbcr *ycbcr);
status_t unlock();
status_t lockAsync(uint32_t usage, void** vaddr, int fenceFd);
status_t lockAsync(uint32_t usage, const Rect& rect, void** vaddr, int fenceFd);
status_t lockAsyncYCbCr(uint32_t usage, android_ycbcr *ycbcr, int fenceFd);
status_t lockAsyncYCbCr(uint32_t usage, const Rect& rect, android_ycbcr *ycbcr, int fenceFd);
status_t lockAsync(uint32_t inUsage, void** vaddr, int fenceFd);
status_t lockAsync(uint32_t inUsage, const Rect& rect, void** vaddr,
int fenceFd);
status_t lockAsyncYCbCr(uint32_t inUsage, android_ycbcr *ycbcr,
int fenceFd);
status_t lockAsyncYCbCr(uint32_t inUsage, const Rect& rect,
android_ycbcr *ycbcr, int fenceFd);
status_t unlockAsync(int *fenceFd);
ANativeWindowBuffer* getNativeBuffer() const;
@ -143,8 +150,8 @@ private:
GraphicBuffer& operator = (const GraphicBuffer& rhs);
const GraphicBuffer& operator = (const GraphicBuffer& rhs) const;
status_t initSize(uint32_t w, uint32_t h, PixelFormat format,
uint32_t usage);
status_t initSize(uint32_t inWidth, uint32_t inHeight, PixelFormat inFormat,
uint32_t inUsage);
void free_handle();

View File

@ -1,17 +1,17 @@
/*
/*
**
** Copyright 2009, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
@ -45,14 +45,14 @@ public:
USAGE_SW_READ_RARELY = GRALLOC_USAGE_SW_READ_RARELY,
USAGE_SW_READ_OFTEN = GRALLOC_USAGE_SW_READ_OFTEN,
USAGE_SW_READ_MASK = GRALLOC_USAGE_SW_READ_MASK,
USAGE_SW_WRITE_NEVER = GRALLOC_USAGE_SW_WRITE_NEVER,
USAGE_SW_WRITE_RARELY = GRALLOC_USAGE_SW_WRITE_RARELY,
USAGE_SW_WRITE_OFTEN = GRALLOC_USAGE_SW_WRITE_OFTEN,
USAGE_SW_WRITE_MASK = GRALLOC_USAGE_SW_WRITE_MASK,
USAGE_SOFTWARE_MASK = USAGE_SW_READ_MASK|USAGE_SW_WRITE_MASK,
USAGE_HW_TEXTURE = GRALLOC_USAGE_HW_TEXTURE,
USAGE_HW_RENDER = GRALLOC_USAGE_HW_RENDER,
USAGE_HW_2D = GRALLOC_USAGE_HW_2D,
@ -60,10 +60,9 @@ public:
};
static inline GraphicBufferAllocator& get() { return getInstance(); }
status_t alloc(uint32_t w, uint32_t h, PixelFormat format, int usage,
buffer_handle_t* handle, int32_t* stride);
status_t alloc(uint32_t w, uint32_t h, PixelFormat format, uint32_t usage,
buffer_handle_t* handle, uint32_t* stride);
status_t free(buffer_handle_t handle);
@ -72,21 +71,21 @@ public:
private:
struct alloc_rec_t {
uint32_t w;
uint32_t h;
uint32_t s;
uint32_t width;
uint32_t height;
uint32_t stride;
PixelFormat format;
uint32_t usage;
size_t size;
};
static Mutex sLock;
static KeyedVector<buffer_handle_t, alloc_rec_t> sAllocList;
friend class Singleton<GraphicBufferAllocator>;
GraphicBufferAllocator();
~GraphicBufferAllocator();
alloc_device_t *mAllocDev;
};

View File

@ -41,23 +41,24 @@ public:
status_t registerBuffer(buffer_handle_t handle);
status_t unregisterBuffer(buffer_handle_t handle);
status_t lock(buffer_handle_t handle,
int usage, const Rect& bounds, void** vaddr);
uint32_t usage, const Rect& bounds, void** vaddr);
status_t lockYCbCr(buffer_handle_t handle,
int usage, const Rect& bounds, android_ycbcr *ycbcr);
uint32_t usage, const Rect& bounds, android_ycbcr *ycbcr);
status_t unlock(buffer_handle_t handle);
status_t lockAsync(buffer_handle_t handle,
int usage, const Rect& bounds, void** vaddr, int fenceFd);
uint32_t usage, const Rect& bounds, void** vaddr, int fenceFd);
status_t lockAsyncYCbCr(buffer_handle_t handle,
int usage, const Rect& bounds, android_ycbcr *ycbcr, int fenceFd);
uint32_t usage, const Rect& bounds, android_ycbcr *ycbcr,
int fenceFd);
status_t unlockAsync(buffer_handle_t handle, int *fenceFd);
// dumps information about the mapping of this handle
void dump(buffer_handle_t handle);

View File

@ -25,9 +25,6 @@
#ifndef UI_PIXELFORMAT_H
#define UI_PIXELFORMAT_H
#include <stdint.h>
#include <sys/types.h>
#include <utils/Errors.h>
#include <hardware/hardware.h>
namespace android {
@ -69,8 +66,8 @@ enum {
typedef int32_t PixelFormat;
ssize_t bytesPerPixel(PixelFormat format);
ssize_t bitsPerPixel(PixelFormat format);
uint32_t bytesPerPixel(PixelFormat format);
uint32_t bitsPerPixel(PixelFormat format);
}; // namespace android

View File

@ -55,11 +55,11 @@ public:
// the region becomes its bounds
Region& makeBoundsSelf();
void clear();
void set(const Rect& r);
void set(uint32_t w, uint32_t h);
void set(int32_t w, int32_t h);
Region& orSelf(const Rect& rhs);
Region& xorSelf(const Rect& rhs);
Region& andSelf(const Rect& rhs);
@ -110,14 +110,14 @@ public:
inline Region& operator -= (const Region& rhs);
inline Region& operator += (const Point& pt);
// returns true if the regions share the same underlying storage
bool isTriviallyEqual(const Region& region) const;
/* various ways to access the rectangle list */
// STL-like iterators
typedef Rect const* const_iterator;
const_iterator begin() const;
@ -133,7 +133,7 @@ public:
SharedBuffer const* getSharedBuffer(size_t* count) const;
/* no user serviceable parts here... */
// add a rectangle to the internal list. This rectangle must
// be sorted in Y and X and must not make the region invalid.
void addRectUnchecked(int l, int t, int r, int b);
@ -149,7 +149,7 @@ public:
private:
class rasterizer;
friend class rasterizer;
Region& operationSelf(const Rect& r, int op);
Region& operationSelf(const Region& r, int op);
Region& operationSelf(const Region& r, int dx, int dy, int op);
@ -172,7 +172,7 @@ private:
static bool validate(const Region& reg,
const char* name, bool silent = false);
// mStorage is a (manually) sorted array of Rects describing the region
// with an extra Rect as the last element which is set to the
// bounds of the region. However, if the region is

View File

@ -16,7 +16,19 @@ LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_CLANG := true
LOCAL_CPPFLAGS := -std=c++11
LOCAL_CPPFLAGS := -std=c++1y -Weverything -Werror
# The static constructors and destructors in this library have not been noted to
# introduce significant overheads
LOCAL_CPPFLAGS += -Wno-exit-time-destructors
LOCAL_CPPFLAGS += -Wno-global-constructors
# We only care about compiling as C++14
LOCAL_CPPFLAGS += -Wno-c++98-compat-pedantic
# We use four-character constants for the GraphicBuffer header, and don't care
# that they're non-portable as long as they're consistent within one execution
LOCAL_CPPFLAGS += -Wno-four-char-constants
LOCAL_SRC_FILES := \
Fence.cpp \

View File

@ -18,10 +18,13 @@
#define ATRACE_TAG ATRACE_TAG_GRAPHICS
//#define LOG_NDEBUG 0
// This is needed for stdint.h to define INT64_MAX in C++
#define __STDC_LIMIT_MACROS
// We would eliminate the non-conforming zero-length array, but we can't since
// this is effectively included from the Linux kernel
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wzero-length-array"
#include <sync/sync.h>
#pragma clang diagnostic pop
#include <ui/Fence.h>
#include <unistd.h>
#include <utils/Log.h>
@ -45,7 +48,7 @@ Fence::~Fence() {
}
}
status_t Fence::wait(unsigned int timeout) {
status_t Fence::wait(int timeout) {
ATRACE_CALL();
if (mFenceFd == -1) {
return NO_ERROR;
@ -59,7 +62,7 @@ status_t Fence::waitForever(const char* logname) {
if (mFenceFd == -1) {
return NO_ERROR;
}
unsigned int warningTimeout = 3000;
int warningTimeout = 3000;
int err = sync_wait(mFenceFd, warningTimeout);
if (err < 0 && errno == ETIME) {
ALOGE("%s: fence %d didn't signal in %u ms", logname, mFenceFd,
@ -138,7 +141,7 @@ status_t Fence::flatten(void*& buffer, size_t& size, int*& fds, size_t& count) c
if (size < getFlattenedSize() || count < getFdCount()) {
return NO_MEMORY;
}
FlattenableUtils::write(buffer, size, (uint32_t)getFdCount());
FlattenableUtils::write(buffer, size, getFdCount());
if (isValid()) {
*fds++ = mFenceFd;
count--;

View File

@ -1,17 +1,17 @@
/*
/*
**
** 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
** Licensed under the Apache License Version 2.0(the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing software
** distributed under the License is distributed on an "AS IS" BASIS
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND either express or implied.
** See the License for the specific language governing permissions and
** Unless required by applicable law or agreed to in writing software
** distributed under the License is distributed on an "AS IS" BASIS
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
@ -43,11 +43,11 @@
namespace android {
// ----------------------------------------------------------------------------
class NativeBuffer
class NativeBuffer final
: public ANativeObjectBase<
ANativeWindowBuffer,
NativeBuffer,
LightRefBase<NativeBuffer> >
ANativeWindowBuffer,
NativeBuffer,
LightRefBase<NativeBuffer>>
{
public:
NativeBuffer(int w, int h, int f, int u) : BASE() {
@ -57,24 +57,23 @@ public:
ANativeWindowBuffer::usage = u;
}
private:
friend class LightRefBase<NativeBuffer>;
~NativeBuffer() { }; // this class cannot be overloaded
friend class LightRefBase<NativeBuffer>;
};
/*
* 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
*
* Currently it is pretty simple, it manages only two buffers (the front and
* back buffer).
*
*
*/
FramebufferNativeWindow::FramebufferNativeWindow()
FramebufferNativeWindow::FramebufferNativeWindow()
: BASE(), fbDev(0), grDev(0), mUpdateOnDemand(false)
{
hw_module_t const* module;
@ -84,16 +83,16 @@ FramebufferNativeWindow::FramebufferNativeWindow()
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
if(fbDev->numFramebuffers >= MIN_NUM_FRAME_BUFFERS &&
fbDev->numFramebuffers <= MAX_NUM_FRAME_BUFFERS){
@ -116,36 +115,37 @@ FramebufferNativeWindow::FramebufferNativeWindow()
*((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++) {
buffers[i] = new NativeBuffer(
static_cast<int>(fbDev->width),
static_cast<int>(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);
for (i = 0; i < mNumBuffers; i++) {
err = grDev->alloc(grDev,
static_cast<int>(fbDev->width),
static_cast<int>(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));
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;
}
if (err) {
mNumBuffers = i;
mNumFreeBuffers = i;
mBufferHead = mNumBuffers-1;
break;
}
}
const_cast<uint32_t&>(ANativeWindow::flags) = fbDev->flags;
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) =
const_cast<int&>(ANativeWindow::minSwapInterval) =
fbDev->minSwapInterval;
const_cast<int&>(ANativeWindow::maxSwapInterval) =
const_cast<int&>(ANativeWindow::maxSwapInterval) =
fbDev->maxSwapInterval;
} else {
ALOGE("Couldn't get gralloc module");
@ -162,7 +162,7 @@ FramebufferNativeWindow::FramebufferNativeWindow()
ANativeWindow::queueBuffer_DEPRECATED = queueBuffer_DEPRECATED;
}
FramebufferNativeWindow::~FramebufferNativeWindow()
FramebufferNativeWindow::~FramebufferNativeWindow()
{
if (grDev) {
for(int i = 0; i < mNumBuffers; i++) {
@ -178,7 +178,7 @@ FramebufferNativeWindow::~FramebufferNativeWindow()
}
}
status_t FramebufferNativeWindow::setUpdateRectangle(const Rect& r)
status_t FramebufferNativeWindow::setUpdateRectangle(const Rect& r)
{
if (!mUpdateOnDemand) {
return INVALID_OPERATION;
@ -195,7 +195,7 @@ status_t FramebufferNativeWindow::compositionComplete()
}
int FramebufferNativeWindow::setSwapInterval(
ANativeWindow* window, int interval)
ANativeWindow* window, int interval)
{
framebuffer_device_t* fb = getSelf(window)->fbDev;
return fb->setSwapInterval(fb, interval);
@ -219,7 +219,7 @@ int FramebufferNativeWindow::getCurrentBufferIndex() const
return index;
}
int FramebufferNativeWindow::dequeueBuffer_DEPRECATED(ANativeWindow* window,
int FramebufferNativeWindow::dequeueBuffer_DEPRECATED(ANativeWindow* window,
ANativeWindowBuffer** buffer)
{
int fenceFd = -1;
@ -234,7 +234,7 @@ int FramebufferNativeWindow::dequeueBuffer_DEPRECATED(ANativeWindow* window,
return result;
}
int FramebufferNativeWindow::dequeueBuffer(ANativeWindow* window,
int FramebufferNativeWindow::dequeueBuffer(ANativeWindow* window,
ANativeWindowBuffer** buffer, int* fenceFd)
{
FramebufferNativeWindow* self = getSelf(window);
@ -249,7 +249,7 @@ int FramebufferNativeWindow::dequeueBuffer(ANativeWindow* window,
while (self->mNumFreeBuffers < 2) {
self->mCondition.wait(self->mutex);
}
ALOG_ASSERT(self->buffers[index] != self->front);
ALOG_ASSERT(self->buffers[index] != self->front, "");
// get this buffer
self->mNumFreeBuffers--;
@ -261,19 +261,19 @@ int FramebufferNativeWindow::dequeueBuffer(ANativeWindow* window,
return 0;
}
int FramebufferNativeWindow::lockBuffer_DEPRECATED(ANativeWindow* /*window*/,
int FramebufferNativeWindow::lockBuffer_DEPRECATED(ANativeWindow* /*window*/,
ANativeWindowBuffer* /*buffer*/)
{
return NO_ERROR;
}
int FramebufferNativeWindow::queueBuffer_DEPRECATED(ANativeWindow* window,
int FramebufferNativeWindow::queueBuffer_DEPRECATED(ANativeWindow* window,
ANativeWindowBuffer* buffer)
{
return queueBuffer(window, buffer, -1);
}
int FramebufferNativeWindow::queueBuffer(ANativeWindow* window,
int FramebufferNativeWindow::queueBuffer(ANativeWindow* window,
ANativeWindowBuffer* buffer, int fenceFd)
{
FramebufferNativeWindow* self = getSelf(window);
@ -293,17 +293,17 @@ int FramebufferNativeWindow::queueBuffer(ANativeWindow* window,
}
int FramebufferNativeWindow::query(const ANativeWindow* window,
int what, int* value)
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;
*value = static_cast<int>(fb->width);
return NO_ERROR;
case NATIVE_WINDOW_HEIGHT:
*value = fb->height;
*value = static_cast<int>(fb->height);
return NO_ERROR;
case NATIVE_WINDOW_FORMAT:
*value = fb->format;
@ -315,10 +315,10 @@ int FramebufferNativeWindow::query(const ANativeWindow* window,
*value = 0;
return NO_ERROR;
case NATIVE_WINDOW_DEFAULT_WIDTH:
*value = fb->width;
*value = static_cast<int>(fb->width);
return NO_ERROR;
case NATIVE_WINDOW_DEFAULT_HEIGHT:
*value = fb->height;
*value = static_cast<int>(fb->height);
return NO_ERROR;
case NATIVE_WINDOW_TRANSFORM_HINT:
*value = 0;
@ -359,7 +359,8 @@ int FramebufferNativeWindow::perform(ANativeWindow* /*window*/,
}; // namespace android
// ----------------------------------------------------------------------------
using namespace android;
using android::sp;
using android::FramebufferNativeWindow;
EGLNativeWindowType android_createDisplaySurface(void)
{
@ -370,5 +371,5 @@ EGLNativeWindowType android_createDisplaySurface(void)
sp<FramebufferNativeWindow> ref(w);
return NULL;
}
return (EGLNativeWindowType)w;
return static_cast<EGLNativeWindowType>(w);
}

View File

@ -53,7 +53,8 @@ GraphicBuffer::GraphicBuffer()
handle = NULL;
}
GraphicBuffer::GraphicBuffer(int w, int h, PixelFormat reqFormat, int reqUsage)
GraphicBuffer::GraphicBuffer(uint32_t inWidth, uint32_t inHeight,
PixelFormat inFormat, uint32_t inUsage)
: BASE(), mOwner(ownData), mBufferMapper(GraphicBufferMapper::get()),
mInitCheck(NO_ERROR), mId(getUniqueId())
{
@ -63,20 +64,21 @@ GraphicBuffer::GraphicBuffer(int w, int h, PixelFormat reqFormat, int reqUsage)
format =
usage = 0;
handle = NULL;
mInitCheck = initSize(w, h, reqFormat, reqUsage);
mInitCheck = initSize(inWidth, inHeight, inFormat, inUsage);
}
GraphicBuffer::GraphicBuffer(int w, int h, PixelFormat inFormat, int inUsage,
int inStride, native_handle_t* inHandle, bool keepOwnership)
GraphicBuffer::GraphicBuffer(uint32_t inWidth, uint32_t inHeight,
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), mId(getUniqueId())
{
width = w;
height = h;
stride = inStride;
width = static_cast<int>(inWidth);
height = static_cast<int>(inHeight);
stride = static_cast<int>(inStride);
format = inFormat;
usage = inUsage;
usage = static_cast<int>(inUsage);
handle = inHandle;
}
@ -129,12 +131,17 @@ ANativeWindowBuffer* GraphicBuffer::getNativeBuffer() const
const_cast<GraphicBuffer*>(this));
}
status_t GraphicBuffer::reallocate(int w, int h, PixelFormat f, int reqUsage)
status_t GraphicBuffer::reallocate(uint32_t inWidth, uint32_t inHeight,
PixelFormat inFormat, uint32_t inUsage)
{
if (mOwner != ownData)
return INVALID_OPERATION;
if (handle && w==width && h==height && f==format && reqUsage==usage)
if (handle &&
static_cast<int>(inWidth) == width &&
static_cast<int>(inHeight) == height &&
inFormat == format &&
static_cast<int>(inUsage) == usage)
return NO_ERROR;
if (handle) {
@ -142,61 +149,64 @@ status_t GraphicBuffer::reallocate(int w, int h, PixelFormat f, int reqUsage)
allocator.free(handle);
handle = 0;
}
return initSize(w, h, f, reqUsage);
return initSize(inWidth, inHeight, inFormat, inUsage);
}
status_t GraphicBuffer::initSize(uint32_t w, uint32_t h, PixelFormat format,
uint32_t reqUsage)
status_t GraphicBuffer::initSize(uint32_t inWidth, uint32_t inHeight,
PixelFormat inFormat, uint32_t inUsage)
{
GraphicBufferAllocator& allocator = GraphicBufferAllocator::get();
status_t err = allocator.alloc(w, h, format, reqUsage, &handle, &stride);
uint32_t outStride = 0;
status_t err = allocator.alloc(inWidth, inHeight, inFormat, inUsage,
&handle, &outStride);
if (err == NO_ERROR) {
this->width = w;
this->height = h;
this->format = format;
this->usage = reqUsage;
width = static_cast<int>(inWidth);
height = static_cast<int>(inHeight);
format = inFormat;
usage = static_cast<int>(inUsage);
stride = static_cast<int>(outStride);
}
return err;
}
status_t GraphicBuffer::lock(uint32_t usage, void** vaddr)
status_t GraphicBuffer::lock(uint32_t inUsage, void** vaddr)
{
const Rect lockBounds(width, height);
status_t res = lock(usage, lockBounds, vaddr);
status_t res = lock(inUsage, lockBounds, vaddr);
return res;
}
status_t GraphicBuffer::lock(uint32_t usage, const Rect& rect, void** vaddr)
status_t GraphicBuffer::lock(uint32_t inUsage, const Rect& rect, void** vaddr)
{
if (rect.left < 0 || rect.right > this->width ||
rect.top < 0 || rect.bottom > this->height) {
if (rect.left < 0 || rect.right > width ||
rect.top < 0 || rect.bottom > 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);
width, height);
return BAD_VALUE;
}
status_t res = getBufferMapper().lock(handle, usage, rect, vaddr);
status_t res = getBufferMapper().lock(handle, inUsage, rect, vaddr);
return res;
}
status_t GraphicBuffer::lockYCbCr(uint32_t usage, android_ycbcr *ycbcr)
status_t GraphicBuffer::lockYCbCr(uint32_t inUsage, android_ycbcr* ycbcr)
{
const Rect lockBounds(width, height);
status_t res = lockYCbCr(usage, lockBounds, ycbcr);
status_t res = lockYCbCr(inUsage, lockBounds, ycbcr);
return res;
}
status_t GraphicBuffer::lockYCbCr(uint32_t usage, const Rect& rect,
android_ycbcr *ycbcr)
status_t GraphicBuffer::lockYCbCr(uint32_t inUsage, const Rect& rect,
android_ycbcr* ycbcr)
{
if (rect.left < 0 || rect.right > this->width ||
rect.top < 0 || rect.bottom > this->height) {
if (rect.left < 0 || rect.right > width ||
rect.top < 0 || rect.bottom > 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);
width, height);
return BAD_VALUE;
}
status_t res = getBufferMapper().lockYCbCr(handle, usage, rect, ycbcr);
status_t res = getBufferMapper().lockYCbCr(handle, inUsage, rect, ycbcr);
return res;
}
@ -206,43 +216,48 @@ status_t GraphicBuffer::unlock()
return res;
}
status_t GraphicBuffer::lockAsync(uint32_t usage, void** vaddr, int fenceFd)
status_t GraphicBuffer::lockAsync(uint32_t inUsage, void** vaddr, int fenceFd)
{
const Rect lockBounds(width, height);
status_t res = lockAsync(usage, lockBounds, vaddr, fenceFd);
status_t res = lockAsync(inUsage, lockBounds, vaddr, fenceFd);
return res;
}
status_t GraphicBuffer::lockAsync(uint32_t usage, const Rect& rect, void** vaddr, int fenceFd)
status_t GraphicBuffer::lockAsync(uint32_t inUsage, const Rect& rect,
void** vaddr, int fenceFd)
{
if (rect.left < 0 || rect.right > this->width ||
rect.top < 0 || rect.bottom > this->height) {
if (rect.left < 0 || rect.right > width ||
rect.top < 0 || rect.bottom > 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);
width, height);
return BAD_VALUE;
}
status_t res = getBufferMapper().lockAsync(handle, usage, rect, vaddr, fenceFd);
status_t res = getBufferMapper().lockAsync(handle, inUsage, rect, vaddr,
fenceFd);
return res;
}
status_t GraphicBuffer::lockAsyncYCbCr(uint32_t usage, android_ycbcr *ycbcr, int fenceFd)
status_t GraphicBuffer::lockAsyncYCbCr(uint32_t inUsage, android_ycbcr* ycbcr,
int fenceFd)
{
const Rect lockBounds(width, height);
status_t res = lockAsyncYCbCr(usage, lockBounds, ycbcr, fenceFd);
status_t res = lockAsyncYCbCr(inUsage, lockBounds, ycbcr, fenceFd);
return res;
}
status_t GraphicBuffer::lockAsyncYCbCr(uint32_t usage, const Rect& rect, android_ycbcr *ycbcr, int fenceFd)
status_t GraphicBuffer::lockAsyncYCbCr(uint32_t inUsage, const Rect& rect,
android_ycbcr* ycbcr, int fenceFd)
{
if (rect.left < 0 || rect.right > this->width ||
rect.top < 0 || rect.bottom > this->height) {
if (rect.left < 0 || rect.right > width ||
rect.top < 0 || rect.bottom > 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);
width, height);
return BAD_VALUE;
}
status_t res = getBufferMapper().lockAsyncYCbCr(handle, usage, rect, ycbcr, fenceFd);
status_t res = getBufferMapper().lockAsyncYCbCr(handle, inUsage, rect,
ycbcr, fenceFd);
return res;
}
@ -253,11 +268,11 @@ status_t GraphicBuffer::unlockAsync(int *fenceFd)
}
size_t GraphicBuffer::getFlattenedSize() const {
return (10 + (handle ? handle->numInts : 0))*sizeof(int);
return static_cast<size_t>(10 + (handle ? handle->numInts : 0)) * sizeof(int);
}
size_t GraphicBuffer::getFdCount() const {
return handle ? handle->numFds : 0;
return static_cast<size_t>(handle ? handle->numFds : 0);
}
status_t GraphicBuffer::flatten(void*& buffer, size_t& size, int*& fds, size_t& count) const {
@ -282,16 +297,17 @@ status_t GraphicBuffer::flatten(void*& buffer, size_t& size, int*& fds, size_t&
if (handle) {
buf[8] = handle->numFds;
buf[9] = handle->numInts;
native_handle_t const* const h = handle;
memcpy(fds, h->data, h->numFds*sizeof(int));
memcpy(&buf[10], h->data + h->numFds, h->numInts*sizeof(int));
memcpy(fds, handle->data,
static_cast<size_t>(handle->numFds) * sizeof(int));
memcpy(&buf[10], handle->data + handle->numFds,
static_cast<size_t>(handle->numInts) * sizeof(int));
}
buffer = reinterpret_cast<void*>(static_cast<int*>(buffer) + sizeNeeded);
size -= sizeNeeded;
if (handle) {
fds += handle->numFds;
count -= handle->numFds;
count -= static_cast<size_t>(handle->numFds);
}
return NO_ERROR;
@ -304,8 +320,8 @@ status_t GraphicBuffer::unflatten(
int const* buf = static_cast<int const*>(buffer);
if (buf[0] != 'GBFR') return BAD_TYPE;
const size_t numFds = buf[8];
const size_t numInts = buf[9];
const size_t numFds = static_cast<size_t>(buf[8]);
const size_t numInts = static_cast<size_t>(buf[9]);
const size_t maxNumber = UINT_MAX / sizeof(int);
if (numFds >= maxNumber || numInts >= (maxNumber - 10)) {
@ -333,15 +349,16 @@ status_t GraphicBuffer::unflatten(
stride = buf[3];
format = buf[4];
usage = buf[5];
native_handle* h = native_handle_create(numFds, numInts);
native_handle* h = native_handle_create(
static_cast<int>(numFds), static_cast<int>(numInts));
if (!h) {
width = height = stride = format = usage = 0;
handle = NULL;
ALOGE("unflatten: native_handle_create failed");
return NO_MEMORY;
}
memcpy(h->data, fds, numFds*sizeof(int));
memcpy(h->data + numFds, &buf[10], numInts*sizeof(int));
memcpy(h->data, fds, numFds * sizeof(int));
memcpy(h->data + numFds, &buf[10], numInts * sizeof(int));
handle = h;
} else {
width = height = stride = format = usage = 0;

View File

@ -1,17 +1,17 @@
/*
/*
**
** Copyright 2009, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
@ -66,11 +66,11 @@ void GraphicBufferAllocator::dump(String8& result) const
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);
rec.width, rec.stride, rec.height, 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);
rec.width, rec.stride, rec.height, rec.format, rec.usage);
}
result.append(buffer);
total += rec.size;
@ -90,39 +90,40 @@ void GraphicBufferAllocator::dumpToSystemLog()
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)
status_t GraphicBufferAllocator::alloc(uint32_t width, uint32_t height,
PixelFormat format, uint32_t usage, buffer_handle_t* handle,
uint32_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;
if (!width || !height)
width = height = 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);
status_t err;
int outStride = 0;
err = mAllocDev->alloc(mAllocDev, static_cast<int>(width),
static_cast<int>(height), format, static_cast<int>(usage), handle,
&outStride);
*stride = static_cast<uint32_t>(outStride);
ALOGW_IF(err, "alloc(%u, %u, %d, %08x, ...) failed %d (%s)",
w, h, format, usage, err, strerror(-err));
width, height, 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;
}
uint32_t bpp = bytesPerPixel(format);
alloc_rec_t rec;
rec.w = w;
rec.h = h;
rec.s = *stride;
rec.width = width;
rec.height = height;
rec.stride = *stride;
rec.format = format;
rec.usage = usage;
rec.size = h * stride[0] * bpp;
rec.size = static_cast<size_t>(height * (*stride) * bpp);
list.add(*handle, rec);
}

View File

@ -20,7 +20,12 @@
#include <stdint.h>
#include <errno.h>
// We would eliminate the non-conforming zero-length array, but we can't since
// this is effectively included from the Linux kernel
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wzero-length-array"
#include <sync/sync.h>
#pragma clang diagnostic pop
#include <utils/Errors.h>
#include <utils/Log.h>
@ -44,7 +49,7 @@ GraphicBufferMapper::GraphicBufferMapper()
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;
mAllocMod = reinterpret_cast<gralloc_module_t const *>(module);
}
}
@ -72,13 +77,13 @@ status_t GraphicBufferMapper::unregisterBuffer(buffer_handle_t handle)
return err;
}
status_t GraphicBufferMapper::lock(buffer_handle_t handle,
int usage, const Rect& bounds, void** vaddr)
status_t GraphicBufferMapper::lock(buffer_handle_t handle,
uint32_t usage, const Rect& bounds, void** vaddr)
{
ATRACE_CALL();
status_t err;
err = mAllocMod->lock(mAllocMod, handle, usage,
err = mAllocMod->lock(mAllocMod, handle, static_cast<int>(usage),
bounds.left, bounds.top, bounds.width(), bounds.height(),
vaddr);
@ -87,12 +92,12 @@ status_t GraphicBufferMapper::lock(buffer_handle_t handle,
}
status_t GraphicBufferMapper::lockYCbCr(buffer_handle_t handle,
int usage, const Rect& bounds, android_ycbcr *ycbcr)
uint32_t usage, const Rect& bounds, android_ycbcr *ycbcr)
{
ATRACE_CALL();
status_t err;
err = mAllocMod->lock_ycbcr(mAllocMod, handle, usage,
err = mAllocMod->lock_ycbcr(mAllocMod, handle, static_cast<int>(usage),
bounds.left, bounds.top, bounds.width(), bounds.height(),
ycbcr);
@ -112,19 +117,19 @@ status_t GraphicBufferMapper::unlock(buffer_handle_t handle)
}
status_t GraphicBufferMapper::lockAsync(buffer_handle_t handle,
int usage, const Rect& bounds, void** vaddr, int fenceFd)
uint32_t usage, const Rect& bounds, void** vaddr, int fenceFd)
{
ATRACE_CALL();
status_t err;
if (mAllocMod->common.module_api_version >= GRALLOC_MODULE_API_VERSION_0_3) {
err = mAllocMod->lockAsync(mAllocMod, handle, usage,
err = mAllocMod->lockAsync(mAllocMod, handle, static_cast<int>(usage),
bounds.left, bounds.top, bounds.width(), bounds.height(),
vaddr, fenceFd);
} else {
sync_wait(fenceFd, -1);
close(fenceFd);
err = mAllocMod->lock(mAllocMod, handle, usage,
err = mAllocMod->lock(mAllocMod, handle, static_cast<int>(usage),
bounds.left, bounds.top, bounds.width(), bounds.height(),
vaddr);
}
@ -134,19 +139,19 @@ status_t GraphicBufferMapper::lockAsync(buffer_handle_t handle,
}
status_t GraphicBufferMapper::lockAsyncYCbCr(buffer_handle_t handle,
int usage, const Rect& bounds, android_ycbcr *ycbcr, int fenceFd)
uint32_t usage, const Rect& bounds, android_ycbcr *ycbcr, int fenceFd)
{
ATRACE_CALL();
status_t err;
if (mAllocMod->common.module_api_version >= GRALLOC_MODULE_API_VERSION_0_3) {
err = mAllocMod->lockAsync_ycbcr(mAllocMod, handle, usage,
bounds.left, bounds.top, bounds.width(), bounds.height(),
ycbcr, fenceFd);
err = mAllocMod->lockAsync_ycbcr(mAllocMod, handle,
static_cast<int>(usage), bounds.left, bounds.top,
bounds.width(), bounds.height(), ycbcr, fenceFd);
} else {
sync_wait(fenceFd, -1);
close(fenceFd);
err = mAllocMod->lock_ycbcr(mAllocMod, handle, usage,
err = mAllocMod->lock_ycbcr(mAllocMod, handle, static_cast<int>(usage),
bounds.left, bounds.top, bounds.width(), bounds.height(),
ycbcr);
}

View File

@ -15,13 +15,12 @@
*/
#include <ui/PixelFormat.h>
#include <hardware/hardware.h>
// ----------------------------------------------------------------------------
namespace android {
// ----------------------------------------------------------------------------
ssize_t bytesPerPixel(PixelFormat format) {
uint32_t bytesPerPixel(PixelFormat format) {
switch (format) {
case PIXEL_FORMAT_RGBA_8888:
case PIXEL_FORMAT_RGBX_8888:
@ -36,10 +35,10 @@ ssize_t bytesPerPixel(PixelFormat format) {
case PIXEL_FORMAT_RGBA_4444:
return 2;
}
return BAD_VALUE;
return 0;
}
ssize_t bitsPerPixel(PixelFormat format) {
uint32_t bitsPerPixel(PixelFormat format) {
switch (format) {
case PIXEL_FORMAT_RGBA_8888:
case PIXEL_FORMAT_RGBX_8888:
@ -52,7 +51,7 @@ ssize_t bitsPerPixel(PixelFormat format) {
case PIXEL_FORMAT_RGBA_4444:
return 16;
}
return BAD_VALUE;
return 0;
}
// ----------------------------------------------------------------------------

View File

@ -102,8 +102,8 @@ static void reverseRectsResolvingJunctions(const Rect* begin, const Rect* end,
current--;
} while (current->top == lastTop && current >= begin);
unsigned int beginLastSpan = -1;
unsigned int endLastSpan = -1;
int beginLastSpan = -1;
int endLastSpan = -1;
int top = -1;
int bottom = -1;
@ -118,7 +118,7 @@ static void reverseRectsResolvingJunctions(const Rect* begin, const Rect* end,
} else {
beginLastSpan = endLastSpan + 1;
}
endLastSpan = dst.size() - 1;
endLastSpan = static_cast<int>(dst.size()) - 1;
top = current->top;
bottom = current->bottom;
@ -126,8 +126,12 @@ static void reverseRectsResolvingJunctions(const Rect* begin, const Rect* end,
int left = current->left;
int right = current->right;
for (unsigned int prevIndex = beginLastSpan; prevIndex <= endLastSpan; prevIndex++) {
const Rect* prev = &dst[prevIndex];
for (int prevIndex = beginLastSpan; prevIndex <= endLastSpan; prevIndex++) {
// prevIndex can't be -1 here because if endLastSpan is set to a
// value greater than -1 (allowing the loop to execute),
// beginLastSpan (and therefore prevIndex) will also be increased
const Rect* prev = &dst[static_cast<size_t>(prevIndex)];
if (spanDirection == direction_RTL) {
// iterating over previous span RTL, quit if it's too far left
if (prev->right <= left) break;
@ -250,10 +254,10 @@ void Region::set(const Rect& r)
mStorage.add(r);
}
void Region::set(uint32_t w, uint32_t h)
void Region::set(int32_t w, int32_t h)
{
mStorage.clear();
mStorage.add(Rect(w,h));
mStorage.add(Rect(w, h));
}
bool Region::isTriviallyEqual(const Region& region) const {
@ -404,7 +408,7 @@ const Region Region::operation(const Region& rhs, int dx, int dy, int op) const
// 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
class Region::rasterizer : public region_operator<Rect>::region_rasterizer
{
Rect bounds;
Vector<Rect>& storage;
@ -413,81 +417,92 @@ class Region::rasterizer : public region_operator<Rect>::region_rasterizer
Vector<Rect> span;
Rect* cur;
public:
rasterizer(Region& reg)
rasterizer(Region& reg)
: bounds(INT_MAX, 0, INT_MIN, 0), storage(reg.mStorage), head(), tail(), cur() {
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;
}
storage.add(bounds);
}
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);
}
virtual ~rasterizer();
virtual void operator()(const Rect& rect);
private:
template<typename T>
template<typename T>
static inline T min(T rhs, T lhs) { return rhs < lhs ? rhs : lhs; }
template<typename T>
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();
}
void flushSpan();
};
Region::rasterizer::~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;
}
storage.add(bounds);
}
void Region::rasterizer::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);
}
void Region::rasterizer::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 silent)
{
bool result = true;
@ -786,10 +801,8 @@ Region::const_iterator Region::end() const {
}
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;
if (count) *count = static_cast<size_t>(end() - begin());
return begin();
}
SharedBuffer const* Region::getSharedBuffer(size_t* count) const {
@ -806,29 +819,22 @@ SharedBuffer const* Region::getSharedBuffer(size_t* count) const {
// ----------------------------------------------------------------------------
void Region::dump(String8& out, const char* what, uint32_t flags) const
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=%" PRIdPTR ")\n",
what, this, tail-head);
out.append(buffer);
out.appendFormat(" Region %s (this=%p, count=%" PRIdPTR ")\n",
what, this, tail - head);
while (head != tail) {
snprintf(buffer, SIZE, " [%3d, %3d, %3d, %3d]\n",
head->left, head->top, head->right, head->bottom);
out.append(buffer);
head++;
out.appendFormat(" [%3d, %3d, %3d, %3d]\n", head->left, head->top,
head->right, head->bottom);
++head;
}
}
void Region::dump(const char* what, uint32_t flags) const
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=%" PRIdPTR ")\n", what, this, tail-head);

View File

@ -18,8 +18,11 @@
namespace android {
#ifdef FRAMEBUFFER_FORCE_FORMAT
// We need the two-level macro to stringify the contents of a macro argument
#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)
#endif
void appendUiConfigString(String8& configStr)
{