blob: 1bfa058f38c70acd83dc883286b0c826dabb04a3 [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
Saurabh Shaha36be922013-12-16 18:18:39 -080045#define IOCTL_DEBUG 0
46
Naseer Ahmed29a26812012-06-14 00:56:20 -070047namespace overlay{
48
49namespace mdp_wrapper{
50/* FBIOGET_FSCREENINFO */
51bool getFScreenInfo(int fd, fb_fix_screeninfo& finfo);
52
53/* FBIOGET_VSCREENINFO */
54bool getVScreenInfo(int fd, fb_var_screeninfo& vinfo);
55
56/* FBIOPUT_VSCREENINFO */
57bool setVScreenInfo(int fd, fb_var_screeninfo& vinfo);
58
59/* MSM_ROTATOR_IOCTL_START */
60bool startRotator(int fd, msm_rotator_img_info& rot);
61
62/* MSM_ROTATOR_IOCTL_ROTATE */
63bool rotate(int fd, msm_rotator_data_info& rot);
64
65/* MSMFB_OVERLAY_SET */
66bool setOverlay(int fd, mdp_overlay& ov);
67
Saurabh Shaha36be922013-12-16 18:18:39 -080068/* MSMFB_OVERLAY_PREPARE */
69bool validateAndSet(const int& fd, mdp_overlay_list& list);
70
Naseer Ahmed29a26812012-06-14 00:56:20 -070071/* MSM_ROTATOR_IOCTL_FINISH */
72bool endRotator(int fd, int sessionId);
73
74/* MSMFB_OVERLAY_UNSET */
75bool unsetOverlay(int fd, int ovId);
76
77/* MSMFB_OVERLAY_GET */
78bool getOverlay(int fd, mdp_overlay& ov);
79
80/* MSMFB_OVERLAY_PLAY */
81bool play(int fd, msmfb_overlay_data& od);
82
Naseer Ahmed29a26812012-06-14 00:56:20 -070083/* MSMFB_OVERLAY_3D */
84bool set3D(int fd, msmfb_overlay_3d& ov);
85
Saurabh Shahc8118ac2013-06-27 10:03:19 -070086/* MSMFB_DISPLAY_COMMIT */
87bool displayCommit(int fd);
88
89/* MSMFB_WRITEBACK_INIT, MSMFB_WRITEBACK_START */
90bool wbInitStart(int fbfd);
91
92/* MSMFB_WRITEBACK_STOP, MSMFB_WRITEBACK_TERMINATE */
93bool wbStopTerminate(int fbfd);
94
95/* MSMFB_WRITEBACK_QUEUE_BUFFER */
96bool wbQueueBuffer(int fbfd, struct msmfb_data& fbData);
97
98/* MSMFB_WRITEBACK_DEQUEUE_BUFFER */
99bool wbDequeueBuffer(int fbfd, struct msmfb_data& fbData);
100
Naseer Ahmed29a26812012-06-14 00:56:20 -0700101/* the following are helper functions for dumping
102 * msm_mdp and friends*/
103void dump(const char* const s, const msmfb_overlay_data& ov);
104void dump(const char* const s, const msmfb_data& ov);
105void dump(const char* const s, const mdp_overlay& ov);
106void dump(const char* const s, const msmfb_overlay_3d& ov);
107void dump(const char* const s, const uint32_t u[], uint32_t cnt);
108void dump(const char* const s, const msmfb_img& ov);
109void dump(const char* const s, const mdp_rect& ov);
110
111/* and rotator */
112void dump(const char* const s, const msm_rotator_img_info& rot);
113void dump(const char* const s, const msm_rotator_data_info& rot);
114
115/* info */
116void dump(const char* const s, const fb_fix_screeninfo& finfo);
117void dump(const char* const s, const fb_var_screeninfo& vinfo);
118
119//---------------Inlines -------------------------------------
120
121inline bool getFScreenInfo(int fd, fb_fix_screeninfo& finfo) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700122 if (ioctl(fd, FBIOGET_FSCREENINFO, &finfo) < 0) {
123 ALOGE("Failed to call ioctl FBIOGET_FSCREENINFO err=%s",
124 strerror(errno));
Naseer Ahmed29a26812012-06-14 00:56:20 -0700125 return false;
126 }
127 return true;
128}
129
130inline bool getVScreenInfo(int fd, fb_var_screeninfo& vinfo) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700131 if (ioctl(fd, FBIOGET_VSCREENINFO, &vinfo) < 0) {
132 ALOGE("Failed to call ioctl FBIOGET_VSCREENINFO err=%s",
133 strerror(errno));
Naseer Ahmed29a26812012-06-14 00:56:20 -0700134 return false;
135 }
136 return true;
137}
138
139inline bool setVScreenInfo(int fd, fb_var_screeninfo& vinfo) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700140 if (ioctl(fd, FBIOPUT_VSCREENINFO, &vinfo) < 0) {
141 ALOGE("Failed to call ioctl FBIOPUT_VSCREENINFO err=%s",
142 strerror(errno));
Naseer Ahmed29a26812012-06-14 00:56:20 -0700143 return false;
144 }
145 return true;
146}
147
148inline bool startRotator(int fd, msm_rotator_img_info& rot) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700149 if (ioctl(fd, MSM_ROTATOR_IOCTL_START, &rot) < 0){
150 ALOGE("Failed to call ioctl MSM_ROTATOR_IOCTL_START err=%s",
151 strerror(errno));
Naseer Ahmed29a26812012-06-14 00:56:20 -0700152 return false;
153 }
154 return true;
155}
156
157inline bool rotate(int fd, msm_rotator_data_info& rot) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700158 if (ioctl(fd, MSM_ROTATOR_IOCTL_ROTATE, &rot) < 0) {
159 ALOGE("Failed to call ioctl MSM_ROTATOR_IOCTL_ROTATE err=%s",
160 strerror(errno));
Naseer Ahmed29a26812012-06-14 00:56:20 -0700161 return false;
162 }
163 return true;
164}
165
166inline bool setOverlay(int fd, mdp_overlay& ov) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700167 if (ioctl(fd, MSMFB_OVERLAY_SET, &ov) < 0) {
168 ALOGE("Failed to call ioctl MSMFB_OVERLAY_SET err=%s",
169 strerror(errno));
Naseer Ahmed29a26812012-06-14 00:56:20 -0700170 return false;
171 }
172 return true;
173}
174
Saurabh Shaha36be922013-12-16 18:18:39 -0800175inline 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
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500184inline bool endRotator(int fd, uint32_t sessionId) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700185 if (ioctl(fd, MSM_ROTATOR_IOCTL_FINISH, &sessionId) < 0) {
186 ALOGE("Failed to call ioctl MSM_ROTATOR_IOCTL_FINISH err=%s",
187 strerror(errno));
Naseer Ahmed29a26812012-06-14 00:56:20 -0700188 return false;
189 }
190 return true;
191}
192
193inline bool unsetOverlay(int fd, int ovId) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700194 if (ioctl(fd, MSMFB_OVERLAY_UNSET, &ovId) < 0) {
195 ALOGE("Failed to call ioctl MSMFB_OVERLAY_UNSET err=%s",
196 strerror(errno));
Naseer Ahmed29a26812012-06-14 00:56:20 -0700197 return false;
198 }
199 return true;
200}
201
202inline bool getOverlay(int fd, mdp_overlay& ov) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700203 if (ioctl(fd, MSMFB_OVERLAY_GET, &ov) < 0) {
204 ALOGE("Failed to call ioctl MSMFB_OVERLAY_GET err=%s",
205 strerror(errno));
Naseer Ahmed29a26812012-06-14 00:56:20 -0700206 return false;
207 }
208 return true;
209}
210
211inline bool play(int fd, msmfb_overlay_data& od) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700212 if (ioctl(fd, MSMFB_OVERLAY_PLAY, &od) < 0) {
213 ALOGE("Failed to call ioctl MSMFB_OVERLAY_PLAY err=%s",
214 strerror(errno));
Naseer Ahmed29a26812012-06-14 00:56:20 -0700215 return false;
216 }
217 return true;
218}
219
Naseer Ahmed29a26812012-06-14 00:56:20 -0700220inline bool set3D(int fd, msmfb_overlay_3d& ov) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700221 if (ioctl(fd, MSMFB_OVERLAY_3D, &ov) < 0) {
222 ALOGE("Failed to call ioctl MSMFB_OVERLAY_3D err=%s",
223 strerror(errno));
Naseer Ahmed29a26812012-06-14 00:56:20 -0700224 return false;
225 }
226 return true;
227}
228
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700229inline 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
238inline 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
252inline 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
266inline 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
275inline 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
Naseer Ahmed29a26812012-06-14 00:56:20 -0700284/* dump funcs */
285inline 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}
290inline 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}
294inline 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);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500301 /*
302 Commented off to prevent verbose logging, since user_data could have 8 or so
303 fields which are mostly 0
Naseer Ahmed29a26812012-06-14 00:56:20 -0700304 dump("user_data", ov.user_data,
305 sizeof(ov.user_data)/sizeof(ov.user_data[0]));
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500306 */
Naseer Ahmed29a26812012-06-14 00:56:20 -0700307}
308inline 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}
313inline 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
318inline 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}
323inline 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}
329inline void dump(const char* const s, const msm_rotator_img_info& rot) {
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800330 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 -0700331 s, rot.session_id, rot.dst_x, rot.dst_y,
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800332 rot.rotations, rot.enable, rot.downscale_ratio);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700333 dump("src", rot.src);
334 dump("dst", rot.dst);
335 dump("src_rect", rot.src_rect);
336}
337inline void dump(const char* const s, const msm_rotator_data_info& rot) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500338 ALOGE("%s msm_rotator_data_info sessid=%u verkey=%d",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700339 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}
345inline void dump(const char* const s, const fb_fix_screeninfo& finfo) {
346 ALOGE("%s fb_fix_screeninfo type=%d", s, finfo.type);
347}
348inline 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
Naseer Ahmed29a26812012-06-14 00:56:20 -0700353} // mdp_wrapper
354
355} // overlay
356
357#endif // MDP_WRAPPER_H