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