blob: 4df921f8bc38f435ad644cd3fdb4d75bfeb60ab6 [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"
Raj Kamala8c065f2013-10-22 14:52:45 +053034#include "mdp_version.h"
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -080035#include "utils/threads.h"
Naseer Ahmed29a26812012-06-14 00:56:20 -070036
Saurabh Shah5daeee52013-01-23 16:52:26 +080037struct MetaData_t;
Saurabh Shahb8f58e22013-09-26 16:20:07 -070038namespace scale {
39class Scale;
40};
Saurabh Shah5daeee52013-01-23 16:52:26 +080041
Naseer Ahmed29a26812012-06-14 00:56:20 -070042namespace overlay {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050043class GenericPipe;
44
Naseer Ahmed29a26812012-06-14 00:56:20 -070045class Overlay : utils::NoCopy {
46public:
Saurabh Shah85234ec2013-04-12 17:09:00 -070047 enum { DMA_BLOCK_MODE, DMA_LINE_MODE };
Saurabh Shahc8118ac2013-06-27 10:03:19 -070048 //Abstract Display types. Each backed by a LayerMixer,
49 //represented by a fb node.
50 //High res panels can be backed by 2 layer mixers and a single fb node.
51 enum { DPY_PRIMARY, DPY_EXTERNAL, DPY_WRITEBACK, DPY_UNUSED };
52 enum { DPY_MAX = DPY_UNUSED };
Saurabh Shahaf5f5972013-07-30 13:56:35 -070053 enum { MIXER_LEFT, MIXER_RIGHT, MIXER_UNUSED };
54 enum { MIXER_DEFAULT = MIXER_LEFT, MIXER_MAX = MIXER_UNUSED };
Saurabh Shahc8118ac2013-06-27 10:03:19 -070055 enum { MAX_FB_DEVICES = DPY_MAX };
Saurabh Shah85234ec2013-04-12 17:09:00 -070056
Naseer Ahmed29a26812012-06-14 00:56:20 -070057 /* dtor close */
58 ~Overlay();
59
Naseer Ahmed758bfc52012-11-28 17:02:08 -050060 /* Marks the beginning of a drawing round, resets usage bits on pipes
61 * Should be called when drawing begins before any pipe config is done.
62 */
63 void configBegin();
Naseer Ahmed29a26812012-06-14 00:56:20 -070064
Naseer Ahmed758bfc52012-11-28 17:02:08 -050065 /* Marks the end of config for this drawing round
66 * Will do garbage collection of pipe objects and thus calling UNSETs,
67 * closing FDs, removing rotator objects and memory, if allocated.
68 * Should be called after all pipe configs are done.
69 */
70 void configDone();
Naseer Ahmed29a26812012-06-14 00:56:20 -070071
Naseer Ahmed758bfc52012-11-28 17:02:08 -050072 /* Returns an available pipe based on the type of pipe requested. When ANY
73 * is requested, the first available VG or RGB is returned. If no pipe is
74 * available for the display "dpy" then INV is returned. Note: If a pipe is
75 * assigned to a certain display, then it cannot be assigned to another
Saurabh Shahaf5f5972013-07-30 13:56:35 -070076 * display without being garbage-collected once. To add if a pipe is
77 * asisgned to a mixer within a display it cannot be reused for another
78 * mixer without being UNSET once*/
79 utils::eDest nextPipe(utils::eMdpPipeType, int dpy, int mixer);
Naseer Ahmedf48aef62012-07-20 09:05:53 -070080
Naseer Ahmed758bfc52012-11-28 17:02:08 -050081 void setSource(const utils::PipeArgs args, utils::eDest dest);
82 void setCrop(const utils::Dim& d, utils::eDest dest);
83 void setTransform(const int orientation, utils::eDest dest);
84 void setPosition(const utils::Dim& dim, utils::eDest dest);
Saurabh Shah5daeee52013-01-23 16:52:26 +080085 void setVisualParams(const MetaData_t& data, utils::eDest dest);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050086 bool commit(utils::eDest dest);
87 bool queueBuffer(int fd, uint32_t offset, utils::eDest dest);
Naseer Ahmedf48aef62012-07-20 09:05:53 -070088
Saurabh Shahaf5f5972013-07-30 13:56:35 -070089 /* Returns available ("unallocated") pipes for a display's mixer */
90 int availablePipes(int dpy, int mixer);
Saurabh Shah082468e2013-09-12 10:05:32 -070091 /* Returns available ("unallocated") pipes for a display */
92 int availablePipes(int dpy);
Saurabh Shah90b7b9b2013-09-12 16:36:08 -070093 /* Returns available ("unallocated") pipe of given type for a display */
94 int availablePipes(int dpy, utils::eMdpPipeType type);
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -070095 /* Returns if any of the requested pipe type is attached to any of the
96 * displays
97 */
98 bool isPipeTypeAttached(utils::eMdpPipeType type);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -080099 /* Returns pipe dump. Expects a NULL terminated buffer of big enough size
100 * to populate.
101 */
102 void getDump(char *buf, size_t len);
Sushil Chauhanbd3ea922013-05-15 12:25:26 -0700103 /* Reset usage and allocation bits on all pipes for given display */
104 void clear(int dpy);
Saurabh Shah784e9852013-08-21 16:51:21 -0700105 /* Marks the display, whose pipes need to be forcibaly configured */
106 void forceSet(const int& dpy);
107
108 /* Closes open pipes, called during startup */
109 static int initOverlay();
110 /* Returns the singleton instance of overlay */
111 static Overlay* getInstance();
Saurabh Shah85234ec2013-04-12 17:09:00 -0700112 static void setDMAMode(const int& mode);
113 static int getDMAMode();
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700114 /* Returns the framebuffer node backing up the display */
115 static int getFbForDpy(const int& dpy);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700116 static bool displayCommit(const int& fd, const utils::Dim& roi);
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700117 static bool displayCommit(const int& fd);
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700118 /* Returns the scalar object */
119 static scale::Scale *getScalar();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700120
121private:
122 /* Ctor setup */
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500123 explicit Overlay();
124 /*Validate index range, abort if invalid */
125 void validate(int index);
Raj Kamala8c065f2013-10-22 14:52:45 +0530126 static void setDMAMultiplexingSupported();
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500127 void dump() const;
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700128 /* Creates a scalar object using libscale.so */
129 static void initScalar();
130 /* Destroys the scalar object using libscale.so */
131 static void destroyScalar();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700132
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500133 /* Just like a Facebook for pipes, but much less profile info */
134 struct PipeBook {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500135 void init();
136 void destroy();
137 /* Check if pipe exists and return true, false otherwise */
138 bool valid();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700139
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500140 /* Hardware pipe wrapper */
141 GenericPipe *mPipe;
142 /* Display using this pipe. Refer to enums above */
143 int mDisplay;
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700144 /* Mixer within a split display this pipe is attached to */
145 int mMixer;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700146
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500147 /* operations on bitmap */
148 static bool pipeUsageUnchanged();
149 static void setUse(int index);
150 static void resetUse(int index);
151 static bool isUsed(int index);
152 static bool isNotUsed(int index);
153 static void save();
154
155 static void setAllocation(int index);
156 static void resetAllocation(int index);
157 static bool isAllocated(int index);
158 static bool isNotAllocated(int index);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500159
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800160 static utils::eMdpPipeType getPipeType(utils::eDest dest);
161 static const char* getDestStr(utils::eDest dest);
162
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500163 static int NUM_PIPES;
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800164 static utils::eMdpPipeType pipeTypeLUT[utils::OV_MAX];
165
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500166
167 private:
168 //usage tracks if a successful commit happened. So a pipe could be
169 //allocated to a display, but it may not end up using it for various
170 //reasons. If one display actually uses a pipe then it amy not be
171 //used by another display, without an UNSET in between.
172 static int sPipeUsageBitmap;
173 static int sLastUsageBitmap;
174 //Tracks which pipe objects are allocated. This does not imply that they
175 //will actually be used. For example, a display might choose to acquire
176 //3 pipe objects in one shot and proceed with config only if it gets all
177 //3. The bitmap helps allocate different pipe objects on each request.
178 static int sAllocatedBitmap;
179 };
180
181 PipeBook mPipeBook[utils::OV_INVALID]; //Used as max
182
183 /* Dump string */
Saurabh Shah9dc88fc2013-07-15 16:02:30 -0700184 char mDumpStr[1024];
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500185
186 /* Singleton Instance*/
187 static Overlay *sInstance;
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700188 static int sDpyFbMap[DPY_MAX];
Saurabh Shah85234ec2013-04-12 17:09:00 -0700189 static int sDMAMode;
Raj Kamala8c065f2013-10-22 14:52:45 +0530190 static bool sDMAMultiplexingSupported;
Saurabh Shah784e9852013-08-21 16:51:21 -0700191 static int sForceSetBitmap;
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700192 static void *sLibScaleHandle;
193 static scale::Scale *sScale;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700194};
195
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500196inline void Overlay::validate(int index) {
197 OVASSERT(index >=0 && index < PipeBook::NUM_PIPES, \
198 "%s, Index out of bounds: %d", __FUNCTION__, index);
199 OVASSERT(mPipeBook[index].valid(), "Pipe does not exist %s",
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800200 PipeBook::getDestStr((utils::eDest)index));
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500201}
202
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700203inline int Overlay::availablePipes(int dpy, int mixer) {
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 (mPipeBook[i].mMixer == MIXER_UNUSED ||
209 mPipeBook[i].mMixer == mixer) &&
210 PipeBook::isNotAllocated(i) &&
211 !(Overlay::getDMAMode() == Overlay::DMA_BLOCK_MODE &&
212 PipeBook::getPipeType((utils::eDest)i) ==
213 utils::OV_MDP_PIPE_DMA)) {
214 avail++;
Jeykumar Sankaranccb44602013-01-03 12:48:22 -0800215 }
216 }
217 return avail;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500218}
219
Saurabh Shah082468e2013-09-12 10:05:32 -0700220inline int Overlay::availablePipes(int dpy) {
221 int avail = 0;
222 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
223 if( (mPipeBook[i].mDisplay == DPY_UNUSED ||
224 mPipeBook[i].mDisplay == dpy) &&
225 PipeBook::isNotAllocated(i) &&
226 !(Overlay::getDMAMode() == Overlay::DMA_BLOCK_MODE &&
227 PipeBook::getPipeType((utils::eDest)i) ==
228 utils::OV_MDP_PIPE_DMA)) {
229 avail++;
230 }
231 }
232 return avail;
233}
234
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700235inline int Overlay::availablePipes(int dpy, utils::eMdpPipeType type) {
236 int avail = 0;
237 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
238 if((mPipeBook[i].mDisplay == DPY_UNUSED ||
239 mPipeBook[i].mDisplay == dpy) &&
240 PipeBook::isNotAllocated(i) &&
241 type == PipeBook::getPipeType((utils::eDest)i)) {
242 avail++;
243 }
244 }
245 return avail;
246}
247
Saurabh Shah85234ec2013-04-12 17:09:00 -0700248inline void Overlay::setDMAMode(const int& mode) {
249 if(mode == DMA_LINE_MODE || mode == DMA_BLOCK_MODE)
250 sDMAMode = mode;
251}
252
Raj Kamala8c065f2013-10-22 14:52:45 +0530253inline void Overlay::setDMAMultiplexingSupported() {
254 sDMAMultiplexingSupported = false;
255 if(qdutils::MDPVersion::getInstance().is8x26())
256 sDMAMultiplexingSupported = true;
257}
258
Saurabh Shah85234ec2013-04-12 17:09:00 -0700259inline int Overlay::getDMAMode() {
260 return sDMAMode;
261}
262
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700263inline int Overlay::getFbForDpy(const int& dpy) {
264 OVASSERT(dpy >= 0 && dpy < DPY_MAX, "Invalid dpy %d", dpy);
265 return sDpyFbMap[dpy];
266}
267
Saurabh Shah784e9852013-08-21 16:51:21 -0700268inline void Overlay::forceSet(const int& dpy) {
269 sForceSetBitmap |= (1 << dpy);
270}
271
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700272inline scale::Scale *Overlay::getScalar() {
273 return sScale;
274}
275
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500276inline bool Overlay::PipeBook::valid() {
277 return (mPipe != NULL);
278}
279
280inline bool Overlay::PipeBook::pipeUsageUnchanged() {
281 return (sPipeUsageBitmap == sLastUsageBitmap);
282}
283
284inline void Overlay::PipeBook::setUse(int index) {
285 sPipeUsageBitmap |= (1 << index);
286}
287
288inline void Overlay::PipeBook::resetUse(int index) {
289 sPipeUsageBitmap &= ~(1 << index);
290}
291
292inline bool Overlay::PipeBook::isUsed(int index) {
293 return sPipeUsageBitmap & (1 << index);
294}
295
296inline bool Overlay::PipeBook::isNotUsed(int index) {
297 return !isUsed(index);
298}
299
300inline void Overlay::PipeBook::save() {
301 sLastUsageBitmap = sPipeUsageBitmap;
302}
303
304inline void Overlay::PipeBook::setAllocation(int index) {
305 sAllocatedBitmap |= (1 << index);
306}
307
308inline void Overlay::PipeBook::resetAllocation(int index) {
309 sAllocatedBitmap &= ~(1 << index);
310}
311
312inline bool Overlay::PipeBook::isAllocated(int index) {
313 return sAllocatedBitmap & (1 << index);
314}
315
316inline bool Overlay::PipeBook::isNotAllocated(int index) {
317 return !isAllocated(index);
318}
319
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800320inline utils::eMdpPipeType Overlay::PipeBook::getPipeType(utils::eDest dest) {
321 return pipeTypeLUT[(int)dest];
322}
323
324inline const char* Overlay::PipeBook::getDestStr(utils::eDest dest) {
325 switch(getPipeType(dest)) {
326 case utils::OV_MDP_PIPE_RGB: return "RGB";
327 case utils::OV_MDP_PIPE_VG: return "VG";
328 case utils::OV_MDP_PIPE_DMA: return "DMA";
329 default: return "Invalid";
330 }
331 return "Invalid";
332}
333
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500334}; // overlay
Naseer Ahmed29a26812012-06-14 00:56:20 -0700335
336#endif // OVERLAY_H