blob: 280223c938a3447319f0fbe1eff83a53cd937642 [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 Shah0ceeb6a2013-04-23 10:46:07 -070087 /* Returns if any of the requested pipe type is attached to any of the
88 * displays
89 */
90 bool isPipeTypeAttached(utils::eMdpPipeType type);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -080091 /* Returns pipe dump. Expects a NULL terminated buffer of big enough size
92 * to populate.
93 */
94 void getDump(char *buf, size_t len);
Sushil Chauhanbd3ea922013-05-15 12:25:26 -070095 /* Reset usage and allocation bits on all pipes for given display */
96 void clear(int dpy);
Saurabh Shah784e9852013-08-21 16:51:21 -070097 /* Marks the display, whose pipes need to be forcibaly configured */
98 void forceSet(const int& dpy);
99
100 /* Closes open pipes, called during startup */
101 static int initOverlay();
102 /* Returns the singleton instance of overlay */
103 static Overlay* getInstance();
Saurabh Shah85234ec2013-04-12 17:09:00 -0700104 static void setDMAMode(const int& mode);
105 static int getDMAMode();
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700106 /* Returns the framebuffer node backing up the display */
107 static int getFbForDpy(const int& dpy);
108 static bool displayCommit(const int& fd);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700109
110private:
111 /* Ctor setup */
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500112 explicit Overlay();
113 /*Validate index range, abort if invalid */
114 void validate(int index);
115 void dump() const;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700116
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500117 /* Just like a Facebook for pipes, but much less profile info */
118 struct PipeBook {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500119 void init();
120 void destroy();
121 /* Check if pipe exists and return true, false otherwise */
122 bool valid();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700123
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500124 /* Hardware pipe wrapper */
125 GenericPipe *mPipe;
126 /* Display using this pipe. Refer to enums above */
127 int mDisplay;
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700128 /* Mixer within a split display this pipe is attached to */
129 int mMixer;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700130
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500131 /* operations on bitmap */
132 static bool pipeUsageUnchanged();
133 static void setUse(int index);
134 static void resetUse(int index);
135 static bool isUsed(int index);
136 static bool isNotUsed(int index);
137 static void save();
138
139 static void setAllocation(int index);
140 static void resetAllocation(int index);
141 static bool isAllocated(int index);
142 static bool isNotAllocated(int index);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500143
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800144 static utils::eMdpPipeType getPipeType(utils::eDest dest);
145 static const char* getDestStr(utils::eDest dest);
146
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500147 static int NUM_PIPES;
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800148 static utils::eMdpPipeType pipeTypeLUT[utils::OV_MAX];
149
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500150
151 private:
152 //usage tracks if a successful commit happened. So a pipe could be
153 //allocated to a display, but it may not end up using it for various
154 //reasons. If one display actually uses a pipe then it amy not be
155 //used by another display, without an UNSET in between.
156 static int sPipeUsageBitmap;
157 static int sLastUsageBitmap;
158 //Tracks which pipe objects are allocated. This does not imply that they
159 //will actually be used. For example, a display might choose to acquire
160 //3 pipe objects in one shot and proceed with config only if it gets all
161 //3. The bitmap helps allocate different pipe objects on each request.
162 static int sAllocatedBitmap;
163 };
164
165 PipeBook mPipeBook[utils::OV_INVALID]; //Used as max
166
167 /* Dump string */
Saurabh Shah9dc88fc2013-07-15 16:02:30 -0700168 char mDumpStr[1024];
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500169
170 /* Singleton Instance*/
171 static Overlay *sInstance;
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700172 static int sDpyFbMap[DPY_MAX];
Saurabh Shah85234ec2013-04-12 17:09:00 -0700173 static int sDMAMode;
Saurabh Shah784e9852013-08-21 16:51:21 -0700174 static int sForceSetBitmap;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700175};
176
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500177inline void Overlay::validate(int index) {
178 OVASSERT(index >=0 && index < PipeBook::NUM_PIPES, \
179 "%s, Index out of bounds: %d", __FUNCTION__, index);
180 OVASSERT(mPipeBook[index].valid(), "Pipe does not exist %s",
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800181 PipeBook::getDestStr((utils::eDest)index));
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500182}
183
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700184inline int Overlay::availablePipes(int dpy, int mixer) {
185 int avail = 0;
186 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
187 if( (mPipeBook[i].mDisplay == DPY_UNUSED ||
188 mPipeBook[i].mDisplay == dpy) &&
189 (mPipeBook[i].mMixer == MIXER_UNUSED ||
190 mPipeBook[i].mMixer == mixer) &&
191 PipeBook::isNotAllocated(i) &&
192 !(Overlay::getDMAMode() == Overlay::DMA_BLOCK_MODE &&
193 PipeBook::getPipeType((utils::eDest)i) ==
194 utils::OV_MDP_PIPE_DMA)) {
195 avail++;
Jeykumar Sankaranccb44602013-01-03 12:48:22 -0800196 }
197 }
198 return avail;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500199}
200
Saurabh Shah85234ec2013-04-12 17:09:00 -0700201inline void Overlay::setDMAMode(const int& mode) {
202 if(mode == DMA_LINE_MODE || mode == DMA_BLOCK_MODE)
203 sDMAMode = mode;
204}
205
206inline int Overlay::getDMAMode() {
207 return sDMAMode;
208}
209
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700210inline int Overlay::getFbForDpy(const int& dpy) {
211 OVASSERT(dpy >= 0 && dpy < DPY_MAX, "Invalid dpy %d", dpy);
212 return sDpyFbMap[dpy];
213}
214
Saurabh Shah784e9852013-08-21 16:51:21 -0700215inline void Overlay::forceSet(const int& dpy) {
216 sForceSetBitmap |= (1 << dpy);
217}
218
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500219inline bool Overlay::PipeBook::valid() {
220 return (mPipe != NULL);
221}
222
223inline bool Overlay::PipeBook::pipeUsageUnchanged() {
224 return (sPipeUsageBitmap == sLastUsageBitmap);
225}
226
227inline void Overlay::PipeBook::setUse(int index) {
228 sPipeUsageBitmap |= (1 << index);
229}
230
231inline void Overlay::PipeBook::resetUse(int index) {
232 sPipeUsageBitmap &= ~(1 << index);
233}
234
235inline bool Overlay::PipeBook::isUsed(int index) {
236 return sPipeUsageBitmap & (1 << index);
237}
238
239inline bool Overlay::PipeBook::isNotUsed(int index) {
240 return !isUsed(index);
241}
242
243inline void Overlay::PipeBook::save() {
244 sLastUsageBitmap = sPipeUsageBitmap;
245}
246
247inline void Overlay::PipeBook::setAllocation(int index) {
248 sAllocatedBitmap |= (1 << index);
249}
250
251inline void Overlay::PipeBook::resetAllocation(int index) {
252 sAllocatedBitmap &= ~(1 << index);
253}
254
255inline bool Overlay::PipeBook::isAllocated(int index) {
256 return sAllocatedBitmap & (1 << index);
257}
258
259inline bool Overlay::PipeBook::isNotAllocated(int index) {
260 return !isAllocated(index);
261}
262
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800263inline utils::eMdpPipeType Overlay::PipeBook::getPipeType(utils::eDest dest) {
264 return pipeTypeLUT[(int)dest];
265}
266
267inline const char* Overlay::PipeBook::getDestStr(utils::eDest dest) {
268 switch(getPipeType(dest)) {
269 case utils::OV_MDP_PIPE_RGB: return "RGB";
270 case utils::OV_MDP_PIPE_VG: return "VG";
271 case utils::OV_MDP_PIPE_DMA: return "DMA";
272 default: return "Invalid";
273 }
274 return "Invalid";
275}
276
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500277}; // overlay
Naseer Ahmed29a26812012-06-14 00:56:20 -0700278
279#endif // OVERLAY_H