blob: 5341c905d700eff3fa5ebc6ba867e8d60a40da60 [file] [log] [blame]
Naseer Ahmed29a26812012-06-14 00:56:20 -07001/*
Naseer Ahmed758bfc52012-11-28 17:02:08 -05002* Copyright (c) 2011-2012, 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
Naseer Ahmed29a26812012-06-14 00:56:20 -070030#include "overlay.h"
Naseer Ahmed758bfc52012-11-28 17:02:08 -050031#include "pipes/overlayGenPipe.h"
32#include "mdp_version.h"
Naseer Ahmed29a26812012-06-14 00:56:20 -070033
Naseer Ahmed758bfc52012-11-28 17:02:08 -050034#define PIPE_DEBUG 0
Naseer Ahmed29a26812012-06-14 00:56:20 -070035
36namespace overlay {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050037using namespace utils;
Naseer Ahmed29a26812012-06-14 00:56:20 -070038
Naseer Ahmed758bfc52012-11-28 17:02:08 -050039Overlay::Overlay() {
40 int numPipes = 0;
41 int mdpVersion = qdutils::MDPVersion::getInstance().getMDPVersion();
42 if (mdpVersion > qdutils::MDP_V3_1) numPipes = 4;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080043 if (mdpVersion >= qdutils::MDSS_V5) numPipes = 8;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050044
45 PipeBook::NUM_PIPES = numPipes;
46 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
47 mPipeBook[i].init();
Naseer Ahmed1ddf3662012-07-31 19:14:18 -070048 }
Naseer Ahmed1ddf3662012-07-31 19:14:18 -070049
Naseer Ahmed758bfc52012-11-28 17:02:08 -050050 mDumpStr[0] = '\0';
Naseer Ahmed29a26812012-06-14 00:56:20 -070051}
52
53Overlay::~Overlay() {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050054 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
55 mPipeBook[i].destroy();
56 }
Naseer Ahmed29a26812012-06-14 00:56:20 -070057}
58
Naseer Ahmed758bfc52012-11-28 17:02:08 -050059void Overlay::configBegin() {
60 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
61 //Mark as available for this round.
62 PipeBook::resetUse(i);
63 PipeBook::resetAllocation(i);
64 }
65 mDumpStr[0] = '\0';
66}
67
68void Overlay::configDone() {
69 if(PipeBook::pipeUsageUnchanged()) return;
70
71 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
72 if(PipeBook::isNotUsed(i)) {
73 //Forces UNSET on pipes, flushes rotator memory and session, closes
74 //fds
75 if(mPipeBook[i].valid()) {
76 char str[32];
77 sprintf(str, "Unset pipe=%s dpy=%d; ", getDestStr((eDest)i),
78 mPipeBook[i].mDisplay);
79 strncat(mDumpStr, str, strlen(str));
80 }
81 mPipeBook[i].destroy();
Naseer Ahmed1ddf3662012-07-31 19:14:18 -070082 }
Naseer Ahmed29a26812012-06-14 00:56:20 -070083 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -050084 dump();
85 PipeBook::save();
86}
87
88eDest Overlay::nextPipe(eMdpPipeType type, int dpy) {
89 eDest dest = OV_INVALID;
90
91 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
92 //Match requested pipe type
93 if(type == OV_MDP_PIPE_ANY || type == getPipeType((eDest)i)) {
94 //If the pipe is not allocated to any display or used by the
95 //requesting display already in previous round.
96 if((mPipeBook[i].mDisplay == PipeBook::DPY_UNUSED ||
97 mPipeBook[i].mDisplay == dpy) &&
98 PipeBook::isNotAllocated(i)) {
99 dest = (eDest)i;
100 PipeBook::setAllocation(i);
101 break;
102 }
103 }
104 }
105
106 if(dest != OV_INVALID) {
107 int index = (int)dest;
108 //If the pipe is not registered with any display OR if the pipe is
109 //requested again by the same display using it, then go ahead.
110 mPipeBook[index].mDisplay = dpy;
111 if(not mPipeBook[index].valid()) {
112 mPipeBook[index].mPipe = new GenericPipe(dpy);
113 char str[32];
114 snprintf(str, 32, "Set pipe=%s dpy=%d; ", getDestStr(dest), dpy);
115 strncat(mDumpStr, str, strlen(str));
116 }
117 } else {
118 ALOGD_IF(PIPE_DEBUG, "Pipe unavailable type=%d display=%d",
119 (int)type, dpy);
120 }
121
122 return dest;
123}
124
125bool Overlay::commit(utils::eDest dest) {
126 bool ret = false;
127 int index = (int)dest;
128 validate(index);
129
130 if(mPipeBook[index].mPipe->commit()) {
131 ret = true;
132 PipeBook::setUse((int)dest);
133 } else {
134 PipeBook::resetUse((int)dest);
Sushil Chauhane0dff932013-03-01 14:33:18 -0800135 int dpy = mPipeBook[index].mDisplay;
136 for(int i = 0; i < PipeBook::NUM_PIPES; i++)
137 if (mPipeBook[i].mDisplay == dpy)
138 PipeBook::resetAllocation(i);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500139 }
140 return ret;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700141}
142
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700143bool Overlay::queueBuffer(int fd, uint32_t offset,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500144 utils::eDest dest) {
145 int index = (int)dest;
146 bool ret = false;
147 validate(index);
148 //Queue only if commit() has succeeded (and the bit set)
149 if(PipeBook::isUsed((int)dest)) {
150 ret = mPipeBook[index].mPipe->queueBuffer(fd, offset);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700151 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500152 return ret;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700153}
154
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500155void Overlay::setCrop(const utils::Dim& d,
156 utils::eDest dest) {
157 int index = (int)dest;
158 validate(index);
159 mPipeBook[index].mPipe->setCrop(d);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700160}
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700161
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500162void Overlay::setPosition(const utils::Dim& d,
163 utils::eDest dest) {
164 int index = (int)dest;
165 validate(index);
166 mPipeBook[index].mPipe->setPosition(d);
167}
168
169void Overlay::setTransform(const int orient,
170 utils::eDest dest) {
171 int index = (int)dest;
172 validate(index);
173
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700174 utils::eTransform transform =
175 static_cast<utils::eTransform>(orient);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500176 mPipeBook[index].mPipe->setTransform(transform);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700177
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500178}
179
180void Overlay::setSource(const utils::PipeArgs args,
181 utils::eDest dest) {
182 int index = (int)dest;
183 validate(index);
184
185 PipeArgs newArgs(args);
186 if(dest == OV_VG0 || dest == OV_VG1) {
187 setMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_SHARE);
188 } else {
189 clearMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_SHARE);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700190 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800191
192 if(dest == OV_DMA0 || dest == OV_DMA1) {
193 setMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_FORCE_DMA);
194 } else {
195 clearMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_FORCE_DMA);
196 }
197
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500198 mPipeBook[index].mPipe->setSource(newArgs);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700199}
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700200
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500201Overlay* Overlay::getInstance() {
202 if(sInstance == NULL) {
203 sInstance = new Overlay();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700204 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500205 return sInstance;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700206}
207
208void Overlay::initOverlay() {
209 if(utils::initOverlay() == -1) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500210 ALOGE("%s failed", __FUNCTION__);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700211 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700212}
213
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500214void Overlay::dump() const {
215 if(strlen(mDumpStr)) { //dump only on state change
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800216 ALOGD_IF(PIPE_DEBUG, "%s\n", mDumpStr);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500217 }
218}
219
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800220void Overlay::getDump(char *buf, size_t len) {
221 int totalPipes = 0;
222 const char *str = "\nOverlay State\n==========================\n";
223 strncat(buf, str, strlen(str));
224 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
225 if(mPipeBook[i].valid()) {
226 mPipeBook[i].mPipe->getDump(buf, len);
227 char str[64] = {'\0'};
228 snprintf(str, 64, "Attached to dpy=%d\n\n", mPipeBook[i].mDisplay);
229 strncat(buf, str, strlen(str));
230 totalPipes++;
231 }
232 }
233 char str_pipes[64] = {'\0'};
234 snprintf(str_pipes, 64, "Pipes used=%d\n\n", totalPipes);
235 strncat(buf, str_pipes, strlen(str_pipes));
236}
237
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500238void Overlay::PipeBook::init() {
239 mPipe = NULL;
240 mDisplay = DPY_UNUSED;
241}
242
243void Overlay::PipeBook::destroy() {
244 if(mPipe) {
245 delete mPipe;
246 mPipe = NULL;
247 }
248 mDisplay = DPY_UNUSED;
249}
250
251Overlay* Overlay::sInstance = 0;
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -0800252int Overlay::sExtFbIndex = 1;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500253int Overlay::PipeBook::NUM_PIPES = 0;
254int Overlay::PipeBook::sPipeUsageBitmap = 0;
255int Overlay::PipeBook::sLastUsageBitmap = 0;
256int Overlay::PipeBook::sAllocatedBitmap = 0;
257
258}; // namespace overlay