blob: 854fa3065d6c28206f8edfa056189bc675899845 [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;
Saurabh Shahb8f58e22013-09-26 16:20:07 -070037namespace scale {
38class Scale;
39};
Saurabh Shah5daeee52013-01-23 16:52:26 +080040
Naseer Ahmed29a26812012-06-14 00:56:20 -070041namespace overlay {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050042class GenericPipe;
43
Naseer Ahmed29a26812012-06-14 00:56:20 -070044class Overlay : utils::NoCopy {
45public:
Saurabh Shah85234ec2013-04-12 17:09:00 -070046 enum { DMA_BLOCK_MODE, DMA_LINE_MODE };
Saurabh Shahc8118ac2013-06-27 10:03:19 -070047 //Abstract Display types. Each backed by a LayerMixer,
48 //represented by a fb node.
49 //High res panels can be backed by 2 layer mixers and a single fb node.
50 enum { DPY_PRIMARY, DPY_EXTERNAL, DPY_WRITEBACK, DPY_UNUSED };
51 enum { DPY_MAX = DPY_UNUSED };
Saurabh Shahaf5f5972013-07-30 13:56:35 -070052 enum { MIXER_LEFT, MIXER_RIGHT, MIXER_UNUSED };
53 enum { MIXER_DEFAULT = MIXER_LEFT, MIXER_MAX = MIXER_UNUSED };
Saurabh Shahc8118ac2013-06-27 10:03:19 -070054 enum { MAX_FB_DEVICES = DPY_MAX };
Saurabh Shah85234ec2013-04-12 17:09:00 -070055
Naseer Ahmed29a26812012-06-14 00:56:20 -070056 /* dtor close */
57 ~Overlay();
58
Naseer Ahmed758bfc52012-11-28 17:02:08 -050059 /* Marks the beginning of a drawing round, resets usage bits on pipes
60 * Should be called when drawing begins before any pipe config is done.
61 */
62 void configBegin();
Naseer Ahmed29a26812012-06-14 00:56:20 -070063
Naseer Ahmed758bfc52012-11-28 17:02:08 -050064 /* Marks the end of config for this drawing round
65 * Will do garbage collection of pipe objects and thus calling UNSETs,
66 * closing FDs, removing rotator objects and memory, if allocated.
67 * Should be called after all pipe configs are done.
68 */
69 void configDone();
Naseer Ahmed29a26812012-06-14 00:56:20 -070070
Naseer Ahmed758bfc52012-11-28 17:02:08 -050071 /* Returns an available pipe based on the type of pipe requested. When ANY
72 * is requested, the first available VG or RGB is returned. If no pipe is
73 * available for the display "dpy" then INV is returned. Note: If a pipe is
74 * assigned to a certain display, then it cannot be assigned to another
Saurabh Shahaf5f5972013-07-30 13:56:35 -070075 * display without being garbage-collected once. To add if a pipe is
76 * asisgned to a mixer within a display it cannot be reused for another
77 * mixer without being UNSET once*/
78 utils::eDest nextPipe(utils::eMdpPipeType, int dpy, int mixer);
Naseer Ahmedf48aef62012-07-20 09:05:53 -070079
Naseer Ahmed758bfc52012-11-28 17:02:08 -050080 void setSource(const utils::PipeArgs args, utils::eDest dest);
81 void setCrop(const utils::Dim& d, utils::eDest dest);
82 void setTransform(const int orientation, utils::eDest dest);
83 void setPosition(const utils::Dim& dim, utils::eDest dest);
Saurabh Shah5daeee52013-01-23 16:52:26 +080084 void setVisualParams(const MetaData_t& data, utils::eDest dest);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050085 bool commit(utils::eDest dest);
86 bool queueBuffer(int fd, uint32_t offset, utils::eDest dest);
Naseer Ahmedf48aef62012-07-20 09:05:53 -070087
Saurabh Shahaf5f5972013-07-30 13:56:35 -070088 /* Returns available ("unallocated") pipes for a display's mixer */
89 int availablePipes(int dpy, int mixer);
Saurabh Shah082468e2013-09-12 10:05:32 -070090 /* Returns available ("unallocated") pipes for a display */
91 int availablePipes(int dpy);
Saurabh Shah90b7b9b2013-09-12 16:36:08 -070092 /* Returns available ("unallocated") pipe of given type for a display */
93 int availablePipes(int dpy, utils::eMdpPipeType type);
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -070094 /* Returns if any of the requested pipe type is attached to any of the
95 * displays
96 */
97 bool isPipeTypeAttached(utils::eMdpPipeType type);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -080098 /* Returns pipe dump. Expects a NULL terminated buffer of big enough size
99 * to populate.
100 */
101 void getDump(char *buf, size_t len);
Sushil Chauhanbd3ea922013-05-15 12:25:26 -0700102 /* Reset usage and allocation bits on all pipes for given display */
103 void clear(int dpy);
Saurabh Shah784e9852013-08-21 16:51:21 -0700104 /* Marks the display, whose pipes need to be forcibaly configured */
105 void forceSet(const int& dpy);
106
107 /* Closes open pipes, called during startup */
108 static int initOverlay();
109 /* Returns the singleton instance of overlay */
110 static Overlay* getInstance();
Saurabh Shah85234ec2013-04-12 17:09:00 -0700111 static void setDMAMode(const int& mode);
112 static int getDMAMode();
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700113 /* Returns the framebuffer node backing up the display */
114 static int getFbForDpy(const int& dpy);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700115 static bool displayCommit(const int& fd, const utils::Dim& roi);
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700116 static bool displayCommit(const int& fd);
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700117 /* Returns the scalar object */
118 static scale::Scale *getScalar();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700119
120private:
121 /* Ctor setup */
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500122 explicit Overlay();
123 /*Validate index range, abort if invalid */
124 void validate(int index);
125 void dump() const;
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700126 /* Creates a scalar object using libscale.so */
127 static void initScalar();
128 /* Destroys the scalar object using libscale.so */
129 static void destroyScalar();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700130
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500131 /* Just like a Facebook for pipes, but much less profile info */
132 struct PipeBook {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500133 void init();
134 void destroy();
135 /* Check if pipe exists and return true, false otherwise */
136 bool valid();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700137
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500138 /* Hardware pipe wrapper */
139 GenericPipe *mPipe;
140 /* Display using this pipe. Refer to enums above */
141 int mDisplay;
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700142 /* Mixer within a split display this pipe is attached to */
143 int mMixer;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700144
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500145 /* operations on bitmap */
146 static bool pipeUsageUnchanged();
147 static void setUse(int index);
148 static void resetUse(int index);
149 static bool isUsed(int index);
150 static bool isNotUsed(int index);
151 static void save();
152
153 static void setAllocation(int index);
154 static void resetAllocation(int index);
155 static bool isAllocated(int index);
156 static bool isNotAllocated(int index);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500157
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800158 static utils::eMdpPipeType getPipeType(utils::eDest dest);
159 static const char* getDestStr(utils::eDest dest);
160
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500161 static int NUM_PIPES;
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800162 static utils::eMdpPipeType pipeTypeLUT[utils::OV_MAX];
163
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500164
165 private:
166 //usage tracks if a successful commit happened. So a pipe could be
167 //allocated to a display, but it may not end up using it for various
168 //reasons. If one display actually uses a pipe then it amy not be
169 //used by another display, without an UNSET in between.
170 static int sPipeUsageBitmap;
171 static int sLastUsageBitmap;
172 //Tracks which pipe objects are allocated. This does not imply that they
173 //will actually be used. For example, a display might choose to acquire
174 //3 pipe objects in one shot and proceed with config only if it gets all
175 //3. The bitmap helps allocate different pipe objects on each request.
176 static int sAllocatedBitmap;
177 };
178
179 PipeBook mPipeBook[utils::OV_INVALID]; //Used as max
180
181 /* Dump string */
Saurabh Shah9dc88fc2013-07-15 16:02:30 -0700182 char mDumpStr[1024];
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500183
184 /* Singleton Instance*/
185 static Overlay *sInstance;
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700186 static int sDpyFbMap[DPY_MAX];
Saurabh Shah85234ec2013-04-12 17:09:00 -0700187 static int sDMAMode;
Saurabh Shah784e9852013-08-21 16:51:21 -0700188 static int sForceSetBitmap;
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700189 static void *sLibScaleHandle;
190 static scale::Scale *sScale;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700191};
192
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500193inline void Overlay::validate(int index) {
194 OVASSERT(index >=0 && index < PipeBook::NUM_PIPES, \
195 "%s, Index out of bounds: %d", __FUNCTION__, index);
196 OVASSERT(mPipeBook[index].valid(), "Pipe does not exist %s",
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800197 PipeBook::getDestStr((utils::eDest)index));
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500198}
199
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700200inline int Overlay::availablePipes(int dpy, int mixer) {
201 int avail = 0;
202 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
203 if( (mPipeBook[i].mDisplay == DPY_UNUSED ||
204 mPipeBook[i].mDisplay == dpy) &&
205 (mPipeBook[i].mMixer == MIXER_UNUSED ||
206 mPipeBook[i].mMixer == mixer) &&
207 PipeBook::isNotAllocated(i) &&
208 !(Overlay::getDMAMode() == Overlay::DMA_BLOCK_MODE &&
209 PipeBook::getPipeType((utils::eDest)i) ==
210 utils::OV_MDP_PIPE_DMA)) {
211 avail++;
Jeykumar Sankaranccb44602013-01-03 12:48:22 -0800212 }
213 }
214 return avail;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500215}
216
Saurabh Shah082468e2013-09-12 10:05:32 -0700217inline int Overlay::availablePipes(int dpy) {
218 int avail = 0;
219 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
220 if( (mPipeBook[i].mDisplay == DPY_UNUSED ||
221 mPipeBook[i].mDisplay == dpy) &&
222 PipeBook::isNotAllocated(i) &&
223 !(Overlay::getDMAMode() == Overlay::DMA_BLOCK_MODE &&
224 PipeBook::getPipeType((utils::eDest)i) ==
225 utils::OV_MDP_PIPE_DMA)) {
226 avail++;
227 }
228 }
229 return avail;
230}
231
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700232inline int Overlay::availablePipes(int dpy, utils::eMdpPipeType type) {
233 int avail = 0;
234 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
235 if((mPipeBook[i].mDisplay == DPY_UNUSED ||
236 mPipeBook[i].mDisplay == dpy) &&
237 PipeBook::isNotAllocated(i) &&
238 type == PipeBook::getPipeType((utils::eDest)i)) {
239 avail++;
240 }
241 }
242 return avail;
243}
244
Saurabh Shah85234ec2013-04-12 17:09:00 -0700245inline void Overlay::setDMAMode(const int& mode) {
246 if(mode == DMA_LINE_MODE || mode == DMA_BLOCK_MODE)
247 sDMAMode = mode;
248}
249
250inline int Overlay::getDMAMode() {
251 return sDMAMode;
252}
253
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700254inline int Overlay::getFbForDpy(const int& dpy) {
255 OVASSERT(dpy >= 0 && dpy < DPY_MAX, "Invalid dpy %d", dpy);
256 return sDpyFbMap[dpy];
257}
258
Saurabh Shah784e9852013-08-21 16:51:21 -0700259inline void Overlay::forceSet(const int& dpy) {
260 sForceSetBitmap |= (1 << dpy);
261}
262
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700263inline scale::Scale *Overlay::getScalar() {
264 return sScale;
265}
266
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500267inline bool Overlay::PipeBook::valid() {
268 return (mPipe != NULL);
269}
270
271inline bool Overlay::PipeBook::pipeUsageUnchanged() {
272 return (sPipeUsageBitmap == sLastUsageBitmap);
273}
274
275inline void Overlay::PipeBook::setUse(int index) {
276 sPipeUsageBitmap |= (1 << index);
277}
278
279inline void Overlay::PipeBook::resetUse(int index) {
280 sPipeUsageBitmap &= ~(1 << index);
281}
282
283inline bool Overlay::PipeBook::isUsed(int index) {
284 return sPipeUsageBitmap & (1 << index);
285}
286
287inline bool Overlay::PipeBook::isNotUsed(int index) {
288 return !isUsed(index);
289}
290
291inline void Overlay::PipeBook::save() {
292 sLastUsageBitmap = sPipeUsageBitmap;
293}
294
295inline void Overlay::PipeBook::setAllocation(int index) {
296 sAllocatedBitmap |= (1 << index);
297}
298
299inline void Overlay::PipeBook::resetAllocation(int index) {
300 sAllocatedBitmap &= ~(1 << index);
301}
302
303inline bool Overlay::PipeBook::isAllocated(int index) {
304 return sAllocatedBitmap & (1 << index);
305}
306
307inline bool Overlay::PipeBook::isNotAllocated(int index) {
308 return !isAllocated(index);
309}
310
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800311inline utils::eMdpPipeType Overlay::PipeBook::getPipeType(utils::eDest dest) {
312 return pipeTypeLUT[(int)dest];
313}
314
315inline const char* Overlay::PipeBook::getDestStr(utils::eDest dest) {
316 switch(getPipeType(dest)) {
317 case utils::OV_MDP_PIPE_RGB: return "RGB";
318 case utils::OV_MDP_PIPE_VG: return "VG";
319 case utils::OV_MDP_PIPE_DMA: return "DMA";
320 default: return "Invalid";
321 }
322 return "Invalid";
323}
324
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500325}; // overlay
Naseer Ahmed29a26812012-06-14 00:56:20 -0700326
327#endif // OVERLAY_H