libgralloc: use proper types and type casts
- Use proper types for pointers - Resolve compiler errors - handle proper type casts - remove unused variables Change-Id: I628ebe174485d30abadea4ca40b67f9aab1a0652
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2011-2012, The Linux Foundation. All rights reserved.
|
* Copyright (c) 2011-2014, The Linux Foundation. All rights reserved.
|
||||||
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are
|
* modification, are permitted provided that the following conditions are
|
||||||
@@ -428,7 +428,7 @@ size_t getSize(int format, int width, int height, const int alignedw,
|
|||||||
}
|
}
|
||||||
size = alignedw*alignedh +
|
size = alignedw*alignedh +
|
||||||
(ALIGN(alignedw/2, 16) * (alignedh/2))*2;
|
(ALIGN(alignedw/2, 16) * (alignedh/2))*2;
|
||||||
size = ALIGN(size, 4096);
|
size = ALIGN(size, (size_t)4096);
|
||||||
break;
|
break;
|
||||||
case HAL_PIXEL_FORMAT_YCbCr_420_SP:
|
case HAL_PIXEL_FORMAT_YCbCr_420_SP:
|
||||||
case HAL_PIXEL_FORMAT_YCrCb_420_SP:
|
case HAL_PIXEL_FORMAT_YCrCb_420_SP:
|
||||||
@@ -577,7 +577,7 @@ int alloc_buffer(private_handle_t **pHnd, int w, int h, int format, int usage)
|
|||||||
private_handle_t* hnd = new private_handle_t(data.fd, data.size,
|
private_handle_t* hnd = new private_handle_t(data.fd, data.size,
|
||||||
data.allocType, 0, format,
|
data.allocType, 0, format,
|
||||||
alignedw, alignedh);
|
alignedw, alignedh);
|
||||||
hnd->base = (int) data.base;
|
hnd->base = (uintptr_t) data.base;
|
||||||
hnd->offset = data.offset;
|
hnd->offset = data.offset;
|
||||||
hnd->gpuaddr = 0;
|
hnd->gpuaddr = 0;
|
||||||
*pHnd = hnd;
|
*pHnd = hnd;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2008 The Android Open Source Project
|
* Copyright (C) 2008 The Android Open Source Project
|
||||||
* Copyright (c) 2012, The Linux Foundation. All rights reserved.
|
* Copyright (c) 2012-2014, The Linux Foundation. All rights reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -41,7 +41,7 @@ struct private_module_t {
|
|||||||
uint32_t fbFormat;
|
uint32_t fbFormat;
|
||||||
uint32_t flags;
|
uint32_t flags;
|
||||||
uint32_t numBuffers;
|
uint32_t numBuffers;
|
||||||
uint32_t bufferMask;
|
size_t bufferMask;
|
||||||
pthread_mutex_t lock;
|
pthread_mutex_t lock;
|
||||||
private_handle_t *currentBuffer;
|
private_handle_t *currentBuffer;
|
||||||
struct fb_var_screeninfo info;
|
struct fb_var_screeninfo info;
|
||||||
@@ -51,7 +51,6 @@ struct private_module_t {
|
|||||||
float ydpi;
|
float ydpi;
|
||||||
float fps;
|
float fps;
|
||||||
uint32_t swapInterval;
|
uint32_t swapInterval;
|
||||||
uint32_t currentOffset;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2008 The Android Open Source Project
|
* Copyright (C) 2008 The Android Open Source Project
|
||||||
* Copyright (c) 2010-2012 The Linux Foundation. All rights reserved.
|
* Copyright (c) 2010-2014 The Linux Foundation. All rights reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -72,7 +72,6 @@ static int fb_setSwapInterval(struct framebuffer_device_t* dev,
|
|||||||
if (property_interval >= 0)
|
if (property_interval >= 0)
|
||||||
interval = property_interval;
|
interval = property_interval;
|
||||||
|
|
||||||
fb_context_t* ctx = (fb_context_t*)dev;
|
|
||||||
private_module_t* m = reinterpret_cast<private_module_t*>(
|
private_module_t* m = reinterpret_cast<private_module_t*>(
|
||||||
dev->common.module);
|
dev->common.module);
|
||||||
if (interval < dev->minSwapInterval || interval > dev->maxSwapInterval)
|
if (interval < dev->minSwapInterval || interval > dev->maxSwapInterval)
|
||||||
@@ -90,7 +89,7 @@ static int fb_post(struct framebuffer_device_t* dev, buffer_handle_t buffer)
|
|||||||
(const_cast<native_handle_t*>(buffer));
|
(const_cast<native_handle_t*>(buffer));
|
||||||
const size_t offset = hnd->base - m->framebuffer->base;
|
const size_t offset = hnd->base - m->framebuffer->base;
|
||||||
m->info.activate = FB_ACTIVATE_VBL;
|
m->info.activate = FB_ACTIVATE_VBL;
|
||||||
m->info.yoffset = offset / m->finfo.line_length;
|
m->info.yoffset = (int)(offset / m->finfo.line_length);
|
||||||
if (ioctl(m->framebuffer->fd, FBIOPUT_VSCREENINFO, &m->info) == -1) {
|
if (ioctl(m->framebuffer->fd, FBIOPUT_VSCREENINFO, &m->info) == -1) {
|
||||||
ALOGE("%s: FBIOPUT_VSCREENINFO for primary failed, str: %s",
|
ALOGE("%s: FBIOPUT_VSCREENINFO for primary failed, str: %s",
|
||||||
__FUNCTION__, strerror(errno));
|
__FUNCTION__, strerror(errno));
|
||||||
@@ -102,6 +101,9 @@ static int fb_post(struct framebuffer_device_t* dev, buffer_handle_t buffer)
|
|||||||
static int fb_compositionComplete(struct framebuffer_device_t* dev)
|
static int fb_compositionComplete(struct framebuffer_device_t* dev)
|
||||||
{
|
{
|
||||||
// TODO: Properly implement composition complete callback
|
// TODO: Properly implement composition complete callback
|
||||||
|
if(!dev) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
glFinish();
|
glFinish();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -202,7 +204,7 @@ int mapFrameBufferLocked(struct private_module_t* module)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//adreno needs 4k aligned offsets. Max hole size is 4096-1
|
//adreno needs 4k aligned offsets. Max hole size is 4096-1
|
||||||
int size = roundUpToPageSize(info.yres * info.xres *
|
size_t size = roundUpToPageSize(info.yres * info.xres *
|
||||||
(info.bits_per_pixel/8));
|
(info.bits_per_pixel/8));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -224,13 +226,13 @@ int mapFrameBufferLocked(struct private_module_t* module)
|
|||||||
|
|
||||||
//consider the included hole by 4k alignment
|
//consider the included hole by 4k alignment
|
||||||
uint32_t line_length = (info.xres * info.bits_per_pixel / 8);
|
uint32_t line_length = (info.xres * info.bits_per_pixel / 8);
|
||||||
info.yres_virtual = (size * numberOfBuffers) / line_length;
|
info.yres_virtual = (uint32_t) ((size * numberOfBuffers) / line_length);
|
||||||
|
|
||||||
uint32_t flags = PAGE_FLIP;
|
uint32_t flags = PAGE_FLIP;
|
||||||
|
|
||||||
if (info.yres_virtual < ((size * 2) / line_length) ) {
|
if (info.yres_virtual < ((size * 2) / line_length) ) {
|
||||||
// we need at least 2 for page-flipping
|
// we need at least 2 for page-flipping
|
||||||
info.yres_virtual = size / line_length;
|
info.yres_virtual = (int)(size / line_length);
|
||||||
flags &= ~PAGE_FLIP;
|
flags &= ~PAGE_FLIP;
|
||||||
ALOGW("page flipping not supported (yres_virtual=%d, requested=%d)",
|
ALOGW("page flipping not supported (yres_virtual=%d, requested=%d)",
|
||||||
info.yres_virtual, info.yres*2);
|
info.yres_virtual, info.yres*2);
|
||||||
@@ -244,12 +246,13 @@ int mapFrameBufferLocked(struct private_module_t* module)
|
|||||||
if (int(info.width) <= 0 || int(info.height) <= 0) {
|
if (int(info.width) <= 0 || int(info.height) <= 0) {
|
||||||
// the driver doesn't return that information
|
// the driver doesn't return that information
|
||||||
// default to 160 dpi
|
// default to 160 dpi
|
||||||
info.width = ((info.xres * 25.4f)/160.0f + 0.5f);
|
info.width = (uint32_t)(((float)(info.xres) * 25.4f)/160.0f + 0.5f);
|
||||||
info.height = ((info.yres * 25.4f)/160.0f + 0.5f);
|
info.height = (uint32_t)(((float)(info.yres) * 25.4f)/160.0f + 0.5f);
|
||||||
}
|
}
|
||||||
|
|
||||||
float xdpi = (info.xres * 25.4f) / info.width;
|
float xdpi = ((float)(info.xres) * 25.4f) / (float)info.width;
|
||||||
float ydpi = (info.yres * 25.4f) / info.height;
|
float ydpi = ((float)(info.yres) * 25.4f) / (float)info.height;
|
||||||
|
|
||||||
#ifdef MSMFB_METADATA_GET
|
#ifdef MSMFB_METADATA_GET
|
||||||
struct msmfb_metadata metadata;
|
struct msmfb_metadata metadata;
|
||||||
memset(&metadata, 0 , sizeof(metadata));
|
memset(&metadata, 0 , sizeof(metadata));
|
||||||
@@ -259,7 +262,7 @@ int mapFrameBufferLocked(struct private_module_t* module)
|
|||||||
close(fd);
|
close(fd);
|
||||||
return -errno;
|
return -errno;
|
||||||
}
|
}
|
||||||
float fps = metadata.data.panel_frame_rate;
|
float fps = (float)metadata.data.panel_frame_rate;
|
||||||
#else
|
#else
|
||||||
//XXX: Remove reserved field usage on all baselines
|
//XXX: Remove reserved field usage on all baselines
|
||||||
//The reserved[3] field is used to store FPS by the driver.
|
//The reserved[3] field is used to store FPS by the driver.
|
||||||
@@ -320,7 +323,6 @@ int mapFrameBufferLocked(struct private_module_t* module)
|
|||||||
* map the framebuffer
|
* map the framebuffer
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int err;
|
|
||||||
module->numBuffers = info.yres_virtual / info.yres;
|
module->numBuffers = info.yres_virtual / info.yres;
|
||||||
module->bufferMask = 0;
|
module->bufferMask = 0;
|
||||||
//adreno needs page aligned offsets. Align the fbsize to pagesize.
|
//adreno needs page aligned offsets. Align the fbsize to pagesize.
|
||||||
@@ -336,9 +338,8 @@ int mapFrameBufferLocked(struct private_module_t* module)
|
|||||||
close(fd);
|
close(fd);
|
||||||
return -errno;
|
return -errno;
|
||||||
}
|
}
|
||||||
module->framebuffer->base = intptr_t(vaddr);
|
module->framebuffer->base = uintptr_t(vaddr);
|
||||||
memset(vaddr, 0, fbSize);
|
memset(vaddr, 0, fbSize);
|
||||||
module->currentOffset = 0;
|
|
||||||
//Enable vsync
|
//Enable vsync
|
||||||
int enable = 1;
|
int enable = 1;
|
||||||
ioctl(module->framebuffer->fd, MSMFB_OVERLAY_VSYNC_CTRL,
|
ioctl(module->framebuffer->fd, MSMFB_OVERLAY_VSYNC_CTRL,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2010 The Android Open Source Project
|
* Copyright (C) 2010 The Android Open Source Project
|
||||||
* Copyright (c) 2011-2013 The Linux Foundation. All rights reserved.
|
* Copyright (c) 2011-2014 The Linux Foundation. All rights reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -70,13 +70,13 @@ int gpu_context_t::gralloc_alloc_buffer(size_t size, int usage,
|
|||||||
/* force 1MB alignment selectively for secure buffers, MDP5 onwards */
|
/* force 1MB alignment selectively for secure buffers, MDP5 onwards */
|
||||||
#ifdef MDSS_TARGET
|
#ifdef MDSS_TARGET
|
||||||
if (usage & GRALLOC_USAGE_PROTECTED) {
|
if (usage & GRALLOC_USAGE_PROTECTED) {
|
||||||
data.align = ALIGN(data.align, SZ_1M);
|
data.align = ALIGN((int) data.align, SZ_1M);
|
||||||
size = ALIGN(size, data.align);
|
size = ALIGN(size, data.align);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
data.size = size;
|
data.size = size;
|
||||||
data.pHandle = (unsigned int) pHandle;
|
data.pHandle = (uintptr_t) pHandle;
|
||||||
err = mAllocCtrl->allocate(data, usage);
|
err = mAllocCtrl->allocate(data, usage);
|
||||||
|
|
||||||
if (!err) {
|
if (!err) {
|
||||||
@@ -148,13 +148,13 @@ int gpu_context_t::gralloc_alloc_buffer(size_t size, int usage,
|
|||||||
}
|
}
|
||||||
|
|
||||||
flags |= data.allocType;
|
flags |= data.allocType;
|
||||||
int eBaseAddr = int(eData.base) + eData.offset;
|
uintptr_t eBaseAddr = (uintptr_t)(eData.base) + eData.offset;
|
||||||
private_handle_t *hnd = new private_handle_t(data.fd, size, flags,
|
private_handle_t *hnd = new private_handle_t(data.fd, size, flags,
|
||||||
bufferType, format, width, height, eData.fd, eData.offset,
|
bufferType, format, width, height, eData.fd, eData.offset,
|
||||||
eBaseAddr);
|
eBaseAddr);
|
||||||
|
|
||||||
hnd->offset = data.offset;
|
hnd->offset = data.offset;
|
||||||
hnd->base = int(data.base) + data.offset;
|
hnd->base = (uintptr_t)(data.base) + data.offset;
|
||||||
hnd->gpuaddr = 0;
|
hnd->gpuaddr = 0;
|
||||||
|
|
||||||
*pHandle = hnd;
|
*pHandle = hnd;
|
||||||
@@ -182,7 +182,7 @@ void gpu_context_t::getGrallocInformationFromFormat(int inputFormat,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int gpu_context_t::gralloc_alloc_framebuffer_locked(size_t size, int usage,
|
int gpu_context_t::gralloc_alloc_framebuffer_locked(int usage,
|
||||||
buffer_handle_t* pHandle)
|
buffer_handle_t* pHandle)
|
||||||
{
|
{
|
||||||
private_module_t* m = reinterpret_cast<private_module_t*>(common.module);
|
private_module_t* m = reinterpret_cast<private_module_t*>(common.module);
|
||||||
@@ -197,7 +197,7 @@ int gpu_context_t::gralloc_alloc_framebuffer_locked(size_t size, int usage,
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint32_t bufferMask = m->bufferMask;
|
const size_t bufferMask = m->bufferMask;
|
||||||
const uint32_t numBuffers = m->numBuffers;
|
const uint32_t numBuffers = m->numBuffers;
|
||||||
size_t bufferSize = m->finfo.line_length * m->info.yres;
|
size_t bufferSize = m->finfo.line_length * m->info.yres;
|
||||||
|
|
||||||
@@ -219,7 +219,7 @@ int gpu_context_t::gralloc_alloc_framebuffer_locked(size_t size, int usage,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create a "fake" handle for it
|
// create a "fake" handle for it
|
||||||
intptr_t vaddr = intptr_t(m->framebuffer->base);
|
uintptr_t vaddr = uintptr_t(m->framebuffer->base);
|
||||||
private_handle_t* hnd = new private_handle_t(
|
private_handle_t* hnd = new private_handle_t(
|
||||||
dup(m->framebuffer->fd), bufferSize,
|
dup(m->framebuffer->fd), bufferSize,
|
||||||
private_handle_t::PRIV_FLAGS_USES_PMEM |
|
private_handle_t::PRIV_FLAGS_USES_PMEM |
|
||||||
@@ -236,18 +236,18 @@ int gpu_context_t::gralloc_alloc_framebuffer_locked(size_t size, int usage,
|
|||||||
vaddr += bufferSize;
|
vaddr += bufferSize;
|
||||||
}
|
}
|
||||||
hnd->base = vaddr;
|
hnd->base = vaddr;
|
||||||
hnd->offset = vaddr - intptr_t(m->framebuffer->base);
|
hnd->offset = vaddr - uintptr_t(m->framebuffer->base);
|
||||||
*pHandle = hnd;
|
*pHandle = hnd;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int gpu_context_t::gralloc_alloc_framebuffer(size_t size, int usage,
|
int gpu_context_t::gralloc_alloc_framebuffer(int usage,
|
||||||
buffer_handle_t* pHandle)
|
buffer_handle_t* pHandle)
|
||||||
{
|
{
|
||||||
private_module_t* m = reinterpret_cast<private_module_t*>(common.module);
|
private_module_t* m = reinterpret_cast<private_module_t*>(common.module);
|
||||||
pthread_mutex_lock(&m->lock);
|
pthread_mutex_lock(&m->lock);
|
||||||
int err = gralloc_alloc_framebuffer_locked(size, usage, pHandle);
|
int err = gralloc_alloc_framebuffer_locked(usage, pHandle);
|
||||||
pthread_mutex_unlock(&m->lock);
|
pthread_mutex_unlock(&m->lock);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@@ -299,7 +299,7 @@ int gpu_context_t::alloc_impl(int w, int h, int format, int usage,
|
|||||||
|
|
||||||
int err = 0;
|
int err = 0;
|
||||||
if(useFbMem) {
|
if(useFbMem) {
|
||||||
err = gralloc_alloc_framebuffer(size, usage, pHandle);
|
err = gralloc_alloc_framebuffer(usage, pHandle);
|
||||||
} else {
|
} else {
|
||||||
err = gralloc_alloc_buffer(size, usage, pHandle, bufferType,
|
err = gralloc_alloc_buffer(size, usage, pHandle, bufferType,
|
||||||
grallocFormat, alignedw, alignedh);
|
grallocFormat, alignedw, alignedh);
|
||||||
@@ -317,8 +317,8 @@ int gpu_context_t::free_impl(private_handle_t const* hnd) {
|
|||||||
private_module_t* m = reinterpret_cast<private_module_t*>(common.module);
|
private_module_t* m = reinterpret_cast<private_module_t*>(common.module);
|
||||||
if (hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER) {
|
if (hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER) {
|
||||||
const size_t bufferSize = m->finfo.line_length * m->info.yres;
|
const size_t bufferSize = m->finfo.line_length * m->info.yres;
|
||||||
int index = (hnd->base - m->framebuffer->base) / bufferSize;
|
size_t index = (hnd->base - m->framebuffer->base) / bufferSize;
|
||||||
m->bufferMask &= ~(1<<index);
|
m->bufferMask &= ~(1LU<<index);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
terminateBuffer(&m->base, const_cast<private_handle_t*>(hnd));
|
terminateBuffer(&m->base, const_cast<private_handle_t*>(hnd));
|
||||||
@@ -328,9 +328,9 @@ int gpu_context_t::free_impl(private_handle_t const* hnd) {
|
|||||||
if(err)
|
if(err)
|
||||||
return err;
|
return err;
|
||||||
// free the metadata space
|
// free the metadata space
|
||||||
unsigned long size = ROUND_UP_PAGESIZE(sizeof(MetaData_t));
|
size_t size = ROUND_UP_PAGESIZE(sizeof(MetaData_t));
|
||||||
err = memalloc->free_buffer((void*)hnd->base_metadata,
|
err = memalloc->free_buffer((void*)hnd->base_metadata,
|
||||||
(size_t) size, hnd->offset_metadata,
|
size, hnd->offset_metadata,
|
||||||
hnd->fd_metadata);
|
hnd->fd_metadata);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2008 The Android Open Source Project
|
* Copyright (C) 2008 The Android Open Source Project
|
||||||
* Copyright (c) 2011-2012, The Linux Foundation. All rights reserved.
|
* Copyright (c) 2011-2014, The Linux Foundation. All rights reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -51,10 +51,10 @@ class gpu_context_t : public alloc_device_t {
|
|||||||
int format, int usage,
|
int format, int usage,
|
||||||
buffer_handle_t* pHandle,
|
buffer_handle_t* pHandle,
|
||||||
int* pStride);
|
int* pStride);
|
||||||
int gralloc_alloc_framebuffer_locked(size_t size, int usage,
|
int gralloc_alloc_framebuffer_locked(int usage,
|
||||||
buffer_handle_t* pHandle);
|
buffer_handle_t* pHandle);
|
||||||
|
|
||||||
int gralloc_alloc_framebuffer(size_t size, int usage,
|
int gralloc_alloc_framebuffer(int usage,
|
||||||
buffer_handle_t* pHandle);
|
buffer_handle_t* pHandle);
|
||||||
|
|
||||||
static int gralloc_free(alloc_device_t* dev, buffer_handle_t handle);
|
static int gralloc_free(alloc_device_t* dev, buffer_handle_t handle);
|
||||||
|
|||||||
@@ -42,7 +42,8 @@ inline size_t roundUpToPageSize(size_t x) {
|
|||||||
return (x + (PAGE_SIZE-1)) & ~(PAGE_SIZE-1);
|
return (x + (PAGE_SIZE-1)) & ~(PAGE_SIZE-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline size_t ALIGN(size_t x, size_t align) {
|
template <class Type>
|
||||||
|
inline Type ALIGN(Type x, Type align) {
|
||||||
return (x + align-1) & ~(align-1);
|
return (x + align-1) & ~(align-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -209,33 +209,35 @@ struct private_handle_t : public native_handle {
|
|||||||
// ints
|
// ints
|
||||||
int magic;
|
int magic;
|
||||||
int flags;
|
int flags;
|
||||||
int size;
|
size_t size;
|
||||||
int offset;
|
size_t offset;
|
||||||
int bufferType;
|
int bufferType;
|
||||||
int base;
|
uintptr_t base;
|
||||||
int offset_metadata;
|
size_t offset_metadata;
|
||||||
// The gpu address mapped into the mmu.
|
// The gpu address mapped into the mmu.
|
||||||
int gpuaddr;
|
uintptr_t gpuaddr;
|
||||||
int format;
|
int format;
|
||||||
int width;
|
int width;
|
||||||
int height;
|
int height;
|
||||||
int base_metadata;
|
uintptr_t base_metadata;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
static const int sNumInts = 12;
|
//TODO64: Revisit this on 64-bit
|
||||||
|
static const int sNumInts = (6 + (3 * (sizeof(size_t)/sizeof(int))) +
|
||||||
|
(3 * (sizeof(uintptr_t)/sizeof(int))));
|
||||||
static const int sNumFds = 2;
|
static const int sNumFds = 2;
|
||||||
static const int sMagic = 'gmsm';
|
static const int sMagic = 'gmsm';
|
||||||
|
|
||||||
private_handle_t(int fd, int size, int flags, int bufferType,
|
private_handle_t(int fd, size_t size, int flags, int bufferType,
|
||||||
int format, int width, int height, int eFd = -1,
|
int format, int width, int height, int eFd = -1,
|
||||||
int eOffset = 0, int eBase = 0) :
|
size_t eOffset = 0, uintptr_t eBase = 0) :
|
||||||
fd(fd), fd_metadata(eFd), magic(sMagic),
|
fd(fd), fd_metadata(eFd), magic(sMagic),
|
||||||
flags(flags), size(size), offset(0), bufferType(bufferType),
|
flags(flags), size(size), offset(0), bufferType(bufferType),
|
||||||
base(0), offset_metadata(eOffset), gpuaddr(0),
|
base(0), offset_metadata(eOffset), gpuaddr(0),
|
||||||
format(format), width(width), height(height),
|
format(format), width(width), height(height),
|
||||||
base_metadata(eBase)
|
base_metadata(eBase)
|
||||||
{
|
{
|
||||||
version = sizeof(native_handle);
|
version = (int) sizeof(native_handle);
|
||||||
numInts = sNumInts;
|
numInts = sNumInts;
|
||||||
numFds = sNumFds;
|
numFds = sNumFds;
|
||||||
}
|
}
|
||||||
@@ -254,7 +256,8 @@ struct private_handle_t : public native_handle {
|
|||||||
hnd->magic != sMagic)
|
hnd->magic != sMagic)
|
||||||
{
|
{
|
||||||
ALOGD("Invalid gralloc handle (at %p): "
|
ALOGD("Invalid gralloc handle (at %p): "
|
||||||
"ver(%d/%d) ints(%d/%d) fds(%d/%d) magic(%c%c%c%c/%c%c%c%c)",
|
"ver(%d/%zu) ints(%d/%d) fds(%d/%d)"
|
||||||
|
"magic(%c%c%c%c/%c%c%c%c)",
|
||||||
h,
|
h,
|
||||||
h ? h->version : -1, sizeof(native_handle),
|
h ? h->version : -1, sizeof(native_handle),
|
||||||
h ? h->numInts : -1, sNumInts,
|
h ? h->numInts : -1, sNumInts,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2011-2012, The Linux Foundation. All rights reserved.
|
* Copyright (c) 2011-2014, The Linux Foundation. All rights reserved.
|
||||||
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are
|
* modification, are permitted provided that the following conditions are
|
||||||
@@ -114,16 +114,16 @@ int IonAlloc::alloc_buffer(alloc_data& data)
|
|||||||
data.base = base;
|
data.base = base;
|
||||||
data.fd = fd_data.fd;
|
data.fd = fd_data.fd;
|
||||||
ioctl(mIonFd, ION_IOC_FREE, &handle_data);
|
ioctl(mIonFd, ION_IOC_FREE, &handle_data);
|
||||||
ALOGD_IF(DEBUG, "ion: Allocated buffer base:%p size:%d fd:%d",
|
ALOGD_IF(DEBUG, "ion: Allocated buffer base:%p size:%zu fd:%d",
|
||||||
data.base, ionAllocData.len, data.fd);
|
data.base, ionAllocData.len, data.fd);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int IonAlloc::free_buffer(void* base, size_t size, int offset, int fd)
|
int IonAlloc::free_buffer(void* base, size_t size, size_t offset, int fd)
|
||||||
{
|
{
|
||||||
Locker::Autolock _l(mLock);
|
Locker::Autolock _l(mLock);
|
||||||
ALOGD_IF(DEBUG, "ion: Freeing buffer base:%p size:%d fd:%d",
|
ALOGD_IF(DEBUG, "ion: Freeing buffer base:%p size:%zu fd:%d",
|
||||||
base, size, fd);
|
base, size, fd);
|
||||||
int err = 0;
|
int err = 0;
|
||||||
err = open_device();
|
err = open_device();
|
||||||
@@ -136,7 +136,7 @@ int IonAlloc::free_buffer(void* base, size_t size, int offset, int fd)
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
int IonAlloc::map_buffer(void **pBase, size_t size, int offset, int fd)
|
int IonAlloc::map_buffer(void **pBase, size_t size, size_t offset, int fd)
|
||||||
{
|
{
|
||||||
int err = 0;
|
int err = 0;
|
||||||
void *base = 0;
|
void *base = 0;
|
||||||
@@ -154,15 +154,15 @@ int IonAlloc::map_buffer(void **pBase, size_t size, int offset, int fd)
|
|||||||
ALOGE("ion: Failed to map memory in the client: %s",
|
ALOGE("ion: Failed to map memory in the client: %s",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
} else {
|
} else {
|
||||||
ALOGD_IF(DEBUG, "ion: Mapped buffer base:%p size:%d offset:%d fd:%d",
|
ALOGD_IF(DEBUG, "ion: Mapped buffer base:%p size:%zu offset:%d fd:%d",
|
||||||
base, size, offset, fd);
|
base, size, offset, fd);
|
||||||
}
|
}
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
int IonAlloc::unmap_buffer(void *base, size_t size, int offset)
|
int IonAlloc::unmap_buffer(void *base, size_t size, size_t /*offset*/)
|
||||||
{
|
{
|
||||||
ALOGD_IF(DEBUG, "ion: Unmapping buffer base:%p size:%d", base, size);
|
ALOGD_IF(DEBUG, "ion: Unmapping buffer base:%p size:%zu", base, size);
|
||||||
int err = 0;
|
int err = 0;
|
||||||
if(munmap(base, size)) {
|
if(munmap(base, size)) {
|
||||||
err = -errno;
|
err = -errno;
|
||||||
@@ -172,12 +172,11 @@ int IonAlloc::unmap_buffer(void *base, size_t size, int offset)
|
|||||||
return err;
|
return err;
|
||||||
|
|
||||||
}
|
}
|
||||||
int IonAlloc::clean_buffer(void *base, size_t size, int offset, int fd, int op)
|
int IonAlloc::clean_buffer(void *base, size_t size, size_t offset, int fd, int op)
|
||||||
{
|
{
|
||||||
struct ion_flush_data flush_data;
|
struct ion_flush_data flush_data;
|
||||||
struct ion_fd_data fd_data;
|
struct ion_fd_data fd_data;
|
||||||
struct ion_handle_data handle_data;
|
struct ion_handle_data handle_data;
|
||||||
ion_user_handle_t handle;
|
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
err = open_device();
|
err = open_device();
|
||||||
@@ -195,8 +194,9 @@ int IonAlloc::clean_buffer(void *base, size_t size, int offset, int fd, int op)
|
|||||||
handle_data.handle = fd_data.handle;
|
handle_data.handle = fd_data.handle;
|
||||||
flush_data.handle = fd_data.handle;
|
flush_data.handle = fd_data.handle;
|
||||||
flush_data.vaddr = base;
|
flush_data.vaddr = base;
|
||||||
flush_data.offset = offset;
|
// offset and length are uint32_t
|
||||||
flush_data.length = size;
|
flush_data.offset = (uint32_t) offset;
|
||||||
|
flush_data.length = (uint32_t) size;
|
||||||
|
|
||||||
struct ion_custom_data d;
|
struct ion_custom_data d;
|
||||||
switch(op) {
|
switch(op) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2011-2012, The Linux Foundation. All rights reserved.
|
* Copyright (c) 2011-2014, The Linux Foundation. All rights reserved.
|
||||||
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are
|
* modification, are permitted provided that the following conditions are
|
||||||
@@ -42,16 +42,16 @@ class IonAlloc : public IMemAlloc {
|
|||||||
virtual int alloc_buffer(alloc_data& data);
|
virtual int alloc_buffer(alloc_data& data);
|
||||||
|
|
||||||
virtual int free_buffer(void *base, size_t size,
|
virtual int free_buffer(void *base, size_t size,
|
||||||
int offset, int fd);
|
size_t offset, int fd);
|
||||||
|
|
||||||
virtual int map_buffer(void **pBase, size_t size,
|
virtual int map_buffer(void **pBase, size_t size,
|
||||||
int offset, int fd);
|
size_t offset, int fd);
|
||||||
|
|
||||||
virtual int unmap_buffer(void *base, size_t size,
|
virtual int unmap_buffer(void *base, size_t size,
|
||||||
int offset);
|
size_t offset);
|
||||||
|
|
||||||
virtual int clean_buffer(void*base, size_t size,
|
virtual int clean_buffer(void*base, size_t size,
|
||||||
int offset, int fd, int op);
|
size_t offset, int fd, int op);
|
||||||
|
|
||||||
IonAlloc() { mIonFd = FD_INIT; }
|
IonAlloc() { mIonFd = FD_INIT; }
|
||||||
|
|
||||||
|
|||||||
@@ -59,6 +59,9 @@ static int gralloc_map(gralloc_module_t const* module,
|
|||||||
buffer_handle_t handle,
|
buffer_handle_t handle,
|
||||||
void** vaddr)
|
void** vaddr)
|
||||||
{
|
{
|
||||||
|
if(!module)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
private_handle_t* hnd = (private_handle_t*)handle;
|
private_handle_t* hnd = (private_handle_t*)handle;
|
||||||
void *mappedAddress;
|
void *mappedAddress;
|
||||||
if (!(hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER) &&
|
if (!(hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER) &&
|
||||||
@@ -96,6 +99,9 @@ static int gralloc_map(gralloc_module_t const* module,
|
|||||||
static int gralloc_unmap(gralloc_module_t const* module,
|
static int gralloc_unmap(gralloc_module_t const* module,
|
||||||
buffer_handle_t handle)
|
buffer_handle_t handle)
|
||||||
{
|
{
|
||||||
|
if(!module)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
private_handle_t* hnd = (private_handle_t*)handle;
|
private_handle_t* hnd = (private_handle_t*)handle;
|
||||||
if (!(hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER)) {
|
if (!(hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER)) {
|
||||||
int err = -EINVAL;
|
int err = -EINVAL;
|
||||||
@@ -131,7 +137,7 @@ static pthread_mutex_t sMapLock = PTHREAD_MUTEX_INITIALIZER;
|
|||||||
int gralloc_register_buffer(gralloc_module_t const* module,
|
int gralloc_register_buffer(gralloc_module_t const* module,
|
||||||
buffer_handle_t handle)
|
buffer_handle_t handle)
|
||||||
{
|
{
|
||||||
if (private_handle_t::validate(handle) < 0)
|
if (!module || private_handle_t::validate(handle) < 0)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
// In this implementation, we don't need to do anything here
|
// In this implementation, we don't need to do anything here
|
||||||
@@ -159,7 +165,7 @@ int gralloc_register_buffer(gralloc_module_t const* module,
|
|||||||
int gralloc_unregister_buffer(gralloc_module_t const* module,
|
int gralloc_unregister_buffer(gralloc_module_t const* module,
|
||||||
buffer_handle_t handle)
|
buffer_handle_t handle)
|
||||||
{
|
{
|
||||||
if (private_handle_t::validate(handle) < 0)
|
if (!module || private_handle_t::validate(handle) < 0)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -181,6 +187,9 @@ int gralloc_unregister_buffer(gralloc_module_t const* module,
|
|||||||
int terminateBuffer(gralloc_module_t const* module,
|
int terminateBuffer(gralloc_module_t const* module,
|
||||||
private_handle_t* hnd)
|
private_handle_t* hnd)
|
||||||
{
|
{
|
||||||
|
if(!module)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the buffer has been mapped during a lock operation, it's time
|
* If the buffer has been mapped during a lock operation, it's time
|
||||||
* to un-map it. It's an error to be here with a locked buffer.
|
* to un-map it. It's an error to be here with a locked buffer.
|
||||||
@@ -205,10 +214,10 @@ int terminateBuffer(gralloc_module_t const* module,
|
|||||||
|
|
||||||
int gralloc_lock(gralloc_module_t const* module,
|
int gralloc_lock(gralloc_module_t const* module,
|
||||||
buffer_handle_t handle, int usage,
|
buffer_handle_t handle, int usage,
|
||||||
int l, int t, int w, int h,
|
int /*l*/, int /*t*/, int /*w*/, int /*h*/,
|
||||||
void** vaddr)
|
void** vaddr)
|
||||||
{
|
{
|
||||||
if (private_handle_t::validate(handle) < 0)
|
if (!module || private_handle_t::validate(handle) < 0)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
int err = 0;
|
int err = 0;
|
||||||
@@ -243,8 +252,9 @@ int gralloc_lock(gralloc_module_t const* module,
|
|||||||
int gralloc_unlock(gralloc_module_t const* module,
|
int gralloc_unlock(gralloc_module_t const* module,
|
||||||
buffer_handle_t handle)
|
buffer_handle_t handle)
|
||||||
{
|
{
|
||||||
if (private_handle_t::validate(handle) < 0)
|
if (!module || private_handle_t::validate(handle) < 0)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
int err = 0;
|
int err = 0;
|
||||||
private_handle_t* hnd = (private_handle_t*)handle;
|
private_handle_t* hnd = (private_handle_t*)handle;
|
||||||
|
|
||||||
@@ -276,6 +286,9 @@ int gralloc_perform(struct gralloc_module_t const* module,
|
|||||||
{
|
{
|
||||||
int res = -EINVAL;
|
int res = -EINVAL;
|
||||||
va_list args;
|
va_list args;
|
||||||
|
if(!module)
|
||||||
|
return res;
|
||||||
|
|
||||||
va_start(args, operation);
|
va_start(args, operation);
|
||||||
switch (operation) {
|
switch (operation) {
|
||||||
case GRALLOC_MODULE_PERFORM_CREATE_HANDLE_FROM_BUFFER:
|
case GRALLOC_MODULE_PERFORM_CREATE_HANDLE_FROM_BUFFER:
|
||||||
@@ -289,7 +302,6 @@ int gralloc_perform(struct gralloc_module_t const* module,
|
|||||||
int format = va_arg(args, int);
|
int format = va_arg(args, int);
|
||||||
|
|
||||||
native_handle_t** handle = va_arg(args, native_handle_t**);
|
native_handle_t** handle = va_arg(args, native_handle_t**);
|
||||||
int memoryFlags = va_arg(args, int);
|
|
||||||
private_handle_t* hnd = (private_handle_t*)native_handle_create(
|
private_handle_t* hnd = (private_handle_t*)native_handle_create(
|
||||||
private_handle_t::sNumFds, private_handle_t::sNumInts);
|
private_handle_t::sNumFds, private_handle_t::sNumInts);
|
||||||
hnd->magic = private_handle_t::sMagic;
|
hnd->magic = private_handle_t::sMagic;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2011-2012, The Linux Foundation. All rights reserved.
|
* Copyright (c) 2011-2014, The Linux Foundation. All rights reserved.
|
||||||
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are
|
* modification, are permitted provided that the following conditions are
|
||||||
@@ -43,10 +43,10 @@ enum {
|
|||||||
struct alloc_data {
|
struct alloc_data {
|
||||||
void *base;
|
void *base;
|
||||||
int fd;
|
int fd;
|
||||||
int offset;
|
size_t offset;
|
||||||
size_t size;
|
size_t size;
|
||||||
size_t align;
|
size_t align;
|
||||||
unsigned int pHandle;
|
uintptr_t pHandle;
|
||||||
bool uncached;
|
bool uncached;
|
||||||
unsigned int flags;
|
unsigned int flags;
|
||||||
int allocType;
|
int allocType;
|
||||||
@@ -62,19 +62,19 @@ class IMemAlloc {
|
|||||||
|
|
||||||
// Free buffer
|
// Free buffer
|
||||||
virtual int free_buffer(void *base, size_t size,
|
virtual int free_buffer(void *base, size_t size,
|
||||||
int offset, int fd) = 0;
|
size_t offset, int fd) = 0;
|
||||||
|
|
||||||
// Map buffer
|
// Map buffer
|
||||||
virtual int map_buffer(void **pBase, size_t size,
|
virtual int map_buffer(void **pBase, size_t size,
|
||||||
int offset, int fd) = 0;
|
size_t offset, int fd) = 0;
|
||||||
|
|
||||||
// Unmap buffer
|
// Unmap buffer
|
||||||
virtual int unmap_buffer(void *base, size_t size,
|
virtual int unmap_buffer(void *base, size_t size,
|
||||||
int offset) = 0;
|
size_t offset) = 0;
|
||||||
|
|
||||||
// Clean and invalidate
|
// Clean and invalidate
|
||||||
virtual int clean_buffer(void *base, size_t size,
|
virtual int clean_buffer(void *base, size_t size,
|
||||||
int offset, int fd, int op) = 0;
|
size_t offset, int fd, int op) = 0;
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
virtual ~IMemAlloc() {};
|
virtual ~IMemAlloc() {};
|
||||||
|
|||||||
Reference in New Issue
Block a user