overlayRotator.h revision 513ddc2124abf90c63af41999201f0d2031af0c8
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
39namespace 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*/
47struct 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
80class Rotator
81{
82public:
83    enum { TYPE_MDP, TYPE_MDSS };
84    virtual ~Rotator();
85    virtual void setSource(const utils::Whf& wfh) = 0;
86    virtual void setFlags(const utils::eMdpFlags& flags) = 0;
87    virtual void setTransform(const utils::eTransform& rot) = 0;
88    virtual bool commit() = 0;
89    virtual void setDownscale(int ds) = 0;
90    virtual int getDstMemId() const = 0;
91    virtual uint32_t getDstOffset() const = 0;
92    virtual uint32_t getDstFormat() const = 0;
93    virtual uint32_t getSessId() const = 0;
94    virtual bool queueBuffer(int fd, uint32_t offset) = 0;
95    virtual void dump() const = 0;
96    virtual void getDump(char *buf, size_t len) const = 0;
97    void setReleaseFd(const int& fence) { mMem.setReleaseFd(fence); }
98    static Rotator *getRotator();
99
100protected:
101    /* Rotator memory manager */
102    RotMem mMem;
103    explicit Rotator() {}
104    static uint32_t calcOutputBufSize(const utils::Whf& destWhf);
105
106private:
107    /*Returns rotator h/w type */
108    static int getRotatorHwType();
109    friend class RotMgr;
110};
111
112/*
113* MDP rot holds MDP's rotation related structures.
114*
115* */
116class MdpRot : public Rotator {
117public:
118    virtual ~MdpRot();
119    virtual void setSource(const utils::Whf& wfh);
120    virtual void setFlags(const utils::eMdpFlags& flags);
121    virtual void setTransform(const utils::eTransform& rot);
122    virtual bool commit();
123    virtual void setDownscale(int ds);
124    virtual int getDstMemId() const;
125    virtual uint32_t getDstOffset() const;
126    virtual uint32_t getDstFormat() const;
127    virtual uint32_t getSessId() const;
128    virtual bool queueBuffer(int fd, uint32_t offset);
129    virtual void dump() const;
130    virtual void getDump(char *buf, size_t len) const;
131
132private:
133    explicit MdpRot();
134    bool init();
135    bool close();
136    void setRotations(uint32_t r);
137    bool enabled () const;
138    /* remap rot buffers */
139    bool remap(uint32_t numbufs);
140    bool open_i(uint32_t numbufs, uint32_t bufsz);
141    /* Deferred transform calculations */
142    void doTransform();
143    /* reset underlying data, basically memset 0 */
144    void reset();
145    /* return true if current rotator config is different
146     * than last known config */
147    bool rotConfChanged() const;
148    /* save mRotImgInfo to be last known good config*/
149    void save();
150    /* Calculates the rotator's o/p buffer size post the transform calcs and
151     * knowing the o/p format depending on whether fastYuv is enabled or not */
152    uint32_t calcOutputBufSize();
153
154    /* rot info*/
155    msm_rotator_img_info mRotImgInfo;
156    /* Last saved rot info*/
157    msm_rotator_img_info mLSRotImgInfo;
158    /* rot data */
159    msm_rotator_data_info mRotDataInfo;
160    /* Orientation */
161    utils::eTransform mOrientation;
162    /* rotator fd */
163    OvFD mFd;
164
165    friend Rotator* Rotator::getRotator();
166};
167
168/*
169+* MDSS Rot holds MDSS's rotation related structures.
170+*
171+* */
172class MdssRot : public Rotator {
173public:
174    virtual ~MdssRot();
175    virtual void setSource(const utils::Whf& wfh);
176    virtual void setFlags(const utils::eMdpFlags& flags);
177    virtual void setTransform(const utils::eTransform& rot);
178    virtual bool commit();
179    virtual void setDownscale(int ds);
180    virtual int getDstMemId() const;
181    virtual uint32_t getDstOffset() const;
182    virtual uint32_t getDstFormat() const;
183    virtual uint32_t getSessId() const;
184    virtual bool queueBuffer(int fd, uint32_t offset);
185    virtual void dump() const;
186    virtual void getDump(char *buf, size_t len) const;
187
188private:
189    explicit MdssRot();
190    bool init();
191    bool close();
192    void setRotations(uint32_t r);
193    bool enabled () const;
194    /* remap rot buffers */
195    bool remap(uint32_t numbufs);
196    bool open_i(uint32_t numbufs, uint32_t bufsz);
197    /* Deferred transform calculations */
198    void doTransform();
199    /* reset underlying data, basically memset 0 */
200    void reset();
201    /* Calculates the rotator's o/p buffer size post the transform calcs and
202     * knowing the o/p format depending on whether fastYuv is enabled or not */
203    uint32_t calcOutputBufSize();
204
205    /* MdssRot info structure */
206    mdp_overlay   mRotInfo;
207    /* MdssRot data structure */
208    msmfb_overlay_data mRotData;
209    /* Orientation */
210    utils::eTransform mOrientation;
211    /* rotator fd */
212    OvFD mFd;
213    /* Enable/Disable Mdss Rot*/
214    bool mEnabled;
215
216    friend Rotator* Rotator::getRotator();
217};
218
219// Holder of rotator objects. Manages lifetimes
220class RotMgr {
221public:
222    //Maximum sessions based on VG pipes, since rotator is used only for videos.
223    //Even though we can have 4 mixer stages, that much may be unnecessary.
224    enum { MAX_ROT_SESS = 3 };
225    RotMgr();
226    ~RotMgr();
227    void configBegin();
228    void configDone();
229    overlay::Rotator *getNext();
230    void clear(); //Removes all instances
231    /* Returns rot dump.
232     * Expects a NULL terminated buffer of big enough size.
233     */
234    void getDump(char *buf, size_t len);
235    int getRotDevFd(); //Called on A-fam only
236private:
237    overlay::Rotator *mRot[MAX_ROT_SESS];
238    int mUseCount;
239    int mRotDevFd; //A-fam
240};
241
242
243} // overlay
244
245#endif // OVERlAY_ROTATOR_H
246