diff options
author | Alistair Strachan <alistair.strachan@imgtec.com> | 2017-03-01 21:22:02 -0800 |
---|---|---|
committer | Daniel Cardenas <danielcar@google.com> | 2017-03-06 16:25:36 -0800 |
commit | a96e082acbc128f06be3e9d71ed093f45744522d (patch) | |
tree | f6a85649215b9ed46ac72b36db5aae56c18fd1bb | |
parent | 494b8a820a24a5868cc008c56e60878fb9b30984 (diff) | |
download | hwcomposer-a96e082acbc128f06be3e9d71ed093f45744522d.tar.gz |
Revert "Revert "Update the DDK interface and add support for gralloc1.""
This reverts commit be5caddb7d82f64ce765752e7451240f6a11a589.
Bug: 35427231
Test: netflix, youtube, play movies
Change-Id: Ifde1ce1fa2dcc52367c158208cb68feaa257a672
24 files changed, 1600 insertions, 338 deletions
diff --git a/merrifield/common/buffers/BufferManager.cpp b/merrifield/common/buffers/BufferManager.cpp index 6a939ae..ca6f0ad 100644 --- a/merrifield/common/buffers/BufferManager.cpp +++ b/merrifield/common/buffers/BufferManager.cpp @@ -17,14 +17,14 @@ #include <HwcTrace.h> #include <hardware/hwcomposer.h> #include <BufferManager.h> +#include <hal_public.h> #include <DrmConfig.h> namespace android { namespace intel { BufferManager::BufferManager() - : mGrallocModule(NULL), - mAllocDev(NULL), + : mGralloc(NULL), mFrameBuffers(), mBufferPool(NULL), mDataBuffer(NULL), @@ -56,16 +56,9 @@ bool BufferManager::initialize() } // init gralloc module - hw_module_t const* module; - if (hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module)) { + if (gralloc_open_img(&mGralloc)) { DEINIT_AND_RETURN_FALSE("failed to get gralloc module"); } - mGrallocModule = (gralloc_module_t const*)module; - - gralloc_open(module, &mAllocDev); - if (!mAllocDev) { - WTRACE("failed to open alloc device"); - } // create a dummy data buffer mDataBuffer = createDataBuffer(0); @@ -100,9 +93,9 @@ void BufferManager::deinitialize() } mFrameBuffers.clear(); - if (mAllocDev) { - gralloc_close(mAllocDev); - mAllocDev = NULL; + if (mGralloc) { + gralloc_close_img(mGralloc); + mGralloc = NULL; } if (mDataBuffer) { @@ -222,7 +215,7 @@ buffer_handle_t BufferManager::allocFrameBuffer(int width, int height, int *stri { RETURN_NULL_IF_NOT_INIT(); - if (!mAllocDev) { + if (!mGralloc) { WTRACE("Alloc device is not available"); return 0; } @@ -234,8 +227,8 @@ buffer_handle_t BufferManager::allocFrameBuffer(int width, int height, int *stri ITRACE("size of frame buffer to create: %dx%d", width, height); buffer_handle_t handle = 0; - status_t err = mAllocDev->alloc( - mAllocDev, + status_t err = gralloc_device_alloc_img( + mGralloc, width, height, DrmConfig::getFrameBufferFormat(), @@ -282,7 +275,7 @@ buffer_handle_t BufferManager::allocFrameBuffer(int width, int height, int *stri if (mapper) { delete mapper; } - mAllocDev->free(mAllocDev, handle); + gralloc_device_free_img(mGralloc, handle); return 0; } @@ -290,7 +283,7 @@ void BufferManager::freeFrameBuffer(buffer_handle_t fbHandle) { RETURN_VOID_IF_NOT_INIT(); - if (!mAllocDev) { + if (!mGralloc) { WTRACE("Alloc device is not available"); return; } @@ -306,14 +299,14 @@ void BufferManager::freeFrameBuffer(buffer_handle_t fbHandle) mapper->putFbHandle(); delete mapper; mFrameBuffers.removeItem(fbHandle); - mAllocDev->free(mAllocDev, handle); + gralloc_device_free_img(mGralloc, handle); } buffer_handle_t BufferManager::allocGrallocBuffer(uint32_t width, uint32_t height, uint32_t format, uint32_t usage) { RETURN_NULL_IF_NOT_INIT(); - if (!mAllocDev) { + if (!mGralloc) { WTRACE("Alloc device is not available"); return 0; } @@ -326,8 +319,8 @@ buffer_handle_t BufferManager::allocGrallocBuffer(uint32_t width, uint32_t heigh ITRACE("size of graphic buffer to create: %dx%d", width, height); buffer_handle_t handle = 0; int stride; - status_t err = mAllocDev->alloc( - mAllocDev, + status_t err = gralloc_device_alloc_img( + mGralloc, width, height, format, @@ -345,13 +338,13 @@ buffer_handle_t BufferManager::allocGrallocBuffer(uint32_t width, uint32_t heigh void BufferManager::freeGrallocBuffer(buffer_handle_t handle) { RETURN_VOID_IF_NOT_INIT(); - if (!mAllocDev) { + if (!mGralloc) { WTRACE("Alloc device is not available"); return; } if (handle) - mAllocDev->free(mAllocDev, handle); + gralloc_device_free_img(mGralloc, handle); } } // namespace intel diff --git a/merrifield/include/BufferManager.h b/merrifield/include/BufferManager.h index 6bc98bf..d304b00 100644 --- a/merrifield/include/BufferManager.h +++ b/merrifield/include/BufferManager.h @@ -65,7 +65,7 @@ protected: virtual DataBuffer* createDataBuffer(buffer_handle_t handle) = 0; virtual BufferMapper* createBufferMapper(DataBuffer& buffer) = 0; - gralloc_module_t const* mGrallocModule; + const hw_device_t* mGralloc; private: enum { // make the buffer pool large enough diff --git a/merrifield/include/pvr/hal/hal_public.h b/merrifield/include/pvr/hal/hal_public.h index e1053bd..19910c1 100644 --- a/merrifield/include/pvr/hal/hal_public.h +++ b/merrifield/include/pvr/hal/hal_public.h @@ -21,28 +21,195 @@ * THE SOFTWARE. */ -#ifndef __HAL_PUBLIC_H -#define __HAL_PUBLIC_H +#ifndef HAL_PUBLIC_H +#define HAL_PUBLIC_H -#define PVR_ANDROID_NATIVE_WINDOW_HAS_SYNC +#define PVR_ANDROID_HAS_SET_BUFFERS_DATASPACE +#define PVR_ANDROID_HAS_SET_BUFFERS_DATASPACE_2 -#include "img_gralloc_public.h" +#include "img_gralloc_common_public.h" -#undef HAL_PIXEL_FORMAT_NV12 +/* Extension pixel formats used by Intel components */ -#define HAL_PIXEL_FORMAT_UYVY 0x107 -#define HAL_PIXEL_FORMAT_INTEL_ZSL 0x109 -#define HAL_PIXEL_FORMAT_NV12 0x3231564E -#define HAL_PIXEL_FORMAT_NV21 0x3132564E -#define HAL_PIXEL_FORMAT_I420 0x30323449 -#define HAL_PIXEL_FORMAT_YUY2 0x32595559 -#define HAL_PIXEL_FORMAT_NV12_VED 0x7FA00E00 -#define HAL_PIXEL_FORMAT_NV12_VEDT 0x7FA00F00 +#undef HAL_PIXEL_FORMAT_NV12 -#define GRALLOC_MODULE_GET_BUFFER_CPU_ADDRESSES_IMG 108 -#define GRALLOC_MODULE_PUT_BUFFER_CPU_ADDRESSES_IMG 109 +#define HAL_PIXEL_FORMAT_UYVY 0x107 +#define HAL_PIXEL_FORMAT_INTEL_YV12 0x108 +#define HAL_PIXEL_FORMAT_INTEL_ZSL 0x109 +#define HAL_PIXEL_FORMAT_NV12 0x3231564E +#define HAL_PIXEL_FORMAT_NV21 0x3132564E +#define HAL_PIXEL_FORMAT_I420 0x30323449 +#define HAL_PIXEL_FORMAT_YUY2 0x32595559 +#define HAL_PIXEL_FORMAT_NV12_VED 0x7FA00E00 +#define HAL_PIXEL_FORMAT_NV12_VEDT 0x7FA00F00 -#define GRALLOC_MODULE_GET_DISPLAY_DEVICE_IMG 1000 -#define GRALLOC_MODULE_GET_DISPLAY_STATUS_IMG 1001 +/* Extension API used by Intel components */ -#endif /* __HAL_PUBLIC_H */ +#define GRALLOC_GET_BUFFER_CPU_ADDRESSES_IMG 108 +#define GRALLOC_PUT_BUFFER_CPU_ADDRESSES_IMG 109 + +#define GRALLOC_GET_DISPLAY_DEVICE_IMG 1000 +#define GRALLOC_GET_DISPLAY_STATUS_IMG 1001 + +#include "img_gralloc.h" +#include "img_gralloc1.h" + +typedef const gralloc_module_t gralloc0_t; +typedef gralloc1_device_t gralloc1_t; + +static inline int gralloc_is_v1_img(const hw_module_t *m) +{ + return ((m->module_api_version >> 8) & 0xff) == 1; +} + +static inline int gralloc_open_img(const hw_device_t **d) +{ + const hw_module_t *m; + int err; + + err = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &m); + if (err) + return err; + + if (gralloc_is_v1_img(m)) + return gralloc1_open(m, (gralloc1_t **)d); + else + return gralloc_open(m, (alloc_device_t **)d); +} + +static inline int gralloc_close_img(const hw_device_t *d) +{ + if (gralloc_is_v1_img(d->module)) + return gralloc1_close((gralloc1_t *)d); + else + return gralloc_close((alloc_device_t *)d); +} + +static inline int gralloc_register_img + (const hw_device_t *d, buffer_handle_t handle) +{ + if (gralloc_is_v1_img(d->module)) + return gralloc1_register_img((gralloc1_t *)d, handle); + else + return gralloc0_register_img((gralloc0_t *)d->module, handle); +} + +static inline int gralloc_unregister_img + (const hw_device_t *d, buffer_handle_t handle) +{ + if (gralloc_is_v1_img(d->module)) + return gralloc1_unregister_img((gralloc1_t *)d, handle); + else + return gralloc0_unregister_img((gralloc0_t *)d->module, handle); +} + +static inline int gralloc_device_alloc_img + (const hw_device_t *d, int w, int h, int format, int usage, + buffer_handle_t *handle, int *stride) +{ + if (gralloc_is_v1_img(d->module)) { + usage = (usage | ((usage & 0x33) << 1)) & ~0x11; + return gralloc1_device_alloc_img((gralloc1_t *)d, w, h, format, + usage, handle, stride); + } else + return gralloc0_device_alloc_img((alloc_device_t *)d, w, h, format, + usage, handle, stride); +} + +static inline int gralloc_device_free_img + (const hw_device_t *d, buffer_handle_t handle) +{ + if (gralloc_is_v1_img(d->module)) + return gralloc1_device_free_img((gralloc1_t *)d, handle); + else + return gralloc0_device_free_img((alloc_device_t *)d, handle); +} + +static inline int gralloc_lock_async_img + (const hw_device_t *d, buffer_handle_t handle, int usage, + const gralloc1_rect_t *r, void **vaddr, int acquireFence) +{ + if (gralloc_is_v1_img(d->module)) { + usage = (usage | ((usage & 0x33) << 1)) & ~0x11; + return gralloc1_lock_async_img((gralloc1_t *)d, + handle, usage, r, vaddr, acquireFence); + } else + return gralloc0_lock_async_img((gralloc0_t *)d->module, + handle, usage, r, vaddr, acquireFence); +} + +static inline int gralloc_unlock_async_img + (const hw_device_t *d, buffer_handle_t handle, int *releaseFence) +{ + if (gralloc_is_v1_img(d->module)) + return gralloc1_unlock_async_img((gralloc1_t *)d, + handle, releaseFence); + else + return gralloc0_unlock_async_img((gralloc0_t *)d->module, + handle, releaseFence); +} + +static inline int gralloc_blit_handle_to_handle_img + (const hw_device_t *d, buffer_handle_t src, buffer_handle_t dest, + int w, int h, int x, int y, int transform, int input_fence, + int *output_fence) +{ + if (gralloc_is_v1_img(d->module)) + return gralloc1_blit_handle_to_handle_img((gralloc1_t *)d, + src, dest, w, h, x, y, + transform, input_fence, + output_fence); + else + return gralloc0_blit_handle_to_handle_img((gralloc0_t *)d->module, + src, dest, w, h, x, y, + transform, input_fence, + output_fence); +} + + +static inline int gralloc_get_buffer_cpu_addresses_img + (const hw_device_t *d, buffer_handle_t handle, void **vaddrs, + size_t *sizes) +{ + if (gralloc_is_v1_img(d->module)) + return gralloc1_get_buffer_cpu_addresses_img((gralloc1_t *)d, + handle, vaddrs, sizes); + else + return gralloc0_get_buffer_cpu_addresses_img((gralloc0_t *)d->module, + handle, vaddrs, sizes); +} + +static inline int gralloc_put_buffer_cpu_addresses_img + (const hw_device_t *d, buffer_handle_t handle) +{ + if (gralloc_is_v1_img(d->module)) + return gralloc1_put_buffer_cpu_addresses_img((gralloc1_t *)d, + handle); + else + return gralloc0_put_buffer_cpu_addresses_img((gralloc0_t *)d->module, + handle); +} + +static inline int gralloc_get_display_device_img + (const hw_device_t *d, void **ppvDispDev) +{ + if (gralloc_is_v1_img(d->module)) + return gralloc1_get_display_device_img((gralloc1_t *)d, + ppvDispDev); + else + return gralloc0_get_display_device_img((gralloc0_t *)d->module, + ppvDispDev); +} + +static inline int gralloc_get_display_status_img + (const hw_device_t *d, buffer_handle_t handle, uint32_t *pui32Status) +{ + if (gralloc_is_v1_img(d->module)) + return gralloc1_get_display_status_img((gralloc1_t *)d, + handle, pui32Status); + else + return gralloc0_get_display_status_img((gralloc0_t *)d->module, + handle, pui32Status); +} + +#endif /* HAL_PUBLIC_H */ diff --git a/merrifield/include/pvr/hal/img_gralloc.h b/merrifield/include/pvr/hal/img_gralloc.h new file mode 100644 index 0000000..d9560fa --- /dev/null +++ b/merrifield/include/pvr/hal/img_gralloc.h @@ -0,0 +1,107 @@ +/* Copyright (c) Imagination Technologies Ltd. + * + * The contents of this file are subject to the MIT license as set out below. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef IMG_GRALLOC_H +#define IMG_GRALLOC_H + +#include <hardware/gralloc.h> + +/* for gralloc1_rect_t */ +#include <hardware/gralloc1.h> + +static inline int gralloc0_register_img + (const gralloc_module_t *g, buffer_handle_t handle) +{ + return g->registerBuffer(g, handle); +} + +static inline int gralloc0_unregister_img + (const gralloc_module_t *g, buffer_handle_t handle) +{ + return g->unregisterBuffer(g, handle); +} + +static inline int gralloc0_device_alloc_img + (alloc_device_t *d, int w, int h, int format, int usage, + buffer_handle_t *handle, int *stride) +{ + return d->alloc(d, w, h, format, usage, handle, stride); +} + +static inline int gralloc0_device_free_img + (alloc_device_t *d, buffer_handle_t handle) +{ + return d->free(d, handle); +} + +static inline int gralloc0_lock_async_img + (const gralloc_module_t *g, buffer_handle_t handle, int usage, + const gralloc1_rect_t *r, void **vaddr, int acquireFence) +{ + return g->lockAsync(g, handle, usage, + r->left, r->top, r->width, r->height, + vaddr, acquireFence); +} + +static inline int gralloc0_unlock_async_img + (const gralloc_module_t *g, buffer_handle_t handle, int *releaseFence) +{ + return g->unlockAsync(g, handle, releaseFence); +} + +static inline int gralloc0_blit_handle_to_handle_img + (const gralloc_module_t *g, buffer_handle_t src, buffer_handle_t dest, + int w, int h, int x, int y, int transform, int input_fence, + int *output_fence) +{ + return g->perform(g, GRALLOC_BLIT_HANDLE_TO_HANDLE_IMG, src, dest, w, h, + x, y, transform, input_fence, output_fence); +} + +static inline int gralloc0_get_buffer_cpu_addresses_img + (const gralloc_module_t *g, buffer_handle_t handle, void **vaddrs, + size_t *sizes) +{ + return g->perform(g, GRALLOC_GET_BUFFER_CPU_ADDRESSES_IMG, handle, vaddrs, + sizes); +} + +static inline int gralloc0_put_buffer_cpu_addresses_img + (const gralloc_module_t *g, buffer_handle_t handle) +{ + return g->perform(g, GRALLOC_PUT_BUFFER_CPU_ADDRESSES_IMG, handle); +} + +static inline int gralloc0_get_display_device_img + (const gralloc_module_t *g, void **ppvDispDev) +{ + return g->perform(g, GRALLOC_GET_DISPLAY_DEVICE_IMG, ppvDispDev); +} + +static inline int gralloc0_get_display_status_img + (const gralloc_module_t *g, buffer_handle_t handle, uint32_t *pui32Status) +{ + return g->perform(g, GRALLOC_GET_DISPLAY_STATUS_IMG, handle, pui32Status); +} + +#endif /* IMG_GRALLOC_H */ diff --git a/merrifield/include/pvr/hal/img_gralloc1.h b/merrifield/include/pvr/hal/img_gralloc1.h new file mode 100644 index 0000000..f9f69a2 --- /dev/null +++ b/merrifield/include/pvr/hal/img_gralloc1.h @@ -0,0 +1,303 @@ +/* Copyright (c) Imagination Technologies Ltd. + * + * The contents of this file are subject to the MIT license as set out below. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef IMG_GRALLOC1_H +#define IMG_GRALLOC1_H + +#include <hardware/gralloc1.h> + +#include <stdlib.h> + +#define GRALLOC1_FUNCTION_IMG_EXT_OFF 1000 + +enum +{ + GRALLOC1_FUNCTION_BLIT_HANDLE_TO_HANDLE_IMG = + (GRALLOC1_FUNCTION_IMG_EXT_OFF + GRALLOC_BLIT_HANDLE_TO_HANDLE_IMG), + GRALLOC1_FUNCTION_GET_BUFFER_CPU_ADDRESSES_IMG = + (GRALLOC1_FUNCTION_IMG_EXT_OFF + GRALLOC_GET_BUFFER_CPU_ADDRESSES_IMG), + GRALLOC1_FUNCTION_PUT_BUFFER_CPU_ADDRESSES_IMG = + (GRALLOC1_FUNCTION_IMG_EXT_OFF + GRALLOC_PUT_BUFFER_CPU_ADDRESSES_IMG), + GRALLOC1_FUNCTION_GET_DISPLAY_DEVICE_IMG = + (GRALLOC1_FUNCTION_IMG_EXT_OFF + GRALLOC_GET_DISPLAY_DEVICE_IMG), + GRALLOC1_FUNCTION_GET_DISPLAY_STATUS_IMG = + (GRALLOC1_FUNCTION_IMG_EXT_OFF + GRALLOC_GET_DISPLAY_STATUS_IMG), +}; + +static inline int gralloc1_register_img + (gralloc1_device_t *g, buffer_handle_t handle) +{ + GRALLOC1_PFN_RETAIN f = + (GRALLOC1_PFN_RETAIN) + g->getFunction(g, GRALLOC1_FUNCTION_RETAIN); + int32_t err; + + err = f(g, handle); + switch (err) + { + case GRALLOC1_ERROR_NO_RESOURCES: + return -EAGAIN; + case GRALLOC1_ERROR_NONE: + return 0; + default: + return -EINVAL; + } +} + +static inline int gralloc1_unregister_img + (gralloc1_device_t *g, buffer_handle_t handle) +{ + GRALLOC1_PFN_RELEASE f = + (GRALLOC1_PFN_RELEASE) + g->getFunction(g, GRALLOC1_FUNCTION_RELEASE); + int32_t err; + + err = f(g, handle); + switch (err) + { + case GRALLOC1_ERROR_NONE: + return 0; + default: + return -EINVAL; + } +} + +static inline int gralloc1_device_alloc_img + (gralloc1_device_t *d, int w, int h, int format, int usage, + buffer_handle_t *handle, int *stride) +{ + GRALLOC1_PFN_ALLOCATE allocate = + (GRALLOC1_PFN_ALLOCATE) + d->getFunction(d, GRALLOC1_FUNCTION_ALLOCATE); + GRALLOC1_PFN_CREATE_DESCRIPTOR createDescriptor = + (GRALLOC1_PFN_CREATE_DESCRIPTOR) + d->getFunction(d, GRALLOC1_FUNCTION_CREATE_DESCRIPTOR); + GRALLOC1_PFN_DESTROY_DESCRIPTOR destroyDescriptor = + (GRALLOC1_PFN_DESTROY_DESCRIPTOR) + d->getFunction(d, GRALLOC1_FUNCTION_DESTROY_DESCRIPTOR); + GRALLOC1_PFN_SET_CONSUMER_USAGE setConsumerUsage = + (GRALLOC1_PFN_SET_CONSUMER_USAGE) + d->getFunction(d, GRALLOC1_FUNCTION_SET_CONSUMER_USAGE); + GRALLOC1_PFN_SET_DIMENSIONS setDimensions = + (GRALLOC1_PFN_SET_DIMENSIONS) + d->getFunction(d, GRALLOC1_FUNCTION_SET_DIMENSIONS); + GRALLOC1_PFN_SET_FORMAT setFormat = + (GRALLOC1_PFN_SET_FORMAT) + d->getFunction(d, GRALLOC1_FUNCTION_SET_FORMAT); + GRALLOC1_PFN_SET_PRODUCER_USAGE setProducerUsage = + (GRALLOC1_PFN_SET_PRODUCER_USAGE) + d->getFunction(d, GRALLOC1_FUNCTION_SET_PRODUCER_USAGE); + GRALLOC1_PFN_GET_STRIDE getStride = + (GRALLOC1_PFN_GET_STRIDE) + d->getFunction(d, GRALLOC1_FUNCTION_GET_STRIDE); + uint64_t producerUsage = + (usage & (GRALLOC1_PRODUCER_USAGE_CPU_READ_OFTEN | + GRALLOC1_PRODUCER_USAGE_CPU_WRITE_OFTEN | + GRALLOC1_PRODUCER_USAGE_GPU_RENDER_TARGET | + GRALLOC1_PRODUCER_USAGE_PROTECTED | + GRALLOC1_PRODUCER_USAGE_CAMERA | + GRALLOC1_PRODUCER_USAGE_VIDEO_DECODER)); + uint64_t consumerUsage = + (usage & (GRALLOC1_CONSUMER_USAGE_CPU_READ_OFTEN | + GRALLOC1_CONSUMER_USAGE_GPU_TEXTURE | + GRALLOC1_CONSUMER_USAGE_HWCOMPOSER | + GRALLOC1_CONSUMER_USAGE_CLIENT_TARGET | + GRALLOC1_CONSUMER_USAGE_CURSOR | + GRALLOC1_CONSUMER_USAGE_VIDEO_ENCODER | + GRALLOC1_CONSUMER_USAGE_CAMERA | + GRALLOC1_CONSUMER_USAGE_RENDERSCRIPT)); + gralloc1_buffer_descriptor_t descriptor; + uint32_t stride32; + int err = -EINVAL; + int32_t err32; + + err32 = createDescriptor(d, &descriptor); + if (err32 != GRALLOC1_ERROR_NONE) + goto err_out; + + err32 = setDimensions(d, descriptor, w, h); + if (err32 != GRALLOC1_ERROR_NONE) + goto err_destroy_descriptor; + + err32 = setFormat(d, descriptor, format); + if (err32 != GRALLOC1_ERROR_NONE) + goto err_destroy_descriptor; + + err32 = setConsumerUsage(d, descriptor, consumerUsage); + if (err32 != GRALLOC1_ERROR_NONE) + goto err_destroy_descriptor; + + err32 = setProducerUsage(d, descriptor, producerUsage); + if (err32 != GRALLOC1_ERROR_NONE) + goto err_destroy_descriptor; + + err32 = allocate(d, 1, &descriptor, handle); + switch (err32) + { + case GRALLOC1_ERROR_NOT_SHARED: + case GRALLOC1_ERROR_NONE: + break; + case GRALLOC1_ERROR_NO_RESOURCES: + err = -EAGAIN; + default: + goto err_destroy_descriptor; + } + + err32 = getStride(d, *handle, &stride32); + if (err32 != GRALLOC1_ERROR_NONE) + { + gralloc1_unregister_img(d, *handle); + goto err_destroy_descriptor; + } + + *stride = (int)stride32; + err = 0; +err_destroy_descriptor: + destroyDescriptor(d, descriptor); +err_out: + return err; +} + +static inline int gralloc1_device_free_img + (gralloc1_device_t *d, buffer_handle_t handle) +{ + return gralloc1_unregister_img(d, handle); +} + +static inline int gralloc1_lock_async_img + (gralloc1_device_t *g, buffer_handle_t handle, int usage, + const gralloc1_rect_t *r, void **vaddr, int acquireFence) +{ + GRALLOC1_PFN_LOCK f = + (GRALLOC1_PFN_LOCK) + g->getFunction(g, GRALLOC1_FUNCTION_LOCK); + uint64_t producerUsage = + (usage & (GRALLOC1_PRODUCER_USAGE_CPU_READ_OFTEN | + GRALLOC1_PRODUCER_USAGE_CPU_WRITE_OFTEN)); + uint64_t consumerUsage = + (usage & GRALLOC1_CONSUMER_USAGE_CPU_READ_OFTEN); + int32_t err; + + err = f(g, handle, producerUsage, consumerUsage, r, vaddr, acquireFence); + switch (err) + { + case GRALLOC1_ERROR_NONE: + return 0; + case GRALLOC1_ERROR_NO_RESOURCES: + return -EAGAIN; + default: + return -EINVAL; + } +} + +static inline int gralloc1_unlock_async_img + (gralloc1_device_t *g, buffer_handle_t handle, int *releaseFence) +{ + GRALLOC1_PFN_UNLOCK f = + (GRALLOC1_PFN_UNLOCK) + g->getFunction(g, GRALLOC1_FUNCTION_UNLOCK); + int32_t err, releaseFence32; + + err = f(g, handle, &releaseFence32); + switch (err) + { + case GRALLOC1_ERROR_NONE: + *releaseFence = releaseFence32; + return 0; + default: + return -EINVAL; + } +} + +typedef int (*GRALLOC1_PFN_BLIT_HANDLE_TO_HANDLE_IMG) + (gralloc1_device_t *g, buffer_handle_t src, buffer_handle_t dest, + int w, int h, int x, int y, int transform, int input_fence, + int *output_fence); + +static inline int gralloc1_blit_handle_to_handle_img + (gralloc1_device_t *g, buffer_handle_t src, buffer_handle_t dest, + int w, int h, int x, int y, int transform, int input_fence, + int *output_fence) +{ + GRALLOC1_PFN_BLIT_HANDLE_TO_HANDLE_IMG f = + (GRALLOC1_PFN_BLIT_HANDLE_TO_HANDLE_IMG) + g->getFunction(g, GRALLOC1_FUNCTION_BLIT_HANDLE_TO_HANDLE_IMG); + + return f(g, src, dest, w, h, x, y, transform, input_fence, output_fence); +} + +typedef int (*GRALLOC1_PFN_GET_BUFFER_CPU_ADDRESSES_IMG) + (gralloc1_device_t *g, buffer_handle_t handle, void **vaddrs, + size_t *sizes); + +static inline int gralloc1_get_buffer_cpu_addresses_img + (gralloc1_device_t *g, buffer_handle_t handle, void **vaddrs, + size_t *sizes) +{ + GRALLOC1_PFN_GET_BUFFER_CPU_ADDRESSES_IMG f = + (GRALLOC1_PFN_GET_BUFFER_CPU_ADDRESSES_IMG) + g->getFunction(g, GRALLOC1_FUNCTION_GET_BUFFER_CPU_ADDRESSES_IMG); + + return f(g, handle, vaddrs, sizes); +} + +typedef int (*GRALLOC1_PFN_PUT_BUFFER_CPU_ADDRESSES_IMG) + (gralloc1_device_t *g, buffer_handle_t handle); + +static inline int gralloc1_put_buffer_cpu_addresses_img + (gralloc1_device_t *g, buffer_handle_t handle) +{ + GRALLOC1_PFN_PUT_BUFFER_CPU_ADDRESSES_IMG f = + (GRALLOC1_PFN_PUT_BUFFER_CPU_ADDRESSES_IMG) + g->getFunction(g, GRALLOC1_FUNCTION_PUT_BUFFER_CPU_ADDRESSES_IMG); + + return f(g, handle); +} + +typedef int (*GRALLOC1_PFN_GET_DISPLAY_DEVICE_IMG) + (gralloc1_device_t *g, void **ppvDispDev); + +static inline int gralloc1_get_display_device_img + (gralloc1_device_t *g, void **ppvDispDev) +{ + GRALLOC1_PFN_GET_DISPLAY_DEVICE_IMG f = + (GRALLOC1_PFN_GET_DISPLAY_DEVICE_IMG) + g->getFunction(g, GRALLOC1_FUNCTION_GET_DISPLAY_DEVICE_IMG); + + return f(g, ppvDispDev); +} + +typedef int (*GRALLOC1_PFN_GET_DISPLAY_STATUS_IMG) + (gralloc1_device_t *g, buffer_handle_t handle, uint32_t *pui32Status); + +static inline int gralloc1_get_display_status_img + (gralloc1_device_t *g, buffer_handle_t handle, uint32_t *pui32Status) +{ + GRALLOC1_PFN_GET_DISPLAY_STATUS_IMG f = + (GRALLOC1_PFN_GET_DISPLAY_STATUS_IMG) + g->getFunction(g, GRALLOC1_FUNCTION_GET_DISPLAY_STATUS_IMG); + + return f(g, handle, pui32Status); +} + +#endif /* IMG_GRALLOC1_H */ diff --git a/merrifield/include/pvr/hal/img_gralloc_public.h b/merrifield/include/pvr/hal/img_gralloc_common_public.h index 1b6ca50..965e5a7 100644 --- a/merrifield/include/pvr/hal/img_gralloc_public.h +++ b/merrifield/include/pvr/hal/img_gralloc_common_public.h @@ -21,16 +21,14 @@ * THE SOFTWARE. */ -#ifndef HAL_PUBLIC_H -#define HAL_PUBLIC_H +#ifndef IMG_GRALLOC_COMMON_PUBLIC_H +#define IMG_GRALLOC_COMMON_PUBLIC_H -/* Authors of third party hardware composer (HWC) modules will need to include - * this header to access functionality in the gralloc HAL. - */ - -#include <hardware/gralloc.h> +#include <cutils/native_handle.h> +#include <system/graphics.h> +#include <linux/ion.h> -#define ALIGN(x,a) (((x) + (a) - 1L) & ~((a) - 1L)) +#define ALIGN(x,a) ((((x) + (a) - 1L) / (a)) * (a)) #define HW_ALIGN 32 /* Use bits [0-3] of "vendor format" bits as real format. Customers should @@ -97,22 +95,15 @@ typedef struct /* These fields can be sent cross process. They are also valid * to duplicate within the same process. * - * A table is stored within psPrivateData on gralloc_module_t (this - * is obviously per-process) which maps stamps to a mapped - * PVRSRV_MEMDESC in that process. Each map entry has a lock - * count associated with it, satisfying the requirements of the - * Android API. This also prevents us from leaking maps/allocations. - * - * This table has entries inserted either by alloc() - * (alloc_device_t) or map() (gralloc_module_t). Entries are removed - * by free() (alloc_device_t) and unmap() (gralloc_module_t). + * A table is stored within the gralloc implementation's private data + * structure (which is per-process) which maps stamps to a mapped + * PVRSRV_MEMDESC in that process. Each map entry has a lock count + * associated with it, satisfying the requirements of the gralloc API. + * This also prevents us from leaking maps/allocations. */ #define IMG_NATIVE_HANDLE_NUMFDS (MAX_SUB_ALLOCS) - /* The `fd' field is used to "export" a meminfo to another process. - * Therefore, it is allocated by alloc_device_t, and consumed by - * gralloc_module_t. - */ + /* The `fd' field is used to "export" a meminfo to another process. */ int fd[IMG_NATIVE_HANDLE_NUMFDS]; /* This define should represent the number of packed 'int's required to @@ -126,9 +117,9 @@ typedef struct 6 + MAX_SUB_ALLOCS + MAX_SUB_ALLOCS + \ sizeof(unsigned long long) / sizeof(int) * MAX_SUB_ALLOCS + \ 1) - /* A KERNEL unique identifier for any exported kernel meminfo. Each - * exported kernel meminfo will have a unique stamp, but note that in - * userspace, several meminfos across multiple processes could have + /* A KERNEL unique identifier for any exported kernel memdesc. Each + * exported kernel memdesc will have a unique stamp, but note that in + * userspace, several memdescs across multiple processes could have * the same stamp. As the native_handle can be dup(2)'d, there could be * multiple handles with the same stamp but different file descriptors. */ @@ -180,18 +171,77 @@ typedef struct } __attribute__((aligned(sizeof(int)),packed)) IMG_native_handle_t; -typedef struct -{ - int l, t, w, h; -} -IMG_write_lock_rect_t; +/* Channel encoding of buffer data. + * + * If the buffer has only one plane, the ENCODING bits should be interpreted + * as a definition of the interleaving pattern. Only two of the possible four + * permutations are defined; this is because the YVYU and VYUY patterns are + * not seen in the wild. + * + * If the buffer has more than one plane, the ENCODING bits should be + * interpreted as a definition of the plane order in memory. Assuming a YUV + * format, Y is always first, but U and V may be defined in 'V then U' or + * 'U then V' orders. + * + * Some bits are not used, to maximize compatibility with older DDKs which + * used them in semantically different ways. + */ +#define IMG_BFF_ENCODING_MASK (3 << 0) +/* For uiPlanes == 1 **********************************/ +/* Reserved for VYUY (check IsYUV if used) (0 << 0) */ +#define IMG_BFF_ENCODING_INTERLEAVED_YUYV (1 << 0) +/* Reserved for YVYU (2 << 0) */ +#define IMG_BFF_ENCODING_INTERLEAVED_UYVY (3 << 0) +/* For uiPlanes > 1 ***********************************/ +/* Unused (check IsYUV if used) (0 << 0) */ +#define IMG_BFF_ENCODING_VUCrCb (1 << 0) +/* Unused (2 << 0) */ +#define IMG_BFF_ENCODING_UVCbCr (3 << 0) + +/* Whether the buffer should be cleared to zero from userspace, or via the + * PowerVR services at import time. This is deprecated functionality as most + * platforms use dma-buf or ion now, and for security reasons these allocators + * should never return uncleared memory. + */ +#define IMG_BFF_CPU_CLEAR (1 << 2) + +/* Deprecated, do not use */ +#define IMG_BFF_DONT_GPU_CLEAR (1 << 3) -#define IMG_BFF_YUV (1 << 0) -#define IMG_BFF_UVCbCrORDERING (1 << 1) -#define IMG_BFF_CPU_CLEAR (1 << 2) -#define IMG_BFF_DONT_GPU_CLEAR (1 << 3) -#define IMG_BFF_PARTIAL_ALLOC (1 << 4) -#define IMG_BFF_NEVER_COMPRESS (1 << 5) +/* Deprecated, do not use */ +#define IMG_BFF_PARTIAL_ALLOC (1 << 4) + +/* Guarantee that GPU framebuffer compression is never used for buffers in + * this format, even if the format is supported by the compressor. This might + * be useful if the buffer is being fed to hardware blocks that cannot handle + * the framebuffer compression encoding, and the existing HAL overrides are + * not sufficiently expressive. + */ +#define IMG_BFF_NEVER_COMPRESS (1 << 5) + +/* Indicates that the buffer should be mapped into the GPU 'tiling range' + * heaps, rather than the 'linear' general heap. This implies that the raw + * buffer data is tiled in physical memory. (The GPU BIF will de-tile it, so + * this is distinct from 'tiled texture' support.) The graphics HAL will + * select the correct 'tiling range' based on the buffer dimensions. + */ +#define IMG_BFF_BIFTILED (1 << 6) + +/* YUV subsampling encoding of buffer data. + * Many YUV formats have less chroma information than luma information. If + * this is not the case, use SUBSAMPLING_4_4_4. If each of the U and V channel + * data are 1/4 the size of the Y channel data, use SUBSAMPLING_4_2_0. + * Otherwise, use SUBSAMPLING_4_2_2. + */ +#define IMG_BFF_YUV_SUBSAMPLING_MASK (3 << 7) +#define IMG_BFF_YUV_SUBSAMPLING_4_2_0 (0 << 7) +/* Unused: 4:1:1, 4:2:1, 4:1:0, 3:1:1? (1 << 7) */ +#define IMG_BFF_YUV_SUBSAMPLING_4_2_2 (2 << 7) +#define IMG_BFF_YUV_SUBSAMPLING_4_4_4 (3 << 7) + +/* Backwards compatibility */ +#define IMG_BFF_YUV IMG_BFF_ENCODING_VUCrCb +#define IMG_BFF_UVCbCrORDERING IMG_BFF_ENCODING_UVCbCr /* Keep this in sync with SGX */ typedef struct IMG_buffer_format_public_t @@ -221,82 +271,98 @@ typedef struct IMG_buffer_format_public_t } IMG_buffer_format_public_t; -/* NOTE: This interface is deprecated. Use module->perform() instead. */ -typedef struct IMG_gralloc_module_public_t +typedef struct { - gralloc_module_t base; + enum + { + IMG_BUFFER_HANDLE_TYPE_ION = 0, + IMG_BUFFER_HANDLE_TYPE_DMABUF = 1, + } + eType; + + union + { + ion_user_handle_t aiIonUserHandle[MAX_SUB_ALLOCS]; + int aiDmaBufShareFd[MAX_SUB_ALLOCS]; + }; +} +IMG_buffer_handle_t; - /* Gets the head of the linked list of all registered formats */ - const IMG_buffer_format_public_t *(*GetBufferFormats)(void); +/* Public extensions, common to v0 and v1 HALs */ - /* Custom-blit components in lieu of overlay hardware */ - int (*Blit)(struct IMG_gralloc_module_public_t const *module, - buffer_handle_t src, buffer_handle_t dest, - int w, int h, int x, int y, int transform, - int iInputFenceFd, int *piOutputFenceFd); +#define GRALLOC_GET_BUFFER_FORMAT_IMG 1 +#define GRALLOC_GET_BUFFER_FORMATS_IMG 2 +#define GRALLOC_BLIT_HANDLE_TO_HANDLE_IMG 3 +#define GRALLOC_BLIT_STAMP_TO_HANDLE_IMG 4 +#define GRALLOC_SET_DATA_SPACE_IMG 5 +#define GRALLOC_GET_ION_CLIENT_IMG 6 +#define GRALLOC_GET_BUFFER_HANDLE_IMG 7 - int (*Blit3)(struct IMG_gralloc_module_public_t const *module, - unsigned long long ui64SrcStamp, int iSrcWidth, - int iSrcHeight, int iSrcFormat, int iSrcStrideInPixels, - int eSrcRotation, buffer_handle_t dest, int eDestRotation, - int iInputFenceFd, int *piOutputFenceFd); +#if !defined(PVR_ANDROID_HAS_SET_BUFFERS_DATASPACE) - /* Walk the above list and return only the specified format */ - const IMG_buffer_format_public_t *(*GetBufferFormat)(int iFormat); -} -IMG_gralloc_module_public_t; +enum +{ + HAL_DATASPACE_SRGB_LINEAR = 0x200, + HAL_DATASPACE_SRGB = 0x201, + HAL_DATASPACE_BT601_625 = 0x102, + HAL_DATASPACE_BT601_525 = 0x103, + HAL_DATASPACE_BT709 = 0x104, +}; -/* Helpers for using the non-type-safe perform() extension functions. Use - * these helpers instead of calling perform() directly in your application. - */ +#endif /* !defined(PVR_ANDROID_HAS_SET_BUFFERS_DATASPACE) */ -#define GRALLOC_MODULE_GET_BUFFER_FORMAT_IMG 1 -#define GRALLOC_MODULE_GET_BUFFER_FORMATS_IMG 2 -#define GRALLOC_MODULE_BLIT_HANDLE_TO_HANDLE_IMG 3 -#define GRALLOC_MODULE_BLIT_STAMP_TO_HANDLE_IMG 4 +#if !defined(PVR_ANDROID_HAS_SET_BUFFERS_DATASPACE_2) -static inline int -gralloc_module_get_buffer_format_img(const gralloc_module_t *module, - int format, - const IMG_buffer_format_public_t **v) +enum { - return module->perform(module, GRALLOC_MODULE_GET_BUFFER_FORMAT_IMG, - format, v); -} + HAL_DATASPACE_STANDARD_SHIFT = 16, + HAL_DATASPACE_TRANSFER_SHIFT = 22, + HAL_DATASPACE_RANGE_SHIFT = 27, -static inline int -gralloc_module_get_buffer_formats_img(const gralloc_module_t *module, - const IMG_buffer_format_public_t **v) -{ - return module->perform(module, GRALLOC_MODULE_GET_BUFFER_FORMATS_IMG, v); -} + HAL_DATASPACE_STANDARD_BT2020 = 6 << HAL_DATASPACE_STANDARD_SHIFT, -static inline int -gralloc_module_blit_handle_to_handle_img(const gralloc_module_t *module, - buffer_handle_t src, - buffer_handle_t dest, - int w, int h, int x, int y, - int transform, int input_fence, - int *output_fence) -{ - return module->perform(module, GRALLOC_MODULE_BLIT_HANDLE_TO_HANDLE_IMG, - src, dest, w, h, x, y, transform, input_fence, - output_fence); -} + HAL_DATASPACE_TRANSFER_SMPTE_170M = 3 << HAL_DATASPACE_TRANSFER_SHIFT, + + HAL_DATASPACE_RANGE_MASK = 7 << HAL_DATASPACE_RANGE_SHIFT, + HAL_DATASPACE_RANGE_FULL = 1 << HAL_DATASPACE_RANGE_SHIFT, + HAL_DATASPACE_RANGE_LIMITED = 2 << HAL_DATASPACE_RANGE_SHIFT, +}; -static inline int -gralloc_module_blit_stamp_to_handle(const gralloc_module_t *module, - unsigned long long src_stamp, - int src_width, int src_height, - int src_format, int src_stride_in_pixels, - int src_rotation, buffer_handle_t dest, - int dest_rotation, int input_fence, - int *output_fence) +#endif /* !defined(PVR_ANDROID_HAS_SET_BUFFERS_DATASPACE_2) */ + +/* We want to add BT.2020 and 'full range' versions of the existing dataspace + * enums. These are extensions, so define a new android_dataspace_ext_t. + * If you only have an android_dataspace_t, you can simply cast it. + */ +typedef enum { - return module->perform(module, GRALLOC_MODULE_BLIT_STAMP_TO_HANDLE_IMG, - src_stamp, src_width, src_height, src_format, - src_stride_in_pixels, src_rotation, dest, - dest_rotation, input_fence, output_fence); + /* Identical to upstream enum android_dataspace */ + HAL_DATASPACE_EXT_UNKNOWN = HAL_DATASPACE_UNKNOWN, + HAL_DATASPACE_EXT_SRGB_LINEAR = HAL_DATASPACE_SRGB_LINEAR, + HAL_DATASPACE_EXT_SRGB = HAL_DATASPACE_SRGB, + HAL_DATASPACE_EXT_BT601_625 = HAL_DATASPACE_BT601_625, + HAL_DATASPACE_EXT_BT601_525 = HAL_DATASPACE_BT601_525, + HAL_DATASPACE_EXT_BT709 = HAL_DATASPACE_BT709, + + /* IMG extension for BT.2020 support */ + HAL_DATASPACE_EXT_BT2020 = HAL_DATASPACE_STANDARD_BT2020 | + HAL_DATASPACE_TRANSFER_SMPTE_170M | + HAL_DATASPACE_RANGE_LIMITED, + + /* IMG extensions for 'full range' versions of previous enums */ + HAL_DATASPACE_EXT_BT601_625_FULL = ( HAL_DATASPACE_BT601_625 & + ~HAL_DATASPACE_RANGE_MASK) | + HAL_DATASPACE_RANGE_FULL, + HAL_DATASPACE_EXT_BT601_525_FULL = ( HAL_DATASPACE_BT601_525 & + ~HAL_DATASPACE_RANGE_MASK) | + HAL_DATASPACE_RANGE_FULL, + HAL_DATASPACE_EXT_BT709_FULL = ( HAL_DATASPACE_BT709 & + ~HAL_DATASPACE_RANGE_MASK) | + HAL_DATASPACE_RANGE_FULL, + HAL_DATASPACE_EXT_BT2020_FULL = ( HAL_DATASPACE_EXT_BT2020 & + ~HAL_DATASPACE_RANGE_MASK) | + HAL_DATASPACE_RANGE_FULL, } +android_dataspace_ext_t; -#endif /* HAL_PUBLIC_H */ +#endif /* IMG_GRALLOC_COMMON_PUBLIC_H */ diff --git a/merrifield/ips/tangier/TngDisplayContext.cpp b/merrifield/ips/tangier/TngDisplayContext.cpp index f78f20e..3f4fd5e 100644 --- a/merrifield/ips/tangier/TngDisplayContext.cpp +++ b/merrifield/ips/tangier/TngDisplayContext.cpp @@ -43,15 +43,15 @@ bool TngDisplayContext::initialize() CTRACE(); // open frame buffer device - gralloc_module_t const* module; - int err = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, (hw_module_t const**)&module); + const hw_device_t *gralloc; + int err = gralloc_open_img(&gralloc); if (err) { ETRACE("failed to load gralloc module, error = %d", err); return false; } // init IMG display device - err = module->perform(module, GRALLOC_MODULE_GET_DISPLAY_DEVICE_IMG, (void **)&mIMGDisplayDevice); + err = gralloc_get_display_device_img(gralloc, (void **)&mIMGDisplayDevice); if (err) { ETRACE("failed to get display device, error = %d", err); return false; diff --git a/merrifield/ips/tangier/TngGrallocBufferMapper.cpp b/merrifield/ips/tangier/TngGrallocBufferMapper.cpp index bee4f5e..4f7eb75 100644 --- a/merrifield/ips/tangier/TngGrallocBufferMapper.cpp +++ b/merrifield/ips/tangier/TngGrallocBufferMapper.cpp @@ -22,10 +22,10 @@ namespace android { namespace intel { -TngGrallocBufferMapper::TngGrallocBufferMapper(gralloc_module_t const& module, - DataBuffer& buffer) +TngGrallocBufferMapper::TngGrallocBufferMapper(const hw_device_t& gralloc, + DataBuffer& buffer) : GrallocBufferMapperBase(buffer), - mGrallocModule(module), + mGralloc(gralloc), mBufferObject(0) { CTRACE(); @@ -122,8 +122,7 @@ bool TngGrallocBufferMapper::map() CTRACE(); // get virtual address - err = mGrallocModule.perform(&mGrallocModule, - GRALLOC_MODULE_GET_BUFFER_CPU_ADDRESSES_IMG, + err = gralloc_get_buffer_cpu_addresses_img(&mGralloc, (buffer_handle_t)mClonedHandle, vaddr, size); @@ -162,8 +161,7 @@ bool TngGrallocBufferMapper::map() } } - err = mGrallocModule.perform(&mGrallocModule, - GRALLOC_MODULE_PUT_BUFFER_CPU_ADDRESSES_IMG, + err = gralloc_put_buffer_cpu_addresses_img(&mGralloc, (buffer_handle_t)mClonedHandle); return false; } @@ -184,8 +182,7 @@ bool TngGrallocBufferMapper::unmap() mSize[i] = 0; } - err = mGrallocModule.perform(&mGrallocModule, - GRALLOC_MODULE_PUT_BUFFER_CPU_ADDRESSES_IMG, + err = gralloc_put_buffer_cpu_addresses_img(&mGralloc, (buffer_handle_t)mClonedHandle); if (err) { ETRACE("failed to unmap. err = %d", err); @@ -239,8 +236,7 @@ buffer_handle_t TngGrallocBufferMapper::getFbHandle(int subIndex) } // get virtual address - err = mGrallocModule.perform(&mGrallocModule, - GRALLOC_MODULE_GET_BUFFER_CPU_ADDRESSES_IMG, + err = gralloc_get_buffer_cpu_addresses_img(&mGralloc, (buffer_handle_t)mClonedHandle, vaddr, size); @@ -254,8 +250,7 @@ buffer_handle_t TngGrallocBufferMapper::getFbHandle(int subIndex) void TngGrallocBufferMapper::putFbHandle() { - int err = mGrallocModule.perform(&mGrallocModule, - GRALLOC_MODULE_PUT_BUFFER_CPU_ADDRESSES_IMG, + int err = gralloc_put_buffer_cpu_addresses_img(&mGralloc, (buffer_handle_t)mClonedHandle); if (err) { ETRACE("failed to unmap. err = %d", err); diff --git a/merrifield/ips/tangier/TngGrallocBufferMapper.h b/merrifield/ips/tangier/TngGrallocBufferMapper.h index 17f34c2..1b27ae1 100644 --- a/merrifield/ips/tangier/TngGrallocBufferMapper.h +++ b/merrifield/ips/tangier/TngGrallocBufferMapper.h @@ -26,8 +26,7 @@ namespace intel { class TngGrallocBufferMapper : public GrallocBufferMapperBase { public: - TngGrallocBufferMapper(gralloc_module_t const& module, - DataBuffer& buffer); + TngGrallocBufferMapper(const hw_device_t& gralloc, DataBuffer& buffer); virtual ~TngGrallocBufferMapper(); public: bool map(); @@ -41,7 +40,7 @@ private: bool mapKhandle(); private: - gralloc_module_t const& mGrallocModule; + const hw_device_t& mGralloc; void* mBufferObject; native_handle_t* mClonedHandle; }; diff --git a/merrifield/platforms/merrifield/Android.mk b/merrifield/platforms/merrifield/Android.mk index 81086b7..9efd7fd 100644 --- a/merrifield/platforms/merrifield/Android.mk +++ b/merrifield/platforms/merrifield/Android.mk @@ -131,8 +131,10 @@ ifeq ($(TARGET_HAS_MULTIPLE_DISPLAY),true) endif LOCAL_COPY_HEADERS := \ - ../../include/pvr/hal/hal_public.h \ - ../../include/pvr/hal/img_gralloc_public.h + ../../include/pvr/hal/img_gralloc.h \ + ../../include/pvr/hal/img_gralloc1.h \ + ../../include/pvr/hal/img_gralloc_common_public.h \ + ../../include/pvr/hal/hal_public.h LOCAL_COPY_HEADERS_TO := pvr/hal ifneq ($(TARGET_BUILD_VARIANT),user) diff --git a/merrifield/platforms/merrifield/PlatfBufferManager.cpp b/merrifield/platforms/merrifield/PlatfBufferManager.cpp index 881f79d..fb9ddcd 100644 --- a/merrifield/platforms/merrifield/PlatfBufferManager.cpp +++ b/merrifield/platforms/merrifield/PlatfBufferManager.cpp @@ -50,7 +50,7 @@ DataBuffer* PlatfBufferManager::createDataBuffer(buffer_handle_t handle) BufferMapper* PlatfBufferManager::createBufferMapper(DataBuffer& buffer) { - return new TngGrallocBufferMapper(*mGrallocModule, buffer); + return new TngGrallocBufferMapper(*mGralloc, buffer); } bool PlatfBufferManager::blit(buffer_handle_t srcHandle, buffer_handle_t destHandle, @@ -59,8 +59,7 @@ bool PlatfBufferManager::blit(buffer_handle_t srcHandle, buffer_handle_t destHan { int fenceFd; - if (mGrallocModule->perform(mGrallocModule, - GRALLOC_MODULE_BLIT_HANDLE_TO_HANDLE_IMG, + if (gralloc_blit_handle_to_handle_img(mGralloc, srcHandle, destHandle, destRect.w, destRect.h, destRect.x, diff --git a/merrifield/platforms/merrifield_plus/Android.mk b/merrifield/platforms/merrifield_plus/Android.mk index 3f8b886..dae5335 100644 --- a/merrifield/platforms/merrifield_plus/Android.mk +++ b/merrifield/platforms/merrifield_plus/Android.mk @@ -130,8 +130,10 @@ ifeq ($(TARGET_HAS_MULTIPLE_DISPLAY),true) endif LOCAL_COPY_HEADERS := \ - ../../include/pvr/hal/hal_public.h \ - ../../include/pvr/hal/img_gralloc_public.h + ../../include/pvr/hal/img_gralloc.h \ + ../../include/pvr/hal/img_gralloc1.h \ + ../../include/pvr/hal/img_gralloc_common_public.h \ + ../../include/pvr/hal/hal_public.h LOCAL_COPY_HEADERS_TO := pvr/hal ifneq ($(TARGET_BUILD_VARIANT),user) diff --git a/merrifield/platforms/merrifield_plus/PlatfBufferManager.cpp b/merrifield/platforms/merrifield_plus/PlatfBufferManager.cpp index 881f79d..fb9ddcd 100644 --- a/merrifield/platforms/merrifield_plus/PlatfBufferManager.cpp +++ b/merrifield/platforms/merrifield_plus/PlatfBufferManager.cpp @@ -50,7 +50,7 @@ DataBuffer* PlatfBufferManager::createDataBuffer(buffer_handle_t handle) BufferMapper* PlatfBufferManager::createBufferMapper(DataBuffer& buffer) { - return new TngGrallocBufferMapper(*mGrallocModule, buffer); + return new TngGrallocBufferMapper(*mGralloc, buffer); } bool PlatfBufferManager::blit(buffer_handle_t srcHandle, buffer_handle_t destHandle, @@ -59,8 +59,7 @@ bool PlatfBufferManager::blit(buffer_handle_t srcHandle, buffer_handle_t destHan { int fenceFd; - if (mGrallocModule->perform(mGrallocModule, - GRALLOC_MODULE_BLIT_HANDLE_TO_HANDLE_IMG, + if (gralloc_blit_handle_to_handle_img(mGralloc, srcHandle, destHandle, destRect.w, destRect.h, destRect.x, diff --git a/moorefield_hdmi/Android.mk b/moorefield_hdmi/Android.mk index fe6caa1..8903585 100644 --- a/moorefield_hdmi/Android.mk +++ b/moorefield_hdmi/Android.mk @@ -101,8 +101,10 @@ ifeq ($(TARGET_SUPPORT_HDMI_PRIMARY),true) endif LOCAL_COPY_HEADERS := \ - include/pvr/hal/hal_public.h \ - include/pvr/hal/img_gralloc_public.h + include/pvr/hal/img_gralloc.h \ + include/pvr/hal/img_gralloc1.h \ + include/pvr/hal/img_gralloc_common_public.h \ + include/pvr/hal/hal_public.h LOCAL_COPY_HEADERS_TO := pvr/hal include $(BUILD_SHARED_LIBRARY) diff --git a/moorefield_hdmi/common/buffers/BufferManager.cpp b/moorefield_hdmi/common/buffers/BufferManager.cpp index a426c5a..3ebda04 100644 --- a/moorefield_hdmi/common/buffers/BufferManager.cpp +++ b/moorefield_hdmi/common/buffers/BufferManager.cpp @@ -17,14 +17,14 @@ #include <common/utils/HwcTrace.h> #include <hardware/hwcomposer.h> #include <BufferManager.h> +#include <hal_public.h> #include <DrmConfig.h> namespace android { namespace intel { BufferManager::BufferManager() - : mGrallocModule(NULL), - mAllocDev(NULL), + : mGralloc(NULL), mFrameBuffers(), mBufferPool(NULL), mDataBuffer(NULL), @@ -56,16 +56,9 @@ bool BufferManager::initialize() } // init gralloc module - hw_module_t const* module; - if (hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module)) { + if (gralloc_open_img(&mGralloc)) { DEINIT_AND_RETURN_FALSE("failed to get gralloc module"); } - mGrallocModule = (gralloc_module_t const*)module; - - gralloc_open(module, &mAllocDev); - if (!mAllocDev) { - WLOGTRACE("failed to open alloc device"); - } // create a dummy data buffer mDataBuffer = createDataBuffer(0); @@ -100,9 +93,9 @@ void BufferManager::deinitialize() } mFrameBuffers.clear(); - if (mAllocDev) { - gralloc_close(mAllocDev); - mAllocDev = NULL; + if (mGralloc) { + gralloc_close_img(mGralloc); + mGralloc = NULL; } if (mDataBuffer) { @@ -222,7 +215,7 @@ uint32_t BufferManager::allocFrameBuffer(int width, int height, int *stride) { RETURN_NULL_IF_NOT_INIT(); - if (!mAllocDev) { + if (!mGralloc) { WLOGTRACE("Alloc device is not available"); return 0; } @@ -234,8 +227,8 @@ uint32_t BufferManager::allocFrameBuffer(int width, int height, int *stride) ILOGTRACE("size of frame buffer to create: %dx%d", width, height); uint32_t handle = 0; - status_t err = mAllocDev->alloc( - mAllocDev, + status_t err = gralloc_device_alloc_img( + mGralloc, width, height, DrmConfig::getFrameBufferFormat(), @@ -282,7 +275,7 @@ uint32_t BufferManager::allocFrameBuffer(int width, int height, int *stride) if (mapper) { delete mapper; } - mAllocDev->free(mAllocDev, (buffer_handle_t)handle); + gralloc_device_free_img(mGralloc, (buffer_handle_t)handle); return 0; } @@ -290,7 +283,7 @@ void BufferManager::freeFrameBuffer(uint32_t fbHandle) { RETURN_VOID_IF_NOT_INIT(); - if (!mAllocDev) { + if (!mGralloc) { WLOGTRACE("Alloc device is not available"); return; } @@ -306,14 +299,14 @@ void BufferManager::freeFrameBuffer(uint32_t fbHandle) mapper->putFbHandle(); delete mapper; mFrameBuffers.removeItem(fbHandle); - mAllocDev->free(mAllocDev, (buffer_handle_t)handle); + gralloc_device_free_img(mGralloc, (buffer_handle_t)handle); } uint32_t BufferManager::allocGrallocBuffer(uint32_t width, uint32_t height, uint32_t format, uint32_t usage) { RETURN_NULL_IF_NOT_INIT(); - if (!mAllocDev) { + if (!mGralloc) { WLOGTRACE("Alloc device is not available"); return 0; } @@ -326,8 +319,8 @@ uint32_t BufferManager::allocGrallocBuffer(uint32_t width, uint32_t height, uint ILOGTRACE("size of graphic buffer to create: %dx%d", width, height); uint32_t handle = 0; int stride; - status_t err = mAllocDev->alloc( - mAllocDev, + status_t err = gralloc_device_alloc_img( + mGralloc, width, height, format, @@ -345,13 +338,13 @@ uint32_t BufferManager::allocGrallocBuffer(uint32_t width, uint32_t height, uint void BufferManager::freeGrallocBuffer(uint32_t handle) { RETURN_VOID_IF_NOT_INIT(); - if (!mAllocDev) { + if (!mGralloc) { WLOGTRACE("Alloc device is not available"); return; } if (handle) - mAllocDev->free(mAllocDev, (buffer_handle_t)handle); + gralloc_device_free_img(mGralloc, (buffer_handle_t)handle); } } // namespace intel diff --git a/moorefield_hdmi/include/BufferManager.h b/moorefield_hdmi/include/BufferManager.h index 0897310..e3ad7ae 100755 --- a/moorefield_hdmi/include/BufferManager.h +++ b/moorefield_hdmi/include/BufferManager.h @@ -65,7 +65,7 @@ protected: virtual DataBuffer* createDataBuffer(uint32_t handle) = 0; virtual BufferMapper* createBufferMapper(DataBuffer& buffer) = 0; - gralloc_module_t const* mGrallocModule; + const hw_device_t *mGralloc; private: enum { // make the buffer pool large enough diff --git a/moorefield_hdmi/include/pvr/hal/hal_public.h b/moorefield_hdmi/include/pvr/hal/hal_public.h index 04939a0..19910c1 100644 --- a/moorefield_hdmi/include/pvr/hal/hal_public.h +++ b/moorefield_hdmi/include/pvr/hal/hal_public.h @@ -21,29 +21,195 @@ * THE SOFTWARE. */ -#ifndef __HAL_PUBLIC_H -#define __HAL_PUBLIC_H +#ifndef HAL_PUBLIC_H +#define HAL_PUBLIC_H -#define PVR_ANDROID_NATIVE_WINDOW_HAS_SYNC +#define PVR_ANDROID_HAS_SET_BUFFERS_DATASPACE +#define PVR_ANDROID_HAS_SET_BUFFERS_DATASPACE_2 -#include "img_gralloc_public.h" +#include "img_gralloc_common_public.h" -#undef HAL_PIXEL_FORMAT_NV12 +/* Extension pixel formats used by Intel components */ -#define HAL_PIXEL_FORMAT_UYVY 0x107 -#define HAL_PIXEL_FORMAT_INTEL_YV12 0x108 -#define HAL_PIXEL_FORMAT_INTEL_ZSL 0x109 -#define HAL_PIXEL_FORMAT_NV12 0x3231564E -#define HAL_PIXEL_FORMAT_NV21 0x3132564E -#define HAL_PIXEL_FORMAT_I420 0x30323449 -#define HAL_PIXEL_FORMAT_YUY2 0x32595559 -#define HAL_PIXEL_FORMAT_NV12_VED 0x7FA00E00 -#define HAL_PIXEL_FORMAT_NV12_VEDT 0x7FA00F00 +#undef HAL_PIXEL_FORMAT_NV12 -#define GRALLOC_MODULE_GET_BUFFER_CPU_ADDRESSES_IMG 108 -#define GRALLOC_MODULE_PUT_BUFFER_CPU_ADDRESSES_IMG 109 +#define HAL_PIXEL_FORMAT_UYVY 0x107 +#define HAL_PIXEL_FORMAT_INTEL_YV12 0x108 +#define HAL_PIXEL_FORMAT_INTEL_ZSL 0x109 +#define HAL_PIXEL_FORMAT_NV12 0x3231564E +#define HAL_PIXEL_FORMAT_NV21 0x3132564E +#define HAL_PIXEL_FORMAT_I420 0x30323449 +#define HAL_PIXEL_FORMAT_YUY2 0x32595559 +#define HAL_PIXEL_FORMAT_NV12_VED 0x7FA00E00 +#define HAL_PIXEL_FORMAT_NV12_VEDT 0x7FA00F00 -#define GRALLOC_MODULE_GET_DISPLAY_DEVICE_IMG 1000 -#define GRALLOC_MODULE_GET_DISPLAY_STATUS_IMG 1001 +/* Extension API used by Intel components */ -#endif /* __HAL_PUBLIC_H */ +#define GRALLOC_GET_BUFFER_CPU_ADDRESSES_IMG 108 +#define GRALLOC_PUT_BUFFER_CPU_ADDRESSES_IMG 109 + +#define GRALLOC_GET_DISPLAY_DEVICE_IMG 1000 +#define GRALLOC_GET_DISPLAY_STATUS_IMG 1001 + +#include "img_gralloc.h" +#include "img_gralloc1.h" + +typedef const gralloc_module_t gralloc0_t; +typedef gralloc1_device_t gralloc1_t; + +static inline int gralloc_is_v1_img(const hw_module_t *m) +{ + return ((m->module_api_version >> 8) & 0xff) == 1; +} + +static inline int gralloc_open_img(const hw_device_t **d) +{ + const hw_module_t *m; + int err; + + err = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &m); + if (err) + return err; + + if (gralloc_is_v1_img(m)) + return gralloc1_open(m, (gralloc1_t **)d); + else + return gralloc_open(m, (alloc_device_t **)d); +} + +static inline int gralloc_close_img(const hw_device_t *d) +{ + if (gralloc_is_v1_img(d->module)) + return gralloc1_close((gralloc1_t *)d); + else + return gralloc_close((alloc_device_t *)d); +} + +static inline int gralloc_register_img + (const hw_device_t *d, buffer_handle_t handle) +{ + if (gralloc_is_v1_img(d->module)) + return gralloc1_register_img((gralloc1_t *)d, handle); + else + return gralloc0_register_img((gralloc0_t *)d->module, handle); +} + +static inline int gralloc_unregister_img + (const hw_device_t *d, buffer_handle_t handle) +{ + if (gralloc_is_v1_img(d->module)) + return gralloc1_unregister_img((gralloc1_t *)d, handle); + else + return gralloc0_unregister_img((gralloc0_t *)d->module, handle); +} + +static inline int gralloc_device_alloc_img + (const hw_device_t *d, int w, int h, int format, int usage, + buffer_handle_t *handle, int *stride) +{ + if (gralloc_is_v1_img(d->module)) { + usage = (usage | ((usage & 0x33) << 1)) & ~0x11; + return gralloc1_device_alloc_img((gralloc1_t *)d, w, h, format, + usage, handle, stride); + } else + return gralloc0_device_alloc_img((alloc_device_t *)d, w, h, format, + usage, handle, stride); +} + +static inline int gralloc_device_free_img + (const hw_device_t *d, buffer_handle_t handle) +{ + if (gralloc_is_v1_img(d->module)) + return gralloc1_device_free_img((gralloc1_t *)d, handle); + else + return gralloc0_device_free_img((alloc_device_t *)d, handle); +} + +static inline int gralloc_lock_async_img + (const hw_device_t *d, buffer_handle_t handle, int usage, + const gralloc1_rect_t *r, void **vaddr, int acquireFence) +{ + if (gralloc_is_v1_img(d->module)) { + usage = (usage | ((usage & 0x33) << 1)) & ~0x11; + return gralloc1_lock_async_img((gralloc1_t *)d, + handle, usage, r, vaddr, acquireFence); + } else + return gralloc0_lock_async_img((gralloc0_t *)d->module, + handle, usage, r, vaddr, acquireFence); +} + +static inline int gralloc_unlock_async_img + (const hw_device_t *d, buffer_handle_t handle, int *releaseFence) +{ + if (gralloc_is_v1_img(d->module)) + return gralloc1_unlock_async_img((gralloc1_t *)d, + handle, releaseFence); + else + return gralloc0_unlock_async_img((gralloc0_t *)d->module, + handle, releaseFence); +} + +static inline int gralloc_blit_handle_to_handle_img + (const hw_device_t *d, buffer_handle_t src, buffer_handle_t dest, + int w, int h, int x, int y, int transform, int input_fence, + int *output_fence) +{ + if (gralloc_is_v1_img(d->module)) + return gralloc1_blit_handle_to_handle_img((gralloc1_t *)d, + src, dest, w, h, x, y, + transform, input_fence, + output_fence); + else + return gralloc0_blit_handle_to_handle_img((gralloc0_t *)d->module, + src, dest, w, h, x, y, + transform, input_fence, + output_fence); +} + + +static inline int gralloc_get_buffer_cpu_addresses_img + (const hw_device_t *d, buffer_handle_t handle, void **vaddrs, + size_t *sizes) +{ + if (gralloc_is_v1_img(d->module)) + return gralloc1_get_buffer_cpu_addresses_img((gralloc1_t *)d, + handle, vaddrs, sizes); + else + return gralloc0_get_buffer_cpu_addresses_img((gralloc0_t *)d->module, + handle, vaddrs, sizes); +} + +static inline int gralloc_put_buffer_cpu_addresses_img + (const hw_device_t *d, buffer_handle_t handle) +{ + if (gralloc_is_v1_img(d->module)) + return gralloc1_put_buffer_cpu_addresses_img((gralloc1_t *)d, + handle); + else + return gralloc0_put_buffer_cpu_addresses_img((gralloc0_t *)d->module, + handle); +} + +static inline int gralloc_get_display_device_img + (const hw_device_t *d, void **ppvDispDev) +{ + if (gralloc_is_v1_img(d->module)) + return gralloc1_get_display_device_img((gralloc1_t *)d, + ppvDispDev); + else + return gralloc0_get_display_device_img((gralloc0_t *)d->module, + ppvDispDev); +} + +static inline int gralloc_get_display_status_img + (const hw_device_t *d, buffer_handle_t handle, uint32_t *pui32Status) +{ + if (gralloc_is_v1_img(d->module)) + return gralloc1_get_display_status_img((gralloc1_t *)d, + handle, pui32Status); + else + return gralloc0_get_display_status_img((gralloc0_t *)d->module, + handle, pui32Status); +} + +#endif /* HAL_PUBLIC_H */ diff --git a/moorefield_hdmi/include/pvr/hal/img_gralloc.h b/moorefield_hdmi/include/pvr/hal/img_gralloc.h new file mode 100644 index 0000000..d9560fa --- /dev/null +++ b/moorefield_hdmi/include/pvr/hal/img_gralloc.h @@ -0,0 +1,107 @@ +/* Copyright (c) Imagination Technologies Ltd. + * + * The contents of this file are subject to the MIT license as set out below. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef IMG_GRALLOC_H +#define IMG_GRALLOC_H + +#include <hardware/gralloc.h> + +/* for gralloc1_rect_t */ +#include <hardware/gralloc1.h> + +static inline int gralloc0_register_img + (const gralloc_module_t *g, buffer_handle_t handle) +{ + return g->registerBuffer(g, handle); +} + +static inline int gralloc0_unregister_img + (const gralloc_module_t *g, buffer_handle_t handle) +{ + return g->unregisterBuffer(g, handle); +} + +static inline int gralloc0_device_alloc_img + (alloc_device_t *d, int w, int h, int format, int usage, + buffer_handle_t *handle, int *stride) +{ + return d->alloc(d, w, h, format, usage, handle, stride); +} + +static inline int gralloc0_device_free_img + (alloc_device_t *d, buffer_handle_t handle) +{ + return d->free(d, handle); +} + +static inline int gralloc0_lock_async_img + (const gralloc_module_t *g, buffer_handle_t handle, int usage, + const gralloc1_rect_t *r, void **vaddr, int acquireFence) +{ + return g->lockAsync(g, handle, usage, + r->left, r->top, r->width, r->height, + vaddr, acquireFence); +} + +static inline int gralloc0_unlock_async_img + (const gralloc_module_t *g, buffer_handle_t handle, int *releaseFence) +{ + return g->unlockAsync(g, handle, releaseFence); +} + +static inline int gralloc0_blit_handle_to_handle_img + (const gralloc_module_t *g, buffer_handle_t src, buffer_handle_t dest, + int w, int h, int x, int y, int transform, int input_fence, + int *output_fence) +{ + return g->perform(g, GRALLOC_BLIT_HANDLE_TO_HANDLE_IMG, src, dest, w, h, + x, y, transform, input_fence, output_fence); +} + +static inline int gralloc0_get_buffer_cpu_addresses_img + (const gralloc_module_t *g, buffer_handle_t handle, void **vaddrs, + size_t *sizes) +{ + return g->perform(g, GRALLOC_GET_BUFFER_CPU_ADDRESSES_IMG, handle, vaddrs, + sizes); +} + +static inline int gralloc0_put_buffer_cpu_addresses_img + (const gralloc_module_t *g, buffer_handle_t handle) +{ + return g->perform(g, GRALLOC_PUT_BUFFER_CPU_ADDRESSES_IMG, handle); +} + +static inline int gralloc0_get_display_device_img + (const gralloc_module_t *g, void **ppvDispDev) +{ + return g->perform(g, GRALLOC_GET_DISPLAY_DEVICE_IMG, ppvDispDev); +} + +static inline int gralloc0_get_display_status_img + (const gralloc_module_t *g, buffer_handle_t handle, uint32_t *pui32Status) +{ + return g->perform(g, GRALLOC_GET_DISPLAY_STATUS_IMG, handle, pui32Status); +} + +#endif /* IMG_GRALLOC_H */ diff --git a/moorefield_hdmi/include/pvr/hal/img_gralloc1.h b/moorefield_hdmi/include/pvr/hal/img_gralloc1.h new file mode 100644 index 0000000..f9f69a2 --- /dev/null +++ b/moorefield_hdmi/include/pvr/hal/img_gralloc1.h @@ -0,0 +1,303 @@ +/* Copyright (c) Imagination Technologies Ltd. + * + * The contents of this file are subject to the MIT license as set out below. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef IMG_GRALLOC1_H +#define IMG_GRALLOC1_H + +#include <hardware/gralloc1.h> + +#include <stdlib.h> + +#define GRALLOC1_FUNCTION_IMG_EXT_OFF 1000 + +enum +{ + GRALLOC1_FUNCTION_BLIT_HANDLE_TO_HANDLE_IMG = + (GRALLOC1_FUNCTION_IMG_EXT_OFF + GRALLOC_BLIT_HANDLE_TO_HANDLE_IMG), + GRALLOC1_FUNCTION_GET_BUFFER_CPU_ADDRESSES_IMG = + (GRALLOC1_FUNCTION_IMG_EXT_OFF + GRALLOC_GET_BUFFER_CPU_ADDRESSES_IMG), + GRALLOC1_FUNCTION_PUT_BUFFER_CPU_ADDRESSES_IMG = + (GRALLOC1_FUNCTION_IMG_EXT_OFF + GRALLOC_PUT_BUFFER_CPU_ADDRESSES_IMG), + GRALLOC1_FUNCTION_GET_DISPLAY_DEVICE_IMG = + (GRALLOC1_FUNCTION_IMG_EXT_OFF + GRALLOC_GET_DISPLAY_DEVICE_IMG), + GRALLOC1_FUNCTION_GET_DISPLAY_STATUS_IMG = + (GRALLOC1_FUNCTION_IMG_EXT_OFF + GRALLOC_GET_DISPLAY_STATUS_IMG), +}; + +static inline int gralloc1_register_img + (gralloc1_device_t *g, buffer_handle_t handle) +{ + GRALLOC1_PFN_RETAIN f = + (GRALLOC1_PFN_RETAIN) + g->getFunction(g, GRALLOC1_FUNCTION_RETAIN); + int32_t err; + + err = f(g, handle); + switch (err) + { + case GRALLOC1_ERROR_NO_RESOURCES: + return -EAGAIN; + case GRALLOC1_ERROR_NONE: + return 0; + default: + return -EINVAL; + } +} + +static inline int gralloc1_unregister_img + (gralloc1_device_t *g, buffer_handle_t handle) +{ + GRALLOC1_PFN_RELEASE f = + (GRALLOC1_PFN_RELEASE) + g->getFunction(g, GRALLOC1_FUNCTION_RELEASE); + int32_t err; + + err = f(g, handle); + switch (err) + { + case GRALLOC1_ERROR_NONE: + return 0; + default: + return -EINVAL; + } +} + +static inline int gralloc1_device_alloc_img + (gralloc1_device_t *d, int w, int h, int format, int usage, + buffer_handle_t *handle, int *stride) +{ + GRALLOC1_PFN_ALLOCATE allocate = + (GRALLOC1_PFN_ALLOCATE) + d->getFunction(d, GRALLOC1_FUNCTION_ALLOCATE); + GRALLOC1_PFN_CREATE_DESCRIPTOR createDescriptor = + (GRALLOC1_PFN_CREATE_DESCRIPTOR) + d->getFunction(d, GRALLOC1_FUNCTION_CREATE_DESCRIPTOR); + GRALLOC1_PFN_DESTROY_DESCRIPTOR destroyDescriptor = + (GRALLOC1_PFN_DESTROY_DESCRIPTOR) + d->getFunction(d, GRALLOC1_FUNCTION_DESTROY_DESCRIPTOR); + GRALLOC1_PFN_SET_CONSUMER_USAGE setConsumerUsage = + (GRALLOC1_PFN_SET_CONSUMER_USAGE) + d->getFunction(d, GRALLOC1_FUNCTION_SET_CONSUMER_USAGE); + GRALLOC1_PFN_SET_DIMENSIONS setDimensions = + (GRALLOC1_PFN_SET_DIMENSIONS) + d->getFunction(d, GRALLOC1_FUNCTION_SET_DIMENSIONS); + GRALLOC1_PFN_SET_FORMAT setFormat = + (GRALLOC1_PFN_SET_FORMAT) + d->getFunction(d, GRALLOC1_FUNCTION_SET_FORMAT); + GRALLOC1_PFN_SET_PRODUCER_USAGE setProducerUsage = + (GRALLOC1_PFN_SET_PRODUCER_USAGE) + d->getFunction(d, GRALLOC1_FUNCTION_SET_PRODUCER_USAGE); + GRALLOC1_PFN_GET_STRIDE getStride = + (GRALLOC1_PFN_GET_STRIDE) + d->getFunction(d, GRALLOC1_FUNCTION_GET_STRIDE); + uint64_t producerUsage = + (usage & (GRALLOC1_PRODUCER_USAGE_CPU_READ_OFTEN | + GRALLOC1_PRODUCER_USAGE_CPU_WRITE_OFTEN | + GRALLOC1_PRODUCER_USAGE_GPU_RENDER_TARGET | + GRALLOC1_PRODUCER_USAGE_PROTECTED | + GRALLOC1_PRODUCER_USAGE_CAMERA | + GRALLOC1_PRODUCER_USAGE_VIDEO_DECODER)); + uint64_t consumerUsage = + (usage & (GRALLOC1_CONSUMER_USAGE_CPU_READ_OFTEN | + GRALLOC1_CONSUMER_USAGE_GPU_TEXTURE | + GRALLOC1_CONSUMER_USAGE_HWCOMPOSER | + GRALLOC1_CONSUMER_USAGE_CLIENT_TARGET | + GRALLOC1_CONSUMER_USAGE_CURSOR | + GRALLOC1_CONSUMER_USAGE_VIDEO_ENCODER | + GRALLOC1_CONSUMER_USAGE_CAMERA | + GRALLOC1_CONSUMER_USAGE_RENDERSCRIPT)); + gralloc1_buffer_descriptor_t descriptor; + uint32_t stride32; + int err = -EINVAL; + int32_t err32; + + err32 = createDescriptor(d, &descriptor); + if (err32 != GRALLOC1_ERROR_NONE) + goto err_out; + + err32 = setDimensions(d, descriptor, w, h); + if (err32 != GRALLOC1_ERROR_NONE) + goto err_destroy_descriptor; + + err32 = setFormat(d, descriptor, format); + if (err32 != GRALLOC1_ERROR_NONE) + goto err_destroy_descriptor; + + err32 = setConsumerUsage(d, descriptor, consumerUsage); + if (err32 != GRALLOC1_ERROR_NONE) + goto err_destroy_descriptor; + + err32 = setProducerUsage(d, descriptor, producerUsage); + if (err32 != GRALLOC1_ERROR_NONE) + goto err_destroy_descriptor; + + err32 = allocate(d, 1, &descriptor, handle); + switch (err32) + { + case GRALLOC1_ERROR_NOT_SHARED: + case GRALLOC1_ERROR_NONE: + break; + case GRALLOC1_ERROR_NO_RESOURCES: + err = -EAGAIN; + default: + goto err_destroy_descriptor; + } + + err32 = getStride(d, *handle, &stride32); + if (err32 != GRALLOC1_ERROR_NONE) + { + gralloc1_unregister_img(d, *handle); + goto err_destroy_descriptor; + } + + *stride = (int)stride32; + err = 0; +err_destroy_descriptor: + destroyDescriptor(d, descriptor); +err_out: + return err; +} + +static inline int gralloc1_device_free_img + (gralloc1_device_t *d, buffer_handle_t handle) +{ + return gralloc1_unregister_img(d, handle); +} + +static inline int gralloc1_lock_async_img + (gralloc1_device_t *g, buffer_handle_t handle, int usage, + const gralloc1_rect_t *r, void **vaddr, int acquireFence) +{ + GRALLOC1_PFN_LOCK f = + (GRALLOC1_PFN_LOCK) + g->getFunction(g, GRALLOC1_FUNCTION_LOCK); + uint64_t producerUsage = + (usage & (GRALLOC1_PRODUCER_USAGE_CPU_READ_OFTEN | + GRALLOC1_PRODUCER_USAGE_CPU_WRITE_OFTEN)); + uint64_t consumerUsage = + (usage & GRALLOC1_CONSUMER_USAGE_CPU_READ_OFTEN); + int32_t err; + + err = f(g, handle, producerUsage, consumerUsage, r, vaddr, acquireFence); + switch (err) + { + case GRALLOC1_ERROR_NONE: + return 0; + case GRALLOC1_ERROR_NO_RESOURCES: + return -EAGAIN; + default: + return -EINVAL; + } +} + +static inline int gralloc1_unlock_async_img + (gralloc1_device_t *g, buffer_handle_t handle, int *releaseFence) +{ + GRALLOC1_PFN_UNLOCK f = + (GRALLOC1_PFN_UNLOCK) + g->getFunction(g, GRALLOC1_FUNCTION_UNLOCK); + int32_t err, releaseFence32; + + err = f(g, handle, &releaseFence32); + switch (err) + { + case GRALLOC1_ERROR_NONE: + *releaseFence = releaseFence32; + return 0; + default: + return -EINVAL; + } +} + +typedef int (*GRALLOC1_PFN_BLIT_HANDLE_TO_HANDLE_IMG) + (gralloc1_device_t *g, buffer_handle_t src, buffer_handle_t dest, + int w, int h, int x, int y, int transform, int input_fence, + int *output_fence); + +static inline int gralloc1_blit_handle_to_handle_img + (gralloc1_device_t *g, buffer_handle_t src, buffer_handle_t dest, + int w, int h, int x, int y, int transform, int input_fence, + int *output_fence) +{ + GRALLOC1_PFN_BLIT_HANDLE_TO_HANDLE_IMG f = + (GRALLOC1_PFN_BLIT_HANDLE_TO_HANDLE_IMG) + g->getFunction(g, GRALLOC1_FUNCTION_BLIT_HANDLE_TO_HANDLE_IMG); + + return f(g, src, dest, w, h, x, y, transform, input_fence, output_fence); +} + +typedef int (*GRALLOC1_PFN_GET_BUFFER_CPU_ADDRESSES_IMG) + (gralloc1_device_t *g, buffer_handle_t handle, void **vaddrs, + size_t *sizes); + +static inline int gralloc1_get_buffer_cpu_addresses_img + (gralloc1_device_t *g, buffer_handle_t handle, void **vaddrs, + size_t *sizes) +{ + GRALLOC1_PFN_GET_BUFFER_CPU_ADDRESSES_IMG f = + (GRALLOC1_PFN_GET_BUFFER_CPU_ADDRESSES_IMG) + g->getFunction(g, GRALLOC1_FUNCTION_GET_BUFFER_CPU_ADDRESSES_IMG); + + return f(g, handle, vaddrs, sizes); +} + +typedef int (*GRALLOC1_PFN_PUT_BUFFER_CPU_ADDRESSES_IMG) + (gralloc1_device_t *g, buffer_handle_t handle); + +static inline int gralloc1_put_buffer_cpu_addresses_img + (gralloc1_device_t *g, buffer_handle_t handle) +{ + GRALLOC1_PFN_PUT_BUFFER_CPU_ADDRESSES_IMG f = + (GRALLOC1_PFN_PUT_BUFFER_CPU_ADDRESSES_IMG) + g->getFunction(g, GRALLOC1_FUNCTION_PUT_BUFFER_CPU_ADDRESSES_IMG); + + return f(g, handle); +} + +typedef int (*GRALLOC1_PFN_GET_DISPLAY_DEVICE_IMG) + (gralloc1_device_t *g, void **ppvDispDev); + +static inline int gralloc1_get_display_device_img + (gralloc1_device_t *g, void **ppvDispDev) +{ + GRALLOC1_PFN_GET_DISPLAY_DEVICE_IMG f = + (GRALLOC1_PFN_GET_DISPLAY_DEVICE_IMG) + g->getFunction(g, GRALLOC1_FUNCTION_GET_DISPLAY_DEVICE_IMG); + + return f(g, ppvDispDev); +} + +typedef int (*GRALLOC1_PFN_GET_DISPLAY_STATUS_IMG) + (gralloc1_device_t *g, buffer_handle_t handle, uint32_t *pui32Status); + +static inline int gralloc1_get_display_status_img + (gralloc1_device_t *g, buffer_handle_t handle, uint32_t *pui32Status) +{ + GRALLOC1_PFN_GET_DISPLAY_STATUS_IMG f = + (GRALLOC1_PFN_GET_DISPLAY_STATUS_IMG) + g->getFunction(g, GRALLOC1_FUNCTION_GET_DISPLAY_STATUS_IMG); + + return f(g, handle, pui32Status); +} + +#endif /* IMG_GRALLOC1_H */ diff --git a/moorefield_hdmi/include/pvr/hal/img_gralloc_public.h b/moorefield_hdmi/include/pvr/hal/img_gralloc_common_public.h index 1b6ca50..965e5a7 100644 --- a/moorefield_hdmi/include/pvr/hal/img_gralloc_public.h +++ b/moorefield_hdmi/include/pvr/hal/img_gralloc_common_public.h @@ -21,16 +21,14 @@ * THE SOFTWARE. */ -#ifndef HAL_PUBLIC_H -#define HAL_PUBLIC_H +#ifndef IMG_GRALLOC_COMMON_PUBLIC_H +#define IMG_GRALLOC_COMMON_PUBLIC_H -/* Authors of third party hardware composer (HWC) modules will need to include - * this header to access functionality in the gralloc HAL. - */ - -#include <hardware/gralloc.h> +#include <cutils/native_handle.h> +#include <system/graphics.h> +#include <linux/ion.h> -#define ALIGN(x,a) (((x) + (a) - 1L) & ~((a) - 1L)) +#define ALIGN(x,a) ((((x) + (a) - 1L) / (a)) * (a)) #define HW_ALIGN 32 /* Use bits [0-3] of "vendor format" bits as real format. Customers should @@ -97,22 +95,15 @@ typedef struct /* These fields can be sent cross process. They are also valid * to duplicate within the same process. * - * A table is stored within psPrivateData on gralloc_module_t (this - * is obviously per-process) which maps stamps to a mapped - * PVRSRV_MEMDESC in that process. Each map entry has a lock - * count associated with it, satisfying the requirements of the - * Android API. This also prevents us from leaking maps/allocations. - * - * This table has entries inserted either by alloc() - * (alloc_device_t) or map() (gralloc_module_t). Entries are removed - * by free() (alloc_device_t) and unmap() (gralloc_module_t). + * A table is stored within the gralloc implementation's private data + * structure (which is per-process) which maps stamps to a mapped + * PVRSRV_MEMDESC in that process. Each map entry has a lock count + * associated with it, satisfying the requirements of the gralloc API. + * This also prevents us from leaking maps/allocations. */ #define IMG_NATIVE_HANDLE_NUMFDS (MAX_SUB_ALLOCS) - /* The `fd' field is used to "export" a meminfo to another process. - * Therefore, it is allocated by alloc_device_t, and consumed by - * gralloc_module_t. - */ + /* The `fd' field is used to "export" a meminfo to another process. */ int fd[IMG_NATIVE_HANDLE_NUMFDS]; /* This define should represent the number of packed 'int's required to @@ -126,9 +117,9 @@ typedef struct 6 + MAX_SUB_ALLOCS + MAX_SUB_ALLOCS + \ sizeof(unsigned long long) / sizeof(int) * MAX_SUB_ALLOCS + \ 1) - /* A KERNEL unique identifier for any exported kernel meminfo. Each - * exported kernel meminfo will have a unique stamp, but note that in - * userspace, several meminfos across multiple processes could have + /* A KERNEL unique identifier for any exported kernel memdesc. Each + * exported kernel memdesc will have a unique stamp, but note that in + * userspace, several memdescs across multiple processes could have * the same stamp. As the native_handle can be dup(2)'d, there could be * multiple handles with the same stamp but different file descriptors. */ @@ -180,18 +171,77 @@ typedef struct } __attribute__((aligned(sizeof(int)),packed)) IMG_native_handle_t; -typedef struct -{ - int l, t, w, h; -} -IMG_write_lock_rect_t; +/* Channel encoding of buffer data. + * + * If the buffer has only one plane, the ENCODING bits should be interpreted + * as a definition of the interleaving pattern. Only two of the possible four + * permutations are defined; this is because the YVYU and VYUY patterns are + * not seen in the wild. + * + * If the buffer has more than one plane, the ENCODING bits should be + * interpreted as a definition of the plane order in memory. Assuming a YUV + * format, Y is always first, but U and V may be defined in 'V then U' or + * 'U then V' orders. + * + * Some bits are not used, to maximize compatibility with older DDKs which + * used them in semantically different ways. + */ +#define IMG_BFF_ENCODING_MASK (3 << 0) +/* For uiPlanes == 1 **********************************/ +/* Reserved for VYUY (check IsYUV if used) (0 << 0) */ +#define IMG_BFF_ENCODING_INTERLEAVED_YUYV (1 << 0) +/* Reserved for YVYU (2 << 0) */ +#define IMG_BFF_ENCODING_INTERLEAVED_UYVY (3 << 0) +/* For uiPlanes > 1 ***********************************/ +/* Unused (check IsYUV if used) (0 << 0) */ +#define IMG_BFF_ENCODING_VUCrCb (1 << 0) +/* Unused (2 << 0) */ +#define IMG_BFF_ENCODING_UVCbCr (3 << 0) + +/* Whether the buffer should be cleared to zero from userspace, or via the + * PowerVR services at import time. This is deprecated functionality as most + * platforms use dma-buf or ion now, and for security reasons these allocators + * should never return uncleared memory. + */ +#define IMG_BFF_CPU_CLEAR (1 << 2) + +/* Deprecated, do not use */ +#define IMG_BFF_DONT_GPU_CLEAR (1 << 3) -#define IMG_BFF_YUV (1 << 0) -#define IMG_BFF_UVCbCrORDERING (1 << 1) -#define IMG_BFF_CPU_CLEAR (1 << 2) -#define IMG_BFF_DONT_GPU_CLEAR (1 << 3) -#define IMG_BFF_PARTIAL_ALLOC (1 << 4) -#define IMG_BFF_NEVER_COMPRESS (1 << 5) +/* Deprecated, do not use */ +#define IMG_BFF_PARTIAL_ALLOC (1 << 4) + +/* Guarantee that GPU framebuffer compression is never used for buffers in + * this format, even if the format is supported by the compressor. This might + * be useful if the buffer is being fed to hardware blocks that cannot handle + * the framebuffer compression encoding, and the existing HAL overrides are + * not sufficiently expressive. + */ +#define IMG_BFF_NEVER_COMPRESS (1 << 5) + +/* Indicates that the buffer should be mapped into the GPU 'tiling range' + * heaps, rather than the 'linear' general heap. This implies that the raw + * buffer data is tiled in physical memory. (The GPU BIF will de-tile it, so + * this is distinct from 'tiled texture' support.) The graphics HAL will + * select the correct 'tiling range' based on the buffer dimensions. + */ +#define IMG_BFF_BIFTILED (1 << 6) + +/* YUV subsampling encoding of buffer data. + * Many YUV formats have less chroma information than luma information. If + * this is not the case, use SUBSAMPLING_4_4_4. If each of the U and V channel + * data are 1/4 the size of the Y channel data, use SUBSAMPLING_4_2_0. + * Otherwise, use SUBSAMPLING_4_2_2. + */ +#define IMG_BFF_YUV_SUBSAMPLING_MASK (3 << 7) +#define IMG_BFF_YUV_SUBSAMPLING_4_2_0 (0 << 7) +/* Unused: 4:1:1, 4:2:1, 4:1:0, 3:1:1? (1 << 7) */ +#define IMG_BFF_YUV_SUBSAMPLING_4_2_2 (2 << 7) +#define IMG_BFF_YUV_SUBSAMPLING_4_4_4 (3 << 7) + +/* Backwards compatibility */ +#define IMG_BFF_YUV IMG_BFF_ENCODING_VUCrCb +#define IMG_BFF_UVCbCrORDERING IMG_BFF_ENCODING_UVCbCr /* Keep this in sync with SGX */ typedef struct IMG_buffer_format_public_t @@ -221,82 +271,98 @@ typedef struct IMG_buffer_format_public_t } IMG_buffer_format_public_t; -/* NOTE: This interface is deprecated. Use module->perform() instead. */ -typedef struct IMG_gralloc_module_public_t +typedef struct { - gralloc_module_t base; + enum + { + IMG_BUFFER_HANDLE_TYPE_ION = 0, + IMG_BUFFER_HANDLE_TYPE_DMABUF = 1, + } + eType; + + union + { + ion_user_handle_t aiIonUserHandle[MAX_SUB_ALLOCS]; + int aiDmaBufShareFd[MAX_SUB_ALLOCS]; + }; +} +IMG_buffer_handle_t; - /* Gets the head of the linked list of all registered formats */ - const IMG_buffer_format_public_t *(*GetBufferFormats)(void); +/* Public extensions, common to v0 and v1 HALs */ - /* Custom-blit components in lieu of overlay hardware */ - int (*Blit)(struct IMG_gralloc_module_public_t const *module, - buffer_handle_t src, buffer_handle_t dest, - int w, int h, int x, int y, int transform, - int iInputFenceFd, int *piOutputFenceFd); +#define GRALLOC_GET_BUFFER_FORMAT_IMG 1 +#define GRALLOC_GET_BUFFER_FORMATS_IMG 2 +#define GRALLOC_BLIT_HANDLE_TO_HANDLE_IMG 3 +#define GRALLOC_BLIT_STAMP_TO_HANDLE_IMG 4 +#define GRALLOC_SET_DATA_SPACE_IMG 5 +#define GRALLOC_GET_ION_CLIENT_IMG 6 +#define GRALLOC_GET_BUFFER_HANDLE_IMG 7 - int (*Blit3)(struct IMG_gralloc_module_public_t const *module, - unsigned long long ui64SrcStamp, int iSrcWidth, - int iSrcHeight, int iSrcFormat, int iSrcStrideInPixels, - int eSrcRotation, buffer_handle_t dest, int eDestRotation, - int iInputFenceFd, int *piOutputFenceFd); +#if !defined(PVR_ANDROID_HAS_SET_BUFFERS_DATASPACE) - /* Walk the above list and return only the specified format */ - const IMG_buffer_format_public_t *(*GetBufferFormat)(int iFormat); -} -IMG_gralloc_module_public_t; +enum +{ + HAL_DATASPACE_SRGB_LINEAR = 0x200, + HAL_DATASPACE_SRGB = 0x201, + HAL_DATASPACE_BT601_625 = 0x102, + HAL_DATASPACE_BT601_525 = 0x103, + HAL_DATASPACE_BT709 = 0x104, +}; -/* Helpers for using the non-type-safe perform() extension functions. Use - * these helpers instead of calling perform() directly in your application. - */ +#endif /* !defined(PVR_ANDROID_HAS_SET_BUFFERS_DATASPACE) */ -#define GRALLOC_MODULE_GET_BUFFER_FORMAT_IMG 1 -#define GRALLOC_MODULE_GET_BUFFER_FORMATS_IMG 2 -#define GRALLOC_MODULE_BLIT_HANDLE_TO_HANDLE_IMG 3 -#define GRALLOC_MODULE_BLIT_STAMP_TO_HANDLE_IMG 4 +#if !defined(PVR_ANDROID_HAS_SET_BUFFERS_DATASPACE_2) -static inline int -gralloc_module_get_buffer_format_img(const gralloc_module_t *module, - int format, - const IMG_buffer_format_public_t **v) +enum { - return module->perform(module, GRALLOC_MODULE_GET_BUFFER_FORMAT_IMG, - format, v); -} + HAL_DATASPACE_STANDARD_SHIFT = 16, + HAL_DATASPACE_TRANSFER_SHIFT = 22, + HAL_DATASPACE_RANGE_SHIFT = 27, -static inline int -gralloc_module_get_buffer_formats_img(const gralloc_module_t *module, - const IMG_buffer_format_public_t **v) -{ - return module->perform(module, GRALLOC_MODULE_GET_BUFFER_FORMATS_IMG, v); -} + HAL_DATASPACE_STANDARD_BT2020 = 6 << HAL_DATASPACE_STANDARD_SHIFT, -static inline int -gralloc_module_blit_handle_to_handle_img(const gralloc_module_t *module, - buffer_handle_t src, - buffer_handle_t dest, - int w, int h, int x, int y, - int transform, int input_fence, - int *output_fence) -{ - return module->perform(module, GRALLOC_MODULE_BLIT_HANDLE_TO_HANDLE_IMG, - src, dest, w, h, x, y, transform, input_fence, - output_fence); -} + HAL_DATASPACE_TRANSFER_SMPTE_170M = 3 << HAL_DATASPACE_TRANSFER_SHIFT, + + HAL_DATASPACE_RANGE_MASK = 7 << HAL_DATASPACE_RANGE_SHIFT, + HAL_DATASPACE_RANGE_FULL = 1 << HAL_DATASPACE_RANGE_SHIFT, + HAL_DATASPACE_RANGE_LIMITED = 2 << HAL_DATASPACE_RANGE_SHIFT, +}; -static inline int -gralloc_module_blit_stamp_to_handle(const gralloc_module_t *module, - unsigned long long src_stamp, - int src_width, int src_height, - int src_format, int src_stride_in_pixels, - int src_rotation, buffer_handle_t dest, - int dest_rotation, int input_fence, - int *output_fence) +#endif /* !defined(PVR_ANDROID_HAS_SET_BUFFERS_DATASPACE_2) */ + +/* We want to add BT.2020 and 'full range' versions of the existing dataspace + * enums. These are extensions, so define a new android_dataspace_ext_t. + * If you only have an android_dataspace_t, you can simply cast it. + */ +typedef enum { - return module->perform(module, GRALLOC_MODULE_BLIT_STAMP_TO_HANDLE_IMG, - src_stamp, src_width, src_height, src_format, - src_stride_in_pixels, src_rotation, dest, - dest_rotation, input_fence, output_fence); + /* Identical to upstream enum android_dataspace */ + HAL_DATASPACE_EXT_UNKNOWN = HAL_DATASPACE_UNKNOWN, + HAL_DATASPACE_EXT_SRGB_LINEAR = HAL_DATASPACE_SRGB_LINEAR, + HAL_DATASPACE_EXT_SRGB = HAL_DATASPACE_SRGB, + HAL_DATASPACE_EXT_BT601_625 = HAL_DATASPACE_BT601_625, + HAL_DATASPACE_EXT_BT601_525 = HAL_DATASPACE_BT601_525, + HAL_DATASPACE_EXT_BT709 = HAL_DATASPACE_BT709, + + /* IMG extension for BT.2020 support */ + HAL_DATASPACE_EXT_BT2020 = HAL_DATASPACE_STANDARD_BT2020 | + HAL_DATASPACE_TRANSFER_SMPTE_170M | + HAL_DATASPACE_RANGE_LIMITED, + + /* IMG extensions for 'full range' versions of previous enums */ + HAL_DATASPACE_EXT_BT601_625_FULL = ( HAL_DATASPACE_BT601_625 & + ~HAL_DATASPACE_RANGE_MASK) | + HAL_DATASPACE_RANGE_FULL, + HAL_DATASPACE_EXT_BT601_525_FULL = ( HAL_DATASPACE_BT601_525 & + ~HAL_DATASPACE_RANGE_MASK) | + HAL_DATASPACE_RANGE_FULL, + HAL_DATASPACE_EXT_BT709_FULL = ( HAL_DATASPACE_BT709 & + ~HAL_DATASPACE_RANGE_MASK) | + HAL_DATASPACE_RANGE_FULL, + HAL_DATASPACE_EXT_BT2020_FULL = ( HAL_DATASPACE_EXT_BT2020 & + ~HAL_DATASPACE_RANGE_MASK) | + HAL_DATASPACE_RANGE_FULL, } +android_dataspace_ext_t; -#endif /* HAL_PUBLIC_H */ +#endif /* IMG_GRALLOC_COMMON_PUBLIC_H */ diff --git a/moorefield_hdmi/ips/tangier/TngDisplayContext.cpp b/moorefield_hdmi/ips/tangier/TngDisplayContext.cpp index e755988..789d80f 100755 --- a/moorefield_hdmi/ips/tangier/TngDisplayContext.cpp +++ b/moorefield_hdmi/ips/tangier/TngDisplayContext.cpp @@ -42,15 +42,15 @@ bool TngDisplayContext::initialize() CTRACE(); // open frame buffer device - gralloc_module_t const* module; - int err = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, (hw_module_t const**)&module); + const hw_device_t *gralloc; + int err = gralloc_open_img(&gralloc); if (err) { ELOGTRACE("failed to load gralloc module, error = %d", err); return false; } // init IMG display device - err = module->perform(module, GRALLOC_MODULE_GET_DISPLAY_DEVICE_IMG, (void **)&mIMGDisplayDevice); + err = gralloc_get_display_device_img(gralloc, (void **)&mIMGDisplayDevice); if (err) { ELOGTRACE("failed to get display device, error = %d", err); return false; diff --git a/moorefield_hdmi/ips/tangier/TngGrallocBufferMapper.cpp b/moorefield_hdmi/ips/tangier/TngGrallocBufferMapper.cpp index 91e6192..6e544e3 100644 --- a/moorefield_hdmi/ips/tangier/TngGrallocBufferMapper.cpp +++ b/moorefield_hdmi/ips/tangier/TngGrallocBufferMapper.cpp @@ -22,10 +22,10 @@ namespace android { namespace intel { -TngGrallocBufferMapper::TngGrallocBufferMapper(gralloc_module_t const& module, - DataBuffer& buffer) +TngGrallocBufferMapper::TngGrallocBufferMapper(const hw_device_t& gralloc, + DataBuffer& buffer) : GrallocBufferMapperBase(buffer), - mGrallocModule(module), + mGralloc(gralloc), mBufferObject(0) { CTRACE(); @@ -122,8 +122,7 @@ bool TngGrallocBufferMapper::map() CTRACE(); // get virtual address - err = mGrallocModule.perform(&mGrallocModule, - GRALLOC_MODULE_GET_BUFFER_CPU_ADDRESSES_IMG, + err = gralloc_get_buffer_cpu_addresses_img(&mGralloc, (buffer_handle_t)mClonedHandle, vaddr, size); @@ -162,8 +161,7 @@ bool TngGrallocBufferMapper::map() } } - err = mGrallocModule.perform(&mGrallocModule, - GRALLOC_MODULE_PUT_BUFFER_CPU_ADDRESSES_IMG, + err = gralloc_put_buffer_cpu_addresses_img(&mGralloc, (buffer_handle_t)mClonedHandle); return false; } @@ -184,8 +182,7 @@ bool TngGrallocBufferMapper::unmap() mSize[i] = 0; } - err = mGrallocModule.perform(&mGrallocModule, - GRALLOC_MODULE_PUT_BUFFER_CPU_ADDRESSES_IMG, + err = gralloc_put_buffer_cpu_addresses_img(&mGralloc, (buffer_handle_t)mClonedHandle); if (err) { ELOGTRACE("failed to unmap. err = %d", err); @@ -239,8 +236,7 @@ uint32_t TngGrallocBufferMapper::getFbHandle(int subIndex) } // get virtual address - err = mGrallocModule.perform(&mGrallocModule, - GRALLOC_MODULE_GET_BUFFER_CPU_ADDRESSES_IMG, + err = gralloc_get_buffer_cpu_addresses_img(&mGralloc, (buffer_handle_t)mClonedHandle, vaddr, size); @@ -254,8 +250,7 @@ uint32_t TngGrallocBufferMapper::getFbHandle(int subIndex) void TngGrallocBufferMapper::putFbHandle() { - int err = mGrallocModule.perform(&mGrallocModule, - GRALLOC_MODULE_PUT_BUFFER_CPU_ADDRESSES_IMG, + int err = gralloc_put_buffer_cpu_addresses_img(&mGralloc, (buffer_handle_t)mClonedHandle); if (err) { ELOGTRACE("failed to unmap. err = %d", err); diff --git a/moorefield_hdmi/ips/tangier/TngGrallocBufferMapper.h b/moorefield_hdmi/ips/tangier/TngGrallocBufferMapper.h index aaf6d4a..94ed8db 100644 --- a/moorefield_hdmi/ips/tangier/TngGrallocBufferMapper.h +++ b/moorefield_hdmi/ips/tangier/TngGrallocBufferMapper.h @@ -25,8 +25,7 @@ namespace intel { class TngGrallocBufferMapper : public GrallocBufferMapperBase { public: - TngGrallocBufferMapper(gralloc_module_t const& module, - DataBuffer& buffer); + TngGrallocBufferMapper(const hw_device_t& gralloc, DataBuffer& buffer); virtual ~TngGrallocBufferMapper(); public: bool map(); @@ -40,7 +39,7 @@ private: bool mapKhandle(); private: - gralloc_module_t const& mGrallocModule; + const hw_device_t& mGralloc; void* mBufferObject; native_handle_t* mClonedHandle; }; diff --git a/moorefield_hdmi/platforms/merrifield_plus/PlatfBufferManager.cpp b/moorefield_hdmi/platforms/merrifield_plus/PlatfBufferManager.cpp index 0a506d0..d1ea6e9 100755 --- a/moorefield_hdmi/platforms/merrifield_plus/PlatfBufferManager.cpp +++ b/moorefield_hdmi/platforms/merrifield_plus/PlatfBufferManager.cpp @@ -50,7 +50,7 @@ DataBuffer* PlatfBufferManager::createDataBuffer(uint32_t handle) BufferMapper* PlatfBufferManager::createBufferMapper(DataBuffer& buffer) { - return new TngGrallocBufferMapper(*mGrallocModule, buffer); + return new TngGrallocBufferMapper(*mGralloc, buffer); } bool PlatfBufferManager::blitGrallocBuffer(uint32_t srcHandle, uint32_t dstHandle, @@ -59,8 +59,7 @@ bool PlatfBufferManager::blitGrallocBuffer(uint32_t srcHandle, uint32_t dstHandl { int fenceFd; - if (mGrallocModule->perform(mGrallocModule, - GRALLOC_MODULE_BLIT_HANDLE_TO_HANDLE_IMG, + if (gralloc_blit_handle_to_handle_img(mGralloc, (buffer_handle_t)srcHandle, (buffer_handle_t)dstHandle, srcCrop.w, srcCrop.h, srcCrop.x, |