blob: 5287f02c75705e6d3d4e805b1e7e2993b792a000 [file] [log] [blame]
Naseer Ahmed29a26812012-06-14 00:56:20 -07001/*
Sushil Chauhan07a2c762013-03-06 15:36:49 -08002* Copyright (c) 2011-2013, 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"
Naseer Ahmed29a26812012-06-14 00:56:20 -070035
Naseer Ahmed758bfc52012-11-28 17:02:08 -050036#define PIPE_DEBUG 0
Naseer Ahmed29a26812012-06-14 00:56:20 -070037
38namespace overlay {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050039using namespace utils;
Saurabh Shahc62f3982014-03-05 14:28:26 -080040using namespace qdutils;
Saurabh Shahb8f58e22013-09-26 16:20:07 -070041
Naseer Ahmed758bfc52012-11-28 17:02:08 -050042Overlay::Overlay() {
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -080043 int numPipes = qdutils::MDPVersion::getInstance().getTotalPipes();
44 PipeBook::NUM_PIPES = (numPipes <= utils::OV_MAX)? numPipes : utils::OV_MAX;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050045 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
46 mPipeBook[i].init();
Naseer Ahmed1ddf3662012-07-31 19:14:18 -070047 }
Naseer Ahmed1ddf3662012-07-31 19:14:18 -070048
Naseer Ahmed758bfc52012-11-28 17:02:08 -050049 mDumpStr[0] = '\0';
Saurabh Shahb8f58e22013-09-26 16:20:07 -070050 initScalar();
Raj Kamala8c065f2013-10-22 14:52:45 +053051 setDMAMultiplexingSupported();
Naseer Ahmed29a26812012-06-14 00:56:20 -070052}
53
54Overlay::~Overlay() {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050055 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
56 mPipeBook[i].destroy();
57 }
Saurabh Shahb8f58e22013-09-26 16:20:07 -070058 destroyScalar();
Naseer Ahmed29a26812012-06-14 00:56:20 -070059}
60
Naseer Ahmed758bfc52012-11-28 17:02:08 -050061void Overlay::configBegin() {
62 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
63 //Mark as available for this round.
64 PipeBook::resetUse(i);
65 PipeBook::resetAllocation(i);
66 }
67 mDumpStr[0] = '\0';
68}
69
70void Overlay::configDone() {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050071 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
Zohaib Alam4b0a9242013-11-20 23:54:12 -050072 if((PipeBook::isNotUsed(i) && !sessionInProgress((eDest)i)) ||
73 isSessionEnded((eDest)i)) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050074 //Forces UNSET on pipes, flushes rotator memory and session, closes
75 //fds
76 if(mPipeBook[i].valid()) {
77 char str[32];
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -080078 snprintf(str, 32, "Unset=%s dpy=%d mix=%d; ",
Saurabh Shahaf5f5972013-07-30 13:56:35 -070079 PipeBook::getDestStr((eDest)i),
80 mPipeBook[i].mDisplay, mPipeBook[i].mMixer);
Saurabh Shah9dc88fc2013-07-15 16:02:30 -070081#if PIPE_DEBUG
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -080082 strlcat(mDumpStr, str, sizeof(mDumpStr));
Saurabh Shah9dc88fc2013-07-15 16:02:30 -070083#endif
Naseer Ahmed758bfc52012-11-28 17:02:08 -050084 }
85 mPipeBook[i].destroy();
Naseer Ahmed1ddf3662012-07-31 19:14:18 -070086 }
Naseer Ahmed29a26812012-06-14 00:56:20 -070087 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -050088 dump();
89 PipeBook::save();
90}
91
Zohaib Alam4b0a9242013-11-20 23:54:12 -050092int Overlay::getPipeId(utils::eDest dest) {
93 return mPipeBook[(int)dest].mPipe->getPipeId();
94}
95
96eDest Overlay::getDest(int pipeid) {
97 eDest dest = OV_INVALID;
98 // finding the dest corresponding to the given pipe
99 for(int i=0; i < PipeBook::NUM_PIPES; ++i) {
100 if(mPipeBook[i].valid() && mPipeBook[i].mPipe->getPipeId() == pipeid) {
101 return (eDest)i;
102 }
103 }
104 return dest;
105}
106
107eDest Overlay::reservePipe(int pipeid) {
108 eDest dest = getDest(pipeid);
109 PipeBook::setAllocation((int)dest);
110 return dest;
111}
112
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700113eDest Overlay::nextPipe(eMdpPipeType type, int dpy, int mixer) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500114 eDest dest = OV_INVALID;
115
116 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700117 if( (type == OV_MDP_PIPE_ANY || //Pipe type match
118 type == PipeBook::getPipeType((eDest)i)) &&
119 (mPipeBook[i].mDisplay == DPY_UNUSED || //Free or same display
120 mPipeBook[i].mDisplay == dpy) &&
121 (mPipeBook[i].mMixer == MIXER_UNUSED || //Free or same mixer
122 mPipeBook[i].mMixer == mixer) &&
123 PipeBook::isNotAllocated(i) && //Free pipe
Raj Kamala8c065f2013-10-22 14:52:45 +0530124 ( (sDMAMultiplexingSupported && dpy) ||
125 !(sDMAMode == DMA_BLOCK_MODE && //DMA pipe in Line mode
126 PipeBook::getPipeType((eDest)i) == OV_MDP_PIPE_DMA)) ){
127 //DMA-Multiplexing is only supported for WB on 8x26
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700128 dest = (eDest)i;
129 PipeBook::setAllocation(i);
130 break;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500131 }
132 }
133
134 if(dest != OV_INVALID) {
135 int index = (int)dest;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500136 mPipeBook[index].mDisplay = dpy;
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700137 mPipeBook[index].mMixer = mixer;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500138 if(not mPipeBook[index].valid()) {
139 mPipeBook[index].mPipe = new GenericPipe(dpy);
Zohaib Alam4b0a9242013-11-20 23:54:12 -0500140 mPipeBook[index].mSession = PipeBook::NONE;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500141 char str[32];
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700142 snprintf(str, 32, "Set=%s dpy=%d mix=%d; ",
143 PipeBook::getDestStr(dest), dpy, mixer);
Saurabh Shah9dc88fc2013-07-15 16:02:30 -0700144#if PIPE_DEBUG
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800145 strlcat(mDumpStr, str, sizeof(mDumpStr));
Saurabh Shah9dc88fc2013-07-15 16:02:30 -0700146#endif
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500147 }
148 } else {
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700149 ALOGD_IF(PIPE_DEBUG, "Pipe unavailable type=%d display=%d mixer=%d",
150 (int)type, dpy, mixer);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500151 }
152
153 return dest;
154}
155
Saurabh Shahc62f3982014-03-05 14:28:26 -0800156utils::eDest Overlay::getPipe(const PipeSpecs& pipeSpecs) {
157 if(MDPVersion::getInstance().is8x26()) {
158 return getPipe_8x26(pipeSpecs);
159 } else if(MDPVersion::getInstance().is8x16()) {
160 return getPipe_8x16(pipeSpecs);
Prabhanjan Kandula958ffa92014-05-12 14:56:56 +0530161 } else if(MDPVersion::getInstance().is8x39()) {
162 return getPipe_8x39(pipeSpecs);
Saurabh Shahc62f3982014-03-05 14:28:26 -0800163 }
164
165 eDest dest = OV_INVALID;
166
167 //The default behavior is to assume RGB and VG pipes have scalars
168 if(pipeSpecs.formatClass == FORMAT_YUV) {
169 return nextPipe(OV_MDP_PIPE_VG, pipeSpecs.dpy, pipeSpecs.mixer);
170 } else if(pipeSpecs.fb == false) { //RGB App layers
171 if(not pipeSpecs.needsScaling) {
172 dest = nextPipe(OV_MDP_PIPE_DMA, pipeSpecs.dpy, pipeSpecs.mixer);
173 }
174 if(dest == OV_INVALID) {
175 dest = nextPipe(OV_MDP_PIPE_RGB, pipeSpecs.dpy, pipeSpecs.mixer);
176 }
177 if(dest == OV_INVALID) {
178 dest = nextPipe(OV_MDP_PIPE_VG, pipeSpecs.dpy, pipeSpecs.mixer);
179 }
180 } else { //FB layer
181 dest = nextPipe(OV_MDP_PIPE_RGB, pipeSpecs.dpy, pipeSpecs.mixer);
182 if(dest == OV_INVALID) {
183 dest = nextPipe(OV_MDP_PIPE_VG, pipeSpecs.dpy, pipeSpecs.mixer);
184 }
185 //Some features can cause FB to have scaling as well.
186 //If we ever come to this block with FB needing scaling,
187 //the screen will be black for a frame, since the FB won't get a pipe
188 //but atleast this will prevent a hang
189 if(dest == OV_INVALID and (not pipeSpecs.needsScaling)) {
190 dest = nextPipe(OV_MDP_PIPE_DMA, pipeSpecs.dpy, pipeSpecs.mixer);
191 }
192 }
193 return dest;
194}
195
196utils::eDest Overlay::getPipe_8x26(const PipeSpecs& pipeSpecs) {
197 //Use this to hide all the 8x26 requirements that cannot be humanly
198 //described in a generic way
199 eDest dest = OV_INVALID;
200 if(pipeSpecs.formatClass == FORMAT_YUV) { //video
201 return nextPipe(OV_MDP_PIPE_VG, pipeSpecs.dpy, pipeSpecs.mixer);
202 } else if(pipeSpecs.fb == false) { //RGB app layers
Xu Yang1e686f62014-04-08 13:56:47 +0800203 if((not pipeSpecs.needsScaling) and
204 (not (pipeSpecs.numActiveDisplays > 1 &&
205 pipeSpecs.dpy == DPY_PRIMARY))) {
Saurabh Shahc62f3982014-03-05 14:28:26 -0800206 dest = nextPipe(OV_MDP_PIPE_DMA, pipeSpecs.dpy, pipeSpecs.mixer);
207 }
208 if(dest == OV_INVALID) {
209 dest = nextPipe(OV_MDP_PIPE_RGB, pipeSpecs.dpy, pipeSpecs.mixer);
210 }
211 if(dest == OV_INVALID) {
212 dest = nextPipe(OV_MDP_PIPE_VG, pipeSpecs.dpy, pipeSpecs.mixer);
213 }
214 } else { //FB layer
215 //For 8x26 Secondary we use DMA always for FB for inline rotation
216 if(pipeSpecs.dpy == DPY_PRIMARY) {
217 dest = nextPipe(OV_MDP_PIPE_RGB, pipeSpecs.dpy, pipeSpecs.mixer);
218 if(dest == OV_INVALID) {
219 dest = nextPipe(OV_MDP_PIPE_VG, pipeSpecs.dpy, pipeSpecs.mixer);
220 }
221 }
Xu Yang1e686f62014-04-08 13:56:47 +0800222 if(dest == OV_INVALID and (not pipeSpecs.needsScaling) and
223 (not (pipeSpecs.numActiveDisplays > 1 &&
224 pipeSpecs.dpy == DPY_PRIMARY))) {
Saurabh Shahc62f3982014-03-05 14:28:26 -0800225 dest = nextPipe(OV_MDP_PIPE_DMA, pipeSpecs.dpy, pipeSpecs.mixer);
226 }
227 }
228 return dest;
229}
230
231utils::eDest Overlay::getPipe_8x16(const PipeSpecs& pipeSpecs) {
232 //Having such functions help keeping the interface generic but code specific
233 //and rife with assumptions
234 eDest dest = OV_INVALID;
235 if(pipeSpecs.formatClass == FORMAT_YUV or pipeSpecs.needsScaling) {
236 return nextPipe(OV_MDP_PIPE_VG, pipeSpecs.dpy, pipeSpecs.mixer);
radhakrishna89298462014-04-22 19:10:36 +0530237 } else {
Saurabh Shahc62f3982014-03-05 14:28:26 -0800238 //Since this is a specific func, we can assume stuff like RGB pipe not
239 //having scalar blocks
240 dest = nextPipe(OV_MDP_PIPE_RGB, pipeSpecs.dpy, pipeSpecs.mixer);
241 if(dest == OV_INVALID) {
242 dest = nextPipe(OV_MDP_PIPE_DMA, pipeSpecs.dpy, pipeSpecs.mixer);
243 }
Saurabh Shahc62f3982014-03-05 14:28:26 -0800244 if(dest == OV_INVALID) {
radhakrishna89298462014-04-22 19:10:36 +0530245 dest = nextPipe(OV_MDP_PIPE_VG, pipeSpecs.dpy, pipeSpecs.mixer);
Saurabh Shahc62f3982014-03-05 14:28:26 -0800246 }
247 }
248 return dest;
249}
250
Prabhanjan Kandula958ffa92014-05-12 14:56:56 +0530251utils::eDest Overlay::getPipe_8x39(const PipeSpecs& pipeSpecs) {
252 //8x16 & 8x36 has same number of pipes, pipe-types & scaling capabilities.
253 //Rely on 8x16 until we see a need to change.
254 return getPipe_8x16(pipeSpecs);
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;
Tatenda Chipeperekwa657afa22014-04-15 12:02:39 -0700282 if(pipe1Prio < pipe2Prio)
283 return 1;
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800284 return 0;
285}
286
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500287bool Overlay::commit(utils::eDest dest) {
288 bool ret = false;
289 int index = (int)dest;
290 validate(index);
291
292 if(mPipeBook[index].mPipe->commit()) {
293 ret = true;
294 PipeBook::setUse((int)dest);
295 } else {
Sushil Chauhane0dff932013-03-01 14:33:18 -0800296 int dpy = mPipeBook[index].mDisplay;
Saurabh Shah7445d4b2013-12-05 17:24:45 -0800297 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
Saurabh Shahdf0be752013-05-23 14:40:00 -0700298 if (mPipeBook[i].mDisplay == dpy) {
Sushil Chauhane0dff932013-03-01 14:33:18 -0800299 PipeBook::resetAllocation(i);
Saurabh Shahdf0be752013-05-23 14:40:00 -0700300 PipeBook::resetUse(i);
Saurabh Shahdf0be752013-05-23 14:40:00 -0700301 }
Saurabh Shah7445d4b2013-12-05 17:24:45 -0800302 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500303 }
304 return ret;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700305}
306
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700307bool Overlay::queueBuffer(int fd, uint32_t offset,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500308 utils::eDest dest) {
309 int index = (int)dest;
310 bool ret = false;
311 validate(index);
312 //Queue only if commit() has succeeded (and the bit set)
313 if(PipeBook::isUsed((int)dest)) {
314 ret = mPipeBook[index].mPipe->queueBuffer(fd, offset);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700315 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500316 return ret;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700317}
318
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500319void Overlay::setCrop(const utils::Dim& d,
320 utils::eDest dest) {
321 int index = (int)dest;
322 validate(index);
323 mPipeBook[index].mPipe->setCrop(d);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700324}
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700325
Sushil Chauhan897a9c32013-07-18 11:09:55 -0700326void Overlay::setColor(const uint32_t color,
327 utils::eDest dest) {
328 int index = (int)dest;
329 validate(index);
330 mPipeBook[index].mPipe->setColor(color);
331}
332
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500333void Overlay::setPosition(const utils::Dim& d,
334 utils::eDest dest) {
335 int index = (int)dest;
336 validate(index);
337 mPipeBook[index].mPipe->setPosition(d);
338}
339
340void Overlay::setTransform(const int orient,
341 utils::eDest dest) {
342 int index = (int)dest;
343 validate(index);
344
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700345 utils::eTransform transform =
346 static_cast<utils::eTransform>(orient);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500347 mPipeBook[index].mPipe->setTransform(transform);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700348
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500349}
350
351void Overlay::setSource(const utils::PipeArgs args,
352 utils::eDest dest) {
353 int index = (int)dest;
354 validate(index);
355
356 PipeArgs newArgs(args);
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800357 if(PipeBook::getPipeType(dest) == OV_MDP_PIPE_VG) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500358 setMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_SHARE);
359 } else {
360 clearMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_SHARE);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700361 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800362
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800363 if(PipeBook::getPipeType(dest) == OV_MDP_PIPE_DMA) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800364 setMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_FORCE_DMA);
365 } else {
366 clearMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_FORCE_DMA);
367 }
368
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500369 mPipeBook[index].mPipe->setSource(newArgs);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700370}
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700371
Saurabh Shah5daeee52013-01-23 16:52:26 +0800372void Overlay::setVisualParams(const MetaData_t& metadata, utils::eDest dest) {
373 int index = (int)dest;
374 validate(index);
375 mPipeBook[index].mPipe->setVisualParams(metadata);
376}
377
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500378Overlay* Overlay::getInstance() {
379 if(sInstance == NULL) {
380 sInstance = new Overlay();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700381 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500382 return sInstance;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700383}
384
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800385// Clears any VG pipes allocated to the fb devices
386// Generates a LUT for pipe types.
387int Overlay::initOverlay() {
388 int mdpVersion = qdutils::MDPVersion::getInstance().getMDPVersion();
389 int numPipesXType[OV_MDP_PIPE_ANY] = {0};
390 numPipesXType[OV_MDP_PIPE_RGB] =
391 qdutils::MDPVersion::getInstance().getRGBPipes();
392 numPipesXType[OV_MDP_PIPE_VG] =
393 qdutils::MDPVersion::getInstance().getVGPipes();
394 numPipesXType[OV_MDP_PIPE_DMA] =
395 qdutils::MDPVersion::getInstance().getDMAPipes();
396
397 int index = 0;
398 for(int X = 0; X < (int)OV_MDP_PIPE_ANY; X++) { //iterate over types
399 for(int j = 0; j < numPipesXType[X]; j++) { //iterate over num
400 PipeBook::pipeTypeLUT[index] = (utils::eMdpPipeType)X;
401 index++;
402 }
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700403 }
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800404
Xiaoming Zhou5eff8b62013-05-01 20:56:09 -0400405 if (mdpVersion < qdutils::MDSS_V5 && mdpVersion != qdutils::MDP_V3_0_4) {
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800406 msmfb_mixer_info_req req;
407 mdp_mixer_info *minfo = NULL;
408 char name[64];
409 int fd = -1;
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700410 for(int i = 0; i < MAX_FB_DEVICES; i++) {
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800411 snprintf(name, 64, FB_DEVICE_TEMPLATE, i);
412 ALOGD("initoverlay:: opening the device:: %s", name);
413 fd = ::open(name, O_RDWR, 0);
414 if(fd < 0) {
415 ALOGE("cannot open framebuffer(%d)", i);
416 return -1;
417 }
418 //Get the mixer configuration */
419 req.mixer_num = i;
420 if (ioctl(fd, MSMFB_MIXER_INFO, &req) == -1) {
421 ALOGE("ERROR: MSMFB_MIXER_INFO ioctl failed");
422 close(fd);
423 return -1;
424 }
425 minfo = req.info;
426 for (int j = 0; j < req.cnt; j++) {
427 ALOGD("ndx=%d num=%d z_order=%d", minfo->pndx, minfo->pnum,
428 minfo->z_order);
429 // except the RGB base layer with z_order of -1, clear any
430 // other pipes connected to mixer.
431 if((minfo->z_order) != -1) {
432 int index = minfo->pndx;
433 ALOGD("Unset overlay with index: %d at mixer %d", index, i);
434 if(ioctl(fd, MSMFB_OVERLAY_UNSET, &index) == -1) {
435 ALOGE("ERROR: MSMFB_OVERLAY_UNSET failed");
436 close(fd);
437 return -1;
438 }
439 }
440 minfo++;
441 }
442 close(fd);
443 fd = -1;
444 }
445 }
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700446
447 FILE *displayDeviceFP = NULL;
448 const int MAX_FRAME_BUFFER_NAME_SIZE = 128;
449 char fbType[MAX_FRAME_BUFFER_NAME_SIZE];
450 char msmFbTypePath[MAX_FRAME_BUFFER_NAME_SIZE];
451 const char *strDtvPanel = "dtv panel";
452 const char *strWbPanel = "writeback panel";
453
454 for(int num = 1; num < MAX_FB_DEVICES; num++) {
455 snprintf (msmFbTypePath, sizeof(msmFbTypePath),
456 "/sys/class/graphics/fb%d/msm_fb_type", num);
457 displayDeviceFP = fopen(msmFbTypePath, "r");
458
459 if(displayDeviceFP){
460 fread(fbType, sizeof(char), MAX_FRAME_BUFFER_NAME_SIZE,
461 displayDeviceFP);
462
463 if(strncmp(fbType, strDtvPanel, strlen(strDtvPanel)) == 0) {
464 sDpyFbMap[DPY_EXTERNAL] = num;
465 } else if(strncmp(fbType, strWbPanel, strlen(strWbPanel)) == 0) {
466 sDpyFbMap[DPY_WRITEBACK] = num;
467 }
468
469 fclose(displayDeviceFP);
470 }
471 }
472
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800473 return 0;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700474}
475
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700476bool Overlay::displayCommit(const int& fd) {
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800477 utils::Dim lRoi, rRoi;
478 return displayCommit(fd, lRoi, rRoi);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700479}
480
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800481bool Overlay::displayCommit(const int& fd, const utils::Dim& lRoi,
482 const utils::Dim& rRoi) {
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700483 //Commit
484 struct mdp_display_commit info;
485 memset(&info, 0, sizeof(struct mdp_display_commit));
486 info.flags = MDP_DISPLAY_COMMIT_OVERLAY;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800487 info.l_roi.x = lRoi.x;
488 info.l_roi.y = lRoi.y;
489 info.l_roi.w = lRoi.w;
490 info.l_roi.h = lRoi.h;
491 info.r_roi.x = rRoi.x;
492 info.r_roi.y = rRoi.y;
493 info.r_roi.w = rRoi.w;
494 info.r_roi.h = rRoi.h;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700495
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700496 if(!mdp_wrapper::displayCommit(fd, info)) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700497 ALOGE("%s: commit failed", __func__);
498 return false;
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700499 }
500 return true;
501}
502
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500503void Overlay::dump() const {
Saurabh Shah9dc88fc2013-07-15 16:02:30 -0700504#if PIPE_DEBUG
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500505 if(strlen(mDumpStr)) { //dump only on state change
Saurabh Shah9dc88fc2013-07-15 16:02:30 -0700506 ALOGD("%s\n", mDumpStr);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500507 }
Saurabh Shah9dc88fc2013-07-15 16:02:30 -0700508#endif
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500509}
510
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800511void Overlay::getDump(char *buf, size_t len) {
512 int totalPipes = 0;
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700513 const char *str = "\nOverlay State\n\n";
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800514 strlcat(buf, str, len);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800515 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
516 if(mPipeBook[i].valid()) {
517 mPipeBook[i].mPipe->getDump(buf, len);
518 char str[64] = {'\0'};
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700519 snprintf(str, 64, "Display=%d\n\n", mPipeBook[i].mDisplay);
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800520 strlcat(buf, str, len);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800521 totalPipes++;
522 }
523 }
524 char str_pipes[64] = {'\0'};
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700525 snprintf(str_pipes, 64, "Pipes=%d\n\n", totalPipes);
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800526 strlcat(buf, str_pipes, len);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800527}
528
Sushil Chauhanbd3ea922013-05-15 12:25:26 -0700529void Overlay::clear(int dpy) {
530 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
531 if (mPipeBook[i].mDisplay == dpy) {
532 // Mark as available for this round
533 PipeBook::resetUse(i);
534 PipeBook::resetAllocation(i);
535 }
536 }
537}
538
Saurabh Shaha36be922013-12-16 18:18:39 -0800539bool Overlay::validateAndSet(const int& dpy, const int& fbFd) {
540 GenericPipe* pipeArray[PipeBook::NUM_PIPES];
541 memset(&pipeArray, 0, sizeof(pipeArray));
542
543 int num = 0;
544 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
545 if(PipeBook::isUsed(i) && mPipeBook[i].valid() &&
546 mPipeBook[i].mDisplay == dpy) {
547 pipeArray[num++] = mPipeBook[i].mPipe;
548 }
549 }
550
551 //Protect against misbehaving clients
552 return num ? GenericPipe::validateAndSet(pipeArray, num, fbFd) : true;
553}
554
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700555void Overlay::initScalar() {
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700556 if(sLibScaleHandle == NULL) {
557 sLibScaleHandle = dlopen("libscale.so", RTLD_NOW);
Saurabh Shaheac146b2014-05-13 11:36:20 -0700558 if(sLibScaleHandle) {
559 *(void **) &sFnProgramScale =
560 dlsym(sLibScaleHandle, "programScale");
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700561 }
562 }
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700563}
564
565void Overlay::destroyScalar() {
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700566 if(sLibScaleHandle) {
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700567 dlclose(sLibScaleHandle);
568 sLibScaleHandle = NULL;
569 }
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700570}
571
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500572void Overlay::PipeBook::init() {
573 mPipe = NULL;
574 mDisplay = DPY_UNUSED;
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700575 mMixer = MIXER_UNUSED;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500576}
577
578void Overlay::PipeBook::destroy() {
579 if(mPipe) {
580 delete mPipe;
581 mPipe = NULL;
582 }
583 mDisplay = DPY_UNUSED;
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700584 mMixer = MIXER_UNUSED;
Zohaib Alam4b0a9242013-11-20 23:54:12 -0500585 mSession = NONE;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500586}
587
588Overlay* Overlay::sInstance = 0;
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700589int Overlay::sDpyFbMap[DPY_MAX] = {0, -1, -1};
Saurabh Shah85234ec2013-04-12 17:09:00 -0700590int Overlay::sDMAMode = DMA_LINE_MODE;
Raj Kamala8c065f2013-10-22 14:52:45 +0530591bool Overlay::sDMAMultiplexingSupported = false;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500592int Overlay::PipeBook::NUM_PIPES = 0;
593int Overlay::PipeBook::sPipeUsageBitmap = 0;
594int Overlay::PipeBook::sLastUsageBitmap = 0;
595int Overlay::PipeBook::sAllocatedBitmap = 0;
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800596utils::eMdpPipeType Overlay::PipeBook::pipeTypeLUT[utils::OV_MAX] =
597 {utils::OV_MDP_PIPE_ANY};
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700598void *Overlay::sLibScaleHandle = NULL;
Saurabh Shaheac146b2014-05-13 11:36:20 -0700599int (*Overlay::sFnProgramScale)(struct mdp_overlay_list *) = NULL;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500600
601}; // namespace overlay