blob: ac1c9ef4a1b26ee1a61914989f89d21161960292 [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
codeworkx62f02ba2012-05-20 12:00:36 +020037#include <linux/videodev.h>
espenfjo34f9d5d2012-12-01 18:52:36 +010038#include "videodev2.h"
codeworkx62f02ba2012-05-20 12:00:36 +020039#include "s5p_fimc.h"
40#include "sec_utils.h"
codeworkx62f02ba2012-05-20 12:00:36 +020041#include <sys/ioctl.h>
42#include <sys/mman.h>
espenfjo34f9d5d2012-12-01 18:52:36 +010043#include <sys/resource.h>
codeworkx62f02ba2012-05-20 12:00:36 +020044#include <hardware/gralloc.h>
45
46#include "linux/fb.h"
47
48#include "s3c_lcd.h"
codeworkx62f02ba2012-05-20 12:00:36 +020049#include "sec_format.h"
50
espenfjo34f9d5d2012-12-01 18:52:36 +010051#define HWC_DEBUG 1
codeworkx62f02ba2012-05-20 12:00:36 +020052#if defined(BOARD_USES_FIMGAPI)
53#include "sec_g2d.h"
codeworkx62f02ba2012-05-20 12:00:36 +020054#endif
55
espenfjo34f9d5d2012-12-01 18:52:36 +010056#define SKIP_DUMMY_UI_LAY_DRAWING
57
58#ifdef SKIP_DUMMY_UI_LAY_DRAWING
59#define GL_WA_OVLY_ALL
60#define THRES_FOR_SWAP (3427) /* 60sec in Frames. 57fps * 60 = 3427 */
61#endif
62
63#define NUM_OF_DUMMY_WIN (4)
codeworkx62f02ba2012-05-20 12:00:36 +020064#define NUM_OF_WIN (2)
65#define NUM_OF_WIN_BUF (2)
66#define NUM_OF_MEM_OBJ (1)
67
68#if (NUM_OF_WIN_BUF < 2)
69 #define ENABLE_FIMD_VSYNC
70#endif
71
72#define MAX_RESIZING_RATIO_LIMIT (63)
73
74#ifdef SAMSUNG_EXYNOS4x12
codeworkx62f02ba2012-05-20 12:00:36 +020075#define PP_DEVICE_DEV_NAME "/dev/video3"
76#endif
codeworkx62f02ba2012-05-20 12:00:36 +020077
78#ifdef SAMSUNG_EXYNOS4210
79#define PP_DEVICE_DEV_NAME "/dev/video1"
80#endif
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];
espenfjo34f9d5d2012-12-01 18:52:36 +0100159#ifdef SKIP_DUMMY_UI_LAY_DRAWING
160 struct hwc_ui_lay_info win_virt[NUM_OF_DUMMY_WIN];
161 int fb_lay_skip_initialized;
162 int num_of_fb_lay_skip;
163#ifdef GL_WA_OVLY_ALL
164 int ui_skip_frame_cnt;
165#endif
166#endif
167
codeworkx62f02ba2012-05-20 12:00:36 +0200168 struct fb_var_screeninfo lcd_info;
espenfjo34f9d5d2012-12-01 18:52:36 +0100169 s5p_fimc_t fimc;
170 hwc_procs_t *procs;
171 pthread_t uevent_thread;
172 pthread_t vsync_thread;
173
codeworkx62f02ba2012-05-20 12:00:36 +0200174 int num_of_fb_layer;
175 int num_of_hwc_layer;
espenfjo34f9d5d2012-12-01 18:52:36 +0100176 int num_of_fb_layer_prev;
177 int num_2d_blit_layer;
codeworkx62f02ba2012-05-20 12:00:36 +0200178 uint32_t layer_prev_buf[NUM_OF_WIN];
espenfjo34f9d5d2012-12-01 18:52:36 +0100179
180 int num_of_ext_disp_layer;
181 int num_of_ext_disp_video_layer;
182
183#ifdef BOARD_USES_HDMI
184 int hdmi_cable_status;
185#endif
codeworkx62f02ba2012-05-20 12:00:36 +0200186};
187
188typedef enum _LOG_LEVEL {
189 HWC_LOG_DEBUG,
190 HWC_LOG_WARNING,
191 HWC_LOG_ERROR,
192} HWC_LOG_LEVEL;
193
194#define SEC_HWC_LOG_TAG "SECHWC_LOG"
195
196#ifdef HWC_DEBUG
197#define SEC_HWC_Log(a, ...) ((void)_SEC_HWC_Log(a, SEC_HWC_LOG_TAG, __VA_ARGS__))
198#else
199#define SEC_HWC_Log(a, ...) \
200 do { \
espenfjo34f9d5d2012-12-01 18:52:36 +0100201 if (a == HWC_LOG_ERROR) \
202 ((void)_SEC_HWC_Log(a, SEC_HWC_LOG_TAG, __VA_ARGS__)); \
codeworkx62f02ba2012-05-20 12:00:36 +0200203 } while (0)
204#endif
205
206extern void _SEC_HWC_Log(HWC_LOG_LEVEL logLevel, const char *tag, const char *msg, ...);
207
208/* copied from gralloc module ..*/
209typedef struct {
210 native_handle_t base;
211
212 /* These fields can be sent cross process. They are also valid
213 * to duplicate within the same process.
214 *
215 * A table is stored within psPrivateData on gralloc_module_t (this
216 * is obviously per-process) which maps stamps to a mapped
217 * PVRSRV_CLIENT_MEM_INFO in that process. Each map entry has a lock
218 * count associated with it, satisfying the requirements of the
219 * Android API. This also prevents us from leaking maps/allocations.
220 *
221 * This table has entries inserted either by alloc()
222 * (alloc_device_t) or map() (gralloc_module_t). Entries are removed
223 * by free() (alloc_device_t) and unmap() (gralloc_module_t).
224 *
225 * As a special case for framebuffer_device_t, framebuffer_open()
226 * will add and framebuffer_close() will remove from this table.
227 */
228
229#define IMG_NATIVE_HANDLE_NUMFDS 1
230 /* The `fd' field is used to "export" a meminfo to another process.
231 * Therefore, it is allocated by alloc_device_t, and consumed by
232 * gralloc_module_t. The framebuffer_device_t does not need a handle,
233 * and the special value IMG_FRAMEBUFFER_FD is used instead.
234 */
235 int fd;
236
237#if 1
238 int format;
239 int magic;
240 int flags;
241 int size;
242 int offset;
243 int base_addr;
244#define IMG_NATIVE_HANDLE_NUMINTS ((sizeof(uint64_t) / sizeof(int)) + 4 + 6)
245#else
246#define IMG_NATIVE_HANDLE_NUMINTS ((sizeof(IMG_UINT64) / sizeof(int)) + 4)
247#endif
248 /* A KERNEL unique identifier for any exported kernel meminfo. Each
249 * exported kernel meminfo will have a unique stamp, but note that in
250 * userspace, several meminfos across multiple processes could have
251 * the same stamp. As the native_handle can be dup(2)'d, there could be
252 * multiple handles with the same stamp but different file descriptors.
253 */
254 uint64_t ui64Stamp;
255
256 /* We could live without this, but it lets us perform some additional
257 * validation on the client side. Normally, we'd have no visibility
258 * of the allocated usage, just the lock usage.
259 */
260 int usage;
261
262 /* In order to do efficient cache flushes we need the buffer dimensions
263 * and format. These are available on the android_native_buffer_t,
264 * but the platform doesn't pass them down to the graphics HAL.
265 *
266 * TODO: Ideally the platform would be modified to not require this.
267 */
268 int width;
269 int height;
270 int bpp;
271}
272__attribute__((aligned(sizeof(int)),packed)) sec_native_handle_t;
273
274int window_open (struct hwc_win_info_t *win, int id);
275int window_close (struct hwc_win_info_t *win);
276int window_set_pos (struct hwc_win_info_t *win);
277int window_get_info (struct hwc_win_info_t *win, int win_num);
278int window_pan_display(struct hwc_win_info_t *win);
279int window_show (struct hwc_win_info_t *win);
280int window_hide (struct hwc_win_info_t *win);
281int window_get_global_lcd_info(int fd, struct fb_var_screeninfo *lcd_info);
282
283int createFimc (s5p_fimc_t *fimc);
284int destroyFimc(s5p_fimc_t *fimc);
285int runFimc(struct hwc_context_t *ctx,
espenfjo34f9d5d2012-12-01 18:52:36 +0100286 struct sec_img *src_img, struct sec_rect *src_rect,
287 struct sec_img *dst_img, struct sec_rect *dst_rect,
288 uint32_t transform);
289int check_yuv_format(unsigned int color_format);
codeworkx62f02ba2012-05-20 12:00:36 +0200290
291#endif /* ANDROID_SEC_HWC_UTILS_H_*/