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