blob: 4cfd3e09f428b431f84d9972349acccc882ea8c9 [file] [log] [blame]
Naseer Ahmed29a26812012-06-14 00:56:20 -07001/*
2* Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved.
3*
4* Redistribution and use in source and binary forms, with or without
5* modification, are permitted provided that the following conditions are
6* met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above
10* copyright notice, this list of conditions and the following
11* disclaimer in the documentation and/or other materials provided
12* with the distribution.
13* * Neither the name of Code Aurora Forum, Inc. nor the names of its
14* contributors may be used to endorse or promote products derived
15* from this software without specific prior written permission.
16*
17* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28*/
29
30#ifndef MDP_WRAPPER_H
31#define MDP_WRAPPER_H
32
33/*
34* In order to make overlay::mdp_wrapper shorter, please do something like:
35* namespace mdpwrap = overlay::mdp_wrapper;
36* */
37
38#include <linux/msm_mdp.h>
39#include <linux/msm_rotator.h>
40#include <sys/ioctl.h>
41#include <utils/Log.h>
42#include <errno.h>
43#include "overlayUtils.h"
44
45namespace overlay{
46
47namespace mdp_wrapper{
48/* FBIOGET_FSCREENINFO */
49bool getFScreenInfo(int fd, fb_fix_screeninfo& finfo);
50
51/* FBIOGET_VSCREENINFO */
52bool getVScreenInfo(int fd, fb_var_screeninfo& vinfo);
53
54/* FBIOPUT_VSCREENINFO */
55bool setVScreenInfo(int fd, fb_var_screeninfo& vinfo);
56
57/* MSM_ROTATOR_IOCTL_START */
58bool startRotator(int fd, msm_rotator_img_info& rot);
59
60/* MSM_ROTATOR_IOCTL_ROTATE */
61bool rotate(int fd, msm_rotator_data_info& rot);
62
63/* MSMFB_OVERLAY_SET */
64bool setOverlay(int fd, mdp_overlay& ov);
65
66/* MSM_ROTATOR_IOCTL_FINISH */
67bool endRotator(int fd, int sessionId);
68
69/* MSMFB_OVERLAY_UNSET */
70bool unsetOverlay(int fd, int ovId);
71
72/* MSMFB_OVERLAY_GET */
73bool getOverlay(int fd, mdp_overlay& ov);
74
75/* MSMFB_OVERLAY_PLAY */
76bool play(int fd, msmfb_overlay_data& od);
77
78/* MSMFB_OVERLAY_PLAY_WAIT */
79bool playWait(int fd, msmfb_overlay_data& od);
80
81/* MSMFB_OVERLAY_3D */
82bool set3D(int fd, msmfb_overlay_3d& ov);
83
84/* the following are helper functions for dumping
85 * msm_mdp and friends*/
86void dump(const char* const s, const msmfb_overlay_data& ov);
87void dump(const char* const s, const msmfb_data& ov);
88void dump(const char* const s, const mdp_overlay& ov);
89void dump(const char* const s, const msmfb_overlay_3d& ov);
90void dump(const char* const s, const uint32_t u[], uint32_t cnt);
91void dump(const char* const s, const msmfb_img& ov);
92void dump(const char* const s, const mdp_rect& ov);
93
94/* and rotator */
95void dump(const char* const s, const msm_rotator_img_info& rot);
96void dump(const char* const s, const msm_rotator_data_info& rot);
97
98/* info */
99void dump(const char* const s, const fb_fix_screeninfo& finfo);
100void dump(const char* const s, const fb_var_screeninfo& vinfo);
101
102//---------------Inlines -------------------------------------
103
104inline bool getFScreenInfo(int fd, fb_fix_screeninfo& finfo) {
105 if (ioctl(fd, FBIOGET_FSCREENINFO, &finfo) == -1) {
106 ALOGE("Failed to call ioctl FBIOGET_FSCREENINFO err=%d", errno);
107 return false;
108 }
109 return true;
110}
111
112inline bool getVScreenInfo(int fd, fb_var_screeninfo& vinfo) {
113 if (ioctl(fd, FBIOGET_VSCREENINFO, &vinfo) == -1) {
114 ALOGE("Failed to call ioctl FBIOGET_VSCREENINFO err=%d", errno);
115 return false;
116 }
117 return true;
118}
119
120inline bool setVScreenInfo(int fd, fb_var_screeninfo& vinfo) {
121 if (ioctl(fd, FBIOPUT_VSCREENINFO, &vinfo) == -1) {
122 ALOGE("Failed to call ioctl FBIOPUT_VSCREENINFO err=%d", errno);
123 return false;
124 }
125 return true;
126}
127
128inline bool startRotator(int fd, msm_rotator_img_info& rot) {
129 if (ioctl(fd, MSM_ROTATOR_IOCTL_START, &rot) == -1){
130 ALOGE("Failed to call ioctl MSM_ROTATOR_IOCTL_START err=%d", errno);
131 return false;
132 }
133 return true;
134}
135
136inline bool rotate(int fd, msm_rotator_data_info& rot) {
137 if (ioctl(fd, MSM_ROTATOR_IOCTL_ROTATE, &rot) == -1) {
138 ALOGE("Failed to call ioctl MSM_ROTATOR_IOCTL_ROTATE err=%d", errno);
139 return false;
140 }
141 return true;
142}
143
144inline bool setOverlay(int fd, mdp_overlay& ov) {
145 if (ioctl(fd, MSMFB_OVERLAY_SET, &ov) == -1) {
146 ALOGE("Failed to call ioctl MSMFB_OVERLAY_SET err=%d", errno);
147 return false;
148 }
149 return true;
150}
151
152inline bool endRotator(int fd, int sessionId) {
153 if (ioctl(fd, MSM_ROTATOR_IOCTL_FINISH, &sessionId) == -1) {
154 ALOGE("Failed to call ioctl MSM_ROTATOR_IOCTL_FINISH err=%d", errno);
155 return false;
156 }
157 return true;
158}
159
160inline bool unsetOverlay(int fd, int ovId) {
161 if (ioctl(fd, MSMFB_OVERLAY_UNSET, &ovId) == -1) {
162 ALOGE("Failed to call ioctl MSMFB_OVERLAY_UNSET err=%d", errno);
163 return false;
164 }
165 return true;
166}
167
168inline bool getOverlay(int fd, mdp_overlay& ov) {
169 if (ioctl(fd, MSMFB_OVERLAY_GET, &ov) == -1) {
170 ALOGE("Failed to call ioctl MSMFB_OVERLAY_GET err=%d", errno);
171 return false;
172 }
173 return true;
174}
175
176inline bool play(int fd, msmfb_overlay_data& od) {
177 if (ioctl(fd, MSMFB_OVERLAY_PLAY, &od) == -1) {
178 ALOGE("Failed to call ioctl MSMFB_OVERLAY_PLAY err=%d", errno);
179 return false;
180 }
181 return true;
182}
183
184inline bool playWait(int fd, msmfb_overlay_data& od) {
185 if (ioctl(fd, MSMFB_OVERLAY_PLAY_WAIT, &od) == -1) {
186 ALOGE("Failed to call ioctl MSMFB_OVERLAY_PLAY_WAIT err=%d", errno);
187 return false;
188 }
189 return true;
190}
191
192inline bool set3D(int fd, msmfb_overlay_3d& ov) {
193 if (ioctl(fd, MSMFB_OVERLAY_3D, &ov) == -1) {
194 ALOGE("Failed to call ioctl MSMFB_OVERLAY_3D err=%d", errno);
195 return false;
196 }
197 return true;
198}
199
200/* dump funcs */
201inline void dump(const char* const s, const msmfb_overlay_data& ov) {
202 ALOGE("%s msmfb_overlay_data id=%d",
203 s, ov.id);
204 dump("data", ov.data);
205}
206inline void dump(const char* const s, const msmfb_data& ov) {
207 ALOGE("%s msmfb_data offset=%d memid=%d id=%d flags=0x%x priv=%d",
208 s, ov.offset, ov.memory_id, ov.id, ov.flags, ov.priv);
209}
210inline void dump(const char* const s, const mdp_overlay& ov) {
211 ALOGE("%s mdp_overlay z=%d fg=%d alpha=%d mask=%d flags=0x%x id=%d",
212 s, ov.z_order, ov.is_fg, ov.alpha,
213 ov.transp_mask, ov.flags, ov.id);
214 dump("src", ov.src);
215 dump("src_rect", ov.src_rect);
216 dump("dst_rect", ov.dst_rect);
217 dump("user_data", ov.user_data,
218 sizeof(ov.user_data)/sizeof(ov.user_data[0]));
219}
220inline void dump(const char* const s, const msmfb_img& ov) {
221 ALOGE("%s msmfb_img w=%d h=%d format=%d %s",
222 s, ov.width, ov.height, ov.format,
223 overlay::utils::getFormatString(ov.format));
224}
225inline void dump(const char* const s, const mdp_rect& ov) {
226 ALOGE("%s mdp_rect x=%d y=%d w=%d h=%d",
227 s, ov.x, ov.y, ov.w, ov.h);
228}
229
230inline void dump(const char* const s, const msmfb_overlay_3d& ov) {
231 ALOGE("%s msmfb_overlay_3d 3d=%d w=%d h=%d",
232 s, ov.is_3d, ov.width, ov.height);
233
234}
235inline void dump(const char* const s, const uint32_t u[], uint32_t cnt) {
236 ALOGE("%s user_data cnt=%d", s, cnt);
237 for(uint32_t i=0; i < cnt; ++i) {
238 ALOGE("i=%d val=%d", i, u[i]);
239 }
240}
241inline void dump(const char* const s, const msm_rotator_img_info& rot) {
242 ALOGE("%s msm_rotator_img_info sessid=%d dstx=%d dsty=%d rot=%d, ena=%d",
243 s, rot.session_id, rot.dst_x, rot.dst_y,
244 rot.rotations, rot.enable);
245 dump("src", rot.src);
246 dump("dst", rot.dst);
247 dump("src_rect", rot.src_rect);
248}
249inline void dump(const char* const s, const msm_rotator_data_info& rot) {
250 ALOGE("%s msm_rotator_data_info sessid=%d verkey=%d",
251 s, rot.session_id, rot.version_key);
252 dump("src", rot.src);
253 dump("dst", rot.dst);
254 dump("src_chroma", rot.src_chroma);
255 dump("dst_chroma", rot.dst_chroma);
256}
257inline void dump(const char* const s, const fb_fix_screeninfo& finfo) {
258 ALOGE("%s fb_fix_screeninfo type=%d", s, finfo.type);
259}
260inline void dump(const char* const s, const fb_var_screeninfo& vinfo) {
261 ALOGE("%s fb_var_screeninfo xres=%d yres=%d",
262 s, vinfo.xres, vinfo.yres);
263}
264
265
266} // mdp_wrapper
267
268} // overlay
269
270#endif // MDP_WRAPPER_H