blob: 295e12399f6bfe21d522dfb526acd1fdad7333e2 [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);
Sushil Chauhan897a9c32013-07-18 11:09:55 -070079 void setColor(const uint32_t color, utils::eDest dest);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050080 void setTransform(const int orientation, utils::eDest dest);
81 void setPosition(const utils::Dim& dim, utils::eDest dest);
Saurabh Shah5daeee52013-01-23 16:52:26 +080082 void setVisualParams(const MetaData_t& data, utils::eDest dest);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050083 bool commit(utils::eDest dest);
84 bool queueBuffer(int fd, uint32_t offset, utils::eDest dest);
Naseer Ahmedf48aef62012-07-20 09:05:53 -070085
Saurabh Shahaf5f5972013-07-30 13:56:35 -070086 /* Returns available ("unallocated") pipes for a display's mixer */
87 int availablePipes(int dpy, int mixer);
Saurabh Shah082468e2013-09-12 10:05:32 -070088 /* Returns available ("unallocated") pipes for a display */
89 int availablePipes(int dpy);
Saurabh Shah90b7b9b2013-09-12 16:36:08 -070090 /* Returns available ("unallocated") pipe of given type for a display */
91 int availablePipes(int dpy, utils::eMdpPipeType type);
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -070092 /* Returns if any of the requested pipe type is attached to any of the
93 * displays
94 */
95 bool isPipeTypeAttached(utils::eMdpPipeType type);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -080096 /* Returns pipe dump. Expects a NULL terminated buffer of big enough size
97 * to populate.
98 */
99 void getDump(char *buf, size_t len);
Sushil Chauhanbd3ea922013-05-15 12:25:26 -0700100 /* Reset usage and allocation bits on all pipes for given display */
101 void clear(int dpy);
Saurabh Shah784e9852013-08-21 16:51:21 -0700102 /* Marks the display, whose pipes need to be forcibaly configured */
103 void forceSet(const int& dpy);
104
105 /* Closes open pipes, called during startup */
106 static int initOverlay();
107 /* Returns the singleton instance of overlay */
108 static Overlay* getInstance();
Saurabh Shah85234ec2013-04-12 17:09:00 -0700109 static void setDMAMode(const int& mode);
110 static int getDMAMode();
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700111 /* Returns the framebuffer node backing up the display */
112 static int getFbForDpy(const int& dpy);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700113 static bool displayCommit(const int& fd, const utils::Dim& roi);
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700114 static bool displayCommit(const int& fd);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700115
116private:
117 /* Ctor setup */
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500118 explicit Overlay();
119 /*Validate index range, abort if invalid */
120 void validate(int index);
121 void dump() const;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700122
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500123 /* Just like a Facebook for pipes, but much less profile info */
124 struct PipeBook {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500125 void init();
126 void destroy();
127 /* Check if pipe exists and return true, false otherwise */
128 bool valid();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700129
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500130 /* Hardware pipe wrapper */
131 GenericPipe *mPipe;
132 /* Display using this pipe. Refer to enums above */
133 int mDisplay;
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700134 /* Mixer within a split display this pipe is attached to */
135 int mMixer;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700136
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500137 /* operations on bitmap */
138 static bool pipeUsageUnchanged();
139 static void setUse(int index);
140 static void resetUse(int index);
141 static bool isUsed(int index);
142 static bool isNotUsed(int index);
143 static void save();
144
145 static void setAllocation(int index);
146 static void resetAllocation(int index);
147 static bool isAllocated(int index);
148 static bool isNotAllocated(int index);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500149
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800150 static utils::eMdpPipeType getPipeType(utils::eDest dest);
151 static const char* getDestStr(utils::eDest dest);
152
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500153 static int NUM_PIPES;
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800154 static utils::eMdpPipeType pipeTypeLUT[utils::OV_MAX];
155
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500156
157 private:
158 //usage tracks if a successful commit happened. So a pipe could be
159 //allocated to a display, but it may not end up using it for various
160 //reasons. If one display actually uses a pipe then it amy not be
161 //used by another display, without an UNSET in between.
162 static int sPipeUsageBitmap;
163 static int sLastUsageBitmap;
164 //Tracks which pipe objects are allocated. This does not imply that they
165 //will actually be used. For example, a display might choose to acquire
166 //3 pipe objects in one shot and proceed with config only if it gets all
167 //3. The bitmap helps allocate different pipe objects on each request.
168 static int sAllocatedBitmap;
169 };
170
171 PipeBook mPipeBook[utils::OV_INVALID]; //Used as max
172
173 /* Dump string */
Saurabh Shah9dc88fc2013-07-15 16:02:30 -0700174 char mDumpStr[1024];
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500175
176 /* Singleton Instance*/
177 static Overlay *sInstance;
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700178 static int sDpyFbMap[DPY_MAX];
Saurabh Shah85234ec2013-04-12 17:09:00 -0700179 static int sDMAMode;
Saurabh Shah784e9852013-08-21 16:51:21 -0700180 static int sForceSetBitmap;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700181};
182
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500183inline void Overlay::validate(int index) {
184 OVASSERT(index >=0 && index < PipeBook::NUM_PIPES, \
185 "%s, Index out of bounds: %d", __FUNCTION__, index);
186 OVASSERT(mPipeBook[index].valid(), "Pipe does not exist %s",
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800187 PipeBook::getDestStr((utils::eDest)index));
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500188}
189
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700190inline int Overlay::availablePipes(int dpy, int mixer) {
191 int avail = 0;
192 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
193 if( (mPipeBook[i].mDisplay == DPY_UNUSED ||
194 mPipeBook[i].mDisplay == dpy) &&
195 (mPipeBook[i].mMixer == MIXER_UNUSED ||
196 mPipeBook[i].mMixer == mixer) &&
197 PipeBook::isNotAllocated(i) &&
198 !(Overlay::getDMAMode() == Overlay::DMA_BLOCK_MODE &&
199 PipeBook::getPipeType((utils::eDest)i) ==
200 utils::OV_MDP_PIPE_DMA)) {
201 avail++;
Jeykumar Sankaranccb44602013-01-03 12:48:22 -0800202 }
203 }
204 return avail;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500205}
206
Saurabh Shah082468e2013-09-12 10:05:32 -0700207inline int Overlay::availablePipes(int dpy) {
208 int avail = 0;
209 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
210 if( (mPipeBook[i].mDisplay == DPY_UNUSED ||
211 mPipeBook[i].mDisplay == dpy) &&
212 PipeBook::isNotAllocated(i) &&
213 !(Overlay::getDMAMode() == Overlay::DMA_BLOCK_MODE &&
214 PipeBook::getPipeType((utils::eDest)i) ==
215 utils::OV_MDP_PIPE_DMA)) {
216 avail++;
217 }
218 }
219 return avail;
220}
221
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700222inline int Overlay::availablePipes(int dpy, utils::eMdpPipeType type) {
223 int avail = 0;
224 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
225 if((mPipeBook[i].mDisplay == DPY_UNUSED ||
226 mPipeBook[i].mDisplay == dpy) &&
227 PipeBook::isNotAllocated(i) &&
228 type == PipeBook::getPipeType((utils::eDest)i)) {
229 avail++;
230 }
231 }
232 return avail;
233}
234
Saurabh Shah85234ec2013-04-12 17:09:00 -0700235inline void Overlay::setDMAMode(const int& mode) {
236 if(mode == DMA_LINE_MODE || mode == DMA_BLOCK_MODE)
237 sDMAMode = mode;
238}
239
240inline int Overlay::getDMAMode() {
241 return sDMAMode;
242}
243
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700244inline int Overlay::getFbForDpy(const int& dpy) {
245 OVASSERT(dpy >= 0 && dpy < DPY_MAX, "Invalid dpy %d", dpy);
246 return sDpyFbMap[dpy];
247}
248
Saurabh Shah784e9852013-08-21 16:51:21 -0700249inline void Overlay::forceSet(const int& dpy) {
250 sForceSetBitmap |= (1 << dpy);
251}
252
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500253inline bool Overlay::PipeBook::valid() {
254 return (mPipe != NULL);
255}
256
257inline bool Overlay::PipeBook::pipeUsageUnchanged() {
258 return (sPipeUsageBitmap == sLastUsageBitmap);
259}
260
261inline void Overlay::PipeBook::setUse(int index) {
262 sPipeUsageBitmap |= (1 << index);
263}
264
265inline void Overlay::PipeBook::resetUse(int index) {
266 sPipeUsageBitmap &= ~(1 << index);
267}
268
269inline bool Overlay::PipeBook::isUsed(int index) {
270 return sPipeUsageBitmap & (1 << index);
271}
272
273inline bool Overlay::PipeBook::isNotUsed(int index) {
274 return !isUsed(index);
275}
276
277inline void Overlay::PipeBook::save() {
278 sLastUsageBitmap = sPipeUsageBitmap;
279}
280
281inline void Overlay::PipeBook::setAllocation(int index) {
282 sAllocatedBitmap |= (1 << index);
283}
284
285inline void Overlay::PipeBook::resetAllocation(int index) {
286 sAllocatedBitmap &= ~(1 << index);
287}
288
289inline bool Overlay::PipeBook::isAllocated(int index) {
290 return sAllocatedBitmap & (1 << index);
291}
292
293inline bool Overlay::PipeBook::isNotAllocated(int index) {
294 return !isAllocated(index);
295}
296
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800297inline utils::eMdpPipeType Overlay::PipeBook::getPipeType(utils::eDest dest) {
298 return pipeTypeLUT[(int)dest];
299}
300
301inline const char* Overlay::PipeBook::getDestStr(utils::eDest dest) {
302 switch(getPipeType(dest)) {
303 case utils::OV_MDP_PIPE_RGB: return "RGB";
304 case utils::OV_MDP_PIPE_VG: return "VG";
305 case utils::OV_MDP_PIPE_DMA: return "DMA";
306 default: return "Invalid";
307 }
308 return "Invalid";
309}
310
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500311}; // overlay
Naseer Ahmed29a26812012-06-14 00:56:20 -0700312
313#endif // OVERLAY_H