blob: aa12b76a410e7665cbe7c7194b31883fbf8915b4 [file] [log] [blame]
Naseer Ahmed29a26812012-06-14 00:56:20 -07001/*
Naseer Ahmed758bfc52012-11-28 17:02:08 -05002* Copyright (c) 2011-2012, 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
36namespace overlay {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050037class GenericPipe;
38
Naseer Ahmed29a26812012-06-14 00:56:20 -070039class Overlay : utils::NoCopy {
40public:
41 /* dtor close */
42 ~Overlay();
43
Naseer Ahmed758bfc52012-11-28 17:02:08 -050044 /* Marks the beginning of a drawing round, resets usage bits on pipes
45 * Should be called when drawing begins before any pipe config is done.
46 */
47 void configBegin();
Naseer Ahmed29a26812012-06-14 00:56:20 -070048
Naseer Ahmed758bfc52012-11-28 17:02:08 -050049 /* Marks the end of config for this drawing round
50 * Will do garbage collection of pipe objects and thus calling UNSETs,
51 * closing FDs, removing rotator objects and memory, if allocated.
52 * Should be called after all pipe configs are done.
53 */
54 void configDone();
Naseer Ahmed29a26812012-06-14 00:56:20 -070055
Naseer Ahmed758bfc52012-11-28 17:02:08 -050056 /* Returns an available pipe based on the type of pipe requested. When ANY
57 * is requested, the first available VG or RGB is returned. If no pipe is
58 * available for the display "dpy" then INV is returned. Note: If a pipe is
59 * assigned to a certain display, then it cannot be assigned to another
60 * display without being garbage-collected once */
61 utils::eDest nextPipe(utils::eMdpPipeType, int dpy);
Naseer Ahmedf48aef62012-07-20 09:05:53 -070062
Naseer Ahmed758bfc52012-11-28 17:02:08 -050063 void setSource(const utils::PipeArgs args, utils::eDest dest);
64 void setCrop(const utils::Dim& d, utils::eDest dest);
65 void setTransform(const int orientation, utils::eDest dest);
66 void setPosition(const utils::Dim& dim, utils::eDest dest);
67 bool commit(utils::eDest dest);
68 bool queueBuffer(int fd, uint32_t offset, utils::eDest dest);
Naseer Ahmedf48aef62012-07-20 09:05:53 -070069
Naseer Ahmed758bfc52012-11-28 17:02:08 -050070 /* Closes open pipes, called during startup */
Sushil Chauhan07a2c762013-03-06 15:36:49 -080071 static int initOverlay();
Naseer Ahmed758bfc52012-11-28 17:02:08 -050072 /* Returns the singleton instance of overlay */
73 static Overlay* getInstance();
Jeykumar Sankaranccb44602013-01-03 12:48:22 -080074 /* Returns available ("unallocated") pipes for a display */
75 int availablePipes(int dpy);
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -080076 /* set the framebuffer index for external display */
77 void setExtFbNum(int fbNum);
78 /* Returns framebuffer index of the current external display */
79 int getExtFbNum();
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -080080 /* Returns pipe dump. Expects a NULL terminated buffer of big enough size
81 * to populate.
82 */
83 void getDump(char *buf, size_t len);
Naseer Ahmed29a26812012-06-14 00:56:20 -070084
85private:
86 /* Ctor setup */
Naseer Ahmed758bfc52012-11-28 17:02:08 -050087 explicit Overlay();
88 /*Validate index range, abort if invalid */
89 void validate(int index);
90 void dump() const;
Naseer Ahmed29a26812012-06-14 00:56:20 -070091
Naseer Ahmed758bfc52012-11-28 17:02:08 -050092 /* Just like a Facebook for pipes, but much less profile info */
93 struct PipeBook {
94 enum { DPY_PRIMARY, DPY_EXTERNAL, DPY_UNUSED };
Naseer Ahmed29a26812012-06-14 00:56:20 -070095
Naseer Ahmed758bfc52012-11-28 17:02:08 -050096 void init();
97 void destroy();
98 /* Check if pipe exists and return true, false otherwise */
99 bool valid();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700100
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500101 /* Hardware pipe wrapper */
102 GenericPipe *mPipe;
103 /* Display using this pipe. Refer to enums above */
104 int mDisplay;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700105
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500106 /* operations on bitmap */
107 static bool pipeUsageUnchanged();
108 static void setUse(int index);
109 static void resetUse(int index);
110 static bool isUsed(int index);
111 static bool isNotUsed(int index);
112 static void save();
113
114 static void setAllocation(int index);
115 static void resetAllocation(int index);
116 static bool isAllocated(int index);
117 static bool isNotAllocated(int index);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500118
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800119 static utils::eMdpPipeType getPipeType(utils::eDest dest);
120 static const char* getDestStr(utils::eDest dest);
121
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500122 static int NUM_PIPES;
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800123 static utils::eMdpPipeType pipeTypeLUT[utils::OV_MAX];
124
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500125
126 private:
127 //usage tracks if a successful commit happened. So a pipe could be
128 //allocated to a display, but it may not end up using it for various
129 //reasons. If one display actually uses a pipe then it amy not be
130 //used by another display, without an UNSET in between.
131 static int sPipeUsageBitmap;
132 static int sLastUsageBitmap;
133 //Tracks which pipe objects are allocated. This does not imply that they
134 //will actually be used. For example, a display might choose to acquire
135 //3 pipe objects in one shot and proceed with config only if it gets all
136 //3. The bitmap helps allocate different pipe objects on each request.
137 static int sAllocatedBitmap;
138 };
139
140 PipeBook mPipeBook[utils::OV_INVALID]; //Used as max
141
142 /* Dump string */
143 char mDumpStr[256];
144
145 /* Singleton Instance*/
146 static Overlay *sInstance;
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -0800147 static int sExtFbIndex;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700148};
149
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500150inline void Overlay::validate(int index) {
151 OVASSERT(index >=0 && index < PipeBook::NUM_PIPES, \
152 "%s, Index out of bounds: %d", __FUNCTION__, index);
153 OVASSERT(mPipeBook[index].valid(), "Pipe does not exist %s",
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800154 PipeBook::getDestStr((utils::eDest)index));
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500155}
156
Jeykumar Sankaranccb44602013-01-03 12:48:22 -0800157inline int Overlay::availablePipes(int dpy) {
158 int avail = 0;
159 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
160 if((mPipeBook[i].mDisplay == PipeBook::DPY_UNUSED ||
161 mPipeBook[i].mDisplay == dpy) && PipeBook::isNotAllocated(i)) {
162 avail++;
163 }
164 }
165 return avail;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500166}
167
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -0800168inline void Overlay::setExtFbNum(int fbNum) {
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -0800169 sExtFbIndex = fbNum;
170}
171
172inline int Overlay::getExtFbNum() {
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -0800173 return sExtFbIndex;
174}
175
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500176inline bool Overlay::PipeBook::valid() {
177 return (mPipe != NULL);
178}
179
180inline bool Overlay::PipeBook::pipeUsageUnchanged() {
181 return (sPipeUsageBitmap == sLastUsageBitmap);
182}
183
184inline void Overlay::PipeBook::setUse(int index) {
185 sPipeUsageBitmap |= (1 << index);
186}
187
188inline void Overlay::PipeBook::resetUse(int index) {
189 sPipeUsageBitmap &= ~(1 << index);
190}
191
192inline bool Overlay::PipeBook::isUsed(int index) {
193 return sPipeUsageBitmap & (1 << index);
194}
195
196inline bool Overlay::PipeBook::isNotUsed(int index) {
197 return !isUsed(index);
198}
199
200inline void Overlay::PipeBook::save() {
201 sLastUsageBitmap = sPipeUsageBitmap;
202}
203
204inline void Overlay::PipeBook::setAllocation(int index) {
205 sAllocatedBitmap |= (1 << index);
206}
207
208inline void Overlay::PipeBook::resetAllocation(int index) {
209 sAllocatedBitmap &= ~(1 << index);
210}
211
212inline bool Overlay::PipeBook::isAllocated(int index) {
213 return sAllocatedBitmap & (1 << index);
214}
215
216inline bool Overlay::PipeBook::isNotAllocated(int index) {
217 return !isAllocated(index);
218}
219
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800220inline utils::eMdpPipeType Overlay::PipeBook::getPipeType(utils::eDest dest) {
221 return pipeTypeLUT[(int)dest];
222}
223
224inline const char* Overlay::PipeBook::getDestStr(utils::eDest dest) {
225 switch(getPipeType(dest)) {
226 case utils::OV_MDP_PIPE_RGB: return "RGB";
227 case utils::OV_MDP_PIPE_VG: return "VG";
228 case utils::OV_MDP_PIPE_DMA: return "DMA";
229 default: return "Invalid";
230 }
231 return "Invalid";
232}
233
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500234}; // overlay
Naseer Ahmed29a26812012-06-14 00:56:20 -0700235
236#endif // OVERLAY_H