blob: 523e3f78e0bb94b2c61b96478fb473d7c064a758 [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"
Naseer Ahmed29a26812012-06-14 00:56:20 -070034
35namespace overlay {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050036class GenericPipe;
37
Naseer Ahmed29a26812012-06-14 00:56:20 -070038class Overlay : utils::NoCopy {
39public:
40 /* dtor close */
41 ~Overlay();
42
Naseer Ahmed758bfc52012-11-28 17:02:08 -050043 /* Marks the beginning of a drawing round, resets usage bits on pipes
44 * Should be called when drawing begins before any pipe config is done.
45 */
46 void configBegin();
Naseer Ahmed29a26812012-06-14 00:56:20 -070047
Naseer Ahmed758bfc52012-11-28 17:02:08 -050048 /* Marks the end of config for this drawing round
49 * Will do garbage collection of pipe objects and thus calling UNSETs,
50 * closing FDs, removing rotator objects and memory, if allocated.
51 * Should be called after all pipe configs are done.
52 */
53 void configDone();
Naseer Ahmed29a26812012-06-14 00:56:20 -070054
Naseer Ahmed758bfc52012-11-28 17:02:08 -050055 /* Returns an available pipe based on the type of pipe requested. When ANY
56 * is requested, the first available VG or RGB is returned. If no pipe is
57 * available for the display "dpy" then INV is returned. Note: If a pipe is
58 * assigned to a certain display, then it cannot be assigned to another
59 * display without being garbage-collected once */
60 utils::eDest nextPipe(utils::eMdpPipeType, int dpy);
Naseer Ahmedf48aef62012-07-20 09:05:53 -070061
Naseer Ahmed758bfc52012-11-28 17:02:08 -050062 void setSource(const utils::PipeArgs args, utils::eDest dest);
63 void setCrop(const utils::Dim& d, utils::eDest dest);
64 void setTransform(const int orientation, utils::eDest dest);
65 void setPosition(const utils::Dim& dim, utils::eDest dest);
66 bool commit(utils::eDest dest);
67 bool queueBuffer(int fd, uint32_t offset, utils::eDest dest);
Naseer Ahmedf48aef62012-07-20 09:05:53 -070068
Naseer Ahmed758bfc52012-11-28 17:02:08 -050069 /* Closes open pipes, called during startup */
Saurabh Shahc4d034f2012-09-27 15:55:15 -070070 static void initOverlay();
Naseer Ahmed758bfc52012-11-28 17:02:08 -050071 /* Returns the singleton instance of overlay */
72 static Overlay* getInstance();
73 /* Returns total of available ("unallocated") pipes */
74 static int availablePipes();
Naseer Ahmed29a26812012-06-14 00:56:20 -070075
76private:
77 /* Ctor setup */
Naseer Ahmed758bfc52012-11-28 17:02:08 -050078 explicit Overlay();
79 /*Validate index range, abort if invalid */
80 void validate(int index);
81 void dump() const;
Naseer Ahmed29a26812012-06-14 00:56:20 -070082
Naseer Ahmed758bfc52012-11-28 17:02:08 -050083 /* Just like a Facebook for pipes, but much less profile info */
84 struct PipeBook {
85 enum { DPY_PRIMARY, DPY_EXTERNAL, DPY_UNUSED };
Naseer Ahmed29a26812012-06-14 00:56:20 -070086
Naseer Ahmed758bfc52012-11-28 17:02:08 -050087 void init();
88 void destroy();
89 /* Check if pipe exists and return true, false otherwise */
90 bool valid();
Naseer Ahmed29a26812012-06-14 00:56:20 -070091
Naseer Ahmed758bfc52012-11-28 17:02:08 -050092 /* Hardware pipe wrapper */
93 GenericPipe *mPipe;
94 /* Display using this pipe. Refer to enums above */
95 int mDisplay;
Naseer Ahmed29a26812012-06-14 00:56:20 -070096
Naseer Ahmed758bfc52012-11-28 17:02:08 -050097 /* operations on bitmap */
98 static bool pipeUsageUnchanged();
99 static void setUse(int index);
100 static void resetUse(int index);
101 static bool isUsed(int index);
102 static bool isNotUsed(int index);
103 static void save();
104
105 static void setAllocation(int index);
106 static void resetAllocation(int index);
107 static bool isAllocated(int index);
108 static bool isNotAllocated(int index);
109 /* Returns total of available ("unallocated") pipes */
110 static int availablePipes();
111
112 static int NUM_PIPES;
113
114 private:
115 //usage tracks if a successful commit happened. So a pipe could be
116 //allocated to a display, but it may not end up using it for various
117 //reasons. If one display actually uses a pipe then it amy not be
118 //used by another display, without an UNSET in between.
119 static int sPipeUsageBitmap;
120 static int sLastUsageBitmap;
121 //Tracks which pipe objects are allocated. This does not imply that they
122 //will actually be used. For example, a display might choose to acquire
123 //3 pipe objects in one shot and proceed with config only if it gets all
124 //3. The bitmap helps allocate different pipe objects on each request.
125 static int sAllocatedBitmap;
126 };
127
128 PipeBook mPipeBook[utils::OV_INVALID]; //Used as max
129
130 /* Dump string */
131 char mDumpStr[256];
132
133 /* Singleton Instance*/
134 static Overlay *sInstance;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700135};
136
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500137inline void Overlay::validate(int index) {
138 OVASSERT(index >=0 && index < PipeBook::NUM_PIPES, \
139 "%s, Index out of bounds: %d", __FUNCTION__, index);
140 OVASSERT(mPipeBook[index].valid(), "Pipe does not exist %s",
141 utils::getDestStr((utils::eDest)index));
142}
143
144inline int Overlay::availablePipes() {
145 return PipeBook::availablePipes();
146}
147
148inline int Overlay::PipeBook::availablePipes() {
149 int used = 0;
150 int bmp = sAllocatedBitmap;
151 for(; bmp; used++) {
152 //clearing from lsb
153 bmp = bmp & (bmp - 1);
154 }
155 return NUM_PIPES - used;
156}
157
158inline bool Overlay::PipeBook::valid() {
159 return (mPipe != NULL);
160}
161
162inline bool Overlay::PipeBook::pipeUsageUnchanged() {
163 return (sPipeUsageBitmap == sLastUsageBitmap);
164}
165
166inline void Overlay::PipeBook::setUse(int index) {
167 sPipeUsageBitmap |= (1 << index);
168}
169
170inline void Overlay::PipeBook::resetUse(int index) {
171 sPipeUsageBitmap &= ~(1 << index);
172}
173
174inline bool Overlay::PipeBook::isUsed(int index) {
175 return sPipeUsageBitmap & (1 << index);
176}
177
178inline bool Overlay::PipeBook::isNotUsed(int index) {
179 return !isUsed(index);
180}
181
182inline void Overlay::PipeBook::save() {
183 sLastUsageBitmap = sPipeUsageBitmap;
184}
185
186inline void Overlay::PipeBook::setAllocation(int index) {
187 sAllocatedBitmap |= (1 << index);
188}
189
190inline void Overlay::PipeBook::resetAllocation(int index) {
191 sAllocatedBitmap &= ~(1 << index);
192}
193
194inline bool Overlay::PipeBook::isAllocated(int index) {
195 return sAllocatedBitmap & (1 << index);
196}
197
198inline bool Overlay::PipeBook::isNotAllocated(int index) {
199 return !isAllocated(index);
200}
201
202}; // overlay
Naseer Ahmed29a26812012-06-14 00:56:20 -0700203
204#endif // OVERLAY_H