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