blob: cad4c7d4b66e4645019e2c0af5fc018b53fd83e1 [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 Ahmed29a26812012-06-14 00:56:20 -070036namespace overlay {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050037using namespace utils;
Saurabh Shahc62f3982014-03-05 14:28:26 -080038using namespace qdutils;
Saurabh Shahb8f58e22013-09-26 16:20:07 -070039
Naseer Ahmed758bfc52012-11-28 17:02:08 -050040Overlay::Overlay() {
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -080041 int numPipes = qdutils::MDPVersion::getInstance().getTotalPipes();
42 PipeBook::NUM_PIPES = (numPipes <= utils::OV_MAX)? numPipes : utils::OV_MAX;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050043 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
44 mPipeBook[i].init();
Naseer Ahmed1ddf3662012-07-31 19:14:18 -070045 }
Naseer Ahmed1ddf3662012-07-31 19:14:18 -070046
Saurabh Shahb8f58e22013-09-26 16:20:07 -070047 initScalar();
Raj Kamala8c065f2013-10-22 14:52:45 +053048 setDMAMultiplexingSupported();
Naseer Ahmed29a26812012-06-14 00:56:20 -070049}
50
51Overlay::~Overlay() {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050052 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
53 mPipeBook[i].destroy();
54 }
Saurabh Shahb8f58e22013-09-26 16:20:07 -070055 destroyScalar();
Naseer Ahmed29a26812012-06-14 00:56:20 -070056}
57
Naseer Ahmed758bfc52012-11-28 17:02:08 -050058void Overlay::configBegin() {
59 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
60 //Mark as available for this round.
61 PipeBook::resetUse(i);
62 PipeBook::resetAllocation(i);
63 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -050064}
65
66void Overlay::configDone() {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050067 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
Zohaib Alam4b0a9242013-11-20 23:54:12 -050068 if((PipeBook::isNotUsed(i) && !sessionInProgress((eDest)i)) ||
69 isSessionEnded((eDest)i)) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050070 //Forces UNSET on pipes, flushes rotator memory and session, closes
71 //fds
Naseer Ahmed758bfc52012-11-28 17:02:08 -050072 mPipeBook[i].destroy();
Naseer Ahmed1ddf3662012-07-31 19:14:18 -070073 }
Naseer Ahmed29a26812012-06-14 00:56:20 -070074 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -050075 PipeBook::save();
76}
77
Zohaib Alam4b0a9242013-11-20 23:54:12 -050078int Overlay::getPipeId(utils::eDest dest) {
79 return mPipeBook[(int)dest].mPipe->getPipeId();
80}
81
82eDest Overlay::getDest(int pipeid) {
83 eDest dest = OV_INVALID;
84 // finding the dest corresponding to the given pipe
85 for(int i=0; i < PipeBook::NUM_PIPES; ++i) {
86 if(mPipeBook[i].valid() && mPipeBook[i].mPipe->getPipeId() == pipeid) {
87 return (eDest)i;
88 }
89 }
90 return dest;
91}
92
93eDest Overlay::reservePipe(int pipeid) {
94 eDest dest = getDest(pipeid);
95 PipeBook::setAllocation((int)dest);
96 return dest;
97}
98
Saurabh Shahaf5f5972013-07-30 13:56:35 -070099eDest Overlay::nextPipe(eMdpPipeType type, int dpy, int mixer) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500100 eDest dest = OV_INVALID;
101
102 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700103 if( (type == OV_MDP_PIPE_ANY || //Pipe type match
104 type == PipeBook::getPipeType((eDest)i)) &&
105 (mPipeBook[i].mDisplay == DPY_UNUSED || //Free or same display
106 mPipeBook[i].mDisplay == dpy) &&
107 (mPipeBook[i].mMixer == MIXER_UNUSED || //Free or same mixer
108 mPipeBook[i].mMixer == mixer) &&
109 PipeBook::isNotAllocated(i) && //Free pipe
Raj Kamala8c065f2013-10-22 14:52:45 +0530110 ( (sDMAMultiplexingSupported && dpy) ||
111 !(sDMAMode == DMA_BLOCK_MODE && //DMA pipe in Line mode
112 PipeBook::getPipeType((eDest)i) == OV_MDP_PIPE_DMA)) ){
113 //DMA-Multiplexing is only supported for WB on 8x26
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700114 dest = (eDest)i;
115 PipeBook::setAllocation(i);
116 break;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500117 }
118 }
119
120 if(dest != OV_INVALID) {
121 int index = (int)dest;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500122 mPipeBook[index].mDisplay = dpy;
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700123 mPipeBook[index].mMixer = mixer;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500124 if(not mPipeBook[index].valid()) {
125 mPipeBook[index].mPipe = new GenericPipe(dpy);
Zohaib Alam4b0a9242013-11-20 23:54:12 -0500126 mPipeBook[index].mSession = PipeBook::NONE;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500127 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500128 }
129
130 return dest;
131}
132
Saurabh Shahc62f3982014-03-05 14:28:26 -0800133utils::eDest Overlay::getPipe(const PipeSpecs& pipeSpecs) {
134 if(MDPVersion::getInstance().is8x26()) {
135 return getPipe_8x26(pipeSpecs);
136 } else if(MDPVersion::getInstance().is8x16()) {
137 return getPipe_8x16(pipeSpecs);
Prabhanjan Kandula958ffa92014-05-12 14:56:56 +0530138 } else if(MDPVersion::getInstance().is8x39()) {
139 return getPipe_8x39(pipeSpecs);
Saurabh Shah59788572014-07-29 10:07:57 -0700140 } else if(MDPVersion::getInstance().is8994()) {
141 return getPipe_8994(pipeSpecs);
Saurabh Shahc62f3982014-03-05 14:28:26 -0800142 }
143
144 eDest dest = OV_INVALID;
145
146 //The default behavior is to assume RGB and VG pipes have scalars
147 if(pipeSpecs.formatClass == FORMAT_YUV) {
148 return nextPipe(OV_MDP_PIPE_VG, pipeSpecs.dpy, pipeSpecs.mixer);
149 } else if(pipeSpecs.fb == false) { //RGB App layers
150 if(not pipeSpecs.needsScaling) {
151 dest = nextPipe(OV_MDP_PIPE_DMA, pipeSpecs.dpy, pipeSpecs.mixer);
152 }
153 if(dest == OV_INVALID) {
154 dest = nextPipe(OV_MDP_PIPE_RGB, pipeSpecs.dpy, pipeSpecs.mixer);
155 }
156 if(dest == OV_INVALID) {
157 dest = nextPipe(OV_MDP_PIPE_VG, pipeSpecs.dpy, pipeSpecs.mixer);
158 }
159 } else { //FB layer
160 dest = nextPipe(OV_MDP_PIPE_RGB, pipeSpecs.dpy, pipeSpecs.mixer);
161 if(dest == OV_INVALID) {
162 dest = nextPipe(OV_MDP_PIPE_VG, pipeSpecs.dpy, pipeSpecs.mixer);
163 }
164 //Some features can cause FB to have scaling as well.
165 //If we ever come to this block with FB needing scaling,
166 //the screen will be black for a frame, since the FB won't get a pipe
167 //but atleast this will prevent a hang
168 if(dest == OV_INVALID and (not pipeSpecs.needsScaling)) {
169 dest = nextPipe(OV_MDP_PIPE_DMA, pipeSpecs.dpy, pipeSpecs.mixer);
170 }
171 }
172 return dest;
173}
174
175utils::eDest Overlay::getPipe_8x26(const PipeSpecs& pipeSpecs) {
176 //Use this to hide all the 8x26 requirements that cannot be humanly
177 //described in a generic way
178 eDest dest = OV_INVALID;
179 if(pipeSpecs.formatClass == FORMAT_YUV) { //video
180 return nextPipe(OV_MDP_PIPE_VG, pipeSpecs.dpy, pipeSpecs.mixer);
181 } else if(pipeSpecs.fb == false) { //RGB app layers
Xu Yang1e686f62014-04-08 13:56:47 +0800182 if((not pipeSpecs.needsScaling) and
183 (not (pipeSpecs.numActiveDisplays > 1 &&
184 pipeSpecs.dpy == DPY_PRIMARY))) {
Saurabh Shahc62f3982014-03-05 14:28:26 -0800185 dest = nextPipe(OV_MDP_PIPE_DMA, pipeSpecs.dpy, pipeSpecs.mixer);
186 }
187 if(dest == OV_INVALID) {
188 dest = nextPipe(OV_MDP_PIPE_RGB, pipeSpecs.dpy, pipeSpecs.mixer);
189 }
190 if(dest == OV_INVALID) {
191 dest = nextPipe(OV_MDP_PIPE_VG, pipeSpecs.dpy, pipeSpecs.mixer);
192 }
193 } else { //FB layer
194 //For 8x26 Secondary we use DMA always for FB for inline rotation
195 if(pipeSpecs.dpy == DPY_PRIMARY) {
196 dest = nextPipe(OV_MDP_PIPE_RGB, pipeSpecs.dpy, pipeSpecs.mixer);
197 if(dest == OV_INVALID) {
198 dest = nextPipe(OV_MDP_PIPE_VG, pipeSpecs.dpy, pipeSpecs.mixer);
199 }
200 }
Xu Yang1e686f62014-04-08 13:56:47 +0800201 if(dest == OV_INVALID and (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 }
207 return dest;
208}
209
210utils::eDest Overlay::getPipe_8x16(const PipeSpecs& pipeSpecs) {
211 //Having such functions help keeping the interface generic but code specific
212 //and rife with assumptions
213 eDest dest = OV_INVALID;
214 if(pipeSpecs.formatClass == FORMAT_YUV or pipeSpecs.needsScaling) {
215 return nextPipe(OV_MDP_PIPE_VG, pipeSpecs.dpy, pipeSpecs.mixer);
radhakrishna89298462014-04-22 19:10:36 +0530216 } else {
Saurabh Shahc62f3982014-03-05 14:28:26 -0800217 //Since this is a specific func, we can assume stuff like RGB pipe not
218 //having scalar blocks
219 dest = nextPipe(OV_MDP_PIPE_RGB, pipeSpecs.dpy, pipeSpecs.mixer);
220 if(dest == OV_INVALID) {
221 dest = nextPipe(OV_MDP_PIPE_DMA, pipeSpecs.dpy, pipeSpecs.mixer);
222 }
Saurabh Shahc62f3982014-03-05 14:28:26 -0800223 if(dest == OV_INVALID) {
radhakrishna89298462014-04-22 19:10:36 +0530224 dest = nextPipe(OV_MDP_PIPE_VG, pipeSpecs.dpy, pipeSpecs.mixer);
Saurabh Shahc62f3982014-03-05 14:28:26 -0800225 }
226 }
227 return dest;
228}
229
Prabhanjan Kandula958ffa92014-05-12 14:56:56 +0530230utils::eDest Overlay::getPipe_8x39(const PipeSpecs& pipeSpecs) {
231 //8x16 & 8x36 has same number of pipes, pipe-types & scaling capabilities.
232 //Rely on 8x16 until we see a need to change.
233 return getPipe_8x16(pipeSpecs);
234}
235
Saurabh Shah59788572014-07-29 10:07:57 -0700236utils::eDest Overlay::getPipe_8994(const PipeSpecs& pipeSpecs) {
237 //If DMA pipes need to be used in block mode for downscale, there could be
238 //cases where consecutive rounds need separate modes, which cannot be
239 //supported since we at least need 1 round in between where the DMA is
240 //unused
241 eDest dest = OV_INVALID;
242 if(pipeSpecs.formatClass == FORMAT_YUV) {
243 return nextPipe(OV_MDP_PIPE_VG, pipeSpecs.dpy, pipeSpecs.mixer);
244 } else {
245 dest = nextPipe(OV_MDP_PIPE_RGB, pipeSpecs.dpy, pipeSpecs.mixer);
246 if(dest == OV_INVALID) {
247 dest = nextPipe(OV_MDP_PIPE_VG, pipeSpecs.dpy, pipeSpecs.mixer);
248 }
249 if(dest == OV_INVALID and not pipeSpecs.needsScaling) {
250 dest = nextPipe(OV_MDP_PIPE_DMA, pipeSpecs.dpy, pipeSpecs.mixer);
251 }
252 }
253 return dest;
254}
255
Zohaib Alam4b0a9242013-11-20 23:54:12 -0500256void Overlay::endAllSessions() {
257 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
258 if(mPipeBook[i].valid() && mPipeBook[i].mSession==PipeBook::START)
259 mPipeBook[i].mSession = PipeBook::END;
260 }
261}
262
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700263bool Overlay::isPipeTypeAttached(eMdpPipeType type) {
264 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
265 if(type == PipeBook::getPipeType((eDest)i) &&
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700266 mPipeBook[i].mDisplay != DPY_UNUSED) {
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700267 return true;
268 }
269 }
270 return false;
271}
272
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800273int Overlay::comparePipePriority(utils::eDest pipe1Index,
274 utils::eDest pipe2Index) {
275 validate((int)pipe1Index);
276 validate((int)pipe2Index);
277 uint8_t pipe1Prio = mPipeBook[(int)pipe1Index].mPipe->getPriority();
278 uint8_t pipe2Prio = mPipeBook[(int)pipe2Index].mPipe->getPriority();
279 if(pipe1Prio > pipe2Prio)
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800280 return -1;
Tatenda Chipeperekwa657afa22014-04-15 12:02:39 -0700281 if(pipe1Prio < pipe2Prio)
282 return 1;
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800283 return 0;
284}
285
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500286bool Overlay::commit(utils::eDest dest) {
287 bool ret = false;
Praveena Pachipulusu2005e8f2014-05-07 20:01:54 +0530288 validate((int)dest);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500289
Praveena Pachipulusu2005e8f2014-05-07 20:01:54 +0530290 if(mPipeBook[dest].mPipe->commit()) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500291 ret = true;
292 PipeBook::setUse((int)dest);
293 } else {
Praveena Pachipulusu2005e8f2014-05-07 20:01:54 +0530294 int dpy = mPipeBook[dest].mDisplay;
Saurabh Shah7445d4b2013-12-05 17:24:45 -0800295 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
Saurabh Shahdf0be752013-05-23 14:40:00 -0700296 if (mPipeBook[i].mDisplay == dpy) {
Sushil Chauhane0dff932013-03-01 14:33:18 -0800297 PipeBook::resetAllocation(i);
Saurabh Shahdf0be752013-05-23 14:40:00 -0700298 PipeBook::resetUse(i);
Saurabh Shahdf0be752013-05-23 14:40:00 -0700299 }
Saurabh Shah7445d4b2013-12-05 17:24:45 -0800300 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500301 }
302 return ret;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700303}
304
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700305bool Overlay::queueBuffer(int fd, uint32_t offset,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500306 utils::eDest dest) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500307 bool ret = false;
Praveena Pachipulusu2005e8f2014-05-07 20:01:54 +0530308 validate((int)dest);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500309 //Queue only if commit() has succeeded (and the bit set)
310 if(PipeBook::isUsed((int)dest)) {
Praveena Pachipulusu2005e8f2014-05-07 20:01:54 +0530311 ret = mPipeBook[dest].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) {
Praveena Pachipulusu2005e8f2014-05-07 20:01:54 +0530318 validate((int)dest);
319 mPipeBook[dest].mPipe->setCrop(d);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700320}
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700321
Sushil Chauhan897a9c32013-07-18 11:09:55 -0700322void Overlay::setColor(const uint32_t color,
323 utils::eDest dest) {
Praveena Pachipulusu2005e8f2014-05-07 20:01:54 +0530324 validate((int)dest);
325 mPipeBook[dest].mPipe->setColor(color);
Sushil Chauhan897a9c32013-07-18 11:09:55 -0700326}
327
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500328void Overlay::setPosition(const utils::Dim& d,
329 utils::eDest dest) {
Praveena Pachipulusu2005e8f2014-05-07 20:01:54 +0530330 validate((int)dest);
331 mPipeBook[dest].mPipe->setPosition(d);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500332}
333
334void Overlay::setTransform(const int orient,
335 utils::eDest dest) {
Praveena Pachipulusu2005e8f2014-05-07 20:01:54 +0530336 validate((int)dest);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500337
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700338 utils::eTransform transform =
339 static_cast<utils::eTransform>(orient);
Praveena Pachipulusu2005e8f2014-05-07 20:01:54 +0530340 mPipeBook[dest].mPipe->setTransform(transform);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700341
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500342}
343
344void Overlay::setSource(const utils::PipeArgs args,
345 utils::eDest dest) {
Praveena Pachipulusu2005e8f2014-05-07 20:01:54 +0530346 validate((int)dest);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500347
radhakrishna8ccb9082014-05-09 16:18:43 +0530348 setPipeType(dest, PipeBook::getPipeType(dest));
349 mPipeBook[dest].mPipe->setSource(args);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700350}
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700351
Saurabh Shah5daeee52013-01-23 16:52:26 +0800352void Overlay::setVisualParams(const MetaData_t& metadata, utils::eDest dest) {
Praveena Pachipulusu2005e8f2014-05-07 20:01:54 +0530353 validate((int)dest);
354 mPipeBook[dest].mPipe->setVisualParams(metadata);
Saurabh Shah5daeee52013-01-23 16:52:26 +0800355}
356
radhakrishna8ccb9082014-05-09 16:18:43 +0530357void Overlay::setPipeType(utils::eDest pipeIndex,
358 const utils::eMdpPipeType pType) {
359 mPipeBook[pipeIndex].mPipe->setPipeType(pType);
360}
361
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500362Overlay* Overlay::getInstance() {
363 if(sInstance == NULL) {
364 sInstance = new Overlay();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700365 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500366 return sInstance;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700367}
368
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800369// Clears any VG pipes allocated to the fb devices
370// Generates a LUT for pipe types.
371int Overlay::initOverlay() {
372 int mdpVersion = qdutils::MDPVersion::getInstance().getMDPVersion();
373 int numPipesXType[OV_MDP_PIPE_ANY] = {0};
374 numPipesXType[OV_MDP_PIPE_RGB] =
375 qdutils::MDPVersion::getInstance().getRGBPipes();
376 numPipesXType[OV_MDP_PIPE_VG] =
377 qdutils::MDPVersion::getInstance().getVGPipes();
378 numPipesXType[OV_MDP_PIPE_DMA] =
379 qdutils::MDPVersion::getInstance().getDMAPipes();
380
381 int index = 0;
382 for(int X = 0; X < (int)OV_MDP_PIPE_ANY; X++) { //iterate over types
383 for(int j = 0; j < numPipesXType[X]; j++) { //iterate over num
384 PipeBook::pipeTypeLUT[index] = (utils::eMdpPipeType)X;
385 index++;
386 }
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700387 }
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800388
Xiaoming Zhou5eff8b62013-05-01 20:56:09 -0400389 if (mdpVersion < qdutils::MDSS_V5 && mdpVersion != qdutils::MDP_V3_0_4) {
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800390 msmfb_mixer_info_req req;
391 mdp_mixer_info *minfo = NULL;
392 char name[64];
393 int fd = -1;
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700394 for(int i = 0; i < MAX_FB_DEVICES; i++) {
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800395 snprintf(name, 64, FB_DEVICE_TEMPLATE, i);
396 ALOGD("initoverlay:: opening the device:: %s", name);
397 fd = ::open(name, O_RDWR, 0);
398 if(fd < 0) {
399 ALOGE("cannot open framebuffer(%d)", i);
400 return -1;
401 }
402 //Get the mixer configuration */
403 req.mixer_num = i;
404 if (ioctl(fd, MSMFB_MIXER_INFO, &req) == -1) {
405 ALOGE("ERROR: MSMFB_MIXER_INFO ioctl failed");
406 close(fd);
407 return -1;
408 }
409 minfo = req.info;
410 for (int j = 0; j < req.cnt; j++) {
411 ALOGD("ndx=%d num=%d z_order=%d", minfo->pndx, minfo->pnum,
412 minfo->z_order);
413 // except the RGB base layer with z_order of -1, clear any
414 // other pipes connected to mixer.
415 if((minfo->z_order) != -1) {
416 int index = minfo->pndx;
417 ALOGD("Unset overlay with index: %d at mixer %d", index, i);
418 if(ioctl(fd, MSMFB_OVERLAY_UNSET, &index) == -1) {
419 ALOGE("ERROR: MSMFB_OVERLAY_UNSET failed");
420 close(fd);
421 return -1;
422 }
423 }
424 minfo++;
425 }
426 close(fd);
427 fd = -1;
428 }
429 }
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700430
431 FILE *displayDeviceFP = NULL;
432 const int MAX_FRAME_BUFFER_NAME_SIZE = 128;
433 char fbType[MAX_FRAME_BUFFER_NAME_SIZE];
434 char msmFbTypePath[MAX_FRAME_BUFFER_NAME_SIZE];
435 const char *strDtvPanel = "dtv panel";
436 const char *strWbPanel = "writeback panel";
437
438 for(int num = 1; num < MAX_FB_DEVICES; num++) {
439 snprintf (msmFbTypePath, sizeof(msmFbTypePath),
440 "/sys/class/graphics/fb%d/msm_fb_type", num);
441 displayDeviceFP = fopen(msmFbTypePath, "r");
442
443 if(displayDeviceFP){
444 fread(fbType, sizeof(char), MAX_FRAME_BUFFER_NAME_SIZE,
445 displayDeviceFP);
446
447 if(strncmp(fbType, strDtvPanel, strlen(strDtvPanel)) == 0) {
448 sDpyFbMap[DPY_EXTERNAL] = num;
449 } else if(strncmp(fbType, strWbPanel, strlen(strWbPanel)) == 0) {
450 sDpyFbMap[DPY_WRITEBACK] = num;
451 }
452
453 fclose(displayDeviceFP);
454 }
455 }
456
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800457 return 0;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700458}
459
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700460bool Overlay::displayCommit(const int& fd) {
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800461 utils::Dim lRoi, rRoi;
462 return displayCommit(fd, lRoi, rRoi);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700463}
464
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800465bool Overlay::displayCommit(const int& fd, const utils::Dim& lRoi,
466 const utils::Dim& rRoi) {
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700467 //Commit
468 struct mdp_display_commit info;
469 memset(&info, 0, sizeof(struct mdp_display_commit));
470 info.flags = MDP_DISPLAY_COMMIT_OVERLAY;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800471 info.l_roi.x = lRoi.x;
472 info.l_roi.y = lRoi.y;
473 info.l_roi.w = lRoi.w;
474 info.l_roi.h = lRoi.h;
475 info.r_roi.x = rRoi.x;
476 info.r_roi.y = rRoi.y;
477 info.r_roi.w = rRoi.w;
478 info.r_roi.h = rRoi.h;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700479
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700480 if(!mdp_wrapper::displayCommit(fd, info)) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700481 ALOGE("%s: commit failed", __func__);
482 return false;
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700483 }
484 return true;
485}
486
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800487void Overlay::getDump(char *buf, size_t len) {
488 int totalPipes = 0;
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700489 const char *str = "\nOverlay State\n\n";
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800490 strlcat(buf, str, len);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800491 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
492 if(mPipeBook[i].valid()) {
493 mPipeBook[i].mPipe->getDump(buf, len);
494 char str[64] = {'\0'};
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700495 snprintf(str, 64, "Display=%d\n\n", mPipeBook[i].mDisplay);
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800496 strlcat(buf, str, len);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800497 totalPipes++;
498 }
499 }
500 char str_pipes[64] = {'\0'};
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700501 snprintf(str_pipes, 64, "Pipes=%d\n\n", totalPipes);
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800502 strlcat(buf, str_pipes, len);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800503}
504
Sushil Chauhanbd3ea922013-05-15 12:25:26 -0700505void Overlay::clear(int dpy) {
506 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
507 if (mPipeBook[i].mDisplay == dpy) {
508 // Mark as available for this round
509 PipeBook::resetUse(i);
510 PipeBook::resetAllocation(i);
511 }
512 }
513}
514
Saurabh Shaha36be922013-12-16 18:18:39 -0800515bool Overlay::validateAndSet(const int& dpy, const int& fbFd) {
516 GenericPipe* pipeArray[PipeBook::NUM_PIPES];
Praveena Pachipulusu2005e8f2014-05-07 20:01:54 +0530517 memset(pipeArray, 0, sizeof(GenericPipe*)*(PipeBook::NUM_PIPES));
Saurabh Shaha36be922013-12-16 18:18:39 -0800518
519 int num = 0;
520 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
521 if(PipeBook::isUsed(i) && mPipeBook[i].valid() &&
522 mPipeBook[i].mDisplay == dpy) {
523 pipeArray[num++] = mPipeBook[i].mPipe;
524 }
525 }
526
527 //Protect against misbehaving clients
528 return num ? GenericPipe::validateAndSet(pipeArray, num, fbFd) : true;
529}
530
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700531void Overlay::initScalar() {
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700532 if(sLibScaleHandle == NULL) {
533 sLibScaleHandle = dlopen("libscale.so", RTLD_NOW);
Saurabh Shaheac146b2014-05-13 11:36:20 -0700534 if(sLibScaleHandle) {
535 *(void **) &sFnProgramScale =
536 dlsym(sLibScaleHandle, "programScale");
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700537 }
538 }
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700539}
540
541void Overlay::destroyScalar() {
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700542 if(sLibScaleHandle) {
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700543 dlclose(sLibScaleHandle);
544 sLibScaleHandle = NULL;
545 }
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700546}
547
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500548void Overlay::PipeBook::init() {
549 mPipe = NULL;
550 mDisplay = DPY_UNUSED;
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700551 mMixer = MIXER_UNUSED;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500552}
553
554void Overlay::PipeBook::destroy() {
555 if(mPipe) {
556 delete mPipe;
557 mPipe = NULL;
558 }
559 mDisplay = DPY_UNUSED;
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700560 mMixer = MIXER_UNUSED;
Zohaib Alam4b0a9242013-11-20 23:54:12 -0500561 mSession = NONE;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500562}
563
564Overlay* Overlay::sInstance = 0;
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700565int Overlay::sDpyFbMap[DPY_MAX] = {0, -1, -1};
Saurabh Shah85234ec2013-04-12 17:09:00 -0700566int Overlay::sDMAMode = DMA_LINE_MODE;
Raj Kamala8c065f2013-10-22 14:52:45 +0530567bool Overlay::sDMAMultiplexingSupported = false;
Saurabh Shah24eec8a2014-08-22 15:07:25 -0700568bool Overlay::sDebugPipeLifecycle = false;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500569int Overlay::PipeBook::NUM_PIPES = 0;
570int Overlay::PipeBook::sPipeUsageBitmap = 0;
571int Overlay::PipeBook::sLastUsageBitmap = 0;
572int Overlay::PipeBook::sAllocatedBitmap = 0;
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800573utils::eMdpPipeType Overlay::PipeBook::pipeTypeLUT[utils::OV_MAX] =
574 {utils::OV_MDP_PIPE_ANY};
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700575void *Overlay::sLibScaleHandle = NULL;
Saurabh Shaheac146b2014-05-13 11:36:20 -0700576int (*Overlay::sFnProgramScale)(struct mdp_overlay_list *) = NULL;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500577
578}; // namespace overlay