blob: bd2fd7eb1988bdc901cb0d4e821459de29e0cb76 [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 bool init() = 0;
47 virtual bool close() = 0;
48 virtual void setSource(const utils::Whf& wfh) = 0;
49 virtual void setFlags(const utils::eMdpFlags& flags) = 0;
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -080050 virtual void setTransform(const utils::eTransform& rot) = 0;
51 virtual void setRotatorUsed(const bool& rotUsed) = 0;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050052 virtual bool commit() = 0;
53 virtual void setRotations(uint32_t r) = 0;
54 virtual void setSrcFB() = 0;
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -080055 virtual void setDownscale(int ds) = 0;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050056 virtual int getDstMemId() const = 0;
57 virtual uint32_t getDstOffset() const = 0;
Raj kamal23f69b22012-11-17 00:20:55 +053058 virtual uint32_t getDstFormat() const = 0;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050059 virtual void setEnable() = 0;
60 virtual void setDisable() = 0;
61 virtual bool enabled () const = 0;
62 virtual uint32_t getSessId() const = 0;
63 virtual bool queueBuffer(int fd, uint32_t offset) = 0;
64 virtual void dump() const = 0;
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -080065 virtual void getDump(char *buf, size_t len) const = 0;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050066 static Rotator *getRotator();
Naseer Ahmed29a26812012-06-14 00:56:20 -070067
Naseer Ahmed758bfc52012-11-28 17:02:08 -050068protected:
69 explicit Rotator() {}
Saurabh Shahfc3652f2013-02-15 13:15:45 -080070 static uint32_t calcOutputBufSize(const utils::Whf& destWhf);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050071
72private:
73 /*Returns rotator h/w type */
74 static int getRotatorHwType();
Naseer Ahmed29a26812012-06-14 00:56:20 -070075};
76
Naseer Ahmedf48aef62012-07-20 09:05:53 -070077/*
78 Manages the case where new rotator memory needs to be
79 allocated, before previous is freed, due to resolution change etc. If we make
80 rotator memory to be always max size, irrespctive of source resolution then
81 we don't need this RotMem wrapper. The inner class is sufficient.
82*/
83struct RotMem {
84 // Max rotator memory allocations
85 enum { MAX_ROT_MEM = 2};
86
87 //Manages the rotator buffer offsets.
88 struct Mem {
89 Mem() : mCurrOffset(0) {utils::memset0(mRotOffset); }
90 bool valid() { return m.valid(); }
91 bool close() { return m.close(); }
92 uint32_t size() const { return m.bufSz(); }
93 // Max rotator buffers
94 enum { ROT_NUM_BUFS = 2 };
95 // rotator data info dst offset
96 uint32_t mRotOffset[ROT_NUM_BUFS];
97 // current offset slot from mRotOffset
98 uint32_t mCurrOffset;
99 OvMem m;
100 };
101
102 RotMem() : _curr(0) {}
103 Mem& curr() { return m[_curr % MAX_ROT_MEM]; }
104 const Mem& curr() const { return m[_curr % MAX_ROT_MEM]; }
105 Mem& prev() { return m[(_curr+1) % MAX_ROT_MEM]; }
106 RotMem& operator++() { ++_curr; return *this; }
107 bool close();
108 uint32_t _curr;
109 Mem m[MAX_ROT_MEM];
110};
Naseer Ahmed29a26812012-06-14 00:56:20 -0700111
112/*
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700113* MDP rot holds MDP's rotation related structures.
114*
Naseer Ahmed29a26812012-06-14 00:56:20 -0700115* */
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500116class MdpRot : public Rotator {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700117public:
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500118 virtual ~MdpRot();
119 virtual bool init();
120 virtual bool close();
121 virtual void setSource(const utils::Whf& wfh);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700122 virtual void setFlags(const utils::eMdpFlags& flags);
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800123 virtual void setTransform(const utils::eTransform& rot);
124 virtual void setRotatorUsed(const bool& rotUsed);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500125 virtual bool commit();
126 virtual void setRotations(uint32_t r);
127 virtual void setSrcFB();
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 void setEnable();
133 virtual void setDisable();
134 virtual bool enabled () const;
135 virtual uint32_t getSessId() const;
136 virtual bool queueBuffer(int fd, uint32_t offset);
137 virtual void dump() const;
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800138 virtual void getDump(char *buf, size_t len) const;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700139
Naseer Ahmed29a26812012-06-14 00:56:20 -0700140private:
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500141 explicit MdpRot();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700142 /* remap rot buffers */
143 bool remap(uint32_t numbufs);
144 bool open_i(uint32_t numbufs, uint32_t bufsz);
145 /* Deferred transform calculations */
146 void doTransform();
147 /* reset underlying data, basically memset 0 */
148 void reset();
Saurabh Shahc23b3802012-08-31 11:11:30 -0700149 /* return true if current rotator config is different
150 * than last known config */
151 bool rotConfChanged() const;
Saurabh Shahc23b3802012-08-31 11:11:30 -0700152 /* save mRotImgInfo to be last known good config*/
153 void save();
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800154 /* Calculates the rotator's o/p buffer size post the transform calcs and
155 * knowing the o/p format depending on whether fastYuv is enabled or not */
156 uint32_t calcOutputBufSize();
Saurabh Shahc23b3802012-08-31 11:11:30 -0700157
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700158 /* rot info*/
159 msm_rotator_img_info mRotImgInfo;
Saurabh Shahc23b3802012-08-31 11:11:30 -0700160 /* Last saved rot info*/
161 msm_rotator_img_info mLSRotImgInfo;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700162 /* rot data */
163 msm_rotator_data_info mRotDataInfo;
164 /* Orientation */
165 utils::eTransform mOrientation;
166 /* rotator fd */
167 OvFD mFd;
168 /* Rotator memory manager */
169 RotMem mMem;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500170
171 friend Rotator* Rotator::getRotator();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700172};
173
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700174/*
175+* MDSS Rot holds MDSS's rotation related structures.
176+*
177+* */
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500178class MdssRot : public Rotator {
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700179public:
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500180 virtual ~MdssRot();
181 virtual bool init();
182 virtual bool close();
183 virtual void setSource(const utils::Whf& wfh);
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700184 virtual void setFlags(const utils::eMdpFlags& flags);
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800185 virtual void setTransform(const utils::eTransform& rot);
186 virtual void setRotatorUsed(const bool& rotUsed);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500187 virtual bool commit();
188 virtual void setRotations(uint32_t r);
189 virtual void setSrcFB();
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800190 virtual void setDownscale(int ds);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500191 virtual int getDstMemId() const;
192 virtual uint32_t getDstOffset() const;
Raj kamal23f69b22012-11-17 00:20:55 +0530193 virtual uint32_t getDstFormat() const;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500194 virtual void setEnable();
195 virtual void setDisable();
196 virtual bool enabled () const;
197 virtual uint32_t getSessId() const;
198 virtual bool queueBuffer(int fd, uint32_t offset);
199 virtual void dump() const;
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800200 virtual void getDump(char *buf, size_t len) const;
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700201
202private:
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500203 explicit MdssRot();
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700204 /* remap rot buffers */
205 bool remap(uint32_t numbufs);
206 bool open_i(uint32_t numbufs, uint32_t bufsz);
207 /* Deferred transform calculations */
208 void doTransform();
209 /* reset underlying data, basically memset 0 */
210 void reset();
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800211 /* Calculates the rotator's o/p buffer size post the transform calcs and
212 * knowing the o/p format depending on whether fastYuv is enabled or not */
213 uint32_t calcOutputBufSize();
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700214
215 /* MdssRot info structure */
216 mdp_overlay mRotInfo;
217 /* MdssRot data structure */
218 msmfb_overlay_data mRotData;
219 /* Orientation */
220 utils::eTransform mOrientation;
221 /* rotator fd */
222 OvFD mFd;
223 /* Rotator memory manager */
224 RotMem mMem;
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700225 /* Enable/Disable Mdss Rot*/
226 bool mEnabled;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500227
228 friend Rotator* Rotator::getRotator();
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700229};
Naseer Ahmed29a26812012-06-14 00:56:20 -0700230
Naseer Ahmed29a26812012-06-14 00:56:20 -0700231} // overlay
232
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700233#endif // OVERlAY_ROTATOR_H