blob: 4b91038467577413919482a5c8b4865d8897c970 [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 Shah0ceeb6a2013-04-23 10:46:07 -070089 /* Returns if any of the requested pipe type is attached to any of the
90 * displays
91 */
92 bool isPipeTypeAttached(utils::eMdpPipeType type);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -080093 /* Returns pipe dump. Expects a NULL terminated buffer of big enough size
94 * to populate.
95 */
96 void getDump(char *buf, size_t len);
Sushil Chauhanbd3ea922013-05-15 12:25:26 -070097 /* Reset usage and allocation bits on all pipes for given display */
98 void clear(int dpy);
Saurabh Shah784e9852013-08-21 16:51:21 -070099 /* Marks the display, whose pipes need to be forcibaly configured */
100 void forceSet(const int& dpy);
101
102 /* Closes open pipes, called during startup */
103 static int initOverlay();
104 /* Returns the singleton instance of overlay */
105 static Overlay* getInstance();
Saurabh Shah85234ec2013-04-12 17:09:00 -0700106 static void setDMAMode(const int& mode);
107 static int getDMAMode();
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700108 /* Returns the framebuffer node backing up the display */
109 static int getFbForDpy(const int& dpy);
110 static bool displayCommit(const int& fd);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700111
112private:
113 /* Ctor setup */
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500114 explicit Overlay();
115 /*Validate index range, abort if invalid */
116 void validate(int index);
117 void dump() const;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700118
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500119 /* Just like a Facebook for pipes, but much less profile info */
120 struct PipeBook {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500121 void init();
122 void destroy();
123 /* Check if pipe exists and return true, false otherwise */
124 bool valid();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700125
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500126 /* Hardware pipe wrapper */
127 GenericPipe *mPipe;
128 /* Display using this pipe. Refer to enums above */
129 int mDisplay;
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700130 /* Mixer within a split display this pipe is attached to */
131 int mMixer;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700132
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500133 /* operations on bitmap */
134 static bool pipeUsageUnchanged();
135 static void setUse(int index);
136 static void resetUse(int index);
137 static bool isUsed(int index);
138 static bool isNotUsed(int index);
139 static void save();
140
141 static void setAllocation(int index);
142 static void resetAllocation(int index);
143 static bool isAllocated(int index);
144 static bool isNotAllocated(int index);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500145
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800146 static utils::eMdpPipeType getPipeType(utils::eDest dest);
147 static const char* getDestStr(utils::eDest dest);
148
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500149 static int NUM_PIPES;
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800150 static utils::eMdpPipeType pipeTypeLUT[utils::OV_MAX];
151
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500152
153 private:
154 //usage tracks if a successful commit happened. So a pipe could be
155 //allocated to a display, but it may not end up using it for various
156 //reasons. If one display actually uses a pipe then it amy not be
157 //used by another display, without an UNSET in between.
158 static int sPipeUsageBitmap;
159 static int sLastUsageBitmap;
160 //Tracks which pipe objects are allocated. This does not imply that they
161 //will actually be used. For example, a display might choose to acquire
162 //3 pipe objects in one shot and proceed with config only if it gets all
163 //3. The bitmap helps allocate different pipe objects on each request.
164 static int sAllocatedBitmap;
165 };
166
167 PipeBook mPipeBook[utils::OV_INVALID]; //Used as max
168
169 /* Dump string */
Saurabh Shah9dc88fc2013-07-15 16:02:30 -0700170 char mDumpStr[1024];
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500171
172 /* Singleton Instance*/
173 static Overlay *sInstance;
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700174 static int sDpyFbMap[DPY_MAX];
Saurabh Shah85234ec2013-04-12 17:09:00 -0700175 static int sDMAMode;
Saurabh Shah784e9852013-08-21 16:51:21 -0700176 static int sForceSetBitmap;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700177};
178
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500179inline void Overlay::validate(int index) {
180 OVASSERT(index >=0 && index < PipeBook::NUM_PIPES, \
181 "%s, Index out of bounds: %d", __FUNCTION__, index);
182 OVASSERT(mPipeBook[index].valid(), "Pipe does not exist %s",
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800183 PipeBook::getDestStr((utils::eDest)index));
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500184}
185
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700186inline int Overlay::availablePipes(int dpy, int mixer) {
187 int avail = 0;
188 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
189 if( (mPipeBook[i].mDisplay == DPY_UNUSED ||
190 mPipeBook[i].mDisplay == dpy) &&
191 (mPipeBook[i].mMixer == MIXER_UNUSED ||
192 mPipeBook[i].mMixer == mixer) &&
193 PipeBook::isNotAllocated(i) &&
194 !(Overlay::getDMAMode() == Overlay::DMA_BLOCK_MODE &&
195 PipeBook::getPipeType((utils::eDest)i) ==
196 utils::OV_MDP_PIPE_DMA)) {
197 avail++;
Jeykumar Sankaranccb44602013-01-03 12:48:22 -0800198 }
199 }
200 return avail;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500201}
202
Saurabh Shah082468e2013-09-12 10:05:32 -0700203inline int Overlay::availablePipes(int dpy) {
204 int avail = 0;
205 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
206 if( (mPipeBook[i].mDisplay == DPY_UNUSED ||
207 mPipeBook[i].mDisplay == dpy) &&
208 PipeBook::isNotAllocated(i) &&
209 !(Overlay::getDMAMode() == Overlay::DMA_BLOCK_MODE &&
210 PipeBook::getPipeType((utils::eDest)i) ==
211 utils::OV_MDP_PIPE_DMA)) {
212 avail++;
213 }
214 }
215 return avail;
216}
217
Saurabh Shah85234ec2013-04-12 17:09:00 -0700218inline void Overlay::setDMAMode(const int& mode) {
219 if(mode == DMA_LINE_MODE || mode == DMA_BLOCK_MODE)
220 sDMAMode = mode;
221}
222
223inline int Overlay::getDMAMode() {
224 return sDMAMode;
225}
226
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700227inline int Overlay::getFbForDpy(const int& dpy) {
228 OVASSERT(dpy >= 0 && dpy < DPY_MAX, "Invalid dpy %d", dpy);
229 return sDpyFbMap[dpy];
230}
231
Saurabh Shah784e9852013-08-21 16:51:21 -0700232inline void Overlay::forceSet(const int& dpy) {
233 sForceSetBitmap |= (1 << dpy);
234}
235
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500236inline bool Overlay::PipeBook::valid() {
237 return (mPipe != NULL);
238}
239
240inline bool Overlay::PipeBook::pipeUsageUnchanged() {
241 return (sPipeUsageBitmap == sLastUsageBitmap);
242}
243
244inline void Overlay::PipeBook::setUse(int index) {
245 sPipeUsageBitmap |= (1 << index);
246}
247
248inline void Overlay::PipeBook::resetUse(int index) {
249 sPipeUsageBitmap &= ~(1 << index);
250}
251
252inline bool Overlay::PipeBook::isUsed(int index) {
253 return sPipeUsageBitmap & (1 << index);
254}
255
256inline bool Overlay::PipeBook::isNotUsed(int index) {
257 return !isUsed(index);
258}
259
260inline void Overlay::PipeBook::save() {
261 sLastUsageBitmap = sPipeUsageBitmap;
262}
263
264inline void Overlay::PipeBook::setAllocation(int index) {
265 sAllocatedBitmap |= (1 << index);
266}
267
268inline void Overlay::PipeBook::resetAllocation(int index) {
269 sAllocatedBitmap &= ~(1 << index);
270}
271
272inline bool Overlay::PipeBook::isAllocated(int index) {
273 return sAllocatedBitmap & (1 << index);
274}
275
276inline bool Overlay::PipeBook::isNotAllocated(int index) {
277 return !isAllocated(index);
278}
279
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800280inline utils::eMdpPipeType Overlay::PipeBook::getPipeType(utils::eDest dest) {
281 return pipeTypeLUT[(int)dest];
282}
283
284inline const char* Overlay::PipeBook::getDestStr(utils::eDest dest) {
285 switch(getPipeType(dest)) {
286 case utils::OV_MDP_PIPE_RGB: return "RGB";
287 case utils::OV_MDP_PIPE_VG: return "VG";
288 case utils::OV_MDP_PIPE_DMA: return "DMA";
289 default: return "Invalid";
290 }
291 return "Invalid";
292}
293
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500294}; // overlay
Naseer Ahmed29a26812012-06-14 00:56:20 -0700295
296#endif // OVERLAY_H