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