blob: 9058d309d1b7c08f7e27f92a11f5f48d53f276e1 [file] [log] [blame]
Naseer Ahmed29a26812012-06-14 00:56:20 -07001/*
Raj kamal23f69b22012-11-17 00:20:55 +05302* Copyright (c) 2011,2013 The Linux Foundation. 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.
Naseer Ahmed758bfc52012-11-28 17:02:08 -050013* * Neither the name of The Linux Foundation. nor the names of its
Naseer Ahmed29a26812012-06-14 00:56:20 -070014* 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
Naseer Ahmed758bfc52012-11-28 17:02:08 -050041class Rotator
Naseer Ahmedf48aef62012-07-20 09:05:53 -070042{
43public:
Naseer Ahmed758bfc52012-11-28 17:02:08 -050044 enum { TYPE_MDP, TYPE_MDSS };
Naseer Ahmedf48aef62012-07-20 09:05:53 -070045 virtual ~Rotator();
Naseer Ahmed758bfc52012-11-28 17:02:08 -050046 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;
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -080050 virtual void setTransform(const utils::eTransform& rot) = 0;
51 virtual void setRotatorUsed(const bool& rotUsed) = 0;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050052 virtual bool commit() = 0;
53 virtual void setRotations(uint32_t r) = 0;
54 virtual void setSrcFB() = 0;
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -080055 virtual void setDownscale(int ds) = 0;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050056 virtual int getDstMemId() const = 0;
57 virtual uint32_t getDstOffset() const = 0;
Raj kamal23f69b22012-11-17 00:20:55 +053058 virtual uint32_t getDstFormat() const = 0;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050059 virtual void setEnable() = 0;
60 virtual void setDisable() = 0;
61 virtual bool enabled () const = 0;
62 virtual uint32_t getSessId() const = 0;
63 virtual bool queueBuffer(int fd, uint32_t offset) = 0;
64 virtual void dump() const = 0;
65 static Rotator *getRotator();
Naseer Ahmed29a26812012-06-14 00:56:20 -070066
Naseer Ahmed758bfc52012-11-28 17:02:08 -050067protected:
68 explicit Rotator() {}
Saurabh Shahfc3652f2013-02-15 13:15:45 -080069 static uint32_t calcOutputBufSize(const utils::Whf& destWhf);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050070
71private:
72 /*Returns rotator h/w type */
73 static int getRotatorHwType();
Naseer Ahmed29a26812012-06-14 00:56:20 -070074};
75
Naseer Ahmedf48aef62012-07-20 09:05:53 -070076/*
77 Manages the case where new rotator memory needs to be
78 allocated, before previous is freed, due to resolution change etc. If we make
79 rotator memory to be always max size, irrespctive of source resolution then
80 we don't need this RotMem wrapper. The inner class is sufficient.
81*/
82struct RotMem {
83 // Max rotator memory allocations
84 enum { MAX_ROT_MEM = 2};
85
86 //Manages the rotator buffer offsets.
87 struct Mem {
88 Mem() : mCurrOffset(0) {utils::memset0(mRotOffset); }
89 bool valid() { return m.valid(); }
90 bool close() { return m.close(); }
91 uint32_t size() const { return m.bufSz(); }
92 // Max rotator buffers
93 enum { ROT_NUM_BUFS = 2 };
94 // rotator data info dst offset
95 uint32_t mRotOffset[ROT_NUM_BUFS];
96 // current offset slot from mRotOffset
97 uint32_t mCurrOffset;
98 OvMem m;
99 };
100
101 RotMem() : _curr(0) {}
102 Mem& curr() { return m[_curr % MAX_ROT_MEM]; }
103 const Mem& curr() const { return m[_curr % MAX_ROT_MEM]; }
104 Mem& prev() { return m[(_curr+1) % MAX_ROT_MEM]; }
105 RotMem& operator++() { ++_curr; return *this; }
106 bool close();
107 uint32_t _curr;
108 Mem m[MAX_ROT_MEM];
109};
Naseer Ahmed29a26812012-06-14 00:56:20 -0700110
111/*
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700112* MDP rot holds MDP's rotation related structures.
113*
Naseer Ahmed29a26812012-06-14 00:56:20 -0700114* */
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500115class MdpRot : public Rotator {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700116public:
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500117 virtual ~MdpRot();
118 virtual bool init();
119 virtual bool close();
120 virtual void setSource(const utils::Whf& wfh);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700121 virtual void setFlags(const utils::eMdpFlags& flags);
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800122 virtual void setTransform(const utils::eTransform& rot);
123 virtual void setRotatorUsed(const bool& rotUsed);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500124 virtual bool commit();
125 virtual void setRotations(uint32_t r);
126 virtual void setSrcFB();
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800127 virtual void setDownscale(int ds);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500128 virtual int getDstMemId() const;
129 virtual uint32_t getDstOffset() const;
Raj kamal23f69b22012-11-17 00:20:55 +0530130 virtual uint32_t getDstFormat() const;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500131 virtual void setEnable();
132 virtual void setDisable();
133 virtual bool enabled () const;
134 virtual uint32_t getSessId() const;
135 virtual bool queueBuffer(int fd, uint32_t offset);
136 virtual void dump() const;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700137
Naseer Ahmed29a26812012-06-14 00:56:20 -0700138private:
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500139 explicit MdpRot();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700140 /* 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();
Saurabh Shahc23b3802012-08-31 11:11:30 -0700147 /* return true if current rotator config is different
148 * than last known config */
149 bool rotConfChanged() const;
Saurabh Shahc23b3802012-08-31 11:11:30 -0700150 /* save mRotImgInfo to be last known good config*/
151 void save();
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800152 /* 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();
Saurabh Shahc23b3802012-08-31 11:11:30 -0700155
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700156 /* rot info*/
157 msm_rotator_img_info mRotImgInfo;
Saurabh Shahc23b3802012-08-31 11:11:30 -0700158 /* Last saved rot info*/
159 msm_rotator_img_info mLSRotImgInfo;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700160 /* rot data */
161 msm_rotator_data_info mRotDataInfo;
162 /* Orientation */
163 utils::eTransform mOrientation;
164 /* rotator fd */
165 OvFD mFd;
166 /* Rotator memory manager */
167 RotMem mMem;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500168
169 friend Rotator* Rotator::getRotator();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700170};
171
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700172/*
173+* MDSS Rot holds MDSS's rotation related structures.
174+*
175+* */
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500176class MdssRot : public Rotator {
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700177public:
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500178 virtual ~MdssRot();
179 virtual bool init();
180 virtual bool close();
181 virtual void setSource(const utils::Whf& wfh);
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700182 virtual void setFlags(const utils::eMdpFlags& flags);
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800183 virtual void setTransform(const utils::eTransform& rot);
184 virtual void setRotatorUsed(const bool& rotUsed);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500185 virtual bool commit();
186 virtual void setRotations(uint32_t r);
187 virtual void setSrcFB();
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800188 virtual void setDownscale(int ds);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500189 virtual int getDstMemId() const;
190 virtual uint32_t getDstOffset() const;
Raj kamal23f69b22012-11-17 00:20:55 +0530191 virtual uint32_t getDstFormat() const;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500192 virtual void setEnable();
193 virtual void setDisable();
194 virtual bool enabled () const;
195 virtual uint32_t getSessId() const;
196 virtual bool queueBuffer(int fd, uint32_t offset);
197 virtual void dump() const;
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700198
199private:
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500200 explicit MdssRot();
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700201 /* remap rot buffers */
202 bool remap(uint32_t numbufs);
203 bool open_i(uint32_t numbufs, uint32_t bufsz);
204 /* Deferred transform calculations */
205 void doTransform();
206 /* reset underlying data, basically memset 0 */
207 void reset();
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800208 /* Calculates the rotator's o/p buffer size post the transform calcs and
209 * knowing the o/p format depending on whether fastYuv is enabled or not */
210 uint32_t calcOutputBufSize();
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700211
212 /* MdssRot info structure */
213 mdp_overlay mRotInfo;
214 /* MdssRot data structure */
215 msmfb_overlay_data mRotData;
216 /* Orientation */
217 utils::eTransform mOrientation;
218 /* rotator fd */
219 OvFD mFd;
220 /* Rotator memory manager */
221 RotMem mMem;
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700222 /* Enable/Disable Mdss Rot*/
223 bool mEnabled;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500224
225 friend Rotator* Rotator::getRotator();
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700226};
Naseer Ahmed29a26812012-06-14 00:56:20 -0700227
Naseer Ahmed29a26812012-06-14 00:56:20 -0700228} // overlay
229
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700230#endif // OVERlAY_ROTATOR_H