Home | History | Annotate | Download | only in hal
      1 /* Copyright (c) Imagination Technologies Ltd.
      2  *
      3  * The contents of this file are subject to the MIT license as set out below.
      4  *
      5  * Permission is hereby granted, free of charge, to any person obtaining a copy
      6  * of this software and associated documentation files (the "Software"), to deal
      7  * in the Software without restriction, including without limitation the rights
      8  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
      9  * copies of the Software, and to permit persons to whom the Software is
     10  * furnished to do so, subject to the following conditions:
     11  *
     12  * The above copyright notice and this permission notice shall be included in
     13  * all copies or substantial portions of the Software.
     14  *
     15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
     18  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     20  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
     21  * THE SOFTWARE.
     22  */
     23 
     24 #ifndef HAL_PUBLIC_H
     25 #define HAL_PUBLIC_H
     26 
     27 #define PVR_ANDROID_HAS_SET_BUFFERS_DATASPACE
     28 #define PVR_ANDROID_HAS_SET_BUFFERS_DATASPACE_2
     29 
     30 #include "img_gralloc_common_public.h"
     31 
     32 /* Extension pixel formats used by Intel components */
     33 
     34 #undef  HAL_PIXEL_FORMAT_NV12
     35 
     36 #define HAL_PIXEL_FORMAT_UYVY                 0x107
     37 #define HAL_PIXEL_FORMAT_INTEL_YV12           0x108
     38 #define HAL_PIXEL_FORMAT_INTEL_ZSL            0x109
     39 #define HAL_PIXEL_FORMAT_NV12                 0x3231564E
     40 #define HAL_PIXEL_FORMAT_NV21                 0x3132564E
     41 #define HAL_PIXEL_FORMAT_I420                 0x30323449
     42 #define HAL_PIXEL_FORMAT_YUY2                 0x32595559
     43 #define HAL_PIXEL_FORMAT_NV12_VED             0x7FA00E00
     44 #define HAL_PIXEL_FORMAT_NV12_VEDT            0x7FA00F00
     45 
     46 /* Extension API used by Intel components */
     47 
     48 #define GRALLOC_GET_BUFFER_CPU_ADDRESSES_IMG  108
     49 #define GRALLOC_PUT_BUFFER_CPU_ADDRESSES_IMG  109
     50 
     51 #define GRALLOC_GET_DISPLAY_DEVICE_IMG        1000
     52 #define GRALLOC_GET_DISPLAY_STATUS_IMG        1001
     53 
     54 #include "img_gralloc.h"
     55 #include "img_gralloc1.h"
     56 
     57 typedef const gralloc_module_t gralloc0_t;
     58 typedef gralloc1_device_t      gralloc1_t;
     59 
     60 static inline int gralloc_is_v1_img(const hw_module_t *m)
     61 {
     62 	return ((m->module_api_version >> 8) & 0xff) == 1;
     63 }
     64 
     65 static inline int gralloc_open_img(const hw_device_t **d)
     66 {
     67 	const hw_module_t *m;
     68 	int err;
     69 
     70 	err = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &m);
     71 	if (err)
     72 		return err;
     73 
     74 	if (gralloc_is_v1_img(m))
     75 		return gralloc1_open(m, (gralloc1_t **)d);
     76 	else
     77 		return gralloc_open(m, (alloc_device_t **)d);
     78 }
     79 
     80 static inline int gralloc_close_img(const hw_device_t *d)
     81 {
     82 	if (gralloc_is_v1_img(d->module))
     83 		return gralloc1_close((gralloc1_t *)d);
     84 	else
     85 		return gralloc_close((alloc_device_t *)d);
     86 }
     87 
     88 static inline int gralloc_register_img
     89 	(const hw_device_t *d, buffer_handle_t handle)
     90 {
     91 	if (gralloc_is_v1_img(d->module))
     92 		return gralloc1_register_img((gralloc1_t *)d, handle);
     93 	else
     94 		return gralloc0_register_img((gralloc0_t *)d->module, handle);
     95 }
     96 
     97 static inline int gralloc_unregister_img
     98 	(const hw_device_t *d, buffer_handle_t handle)
     99 {
    100 	if (gralloc_is_v1_img(d->module))
    101 		return gralloc1_unregister_img((gralloc1_t *)d, handle);
    102 	else
    103 		return gralloc0_unregister_img((gralloc0_t *)d->module, handle);
    104 }
    105 
    106 static inline int gralloc_device_alloc_img
    107 	(const hw_device_t *d, int w, int h, int format, int usage,
    108 	 buffer_handle_t *handle, int *stride)
    109 {
    110 	if (gralloc_is_v1_img(d->module)) {
    111 		usage = (usage | ((usage & 0x33) << 1)) & ~0x11;
    112 		return gralloc1_device_alloc_img((gralloc1_t *)d, w, h, format,
    113 										 usage, handle, stride);
    114 	} else
    115 		return gralloc0_device_alloc_img((alloc_device_t *)d, w, h, format,
    116 										 usage, handle, stride);
    117 }
    118 
    119 static inline int gralloc_device_free_img
    120 	(const hw_device_t *d, buffer_handle_t handle)
    121 {
    122 	if (gralloc_is_v1_img(d->module))
    123 		return gralloc1_device_free_img((gralloc1_t *)d, handle);
    124 	else
    125 		return gralloc0_device_free_img((alloc_device_t *)d, handle);
    126 }
    127 
    128 static inline int gralloc_lock_async_img
    129 	(const hw_device_t *d, buffer_handle_t handle, int usage,
    130 	 const gralloc1_rect_t *r, void **vaddr, int acquireFence)
    131 {
    132 	if (gralloc_is_v1_img(d->module)) {
    133 		usage = (usage | ((usage & 0x33) << 1)) & ~0x11;
    134 		return gralloc1_lock_async_img((gralloc1_t *)d,
    135 									   handle, usage, r, vaddr, acquireFence);
    136 	} else
    137 		return gralloc0_lock_async_img((gralloc0_t *)d->module,
    138 									   handle, usage, r, vaddr, acquireFence);
    139 }
    140 
    141 static inline int gralloc_unlock_async_img
    142 	(const hw_device_t *d, buffer_handle_t handle, int *releaseFence)
    143 {
    144 	if (gralloc_is_v1_img(d->module))
    145 		return gralloc1_unlock_async_img((gralloc1_t *)d,
    146 										 handle, releaseFence);
    147 	else
    148 		return gralloc0_unlock_async_img((gralloc0_t *)d->module,
    149 										 handle, releaseFence);
    150 }
    151 
    152 static inline int gralloc_blit_handle_to_handle_img
    153 	(const hw_device_t *d, buffer_handle_t src, buffer_handle_t dest,
    154 	 int w, int h, int x, int y, int transform, int input_fence,
    155 	 int *output_fence)
    156 {
    157 	if (gralloc_is_v1_img(d->module))
    158 		return gralloc1_blit_handle_to_handle_img((gralloc1_t *)d,
    159 												  src, dest, w, h, x, y,
    160 												  transform, input_fence,
    161 												  output_fence);
    162 	else
    163 		return gralloc0_blit_handle_to_handle_img((gralloc0_t *)d->module,
    164 												  src, dest, w, h, x, y,
    165 												  transform, input_fence,
    166 												  output_fence);
    167 }
    168 
    169 
    170 static inline int gralloc_get_buffer_cpu_addresses_img
    171 	(const hw_device_t *d, buffer_handle_t handle, void **vaddrs,
    172 	 size_t *sizes)
    173 {
    174 	if (gralloc_is_v1_img(d->module))
    175 		return gralloc1_get_buffer_cpu_addresses_img((gralloc1_t *)d,
    176 													 handle, vaddrs, sizes);
    177 	else
    178 		return gralloc0_get_buffer_cpu_addresses_img((gralloc0_t *)d->module,
    179 													 handle, vaddrs, sizes);
    180 }
    181 
    182 static inline int gralloc_put_buffer_cpu_addresses_img
    183 	(const hw_device_t *d, buffer_handle_t handle)
    184 {
    185 	if (gralloc_is_v1_img(d->module))
    186 		return gralloc1_put_buffer_cpu_addresses_img((gralloc1_t *)d,
    187 													 handle);
    188 	else
    189 		return gralloc0_put_buffer_cpu_addresses_img((gralloc0_t *)d->module,
    190 													 handle);
    191 }
    192 
    193 static inline int gralloc_get_display_device_img
    194 	(const hw_device_t *d, void **ppvDispDev)
    195 {
    196 	if (gralloc_is_v1_img(d->module))
    197 		return gralloc1_get_display_device_img((gralloc1_t *)d,
    198 											   ppvDispDev);
    199 	else
    200 		return gralloc0_get_display_device_img((gralloc0_t *)d->module,
    201 											   ppvDispDev);
    202 }
    203 
    204 static inline int gralloc_get_display_status_img
    205 	(const hw_device_t *d, buffer_handle_t handle, uint32_t *pui32Status)
    206 {
    207 	if (gralloc_is_v1_img(d->module))
    208 		return gralloc1_get_display_status_img((gralloc1_t *)d,
    209 											   handle, pui32Status);
    210 	else
    211 		return gralloc0_get_display_status_img((gralloc0_t *)d->module,
    212 											   handle, pui32Status);
    213 }
    214 
    215 #endif /* HAL_PUBLIC_H */
    216