Home | History | Annotate | Download | only in liboverlay
      1 /*
      2 * Copyright (c) 2012-2013, 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 OVERLAY_CTRLDATA_H
     31 #define OVERLAY_CTRLDATA_H
     32 
     33 #include "overlayUtils.h"
     34 #include "overlayMdp.h"
     35 #include "gralloc_priv.h" // INTERLACE_MASK
     36 
     37 namespace ovutils = overlay::utils;
     38 
     39 namespace overlay {
     40 
     41 /*
     42 * Sequence to use:
     43 * init
     44 * start
     45 * setXXX
     46 * close
     47 * */
     48 class Ctrl : utils::NoCopy {
     49 public:
     50 
     51     /* ctor */
     52     explicit Ctrl(const int& dpy);
     53     /* dtor close */
     54     ~Ctrl();
     55 
     56     /* set source using whf, orient and wait flag */
     57     void setSource(const utils::PipeArgs& args);
     58     /* set crop info and pass it down to mdp */
     59     void setCrop(const utils::Dim& d);
     60     /* set color for mdp pipe */
     61     void setColor(const uint32_t color);
     62     /* set orientation */
     63     void setTransform(const utils::eTransform& p);
     64     /* set mdp position using dim */
     65     void setPosition(const utils::Dim& dim);
     66     /* set mdp visual params using metadata */
     67     bool setVisualParams(const MetaData_t &metadata);
     68     /* set pipe type RGB/DMA/VG */
     69     void setPipeType(const utils::eMdpPipeType& pType);
     70     /* mdp set overlay/commit changes */
     71     bool commit();
     72 
     73     /* ctrl id */
     74     int  getPipeId() const;
     75     /* ctrl fd */
     76     int  getFd() const;
     77     /* retrieve crop data */
     78     utils::Dim getCrop() const;
     79     utils::Dim getPosition() const;
     80     /* Update the src format based on rotator's dest */
     81     void updateSrcFormat(const uint32_t& rotDstFormat);
     82     /* return pipe priority */
     83     uint8_t getPriority() const;
     84     /* dump the state of the object */
     85     void dump() const;
     86     /* Return the dump in the specified buffer */
     87     void getDump(char *buf, size_t len);
     88 
     89     static bool validateAndSet(Ctrl* ctrlArray[], const int& count,
     90             const int& fbFd);
     91 private:
     92     // mdp ctrl struct(info e.g.)
     93     MdpCtrl *mMdp;
     94 };
     95 
     96 
     97 class Data : utils::NoCopy {
     98 public:
     99     /* init, reset */
    100     explicit Data(const int& dpy);
    101     /* calls close */
    102     ~Data();
    103     /* set overlay pipe id in the mdp struct */
    104     void setPipeId(int id);
    105     /* get overlay id in the mdp struct */
    106     int getPipeId() const;
    107     /* queue buffer to the overlay */
    108     bool queueBuffer(int fd, uint32_t offset);
    109     /* sump the state of the obj */
    110     void dump() const;
    111     /* Return the dump in the specified buffer */
    112     void getDump(char *buf, size_t len);
    113 
    114 private:
    115     // mdp data struct
    116     MdpData *mMdp;
    117 };
    118 
    119 //-------------Inlines-------------------------------
    120 
    121 inline Ctrl::Ctrl(const int& dpy) : mMdp(new MdpCtrl(dpy)) {
    122 }
    123 
    124 inline Ctrl::~Ctrl() {
    125     delete mMdp;
    126 }
    127 
    128 inline void Ctrl::setSource(const utils::PipeArgs& args)
    129 {
    130     mMdp->setSource(args);
    131 }
    132 
    133 inline void Ctrl::setPosition(const utils::Dim& dim)
    134 {
    135     mMdp->setPosition(dim);
    136 }
    137 
    138 inline void Ctrl::setTransform(const utils::eTransform& orient)
    139 {
    140     mMdp->setTransform(orient);
    141 }
    142 
    143 inline void Ctrl::setCrop(const utils::Dim& d)
    144 {
    145     mMdp->setCrop(d);
    146 }
    147 
    148 inline void Ctrl::setColor(const uint32_t color)
    149 {
    150     mMdp->setColor(color);
    151 }
    152 
    153 inline bool Ctrl::setVisualParams(const MetaData_t &metadata)
    154 {
    155     if (!mMdp->setVisualParams(metadata)) {
    156         ALOGE("Ctrl setVisualParams failed in MDP setVisualParams");
    157         return false;
    158     }
    159     return true;
    160 }
    161 
    162 inline void Ctrl::setPipeType(const utils::eMdpPipeType& pType)
    163 {
    164     mMdp->setPipeType(pType);
    165 }
    166 
    167 inline void Ctrl::dump() const {
    168     ALOGE("== Dump Ctrl start ==");
    169     mMdp->dump();
    170     ALOGE("== Dump Ctrl end ==");
    171 }
    172 
    173 inline bool Ctrl::commit() {
    174     if(!mMdp->set()) {
    175         ALOGE("Ctrl commit failed set overlay");
    176         return false;
    177     }
    178     return true;
    179 }
    180 
    181 inline int Ctrl::getPipeId() const {
    182     return mMdp->getPipeId();
    183 }
    184 
    185 inline int Ctrl::getFd() const {
    186     return mMdp->getFd();
    187 }
    188 
    189 inline void Ctrl::updateSrcFormat(const uint32_t& rotDstFmt) {
    190     mMdp->updateSrcFormat(rotDstFmt);
    191 }
    192 
    193 inline bool Ctrl::validateAndSet(Ctrl* ctrlArray[], const int& count,
    194         const int& fbFd) {
    195     MdpCtrl* mdpCtrlArray[count];
    196     memset(&mdpCtrlArray, 0, sizeof(mdpCtrlArray));
    197 
    198     for(int i = 0; i < count; i++) {
    199         mdpCtrlArray[i] = ctrlArray[i]->mMdp;
    200     }
    201 
    202     bool ret = MdpCtrl::validateAndSet(mdpCtrlArray, count, fbFd);
    203     return ret;
    204 }
    205 
    206 inline utils::Dim Ctrl::getCrop() const {
    207     return mMdp->getSrcRectDim();
    208 }
    209 
    210 inline utils::Dim Ctrl::getPosition() const {
    211     return mMdp->getDstRectDim();
    212 }
    213 
    214 inline uint8_t Ctrl::getPriority() const {
    215     return mMdp->getPriority();
    216 }
    217 
    218 inline void Ctrl::getDump(char *buf, size_t len) {
    219     mMdp->getDump(buf, len);
    220 }
    221 
    222 inline Data::Data(const int& dpy) : mMdp(new MdpData(dpy)) {
    223 }
    224 
    225 inline Data::~Data() {
    226     delete mMdp;
    227 }
    228 
    229 inline void Data::setPipeId(int id) { mMdp->setPipeId(id); }
    230 
    231 inline int Data::getPipeId() const { return mMdp->getPipeId(); }
    232 
    233 inline bool Data::queueBuffer(int fd, uint32_t offset) {
    234     return mMdp->play(fd, offset);
    235 }
    236 
    237 inline void Data::dump() const {
    238     ALOGE("== Dump Data MDP start ==");
    239     mMdp->dump();
    240     ALOGE("== Dump Data MDP end ==");
    241 }
    242 
    243 inline void Data::getDump(char *buf, size_t len) {
    244     mMdp->getDump(buf, len);
    245 }
    246 
    247 } // overlay
    248 
    249 #endif
    250