Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1 | /* |
Sushil Chauhan | 07a2c76 | 2013-03-06 15:36:49 -0800 | [diff] [blame] | 2 | * Copyright (c) 2011-2013, 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 | |
Saurabh Shah | b8f58e2 | 2013-09-26 16:20:07 -0700 | [diff] [blame] | 30 | #include <dlfcn.h> |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 31 | #include "overlay.h" |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 32 | #include "pipes/overlayGenPipe.h" |
| 33 | #include "mdp_version.h" |
Saurabh Shah | 5daeee5 | 2013-01-23 16:52:26 +0800 | [diff] [blame] | 34 | #include "qdMetaData.h" |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 35 | |
Saurabh Shah | b8f58e2 | 2013-09-26 16:20:07 -0700 | [diff] [blame] | 36 | #ifdef USES_QSEED_SCALAR |
| 37 | #include <scale/scale.h> |
| 38 | using namespace scale; |
| 39 | #endif |
| 40 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 41 | #define PIPE_DEBUG 0 |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 42 | |
| 43 | namespace overlay { |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 44 | using namespace utils; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 45 | |
Saurabh Shah | b8f58e2 | 2013-09-26 16:20:07 -0700 | [diff] [blame] | 46 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 47 | Overlay::Overlay() { |
Sushil Chauhan | 07a2c76 | 2013-03-06 15:36:49 -0800 | [diff] [blame] | 48 | PipeBook::NUM_PIPES = qdutils::MDPVersion::getInstance().getTotalPipes(); |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 49 | for(int i = 0; i < PipeBook::NUM_PIPES; i++) { |
| 50 | mPipeBook[i].init(); |
Naseer Ahmed | 1ddf366 | 2012-07-31 19:14:18 -0700 | [diff] [blame] | 51 | } |
Naseer Ahmed | 1ddf366 | 2012-07-31 19:14:18 -0700 | [diff] [blame] | 52 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 53 | mDumpStr[0] = '\0'; |
Saurabh Shah | b8f58e2 | 2013-09-26 16:20:07 -0700 | [diff] [blame] | 54 | initScalar(); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | Overlay::~Overlay() { |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 58 | for(int i = 0; i < PipeBook::NUM_PIPES; i++) { |
| 59 | mPipeBook[i].destroy(); |
| 60 | } |
Saurabh Shah | b8f58e2 | 2013-09-26 16:20:07 -0700 | [diff] [blame] | 61 | destroyScalar(); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 62 | } |
| 63 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 64 | void Overlay::configBegin() { |
| 65 | for(int i = 0; i < PipeBook::NUM_PIPES; i++) { |
| 66 | //Mark as available for this round. |
| 67 | PipeBook::resetUse(i); |
| 68 | PipeBook::resetAllocation(i); |
| 69 | } |
Saurabh Shah | 784e985 | 2013-08-21 16:51:21 -0700 | [diff] [blame] | 70 | sForceSetBitmap = 0; |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 71 | mDumpStr[0] = '\0'; |
Saurabh Shah | b8f58e2 | 2013-09-26 16:20:07 -0700 | [diff] [blame] | 72 | |
| 73 | #ifdef USES_QSEED_SCALAR |
| 74 | Scale *scalar = getScalar(); |
| 75 | if(scalar) { |
| 76 | scalar->configBegin(); |
| 77 | } |
| 78 | #endif |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | void Overlay::configDone() { |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 82 | for(int i = 0; i < PipeBook::NUM_PIPES; i++) { |
Zohaib Alam | 4b0a924 | 2013-11-20 23:54:12 -0500 | [diff] [blame^] | 83 | if((PipeBook::isNotUsed(i) && !sessionInProgress((eDest)i)) || |
| 84 | isSessionEnded((eDest)i)) { |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 85 | //Forces UNSET on pipes, flushes rotator memory and session, closes |
| 86 | //fds |
| 87 | if(mPipeBook[i].valid()) { |
| 88 | char str[32]; |
Saurabh Shah | af5f597 | 2013-07-30 13:56:35 -0700 | [diff] [blame] | 89 | sprintf(str, "Unset=%s dpy=%d mix=%d; ", |
| 90 | PipeBook::getDestStr((eDest)i), |
| 91 | mPipeBook[i].mDisplay, mPipeBook[i].mMixer); |
Saurabh Shah | 9dc88fc | 2013-07-15 16:02:30 -0700 | [diff] [blame] | 92 | #if PIPE_DEBUG |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 93 | strncat(mDumpStr, str, strlen(str)); |
Saurabh Shah | 9dc88fc | 2013-07-15 16:02:30 -0700 | [diff] [blame] | 94 | #endif |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 95 | } |
| 96 | mPipeBook[i].destroy(); |
Naseer Ahmed | 1ddf366 | 2012-07-31 19:14:18 -0700 | [diff] [blame] | 97 | } |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 98 | } |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 99 | dump(); |
| 100 | PipeBook::save(); |
Saurabh Shah | b8f58e2 | 2013-09-26 16:20:07 -0700 | [diff] [blame] | 101 | |
| 102 | #ifdef USES_QSEED_SCALAR |
| 103 | Scale *scalar = getScalar(); |
| 104 | if(scalar) { |
| 105 | scalar->configDone(); |
| 106 | } |
| 107 | #endif |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 108 | } |
| 109 | |
Zohaib Alam | 4b0a924 | 2013-11-20 23:54:12 -0500 | [diff] [blame^] | 110 | int Overlay::getPipeId(utils::eDest dest) { |
| 111 | return mPipeBook[(int)dest].mPipe->getPipeId(); |
| 112 | } |
| 113 | |
| 114 | eDest Overlay::getDest(int pipeid) { |
| 115 | eDest dest = OV_INVALID; |
| 116 | // finding the dest corresponding to the given pipe |
| 117 | for(int i=0; i < PipeBook::NUM_PIPES; ++i) { |
| 118 | if(mPipeBook[i].valid() && mPipeBook[i].mPipe->getPipeId() == pipeid) { |
| 119 | return (eDest)i; |
| 120 | } |
| 121 | } |
| 122 | return dest; |
| 123 | } |
| 124 | |
| 125 | eDest Overlay::reservePipe(int pipeid) { |
| 126 | eDest dest = getDest(pipeid); |
| 127 | PipeBook::setAllocation((int)dest); |
| 128 | return dest; |
| 129 | } |
| 130 | |
Saurabh Shah | af5f597 | 2013-07-30 13:56:35 -0700 | [diff] [blame] | 131 | eDest Overlay::nextPipe(eMdpPipeType type, int dpy, int mixer) { |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 132 | eDest dest = OV_INVALID; |
| 133 | |
| 134 | for(int i = 0; i < PipeBook::NUM_PIPES; i++) { |
Saurabh Shah | af5f597 | 2013-07-30 13:56:35 -0700 | [diff] [blame] | 135 | if( (type == OV_MDP_PIPE_ANY || //Pipe type match |
| 136 | type == PipeBook::getPipeType((eDest)i)) && |
| 137 | (mPipeBook[i].mDisplay == DPY_UNUSED || //Free or same display |
| 138 | mPipeBook[i].mDisplay == dpy) && |
| 139 | (mPipeBook[i].mMixer == MIXER_UNUSED || //Free or same mixer |
| 140 | mPipeBook[i].mMixer == mixer) && |
| 141 | PipeBook::isNotAllocated(i) && //Free pipe |
| 142 | !(sDMAMode == DMA_BLOCK_MODE && //DMA pipe in Line mode |
| 143 | PipeBook::getPipeType((eDest)i) == OV_MDP_PIPE_DMA)) { |
| 144 | dest = (eDest)i; |
| 145 | PipeBook::setAllocation(i); |
| 146 | break; |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 147 | } |
| 148 | } |
| 149 | |
| 150 | if(dest != OV_INVALID) { |
| 151 | int index = (int)dest; |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 152 | mPipeBook[index].mDisplay = dpy; |
Saurabh Shah | af5f597 | 2013-07-30 13:56:35 -0700 | [diff] [blame] | 153 | mPipeBook[index].mMixer = mixer; |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 154 | if(not mPipeBook[index].valid()) { |
| 155 | mPipeBook[index].mPipe = new GenericPipe(dpy); |
Zohaib Alam | 4b0a924 | 2013-11-20 23:54:12 -0500 | [diff] [blame^] | 156 | mPipeBook[index].mSession = PipeBook::NONE; |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 157 | char str[32]; |
Saurabh Shah | af5f597 | 2013-07-30 13:56:35 -0700 | [diff] [blame] | 158 | snprintf(str, 32, "Set=%s dpy=%d mix=%d; ", |
| 159 | PipeBook::getDestStr(dest), dpy, mixer); |
Saurabh Shah | 9dc88fc | 2013-07-15 16:02:30 -0700 | [diff] [blame] | 160 | #if PIPE_DEBUG |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 161 | strncat(mDumpStr, str, strlen(str)); |
Saurabh Shah | 9dc88fc | 2013-07-15 16:02:30 -0700 | [diff] [blame] | 162 | #endif |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 163 | } |
| 164 | } else { |
Saurabh Shah | af5f597 | 2013-07-30 13:56:35 -0700 | [diff] [blame] | 165 | ALOGD_IF(PIPE_DEBUG, "Pipe unavailable type=%d display=%d mixer=%d", |
| 166 | (int)type, dpy, mixer); |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | return dest; |
| 170 | } |
| 171 | |
Zohaib Alam | 4b0a924 | 2013-11-20 23:54:12 -0500 | [diff] [blame^] | 172 | void Overlay::endAllSessions() { |
| 173 | for(int i = 0; i < PipeBook::NUM_PIPES; i++) { |
| 174 | if(mPipeBook[i].valid() && mPipeBook[i].mSession==PipeBook::START) |
| 175 | mPipeBook[i].mSession = PipeBook::END; |
| 176 | } |
| 177 | } |
| 178 | |
Saurabh Shah | 0ceeb6a | 2013-04-23 10:46:07 -0700 | [diff] [blame] | 179 | bool Overlay::isPipeTypeAttached(eMdpPipeType type) { |
| 180 | for(int i = 0; i < PipeBook::NUM_PIPES; i++) { |
| 181 | if(type == PipeBook::getPipeType((eDest)i) && |
Saurabh Shah | c8118ac | 2013-06-27 10:03:19 -0700 | [diff] [blame] | 182 | mPipeBook[i].mDisplay != DPY_UNUSED) { |
Saurabh Shah | 0ceeb6a | 2013-04-23 10:46:07 -0700 | [diff] [blame] | 183 | return true; |
| 184 | } |
| 185 | } |
| 186 | return false; |
| 187 | } |
| 188 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 189 | bool Overlay::commit(utils::eDest dest) { |
| 190 | bool ret = false; |
| 191 | int index = (int)dest; |
| 192 | validate(index); |
| 193 | |
| 194 | if(mPipeBook[index].mPipe->commit()) { |
| 195 | ret = true; |
| 196 | PipeBook::setUse((int)dest); |
Saurabh Shah | 784e985 | 2013-08-21 16:51:21 -0700 | [diff] [blame] | 197 | if(sForceSetBitmap & (1 << mPipeBook[index].mDisplay)) { |
| 198 | mPipeBook[index].mPipe->forceSet(); |
| 199 | } |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 200 | } else { |
Sushil Chauhan | e0dff93 | 2013-03-01 14:33:18 -0800 | [diff] [blame] | 201 | int dpy = mPipeBook[index].mDisplay; |
| 202 | for(int i = 0; i < PipeBook::NUM_PIPES; i++) |
Saurabh Shah | df0be75 | 2013-05-23 14:40:00 -0700 | [diff] [blame] | 203 | if (mPipeBook[i].mDisplay == dpy) { |
Sushil Chauhan | e0dff93 | 2013-03-01 14:33:18 -0800 | [diff] [blame] | 204 | PipeBook::resetAllocation(i); |
Saurabh Shah | df0be75 | 2013-05-23 14:40:00 -0700 | [diff] [blame] | 205 | PipeBook::resetUse(i); |
| 206 | if(mPipeBook[i].valid()) { |
| 207 | mPipeBook[i].mPipe->forceSet(); |
| 208 | } |
| 209 | } |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 210 | } |
| 211 | return ret; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 212 | } |
| 213 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 214 | bool Overlay::queueBuffer(int fd, uint32_t offset, |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 215 | utils::eDest dest) { |
| 216 | int index = (int)dest; |
| 217 | bool ret = false; |
| 218 | validate(index); |
| 219 | //Queue only if commit() has succeeded (and the bit set) |
| 220 | if(PipeBook::isUsed((int)dest)) { |
| 221 | ret = mPipeBook[index].mPipe->queueBuffer(fd, offset); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 222 | } |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 223 | return ret; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 224 | } |
| 225 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 226 | void Overlay::setCrop(const utils::Dim& d, |
| 227 | utils::eDest dest) { |
| 228 | int index = (int)dest; |
| 229 | validate(index); |
| 230 | mPipeBook[index].mPipe->setCrop(d); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 231 | } |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 232 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 233 | void Overlay::setPosition(const utils::Dim& d, |
| 234 | utils::eDest dest) { |
| 235 | int index = (int)dest; |
| 236 | validate(index); |
| 237 | mPipeBook[index].mPipe->setPosition(d); |
| 238 | } |
| 239 | |
| 240 | void Overlay::setTransform(const int orient, |
| 241 | utils::eDest dest) { |
| 242 | int index = (int)dest; |
| 243 | validate(index); |
| 244 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 245 | utils::eTransform transform = |
| 246 | static_cast<utils::eTransform>(orient); |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 247 | mPipeBook[index].mPipe->setTransform(transform); |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 248 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | void Overlay::setSource(const utils::PipeArgs args, |
| 252 | utils::eDest dest) { |
| 253 | int index = (int)dest; |
| 254 | validate(index); |
| 255 | |
| 256 | PipeArgs newArgs(args); |
Sushil Chauhan | 07a2c76 | 2013-03-06 15:36:49 -0800 | [diff] [blame] | 257 | if(PipeBook::getPipeType(dest) == OV_MDP_PIPE_VG) { |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 258 | setMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_SHARE); |
| 259 | } else { |
| 260 | clearMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_SHARE); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 261 | } |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 262 | |
Sushil Chauhan | 07a2c76 | 2013-03-06 15:36:49 -0800 | [diff] [blame] | 263 | if(PipeBook::getPipeType(dest) == OV_MDP_PIPE_DMA) { |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 264 | setMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_FORCE_DMA); |
| 265 | } else { |
| 266 | clearMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_FORCE_DMA); |
| 267 | } |
| 268 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 269 | mPipeBook[index].mPipe->setSource(newArgs); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 270 | } |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 271 | |
Saurabh Shah | 5daeee5 | 2013-01-23 16:52:26 +0800 | [diff] [blame] | 272 | void Overlay::setVisualParams(const MetaData_t& metadata, utils::eDest dest) { |
| 273 | int index = (int)dest; |
| 274 | validate(index); |
| 275 | mPipeBook[index].mPipe->setVisualParams(metadata); |
| 276 | } |
| 277 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 278 | Overlay* Overlay::getInstance() { |
| 279 | if(sInstance == NULL) { |
| 280 | sInstance = new Overlay(); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 281 | } |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 282 | return sInstance; |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 283 | } |
| 284 | |
Sushil Chauhan | 07a2c76 | 2013-03-06 15:36:49 -0800 | [diff] [blame] | 285 | // Clears any VG pipes allocated to the fb devices |
| 286 | // Generates a LUT for pipe types. |
| 287 | int Overlay::initOverlay() { |
| 288 | int mdpVersion = qdutils::MDPVersion::getInstance().getMDPVersion(); |
| 289 | int numPipesXType[OV_MDP_PIPE_ANY] = {0}; |
| 290 | numPipesXType[OV_MDP_PIPE_RGB] = |
| 291 | qdutils::MDPVersion::getInstance().getRGBPipes(); |
| 292 | numPipesXType[OV_MDP_PIPE_VG] = |
| 293 | qdutils::MDPVersion::getInstance().getVGPipes(); |
| 294 | numPipesXType[OV_MDP_PIPE_DMA] = |
| 295 | qdutils::MDPVersion::getInstance().getDMAPipes(); |
| 296 | |
| 297 | int index = 0; |
| 298 | for(int X = 0; X < (int)OV_MDP_PIPE_ANY; X++) { //iterate over types |
| 299 | for(int j = 0; j < numPipesXType[X]; j++) { //iterate over num |
| 300 | PipeBook::pipeTypeLUT[index] = (utils::eMdpPipeType)X; |
| 301 | index++; |
| 302 | } |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 303 | } |
Sushil Chauhan | 07a2c76 | 2013-03-06 15:36:49 -0800 | [diff] [blame] | 304 | |
Xiaoming Zhou | 5eff8b6 | 2013-05-01 20:56:09 -0400 | [diff] [blame] | 305 | if (mdpVersion < qdutils::MDSS_V5 && mdpVersion != qdutils::MDP_V3_0_4) { |
Sushil Chauhan | 07a2c76 | 2013-03-06 15:36:49 -0800 | [diff] [blame] | 306 | msmfb_mixer_info_req req; |
| 307 | mdp_mixer_info *minfo = NULL; |
| 308 | char name[64]; |
| 309 | int fd = -1; |
Saurabh Shah | c8118ac | 2013-06-27 10:03:19 -0700 | [diff] [blame] | 310 | for(int i = 0; i < MAX_FB_DEVICES; i++) { |
Sushil Chauhan | 07a2c76 | 2013-03-06 15:36:49 -0800 | [diff] [blame] | 311 | snprintf(name, 64, FB_DEVICE_TEMPLATE, i); |
| 312 | ALOGD("initoverlay:: opening the device:: %s", name); |
| 313 | fd = ::open(name, O_RDWR, 0); |
| 314 | if(fd < 0) { |
| 315 | ALOGE("cannot open framebuffer(%d)", i); |
| 316 | return -1; |
| 317 | } |
| 318 | //Get the mixer configuration */ |
| 319 | req.mixer_num = i; |
| 320 | if (ioctl(fd, MSMFB_MIXER_INFO, &req) == -1) { |
| 321 | ALOGE("ERROR: MSMFB_MIXER_INFO ioctl failed"); |
| 322 | close(fd); |
| 323 | return -1; |
| 324 | } |
| 325 | minfo = req.info; |
| 326 | for (int j = 0; j < req.cnt; j++) { |
| 327 | ALOGD("ndx=%d num=%d z_order=%d", minfo->pndx, minfo->pnum, |
| 328 | minfo->z_order); |
| 329 | // except the RGB base layer with z_order of -1, clear any |
| 330 | // other pipes connected to mixer. |
| 331 | if((minfo->z_order) != -1) { |
| 332 | int index = minfo->pndx; |
| 333 | ALOGD("Unset overlay with index: %d at mixer %d", index, i); |
| 334 | if(ioctl(fd, MSMFB_OVERLAY_UNSET, &index) == -1) { |
| 335 | ALOGE("ERROR: MSMFB_OVERLAY_UNSET failed"); |
| 336 | close(fd); |
| 337 | return -1; |
| 338 | } |
| 339 | } |
| 340 | minfo++; |
| 341 | } |
| 342 | close(fd); |
| 343 | fd = -1; |
| 344 | } |
| 345 | } |
Saurabh Shah | c8118ac | 2013-06-27 10:03:19 -0700 | [diff] [blame] | 346 | |
| 347 | FILE *displayDeviceFP = NULL; |
| 348 | const int MAX_FRAME_BUFFER_NAME_SIZE = 128; |
| 349 | char fbType[MAX_FRAME_BUFFER_NAME_SIZE]; |
| 350 | char msmFbTypePath[MAX_FRAME_BUFFER_NAME_SIZE]; |
| 351 | const char *strDtvPanel = "dtv panel"; |
| 352 | const char *strWbPanel = "writeback panel"; |
| 353 | |
| 354 | for(int num = 1; num < MAX_FB_DEVICES; num++) { |
| 355 | snprintf (msmFbTypePath, sizeof(msmFbTypePath), |
| 356 | "/sys/class/graphics/fb%d/msm_fb_type", num); |
| 357 | displayDeviceFP = fopen(msmFbTypePath, "r"); |
| 358 | |
| 359 | if(displayDeviceFP){ |
| 360 | fread(fbType, sizeof(char), MAX_FRAME_BUFFER_NAME_SIZE, |
| 361 | displayDeviceFP); |
| 362 | |
| 363 | if(strncmp(fbType, strDtvPanel, strlen(strDtvPanel)) == 0) { |
| 364 | sDpyFbMap[DPY_EXTERNAL] = num; |
| 365 | } else if(strncmp(fbType, strWbPanel, strlen(strWbPanel)) == 0) { |
| 366 | sDpyFbMap[DPY_WRITEBACK] = num; |
| 367 | } |
| 368 | |
| 369 | fclose(displayDeviceFP); |
| 370 | } |
| 371 | } |
| 372 | |
Sushil Chauhan | 07a2c76 | 2013-03-06 15:36:49 -0800 | [diff] [blame] | 373 | return 0; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 374 | } |
| 375 | |
Saurabh Shah | c8118ac | 2013-06-27 10:03:19 -0700 | [diff] [blame] | 376 | bool Overlay::displayCommit(const int& fd) { |
Jeykumar Sankaran | 6a9bb9e | 2013-08-01 14:19:26 -0700 | [diff] [blame] | 377 | utils::Dim roi; |
| 378 | return displayCommit(fd, roi); |
| 379 | } |
| 380 | |
| 381 | bool Overlay::displayCommit(const int& fd, const utils::Dim& roi) { |
Saurabh Shah | c8118ac | 2013-06-27 10:03:19 -0700 | [diff] [blame] | 382 | //Commit |
| 383 | struct mdp_display_commit info; |
| 384 | memset(&info, 0, sizeof(struct mdp_display_commit)); |
| 385 | info.flags = MDP_DISPLAY_COMMIT_OVERLAY; |
Jeykumar Sankaran | 6a9bb9e | 2013-08-01 14:19:26 -0700 | [diff] [blame] | 386 | info.roi.x = roi.x; |
| 387 | info.roi.y = roi.y; |
| 388 | info.roi.w = roi.w; |
| 389 | info.roi.h = roi.h; |
| 390 | |
Saurabh Shah | c8118ac | 2013-06-27 10:03:19 -0700 | [diff] [blame] | 391 | if(!mdp_wrapper::displayCommit(fd, info)) { |
Jeykumar Sankaran | 6a9bb9e | 2013-08-01 14:19:26 -0700 | [diff] [blame] | 392 | ALOGE("%s: commit failed", __func__); |
| 393 | return false; |
Saurabh Shah | c8118ac | 2013-06-27 10:03:19 -0700 | [diff] [blame] | 394 | } |
| 395 | return true; |
| 396 | } |
| 397 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 398 | void Overlay::dump() const { |
Saurabh Shah | 9dc88fc | 2013-07-15 16:02:30 -0700 | [diff] [blame] | 399 | #if PIPE_DEBUG |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 400 | if(strlen(mDumpStr)) { //dump only on state change |
Saurabh Shah | 9dc88fc | 2013-07-15 16:02:30 -0700 | [diff] [blame] | 401 | ALOGD("%s\n", mDumpStr); |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 402 | } |
Saurabh Shah | 9dc88fc | 2013-07-15 16:02:30 -0700 | [diff] [blame] | 403 | #endif |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 404 | } |
| 405 | |
Saurabh Shah | 0d0a7cb | 2013-02-12 17:58:19 -0800 | [diff] [blame] | 406 | void Overlay::getDump(char *buf, size_t len) { |
| 407 | int totalPipes = 0; |
Saurabh Shah | ae61b2b | 2013-04-10 16:37:25 -0700 | [diff] [blame] | 408 | const char *str = "\nOverlay State\n\n"; |
Saurabh Shah | 0d0a7cb | 2013-02-12 17:58:19 -0800 | [diff] [blame] | 409 | strncat(buf, str, strlen(str)); |
| 410 | for(int i = 0; i < PipeBook::NUM_PIPES; i++) { |
| 411 | if(mPipeBook[i].valid()) { |
| 412 | mPipeBook[i].mPipe->getDump(buf, len); |
| 413 | char str[64] = {'\0'}; |
Saurabh Shah | ae61b2b | 2013-04-10 16:37:25 -0700 | [diff] [blame] | 414 | snprintf(str, 64, "Display=%d\n\n", mPipeBook[i].mDisplay); |
Saurabh Shah | 0d0a7cb | 2013-02-12 17:58:19 -0800 | [diff] [blame] | 415 | strncat(buf, str, strlen(str)); |
| 416 | totalPipes++; |
| 417 | } |
| 418 | } |
| 419 | char str_pipes[64] = {'\0'}; |
Saurabh Shah | ae61b2b | 2013-04-10 16:37:25 -0700 | [diff] [blame] | 420 | snprintf(str_pipes, 64, "Pipes=%d\n\n", totalPipes); |
Saurabh Shah | 0d0a7cb | 2013-02-12 17:58:19 -0800 | [diff] [blame] | 421 | strncat(buf, str_pipes, strlen(str_pipes)); |
| 422 | } |
| 423 | |
Sushil Chauhan | bd3ea92 | 2013-05-15 12:25:26 -0700 | [diff] [blame] | 424 | void Overlay::clear(int dpy) { |
| 425 | for(int i = 0; i < PipeBook::NUM_PIPES; i++) { |
| 426 | if (mPipeBook[i].mDisplay == dpy) { |
| 427 | // Mark as available for this round |
| 428 | PipeBook::resetUse(i); |
| 429 | PipeBook::resetAllocation(i); |
Saurabh Shah | df0be75 | 2013-05-23 14:40:00 -0700 | [diff] [blame] | 430 | if(mPipeBook[i].valid()) { |
| 431 | mPipeBook[i].mPipe->forceSet(); |
| 432 | } |
Sushil Chauhan | bd3ea92 | 2013-05-15 12:25:26 -0700 | [diff] [blame] | 433 | } |
| 434 | } |
| 435 | } |
| 436 | |
Saurabh Shah | b8f58e2 | 2013-09-26 16:20:07 -0700 | [diff] [blame] | 437 | void Overlay::initScalar() { |
| 438 | #ifdef USES_QSEED_SCALAR |
| 439 | if(sLibScaleHandle == NULL) { |
| 440 | sLibScaleHandle = dlopen("libscale.so", RTLD_NOW); |
| 441 | } |
| 442 | |
| 443 | if(sLibScaleHandle) { |
| 444 | if(sScale == NULL) { |
| 445 | Scale* (*getInstance)(); |
| 446 | *(void **) &getInstance = dlsym(sLibScaleHandle, "getInstance"); |
| 447 | if(getInstance) { |
| 448 | sScale = getInstance(); |
| 449 | } |
| 450 | } |
| 451 | } |
| 452 | #endif |
| 453 | } |
| 454 | |
| 455 | void Overlay::destroyScalar() { |
| 456 | #ifdef USES_QSEED_SCALAR |
| 457 | if(sLibScaleHandle) { |
| 458 | if(sScale) { |
| 459 | void (*destroyInstance)(Scale*); |
| 460 | *(void **) &destroyInstance = dlsym(sLibScaleHandle, |
| 461 | "destroyInstance"); |
| 462 | if(destroyInstance) { |
| 463 | destroyInstance(sScale); |
| 464 | sScale = NULL; |
| 465 | } |
| 466 | } |
| 467 | dlclose(sLibScaleHandle); |
| 468 | sLibScaleHandle = NULL; |
| 469 | } |
| 470 | #endif |
| 471 | } |
| 472 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 473 | void Overlay::PipeBook::init() { |
| 474 | mPipe = NULL; |
| 475 | mDisplay = DPY_UNUSED; |
Saurabh Shah | af5f597 | 2013-07-30 13:56:35 -0700 | [diff] [blame] | 476 | mMixer = MIXER_UNUSED; |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | void Overlay::PipeBook::destroy() { |
| 480 | if(mPipe) { |
| 481 | delete mPipe; |
| 482 | mPipe = NULL; |
| 483 | } |
| 484 | mDisplay = DPY_UNUSED; |
Saurabh Shah | af5f597 | 2013-07-30 13:56:35 -0700 | [diff] [blame] | 485 | mMixer = MIXER_UNUSED; |
Zohaib Alam | 4b0a924 | 2013-11-20 23:54:12 -0500 | [diff] [blame^] | 486 | mSession = NONE; |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | Overlay* Overlay::sInstance = 0; |
Saurabh Shah | c8118ac | 2013-06-27 10:03:19 -0700 | [diff] [blame] | 490 | int Overlay::sDpyFbMap[DPY_MAX] = {0, -1, -1}; |
Saurabh Shah | 85234ec | 2013-04-12 17:09:00 -0700 | [diff] [blame] | 491 | int Overlay::sDMAMode = DMA_LINE_MODE; |
Saurabh Shah | 784e985 | 2013-08-21 16:51:21 -0700 | [diff] [blame] | 492 | int Overlay::sForceSetBitmap = 0; |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 493 | int Overlay::PipeBook::NUM_PIPES = 0; |
| 494 | int Overlay::PipeBook::sPipeUsageBitmap = 0; |
| 495 | int Overlay::PipeBook::sLastUsageBitmap = 0; |
| 496 | int Overlay::PipeBook::sAllocatedBitmap = 0; |
Sushil Chauhan | 07a2c76 | 2013-03-06 15:36:49 -0800 | [diff] [blame] | 497 | utils::eMdpPipeType Overlay::PipeBook::pipeTypeLUT[utils::OV_MAX] = |
| 498 | {utils::OV_MDP_PIPE_ANY}; |
Saurabh Shah | b8f58e2 | 2013-09-26 16:20:07 -0700 | [diff] [blame] | 499 | void *Overlay::sLibScaleHandle = NULL; |
| 500 | scale::Scale *Overlay::sScale = NULL; |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 501 | |
| 502 | }; // namespace overlay |