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(); |
| 74 | /* Returns total of available ("unallocated") pipes */ |
| 75 | static int availablePipes(); |
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(); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 80 | |
| 81 | private: |
| 82 | /* Ctor setup */ |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 83 | explicit Overlay(); |
| 84 | /*Validate index range, abort if invalid */ |
| 85 | void validate(int index); |
| 86 | void dump() const; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 87 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 88 | /* Just like a Facebook for pipes, but much less profile info */ |
| 89 | struct PipeBook { |
| 90 | enum { DPY_PRIMARY, DPY_EXTERNAL, DPY_UNUSED }; |
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 | void init(); |
| 93 | void destroy(); |
| 94 | /* Check if pipe exists and return true, false otherwise */ |
| 95 | bool valid(); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 96 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 97 | /* Hardware pipe wrapper */ |
| 98 | GenericPipe *mPipe; |
| 99 | /* Display using this pipe. Refer to enums above */ |
| 100 | int mDisplay; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 101 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 102 | /* operations on bitmap */ |
| 103 | static bool pipeUsageUnchanged(); |
| 104 | static void setUse(int index); |
| 105 | static void resetUse(int index); |
| 106 | static bool isUsed(int index); |
| 107 | static bool isNotUsed(int index); |
| 108 | static void save(); |
| 109 | |
| 110 | static void setAllocation(int index); |
| 111 | static void resetAllocation(int index); |
| 112 | static bool isAllocated(int index); |
| 113 | static bool isNotAllocated(int index); |
| 114 | /* Returns total of available ("unallocated") pipes */ |
| 115 | static int availablePipes(); |
| 116 | |
| 117 | static int NUM_PIPES; |
| 118 | |
| 119 | private: |
| 120 | //usage tracks if a successful commit happened. So a pipe could be |
| 121 | //allocated to a display, but it may not end up using it for various |
| 122 | //reasons. If one display actually uses a pipe then it amy not be |
| 123 | //used by another display, without an UNSET in between. |
| 124 | static int sPipeUsageBitmap; |
| 125 | static int sLastUsageBitmap; |
| 126 | //Tracks which pipe objects are allocated. This does not imply that they |
| 127 | //will actually be used. For example, a display might choose to acquire |
| 128 | //3 pipe objects in one shot and proceed with config only if it gets all |
| 129 | //3. The bitmap helps allocate different pipe objects on each request. |
| 130 | static int sAllocatedBitmap; |
| 131 | }; |
| 132 | |
| 133 | PipeBook mPipeBook[utils::OV_INVALID]; //Used as max |
| 134 | |
| 135 | /* Dump string */ |
| 136 | char mDumpStr[256]; |
| 137 | |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame^] | 138 | mutable android::Mutex mOvExtFbLock; |
| 139 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 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 | |
| 152 | inline int Overlay::availablePipes() { |
| 153 | return PipeBook::availablePipes(); |
| 154 | } |
| 155 | |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame^] | 156 | inline void Overlay::setExtFbNum(int fbNum) { |
| 157 | android::Mutex::Autolock lock(mOvExtFbLock); |
| 158 | sExtFbIndex = fbNum; |
| 159 | } |
| 160 | |
| 161 | inline int Overlay::getExtFbNum() { |
| 162 | android::Mutex::Autolock lock(mOvExtFbLock); |
| 163 | return sExtFbIndex; |
| 164 | } |
| 165 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 166 | inline int Overlay::PipeBook::availablePipes() { |
| 167 | int used = 0; |
| 168 | int bmp = sAllocatedBitmap; |
| 169 | for(; bmp; used++) { |
| 170 | //clearing from lsb |
| 171 | bmp = bmp & (bmp - 1); |
| 172 | } |
| 173 | return NUM_PIPES - used; |
| 174 | } |
| 175 | |
| 176 | inline bool Overlay::PipeBook::valid() { |
| 177 | return (mPipe != NULL); |
| 178 | } |
| 179 | |
| 180 | inline bool Overlay::PipeBook::pipeUsageUnchanged() { |
| 181 | return (sPipeUsageBitmap == sLastUsageBitmap); |
| 182 | } |
| 183 | |
| 184 | inline void Overlay::PipeBook::setUse(int index) { |
| 185 | sPipeUsageBitmap |= (1 << index); |
| 186 | } |
| 187 | |
| 188 | inline void Overlay::PipeBook::resetUse(int index) { |
| 189 | sPipeUsageBitmap &= ~(1 << index); |
| 190 | } |
| 191 | |
| 192 | inline bool Overlay::PipeBook::isUsed(int index) { |
| 193 | return sPipeUsageBitmap & (1 << index); |
| 194 | } |
| 195 | |
| 196 | inline bool Overlay::PipeBook::isNotUsed(int index) { |
| 197 | return !isUsed(index); |
| 198 | } |
| 199 | |
| 200 | inline void Overlay::PipeBook::save() { |
| 201 | sLastUsageBitmap = sPipeUsageBitmap; |
| 202 | } |
| 203 | |
| 204 | inline void Overlay::PipeBook::setAllocation(int index) { |
| 205 | sAllocatedBitmap |= (1 << index); |
| 206 | } |
| 207 | |
| 208 | inline void Overlay::PipeBook::resetAllocation(int index) { |
| 209 | sAllocatedBitmap &= ~(1 << index); |
| 210 | } |
| 211 | |
| 212 | inline bool Overlay::PipeBook::isAllocated(int index) { |
| 213 | return sAllocatedBitmap & (1 << index); |
| 214 | } |
| 215 | |
| 216 | inline bool Overlay::PipeBook::isNotAllocated(int index) { |
| 217 | return !isAllocated(index); |
| 218 | } |
| 219 | |
| 220 | }; // overlay |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 221 | |
| 222 | #endif // OVERLAY_H |