Home | History | Annotate | Download | only in liboverlay
      1 /*
      2 * Copyright (c) 2011,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_ROTATOR_H
     31 #define OVERlAY_ROTATOR_H
     32 
     33 #include <stdlib.h>
     34 
     35 #include "mdpWrapper.h"
     36 #include "overlayUtils.h"
     37 #include "overlayMem.h"
     38 
     39 namespace overlay {
     40 
     41 /*
     42    Manages the case where new rotator memory needs to be
     43    allocated, before previous is freed, due to resolution change etc. If we make
     44    rotator memory to be always max size, irrespctive of source resolution then
     45    we don't need this RotMem wrapper. The inner class is sufficient.
     46 */
     47 struct RotMem {
     48     // Max rotator memory allocations
     49     enum { MAX_ROT_MEM = 2};
     50 
     51     //Manages the rotator buffer offsets.
     52     struct Mem {
     53         Mem();
     54         ~Mem();
     55         bool valid() { return m.valid(); }
     56         bool close() { return m.close(); }
     57         uint32_t size() const { return m.bufSz(); }
     58         void setReleaseFd(const int& fence);
     59         // Max rotator buffers
     60         enum { ROT_NUM_BUFS = 2 };
     61         // rotator data info dst offset
     62         uint32_t mRotOffset[ROT_NUM_BUFS];
     63         int mRelFence[ROT_NUM_BUFS];
     64         // current offset slot from mRotOffset
     65         uint32_t mCurrOffset;
     66         OvMem m;
     67     };
     68 
     69     RotMem() : _curr(0) {}
     70     Mem& curr() { return m[_curr % MAX_ROT_MEM]; }
     71     const Mem& curr() const { return m[_curr % MAX_ROT_MEM]; }
     72     Mem& prev() { return m[(_curr+1) % MAX_ROT_MEM]; }
     73     RotMem& operator++() { ++_curr; return *this; }
     74     void setReleaseFd(const int& fence) { curr().setReleaseFd(fence); }
     75     bool close();
     76     uint32_t _curr;
     77     Mem m[MAX_ROT_MEM];
     78 };
     79 
     80 class Rotator
     81 {
     82 public:
     83     enum { TYPE_MDP, TYPE_MDSS };
     84     virtual ~Rotator();
     85     virtual void setSource(const utils::Whf& wfh) = 0;
     86     virtual void setSource(const utils::Whf& awhf, const utils::Whf& owhf) = 0;
     87     virtual void setFlags(const utils::eMdpFlags& flags) = 0;
     88     virtual void setTransform(const utils::eTransform& rot) = 0;
     89     virtual bool commit() = 0;
     90     virtual void setDownscale(int ds) = 0;
     91     virtual int getDstMemId() const = 0;
     92     virtual uint32_t getDstOffset() const = 0;
     93     virtual uint32_t getDstFormat() const = 0;
     94     virtual uint32_t getSessId() const = 0;
     95     virtual bool queueBuffer(int fd, uint32_t offset) = 0;
     96     virtual void dump() const = 0;
     97     virtual void getDump(char *buf, size_t len) const = 0;
     98     void setReleaseFd(const int& fence) { mMem.setReleaseFd(fence); }
     99     static Rotator *getRotator();
    100 
    101 protected:
    102     /* Rotator memory manager */
    103     RotMem mMem;
    104     explicit Rotator() {}
    105     static uint32_t calcOutputBufSize(const utils::Whf& destWhf);
    106 
    107 private:
    108     /*Returns rotator h/w type */
    109     static int getRotatorHwType();
    110     friend class RotMgr;
    111 };
    112 
    113 /*
    114 * MDP rot holds MDP's rotation related structures.
    115 *
    116 * */
    117 class MdpRot : public Rotator {
    118 public:
    119     virtual ~MdpRot();
    120     virtual void setSource(const utils::Whf& wfh);
    121     virtual void setSource(const utils::Whf& awhf, const utils::Whf& owhf);
    122     virtual void setFlags(const utils::eMdpFlags& flags);
    123     virtual void setTransform(const utils::eTransform& rot);
    124     virtual bool commit();
    125     virtual void setDownscale(int ds);
    126     virtual int getDstMemId() const;
    127     virtual uint32_t getDstOffset() const;
    128     virtual uint32_t getDstFormat() const;
    129     virtual uint32_t getSessId() const;
    130     virtual bool queueBuffer(int fd, uint32_t offset);
    131     virtual void dump() const;
    132     virtual void getDump(char *buf, size_t len) const;
    133 
    134 private:
    135     explicit MdpRot();
    136     bool init();
    137     bool close();
    138     void setRotations(uint32_t r);
    139     bool enabled () const;
    140     /* remap rot buffers */
    141     bool remap(uint32_t numbufs);
    142     bool open_i(uint32_t numbufs, uint32_t bufsz);
    143     /* Deferred transform calculations */
    144     void doTransform();
    145     /* reset underlying data, basically memset 0 */
    146     void reset();
    147     /* return true if current rotator config is different
    148      * than last known config */
    149     bool rotConfChanged() const;
    150     /* save mRotImgInfo to be last known good config*/
    151     void save();
    152     /* Calculates the rotator's o/p buffer size post the transform calcs and
    153      * knowing the o/p format depending on whether fastYuv is enabled or not */
    154     uint32_t calcOutputBufSize();
    155 
    156     /* rot info*/
    157     msm_rotator_img_info mRotImgInfo;
    158     /* Original buffer dimensions*/
    159     utils::Whf mOrigWhf;
    160     /* Last saved rot info*/
    161     msm_rotator_img_info mLSRotImgInfo;
    162     /* rot data */
    163     msm_rotator_data_info mRotDataInfo;
    164     /* Orientation */
    165     utils::eTransform mOrientation;
    166     /* rotator fd */
    167     OvFD mFd;
    168 
    169     friend Rotator* Rotator::getRotator();
    170 };
    171 
    172 /*
    173 +* MDSS Rot holds MDSS's rotation related structures.
    174 +*
    175 +* */
    176 class MdssRot : public Rotator {
    177 public:
    178     virtual ~MdssRot();
    179     virtual void setSource(const utils::Whf& whf);
    180     virtual void setSource(const utils::Whf& awhf, const utils::Whf& owhf);
    181     virtual void setFlags(const utils::eMdpFlags& flags);
    182     virtual void setTransform(const utils::eTransform& rot);
    183     virtual bool commit();
    184     virtual void setDownscale(int ds);
    185     virtual int getDstMemId() const;
    186     virtual uint32_t getDstOffset() const;
    187     virtual uint32_t getDstFormat() const;
    188     virtual uint32_t getSessId() const;
    189     virtual bool queueBuffer(int fd, uint32_t offset);
    190     virtual void dump() const;
    191     virtual void getDump(char *buf, size_t len) const;
    192 
    193 private:
    194     explicit MdssRot();
    195     bool init();
    196     bool close();
    197     void setRotations(uint32_t r);
    198     bool enabled () const;
    199     /* remap rot buffers */
    200     bool remap(uint32_t numbufs);
    201     bool open_i(uint32_t numbufs, uint32_t bufsz);
    202     /* Deferred transform calculations */
    203     void doTransform();
    204     /* reset underlying data, basically memset 0 */
    205     void reset();
    206     /* Calculates the rotator's o/p buffer size post the transform calcs and
    207      * knowing the o/p format depending on whether fastYuv is enabled or not */
    208     uint32_t calcOutputBufSize();
    209 
    210     /* MdssRot info structure */
    211     mdp_overlay   mRotInfo;
    212     /* MdssRot data structure */
    213     msmfb_overlay_data mRotData;
    214     /* Orientation */
    215     utils::eTransform mOrientation;
    216     /* rotator fd */
    217     OvFD mFd;
    218     /* Enable/Disable Mdss Rot*/
    219     bool mEnabled;
    220 
    221     friend Rotator* Rotator::getRotator();
    222 };
    223 
    224 // Holder of rotator objects. Manages lifetimes
    225 class RotMgr {
    226 public:
    227     //Maximum sessions based on VG pipes, since rotator is used only for videos.
    228     //Even though we can have 4 mixer stages, that much may be unnecessary.
    229     enum { MAX_ROT_SESS = 3 };
    230     RotMgr();
    231     ~RotMgr();
    232     void configBegin();
    233     void configDone();
    234     overlay::Rotator *getNext();
    235     void clear(); //Removes all instances
    236     /* Returns rot dump.
    237      * Expects a NULL terminated buffer of big enough size.
    238      */
    239     void getDump(char *buf, size_t len);
    240     int getRotDevFd(); //Called on A-fam only
    241 private:
    242     overlay::Rotator *mRot[MAX_ROT_SESS];
    243     int mUseCount;
    244     int mRotDevFd; //A-fam
    245 };
    246 
    247 
    248 } // overlay
    249 
    250 #endif // OVERlAY_ROTATOR_H
    251