blob: 3a96b718269d8617f08bc0e73b3ce79c683b33db [file] [log] [blame]
Naseer Ahmed29a26812012-06-14 00:56:20 -07001/*
Ramakant Singhb4106a12014-10-07 18:06:56 +05302* Copyright (c) 2011-2014, The Linux Foundation. All rights reserved.
Naseer Ahmed29a26812012-06-14 00:56:20 -07003*
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 Ahmed758bfc52012-11-28 17:02:08 -050013* * Neither the name of The Linux Foundation nor the names of its
Naseer Ahmed29a26812012-06-14 00:56:20 -070014* 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 Shahb8f58e22013-09-26 16:20:07 -070030#include <dlfcn.h>
Naseer Ahmed29a26812012-06-14 00:56:20 -070031#include "overlay.h"
Naseer Ahmed758bfc52012-11-28 17:02:08 -050032#include "pipes/overlayGenPipe.h"
33#include "mdp_version.h"
Saurabh Shah5daeee52013-01-23 16:52:26 +080034#include "qdMetaData.h"
Tatenda Chipeperekwace8d5c42014-08-13 10:53:49 -070035#include "qd_utils.h"
Naseer Ahmed29a26812012-06-14 00:56:20 -070036
Naseer Ahmed29a26812012-06-14 00:56:20 -070037namespace overlay {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050038using namespace utils;
Saurabh Shahc62f3982014-03-05 14:28:26 -080039using namespace qdutils;
Saurabh Shahb8f58e22013-09-26 16:20:07 -070040
Naseer Ahmed758bfc52012-11-28 17:02:08 -050041Overlay::Overlay() {
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -080042 int numPipes = qdutils::MDPVersion::getInstance().getTotalPipes();
43 PipeBook::NUM_PIPES = (numPipes <= utils::OV_MAX)? numPipes : utils::OV_MAX;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050044 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
45 mPipeBook[i].init();
Naseer Ahmed1ddf3662012-07-31 19:14:18 -070046 }
Naseer Ahmed1ddf3662012-07-31 19:14:18 -070047
Saurabh Shahb8f58e22013-09-26 16:20:07 -070048 initScalar();
Raj Kamala8c065f2013-10-22 14:52:45 +053049 setDMAMultiplexingSupported();
Naseer Ahmed29a26812012-06-14 00:56:20 -070050}
51
52Overlay::~Overlay() {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050053 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
54 mPipeBook[i].destroy();
55 }
Saurabh Shahb8f58e22013-09-26 16:20:07 -070056 destroyScalar();
Naseer Ahmed29a26812012-06-14 00:56:20 -070057}
58
Naseer Ahmed758bfc52012-11-28 17:02:08 -050059void 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 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -050065}
66
67void Overlay::configDone() {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050068 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
Zohaib Alam4b0a9242013-11-20 23:54:12 -050069 if((PipeBook::isNotUsed(i) && !sessionInProgress((eDest)i)) ||
70 isSessionEnded((eDest)i)) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050071 //Forces UNSET on pipes, flushes rotator memory and session, closes
72 //fds
Naseer Ahmed758bfc52012-11-28 17:02:08 -050073 mPipeBook[i].destroy();
Naseer Ahmed1ddf3662012-07-31 19:14:18 -070074 }
Naseer Ahmed29a26812012-06-14 00:56:20 -070075 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -050076 PipeBook::save();
77}
78
Zohaib Alam4b0a9242013-11-20 23:54:12 -050079int Overlay::getPipeId(utils::eDest dest) {
80 return mPipeBook[(int)dest].mPipe->getPipeId();
81}
82
83eDest Overlay::getDest(int pipeid) {
84 eDest dest = OV_INVALID;
85 // finding the dest corresponding to the given pipe
86 for(int i=0; i < PipeBook::NUM_PIPES; ++i) {
87 if(mPipeBook[i].valid() && mPipeBook[i].mPipe->getPipeId() == pipeid) {
88 return (eDest)i;
89 }
90 }
91 return dest;
92}
93
94eDest Overlay::reservePipe(int pipeid) {
95 eDest dest = getDest(pipeid);
96 PipeBook::setAllocation((int)dest);
97 return dest;
98}
99
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700100eDest Overlay::nextPipe(eMdpPipeType type, int dpy, int mixer) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500101 eDest dest = OV_INVALID;
102
103 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700104 if( (type == OV_MDP_PIPE_ANY || //Pipe type match
105 type == PipeBook::getPipeType((eDest)i)) &&
106 (mPipeBook[i].mDisplay == DPY_UNUSED || //Free or same display
107 mPipeBook[i].mDisplay == dpy) &&
108 (mPipeBook[i].mMixer == MIXER_UNUSED || //Free or same mixer
109 mPipeBook[i].mMixer == mixer) &&
110 PipeBook::isNotAllocated(i) && //Free pipe
Raj Kamala8c065f2013-10-22 14:52:45 +0530111 ( (sDMAMultiplexingSupported && dpy) ||
112 !(sDMAMode == DMA_BLOCK_MODE && //DMA pipe in Line mode
113 PipeBook::getPipeType((eDest)i) == OV_MDP_PIPE_DMA)) ){
114 //DMA-Multiplexing is only supported for WB on 8x26
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700115 dest = (eDest)i;
116 PipeBook::setAllocation(i);
117 break;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500118 }
119 }
120
121 if(dest != OV_INVALID) {
122 int index = (int)dest;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500123 mPipeBook[index].mDisplay = dpy;
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700124 mPipeBook[index].mMixer = mixer;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500125 if(not mPipeBook[index].valid()) {
126 mPipeBook[index].mPipe = new GenericPipe(dpy);
Zohaib Alam4b0a9242013-11-20 23:54:12 -0500127 mPipeBook[index].mSession = PipeBook::NONE;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500128 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500129 }
130
131 return dest;
132}
133
Saurabh Shahc62f3982014-03-05 14:28:26 -0800134utils::eDest Overlay::getPipe(const PipeSpecs& pipeSpecs) {
135 if(MDPVersion::getInstance().is8x26()) {
136 return getPipe_8x26(pipeSpecs);
137 } else if(MDPVersion::getInstance().is8x16()) {
138 return getPipe_8x16(pipeSpecs);
Prabhanjan Kandula958ffa92014-05-12 14:56:56 +0530139 } else if(MDPVersion::getInstance().is8x39()) {
140 return getPipe_8x39(pipeSpecs);
Saurabh Shah59788572014-07-29 10:07:57 -0700141 } else if(MDPVersion::getInstance().is8994()) {
142 return getPipe_8994(pipeSpecs);
Saurabh Shahc62f3982014-03-05 14:28:26 -0800143 }
144
145 eDest dest = OV_INVALID;
146
147 //The default behavior is to assume RGB and VG pipes have scalars
148 if(pipeSpecs.formatClass == FORMAT_YUV) {
149 return nextPipe(OV_MDP_PIPE_VG, pipeSpecs.dpy, pipeSpecs.mixer);
150 } else if(pipeSpecs.fb == false) { //RGB App layers
151 if(not pipeSpecs.needsScaling) {
152 dest = nextPipe(OV_MDP_PIPE_DMA, pipeSpecs.dpy, pipeSpecs.mixer);
153 }
154 if(dest == OV_INVALID) {
155 dest = nextPipe(OV_MDP_PIPE_RGB, pipeSpecs.dpy, pipeSpecs.mixer);
156 }
157 if(dest == OV_INVALID) {
158 dest = nextPipe(OV_MDP_PIPE_VG, pipeSpecs.dpy, pipeSpecs.mixer);
159 }
160 } else { //FB layer
161 dest = nextPipe(OV_MDP_PIPE_RGB, pipeSpecs.dpy, pipeSpecs.mixer);
162 if(dest == OV_INVALID) {
163 dest = nextPipe(OV_MDP_PIPE_VG, pipeSpecs.dpy, pipeSpecs.mixer);
164 }
165 //Some features can cause FB to have scaling as well.
166 //If we ever come to this block with FB needing scaling,
167 //the screen will be black for a frame, since the FB won't get a pipe
168 //but atleast this will prevent a hang
169 if(dest == OV_INVALID and (not pipeSpecs.needsScaling)) {
170 dest = nextPipe(OV_MDP_PIPE_DMA, pipeSpecs.dpy, pipeSpecs.mixer);
171 }
172 }
173 return dest;
174}
175
176utils::eDest Overlay::getPipe_8x26(const PipeSpecs& pipeSpecs) {
177 //Use this to hide all the 8x26 requirements that cannot be humanly
178 //described in a generic way
179 eDest dest = OV_INVALID;
180 if(pipeSpecs.formatClass == FORMAT_YUV) { //video
181 return nextPipe(OV_MDP_PIPE_VG, pipeSpecs.dpy, pipeSpecs.mixer);
182 } else if(pipeSpecs.fb == false) { //RGB app layers
Xu Yang1e686f62014-04-08 13:56:47 +0800183 if((not pipeSpecs.needsScaling) and
184 (not (pipeSpecs.numActiveDisplays > 1 &&
185 pipeSpecs.dpy == DPY_PRIMARY))) {
Saurabh Shahc62f3982014-03-05 14:28:26 -0800186 dest = nextPipe(OV_MDP_PIPE_DMA, pipeSpecs.dpy, pipeSpecs.mixer);
187 }
188 if(dest == OV_INVALID) {
189 dest = nextPipe(OV_MDP_PIPE_RGB, pipeSpecs.dpy, pipeSpecs.mixer);
190 }
191 if(dest == OV_INVALID) {
192 dest = nextPipe(OV_MDP_PIPE_VG, pipeSpecs.dpy, pipeSpecs.mixer);
193 }
194 } else { //FB layer
195 //For 8x26 Secondary we use DMA always for FB for inline rotation
196 if(pipeSpecs.dpy == DPY_PRIMARY) {
197 dest = nextPipe(OV_MDP_PIPE_RGB, pipeSpecs.dpy, pipeSpecs.mixer);
198 if(dest == OV_INVALID) {
199 dest = nextPipe(OV_MDP_PIPE_VG, pipeSpecs.dpy, pipeSpecs.mixer);
200 }
201 }
Xu Yang1e686f62014-04-08 13:56:47 +0800202 if(dest == OV_INVALID and (not pipeSpecs.needsScaling) and
203 (not (pipeSpecs.numActiveDisplays > 1 &&
204 pipeSpecs.dpy == DPY_PRIMARY))) {
Saurabh Shahc62f3982014-03-05 14:28:26 -0800205 dest = nextPipe(OV_MDP_PIPE_DMA, pipeSpecs.dpy, pipeSpecs.mixer);
206 }
207 }
208 return dest;
209}
210
211utils::eDest Overlay::getPipe_8x16(const PipeSpecs& pipeSpecs) {
212 //Having such functions help keeping the interface generic but code specific
213 //and rife with assumptions
214 eDest dest = OV_INVALID;
215 if(pipeSpecs.formatClass == FORMAT_YUV or pipeSpecs.needsScaling) {
216 return nextPipe(OV_MDP_PIPE_VG, pipeSpecs.dpy, pipeSpecs.mixer);
radhakrishna89298462014-04-22 19:10:36 +0530217 } else {
Saurabh Shahc62f3982014-03-05 14:28:26 -0800218 //Since this is a specific func, we can assume stuff like RGB pipe not
219 //having scalar blocks
220 dest = nextPipe(OV_MDP_PIPE_RGB, pipeSpecs.dpy, pipeSpecs.mixer);
221 if(dest == OV_INVALID) {
222 dest = nextPipe(OV_MDP_PIPE_DMA, pipeSpecs.dpy, pipeSpecs.mixer);
223 }
Saurabh Shahc62f3982014-03-05 14:28:26 -0800224 if(dest == OV_INVALID) {
radhakrishna89298462014-04-22 19:10:36 +0530225 dest = nextPipe(OV_MDP_PIPE_VG, pipeSpecs.dpy, pipeSpecs.mixer);
Saurabh Shahc62f3982014-03-05 14:28:26 -0800226 }
227 }
228 return dest;
229}
230
Prabhanjan Kandula958ffa92014-05-12 14:56:56 +0530231utils::eDest Overlay::getPipe_8x39(const PipeSpecs& pipeSpecs) {
232 //8x16 & 8x36 has same number of pipes, pipe-types & scaling capabilities.
233 //Rely on 8x16 until we see a need to change.
234 return getPipe_8x16(pipeSpecs);
235}
236
Saurabh Shah59788572014-07-29 10:07:57 -0700237utils::eDest Overlay::getPipe_8994(const PipeSpecs& pipeSpecs) {
238 //If DMA pipes need to be used in block mode for downscale, there could be
239 //cases where consecutive rounds need separate modes, which cannot be
240 //supported since we at least need 1 round in between where the DMA is
241 //unused
242 eDest dest = OV_INVALID;
243 if(pipeSpecs.formatClass == FORMAT_YUV) {
244 return nextPipe(OV_MDP_PIPE_VG, pipeSpecs.dpy, pipeSpecs.mixer);
245 } else {
246 dest = nextPipe(OV_MDP_PIPE_RGB, pipeSpecs.dpy, pipeSpecs.mixer);
247 if(dest == OV_INVALID) {
248 dest = nextPipe(OV_MDP_PIPE_VG, pipeSpecs.dpy, pipeSpecs.mixer);
249 }
250 if(dest == OV_INVALID and not pipeSpecs.needsScaling) {
251 dest = nextPipe(OV_MDP_PIPE_DMA, pipeSpecs.dpy, pipeSpecs.mixer);
252 }
253 }
254 return dest;
255}
256
Zohaib Alam4b0a9242013-11-20 23:54:12 -0500257void Overlay::endAllSessions() {
258 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
259 if(mPipeBook[i].valid() && mPipeBook[i].mSession==PipeBook::START)
260 mPipeBook[i].mSession = PipeBook::END;
261 }
262}
263
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700264bool Overlay::isPipeTypeAttached(eMdpPipeType type) {
265 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
266 if(type == PipeBook::getPipeType((eDest)i) &&
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700267 mPipeBook[i].mDisplay != DPY_UNUSED) {
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700268 return true;
269 }
270 }
271 return false;
272}
273
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800274int Overlay::comparePipePriority(utils::eDest pipe1Index,
275 utils::eDest pipe2Index) {
276 validate((int)pipe1Index);
277 validate((int)pipe2Index);
278 uint8_t pipe1Prio = mPipeBook[(int)pipe1Index].mPipe->getPriority();
279 uint8_t pipe2Prio = mPipeBook[(int)pipe2Index].mPipe->getPriority();
280 if(pipe1Prio > pipe2Prio)
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800281 return -1;
Saurabh Shahea3cf302014-11-07 12:10:46 -0800282 else if(pipe1Prio < pipe2Prio)
Tatenda Chipeperekwa657afa22014-04-15 12:02:39 -0700283 return 1;
Saurabh Shahea3cf302014-11-07 12:10:46 -0800284 else {
285 // If we are here, Source Split is enabled and both pipes are
286 // new requests. In this case left type should be of higher prio
287 // than right type
288 utils::eMdpPipeType leftType = PipeBook::getPipeType(pipe1Index);
289 utils::eMdpPipeType rightType = PipeBook::getPipeType(pipe2Index);
290
291 if(leftType == rightType) {
292 //Safe. Onus on driver to assign correct pipes within same type
293 return 1;
294 } else if(leftType == OV_MDP_PIPE_DMA or rightType == OV_MDP_PIPE_VG) {
295 //If we are here, right is definitely a higher prio type.
296 //This check takes advantage of having only 3 types and avoids 3
297 //different failure combination checks.
298 return -1;
299 } else {
300 //Types are correct priority-wise
301 return 1;
302 }
303 }
304
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800305 return 0;
306}
307
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500308bool Overlay::commit(utils::eDest dest) {
309 bool ret = false;
Praveena Pachipulusu2005e8f2014-05-07 20:01:54 +0530310 validate((int)dest);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500311
Praveena Pachipulusu2005e8f2014-05-07 20:01:54 +0530312 if(mPipeBook[dest].mPipe->commit()) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500313 ret = true;
314 PipeBook::setUse((int)dest);
315 } else {
Praveena Pachipulusu2005e8f2014-05-07 20:01:54 +0530316 int dpy = mPipeBook[dest].mDisplay;
Saurabh Shah7445d4b2013-12-05 17:24:45 -0800317 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
Saurabh Shahdf0be752013-05-23 14:40:00 -0700318 if (mPipeBook[i].mDisplay == dpy) {
Sushil Chauhane0dff932013-03-01 14:33:18 -0800319 PipeBook::resetAllocation(i);
Saurabh Shahdf0be752013-05-23 14:40:00 -0700320 PipeBook::resetUse(i);
Saurabh Shahdf0be752013-05-23 14:40:00 -0700321 }
Saurabh Shah7445d4b2013-12-05 17:24:45 -0800322 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500323 }
324 return ret;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700325}
326
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700327bool Overlay::queueBuffer(int fd, uint32_t offset,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500328 utils::eDest dest) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500329 bool ret = false;
Praveena Pachipulusu2005e8f2014-05-07 20:01:54 +0530330 validate((int)dest);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500331 //Queue only if commit() has succeeded (and the bit set)
332 if(PipeBook::isUsed((int)dest)) {
Praveena Pachipulusu2005e8f2014-05-07 20:01:54 +0530333 ret = mPipeBook[dest].mPipe->queueBuffer(fd, offset);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700334 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500335 return ret;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700336}
337
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500338void Overlay::setCrop(const utils::Dim& d,
339 utils::eDest dest) {
Praveena Pachipulusu2005e8f2014-05-07 20:01:54 +0530340 validate((int)dest);
341 mPipeBook[dest].mPipe->setCrop(d);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700342}
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700343
Sushil Chauhan897a9c32013-07-18 11:09:55 -0700344void Overlay::setColor(const uint32_t color,
345 utils::eDest dest) {
Praveena Pachipulusu2005e8f2014-05-07 20:01:54 +0530346 validate((int)dest);
347 mPipeBook[dest].mPipe->setColor(color);
Sushil Chauhan897a9c32013-07-18 11:09:55 -0700348}
349
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500350void Overlay::setPosition(const utils::Dim& d,
351 utils::eDest dest) {
Praveena Pachipulusu2005e8f2014-05-07 20:01:54 +0530352 validate((int)dest);
353 mPipeBook[dest].mPipe->setPosition(d);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500354}
355
356void Overlay::setTransform(const int orient,
357 utils::eDest dest) {
Praveena Pachipulusu2005e8f2014-05-07 20:01:54 +0530358 validate((int)dest);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500359
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700360 utils::eTransform transform =
361 static_cast<utils::eTransform>(orient);
Praveena Pachipulusu2005e8f2014-05-07 20:01:54 +0530362 mPipeBook[dest].mPipe->setTransform(transform);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700363
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500364}
365
366void Overlay::setSource(const utils::PipeArgs args,
367 utils::eDest dest) {
Praveena Pachipulusu2005e8f2014-05-07 20:01:54 +0530368 validate((int)dest);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500369
radhakrishna8ccb9082014-05-09 16:18:43 +0530370 setPipeType(dest, PipeBook::getPipeType(dest));
371 mPipeBook[dest].mPipe->setSource(args);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700372}
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700373
Saurabh Shah5daeee52013-01-23 16:52:26 +0800374void Overlay::setVisualParams(const MetaData_t& metadata, utils::eDest dest) {
Praveena Pachipulusu2005e8f2014-05-07 20:01:54 +0530375 validate((int)dest);
376 mPipeBook[dest].mPipe->setVisualParams(metadata);
Saurabh Shah5daeee52013-01-23 16:52:26 +0800377}
378
radhakrishna8ccb9082014-05-09 16:18:43 +0530379void Overlay::setPipeType(utils::eDest pipeIndex,
380 const utils::eMdpPipeType pType) {
381 mPipeBook[pipeIndex].mPipe->setPipeType(pType);
382}
383
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500384Overlay* Overlay::getInstance() {
385 if(sInstance == NULL) {
386 sInstance = new Overlay();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700387 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500388 return sInstance;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700389}
390
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800391// Clears any VG pipes allocated to the fb devices
392// Generates a LUT for pipe types.
393int Overlay::initOverlay() {
394 int mdpVersion = qdutils::MDPVersion::getInstance().getMDPVersion();
395 int numPipesXType[OV_MDP_PIPE_ANY] = {0};
396 numPipesXType[OV_MDP_PIPE_RGB] =
397 qdutils::MDPVersion::getInstance().getRGBPipes();
398 numPipesXType[OV_MDP_PIPE_VG] =
399 qdutils::MDPVersion::getInstance().getVGPipes();
400 numPipesXType[OV_MDP_PIPE_DMA] =
401 qdutils::MDPVersion::getInstance().getDMAPipes();
402
403 int index = 0;
404 for(int X = 0; X < (int)OV_MDP_PIPE_ANY; X++) { //iterate over types
405 for(int j = 0; j < numPipesXType[X]; j++) { //iterate over num
406 PipeBook::pipeTypeLUT[index] = (utils::eMdpPipeType)X;
407 index++;
408 }
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700409 }
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800410
Ramakant Singhb4106a12014-10-07 18:06:56 +0530411 if (mdpVersion < qdutils::MDSS_V5 && mdpVersion > qdutils::MDP_V3_0_5) {
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800412 msmfb_mixer_info_req req;
413 mdp_mixer_info *minfo = NULL;
414 char name[64];
415 int fd = -1;
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700416 for(int i = 0; i < MAX_FB_DEVICES; i++) {
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800417 snprintf(name, 64, FB_DEVICE_TEMPLATE, i);
418 ALOGD("initoverlay:: opening the device:: %s", name);
419 fd = ::open(name, O_RDWR, 0);
420 if(fd < 0) {
421 ALOGE("cannot open framebuffer(%d)", i);
422 return -1;
423 }
424 //Get the mixer configuration */
425 req.mixer_num = i;
426 if (ioctl(fd, MSMFB_MIXER_INFO, &req) == -1) {
427 ALOGE("ERROR: MSMFB_MIXER_INFO ioctl failed");
428 close(fd);
429 return -1;
430 }
431 minfo = req.info;
432 for (int j = 0; j < req.cnt; j++) {
433 ALOGD("ndx=%d num=%d z_order=%d", minfo->pndx, minfo->pnum,
434 minfo->z_order);
435 // except the RGB base layer with z_order of -1, clear any
436 // other pipes connected to mixer.
437 if((minfo->z_order) != -1) {
438 int index = minfo->pndx;
439 ALOGD("Unset overlay with index: %d at mixer %d", index, i);
440 if(ioctl(fd, MSMFB_OVERLAY_UNSET, &index) == -1) {
441 ALOGE("ERROR: MSMFB_OVERLAY_UNSET failed");
442 close(fd);
443 return -1;
444 }
445 }
446 minfo++;
447 }
448 close(fd);
449 fd = -1;
450 }
451 }
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700452
453 FILE *displayDeviceFP = NULL;
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700454 char fbType[MAX_FRAME_BUFFER_NAME_SIZE];
455 char msmFbTypePath[MAX_FRAME_BUFFER_NAME_SIZE];
456 const char *strDtvPanel = "dtv panel";
457 const char *strWbPanel = "writeback panel";
458
459 for(int num = 1; num < MAX_FB_DEVICES; num++) {
460 snprintf (msmFbTypePath, sizeof(msmFbTypePath),
461 "/sys/class/graphics/fb%d/msm_fb_type", num);
462 displayDeviceFP = fopen(msmFbTypePath, "r");
463
464 if(displayDeviceFP){
465 fread(fbType, sizeof(char), MAX_FRAME_BUFFER_NAME_SIZE,
466 displayDeviceFP);
467
468 if(strncmp(fbType, strDtvPanel, strlen(strDtvPanel)) == 0) {
469 sDpyFbMap[DPY_EXTERNAL] = num;
470 } else if(strncmp(fbType, strWbPanel, strlen(strWbPanel)) == 0) {
471 sDpyFbMap[DPY_WRITEBACK] = num;
472 }
473
474 fclose(displayDeviceFP);
475 }
476 }
477
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800478 return 0;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700479}
480
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700481bool Overlay::displayCommit(const int& fd) {
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800482 utils::Dim lRoi, rRoi;
483 return displayCommit(fd, lRoi, rRoi);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700484}
485
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800486bool Overlay::displayCommit(const int& fd, const utils::Dim& lRoi,
487 const utils::Dim& rRoi) {
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700488 //Commit
489 struct mdp_display_commit info;
490 memset(&info, 0, sizeof(struct mdp_display_commit));
491 info.flags = MDP_DISPLAY_COMMIT_OVERLAY;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800492 info.l_roi.x = lRoi.x;
493 info.l_roi.y = lRoi.y;
494 info.l_roi.w = lRoi.w;
495 info.l_roi.h = lRoi.h;
496 info.r_roi.x = rRoi.x;
497 info.r_roi.y = rRoi.y;
498 info.r_roi.w = rRoi.w;
499 info.r_roi.h = rRoi.h;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700500
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700501 if(!mdp_wrapper::displayCommit(fd, info)) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700502 ALOGE("%s: commit failed", __func__);
503 return false;
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700504 }
505 return true;
506}
507
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800508void Overlay::getDump(char *buf, size_t len) {
509 int totalPipes = 0;
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700510 const char *str = "\nOverlay State\n\n";
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800511 strlcat(buf, str, len);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800512 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
513 if(mPipeBook[i].valid()) {
514 mPipeBook[i].mPipe->getDump(buf, len);
515 char str[64] = {'\0'};
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700516 snprintf(str, 64, "Display=%d\n\n", mPipeBook[i].mDisplay);
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800517 strlcat(buf, str, len);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800518 totalPipes++;
519 }
520 }
521 char str_pipes[64] = {'\0'};
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700522 snprintf(str_pipes, 64, "Pipes=%d\n\n", totalPipes);
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800523 strlcat(buf, str_pipes, len);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800524}
525
Sushil Chauhanbd3ea922013-05-15 12:25:26 -0700526void Overlay::clear(int dpy) {
527 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
528 if (mPipeBook[i].mDisplay == dpy) {
529 // Mark as available for this round
530 PipeBook::resetUse(i);
531 PipeBook::resetAllocation(i);
532 }
533 }
534}
535
Saurabh Shaha36be922013-12-16 18:18:39 -0800536bool Overlay::validateAndSet(const int& dpy, const int& fbFd) {
537 GenericPipe* pipeArray[PipeBook::NUM_PIPES];
Praveena Pachipulusu2005e8f2014-05-07 20:01:54 +0530538 memset(pipeArray, 0, sizeof(GenericPipe*)*(PipeBook::NUM_PIPES));
Saurabh Shaha36be922013-12-16 18:18:39 -0800539
540 int num = 0;
541 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
542 if(PipeBook::isUsed(i) && mPipeBook[i].valid() &&
543 mPipeBook[i].mDisplay == dpy) {
544 pipeArray[num++] = mPipeBook[i].mPipe;
545 }
546 }
547
548 //Protect against misbehaving clients
549 return num ? GenericPipe::validateAndSet(pipeArray, num, fbFd) : true;
550}
551
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700552void Overlay::initScalar() {
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700553 if(sLibScaleHandle == NULL) {
554 sLibScaleHandle = dlopen("libscale.so", RTLD_NOW);
Saurabh Shaheac146b2014-05-13 11:36:20 -0700555 if(sLibScaleHandle) {
556 *(void **) &sFnProgramScale =
557 dlsym(sLibScaleHandle, "programScale");
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700558 }
559 }
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700560}
561
562void Overlay::destroyScalar() {
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700563 if(sLibScaleHandle) {
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700564 dlclose(sLibScaleHandle);
565 sLibScaleHandle = NULL;
566 }
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700567}
568
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500569void Overlay::PipeBook::init() {
570 mPipe = NULL;
571 mDisplay = DPY_UNUSED;
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700572 mMixer = MIXER_UNUSED;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500573}
574
575void Overlay::PipeBook::destroy() {
576 if(mPipe) {
577 delete mPipe;
578 mPipe = NULL;
579 }
580 mDisplay = DPY_UNUSED;
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700581 mMixer = MIXER_UNUSED;
Zohaib Alam4b0a9242013-11-20 23:54:12 -0500582 mSession = NONE;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500583}
584
585Overlay* Overlay::sInstance = 0;
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700586int Overlay::sDpyFbMap[DPY_MAX] = {0, -1, -1};
Saurabh Shah85234ec2013-04-12 17:09:00 -0700587int Overlay::sDMAMode = DMA_LINE_MODE;
Raj Kamala8c065f2013-10-22 14:52:45 +0530588bool Overlay::sDMAMultiplexingSupported = false;
Saurabh Shah24eec8a2014-08-22 15:07:25 -0700589bool Overlay::sDebugPipeLifecycle = false;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500590int Overlay::PipeBook::NUM_PIPES = 0;
591int Overlay::PipeBook::sPipeUsageBitmap = 0;
592int Overlay::PipeBook::sLastUsageBitmap = 0;
593int Overlay::PipeBook::sAllocatedBitmap = 0;
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800594utils::eMdpPipeType Overlay::PipeBook::pipeTypeLUT[utils::OV_MAX] =
595 {utils::OV_MDP_PIPE_ANY};
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700596void *Overlay::sLibScaleHandle = NULL;
Saurabh Shaheac146b2014-05-13 11:36:20 -0700597int (*Overlay::sFnProgramScale)(struct mdp_overlay_list *) = NULL;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500598
599}; // namespace overlay