Home | History | Annotate | Download | only in liboverlay
      1 /*
      2 * Copyright (C) 2008 The Android Open Source Project
      3 * Copyright (c) 2010-2013, The Linux Foundation. All rights reserved.
      4 *
      5 * Licensed under the Apache License, Version 2.0 (the "License");
      6 * you may not use this file except in compliance with the License.
      7 * You may obtain a copy of the License at
      8 *
      9 *      http://www.apache.org/licenses/LICENSE-2.0
     10 *
     11 * Unless required by applicable law or agreed to in writing, software
     12 * distributed under the License is distributed on an "AS IS" BASIS,
     13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14 * See the License for the specific language governing permissions and
     15 * limitations under the License.
     16 */
     17 
     18 #ifndef OVERLAY_MDP_H
     19 #define OVERLAY_MDP_H
     20 
     21 #include <linux/msm_mdp.h>
     22 
     23 #include "overlayUtils.h"
     24 #include "mdpWrapper.h"
     25 #include "qdMetaData.h"
     26 #ifdef USES_POST_PROCESSING
     27 #include "lib-postproc.h"
     28 #endif
     29 
     30 namespace overlay{
     31 
     32 /*
     33 * Mdp Ctrl holds corresponding fd and MDP related struct.
     34 * It is simple wrapper to MDP services
     35 * */
     36 class MdpCtrl {
     37 public:
     38     /* ctor reset */
     39     explicit MdpCtrl(const int& dpy);
     40     /* dtor close */
     41     ~MdpCtrl();
     42     /* init underlying device using fbnum for dpy */
     43     bool init(const int& dpy);
     44     /* unset overlay, reset and close fd */
     45     bool close();
     46     /* reset and set ov id to -1 / MSMFB_NEW_REQUEST */
     47     void reset();
     48     /* calls overlay set
     49      * Set would always consult last good known ov instance.
     50      * Only if it is different, set would actually exectue ioctl.
     51      * On a sucess ioctl. last good known ov instance is updated */
     52     bool set();
     53     /* Sets the source total width, height, format */
     54     void setSource(const utils::PipeArgs& pargs);
     55     /*
     56      * Sets ROI, the unpadded region, for source buffer.
     57      * Dim - ROI dimensions.
     58      */
     59     void setCrop(const utils::Dim& d);
     60     /* set color for mdp pipe */
     61     void setColor(const uint32_t color);
     62     void setTransform(const utils::eTransform& orient);
     63     /* given a dim and w/h, set overlay dim */
     64     void setPosition(const utils::Dim& dim);
     65     /* using user_data, sets/unsets roationvalue in mdp flags */
     66     void setRotationFlags();
     67     /* Update the src format with rotator's dest*/
     68     void updateSrcFormat(const uint32_t& rotDstFormat);
     69     /* dump state of the object */
     70     void dump() const;
     71     /* Return the dump in the specified buffer */
     72     void getDump(char *buf, size_t len);
     73     /* returns session id */
     74     int getPipeId() const;
     75     /* returns the fd associated to ctrl*/
     76     int getFd() const;
     77     /* returns a copy ro dst rect dim */
     78     utils::Dim getDstRectDim() const;
     79     /* returns a copy to src rect dim */
     80     utils::Dim getSrcRectDim() const;
     81     /* return pipe priority */
     82     uint8_t getPriority() const;
     83     /* setVisualParam */
     84     bool setVisualParams(const MetaData_t& data);
     85     /* sets pipe type RGB/DMA/VG */
     86     void setPipeType(const utils::eMdpPipeType& pType);
     87 
     88     static bool validateAndSet(MdpCtrl* mdpCtrlArray[], const int& count,
     89             const int& fbFd);
     90 private:
     91     /* Perform transformation calculations */
     92     void doTransform();
     93     void doDownscale();
     94     /* get orient / user_data[0] */
     95     int getOrient() const;
     96     /* returns flags from mdp structure */
     97     int getFlags() const;
     98     /* set flags to mdp structure */
     99     void setFlags(int f);
    100     /* set z order */
    101     void setZ(utils::eZorder z);
    102     /* return a copy of src whf*/
    103     utils::Whf getSrcWhf() const;
    104     /* set plane alpha */
    105     void setPlaneAlpha(int planeAlpha);
    106     /* set blending method */
    107     void setBlending(overlay::utils::eBlending blending);
    108 
    109     /* set src whf */
    110     void setSrcWhf(const utils::Whf& whf);
    111     /* set src/dst rect dim */
    112     void setSrcRectDim(const utils::Dim d);
    113     void setDstRectDim(const utils::Dim d);
    114     /* returns user_data[0]*/
    115     int getUserData() const;
    116     /* sets user_data[0] */
    117     void setUserData(int v);
    118 
    119     utils::eTransform mOrientation; //Holds requested orientation
    120     /* Actual overlay mdp structure */
    121     mdp_overlay   mOVInfo;
    122     /* FD for the mdp fbnum */
    123     OvFD          mFd;
    124     int mDpy;
    125 
    126 #ifdef USES_POST_PROCESSING
    127     /* PP Compute Params */
    128     struct compute_params mParams;
    129 #endif
    130 };
    131 
    132 /* MDP data */
    133 class MdpData {
    134 public:
    135     /* ctor reset data */
    136     explicit MdpData(const int& dpy);
    137     /* dtor close*/
    138     ~MdpData();
    139     /* init FD */
    140     bool init(const int& dpy);
    141     /* memset0 the underlying mdp object */
    142     void reset();
    143     /* close fd, and reset */
    144     bool close();
    145     /* set id of mdp data */
    146     void setPipeId(int id);
    147     /* return ses id of data */
    148     int getPipeId() const;
    149     /* get underlying fd*/
    150     int getFd() const;
    151     /* get memory_id */
    152     int getSrcMemoryId() const;
    153     /* calls wrapper play */
    154     bool play(int fd, uint32_t offset);
    155     /* dump state of the object */
    156     void dump() const;
    157     /* Return the dump in the specified buffer */
    158     void getDump(char *buf, size_t len);
    159 
    160 private:
    161 
    162     /* actual overlay mdp data */
    163     msmfb_overlay_data mOvData;
    164     /* fd to mdp fbnum */
    165     OvFD mFd;
    166 };
    167 
    168 //--------------Inlines---------------------------------
    169 
    170 /////   MdpCtrl  //////
    171 
    172 inline MdpCtrl::MdpCtrl(const int& dpy) {
    173     reset();
    174     init(dpy);
    175 }
    176 
    177 inline MdpCtrl::~MdpCtrl() {
    178     close();
    179 }
    180 
    181 inline int MdpCtrl::getOrient() const {
    182     return getUserData();
    183 }
    184 
    185 inline int MdpCtrl::getPipeId() const {
    186     return mOVInfo.id;
    187 }
    188 
    189 inline int MdpCtrl::getFd() const {
    190     return mFd.getFD();
    191 }
    192 
    193 inline int MdpCtrl::getFlags() const {
    194     return mOVInfo.flags;
    195 }
    196 
    197 inline void MdpCtrl::setFlags(int f) {
    198     mOVInfo.flags = f;
    199 }
    200 
    201 inline void MdpCtrl::setZ(overlay::utils::eZorder z) {
    202     mOVInfo.z_order = z;
    203 }
    204 
    205 inline void MdpCtrl::setPlaneAlpha(int planeAlpha) {
    206     mOVInfo.alpha = planeAlpha;
    207 }
    208 
    209 inline void MdpCtrl::setBlending(overlay::utils::eBlending blending) {
    210     switch((int) blending) {
    211     case utils::OVERLAY_BLENDING_OPAQUE:
    212         mOVInfo.blend_op = BLEND_OP_OPAQUE;
    213         break;
    214     case utils::OVERLAY_BLENDING_PREMULT:
    215         mOVInfo.blend_op = BLEND_OP_PREMULTIPLIED;
    216         break;
    217     case utils::OVERLAY_BLENDING_COVERAGE:
    218     default:
    219         mOVInfo.blend_op = BLEND_OP_COVERAGE;
    220     }
    221 }
    222 
    223 inline overlay::utils::Whf MdpCtrl::getSrcWhf() const {
    224     return utils::Whf(  mOVInfo.src.width,
    225                         mOVInfo.src.height,
    226                         mOVInfo.src.format);
    227 }
    228 
    229 inline void MdpCtrl::setSrcWhf(const overlay::utils::Whf& whf) {
    230     mOVInfo.src.width  = whf.w;
    231     mOVInfo.src.height = whf.h;
    232     mOVInfo.src.format = whf.format;
    233 }
    234 
    235 inline overlay::utils::Dim MdpCtrl::getSrcRectDim() const {
    236     return utils::Dim(  mOVInfo.src_rect.x,
    237                         mOVInfo.src_rect.y,
    238                         mOVInfo.src_rect.w,
    239                         mOVInfo.src_rect.h);
    240 }
    241 
    242 inline void MdpCtrl::setSrcRectDim(const overlay::utils::Dim d) {
    243     mOVInfo.src_rect.x = d.x;
    244     mOVInfo.src_rect.y = d.y;
    245     mOVInfo.src_rect.w = d.w;
    246     mOVInfo.src_rect.h = d.h;
    247 }
    248 
    249 inline overlay::utils::Dim MdpCtrl::getDstRectDim() const {
    250     return utils::Dim(  mOVInfo.dst_rect.x,
    251                         mOVInfo.dst_rect.y,
    252                         mOVInfo.dst_rect.w,
    253                         mOVInfo.dst_rect.h);
    254 }
    255 
    256 inline void MdpCtrl::setDstRectDim(const overlay::utils::Dim d) {
    257     mOVInfo.dst_rect.x = d.x;
    258     mOVInfo.dst_rect.y = d.y;
    259     mOVInfo.dst_rect.w = d.w;
    260     mOVInfo.dst_rect.h = d.h;
    261 }
    262 
    263 inline int MdpCtrl::getUserData() const { return mOVInfo.user_data[0]; }
    264 
    265 inline void MdpCtrl::setUserData(int v) { mOVInfo.user_data[0] = v; }
    266 
    267 inline void MdpCtrl::setRotationFlags() {
    268     const int u = getUserData();
    269     if (u & MDP_ROT_90)
    270         mOVInfo.flags |= MDP_SOURCE_ROTATED_90;
    271 }
    272 
    273 inline uint8_t MdpCtrl::getPriority() const {
    274     return mOVInfo.priority;
    275 }
    276 
    277 ///////    MdpData   //////
    278 
    279 inline MdpData::MdpData(const int& dpy) {
    280     reset();
    281     init(dpy);
    282 }
    283 
    284 inline MdpData::~MdpData() { close(); }
    285 
    286 inline void MdpData::reset() {
    287     overlay::utils::memset0(mOvData);
    288     mOvData.data.memory_id = -1;
    289 }
    290 
    291 inline bool MdpData::close() {
    292     reset();
    293     return mFd.close();
    294 }
    295 
    296 inline int MdpData::getSrcMemoryId() const { return mOvData.data.memory_id; }
    297 
    298 inline void MdpData::setPipeId(int id) { mOvData.id = id; }
    299 
    300 inline int MdpData::getPipeId() const { return mOvData.id; }
    301 
    302 inline int MdpData::getFd() const { return mFd.getFD(); }
    303 
    304 inline bool MdpData::play(int fd, uint32_t offset) {
    305     mOvData.data.memory_id = fd;
    306     mOvData.data.offset = offset;
    307     if(!mdp_wrapper::play(mFd.getFD(), mOvData)){
    308         ALOGE("MdpData failed to play");
    309         dump();
    310         return false;
    311     }
    312     return true;
    313 }
    314 
    315 } // overlay
    316 
    317 inline bool isEqual(float f1, float f2) {
    318         return ((int)(f1*100) == (int)(f2*100)) ? true : false;
    319 }
    320 
    321 #endif // OVERLAY_MDP_H
    322