blob: 1aada9e29b49c113cbef98bfd477d659c799884e [file] [log] [blame]
Naseer Ahmed29a26812012-06-14 00:56:20 -07001/*
Naseer Ahmed758bfc52012-11-28 17:02:08 -05002* Copyright (c) 2011, The Linux Foundation. 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.
Naseer Ahmed758bfc52012-11-28 17:02:08 -050013* * Neither the name of The Linux Foundation nor the names of its
Naseer Ahmed29a26812012-06-14 00:56:20 -070014* 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
Naseer Ahmedabd76882014-06-30 11:10:14 -040033#define ATRACE_TAG (ATRACE_TAG_GRAPHICS | ATRACE_TAG_HAL)
34
Naseer Ahmed29a26812012-06-14 00:56:20 -070035/*
36* In order to make overlay::mdp_wrapper shorter, please do something like:
37* namespace mdpwrap = overlay::mdp_wrapper;
38* */
39
40#include <linux/msm_mdp.h>
41#include <linux/msm_rotator.h>
42#include <sys/ioctl.h>
43#include <utils/Log.h>
Naseer Ahmedabd76882014-06-30 11:10:14 -040044#include <utils/Trace.h>
Naseer Ahmed29a26812012-06-14 00:56:20 -070045#include <errno.h>
46#include "overlayUtils.h"
47
Saurabh Shaha36be922013-12-16 18:18:39 -080048#define IOCTL_DEBUG 0
49
Naseer Ahmed29a26812012-06-14 00:56:20 -070050namespace overlay{
51
52namespace mdp_wrapper{
53/* FBIOGET_FSCREENINFO */
54bool getFScreenInfo(int fd, fb_fix_screeninfo& finfo);
55
56/* FBIOGET_VSCREENINFO */
57bool getVScreenInfo(int fd, fb_var_screeninfo& vinfo);
58
59/* FBIOPUT_VSCREENINFO */
60bool setVScreenInfo(int fd, fb_var_screeninfo& vinfo);
61
62/* MSM_ROTATOR_IOCTL_START */
63bool startRotator(int fd, msm_rotator_img_info& rot);
64
65/* MSM_ROTATOR_IOCTL_ROTATE */
66bool rotate(int fd, msm_rotator_data_info& rot);
67
68/* MSMFB_OVERLAY_SET */
69bool setOverlay(int fd, mdp_overlay& ov);
70
Saurabh Shaha36be922013-12-16 18:18:39 -080071/* MSMFB_OVERLAY_PREPARE */
72bool validateAndSet(const int& fd, mdp_overlay_list& list);
73
Naseer Ahmed29a26812012-06-14 00:56:20 -070074/* MSM_ROTATOR_IOCTL_FINISH */
75bool endRotator(int fd, int sessionId);
76
77/* MSMFB_OVERLAY_UNSET */
78bool unsetOverlay(int fd, int ovId);
79
80/* MSMFB_OVERLAY_GET */
81bool getOverlay(int fd, mdp_overlay& ov);
82
83/* MSMFB_OVERLAY_PLAY */
84bool play(int fd, msmfb_overlay_data& od);
85
Naseer Ahmed29a26812012-06-14 00:56:20 -070086/* MSMFB_OVERLAY_3D */
87bool set3D(int fd, msmfb_overlay_3d& ov);
88
Saurabh Shahc8118ac2013-06-27 10:03:19 -070089/* MSMFB_DISPLAY_COMMIT */
90bool displayCommit(int fd);
91
92/* MSMFB_WRITEBACK_INIT, MSMFB_WRITEBACK_START */
93bool wbInitStart(int fbfd);
94
95/* MSMFB_WRITEBACK_STOP, MSMFB_WRITEBACK_TERMINATE */
96bool wbStopTerminate(int fbfd);
97
98/* MSMFB_WRITEBACK_QUEUE_BUFFER */
99bool wbQueueBuffer(int fbfd, struct msmfb_data& fbData);
100
101/* MSMFB_WRITEBACK_DEQUEUE_BUFFER */
102bool wbDequeueBuffer(int fbfd, struct msmfb_data& fbData);
103
Naseer Ahmed29a26812012-06-14 00:56:20 -0700104/* the following are helper functions for dumping
105 * msm_mdp and friends*/
106void dump(const char* const s, const msmfb_overlay_data& ov);
107void dump(const char* const s, const msmfb_data& ov);
108void dump(const char* const s, const mdp_overlay& ov);
109void dump(const char* const s, const msmfb_overlay_3d& ov);
110void dump(const char* const s, const uint32_t u[], uint32_t cnt);
111void dump(const char* const s, const msmfb_img& ov);
112void dump(const char* const s, const mdp_rect& ov);
113
114/* and rotator */
115void dump(const char* const s, const msm_rotator_img_info& rot);
116void dump(const char* const s, const msm_rotator_data_info& rot);
117
118/* info */
119void dump(const char* const s, const fb_fix_screeninfo& finfo);
120void dump(const char* const s, const fb_var_screeninfo& vinfo);
121
122//---------------Inlines -------------------------------------
123
124inline bool getFScreenInfo(int fd, fb_fix_screeninfo& finfo) {
Naseer Ahmedabd76882014-06-30 11:10:14 -0400125 ATRACE_CALL();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700126 if (ioctl(fd, FBIOGET_FSCREENINFO, &finfo) < 0) {
127 ALOGE("Failed to call ioctl FBIOGET_FSCREENINFO err=%s",
128 strerror(errno));
Naseer Ahmed29a26812012-06-14 00:56:20 -0700129 return false;
130 }
131 return true;
132}
133
134inline bool getVScreenInfo(int fd, fb_var_screeninfo& vinfo) {
Naseer Ahmedabd76882014-06-30 11:10:14 -0400135 ATRACE_CALL();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700136 if (ioctl(fd, FBIOGET_VSCREENINFO, &vinfo) < 0) {
137 ALOGE("Failed to call ioctl FBIOGET_VSCREENINFO err=%s",
138 strerror(errno));
Naseer Ahmed29a26812012-06-14 00:56:20 -0700139 return false;
140 }
141 return true;
142}
143
144inline bool setVScreenInfo(int fd, fb_var_screeninfo& vinfo) {
Naseer Ahmedabd76882014-06-30 11:10:14 -0400145 ATRACE_CALL();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700146 if (ioctl(fd, FBIOPUT_VSCREENINFO, &vinfo) < 0) {
147 ALOGE("Failed to call ioctl FBIOPUT_VSCREENINFO err=%s",
148 strerror(errno));
Naseer Ahmed29a26812012-06-14 00:56:20 -0700149 return false;
150 }
151 return true;
152}
153
154inline bool startRotator(int fd, msm_rotator_img_info& rot) {
Naseer Ahmedabd76882014-06-30 11:10:14 -0400155 ATRACE_CALL();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700156 if (ioctl(fd, MSM_ROTATOR_IOCTL_START, &rot) < 0){
157 ALOGE("Failed to call ioctl MSM_ROTATOR_IOCTL_START err=%s",
158 strerror(errno));
Naseer Ahmed29a26812012-06-14 00:56:20 -0700159 return false;
160 }
161 return true;
162}
163
164inline bool rotate(int fd, msm_rotator_data_info& rot) {
Naseer Ahmedabd76882014-06-30 11:10:14 -0400165 ATRACE_CALL();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700166 if (ioctl(fd, MSM_ROTATOR_IOCTL_ROTATE, &rot) < 0) {
167 ALOGE("Failed to call ioctl MSM_ROTATOR_IOCTL_ROTATE err=%s",
168 strerror(errno));
Naseer Ahmed29a26812012-06-14 00:56:20 -0700169 return false;
170 }
171 return true;
172}
173
174inline bool setOverlay(int fd, mdp_overlay& ov) {
Naseer Ahmedabd76882014-06-30 11:10:14 -0400175 ATRACE_CALL();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700176 if (ioctl(fd, MSMFB_OVERLAY_SET, &ov) < 0) {
177 ALOGE("Failed to call ioctl MSMFB_OVERLAY_SET err=%s",
178 strerror(errno));
Naseer Ahmed29a26812012-06-14 00:56:20 -0700179 return false;
180 }
181 return true;
182}
183
Saurabh Shaha36be922013-12-16 18:18:39 -0800184inline bool validateAndSet(const int& fd, mdp_overlay_list& list) {
Naseer Ahmedabd76882014-06-30 11:10:14 -0400185 ATRACE_CALL();
Saurabh Shaha36be922013-12-16 18:18:39 -0800186 if (ioctl(fd, MSMFB_OVERLAY_PREPARE, &list) < 0) {
187 ALOGD_IF(IOCTL_DEBUG, "Failed to call ioctl MSMFB_OVERLAY_PREPARE "
188 "err=%s", strerror(errno));
189 return false;
190 }
191 return true;
192}
193
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500194inline bool endRotator(int fd, uint32_t sessionId) {
Naseer Ahmedabd76882014-06-30 11:10:14 -0400195 ATRACE_CALL();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700196 if (ioctl(fd, MSM_ROTATOR_IOCTL_FINISH, &sessionId) < 0) {
197 ALOGE("Failed to call ioctl MSM_ROTATOR_IOCTL_FINISH err=%s",
198 strerror(errno));
Naseer Ahmed29a26812012-06-14 00:56:20 -0700199 return false;
200 }
201 return true;
202}
203
204inline bool unsetOverlay(int fd, int ovId) {
Naseer Ahmedabd76882014-06-30 11:10:14 -0400205 ATRACE_CALL();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700206 if (ioctl(fd, MSMFB_OVERLAY_UNSET, &ovId) < 0) {
207 ALOGE("Failed to call ioctl MSMFB_OVERLAY_UNSET err=%s",
208 strerror(errno));
Naseer Ahmed29a26812012-06-14 00:56:20 -0700209 return false;
210 }
211 return true;
212}
213
214inline bool getOverlay(int fd, mdp_overlay& ov) {
Naseer Ahmedabd76882014-06-30 11:10:14 -0400215 ATRACE_CALL();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700216 if (ioctl(fd, MSMFB_OVERLAY_GET, &ov) < 0) {
217 ALOGE("Failed to call ioctl MSMFB_OVERLAY_GET err=%s",
218 strerror(errno));
Naseer Ahmed29a26812012-06-14 00:56:20 -0700219 return false;
220 }
221 return true;
222}
223
224inline bool play(int fd, msmfb_overlay_data& od) {
Naseer Ahmedabd76882014-06-30 11:10:14 -0400225 ATRACE_CALL();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700226 if (ioctl(fd, MSMFB_OVERLAY_PLAY, &od) < 0) {
227 ALOGE("Failed to call ioctl MSMFB_OVERLAY_PLAY err=%s",
228 strerror(errno));
Naseer Ahmed29a26812012-06-14 00:56:20 -0700229 return false;
230 }
231 return true;
232}
233
Naseer Ahmed29a26812012-06-14 00:56:20 -0700234inline bool set3D(int fd, msmfb_overlay_3d& ov) {
Naseer Ahmedabd76882014-06-30 11:10:14 -0400235 ATRACE_CALL();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700236 if (ioctl(fd, MSMFB_OVERLAY_3D, &ov) < 0) {
237 ALOGE("Failed to call ioctl MSMFB_OVERLAY_3D err=%s",
238 strerror(errno));
Naseer Ahmed29a26812012-06-14 00:56:20 -0700239 return false;
240 }
241 return true;
242}
243
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700244inline bool displayCommit(int fd, mdp_display_commit& info) {
Naseer Ahmedabd76882014-06-30 11:10:14 -0400245 ATRACE_CALL();
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700246 if(ioctl(fd, MSMFB_DISPLAY_COMMIT, &info) == -1) {
247 ALOGE("Failed to call ioctl MSMFB_DISPLAY_COMMIT err=%s",
248 strerror(errno));
249 return false;
250 }
251 return true;
252}
253
254inline bool wbInitStart(int fbfd) {
Naseer Ahmedabd76882014-06-30 11:10:14 -0400255 ATRACE_CALL();
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700256 if(ioctl(fbfd, MSMFB_WRITEBACK_INIT, NULL) < 0) {
257 ALOGE("Failed to call ioctl MSMFB_WRITEBACK_INIT err=%s",
258 strerror(errno));
259 return false;
260 }
261 if(ioctl(fbfd, MSMFB_WRITEBACK_START, NULL) < 0) {
262 ALOGE("Failed to call ioctl MSMFB_WRITEBACK_START err=%s",
263 strerror(errno));
264 return false;
265 }
266 return true;
267}
268
269inline bool wbStopTerminate(int fbfd) {
Naseer Ahmedabd76882014-06-30 11:10:14 -0400270 ATRACE_CALL();
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700271 if(ioctl(fbfd, MSMFB_WRITEBACK_STOP, NULL) < 0) {
272 ALOGE("Failed to call ioctl MSMFB_WRITEBACK_STOP err=%s",
273 strerror(errno));
274 return false;
275 }
276 if(ioctl(fbfd, MSMFB_WRITEBACK_TERMINATE, NULL) < 0) {
277 ALOGE("Failed to call ioctl MSMFB_WRITEBACK_TERMINATE err=%s",
278 strerror(errno));
279 return false;
280 }
281 return true;
282}
283
284inline bool wbQueueBuffer(int fbfd, struct msmfb_data& fbData) {
Naseer Ahmedabd76882014-06-30 11:10:14 -0400285 ATRACE_CALL();
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700286 if(ioctl(fbfd, MSMFB_WRITEBACK_QUEUE_BUFFER, &fbData) < 0) {
287 ALOGE("Failed to call ioctl MSMFB_WRITEBACK_QUEUE_BUFFER err=%s",
288 strerror(errno));
289 return false;
290 }
291 return true;
292}
293
294inline bool wbDequeueBuffer(int fbfd, struct msmfb_data& fbData) {
Naseer Ahmedabd76882014-06-30 11:10:14 -0400295 ATRACE_CALL();
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700296 if(ioctl(fbfd, MSMFB_WRITEBACK_DEQUEUE_BUFFER, &fbData) < 0) {
297 ALOGE("Failed to call ioctl MSMFB_WRITEBACK_DEQUEUE_BUFFER err=%s",
298 strerror(errno));
299 return false;
300 }
301 return true;
302}
303
Naseer Ahmed29a26812012-06-14 00:56:20 -0700304/* dump funcs */
305inline void dump(const char* const s, const msmfb_overlay_data& ov) {
306 ALOGE("%s msmfb_overlay_data id=%d",
307 s, ov.id);
308 dump("data", ov.data);
309}
310inline void dump(const char* const s, const msmfb_data& ov) {
311 ALOGE("%s msmfb_data offset=%d memid=%d id=%d flags=0x%x priv=%d",
312 s, ov.offset, ov.memory_id, ov.id, ov.flags, ov.priv);
313}
314inline void dump(const char* const s, const mdp_overlay& ov) {
315 ALOGE("%s mdp_overlay z=%d fg=%d alpha=%d mask=%d flags=0x%x id=%d",
316 s, ov.z_order, ov.is_fg, ov.alpha,
317 ov.transp_mask, ov.flags, ov.id);
318 dump("src", ov.src);
319 dump("src_rect", ov.src_rect);
320 dump("dst_rect", ov.dst_rect);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500321 /*
322 Commented off to prevent verbose logging, since user_data could have 8 or so
323 fields which are mostly 0
Naseer Ahmed29a26812012-06-14 00:56:20 -0700324 dump("user_data", ov.user_data,
325 sizeof(ov.user_data)/sizeof(ov.user_data[0]));
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500326 */
Naseer Ahmed29a26812012-06-14 00:56:20 -0700327}
328inline void dump(const char* const s, const msmfb_img& ov) {
329 ALOGE("%s msmfb_img w=%d h=%d format=%d %s",
330 s, ov.width, ov.height, ov.format,
331 overlay::utils::getFormatString(ov.format));
332}
333inline void dump(const char* const s, const mdp_rect& ov) {
334 ALOGE("%s mdp_rect x=%d y=%d w=%d h=%d",
335 s, ov.x, ov.y, ov.w, ov.h);
336}
337
338inline void dump(const char* const s, const msmfb_overlay_3d& ov) {
339 ALOGE("%s msmfb_overlay_3d 3d=%d w=%d h=%d",
340 s, ov.is_3d, ov.width, ov.height);
341
342}
343inline void dump(const char* const s, const uint32_t u[], uint32_t cnt) {
344 ALOGE("%s user_data cnt=%d", s, cnt);
345 for(uint32_t i=0; i < cnt; ++i) {
346 ALOGE("i=%d val=%d", i, u[i]);
347 }
348}
349inline void dump(const char* const s, const msm_rotator_img_info& rot) {
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800350 ALOGE("%s msm_rotator_img_info sessid=%u dstx=%d dsty=%d rot=%d, ena=%d scale=%d",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700351 s, rot.session_id, rot.dst_x, rot.dst_y,
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800352 rot.rotations, rot.enable, rot.downscale_ratio);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700353 dump("src", rot.src);
354 dump("dst", rot.dst);
355 dump("src_rect", rot.src_rect);
356}
357inline void dump(const char* const s, const msm_rotator_data_info& rot) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500358 ALOGE("%s msm_rotator_data_info sessid=%u verkey=%d",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700359 s, rot.session_id, rot.version_key);
360 dump("src", rot.src);
361 dump("dst", rot.dst);
362 dump("src_chroma", rot.src_chroma);
363 dump("dst_chroma", rot.dst_chroma);
364}
365inline void dump(const char* const s, const fb_fix_screeninfo& finfo) {
366 ALOGE("%s fb_fix_screeninfo type=%d", s, finfo.type);
367}
368inline void dump(const char* const s, const fb_var_screeninfo& vinfo) {
369 ALOGE("%s fb_var_screeninfo xres=%d yres=%d",
370 s, vinfo.xres, vinfo.yres);
371}
372
Naseer Ahmed29a26812012-06-14 00:56:20 -0700373} // mdp_wrapper
374
375} // overlay
376
377#endif // MDP_WRAPPER_H