blob: d96317c11a9d1a805cf2dc5b8d3686d00d172e29 [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
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
Naseer Ahmed29a26812012-06-14 00:56:20 -070078/* MSMFB_OVERLAY_3D */
79bool set3D(int fd, msmfb_overlay_3d& ov);
80
Saurabh Shahc8118ac2013-06-27 10:03:19 -070081/* MSMFB_DISPLAY_COMMIT */
82bool displayCommit(int fd);
83
84/* MSMFB_WRITEBACK_INIT, MSMFB_WRITEBACK_START */
85bool wbInitStart(int fbfd);
86
87/* MSMFB_WRITEBACK_STOP, MSMFB_WRITEBACK_TERMINATE */
88bool wbStopTerminate(int fbfd);
89
90/* MSMFB_WRITEBACK_QUEUE_BUFFER */
91bool wbQueueBuffer(int fbfd, struct msmfb_data& fbData);
92
93/* MSMFB_WRITEBACK_DEQUEUE_BUFFER */
94bool wbDequeueBuffer(int fbfd, struct msmfb_data& fbData);
95
Naseer Ahmed29a26812012-06-14 00:56:20 -070096/* the following are helper functions for dumping
97 * msm_mdp and friends*/
98void dump(const char* const s, const msmfb_overlay_data& ov);
99void dump(const char* const s, const msmfb_data& ov);
100void dump(const char* const s, const mdp_overlay& ov);
101void dump(const char* const s, const msmfb_overlay_3d& ov);
102void dump(const char* const s, const uint32_t u[], uint32_t cnt);
103void dump(const char* const s, const msmfb_img& ov);
104void dump(const char* const s, const mdp_rect& ov);
105
106/* and rotator */
107void dump(const char* const s, const msm_rotator_img_info& rot);
108void dump(const char* const s, const msm_rotator_data_info& rot);
109
110/* info */
111void dump(const char* const s, const fb_fix_screeninfo& finfo);
112void dump(const char* const s, const fb_var_screeninfo& vinfo);
113
114//---------------Inlines -------------------------------------
115
116inline bool getFScreenInfo(int fd, fb_fix_screeninfo& finfo) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700117 if (ioctl(fd, FBIOGET_FSCREENINFO, &finfo) < 0) {
118 ALOGE("Failed to call ioctl FBIOGET_FSCREENINFO err=%s",
119 strerror(errno));
Naseer Ahmed29a26812012-06-14 00:56:20 -0700120 return false;
121 }
122 return true;
123}
124
125inline bool getVScreenInfo(int fd, fb_var_screeninfo& vinfo) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700126 if (ioctl(fd, FBIOGET_VSCREENINFO, &vinfo) < 0) {
127 ALOGE("Failed to call ioctl FBIOGET_VSCREENINFO err=%s",
128 strerror(errno));
Naseer Ahmed29a26812012-06-14 00:56:20 -0700129 return false;
130 }
131 return true;
132}
133
134inline bool setVScreenInfo(int fd, fb_var_screeninfo& vinfo) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700135 if (ioctl(fd, FBIOPUT_VSCREENINFO, &vinfo) < 0) {
136 ALOGE("Failed to call ioctl FBIOPUT_VSCREENINFO err=%s",
137 strerror(errno));
Naseer Ahmed29a26812012-06-14 00:56:20 -0700138 return false;
139 }
140 return true;
141}
142
143inline bool startRotator(int fd, msm_rotator_img_info& rot) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700144 if (ioctl(fd, MSM_ROTATOR_IOCTL_START, &rot) < 0){
145 ALOGE("Failed to call ioctl MSM_ROTATOR_IOCTL_START err=%s",
146 strerror(errno));
Naseer Ahmed29a26812012-06-14 00:56:20 -0700147 return false;
148 }
149 return true;
150}
151
152inline bool rotate(int fd, msm_rotator_data_info& rot) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700153 if (ioctl(fd, MSM_ROTATOR_IOCTL_ROTATE, &rot) < 0) {
154 ALOGE("Failed to call ioctl MSM_ROTATOR_IOCTL_ROTATE err=%s",
155 strerror(errno));
Naseer Ahmed29a26812012-06-14 00:56:20 -0700156 return false;
157 }
158 return true;
159}
160
161inline bool setOverlay(int fd, mdp_overlay& ov) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700162 if (ioctl(fd, MSMFB_OVERLAY_SET, &ov) < 0) {
163 ALOGE("Failed to call ioctl MSMFB_OVERLAY_SET err=%s",
164 strerror(errno));
Naseer Ahmed29a26812012-06-14 00:56:20 -0700165 return false;
166 }
167 return true;
168}
169
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500170inline bool endRotator(int fd, uint32_t sessionId) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700171 if (ioctl(fd, MSM_ROTATOR_IOCTL_FINISH, &sessionId) < 0) {
172 ALOGE("Failed to call ioctl MSM_ROTATOR_IOCTL_FINISH err=%s",
173 strerror(errno));
Naseer Ahmed29a26812012-06-14 00:56:20 -0700174 return false;
175 }
176 return true;
177}
178
179inline bool unsetOverlay(int fd, int ovId) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700180 if (ioctl(fd, MSMFB_OVERLAY_UNSET, &ovId) < 0) {
181 ALOGE("Failed to call ioctl MSMFB_OVERLAY_UNSET err=%s",
182 strerror(errno));
Naseer Ahmed29a26812012-06-14 00:56:20 -0700183 return false;
184 }
185 return true;
186}
187
188inline bool getOverlay(int fd, mdp_overlay& ov) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700189 if (ioctl(fd, MSMFB_OVERLAY_GET, &ov) < 0) {
190 ALOGE("Failed to call ioctl MSMFB_OVERLAY_GET err=%s",
191 strerror(errno));
Naseer Ahmed29a26812012-06-14 00:56:20 -0700192 return false;
193 }
194 return true;
195}
196
197inline bool play(int fd, msmfb_overlay_data& od) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700198 if (ioctl(fd, MSMFB_OVERLAY_PLAY, &od) < 0) {
199 ALOGE("Failed to call ioctl MSMFB_OVERLAY_PLAY err=%s",
200 strerror(errno));
Naseer Ahmed29a26812012-06-14 00:56:20 -0700201 return false;
202 }
203 return true;
204}
205
Naseer Ahmed29a26812012-06-14 00:56:20 -0700206inline bool set3D(int fd, msmfb_overlay_3d& ov) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700207 if (ioctl(fd, MSMFB_OVERLAY_3D, &ov) < 0) {
208 ALOGE("Failed to call ioctl MSMFB_OVERLAY_3D err=%s",
209 strerror(errno));
Naseer Ahmed29a26812012-06-14 00:56:20 -0700210 return false;
211 }
212 return true;
213}
214
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700215inline bool displayCommit(int fd, mdp_display_commit& info) {
216 if(ioctl(fd, MSMFB_DISPLAY_COMMIT, &info) == -1) {
217 ALOGE("Failed to call ioctl MSMFB_DISPLAY_COMMIT err=%s",
218 strerror(errno));
219 return false;
220 }
221 return true;
222}
223
224inline bool wbInitStart(int fbfd) {
225 if(ioctl(fbfd, MSMFB_WRITEBACK_INIT, NULL) < 0) {
226 ALOGE("Failed to call ioctl MSMFB_WRITEBACK_INIT err=%s",
227 strerror(errno));
228 return false;
229 }
230 if(ioctl(fbfd, MSMFB_WRITEBACK_START, NULL) < 0) {
231 ALOGE("Failed to call ioctl MSMFB_WRITEBACK_START err=%s",
232 strerror(errno));
233 return false;
234 }
235 return true;
236}
237
238inline bool wbStopTerminate(int fbfd) {
239 if(ioctl(fbfd, MSMFB_WRITEBACK_STOP, NULL) < 0) {
240 ALOGE("Failed to call ioctl MSMFB_WRITEBACK_STOP err=%s",
241 strerror(errno));
242 return false;
243 }
244 if(ioctl(fbfd, MSMFB_WRITEBACK_TERMINATE, NULL) < 0) {
245 ALOGE("Failed to call ioctl MSMFB_WRITEBACK_TERMINATE err=%s",
246 strerror(errno));
247 return false;
248 }
249 return true;
250}
251
252inline bool wbQueueBuffer(int fbfd, struct msmfb_data& fbData) {
253 if(ioctl(fbfd, MSMFB_WRITEBACK_QUEUE_BUFFER, &fbData) < 0) {
254 ALOGE("Failed to call ioctl MSMFB_WRITEBACK_QUEUE_BUFFER err=%s",
255 strerror(errno));
256 return false;
257 }
258 return true;
259}
260
261inline bool wbDequeueBuffer(int fbfd, struct msmfb_data& fbData) {
262 if(ioctl(fbfd, MSMFB_WRITEBACK_DEQUEUE_BUFFER, &fbData) < 0) {
263 ALOGE("Failed to call ioctl MSMFB_WRITEBACK_DEQUEUE_BUFFER err=%s",
264 strerror(errno));
265 return false;
266 }
267 return true;
268}
269
Naseer Ahmed29a26812012-06-14 00:56:20 -0700270/* dump funcs */
271inline void dump(const char* const s, const msmfb_overlay_data& ov) {
272 ALOGE("%s msmfb_overlay_data id=%d",
273 s, ov.id);
274 dump("data", ov.data);
275}
276inline void dump(const char* const s, const msmfb_data& ov) {
277 ALOGE("%s msmfb_data offset=%d memid=%d id=%d flags=0x%x priv=%d",
278 s, ov.offset, ov.memory_id, ov.id, ov.flags, ov.priv);
279}
280inline void dump(const char* const s, const mdp_overlay& ov) {
281 ALOGE("%s mdp_overlay z=%d fg=%d alpha=%d mask=%d flags=0x%x id=%d",
282 s, ov.z_order, ov.is_fg, ov.alpha,
283 ov.transp_mask, ov.flags, ov.id);
284 dump("src", ov.src);
285 dump("src_rect", ov.src_rect);
286 dump("dst_rect", ov.dst_rect);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500287 /*
288 Commented off to prevent verbose logging, since user_data could have 8 or so
289 fields which are mostly 0
Naseer Ahmed29a26812012-06-14 00:56:20 -0700290 dump("user_data", ov.user_data,
291 sizeof(ov.user_data)/sizeof(ov.user_data[0]));
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500292 */
Naseer Ahmed29a26812012-06-14 00:56:20 -0700293}
294inline void dump(const char* const s, const msmfb_img& ov) {
295 ALOGE("%s msmfb_img w=%d h=%d format=%d %s",
296 s, ov.width, ov.height, ov.format,
297 overlay::utils::getFormatString(ov.format));
298}
299inline void dump(const char* const s, const mdp_rect& ov) {
300 ALOGE("%s mdp_rect x=%d y=%d w=%d h=%d",
301 s, ov.x, ov.y, ov.w, ov.h);
302}
303
304inline void dump(const char* const s, const msmfb_overlay_3d& ov) {
305 ALOGE("%s msmfb_overlay_3d 3d=%d w=%d h=%d",
306 s, ov.is_3d, ov.width, ov.height);
307
308}
309inline void dump(const char* const s, const uint32_t u[], uint32_t cnt) {
310 ALOGE("%s user_data cnt=%d", s, cnt);
311 for(uint32_t i=0; i < cnt; ++i) {
312 ALOGE("i=%d val=%d", i, u[i]);
313 }
314}
315inline void dump(const char* const s, const msm_rotator_img_info& rot) {
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800316 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 -0700317 s, rot.session_id, rot.dst_x, rot.dst_y,
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800318 rot.rotations, rot.enable, rot.downscale_ratio);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700319 dump("src", rot.src);
320 dump("dst", rot.dst);
321 dump("src_rect", rot.src_rect);
322}
323inline void dump(const char* const s, const msm_rotator_data_info& rot) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500324 ALOGE("%s msm_rotator_data_info sessid=%u verkey=%d",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700325 s, rot.session_id, rot.version_key);
326 dump("src", rot.src);
327 dump("dst", rot.dst);
328 dump("src_chroma", rot.src_chroma);
329 dump("dst_chroma", rot.dst_chroma);
330}
331inline void dump(const char* const s, const fb_fix_screeninfo& finfo) {
332 ALOGE("%s fb_fix_screeninfo type=%d", s, finfo.type);
333}
334inline void dump(const char* const s, const fb_var_screeninfo& vinfo) {
335 ALOGE("%s fb_var_screeninfo xres=%d yres=%d",
336 s, vinfo.xres, vinfo.yres);
337}
338
Naseer Ahmed29a26812012-06-14 00:56:20 -0700339} // mdp_wrapper
340
341} // overlay
342
343#endif // MDP_WRAPPER_H