Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1 | /* |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame^] | 2 | * Copyright (c) 2011, Code Aurora Forum. 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. |
| 13 | * * Neither the name of Code Aurora Forum, Inc. nor the names of its |
| 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 | |
| 78 | /* MSMFB_OVERLAY_PLAY_WAIT */ |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame^] | 79 | bool waitForVsync(int fd, msmfb_overlay_data& od); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 80 | |
| 81 | /* MSMFB_OVERLAY_3D */ |
| 82 | bool set3D(int fd, msmfb_overlay_3d& ov); |
| 83 | |
| 84 | /* the following are helper functions for dumping |
| 85 | * msm_mdp and friends*/ |
| 86 | void dump(const char* const s, const msmfb_overlay_data& ov); |
| 87 | void dump(const char* const s, const msmfb_data& ov); |
| 88 | void dump(const char* const s, const mdp_overlay& ov); |
| 89 | void dump(const char* const s, const msmfb_overlay_3d& ov); |
| 90 | void dump(const char* const s, const uint32_t u[], uint32_t cnt); |
| 91 | void dump(const char* const s, const msmfb_img& ov); |
| 92 | void dump(const char* const s, const mdp_rect& ov); |
| 93 | |
| 94 | /* and rotator */ |
| 95 | void dump(const char* const s, const msm_rotator_img_info& rot); |
| 96 | void dump(const char* const s, const msm_rotator_data_info& rot); |
| 97 | |
| 98 | /* info */ |
| 99 | void dump(const char* const s, const fb_fix_screeninfo& finfo); |
| 100 | void dump(const char* const s, const fb_var_screeninfo& vinfo); |
| 101 | |
| 102 | //---------------Inlines ------------------------------------- |
| 103 | |
| 104 | inline bool getFScreenInfo(int fd, fb_fix_screeninfo& finfo) { |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame^] | 105 | if (ioctl(fd, FBIOGET_FSCREENINFO, &finfo) < 0) { |
| 106 | ALOGE("Failed to call ioctl FBIOGET_FSCREENINFO err=%s", |
| 107 | strerror(errno)); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 108 | return false; |
| 109 | } |
| 110 | return true; |
| 111 | } |
| 112 | |
| 113 | inline bool getVScreenInfo(int fd, fb_var_screeninfo& vinfo) { |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame^] | 114 | if (ioctl(fd, FBIOGET_VSCREENINFO, &vinfo) < 0) { |
| 115 | ALOGE("Failed to call ioctl FBIOGET_VSCREENINFO err=%s", |
| 116 | strerror(errno)); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 117 | return false; |
| 118 | } |
| 119 | return true; |
| 120 | } |
| 121 | |
| 122 | inline bool setVScreenInfo(int fd, fb_var_screeninfo& vinfo) { |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame^] | 123 | if (ioctl(fd, FBIOPUT_VSCREENINFO, &vinfo) < 0) { |
| 124 | ALOGE("Failed to call ioctl FBIOPUT_VSCREENINFO err=%s", |
| 125 | strerror(errno)); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 126 | return false; |
| 127 | } |
| 128 | return true; |
| 129 | } |
| 130 | |
| 131 | inline bool startRotator(int fd, msm_rotator_img_info& rot) { |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame^] | 132 | if (ioctl(fd, MSM_ROTATOR_IOCTL_START, &rot) < 0){ |
| 133 | ALOGE("Failed to call ioctl MSM_ROTATOR_IOCTL_START err=%s", |
| 134 | strerror(errno)); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 135 | return false; |
| 136 | } |
| 137 | return true; |
| 138 | } |
| 139 | |
| 140 | inline bool rotate(int fd, msm_rotator_data_info& rot) { |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame^] | 141 | if (ioctl(fd, MSM_ROTATOR_IOCTL_ROTATE, &rot) < 0) { |
| 142 | ALOGE("Failed to call ioctl MSM_ROTATOR_IOCTL_ROTATE err=%s", |
| 143 | strerror(errno)); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 144 | return false; |
| 145 | } |
| 146 | return true; |
| 147 | } |
| 148 | |
| 149 | inline bool setOverlay(int fd, mdp_overlay& ov) { |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame^] | 150 | if (ioctl(fd, MSMFB_OVERLAY_SET, &ov) < 0) { |
| 151 | ALOGE("Failed to call ioctl MSMFB_OVERLAY_SET err=%s", |
| 152 | strerror(errno)); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 153 | return false; |
| 154 | } |
| 155 | return true; |
| 156 | } |
| 157 | |
| 158 | inline bool endRotator(int fd, int sessionId) { |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame^] | 159 | if (ioctl(fd, MSM_ROTATOR_IOCTL_FINISH, &sessionId) < 0) { |
| 160 | ALOGE("Failed to call ioctl MSM_ROTATOR_IOCTL_FINISH err=%s", |
| 161 | strerror(errno)); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 162 | return false; |
| 163 | } |
| 164 | return true; |
| 165 | } |
| 166 | |
| 167 | inline bool unsetOverlay(int fd, int ovId) { |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame^] | 168 | if (ioctl(fd, MSMFB_OVERLAY_UNSET, &ovId) < 0) { |
| 169 | ALOGE("Failed to call ioctl MSMFB_OVERLAY_UNSET err=%s", |
| 170 | strerror(errno)); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 171 | return false; |
| 172 | } |
| 173 | return true; |
| 174 | } |
| 175 | |
| 176 | inline bool getOverlay(int fd, mdp_overlay& ov) { |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame^] | 177 | if (ioctl(fd, MSMFB_OVERLAY_GET, &ov) < 0) { |
| 178 | ALOGE("Failed to call ioctl MSMFB_OVERLAY_GET err=%s", |
| 179 | strerror(errno)); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 180 | return false; |
| 181 | } |
| 182 | return true; |
| 183 | } |
| 184 | |
| 185 | inline bool play(int fd, msmfb_overlay_data& od) { |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame^] | 186 | if (ioctl(fd, MSMFB_OVERLAY_PLAY, &od) < 0) { |
| 187 | ALOGE("Failed to call ioctl MSMFB_OVERLAY_PLAY err=%s", |
| 188 | strerror(errno)); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 189 | return false; |
| 190 | } |
| 191 | return true; |
| 192 | } |
| 193 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame^] | 194 | inline bool waitForVsync(int fd, msmfb_overlay_data& od) { |
| 195 | if (ioctl(fd, MSMFB_OVERLAY_PLAY_WAIT, &od) < 0) { |
| 196 | ALOGE("Failed to call ioctl MSMFB_OVERLAY_PLAY_WAIT err=%s", |
| 197 | strerror(errno)); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 198 | return false; |
| 199 | } |
| 200 | return true; |
| 201 | } |
| 202 | |
| 203 | inline bool set3D(int fd, msmfb_overlay_3d& ov) { |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame^] | 204 | if (ioctl(fd, MSMFB_OVERLAY_3D, &ov) < 0) { |
| 205 | ALOGE("Failed to call ioctl MSMFB_OVERLAY_3D err=%s", |
| 206 | strerror(errno)); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 207 | return false; |
| 208 | } |
| 209 | return true; |
| 210 | } |
| 211 | |
| 212 | /* dump funcs */ |
| 213 | inline void dump(const char* const s, const msmfb_overlay_data& ov) { |
| 214 | ALOGE("%s msmfb_overlay_data id=%d", |
| 215 | s, ov.id); |
| 216 | dump("data", ov.data); |
| 217 | } |
| 218 | inline void dump(const char* const s, const msmfb_data& ov) { |
| 219 | ALOGE("%s msmfb_data offset=%d memid=%d id=%d flags=0x%x priv=%d", |
| 220 | s, ov.offset, ov.memory_id, ov.id, ov.flags, ov.priv); |
| 221 | } |
| 222 | inline void dump(const char* const s, const mdp_overlay& ov) { |
| 223 | ALOGE("%s mdp_overlay z=%d fg=%d alpha=%d mask=%d flags=0x%x id=%d", |
| 224 | s, ov.z_order, ov.is_fg, ov.alpha, |
| 225 | ov.transp_mask, ov.flags, ov.id); |
| 226 | dump("src", ov.src); |
| 227 | dump("src_rect", ov.src_rect); |
| 228 | dump("dst_rect", ov.dst_rect); |
| 229 | dump("user_data", ov.user_data, |
| 230 | sizeof(ov.user_data)/sizeof(ov.user_data[0])); |
| 231 | } |
| 232 | inline void dump(const char* const s, const msmfb_img& ov) { |
| 233 | ALOGE("%s msmfb_img w=%d h=%d format=%d %s", |
| 234 | s, ov.width, ov.height, ov.format, |
| 235 | overlay::utils::getFormatString(ov.format)); |
| 236 | } |
| 237 | inline void dump(const char* const s, const mdp_rect& ov) { |
| 238 | ALOGE("%s mdp_rect x=%d y=%d w=%d h=%d", |
| 239 | s, ov.x, ov.y, ov.w, ov.h); |
| 240 | } |
| 241 | |
| 242 | inline void dump(const char* const s, const msmfb_overlay_3d& ov) { |
| 243 | ALOGE("%s msmfb_overlay_3d 3d=%d w=%d h=%d", |
| 244 | s, ov.is_3d, ov.width, ov.height); |
| 245 | |
| 246 | } |
| 247 | inline void dump(const char* const s, const uint32_t u[], uint32_t cnt) { |
| 248 | ALOGE("%s user_data cnt=%d", s, cnt); |
| 249 | for(uint32_t i=0; i < cnt; ++i) { |
| 250 | ALOGE("i=%d val=%d", i, u[i]); |
| 251 | } |
| 252 | } |
| 253 | inline void dump(const char* const s, const msm_rotator_img_info& rot) { |
| 254 | ALOGE("%s msm_rotator_img_info sessid=%d dstx=%d dsty=%d rot=%d, ena=%d", |
| 255 | s, rot.session_id, rot.dst_x, rot.dst_y, |
| 256 | rot.rotations, rot.enable); |
| 257 | dump("src", rot.src); |
| 258 | dump("dst", rot.dst); |
| 259 | dump("src_rect", rot.src_rect); |
| 260 | } |
| 261 | inline void dump(const char* const s, const msm_rotator_data_info& rot) { |
| 262 | ALOGE("%s msm_rotator_data_info sessid=%d verkey=%d", |
| 263 | s, rot.session_id, rot.version_key); |
| 264 | dump("src", rot.src); |
| 265 | dump("dst", rot.dst); |
| 266 | dump("src_chroma", rot.src_chroma); |
| 267 | dump("dst_chroma", rot.dst_chroma); |
| 268 | } |
| 269 | inline void dump(const char* const s, const fb_fix_screeninfo& finfo) { |
| 270 | ALOGE("%s fb_fix_screeninfo type=%d", s, finfo.type); |
| 271 | } |
| 272 | inline void dump(const char* const s, const fb_var_screeninfo& vinfo) { |
| 273 | ALOGE("%s fb_var_screeninfo xres=%d yres=%d", |
| 274 | s, vinfo.xres, vinfo.yres); |
| 275 | } |
| 276 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 277 | } // mdp_wrapper |
| 278 | |
| 279 | } // overlay |
| 280 | |
| 281 | #endif // MDP_WRAPPER_H |