blob: 075e46decae46a82f7bd4744f300ac96edd902b6 [file] [log] [blame]
Naseer Ahmed29a26812012-06-14 00:56:20 -07001/*
Naseer Ahmedf48aef62012-07-20 09:05:53 -07002* Copyright (c) 2011, Code Aurora Forum. All rights reserved.
Naseer Ahmed29a26812012-06-14 00:56:20 -07003*
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 Code Aurora Forum, Inc. 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
Naseer Ahmedf48aef62012-07-20 09:05:53 -070030#ifndef OVERlAY_ROTATOR_H
31#define OVERlAY_ROTATOR_H
Naseer Ahmed29a26812012-06-14 00:56:20 -070032
33#include <stdlib.h>
34
35#include "mdpWrapper.h"
36#include "overlayUtils.h"
37#include "overlayMem.h"
38
39namespace overlay {
Naseer Ahmedf48aef62012-07-20 09:05:53 -070040
41class IRotatorHw;
Naseer Ahmed29a26812012-06-14 00:56:20 -070042/*
Naseer Ahmedf48aef62012-07-20 09:05:53 -070043* RotatorBase. No members, just interface.
44* can also be =0 with empty impl in cpp.
Naseer Ahmed29a26812012-06-14 00:56:20 -070045* */
46class RotatorBase {
47public:
48 /* Most of the below are No op funcs for RotatorBase */
49 virtual ~RotatorBase() {}
Naseer Ahmedf48aef62012-07-20 09:05:53 -070050 virtual bool init() = 0;
Naseer Ahmed29a26812012-06-14 00:56:20 -070051 virtual bool close() = 0;
Naseer Ahmedf48aef62012-07-20 09:05:53 -070052 virtual void setSource(const utils::Whf& wfh) = 0;
53 virtual void setFlags(const utils::eMdpFlags& flags) = 0;
54 virtual void setTransform(const utils::eTransform& rot,
55 const bool& rotUsed) = 0;
56 virtual bool commit() = 0;
57 virtual bool queueBuffer(int fd, uint32_t offset) = 0;
58
Naseer Ahmed29a26812012-06-14 00:56:20 -070059 virtual void setEnable() = 0;
60 virtual void setDisable() = 0;
Naseer Ahmedf48aef62012-07-20 09:05:53 -070061 virtual void setRotations(uint32_t r) = 0;
62 virtual void setSrcFB() = 0;
63
Naseer Ahmed29a26812012-06-14 00:56:20 -070064 virtual bool enabled() const = 0;
Saurabh Shahc23b3802012-08-31 11:11:30 -070065 virtual uint32_t getSessId() const = 0;
Naseer Ahmedf48aef62012-07-20 09:05:53 -070066 virtual int getDstMemId() const = 0;
67 virtual uint32_t getDstOffset() const = 0;
Naseer Ahmed29a26812012-06-14 00:56:20 -070068 virtual void dump() const = 0;
Naseer Ahmedf48aef62012-07-20 09:05:53 -070069
70protected:
71 //Hardware specific rotator impl.
72 IRotatorHw *mRot;
73};
74
75/*
76 * Rotator Hw Interface. Any hardware specific implementation should inherit
77 * from this.
78 */
79class IRotatorHw {
80public:
81 /* Most of the below are No op funcs for RotatorBase */
82 virtual ~IRotatorHw() {}
83 /* init fd for rotator. map bufs is defered */
84 virtual bool init() = 0;
85 /* close fd, mem */
86 virtual bool close() = 0;
87 /* set src */
88 virtual void setSource(const utils::Whf& wfh) = 0;
89 /* set mdp flags, will use only stuff necessary for rotator */
90 virtual void setFlags(const utils::eMdpFlags& flags) = 0;
91 /* Set rotation and calculate */
92 virtual void setTransform(const utils::eTransform& rot,
93 const bool& rotUsed) = 0;
94 /* calls underlying wrappers to start rotator */
95 virtual bool commit() = 0;
96 /* Lazy buffer allocation. queue buffer */
97 virtual bool queueBuffer(int fd, uint32_t offset) = 0;
98 /* set enable/disable flag */
99 virtual void setEnable() = 0;
100 virtual void setDisable() = 0;
101 /* set rotator flag*/
102 virtual void setRotations(uint32_t r) = 0;
103 /* Mark src as FB (non-ION) */
104 virtual void setSrcFB() = 0;
105 /* Retusn true if rotator enabled */
106 virtual bool enabled() const = 0;
107 /* returns rotator session id */
Saurabh Shahc23b3802012-08-31 11:11:30 -0700108 virtual uint32_t getSessId() const = 0;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700109 /* get dst (for offset and memory id) non-virt */
110 virtual int getDstMemId() const = 0;
111 virtual uint32_t getDstOffset() const = 0;
112 /* dump the state of the object */
113 virtual void dump() const = 0;
114
115 enum { TYPE_MDP, TYPE_MDSS };
116 /*Returns rotator h/w type */
117 static int getRotatorHwType();
118};
119
120/*
121* Actual Rotator impl.
122* */
123class Rotator : public RotatorBase
124{
125public:
126 explicit Rotator();
127 virtual ~Rotator();
128 virtual bool init();
129 virtual bool close();
130 virtual void setSource(const utils::Whf& wfh);
131 virtual void setFlags(const utils::eMdpFlags& flags);
132 virtual void setTransform(const utils::eTransform& rot,
133 const bool& rotUsed);
134 virtual bool commit();
135 virtual void setRotations(uint32_t r);
136 virtual void setSrcFB();
137 virtual int getDstMemId() const;
138 virtual uint32_t getDstOffset() const;
139 virtual void setEnable();
140 virtual void setDisable();
141 virtual bool enabled () const;
Saurabh Shahc23b3802012-08-31 11:11:30 -0700142 virtual uint32_t getSessId() const;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700143 virtual bool queueBuffer(int fd, uint32_t offset);
144 virtual void dump() const;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700145};
146
147/*
148* Null/Empty impl of RotatorBase
149* */
150class NullRotator : public RotatorBase {
151public:
152 /* Most of the below are No op funcs for RotatorBase */
153 virtual ~NullRotator();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700154 virtual bool init();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700155 virtual bool close();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700156 virtual void setSource(const utils::Whf& wfh);
157 virtual void setFlags(const utils::eMdpFlags& flags);
158 virtual void setTransform(const utils::eTransform& rot,
159 const bool& rotUsed);
160 virtual bool commit();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700161 virtual void setRotations(uint32_t r);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700162 virtual bool queueBuffer(int fd, uint32_t offset);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700163 virtual void setEnable();
164 virtual void setDisable();
165 virtual bool enabled () const;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700166 virtual void setSrcFB();
Saurabh Shahc23b3802012-08-31 11:11:30 -0700167 virtual uint32_t getSessId() const;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700168 virtual int getDstMemId() const;
169 virtual uint32_t getDstOffset() const;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700170 virtual void dump() const;
171};
172
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700173/*
174 Manages the case where new rotator memory needs to be
175 allocated, before previous is freed, due to resolution change etc. If we make
176 rotator memory to be always max size, irrespctive of source resolution then
177 we don't need this RotMem wrapper. The inner class is sufficient.
178*/
179struct RotMem {
180 // Max rotator memory allocations
181 enum { MAX_ROT_MEM = 2};
182
183 //Manages the rotator buffer offsets.
184 struct Mem {
185 Mem() : mCurrOffset(0) {utils::memset0(mRotOffset); }
186 bool valid() { return m.valid(); }
187 bool close() { return m.close(); }
188 uint32_t size() const { return m.bufSz(); }
189 // Max rotator buffers
190 enum { ROT_NUM_BUFS = 2 };
191 // rotator data info dst offset
192 uint32_t mRotOffset[ROT_NUM_BUFS];
193 // current offset slot from mRotOffset
194 uint32_t mCurrOffset;
195 OvMem m;
196 };
197
198 RotMem() : _curr(0) {}
199 Mem& curr() { return m[_curr % MAX_ROT_MEM]; }
200 const Mem& curr() const { return m[_curr % MAX_ROT_MEM]; }
201 Mem& prev() { return m[(_curr+1) % MAX_ROT_MEM]; }
202 RotMem& operator++() { ++_curr; return *this; }
203 bool close();
204 uint32_t _curr;
205 Mem m[MAX_ROT_MEM];
206};
Naseer Ahmed29a26812012-06-14 00:56:20 -0700207
208/*
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700209* MDP rot holds MDP's rotation related structures.
210*
Naseer Ahmed29a26812012-06-14 00:56:20 -0700211* */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700212class MdpRot : public IRotatorHw {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700213public:
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700214 explicit MdpRot();
215 ~MdpRot();
216 bool init();
217 bool close();
218 void setSource(const utils::Whf& whf);
219 virtual void setFlags(const utils::eMdpFlags& flags);
220 void setTransform(const utils::eTransform& rot,
221 const bool& rotUsed);
222 bool commit();
223 bool queueBuffer(int fd, uint32_t offset);
224 void setEnable();
225 void setDisable();
226 void setRotations(uint32_t r);
227 void setSrcFB();
228 bool enabled() const;
Saurabh Shahc23b3802012-08-31 11:11:30 -0700229 uint32_t getSessId() const;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700230 int getDstMemId() const;
231 uint32_t getDstOffset() const;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700232 void dump() const;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700233
Naseer Ahmed29a26812012-06-14 00:56:20 -0700234private:
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700235 /* remap rot buffers */
236 bool remap(uint32_t numbufs);
237 bool open_i(uint32_t numbufs, uint32_t bufsz);
238 /* Deferred transform calculations */
239 void doTransform();
240 /* reset underlying data, basically memset 0 */
241 void reset();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700242
Saurabh Shahc23b3802012-08-31 11:11:30 -0700243 /* return true if current rotator config is different
244 * than last known config */
245 bool rotConfChanged() const;
246
247 /* save mRotImgInfo to be last known good config*/
248 void save();
249
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700250 /* rot info*/
251 msm_rotator_img_info mRotImgInfo;
Saurabh Shahc23b3802012-08-31 11:11:30 -0700252 /* Last saved rot info*/
253 msm_rotator_img_info mLSRotImgInfo;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700254 /* rot data */
255 msm_rotator_data_info mRotDataInfo;
256 /* Orientation */
257 utils::eTransform mOrientation;
258 /* rotator fd */
259 OvFD mFd;
260 /* Rotator memory manager */
261 RotMem mMem;
262 /* Single Rotator buffer size */
263 uint32_t mBufSize;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700264};
265
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700266/*
267+* MDSS Rot holds MDSS's rotation related structures.
268+*
269+* */
270class MdssRot : public IRotatorHw {
271public:
272 explicit MdssRot();
273 ~MdssRot();
274 bool init();
275 bool close();
276 void setSource(const utils::Whf& whf);
277 virtual void setFlags(const utils::eMdpFlags& flags);
278 void setTransform(const utils::eTransform& rot,
279 const bool& rotUsed);
280 bool commit();
281 bool queueBuffer(int fd, uint32_t offset);
282 void setEnable();
283 void setDisable();
284 void setRotations(uint32_t r);
285 void setSrcFB();
286 bool enabled() const;
Saurabh Shahc23b3802012-08-31 11:11:30 -0700287 uint32_t getSessId() const;
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700288 int getDstMemId() const;
289 uint32_t getDstOffset() const;
290 void dump() const;
291
292private:
293 /* remap rot buffers */
294 bool remap(uint32_t numbufs);
295 bool open_i(uint32_t numbufs, uint32_t bufsz);
296 /* Deferred transform calculations */
297 void doTransform();
298 /* reset underlying data, basically memset 0 */
299 void reset();
300
301 /* MdssRot info structure */
302 mdp_overlay mRotInfo;
303 /* MdssRot data structure */
304 msmfb_overlay_data mRotData;
305 /* Orientation */
306 utils::eTransform mOrientation;
307 /* rotator fd */
308 OvFD mFd;
309 /* Rotator memory manager */
310 RotMem mMem;
311 /* Single Rotator buffer size */
312 uint32_t mBufSize;
313 /* Enable/Disable Mdss Rot*/
314 bool mEnabled;
315};
Naseer Ahmed29a26812012-06-14 00:56:20 -0700316
317//--------------inlines------------------------------------
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700318
319///// Rotator /////
320inline Rotator::Rotator() {
321 int type = IRotatorHw::getRotatorHwType();
322 if(type == IRotatorHw::TYPE_MDP) {
323 mRot = new MdpRot(); //will do reset
324 } else if(type == IRotatorHw::TYPE_MDSS) {
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700325 mRot = new MdssRot();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700326 } else {
327 ALOGE("%s Unknown h/w type %d", __FUNCTION__, type);
328 }
329}
330inline Rotator::~Rotator() {
331 delete mRot; //will do close
332}
333inline bool Rotator::init() {
334 if(!mRot->init()) {
335 ALOGE("Rotator::init failed");
336 return false;
337 }
338 return true;
339}
340inline bool Rotator::close() {
341 return mRot->close();
342}
343inline void Rotator::setSource(const utils::Whf& whf) {
344 mRot->setSource(whf);
345}
346inline void Rotator::setFlags(const utils::eMdpFlags& flags) {
347 mRot->setFlags(flags);
348}
349inline void Rotator::setTransform(const utils::eTransform& rot,
350 const bool& rotUsed)
351{
352 mRot->setTransform(rot, rotUsed);
353}
354inline bool Rotator::commit() {
355 return mRot->commit();
356}
357inline void Rotator::setEnable(){ mRot->setEnable(); }
358inline void Rotator::setDisable(){ mRot->setDisable(); }
359inline bool Rotator::enabled() const { return mRot->enabled(); }
360inline void Rotator::setSrcFB() { mRot->setSrcFB(); }
361inline int Rotator::getDstMemId() const {
362 return mRot->getDstMemId();
363}
364inline uint32_t Rotator::getDstOffset() const {
365 return mRot->getDstOffset();
366}
367inline void Rotator::setRotations(uint32_t rot) {
368 mRot->setRotations (rot);
369}
Saurabh Shahc23b3802012-08-31 11:11:30 -0700370inline uint32_t Rotator::getSessId() const {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700371 return mRot->getSessId();
372}
373inline void Rotator::dump() const {
374 ALOGE("== Dump Rotator start ==");
375 mRot->dump();
376 ALOGE("== Dump Rotator end ==");
377}
378inline bool Rotator::queueBuffer(int fd, uint32_t offset) {
379 return mRot->queueBuffer(fd, offset);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700380}
381
Naseer Ahmed29a26812012-06-14 00:56:20 -0700382
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700383///// Null Rotator /////
384inline NullRotator::~NullRotator() {}
385inline bool NullRotator::init() { return true; }
386inline bool NullRotator::close() { return true; }
387inline bool NullRotator::commit() { return true; }
388inline void NullRotator::setSource(const utils::Whf& wfh) {}
389inline void NullRotator::setFlags(const utils::eMdpFlags& flags) {}
390inline void NullRotator::setTransform(const utils::eTransform& rot, const bool&)
391{}
392inline void NullRotator::setRotations(uint32_t) {}
393inline void NullRotator::setEnable() {}
394inline void NullRotator::setDisable() {}
395inline bool NullRotator::enabled() const { return false; }
Saurabh Shahc23b3802012-08-31 11:11:30 -0700396inline uint32_t NullRotator::getSessId() const { return 0; }
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700397inline bool NullRotator::queueBuffer(int fd, uint32_t offset) { return true; }
398inline void NullRotator::setSrcFB() {}
399inline int NullRotator::getDstMemId() const { return -1; }
400inline uint32_t NullRotator::getDstOffset() const { return 0;}
401inline void NullRotator::dump() const {
402 ALOGE("== Dump NullRotator dump (null) start/end ==");
403}
404
405
406//// MdpRot ////
407inline MdpRot::MdpRot() { reset(); }
408inline MdpRot::~MdpRot() { close(); }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700409inline void MdpRot::setEnable() { mRotImgInfo.enable = 1; }
410inline void MdpRot::setDisable() { mRotImgInfo.enable = 0; }
411inline bool MdpRot::enabled() const { return mRotImgInfo.enable; }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700412inline void MdpRot::setRotations(uint32_t r) { mRotImgInfo.rotations = r; }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700413inline int MdpRot::getDstMemId() const {
414 return mRotDataInfo.dst.memory_id;
415}
416inline uint32_t MdpRot::getDstOffset() const {
417 return mRotDataInfo.dst.offset;
418}
Saurabh Shahc23b3802012-08-31 11:11:30 -0700419inline uint32_t MdpRot::getSessId() const { return mRotImgInfo.session_id; }
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700420inline void MdpRot::setSrcFB() {
421 mRotDataInfo.src.flags |= MDP_MEMORY_ID_TYPE_FB;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700422}
Saurabh Shahc23b3802012-08-31 11:11:30 -0700423inline void MdpRot::save() {
424 mLSRotImgInfo = mRotImgInfo;
425}
426inline bool MdpRot::rotConfChanged() const {
427 // 0 means same
428 if(0 == ::memcmp(&mRotImgInfo, &mLSRotImgInfo,
429 sizeof (msm_rotator_img_info))) {
430 return false;
431 }
432 return true;
433}
Naseer Ahmed29a26812012-06-14 00:56:20 -0700434
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700435
436//// MdssRot ////
437inline MdssRot::MdssRot() { reset(); }
438inline MdssRot::~MdssRot() { close(); }
439inline void MdssRot::setEnable() { mEnabled = true; }
440inline void MdssRot::setDisable() { mEnabled = false; }
441inline bool MdssRot::enabled() const { return mEnabled; }
442inline void MdssRot::setRotations(uint32_t flags) { mRotInfo.flags |= flags; }
443inline int MdssRot::getDstMemId() const {
444 return mRotData.dst_data.memory_id;
445}
446inline uint32_t MdssRot::getDstOffset() const {
447 return mRotData.dst_data.offset;
448}
Saurabh Shahc23b3802012-08-31 11:11:30 -0700449inline uint32_t MdssRot::getSessId() const { return mRotInfo.id; }
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700450inline void MdssRot::setSrcFB() {
451 mRotData.data.flags |= MDP_MEMORY_ID_TYPE_FB;
452}
453
Naseer Ahmed29a26812012-06-14 00:56:20 -0700454} // overlay
455
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700456#endif // OVERlAY_ROTATOR_H