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 }; |
| 44 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 45 | /* dtor close */ |
| 46 | ~Overlay(); |
| 47 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 48 | /* Marks the beginning of a drawing round, resets usage bits on pipes |
| 49 | * Should be called when drawing begins before any pipe config is done. |
| 50 | */ |
| 51 | void configBegin(); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 52 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 53 | /* Marks the end of config for this drawing round |
| 54 | * Will do garbage collection of pipe objects and thus calling UNSETs, |
| 55 | * closing FDs, removing rotator objects and memory, if allocated. |
| 56 | * Should be called after all pipe configs are done. |
| 57 | */ |
| 58 | void configDone(); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 59 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 60 | /* Returns an available pipe based on the type of pipe requested. When ANY |
| 61 | * is requested, the first available VG or RGB is returned. If no pipe is |
| 62 | * available for the display "dpy" then INV is returned. Note: If a pipe is |
| 63 | * assigned to a certain display, then it cannot be assigned to another |
| 64 | * display without being garbage-collected once */ |
| 65 | utils::eDest nextPipe(utils::eMdpPipeType, int dpy); |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 66 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 67 | void setSource(const utils::PipeArgs args, utils::eDest dest); |
| 68 | void setCrop(const utils::Dim& d, utils::eDest dest); |
| 69 | void setTransform(const int orientation, utils::eDest dest); |
| 70 | void setPosition(const utils::Dim& dim, utils::eDest dest); |
Saurabh Shah | 5daeee5 | 2013-01-23 16:52:26 +0800 | [diff] [blame] | 71 | void setVisualParams(const MetaData_t& data, utils::eDest dest); |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 72 | bool commit(utils::eDest dest); |
| 73 | bool queueBuffer(int fd, uint32_t offset, utils::eDest dest); |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 74 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 75 | /* Closes open pipes, called during startup */ |
Sushil Chauhan | 07a2c76 | 2013-03-06 15:36:49 -0800 | [diff] [blame] | 76 | static int initOverlay(); |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 77 | /* Returns the singleton instance of overlay */ |
| 78 | static Overlay* getInstance(); |
Jeykumar Sankaran | ccb4460 | 2013-01-03 12:48:22 -0800 | [diff] [blame] | 79 | /* Returns available ("unallocated") pipes for a display */ |
| 80 | int availablePipes(int dpy); |
Saurabh Shah | 0ceeb6a | 2013-04-23 10:46:07 -0700 | [diff] [blame] | 81 | /* Returns if any of the requested pipe type is attached to any of the |
| 82 | * displays |
| 83 | */ |
| 84 | bool isPipeTypeAttached(utils::eMdpPipeType type); |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 85 | /* set the framebuffer index for external display */ |
| 86 | void setExtFbNum(int fbNum); |
| 87 | /* Returns framebuffer index of the current external display */ |
| 88 | int getExtFbNum(); |
Saurabh Shah | 0d0a7cb | 2013-02-12 17:58:19 -0800 | [diff] [blame] | 89 | /* Returns pipe dump. Expects a NULL terminated buffer of big enough size |
| 90 | * to populate. |
| 91 | */ |
| 92 | void getDump(char *buf, size_t len); |
Sushil Chauhan | bd3ea92 | 2013-05-15 12:25:26 -0700 | [diff] [blame^] | 93 | /* Reset usage and allocation bits on all pipes for given display */ |
| 94 | void clear(int dpy); |
Saurabh Shah | 85234ec | 2013-04-12 17:09:00 -0700 | [diff] [blame] | 95 | static void setDMAMode(const int& mode); |
| 96 | static int getDMAMode(); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 97 | |
| 98 | private: |
| 99 | /* Ctor setup */ |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 100 | explicit Overlay(); |
| 101 | /*Validate index range, abort if invalid */ |
| 102 | void validate(int index); |
| 103 | void dump() const; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 104 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 105 | /* Just like a Facebook for pipes, but much less profile info */ |
| 106 | struct PipeBook { |
| 107 | enum { DPY_PRIMARY, DPY_EXTERNAL, DPY_UNUSED }; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 108 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 109 | void init(); |
| 110 | void destroy(); |
| 111 | /* Check if pipe exists and return true, false otherwise */ |
| 112 | bool valid(); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 113 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 114 | /* Hardware pipe wrapper */ |
| 115 | GenericPipe *mPipe; |
| 116 | /* Display using this pipe. Refer to enums above */ |
| 117 | int mDisplay; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 118 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 119 | /* operations on bitmap */ |
| 120 | static bool pipeUsageUnchanged(); |
| 121 | static void setUse(int index); |
| 122 | static void resetUse(int index); |
| 123 | static bool isUsed(int index); |
| 124 | static bool isNotUsed(int index); |
| 125 | static void save(); |
| 126 | |
| 127 | static void setAllocation(int index); |
| 128 | static void resetAllocation(int index); |
| 129 | static bool isAllocated(int index); |
| 130 | static bool isNotAllocated(int index); |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 131 | |
Sushil Chauhan | 07a2c76 | 2013-03-06 15:36:49 -0800 | [diff] [blame] | 132 | static utils::eMdpPipeType getPipeType(utils::eDest dest); |
| 133 | static const char* getDestStr(utils::eDest dest); |
| 134 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 135 | static int NUM_PIPES; |
Sushil Chauhan | 07a2c76 | 2013-03-06 15:36:49 -0800 | [diff] [blame] | 136 | static utils::eMdpPipeType pipeTypeLUT[utils::OV_MAX]; |
| 137 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 138 | |
| 139 | private: |
| 140 | //usage tracks if a successful commit happened. So a pipe could be |
| 141 | //allocated to a display, but it may not end up using it for various |
| 142 | //reasons. If one display actually uses a pipe then it amy not be |
| 143 | //used by another display, without an UNSET in between. |
| 144 | static int sPipeUsageBitmap; |
| 145 | static int sLastUsageBitmap; |
| 146 | //Tracks which pipe objects are allocated. This does not imply that they |
| 147 | //will actually be used. For example, a display might choose to acquire |
| 148 | //3 pipe objects in one shot and proceed with config only if it gets all |
| 149 | //3. The bitmap helps allocate different pipe objects on each request. |
| 150 | static int sAllocatedBitmap; |
| 151 | }; |
| 152 | |
| 153 | PipeBook mPipeBook[utils::OV_INVALID]; //Used as max |
| 154 | |
| 155 | /* Dump string */ |
| 156 | char mDumpStr[256]; |
| 157 | |
| 158 | /* Singleton Instance*/ |
| 159 | static Overlay *sInstance; |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 160 | static int sExtFbIndex; |
Saurabh Shah | 85234ec | 2013-04-12 17:09:00 -0700 | [diff] [blame] | 161 | static int sDMAMode; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 162 | }; |
| 163 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 164 | inline void Overlay::validate(int index) { |
| 165 | OVASSERT(index >=0 && index < PipeBook::NUM_PIPES, \ |
| 166 | "%s, Index out of bounds: %d", __FUNCTION__, index); |
| 167 | OVASSERT(mPipeBook[index].valid(), "Pipe does not exist %s", |
Sushil Chauhan | 07a2c76 | 2013-03-06 15:36:49 -0800 | [diff] [blame] | 168 | PipeBook::getDestStr((utils::eDest)index)); |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 169 | } |
| 170 | |
Jeykumar Sankaran | ccb4460 | 2013-01-03 12:48:22 -0800 | [diff] [blame] | 171 | inline int Overlay::availablePipes(int dpy) { |
| 172 | int avail = 0; |
| 173 | for(int i = 0; i < PipeBook::NUM_PIPES; i++) { |
| 174 | if((mPipeBook[i].mDisplay == PipeBook::DPY_UNUSED || |
| 175 | mPipeBook[i].mDisplay == dpy) && PipeBook::isNotAllocated(i)) { |
| 176 | avail++; |
| 177 | } |
| 178 | } |
| 179 | return avail; |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 180 | } |
| 181 | |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 182 | inline void Overlay::setExtFbNum(int fbNum) { |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 183 | sExtFbIndex = fbNum; |
| 184 | } |
| 185 | |
| 186 | inline int Overlay::getExtFbNum() { |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 187 | return sExtFbIndex; |
| 188 | } |
| 189 | |
Saurabh Shah | 85234ec | 2013-04-12 17:09:00 -0700 | [diff] [blame] | 190 | inline void Overlay::setDMAMode(const int& mode) { |
| 191 | if(mode == DMA_LINE_MODE || mode == DMA_BLOCK_MODE) |
| 192 | sDMAMode = mode; |
| 193 | } |
| 194 | |
| 195 | inline int Overlay::getDMAMode() { |
| 196 | return sDMAMode; |
| 197 | } |
| 198 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 199 | inline bool Overlay::PipeBook::valid() { |
| 200 | return (mPipe != NULL); |
| 201 | } |
| 202 | |
| 203 | inline bool Overlay::PipeBook::pipeUsageUnchanged() { |
| 204 | return (sPipeUsageBitmap == sLastUsageBitmap); |
| 205 | } |
| 206 | |
| 207 | inline void Overlay::PipeBook::setUse(int index) { |
| 208 | sPipeUsageBitmap |= (1 << index); |
| 209 | } |
| 210 | |
| 211 | inline void Overlay::PipeBook::resetUse(int index) { |
| 212 | sPipeUsageBitmap &= ~(1 << index); |
| 213 | } |
| 214 | |
| 215 | inline bool Overlay::PipeBook::isUsed(int index) { |
| 216 | return sPipeUsageBitmap & (1 << index); |
| 217 | } |
| 218 | |
| 219 | inline bool Overlay::PipeBook::isNotUsed(int index) { |
| 220 | return !isUsed(index); |
| 221 | } |
| 222 | |
| 223 | inline void Overlay::PipeBook::save() { |
| 224 | sLastUsageBitmap = sPipeUsageBitmap; |
| 225 | } |
| 226 | |
| 227 | inline void Overlay::PipeBook::setAllocation(int index) { |
| 228 | sAllocatedBitmap |= (1 << index); |
| 229 | } |
| 230 | |
| 231 | inline void Overlay::PipeBook::resetAllocation(int index) { |
| 232 | sAllocatedBitmap &= ~(1 << index); |
| 233 | } |
| 234 | |
| 235 | inline bool Overlay::PipeBook::isAllocated(int index) { |
| 236 | return sAllocatedBitmap & (1 << index); |
| 237 | } |
| 238 | |
| 239 | inline bool Overlay::PipeBook::isNotAllocated(int index) { |
| 240 | return !isAllocated(index); |
| 241 | } |
| 242 | |
Sushil Chauhan | 07a2c76 | 2013-03-06 15:36:49 -0800 | [diff] [blame] | 243 | inline utils::eMdpPipeType Overlay::PipeBook::getPipeType(utils::eDest dest) { |
| 244 | return pipeTypeLUT[(int)dest]; |
| 245 | } |
| 246 | |
| 247 | inline const char* Overlay::PipeBook::getDestStr(utils::eDest dest) { |
| 248 | switch(getPipeType(dest)) { |
| 249 | case utils::OV_MDP_PIPE_RGB: return "RGB"; |
| 250 | case utils::OV_MDP_PIPE_VG: return "VG"; |
| 251 | case utils::OV_MDP_PIPE_DMA: return "DMA"; |
| 252 | default: return "Invalid"; |
| 253 | } |
| 254 | return "Invalid"; |
| 255 | } |
| 256 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 257 | }; // overlay |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 258 | |
| 259 | #endif // OVERLAY_H |