overlay.h revision a8c3d11acf21811ee74589d08dbcc037cd763526
1/* 2* Copyright (c) 2011-2013, The Linux Foundation. All rights reserved. 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. 13* * Neither the name of The Linux Foundation. nor the names of its 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" 34#include "utils/threads.h" 35 36struct MetaData_t; 37 38namespace overlay { 39class GenericPipe; 40 41class Overlay : utils::NoCopy { 42public: 43 enum { DMA_BLOCK_MODE, DMA_LINE_MODE }; 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 { MIXER_LEFT, MIXER_RIGHT, MIXER_UNUSED }; 50 enum { MIXER_DEFAULT = MIXER_LEFT, MIXER_MAX = MIXER_UNUSED }; 51 enum { MAX_FB_DEVICES = DPY_MAX }; 52 53 /* dtor close */ 54 ~Overlay(); 55 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(); 60 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(); 67 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 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); 76 77 void setSource(const utils::PipeArgs args, utils::eDest dest); 78 void setCrop(const utils::Dim& d, utils::eDest dest); 79 void setTransform(const int orientation, utils::eDest dest); 80 void setPosition(const utils::Dim& dim, utils::eDest dest); 81 void setVisualParams(const MetaData_t& data, utils::eDest dest); 82 bool commit(utils::eDest dest); 83 bool queueBuffer(int fd, uint32_t offset, utils::eDest dest); 84 85 /* Closes open pipes, called during startup */ 86 static int initOverlay(); 87 /* Returns the singleton instance of overlay */ 88 static Overlay* getInstance(); 89 /* Returns available ("unallocated") pipes for a display's mixer */ 90 int availablePipes(int dpy, int mixer); 91 /* Returns if any of the requested pipe type is attached to any of the 92 * displays 93 */ 94 bool isPipeTypeAttached(utils::eMdpPipeType type); 95 /* set the framebuffer index for external display */ 96 void setExtFbNum(int fbNum); 97 /* Returns framebuffer index of the current external display */ 98 /* TODO Deprecate */ 99 int getExtFbNum(); 100 /* Returns pipe dump. Expects a NULL terminated buffer of big enough size 101 * to populate. 102 */ 103 void getDump(char *buf, size_t len); 104 /* Reset usage and allocation bits on all pipes for given display */ 105 void clear(int dpy); 106 static void setDMAMode(const int& mode); 107 static int getDMAMode(); 108 /* Returns the framebuffer node backing up the display */ 109 static int getFbForDpy(const int& dpy); 110 static bool displayCommit(const int& fd); 111 112private: 113 /* Ctor setup */ 114 explicit Overlay(); 115 /*Validate index range, abort if invalid */ 116 void validate(int index); 117 void dump() const; 118 119 /* Just like a Facebook for pipes, but much less profile info */ 120 struct PipeBook { 121 void init(); 122 void destroy(); 123 /* Check if pipe exists and return true, false otherwise */ 124 bool valid(); 125 126 /* Hardware pipe wrapper */ 127 GenericPipe *mPipe; 128 /* Display using this pipe. Refer to enums above */ 129 int mDisplay; 130 /* Mixer within a split display this pipe is attached to */ 131 int mMixer; 132 133 /* operations on bitmap */ 134 static bool pipeUsageUnchanged(); 135 static void setUse(int index); 136 static void resetUse(int index); 137 static bool isUsed(int index); 138 static bool isNotUsed(int index); 139 static void save(); 140 141 static void setAllocation(int index); 142 static void resetAllocation(int index); 143 static bool isAllocated(int index); 144 static bool isNotAllocated(int index); 145 146 static utils::eMdpPipeType getPipeType(utils::eDest dest); 147 static const char* getDestStr(utils::eDest dest); 148 149 static int NUM_PIPES; 150 static utils::eMdpPipeType pipeTypeLUT[utils::OV_MAX]; 151 152 153 private: 154 //usage tracks if a successful commit happened. So a pipe could be 155 //allocated to a display, but it may not end up using it for various 156 //reasons. If one display actually uses a pipe then it amy not be 157 //used by another display, without an UNSET in between. 158 static int sPipeUsageBitmap; 159 static int sLastUsageBitmap; 160 //Tracks which pipe objects are allocated. This does not imply that they 161 //will actually be used. For example, a display might choose to acquire 162 //3 pipe objects in one shot and proceed with config only if it gets all 163 //3. The bitmap helps allocate different pipe objects on each request. 164 static int sAllocatedBitmap; 165 }; 166 167 PipeBook mPipeBook[utils::OV_INVALID]; //Used as max 168 169 /* Dump string */ 170 char mDumpStr[1024]; 171 172 /* Singleton Instance*/ 173 static Overlay *sInstance; 174 //TODO Deprecate 175 static int sExtFbIndex; 176 static int sDpyFbMap[DPY_MAX]; 177 static int sDMAMode; 178}; 179 180inline void Overlay::validate(int index) { 181 OVASSERT(index >=0 && index < PipeBook::NUM_PIPES, \ 182 "%s, Index out of bounds: %d", __FUNCTION__, index); 183 OVASSERT(mPipeBook[index].valid(), "Pipe does not exist %s", 184 PipeBook::getDestStr((utils::eDest)index)); 185} 186 187inline int Overlay::availablePipes(int dpy, int mixer) { 188 int avail = 0; 189 for(int i = 0; i < PipeBook::NUM_PIPES; i++) { 190 if( (mPipeBook[i].mDisplay == DPY_UNUSED || 191 mPipeBook[i].mDisplay == dpy) && 192 (mPipeBook[i].mMixer == MIXER_UNUSED || 193 mPipeBook[i].mMixer == mixer) && 194 PipeBook::isNotAllocated(i) && 195 !(Overlay::getDMAMode() == Overlay::DMA_BLOCK_MODE && 196 PipeBook::getPipeType((utils::eDest)i) == 197 utils::OV_MDP_PIPE_DMA)) { 198 avail++; 199 } 200 } 201 return avail; 202} 203 204inline void Overlay::setExtFbNum(int fbNum) { 205 sExtFbIndex = fbNum; 206} 207 208inline int Overlay::getExtFbNum() { 209 return sExtFbIndex; 210} 211 212inline void Overlay::setDMAMode(const int& mode) { 213 if(mode == DMA_LINE_MODE || mode == DMA_BLOCK_MODE) 214 sDMAMode = mode; 215} 216 217inline int Overlay::getDMAMode() { 218 return sDMAMode; 219} 220 221inline int Overlay::getFbForDpy(const int& dpy) { 222 OVASSERT(dpy >= 0 && dpy < DPY_MAX, "Invalid dpy %d", dpy); 223 return sDpyFbMap[dpy]; 224} 225 226inline bool Overlay::PipeBook::valid() { 227 return (mPipe != NULL); 228} 229 230inline bool Overlay::PipeBook::pipeUsageUnchanged() { 231 return (sPipeUsageBitmap == sLastUsageBitmap); 232} 233 234inline void Overlay::PipeBook::setUse(int index) { 235 sPipeUsageBitmap |= (1 << index); 236} 237 238inline void Overlay::PipeBook::resetUse(int index) { 239 sPipeUsageBitmap &= ~(1 << index); 240} 241 242inline bool Overlay::PipeBook::isUsed(int index) { 243 return sPipeUsageBitmap & (1 << index); 244} 245 246inline bool Overlay::PipeBook::isNotUsed(int index) { 247 return !isUsed(index); 248} 249 250inline void Overlay::PipeBook::save() { 251 sLastUsageBitmap = sPipeUsageBitmap; 252} 253 254inline void Overlay::PipeBook::setAllocation(int index) { 255 sAllocatedBitmap |= (1 << index); 256} 257 258inline void Overlay::PipeBook::resetAllocation(int index) { 259 sAllocatedBitmap &= ~(1 << index); 260} 261 262inline bool Overlay::PipeBook::isAllocated(int index) { 263 return sAllocatedBitmap & (1 << index); 264} 265 266inline bool Overlay::PipeBook::isNotAllocated(int index) { 267 return !isAllocated(index); 268} 269 270inline utils::eMdpPipeType Overlay::PipeBook::getPipeType(utils::eDest dest) { 271 return pipeTypeLUT[(int)dest]; 272} 273 274inline const char* Overlay::PipeBook::getDestStr(utils::eDest dest) { 275 switch(getPipeType(dest)) { 276 case utils::OV_MDP_PIPE_RGB: return "RGB"; 277 case utils::OV_MDP_PIPE_VG: return "VG"; 278 case utils::OV_MDP_PIPE_DMA: return "DMA"; 279 default: return "Invalid"; 280 } 281 return "Invalid"; 282} 283 284}; // overlay 285 286#endif // OVERLAY_H 287