blob: 64387cd7075acc9bfccf56876f6889b57e5b4cda [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"
Saurabh Shah74eff4d2014-03-28 16:33:13 -070038#include "sync/sync.h"
Naseer Ahmed29a26812012-06-14 00:56:20 -070039
40namespace overlay {
Naseer Ahmedf48aef62012-07-20 09:05:53 -070041
Saurabh Shah23a813c2013-03-20 16:58:12 -070042/*
43 Manages the case where new rotator memory needs to be
44 allocated, before previous is freed, due to resolution change etc. If we make
45 rotator memory to be always max size, irrespctive of source resolution then
46 we don't need this RotMem wrapper. The inner class is sufficient.
47*/
48struct RotMem {
Saurabh Shah912c9482014-02-07 14:01:04 -080049 // Max rotator buffers
50 enum { ROT_NUM_BUFS = 2 };
51 RotMem();
52 ~RotMem();
Saurabh Shah23a813c2013-03-20 16:58:12 -070053 bool close();
Saurabh Shah912c9482014-02-07 14:01:04 -080054 bool valid() { return mem.valid(); }
55 uint32_t size() const { return mem.bufSz(); }
56 void setReleaseFd(const int& fence);
57
58 // rotator data info dst offset
59 uint32_t mRotOffset[ROT_NUM_BUFS];
60 int mRelFence[ROT_NUM_BUFS];
61 // current slot being used
62 uint32_t mCurrIndex;
63 OvMem mem;
Saurabh Shah23a813c2013-03-20 16:58:12 -070064};
65
Naseer Ahmed758bfc52012-11-28 17:02:08 -050066class Rotator
Naseer Ahmedf48aef62012-07-20 09:05:53 -070067{
68public:
Naseer Ahmed758bfc52012-11-28 17:02:08 -050069 enum { TYPE_MDP, TYPE_MDSS };
Naseer Ahmedf48aef62012-07-20 09:05:53 -070070 virtual ~Rotator();
Naseer Ahmed758bfc52012-11-28 17:02:08 -050071 virtual void setSource(const utils::Whf& wfh) = 0;
Sushil Chauhan80fc1f92013-04-23 17:30:05 -070072 virtual void setCrop(const utils::Dim& crop) = 0;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050073 virtual void setFlags(const utils::eMdpFlags& flags) = 0;
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -080074 virtual void setTransform(const utils::eTransform& rot) = 0;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050075 virtual bool commit() = 0;
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -080076 virtual void setDownscale(int ds) = 0;
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -070077 //Mem id and offset should be retrieved only after rotator kickoff
Naseer Ahmed758bfc52012-11-28 17:02:08 -050078 virtual int getDstMemId() const = 0;
79 virtual uint32_t getDstOffset() const = 0;
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -070080 //Destination width, height, format, position should be retrieved only after
81 //rotator configuration is committed via commit API
Raj kamal23f69b22012-11-17 00:20:55 +053082 virtual uint32_t getDstFormat() const = 0;
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -070083 virtual utils::Whf getDstWhf() const = 0;
84 virtual utils::Dim getDstDimensions() const = 0;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050085 virtual uint32_t getSessId() const = 0;
86 virtual bool queueBuffer(int fd, uint32_t offset) = 0;
87 virtual void dump() const = 0;
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -080088 virtual void getDump(char *buf, size_t len) const = 0;
Saurabh Shah23a813c2013-03-20 16:58:12 -070089 void setReleaseFd(const int& fence) { mMem.setReleaseFd(fence); }
Naseer Ahmed758bfc52012-11-28 17:02:08 -050090 static Rotator *getRotator();
Naseer Ahmed29a26812012-06-14 00:56:20 -070091
Naseer Ahmed758bfc52012-11-28 17:02:08 -050092protected:
Saurabh Shah23a813c2013-03-20 16:58:12 -070093 /* Rotator memory manager */
94 RotMem mMem;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050095 explicit Rotator() {}
Saurabh Shahfc3652f2013-02-15 13:15:45 -080096 static uint32_t calcOutputBufSize(const utils::Whf& destWhf);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050097
98private:
99 /*Returns rotator h/w type */
100 static int getRotatorHwType();
Saurabh Shah23a813c2013-03-20 16:58:12 -0700101 friend class RotMgr;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700102};
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);
Sushil Chauhan80fc1f92013-04-23 17:30:05 -0700112 virtual void setCrop(const utils::Dim& crop);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700113 virtual void setFlags(const utils::eMdpFlags& flags);
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800114 virtual void setTransform(const utils::eTransform& rot);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500115 virtual bool commit();
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800116 virtual void setDownscale(int ds);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500117 virtual int getDstMemId() const;
118 virtual uint32_t getDstOffset() const;
Raj kamal23f69b22012-11-17 00:20:55 +0530119 virtual uint32_t getDstFormat() const;
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -0700120 virtual utils::Whf getDstWhf() const;
121 virtual utils::Dim getDstDimensions() const;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500122 virtual uint32_t getSessId() const;
123 virtual bool queueBuffer(int fd, uint32_t offset);
124 virtual void dump() const;
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800125 virtual void getDump(char *buf, size_t len) const;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700126
Naseer Ahmed29a26812012-06-14 00:56:20 -0700127private:
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500128 explicit MdpRot();
Saurabh Shahacf10202013-02-26 10:15:15 -0800129 bool init();
130 bool close();
131 void setRotations(uint32_t r);
132 bool enabled () const;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700133 /* remap rot buffers */
134 bool remap(uint32_t numbufs);
135 bool open_i(uint32_t numbufs, uint32_t bufsz);
136 /* Deferred transform calculations */
137 void doTransform();
138 /* reset underlying data, basically memset 0 */
139 void reset();
Saurabh Shahc23b3802012-08-31 11:11:30 -0700140 /* return true if current rotator config is different
141 * than last known config */
142 bool rotConfChanged() const;
Saurabh Shahc23b3802012-08-31 11:11:30 -0700143 /* save mRotImgInfo to be last known good config*/
144 void save();
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800145 /* Calculates the rotator's o/p buffer size post the transform calcs and
146 * knowing the o/p format depending on whether fastYuv is enabled or not */
147 uint32_t calcOutputBufSize();
Saurabh Shahc23b3802012-08-31 11:11:30 -0700148
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700149 /* rot info*/
150 msm_rotator_img_info mRotImgInfo;
Saurabh Shahc23b3802012-08-31 11:11:30 -0700151 /* Last saved rot info*/
152 msm_rotator_img_info mLSRotImgInfo;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700153 /* rot data */
154 msm_rotator_data_info mRotDataInfo;
155 /* Orientation */
156 utils::eTransform mOrientation;
157 /* rotator fd */
158 OvFD mFd;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500159
160 friend Rotator* Rotator::getRotator();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700161};
162
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700163/*
164+* MDSS Rot holds MDSS's rotation related structures.
165+*
166+* */
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500167class MdssRot : public Rotator {
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700168public:
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500169 virtual ~MdssRot();
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500170 virtual void setSource(const utils::Whf& wfh);
Sushil Chauhan80fc1f92013-04-23 17:30:05 -0700171 virtual void setCrop(const utils::Dim& crop);
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700172 virtual void setFlags(const utils::eMdpFlags& flags);
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800173 virtual void setTransform(const utils::eTransform& rot);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500174 virtual bool commit();
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800175 virtual void setDownscale(int ds);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500176 virtual int getDstMemId() const;
177 virtual uint32_t getDstOffset() const;
Raj kamal23f69b22012-11-17 00:20:55 +0530178 virtual uint32_t getDstFormat() const;
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -0700179 virtual utils::Whf getDstWhf() const;
180 virtual utils::Dim getDstDimensions() const;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500181 virtual uint32_t getSessId() const;
182 virtual bool queueBuffer(int fd, uint32_t offset);
183 virtual void dump() const;
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800184 virtual void getDump(char *buf, size_t len) const;
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700185
186private:
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500187 explicit MdssRot();
Saurabh Shahacf10202013-02-26 10:15:15 -0800188 bool init();
189 bool close();
190 void setRotations(uint32_t r);
191 bool enabled () const;
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700192 /* remap rot buffers */
193 bool remap(uint32_t numbufs);
194 bool open_i(uint32_t numbufs, uint32_t bufsz);
195 /* Deferred transform calculations */
196 void doTransform();
197 /* reset underlying data, basically memset 0 */
198 void reset();
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800199 /* Calculates the rotator's o/p buffer size post the transform calcs and
200 * knowing the o/p format depending on whether fastYuv is enabled or not */
201 uint32_t calcOutputBufSize();
Sushil Chauhanbab187a2013-01-30 17:44:15 -0800202 // Calculate the compressed o/p buffer size for BWC
Sushil Chauhan466766f2013-07-31 11:21:07 -0700203 uint32_t calcCompressedBufSize(const utils::Whf& destWhf);
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700204
205 /* MdssRot info structure */
206 mdp_overlay mRotInfo;
207 /* MdssRot data structure */
208 msmfb_overlay_data mRotData;
209 /* Orientation */
210 utils::eTransform mOrientation;
211 /* rotator fd */
212 OvFD mFd;
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700213 /* Enable/Disable Mdss Rot*/
214 bool mEnabled;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500215
216 friend Rotator* Rotator::getRotator();
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700217};
Naseer Ahmed29a26812012-06-14 00:56:20 -0700218
Saurabh Shahacf10202013-02-26 10:15:15 -0800219// Holder of rotator objects. Manages lifetimes
220class RotMgr {
221public:
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -0800222 //Virtually we can support as many rotator sessions as possible, However
223 // more number of rotator sessions leads to performance issues, so
224 // restricting the max rotator session to 4
Saurabh Shah54318572014-05-30 16:42:33 -0700225 enum { MAX_ROT_SESS = 4 };
Saurabh Shah7a606842013-12-11 14:36:04 -0800226
Saurabh Shahacf10202013-02-26 10:15:15 -0800227 ~RotMgr();
228 void configBegin();
229 void configDone();
230 overlay::Rotator *getNext();
231 void clear(); //Removes all instances
Saurabh Shah7a606842013-12-11 14:36:04 -0800232 //Resets the usage of top count objects, making them available for reuse
233 void markUnusedTop(const uint32_t& count) { mUseCount -= count; }
Saurabh Shahacf10202013-02-26 10:15:15 -0800234 /* Returns rot dump.
235 * Expects a NULL terminated buffer of big enough size.
236 */
237 void getDump(char *buf, size_t len);
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -0700238 int getRotDevFd();
Saurabh Shah2b6e5192013-10-22 17:22:04 -0700239 int getNumActiveSessions() { return mUseCount; }
Saurabh Shah7a606842013-12-11 14:36:04 -0800240
241 static RotMgr *getInstance();
242
Saurabh Shahacf10202013-02-26 10:15:15 -0800243private:
Saurabh Shah7a606842013-12-11 14:36:04 -0800244 RotMgr();
245 static RotMgr *sRotMgr;
246
Saurabh Shahacf10202013-02-26 10:15:15 -0800247 overlay::Rotator *mRot[MAX_ROT_SESS];
Saurabh Shah7a606842013-12-11 14:36:04 -0800248 uint32_t mUseCount;
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -0700249 int mRotDevFd;
Saurabh Shahacf10202013-02-26 10:15:15 -0800250};
251
252
Naseer Ahmed29a26812012-06-14 00:56:20 -0700253} // overlay
254
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700255#endif // OVERlAY_ROTATOR_H