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 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 30 | #include "overlay.h" |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 31 | #include "pipes/overlayGenPipe.h" |
| 32 | #include "mdp_version.h" |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 33 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 34 | #define PIPE_DEBUG 0 |
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 | using namespace utils; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 38 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 39 | Overlay::Overlay() { |
| 40 | int numPipes = 0; |
| 41 | int mdpVersion = qdutils::MDPVersion::getInstance().getMDPVersion(); |
| 42 | if (mdpVersion > qdutils::MDP_V3_1) numPipes = 4; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame^] | 43 | if (mdpVersion >= qdutils::MDSS_V5) numPipes = 8; |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 44 | |
| 45 | PipeBook::NUM_PIPES = numPipes; |
| 46 | for(int i = 0; i < PipeBook::NUM_PIPES; i++) { |
| 47 | mPipeBook[i].init(); |
Naseer Ahmed | 1ddf366 | 2012-07-31 19:14:18 -0700 | [diff] [blame] | 48 | } |
Naseer Ahmed | 1ddf366 | 2012-07-31 19:14:18 -0700 | [diff] [blame] | 49 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 50 | mDumpStr[0] = '\0'; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | Overlay::~Overlay() { |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 54 | for(int i = 0; i < PipeBook::NUM_PIPES; i++) { |
| 55 | mPipeBook[i].destroy(); |
| 56 | } |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 57 | } |
| 58 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 59 | void Overlay::configBegin() { |
| 60 | for(int i = 0; i < PipeBook::NUM_PIPES; i++) { |
| 61 | //Mark as available for this round. |
| 62 | PipeBook::resetUse(i); |
| 63 | PipeBook::resetAllocation(i); |
| 64 | } |
| 65 | mDumpStr[0] = '\0'; |
| 66 | } |
| 67 | |
| 68 | void Overlay::configDone() { |
| 69 | if(PipeBook::pipeUsageUnchanged()) return; |
| 70 | |
| 71 | for(int i = 0; i < PipeBook::NUM_PIPES; i++) { |
| 72 | if(PipeBook::isNotUsed(i)) { |
| 73 | //Forces UNSET on pipes, flushes rotator memory and session, closes |
| 74 | //fds |
| 75 | if(mPipeBook[i].valid()) { |
| 76 | char str[32]; |
| 77 | sprintf(str, "Unset pipe=%s dpy=%d; ", getDestStr((eDest)i), |
| 78 | mPipeBook[i].mDisplay); |
| 79 | strncat(mDumpStr, str, strlen(str)); |
| 80 | } |
| 81 | mPipeBook[i].destroy(); |
Naseer Ahmed | 1ddf366 | 2012-07-31 19:14:18 -0700 | [diff] [blame] | 82 | } |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 83 | } |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 84 | dump(); |
| 85 | PipeBook::save(); |
| 86 | } |
| 87 | |
| 88 | eDest Overlay::nextPipe(eMdpPipeType type, int dpy) { |
| 89 | eDest dest = OV_INVALID; |
| 90 | |
| 91 | for(int i = 0; i < PipeBook::NUM_PIPES; i++) { |
| 92 | //Match requested pipe type |
| 93 | if(type == OV_MDP_PIPE_ANY || type == getPipeType((eDest)i)) { |
| 94 | //If the pipe is not allocated to any display or used by the |
| 95 | //requesting display already in previous round. |
| 96 | if((mPipeBook[i].mDisplay == PipeBook::DPY_UNUSED || |
| 97 | mPipeBook[i].mDisplay == dpy) && |
| 98 | PipeBook::isNotAllocated(i)) { |
| 99 | dest = (eDest)i; |
| 100 | PipeBook::setAllocation(i); |
| 101 | break; |
| 102 | } |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | if(dest != OV_INVALID) { |
| 107 | int index = (int)dest; |
| 108 | //If the pipe is not registered with any display OR if the pipe is |
| 109 | //requested again by the same display using it, then go ahead. |
| 110 | mPipeBook[index].mDisplay = dpy; |
| 111 | if(not mPipeBook[index].valid()) { |
| 112 | mPipeBook[index].mPipe = new GenericPipe(dpy); |
| 113 | char str[32]; |
| 114 | snprintf(str, 32, "Set pipe=%s dpy=%d; ", getDestStr(dest), dpy); |
| 115 | strncat(mDumpStr, str, strlen(str)); |
| 116 | } |
| 117 | } else { |
| 118 | ALOGD_IF(PIPE_DEBUG, "Pipe unavailable type=%d display=%d", |
| 119 | (int)type, dpy); |
| 120 | } |
| 121 | |
| 122 | return dest; |
| 123 | } |
| 124 | |
| 125 | bool Overlay::commit(utils::eDest dest) { |
| 126 | bool ret = false; |
| 127 | int index = (int)dest; |
| 128 | validate(index); |
| 129 | |
| 130 | if(mPipeBook[index].mPipe->commit()) { |
| 131 | ret = true; |
| 132 | PipeBook::setUse((int)dest); |
| 133 | } else { |
| 134 | PipeBook::resetUse((int)dest); |
| 135 | } |
| 136 | return ret; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 137 | } |
| 138 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 139 | bool Overlay::queueBuffer(int fd, uint32_t offset, |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 140 | utils::eDest dest) { |
| 141 | int index = (int)dest; |
| 142 | bool ret = false; |
| 143 | validate(index); |
| 144 | //Queue only if commit() has succeeded (and the bit set) |
| 145 | if(PipeBook::isUsed((int)dest)) { |
| 146 | ret = mPipeBook[index].mPipe->queueBuffer(fd, offset); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 147 | } |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 148 | return ret; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 149 | } |
| 150 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 151 | void Overlay::setCrop(const utils::Dim& d, |
| 152 | utils::eDest dest) { |
| 153 | int index = (int)dest; |
| 154 | validate(index); |
| 155 | mPipeBook[index].mPipe->setCrop(d); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 156 | } |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 157 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 158 | void Overlay::setPosition(const utils::Dim& d, |
| 159 | utils::eDest dest) { |
| 160 | int index = (int)dest; |
| 161 | validate(index); |
| 162 | mPipeBook[index].mPipe->setPosition(d); |
| 163 | } |
| 164 | |
| 165 | void Overlay::setTransform(const int orient, |
| 166 | utils::eDest dest) { |
| 167 | int index = (int)dest; |
| 168 | validate(index); |
| 169 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 170 | utils::eTransform transform = |
| 171 | static_cast<utils::eTransform>(orient); |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 172 | mPipeBook[index].mPipe->setTransform(transform); |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 173 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | void Overlay::setSource(const utils::PipeArgs args, |
| 177 | utils::eDest dest) { |
| 178 | int index = (int)dest; |
| 179 | validate(index); |
| 180 | |
| 181 | PipeArgs newArgs(args); |
| 182 | if(dest == OV_VG0 || dest == OV_VG1) { |
| 183 | setMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_SHARE); |
| 184 | } else { |
| 185 | clearMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_SHARE); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 186 | } |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame^] | 187 | |
| 188 | if(dest == OV_DMA0 || dest == OV_DMA1) { |
| 189 | setMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_FORCE_DMA); |
| 190 | } else { |
| 191 | clearMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_FORCE_DMA); |
| 192 | } |
| 193 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 194 | mPipeBook[index].mPipe->setSource(newArgs); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 195 | } |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 196 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 197 | Overlay* Overlay::getInstance() { |
| 198 | if(sInstance == NULL) { |
| 199 | sInstance = new Overlay(); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 200 | } |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 201 | return sInstance; |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | void Overlay::initOverlay() { |
| 205 | if(utils::initOverlay() == -1) { |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 206 | ALOGE("%s failed", __FUNCTION__); |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 207 | } |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 208 | } |
| 209 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 210 | void Overlay::dump() const { |
| 211 | if(strlen(mDumpStr)) { //dump only on state change |
Saurabh Shah | 0d0a7cb | 2013-02-12 17:58:19 -0800 | [diff] [blame] | 212 | ALOGD_IF(PIPE_DEBUG, "%s\n", mDumpStr); |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 213 | } |
| 214 | } |
| 215 | |
Saurabh Shah | 0d0a7cb | 2013-02-12 17:58:19 -0800 | [diff] [blame] | 216 | void Overlay::getDump(char *buf, size_t len) { |
| 217 | int totalPipes = 0; |
| 218 | const char *str = "\nOverlay State\n==========================\n"; |
| 219 | strncat(buf, str, strlen(str)); |
| 220 | for(int i = 0; i < PipeBook::NUM_PIPES; i++) { |
| 221 | if(mPipeBook[i].valid()) { |
| 222 | mPipeBook[i].mPipe->getDump(buf, len); |
| 223 | char str[64] = {'\0'}; |
| 224 | snprintf(str, 64, "Attached to dpy=%d\n\n", mPipeBook[i].mDisplay); |
| 225 | strncat(buf, str, strlen(str)); |
| 226 | totalPipes++; |
| 227 | } |
| 228 | } |
| 229 | char str_pipes[64] = {'\0'}; |
| 230 | snprintf(str_pipes, 64, "Pipes used=%d\n\n", totalPipes); |
| 231 | strncat(buf, str_pipes, strlen(str_pipes)); |
| 232 | } |
| 233 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 234 | void Overlay::PipeBook::init() { |
| 235 | mPipe = NULL; |
| 236 | mDisplay = DPY_UNUSED; |
| 237 | } |
| 238 | |
| 239 | void Overlay::PipeBook::destroy() { |
| 240 | if(mPipe) { |
| 241 | delete mPipe; |
| 242 | mPipe = NULL; |
| 243 | } |
| 244 | mDisplay = DPY_UNUSED; |
| 245 | } |
| 246 | |
| 247 | Overlay* Overlay::sInstance = 0; |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 248 | int Overlay::sExtFbIndex = 1; |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 249 | int Overlay::PipeBook::NUM_PIPES = 0; |
| 250 | int Overlay::PipeBook::sPipeUsageBitmap = 0; |
| 251 | int Overlay::PipeBook::sLastUsageBitmap = 0; |
| 252 | int Overlay::PipeBook::sAllocatedBitmap = 0; |
| 253 | |
| 254 | }; // namespace overlay |