blob: c016d3dd09f4f55018e47fd4806ed5ad887cae6c [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"
Tatenda Chipeperekwace8d5c42014-08-13 10:53:49 -070035#include "qd_utils.h"
Naseer Ahmed29a26812012-06-14 00:56:20 -070036
Naseer Ahmed758bfc52012-11-28 17:02:08 -050037#define PIPE_DEBUG 0
Naseer Ahmed29a26812012-06-14 00:56:20 -070038
39namespace overlay {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050040using namespace utils;
Saurabh Shahc62f3982014-03-05 14:28:26 -080041using namespace qdutils;
Saurabh Shahb8f58e22013-09-26 16:20:07 -070042
Naseer Ahmed758bfc52012-11-28 17:02:08 -050043Overlay::Overlay() {
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -080044 int numPipes = qdutils::MDPVersion::getInstance().getTotalPipes();
45 PipeBook::NUM_PIPES = (numPipes <= utils::OV_MAX)? numPipes : utils::OV_MAX;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050046 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
47 mPipeBook[i].init();
Naseer Ahmed1ddf3662012-07-31 19:14:18 -070048 }
Naseer Ahmed1ddf3662012-07-31 19:14:18 -070049
Naseer Ahmed758bfc52012-11-28 17:02:08 -050050 mDumpStr[0] = '\0';
Saurabh Shahb8f58e22013-09-26 16:20:07 -070051 initScalar();
Raj Kamala8c065f2013-10-22 14:52:45 +053052 setDMAMultiplexingSupported();
Naseer Ahmed29a26812012-06-14 00:56:20 -070053}
54
55Overlay::~Overlay() {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050056 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
57 mPipeBook[i].destroy();
58 }
Saurabh Shahb8f58e22013-09-26 16:20:07 -070059 destroyScalar();
Naseer Ahmed29a26812012-06-14 00:56:20 -070060}
61
Naseer Ahmed758bfc52012-11-28 17:02:08 -050062void Overlay::configBegin() {
63 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
64 //Mark as available for this round.
65 PipeBook::resetUse(i);
66 PipeBook::resetAllocation(i);
67 }
68 mDumpStr[0] = '\0';
69}
70
71void Overlay::configDone() {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050072 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
Zohaib Alam4b0a9242013-11-20 23:54:12 -050073 if((PipeBook::isNotUsed(i) && !sessionInProgress((eDest)i)) ||
74 isSessionEnded((eDest)i)) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050075 //Forces UNSET on pipes, flushes rotator memory and session, closes
76 //fds
77 if(mPipeBook[i].valid()) {
78 char str[32];
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -080079 snprintf(str, 32, "Unset=%s dpy=%d mix=%d; ",
Saurabh Shahaf5f5972013-07-30 13:56:35 -070080 PipeBook::getDestStr((eDest)i),
81 mPipeBook[i].mDisplay, mPipeBook[i].mMixer);
Saurabh Shah9dc88fc2013-07-15 16:02:30 -070082#if PIPE_DEBUG
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -080083 strlcat(mDumpStr, str, sizeof(mDumpStr));
Saurabh Shah9dc88fc2013-07-15 16:02:30 -070084#endif
Naseer Ahmed758bfc52012-11-28 17:02:08 -050085 }
86 mPipeBook[i].destroy();
Naseer Ahmed1ddf3662012-07-31 19:14:18 -070087 }
Naseer Ahmed29a26812012-06-14 00:56:20 -070088 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -050089 dump();
90 PipeBook::save();
91}
92
Zohaib Alam4b0a9242013-11-20 23:54:12 -050093int Overlay::getPipeId(utils::eDest dest) {
94 return mPipeBook[(int)dest].mPipe->getPipeId();
95}
96
97eDest Overlay::getDest(int pipeid) {
98 eDest dest = OV_INVALID;
99 // finding the dest corresponding to the given pipe
100 for(int i=0; i < PipeBook::NUM_PIPES; ++i) {
101 if(mPipeBook[i].valid() && mPipeBook[i].mPipe->getPipeId() == pipeid) {
102 return (eDest)i;
103 }
104 }
105 return dest;
106}
107
108eDest Overlay::reservePipe(int pipeid) {
109 eDest dest = getDest(pipeid);
110 PipeBook::setAllocation((int)dest);
111 return dest;
112}
113
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700114eDest Overlay::nextPipe(eMdpPipeType type, int dpy, int mixer) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500115 eDest dest = OV_INVALID;
116
117 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700118 if( (type == OV_MDP_PIPE_ANY || //Pipe type match
119 type == PipeBook::getPipeType((eDest)i)) &&
120 (mPipeBook[i].mDisplay == DPY_UNUSED || //Free or same display
121 mPipeBook[i].mDisplay == dpy) &&
122 (mPipeBook[i].mMixer == MIXER_UNUSED || //Free or same mixer
123 mPipeBook[i].mMixer == mixer) &&
124 PipeBook::isNotAllocated(i) && //Free pipe
Raj Kamala8c065f2013-10-22 14:52:45 +0530125 ( (sDMAMultiplexingSupported && dpy) ||
126 !(sDMAMode == DMA_BLOCK_MODE && //DMA pipe in Line mode
127 PipeBook::getPipeType((eDest)i) == OV_MDP_PIPE_DMA)) ){
128 //DMA-Multiplexing is only supported for WB on 8x26
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700129 dest = (eDest)i;
130 PipeBook::setAllocation(i);
131 break;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500132 }
133 }
134
135 if(dest != OV_INVALID) {
136 int index = (int)dest;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500137 mPipeBook[index].mDisplay = dpy;
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700138 mPipeBook[index].mMixer = mixer;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500139 if(not mPipeBook[index].valid()) {
140 mPipeBook[index].mPipe = new GenericPipe(dpy);
Zohaib Alam4b0a9242013-11-20 23:54:12 -0500141 mPipeBook[index].mSession = PipeBook::NONE;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500142 char str[32];
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700143 snprintf(str, 32, "Set=%s dpy=%d mix=%d; ",
144 PipeBook::getDestStr(dest), dpy, mixer);
Saurabh Shah9dc88fc2013-07-15 16:02:30 -0700145#if PIPE_DEBUG
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800146 strlcat(mDumpStr, str, sizeof(mDumpStr));
Saurabh Shah9dc88fc2013-07-15 16:02:30 -0700147#endif
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500148 }
149 } else {
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700150 ALOGD_IF(PIPE_DEBUG, "Pipe unavailable type=%d display=%d mixer=%d",
151 (int)type, dpy, mixer);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500152 }
153
154 return dest;
155}
156
Saurabh Shahc62f3982014-03-05 14:28:26 -0800157utils::eDest Overlay::getPipe(const PipeSpecs& pipeSpecs) {
158 if(MDPVersion::getInstance().is8x26()) {
159 return getPipe_8x26(pipeSpecs);
160 } else if(MDPVersion::getInstance().is8x16()) {
161 return getPipe_8x16(pipeSpecs);
Prabhanjan Kandula958ffa92014-05-12 14:56:56 +0530162 } else if(MDPVersion::getInstance().is8x39()) {
163 return getPipe_8x39(pipeSpecs);
Saurabh Shah59788572014-07-29 10:07:57 -0700164 } else if(MDPVersion::getInstance().is8994()) {
165 return getPipe_8994(pipeSpecs);
Saurabh Shahc62f3982014-03-05 14:28:26 -0800166 }
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
Prabhanjan Kandula958ffa92014-05-12 14:56:56 +0530254utils::eDest Overlay::getPipe_8x39(const PipeSpecs& pipeSpecs) {
255 //8x16 & 8x36 has same number of pipes, pipe-types & scaling capabilities.
256 //Rely on 8x16 until we see a need to change.
257 return getPipe_8x16(pipeSpecs);
258}
259
Saurabh Shah59788572014-07-29 10:07:57 -0700260utils::eDest Overlay::getPipe_8994(const PipeSpecs& pipeSpecs) {
261 //If DMA pipes need to be used in block mode for downscale, there could be
262 //cases where consecutive rounds need separate modes, which cannot be
263 //supported since we at least need 1 round in between where the DMA is
264 //unused
265 eDest dest = OV_INVALID;
266 if(pipeSpecs.formatClass == FORMAT_YUV) {
267 return nextPipe(OV_MDP_PIPE_VG, pipeSpecs.dpy, pipeSpecs.mixer);
268 } else {
269 dest = nextPipe(OV_MDP_PIPE_RGB, pipeSpecs.dpy, pipeSpecs.mixer);
270 if(dest == OV_INVALID) {
271 dest = nextPipe(OV_MDP_PIPE_VG, pipeSpecs.dpy, pipeSpecs.mixer);
272 }
273 if(dest == OV_INVALID and not pipeSpecs.needsScaling) {
274 dest = nextPipe(OV_MDP_PIPE_DMA, pipeSpecs.dpy, pipeSpecs.mixer);
275 }
276 }
277 return dest;
278}
279
Zohaib Alam4b0a9242013-11-20 23:54:12 -0500280void Overlay::endAllSessions() {
281 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
282 if(mPipeBook[i].valid() && mPipeBook[i].mSession==PipeBook::START)
283 mPipeBook[i].mSession = PipeBook::END;
284 }
285}
286
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700287bool Overlay::isPipeTypeAttached(eMdpPipeType type) {
288 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
289 if(type == PipeBook::getPipeType((eDest)i) &&
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700290 mPipeBook[i].mDisplay != DPY_UNUSED) {
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700291 return true;
292 }
293 }
294 return false;
295}
296
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800297int Overlay::comparePipePriority(utils::eDest pipe1Index,
298 utils::eDest pipe2Index) {
299 validate((int)pipe1Index);
300 validate((int)pipe2Index);
301 uint8_t pipe1Prio = mPipeBook[(int)pipe1Index].mPipe->getPriority();
302 uint8_t pipe2Prio = mPipeBook[(int)pipe2Index].mPipe->getPriority();
303 if(pipe1Prio > pipe2Prio)
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800304 return -1;
Tatenda Chipeperekwa657afa22014-04-15 12:02:39 -0700305 if(pipe1Prio < pipe2Prio)
306 return 1;
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800307 return 0;
308}
309
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500310bool Overlay::commit(utils::eDest dest) {
311 bool ret = false;
Praveena Pachipulusu2005e8f2014-05-07 20:01:54 +0530312 validate((int)dest);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500313
Praveena Pachipulusu2005e8f2014-05-07 20:01:54 +0530314 if(mPipeBook[dest].mPipe->commit()) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500315 ret = true;
316 PipeBook::setUse((int)dest);
317 } else {
Praveena Pachipulusu2005e8f2014-05-07 20:01:54 +0530318 int dpy = mPipeBook[dest].mDisplay;
Saurabh Shah7445d4b2013-12-05 17:24:45 -0800319 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
Saurabh Shahdf0be752013-05-23 14:40:00 -0700320 if (mPipeBook[i].mDisplay == dpy) {
Sushil Chauhane0dff932013-03-01 14:33:18 -0800321 PipeBook::resetAllocation(i);
Saurabh Shahdf0be752013-05-23 14:40:00 -0700322 PipeBook::resetUse(i);
Saurabh Shahdf0be752013-05-23 14:40:00 -0700323 }
Saurabh Shah7445d4b2013-12-05 17:24:45 -0800324 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500325 }
326 return ret;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700327}
328
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700329bool Overlay::queueBuffer(int fd, uint32_t offset,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500330 utils::eDest dest) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500331 bool ret = false;
Praveena Pachipulusu2005e8f2014-05-07 20:01:54 +0530332 validate((int)dest);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500333 //Queue only if commit() has succeeded (and the bit set)
334 if(PipeBook::isUsed((int)dest)) {
Praveena Pachipulusu2005e8f2014-05-07 20:01:54 +0530335 ret = mPipeBook[dest].mPipe->queueBuffer(fd, offset);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700336 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500337 return ret;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700338}
339
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500340void Overlay::setCrop(const utils::Dim& d,
341 utils::eDest dest) {
Praveena Pachipulusu2005e8f2014-05-07 20:01:54 +0530342 validate((int)dest);
343 mPipeBook[dest].mPipe->setCrop(d);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700344}
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700345
Sushil Chauhan897a9c32013-07-18 11:09:55 -0700346void Overlay::setColor(const uint32_t color,
347 utils::eDest dest) {
Praveena Pachipulusu2005e8f2014-05-07 20:01:54 +0530348 validate((int)dest);
349 mPipeBook[dest].mPipe->setColor(color);
Sushil Chauhan897a9c32013-07-18 11:09:55 -0700350}
351
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500352void Overlay::setPosition(const utils::Dim& d,
353 utils::eDest dest) {
Praveena Pachipulusu2005e8f2014-05-07 20:01:54 +0530354 validate((int)dest);
355 mPipeBook[dest].mPipe->setPosition(d);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500356}
357
358void Overlay::setTransform(const int orient,
359 utils::eDest dest) {
Praveena Pachipulusu2005e8f2014-05-07 20:01:54 +0530360 validate((int)dest);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500361
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700362 utils::eTransform transform =
363 static_cast<utils::eTransform>(orient);
Praveena Pachipulusu2005e8f2014-05-07 20:01:54 +0530364 mPipeBook[dest].mPipe->setTransform(transform);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700365
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500366}
367
368void Overlay::setSource(const utils::PipeArgs args,
369 utils::eDest dest) {
Praveena Pachipulusu2005e8f2014-05-07 20:01:54 +0530370 validate((int)dest);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500371
radhakrishna8ccb9082014-05-09 16:18:43 +0530372 setPipeType(dest, PipeBook::getPipeType(dest));
373 mPipeBook[dest].mPipe->setSource(args);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700374}
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700375
Saurabh Shah5daeee52013-01-23 16:52:26 +0800376void Overlay::setVisualParams(const MetaData_t& metadata, utils::eDest dest) {
Praveena Pachipulusu2005e8f2014-05-07 20:01:54 +0530377 validate((int)dest);
378 mPipeBook[dest].mPipe->setVisualParams(metadata);
Saurabh Shah5daeee52013-01-23 16:52:26 +0800379}
380
radhakrishna8ccb9082014-05-09 16:18:43 +0530381void Overlay::setPipeType(utils::eDest pipeIndex,
382 const utils::eMdpPipeType pType) {
383 mPipeBook[pipeIndex].mPipe->setPipeType(pType);
384}
385
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500386Overlay* Overlay::getInstance() {
387 if(sInstance == NULL) {
388 sInstance = new Overlay();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700389 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500390 return sInstance;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700391}
392
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800393// Clears any VG pipes allocated to the fb devices
394// Generates a LUT for pipe types.
395int Overlay::initOverlay() {
396 int mdpVersion = qdutils::MDPVersion::getInstance().getMDPVersion();
397 int numPipesXType[OV_MDP_PIPE_ANY] = {0};
398 numPipesXType[OV_MDP_PIPE_RGB] =
399 qdutils::MDPVersion::getInstance().getRGBPipes();
400 numPipesXType[OV_MDP_PIPE_VG] =
401 qdutils::MDPVersion::getInstance().getVGPipes();
402 numPipesXType[OV_MDP_PIPE_DMA] =
403 qdutils::MDPVersion::getInstance().getDMAPipes();
404
405 int index = 0;
406 for(int X = 0; X < (int)OV_MDP_PIPE_ANY; X++) { //iterate over types
407 for(int j = 0; j < numPipesXType[X]; j++) { //iterate over num
408 PipeBook::pipeTypeLUT[index] = (utils::eMdpPipeType)X;
409 index++;
410 }
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700411 }
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800412
Xiaoming Zhou5eff8b62013-05-01 20:56:09 -0400413 if (mdpVersion < qdutils::MDSS_V5 && mdpVersion != qdutils::MDP_V3_0_4) {
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800414 msmfb_mixer_info_req req;
415 mdp_mixer_info *minfo = NULL;
416 char name[64];
417 int fd = -1;
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700418 for(int i = 0; i < MAX_FB_DEVICES; i++) {
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800419 snprintf(name, 64, FB_DEVICE_TEMPLATE, i);
420 ALOGD("initoverlay:: opening the device:: %s", name);
421 fd = ::open(name, O_RDWR, 0);
422 if(fd < 0) {
423 ALOGE("cannot open framebuffer(%d)", i);
424 return -1;
425 }
426 //Get the mixer configuration */
427 req.mixer_num = i;
428 if (ioctl(fd, MSMFB_MIXER_INFO, &req) == -1) {
429 ALOGE("ERROR: MSMFB_MIXER_INFO ioctl failed");
430 close(fd);
431 return -1;
432 }
433 minfo = req.info;
434 for (int j = 0; j < req.cnt; j++) {
435 ALOGD("ndx=%d num=%d z_order=%d", minfo->pndx, minfo->pnum,
436 minfo->z_order);
437 // except the RGB base layer with z_order of -1, clear any
438 // other pipes connected to mixer.
439 if((minfo->z_order) != -1) {
440 int index = minfo->pndx;
441 ALOGD("Unset overlay with index: %d at mixer %d", index, i);
442 if(ioctl(fd, MSMFB_OVERLAY_UNSET, &index) == -1) {
443 ALOGE("ERROR: MSMFB_OVERLAY_UNSET failed");
444 close(fd);
445 return -1;
446 }
447 }
448 minfo++;
449 }
450 close(fd);
451 fd = -1;
452 }
453 }
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700454
455 FILE *displayDeviceFP = NULL;
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700456 char fbType[MAX_FRAME_BUFFER_NAME_SIZE];
457 char msmFbTypePath[MAX_FRAME_BUFFER_NAME_SIZE];
458 const char *strDtvPanel = "dtv panel";
459 const char *strWbPanel = "writeback panel";
460
461 for(int num = 1; num < MAX_FB_DEVICES; num++) {
462 snprintf (msmFbTypePath, sizeof(msmFbTypePath),
463 "/sys/class/graphics/fb%d/msm_fb_type", num);
464 displayDeviceFP = fopen(msmFbTypePath, "r");
465
466 if(displayDeviceFP){
467 fread(fbType, sizeof(char), MAX_FRAME_BUFFER_NAME_SIZE,
468 displayDeviceFP);
469
470 if(strncmp(fbType, strDtvPanel, strlen(strDtvPanel)) == 0) {
471 sDpyFbMap[DPY_EXTERNAL] = num;
472 } else if(strncmp(fbType, strWbPanel, strlen(strWbPanel)) == 0) {
473 sDpyFbMap[DPY_WRITEBACK] = num;
474 }
475
476 fclose(displayDeviceFP);
477 }
478 }
479
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800480 return 0;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700481}
482
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700483bool Overlay::displayCommit(const int& fd) {
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800484 utils::Dim lRoi, rRoi;
485 return displayCommit(fd, lRoi, rRoi);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700486}
487
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800488bool Overlay::displayCommit(const int& fd, const utils::Dim& lRoi,
489 const utils::Dim& rRoi) {
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700490 //Commit
491 struct mdp_display_commit info;
492 memset(&info, 0, sizeof(struct mdp_display_commit));
493 info.flags = MDP_DISPLAY_COMMIT_OVERLAY;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800494 info.l_roi.x = lRoi.x;
495 info.l_roi.y = lRoi.y;
496 info.l_roi.w = lRoi.w;
497 info.l_roi.h = lRoi.h;
498 info.r_roi.x = rRoi.x;
499 info.r_roi.y = rRoi.y;
500 info.r_roi.w = rRoi.w;
501 info.r_roi.h = rRoi.h;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700502
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700503 if(!mdp_wrapper::displayCommit(fd, info)) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700504 ALOGE("%s: commit failed", __func__);
505 return false;
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700506 }
507 return true;
508}
509
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500510void Overlay::dump() const {
Saurabh Shah9dc88fc2013-07-15 16:02:30 -0700511#if PIPE_DEBUG
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500512 if(strlen(mDumpStr)) { //dump only on state change
Saurabh Shah9dc88fc2013-07-15 16:02:30 -0700513 ALOGD("%s\n", mDumpStr);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500514 }
Saurabh Shah9dc88fc2013-07-15 16:02:30 -0700515#endif
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500516}
517
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800518void Overlay::getDump(char *buf, size_t len) {
519 int totalPipes = 0;
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700520 const char *str = "\nOverlay State\n\n";
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800521 strlcat(buf, str, len);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800522 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
523 if(mPipeBook[i].valid()) {
524 mPipeBook[i].mPipe->getDump(buf, len);
525 char str[64] = {'\0'};
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700526 snprintf(str, 64, "Display=%d\n\n", mPipeBook[i].mDisplay);
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800527 strlcat(buf, str, len);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800528 totalPipes++;
529 }
530 }
531 char str_pipes[64] = {'\0'};
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700532 snprintf(str_pipes, 64, "Pipes=%d\n\n", totalPipes);
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800533 strlcat(buf, str_pipes, len);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800534}
535
Sushil Chauhanbd3ea922013-05-15 12:25:26 -0700536void Overlay::clear(int dpy) {
537 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
538 if (mPipeBook[i].mDisplay == dpy) {
539 // Mark as available for this round
540 PipeBook::resetUse(i);
541 PipeBook::resetAllocation(i);
542 }
543 }
544}
545
Saurabh Shaha36be922013-12-16 18:18:39 -0800546bool Overlay::validateAndSet(const int& dpy, const int& fbFd) {
547 GenericPipe* pipeArray[PipeBook::NUM_PIPES];
Praveena Pachipulusu2005e8f2014-05-07 20:01:54 +0530548 memset(pipeArray, 0, sizeof(GenericPipe*)*(PipeBook::NUM_PIPES));
Saurabh Shaha36be922013-12-16 18:18:39 -0800549
550 int num = 0;
551 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
552 if(PipeBook::isUsed(i) && mPipeBook[i].valid() &&
553 mPipeBook[i].mDisplay == dpy) {
554 pipeArray[num++] = mPipeBook[i].mPipe;
555 }
556 }
557
558 //Protect against misbehaving clients
559 return num ? GenericPipe::validateAndSet(pipeArray, num, fbFd) : true;
560}
561
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700562void Overlay::initScalar() {
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700563 if(sLibScaleHandle == NULL) {
564 sLibScaleHandle = dlopen("libscale.so", RTLD_NOW);
Saurabh Shaheac146b2014-05-13 11:36:20 -0700565 if(sLibScaleHandle) {
566 *(void **) &sFnProgramScale =
567 dlsym(sLibScaleHandle, "programScale");
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700568 }
569 }
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700570}
571
572void Overlay::destroyScalar() {
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700573 if(sLibScaleHandle) {
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700574 dlclose(sLibScaleHandle);
575 sLibScaleHandle = NULL;
576 }
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700577}
578
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500579void Overlay::PipeBook::init() {
580 mPipe = NULL;
581 mDisplay = DPY_UNUSED;
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700582 mMixer = MIXER_UNUSED;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500583}
584
585void Overlay::PipeBook::destroy() {
586 if(mPipe) {
587 delete mPipe;
588 mPipe = NULL;
589 }
590 mDisplay = DPY_UNUSED;
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700591 mMixer = MIXER_UNUSED;
Zohaib Alam4b0a9242013-11-20 23:54:12 -0500592 mSession = NONE;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500593}
594
595Overlay* Overlay::sInstance = 0;
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700596int Overlay::sDpyFbMap[DPY_MAX] = {0, -1, -1};
Saurabh Shah85234ec2013-04-12 17:09:00 -0700597int Overlay::sDMAMode = DMA_LINE_MODE;
Raj Kamala8c065f2013-10-22 14:52:45 +0530598bool Overlay::sDMAMultiplexingSupported = false;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500599int Overlay::PipeBook::NUM_PIPES = 0;
600int Overlay::PipeBook::sPipeUsageBitmap = 0;
601int Overlay::PipeBook::sLastUsageBitmap = 0;
602int Overlay::PipeBook::sAllocatedBitmap = 0;
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800603utils::eMdpPipeType Overlay::PipeBook::pipeTypeLUT[utils::OV_MAX] =
604 {utils::OV_MDP_PIPE_ANY};
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700605void *Overlay::sLibScaleHandle = NULL;
Saurabh Shaheac146b2014-05-13 11:36:20 -0700606int (*Overlay::sFnProgramScale)(struct mdp_overlay_list *) = NULL;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500607
608}; // namespace overlay