blob: 120721c74eaa3048e421ca707ab228198a8c33fe [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;
Sushil Chauhan80fc1f92013-04-23 17:30:05 -070047 virtual void setCrop(const utils::Dim& crop) = 0;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050048 virtual void setFlags(const utils::eMdpFlags& flags) = 0;
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -080049 virtual void setTransform(const utils::eTransform& rot) = 0;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050050 virtual bool commit() = 0;
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -080051 virtual void setDownscale(int ds) = 0;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050052 virtual int getDstMemId() const = 0;
53 virtual uint32_t getDstOffset() const = 0;
Raj kamal23f69b22012-11-17 00:20:55 +053054 virtual uint32_t getDstFormat() const = 0;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050055 virtual uint32_t getSessId() const = 0;
56 virtual bool queueBuffer(int fd, uint32_t offset) = 0;
57 virtual void dump() const = 0;
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -080058 virtual void getDump(char *buf, size_t len) const = 0;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050059 static Rotator *getRotator();
Naseer Ahmed29a26812012-06-14 00:56:20 -070060
Naseer Ahmed758bfc52012-11-28 17:02:08 -050061protected:
62 explicit Rotator() {}
Saurabh Shahfc3652f2013-02-15 13:15:45 -080063 static uint32_t calcOutputBufSize(const utils::Whf& destWhf);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050064
65private:
66 /*Returns rotator h/w type */
67 static int getRotatorHwType();
Naseer Ahmed29a26812012-06-14 00:56:20 -070068};
69
Naseer Ahmedf48aef62012-07-20 09:05:53 -070070/*
71 Manages the case where new rotator memory needs to be
72 allocated, before previous is freed, due to resolution change etc. If we make
73 rotator memory to be always max size, irrespctive of source resolution then
74 we don't need this RotMem wrapper. The inner class is sufficient.
75*/
76struct RotMem {
77 // Max rotator memory allocations
78 enum { MAX_ROT_MEM = 2};
79
80 //Manages the rotator buffer offsets.
81 struct Mem {
82 Mem() : mCurrOffset(0) {utils::memset0(mRotOffset); }
83 bool valid() { return m.valid(); }
84 bool close() { return m.close(); }
85 uint32_t size() const { return m.bufSz(); }
86 // Max rotator buffers
87 enum { ROT_NUM_BUFS = 2 };
88 // rotator data info dst offset
89 uint32_t mRotOffset[ROT_NUM_BUFS];
90 // current offset slot from mRotOffset
91 uint32_t mCurrOffset;
92 OvMem m;
93 };
94
95 RotMem() : _curr(0) {}
96 Mem& curr() { return m[_curr % MAX_ROT_MEM]; }
97 const Mem& curr() const { return m[_curr % MAX_ROT_MEM]; }
98 Mem& prev() { return m[(_curr+1) % MAX_ROT_MEM]; }
99 RotMem& operator++() { ++_curr; return *this; }
100 bool close();
101 uint32_t _curr;
102 Mem m[MAX_ROT_MEM];
103};
Naseer Ahmed29a26812012-06-14 00:56:20 -0700104
105/*
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700106* MDP rot holds MDP's rotation related structures.
107*
Naseer Ahmed29a26812012-06-14 00:56:20 -0700108* */
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500109class MdpRot : public Rotator {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700110public:
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500111 virtual ~MdpRot();
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500112 virtual void setSource(const utils::Whf& wfh);
Sushil Chauhan80fc1f92013-04-23 17:30:05 -0700113 virtual void setCrop(const utils::Dim& crop);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700114 virtual void setFlags(const utils::eMdpFlags& flags);
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800115 virtual void setTransform(const utils::eTransform& rot);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500116 virtual bool commit();
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800117 virtual void setDownscale(int ds);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500118 virtual int getDstMemId() const;
119 virtual uint32_t getDstOffset() const;
Raj kamal23f69b22012-11-17 00:20:55 +0530120 virtual uint32_t getDstFormat() const;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500121 virtual uint32_t getSessId() const;
122 virtual bool queueBuffer(int fd, uint32_t offset);
123 virtual void dump() const;
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800124 virtual void getDump(char *buf, size_t len) const;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700125
Naseer Ahmed29a26812012-06-14 00:56:20 -0700126private:
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500127 explicit MdpRot();
Saurabh Shahacf10202013-02-26 10:15:15 -0800128 bool init();
129 bool close();
130 void setRotations(uint32_t r);
131 bool enabled () const;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700132 /* remap rot buffers */
133 bool remap(uint32_t numbufs);
134 bool open_i(uint32_t numbufs, uint32_t bufsz);
135 /* Deferred transform calculations */
136 void doTransform();
137 /* reset underlying data, basically memset 0 */
138 void reset();
Saurabh Shahc23b3802012-08-31 11:11:30 -0700139 /* return true if current rotator config is different
140 * than last known config */
141 bool rotConfChanged() const;
Saurabh Shahc23b3802012-08-31 11:11:30 -0700142 /* save mRotImgInfo to be last known good config*/
143 void save();
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800144 /* Calculates the rotator's o/p buffer size post the transform calcs and
145 * knowing the o/p format depending on whether fastYuv is enabled or not */
146 uint32_t calcOutputBufSize();
Saurabh Shahc23b3802012-08-31 11:11:30 -0700147
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700148 /* rot info*/
149 msm_rotator_img_info mRotImgInfo;
Saurabh Shahc23b3802012-08-31 11:11:30 -0700150 /* Last saved rot info*/
151 msm_rotator_img_info mLSRotImgInfo;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700152 /* rot data */
153 msm_rotator_data_info mRotDataInfo;
154 /* Orientation */
155 utils::eTransform mOrientation;
156 /* rotator fd */
157 OvFD mFd;
158 /* Rotator memory manager */
159 RotMem mMem;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500160
161 friend Rotator* Rotator::getRotator();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700162};
163
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700164/*
165+* MDSS Rot holds MDSS's rotation related structures.
166+*
167+* */
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500168class MdssRot : public Rotator {
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700169public:
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500170 virtual ~MdssRot();
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500171 virtual void setSource(const utils::Whf& wfh);
Sushil Chauhan80fc1f92013-04-23 17:30:05 -0700172 virtual void setCrop(const utils::Dim& crop);
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700173 virtual void setFlags(const utils::eMdpFlags& flags);
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800174 virtual void setTransform(const utils::eTransform& rot);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500175 virtual bool commit();
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800176 virtual void setDownscale(int ds);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500177 virtual int getDstMemId() const;
178 virtual uint32_t getDstOffset() const;
Raj kamal23f69b22012-11-17 00:20:55 +0530179 virtual uint32_t getDstFormat() const;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500180 virtual uint32_t getSessId() const;
181 virtual bool queueBuffer(int fd, uint32_t offset);
182 virtual void dump() const;
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800183 virtual void getDump(char *buf, size_t len) const;
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700184
185private:
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500186 explicit MdssRot();
Saurabh Shahacf10202013-02-26 10:15:15 -0800187 bool init();
188 bool close();
189 void setRotations(uint32_t r);
190 bool enabled () const;
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700191 /* remap rot buffers */
192 bool remap(uint32_t numbufs);
193 bool open_i(uint32_t numbufs, uint32_t bufsz);
194 /* Deferred transform calculations */
195 void doTransform();
196 /* reset underlying data, basically memset 0 */
197 void reset();
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800198 /* Calculates the rotator's o/p buffer size post the transform calcs and
199 * knowing the o/p format depending on whether fastYuv is enabled or not */
200 uint32_t calcOutputBufSize();
Sushil Chauhanbab187a2013-01-30 17:44:15 -0800201 // Calculate the compressed o/p buffer size for BWC
202 uint32_t calcCompressedBufSize();
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700203
204 /* MdssRot info structure */
205 mdp_overlay mRotInfo;
206 /* MdssRot data structure */
207 msmfb_overlay_data mRotData;
208 /* Orientation */
209 utils::eTransform mOrientation;
210 /* rotator fd */
211 OvFD mFd;
212 /* Rotator memory manager */
213 RotMem mMem;
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700214 /* Enable/Disable Mdss Rot*/
215 bool mEnabled;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500216
217 friend Rotator* Rotator::getRotator();
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700218};
Naseer Ahmed29a26812012-06-14 00:56:20 -0700219
Saurabh Shahacf10202013-02-26 10:15:15 -0800220// Holder of rotator objects. Manages lifetimes
221class RotMgr {
222public:
223 //Maximum sessions based on VG pipes, since rotator is used only for videos.
224 //Even though we can have 4 mixer stages, that much may be unnecessary.
225 enum { MAX_ROT_SESS = 3 };
226 RotMgr();
227 ~RotMgr();
228 void configBegin();
229 void configDone();
230 overlay::Rotator *getNext();
231 void clear(); //Removes all instances
232 /* Returns rot dump.
233 * Expects a NULL terminated buffer of big enough size.
234 */
235 void getDump(char *buf, size_t len);
236private:
237 overlay::Rotator *mRot[MAX_ROT_SESS];
238 int mUseCount;
239};
240
241
Naseer Ahmed29a26812012-06-14 00:56:20 -0700242} // overlay
243
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700244#endif // OVERlAY_ROTATOR_H