blob: 36fe581f8a29fbff1c78aaedbc73bc7088a59d24 [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 void setSource(const utils::Whf& wfh) = 0;
47 virtual void setFlags(const utils::eMdpFlags& flags) = 0;
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -080048 virtual void setTransform(const utils::eTransform& rot) = 0;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050049 virtual bool commit() = 0;
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -080050 virtual void setDownscale(int ds) = 0;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050051 virtual int getDstMemId() const = 0;
52 virtual uint32_t getDstOffset() const = 0;
Raj kamal23f69b22012-11-17 00:20:55 +053053 virtual uint32_t getDstFormat() const = 0;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050054 virtual uint32_t getSessId() const = 0;
55 virtual bool queueBuffer(int fd, uint32_t offset) = 0;
56 virtual void dump() const = 0;
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -080057 virtual void getDump(char *buf, size_t len) const = 0;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050058 static Rotator *getRotator();
Naseer Ahmed29a26812012-06-14 00:56:20 -070059
Naseer Ahmed758bfc52012-11-28 17:02:08 -050060protected:
61 explicit Rotator() {}
Saurabh Shahfc3652f2013-02-15 13:15:45 -080062 static uint32_t calcOutputBufSize(const utils::Whf& destWhf);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050063
64private:
65 /*Returns rotator h/w type */
66 static int getRotatorHwType();
Naseer Ahmed29a26812012-06-14 00:56:20 -070067};
68
Naseer Ahmedf48aef62012-07-20 09:05:53 -070069/*
70 Manages the case where new rotator memory needs to be
71 allocated, before previous is freed, due to resolution change etc. If we make
72 rotator memory to be always max size, irrespctive of source resolution then
73 we don't need this RotMem wrapper. The inner class is sufficient.
74*/
75struct RotMem {
76 // Max rotator memory allocations
77 enum { MAX_ROT_MEM = 2};
78
79 //Manages the rotator buffer offsets.
80 struct Mem {
81 Mem() : mCurrOffset(0) {utils::memset0(mRotOffset); }
82 bool valid() { return m.valid(); }
83 bool close() { return m.close(); }
84 uint32_t size() const { return m.bufSz(); }
85 // Max rotator buffers
86 enum { ROT_NUM_BUFS = 2 };
87 // rotator data info dst offset
88 uint32_t mRotOffset[ROT_NUM_BUFS];
89 // current offset slot from mRotOffset
90 uint32_t mCurrOffset;
91 OvMem m;
92 };
93
94 RotMem() : _curr(0) {}
95 Mem& curr() { return m[_curr % MAX_ROT_MEM]; }
96 const Mem& curr() const { return m[_curr % MAX_ROT_MEM]; }
97 Mem& prev() { return m[(_curr+1) % MAX_ROT_MEM]; }
98 RotMem& operator++() { ++_curr; return *this; }
99 bool close();
100 uint32_t _curr;
101 Mem m[MAX_ROT_MEM];
102};
Naseer Ahmed29a26812012-06-14 00:56:20 -0700103
104/*
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700105* MDP rot holds MDP's rotation related structures.
106*
Naseer Ahmed29a26812012-06-14 00:56:20 -0700107* */
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500108class MdpRot : public Rotator {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700109public:
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500110 virtual ~MdpRot();
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500111 virtual void setSource(const utils::Whf& wfh);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700112 virtual void setFlags(const utils::eMdpFlags& flags);
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800113 virtual void setTransform(const utils::eTransform& rot);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500114 virtual bool commit();
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800115 virtual void setDownscale(int ds);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500116 virtual int getDstMemId() const;
117 virtual uint32_t getDstOffset() const;
Raj kamal23f69b22012-11-17 00:20:55 +0530118 virtual uint32_t getDstFormat() const;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500119 virtual uint32_t getSessId() const;
120 virtual bool queueBuffer(int fd, uint32_t offset);
121 virtual void dump() const;
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800122 virtual void getDump(char *buf, size_t len) const;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700123
Naseer Ahmed29a26812012-06-14 00:56:20 -0700124private:
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500125 explicit MdpRot();
Saurabh Shahacf10202013-02-26 10:15:15 -0800126 bool init();
127 bool close();
128 void setRotations(uint32_t r);
129 bool enabled () const;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700130 /* remap rot buffers */
131 bool remap(uint32_t numbufs);
132 bool open_i(uint32_t numbufs, uint32_t bufsz);
133 /* Deferred transform calculations */
134 void doTransform();
135 /* reset underlying data, basically memset 0 */
136 void reset();
Saurabh Shahc23b3802012-08-31 11:11:30 -0700137 /* return true if current rotator config is different
138 * than last known config */
139 bool rotConfChanged() const;
Saurabh Shahc23b3802012-08-31 11:11:30 -0700140 /* save mRotImgInfo to be last known good config*/
141 void save();
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800142 /* Calculates the rotator's o/p buffer size post the transform calcs and
143 * knowing the o/p format depending on whether fastYuv is enabled or not */
144 uint32_t calcOutputBufSize();
Saurabh Shahc23b3802012-08-31 11:11:30 -0700145
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700146 /* rot info*/
147 msm_rotator_img_info mRotImgInfo;
Saurabh Shahc23b3802012-08-31 11:11:30 -0700148 /* Last saved rot info*/
149 msm_rotator_img_info mLSRotImgInfo;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700150 /* rot data */
151 msm_rotator_data_info mRotDataInfo;
152 /* Orientation */
153 utils::eTransform mOrientation;
154 /* rotator fd */
155 OvFD mFd;
156 /* Rotator memory manager */
157 RotMem mMem;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500158
159 friend Rotator* Rotator::getRotator();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700160};
161
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700162/*
163+* MDSS Rot holds MDSS's rotation related structures.
164+*
165+* */
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500166class MdssRot : public Rotator {
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700167public:
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500168 virtual ~MdssRot();
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500169 virtual void setSource(const utils::Whf& wfh);
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700170 virtual void setFlags(const utils::eMdpFlags& flags);
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800171 virtual void setTransform(const utils::eTransform& rot);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500172 virtual bool commit();
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800173 virtual void setDownscale(int ds);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500174 virtual int getDstMemId() const;
175 virtual uint32_t getDstOffset() const;
Raj kamal23f69b22012-11-17 00:20:55 +0530176 virtual uint32_t getDstFormat() const;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500177 virtual uint32_t getSessId() const;
178 virtual bool queueBuffer(int fd, uint32_t offset);
179 virtual void dump() const;
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800180 virtual void getDump(char *buf, size_t len) const;
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700181
182private:
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500183 explicit MdssRot();
Saurabh Shahacf10202013-02-26 10:15:15 -0800184 bool init();
185 bool close();
186 void setRotations(uint32_t r);
187 bool enabled () const;
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700188 /* remap rot buffers */
189 bool remap(uint32_t numbufs);
190 bool open_i(uint32_t numbufs, uint32_t bufsz);
191 /* Deferred transform calculations */
192 void doTransform();
193 /* reset underlying data, basically memset 0 */
194 void reset();
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800195 /* Calculates the rotator's o/p buffer size post the transform calcs and
196 * knowing the o/p format depending on whether fastYuv is enabled or not */
197 uint32_t calcOutputBufSize();
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700198
199 /* MdssRot info structure */
200 mdp_overlay mRotInfo;
201 /* MdssRot data structure */
202 msmfb_overlay_data mRotData;
203 /* Orientation */
204 utils::eTransform mOrientation;
205 /* rotator fd */
206 OvFD mFd;
207 /* Rotator memory manager */
208 RotMem mMem;
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700209 /* Enable/Disable Mdss Rot*/
210 bool mEnabled;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500211
212 friend Rotator* Rotator::getRotator();
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700213};
Naseer Ahmed29a26812012-06-14 00:56:20 -0700214
Saurabh Shahacf10202013-02-26 10:15:15 -0800215// Holder of rotator objects. Manages lifetimes
216class RotMgr {
217public:
218 //Maximum sessions based on VG pipes, since rotator is used only for videos.
219 //Even though we can have 4 mixer stages, that much may be unnecessary.
220 enum { MAX_ROT_SESS = 3 };
221 RotMgr();
222 ~RotMgr();
223 void configBegin();
224 void configDone();
225 overlay::Rotator *getNext();
226 void clear(); //Removes all instances
227 /* Returns rot dump.
228 * Expects a NULL terminated buffer of big enough size.
229 */
230 void getDump(char *buf, size_t len);
231private:
232 overlay::Rotator *mRot[MAX_ROT_SESS];
233 int mUseCount;
234};
235
236
Naseer Ahmed29a26812012-06-14 00:56:20 -0700237} // overlay
238
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700239#endif // OVERlAY_ROTATOR_H