blob: 6bb94a610ff611e5df55ae79bd9c4911fc10b251 [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 {
48 // Max rotator memory allocations
49 enum { MAX_ROT_MEM = 2};
50
51 //Manages the rotator buffer offsets.
52 struct Mem {
53 Mem();
54 ~Mem();
55 bool valid() { return m.valid(); }
56 bool close() { return m.close(); }
57 uint32_t size() const { return m.bufSz(); }
58 void setReleaseFd(const int& fence);
Saurabh Shahda5b3ce2013-11-26 10:48:06 -080059 void resetReleaseFd();
Saurabh Shah23a813c2013-03-20 16:58:12 -070060 // Max rotator buffers
61 enum { ROT_NUM_BUFS = 2 };
62 // rotator data info dst offset
63 uint32_t mRotOffset[ROT_NUM_BUFS];
64 int mRelFence[ROT_NUM_BUFS];
65 // current offset slot from mRotOffset
66 uint32_t mCurrOffset;
67 OvMem m;
68 };
69
70 RotMem() : _curr(0) {}
71 Mem& curr() { return m[_curr % MAX_ROT_MEM]; }
72 const Mem& curr() const { return m[_curr % MAX_ROT_MEM]; }
73 Mem& prev() { return m[(_curr+1) % MAX_ROT_MEM]; }
74 RotMem& operator++() { ++_curr; return *this; }
75 void setReleaseFd(const int& fence) { curr().setReleaseFd(fence); }
Saurabh Shahda5b3ce2013-11-26 10:48:06 -080076 void resetReleaseFd() { curr().resetReleaseFd(); }
Saurabh Shah23a813c2013-03-20 16:58:12 -070077 bool close();
78 uint32_t _curr;
79 Mem m[MAX_ROT_MEM];
80};
81
Naseer Ahmed758bfc52012-11-28 17:02:08 -050082class Rotator
Naseer Ahmedf48aef62012-07-20 09:05:53 -070083{
84public:
Naseer Ahmed758bfc52012-11-28 17:02:08 -050085 enum { TYPE_MDP, TYPE_MDSS };
Naseer Ahmedf48aef62012-07-20 09:05:53 -070086 virtual ~Rotator();
Naseer Ahmed758bfc52012-11-28 17:02:08 -050087 virtual void setSource(const utils::Whf& wfh) = 0;
Sushil Chauhan80fc1f92013-04-23 17:30:05 -070088 virtual void setCrop(const utils::Dim& crop) = 0;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050089 virtual void setFlags(const utils::eMdpFlags& flags) = 0;
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -080090 virtual void setTransform(const utils::eTransform& rot) = 0;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050091 virtual bool commit() = 0;
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -080092 virtual void setDownscale(int ds) = 0;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050093 virtual int getDstMemId() const = 0;
94 virtual uint32_t getDstOffset() const = 0;
Raj kamal23f69b22012-11-17 00:20:55 +053095 virtual uint32_t getDstFormat() 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;
Saurabh Shah23a813c2013-03-20 16:58:12 -0700100 void setReleaseFd(const int& fence) { mMem.setReleaseFd(fence); }
Saurabh Shahda5b3ce2013-11-26 10:48:06 -0800101 void resetReleaseFd() { mMem.resetReleaseFd(); }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500102 static Rotator *getRotator();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700103
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500104protected:
Saurabh Shah23a813c2013-03-20 16:58:12 -0700105 /* Rotator memory manager */
106 RotMem mMem;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500107 explicit Rotator() {}
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800108 static uint32_t calcOutputBufSize(const utils::Whf& destWhf);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500109
110private:
111 /*Returns rotator h/w type */
112 static int getRotatorHwType();
Saurabh Shah23a813c2013-03-20 16:58:12 -0700113 friend class RotMgr;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700114};
Naseer Ahmed29a26812012-06-14 00:56:20 -0700115
116/*
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700117* MDP rot holds MDP's rotation related structures.
118*
Naseer Ahmed29a26812012-06-14 00:56:20 -0700119* */
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500120class MdpRot : public Rotator {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700121public:
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500122 virtual ~MdpRot();
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500123 virtual void setSource(const utils::Whf& wfh);
Sushil Chauhan80fc1f92013-04-23 17:30:05 -0700124 virtual void setCrop(const utils::Dim& crop);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700125 virtual void setFlags(const utils::eMdpFlags& flags);
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800126 virtual void setTransform(const utils::eTransform& rot);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500127 virtual bool commit();
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800128 virtual void setDownscale(int ds);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500129 virtual int getDstMemId() const;
130 virtual uint32_t getDstOffset() const;
Raj kamal23f69b22012-11-17 00:20:55 +0530131 virtual uint32_t getDstFormat() const;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500132 virtual uint32_t getSessId() const;
133 virtual bool queueBuffer(int fd, uint32_t offset);
134 virtual void dump() const;
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800135 virtual void getDump(char *buf, size_t len) const;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700136
Naseer Ahmed29a26812012-06-14 00:56:20 -0700137private:
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500138 explicit MdpRot();
Saurabh Shahacf10202013-02-26 10:15:15 -0800139 bool init();
140 bool close();
141 void setRotations(uint32_t r);
142 bool enabled () const;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700143 /* remap rot buffers */
144 bool remap(uint32_t numbufs);
145 bool open_i(uint32_t numbufs, uint32_t bufsz);
146 /* Deferred transform calculations */
147 void doTransform();
148 /* reset underlying data, basically memset 0 */
149 void reset();
Saurabh Shahc23b3802012-08-31 11:11:30 -0700150 /* return true if current rotator config is different
151 * than last known config */
152 bool rotConfChanged() const;
Saurabh Shahc23b3802012-08-31 11:11:30 -0700153 /* save mRotImgInfo to be last known good config*/
154 void save();
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800155 /* Calculates the rotator's o/p buffer size post the transform calcs and
156 * knowing the o/p format depending on whether fastYuv is enabled or not */
157 uint32_t calcOutputBufSize();
Saurabh Shahc23b3802012-08-31 11:11:30 -0700158
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700159 /* rot info*/
160 msm_rotator_img_info mRotImgInfo;
Saurabh Shahc23b3802012-08-31 11:11:30 -0700161 /* Last saved rot info*/
162 msm_rotator_img_info mLSRotImgInfo;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700163 /* rot data */
164 msm_rotator_data_info mRotDataInfo;
165 /* Orientation */
166 utils::eTransform mOrientation;
167 /* rotator fd */
168 OvFD mFd;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500169
170 friend Rotator* Rotator::getRotator();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700171};
172
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700173/*
174+* MDSS Rot holds MDSS's rotation related structures.
175+*
176+* */
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500177class MdssRot : public Rotator {
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700178public:
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500179 virtual ~MdssRot();
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500180 virtual void setSource(const utils::Whf& wfh);
Sushil Chauhan80fc1f92013-04-23 17:30:05 -0700181 virtual void setCrop(const utils::Dim& crop);
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700182 virtual void setFlags(const utils::eMdpFlags& flags);
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800183 virtual void setTransform(const utils::eTransform& rot);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500184 virtual bool commit();
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800185 virtual void setDownscale(int ds);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500186 virtual int getDstMemId() const;
187 virtual uint32_t getDstOffset() const;
Raj kamal23f69b22012-11-17 00:20:55 +0530188 virtual uint32_t getDstFormat() const;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500189 virtual uint32_t getSessId() const;
190 virtual bool queueBuffer(int fd, uint32_t offset);
191 virtual void dump() const;
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800192 virtual void getDump(char *buf, size_t len) const;
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700193
194private:
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500195 explicit MdssRot();
Saurabh Shahacf10202013-02-26 10:15:15 -0800196 bool init();
197 bool close();
198 void setRotations(uint32_t r);
199 bool enabled () const;
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700200 /* remap rot buffers */
201 bool remap(uint32_t numbufs);
202 bool open_i(uint32_t numbufs, uint32_t bufsz);
203 /* Deferred transform calculations */
204 void doTransform();
205 /* reset underlying data, basically memset 0 */
206 void reset();
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800207 /* Calculates the rotator's o/p buffer size post the transform calcs and
208 * knowing the o/p format depending on whether fastYuv is enabled or not */
209 uint32_t calcOutputBufSize();
Sushil Chauhanbab187a2013-01-30 17:44:15 -0800210 // Calculate the compressed o/p buffer size for BWC
Sushil Chauhan466766f2013-07-31 11:21:07 -0700211 uint32_t calcCompressedBufSize(const utils::Whf& destWhf);
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700212
213 /* MdssRot info structure */
214 mdp_overlay mRotInfo;
215 /* MdssRot data structure */
216 msmfb_overlay_data mRotData;
217 /* Orientation */
218 utils::eTransform mOrientation;
219 /* rotator fd */
220 OvFD mFd;
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700221 /* Enable/Disable Mdss Rot*/
222 bool mEnabled;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500223
224 friend Rotator* Rotator::getRotator();
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700225};
Naseer Ahmed29a26812012-06-14 00:56:20 -0700226
Saurabh Shahacf10202013-02-26 10:15:15 -0800227// Holder of rotator objects. Manages lifetimes
228class RotMgr {
229public:
230 //Maximum sessions based on VG pipes, since rotator is used only for videos.
231 //Even though we can have 4 mixer stages, that much may be unnecessary.
232 enum { MAX_ROT_SESS = 3 };
233 RotMgr();
234 ~RotMgr();
235 void configBegin();
236 void configDone();
237 overlay::Rotator *getNext();
238 void clear(); //Removes all instances
239 /* Returns rot dump.
240 * Expects a NULL terminated buffer of big enough size.
241 */
242 void getDump(char *buf, size_t len);
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -0700243 int getRotDevFd();
Saurabh Shah2b6e5192013-10-22 17:22:04 -0700244 int getNumActiveSessions() { return mUseCount; }
Saurabh Shahacf10202013-02-26 10:15:15 -0800245private:
246 overlay::Rotator *mRot[MAX_ROT_SESS];
247 int mUseCount;
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -0700248 int mRotDevFd;
Saurabh Shahacf10202013-02-26 10:15:15 -0800249};
250
251
Naseer Ahmed29a26812012-06-14 00:56:20 -0700252} // overlay
253
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700254#endif // OVERlAY_ROTATOR_H