blob: 0766c86736e4ba709b44e923df3d9c9519c20a18 [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(); }
Raj Kamalbd3bdc62014-08-05 18:52:49 +053055 void setCurrBufReleaseFd(const int& fence);
56 void setPrevBufReleaseFd(const int& fence);
Saurabh Shah912c9482014-02-07 14:01:04 -080057
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;
Raj Kamalbd3bdc62014-08-05 18:52:49 +053076 /* return true if the current rotator state is cached */
77 virtual bool isRotCached(int fd, uint32_t offset) const;
78 /* return true if current rotator config is same as the last round*/
79 virtual bool rotConfChanged() const = 0;
80 /* return true if the current rotator input buffer fd and offset
81 * are same as the last round */
82 virtual bool rotDataChanged(int fd, uint32_t offset) const;
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -080083 virtual void setDownscale(int ds) = 0;
Raj Kamalbd3bdc62014-08-05 18:52:49 +053084 /* returns the src buffer of the rotator for the previous/current round,
85 * depending on when it is called(before/after the queuebuffer)*/
86 virtual int getSrcMemId() const = 0;
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -070087 //Mem id and offset should be retrieved only after rotator kickoff
Naseer Ahmed758bfc52012-11-28 17:02:08 -050088 virtual int getDstMemId() const = 0;
Raj Kamalbd3bdc62014-08-05 18:52:49 +053089 virtual uint32_t getSrcOffset() const = 0;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050090 virtual uint32_t getDstOffset() const = 0;
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -070091 //Destination width, height, format, position should be retrieved only after
92 //rotator configuration is committed via commit API
Raj kamal23f69b22012-11-17 00:20:55 +053093 virtual uint32_t getDstFormat() const = 0;
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -070094 virtual utils::Whf getDstWhf() const = 0;
95 virtual utils::Dim getDstDimensions() const = 0;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050096 virtual uint32_t getSessId() const = 0;
97 virtual bool queueBuffer(int fd, uint32_t offset) = 0;
98 virtual void dump() const = 0;
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -080099 virtual void getDump(char *buf, size_t len) const = 0;
radhakrishnab8e2c952015-06-04 16:09:16 +0530100 virtual void setFrameRate(uint32_t frame_rate) = 0;
Raj Kamalbd3bdc62014-08-05 18:52:49 +0530101 inline void setCurrBufReleaseFd(const int& fence) {
102 mMem.setCurrBufReleaseFd(fence);
103 }
104 inline void setPrevBufReleaseFd(const int& fence) {
105 mMem.setPrevBufReleaseFd(fence);
106 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500107 static Rotator *getRotator();
Saurabh Shahc46cf9d2014-07-02 15:22:34 -0700108 /* Returns downscale by successfully applying constraints
109 * Returns 0 if target doesnt support rotator downscaling
110 * or if any of the constraints are not met
111 */
112 static int getDownscaleFactor(const int& srcW, const int& srcH,
113 const int& dstW, const int& dstH, const uint32_t& mdpFormat,
114 const bool& isInterlaced);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700115
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500116protected:
Saurabh Shah23a813c2013-03-20 16:58:12 -0700117 /* Rotator memory manager */
118 RotMem mMem;
Raj Kamalbd3bdc62014-08-05 18:52:49 +0530119 Rotator();
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800120 static uint32_t calcOutputBufSize(const utils::Whf& destWhf);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500121
122private:
Raj Kamalbd3bdc62014-08-05 18:52:49 +0530123 bool mRotCacheDisabled;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500124 /*Returns rotator h/w type */
125 static int getRotatorHwType();
Saurabh Shah23a813c2013-03-20 16:58:12 -0700126 friend class RotMgr;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700127};
Naseer Ahmed29a26812012-06-14 00:56:20 -0700128
129/*
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700130* MDP rot holds MDP's rotation related structures.
131*
Naseer Ahmed29a26812012-06-14 00:56:20 -0700132* */
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500133class MdpRot : public Rotator {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700134public:
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500135 virtual ~MdpRot();
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500136 virtual void setSource(const utils::Whf& wfh);
Sushil Chauhan80fc1f92013-04-23 17:30:05 -0700137 virtual void setCrop(const utils::Dim& crop);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700138 virtual void setFlags(const utils::eMdpFlags& flags);
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800139 virtual void setTransform(const utils::eTransform& rot);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500140 virtual bool commit();
Raj Kamalbd3bdc62014-08-05 18:52:49 +0530141 virtual bool rotConfChanged() const;
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800142 virtual void setDownscale(int ds);
Raj Kamalbd3bdc62014-08-05 18:52:49 +0530143 virtual int getSrcMemId() const;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500144 virtual int getDstMemId() const;
Raj Kamalbd3bdc62014-08-05 18:52:49 +0530145 virtual uint32_t getSrcOffset() const;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500146 virtual uint32_t getDstOffset() const;
Raj kamal23f69b22012-11-17 00:20:55 +0530147 virtual uint32_t getDstFormat() const;
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -0700148 virtual utils::Whf getDstWhf() const;
149 virtual utils::Dim getDstDimensions() const;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500150 virtual uint32_t getSessId() const;
151 virtual bool queueBuffer(int fd, uint32_t offset);
152 virtual void dump() const;
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800153 virtual void getDump(char *buf, size_t len) const;
radhakrishnab8e2c952015-06-04 16:09:16 +0530154 virtual void setFrameRate(uint32_t frame_rate);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700155
Naseer Ahmed29a26812012-06-14 00:56:20 -0700156private:
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500157 explicit MdpRot();
Saurabh Shahacf10202013-02-26 10:15:15 -0800158 bool init();
159 bool close();
160 void setRotations(uint32_t r);
161 bool enabled () const;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700162 /* remap rot buffers */
163 bool remap(uint32_t numbufs);
164 bool open_i(uint32_t numbufs, uint32_t bufsz);
165 /* Deferred transform calculations */
166 void doTransform();
167 /* reset underlying data, basically memset 0 */
168 void reset();
Saurabh Shahc23b3802012-08-31 11:11:30 -0700169 /* save mRotImgInfo to be last known good config*/
170 void save();
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800171 /* Calculates the rotator's o/p buffer size post the transform calcs and
172 * knowing the o/p format depending on whether fastYuv is enabled or not */
173 uint32_t calcOutputBufSize();
Saurabh Shahc23b3802012-08-31 11:11:30 -0700174
Saurabh Shahc46cf9d2014-07-02 15:22:34 -0700175 /* Applies downscale by taking areas
176 * Returns a log(downscale)
177 * Constraints applied:
178 * - downscale should be a power of 2
179 * - Max downscale is 1/8
180 */
181 static int getDownscaleFactor(const int& srcW, const int& srcH,
182 const int& dstW, const int& dstH, const uint32_t& mdpFormat,
183 const bool& isInterlaced);
184
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700185 /* rot info*/
186 msm_rotator_img_info mRotImgInfo;
Saurabh Shahc23b3802012-08-31 11:11:30 -0700187 /* Last saved rot info*/
188 msm_rotator_img_info mLSRotImgInfo;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700189 /* rot data */
190 msm_rotator_data_info mRotDataInfo;
191 /* Orientation */
192 utils::eTransform mOrientation;
193 /* rotator fd */
194 OvFD mFd;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500195
196 friend Rotator* Rotator::getRotator();
Saurabh Shahc46cf9d2014-07-02 15:22:34 -0700197 friend int Rotator::getDownscaleFactor(const int& srcW, const int& srcH,
198 const int& dstW, const int& dstH, const uint32_t& mdpFormat,
199 const bool& isInterlaced);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700200};
201
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700202/*
203+* MDSS Rot holds MDSS's rotation related structures.
204+*
205+* */
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500206class MdssRot : public Rotator {
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700207public:
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500208 virtual ~MdssRot();
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500209 virtual void setSource(const utils::Whf& wfh);
Sushil Chauhan80fc1f92013-04-23 17:30:05 -0700210 virtual void setCrop(const utils::Dim& crop);
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700211 virtual void setFlags(const utils::eMdpFlags& flags);
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800212 virtual void setTransform(const utils::eTransform& rot);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500213 virtual bool commit();
Raj Kamalbd3bdc62014-08-05 18:52:49 +0530214 virtual bool rotConfChanged() const;
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800215 virtual void setDownscale(int ds);
Raj Kamalbd3bdc62014-08-05 18:52:49 +0530216 virtual int getSrcMemId() const;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500217 virtual int getDstMemId() const;
Raj Kamalbd3bdc62014-08-05 18:52:49 +0530218 virtual uint32_t getSrcOffset() const;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500219 virtual uint32_t getDstOffset() const;
Raj kamal23f69b22012-11-17 00:20:55 +0530220 virtual uint32_t getDstFormat() const;
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -0700221 virtual utils::Whf getDstWhf() const;
222 virtual utils::Dim getDstDimensions() const;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500223 virtual uint32_t getSessId() const;
224 virtual bool queueBuffer(int fd, uint32_t offset);
225 virtual void dump() const;
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800226 virtual void getDump(char *buf, size_t len) const;
radhakrishnab8e2c952015-06-04 16:09:16 +0530227 virtual void setFrameRate(uint32_t frame_rate);
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700228
229private:
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500230 explicit MdssRot();
Saurabh Shahacf10202013-02-26 10:15:15 -0800231 bool init();
232 bool close();
233 void setRotations(uint32_t r);
234 bool enabled () const;
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700235 /* remap rot buffers */
236 bool remap(uint32_t numbufs);
237 bool open_i(uint32_t numbufs, uint32_t bufsz);
238 /* Deferred transform calculations */
239 void doTransform();
240 /* reset underlying data, basically memset 0 */
241 void reset();
Raj Kamalbd3bdc62014-08-05 18:52:49 +0530242 /* save mRotInfo to be last known good config*/
243 void save();
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800244 /* Calculates the rotator's o/p buffer size post the transform calcs and
245 * knowing the o/p format depending on whether fastYuv is enabled or not */
246 uint32_t calcOutputBufSize();
Sushil Chauhanbab187a2013-01-30 17:44:15 -0800247 // Calculate the compressed o/p buffer size for BWC
Sushil Chauhan466766f2013-07-31 11:21:07 -0700248 uint32_t calcCompressedBufSize(const utils::Whf& destWhf);
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700249
Saurabh Shahc46cf9d2014-07-02 15:22:34 -0700250 /* Caller's responsibility to swap srcW, srcH if there is a 90 transform
251 * Returns actual downscale (not a log value)
252 * Constraints applied:
253 * - downscale should be a power of 2
254 * - Max downscale is 1/32
255 * - Equal downscale is applied in both directions
256 * - {srcW, srcH} mod downscale = 0
257 * - Interlaced content is not supported
258 */
259 static int getDownscaleFactor(const int& srcW, const int& srcH,
260 const int& dstW, const int& dstH, const uint32_t& mdpFormat,
261 const bool& isInterlaced);
262
263 static utils::Dim getFormatAdjustedCrop(const utils::Dim& crop,
264 const uint32_t& mdpFormat, const bool& isInterlaced);
265
266 static utils::Dim getDownscaleAdjustedCrop(const utils::Dim& crop,
267 const uint32_t& downscale);
268
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700269 /* MdssRot info structure */
Raj Kamalbd3bdc62014-08-05 18:52:49 +0530270 mdp_overlay mRotInfo;
271 /* Last saved MdssRot info structure*/
272 mdp_overlay mLSRotInfo;
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700273 /* MdssRot data structure */
274 msmfb_overlay_data mRotData;
275 /* Orientation */
276 utils::eTransform mOrientation;
277 /* rotator fd */
278 OvFD mFd;
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700279 /* Enable/Disable Mdss Rot*/
280 bool mEnabled;
Saurabh Shahc46cf9d2014-07-02 15:22:34 -0700281 int mDownscale;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500282
283 friend Rotator* Rotator::getRotator();
Saurabh Shahc46cf9d2014-07-02 15:22:34 -0700284 friend int Rotator::getDownscaleFactor(const int& srcW, const int& srcH,
285 const int& dstW, const int& dstH, const uint32_t& mdpFormat,
286 const bool& isInterlaced);
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700287};
Naseer Ahmed29a26812012-06-14 00:56:20 -0700288
Saurabh Shahacf10202013-02-26 10:15:15 -0800289// Holder of rotator objects. Manages lifetimes
290class RotMgr {
291public:
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -0800292 //Virtually we can support as many rotator sessions as possible, However
293 // more number of rotator sessions leads to performance issues, so
294 // restricting the max rotator session to 4
Saurabh Shah54318572014-05-30 16:42:33 -0700295 enum { MAX_ROT_SESS = 4 };
Saurabh Shah7a606842013-12-11 14:36:04 -0800296
Saurabh Shahacf10202013-02-26 10:15:15 -0800297 ~RotMgr();
298 void configBegin();
299 void configDone();
300 overlay::Rotator *getNext();
301 void clear(); //Removes all instances
Saurabh Shah7a606842013-12-11 14:36:04 -0800302 //Resets the usage of top count objects, making them available for reuse
303 void markUnusedTop(const uint32_t& count) { mUseCount -= count; }
Saurabh Shahacf10202013-02-26 10:15:15 -0800304 /* Returns rot dump.
305 * Expects a NULL terminated buffer of big enough size.
306 */
307 void getDump(char *buf, size_t len);
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -0700308 int getRotDevFd();
Saurabh Shah2b6e5192013-10-22 17:22:04 -0700309 int getNumActiveSessions() { return mUseCount; }
Saurabh Shah7a606842013-12-11 14:36:04 -0800310
311 static RotMgr *getInstance();
312
Saurabh Shahacf10202013-02-26 10:15:15 -0800313private:
Saurabh Shah7a606842013-12-11 14:36:04 -0800314 RotMgr();
315 static RotMgr *sRotMgr;
316
Saurabh Shahacf10202013-02-26 10:15:15 -0800317 overlay::Rotator *mRot[MAX_ROT_SESS];
Saurabh Shah7a606842013-12-11 14:36:04 -0800318 uint32_t mUseCount;
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -0700319 int mRotDevFd;
Saurabh Shahacf10202013-02-26 10:15:15 -0800320};
321
322
Naseer Ahmed29a26812012-06-14 00:56:20 -0700323} // overlay
324
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700325#endif // OVERlAY_ROTATOR_H