• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Copyright (c) 2011-2013, The Linux Foundation. All rights reserved.
3 *
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.
13 *    * Neither the name of The Linux Foundation nor the names of its
14 *      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 
30 #include <dlfcn.h>
31 #include "overlay.h"
32 #include "pipes/overlayGenPipe.h"
33 #include "mdp_version.h"
34 #include "qdMetaData.h"
35 
36 #define PIPE_DEBUG 0
37 
38 namespace overlay {
39 using namespace utils;
40 using namespace qdutils;
41 
Overlay()42 Overlay::Overlay() {
43     int numPipes = qdutils::MDPVersion::getInstance().getTotalPipes();
44     PipeBook::NUM_PIPES = (numPipes <= utils::OV_MAX)? numPipes : utils::OV_MAX;
45     for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
46         mPipeBook[i].init();
47     }
48 
49     mDumpStr[0] = '\0';
50     initScalar();
51     setDMAMultiplexingSupported();
52 }
53 
~Overlay()54 Overlay::~Overlay() {
55     for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
56         mPipeBook[i].destroy();
57     }
58     destroyScalar();
59 }
60 
configBegin()61 void Overlay::configBegin() {
62     for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
63         //Mark as available for this round.
64         PipeBook::resetUse(i);
65         PipeBook::resetAllocation(i);
66     }
67     mDumpStr[0] = '\0';
68 }
69 
configDone()70 void Overlay::configDone() {
71     for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
72         if((PipeBook::isNotUsed(i) && !sessionInProgress((eDest)i)) ||
73                     isSessionEnded((eDest)i)) {
74             //Forces UNSET on pipes, flushes rotator memory and session, closes
75             //fds
76             if(mPipeBook[i].valid()) {
77                 char str[32];
78                 snprintf(str, 32, "Unset=%s dpy=%d mix=%d; ",
79                         PipeBook::getDestStr((eDest)i),
80                         mPipeBook[i].mDisplay, mPipeBook[i].mMixer);
81 #if PIPE_DEBUG
82                 strlcat(mDumpStr, str, sizeof(mDumpStr));
83 #endif
84             }
85             mPipeBook[i].destroy();
86         }
87     }
88     dump();
89     PipeBook::save();
90 }
91 
getPipeId(utils::eDest dest)92 int Overlay::getPipeId(utils::eDest dest) {
93     return mPipeBook[(int)dest].mPipe->getPipeId();
94 }
95 
getDest(int pipeid)96 eDest Overlay::getDest(int pipeid) {
97     eDest dest = OV_INVALID;
98     // finding the dest corresponding to the given pipe
99     for(int i=0; i < PipeBook::NUM_PIPES; ++i) {
100         if(mPipeBook[i].valid() && mPipeBook[i].mPipe->getPipeId() == pipeid) {
101             return (eDest)i;
102         }
103     }
104     return dest;
105 }
106 
reservePipe(int pipeid)107 eDest Overlay::reservePipe(int pipeid) {
108     eDest dest = getDest(pipeid);
109     PipeBook::setAllocation((int)dest);
110     return dest;
111 }
112 
nextPipe(eMdpPipeType type,int dpy,int mixer)113 eDest Overlay::nextPipe(eMdpPipeType type, int dpy, int mixer) {
114     eDest dest = OV_INVALID;
115 
116     for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
117         if( (type == OV_MDP_PIPE_ANY || //Pipe type match
118              type == PipeBook::getPipeType((eDest)i)) &&
119             (mPipeBook[i].mDisplay == DPY_UNUSED || //Free or same display
120              mPipeBook[i].mDisplay == dpy) &&
121             (mPipeBook[i].mMixer == MIXER_UNUSED || //Free or same mixer
122              mPipeBook[i].mMixer == mixer) &&
123             PipeBook::isNotAllocated(i) && //Free pipe
124             ( (sDMAMultiplexingSupported && dpy) ||
125               !(sDMAMode == DMA_BLOCK_MODE && //DMA pipe in Line mode
126                PipeBook::getPipeType((eDest)i) == OV_MDP_PIPE_DMA)) ){
127               //DMA-Multiplexing is only supported for WB on 8x26
128             dest = (eDest)i;
129             PipeBook::setAllocation(i);
130             break;
131         }
132     }
133 
134     if(dest != OV_INVALID) {
135         int index = (int)dest;
136         mPipeBook[index].mDisplay = dpy;
137         mPipeBook[index].mMixer = mixer;
138         if(not mPipeBook[index].valid()) {
139             mPipeBook[index].mPipe = new GenericPipe(dpy);
140             mPipeBook[index].mSession = PipeBook::NONE;
141             char str[32];
142             snprintf(str, 32, "Set=%s dpy=%d mix=%d; ",
143                      PipeBook::getDestStr(dest), dpy, mixer);
144 #if PIPE_DEBUG
145             strlcat(mDumpStr, str, sizeof(mDumpStr));
146 #endif
147         }
148     } else {
149         ALOGD_IF(PIPE_DEBUG, "Pipe unavailable type=%d display=%d mixer=%d",
150                 (int)type, dpy, mixer);
151     }
152 
153     return dest;
154 }
155 
getPipe(const PipeSpecs & pipeSpecs)156 utils::eDest Overlay::getPipe(const PipeSpecs& pipeSpecs) {
157     if(MDPVersion::getInstance().is8x26()) {
158         return getPipe_8x26(pipeSpecs);
159     } else if(MDPVersion::getInstance().is8x16()) {
160         return getPipe_8x16(pipeSpecs);
161     } else if(MDPVersion::getInstance().is8x39()) {
162         return getPipe_8x39(pipeSpecs);
163     }
164 
165     eDest dest = OV_INVALID;
166 
167     //The default behavior is to assume RGB and VG pipes have scalars
168     if(pipeSpecs.formatClass == FORMAT_YUV) {
169         return nextPipe(OV_MDP_PIPE_VG, pipeSpecs.dpy, pipeSpecs.mixer);
170     } else if(pipeSpecs.fb == false) { //RGB App layers
171         if(not pipeSpecs.needsScaling) {
172             dest = nextPipe(OV_MDP_PIPE_DMA, pipeSpecs.dpy, pipeSpecs.mixer);
173         }
174         if(dest == OV_INVALID) {
175             dest = nextPipe(OV_MDP_PIPE_RGB, pipeSpecs.dpy, pipeSpecs.mixer);
176         }
177         if(dest == OV_INVALID) {
178             dest = nextPipe(OV_MDP_PIPE_VG, pipeSpecs.dpy, pipeSpecs.mixer);
179         }
180     } else { //FB layer
181         dest = nextPipe(OV_MDP_PIPE_RGB, pipeSpecs.dpy, pipeSpecs.mixer);
182         if(dest == OV_INVALID) {
183             dest = nextPipe(OV_MDP_PIPE_VG, pipeSpecs.dpy, pipeSpecs.mixer);
184         }
185         //Some features can cause FB to have scaling as well.
186         //If we ever come to this block with FB needing scaling,
187         //the screen will be black for a frame, since the FB won't get a pipe
188         //but atleast this will prevent a hang
189         if(dest == OV_INVALID and (not pipeSpecs.needsScaling)) {
190             dest = nextPipe(OV_MDP_PIPE_DMA, pipeSpecs.dpy, pipeSpecs.mixer);
191         }
192     }
193     return dest;
194 }
195 
getPipe_8x26(const PipeSpecs & pipeSpecs)196 utils::eDest Overlay::getPipe_8x26(const PipeSpecs& pipeSpecs) {
197     //Use this to hide all the 8x26 requirements that cannot be humanly
198     //described in a generic way
199     eDest dest = OV_INVALID;
200     if(pipeSpecs.formatClass == FORMAT_YUV) { //video
201         return nextPipe(OV_MDP_PIPE_VG, pipeSpecs.dpy, pipeSpecs.mixer);
202     } else if(pipeSpecs.fb == false) { //RGB app layers
203         if((not pipeSpecs.needsScaling) and
204           (not (pipeSpecs.numActiveDisplays > 1 &&
205                 pipeSpecs.dpy == DPY_PRIMARY))) {
206             dest = nextPipe(OV_MDP_PIPE_DMA, pipeSpecs.dpy, pipeSpecs.mixer);
207         }
208         if(dest == OV_INVALID) {
209             dest = nextPipe(OV_MDP_PIPE_RGB, pipeSpecs.dpy, pipeSpecs.mixer);
210         }
211         if(dest == OV_INVALID) {
212             dest = nextPipe(OV_MDP_PIPE_VG, pipeSpecs.dpy, pipeSpecs.mixer);
213         }
214     } else { //FB layer
215         //For 8x26 Secondary we use DMA always for FB for inline rotation
216         if(pipeSpecs.dpy == DPY_PRIMARY) {
217             dest = nextPipe(OV_MDP_PIPE_RGB, pipeSpecs.dpy, pipeSpecs.mixer);
218             if(dest == OV_INVALID) {
219                 dest = nextPipe(OV_MDP_PIPE_VG, pipeSpecs.dpy, pipeSpecs.mixer);
220             }
221         }
222         if(dest == OV_INVALID and (not pipeSpecs.needsScaling) and
223           (not (pipeSpecs.numActiveDisplays > 1 &&
224                 pipeSpecs.dpy == DPY_PRIMARY))) {
225             dest = nextPipe(OV_MDP_PIPE_DMA, pipeSpecs.dpy, pipeSpecs.mixer);
226         }
227     }
228     return dest;
229 }
230 
getPipe_8x16(const PipeSpecs & pipeSpecs)231 utils::eDest Overlay::getPipe_8x16(const PipeSpecs& pipeSpecs) {
232     //Having such functions help keeping the interface generic but code specific
233     //and rife with assumptions
234     eDest dest = OV_INVALID;
235     if(pipeSpecs.formatClass == FORMAT_YUV or pipeSpecs.needsScaling) {
236         return nextPipe(OV_MDP_PIPE_VG, pipeSpecs.dpy, pipeSpecs.mixer);
237     } else {
238         //Since this is a specific func, we can assume stuff like RGB pipe not
239         //having scalar blocks
240         dest = nextPipe(OV_MDP_PIPE_RGB, pipeSpecs.dpy, pipeSpecs.mixer);
241         if(dest == OV_INVALID) {
242             dest = nextPipe(OV_MDP_PIPE_DMA, pipeSpecs.dpy, pipeSpecs.mixer);
243         }
244         if(dest == OV_INVALID) {
245             dest = nextPipe(OV_MDP_PIPE_VG, pipeSpecs.dpy, pipeSpecs.mixer);
246         }
247     }
248     return dest;
249 }
250 
getPipe_8x39(const PipeSpecs & pipeSpecs)251 utils::eDest Overlay::getPipe_8x39(const PipeSpecs& pipeSpecs) {
252     //8x16 & 8x36 has same number of pipes, pipe-types & scaling capabilities.
253     //Rely on 8x16 until we see a need to change.
254     return getPipe_8x16(pipeSpecs);
255 }
256 
endAllSessions()257 void Overlay::endAllSessions() {
258     for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
259         if(mPipeBook[i].valid() && mPipeBook[i].mSession==PipeBook::START)
260             mPipeBook[i].mSession = PipeBook::END;
261     }
262 }
263 
isPipeTypeAttached(eMdpPipeType type)264 bool Overlay::isPipeTypeAttached(eMdpPipeType type) {
265     for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
266         if(type == PipeBook::getPipeType((eDest)i) &&
267                 mPipeBook[i].mDisplay != DPY_UNUSED) {
268             return true;
269         }
270     }
271     return false;
272 }
273 
comparePipePriority(utils::eDest pipe1Index,utils::eDest pipe2Index)274 int Overlay::comparePipePriority(utils::eDest pipe1Index,
275         utils::eDest pipe2Index) {
276     validate((int)pipe1Index);
277     validate((int)pipe2Index);
278     uint8_t pipe1Prio = mPipeBook[(int)pipe1Index].mPipe->getPriority();
279     uint8_t pipe2Prio = mPipeBook[(int)pipe2Index].mPipe->getPriority();
280     if(pipe1Prio > pipe2Prio)
281         return -1;
282     if(pipe1Prio < pipe2Prio)
283         return 1;
284     return 0;
285 }
286 
commit(utils::eDest dest)287 bool Overlay::commit(utils::eDest dest) {
288     bool ret = false;
289     validate((int)dest);
290 
291     if(mPipeBook[dest].mPipe->commit()) {
292         ret = true;
293         PipeBook::setUse((int)dest);
294     } else {
295         int dpy = mPipeBook[dest].mDisplay;
296         for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
297             if (mPipeBook[i].mDisplay == dpy) {
298                 PipeBook::resetAllocation(i);
299                 PipeBook::resetUse(i);
300             }
301         }
302     }
303     return ret;
304 }
305 
queueBuffer(int fd,uint32_t offset,utils::eDest dest)306 bool Overlay::queueBuffer(int fd, uint32_t offset,
307         utils::eDest dest) {
308     bool ret = false;
309     validate((int)dest);
310     //Queue only if commit() has succeeded (and the bit set)
311     if(PipeBook::isUsed((int)dest)) {
312         ret = mPipeBook[dest].mPipe->queueBuffer(fd, offset);
313     }
314     return ret;
315 }
316 
setCrop(const utils::Dim & d,utils::eDest dest)317 void Overlay::setCrop(const utils::Dim& d,
318         utils::eDest dest) {
319     validate((int)dest);
320     mPipeBook[dest].mPipe->setCrop(d);
321 }
322 
setColor(const uint32_t color,utils::eDest dest)323 void Overlay::setColor(const uint32_t color,
324         utils::eDest dest) {
325     validate((int)dest);
326     mPipeBook[dest].mPipe->setColor(color);
327 }
328 
setPosition(const utils::Dim & d,utils::eDest dest)329 void Overlay::setPosition(const utils::Dim& d,
330         utils::eDest dest) {
331     validate((int)dest);
332     mPipeBook[dest].mPipe->setPosition(d);
333 }
334 
setTransform(const int orient,utils::eDest dest)335 void Overlay::setTransform(const int orient,
336         utils::eDest dest) {
337     validate((int)dest);
338 
339     utils::eTransform transform =
340             static_cast<utils::eTransform>(orient);
341     mPipeBook[dest].mPipe->setTransform(transform);
342 
343 }
344 
setSource(const utils::PipeArgs args,utils::eDest dest)345 void Overlay::setSource(const utils::PipeArgs args,
346         utils::eDest dest) {
347     validate((int)dest);
348 
349     setPipeType(dest, PipeBook::getPipeType(dest));
350     mPipeBook[dest].mPipe->setSource(args);
351 }
352 
setVisualParams(const MetaData_t & metadata,utils::eDest dest)353 void Overlay::setVisualParams(const MetaData_t& metadata, utils::eDest dest) {
354     validate((int)dest);
355     mPipeBook[dest].mPipe->setVisualParams(metadata);
356 }
357 
setPipeType(utils::eDest pipeIndex,const utils::eMdpPipeType pType)358 void Overlay::setPipeType(utils::eDest pipeIndex,
359         const utils::eMdpPipeType pType) {
360     mPipeBook[pipeIndex].mPipe->setPipeType(pType);
361 }
362 
getInstance()363 Overlay* Overlay::getInstance() {
364     if(sInstance == NULL) {
365         sInstance = new Overlay();
366     }
367     return sInstance;
368 }
369 
370 // Clears any VG pipes allocated to the fb devices
371 // Generates a LUT for pipe types.
initOverlay()372 int Overlay::initOverlay() {
373     int mdpVersion = qdutils::MDPVersion::getInstance().getMDPVersion();
374     int numPipesXType[OV_MDP_PIPE_ANY] = {0};
375     numPipesXType[OV_MDP_PIPE_RGB] =
376             qdutils::MDPVersion::getInstance().getRGBPipes();
377     numPipesXType[OV_MDP_PIPE_VG] =
378             qdutils::MDPVersion::getInstance().getVGPipes();
379     numPipesXType[OV_MDP_PIPE_DMA] =
380             qdutils::MDPVersion::getInstance().getDMAPipes();
381 
382     int index = 0;
383     for(int X = 0; X < (int)OV_MDP_PIPE_ANY; X++) { //iterate over types
384         for(int j = 0; j < numPipesXType[X]; j++) { //iterate over num
385             PipeBook::pipeTypeLUT[index] = (utils::eMdpPipeType)X;
386             index++;
387         }
388     }
389 
390     if (mdpVersion < qdutils::MDSS_V5 && mdpVersion != qdutils::MDP_V3_0_4) {
391         msmfb_mixer_info_req  req;
392         mdp_mixer_info *minfo = NULL;
393         char name[64];
394         int fd = -1;
395         for(int i = 0; i < MAX_FB_DEVICES; i++) {
396             snprintf(name, 64, FB_DEVICE_TEMPLATE, i);
397             ALOGD("initoverlay:: opening the device:: %s", name);
398             fd = ::open(name, O_RDWR, 0);
399             if(fd < 0) {
400                 ALOGE("cannot open framebuffer(%d)", i);
401                 return -1;
402             }
403             //Get the mixer configuration */
404             req.mixer_num = i;
405             if (ioctl(fd, MSMFB_MIXER_INFO, &req) == -1) {
406                 ALOGE("ERROR: MSMFB_MIXER_INFO ioctl failed");
407                 close(fd);
408                 return -1;
409             }
410             minfo = req.info;
411             for (int j = 0; j < req.cnt; j++) {
412                 ALOGD("ndx=%d num=%d z_order=%d", minfo->pndx, minfo->pnum,
413                       minfo->z_order);
414                 // except the RGB base layer with z_order of -1, clear any
415                 // other pipes connected to mixer.
416                 if((minfo->z_order) != -1) {
417                     int index = minfo->pndx;
418                     ALOGD("Unset overlay with index: %d at mixer %d", index, i);
419                     if(ioctl(fd, MSMFB_OVERLAY_UNSET, &index) == -1) {
420                         ALOGE("ERROR: MSMFB_OVERLAY_UNSET failed");
421                         close(fd);
422                         return -1;
423                     }
424                 }
425                 minfo++;
426             }
427             close(fd);
428             fd = -1;
429         }
430     }
431 
432     FILE *displayDeviceFP = NULL;
433     const int MAX_FRAME_BUFFER_NAME_SIZE = 128;
434     char fbType[MAX_FRAME_BUFFER_NAME_SIZE];
435     char msmFbTypePath[MAX_FRAME_BUFFER_NAME_SIZE];
436     const char *strDtvPanel = "dtv panel";
437     const char *strWbPanel = "writeback panel";
438 
439     for(int num = 1; num < MAX_FB_DEVICES; num++) {
440         snprintf (msmFbTypePath, sizeof(msmFbTypePath),
441                 "/sys/class/graphics/fb%d/msm_fb_type", num);
442         displayDeviceFP = fopen(msmFbTypePath, "r");
443 
444         if(displayDeviceFP){
445             fread(fbType, sizeof(char), MAX_FRAME_BUFFER_NAME_SIZE,
446                     displayDeviceFP);
447 
448             if(strncmp(fbType, strDtvPanel, strlen(strDtvPanel)) == 0) {
449                 sDpyFbMap[DPY_EXTERNAL] = num;
450             } else if(strncmp(fbType, strWbPanel, strlen(strWbPanel)) == 0) {
451                 sDpyFbMap[DPY_WRITEBACK] = num;
452             }
453 
454             fclose(displayDeviceFP);
455         }
456     }
457 
458     return 0;
459 }
460 
displayCommit(const int & fd)461 bool Overlay::displayCommit(const int& fd) {
462     utils::Dim lRoi, rRoi;
463     return displayCommit(fd, lRoi, rRoi);
464 }
465 
displayCommit(const int & fd,const utils::Dim & lRoi,const utils::Dim & rRoi)466 bool Overlay::displayCommit(const int& fd, const utils::Dim& lRoi,
467         const utils::Dim& rRoi) {
468     //Commit
469     struct mdp_display_commit info;
470     memset(&info, 0, sizeof(struct mdp_display_commit));
471     info.flags = MDP_DISPLAY_COMMIT_OVERLAY;
472     info.l_roi.x = lRoi.x;
473     info.l_roi.y = lRoi.y;
474     info.l_roi.w = lRoi.w;
475     info.l_roi.h = lRoi.h;
476     info.r_roi.x = rRoi.x;
477     info.r_roi.y = rRoi.y;
478     info.r_roi.w = rRoi.w;
479     info.r_roi.h = rRoi.h;
480 
481     if(!mdp_wrapper::displayCommit(fd, info)) {
482         ALOGE("%s: commit failed", __func__);
483         return false;
484     }
485     return true;
486 }
487 
dump() const488 void Overlay::dump() const {
489 #if PIPE_DEBUG
490     if(strlen(mDumpStr)) { //dump only on state change
491         ALOGD("%s\n", mDumpStr);
492     }
493 #endif
494 }
495 
getDump(char * buf,size_t len)496 void Overlay::getDump(char *buf, size_t len) {
497     int totalPipes = 0;
498     const char *str = "\nOverlay State\n\n";
499     strlcat(buf, str, len);
500     for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
501         if(mPipeBook[i].valid()) {
502             mPipeBook[i].mPipe->getDump(buf, len);
503             char str[64] = {'\0'};
504             snprintf(str, 64, "Display=%d\n\n", mPipeBook[i].mDisplay);
505             strlcat(buf, str, len);
506             totalPipes++;
507         }
508     }
509     char str_pipes[64] = {'\0'};
510     snprintf(str_pipes, 64, "Pipes=%d\n\n", totalPipes);
511     strlcat(buf, str_pipes, len);
512 }
513 
clear(int dpy)514 void Overlay::clear(int dpy) {
515     for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
516         if (mPipeBook[i].mDisplay == dpy) {
517             // Mark as available for this round
518             PipeBook::resetUse(i);
519             PipeBook::resetAllocation(i);
520         }
521     }
522 }
523 
validateAndSet(const int & dpy,const int & fbFd)524 bool Overlay::validateAndSet(const int& dpy, const int& fbFd) {
525     GenericPipe* pipeArray[PipeBook::NUM_PIPES];
526     memset(pipeArray, 0, sizeof(GenericPipe*)*(PipeBook::NUM_PIPES));
527 
528     int num = 0;
529     for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
530         if(PipeBook::isUsed(i) && mPipeBook[i].valid() &&
531                 mPipeBook[i].mDisplay == dpy) {
532             pipeArray[num++] = mPipeBook[i].mPipe;
533         }
534     }
535 
536     //Protect against misbehaving clients
537     return num ? GenericPipe::validateAndSet(pipeArray, num, fbFd) : true;
538 }
539 
initScalar()540 void Overlay::initScalar() {
541     if(sLibScaleHandle == NULL) {
542         sLibScaleHandle = dlopen("libscale.so", RTLD_NOW);
543         if(sLibScaleHandle) {
544             *(void **) &sFnProgramScale =
545                     dlsym(sLibScaleHandle, "programScale");
546         }
547     }
548 }
549 
destroyScalar()550 void Overlay::destroyScalar() {
551     if(sLibScaleHandle) {
552         dlclose(sLibScaleHandle);
553         sLibScaleHandle = NULL;
554     }
555 }
556 
init()557 void Overlay::PipeBook::init() {
558     mPipe = NULL;
559     mDisplay = DPY_UNUSED;
560     mMixer = MIXER_UNUSED;
561 }
562 
destroy()563 void Overlay::PipeBook::destroy() {
564     if(mPipe) {
565         delete mPipe;
566         mPipe = NULL;
567     }
568     mDisplay = DPY_UNUSED;
569     mMixer = MIXER_UNUSED;
570     mSession = NONE;
571 }
572 
573 Overlay* Overlay::sInstance = 0;
574 int Overlay::sDpyFbMap[DPY_MAX] = {0, -1, -1};
575 int Overlay::sDMAMode = DMA_LINE_MODE;
576 bool Overlay::sDMAMultiplexingSupported = false;
577 int Overlay::PipeBook::NUM_PIPES = 0;
578 int Overlay::PipeBook::sPipeUsageBitmap = 0;
579 int Overlay::PipeBook::sLastUsageBitmap = 0;
580 int Overlay::PipeBook::sAllocatedBitmap = 0;
581 utils::eMdpPipeType Overlay::PipeBook::pipeTypeLUT[utils::OV_MAX] =
582     {utils::OV_MDP_PIPE_ANY};
583 void *Overlay::sLibScaleHandle = NULL;
584 int (*Overlay::sFnProgramScale)(struct mdp_overlay_list *) = NULL;
585 
586 }; // namespace overlay
587