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