Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1 | /* |
Saurabh Shah | 5daeee5 | 2013-01-23 16:52:26 +0800 | [diff] [blame] | 2 | * Copyright (c) 2011-2013, The Linux Foundation. All rights reserved. |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 3 | * |
| 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 Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 13 | * * Neither the name of The Linux Foundation. nor the names of its |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 14 | * 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 Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 34 | #include "utils/threads.h" |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 35 | |
Saurabh Shah | 5daeee5 | 2013-01-23 16:52:26 +0800 | [diff] [blame] | 36 | struct MetaData_t; |
| 37 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 38 | namespace overlay { |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 39 | class GenericPipe; |
| 40 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 41 | class Overlay : utils::NoCopy { |
| 42 | public: |
Saurabh Shah | 85234ec | 2013-04-12 17:09:00 -0700 | [diff] [blame] | 43 | enum { DMA_BLOCK_MODE, DMA_LINE_MODE }; |
Saurabh Shah | c8118ac | 2013-06-27 10:03:19 -0700 | [diff] [blame] | 44 | //Abstract Display types. Each backed by a LayerMixer, |
| 45 | //represented by a fb node. |
| 46 | //High res panels can be backed by 2 layer mixers and a single fb node. |
| 47 | enum { DPY_PRIMARY, DPY_EXTERNAL, DPY_WRITEBACK, DPY_UNUSED }; |
| 48 | enum { DPY_MAX = DPY_UNUSED }; |
Saurabh Shah | af5f597 | 2013-07-30 13:56:35 -0700 | [diff] [blame] | 49 | enum { MIXER_LEFT, MIXER_RIGHT, MIXER_UNUSED }; |
| 50 | enum { MIXER_DEFAULT = MIXER_LEFT, MIXER_MAX = MIXER_UNUSED }; |
Saurabh Shah | c8118ac | 2013-06-27 10:03:19 -0700 | [diff] [blame] | 51 | enum { MAX_FB_DEVICES = DPY_MAX }; |
Saurabh Shah | 85234ec | 2013-04-12 17:09:00 -0700 | [diff] [blame] | 52 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 53 | /* dtor close */ |
| 54 | ~Overlay(); |
| 55 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 56 | /* Marks the beginning of a drawing round, resets usage bits on pipes |
| 57 | * Should be called when drawing begins before any pipe config is done. |
| 58 | */ |
| 59 | void configBegin(); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 60 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 61 | /* Marks the end of config for this drawing round |
| 62 | * Will do garbage collection of pipe objects and thus calling UNSETs, |
| 63 | * closing FDs, removing rotator objects and memory, if allocated. |
| 64 | * Should be called after all pipe configs are done. |
| 65 | */ |
| 66 | void configDone(); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 67 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 68 | /* Returns an available pipe based on the type of pipe requested. When ANY |
| 69 | * is requested, the first available VG or RGB is returned. If no pipe is |
| 70 | * available for the display "dpy" then INV is returned. Note: If a pipe is |
| 71 | * assigned to a certain display, then it cannot be assigned to another |
Saurabh Shah | af5f597 | 2013-07-30 13:56:35 -0700 | [diff] [blame] | 72 | * display without being garbage-collected once. To add if a pipe is |
| 73 | * asisgned to a mixer within a display it cannot be reused for another |
| 74 | * mixer without being UNSET once*/ |
| 75 | utils::eDest nextPipe(utils::eMdpPipeType, int dpy, int mixer); |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 76 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 77 | void setSource(const utils::PipeArgs args, utils::eDest dest); |
| 78 | void setCrop(const utils::Dim& d, utils::eDest dest); |
Sushil Chauhan | 897a9c3 | 2013-07-18 11:09:55 -0700 | [diff] [blame^] | 79 | void setColor(const uint32_t color, utils::eDest dest); |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 80 | void setTransform(const int orientation, utils::eDest dest); |
| 81 | void setPosition(const utils::Dim& dim, utils::eDest dest); |
Saurabh Shah | 5daeee5 | 2013-01-23 16:52:26 +0800 | [diff] [blame] | 82 | void setVisualParams(const MetaData_t& data, utils::eDest dest); |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 83 | bool commit(utils::eDest dest); |
| 84 | bool queueBuffer(int fd, uint32_t offset, utils::eDest dest); |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 85 | |
Saurabh Shah | af5f597 | 2013-07-30 13:56:35 -0700 | [diff] [blame] | 86 | /* Returns available ("unallocated") pipes for a display's mixer */ |
| 87 | int availablePipes(int dpy, int mixer); |
Saurabh Shah | 082468e | 2013-09-12 10:05:32 -0700 | [diff] [blame] | 88 | /* Returns available ("unallocated") pipes for a display */ |
| 89 | int availablePipes(int dpy); |
Saurabh Shah | 90b7b9b | 2013-09-12 16:36:08 -0700 | [diff] [blame] | 90 | /* Returns available ("unallocated") pipe of given type for a display */ |
| 91 | int availablePipes(int dpy, utils::eMdpPipeType type); |
Saurabh Shah | 0ceeb6a | 2013-04-23 10:46:07 -0700 | [diff] [blame] | 92 | /* Returns if any of the requested pipe type is attached to any of the |
| 93 | * displays |
| 94 | */ |
| 95 | bool isPipeTypeAttached(utils::eMdpPipeType type); |
Saurabh Shah | 0d0a7cb | 2013-02-12 17:58:19 -0800 | [diff] [blame] | 96 | /* Returns pipe dump. Expects a NULL terminated buffer of big enough size |
| 97 | * to populate. |
| 98 | */ |
| 99 | void getDump(char *buf, size_t len); |
Sushil Chauhan | bd3ea92 | 2013-05-15 12:25:26 -0700 | [diff] [blame] | 100 | /* Reset usage and allocation bits on all pipes for given display */ |
| 101 | void clear(int dpy); |
Saurabh Shah | 784e985 | 2013-08-21 16:51:21 -0700 | [diff] [blame] | 102 | /* Marks the display, whose pipes need to be forcibaly configured */ |
| 103 | void forceSet(const int& dpy); |
| 104 | |
| 105 | /* Closes open pipes, called during startup */ |
| 106 | static int initOverlay(); |
| 107 | /* Returns the singleton instance of overlay */ |
| 108 | static Overlay* getInstance(); |
Saurabh Shah | 85234ec | 2013-04-12 17:09:00 -0700 | [diff] [blame] | 109 | static void setDMAMode(const int& mode); |
| 110 | static int getDMAMode(); |
Saurabh Shah | c8118ac | 2013-06-27 10:03:19 -0700 | [diff] [blame] | 111 | /* Returns the framebuffer node backing up the display */ |
| 112 | static int getFbForDpy(const int& dpy); |
Jeykumar Sankaran | 6a9bb9e | 2013-08-01 14:19:26 -0700 | [diff] [blame] | 113 | static bool displayCommit(const int& fd, const utils::Dim& roi); |
Saurabh Shah | c8118ac | 2013-06-27 10:03:19 -0700 | [diff] [blame] | 114 | static bool displayCommit(const int& fd); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 115 | |
| 116 | private: |
| 117 | /* Ctor setup */ |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 118 | explicit Overlay(); |
| 119 | /*Validate index range, abort if invalid */ |
| 120 | void validate(int index); |
| 121 | void dump() const; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 122 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 123 | /* Just like a Facebook for pipes, but much less profile info */ |
| 124 | struct PipeBook { |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 125 | void init(); |
| 126 | void destroy(); |
| 127 | /* Check if pipe exists and return true, false otherwise */ |
| 128 | bool valid(); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 129 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 130 | /* Hardware pipe wrapper */ |
| 131 | GenericPipe *mPipe; |
| 132 | /* Display using this pipe. Refer to enums above */ |
| 133 | int mDisplay; |
Saurabh Shah | af5f597 | 2013-07-30 13:56:35 -0700 | [diff] [blame] | 134 | /* Mixer within a split display this pipe is attached to */ |
| 135 | int mMixer; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 136 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 137 | /* operations on bitmap */ |
| 138 | static bool pipeUsageUnchanged(); |
| 139 | static void setUse(int index); |
| 140 | static void resetUse(int index); |
| 141 | static bool isUsed(int index); |
| 142 | static bool isNotUsed(int index); |
| 143 | static void save(); |
| 144 | |
| 145 | static void setAllocation(int index); |
| 146 | static void resetAllocation(int index); |
| 147 | static bool isAllocated(int index); |
| 148 | static bool isNotAllocated(int index); |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 149 | |
Sushil Chauhan | 07a2c76 | 2013-03-06 15:36:49 -0800 | [diff] [blame] | 150 | static utils::eMdpPipeType getPipeType(utils::eDest dest); |
| 151 | static const char* getDestStr(utils::eDest dest); |
| 152 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 153 | static int NUM_PIPES; |
Sushil Chauhan | 07a2c76 | 2013-03-06 15:36:49 -0800 | [diff] [blame] | 154 | static utils::eMdpPipeType pipeTypeLUT[utils::OV_MAX]; |
| 155 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 156 | |
| 157 | private: |
| 158 | //usage tracks if a successful commit happened. So a pipe could be |
| 159 | //allocated to a display, but it may not end up using it for various |
| 160 | //reasons. If one display actually uses a pipe then it amy not be |
| 161 | //used by another display, without an UNSET in between. |
| 162 | static int sPipeUsageBitmap; |
| 163 | static int sLastUsageBitmap; |
| 164 | //Tracks which pipe objects are allocated. This does not imply that they |
| 165 | //will actually be used. For example, a display might choose to acquire |
| 166 | //3 pipe objects in one shot and proceed with config only if it gets all |
| 167 | //3. The bitmap helps allocate different pipe objects on each request. |
| 168 | static int sAllocatedBitmap; |
| 169 | }; |
| 170 | |
| 171 | PipeBook mPipeBook[utils::OV_INVALID]; //Used as max |
| 172 | |
| 173 | /* Dump string */ |
Saurabh Shah | 9dc88fc | 2013-07-15 16:02:30 -0700 | [diff] [blame] | 174 | char mDumpStr[1024]; |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 175 | |
| 176 | /* Singleton Instance*/ |
| 177 | static Overlay *sInstance; |
Saurabh Shah | c8118ac | 2013-06-27 10:03:19 -0700 | [diff] [blame] | 178 | static int sDpyFbMap[DPY_MAX]; |
Saurabh Shah | 85234ec | 2013-04-12 17:09:00 -0700 | [diff] [blame] | 179 | static int sDMAMode; |
Saurabh Shah | 784e985 | 2013-08-21 16:51:21 -0700 | [diff] [blame] | 180 | static int sForceSetBitmap; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 181 | }; |
| 182 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 183 | inline void Overlay::validate(int index) { |
| 184 | OVASSERT(index >=0 && index < PipeBook::NUM_PIPES, \ |
| 185 | "%s, Index out of bounds: %d", __FUNCTION__, index); |
| 186 | OVASSERT(mPipeBook[index].valid(), "Pipe does not exist %s", |
Sushil Chauhan | 07a2c76 | 2013-03-06 15:36:49 -0800 | [diff] [blame] | 187 | PipeBook::getDestStr((utils::eDest)index)); |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 188 | } |
| 189 | |
Saurabh Shah | af5f597 | 2013-07-30 13:56:35 -0700 | [diff] [blame] | 190 | inline int Overlay::availablePipes(int dpy, int mixer) { |
| 191 | int avail = 0; |
| 192 | for(int i = 0; i < PipeBook::NUM_PIPES; i++) { |
| 193 | if( (mPipeBook[i].mDisplay == DPY_UNUSED || |
| 194 | mPipeBook[i].mDisplay == dpy) && |
| 195 | (mPipeBook[i].mMixer == MIXER_UNUSED || |
| 196 | mPipeBook[i].mMixer == mixer) && |
| 197 | PipeBook::isNotAllocated(i) && |
| 198 | !(Overlay::getDMAMode() == Overlay::DMA_BLOCK_MODE && |
| 199 | PipeBook::getPipeType((utils::eDest)i) == |
| 200 | utils::OV_MDP_PIPE_DMA)) { |
| 201 | avail++; |
Jeykumar Sankaran | ccb4460 | 2013-01-03 12:48:22 -0800 | [diff] [blame] | 202 | } |
| 203 | } |
| 204 | return avail; |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 205 | } |
| 206 | |
Saurabh Shah | 082468e | 2013-09-12 10:05:32 -0700 | [diff] [blame] | 207 | inline int Overlay::availablePipes(int dpy) { |
| 208 | int avail = 0; |
| 209 | for(int i = 0; i < PipeBook::NUM_PIPES; i++) { |
| 210 | if( (mPipeBook[i].mDisplay == DPY_UNUSED || |
| 211 | mPipeBook[i].mDisplay == dpy) && |
| 212 | PipeBook::isNotAllocated(i) && |
| 213 | !(Overlay::getDMAMode() == Overlay::DMA_BLOCK_MODE && |
| 214 | PipeBook::getPipeType((utils::eDest)i) == |
| 215 | utils::OV_MDP_PIPE_DMA)) { |
| 216 | avail++; |
| 217 | } |
| 218 | } |
| 219 | return avail; |
| 220 | } |
| 221 | |
Saurabh Shah | 90b7b9b | 2013-09-12 16:36:08 -0700 | [diff] [blame] | 222 | inline int Overlay::availablePipes(int dpy, utils::eMdpPipeType type) { |
| 223 | int avail = 0; |
| 224 | for(int i = 0; i < PipeBook::NUM_PIPES; i++) { |
| 225 | if((mPipeBook[i].mDisplay == DPY_UNUSED || |
| 226 | mPipeBook[i].mDisplay == dpy) && |
| 227 | PipeBook::isNotAllocated(i) && |
| 228 | type == PipeBook::getPipeType((utils::eDest)i)) { |
| 229 | avail++; |
| 230 | } |
| 231 | } |
| 232 | return avail; |
| 233 | } |
| 234 | |
Saurabh Shah | 85234ec | 2013-04-12 17:09:00 -0700 | [diff] [blame] | 235 | inline void Overlay::setDMAMode(const int& mode) { |
| 236 | if(mode == DMA_LINE_MODE || mode == DMA_BLOCK_MODE) |
| 237 | sDMAMode = mode; |
| 238 | } |
| 239 | |
| 240 | inline int Overlay::getDMAMode() { |
| 241 | return sDMAMode; |
| 242 | } |
| 243 | |
Saurabh Shah | c8118ac | 2013-06-27 10:03:19 -0700 | [diff] [blame] | 244 | inline int Overlay::getFbForDpy(const int& dpy) { |
| 245 | OVASSERT(dpy >= 0 && dpy < DPY_MAX, "Invalid dpy %d", dpy); |
| 246 | return sDpyFbMap[dpy]; |
| 247 | } |
| 248 | |
Saurabh Shah | 784e985 | 2013-08-21 16:51:21 -0700 | [diff] [blame] | 249 | inline void Overlay::forceSet(const int& dpy) { |
| 250 | sForceSetBitmap |= (1 << dpy); |
| 251 | } |
| 252 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 253 | inline bool Overlay::PipeBook::valid() { |
| 254 | return (mPipe != NULL); |
| 255 | } |
| 256 | |
| 257 | inline bool Overlay::PipeBook::pipeUsageUnchanged() { |
| 258 | return (sPipeUsageBitmap == sLastUsageBitmap); |
| 259 | } |
| 260 | |
| 261 | inline void Overlay::PipeBook::setUse(int index) { |
| 262 | sPipeUsageBitmap |= (1 << index); |
| 263 | } |
| 264 | |
| 265 | inline void Overlay::PipeBook::resetUse(int index) { |
| 266 | sPipeUsageBitmap &= ~(1 << index); |
| 267 | } |
| 268 | |
| 269 | inline bool Overlay::PipeBook::isUsed(int index) { |
| 270 | return sPipeUsageBitmap & (1 << index); |
| 271 | } |
| 272 | |
| 273 | inline bool Overlay::PipeBook::isNotUsed(int index) { |
| 274 | return !isUsed(index); |
| 275 | } |
| 276 | |
| 277 | inline void Overlay::PipeBook::save() { |
| 278 | sLastUsageBitmap = sPipeUsageBitmap; |
| 279 | } |
| 280 | |
| 281 | inline void Overlay::PipeBook::setAllocation(int index) { |
| 282 | sAllocatedBitmap |= (1 << index); |
| 283 | } |
| 284 | |
| 285 | inline void Overlay::PipeBook::resetAllocation(int index) { |
| 286 | sAllocatedBitmap &= ~(1 << index); |
| 287 | } |
| 288 | |
| 289 | inline bool Overlay::PipeBook::isAllocated(int index) { |
| 290 | return sAllocatedBitmap & (1 << index); |
| 291 | } |
| 292 | |
| 293 | inline bool Overlay::PipeBook::isNotAllocated(int index) { |
| 294 | return !isAllocated(index); |
| 295 | } |
| 296 | |
Sushil Chauhan | 07a2c76 | 2013-03-06 15:36:49 -0800 | [diff] [blame] | 297 | inline utils::eMdpPipeType Overlay::PipeBook::getPipeType(utils::eDest dest) { |
| 298 | return pipeTypeLUT[(int)dest]; |
| 299 | } |
| 300 | |
| 301 | inline const char* Overlay::PipeBook::getDestStr(utils::eDest dest) { |
| 302 | switch(getPipeType(dest)) { |
| 303 | case utils::OV_MDP_PIPE_RGB: return "RGB"; |
| 304 | case utils::OV_MDP_PIPE_VG: return "VG"; |
| 305 | case utils::OV_MDP_PIPE_DMA: return "DMA"; |
| 306 | default: return "Invalid"; |
| 307 | } |
| 308 | return "Invalid"; |
| 309 | } |
| 310 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 311 | }; // overlay |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 312 | |
| 313 | #endif // OVERLAY_H |