blob: defb9dc8a21a53031eb17209cc82885f92277e99 [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);
161 }
162
163 eDest dest = OV_INVALID;
164
165 //The default behavior is to assume RGB and VG pipes have scalars
166 if(pipeSpecs.formatClass == FORMAT_YUV) {
167 return nextPipe(OV_MDP_PIPE_VG, pipeSpecs.dpy, pipeSpecs.mixer);
168 } else if(pipeSpecs.fb == false) { //RGB App layers
169 if(not pipeSpecs.needsScaling) {
170 dest = nextPipe(OV_MDP_PIPE_DMA, pipeSpecs.dpy, pipeSpecs.mixer);
171 }
172 if(dest == OV_INVALID) {
173 dest = nextPipe(OV_MDP_PIPE_RGB, pipeSpecs.dpy, pipeSpecs.mixer);
174 }
175 if(dest == OV_INVALID) {
176 dest = nextPipe(OV_MDP_PIPE_VG, pipeSpecs.dpy, pipeSpecs.mixer);
177 }
178 } else { //FB layer
179 dest = nextPipe(OV_MDP_PIPE_RGB, pipeSpecs.dpy, pipeSpecs.mixer);
180 if(dest == OV_INVALID) {
181 dest = nextPipe(OV_MDP_PIPE_VG, pipeSpecs.dpy, pipeSpecs.mixer);
182 }
183 //Some features can cause FB to have scaling as well.
184 //If we ever come to this block with FB needing scaling,
185 //the screen will be black for a frame, since the FB won't get a pipe
186 //but atleast this will prevent a hang
187 if(dest == OV_INVALID and (not pipeSpecs.needsScaling)) {
188 dest = nextPipe(OV_MDP_PIPE_DMA, pipeSpecs.dpy, pipeSpecs.mixer);
189 }
190 }
191 return dest;
192}
193
194utils::eDest Overlay::getPipe_8x26(const PipeSpecs& pipeSpecs) {
195 //Use this to hide all the 8x26 requirements that cannot be humanly
196 //described in a generic way
197 eDest dest = OV_INVALID;
198 if(pipeSpecs.formatClass == FORMAT_YUV) { //video
199 return nextPipe(OV_MDP_PIPE_VG, pipeSpecs.dpy, pipeSpecs.mixer);
200 } else if(pipeSpecs.fb == false) { //RGB app layers
Xu Yang1e686f62014-04-08 13:56:47 +0800201 if((not pipeSpecs.needsScaling) and
202 (not (pipeSpecs.numActiveDisplays > 1 &&
203 pipeSpecs.dpy == DPY_PRIMARY))) {
Saurabh Shahc62f3982014-03-05 14:28:26 -0800204 dest = nextPipe(OV_MDP_PIPE_DMA, pipeSpecs.dpy, pipeSpecs.mixer);
205 }
206 if(dest == OV_INVALID) {
207 dest = nextPipe(OV_MDP_PIPE_RGB, pipeSpecs.dpy, pipeSpecs.mixer);
208 }
209 if(dest == OV_INVALID) {
210 dest = nextPipe(OV_MDP_PIPE_VG, pipeSpecs.dpy, pipeSpecs.mixer);
211 }
212 } else { //FB layer
213 //For 8x26 Secondary we use DMA always for FB for inline rotation
214 if(pipeSpecs.dpy == DPY_PRIMARY) {
215 dest = nextPipe(OV_MDP_PIPE_RGB, pipeSpecs.dpy, pipeSpecs.mixer);
216 if(dest == OV_INVALID) {
217 dest = nextPipe(OV_MDP_PIPE_VG, pipeSpecs.dpy, pipeSpecs.mixer);
218 }
219 }
Xu Yang1e686f62014-04-08 13:56:47 +0800220 if(dest == OV_INVALID and (not pipeSpecs.needsScaling) and
221 (not (pipeSpecs.numActiveDisplays > 1 &&
222 pipeSpecs.dpy == DPY_PRIMARY))) {
Saurabh Shahc62f3982014-03-05 14:28:26 -0800223 dest = nextPipe(OV_MDP_PIPE_DMA, pipeSpecs.dpy, pipeSpecs.mixer);
224 }
225 }
226 return dest;
227}
228
229utils::eDest Overlay::getPipe_8x16(const PipeSpecs& pipeSpecs) {
230 //Having such functions help keeping the interface generic but code specific
231 //and rife with assumptions
232 eDest dest = OV_INVALID;
233 if(pipeSpecs.formatClass == FORMAT_YUV or pipeSpecs.needsScaling) {
234 return nextPipe(OV_MDP_PIPE_VG, pipeSpecs.dpy, pipeSpecs.mixer);
radhakrishna89298462014-04-22 19:10:36 +0530235 } else {
Saurabh Shahc62f3982014-03-05 14:28:26 -0800236 //Since this is a specific func, we can assume stuff like RGB pipe not
237 //having scalar blocks
238 dest = nextPipe(OV_MDP_PIPE_RGB, pipeSpecs.dpy, pipeSpecs.mixer);
239 if(dest == OV_INVALID) {
240 dest = nextPipe(OV_MDP_PIPE_DMA, pipeSpecs.dpy, pipeSpecs.mixer);
241 }
Saurabh Shahc62f3982014-03-05 14:28:26 -0800242 if(dest == OV_INVALID) {
radhakrishna89298462014-04-22 19:10:36 +0530243 dest = nextPipe(OV_MDP_PIPE_VG, pipeSpecs.dpy, pipeSpecs.mixer);
Saurabh Shahc62f3982014-03-05 14:28:26 -0800244 }
245 }
246 return dest;
247}
248
Zohaib Alam4b0a9242013-11-20 23:54:12 -0500249void Overlay::endAllSessions() {
250 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
251 if(mPipeBook[i].valid() && mPipeBook[i].mSession==PipeBook::START)
252 mPipeBook[i].mSession = PipeBook::END;
253 }
254}
255
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700256bool Overlay::isPipeTypeAttached(eMdpPipeType type) {
257 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
258 if(type == PipeBook::getPipeType((eDest)i) &&
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700259 mPipeBook[i].mDisplay != DPY_UNUSED) {
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700260 return true;
261 }
262 }
263 return false;
264}
265
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800266int Overlay::comparePipePriority(utils::eDest pipe1Index,
267 utils::eDest pipe2Index) {
268 validate((int)pipe1Index);
269 validate((int)pipe2Index);
270 uint8_t pipe1Prio = mPipeBook[(int)pipe1Index].mPipe->getPriority();
271 uint8_t pipe2Prio = mPipeBook[(int)pipe2Index].mPipe->getPriority();
272 if(pipe1Prio > pipe2Prio)
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800273 return -1;
Tatenda Chipeperekwa657afa22014-04-15 12:02:39 -0700274 if(pipe1Prio < pipe2Prio)
275 return 1;
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800276 return 0;
277}
278
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500279bool Overlay::commit(utils::eDest dest) {
280 bool ret = false;
281 int index = (int)dest;
282 validate(index);
283
284 if(mPipeBook[index].mPipe->commit()) {
285 ret = true;
286 PipeBook::setUse((int)dest);
287 } else {
Sushil Chauhane0dff932013-03-01 14:33:18 -0800288 int dpy = mPipeBook[index].mDisplay;
Saurabh Shah7445d4b2013-12-05 17:24:45 -0800289 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
Saurabh Shahdf0be752013-05-23 14:40:00 -0700290 if (mPipeBook[i].mDisplay == dpy) {
Sushil Chauhane0dff932013-03-01 14:33:18 -0800291 PipeBook::resetAllocation(i);
Saurabh Shahdf0be752013-05-23 14:40:00 -0700292 PipeBook::resetUse(i);
Saurabh Shahdf0be752013-05-23 14:40:00 -0700293 }
Saurabh Shah7445d4b2013-12-05 17:24:45 -0800294 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500295 }
296 return ret;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700297}
298
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700299bool Overlay::queueBuffer(int fd, uint32_t offset,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500300 utils::eDest dest) {
301 int index = (int)dest;
302 bool ret = false;
303 validate(index);
304 //Queue only if commit() has succeeded (and the bit set)
305 if(PipeBook::isUsed((int)dest)) {
306 ret = mPipeBook[index].mPipe->queueBuffer(fd, offset);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700307 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500308 return ret;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700309}
310
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500311void Overlay::setCrop(const utils::Dim& d,
312 utils::eDest dest) {
313 int index = (int)dest;
314 validate(index);
315 mPipeBook[index].mPipe->setCrop(d);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700316}
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700317
Sushil Chauhan897a9c32013-07-18 11:09:55 -0700318void Overlay::setColor(const uint32_t color,
319 utils::eDest dest) {
320 int index = (int)dest;
321 validate(index);
322 mPipeBook[index].mPipe->setColor(color);
323}
324
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500325void Overlay::setPosition(const utils::Dim& d,
326 utils::eDest dest) {
327 int index = (int)dest;
328 validate(index);
329 mPipeBook[index].mPipe->setPosition(d);
330}
331
332void Overlay::setTransform(const int orient,
333 utils::eDest dest) {
334 int index = (int)dest;
335 validate(index);
336
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700337 utils::eTransform transform =
338 static_cast<utils::eTransform>(orient);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500339 mPipeBook[index].mPipe->setTransform(transform);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700340
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500341}
342
343void Overlay::setSource(const utils::PipeArgs args,
344 utils::eDest dest) {
345 int index = (int)dest;
346 validate(index);
347
348 PipeArgs newArgs(args);
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800349 if(PipeBook::getPipeType(dest) == OV_MDP_PIPE_VG) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500350 setMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_SHARE);
351 } else {
352 clearMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_SHARE);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700353 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800354
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800355 if(PipeBook::getPipeType(dest) == OV_MDP_PIPE_DMA) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800356 setMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_FORCE_DMA);
357 } else {
358 clearMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_FORCE_DMA);
359 }
360
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500361 mPipeBook[index].mPipe->setSource(newArgs);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700362}
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700363
Saurabh Shah5daeee52013-01-23 16:52:26 +0800364void Overlay::setVisualParams(const MetaData_t& metadata, utils::eDest dest) {
365 int index = (int)dest;
366 validate(index);
367 mPipeBook[index].mPipe->setVisualParams(metadata);
368}
369
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500370Overlay* Overlay::getInstance() {
371 if(sInstance == NULL) {
372 sInstance = new Overlay();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700373 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500374 return sInstance;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700375}
376
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800377// Clears any VG pipes allocated to the fb devices
378// Generates a LUT for pipe types.
379int Overlay::initOverlay() {
380 int mdpVersion = qdutils::MDPVersion::getInstance().getMDPVersion();
381 int numPipesXType[OV_MDP_PIPE_ANY] = {0};
382 numPipesXType[OV_MDP_PIPE_RGB] =
383 qdutils::MDPVersion::getInstance().getRGBPipes();
384 numPipesXType[OV_MDP_PIPE_VG] =
385 qdutils::MDPVersion::getInstance().getVGPipes();
386 numPipesXType[OV_MDP_PIPE_DMA] =
387 qdutils::MDPVersion::getInstance().getDMAPipes();
388
389 int index = 0;
390 for(int X = 0; X < (int)OV_MDP_PIPE_ANY; X++) { //iterate over types
391 for(int j = 0; j < numPipesXType[X]; j++) { //iterate over num
392 PipeBook::pipeTypeLUT[index] = (utils::eMdpPipeType)X;
393 index++;
394 }
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700395 }
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800396
Xiaoming Zhou5eff8b62013-05-01 20:56:09 -0400397 if (mdpVersion < qdutils::MDSS_V5 && mdpVersion != qdutils::MDP_V3_0_4) {
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800398 msmfb_mixer_info_req req;
399 mdp_mixer_info *minfo = NULL;
400 char name[64];
401 int fd = -1;
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700402 for(int i = 0; i < MAX_FB_DEVICES; i++) {
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800403 snprintf(name, 64, FB_DEVICE_TEMPLATE, i);
404 ALOGD("initoverlay:: opening the device:: %s", name);
405 fd = ::open(name, O_RDWR, 0);
406 if(fd < 0) {
407 ALOGE("cannot open framebuffer(%d)", i);
408 return -1;
409 }
410 //Get the mixer configuration */
411 req.mixer_num = i;
412 if (ioctl(fd, MSMFB_MIXER_INFO, &req) == -1) {
413 ALOGE("ERROR: MSMFB_MIXER_INFO ioctl failed");
414 close(fd);
415 return -1;
416 }
417 minfo = req.info;
418 for (int j = 0; j < req.cnt; j++) {
419 ALOGD("ndx=%d num=%d z_order=%d", minfo->pndx, minfo->pnum,
420 minfo->z_order);
421 // except the RGB base layer with z_order of -1, clear any
422 // other pipes connected to mixer.
423 if((minfo->z_order) != -1) {
424 int index = minfo->pndx;
425 ALOGD("Unset overlay with index: %d at mixer %d", index, i);
426 if(ioctl(fd, MSMFB_OVERLAY_UNSET, &index) == -1) {
427 ALOGE("ERROR: MSMFB_OVERLAY_UNSET failed");
428 close(fd);
429 return -1;
430 }
431 }
432 minfo++;
433 }
434 close(fd);
435 fd = -1;
436 }
437 }
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700438
439 FILE *displayDeviceFP = NULL;
440 const int MAX_FRAME_BUFFER_NAME_SIZE = 128;
441 char fbType[MAX_FRAME_BUFFER_NAME_SIZE];
442 char msmFbTypePath[MAX_FRAME_BUFFER_NAME_SIZE];
443 const char *strDtvPanel = "dtv panel";
444 const char *strWbPanel = "writeback panel";
445
446 for(int num = 1; num < MAX_FB_DEVICES; num++) {
447 snprintf (msmFbTypePath, sizeof(msmFbTypePath),
448 "/sys/class/graphics/fb%d/msm_fb_type", num);
449 displayDeviceFP = fopen(msmFbTypePath, "r");
450
451 if(displayDeviceFP){
452 fread(fbType, sizeof(char), MAX_FRAME_BUFFER_NAME_SIZE,
453 displayDeviceFP);
454
455 if(strncmp(fbType, strDtvPanel, strlen(strDtvPanel)) == 0) {
456 sDpyFbMap[DPY_EXTERNAL] = num;
457 } else if(strncmp(fbType, strWbPanel, strlen(strWbPanel)) == 0) {
458 sDpyFbMap[DPY_WRITEBACK] = num;
459 }
460
461 fclose(displayDeviceFP);
462 }
463 }
464
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800465 return 0;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700466}
467
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700468bool Overlay::displayCommit(const int& fd) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700469 utils::Dim roi;
470 return displayCommit(fd, roi);
471}
472
473bool Overlay::displayCommit(const int& fd, const utils::Dim& roi) {
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700474 //Commit
475 struct mdp_display_commit info;
476 memset(&info, 0, sizeof(struct mdp_display_commit));
477 info.flags = MDP_DISPLAY_COMMIT_OVERLAY;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700478 info.roi.x = roi.x;
479 info.roi.y = roi.y;
480 info.roi.w = roi.w;
481 info.roi.h = roi.h;
482
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700483 if(!mdp_wrapper::displayCommit(fd, info)) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700484 ALOGE("%s: commit failed", __func__);
485 return false;
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700486 }
487 return true;
488}
489
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500490void Overlay::dump() const {
Saurabh Shah9dc88fc2013-07-15 16:02:30 -0700491#if PIPE_DEBUG
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500492 if(strlen(mDumpStr)) { //dump only on state change
Saurabh Shah9dc88fc2013-07-15 16:02:30 -0700493 ALOGD("%s\n", mDumpStr);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500494 }
Saurabh Shah9dc88fc2013-07-15 16:02:30 -0700495#endif
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500496}
497
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800498void Overlay::getDump(char *buf, size_t len) {
499 int totalPipes = 0;
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700500 const char *str = "\nOverlay State\n\n";
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800501 strlcat(buf, str, len);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800502 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
503 if(mPipeBook[i].valid()) {
504 mPipeBook[i].mPipe->getDump(buf, len);
505 char str[64] = {'\0'};
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700506 snprintf(str, 64, "Display=%d\n\n", mPipeBook[i].mDisplay);
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800507 strlcat(buf, str, len);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800508 totalPipes++;
509 }
510 }
511 char str_pipes[64] = {'\0'};
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700512 snprintf(str_pipes, 64, "Pipes=%d\n\n", totalPipes);
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800513 strlcat(buf, str_pipes, len);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800514}
515
Sushil Chauhanbd3ea922013-05-15 12:25:26 -0700516void Overlay::clear(int dpy) {
517 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
518 if (mPipeBook[i].mDisplay == dpy) {
519 // Mark as available for this round
520 PipeBook::resetUse(i);
521 PipeBook::resetAllocation(i);
522 }
523 }
524}
525
Saurabh Shaha36be922013-12-16 18:18:39 -0800526bool Overlay::validateAndSet(const int& dpy, const int& fbFd) {
527 GenericPipe* pipeArray[PipeBook::NUM_PIPES];
528 memset(&pipeArray, 0, sizeof(pipeArray));
529
530 int num = 0;
531 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
532 if(PipeBook::isUsed(i) && mPipeBook[i].valid() &&
533 mPipeBook[i].mDisplay == dpy) {
534 pipeArray[num++] = mPipeBook[i].mPipe;
535 }
536 }
537
538 //Protect against misbehaving clients
539 return num ? GenericPipe::validateAndSet(pipeArray, num, fbFd) : true;
540}
541
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700542void Overlay::initScalar() {
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700543 if(sLibScaleHandle == NULL) {
544 sLibScaleHandle = dlopen("libscale.so", RTLD_NOW);
Saurabh Shaheac146b2014-05-13 11:36:20 -0700545 if(sLibScaleHandle) {
546 *(void **) &sFnProgramScale =
547 dlsym(sLibScaleHandle, "programScale");
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700548 }
549 }
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700550}
551
552void Overlay::destroyScalar() {
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700553 if(sLibScaleHandle) {
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700554 dlclose(sLibScaleHandle);
555 sLibScaleHandle = NULL;
556 }
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700557}
558
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500559void Overlay::PipeBook::init() {
560 mPipe = NULL;
561 mDisplay = DPY_UNUSED;
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700562 mMixer = MIXER_UNUSED;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500563}
564
565void Overlay::PipeBook::destroy() {
566 if(mPipe) {
567 delete mPipe;
568 mPipe = NULL;
569 }
570 mDisplay = DPY_UNUSED;
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700571 mMixer = MIXER_UNUSED;
Zohaib Alam4b0a9242013-11-20 23:54:12 -0500572 mSession = NONE;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500573}
574
575Overlay* Overlay::sInstance = 0;
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700576int Overlay::sDpyFbMap[DPY_MAX] = {0, -1, -1};
Saurabh Shah85234ec2013-04-12 17:09:00 -0700577int Overlay::sDMAMode = DMA_LINE_MODE;
Raj Kamala8c065f2013-10-22 14:52:45 +0530578bool Overlay::sDMAMultiplexingSupported = false;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500579int Overlay::PipeBook::NUM_PIPES = 0;
580int Overlay::PipeBook::sPipeUsageBitmap = 0;
581int Overlay::PipeBook::sLastUsageBitmap = 0;
582int Overlay::PipeBook::sAllocatedBitmap = 0;
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800583utils::eMdpPipeType Overlay::PipeBook::pipeTypeLUT[utils::OV_MAX] =
584 {utils::OV_MDP_PIPE_ANY};
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700585void *Overlay::sLibScaleHandle = NULL;
Saurabh Shaheac146b2014-05-13 11:36:20 -0700586int (*Overlay::sFnProgramScale)(struct mdp_overlay_list *) = NULL;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500587
588}; // namespace overlay