codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | /* |
| 18 | * |
| 19 | * @author Rama, Meka(v.meka@samsung.com) |
espenfjo | 34f9d5d | 2012-12-01 18:52:36 +0100 | [diff] [blame] | 20 | Sangwoo, Park(sw5771.park@samsung.com) |
| 21 | Jamie, Oh (jung-min.oh@samsung.com) |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 22 | * @date 2011-03-11 |
| 23 | * |
| 24 | */ |
| 25 | |
| 26 | #ifndef ANDROID_SEC_HWC_UTILS_H_ |
| 27 | #define ANDROID_SEC_HWC_UTILS_H_ |
| 28 | |
| 29 | #include <stdlib.h> |
| 30 | #include <hardware/hardware.h> |
| 31 | #include <hardware/hwcomposer.h> |
| 32 | |
| 33 | #include <fcntl.h> |
| 34 | #include <errno.h> |
| 35 | #include <cutils/log.h> |
| 36 | |
sbrissen | 99008c2 | 2014-11-19 08:26:32 -0500 | [diff] [blame^] | 37 | #include <linux/videodev2.h> |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 38 | #include "s5p_fimc.h" |
| 39 | #include "sec_utils.h" |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 40 | #include <sys/ioctl.h> |
| 41 | #include <sys/mman.h> |
espenfjo | 34f9d5d | 2012-12-01 18:52:36 +0100 | [diff] [blame] | 42 | #include <sys/resource.h> |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 43 | #include <hardware/gralloc.h> |
| 44 | |
| 45 | #include "linux/fb.h" |
| 46 | |
| 47 | #include "s3c_lcd.h" |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 48 | #include "sec_format.h" |
| 49 | |
codeworkx | 6ab6c16 | 2012-12-09 09:51:22 +0100 | [diff] [blame] | 50 | //#define HWC_DEBUG 1 |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 51 | #if defined(BOARD_USES_FIMGAPI) |
| 52 | #include "sec_g2d.h" |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 53 | #endif |
| 54 | |
espenfjo | 34f9d5d | 2012-12-01 18:52:36 +0100 | [diff] [blame] | 55 | #define SKIP_DUMMY_UI_LAY_DRAWING |
| 56 | |
| 57 | #ifdef SKIP_DUMMY_UI_LAY_DRAWING |
| 58 | #define GL_WA_OVLY_ALL |
| 59 | #define THRES_FOR_SWAP (3427) /* 60sec in Frames. 57fps * 60 = 3427 */ |
| 60 | #endif |
| 61 | |
| 62 | #define NUM_OF_DUMMY_WIN (4) |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 63 | #define NUM_OF_WIN (2) |
| 64 | #define NUM_OF_WIN_BUF (2) |
| 65 | #define NUM_OF_MEM_OBJ (1) |
| 66 | |
| 67 | #if (NUM_OF_WIN_BUF < 2) |
| 68 | #define ENABLE_FIMD_VSYNC |
| 69 | #endif |
| 70 | |
| 71 | #define MAX_RESIZING_RATIO_LIMIT (63) |
| 72 | |
| 73 | #ifdef SAMSUNG_EXYNOS4x12 |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 74 | #define PP_DEVICE_DEV_NAME "/dev/video3" |
| 75 | #endif |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 76 | |
| 77 | #ifdef SAMSUNG_EXYNOS4210 |
| 78 | #define PP_DEVICE_DEV_NAME "/dev/video1" |
| 79 | #endif |
codeworkx | 39aefd0 | 2012-12-02 19:39:25 +0100 | [diff] [blame] | 80 | |
espenfjo | 34f9d5d | 2012-12-01 18:52:36 +0100 | [diff] [blame] | 81 | /* cacheable configuration */ |
| 82 | #define V4L2_CID_CACHEABLE (V4L2_CID_BASE+40) |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 83 | |
| 84 | struct sec_rect { |
| 85 | int32_t x; |
| 86 | int32_t y; |
| 87 | int32_t w; |
| 88 | int32_t h; |
| 89 | }; |
| 90 | |
| 91 | struct sec_img { |
| 92 | uint32_t f_w; |
| 93 | uint32_t f_h; |
| 94 | uint32_t w; |
| 95 | uint32_t h; |
| 96 | uint32_t format; |
| 97 | uint32_t base; |
| 98 | uint32_t offset; |
| 99 | uint32_t paddr; |
| 100 | uint32_t uoffset; |
| 101 | uint32_t voffset; |
| 102 | int usage; |
| 103 | int mem_id; |
| 104 | int mem_type; |
| 105 | }; |
| 106 | |
| 107 | inline int SEC_MIN(int x, int y) |
| 108 | { |
| 109 | return ((x < y) ? x : y); |
| 110 | } |
| 111 | |
| 112 | inline int SEC_MAX(int x, int y) |
| 113 | { |
| 114 | return ((x > y) ? x : y); |
| 115 | } |
| 116 | |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 117 | struct hwc_win_info_t { |
| 118 | int fd; |
| 119 | int size; |
| 120 | sec_rect rect_info; |
| 121 | uint32_t addr[NUM_OF_WIN_BUF]; |
| 122 | int buf_index; |
| 123 | |
| 124 | int power_state; |
| 125 | int blending; |
| 126 | int layer_index; |
| 127 | int status; |
| 128 | int vsync; |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 129 | |
| 130 | struct fb_fix_screeninfo fix_info; |
| 131 | struct fb_var_screeninfo var_info; |
| 132 | struct fb_var_screeninfo lcd_info; |
| 133 | }; |
| 134 | |
| 135 | enum { |
| 136 | HWC_WIN_FREE = 0, |
| 137 | HWC_WIN_RESERVED, |
| 138 | }; |
| 139 | |
| 140 | enum { |
| 141 | HWC_UNKNOWN_MEM_TYPE = 0, |
| 142 | HWC_PHYS_MEM_TYPE, |
| 143 | HWC_VIRT_MEM_TYPE, |
| 144 | }; |
| 145 | |
espenfjo | 34f9d5d | 2012-12-01 18:52:36 +0100 | [diff] [blame] | 146 | #ifdef SKIP_DUMMY_UI_LAY_DRAWING |
| 147 | struct hwc_ui_lay_info{ |
| 148 | uint32_t layer_prev_buf; |
| 149 | int layer_index; |
| 150 | int status; |
| 151 | }; |
| 152 | #endif |
| 153 | |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 154 | struct hwc_context_t { |
espenfjo | 34f9d5d | 2012-12-01 18:52:36 +0100 | [diff] [blame] | 155 | hwc_composer_device_1_t device; |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 156 | |
| 157 | /* our private state goes below here */ |
| 158 | struct hwc_win_info_t win[NUM_OF_WIN]; |
codeworkx | 39aefd0 | 2012-12-02 19:39:25 +0100 | [diff] [blame] | 159 | struct hwc_win_info_t global_lcd_win; |
espenfjo | 34f9d5d | 2012-12-01 18:52:36 +0100 | [diff] [blame] | 160 | #ifdef SKIP_DUMMY_UI_LAY_DRAWING |
| 161 | struct hwc_ui_lay_info win_virt[NUM_OF_DUMMY_WIN]; |
| 162 | int fb_lay_skip_initialized; |
| 163 | int num_of_fb_lay_skip; |
| 164 | #ifdef GL_WA_OVLY_ALL |
| 165 | int ui_skip_frame_cnt; |
| 166 | #endif |
| 167 | #endif |
| 168 | |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 169 | struct fb_var_screeninfo lcd_info; |
espenfjo | 34f9d5d | 2012-12-01 18:52:36 +0100 | [diff] [blame] | 170 | s5p_fimc_t fimc; |
| 171 | hwc_procs_t *procs; |
| 172 | pthread_t uevent_thread; |
| 173 | pthread_t vsync_thread; |
| 174 | |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 175 | int num_of_fb_layer; |
| 176 | int num_of_hwc_layer; |
espenfjo | 34f9d5d | 2012-12-01 18:52:36 +0100 | [diff] [blame] | 177 | int num_of_fb_layer_prev; |
| 178 | int num_2d_blit_layer; |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 179 | uint32_t layer_prev_buf[NUM_OF_WIN]; |
espenfjo | 34f9d5d | 2012-12-01 18:52:36 +0100 | [diff] [blame] | 180 | |
| 181 | int num_of_ext_disp_layer; |
| 182 | int num_of_ext_disp_video_layer; |
| 183 | |
| 184 | #ifdef BOARD_USES_HDMI |
| 185 | int hdmi_cable_status; |
| 186 | #endif |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 187 | }; |
| 188 | |
| 189 | typedef enum _LOG_LEVEL { |
| 190 | HWC_LOG_DEBUG, |
| 191 | HWC_LOG_WARNING, |
| 192 | HWC_LOG_ERROR, |
| 193 | } HWC_LOG_LEVEL; |
| 194 | |
| 195 | #define SEC_HWC_LOG_TAG "SECHWC_LOG" |
| 196 | |
| 197 | #ifdef HWC_DEBUG |
| 198 | #define SEC_HWC_Log(a, ...) ((void)_SEC_HWC_Log(a, SEC_HWC_LOG_TAG, __VA_ARGS__)) |
| 199 | #else |
| 200 | #define SEC_HWC_Log(a, ...) \ |
| 201 | do { \ |
espenfjo | 34f9d5d | 2012-12-01 18:52:36 +0100 | [diff] [blame] | 202 | if (a == HWC_LOG_ERROR) \ |
| 203 | ((void)_SEC_HWC_Log(a, SEC_HWC_LOG_TAG, __VA_ARGS__)); \ |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 204 | } while (0) |
| 205 | #endif |
| 206 | |
| 207 | extern void _SEC_HWC_Log(HWC_LOG_LEVEL logLevel, const char *tag, const char *msg, ...); |
| 208 | |
| 209 | /* copied from gralloc module ..*/ |
| 210 | typedef struct { |
| 211 | native_handle_t base; |
| 212 | |
| 213 | /* These fields can be sent cross process. They are also valid |
| 214 | * to duplicate within the same process. |
| 215 | * |
| 216 | * A table is stored within psPrivateData on gralloc_module_t (this |
| 217 | * is obviously per-process) which maps stamps to a mapped |
| 218 | * PVRSRV_CLIENT_MEM_INFO in that process. Each map entry has a lock |
| 219 | * count associated with it, satisfying the requirements of the |
| 220 | * Android API. This also prevents us from leaking maps/allocations. |
| 221 | * |
| 222 | * This table has entries inserted either by alloc() |
| 223 | * (alloc_device_t) or map() (gralloc_module_t). Entries are removed |
| 224 | * by free() (alloc_device_t) and unmap() (gralloc_module_t). |
| 225 | * |
| 226 | * As a special case for framebuffer_device_t, framebuffer_open() |
| 227 | * will add and framebuffer_close() will remove from this table. |
| 228 | */ |
| 229 | |
| 230 | #define IMG_NATIVE_HANDLE_NUMFDS 1 |
| 231 | /* The `fd' field is used to "export" a meminfo to another process. |
| 232 | * Therefore, it is allocated by alloc_device_t, and consumed by |
| 233 | * gralloc_module_t. The framebuffer_device_t does not need a handle, |
| 234 | * and the special value IMG_FRAMEBUFFER_FD is used instead. |
| 235 | */ |
| 236 | int fd; |
| 237 | |
| 238 | #if 1 |
| 239 | int format; |
| 240 | int magic; |
| 241 | int flags; |
| 242 | int size; |
| 243 | int offset; |
| 244 | int base_addr; |
| 245 | #define IMG_NATIVE_HANDLE_NUMINTS ((sizeof(uint64_t) / sizeof(int)) + 4 + 6) |
| 246 | #else |
| 247 | #define IMG_NATIVE_HANDLE_NUMINTS ((sizeof(IMG_UINT64) / sizeof(int)) + 4) |
| 248 | #endif |
| 249 | /* A KERNEL unique identifier for any exported kernel meminfo. Each |
| 250 | * exported kernel meminfo will have a unique stamp, but note that in |
| 251 | * userspace, several meminfos across multiple processes could have |
| 252 | * the same stamp. As the native_handle can be dup(2)'d, there could be |
| 253 | * multiple handles with the same stamp but different file descriptors. |
| 254 | */ |
| 255 | uint64_t ui64Stamp; |
| 256 | |
| 257 | /* We could live without this, but it lets us perform some additional |
| 258 | * validation on the client side. Normally, we'd have no visibility |
| 259 | * of the allocated usage, just the lock usage. |
| 260 | */ |
| 261 | int usage; |
| 262 | |
| 263 | /* In order to do efficient cache flushes we need the buffer dimensions |
| 264 | * and format. These are available on the android_native_buffer_t, |
| 265 | * but the platform doesn't pass them down to the graphics HAL. |
| 266 | * |
| 267 | * TODO: Ideally the platform would be modified to not require this. |
| 268 | */ |
| 269 | int width; |
| 270 | int height; |
| 271 | int bpp; |
| 272 | } |
| 273 | __attribute__((aligned(sizeof(int)),packed)) sec_native_handle_t; |
| 274 | |
| 275 | int window_open (struct hwc_win_info_t *win, int id); |
| 276 | int window_close (struct hwc_win_info_t *win); |
| 277 | int window_set_pos (struct hwc_win_info_t *win); |
| 278 | int window_get_info (struct hwc_win_info_t *win, int win_num); |
| 279 | int window_pan_display(struct hwc_win_info_t *win); |
| 280 | int window_show (struct hwc_win_info_t *win); |
| 281 | int window_hide (struct hwc_win_info_t *win); |
codeworkx | 39aefd0 | 2012-12-02 19:39:25 +0100 | [diff] [blame] | 282 | int window_get_global_lcd_info(struct hwc_context_t *ctx); |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 283 | |
| 284 | int createFimc (s5p_fimc_t *fimc); |
| 285 | int destroyFimc(s5p_fimc_t *fimc); |
| 286 | int runFimc(struct hwc_context_t *ctx, |
espenfjo | 34f9d5d | 2012-12-01 18:52:36 +0100 | [diff] [blame] | 287 | struct sec_img *src_img, struct sec_rect *src_rect, |
| 288 | struct sec_img *dst_img, struct sec_rect *dst_rect, |
| 289 | uint32_t transform); |
| 290 | int check_yuv_format(unsigned int color_format); |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 291 | |
| 292 | #endif /* ANDROID_SEC_HWC_UTILS_H_*/ |