blob: 0f15baa521a6feec25d3b609bafd6dab736bae46 [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 */
Saurabh Shahc4d034f2012-09-27 15:55:15 -070071 static void 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
119 static int NUM_PIPES;
120
121 private:
122 //usage tracks if a successful commit happened. So a pipe could be
123 //allocated to a display, but it may not end up using it for various
124 //reasons. If one display actually uses a pipe then it amy not be
125 //used by another display, without an UNSET in between.
126 static int sPipeUsageBitmap;
127 static int sLastUsageBitmap;
128 //Tracks which pipe objects are allocated. This does not imply that they
129 //will actually be used. For example, a display might choose to acquire
130 //3 pipe objects in one shot and proceed with config only if it gets all
131 //3. The bitmap helps allocate different pipe objects on each request.
132 static int sAllocatedBitmap;
133 };
134
135 PipeBook mPipeBook[utils::OV_INVALID]; //Used as max
136
137 /* Dump string */
138 char mDumpStr[256];
139
140 /* Singleton Instance*/
141 static Overlay *sInstance;
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -0800142 static int sExtFbIndex;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700143};
144
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500145inline void Overlay::validate(int index) {
146 OVASSERT(index >=0 && index < PipeBook::NUM_PIPES, \
147 "%s, Index out of bounds: %d", __FUNCTION__, index);
148 OVASSERT(mPipeBook[index].valid(), "Pipe does not exist %s",
149 utils::getDestStr((utils::eDest)index));
150}
151
Jeykumar Sankaranccb44602013-01-03 12:48:22 -0800152inline int Overlay::availablePipes(int dpy) {
153 int avail = 0;
154 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
155 if((mPipeBook[i].mDisplay == PipeBook::DPY_UNUSED ||
156 mPipeBook[i].mDisplay == dpy) && PipeBook::isNotAllocated(i)) {
157 avail++;
158 }
159 }
160 return avail;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500161}
162
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -0800163inline void Overlay::setExtFbNum(int fbNum) {
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -0800164 sExtFbIndex = fbNum;
165}
166
167inline int Overlay::getExtFbNum() {
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -0800168 return sExtFbIndex;
169}
170
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500171inline bool Overlay::PipeBook::valid() {
172 return (mPipe != NULL);
173}
174
175inline bool Overlay::PipeBook::pipeUsageUnchanged() {
176 return (sPipeUsageBitmap == sLastUsageBitmap);
177}
178
179inline void Overlay::PipeBook::setUse(int index) {
180 sPipeUsageBitmap |= (1 << index);
181}
182
183inline void Overlay::PipeBook::resetUse(int index) {
184 sPipeUsageBitmap &= ~(1 << index);
185}
186
187inline bool Overlay::PipeBook::isUsed(int index) {
188 return sPipeUsageBitmap & (1 << index);
189}
190
191inline bool Overlay::PipeBook::isNotUsed(int index) {
192 return !isUsed(index);
193}
194
195inline void Overlay::PipeBook::save() {
196 sLastUsageBitmap = sPipeUsageBitmap;
197}
198
199inline void Overlay::PipeBook::setAllocation(int index) {
200 sAllocatedBitmap |= (1 << index);
201}
202
203inline void Overlay::PipeBook::resetAllocation(int index) {
204 sAllocatedBitmap &= ~(1 << index);
205}
206
207inline bool Overlay::PipeBook::isAllocated(int index) {
208 return sAllocatedBitmap & (1 << index);
209}
210
211inline bool Overlay::PipeBook::isNotAllocated(int index) {
212 return !isAllocated(index);
213}
214
215}; // overlay
Naseer Ahmed29a26812012-06-14 00:56:20 -0700216
217#endif // OVERLAY_H