• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 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 class Rotator
42 {
43 public:
44     enum { TYPE_MDP, TYPE_MDSS };
45     virtual ~Rotator();
46     virtual bool init() = 0;
47     virtual bool close() = 0;
48     virtual void setSource(const utils::Whf& wfh) = 0;
49     virtual void setFlags(const utils::eMdpFlags& flags) = 0;
50     virtual void setTransform(const utils::eTransform& rot,
51             const bool& rotUsed) = 0;
52     virtual bool commit() = 0;
53     virtual void setRotations(uint32_t r) = 0;
54     virtual void setSrcFB() = 0;
55     virtual int getDstMemId() const = 0;
56     virtual uint32_t getDstOffset() const = 0;
57     virtual void setEnable() = 0;
58     virtual void setDisable() = 0;
59     virtual bool enabled () const = 0;
60     virtual uint32_t getSessId() const = 0;
61     virtual bool queueBuffer(int fd, uint32_t offset) = 0;
62     virtual void dump() const = 0;
63     static Rotator *getRotator();
64 
65 protected:
Rotator()66     explicit Rotator() {}
67 
68 private:
69     /*Returns rotator h/w type */
70     static int getRotatorHwType();
71 };
72 
73 /*
74    Manages the case where new rotator memory needs to be
75    allocated, before previous is freed, due to resolution change etc. If we make
76    rotator memory to be always max size, irrespctive of source resolution then
77    we don't need this RotMem wrapper. The inner class is sufficient.
78 */
79 struct RotMem {
80     // Max rotator memory allocations
81     enum { MAX_ROT_MEM = 2};
82 
83     //Manages the rotator buffer offsets.
84     struct Mem {
MemRotMem::Mem85         Mem() : mCurrOffset(0) {utils::memset0(mRotOffset); }
validRotMem::Mem86         bool valid() { return m.valid(); }
closeRotMem::Mem87         bool close() { return m.close(); }
sizeRotMem::Mem88         uint32_t size() const { return m.bufSz(); }
89         // Max rotator buffers
90         enum { ROT_NUM_BUFS = 2 };
91         // rotator data info dst offset
92         uint32_t mRotOffset[ROT_NUM_BUFS];
93         // current offset slot from mRotOffset
94         uint32_t mCurrOffset;
95         OvMem m;
96     };
97 
RotMemRotMem98     RotMem() : _curr(0) {}
currRotMem99     Mem& curr() { return m[_curr % MAX_ROT_MEM]; }
currRotMem100     const Mem& curr() const { return m[_curr % MAX_ROT_MEM]; }
prevRotMem101     Mem& prev() { return m[(_curr+1) % MAX_ROT_MEM]; }
102     RotMem& operator++() { ++_curr; return *this; }
103     bool close();
104     uint32_t _curr;
105     Mem m[MAX_ROT_MEM];
106 };
107 
108 /*
109 * MDP rot holds MDP's rotation related structures.
110 *
111 * */
112 class MdpRot : public Rotator {
113 public:
114     virtual ~MdpRot();
115     virtual bool init();
116     virtual bool close();
117     virtual void setSource(const utils::Whf& wfh);
118     virtual void setFlags(const utils::eMdpFlags& flags);
119     virtual void setTransform(const utils::eTransform& rot,
120             const bool& rotUsed);
121     virtual bool commit();
122     virtual void setRotations(uint32_t r);
123     virtual void setSrcFB();
124     virtual int getDstMemId() const;
125     virtual uint32_t getDstOffset() const;
126     virtual void setEnable();
127     virtual void setDisable();
128     virtual bool enabled () const;
129     virtual uint32_t getSessId() const;
130     virtual bool queueBuffer(int fd, uint32_t offset);
131     virtual void dump() const;
132 
133 private:
134     explicit MdpRot();
135     /* remap rot buffers */
136     bool remap(uint32_t numbufs);
137     bool open_i(uint32_t numbufs, uint32_t bufsz);
138     /* Deferred transform calculations */
139     void doTransform();
140     /* reset underlying data, basically memset 0 */
141     void reset();
142 
143     /* return true if current rotator config is different
144      * than last known config */
145     bool rotConfChanged() const;
146 
147     /* save mRotImgInfo to be last known good config*/
148     void save();
149 
150     /* rot info*/
151     msm_rotator_img_info mRotImgInfo;
152     /* Last saved rot info*/
153     msm_rotator_img_info mLSRotImgInfo;
154     /* rot data */
155     msm_rotator_data_info mRotDataInfo;
156     /* Orientation */
157     utils::eTransform mOrientation;
158     /* rotator fd */
159     OvFD mFd;
160     /* Rotator memory manager */
161     RotMem mMem;
162     /* Single Rotator buffer size */
163     uint32_t mBufSize;
164 
165     friend Rotator* Rotator::getRotator();
166 };
167 
168 /*
169 +* MDSS Rot holds MDSS's rotation related structures.
170 +*
171 +* */
172 class MdssRot : public Rotator {
173 public:
174     virtual ~MdssRot();
175     virtual bool init();
176     virtual bool close();
177     virtual void setSource(const utils::Whf& wfh);
178     virtual void setFlags(const utils::eMdpFlags& flags);
179     virtual void setTransform(const utils::eTransform& rot,
180             const bool& rotUsed);
181     virtual bool commit();
182     virtual void setRotations(uint32_t r);
183     virtual void setSrcFB();
184     virtual int getDstMemId() const;
185     virtual uint32_t getDstOffset() const;
186     virtual void setEnable();
187     virtual void setDisable();
188     virtual bool enabled () const;
189     virtual uint32_t getSessId() const;
190     virtual bool queueBuffer(int fd, uint32_t offset);
191     virtual void dump() const;
192 
193 private:
194     explicit MdssRot();
195     /* remap rot buffers */
196     bool remap(uint32_t numbufs);
197     bool open_i(uint32_t numbufs, uint32_t bufsz);
198     /* Deferred transform calculations */
199     void doTransform();
200     /* reset underlying data, basically memset 0 */
201     void reset();
202 
203     /* MdssRot info structure */
204     mdp_overlay   mRotInfo;
205     /* MdssRot data structure */
206     msmfb_overlay_data mRotData;
207     /* Orientation */
208     utils::eTransform mOrientation;
209     /* rotator fd */
210     OvFD mFd;
211     /* Rotator memory manager */
212     RotMem mMem;
213     /* Single Rotator buffer size */
214     uint32_t mBufSize;
215     /* Enable/Disable Mdss Rot*/
216     bool mEnabled;
217 
218     friend Rotator* Rotator::getRotator();
219 };
220 
221 } // overlay
222 
223 #endif // OVERlAY_ROTATOR_H
224