blob: 8c5f624ffe51e9510582e7563745814f9827e016 [file] [log] [blame]
Naseer Ahmed29a26812012-06-14 00:56:20 -07001/*
Naseer Ahmedf48aef62012-07-20 09:05:53 -07002* Copyright (c) 2011, Code Aurora Forum. All rights reserved.
Naseer Ahmed29a26812012-06-14 00:56:20 -07003*
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 */
Naseer Ahmedf48aef62012-07-20 09:05:53 -070079bool waitForVsync(int fd, msmfb_overlay_data& od);
Naseer Ahmed29a26812012-06-14 00:56:20 -070080
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) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700105 if (ioctl(fd, FBIOGET_FSCREENINFO, &finfo) < 0) {
106 ALOGE("Failed to call ioctl FBIOGET_FSCREENINFO err=%s",
107 strerror(errno));
Naseer Ahmed29a26812012-06-14 00:56:20 -0700108 return false;
109 }
110 return true;
111}
112
113inline bool getVScreenInfo(int fd, fb_var_screeninfo& vinfo) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700114 if (ioctl(fd, FBIOGET_VSCREENINFO, &vinfo) < 0) {
115 ALOGE("Failed to call ioctl FBIOGET_VSCREENINFO err=%s",
116 strerror(errno));
Naseer Ahmed29a26812012-06-14 00:56:20 -0700117 return false;
118 }
119 return true;
120}
121
122inline bool setVScreenInfo(int fd, fb_var_screeninfo& vinfo) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700123 if (ioctl(fd, FBIOPUT_VSCREENINFO, &vinfo) < 0) {
124 ALOGE("Failed to call ioctl FBIOPUT_VSCREENINFO err=%s",
125 strerror(errno));
Naseer Ahmed29a26812012-06-14 00:56:20 -0700126 return false;
127 }
128 return true;
129}
130
131inline bool startRotator(int fd, msm_rotator_img_info& rot) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700132 if (ioctl(fd, MSM_ROTATOR_IOCTL_START, &rot) < 0){
133 ALOGE("Failed to call ioctl MSM_ROTATOR_IOCTL_START err=%s",
134 strerror(errno));
Naseer Ahmed29a26812012-06-14 00:56:20 -0700135 return false;
136 }
137 return true;
138}
139
140inline bool rotate(int fd, msm_rotator_data_info& rot) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700141 if (ioctl(fd, MSM_ROTATOR_IOCTL_ROTATE, &rot) < 0) {
142 ALOGE("Failed to call ioctl MSM_ROTATOR_IOCTL_ROTATE err=%s",
143 strerror(errno));
Naseer Ahmed29a26812012-06-14 00:56:20 -0700144 return false;
145 }
146 return true;
147}
148
149inline bool setOverlay(int fd, mdp_overlay& ov) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700150 if (ioctl(fd, MSMFB_OVERLAY_SET, &ov) < 0) {
151 ALOGE("Failed to call ioctl MSMFB_OVERLAY_SET err=%s",
152 strerror(errno));
Naseer Ahmed29a26812012-06-14 00:56:20 -0700153 return false;
154 }
155 return true;
156}
157
158inline bool endRotator(int fd, int sessionId) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700159 if (ioctl(fd, MSM_ROTATOR_IOCTL_FINISH, &sessionId) < 0) {
160 ALOGE("Failed to call ioctl MSM_ROTATOR_IOCTL_FINISH err=%s",
161 strerror(errno));
Naseer Ahmed29a26812012-06-14 00:56:20 -0700162 return false;
163 }
164 return true;
165}
166
167inline bool unsetOverlay(int fd, int ovId) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700168 if (ioctl(fd, MSMFB_OVERLAY_UNSET, &ovId) < 0) {
169 ALOGE("Failed to call ioctl MSMFB_OVERLAY_UNSET err=%s",
170 strerror(errno));
Naseer Ahmed29a26812012-06-14 00:56:20 -0700171 return false;
172 }
173 return true;
174}
175
176inline bool getOverlay(int fd, mdp_overlay& ov) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700177 if (ioctl(fd, MSMFB_OVERLAY_GET, &ov) < 0) {
178 ALOGE("Failed to call ioctl MSMFB_OVERLAY_GET err=%s",
179 strerror(errno));
Naseer Ahmed29a26812012-06-14 00:56:20 -0700180 return false;
181 }
182 return true;
183}
184
185inline bool play(int fd, msmfb_overlay_data& od) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700186 if (ioctl(fd, MSMFB_OVERLAY_PLAY, &od) < 0) {
187 ALOGE("Failed to call ioctl MSMFB_OVERLAY_PLAY err=%s",
188 strerror(errno));
Naseer Ahmed29a26812012-06-14 00:56:20 -0700189 return false;
190 }
191 return true;
192}
193
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700194inline bool waitForVsync(int fd, msmfb_overlay_data& od) {
195 if (ioctl(fd, MSMFB_OVERLAY_PLAY_WAIT, &od) < 0) {
196 ALOGE("Failed to call ioctl MSMFB_OVERLAY_PLAY_WAIT err=%s",
197 strerror(errno));
Naseer Ahmed29a26812012-06-14 00:56:20 -0700198 return false;
199 }
200 return true;
201}
202
203inline bool set3D(int fd, msmfb_overlay_3d& ov) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700204 if (ioctl(fd, MSMFB_OVERLAY_3D, &ov) < 0) {
205 ALOGE("Failed to call ioctl MSMFB_OVERLAY_3D err=%s",
206 strerror(errno));
Naseer Ahmed29a26812012-06-14 00:56:20 -0700207 return false;
208 }
209 return true;
210}
211
212/* dump funcs */
213inline void dump(const char* const s, const msmfb_overlay_data& ov) {
214 ALOGE("%s msmfb_overlay_data id=%d",
215 s, ov.id);
216 dump("data", ov.data);
217}
218inline void dump(const char* const s, const msmfb_data& ov) {
219 ALOGE("%s msmfb_data offset=%d memid=%d id=%d flags=0x%x priv=%d",
220 s, ov.offset, ov.memory_id, ov.id, ov.flags, ov.priv);
221}
222inline void dump(const char* const s, const mdp_overlay& ov) {
223 ALOGE("%s mdp_overlay z=%d fg=%d alpha=%d mask=%d flags=0x%x id=%d",
224 s, ov.z_order, ov.is_fg, ov.alpha,
225 ov.transp_mask, ov.flags, ov.id);
226 dump("src", ov.src);
227 dump("src_rect", ov.src_rect);
228 dump("dst_rect", ov.dst_rect);
229 dump("user_data", ov.user_data,
230 sizeof(ov.user_data)/sizeof(ov.user_data[0]));
231}
232inline void dump(const char* const s, const msmfb_img& ov) {
233 ALOGE("%s msmfb_img w=%d h=%d format=%d %s",
234 s, ov.width, ov.height, ov.format,
235 overlay::utils::getFormatString(ov.format));
236}
237inline void dump(const char* const s, const mdp_rect& ov) {
238 ALOGE("%s mdp_rect x=%d y=%d w=%d h=%d",
239 s, ov.x, ov.y, ov.w, ov.h);
240}
241
242inline void dump(const char* const s, const msmfb_overlay_3d& ov) {
243 ALOGE("%s msmfb_overlay_3d 3d=%d w=%d h=%d",
244 s, ov.is_3d, ov.width, ov.height);
245
246}
247inline void dump(const char* const s, const uint32_t u[], uint32_t cnt) {
248 ALOGE("%s user_data cnt=%d", s, cnt);
249 for(uint32_t i=0; i < cnt; ++i) {
250 ALOGE("i=%d val=%d", i, u[i]);
251 }
252}
253inline void dump(const char* const s, const msm_rotator_img_info& rot) {
254 ALOGE("%s msm_rotator_img_info sessid=%d dstx=%d dsty=%d rot=%d, ena=%d",
255 s, rot.session_id, rot.dst_x, rot.dst_y,
256 rot.rotations, rot.enable);
257 dump("src", rot.src);
258 dump("dst", rot.dst);
259 dump("src_rect", rot.src_rect);
260}
261inline void dump(const char* const s, const msm_rotator_data_info& rot) {
262 ALOGE("%s msm_rotator_data_info sessid=%d verkey=%d",
263 s, rot.session_id, rot.version_key);
264 dump("src", rot.src);
265 dump("dst", rot.dst);
266 dump("src_chroma", rot.src_chroma);
267 dump("dst_chroma", rot.dst_chroma);
268}
269inline void dump(const char* const s, const fb_fix_screeninfo& finfo) {
270 ALOGE("%s fb_fix_screeninfo type=%d", s, finfo.type);
271}
272inline void dump(const char* const s, const fb_var_screeninfo& vinfo) {
273 ALOGE("%s fb_var_screeninfo xres=%d yres=%d",
274 s, vinfo.xres, vinfo.yres);
275}
276
Naseer Ahmed29a26812012-06-14 00:56:20 -0700277} // mdp_wrapper
278
279} // overlay
280
281#endif // MDP_WRAPPER_H