blob: bf85b700415d78f46c17ff1aefd996c77086e084 [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 };
44
Naseer Ahmed29a26812012-06-14 00:56:20 -070045 /* dtor close */
46 ~Overlay();
47
Naseer Ahmed758bfc52012-11-28 17:02:08 -050048 /* Marks the beginning of a drawing round, resets usage bits on pipes
49 * Should be called when drawing begins before any pipe config is done.
50 */
51 void configBegin();
Naseer Ahmed29a26812012-06-14 00:56:20 -070052
Naseer Ahmed758bfc52012-11-28 17:02:08 -050053 /* Marks the end of config for this drawing round
54 * Will do garbage collection of pipe objects and thus calling UNSETs,
55 * closing FDs, removing rotator objects and memory, if allocated.
56 * Should be called after all pipe configs are done.
57 */
58 void configDone();
Naseer Ahmed29a26812012-06-14 00:56:20 -070059
Naseer Ahmed758bfc52012-11-28 17:02:08 -050060 /* Returns an available pipe based on the type of pipe requested. When ANY
61 * is requested, the first available VG or RGB is returned. If no pipe is
62 * available for the display "dpy" then INV is returned. Note: If a pipe is
63 * assigned to a certain display, then it cannot be assigned to another
64 * display without being garbage-collected once */
65 utils::eDest nextPipe(utils::eMdpPipeType, int dpy);
Naseer Ahmedf48aef62012-07-20 09:05:53 -070066
Naseer Ahmed758bfc52012-11-28 17:02:08 -050067 void setSource(const utils::PipeArgs args, utils::eDest dest);
68 void setCrop(const utils::Dim& d, utils::eDest dest);
69 void setTransform(const int orientation, utils::eDest dest);
70 void setPosition(const utils::Dim& dim, utils::eDest dest);
Saurabh Shah5daeee52013-01-23 16:52:26 +080071 void setVisualParams(const MetaData_t& data, utils::eDest dest);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050072 bool commit(utils::eDest dest);
73 bool queueBuffer(int fd, uint32_t offset, utils::eDest dest);
Naseer Ahmedf48aef62012-07-20 09:05:53 -070074
Naseer Ahmed758bfc52012-11-28 17:02:08 -050075 /* Closes open pipes, called during startup */
Sushil Chauhan07a2c762013-03-06 15:36:49 -080076 static int initOverlay();
Naseer Ahmed758bfc52012-11-28 17:02:08 -050077 /* Returns the singleton instance of overlay */
78 static Overlay* getInstance();
Jeykumar Sankaranccb44602013-01-03 12:48:22 -080079 /* Returns available ("unallocated") pipes for a display */
80 int availablePipes(int dpy);
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -070081 /* Returns if any of the requested pipe type is attached to any of the
82 * displays
83 */
84 bool isPipeTypeAttached(utils::eMdpPipeType type);
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -080085 /* set the framebuffer index for external display */
86 void setExtFbNum(int fbNum);
87 /* Returns framebuffer index of the current external display */
88 int getExtFbNum();
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -080089 /* Returns pipe dump. Expects a NULL terminated buffer of big enough size
90 * to populate.
91 */
92 void getDump(char *buf, size_t len);
Saurabh Shah85234ec2013-04-12 17:09:00 -070093 static void setDMAMode(const int& mode);
94 static int getDMAMode();
Naseer Ahmed29a26812012-06-14 00:56:20 -070095
96private:
97 /* Ctor setup */
Naseer Ahmed758bfc52012-11-28 17:02:08 -050098 explicit Overlay();
99 /*Validate index range, abort if invalid */
100 void validate(int index);
101 void dump() const;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700102
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500103 /* Just like a Facebook for pipes, but much less profile info */
104 struct PipeBook {
105 enum { DPY_PRIMARY, DPY_EXTERNAL, DPY_UNUSED };
Naseer Ahmed29a26812012-06-14 00:56:20 -0700106
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500107 void init();
108 void destroy();
109 /* Check if pipe exists and return true, false otherwise */
110 bool valid();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700111
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500112 /* Hardware pipe wrapper */
113 GenericPipe *mPipe;
114 /* Display using this pipe. Refer to enums above */
115 int mDisplay;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700116
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500117 /* operations on bitmap */
118 static bool pipeUsageUnchanged();
119 static void setUse(int index);
120 static void resetUse(int index);
121 static bool isUsed(int index);
122 static bool isNotUsed(int index);
123 static void save();
124
125 static void setAllocation(int index);
126 static void resetAllocation(int index);
127 static bool isAllocated(int index);
128 static bool isNotAllocated(int index);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500129
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800130 static utils::eMdpPipeType getPipeType(utils::eDest dest);
131 static const char* getDestStr(utils::eDest dest);
132
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500133 static int NUM_PIPES;
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800134 static utils::eMdpPipeType pipeTypeLUT[utils::OV_MAX];
135
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500136
137 private:
138 //usage tracks if a successful commit happened. So a pipe could be
139 //allocated to a display, but it may not end up using it for various
140 //reasons. If one display actually uses a pipe then it amy not be
141 //used by another display, without an UNSET in between.
142 static int sPipeUsageBitmap;
143 static int sLastUsageBitmap;
144 //Tracks which pipe objects are allocated. This does not imply that they
145 //will actually be used. For example, a display might choose to acquire
146 //3 pipe objects in one shot and proceed with config only if it gets all
147 //3. The bitmap helps allocate different pipe objects on each request.
148 static int sAllocatedBitmap;
149 };
150
151 PipeBook mPipeBook[utils::OV_INVALID]; //Used as max
152
153 /* Dump string */
154 char mDumpStr[256];
155
156 /* Singleton Instance*/
157 static Overlay *sInstance;
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -0800158 static int sExtFbIndex;
Saurabh Shah85234ec2013-04-12 17:09:00 -0700159 static int sDMAMode;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700160};
161
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500162inline void Overlay::validate(int index) {
163 OVASSERT(index >=0 && index < PipeBook::NUM_PIPES, \
164 "%s, Index out of bounds: %d", __FUNCTION__, index);
165 OVASSERT(mPipeBook[index].valid(), "Pipe does not exist %s",
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800166 PipeBook::getDestStr((utils::eDest)index));
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500167}
168
Jeykumar Sankaranccb44602013-01-03 12:48:22 -0800169inline int Overlay::availablePipes(int dpy) {
170 int avail = 0;
171 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
172 if((mPipeBook[i].mDisplay == PipeBook::DPY_UNUSED ||
173 mPipeBook[i].mDisplay == dpy) && PipeBook::isNotAllocated(i)) {
174 avail++;
175 }
176 }
177 return avail;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500178}
179
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -0800180inline void Overlay::setExtFbNum(int fbNum) {
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -0800181 sExtFbIndex = fbNum;
182}
183
184inline int Overlay::getExtFbNum() {
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -0800185 return sExtFbIndex;
186}
187
Saurabh Shah85234ec2013-04-12 17:09:00 -0700188inline void Overlay::setDMAMode(const int& mode) {
189 if(mode == DMA_LINE_MODE || mode == DMA_BLOCK_MODE)
190 sDMAMode = mode;
191}
192
193inline int Overlay::getDMAMode() {
194 return sDMAMode;
195}
196
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500197inline bool Overlay::PipeBook::valid() {
198 return (mPipe != NULL);
199}
200
201inline bool Overlay::PipeBook::pipeUsageUnchanged() {
202 return (sPipeUsageBitmap == sLastUsageBitmap);
203}
204
205inline void Overlay::PipeBook::setUse(int index) {
206 sPipeUsageBitmap |= (1 << index);
207}
208
209inline void Overlay::PipeBook::resetUse(int index) {
210 sPipeUsageBitmap &= ~(1 << index);
211}
212
213inline bool Overlay::PipeBook::isUsed(int index) {
214 return sPipeUsageBitmap & (1 << index);
215}
216
217inline bool Overlay::PipeBook::isNotUsed(int index) {
218 return !isUsed(index);
219}
220
221inline void Overlay::PipeBook::save() {
222 sLastUsageBitmap = sPipeUsageBitmap;
223}
224
225inline void Overlay::PipeBook::setAllocation(int index) {
226 sAllocatedBitmap |= (1 << index);
227}
228
229inline void Overlay::PipeBook::resetAllocation(int index) {
230 sAllocatedBitmap &= ~(1 << index);
231}
232
233inline bool Overlay::PipeBook::isAllocated(int index) {
234 return sAllocatedBitmap & (1 << index);
235}
236
237inline bool Overlay::PipeBook::isNotAllocated(int index) {
238 return !isAllocated(index);
239}
240
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800241inline utils::eMdpPipeType Overlay::PipeBook::getPipeType(utils::eDest dest) {
242 return pipeTypeLUT[(int)dest];
243}
244
245inline const char* Overlay::PipeBook::getDestStr(utils::eDest dest) {
246 switch(getPipeType(dest)) {
247 case utils::OV_MDP_PIPE_RGB: return "RGB";
248 case utils::OV_MDP_PIPE_VG: return "VG";
249 case utils::OV_MDP_PIPE_DMA: return "DMA";
250 default: return "Invalid";
251 }
252 return "Invalid";
253}
254
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500255}; // overlay
Naseer Ahmed29a26812012-06-14 00:56:20 -0700256
257#endif // OVERLAY_H