overlay.cpp revision ef53c1c84ec55ed50f607d52b7abfbb86239408e
1ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson/*
2ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson* Copyright (c) 2011-2013, The Linux Foundation. All rights reserved.
3ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson*
4ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson* Redistribution and use in source and binary forms, with or without
5ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson* modification, are permitted provided that the following conditions are
6ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson* met:
7ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson*    * Redistributions of source code must retain the above copyright
8ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson*      notice, this list of conditions and the following disclaimer.
9ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson*    * Redistributions in binary form must reproduce the above
10ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson*      copyright notice, this list of conditions and the following
11ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson*      disclaimer in the documentation and/or other materials provided
12ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson*      with the distribution.
13ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson*    * Neither the name of The Linux Foundation nor the names of its
14ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson*      contributors may be used to endorse or promote products derived
15ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson*      from this software without specific prior written permission.
16ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson*
17ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson* ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson*/
29ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
30ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson#include "overlay.h"
31ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson#include "pipes/overlayGenPipe.h"
32ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson#include "mdp_version.h"
33ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson#include "qdMetaData.h"
34ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
35ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson#define PIPE_DEBUG 0
36ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
37ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsonnamespace overlay {
38ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsonusing namespace utils;
39ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
40ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon WilsonOverlay::Overlay() {
41ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    PipeBook::NUM_PIPES = qdutils::MDPVersion::getInstance().getTotalPipes();
42ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
43ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson        mPipeBook[i].init();
44ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    }
45ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
46ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    mDumpStr[0] = '\0';
47ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson}
48ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
49ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon WilsonOverlay::~Overlay() {
50ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
51ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson        mPipeBook[i].destroy();
52ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    }
53ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson}
54ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
55ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsonvoid Overlay::configBegin() {
56ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
57ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson        //Mark as available for this round.
58ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson        PipeBook::resetUse(i);
59ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson        PipeBook::resetAllocation(i);
60ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    }
61ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    sForceSetBitmap = 0;
62ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    mDumpStr[0] = '\0';
63ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson}
64ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
65ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsonvoid Overlay::configDone() {
66ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
67ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson        if(PipeBook::isNotUsed(i)) {
68ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson            //Forces UNSET on pipes, flushes rotator memory and session, closes
69ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson            //fds
70ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson            if(mPipeBook[i].valid()) {
71ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson                char str[32];
72ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson                sprintf(str, "Unset=%s dpy=%d mix=%d; ",
73ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson                        PipeBook::getDestStr((eDest)i),
74ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson                        mPipeBook[i].mDisplay, mPipeBook[i].mMixer);
75ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson#if PIPE_DEBUG
76ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson                strncat(mDumpStr, str, strlen(str));
77ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson#endif
78ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson            }
79ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson            mPipeBook[i].destroy();
80ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson        }
81ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    }
82ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    dump();
83ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    PipeBook::save();
84ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson}
85ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
86ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon WilsoneDest Overlay::nextPipe(eMdpPipeType type, int dpy, int mixer) {
87ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    eDest dest = OV_INVALID;
88ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
89ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
90ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson        if( (type == OV_MDP_PIPE_ANY || //Pipe type match
91ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson             type == PipeBook::getPipeType((eDest)i)) &&
92ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson            (mPipeBook[i].mDisplay == DPY_UNUSED || //Free or same display
93ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson             mPipeBook[i].mDisplay == dpy) &&
94ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson            (mPipeBook[i].mMixer == MIXER_UNUSED || //Free or same mixer
95ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson             mPipeBook[i].mMixer == mixer) &&
96ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson            PipeBook::isNotAllocated(i) && //Free pipe
97ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson            !(sDMAMode == DMA_BLOCK_MODE && //DMA pipe in Line mode
98ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson               PipeBook::getPipeType((eDest)i) == OV_MDP_PIPE_DMA)) {
99ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson            dest = (eDest)i;
100ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson            PipeBook::setAllocation(i);
101ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson            break;
102ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson        }
103ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    }
104ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
105ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    if(dest != OV_INVALID) {
106ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson        int index = (int)dest;
107ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson        mPipeBook[index].mDisplay = dpy;
108ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson        mPipeBook[index].mMixer = mixer;
109ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson        if(not mPipeBook[index].valid()) {
110ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson            mPipeBook[index].mPipe = new GenericPipe(dpy);
111ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson            char str[32];
112ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson            snprintf(str, 32, "Set=%s dpy=%d mix=%d; ",
113ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson                     PipeBook::getDestStr(dest), dpy, mixer);
114ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson#if PIPE_DEBUG
115ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson            strncat(mDumpStr, str, strlen(str));
116ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson#endif
117ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson        }
118ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    } else {
119ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson        ALOGD_IF(PIPE_DEBUG, "Pipe unavailable type=%d display=%d mixer=%d",
120ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson                (int)type, dpy, mixer);
121ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    }
122ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
123ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    return dest;
124ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson}
125ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
126ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsonbool Overlay::isPipeTypeAttached(eMdpPipeType type) {
127ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
128ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson        if(type == PipeBook::getPipeType((eDest)i) &&
129ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson                mPipeBook[i].mDisplay != DPY_UNUSED) {
130ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson            return true;
131ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson        }
132ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    }
133ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    return false;
134ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson}
135ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
136ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsonbool Overlay::commit(utils::eDest dest) {
137ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    bool ret = false;
138ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    int index = (int)dest;
139ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    validate(index);
140ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
141ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    if(mPipeBook[index].mPipe->commit()) {
142ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson        ret = true;
143ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson        PipeBook::setUse((int)dest);
144ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson        if(sForceSetBitmap & (1 << mPipeBook[index].mDisplay)) {
145ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson            mPipeBook[index].mPipe->forceSet();
146ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson        }
147ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    } else {
148ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson        int dpy = mPipeBook[index].mDisplay;
149ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson        for(int i = 0; i < PipeBook::NUM_PIPES; i++)
150ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson            if (mPipeBook[i].mDisplay == dpy) {
151ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson                PipeBook::resetAllocation(i);
152ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson                PipeBook::resetUse(i);
153ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson                if(mPipeBook[i].valid()) {
154ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson                    mPipeBook[i].mPipe->forceSet();
155ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson                }
156ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson            }
157ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    }
158ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    return ret;
159ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson}
160ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
161ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsonbool Overlay::queueBuffer(int fd, uint32_t offset,
162ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson        utils::eDest dest) {
163ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    int index = (int)dest;
164ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    bool ret = false;
165ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    validate(index);
166ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    //Queue only if commit() has succeeded (and the bit set)
167ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    if(PipeBook::isUsed((int)dest)) {
168ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson        ret = mPipeBook[index].mPipe->queueBuffer(fd, offset);
169ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    }
170ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    return ret;
171ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson}
172ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
173ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsonvoid Overlay::setCrop(const utils::Dim& d,
174ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson        utils::eDest dest) {
175ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    int index = (int)dest;
176ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    validate(index);
177ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    mPipeBook[index].mPipe->setCrop(d);
178ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson}
179ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
180ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsonvoid Overlay::setPosition(const utils::Dim& d,
181ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson        utils::eDest dest) {
182ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    int index = (int)dest;
183ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    validate(index);
184ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    mPipeBook[index].mPipe->setPosition(d);
185ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson}
186ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
187ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsonvoid Overlay::setTransform(const int orient,
188ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson        utils::eDest dest) {
189ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    int index = (int)dest;
190ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    validate(index);
191ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
192ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    utils::eTransform transform =
193ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson            static_cast<utils::eTransform>(orient);
194ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    mPipeBook[index].mPipe->setTransform(transform);
195ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
196ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson}
197ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
198ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsonvoid Overlay::setSource(const utils::PipeArgs args,
199ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson        utils::eDest dest) {
200ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    int index = (int)dest;
201ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    validate(index);
202ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
203ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    PipeArgs newArgs(args);
204ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    if(PipeBook::getPipeType(dest) == OV_MDP_PIPE_VG) {
205ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson        setMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_SHARE);
206ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    } else {
207ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson        clearMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_SHARE);
208ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    }
209ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
210ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    if(PipeBook::getPipeType(dest) == OV_MDP_PIPE_DMA) {
211ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson        setMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_FORCE_DMA);
212ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    } else {
213ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson        clearMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_FORCE_DMA);
214ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    }
215ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
216ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    mPipeBook[index].mPipe->setSource(newArgs);
217ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson}
218ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
219ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsonvoid Overlay::setVisualParams(const MetaData_t& metadata, utils::eDest dest) {
220ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    int index = (int)dest;
221ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    validate(index);
222ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    mPipeBook[index].mPipe->setVisualParams(metadata);
223ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson}
224ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
225ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon WilsonOverlay* Overlay::getInstance() {
226ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    if(sInstance == NULL) {
227ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson        sInstance = new Overlay();
228ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    }
229ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    return sInstance;
230ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson}
231ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
232ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson// Clears any VG pipes allocated to the fb devices
233ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson// Generates a LUT for pipe types.
234ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsonint Overlay::initOverlay() {
235ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    int mdpVersion = qdutils::MDPVersion::getInstance().getMDPVersion();
236ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    int numPipesXType[OV_MDP_PIPE_ANY] = {0};
237ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    numPipesXType[OV_MDP_PIPE_RGB] =
238ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson            qdutils::MDPVersion::getInstance().getRGBPipes();
239ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    numPipesXType[OV_MDP_PIPE_VG] =
240ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson            qdutils::MDPVersion::getInstance().getVGPipes();
241ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    numPipesXType[OV_MDP_PIPE_DMA] =
242ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson            qdutils::MDPVersion::getInstance().getDMAPipes();
243ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
244ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    int index = 0;
245ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    for(int X = 0; X < (int)OV_MDP_PIPE_ANY; X++) { //iterate over types
246ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson        for(int j = 0; j < numPipesXType[X]; j++) { //iterate over num
247ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson            PipeBook::pipeTypeLUT[index] = (utils::eMdpPipeType)X;
248ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson            index++;
249ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson        }
250ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    }
251ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
252ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    if (mdpVersion < qdutils::MDSS_V5 && mdpVersion != qdutils::MDP_V3_0_4) {
253ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson        msmfb_mixer_info_req  req;
254ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson        mdp_mixer_info *minfo = NULL;
255ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson        char name[64];
256ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson        int fd = -1;
257ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson        for(int i = 0; i < MAX_FB_DEVICES; i++) {
258ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson            snprintf(name, 64, FB_DEVICE_TEMPLATE, i);
259ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson            ALOGD("initoverlay:: opening the device:: %s", name);
260ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson            fd = ::open(name, O_RDWR, 0);
261ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson            if(fd < 0) {
262ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson                ALOGE("cannot open framebuffer(%d)", i);
263ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson                return -1;
264ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson            }
265ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson            //Get the mixer configuration */
266ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson            req.mixer_num = i;
267ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson            if (ioctl(fd, MSMFB_MIXER_INFO, &req) == -1) {
268ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson                ALOGE("ERROR: MSMFB_MIXER_INFO ioctl failed");
269ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson                close(fd);
270ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson                return -1;
271ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson            }
272ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson            minfo = req.info;
273ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson            for (int j = 0; j < req.cnt; j++) {
274ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson                ALOGD("ndx=%d num=%d z_order=%d", minfo->pndx, minfo->pnum,
275ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson                      minfo->z_order);
276ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson                // clear any pipe connected to mixer including base pipe.
277ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson                int index = minfo->pndx;
278ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson                ALOGD("Unset overlay with index: %d at mixer %d", index, i);
279ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson                if(ioctl(fd, MSMFB_OVERLAY_UNSET, &index) == -1) {
280ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson                    ALOGE("ERROR: MSMFB_OVERLAY_UNSET failed");
281ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson                    close(fd);
282ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson                    return -1;
283ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson                }
284ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson                minfo++;
285ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson            }
286ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson            close(fd);
287ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson            fd = -1;
288ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson        }
289ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    }
290ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
291ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    FILE *displayDeviceFP = NULL;
292ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    const int MAX_FRAME_BUFFER_NAME_SIZE = 128;
293ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    char fbType[MAX_FRAME_BUFFER_NAME_SIZE];
294ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    char msmFbTypePath[MAX_FRAME_BUFFER_NAME_SIZE];
295ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    const char *strDtvPanel = "dtv panel";
296ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    const char *strWbPanel = "writeback panel";
297ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
298ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    for(int num = 1; num < MAX_FB_DEVICES; num++) {
299ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson        snprintf (msmFbTypePath, sizeof(msmFbTypePath),
300ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson                "/sys/class/graphics/fb%d/msm_fb_type", num);
301ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson        displayDeviceFP = fopen(msmFbTypePath, "r");
302ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
303ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson        if(displayDeviceFP){
304ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson            fread(fbType, sizeof(char), MAX_FRAME_BUFFER_NAME_SIZE,
305ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson                    displayDeviceFP);
306ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
307ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson            if(strncmp(fbType, strDtvPanel, strlen(strDtvPanel)) == 0) {
308ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson                sDpyFbMap[DPY_EXTERNAL] = num;
309ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson            } else if(strncmp(fbType, strWbPanel, strlen(strWbPanel)) == 0) {
310ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson                sDpyFbMap[DPY_WRITEBACK] = num;
311ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson            }
312ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
313ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson            fclose(displayDeviceFP);
314ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson        }
315ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    }
316ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
317ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    return 0;
318ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson}
319ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
320ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsonbool Overlay::displayCommit(const int& fd) {
321ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    //Commit
322ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    struct mdp_display_commit info;
323ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    memset(&info, 0, sizeof(struct mdp_display_commit));
324ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    info.flags = MDP_DISPLAY_COMMIT_OVERLAY;
325ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    if(!mdp_wrapper::displayCommit(fd, info)) {
326ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson       ALOGE("%s: commit failed", __func__);
327ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson       return false;
328ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    }
329ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    return true;
330ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson}
331ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
332ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsonvoid Overlay::dump() const {
333ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson#if PIPE_DEBUG
334ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    if(strlen(mDumpStr)) { //dump only on state change
335ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson        ALOGD("%s\n", mDumpStr);
336ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    }
337ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson#endif
338ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson}
339ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
340ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsonvoid Overlay::getDump(char *buf, size_t len) {
341ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    int totalPipes = 0;
342ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    const char *str = "\nOverlay State\n\n";
343ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    strncat(buf, str, strlen(str));
344ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
345ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson        if(mPipeBook[i].valid()) {
346ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson            mPipeBook[i].mPipe->getDump(buf, len);
347ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson            char str[64] = {'\0'};
348ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson            snprintf(str, 64, "Display=%d\n\n", mPipeBook[i].mDisplay);
349ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson            strncat(buf, str, strlen(str));
350ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson            totalPipes++;
351ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson        }
352ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    }
353ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    char str_pipes[64] = {'\0'};
354ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    snprintf(str_pipes, 64, "Pipes=%d\n\n", totalPipes);
355ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    strncat(buf, str_pipes, strlen(str_pipes));
356ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson}
357ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
358ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsonvoid Overlay::clear(int dpy) {
359ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
360ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson        if (mPipeBook[i].mDisplay == dpy) {
361ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson            // Mark as available for this round
362ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson            PipeBook::resetUse(i);
363ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson            PipeBook::resetAllocation(i);
364ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson            if(mPipeBook[i].valid()) {
365ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson                mPipeBook[i].mPipe->forceSet();
366ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson            }
367ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson        }
368ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    }
369ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson}
370ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
371ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsonvoid Overlay::PipeBook::init() {
372ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    mPipe = NULL;
373ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    mDisplay = DPY_UNUSED;
374ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    mMixer = MIXER_UNUSED;
375ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson}
376ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
377ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsonvoid Overlay::PipeBook::destroy() {
378ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    if(mPipe) {
379ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson        delete mPipe;
380ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson        mPipe = NULL;
381ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    }
382ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    mDisplay = DPY_UNUSED;
383ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    mMixer = MIXER_UNUSED;
384ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson}
385ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
386ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon WilsonOverlay* Overlay::sInstance = 0;
387ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsonint Overlay::sDpyFbMap[DPY_MAX] = {0, -1, -1};
388ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsonint Overlay::sDMAMode = DMA_LINE_MODE;
389ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsonint Overlay::sForceSetBitmap = 0;
390ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsonint Overlay::PipeBook::NUM_PIPES = 0;
391ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsonint Overlay::PipeBook::sPipeUsageBitmap = 0;
392ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsonint Overlay::PipeBook::sLastUsageBitmap = 0;
393ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsonint Overlay::PipeBook::sAllocatedBitmap = 0;
394ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsonutils::eMdpPipeType Overlay::PipeBook::pipeTypeLUT[utils::OV_MAX] =
395ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    {utils::OV_MDP_PIPE_ANY};
396ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
397ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson}; // namespace overlay
398