blob: 851422faf5626b800b0c4985fb698ee3b88281e6 [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);
135 }
136 return ret;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700137}
138
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700139bool Overlay::queueBuffer(int fd, uint32_t offset,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500140 utils::eDest dest) {
141 int index = (int)dest;
142 bool ret = false;
143 validate(index);
144 //Queue only if commit() has succeeded (and the bit set)
145 if(PipeBook::isUsed((int)dest)) {
146 ret = mPipeBook[index].mPipe->queueBuffer(fd, offset);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700147 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500148 return ret;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700149}
150
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500151void Overlay::setCrop(const utils::Dim& d,
152 utils::eDest dest) {
153 int index = (int)dest;
154 validate(index);
155 mPipeBook[index].mPipe->setCrop(d);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700156}
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700157
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500158void Overlay::setPosition(const utils::Dim& d,
159 utils::eDest dest) {
160 int index = (int)dest;
161 validate(index);
162 mPipeBook[index].mPipe->setPosition(d);
163}
164
165void Overlay::setTransform(const int orient,
166 utils::eDest dest) {
167 int index = (int)dest;
168 validate(index);
169
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700170 utils::eTransform transform =
171 static_cast<utils::eTransform>(orient);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500172 mPipeBook[index].mPipe->setTransform(transform);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700173
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500174}
175
176void Overlay::setSource(const utils::PipeArgs args,
177 utils::eDest dest) {
178 int index = (int)dest;
179 validate(index);
180
181 PipeArgs newArgs(args);
182 if(dest == OV_VG0 || dest == OV_VG1) {
183 setMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_SHARE);
184 } else {
185 clearMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_SHARE);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700186 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800187
188 if(dest == OV_DMA0 || dest == OV_DMA1) {
189 setMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_FORCE_DMA);
190 } else {
191 clearMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_FORCE_DMA);
192 }
193
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500194 mPipeBook[index].mPipe->setSource(newArgs);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700195}
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700196
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500197Overlay* Overlay::getInstance() {
198 if(sInstance == NULL) {
199 sInstance = new Overlay();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700200 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500201 return sInstance;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700202}
203
204void Overlay::initOverlay() {
205 if(utils::initOverlay() == -1) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500206 ALOGE("%s failed", __FUNCTION__);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700207 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700208}
209
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500210void Overlay::dump() const {
211 if(strlen(mDumpStr)) { //dump only on state change
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800212 ALOGD_IF(PIPE_DEBUG, "%s\n", mDumpStr);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500213 }
214}
215
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800216void Overlay::getDump(char *buf, size_t len) {
217 int totalPipes = 0;
218 const char *str = "\nOverlay State\n==========================\n";
219 strncat(buf, str, strlen(str));
220 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
221 if(mPipeBook[i].valid()) {
222 mPipeBook[i].mPipe->getDump(buf, len);
223 char str[64] = {'\0'};
224 snprintf(str, 64, "Attached to dpy=%d\n\n", mPipeBook[i].mDisplay);
225 strncat(buf, str, strlen(str));
226 totalPipes++;
227 }
228 }
229 char str_pipes[64] = {'\0'};
230 snprintf(str_pipes, 64, "Pipes used=%d\n\n", totalPipes);
231 strncat(buf, str_pipes, strlen(str_pipes));
232}
233
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500234void Overlay::PipeBook::init() {
235 mPipe = NULL;
236 mDisplay = DPY_UNUSED;
237}
238
239void Overlay::PipeBook::destroy() {
240 if(mPipe) {
241 delete mPipe;
242 mPipe = NULL;
243 }
244 mDisplay = DPY_UNUSED;
245}
246
247Overlay* Overlay::sInstance = 0;
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -0800248int Overlay::sExtFbIndex = 1;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500249int Overlay::PipeBook::NUM_PIPES = 0;
250int Overlay::PipeBook::sPipeUsageBitmap = 0;
251int Overlay::PipeBook::sLastUsageBitmap = 0;
252int Overlay::PipeBook::sAllocatedBitmap = 0;
253
254}; // namespace overlay