Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1 | /* |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 2 | * Copyright (c) 2011, The Linux Foundation. All rights reserved. |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 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. |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 13 | * * Neither the name of The Linux Foundation nor the names of its |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 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 | namespace overlay{ |
| 46 | |
| 47 | namespace mdp_wrapper{ |
| 48 | /* FBIOGET_FSCREENINFO */ |
| 49 | bool getFScreenInfo(int fd, fb_fix_screeninfo& finfo); |
| 50 | |
| 51 | /* FBIOGET_VSCREENINFO */ |
| 52 | bool getVScreenInfo(int fd, fb_var_screeninfo& vinfo); |
| 53 | |
| 54 | /* FBIOPUT_VSCREENINFO */ |
| 55 | bool setVScreenInfo(int fd, fb_var_screeninfo& vinfo); |
| 56 | |
| 57 | /* MSM_ROTATOR_IOCTL_START */ |
| 58 | bool startRotator(int fd, msm_rotator_img_info& rot); |
| 59 | |
| 60 | /* MSM_ROTATOR_IOCTL_ROTATE */ |
| 61 | bool rotate(int fd, msm_rotator_data_info& rot); |
| 62 | |
| 63 | /* MSMFB_OVERLAY_SET */ |
| 64 | bool setOverlay(int fd, mdp_overlay& ov); |
| 65 | |
| 66 | /* MSM_ROTATOR_IOCTL_FINISH */ |
| 67 | bool endRotator(int fd, int sessionId); |
| 68 | |
| 69 | /* MSMFB_OVERLAY_UNSET */ |
| 70 | bool unsetOverlay(int fd, int ovId); |
| 71 | |
| 72 | /* MSMFB_OVERLAY_GET */ |
| 73 | bool getOverlay(int fd, mdp_overlay& ov); |
| 74 | |
| 75 | /* MSMFB_OVERLAY_PLAY */ |
| 76 | bool play(int fd, msmfb_overlay_data& od); |
| 77 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 78 | /* MSMFB_OVERLAY_3D */ |
| 79 | bool set3D(int fd, msmfb_overlay_3d& ov); |
| 80 | |
Saurabh Shah | c8118ac | 2013-06-27 10:03:19 -0700 | [diff] [blame^] | 81 | /* MSMFB_DISPLAY_COMMIT */ |
| 82 | bool displayCommit(int fd); |
| 83 | |
| 84 | /* MSMFB_WRITEBACK_INIT, MSMFB_WRITEBACK_START */ |
| 85 | bool wbInitStart(int fbfd); |
| 86 | |
| 87 | /* MSMFB_WRITEBACK_STOP, MSMFB_WRITEBACK_TERMINATE */ |
| 88 | bool wbStopTerminate(int fbfd); |
| 89 | |
| 90 | /* MSMFB_WRITEBACK_QUEUE_BUFFER */ |
| 91 | bool wbQueueBuffer(int fbfd, struct msmfb_data& fbData); |
| 92 | |
| 93 | /* MSMFB_WRITEBACK_DEQUEUE_BUFFER */ |
| 94 | bool wbDequeueBuffer(int fbfd, struct msmfb_data& fbData); |
| 95 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 96 | /* the following are helper functions for dumping |
| 97 | * msm_mdp and friends*/ |
| 98 | void dump(const char* const s, const msmfb_overlay_data& ov); |
| 99 | void dump(const char* const s, const msmfb_data& ov); |
| 100 | void dump(const char* const s, const mdp_overlay& ov); |
| 101 | void dump(const char* const s, const msmfb_overlay_3d& ov); |
| 102 | void dump(const char* const s, const uint32_t u[], uint32_t cnt); |
| 103 | void dump(const char* const s, const msmfb_img& ov); |
| 104 | void dump(const char* const s, const mdp_rect& ov); |
| 105 | |
| 106 | /* and rotator */ |
| 107 | void dump(const char* const s, const msm_rotator_img_info& rot); |
| 108 | void dump(const char* const s, const msm_rotator_data_info& rot); |
| 109 | |
| 110 | /* info */ |
| 111 | void dump(const char* const s, const fb_fix_screeninfo& finfo); |
| 112 | void dump(const char* const s, const fb_var_screeninfo& vinfo); |
| 113 | |
| 114 | //---------------Inlines ------------------------------------- |
| 115 | |
| 116 | inline bool getFScreenInfo(int fd, fb_fix_screeninfo& finfo) { |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 117 | if (ioctl(fd, FBIOGET_FSCREENINFO, &finfo) < 0) { |
| 118 | ALOGE("Failed to call ioctl FBIOGET_FSCREENINFO err=%s", |
| 119 | strerror(errno)); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 120 | return false; |
| 121 | } |
| 122 | return true; |
| 123 | } |
| 124 | |
| 125 | inline bool getVScreenInfo(int fd, fb_var_screeninfo& vinfo) { |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 126 | if (ioctl(fd, FBIOGET_VSCREENINFO, &vinfo) < 0) { |
| 127 | ALOGE("Failed to call ioctl FBIOGET_VSCREENINFO err=%s", |
| 128 | strerror(errno)); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 129 | return false; |
| 130 | } |
| 131 | return true; |
| 132 | } |
| 133 | |
| 134 | inline bool setVScreenInfo(int fd, fb_var_screeninfo& vinfo) { |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 135 | if (ioctl(fd, FBIOPUT_VSCREENINFO, &vinfo) < 0) { |
| 136 | ALOGE("Failed to call ioctl FBIOPUT_VSCREENINFO err=%s", |
| 137 | strerror(errno)); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 138 | return false; |
| 139 | } |
| 140 | return true; |
| 141 | } |
| 142 | |
| 143 | inline bool startRotator(int fd, msm_rotator_img_info& rot) { |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 144 | 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 Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 147 | return false; |
| 148 | } |
| 149 | return true; |
| 150 | } |
| 151 | |
| 152 | inline bool rotate(int fd, msm_rotator_data_info& rot) { |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 153 | 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 Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 156 | return false; |
| 157 | } |
| 158 | return true; |
| 159 | } |
| 160 | |
| 161 | inline bool setOverlay(int fd, mdp_overlay& ov) { |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 162 | if (ioctl(fd, MSMFB_OVERLAY_SET, &ov) < 0) { |
| 163 | ALOGE("Failed to call ioctl MSMFB_OVERLAY_SET err=%s", |
| 164 | strerror(errno)); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 165 | return false; |
| 166 | } |
| 167 | return true; |
| 168 | } |
| 169 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 170 | inline bool endRotator(int fd, uint32_t sessionId) { |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 171 | 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 Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 174 | return false; |
| 175 | } |
| 176 | return true; |
| 177 | } |
| 178 | |
| 179 | inline bool unsetOverlay(int fd, int ovId) { |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 180 | if (ioctl(fd, MSMFB_OVERLAY_UNSET, &ovId) < 0) { |
| 181 | ALOGE("Failed to call ioctl MSMFB_OVERLAY_UNSET err=%s", |
| 182 | strerror(errno)); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 183 | return false; |
| 184 | } |
| 185 | return true; |
| 186 | } |
| 187 | |
| 188 | inline bool getOverlay(int fd, mdp_overlay& ov) { |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 189 | if (ioctl(fd, MSMFB_OVERLAY_GET, &ov) < 0) { |
| 190 | ALOGE("Failed to call ioctl MSMFB_OVERLAY_GET err=%s", |
| 191 | strerror(errno)); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 192 | return false; |
| 193 | } |
| 194 | return true; |
| 195 | } |
| 196 | |
| 197 | inline bool play(int fd, msmfb_overlay_data& od) { |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 198 | if (ioctl(fd, MSMFB_OVERLAY_PLAY, &od) < 0) { |
| 199 | ALOGE("Failed to call ioctl MSMFB_OVERLAY_PLAY err=%s", |
| 200 | strerror(errno)); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 201 | return false; |
| 202 | } |
| 203 | return true; |
| 204 | } |
| 205 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 206 | inline bool set3D(int fd, msmfb_overlay_3d& ov) { |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 207 | if (ioctl(fd, MSMFB_OVERLAY_3D, &ov) < 0) { |
| 208 | ALOGE("Failed to call ioctl MSMFB_OVERLAY_3D err=%s", |
| 209 | strerror(errno)); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 210 | return false; |
| 211 | } |
| 212 | return true; |
| 213 | } |
| 214 | |
Saurabh Shah | c8118ac | 2013-06-27 10:03:19 -0700 | [diff] [blame^] | 215 | inline 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 | |
| 224 | inline 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 | |
| 238 | inline 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 | |
| 252 | inline 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 | |
| 261 | inline 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 Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 270 | /* dump funcs */ |
| 271 | inline 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 | } |
| 276 | inline 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 | } |
| 280 | inline 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 Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 287 | /* |
| 288 | Commented off to prevent verbose logging, since user_data could have 8 or so |
| 289 | fields which are mostly 0 |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 290 | dump("user_data", ov.user_data, |
| 291 | sizeof(ov.user_data)/sizeof(ov.user_data[0])); |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 292 | */ |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 293 | } |
| 294 | inline 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 | } |
| 299 | inline 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 | |
| 304 | inline 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 | } |
| 309 | inline 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 | } |
| 315 | inline void dump(const char* const s, const msm_rotator_img_info& rot) { |
Ramkumar Radhakrishnan | 288f8c7 | 2013-01-15 11:37:54 -0800 | [diff] [blame] | 316 | ALOGE("%s msm_rotator_img_info sessid=%u dstx=%d dsty=%d rot=%d, ena=%d scale=%d", |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 317 | s, rot.session_id, rot.dst_x, rot.dst_y, |
Ramkumar Radhakrishnan | 288f8c7 | 2013-01-15 11:37:54 -0800 | [diff] [blame] | 318 | rot.rotations, rot.enable, rot.downscale_ratio); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 319 | dump("src", rot.src); |
| 320 | dump("dst", rot.dst); |
| 321 | dump("src_rect", rot.src_rect); |
| 322 | } |
| 323 | inline void dump(const char* const s, const msm_rotator_data_info& rot) { |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 324 | ALOGE("%s msm_rotator_data_info sessid=%u verkey=%d", |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 325 | 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 | } |
| 331 | inline void dump(const char* const s, const fb_fix_screeninfo& finfo) { |
| 332 | ALOGE("%s fb_fix_screeninfo type=%d", s, finfo.type); |
| 333 | } |
| 334 | inline 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 Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 339 | } // mdp_wrapper |
| 340 | |
| 341 | } // overlay |
| 342 | |
| 343 | #endif // MDP_WRAPPER_H |