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