1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
|
/*
* Copyright (c) 2011-2012, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "overlay.h"
#include "pipes/overlayGenPipe.h"
#include "mdp_version.h"
#define PIPE_DEBUG 0
namespace overlay {
using namespace utils;
Overlay::Overlay() {
int numPipes = 0;
int mdpVersion = qdutils::MDPVersion::getInstance().getMDPVersion();
if (mdpVersion > qdutils::MDP_V3_1) numPipes = 4;
if (mdpVersion >= qdutils::MDSS_V5) numPipes = 6;
PipeBook::NUM_PIPES = numPipes;
for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
mPipeBook[i].init();
}
mDumpStr[0] = '\0';
}
Overlay::~Overlay() {
for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
mPipeBook[i].destroy();
}
}
void Overlay::configBegin() {
for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
//Mark as available for this round.
PipeBook::resetUse(i);
PipeBook::resetAllocation(i);
}
mDumpStr[0] = '\0';
}
void Overlay::configDone() {
if(PipeBook::pipeUsageUnchanged()) return;
for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
if(PipeBook::isNotUsed(i)) {
//Forces UNSET on pipes, flushes rotator memory and session, closes
//fds
if(mPipeBook[i].valid()) {
char str[32];
sprintf(str, "Unset pipe=%s dpy=%d; ", getDestStr((eDest)i),
mPipeBook[i].mDisplay);
strncat(mDumpStr, str, strlen(str));
}
mPipeBook[i].destroy();
}
}
dump();
PipeBook::save();
}
eDest Overlay::nextPipe(eMdpPipeType type, int dpy) {
eDest dest = OV_INVALID;
for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
//Match requested pipe type
if(type == OV_MDP_PIPE_ANY || type == getPipeType((eDest)i)) {
//If the pipe is not allocated to any display or used by the
//requesting display already in previous round.
if((mPipeBook[i].mDisplay == PipeBook::DPY_UNUSED ||
mPipeBook[i].mDisplay == dpy) &&
PipeBook::isNotAllocated(i)) {
dest = (eDest)i;
PipeBook::setAllocation(i);
break;
}
}
}
if(dest != OV_INVALID) {
int index = (int)dest;
//If the pipe is not registered with any display OR if the pipe is
//requested again by the same display using it, then go ahead.
mPipeBook[index].mDisplay = dpy;
if(not mPipeBook[index].valid()) {
mPipeBook[index].mPipe = new GenericPipe(dpy);
char str[32];
snprintf(str, 32, "Set pipe=%s dpy=%d; ", getDestStr(dest), dpy);
strncat(mDumpStr, str, strlen(str));
}
} else {
ALOGD_IF(PIPE_DEBUG, "Pipe unavailable type=%d display=%d",
(int)type, dpy);
}
return dest;
}
bool Overlay::commit(utils::eDest dest) {
bool ret = false;
int index = (int)dest;
validate(index);
if(mPipeBook[index].mPipe->commit()) {
ret = true;
PipeBook::setUse((int)dest);
} else {
PipeBook::resetUse((int)dest);
}
return ret;
}
bool Overlay::queueBuffer(int fd, uint32_t offset,
utils::eDest dest) {
int index = (int)dest;
bool ret = false;
validate(index);
//Queue only if commit() has succeeded (and the bit set)
if(PipeBook::isUsed((int)dest)) {
ret = mPipeBook[index].mPipe->queueBuffer(fd, offset);
}
return ret;
}
void Overlay::setCrop(const utils::Dim& d,
utils::eDest dest) {
int index = (int)dest;
validate(index);
mPipeBook[index].mPipe->setCrop(d);
}
void Overlay::setPosition(const utils::Dim& d,
utils::eDest dest) {
int index = (int)dest;
validate(index);
mPipeBook[index].mPipe->setPosition(d);
}
void Overlay::setTransform(const int orient,
utils::eDest dest) {
int index = (int)dest;
validate(index);
utils::eTransform transform =
static_cast<utils::eTransform>(orient);
mPipeBook[index].mPipe->setTransform(transform);
}
void Overlay::setSource(const utils::PipeArgs args,
utils::eDest dest) {
int index = (int)dest;
validate(index);
PipeArgs newArgs(args);
if(dest == OV_VG0 || dest == OV_VG1) {
setMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_SHARE);
} else {
clearMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_SHARE);
}
mPipeBook[index].mPipe->setSource(newArgs);
}
Overlay* Overlay::getInstance() {
if(sInstance == NULL) {
sInstance = new Overlay();
}
return sInstance;
}
void Overlay::initOverlay() {
if(utils::initOverlay() == -1) {
ALOGE("%s failed", __FUNCTION__);
}
}
void Overlay::dump() const {
if(strlen(mDumpStr)) { //dump only on state change
ALOGD("%s\n", mDumpStr);
}
}
void Overlay::PipeBook::init() {
mPipe = NULL;
mDisplay = DPY_UNUSED;
}
void Overlay::PipeBook::destroy() {
if(mPipe) {
delete mPipe;
mPipe = NULL;
}
mDisplay = DPY_UNUSED;
}
Overlay* Overlay::sInstance = 0;
int Overlay::PipeBook::NUM_PIPES = 0;
int Overlay::PipeBook::sPipeUsageBitmap = 0;
int Overlay::PipeBook::sLastUsageBitmap = 0;
int Overlay::PipeBook::sAllocatedBitmap = 0;
}; // namespace overlay
|