1 /*
2 * Copyright (c) 2011, The Linux Foundation. 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 The Linux Foundation 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
45 #define IOCTL_DEBUG 0
46
47 namespace overlay{
48
49 namespace mdp_wrapper{
50 /* FBIOGET_FSCREENINFO */
51 bool getFScreenInfo(int fd, fb_fix_screeninfo& finfo);
52
53 /* FBIOGET_VSCREENINFO */
54 bool getVScreenInfo(int fd, fb_var_screeninfo& vinfo);
55
56 /* FBIOPUT_VSCREENINFO */
57 bool setVScreenInfo(int fd, fb_var_screeninfo& vinfo);
58
59 /* MSM_ROTATOR_IOCTL_START */
60 bool startRotator(int fd, msm_rotator_img_info& rot);
61
62 /* MSM_ROTATOR_IOCTL_ROTATE */
63 bool rotate(int fd, msm_rotator_data_info& rot);
64
65 /* MSMFB_OVERLAY_SET */
66 bool setOverlay(int fd, mdp_overlay& ov);
67
68 /* MSMFB_OVERLAY_PREPARE */
69 bool validateAndSet(const int& fd, mdp_overlay_list& list);
70
71 /* MSM_ROTATOR_IOCTL_FINISH */
72 bool endRotator(int fd, int sessionId);
73
74 /* MSMFB_OVERLAY_UNSET */
75 bool unsetOverlay(int fd, int ovId);
76
77 /* MSMFB_OVERLAY_GET */
78 bool getOverlay(int fd, mdp_overlay& ov);
79
80 /* MSMFB_OVERLAY_PLAY */
81 bool play(int fd, msmfb_overlay_data& od);
82
83 /* MSMFB_OVERLAY_3D */
84 bool set3D(int fd, msmfb_overlay_3d& ov);
85
86 /* MSMFB_DISPLAY_COMMIT */
87 bool displayCommit(int fd);
88
89 /* MSMFB_WRITEBACK_INIT, MSMFB_WRITEBACK_START */
90 bool wbInitStart(int fbfd);
91
92 /* MSMFB_WRITEBACK_STOP, MSMFB_WRITEBACK_TERMINATE */
93 bool wbStopTerminate(int fbfd);
94
95 /* MSMFB_WRITEBACK_QUEUE_BUFFER */
96 bool wbQueueBuffer(int fbfd, struct msmfb_data& fbData);
97
98 /* MSMFB_WRITEBACK_DEQUEUE_BUFFER */
99 bool wbDequeueBuffer(int fbfd, struct msmfb_data& fbData);
100
101 /* the following are helper functions for dumping
102 * msm_mdp and friends*/
103 void dump(const char* const s, const msmfb_overlay_data& ov);
104 void dump(const char* const s, const msmfb_data& ov);
105 void dump(const char* const s, const mdp_overlay& ov);
106 void dump(const char* const s, const msmfb_overlay_3d& ov);
107 void dump(const char* const s, const uint32_t u[], uint32_t cnt);
108 void dump(const char* const s, const msmfb_img& ov);
109 void dump(const char* const s, const mdp_rect& ov);
110
111 /* and rotator */
112 void dump(const char* const s, const msm_rotator_img_info& rot);
113 void dump(const char* const s, const msm_rotator_data_info& rot);
114
115 /* info */
116 void dump(const char* const s, const fb_fix_screeninfo& finfo);
117 void dump(const char* const s, const fb_var_screeninfo& vinfo);
118
119 //---------------Inlines -------------------------------------
120
getFScreenInfo(int fd,fb_fix_screeninfo & finfo)121 inline bool getFScreenInfo(int fd, fb_fix_screeninfo& finfo) {
122 if (ioctl(fd, FBIOGET_FSCREENINFO, &finfo) < 0) {
123 ALOGE("Failed to call ioctl FBIOGET_FSCREENINFO err=%s",
124 strerror(errno));
125 return false;
126 }
127 return true;
128 }
129
getVScreenInfo(int fd,fb_var_screeninfo & vinfo)130 inline bool getVScreenInfo(int fd, fb_var_screeninfo& vinfo) {
131 if (ioctl(fd, FBIOGET_VSCREENINFO, &vinfo) < 0) {
132 ALOGE("Failed to call ioctl FBIOGET_VSCREENINFO err=%s",
133 strerror(errno));
134 return false;
135 }
136 return true;
137 }
138
setVScreenInfo(int fd,fb_var_screeninfo & vinfo)139 inline bool setVScreenInfo(int fd, fb_var_screeninfo& vinfo) {
140 if (ioctl(fd, FBIOPUT_VSCREENINFO, &vinfo) < 0) {
141 ALOGE("Failed to call ioctl FBIOPUT_VSCREENINFO err=%s",
142 strerror(errno));
143 return false;
144 }
145 return true;
146 }
147
startRotator(int fd,msm_rotator_img_info & rot)148 inline bool startRotator(int fd, msm_rotator_img_info& rot) {
149 if (ioctl(fd, MSM_ROTATOR_IOCTL_START, &rot) < 0){
150 ALOGE("Failed to call ioctl MSM_ROTATOR_IOCTL_START err=%s",
151 strerror(errno));
152 return false;
153 }
154 return true;
155 }
156
rotate(int fd,msm_rotator_data_info & rot)157 inline bool rotate(int fd, msm_rotator_data_info& rot) {
158 if (ioctl(fd, MSM_ROTATOR_IOCTL_ROTATE, &rot) < 0) {
159 ALOGE("Failed to call ioctl MSM_ROTATOR_IOCTL_ROTATE err=%s",
160 strerror(errno));
161 return false;
162 }
163 return true;
164 }
165
setOverlay(int fd,mdp_overlay & ov)166 inline bool setOverlay(int fd, mdp_overlay& ov) {
167 if (ioctl(fd, MSMFB_OVERLAY_SET, &ov) < 0) {
168 ALOGE("Failed to call ioctl MSMFB_OVERLAY_SET err=%s",
169 strerror(errno));
170 return false;
171 }
172 return true;
173 }
174
validateAndSet(const int & fd,mdp_overlay_list & list)175 inline bool validateAndSet(const int& fd, mdp_overlay_list& list) {
176 if (ioctl(fd, MSMFB_OVERLAY_PREPARE, &list) < 0) {
177 ALOGD_IF(IOCTL_DEBUG, "Failed to call ioctl MSMFB_OVERLAY_PREPARE "
178 "err=%s", strerror(errno));
179 return false;
180 }
181 return true;
182 }
183
endRotator(int fd,uint32_t sessionId)184 inline bool endRotator(int fd, uint32_t sessionId) {
185 if (ioctl(fd, MSM_ROTATOR_IOCTL_FINISH, &sessionId) < 0) {
186 ALOGE("Failed to call ioctl MSM_ROTATOR_IOCTL_FINISH err=%s",
187 strerror(errno));
188 return false;
189 }
190 return true;
191 }
192
unsetOverlay(int fd,int ovId)193 inline bool unsetOverlay(int fd, int ovId) {
194 if (ioctl(fd, MSMFB_OVERLAY_UNSET, &ovId) < 0) {
195 ALOGE("Failed to call ioctl MSMFB_OVERLAY_UNSET err=%s",
196 strerror(errno));
197 return false;
198 }
199 return true;
200 }
201
getOverlay(int fd,mdp_overlay & ov)202 inline bool getOverlay(int fd, mdp_overlay& ov) {
203 if (ioctl(fd, MSMFB_OVERLAY_GET, &ov) < 0) {
204 ALOGE("Failed to call ioctl MSMFB_OVERLAY_GET err=%s",
205 strerror(errno));
206 return false;
207 }
208 return true;
209 }
210
play(int fd,msmfb_overlay_data & od)211 inline bool play(int fd, msmfb_overlay_data& od) {
212 if (ioctl(fd, MSMFB_OVERLAY_PLAY, &od) < 0) {
213 ALOGE("Failed to call ioctl MSMFB_OVERLAY_PLAY err=%s",
214 strerror(errno));
215 return false;
216 }
217 return true;
218 }
219
set3D(int fd,msmfb_overlay_3d & ov)220 inline bool set3D(int fd, msmfb_overlay_3d& ov) {
221 if (ioctl(fd, MSMFB_OVERLAY_3D, &ov) < 0) {
222 ALOGE("Failed to call ioctl MSMFB_OVERLAY_3D err=%s",
223 strerror(errno));
224 return false;
225 }
226 return true;
227 }
228
displayCommit(int fd,mdp_display_commit & info)229 inline bool displayCommit(int fd, mdp_display_commit& info) {
230 if(ioctl(fd, MSMFB_DISPLAY_COMMIT, &info) == -1) {
231 ALOGE("Failed to call ioctl MSMFB_DISPLAY_COMMIT err=%s",
232 strerror(errno));
233 return false;
234 }
235 return true;
236 }
237
wbInitStart(int fbfd)238 inline bool wbInitStart(int fbfd) {
239 if(ioctl(fbfd, MSMFB_WRITEBACK_INIT, NULL) < 0) {
240 ALOGE("Failed to call ioctl MSMFB_WRITEBACK_INIT err=%s",
241 strerror(errno));
242 return false;
243 }
244 if(ioctl(fbfd, MSMFB_WRITEBACK_START, NULL) < 0) {
245 ALOGE("Failed to call ioctl MSMFB_WRITEBACK_START err=%s",
246 strerror(errno));
247 return false;
248 }
249 return true;
250 }
251
wbStopTerminate(int fbfd)252 inline bool wbStopTerminate(int fbfd) {
253 if(ioctl(fbfd, MSMFB_WRITEBACK_STOP, NULL) < 0) {
254 ALOGE("Failed to call ioctl MSMFB_WRITEBACK_STOP err=%s",
255 strerror(errno));
256 return false;
257 }
258 if(ioctl(fbfd, MSMFB_WRITEBACK_TERMINATE, NULL) < 0) {
259 ALOGE("Failed to call ioctl MSMFB_WRITEBACK_TERMINATE err=%s",
260 strerror(errno));
261 return false;
262 }
263 return true;
264 }
265
wbQueueBuffer(int fbfd,struct msmfb_data & fbData)266 inline bool wbQueueBuffer(int fbfd, struct msmfb_data& fbData) {
267 if(ioctl(fbfd, MSMFB_WRITEBACK_QUEUE_BUFFER, &fbData) < 0) {
268 ALOGE("Failed to call ioctl MSMFB_WRITEBACK_QUEUE_BUFFER err=%s",
269 strerror(errno));
270 return false;
271 }
272 return true;
273 }
274
wbDequeueBuffer(int fbfd,struct msmfb_data & fbData)275 inline bool wbDequeueBuffer(int fbfd, struct msmfb_data& fbData) {
276 if(ioctl(fbfd, MSMFB_WRITEBACK_DEQUEUE_BUFFER, &fbData) < 0) {
277 ALOGE("Failed to call ioctl MSMFB_WRITEBACK_DEQUEUE_BUFFER err=%s",
278 strerror(errno));
279 return false;
280 }
281 return true;
282 }
283
284 /* dump funcs */
dump(const char * const s,const msmfb_overlay_data & ov)285 inline void dump(const char* const s, const msmfb_overlay_data& ov) {
286 ALOGE("%s msmfb_overlay_data id=%d",
287 s, ov.id);
288 dump("data", ov.data);
289 }
dump(const char * const s,const msmfb_data & ov)290 inline void dump(const char* const s, const msmfb_data& ov) {
291 ALOGE("%s msmfb_data offset=%d memid=%d id=%d flags=0x%x priv=%d",
292 s, ov.offset, ov.memory_id, ov.id, ov.flags, ov.priv);
293 }
dump(const char * const s,const mdp_overlay & ov)294 inline void dump(const char* const s, const mdp_overlay& ov) {
295 ALOGE("%s mdp_overlay z=%d fg=%d alpha=%d mask=%d flags=0x%x id=%d",
296 s, ov.z_order, ov.is_fg, ov.alpha,
297 ov.transp_mask, ov.flags, ov.id);
298 dump("src", ov.src);
299 dump("src_rect", ov.src_rect);
300 dump("dst_rect", ov.dst_rect);
301 /*
302 Commented off to prevent verbose logging, since user_data could have 8 or so
303 fields which are mostly 0
304 dump("user_data", ov.user_data,
305 sizeof(ov.user_data)/sizeof(ov.user_data[0]));
306 */
307 }
dump(const char * const s,const msmfb_img & ov)308 inline void dump(const char* const s, const msmfb_img& ov) {
309 ALOGE("%s msmfb_img w=%d h=%d format=%d %s",
310 s, ov.width, ov.height, ov.format,
311 overlay::utils::getFormatString(ov.format));
312 }
dump(const char * const s,const mdp_rect & ov)313 inline void dump(const char* const s, const mdp_rect& ov) {
314 ALOGE("%s mdp_rect x=%d y=%d w=%d h=%d",
315 s, ov.x, ov.y, ov.w, ov.h);
316 }
317
dump(const char * const s,const msmfb_overlay_3d & ov)318 inline void dump(const char* const s, const msmfb_overlay_3d& ov) {
319 ALOGE("%s msmfb_overlay_3d 3d=%d w=%d h=%d",
320 s, ov.is_3d, ov.width, ov.height);
321
322 }
dump(const char * const s,const uint32_t u[],uint32_t cnt)323 inline void dump(const char* const s, const uint32_t u[], uint32_t cnt) {
324 ALOGE("%s user_data cnt=%d", s, cnt);
325 for(uint32_t i=0; i < cnt; ++i) {
326 ALOGE("i=%d val=%d", i, u[i]);
327 }
328 }
dump(const char * const s,const msm_rotator_img_info & rot)329 inline void dump(const char* const s, const msm_rotator_img_info& rot) {
330 ALOGE("%s msm_rotator_img_info sessid=%u dstx=%d dsty=%d rot=%d, ena=%d scale=%d",
331 s, rot.session_id, rot.dst_x, rot.dst_y,
332 rot.rotations, rot.enable, rot.downscale_ratio);
333 dump("src", rot.src);
334 dump("dst", rot.dst);
335 dump("src_rect", rot.src_rect);
336 }
dump(const char * const s,const msm_rotator_data_info & rot)337 inline void dump(const char* const s, const msm_rotator_data_info& rot) {
338 ALOGE("%s msm_rotator_data_info sessid=%u verkey=%d",
339 s, rot.session_id, rot.version_key);
340 dump("src", rot.src);
341 dump("dst", rot.dst);
342 dump("src_chroma", rot.src_chroma);
343 dump("dst_chroma", rot.dst_chroma);
344 }
dump(const char * const s,const fb_fix_screeninfo & finfo)345 inline void dump(const char* const s, const fb_fix_screeninfo& finfo) {
346 ALOGE("%s fb_fix_screeninfo type=%d", s, finfo.type);
347 }
dump(const char * const s,const fb_var_screeninfo & vinfo)348 inline void dump(const char* const s, const fb_var_screeninfo& vinfo) {
349 ALOGE("%s fb_var_screeninfo xres=%d yres=%d",
350 s, vinfo.xres, vinfo.yres);
351 }
352
353 } // mdp_wrapper
354
355 } // overlay
356
357 #endif // MDP_WRAPPER_H
358