blob: 36faf07481f99dce34f1c7456259851bb237ebe6 [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"
Saurabh Shah24eec8a2014-08-22 15:07:25 -070047#include "overlay.h"
Naseer Ahmed29a26812012-06-14 00:56:20 -070048
Saurabh Shaha36be922013-12-16 18:18:39 -080049#define IOCTL_DEBUG 0
Saurabh Shah24eec8a2014-08-22 15:07:25 -070050#define LIKELY( exp ) (__builtin_expect( (exp) != 0, true ))
51#define UNLIKELY( exp ) (__builtin_expect( (exp) != 0, false ))
Saurabh Shaha36be922013-12-16 18:18:39 -080052
Naseer Ahmed29a26812012-06-14 00:56:20 -070053namespace overlay{
54
55namespace mdp_wrapper{
56/* FBIOGET_FSCREENINFO */
57bool getFScreenInfo(int fd, fb_fix_screeninfo& finfo);
58
59/* FBIOGET_VSCREENINFO */
60bool getVScreenInfo(int fd, fb_var_screeninfo& vinfo);
61
62/* FBIOPUT_VSCREENINFO */
63bool setVScreenInfo(int fd, fb_var_screeninfo& vinfo);
64
65/* MSM_ROTATOR_IOCTL_START */
66bool startRotator(int fd, msm_rotator_img_info& rot);
67
68/* MSM_ROTATOR_IOCTL_ROTATE */
69bool rotate(int fd, msm_rotator_data_info& rot);
70
71/* MSMFB_OVERLAY_SET */
72bool setOverlay(int fd, mdp_overlay& ov);
73
Saurabh Shaha36be922013-12-16 18:18:39 -080074/* MSMFB_OVERLAY_PREPARE */
75bool validateAndSet(const int& fd, mdp_overlay_list& list);
76
Naseer Ahmed29a26812012-06-14 00:56:20 -070077/* MSM_ROTATOR_IOCTL_FINISH */
78bool endRotator(int fd, int sessionId);
79
80/* MSMFB_OVERLAY_UNSET */
81bool unsetOverlay(int fd, int ovId);
82
83/* MSMFB_OVERLAY_GET */
84bool getOverlay(int fd, mdp_overlay& ov);
85
86/* MSMFB_OVERLAY_PLAY */
87bool play(int fd, msmfb_overlay_data& od);
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 Shah24eec8a2014-08-22 15:07:25 -0700186 uint32_t id = 0;
187 if(UNLIKELY(Overlay::isDebugPipeLifecycle())) {
188 for(uint32_t i = 0; i < list.num_overlays; i++) {
189 if(list.overlay_list[i]->id != (uint32_t)MSMFB_NEW_REQUEST) {
190 id |= list.overlay_list[i]->id;
191 }
192 }
193
194 ALOGD("%s Total pipes needed: %d, Exisiting pipe mask 0x%04x",
195 __FUNCTION__, list.num_overlays, id);
196 id = 0;
197 }
198
Saurabh Shaha36be922013-12-16 18:18:39 -0800199 if (ioctl(fd, MSMFB_OVERLAY_PREPARE, &list) < 0) {
200 ALOGD_IF(IOCTL_DEBUG, "Failed to call ioctl MSMFB_OVERLAY_PREPARE "
201 "err=%s", strerror(errno));
202 return false;
203 }
Saurabh Shah24eec8a2014-08-22 15:07:25 -0700204
205 if(UNLIKELY(Overlay::isDebugPipeLifecycle())) {
206 for(uint32_t i = 0; i < list.num_overlays; i++) {
207 id |= list.overlay_list[i]->id;
208 }
209
210 ALOGD("%s Pipe mask after OVERLAY_PREPARE 0x%04x", __FUNCTION__, id);
211 }
212
Saurabh Shaha36be922013-12-16 18:18:39 -0800213 return true;
214}
215
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500216inline bool endRotator(int fd, uint32_t sessionId) {
Naseer Ahmedabd76882014-06-30 11:10:14 -0400217 ATRACE_CALL();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700218 if (ioctl(fd, MSM_ROTATOR_IOCTL_FINISH, &sessionId) < 0) {
219 ALOGE("Failed to call ioctl MSM_ROTATOR_IOCTL_FINISH err=%s",
220 strerror(errno));
Naseer Ahmed29a26812012-06-14 00:56:20 -0700221 return false;
222 }
223 return true;
224}
225
226inline bool unsetOverlay(int fd, int ovId) {
Naseer Ahmedabd76882014-06-30 11:10:14 -0400227 ATRACE_CALL();
Saurabh Shah24eec8a2014-08-22 15:07:25 -0700228 ALOGD_IF(Overlay::isDebugPipeLifecycle(), "%s Unsetting pipe 0x%04x",
229 __FUNCTION__, ovId);
230
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700231 if (ioctl(fd, MSMFB_OVERLAY_UNSET, &ovId) < 0) {
232 ALOGE("Failed to call ioctl MSMFB_OVERLAY_UNSET err=%s",
233 strerror(errno));
Naseer Ahmed29a26812012-06-14 00:56:20 -0700234 return false;
235 }
236 return true;
237}
238
239inline bool getOverlay(int fd, mdp_overlay& ov) {
Naseer Ahmedabd76882014-06-30 11:10:14 -0400240 ATRACE_CALL();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700241 if (ioctl(fd, MSMFB_OVERLAY_GET, &ov) < 0) {
242 ALOGE("Failed to call ioctl MSMFB_OVERLAY_GET err=%s",
243 strerror(errno));
Naseer Ahmed29a26812012-06-14 00:56:20 -0700244 return false;
245 }
246 return true;
247}
248
249inline bool play(int fd, msmfb_overlay_data& od) {
Naseer Ahmedabd76882014-06-30 11:10:14 -0400250 ATRACE_CALL();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700251 if (ioctl(fd, MSMFB_OVERLAY_PLAY, &od) < 0) {
252 ALOGE("Failed to call ioctl MSMFB_OVERLAY_PLAY err=%s",
253 strerror(errno));
Naseer Ahmed29a26812012-06-14 00:56:20 -0700254 return false;
255 }
256 return true;
257}
258
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700259inline bool displayCommit(int fd, mdp_display_commit& info) {
Naseer Ahmedabd76882014-06-30 11:10:14 -0400260 ATRACE_CALL();
Saurabh Shah24eec8a2014-08-22 15:07:25 -0700261 ALOGD_IF(Overlay::isDebugPipeLifecycle(), "%s", __FUNCTION__);
262
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700263 if(ioctl(fd, MSMFB_DISPLAY_COMMIT, &info) == -1) {
264 ALOGE("Failed to call ioctl MSMFB_DISPLAY_COMMIT err=%s",
265 strerror(errno));
266 return false;
267 }
268 return true;
269}
270
271inline bool wbInitStart(int fbfd) {
Naseer Ahmedabd76882014-06-30 11:10:14 -0400272 ATRACE_CALL();
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700273 if(ioctl(fbfd, MSMFB_WRITEBACK_INIT, NULL) < 0) {
274 ALOGE("Failed to call ioctl MSMFB_WRITEBACK_INIT err=%s",
275 strerror(errno));
276 return false;
277 }
278 if(ioctl(fbfd, MSMFB_WRITEBACK_START, NULL) < 0) {
279 ALOGE("Failed to call ioctl MSMFB_WRITEBACK_START err=%s",
280 strerror(errno));
281 return false;
282 }
283 return true;
284}
285
286inline bool wbStopTerminate(int fbfd) {
Naseer Ahmedabd76882014-06-30 11:10:14 -0400287 ATRACE_CALL();
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700288 if(ioctl(fbfd, MSMFB_WRITEBACK_STOP, NULL) < 0) {
289 ALOGE("Failed to call ioctl MSMFB_WRITEBACK_STOP err=%s",
290 strerror(errno));
291 return false;
292 }
293 if(ioctl(fbfd, MSMFB_WRITEBACK_TERMINATE, NULL) < 0) {
294 ALOGE("Failed to call ioctl MSMFB_WRITEBACK_TERMINATE err=%s",
295 strerror(errno));
296 return false;
297 }
298 return true;
299}
300
301inline bool wbQueueBuffer(int fbfd, struct msmfb_data& fbData) {
Naseer Ahmedabd76882014-06-30 11:10:14 -0400302 ATRACE_CALL();
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700303 if(ioctl(fbfd, MSMFB_WRITEBACK_QUEUE_BUFFER, &fbData) < 0) {
304 ALOGE("Failed to call ioctl MSMFB_WRITEBACK_QUEUE_BUFFER err=%s",
305 strerror(errno));
306 return false;
307 }
308 return true;
309}
310
311inline bool wbDequeueBuffer(int fbfd, struct msmfb_data& fbData) {
Naseer Ahmedabd76882014-06-30 11:10:14 -0400312 ATRACE_CALL();
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700313 if(ioctl(fbfd, MSMFB_WRITEBACK_DEQUEUE_BUFFER, &fbData) < 0) {
314 ALOGE("Failed to call ioctl MSMFB_WRITEBACK_DEQUEUE_BUFFER err=%s",
315 strerror(errno));
316 return false;
317 }
318 return true;
319}
320
Naseer Ahmed29a26812012-06-14 00:56:20 -0700321/* dump funcs */
322inline void dump(const char* const s, const msmfb_overlay_data& ov) {
323 ALOGE("%s msmfb_overlay_data id=%d",
324 s, ov.id);
325 dump("data", ov.data);
326}
327inline void dump(const char* const s, const msmfb_data& ov) {
328 ALOGE("%s msmfb_data offset=%d memid=%d id=%d flags=0x%x priv=%d",
329 s, ov.offset, ov.memory_id, ov.id, ov.flags, ov.priv);
330}
331inline void dump(const char* const s, const mdp_overlay& ov) {
Saurabh Shah2c8ad052014-08-15 13:27:46 -0700332 ALOGE("%s mdp_overlay z=%d alpha=%d mask=%d flags=0x%x id=%d",
333 s, ov.z_order, ov.alpha,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700334 ov.transp_mask, ov.flags, ov.id);
335 dump("src", ov.src);
336 dump("src_rect", ov.src_rect);
337 dump("dst_rect", ov.dst_rect);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500338 /*
339 Commented off to prevent verbose logging, since user_data could have 8 or so
340 fields which are mostly 0
Naseer Ahmed29a26812012-06-14 00:56:20 -0700341 dump("user_data", ov.user_data,
342 sizeof(ov.user_data)/sizeof(ov.user_data[0]));
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500343 */
Naseer Ahmed29a26812012-06-14 00:56:20 -0700344}
345inline void dump(const char* const s, const msmfb_img& ov) {
346 ALOGE("%s msmfb_img w=%d h=%d format=%d %s",
347 s, ov.width, ov.height, ov.format,
348 overlay::utils::getFormatString(ov.format));
349}
350inline void dump(const char* const s, const mdp_rect& ov) {
351 ALOGE("%s mdp_rect x=%d y=%d w=%d h=%d",
352 s, ov.x, ov.y, ov.w, ov.h);
353}
354
355inline void dump(const char* const s, const msmfb_overlay_3d& ov) {
356 ALOGE("%s msmfb_overlay_3d 3d=%d w=%d h=%d",
357 s, ov.is_3d, ov.width, ov.height);
358
359}
360inline void dump(const char* const s, const uint32_t u[], uint32_t cnt) {
361 ALOGE("%s user_data cnt=%d", s, cnt);
362 for(uint32_t i=0; i < cnt; ++i) {
363 ALOGE("i=%d val=%d", i, u[i]);
364 }
365}
366inline void dump(const char* const s, const msm_rotator_img_info& rot) {
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800367 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 -0700368 s, rot.session_id, rot.dst_x, rot.dst_y,
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800369 rot.rotations, rot.enable, rot.downscale_ratio);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700370 dump("src", rot.src);
371 dump("dst", rot.dst);
372 dump("src_rect", rot.src_rect);
373}
374inline void dump(const char* const s, const msm_rotator_data_info& rot) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500375 ALOGE("%s msm_rotator_data_info sessid=%u verkey=%d",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700376 s, rot.session_id, rot.version_key);
377 dump("src", rot.src);
378 dump("dst", rot.dst);
379 dump("src_chroma", rot.src_chroma);
380 dump("dst_chroma", rot.dst_chroma);
381}
382inline void dump(const char* const s, const fb_fix_screeninfo& finfo) {
383 ALOGE("%s fb_fix_screeninfo type=%d", s, finfo.type);
384}
385inline void dump(const char* const s, const fb_var_screeninfo& vinfo) {
386 ALOGE("%s fb_var_screeninfo xres=%d yres=%d",
387 s, vinfo.xres, vinfo.yres);
388}
389
Naseer Ahmed29a26812012-06-14 00:56:20 -0700390} // mdp_wrapper
391
392} // overlay
393
394#endif // MDP_WRAPPER_H