blob: c1b8dab88e70b03a51d7ac71e952ea1a8afb31d5 [file] [log] [blame]
codeworkx62f02ba2012-05-20 12:00:36 +02001/*
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)
espenfjo34f9d5d2012-12-01 18:52:36 +010020 Sangwoo, Park(sw5771.park@samsung.com)
21 Jamie, Oh (jung-min.oh@samsung.com)
codeworkx62f02ba2012-05-20 12:00:36 +020022 * @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
sbrissen99008c22014-11-19 08:26:32 -050037#include <linux/videodev2.h>
codeworkx62f02ba2012-05-20 12:00:36 +020038#include "s5p_fimc.h"
39#include "sec_utils.h"
codeworkx62f02ba2012-05-20 12:00:36 +020040#include <sys/ioctl.h>
41#include <sys/mman.h>
espenfjo34f9d5d2012-12-01 18:52:36 +010042#include <sys/resource.h>
codeworkx62f02ba2012-05-20 12:00:36 +020043#include <hardware/gralloc.h>
44
45#include "linux/fb.h"
46
47#include "s3c_lcd.h"
codeworkx62f02ba2012-05-20 12:00:36 +020048#include "sec_format.h"
49
codeworkx6ab6c162012-12-09 09:51:22 +010050//#define HWC_DEBUG 1
codeworkx62f02ba2012-05-20 12:00:36 +020051#if defined(BOARD_USES_FIMGAPI)
52#include "sec_g2d.h"
codeworkx62f02ba2012-05-20 12:00:36 +020053#endif
54
espenfjo34f9d5d2012-12-01 18:52:36 +010055#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)
codeworkx62f02ba2012-05-20 12:00:36 +020063#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
codeworkx62f02ba2012-05-20 12:00:36 +020074#define PP_DEVICE_DEV_NAME "/dev/video3"
75#endif
codeworkx62f02ba2012-05-20 12:00:36 +020076
77#ifdef SAMSUNG_EXYNOS4210
78#define PP_DEVICE_DEV_NAME "/dev/video1"
79#endif
codeworkx39aefd02012-12-02 19:39:25 +010080
espenfjo34f9d5d2012-12-01 18:52:36 +010081/* cacheable configuration */
82#define V4L2_CID_CACHEABLE (V4L2_CID_BASE+40)
codeworkx62f02ba2012-05-20 12:00:36 +020083
84struct sec_rect {
85 int32_t x;
86 int32_t y;
87 int32_t w;
88 int32_t h;
89};
90
91struct 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
107inline int SEC_MIN(int x, int y)
108{
109 return ((x < y) ? x : y);
110}
111
112inline int SEC_MAX(int x, int y)
113{
114 return ((x > y) ? x : y);
115}
116
codeworkx62f02ba2012-05-20 12:00:36 +0200117struct 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;
codeworkx62f02ba2012-05-20 12:00:36 +0200129
130 struct fb_fix_screeninfo fix_info;
131 struct fb_var_screeninfo var_info;
132 struct fb_var_screeninfo lcd_info;
133};
134
135enum {
136 HWC_WIN_FREE = 0,
137 HWC_WIN_RESERVED,
138};
139
140enum {
141 HWC_UNKNOWN_MEM_TYPE = 0,
142 HWC_PHYS_MEM_TYPE,
143 HWC_VIRT_MEM_TYPE,
144};
145
espenfjo34f9d5d2012-12-01 18:52:36 +0100146#ifdef SKIP_DUMMY_UI_LAY_DRAWING
147struct hwc_ui_lay_info{
148 uint32_t layer_prev_buf;
149 int layer_index;
150 int status;
151};
152#endif
153
codeworkx62f02ba2012-05-20 12:00:36 +0200154struct hwc_context_t {
espenfjo34f9d5d2012-12-01 18:52:36 +0100155 hwc_composer_device_1_t device;
codeworkx62f02ba2012-05-20 12:00:36 +0200156
157 /* our private state goes below here */
158 struct hwc_win_info_t win[NUM_OF_WIN];
codeworkx39aefd02012-12-02 19:39:25 +0100159 struct hwc_win_info_t global_lcd_win;
espenfjo34f9d5d2012-12-01 18:52:36 +0100160#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
codeworkx62f02ba2012-05-20 12:00:36 +0200169 struct fb_var_screeninfo lcd_info;
espenfjo34f9d5d2012-12-01 18:52:36 +0100170 s5p_fimc_t fimc;
171 hwc_procs_t *procs;
172 pthread_t uevent_thread;
173 pthread_t vsync_thread;
174
codeworkx62f02ba2012-05-20 12:00:36 +0200175 int num_of_fb_layer;
176 int num_of_hwc_layer;
espenfjo34f9d5d2012-12-01 18:52:36 +0100177 int num_of_fb_layer_prev;
178 int num_2d_blit_layer;
codeworkx62f02ba2012-05-20 12:00:36 +0200179 uint32_t layer_prev_buf[NUM_OF_WIN];
espenfjo34f9d5d2012-12-01 18:52:36 +0100180
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
codeworkx62f02ba2012-05-20 12:00:36 +0200187};
188
189typedef 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 { \
espenfjo34f9d5d2012-12-01 18:52:36 +0100202 if (a == HWC_LOG_ERROR) \
203 ((void)_SEC_HWC_Log(a, SEC_HWC_LOG_TAG, __VA_ARGS__)); \
codeworkx62f02ba2012-05-20 12:00:36 +0200204 } while (0)
205#endif
206
207extern void _SEC_HWC_Log(HWC_LOG_LEVEL logLevel, const char *tag, const char *msg, ...);
208
209/* copied from gralloc module ..*/
210typedef 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
275int window_open (struct hwc_win_info_t *win, int id);
276int window_close (struct hwc_win_info_t *win);
277int window_set_pos (struct hwc_win_info_t *win);
278int window_get_info (struct hwc_win_info_t *win, int win_num);
279int window_pan_display(struct hwc_win_info_t *win);
280int window_show (struct hwc_win_info_t *win);
281int window_hide (struct hwc_win_info_t *win);
codeworkx39aefd02012-12-02 19:39:25 +0100282int window_get_global_lcd_info(struct hwc_context_t *ctx);
codeworkx62f02ba2012-05-20 12:00:36 +0200283
284int createFimc (s5p_fimc_t *fimc);
285int destroyFimc(s5p_fimc_t *fimc);
286int runFimc(struct hwc_context_t *ctx,
espenfjo34f9d5d2012-12-01 18:52:36 +0100287 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);
290int check_yuv_format(unsigned int color_format);
codeworkx62f02ba2012-05-20 12:00:36 +0200291
292#endif /* ANDROID_SEC_HWC_UTILS_H_*/