blob: 812a400290b8db4011a364bcf377a8f8adeadba9 [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
codeworkx39aefd02012-12-02 19:39:25 +010081
espenfjo34f9d5d2012-12-01 18:52:36 +010082/* cacheable configuration */
83#define V4L2_CID_CACHEABLE (V4L2_CID_BASE+40)
codeworkx62f02ba2012-05-20 12:00:36 +020084
85struct sec_rect {
86 int32_t x;
87 int32_t y;
88 int32_t w;
89 int32_t h;
90};
91
92struct sec_img {
93 uint32_t f_w;
94 uint32_t f_h;
95 uint32_t w;
96 uint32_t h;
97 uint32_t format;
98 uint32_t base;
99 uint32_t offset;
100 uint32_t paddr;
101 uint32_t uoffset;
102 uint32_t voffset;
103 int usage;
104 int mem_id;
105 int mem_type;
106};
107
108inline int SEC_MIN(int x, int y)
109{
110 return ((x < y) ? x : y);
111}
112
113inline int SEC_MAX(int x, int y)
114{
115 return ((x > y) ? x : y);
116}
117
codeworkx62f02ba2012-05-20 12:00:36 +0200118struct hwc_win_info_t {
119 int fd;
120 int size;
121 sec_rect rect_info;
122 uint32_t addr[NUM_OF_WIN_BUF];
123 int buf_index;
124
125 int power_state;
126 int blending;
127 int layer_index;
128 int status;
129 int vsync;
codeworkx62f02ba2012-05-20 12:00:36 +0200130
131 struct fb_fix_screeninfo fix_info;
132 struct fb_var_screeninfo var_info;
133 struct fb_var_screeninfo lcd_info;
134};
135
136enum {
137 HWC_WIN_FREE = 0,
138 HWC_WIN_RESERVED,
139};
140
141enum {
142 HWC_UNKNOWN_MEM_TYPE = 0,
143 HWC_PHYS_MEM_TYPE,
144 HWC_VIRT_MEM_TYPE,
145};
146
espenfjo34f9d5d2012-12-01 18:52:36 +0100147#ifdef SKIP_DUMMY_UI_LAY_DRAWING
148struct hwc_ui_lay_info{
149 uint32_t layer_prev_buf;
150 int layer_index;
151 int status;
152};
153#endif
154
codeworkx62f02ba2012-05-20 12:00:36 +0200155struct hwc_context_t {
espenfjo34f9d5d2012-12-01 18:52:36 +0100156 hwc_composer_device_1_t device;
codeworkx62f02ba2012-05-20 12:00:36 +0200157
158 /* our private state goes below here */
159 struct hwc_win_info_t win[NUM_OF_WIN];
codeworkx39aefd02012-12-02 19:39:25 +0100160 struct hwc_win_info_t global_lcd_win;
espenfjo34f9d5d2012-12-01 18:52:36 +0100161#ifdef SKIP_DUMMY_UI_LAY_DRAWING
162 struct hwc_ui_lay_info win_virt[NUM_OF_DUMMY_WIN];
163 int fb_lay_skip_initialized;
164 int num_of_fb_lay_skip;
165#ifdef GL_WA_OVLY_ALL
166 int ui_skip_frame_cnt;
167#endif
168#endif
169
codeworkx62f02ba2012-05-20 12:00:36 +0200170 struct fb_var_screeninfo lcd_info;
espenfjo34f9d5d2012-12-01 18:52:36 +0100171 s5p_fimc_t fimc;
172 hwc_procs_t *procs;
173 pthread_t uevent_thread;
174 pthread_t vsync_thread;
175
codeworkx62f02ba2012-05-20 12:00:36 +0200176 int num_of_fb_layer;
177 int num_of_hwc_layer;
espenfjo34f9d5d2012-12-01 18:52:36 +0100178 int num_of_fb_layer_prev;
179 int num_2d_blit_layer;
codeworkx62f02ba2012-05-20 12:00:36 +0200180 uint32_t layer_prev_buf[NUM_OF_WIN];
espenfjo34f9d5d2012-12-01 18:52:36 +0100181
182 int num_of_ext_disp_layer;
183 int num_of_ext_disp_video_layer;
184
185#ifdef BOARD_USES_HDMI
186 int hdmi_cable_status;
187#endif
codeworkx62f02ba2012-05-20 12:00:36 +0200188};
189
190typedef enum _LOG_LEVEL {
191 HWC_LOG_DEBUG,
192 HWC_LOG_WARNING,
193 HWC_LOG_ERROR,
194} HWC_LOG_LEVEL;
195
196#define SEC_HWC_LOG_TAG "SECHWC_LOG"
197
198#ifdef HWC_DEBUG
199#define SEC_HWC_Log(a, ...) ((void)_SEC_HWC_Log(a, SEC_HWC_LOG_TAG, __VA_ARGS__))
200#else
201#define SEC_HWC_Log(a, ...) \
202 do { \
espenfjo34f9d5d2012-12-01 18:52:36 +0100203 if (a == HWC_LOG_ERROR) \
204 ((void)_SEC_HWC_Log(a, SEC_HWC_LOG_TAG, __VA_ARGS__)); \
codeworkx62f02ba2012-05-20 12:00:36 +0200205 } while (0)
206#endif
207
208extern void _SEC_HWC_Log(HWC_LOG_LEVEL logLevel, const char *tag, const char *msg, ...);
209
210/* copied from gralloc module ..*/
211typedef struct {
212 native_handle_t base;
213
214 /* These fields can be sent cross process. They are also valid
215 * to duplicate within the same process.
216 *
217 * A table is stored within psPrivateData on gralloc_module_t (this
218 * is obviously per-process) which maps stamps to a mapped
219 * PVRSRV_CLIENT_MEM_INFO in that process. Each map entry has a lock
220 * count associated with it, satisfying the requirements of the
221 * Android API. This also prevents us from leaking maps/allocations.
222 *
223 * This table has entries inserted either by alloc()
224 * (alloc_device_t) or map() (gralloc_module_t). Entries are removed
225 * by free() (alloc_device_t) and unmap() (gralloc_module_t).
226 *
227 * As a special case for framebuffer_device_t, framebuffer_open()
228 * will add and framebuffer_close() will remove from this table.
229 */
230
231#define IMG_NATIVE_HANDLE_NUMFDS 1
232 /* The `fd' field is used to "export" a meminfo to another process.
233 * Therefore, it is allocated by alloc_device_t, and consumed by
234 * gralloc_module_t. The framebuffer_device_t does not need a handle,
235 * and the special value IMG_FRAMEBUFFER_FD is used instead.
236 */
237 int fd;
238
239#if 1
240 int format;
241 int magic;
242 int flags;
243 int size;
244 int offset;
245 int base_addr;
246#define IMG_NATIVE_HANDLE_NUMINTS ((sizeof(uint64_t) / sizeof(int)) + 4 + 6)
247#else
248#define IMG_NATIVE_HANDLE_NUMINTS ((sizeof(IMG_UINT64) / sizeof(int)) + 4)
249#endif
250 /* A KERNEL unique identifier for any exported kernel meminfo. Each
251 * exported kernel meminfo will have a unique stamp, but note that in
252 * userspace, several meminfos across multiple processes could have
253 * the same stamp. As the native_handle can be dup(2)'d, there could be
254 * multiple handles with the same stamp but different file descriptors.
255 */
256 uint64_t ui64Stamp;
257
258 /* We could live without this, but it lets us perform some additional
259 * validation on the client side. Normally, we'd have no visibility
260 * of the allocated usage, just the lock usage.
261 */
262 int usage;
263
264 /* In order to do efficient cache flushes we need the buffer dimensions
265 * and format. These are available on the android_native_buffer_t,
266 * but the platform doesn't pass them down to the graphics HAL.
267 *
268 * TODO: Ideally the platform would be modified to not require this.
269 */
270 int width;
271 int height;
272 int bpp;
273}
274__attribute__((aligned(sizeof(int)),packed)) sec_native_handle_t;
275
276int window_open (struct hwc_win_info_t *win, int id);
277int window_close (struct hwc_win_info_t *win);
278int window_set_pos (struct hwc_win_info_t *win);
279int window_get_info (struct hwc_win_info_t *win, int win_num);
280int window_pan_display(struct hwc_win_info_t *win);
281int window_show (struct hwc_win_info_t *win);
282int window_hide (struct hwc_win_info_t *win);
codeworkx39aefd02012-12-02 19:39:25 +0100283int window_get_global_lcd_info(struct hwc_context_t *ctx);
codeworkx62f02ba2012-05-20 12:00:36 +0200284
285int createFimc (s5p_fimc_t *fimc);
286int destroyFimc(s5p_fimc_t *fimc);
287int runFimc(struct hwc_context_t *ctx,
espenfjo34f9d5d2012-12-01 18:52:36 +0100288 struct sec_img *src_img, struct sec_rect *src_rect,
289 struct sec_img *dst_img, struct sec_rect *dst_rect,
290 uint32_t transform);
291int check_yuv_format(unsigned int color_format);
codeworkx62f02ba2012-05-20 12:00:36 +0200292
293#endif /* ANDROID_SEC_HWC_UTILS_H_*/