libgralloc-qsd8k: support for specifying buffer size during allocation

Add support in the gralloc to specify the desired buffer size during
buffer allocation. This is done via a new function in the gralloc(allocSize).

If the specified size is lesser that the calculated size,
set the buffer size to the calculated size.

Change-Id: Iad9609d3b9074dcf3af07430966590078081ab72
This commit is contained in:
Naomi Luis 2011-03-16 13:32:07 -07:00 committed by Govind Surti
parent 62955d9fc4
commit 7a23eb34e1
2 changed files with 18 additions and 3 deletions

View File

@ -43,6 +43,7 @@ gpu_context_t::gpu_context_t(Deps& deps, PmemAllocator& pmemAllocator,
common.module = const_cast<hw_module_t*>(&module->base.common);
common.close = gralloc_close;
alloc = gralloc_alloc;
allocSize = gralloc_alloc_size;
free = gralloc_free;
}
@ -313,7 +314,7 @@ void gpu_context_t::getGrallocInformationFromFormat(int inputFormat, int *colorF
}
int gpu_context_t::alloc_impl(int w, int h, int format, int usage,
buffer_handle_t* pHandle, int* pStride) {
buffer_handle_t* pHandle, int* pStride, int bufferSize) {
if (!pHandle || !pStride)
return -EINVAL;
@ -373,6 +374,8 @@ int gpu_context_t::alloc_impl(int w, int h, int format, int usage,
if ((ssize_t)size <= 0)
return -EINVAL;
size = (bufferSize >= size)? bufferSize : size;
int err;
if (usage & GRALLOC_USAGE_HW_FB) {
err = gralloc_alloc_framebuffer(size, usage, pHandle);
@ -439,7 +442,17 @@ int gpu_context_t::gralloc_alloc(alloc_device_t* dev, int w, int h, int format,
return -EINVAL;
}
gpu_context_t* gpu = reinterpret_cast<gpu_context_t*>(dev);
return gpu->alloc_impl(w, h, format, usage, pHandle, pStride);
return gpu->alloc_impl(w, h, format, usage, pHandle, pStride, 0);
}
int gpu_context_t::gralloc_alloc_size(alloc_device_t* dev, int w, int h, int format,
int usage, buffer_handle_t* pHandle, int* pStride, int bufferSize)
{
if (!dev) {
return -EINVAL;
}
gpu_context_t* gpu = reinterpret_cast<gpu_context_t*>(dev);
return gpu->alloc_impl(w, h, format, usage, pHandle, pStride, bufferSize);
}
int gpu_context_t::gralloc_free(alloc_device_t* dev,

View File

@ -60,11 +60,13 @@ class gpu_context_t : public alloc_device_t {
int width, int height);
int free_impl(private_handle_t const* hnd);
int alloc_impl(int w, int h, int format, int usage,
buffer_handle_t* pHandle, int* pStride);
buffer_handle_t* pHandle, int* pStride, int bufferSize = 0);
static int gralloc_alloc(alloc_device_t* dev, int w, int h, int format,
int usage, buffer_handle_t* pHandle, int* pStride);
static int gralloc_free(alloc_device_t* dev, buffer_handle_t handle);
static int gralloc_alloc_size(alloc_device_t* dev, int w, int h, int format,
int usage, buffer_handle_t* pHandle, int* pStride, int bufferSize);
static int gralloc_close(struct hw_device_t *dev);
private: