blob: d53b46d9bd7cbd629213b9360ad0829259957a67 [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
Saurabh Shahb8f58e22013-09-26 16:20:07 -070036#ifdef USES_QSEED_SCALAR
37#include <scale/scale.h>
38using namespace scale;
39#endif
40
Naseer Ahmed758bfc52012-11-28 17:02:08 -050041#define PIPE_DEBUG 0
Naseer Ahmed29a26812012-06-14 00:56:20 -070042
43namespace overlay {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050044using namespace utils;
Saurabh Shahc62f3982014-03-05 14:28:26 -080045using namespace qdutils;
Saurabh Shahb8f58e22013-09-26 16:20:07 -070046
Naseer Ahmed758bfc52012-11-28 17:02:08 -050047Overlay::Overlay() {
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -080048 int numPipes = qdutils::MDPVersion::getInstance().getTotalPipes();
49 PipeBook::NUM_PIPES = (numPipes <= utils::OV_MAX)? numPipes : utils::OV_MAX;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050050 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
51 mPipeBook[i].init();
Naseer Ahmed1ddf3662012-07-31 19:14:18 -070052 }
Naseer Ahmed1ddf3662012-07-31 19:14:18 -070053
Naseer Ahmed758bfc52012-11-28 17:02:08 -050054 mDumpStr[0] = '\0';
Saurabh Shahb8f58e22013-09-26 16:20:07 -070055 initScalar();
Raj Kamala8c065f2013-10-22 14:52:45 +053056 setDMAMultiplexingSupported();
Naseer Ahmed29a26812012-06-14 00:56:20 -070057}
58
59Overlay::~Overlay() {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050060 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
61 mPipeBook[i].destroy();
62 }
Saurabh Shahb8f58e22013-09-26 16:20:07 -070063 destroyScalar();
Naseer Ahmed29a26812012-06-14 00:56:20 -070064}
65
Naseer Ahmed758bfc52012-11-28 17:02:08 -050066void Overlay::configBegin() {
67 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
68 //Mark as available for this round.
69 PipeBook::resetUse(i);
70 PipeBook::resetAllocation(i);
71 }
72 mDumpStr[0] = '\0';
73}
74
75void Overlay::configDone() {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050076 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
Zohaib Alam4b0a9242013-11-20 23:54:12 -050077 if((PipeBook::isNotUsed(i) && !sessionInProgress((eDest)i)) ||
78 isSessionEnded((eDest)i)) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050079 //Forces UNSET on pipes, flushes rotator memory and session, closes
80 //fds
81 if(mPipeBook[i].valid()) {
82 char str[32];
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -080083 snprintf(str, 32, "Unset=%s dpy=%d mix=%d; ",
Saurabh Shahaf5f5972013-07-30 13:56:35 -070084 PipeBook::getDestStr((eDest)i),
85 mPipeBook[i].mDisplay, mPipeBook[i].mMixer);
Saurabh Shah9dc88fc2013-07-15 16:02:30 -070086#if PIPE_DEBUG
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -080087 strlcat(mDumpStr, str, sizeof(mDumpStr));
Saurabh Shah9dc88fc2013-07-15 16:02:30 -070088#endif
Naseer Ahmed758bfc52012-11-28 17:02:08 -050089 }
90 mPipeBook[i].destroy();
Naseer Ahmed1ddf3662012-07-31 19:14:18 -070091 }
Naseer Ahmed29a26812012-06-14 00:56:20 -070092 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -050093 dump();
94 PipeBook::save();
95}
96
Zohaib Alam4b0a9242013-11-20 23:54:12 -050097int Overlay::getPipeId(utils::eDest dest) {
98 return mPipeBook[(int)dest].mPipe->getPipeId();
99}
100
101eDest Overlay::getDest(int pipeid) {
102 eDest dest = OV_INVALID;
103 // finding the dest corresponding to the given pipe
104 for(int i=0; i < PipeBook::NUM_PIPES; ++i) {
105 if(mPipeBook[i].valid() && mPipeBook[i].mPipe->getPipeId() == pipeid) {
106 return (eDest)i;
107 }
108 }
109 return dest;
110}
111
112eDest Overlay::reservePipe(int pipeid) {
113 eDest dest = getDest(pipeid);
114 PipeBook::setAllocation((int)dest);
115 return dest;
116}
117
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700118eDest Overlay::nextPipe(eMdpPipeType type, int dpy, int mixer) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500119 eDest dest = OV_INVALID;
120
121 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700122 if( (type == OV_MDP_PIPE_ANY || //Pipe type match
123 type == PipeBook::getPipeType((eDest)i)) &&
124 (mPipeBook[i].mDisplay == DPY_UNUSED || //Free or same display
125 mPipeBook[i].mDisplay == dpy) &&
126 (mPipeBook[i].mMixer == MIXER_UNUSED || //Free or same mixer
127 mPipeBook[i].mMixer == mixer) &&
128 PipeBook::isNotAllocated(i) && //Free pipe
Raj Kamala8c065f2013-10-22 14:52:45 +0530129 ( (sDMAMultiplexingSupported && dpy) ||
130 !(sDMAMode == DMA_BLOCK_MODE && //DMA pipe in Line mode
131 PipeBook::getPipeType((eDest)i) == OV_MDP_PIPE_DMA)) ){
132 //DMA-Multiplexing is only supported for WB on 8x26
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700133 dest = (eDest)i;
134 PipeBook::setAllocation(i);
135 break;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500136 }
137 }
138
139 if(dest != OV_INVALID) {
140 int index = (int)dest;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500141 mPipeBook[index].mDisplay = dpy;
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700142 mPipeBook[index].mMixer = mixer;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500143 if(not mPipeBook[index].valid()) {
144 mPipeBook[index].mPipe = new GenericPipe(dpy);
Zohaib Alam4b0a9242013-11-20 23:54:12 -0500145 mPipeBook[index].mSession = PipeBook::NONE;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500146 char str[32];
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700147 snprintf(str, 32, "Set=%s dpy=%d mix=%d; ",
148 PipeBook::getDestStr(dest), dpy, mixer);
Saurabh Shah9dc88fc2013-07-15 16:02:30 -0700149#if PIPE_DEBUG
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800150 strlcat(mDumpStr, str, sizeof(mDumpStr));
Saurabh Shah9dc88fc2013-07-15 16:02:30 -0700151#endif
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500152 }
153 } else {
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700154 ALOGD_IF(PIPE_DEBUG, "Pipe unavailable type=%d display=%d mixer=%d",
155 (int)type, dpy, mixer);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500156 }
157
158 return dest;
159}
160
Saurabh Shahc62f3982014-03-05 14:28:26 -0800161utils::eDest Overlay::getPipe(const PipeSpecs& pipeSpecs) {
162 if(MDPVersion::getInstance().is8x26()) {
163 return getPipe_8x26(pipeSpecs);
164 } else if(MDPVersion::getInstance().is8x16()) {
165 return getPipe_8x16(pipeSpecs);
166 }
167
168 eDest dest = OV_INVALID;
169
170 //The default behavior is to assume RGB and VG pipes have scalars
171 if(pipeSpecs.formatClass == FORMAT_YUV) {
172 return nextPipe(OV_MDP_PIPE_VG, pipeSpecs.dpy, pipeSpecs.mixer);
173 } else if(pipeSpecs.fb == false) { //RGB App layers
174 if(not pipeSpecs.needsScaling) {
175 dest = nextPipe(OV_MDP_PIPE_DMA, pipeSpecs.dpy, pipeSpecs.mixer);
176 }
177 if(dest == OV_INVALID) {
178 dest = nextPipe(OV_MDP_PIPE_RGB, pipeSpecs.dpy, pipeSpecs.mixer);
179 }
180 if(dest == OV_INVALID) {
181 dest = nextPipe(OV_MDP_PIPE_VG, pipeSpecs.dpy, pipeSpecs.mixer);
182 }
183 } else { //FB layer
184 dest = nextPipe(OV_MDP_PIPE_RGB, pipeSpecs.dpy, pipeSpecs.mixer);
185 if(dest == OV_INVALID) {
186 dest = nextPipe(OV_MDP_PIPE_VG, pipeSpecs.dpy, pipeSpecs.mixer);
187 }
188 //Some features can cause FB to have scaling as well.
189 //If we ever come to this block with FB needing scaling,
190 //the screen will be black for a frame, since the FB won't get a pipe
191 //but atleast this will prevent a hang
192 if(dest == OV_INVALID and (not pipeSpecs.needsScaling)) {
193 dest = nextPipe(OV_MDP_PIPE_DMA, pipeSpecs.dpy, pipeSpecs.mixer);
194 }
195 }
196 return dest;
197}
198
199utils::eDest Overlay::getPipe_8x26(const PipeSpecs& pipeSpecs) {
200 //Use this to hide all the 8x26 requirements that cannot be humanly
201 //described in a generic way
202 eDest dest = OV_INVALID;
203 if(pipeSpecs.formatClass == FORMAT_YUV) { //video
204 return nextPipe(OV_MDP_PIPE_VG, pipeSpecs.dpy, pipeSpecs.mixer);
205 } else if(pipeSpecs.fb == false) { //RGB app layers
Xu Yang1e686f62014-04-08 13:56:47 +0800206 if((not pipeSpecs.needsScaling) and
207 (not (pipeSpecs.numActiveDisplays > 1 &&
208 pipeSpecs.dpy == DPY_PRIMARY))) {
Saurabh Shahc62f3982014-03-05 14:28:26 -0800209 dest = nextPipe(OV_MDP_PIPE_DMA, pipeSpecs.dpy, pipeSpecs.mixer);
210 }
211 if(dest == OV_INVALID) {
212 dest = nextPipe(OV_MDP_PIPE_RGB, pipeSpecs.dpy, pipeSpecs.mixer);
213 }
214 if(dest == OV_INVALID) {
215 dest = nextPipe(OV_MDP_PIPE_VG, pipeSpecs.dpy, pipeSpecs.mixer);
216 }
217 } else { //FB layer
218 //For 8x26 Secondary we use DMA always for FB for inline rotation
219 if(pipeSpecs.dpy == DPY_PRIMARY) {
220 dest = nextPipe(OV_MDP_PIPE_RGB, pipeSpecs.dpy, pipeSpecs.mixer);
221 if(dest == OV_INVALID) {
222 dest = nextPipe(OV_MDP_PIPE_VG, pipeSpecs.dpy, pipeSpecs.mixer);
223 }
224 }
Xu Yang1e686f62014-04-08 13:56:47 +0800225 if(dest == OV_INVALID and (not pipeSpecs.needsScaling) and
226 (not (pipeSpecs.numActiveDisplays > 1 &&
227 pipeSpecs.dpy == DPY_PRIMARY))) {
Saurabh Shahc62f3982014-03-05 14:28:26 -0800228 dest = nextPipe(OV_MDP_PIPE_DMA, pipeSpecs.dpy, pipeSpecs.mixer);
229 }
230 }
231 return dest;
232}
233
234utils::eDest Overlay::getPipe_8x16(const PipeSpecs& pipeSpecs) {
235 //Having such functions help keeping the interface generic but code specific
236 //and rife with assumptions
237 eDest dest = OV_INVALID;
238 if(pipeSpecs.formatClass == FORMAT_YUV or pipeSpecs.needsScaling) {
239 return nextPipe(OV_MDP_PIPE_VG, pipeSpecs.dpy, pipeSpecs.mixer);
radhakrishna89298462014-04-22 19:10:36 +0530240 } else {
Saurabh Shahc62f3982014-03-05 14:28:26 -0800241 //Since this is a specific func, we can assume stuff like RGB pipe not
242 //having scalar blocks
243 dest = nextPipe(OV_MDP_PIPE_RGB, pipeSpecs.dpy, pipeSpecs.mixer);
244 if(dest == OV_INVALID) {
245 dest = nextPipe(OV_MDP_PIPE_DMA, pipeSpecs.dpy, pipeSpecs.mixer);
246 }
Saurabh Shahc62f3982014-03-05 14:28:26 -0800247 if(dest == OV_INVALID) {
radhakrishna89298462014-04-22 19:10:36 +0530248 dest = nextPipe(OV_MDP_PIPE_VG, pipeSpecs.dpy, pipeSpecs.mixer);
Saurabh Shahc62f3982014-03-05 14:28:26 -0800249 }
250 }
251 return dest;
252}
253
Zohaib Alam4b0a9242013-11-20 23:54:12 -0500254void Overlay::endAllSessions() {
255 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
256 if(mPipeBook[i].valid() && mPipeBook[i].mSession==PipeBook::START)
257 mPipeBook[i].mSession = PipeBook::END;
258 }
259}
260
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700261bool Overlay::isPipeTypeAttached(eMdpPipeType type) {
262 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
263 if(type == PipeBook::getPipeType((eDest)i) &&
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700264 mPipeBook[i].mDisplay != DPY_UNUSED) {
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700265 return true;
266 }
267 }
268 return false;
269}
270
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800271int Overlay::comparePipePriority(utils::eDest pipe1Index,
272 utils::eDest pipe2Index) {
273 validate((int)pipe1Index);
274 validate((int)pipe2Index);
275 uint8_t pipe1Prio = mPipeBook[(int)pipe1Index].mPipe->getPriority();
276 uint8_t pipe2Prio = mPipeBook[(int)pipe2Index].mPipe->getPriority();
277 if(pipe1Prio > pipe2Prio)
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800278 return -1;
Tatenda Chipeperekwa657afa22014-04-15 12:02:39 -0700279 if(pipe1Prio < pipe2Prio)
280 return 1;
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800281 return 0;
282}
283
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500284bool Overlay::commit(utils::eDest dest) {
285 bool ret = false;
286 int index = (int)dest;
287 validate(index);
288
289 if(mPipeBook[index].mPipe->commit()) {
290 ret = true;
291 PipeBook::setUse((int)dest);
292 } else {
Sushil Chauhane0dff932013-03-01 14:33:18 -0800293 int dpy = mPipeBook[index].mDisplay;
Saurabh Shah7445d4b2013-12-05 17:24:45 -0800294 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
Saurabh Shahdf0be752013-05-23 14:40:00 -0700295 if (mPipeBook[i].mDisplay == dpy) {
Sushil Chauhane0dff932013-03-01 14:33:18 -0800296 PipeBook::resetAllocation(i);
Saurabh Shahdf0be752013-05-23 14:40:00 -0700297 PipeBook::resetUse(i);
Saurabh Shahdf0be752013-05-23 14:40:00 -0700298 }
Saurabh Shah7445d4b2013-12-05 17:24:45 -0800299 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500300 }
301 return ret;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700302}
303
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700304bool Overlay::queueBuffer(int fd, uint32_t offset,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500305 utils::eDest dest) {
306 int index = (int)dest;
307 bool ret = false;
308 validate(index);
309 //Queue only if commit() has succeeded (and the bit set)
310 if(PipeBook::isUsed((int)dest)) {
311 ret = mPipeBook[index].mPipe->queueBuffer(fd, offset);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700312 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500313 return ret;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700314}
315
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500316void Overlay::setCrop(const utils::Dim& d,
317 utils::eDest dest) {
318 int index = (int)dest;
319 validate(index);
320 mPipeBook[index].mPipe->setCrop(d);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700321}
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700322
Sushil Chauhan897a9c32013-07-18 11:09:55 -0700323void Overlay::setColor(const uint32_t color,
324 utils::eDest dest) {
325 int index = (int)dest;
326 validate(index);
327 mPipeBook[index].mPipe->setColor(color);
328}
329
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500330void Overlay::setPosition(const utils::Dim& d,
331 utils::eDest dest) {
332 int index = (int)dest;
333 validate(index);
334 mPipeBook[index].mPipe->setPosition(d);
335}
336
337void Overlay::setTransform(const int orient,
338 utils::eDest dest) {
339 int index = (int)dest;
340 validate(index);
341
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700342 utils::eTransform transform =
343 static_cast<utils::eTransform>(orient);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500344 mPipeBook[index].mPipe->setTransform(transform);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700345
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500346}
347
348void Overlay::setSource(const utils::PipeArgs args,
349 utils::eDest dest) {
350 int index = (int)dest;
351 validate(index);
352
353 PipeArgs newArgs(args);
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800354 if(PipeBook::getPipeType(dest) == OV_MDP_PIPE_VG) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500355 setMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_SHARE);
356 } else {
357 clearMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_SHARE);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700358 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800359
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800360 if(PipeBook::getPipeType(dest) == OV_MDP_PIPE_DMA) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800361 setMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_FORCE_DMA);
362 } else {
363 clearMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_FORCE_DMA);
364 }
365
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500366 mPipeBook[index].mPipe->setSource(newArgs);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700367}
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700368
Saurabh Shah5daeee52013-01-23 16:52:26 +0800369void Overlay::setVisualParams(const MetaData_t& metadata, utils::eDest dest) {
370 int index = (int)dest;
371 validate(index);
372 mPipeBook[index].mPipe->setVisualParams(metadata);
373}
374
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500375Overlay* Overlay::getInstance() {
376 if(sInstance == NULL) {
377 sInstance = new Overlay();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700378 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500379 return sInstance;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700380}
381
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800382// Clears any VG pipes allocated to the fb devices
383// Generates a LUT for pipe types.
384int Overlay::initOverlay() {
385 int mdpVersion = qdutils::MDPVersion::getInstance().getMDPVersion();
386 int numPipesXType[OV_MDP_PIPE_ANY] = {0};
387 numPipesXType[OV_MDP_PIPE_RGB] =
388 qdutils::MDPVersion::getInstance().getRGBPipes();
389 numPipesXType[OV_MDP_PIPE_VG] =
390 qdutils::MDPVersion::getInstance().getVGPipes();
391 numPipesXType[OV_MDP_PIPE_DMA] =
392 qdutils::MDPVersion::getInstance().getDMAPipes();
393
394 int index = 0;
395 for(int X = 0; X < (int)OV_MDP_PIPE_ANY; X++) { //iterate over types
396 for(int j = 0; j < numPipesXType[X]; j++) { //iterate over num
397 PipeBook::pipeTypeLUT[index] = (utils::eMdpPipeType)X;
398 index++;
399 }
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700400 }
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800401
Xiaoming Zhou5eff8b62013-05-01 20:56:09 -0400402 if (mdpVersion < qdutils::MDSS_V5 && mdpVersion != qdutils::MDP_V3_0_4) {
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800403 msmfb_mixer_info_req req;
404 mdp_mixer_info *minfo = NULL;
405 char name[64];
406 int fd = -1;
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700407 for(int i = 0; i < MAX_FB_DEVICES; i++) {
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800408 snprintf(name, 64, FB_DEVICE_TEMPLATE, i);
409 ALOGD("initoverlay:: opening the device:: %s", name);
410 fd = ::open(name, O_RDWR, 0);
411 if(fd < 0) {
412 ALOGE("cannot open framebuffer(%d)", i);
413 return -1;
414 }
415 //Get the mixer configuration */
416 req.mixer_num = i;
417 if (ioctl(fd, MSMFB_MIXER_INFO, &req) == -1) {
418 ALOGE("ERROR: MSMFB_MIXER_INFO ioctl failed");
419 close(fd);
420 return -1;
421 }
422 minfo = req.info;
423 for (int j = 0; j < req.cnt; j++) {
424 ALOGD("ndx=%d num=%d z_order=%d", minfo->pndx, minfo->pnum,
425 minfo->z_order);
426 // except the RGB base layer with z_order of -1, clear any
427 // other pipes connected to mixer.
428 if((minfo->z_order) != -1) {
429 int index = minfo->pndx;
430 ALOGD("Unset overlay with index: %d at mixer %d", index, i);
431 if(ioctl(fd, MSMFB_OVERLAY_UNSET, &index) == -1) {
432 ALOGE("ERROR: MSMFB_OVERLAY_UNSET failed");
433 close(fd);
434 return -1;
435 }
436 }
437 minfo++;
438 }
439 close(fd);
440 fd = -1;
441 }
442 }
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700443
444 FILE *displayDeviceFP = NULL;
445 const int MAX_FRAME_BUFFER_NAME_SIZE = 128;
446 char fbType[MAX_FRAME_BUFFER_NAME_SIZE];
447 char msmFbTypePath[MAX_FRAME_BUFFER_NAME_SIZE];
448 const char *strDtvPanel = "dtv panel";
449 const char *strWbPanel = "writeback panel";
450
451 for(int num = 1; num < MAX_FB_DEVICES; num++) {
452 snprintf (msmFbTypePath, sizeof(msmFbTypePath),
453 "/sys/class/graphics/fb%d/msm_fb_type", num);
454 displayDeviceFP = fopen(msmFbTypePath, "r");
455
456 if(displayDeviceFP){
457 fread(fbType, sizeof(char), MAX_FRAME_BUFFER_NAME_SIZE,
458 displayDeviceFP);
459
460 if(strncmp(fbType, strDtvPanel, strlen(strDtvPanel)) == 0) {
461 sDpyFbMap[DPY_EXTERNAL] = num;
462 } else if(strncmp(fbType, strWbPanel, strlen(strWbPanel)) == 0) {
463 sDpyFbMap[DPY_WRITEBACK] = num;
464 }
465
466 fclose(displayDeviceFP);
467 }
468 }
469
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800470 return 0;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700471}
472
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700473bool Overlay::displayCommit(const int& fd) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700474 utils::Dim roi;
475 return displayCommit(fd, roi);
476}
477
478bool Overlay::displayCommit(const int& fd, const utils::Dim& roi) {
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700479 //Commit
480 struct mdp_display_commit info;
481 memset(&info, 0, sizeof(struct mdp_display_commit));
482 info.flags = MDP_DISPLAY_COMMIT_OVERLAY;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700483 info.roi.x = roi.x;
484 info.roi.y = roi.y;
485 info.roi.w = roi.w;
486 info.roi.h = roi.h;
487
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700488 if(!mdp_wrapper::displayCommit(fd, info)) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700489 ALOGE("%s: commit failed", __func__);
490 return false;
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700491 }
492 return true;
493}
494
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500495void Overlay::dump() const {
Saurabh Shah9dc88fc2013-07-15 16:02:30 -0700496#if PIPE_DEBUG
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500497 if(strlen(mDumpStr)) { //dump only on state change
Saurabh Shah9dc88fc2013-07-15 16:02:30 -0700498 ALOGD("%s\n", mDumpStr);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500499 }
Saurabh Shah9dc88fc2013-07-15 16:02:30 -0700500#endif
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500501}
502
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800503void Overlay::getDump(char *buf, size_t len) {
504 int totalPipes = 0;
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700505 const char *str = "\nOverlay State\n\n";
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800506 strlcat(buf, str, len);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800507 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
508 if(mPipeBook[i].valid()) {
509 mPipeBook[i].mPipe->getDump(buf, len);
510 char str[64] = {'\0'};
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700511 snprintf(str, 64, "Display=%d\n\n", mPipeBook[i].mDisplay);
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800512 strlcat(buf, str, len);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800513 totalPipes++;
514 }
515 }
516 char str_pipes[64] = {'\0'};
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700517 snprintf(str_pipes, 64, "Pipes=%d\n\n", totalPipes);
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800518 strlcat(buf, str_pipes, len);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800519}
520
Sushil Chauhanbd3ea922013-05-15 12:25:26 -0700521void Overlay::clear(int dpy) {
522 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
523 if (mPipeBook[i].mDisplay == dpy) {
524 // Mark as available for this round
525 PipeBook::resetUse(i);
526 PipeBook::resetAllocation(i);
527 }
528 }
529}
530
Saurabh Shaha36be922013-12-16 18:18:39 -0800531bool Overlay::validateAndSet(const int& dpy, const int& fbFd) {
532 GenericPipe* pipeArray[PipeBook::NUM_PIPES];
533 memset(&pipeArray, 0, sizeof(pipeArray));
534
535 int num = 0;
536 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
537 if(PipeBook::isUsed(i) && mPipeBook[i].valid() &&
538 mPipeBook[i].mDisplay == dpy) {
539 pipeArray[num++] = mPipeBook[i].mPipe;
540 }
541 }
542
543 //Protect against misbehaving clients
544 return num ? GenericPipe::validateAndSet(pipeArray, num, fbFd) : true;
545}
546
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700547void Overlay::initScalar() {
548#ifdef USES_QSEED_SCALAR
549 if(sLibScaleHandle == NULL) {
550 sLibScaleHandle = dlopen("libscale.so", RTLD_NOW);
551 }
552
553 if(sLibScaleHandle) {
554 if(sScale == NULL) {
555 Scale* (*getInstance)();
556 *(void **) &getInstance = dlsym(sLibScaleHandle, "getInstance");
557 if(getInstance) {
558 sScale = getInstance();
559 }
560 }
561 }
562#endif
563}
564
565void Overlay::destroyScalar() {
566#ifdef USES_QSEED_SCALAR
567 if(sLibScaleHandle) {
568 if(sScale) {
569 void (*destroyInstance)(Scale*);
570 *(void **) &destroyInstance = dlsym(sLibScaleHandle,
571 "destroyInstance");
572 if(destroyInstance) {
573 destroyInstance(sScale);
574 sScale = NULL;
575 }
576 }
577 dlclose(sLibScaleHandle);
578 sLibScaleHandle = NULL;
579 }
580#endif
581}
582
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500583void Overlay::PipeBook::init() {
584 mPipe = NULL;
585 mDisplay = DPY_UNUSED;
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700586 mMixer = MIXER_UNUSED;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500587}
588
589void Overlay::PipeBook::destroy() {
590 if(mPipe) {
591 delete mPipe;
592 mPipe = NULL;
593 }
594 mDisplay = DPY_UNUSED;
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700595 mMixer = MIXER_UNUSED;
Zohaib Alam4b0a9242013-11-20 23:54:12 -0500596 mSession = NONE;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500597}
598
599Overlay* Overlay::sInstance = 0;
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700600int Overlay::sDpyFbMap[DPY_MAX] = {0, -1, -1};
Saurabh Shah85234ec2013-04-12 17:09:00 -0700601int Overlay::sDMAMode = DMA_LINE_MODE;
Raj Kamala8c065f2013-10-22 14:52:45 +0530602bool Overlay::sDMAMultiplexingSupported = false;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500603int Overlay::PipeBook::NUM_PIPES = 0;
604int Overlay::PipeBook::sPipeUsageBitmap = 0;
605int Overlay::PipeBook::sLastUsageBitmap = 0;
606int Overlay::PipeBook::sAllocatedBitmap = 0;
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800607utils::eMdpPipeType Overlay::PipeBook::pipeTypeLUT[utils::OV_MAX] =
608 {utils::OV_MDP_PIPE_ANY};
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700609void *Overlay::sLibScaleHandle = NULL;
610scale::Scale *Overlay::sScale = NULL;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500611
612}; // namespace overlay