Home | History | Annotate | Download | only in liboverlay
      1 /*
      2 * Copyright (c) 2011, The Linux Foundation. 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 The Linux Foundation 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_3D */
     79 bool set3D(int fd, msmfb_overlay_3d& ov);
     80 
     81 /* the following are helper functions for dumping
     82  * msm_mdp and friends*/
     83 void dump(const char* const s, const msmfb_overlay_data& ov);
     84 void dump(const char* const s, const msmfb_data& ov);
     85 void dump(const char* const s, const mdp_overlay& ov);
     86 void dump(const char* const s, const msmfb_overlay_3d& ov);
     87 void dump(const char* const s, const uint32_t u[], uint32_t cnt);
     88 void dump(const char* const s, const msmfb_img& ov);
     89 void dump(const char* const s, const mdp_rect& ov);
     90 
     91 /* and rotator */
     92 void dump(const char* const s, const msm_rotator_img_info& rot);
     93 void dump(const char* const s, const msm_rotator_data_info& rot);
     94 
     95 /* info */
     96 void dump(const char* const s, const fb_fix_screeninfo& finfo);
     97 void dump(const char* const s, const fb_var_screeninfo& vinfo);
     98 
     99 //---------------Inlines -------------------------------------
    100 
    101 inline bool getFScreenInfo(int fd, fb_fix_screeninfo& finfo) {
    102     if (ioctl(fd, FBIOGET_FSCREENINFO, &finfo) < 0) {
    103         ALOGE("Failed to call ioctl FBIOGET_FSCREENINFO err=%s",
    104                 strerror(errno));
    105         return false;
    106     }
    107     return true;
    108 }
    109 
    110 inline bool getVScreenInfo(int fd, fb_var_screeninfo& vinfo) {
    111     if (ioctl(fd, FBIOGET_VSCREENINFO, &vinfo) < 0) {
    112         ALOGE("Failed to call ioctl FBIOGET_VSCREENINFO err=%s",
    113                 strerror(errno));
    114         return false;
    115     }
    116     return true;
    117 }
    118 
    119 inline bool setVScreenInfo(int fd, fb_var_screeninfo& vinfo) {
    120     if (ioctl(fd, FBIOPUT_VSCREENINFO, &vinfo) < 0) {
    121         ALOGE("Failed to call ioctl FBIOPUT_VSCREENINFO err=%s",
    122                 strerror(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) < 0){
    130         ALOGE("Failed to call ioctl MSM_ROTATOR_IOCTL_START err=%s",
    131                 strerror(errno));
    132         return false;
    133     }
    134     return true;
    135 }
    136 
    137 inline bool rotate(int fd, msm_rotator_data_info& rot) {
    138     if (ioctl(fd, MSM_ROTATOR_IOCTL_ROTATE, &rot) < 0) {
    139         ALOGE("Failed to call ioctl MSM_ROTATOR_IOCTL_ROTATE err=%s",
    140                 strerror(errno));
    141         return false;
    142     }
    143     return true;
    144 }
    145 
    146 inline bool setOverlay(int fd, mdp_overlay& ov) {
    147     if (ioctl(fd, MSMFB_OVERLAY_SET, &ov) < 0) {
    148         ALOGE("Failed to call ioctl MSMFB_OVERLAY_SET err=%s",
    149                 strerror(errno));
    150         return false;
    151     }
    152     return true;
    153 }
    154 
    155 inline bool endRotator(int fd, uint32_t sessionId) {
    156     if (ioctl(fd, MSM_ROTATOR_IOCTL_FINISH, &sessionId) < 0) {
    157         ALOGE("Failed to call ioctl MSM_ROTATOR_IOCTL_FINISH err=%s",
    158                 strerror(errno));
    159         return false;
    160     }
    161     return true;
    162 }
    163 
    164 inline bool unsetOverlay(int fd, int ovId) {
    165     if (ioctl(fd, MSMFB_OVERLAY_UNSET, &ovId) < 0) {
    166         ALOGE("Failed to call ioctl MSMFB_OVERLAY_UNSET err=%s",
    167                 strerror(errno));
    168         return false;
    169     }
    170     return true;
    171 }
    172 
    173 inline bool getOverlay(int fd, mdp_overlay& ov) {
    174     if (ioctl(fd, MSMFB_OVERLAY_GET, &ov) < 0) {
    175         ALOGE("Failed to call ioctl MSMFB_OVERLAY_GET err=%s",
    176                 strerror(errno));
    177         return false;
    178     }
    179     return true;
    180 }
    181 
    182 inline bool play(int fd, msmfb_overlay_data& od) {
    183     if (ioctl(fd, MSMFB_OVERLAY_PLAY, &od) < 0) {
    184         ALOGE("Failed to call ioctl MSMFB_OVERLAY_PLAY err=%s",
    185                 strerror(errno));
    186         return false;
    187     }
    188     return true;
    189 }
    190 
    191 inline bool set3D(int fd, msmfb_overlay_3d& ov) {
    192     if (ioctl(fd, MSMFB_OVERLAY_3D, &ov) < 0) {
    193         ALOGE("Failed to call ioctl MSMFB_OVERLAY_3D err=%s",
    194                 strerror(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     /*
    218     Commented off to prevent verbose logging, since user_data could have 8 or so
    219     fields which are mostly 0
    220     dump("user_data", ov.user_data,
    221             sizeof(ov.user_data)/sizeof(ov.user_data[0]));
    222     */
    223 }
    224 inline void dump(const char* const s, const msmfb_img& ov) {
    225     ALOGE("%s msmfb_img w=%d h=%d format=%d %s",
    226             s, ov.width, ov.height, ov.format,
    227             overlay::utils::getFormatString(ov.format));
    228 }
    229 inline void dump(const char* const s, const mdp_rect& ov) {
    230     ALOGE("%s mdp_rect x=%d y=%d w=%d h=%d",
    231             s, ov.x, ov.y, ov.w, ov.h);
    232 }
    233 
    234 inline void dump(const char* const s, const msmfb_overlay_3d& ov) {
    235     ALOGE("%s msmfb_overlay_3d 3d=%d w=%d h=%d",
    236             s, ov.is_3d, ov.width, ov.height);
    237 
    238 }
    239 inline void dump(const char* const s, const uint32_t u[], uint32_t cnt) {
    240     ALOGE("%s user_data cnt=%d", s, cnt);
    241     for(uint32_t i=0; i < cnt; ++i) {
    242         ALOGE("i=%d val=%d", i, u[i]);
    243     }
    244 }
    245 inline void dump(const char* const s, const msm_rotator_img_info& rot) {
    246     ALOGE("%s msm_rotator_img_info sessid=%u dstx=%d dsty=%d rot=%d, ena=%d scale=%d",
    247             s, rot.session_id, rot.dst_x, rot.dst_y,
    248             rot.rotations, rot.enable, rot.downscale_ratio);
    249     dump("src", rot.src);
    250     dump("dst", rot.dst);
    251     dump("src_rect", rot.src_rect);
    252 }
    253 inline void dump(const char* const s, const msm_rotator_data_info& rot) {
    254     ALOGE("%s msm_rotator_data_info sessid=%u verkey=%d",
    255             s, rot.session_id, rot.version_key);
    256     dump("src", rot.src);
    257     dump("dst", rot.dst);
    258     dump("src_chroma", rot.src_chroma);
    259     dump("dst_chroma", rot.dst_chroma);
    260 }
    261 inline void dump(const char* const s, const fb_fix_screeninfo& finfo) {
    262     ALOGE("%s fb_fix_screeninfo type=%d", s, finfo.type);
    263 }
    264 inline void dump(const char* const s, const fb_var_screeninfo& vinfo) {
    265     ALOGE("%s fb_var_screeninfo xres=%d yres=%d",
    266             s, vinfo.xres, vinfo.yres);
    267 }
    268 
    269 } // mdp_wrapper
    270 
    271 } // overlay
    272 
    273 #endif // MDP_WRAPPER_H
    274