blob: d92bf16fc3bee3801545a0a868df439d6c5ef34f [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;
Naseer Ahmed29a26812012-06-14 00:56:20 -070065 virtual int 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 */
108 virtual int getSessId() const = 0;
109 /* 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;
142 virtual int getSessId() const;
143 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();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700167 virtual int 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;
229 int 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
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700243 /* rot info*/
244 msm_rotator_img_info mRotImgInfo;
245 /* rot data */
246 msm_rotator_data_info mRotDataInfo;
247 /* Orientation */
248 utils::eTransform mOrientation;
249 /* rotator fd */
250 OvFD mFd;
251 /* Rotator memory manager */
252 RotMem mMem;
253 /* Single Rotator buffer size */
254 uint32_t mBufSize;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700255};
256
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700257/*
258+* MDSS Rot holds MDSS's rotation related structures.
259+*
260+* */
261class MdssRot : public IRotatorHw {
262public:
263 explicit MdssRot();
264 ~MdssRot();
265 bool init();
266 bool close();
267 void setSource(const utils::Whf& whf);
268 virtual void setFlags(const utils::eMdpFlags& flags);
269 void setTransform(const utils::eTransform& rot,
270 const bool& rotUsed);
271 bool commit();
272 bool queueBuffer(int fd, uint32_t offset);
273 void setEnable();
274 void setDisable();
275 void setRotations(uint32_t r);
276 void setSrcFB();
277 bool enabled() const;
278 int getSessId() const;
279 int getDstMemId() const;
280 uint32_t getDstOffset() const;
281 void dump() const;
282
283private:
284 /* remap rot buffers */
285 bool remap(uint32_t numbufs);
286 bool open_i(uint32_t numbufs, uint32_t bufsz);
287 /* Deferred transform calculations */
288 void doTransform();
289 /* reset underlying data, basically memset 0 */
290 void reset();
291
292 /* MdssRot info structure */
293 mdp_overlay mRotInfo;
294 /* MdssRot data structure */
295 msmfb_overlay_data mRotData;
296 /* Orientation */
297 utils::eTransform mOrientation;
298 /* rotator fd */
299 OvFD mFd;
300 /* Rotator memory manager */
301 RotMem mMem;
302 /* Single Rotator buffer size */
303 uint32_t mBufSize;
304 /* Enable/Disable Mdss Rot*/
305 bool mEnabled;
306};
Naseer Ahmed29a26812012-06-14 00:56:20 -0700307
308//--------------inlines------------------------------------
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700309
310///// Rotator /////
311inline Rotator::Rotator() {
312 int type = IRotatorHw::getRotatorHwType();
313 if(type == IRotatorHw::TYPE_MDP) {
314 mRot = new MdpRot(); //will do reset
315 } else if(type == IRotatorHw::TYPE_MDSS) {
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700316 mRot = new MdssRot();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700317 } else {
318 ALOGE("%s Unknown h/w type %d", __FUNCTION__, type);
319 }
320}
321inline Rotator::~Rotator() {
322 delete mRot; //will do close
323}
324inline bool Rotator::init() {
325 if(!mRot->init()) {
326 ALOGE("Rotator::init failed");
327 return false;
328 }
329 return true;
330}
331inline bool Rotator::close() {
332 return mRot->close();
333}
334inline void Rotator::setSource(const utils::Whf& whf) {
335 mRot->setSource(whf);
336}
337inline void Rotator::setFlags(const utils::eMdpFlags& flags) {
338 mRot->setFlags(flags);
339}
340inline void Rotator::setTransform(const utils::eTransform& rot,
341 const bool& rotUsed)
342{
343 mRot->setTransform(rot, rotUsed);
344}
345inline bool Rotator::commit() {
346 return mRot->commit();
347}
348inline void Rotator::setEnable(){ mRot->setEnable(); }
349inline void Rotator::setDisable(){ mRot->setDisable(); }
350inline bool Rotator::enabled() const { return mRot->enabled(); }
351inline void Rotator::setSrcFB() { mRot->setSrcFB(); }
352inline int Rotator::getDstMemId() const {
353 return mRot->getDstMemId();
354}
355inline uint32_t Rotator::getDstOffset() const {
356 return mRot->getDstOffset();
357}
358inline void Rotator::setRotations(uint32_t rot) {
359 mRot->setRotations (rot);
360}
361inline int Rotator::getSessId() const {
362 return mRot->getSessId();
363}
364inline void Rotator::dump() const {
365 ALOGE("== Dump Rotator start ==");
366 mRot->dump();
367 ALOGE("== Dump Rotator end ==");
368}
369inline bool Rotator::queueBuffer(int fd, uint32_t offset) {
370 return mRot->queueBuffer(fd, offset);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700371}
372
Naseer Ahmed29a26812012-06-14 00:56:20 -0700373
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700374///// Null Rotator /////
375inline NullRotator::~NullRotator() {}
376inline bool NullRotator::init() { return true; }
377inline bool NullRotator::close() { return true; }
378inline bool NullRotator::commit() { return true; }
379inline void NullRotator::setSource(const utils::Whf& wfh) {}
380inline void NullRotator::setFlags(const utils::eMdpFlags& flags) {}
381inline void NullRotator::setTransform(const utils::eTransform& rot, const bool&)
382{}
383inline void NullRotator::setRotations(uint32_t) {}
384inline void NullRotator::setEnable() {}
385inline void NullRotator::setDisable() {}
386inline bool NullRotator::enabled() const { return false; }
387inline int NullRotator::getSessId() const { return -1; }
388inline bool NullRotator::queueBuffer(int fd, uint32_t offset) { return true; }
389inline void NullRotator::setSrcFB() {}
390inline int NullRotator::getDstMemId() const { return -1; }
391inline uint32_t NullRotator::getDstOffset() const { return 0;}
392inline void NullRotator::dump() const {
393 ALOGE("== Dump NullRotator dump (null) start/end ==");
394}
395
396
397//// MdpRot ////
398inline MdpRot::MdpRot() { reset(); }
399inline MdpRot::~MdpRot() { close(); }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700400inline void MdpRot::setEnable() { mRotImgInfo.enable = 1; }
401inline void MdpRot::setDisable() { mRotImgInfo.enable = 0; }
402inline bool MdpRot::enabled() const { return mRotImgInfo.enable; }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700403inline void MdpRot::setRotations(uint32_t r) { mRotImgInfo.rotations = r; }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700404inline int MdpRot::getDstMemId() const {
405 return mRotDataInfo.dst.memory_id;
406}
407inline uint32_t MdpRot::getDstOffset() const {
408 return mRotDataInfo.dst.offset;
409}
Naseer Ahmed29a26812012-06-14 00:56:20 -0700410inline int MdpRot::getSessId() const { return mRotImgInfo.session_id; }
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700411inline void MdpRot::setSrcFB() {
412 mRotDataInfo.src.flags |= MDP_MEMORY_ID_TYPE_FB;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700413}
414
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700415
416//// MdssRot ////
417inline MdssRot::MdssRot() { reset(); }
418inline MdssRot::~MdssRot() { close(); }
419inline void MdssRot::setEnable() { mEnabled = true; }
420inline void MdssRot::setDisable() { mEnabled = false; }
421inline bool MdssRot::enabled() const { return mEnabled; }
422inline void MdssRot::setRotations(uint32_t flags) { mRotInfo.flags |= flags; }
423inline int MdssRot::getDstMemId() const {
424 return mRotData.dst_data.memory_id;
425}
426inline uint32_t MdssRot::getDstOffset() const {
427 return mRotData.dst_data.offset;
428}
429inline int MdssRot::getSessId() const { return mRotInfo.id; }
430inline void MdssRot::setSrcFB() {
431 mRotData.data.flags |= MDP_MEMORY_ID_TYPE_FB;
432}
433
Naseer Ahmed29a26812012-06-14 00:56:20 -0700434} // overlay
435
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700436#endif // OVERlAY_ROTATOR_H