From 7a23eb34e1cff1fd3a696a75d3916d3e1bd96e57 Mon Sep 17 00:00:00 2001 From: Naomi Luis Date: Wed, 16 Mar 2011 13:32:07 -0700 Subject: [PATCH] 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 --- libgralloc-qsd8k/gpu.cpp | 17 +++++++++++++++-- libgralloc-qsd8k/gpu.h | 4 +++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/libgralloc-qsd8k/gpu.cpp b/libgralloc-qsd8k/gpu.cpp index a2c35b4..6f1420c 100755 --- a/libgralloc-qsd8k/gpu.cpp +++ b/libgralloc-qsd8k/gpu.cpp @@ -43,6 +43,7 @@ gpu_context_t::gpu_context_t(Deps& deps, PmemAllocator& pmemAllocator, common.module = const_cast(&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(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(dev); + return gpu->alloc_impl(w, h, format, usage, pHandle, pStride, bufferSize); } int gpu_context_t::gralloc_free(alloc_device_t* dev, diff --git a/libgralloc-qsd8k/gpu.h b/libgralloc-qsd8k/gpu.h index 67a58d8..3789f6c 100755 --- a/libgralloc-qsd8k/gpu.h +++ b/libgralloc-qsd8k/gpu.h @@ -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: