blob: 9d7f5c8ca50c115f145c85b57a39a7cb184af5c3 [file] [log] [blame]
Naseer Ahmed29a26812012-06-14 00:56:20 -07001/*
Saurabh Shah5daeee52013-01-23 16:52:26 +08002* 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
30#ifndef OVERLAY_H
31#define OVERLAY_H
32
33#include "overlayUtils.h"
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -080034#include "utils/threads.h"
Naseer Ahmed29a26812012-06-14 00:56:20 -070035
Saurabh Shah5daeee52013-01-23 16:52:26 +080036struct MetaData_t;
37
Naseer Ahmed29a26812012-06-14 00:56:20 -070038namespace overlay {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050039class GenericPipe;
40
Naseer Ahmed29a26812012-06-14 00:56:20 -070041class Overlay : utils::NoCopy {
42public:
Saurabh Shah85234ec2013-04-12 17:09:00 -070043 enum { DMA_BLOCK_MODE, DMA_LINE_MODE };
Saurabh Shahc8118ac2013-06-27 10:03:19 -070044 //Abstract Display types. Each backed by a LayerMixer,
45 //represented by a fb node.
46 //High res panels can be backed by 2 layer mixers and a single fb node.
47 enum { DPY_PRIMARY, DPY_EXTERNAL, DPY_WRITEBACK, DPY_UNUSED };
48 enum { DPY_MAX = DPY_UNUSED };
Saurabh Shahaf5f5972013-07-30 13:56:35 -070049 enum { MIXER_LEFT, MIXER_RIGHT, MIXER_UNUSED };
50 enum { MIXER_DEFAULT = MIXER_LEFT, MIXER_MAX = MIXER_UNUSED };
Saurabh Shahc8118ac2013-06-27 10:03:19 -070051 enum { MAX_FB_DEVICES = DPY_MAX };
Saurabh Shah85234ec2013-04-12 17:09:00 -070052
Naseer Ahmed29a26812012-06-14 00:56:20 -070053 /* dtor close */
54 ~Overlay();
55
Naseer Ahmed758bfc52012-11-28 17:02:08 -050056 /* Marks the beginning of a drawing round, resets usage bits on pipes
57 * Should be called when drawing begins before any pipe config is done.
58 */
59 void configBegin();
Naseer Ahmed29a26812012-06-14 00:56:20 -070060
Naseer Ahmed758bfc52012-11-28 17:02:08 -050061 /* Marks the end of config for this drawing round
62 * Will do garbage collection of pipe objects and thus calling UNSETs,
63 * closing FDs, removing rotator objects and memory, if allocated.
64 * Should be called after all pipe configs are done.
65 */
66 void configDone();
Naseer Ahmed29a26812012-06-14 00:56:20 -070067
Naseer Ahmed758bfc52012-11-28 17:02:08 -050068 /* Returns an available pipe based on the type of pipe requested. When ANY
69 * is requested, the first available VG or RGB is returned. If no pipe is
70 * available for the display "dpy" then INV is returned. Note: If a pipe is
71 * assigned to a certain display, then it cannot be assigned to another
Saurabh Shahaf5f5972013-07-30 13:56:35 -070072 * display without being garbage-collected once. To add if a pipe is
73 * asisgned to a mixer within a display it cannot be reused for another
74 * mixer without being UNSET once*/
75 utils::eDest nextPipe(utils::eMdpPipeType, int dpy, int mixer);
Naseer Ahmedf48aef62012-07-20 09:05:53 -070076
Naseer Ahmed758bfc52012-11-28 17:02:08 -050077 void setSource(const utils::PipeArgs args, utils::eDest dest);
78 void setCrop(const utils::Dim& d, utils::eDest dest);
79 void setTransform(const int orientation, utils::eDest dest);
80 void setPosition(const utils::Dim& dim, utils::eDest dest);
Saurabh Shah5daeee52013-01-23 16:52:26 +080081 void setVisualParams(const MetaData_t& data, utils::eDest dest);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050082 bool commit(utils::eDest dest);
83 bool queueBuffer(int fd, uint32_t offset, utils::eDest dest);
Naseer Ahmedf48aef62012-07-20 09:05:53 -070084
Saurabh Shahaf5f5972013-07-30 13:56:35 -070085 /* Returns available ("unallocated") pipes for a display's mixer */
86 int availablePipes(int dpy, int mixer);
Saurabh Shah082468e2013-09-12 10:05:32 -070087 /* Returns available ("unallocated") pipes for a display */
88 int availablePipes(int dpy);
Saurabh Shah90b7b9b2013-09-12 16:36:08 -070089 /* Returns available ("unallocated") pipe of given type for a display */
90 int availablePipes(int dpy, utils::eMdpPipeType type);
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -070091 /* Returns if any of the requested pipe type is attached to any of the
92 * displays
93 */
94 bool isPipeTypeAttached(utils::eMdpPipeType type);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -080095 /* Returns pipe dump. Expects a NULL terminated buffer of big enough size
96 * to populate.
97 */
98 void getDump(char *buf, size_t len);
Sushil Chauhanbd3ea922013-05-15 12:25:26 -070099 /* Reset usage and allocation bits on all pipes for given display */
100 void clear(int dpy);
Saurabh Shah784e9852013-08-21 16:51:21 -0700101 /* Marks the display, whose pipes need to be forcibaly configured */
102 void forceSet(const int& dpy);
103
104 /* Closes open pipes, called during startup */
105 static int initOverlay();
106 /* Returns the singleton instance of overlay */
107 static Overlay* getInstance();
Saurabh Shah85234ec2013-04-12 17:09:00 -0700108 static void setDMAMode(const int& mode);
109 static int getDMAMode();
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700110 /* Returns the framebuffer node backing up the display */
111 static int getFbForDpy(const int& dpy);
112 static bool displayCommit(const int& fd);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700113
114private:
115 /* Ctor setup */
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500116 explicit Overlay();
117 /*Validate index range, abort if invalid */
118 void validate(int index);
119 void dump() const;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700120
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500121 /* Just like a Facebook for pipes, but much less profile info */
122 struct PipeBook {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500123 void init();
124 void destroy();
125 /* Check if pipe exists and return true, false otherwise */
126 bool valid();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700127
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500128 /* Hardware pipe wrapper */
129 GenericPipe *mPipe;
130 /* Display using this pipe. Refer to enums above */
131 int mDisplay;
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700132 /* Mixer within a split display this pipe is attached to */
133 int mMixer;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700134
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500135 /* operations on bitmap */
136 static bool pipeUsageUnchanged();
137 static void setUse(int index);
138 static void resetUse(int index);
139 static bool isUsed(int index);
140 static bool isNotUsed(int index);
141 static void save();
142
143 static void setAllocation(int index);
144 static void resetAllocation(int index);
145 static bool isAllocated(int index);
146 static bool isNotAllocated(int index);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500147
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800148 static utils::eMdpPipeType getPipeType(utils::eDest dest);
149 static const char* getDestStr(utils::eDest dest);
150
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500151 static int NUM_PIPES;
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800152 static utils::eMdpPipeType pipeTypeLUT[utils::OV_MAX];
153
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500154
155 private:
156 //usage tracks if a successful commit happened. So a pipe could be
157 //allocated to a display, but it may not end up using it for various
158 //reasons. If one display actually uses a pipe then it amy not be
159 //used by another display, without an UNSET in between.
160 static int sPipeUsageBitmap;
161 static int sLastUsageBitmap;
162 //Tracks which pipe objects are allocated. This does not imply that they
163 //will actually be used. For example, a display might choose to acquire
164 //3 pipe objects in one shot and proceed with config only if it gets all
165 //3. The bitmap helps allocate different pipe objects on each request.
166 static int sAllocatedBitmap;
167 };
168
169 PipeBook mPipeBook[utils::OV_INVALID]; //Used as max
170
171 /* Dump string */
Saurabh Shah9dc88fc2013-07-15 16:02:30 -0700172 char mDumpStr[1024];
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500173
174 /* Singleton Instance*/
175 static Overlay *sInstance;
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700176 static int sDpyFbMap[DPY_MAX];
Saurabh Shah85234ec2013-04-12 17:09:00 -0700177 static int sDMAMode;
Saurabh Shah784e9852013-08-21 16:51:21 -0700178 static int sForceSetBitmap;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700179};
180
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500181inline void Overlay::validate(int index) {
182 OVASSERT(index >=0 && index < PipeBook::NUM_PIPES, \
183 "%s, Index out of bounds: %d", __FUNCTION__, index);
184 OVASSERT(mPipeBook[index].valid(), "Pipe does not exist %s",
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800185 PipeBook::getDestStr((utils::eDest)index));
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500186}
187
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700188inline int Overlay::availablePipes(int dpy, int mixer) {
189 int avail = 0;
190 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
191 if( (mPipeBook[i].mDisplay == DPY_UNUSED ||
192 mPipeBook[i].mDisplay == dpy) &&
193 (mPipeBook[i].mMixer == MIXER_UNUSED ||
194 mPipeBook[i].mMixer == mixer) &&
195 PipeBook::isNotAllocated(i) &&
196 !(Overlay::getDMAMode() == Overlay::DMA_BLOCK_MODE &&
197 PipeBook::getPipeType((utils::eDest)i) ==
198 utils::OV_MDP_PIPE_DMA)) {
199 avail++;
Jeykumar Sankaranccb44602013-01-03 12:48:22 -0800200 }
201 }
202 return avail;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500203}
204
Saurabh Shah082468e2013-09-12 10:05:32 -0700205inline int Overlay::availablePipes(int dpy) {
206 int avail = 0;
207 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
208 if( (mPipeBook[i].mDisplay == DPY_UNUSED ||
209 mPipeBook[i].mDisplay == dpy) &&
210 PipeBook::isNotAllocated(i) &&
211 !(Overlay::getDMAMode() == Overlay::DMA_BLOCK_MODE &&
212 PipeBook::getPipeType((utils::eDest)i) ==
213 utils::OV_MDP_PIPE_DMA)) {
214 avail++;
215 }
216 }
217 return avail;
218}
219
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700220inline int Overlay::availablePipes(int dpy, utils::eMdpPipeType type) {
221 int avail = 0;
222 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
223 if((mPipeBook[i].mDisplay == DPY_UNUSED ||
224 mPipeBook[i].mDisplay == dpy) &&
225 PipeBook::isNotAllocated(i) &&
226 type == PipeBook::getPipeType((utils::eDest)i)) {
227 avail++;
228 }
229 }
230 return avail;
231}
232
Saurabh Shah85234ec2013-04-12 17:09:00 -0700233inline void Overlay::setDMAMode(const int& mode) {
234 if(mode == DMA_LINE_MODE || mode == DMA_BLOCK_MODE)
235 sDMAMode = mode;
236}
237
238inline int Overlay::getDMAMode() {
239 return sDMAMode;
240}
241
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700242inline int Overlay::getFbForDpy(const int& dpy) {
243 OVASSERT(dpy >= 0 && dpy < DPY_MAX, "Invalid dpy %d", dpy);
244 return sDpyFbMap[dpy];
245}
246
Saurabh Shah784e9852013-08-21 16:51:21 -0700247inline void Overlay::forceSet(const int& dpy) {
248 sForceSetBitmap |= (1 << dpy);
249}
250
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500251inline bool Overlay::PipeBook::valid() {
252 return (mPipe != NULL);
253}
254
255inline bool Overlay::PipeBook::pipeUsageUnchanged() {
256 return (sPipeUsageBitmap == sLastUsageBitmap);
257}
258
259inline void Overlay::PipeBook::setUse(int index) {
260 sPipeUsageBitmap |= (1 << index);
261}
262
263inline void Overlay::PipeBook::resetUse(int index) {
264 sPipeUsageBitmap &= ~(1 << index);
265}
266
267inline bool Overlay::PipeBook::isUsed(int index) {
268 return sPipeUsageBitmap & (1 << index);
269}
270
271inline bool Overlay::PipeBook::isNotUsed(int index) {
272 return !isUsed(index);
273}
274
275inline void Overlay::PipeBook::save() {
276 sLastUsageBitmap = sPipeUsageBitmap;
277}
278
279inline void Overlay::PipeBook::setAllocation(int index) {
280 sAllocatedBitmap |= (1 << index);
281}
282
283inline void Overlay::PipeBook::resetAllocation(int index) {
284 sAllocatedBitmap &= ~(1 << index);
285}
286
287inline bool Overlay::PipeBook::isAllocated(int index) {
288 return sAllocatedBitmap & (1 << index);
289}
290
291inline bool Overlay::PipeBook::isNotAllocated(int index) {
292 return !isAllocated(index);
293}
294
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800295inline utils::eMdpPipeType Overlay::PipeBook::getPipeType(utils::eDest dest) {
296 return pipeTypeLUT[(int)dest];
297}
298
299inline const char* Overlay::PipeBook::getDestStr(utils::eDest dest) {
300 switch(getPipeType(dest)) {
301 case utils::OV_MDP_PIPE_RGB: return "RGB";
302 case utils::OV_MDP_PIPE_VG: return "VG";
303 case utils::OV_MDP_PIPE_DMA: return "DMA";
304 default: return "Invalid";
305 }
306 return "Invalid";
307}
308
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500309}; // overlay
Naseer Ahmed29a26812012-06-14 00:56:20 -0700310
311#endif // OVERLAY_H