blob: 118f71f350372d516eb7cdfb54fdb69bf3fef979 [file] [log] [blame]
Naseer Ahmed29a26812012-06-14 00:56:20 -07001/*
Naseer Ahmed758bfc52012-11-28 17:02:08 -05002* Copyright (c) 2011, 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;
58 virtual void setEnable() = 0;
59 virtual void setDisable() = 0;
60 virtual bool enabled () const = 0;
61 virtual uint32_t getSessId() const = 0;
62 virtual bool queueBuffer(int fd, uint32_t offset) = 0;
63 virtual void dump() const = 0;
64 static Rotator *getRotator();
Naseer Ahmed29a26812012-06-14 00:56:20 -070065
Naseer Ahmed758bfc52012-11-28 17:02:08 -050066protected:
67 explicit Rotator() {}
68
69private:
70 /*Returns rotator h/w type */
71 static int getRotatorHwType();
Naseer Ahmed29a26812012-06-14 00:56:20 -070072};
73
Naseer Ahmedf48aef62012-07-20 09:05:53 -070074/*
75 Manages the case where new rotator memory needs to be
76 allocated, before previous is freed, due to resolution change etc. If we make
77 rotator memory to be always max size, irrespctive of source resolution then
78 we don't need this RotMem wrapper. The inner class is sufficient.
79*/
80struct RotMem {
81 // Max rotator memory allocations
82 enum { MAX_ROT_MEM = 2};
83
84 //Manages the rotator buffer offsets.
85 struct Mem {
86 Mem() : mCurrOffset(0) {utils::memset0(mRotOffset); }
87 bool valid() { return m.valid(); }
88 bool close() { return m.close(); }
89 uint32_t size() const { return m.bufSz(); }
90 // Max rotator buffers
91 enum { ROT_NUM_BUFS = 2 };
92 // rotator data info dst offset
93 uint32_t mRotOffset[ROT_NUM_BUFS];
94 // current offset slot from mRotOffset
95 uint32_t mCurrOffset;
96 OvMem m;
97 };
98
99 RotMem() : _curr(0) {}
100 Mem& curr() { return m[_curr % MAX_ROT_MEM]; }
101 const Mem& curr() const { return m[_curr % MAX_ROT_MEM]; }
102 Mem& prev() { return m[(_curr+1) % MAX_ROT_MEM]; }
103 RotMem& operator++() { ++_curr; return *this; }
104 bool close();
105 uint32_t _curr;
106 Mem m[MAX_ROT_MEM];
107};
Naseer Ahmed29a26812012-06-14 00:56:20 -0700108
109/*
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700110* MDP rot holds MDP's rotation related structures.
111*
Naseer Ahmed29a26812012-06-14 00:56:20 -0700112* */
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500113class MdpRot : public Rotator {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700114public:
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500115 virtual ~MdpRot();
116 virtual bool init();
117 virtual bool close();
118 virtual void setSource(const utils::Whf& wfh);
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);
121 virtual void setRotatorUsed(const bool& rotUsed);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500122 virtual bool commit();
123 virtual void setRotations(uint32_t r);
124 virtual void setSrcFB();
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800125 virtual void setDownscale(int ds);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500126 virtual int getDstMemId() const;
127 virtual uint32_t getDstOffset() const;
128 virtual void setEnable();
129 virtual void setDisable();
130 virtual bool enabled () const;
131 virtual uint32_t getSessId() const;
132 virtual bool queueBuffer(int fd, uint32_t offset);
133 virtual void dump() const;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700134
Naseer Ahmed29a26812012-06-14 00:56:20 -0700135private:
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500136 explicit MdpRot();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700137 /* remap rot buffers */
138 bool remap(uint32_t numbufs);
139 bool open_i(uint32_t numbufs, uint32_t bufsz);
140 /* Deferred transform calculations */
141 void doTransform();
142 /* reset underlying data, basically memset 0 */
143 void reset();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700144
Saurabh Shahc23b3802012-08-31 11:11:30 -0700145 /* return true if current rotator config is different
146 * than last known config */
147 bool rotConfChanged() const;
148
149 /* save mRotImgInfo to be last known good config*/
150 void save();
151
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700152 /* rot info*/
153 msm_rotator_img_info mRotImgInfo;
Saurabh Shahc23b3802012-08-31 11:11:30 -0700154 /* Last saved rot info*/
155 msm_rotator_img_info mLSRotImgInfo;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700156 /* rot data */
157 msm_rotator_data_info mRotDataInfo;
158 /* Orientation */
159 utils::eTransform mOrientation;
160 /* rotator fd */
161 OvFD mFd;
162 /* Rotator memory manager */
163 RotMem mMem;
164 /* Single Rotator buffer size */
165 uint32_t mBufSize;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500166
167 friend Rotator* Rotator::getRotator();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700168};
169
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700170/*
171+* MDSS Rot holds MDSS's rotation related structures.
172+*
173+* */
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500174class MdssRot : public Rotator {
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700175public:
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500176 virtual ~MdssRot();
177 virtual bool init();
178 virtual bool close();
179 virtual void setSource(const utils::Whf& wfh);
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700180 virtual void setFlags(const utils::eMdpFlags& flags);
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800181 virtual void setTransform(const utils::eTransform& rot);
182 virtual void setRotatorUsed(const bool& rotUsed);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500183 virtual bool commit();
184 virtual void setRotations(uint32_t r);
185 virtual void setSrcFB();
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800186 virtual void setDownscale(int ds);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500187 virtual int getDstMemId() const;
188 virtual uint32_t getDstOffset() const;
189 virtual void setEnable();
190 virtual void setDisable();
191 virtual bool enabled () const;
192 virtual uint32_t getSessId() const;
193 virtual bool queueBuffer(int fd, uint32_t offset);
194 virtual void dump() const;
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700195
196private:
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500197 explicit MdssRot();
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700198 /* remap rot buffers */
199 bool remap(uint32_t numbufs);
200 bool open_i(uint32_t numbufs, uint32_t bufsz);
201 /* Deferred transform calculations */
202 void doTransform();
203 /* reset underlying data, basically memset 0 */
204 void reset();
Sushil Chauhanfbffad72012-11-06 13:05:42 -0800205 void setBufSize(int format);
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700206
207 /* MdssRot info structure */
208 mdp_overlay mRotInfo;
209 /* MdssRot data structure */
210 msmfb_overlay_data mRotData;
211 /* Orientation */
212 utils::eTransform mOrientation;
213 /* rotator fd */
214 OvFD mFd;
215 /* Rotator memory manager */
216 RotMem mMem;
217 /* Single Rotator buffer size */
218 uint32_t mBufSize;
219 /* Enable/Disable Mdss Rot*/
220 bool mEnabled;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500221
222 friend Rotator* Rotator::getRotator();
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700223};
Naseer Ahmed29a26812012-06-14 00:56:20 -0700224
Naseer Ahmed29a26812012-06-14 00:56:20 -0700225} // overlay
226
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700227#endif // OVERlAY_ROTATOR_H