blob: 3f09a23b8951eda5a69a48735ed3f12e417f5298 [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
Saurabh Shah23a813c2013-03-20 16:58:12 -070041/*
42 Manages the case where new rotator memory needs to be
43 allocated, before previous is freed, due to resolution change etc. If we make
44 rotator memory to be always max size, irrespctive of source resolution then
45 we don't need this RotMem wrapper. The inner class is sufficient.
46*/
47struct RotMem {
Saurabh Shah912c9482014-02-07 14:01:04 -080048 // Max rotator buffers
49 enum { ROT_NUM_BUFS = 2 };
50 RotMem();
51 ~RotMem();
Saurabh Shah23a813c2013-03-20 16:58:12 -070052 bool close();
Saurabh Shah912c9482014-02-07 14:01:04 -080053 bool valid() { return mem.valid(); }
54 uint32_t size() const { return mem.bufSz(); }
55 void setReleaseFd(const int& fence);
56
57 // rotator data info dst offset
58 uint32_t mRotOffset[ROT_NUM_BUFS];
59 int mRelFence[ROT_NUM_BUFS];
60 // current slot being used
61 uint32_t mCurrIndex;
62 OvMem mem;
Saurabh Shah23a813c2013-03-20 16:58:12 -070063};
64
Naseer Ahmed758bfc52012-11-28 17:02:08 -050065class Rotator
Naseer Ahmedf48aef62012-07-20 09:05:53 -070066{
67public:
Naseer Ahmed758bfc52012-11-28 17:02:08 -050068 enum { TYPE_MDP, TYPE_MDSS };
Naseer Ahmedf48aef62012-07-20 09:05:53 -070069 virtual ~Rotator();
Naseer Ahmed758bfc52012-11-28 17:02:08 -050070 virtual void setSource(const utils::Whf& wfh) = 0;
Sushil Chauhan80fc1f92013-04-23 17:30:05 -070071 virtual void setCrop(const utils::Dim& crop) = 0;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050072 virtual void setFlags(const utils::eMdpFlags& flags) = 0;
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -080073 virtual void setTransform(const utils::eTransform& rot) = 0;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050074 virtual bool commit() = 0;
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -080075 virtual void setDownscale(int ds) = 0;
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -070076 //Mem id and offset should be retrieved only after rotator kickoff
Naseer Ahmed758bfc52012-11-28 17:02:08 -050077 virtual int getDstMemId() const = 0;
78 virtual uint32_t getDstOffset() const = 0;
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -070079 //Destination width, height, format, position should be retrieved only after
80 //rotator configuration is committed via commit API
Raj kamal23f69b22012-11-17 00:20:55 +053081 virtual uint32_t getDstFormat() const = 0;
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -070082 virtual utils::Whf getDstWhf() const = 0;
83 virtual utils::Dim getDstDimensions() const = 0;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050084 virtual uint32_t getSessId() const = 0;
85 virtual bool queueBuffer(int fd, uint32_t offset) = 0;
86 virtual void dump() const = 0;
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -080087 virtual void getDump(char *buf, size_t len) const = 0;
Saurabh Shah23a813c2013-03-20 16:58:12 -070088 void setReleaseFd(const int& fence) { mMem.setReleaseFd(fence); }
Naseer Ahmed758bfc52012-11-28 17:02:08 -050089 static Rotator *getRotator();
Saurabh Shahc46cf9d2014-07-02 15:22:34 -070090 /* Returns downscale by successfully applying constraints
91 * Returns 0 if target doesnt support rotator downscaling
92 * or if any of the constraints are not met
93 */
94 static int getDownscaleFactor(const int& srcW, const int& srcH,
95 const int& dstW, const int& dstH, const uint32_t& mdpFormat,
96 const bool& isInterlaced);
Naseer Ahmed29a26812012-06-14 00:56:20 -070097
Naseer Ahmed758bfc52012-11-28 17:02:08 -050098protected:
Saurabh Shah23a813c2013-03-20 16:58:12 -070099 /* Rotator memory manager */
100 RotMem mMem;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500101 explicit Rotator() {}
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800102 static uint32_t calcOutputBufSize(const utils::Whf& destWhf);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500103
104private:
105 /*Returns rotator h/w type */
106 static int getRotatorHwType();
Saurabh Shah23a813c2013-03-20 16:58:12 -0700107 friend class RotMgr;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700108};
Naseer Ahmed29a26812012-06-14 00:56:20 -0700109
110/*
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700111* MDP rot holds MDP's rotation related structures.
112*
Naseer Ahmed29a26812012-06-14 00:56:20 -0700113* */
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500114class MdpRot : public Rotator {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700115public:
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500116 virtual ~MdpRot();
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500117 virtual void setSource(const utils::Whf& wfh);
Sushil Chauhan80fc1f92013-04-23 17:30:05 -0700118 virtual void setCrop(const utils::Dim& crop);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700119 virtual void setFlags(const utils::eMdpFlags& flags);
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800120 virtual void setTransform(const utils::eTransform& rot);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500121 virtual bool commit();
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800122 virtual void setDownscale(int ds);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500123 virtual int getDstMemId() const;
124 virtual uint32_t getDstOffset() const;
Raj kamal23f69b22012-11-17 00:20:55 +0530125 virtual uint32_t getDstFormat() const;
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -0700126 virtual utils::Whf getDstWhf() const;
127 virtual utils::Dim getDstDimensions() const;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500128 virtual uint32_t getSessId() const;
129 virtual bool queueBuffer(int fd, uint32_t offset);
130 virtual void dump() const;
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800131 virtual void getDump(char *buf, size_t len) const;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700132
Naseer Ahmed29a26812012-06-14 00:56:20 -0700133private:
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500134 explicit MdpRot();
Saurabh Shahacf10202013-02-26 10:15:15 -0800135 bool init();
136 bool close();
137 void setRotations(uint32_t r);
138 bool enabled () const;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700139 /* remap rot buffers */
140 bool remap(uint32_t numbufs);
141 bool open_i(uint32_t numbufs, uint32_t bufsz);
142 /* Deferred transform calculations */
143 void doTransform();
144 /* reset underlying data, basically memset 0 */
145 void reset();
Saurabh Shahc23b3802012-08-31 11:11:30 -0700146 /* return true if current rotator config is different
147 * than last known config */
148 bool rotConfChanged() const;
Saurabh Shahc23b3802012-08-31 11:11:30 -0700149 /* save mRotImgInfo to be last known good config*/
150 void save();
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800151 /* Calculates the rotator's o/p buffer size post the transform calcs and
152 * knowing the o/p format depending on whether fastYuv is enabled or not */
153 uint32_t calcOutputBufSize();
Saurabh Shahc23b3802012-08-31 11:11:30 -0700154
Saurabh Shahc46cf9d2014-07-02 15:22:34 -0700155 /* Applies downscale by taking areas
156 * Returns a log(downscale)
157 * Constraints applied:
158 * - downscale should be a power of 2
159 * - Max downscale is 1/8
160 */
161 static int getDownscaleFactor(const int& srcW, const int& srcH,
162 const int& dstW, const int& dstH, const uint32_t& mdpFormat,
163 const bool& isInterlaced);
164
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700165 /* rot info*/
166 msm_rotator_img_info mRotImgInfo;
Saurabh Shahc23b3802012-08-31 11:11:30 -0700167 /* Last saved rot info*/
168 msm_rotator_img_info mLSRotImgInfo;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700169 /* rot data */
170 msm_rotator_data_info mRotDataInfo;
171 /* Orientation */
172 utils::eTransform mOrientation;
173 /* rotator fd */
174 OvFD mFd;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500175
176 friend Rotator* Rotator::getRotator();
Saurabh Shahc46cf9d2014-07-02 15:22:34 -0700177 friend int Rotator::getDownscaleFactor(const int& srcW, const int& srcH,
178 const int& dstW, const int& dstH, const uint32_t& mdpFormat,
179 const bool& isInterlaced);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700180};
181
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700182/*
183+* MDSS Rot holds MDSS's rotation related structures.
184+*
185+* */
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500186class MdssRot : public Rotator {
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700187public:
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500188 virtual ~MdssRot();
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500189 virtual void setSource(const utils::Whf& wfh);
Sushil Chauhan80fc1f92013-04-23 17:30:05 -0700190 virtual void setCrop(const utils::Dim& crop);
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700191 virtual void setFlags(const utils::eMdpFlags& flags);
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800192 virtual void setTransform(const utils::eTransform& rot);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500193 virtual bool commit();
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800194 virtual void setDownscale(int ds);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500195 virtual int getDstMemId() const;
196 virtual uint32_t getDstOffset() const;
Raj kamal23f69b22012-11-17 00:20:55 +0530197 virtual uint32_t getDstFormat() const;
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -0700198 virtual utils::Whf getDstWhf() const;
199 virtual utils::Dim getDstDimensions() const;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500200 virtual uint32_t getSessId() const;
201 virtual bool queueBuffer(int fd, uint32_t offset);
202 virtual void dump() const;
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800203 virtual void getDump(char *buf, size_t len) const;
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700204
205private:
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500206 explicit MdssRot();
Saurabh Shahacf10202013-02-26 10:15:15 -0800207 bool init();
208 bool close();
209 void setRotations(uint32_t r);
210 bool enabled () const;
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700211 /* remap rot buffers */
212 bool remap(uint32_t numbufs);
213 bool open_i(uint32_t numbufs, uint32_t bufsz);
214 /* Deferred transform calculations */
215 void doTransform();
216 /* reset underlying data, basically memset 0 */
217 void reset();
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800218 /* Calculates the rotator's o/p buffer size post the transform calcs and
219 * knowing the o/p format depending on whether fastYuv is enabled or not */
220 uint32_t calcOutputBufSize();
Sushil Chauhanbab187a2013-01-30 17:44:15 -0800221 // Calculate the compressed o/p buffer size for BWC
Sushil Chauhan466766f2013-07-31 11:21:07 -0700222 uint32_t calcCompressedBufSize(const utils::Whf& destWhf);
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700223
Saurabh Shahc46cf9d2014-07-02 15:22:34 -0700224 /* Caller's responsibility to swap srcW, srcH if there is a 90 transform
225 * Returns actual downscale (not a log value)
226 * Constraints applied:
227 * - downscale should be a power of 2
228 * - Max downscale is 1/32
229 * - Equal downscale is applied in both directions
230 * - {srcW, srcH} mod downscale = 0
231 * - Interlaced content is not supported
232 */
233 static int getDownscaleFactor(const int& srcW, const int& srcH,
234 const int& dstW, const int& dstH, const uint32_t& mdpFormat,
235 const bool& isInterlaced);
236
237 static utils::Dim getFormatAdjustedCrop(const utils::Dim& crop,
238 const uint32_t& mdpFormat, const bool& isInterlaced);
239
240 static utils::Dim getDownscaleAdjustedCrop(const utils::Dim& crop,
241 const uint32_t& downscale);
242
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700243 /* MdssRot info structure */
244 mdp_overlay mRotInfo;
245 /* MdssRot data structure */
246 msmfb_overlay_data mRotData;
247 /* Orientation */
248 utils::eTransform mOrientation;
249 /* rotator fd */
250 OvFD mFd;
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700251 /* Enable/Disable Mdss Rot*/
252 bool mEnabled;
Saurabh Shahc46cf9d2014-07-02 15:22:34 -0700253 int mDownscale;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500254
255 friend Rotator* Rotator::getRotator();
Saurabh Shahc46cf9d2014-07-02 15:22:34 -0700256 friend int Rotator::getDownscaleFactor(const int& srcW, const int& srcH,
257 const int& dstW, const int& dstH, const uint32_t& mdpFormat,
258 const bool& isInterlaced);
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700259};
Naseer Ahmed29a26812012-06-14 00:56:20 -0700260
Saurabh Shahacf10202013-02-26 10:15:15 -0800261// Holder of rotator objects. Manages lifetimes
262class RotMgr {
263public:
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -0800264 //Virtually we can support as many rotator sessions as possible, However
265 // more number of rotator sessions leads to performance issues, so
266 // restricting the max rotator session to 4
Saurabh Shah54318572014-05-30 16:42:33 -0700267 enum { MAX_ROT_SESS = 4 };
Saurabh Shah7a606842013-12-11 14:36:04 -0800268
Saurabh Shahacf10202013-02-26 10:15:15 -0800269 ~RotMgr();
270 void configBegin();
271 void configDone();
272 overlay::Rotator *getNext();
273 void clear(); //Removes all instances
Saurabh Shah7a606842013-12-11 14:36:04 -0800274 //Resets the usage of top count objects, making them available for reuse
275 void markUnusedTop(const uint32_t& count) { mUseCount -= count; }
Saurabh Shahacf10202013-02-26 10:15:15 -0800276 /* Returns rot dump.
277 * Expects a NULL terminated buffer of big enough size.
278 */
279 void getDump(char *buf, size_t len);
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -0700280 int getRotDevFd();
Saurabh Shah2b6e5192013-10-22 17:22:04 -0700281 int getNumActiveSessions() { return mUseCount; }
Saurabh Shah7a606842013-12-11 14:36:04 -0800282
283 static RotMgr *getInstance();
284
Saurabh Shahacf10202013-02-26 10:15:15 -0800285private:
Saurabh Shah7a606842013-12-11 14:36:04 -0800286 RotMgr();
287 static RotMgr *sRotMgr;
288
Saurabh Shahacf10202013-02-26 10:15:15 -0800289 overlay::Rotator *mRot[MAX_ROT_SESS];
Saurabh Shah7a606842013-12-11 14:36:04 -0800290 uint32_t mUseCount;
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -0700291 int mRotDevFd;
Saurabh Shahacf10202013-02-26 10:15:15 -0800292};
293
294
Naseer Ahmed29a26812012-06-14 00:56:20 -0700295} // overlay
296
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700297#endif // OVERlAY_ROTATOR_H