blob: 113bd485bac88f85fa67a78e4cdd002458bd0679 [file] [log] [blame]
Naseer Ahmed29a26812012-06-14 00:56:20 -07001/*
Ramakant Singhb4106a12014-10-07 18:06:56 +05302* Copyright (c) 2011-2014, 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 Ahmed29a26812012-06-14 00:56:20 -070037namespace overlay {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050038using namespace utils;
Saurabh Shahc62f3982014-03-05 14:28:26 -080039using namespace qdutils;
Saurabh Shahb8f58e22013-09-26 16:20:07 -070040
Naseer Ahmed758bfc52012-11-28 17:02:08 -050041Overlay::Overlay() {
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -080042 int numPipes = qdutils::MDPVersion::getInstance().getTotalPipes();
43 PipeBook::NUM_PIPES = (numPipes <= utils::OV_MAX)? numPipes : utils::OV_MAX;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050044 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
45 mPipeBook[i].init();
Naseer Ahmed1ddf3662012-07-31 19:14:18 -070046 }
Naseer Ahmed1ddf3662012-07-31 19:14:18 -070047
Saurabh Shahb8f58e22013-09-26 16:20:07 -070048 initScalar();
Raj Kamala8c065f2013-10-22 14:52:45 +053049 setDMAMultiplexingSupported();
Praveena Pachipulusu734118a2014-12-04 14:53:12 +053050#ifdef USES_POST_PROCESSING
51 initPostProc();
52#endif
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();
Praveena Pachipulusu734118a2014-12-04 14:53:12 +053060#ifdef USES_POST_PROCESSING
61 destroyPostProc();
62#endif
Naseer Ahmed29a26812012-06-14 00:56:20 -070063}
64
Naseer Ahmed758bfc52012-11-28 17:02:08 -050065void Overlay::configBegin() {
66 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
67 //Mark as available for this round.
68 PipeBook::resetUse(i);
69 PipeBook::resetAllocation(i);
70 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -050071}
72
73void Overlay::configDone() {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050074 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
Zohaib Alam4b0a9242013-11-20 23:54:12 -050075 if((PipeBook::isNotUsed(i) && !sessionInProgress((eDest)i)) ||
76 isSessionEnded((eDest)i)) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050077 //Forces UNSET on pipes, flushes rotator memory and session, closes
78 //fds
Naseer Ahmed758bfc52012-11-28 17:02:08 -050079 mPipeBook[i].destroy();
Naseer Ahmed1ddf3662012-07-31 19:14:18 -070080 }
Naseer Ahmed29a26812012-06-14 00:56:20 -070081 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -050082 PipeBook::save();
83}
84
Zohaib Alam4b0a9242013-11-20 23:54:12 -050085int Overlay::getPipeId(utils::eDest dest) {
86 return mPipeBook[(int)dest].mPipe->getPipeId();
87}
88
89eDest Overlay::getDest(int pipeid) {
90 eDest dest = OV_INVALID;
91 // finding the dest corresponding to the given pipe
92 for(int i=0; i < PipeBook::NUM_PIPES; ++i) {
93 if(mPipeBook[i].valid() && mPipeBook[i].mPipe->getPipeId() == pipeid) {
94 return (eDest)i;
95 }
96 }
97 return dest;
98}
99
100eDest Overlay::reservePipe(int pipeid) {
101 eDest dest = getDest(pipeid);
102 PipeBook::setAllocation((int)dest);
103 return dest;
104}
105
Baldev Sahu979e8f02014-11-12 15:35:13 +0530106eDest Overlay::nextPipe(eMdpPipeType type, const PipeSpecs& pipeSpecs) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500107 eDest dest = OV_INVALID;
Baldev Sahu979e8f02014-11-12 15:35:13 +0530108 int dpy = pipeSpecs.dpy;
109 int mixer = pipeSpecs.mixer;
110 int formatType = pipeSpecs.formatClass;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500111 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700112 if( (type == OV_MDP_PIPE_ANY || //Pipe type match
113 type == PipeBook::getPipeType((eDest)i)) &&
114 (mPipeBook[i].mDisplay == DPY_UNUSED || //Free or same display
115 mPipeBook[i].mDisplay == dpy) &&
116 (mPipeBook[i].mMixer == MIXER_UNUSED || //Free or same mixer
117 mPipeBook[i].mMixer == mixer) &&
Baldev Sahu979e8f02014-11-12 15:35:13 +0530118 (mPipeBook[i].mFormatType == FORMAT_NONE || //Free or same format
119 mPipeBook[i].mFormatType == formatType) &&
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700120 PipeBook::isNotAllocated(i) && //Free pipe
Raj Kamala8c065f2013-10-22 14:52:45 +0530121 ( (sDMAMultiplexingSupported && dpy) ||
122 !(sDMAMode == DMA_BLOCK_MODE && //DMA pipe in Line mode
123 PipeBook::getPipeType((eDest)i) == OV_MDP_PIPE_DMA)) ){
124 //DMA-Multiplexing is only supported for WB on 8x26
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700125 dest = (eDest)i;
126 PipeBook::setAllocation(i);
127 break;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500128 }
129 }
130
131 if(dest != OV_INVALID) {
132 int index = (int)dest;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500133 mPipeBook[index].mDisplay = dpy;
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700134 mPipeBook[index].mMixer = mixer;
Baldev Sahu979e8f02014-11-12 15:35:13 +0530135 mPipeBook[index].mFormatType = formatType;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500136 if(not mPipeBook[index].valid()) {
137 mPipeBook[index].mPipe = new GenericPipe(dpy);
Zohaib Alam4b0a9242013-11-20 23:54:12 -0500138 mPipeBook[index].mSession = PipeBook::NONE;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500139 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500140 }
141
142 return dest;
143}
144
Saurabh Shahc62f3982014-03-05 14:28:26 -0800145utils::eDest Overlay::getPipe(const PipeSpecs& pipeSpecs) {
146 if(MDPVersion::getInstance().is8x26()) {
147 return getPipe_8x26(pipeSpecs);
148 } else if(MDPVersion::getInstance().is8x16()) {
149 return getPipe_8x16(pipeSpecs);
Prabhanjan Kandula958ffa92014-05-12 14:56:56 +0530150 } else if(MDPVersion::getInstance().is8x39()) {
151 return getPipe_8x39(pipeSpecs);
Prabhanjan Kandulafc541b32015-03-30 20:56:16 +0530152 } else if(MDPVersion::getInstance().is8x52()) {
153 return getPipe_8x52(pipeSpecs);
Saurabh Shah59788572014-07-29 10:07:57 -0700154 } else if(MDPVersion::getInstance().is8994()) {
155 return getPipe_8994(pipeSpecs);
Ramkumar Radhakrishnan87a1cd12015-02-25 17:47:29 -0800156 } else if(MDPVersion::getInstance().is8992()) {
157 return getPipe_8992(pipeSpecs);
Saurabh Shahc62f3982014-03-05 14:28:26 -0800158 }
159
160 eDest dest = OV_INVALID;
161
162 //The default behavior is to assume RGB and VG pipes have scalars
163 if(pipeSpecs.formatClass == FORMAT_YUV) {
Baldev Sahu979e8f02014-11-12 15:35:13 +0530164 return nextPipe(OV_MDP_PIPE_VG, pipeSpecs);
Saurabh Shahc62f3982014-03-05 14:28:26 -0800165 } else if(pipeSpecs.fb == false) { //RGB App layers
166 if(not pipeSpecs.needsScaling) {
Baldev Sahu979e8f02014-11-12 15:35:13 +0530167 dest = nextPipe(OV_MDP_PIPE_DMA, pipeSpecs);
Saurabh Shahc62f3982014-03-05 14:28:26 -0800168 }
169 if(dest == OV_INVALID) {
Baldev Sahu979e8f02014-11-12 15:35:13 +0530170 dest = nextPipe(OV_MDP_PIPE_RGB, pipeSpecs);
Saurabh Shahc62f3982014-03-05 14:28:26 -0800171 }
172 if(dest == OV_INVALID) {
Baldev Sahu979e8f02014-11-12 15:35:13 +0530173 dest = nextPipe(OV_MDP_PIPE_VG, pipeSpecs);
Saurabh Shahc62f3982014-03-05 14:28:26 -0800174 }
175 } else { //FB layer
Baldev Sahu979e8f02014-11-12 15:35:13 +0530176 dest = nextPipe(OV_MDP_PIPE_RGB, pipeSpecs);
Saurabh Shahc62f3982014-03-05 14:28:26 -0800177 if(dest == OV_INVALID) {
Baldev Sahu979e8f02014-11-12 15:35:13 +0530178 dest = nextPipe(OV_MDP_PIPE_VG, pipeSpecs);
Saurabh Shahc62f3982014-03-05 14:28:26 -0800179 }
180 //Some features can cause FB to have scaling as well.
181 //If we ever come to this block with FB needing scaling,
182 //the screen will be black for a frame, since the FB won't get a pipe
183 //but atleast this will prevent a hang
184 if(dest == OV_INVALID and (not pipeSpecs.needsScaling)) {
Baldev Sahu979e8f02014-11-12 15:35:13 +0530185 dest = nextPipe(OV_MDP_PIPE_DMA, pipeSpecs);
Saurabh Shahc62f3982014-03-05 14:28:26 -0800186 }
187 }
188 return dest;
189}
190
191utils::eDest Overlay::getPipe_8x26(const PipeSpecs& pipeSpecs) {
192 //Use this to hide all the 8x26 requirements that cannot be humanly
193 //described in a generic way
194 eDest dest = OV_INVALID;
195 if(pipeSpecs.formatClass == FORMAT_YUV) { //video
Baldev Sahu979e8f02014-11-12 15:35:13 +0530196 return nextPipe(OV_MDP_PIPE_VG, pipeSpecs);
Saurabh Shahc62f3982014-03-05 14:28:26 -0800197 } else if(pipeSpecs.fb == false) { //RGB app layers
Xu Yang1e686f62014-04-08 13:56:47 +0800198 if((not pipeSpecs.needsScaling) and
199 (not (pipeSpecs.numActiveDisplays > 1 &&
200 pipeSpecs.dpy == DPY_PRIMARY))) {
Baldev Sahu979e8f02014-11-12 15:35:13 +0530201 dest = nextPipe(OV_MDP_PIPE_DMA, pipeSpecs);
Saurabh Shahc62f3982014-03-05 14:28:26 -0800202 }
203 if(dest == OV_INVALID) {
Baldev Sahu979e8f02014-11-12 15:35:13 +0530204 dest = nextPipe(OV_MDP_PIPE_RGB, pipeSpecs);
Saurabh Shahc62f3982014-03-05 14:28:26 -0800205 }
206 if(dest == OV_INVALID) {
Baldev Sahu979e8f02014-11-12 15:35:13 +0530207 dest = nextPipe(OV_MDP_PIPE_VG, pipeSpecs);
Saurabh Shahc62f3982014-03-05 14:28:26 -0800208 }
209 } else { //FB layer
210 //For 8x26 Secondary we use DMA always for FB for inline rotation
211 if(pipeSpecs.dpy == DPY_PRIMARY) {
Baldev Sahu979e8f02014-11-12 15:35:13 +0530212 dest = nextPipe(OV_MDP_PIPE_RGB, pipeSpecs);
Saurabh Shahc62f3982014-03-05 14:28:26 -0800213 if(dest == OV_INVALID) {
Baldev Sahu979e8f02014-11-12 15:35:13 +0530214 dest = nextPipe(OV_MDP_PIPE_VG, pipeSpecs);
Saurabh Shahc62f3982014-03-05 14:28:26 -0800215 }
216 }
Xu Yang1e686f62014-04-08 13:56:47 +0800217 if(dest == OV_INVALID and (not pipeSpecs.needsScaling) and
218 (not (pipeSpecs.numActiveDisplays > 1 &&
219 pipeSpecs.dpy == DPY_PRIMARY))) {
Baldev Sahu979e8f02014-11-12 15:35:13 +0530220 dest = nextPipe(OV_MDP_PIPE_DMA, pipeSpecs);
Saurabh Shahc62f3982014-03-05 14:28:26 -0800221 }
222 }
223 return dest;
224}
225
226utils::eDest Overlay::getPipe_8x16(const PipeSpecs& pipeSpecs) {
227 //Having such functions help keeping the interface generic but code specific
228 //and rife with assumptions
229 eDest dest = OV_INVALID;
230 if(pipeSpecs.formatClass == FORMAT_YUV or pipeSpecs.needsScaling) {
Baldev Sahu979e8f02014-11-12 15:35:13 +0530231 return nextPipe(OV_MDP_PIPE_VG, pipeSpecs);
radhakrishna89298462014-04-22 19:10:36 +0530232 } else {
Saurabh Shahc62f3982014-03-05 14:28:26 -0800233 //Since this is a specific func, we can assume stuff like RGB pipe not
234 //having scalar blocks
Baldev Sahu979e8f02014-11-12 15:35:13 +0530235 dest = nextPipe(OV_MDP_PIPE_RGB, pipeSpecs);
Saurabh Shahc62f3982014-03-05 14:28:26 -0800236 if(dest == OV_INVALID) {
Baldev Sahu979e8f02014-11-12 15:35:13 +0530237 dest = nextPipe(OV_MDP_PIPE_DMA, pipeSpecs);
Saurabh Shahc62f3982014-03-05 14:28:26 -0800238 }
Saurabh Shahc62f3982014-03-05 14:28:26 -0800239 if(dest == OV_INVALID) {
Baldev Sahu979e8f02014-11-12 15:35:13 +0530240 dest = nextPipe(OV_MDP_PIPE_VG, pipeSpecs);
Saurabh Shahc62f3982014-03-05 14:28:26 -0800241 }
242 }
243 return dest;
244}
245
Prabhanjan Kandula958ffa92014-05-12 14:56:56 +0530246utils::eDest Overlay::getPipe_8x39(const PipeSpecs& pipeSpecs) {
247 //8x16 & 8x36 has same number of pipes, pipe-types & scaling capabilities.
248 //Rely on 8x16 until we see a need to change.
249 return getPipe_8x16(pipeSpecs);
250}
251
Prabhanjan Kandulafc541b32015-03-30 20:56:16 +0530252utils::eDest Overlay::getPipe_8x52(const PipeSpecs& pipeSpecs) {
253 //8x16 & 8x52 has same number of pipes, pipe-types & scaling capabilities.
254 //Rely on 8x16 until we see a need to change.
255 return getPipe_8x16(pipeSpecs);
256}
257
Saurabh Shah59788572014-07-29 10:07:57 -0700258utils::eDest Overlay::getPipe_8994(const PipeSpecs& pipeSpecs) {
259 //If DMA pipes need to be used in block mode for downscale, there could be
260 //cases where consecutive rounds need separate modes, which cannot be
261 //supported since we at least need 1 round in between where the DMA is
262 //unused
263 eDest dest = OV_INVALID;
Ramkumar Radhakrishnan87a1cd12015-02-25 17:47:29 -0800264
265 // Reset format type to FORMAT_NONE to select the pipe irrespective of the
266 // format specifed by the client. This is required for the device where
267 // SMP starvation is unlikely, we need not keep track of formats
268 // programmed in the pipes to avoid potential pipe crunching.
269 resetPipeBookFormat(pipeSpecs.dpy);
270
Saurabh Shah59788572014-07-29 10:07:57 -0700271 if(pipeSpecs.formatClass == FORMAT_YUV) {
Baldev Sahu979e8f02014-11-12 15:35:13 +0530272 return nextPipe(OV_MDP_PIPE_VG, pipeSpecs);
Saurabh Shah59788572014-07-29 10:07:57 -0700273 } else {
Baldev Sahu979e8f02014-11-12 15:35:13 +0530274 dest = nextPipe(OV_MDP_PIPE_RGB, pipeSpecs);
Saurabh Shah59788572014-07-29 10:07:57 -0700275 if(dest == OV_INVALID) {
Baldev Sahu979e8f02014-11-12 15:35:13 +0530276 dest = nextPipe(OV_MDP_PIPE_VG, pipeSpecs);
Saurabh Shah59788572014-07-29 10:07:57 -0700277 }
278 if(dest == OV_INVALID and not pipeSpecs.needsScaling) {
Baldev Sahu979e8f02014-11-12 15:35:13 +0530279 dest = nextPipe(OV_MDP_PIPE_DMA, pipeSpecs);
Saurabh Shah59788572014-07-29 10:07:57 -0700280 }
281 }
Ramkumar Radhakrishnan87a1cd12015-02-25 17:47:29 -0800282
Saurabh Shah59788572014-07-29 10:07:57 -0700283 return dest;
284}
285
Ramkumar Radhakrishnan87a1cd12015-02-25 17:47:29 -0800286utils::eDest Overlay::getPipe_8992(const PipeSpecs& pipeSpecs) {
287 return getPipe_8994(pipeSpecs);
288}
289
Zohaib Alam4b0a9242013-11-20 23:54:12 -0500290void Overlay::endAllSessions() {
291 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
292 if(mPipeBook[i].valid() && mPipeBook[i].mSession==PipeBook::START)
293 mPipeBook[i].mSession = PipeBook::END;
294 }
295}
296
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700297bool Overlay::isPipeTypeAttached(eMdpPipeType type) {
298 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
299 if(type == PipeBook::getPipeType((eDest)i) &&
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700300 mPipeBook[i].mDisplay != DPY_UNUSED) {
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700301 return true;
302 }
303 }
304 return false;
305}
306
Jeykumar Sankaran89e23ab2015-01-28 15:57:46 -0800307bool Overlay::needsPrioritySwap(utils::eDest pipe1Index,
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800308 utils::eDest pipe2Index) {
309 validate((int)pipe1Index);
310 validate((int)pipe2Index);
Jeykumar Sankaran89e23ab2015-01-28 15:57:46 -0800311
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800312 uint8_t pipe1Prio = mPipeBook[(int)pipe1Index].mPipe->getPriority();
313 uint8_t pipe2Prio = mPipeBook[(int)pipe2Index].mPipe->getPriority();
Jeykumar Sankaran89e23ab2015-01-28 15:57:46 -0800314
315 int pipe1Id = mPipeBook[(int)pipe1Index].mPipe->getPipeId();
316 int pipe2Id = mPipeBook[(int)pipe2Index].mPipe->getPipeId();
317
318 utils::eMdpPipeType leftType = PipeBook::getPipeType(pipe1Index);
319 utils::eMdpPipeType rightType = PipeBook::getPipeType(pipe2Index);
320
321 if(pipe1Id >=0 && pipe2Id >=0) {
322 // LEFT priority should be higher then RIGHT
323 return (pipe1Prio > pipe2Prio);
324 } else if(pipe1Id < 0 && pipe2Id < 0) {
Saurabh Shahea3cf302014-11-07 12:10:46 -0800325 // If we are here, Source Split is enabled and both pipes are
326 // new requests. In this case left type should be of higher prio
327 // than right type
Saurabh Shahea3cf302014-11-07 12:10:46 -0800328 if(leftType == rightType) {
329 //Safe. Onus on driver to assign correct pipes within same type
Jeykumar Sankaran89e23ab2015-01-28 15:57:46 -0800330 return false;
Saurabh Shah218a61a2015-01-28 15:57:46 -0800331 } else {
Saurabh Shahea3cf302014-11-07 12:10:46 -0800332 //This check takes advantage of having only 3 types and avoids 3
333 //different failure combination checks.
Saurabh Shah218a61a2015-01-28 15:57:46 -0800334 // Swap IF:
335 // ----------------
336 // | Left | Right |
337 // ================
338 // | DMA | ViG |
339 // ----------------
340 // | DMA | RGB |
341 // ----------------
342 // | RGB | ViG |
343 // ----------------
344 return (leftType == OV_MDP_PIPE_DMA or rightType == OV_MDP_PIPE_VG);
Jeykumar Sankaran89e23ab2015-01-28 15:57:46 -0800345 }
346 } else if(pipe1Id < 0) {
347 //LEFT needs new allocation.
348 if(leftType == rightType) {
349 // If RIGHT has highest priority(lowest id), swap it.
350 return (pipe2Id == PipeBook::pipeMinID[leftType]);
351 } else {
Saurabh Shah218a61a2015-01-28 15:57:46 -0800352 return (leftType == OV_MDP_PIPE_DMA or rightType == OV_MDP_PIPE_VG);
Jeykumar Sankaran89e23ab2015-01-28 15:57:46 -0800353 }
354 } else { /* if (pipe2Id < 0) */
355 // RIGHT needs new allocation.
356 if(leftType == rightType) {
357 // If LEFT has lowest priority(highest id), swap it.
358 return (pipe1Id == PipeBook::pipeMaxID[leftType]);
359 } else {
Saurabh Shah218a61a2015-01-28 15:57:46 -0800360 return (leftType == OV_MDP_PIPE_DMA or rightType == OV_MDP_PIPE_VG);
Saurabh Shahea3cf302014-11-07 12:10:46 -0800361 }
362 }
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800363}
364
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500365bool Overlay::commit(utils::eDest dest) {
366 bool ret = false;
Praveena Pachipulusu2005e8f2014-05-07 20:01:54 +0530367 validate((int)dest);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500368
Praveena Pachipulusu2005e8f2014-05-07 20:01:54 +0530369 if(mPipeBook[dest].mPipe->commit()) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500370 ret = true;
371 PipeBook::setUse((int)dest);
372 } else {
Saurabh Shah7cd67782014-11-12 10:33:19 -0800373 clear(mPipeBook[dest].mDisplay);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500374 }
375 return ret;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700376}
377
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700378bool Overlay::queueBuffer(int fd, uint32_t offset,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500379 utils::eDest dest) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500380 bool ret = false;
Praveena Pachipulusu2005e8f2014-05-07 20:01:54 +0530381 validate((int)dest);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500382 //Queue only if commit() has succeeded (and the bit set)
383 if(PipeBook::isUsed((int)dest)) {
Praveena Pachipulusu2005e8f2014-05-07 20:01:54 +0530384 ret = mPipeBook[dest].mPipe->queueBuffer(fd, offset);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700385 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500386 return ret;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700387}
388
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500389void Overlay::setCrop(const utils::Dim& d,
390 utils::eDest dest) {
Praveena Pachipulusu2005e8f2014-05-07 20:01:54 +0530391 validate((int)dest);
392 mPipeBook[dest].mPipe->setCrop(d);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700393}
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700394
Sushil Chauhan897a9c32013-07-18 11:09:55 -0700395void Overlay::setColor(const uint32_t color,
396 utils::eDest dest) {
Praveena Pachipulusu2005e8f2014-05-07 20:01:54 +0530397 validate((int)dest);
398 mPipeBook[dest].mPipe->setColor(color);
Sushil Chauhan897a9c32013-07-18 11:09:55 -0700399}
400
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500401void Overlay::setPosition(const utils::Dim& d,
402 utils::eDest dest) {
Praveena Pachipulusu2005e8f2014-05-07 20:01:54 +0530403 validate((int)dest);
404 mPipeBook[dest].mPipe->setPosition(d);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500405}
406
407void Overlay::setTransform(const int orient,
408 utils::eDest dest) {
Praveena Pachipulusu2005e8f2014-05-07 20:01:54 +0530409 validate((int)dest);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500410
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700411 utils::eTransform transform =
412 static_cast<utils::eTransform>(orient);
Praveena Pachipulusu2005e8f2014-05-07 20:01:54 +0530413 mPipeBook[dest].mPipe->setTransform(transform);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700414
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500415}
416
417void Overlay::setSource(const utils::PipeArgs args,
418 utils::eDest dest) {
Praveena Pachipulusu2005e8f2014-05-07 20:01:54 +0530419 validate((int)dest);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500420
radhakrishna8ccb9082014-05-09 16:18:43 +0530421 setPipeType(dest, PipeBook::getPipeType(dest));
422 mPipeBook[dest].mPipe->setSource(args);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700423}
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700424
Saurabh Shah5daeee52013-01-23 16:52:26 +0800425void Overlay::setVisualParams(const MetaData_t& metadata, utils::eDest dest) {
Praveena Pachipulusu2005e8f2014-05-07 20:01:54 +0530426 validate((int)dest);
427 mPipeBook[dest].mPipe->setVisualParams(metadata);
Saurabh Shah5daeee52013-01-23 16:52:26 +0800428}
429
radhakrishna8ccb9082014-05-09 16:18:43 +0530430void Overlay::setPipeType(utils::eDest pipeIndex,
431 const utils::eMdpPipeType pType) {
432 mPipeBook[pipeIndex].mPipe->setPipeType(pType);
433}
434
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500435Overlay* Overlay::getInstance() {
436 if(sInstance == NULL) {
437 sInstance = new Overlay();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700438 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500439 return sInstance;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700440}
441
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800442// Clears any VG pipes allocated to the fb devices
443// Generates a LUT for pipe types.
444int Overlay::initOverlay() {
445 int mdpVersion = qdutils::MDPVersion::getInstance().getMDPVersion();
446 int numPipesXType[OV_MDP_PIPE_ANY] = {0};
447 numPipesXType[OV_MDP_PIPE_RGB] =
448 qdutils::MDPVersion::getInstance().getRGBPipes();
449 numPipesXType[OV_MDP_PIPE_VG] =
450 qdutils::MDPVersion::getInstance().getVGPipes();
451 numPipesXType[OV_MDP_PIPE_DMA] =
452 qdutils::MDPVersion::getInstance().getDMAPipes();
453
454 int index = 0;
455 for(int X = 0; X < (int)OV_MDP_PIPE_ANY; X++) { //iterate over types
456 for(int j = 0; j < numPipesXType[X]; j++) { //iterate over num
457 PipeBook::pipeTypeLUT[index] = (utils::eMdpPipeType)X;
458 index++;
459 }
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700460 }
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800461
Jeykumar Sankaran89e23ab2015-01-28 15:57:46 -0800462 PipeBook::pipeMinID[OV_MDP_PIPE_RGB] = 8;
463 PipeBook::pipeMaxID[OV_MDP_PIPE_RGB] = (numPipesXType[OV_MDP_PIPE_RGB] == 3)? 32 : 512;
464 PipeBook::pipeMinID[OV_MDP_PIPE_VG] = 1;
465 PipeBook::pipeMaxID[OV_MDP_PIPE_VG] = (numPipesXType[OV_MDP_PIPE_VG] == 3)? 4 : 256;
466 PipeBook::pipeMinID[OV_MDP_PIPE_DMA] = 64;
467 PipeBook::pipeMaxID[OV_MDP_PIPE_DMA] = 128;
468
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700469 FILE *displayDeviceFP = NULL;
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700470 char fbType[MAX_FRAME_BUFFER_NAME_SIZE];
471 char msmFbTypePath[MAX_FRAME_BUFFER_NAME_SIZE];
472 const char *strDtvPanel = "dtv panel";
473 const char *strWbPanel = "writeback panel";
474
475 for(int num = 1; num < MAX_FB_DEVICES; num++) {
476 snprintf (msmFbTypePath, sizeof(msmFbTypePath),
477 "/sys/class/graphics/fb%d/msm_fb_type", num);
478 displayDeviceFP = fopen(msmFbTypePath, "r");
479
480 if(displayDeviceFP){
481 fread(fbType, sizeof(char), MAX_FRAME_BUFFER_NAME_SIZE,
482 displayDeviceFP);
483
484 if(strncmp(fbType, strDtvPanel, strlen(strDtvPanel)) == 0) {
485 sDpyFbMap[DPY_EXTERNAL] = num;
486 } else if(strncmp(fbType, strWbPanel, strlen(strWbPanel)) == 0) {
487 sDpyFbMap[DPY_WRITEBACK] = num;
488 }
489
490 fclose(displayDeviceFP);
491 }
492 }
493
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800494 return 0;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700495}
496
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700497bool Overlay::displayCommit(const int& fd) {
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800498 utils::Dim lRoi, rRoi;
499 return displayCommit(fd, lRoi, rRoi);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700500}
501
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800502bool Overlay::displayCommit(const int& fd, const utils::Dim& lRoi,
503 const utils::Dim& rRoi) {
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700504 //Commit
505 struct mdp_display_commit info;
506 memset(&info, 0, sizeof(struct mdp_display_commit));
507 info.flags = MDP_DISPLAY_COMMIT_OVERLAY;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800508 info.l_roi.x = lRoi.x;
509 info.l_roi.y = lRoi.y;
510 info.l_roi.w = lRoi.w;
511 info.l_roi.h = lRoi.h;
512 info.r_roi.x = rRoi.x;
513 info.r_roi.y = rRoi.y;
514 info.r_roi.w = rRoi.w;
515 info.r_roi.h = rRoi.h;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700516
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700517 if(!mdp_wrapper::displayCommit(fd, info)) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700518 ALOGE("%s: commit failed", __func__);
519 return false;
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700520 }
521 return true;
522}
523
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800524void Overlay::getDump(char *buf, size_t len) {
525 int totalPipes = 0;
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700526 const char *str = "\nOverlay State\n\n";
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800527 strlcat(buf, str, len);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800528 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
529 if(mPipeBook[i].valid()) {
530 mPipeBook[i].mPipe->getDump(buf, len);
531 char str[64] = {'\0'};
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700532 snprintf(str, 64, "Display=%d\n\n", mPipeBook[i].mDisplay);
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800533 strlcat(buf, str, len);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800534 totalPipes++;
535 }
536 }
537 char str_pipes[64] = {'\0'};
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700538 snprintf(str_pipes, 64, "Pipes=%d\n\n", totalPipes);
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800539 strlcat(buf, str_pipes, len);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800540}
541
Sushil Chauhanbd3ea922013-05-15 12:25:26 -0700542void Overlay::clear(int dpy) {
543 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
544 if (mPipeBook[i].mDisplay == dpy) {
545 // Mark as available for this round
546 PipeBook::resetUse(i);
547 PipeBook::resetAllocation(i);
Saurabh Shah7cd67782014-11-12 10:33:19 -0800548 if(getPipeId((utils::eDest)i) == -1) {
549 mPipeBook[i].destroy();
550 }
Sushil Chauhanbd3ea922013-05-15 12:25:26 -0700551 }
552 }
553}
554
Saurabh Shaha36be922013-12-16 18:18:39 -0800555bool Overlay::validateAndSet(const int& dpy, const int& fbFd) {
556 GenericPipe* pipeArray[PipeBook::NUM_PIPES];
Praveena Pachipulusu2005e8f2014-05-07 20:01:54 +0530557 memset(pipeArray, 0, sizeof(GenericPipe*)*(PipeBook::NUM_PIPES));
Saurabh Shaha36be922013-12-16 18:18:39 -0800558
559 int num = 0;
560 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
561 if(PipeBook::isUsed(i) && mPipeBook[i].valid() &&
562 mPipeBook[i].mDisplay == dpy) {
563 pipeArray[num++] = mPipeBook[i].mPipe;
564 }
565 }
566
567 //Protect against misbehaving clients
568 return num ? GenericPipe::validateAndSet(pipeArray, num, fbFd) : true;
569}
570
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700571void Overlay::initScalar() {
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700572 if(sLibScaleHandle == NULL) {
573 sLibScaleHandle = dlopen("libscale.so", RTLD_NOW);
Saurabh Shaheac146b2014-05-13 11:36:20 -0700574 if(sLibScaleHandle) {
575 *(void **) &sFnProgramScale =
576 dlsym(sLibScaleHandle, "programScale");
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700577 }
578 }
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700579}
580
581void Overlay::destroyScalar() {
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700582 if(sLibScaleHandle) {
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700583 dlclose(sLibScaleHandle);
584 sLibScaleHandle = NULL;
585 }
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700586}
587
Praveena Pachipulusu734118a2014-12-04 14:53:12 +0530588void Overlay::initPostProc() {
589 sLibAblHandle = dlopen("libmm-abl.so", RTLD_NOW);
590 if (sLibAblHandle) {
591 *(void **)&sFnppParams = dlsym(sLibAblHandle,
592 "display_pp_compute_params");
593 } else {
594 ALOGE("%s: Not able to load libmm-abl.so", __FUNCTION__);
595 }
596}
597
598void Overlay::destroyPostProc() {
599 if (sLibAblHandle) {
600 dlclose(sLibAblHandle);
601 sLibAblHandle = NULL;
602 }
603}
604
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500605void Overlay::PipeBook::init() {
606 mPipe = NULL;
607 mDisplay = DPY_UNUSED;
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700608 mMixer = MIXER_UNUSED;
Baldev Sahu979e8f02014-11-12 15:35:13 +0530609 mFormatType = FORMAT_NONE;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500610}
611
612void Overlay::PipeBook::destroy() {
613 if(mPipe) {
614 delete mPipe;
615 mPipe = NULL;
616 }
617 mDisplay = DPY_UNUSED;
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700618 mMixer = MIXER_UNUSED;
Baldev Sahu979e8f02014-11-12 15:35:13 +0530619 mFormatType = FORMAT_NONE;
Zohaib Alam4b0a9242013-11-20 23:54:12 -0500620 mSession = NONE;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500621}
622
623Overlay* Overlay::sInstance = 0;
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700624int Overlay::sDpyFbMap[DPY_MAX] = {0, -1, -1};
Saurabh Shah85234ec2013-04-12 17:09:00 -0700625int Overlay::sDMAMode = DMA_LINE_MODE;
Raj Kamala8c065f2013-10-22 14:52:45 +0530626bool Overlay::sDMAMultiplexingSupported = false;
Saurabh Shah24eec8a2014-08-22 15:07:25 -0700627bool Overlay::sDebugPipeLifecycle = false;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500628int Overlay::PipeBook::NUM_PIPES = 0;
629int Overlay::PipeBook::sPipeUsageBitmap = 0;
630int Overlay::PipeBook::sLastUsageBitmap = 0;
631int Overlay::PipeBook::sAllocatedBitmap = 0;
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800632utils::eMdpPipeType Overlay::PipeBook::pipeTypeLUT[utils::OV_MAX] =
633 {utils::OV_MDP_PIPE_ANY};
Jeykumar Sankaran89e23ab2015-01-28 15:57:46 -0800634int Overlay::PipeBook::pipeMinID[utils::OV_MDP_PIPE_ANY] = {0};
635int Overlay::PipeBook::pipeMaxID[utils::OV_MDP_PIPE_ANY] = {0};
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700636void *Overlay::sLibScaleHandle = NULL;
Saurabh Shaheac146b2014-05-13 11:36:20 -0700637int (*Overlay::sFnProgramScale)(struct mdp_overlay_list *) = NULL;
Praveena Pachipulusu734118a2014-12-04 14:53:12 +0530638/* Dynamically link ABL library */
639void *Overlay::sLibAblHandle = NULL;
640int (*Overlay::sFnppParams)(const struct compute_params *,
641 struct mdp_overlay_pp_params *) = NULL;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500642
643}; // namespace overlay