blob: 9b91760e75d70fbf697ef36e3a765d7f0a82811c [file] [log] [blame]
Naseer Ahmed29a26812012-06-14 00:56:20 -07001/*
Sushil Chauhan07a2c762013-03-06 15:36:49 -08002* Copyright (c) 2011-2013, 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"
Saurabh Shah5daeee52013-01-23 16:52:26 +080033#include "qdMetaData.h"
Naseer Ahmed29a26812012-06-14 00:56:20 -070034
Naseer Ahmed758bfc52012-11-28 17:02:08 -050035#define PIPE_DEBUG 0
Naseer Ahmed29a26812012-06-14 00:56:20 -070036
37namespace overlay {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050038using namespace utils;
Naseer Ahmed29a26812012-06-14 00:56:20 -070039
Naseer Ahmed758bfc52012-11-28 17:02:08 -050040Overlay::Overlay() {
Sushil Chauhan07a2c762013-03-06 15:36:49 -080041 PipeBook::NUM_PIPES = qdutils::MDPVersion::getInstance().getTotalPipes();
Naseer Ahmed758bfc52012-11-28 17:02:08 -050042 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
43 mPipeBook[i].init();
Naseer Ahmed1ddf3662012-07-31 19:14:18 -070044 }
Naseer Ahmed1ddf3662012-07-31 19:14:18 -070045
Naseer Ahmed758bfc52012-11-28 17:02:08 -050046 mDumpStr[0] = '\0';
Naseer Ahmed29a26812012-06-14 00:56:20 -070047}
48
49Overlay::~Overlay() {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050050 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
51 mPipeBook[i].destroy();
52 }
Naseer Ahmed29a26812012-06-14 00:56:20 -070053}
54
Naseer Ahmed758bfc52012-11-28 17:02:08 -050055void Overlay::configBegin() {
56 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
57 //Mark as available for this round.
58 PipeBook::resetUse(i);
59 PipeBook::resetAllocation(i);
60 }
61 mDumpStr[0] = '\0';
62}
63
64void Overlay::configDone() {
65 if(PipeBook::pipeUsageUnchanged()) return;
66
67 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
68 if(PipeBook::isNotUsed(i)) {
69 //Forces UNSET on pipes, flushes rotator memory and session, closes
70 //fds
71 if(mPipeBook[i].valid()) {
72 char str[32];
Sushil Chauhan07a2c762013-03-06 15:36:49 -080073 sprintf(str, "Unset pipe=%s dpy=%d; ",
74 PipeBook::getDestStr((eDest)i), mPipeBook[i].mDisplay);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050075 strncat(mDumpStr, str, strlen(str));
76 }
77 mPipeBook[i].destroy();
Naseer Ahmed1ddf3662012-07-31 19:14:18 -070078 }
Naseer Ahmed29a26812012-06-14 00:56:20 -070079 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -050080 dump();
81 PipeBook::save();
82}
83
84eDest Overlay::nextPipe(eMdpPipeType type, int dpy) {
85 eDest dest = OV_INVALID;
86
87 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
88 //Match requested pipe type
Sushil Chauhan07a2c762013-03-06 15:36:49 -080089 if(type == OV_MDP_PIPE_ANY || type == PipeBook::getPipeType((eDest)i)) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050090 //If the pipe is not allocated to any display or used by the
91 //requesting display already in previous round.
92 if((mPipeBook[i].mDisplay == PipeBook::DPY_UNUSED ||
93 mPipeBook[i].mDisplay == dpy) &&
94 PipeBook::isNotAllocated(i)) {
Saurabh Shah85234ec2013-04-12 17:09:00 -070095 //In block mode we don't allow line operations
96 if(sDMAMode == DMA_BLOCK_MODE &&
97 PipeBook::getPipeType((eDest)i) == OV_MDP_PIPE_DMA)
98 continue;
99
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500100 dest = (eDest)i;
101 PipeBook::setAllocation(i);
102 break;
103 }
104 }
105 }
106
107 if(dest != OV_INVALID) {
108 int index = (int)dest;
109 //If the pipe is not registered with any display OR if the pipe is
110 //requested again by the same display using it, then go ahead.
111 mPipeBook[index].mDisplay = dpy;
112 if(not mPipeBook[index].valid()) {
113 mPipeBook[index].mPipe = new GenericPipe(dpy);
114 char str[32];
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800115 snprintf(str, 32, "Set pipe=%s dpy=%d; ",
116 PipeBook::getDestStr(dest), dpy);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500117 strncat(mDumpStr, str, strlen(str));
118 }
119 } else {
120 ALOGD_IF(PIPE_DEBUG, "Pipe unavailable type=%d display=%d",
121 (int)type, dpy);
122 }
123
124 return dest;
125}
126
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700127bool Overlay::isPipeTypeAttached(eMdpPipeType type) {
128 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
129 if(type == PipeBook::getPipeType((eDest)i) &&
130 mPipeBook[i].mDisplay != PipeBook::DPY_UNUSED) {
131 return true;
132 }
133 }
134 return false;
135}
136
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500137bool Overlay::commit(utils::eDest dest) {
138 bool ret = false;
139 int index = (int)dest;
140 validate(index);
141
142 if(mPipeBook[index].mPipe->commit()) {
143 ret = true;
144 PipeBook::setUse((int)dest);
145 } else {
146 PipeBook::resetUse((int)dest);
Sushil Chauhane0dff932013-03-01 14:33:18 -0800147 int dpy = mPipeBook[index].mDisplay;
148 for(int i = 0; i < PipeBook::NUM_PIPES; i++)
149 if (mPipeBook[i].mDisplay == dpy)
150 PipeBook::resetAllocation(i);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500151 }
152 return ret;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700153}
154
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700155bool Overlay::queueBuffer(int fd, uint32_t offset,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500156 utils::eDest dest) {
157 int index = (int)dest;
158 bool ret = false;
159 validate(index);
160 //Queue only if commit() has succeeded (and the bit set)
161 if(PipeBook::isUsed((int)dest)) {
162 ret = mPipeBook[index].mPipe->queueBuffer(fd, offset);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700163 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500164 return ret;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700165}
166
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500167void Overlay::setCrop(const utils::Dim& d,
168 utils::eDest dest) {
169 int index = (int)dest;
170 validate(index);
171 mPipeBook[index].mPipe->setCrop(d);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700172}
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700173
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500174void Overlay::setPosition(const utils::Dim& d,
175 utils::eDest dest) {
176 int index = (int)dest;
177 validate(index);
178 mPipeBook[index].mPipe->setPosition(d);
179}
180
181void Overlay::setTransform(const int orient,
182 utils::eDest dest) {
183 int index = (int)dest;
184 validate(index);
185
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700186 utils::eTransform transform =
187 static_cast<utils::eTransform>(orient);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500188 mPipeBook[index].mPipe->setTransform(transform);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700189
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500190}
191
192void Overlay::setSource(const utils::PipeArgs args,
193 utils::eDest dest) {
194 int index = (int)dest;
195 validate(index);
196
197 PipeArgs newArgs(args);
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800198 if(PipeBook::getPipeType(dest) == OV_MDP_PIPE_VG) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500199 setMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_SHARE);
200 } else {
201 clearMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_SHARE);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700202 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800203
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800204 if(PipeBook::getPipeType(dest) == OV_MDP_PIPE_DMA) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800205 setMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_FORCE_DMA);
206 } else {
207 clearMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_FORCE_DMA);
208 }
209
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500210 mPipeBook[index].mPipe->setSource(newArgs);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700211}
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700212
Saurabh Shah5daeee52013-01-23 16:52:26 +0800213void Overlay::setVisualParams(const MetaData_t& metadata, utils::eDest dest) {
214 int index = (int)dest;
215 validate(index);
216 mPipeBook[index].mPipe->setVisualParams(metadata);
217}
218
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500219Overlay* Overlay::getInstance() {
220 if(sInstance == NULL) {
221 sInstance = new Overlay();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700222 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500223 return sInstance;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700224}
225
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800226// Clears any VG pipes allocated to the fb devices
227// Generates a LUT for pipe types.
228int Overlay::initOverlay() {
229 int mdpVersion = qdutils::MDPVersion::getInstance().getMDPVersion();
230 int numPipesXType[OV_MDP_PIPE_ANY] = {0};
231 numPipesXType[OV_MDP_PIPE_RGB] =
232 qdutils::MDPVersion::getInstance().getRGBPipes();
233 numPipesXType[OV_MDP_PIPE_VG] =
234 qdutils::MDPVersion::getInstance().getVGPipes();
235 numPipesXType[OV_MDP_PIPE_DMA] =
236 qdutils::MDPVersion::getInstance().getDMAPipes();
237
238 int index = 0;
239 for(int X = 0; X < (int)OV_MDP_PIPE_ANY; X++) { //iterate over types
240 for(int j = 0; j < numPipesXType[X]; j++) { //iterate over num
241 PipeBook::pipeTypeLUT[index] = (utils::eMdpPipeType)X;
242 index++;
243 }
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700244 }
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800245
Xiaoming Zhou5eff8b62013-05-01 20:56:09 -0400246 if (mdpVersion < qdutils::MDSS_V5 && mdpVersion != qdutils::MDP_V3_0_4) {
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800247 msmfb_mixer_info_req req;
248 mdp_mixer_info *minfo = NULL;
249 char name[64];
250 int fd = -1;
251 for(int i = 0; i < NUM_FB_DEVICES; i++) {
252 snprintf(name, 64, FB_DEVICE_TEMPLATE, i);
253 ALOGD("initoverlay:: opening the device:: %s", name);
254 fd = ::open(name, O_RDWR, 0);
255 if(fd < 0) {
256 ALOGE("cannot open framebuffer(%d)", i);
257 return -1;
258 }
259 //Get the mixer configuration */
260 req.mixer_num = i;
261 if (ioctl(fd, MSMFB_MIXER_INFO, &req) == -1) {
262 ALOGE("ERROR: MSMFB_MIXER_INFO ioctl failed");
263 close(fd);
264 return -1;
265 }
266 minfo = req.info;
267 for (int j = 0; j < req.cnt; j++) {
268 ALOGD("ndx=%d num=%d z_order=%d", minfo->pndx, minfo->pnum,
269 minfo->z_order);
270 // except the RGB base layer with z_order of -1, clear any
271 // other pipes connected to mixer.
272 if((minfo->z_order) != -1) {
273 int index = minfo->pndx;
274 ALOGD("Unset overlay with index: %d at mixer %d", index, i);
275 if(ioctl(fd, MSMFB_OVERLAY_UNSET, &index) == -1) {
276 ALOGE("ERROR: MSMFB_OVERLAY_UNSET failed");
277 close(fd);
278 return -1;
279 }
280 }
281 minfo++;
282 }
283 close(fd);
284 fd = -1;
285 }
286 }
287 return 0;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700288}
289
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500290void Overlay::dump() const {
291 if(strlen(mDumpStr)) { //dump only on state change
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800292 ALOGD_IF(PIPE_DEBUG, "%s\n", mDumpStr);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500293 }
294}
295
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800296void Overlay::getDump(char *buf, size_t len) {
297 int totalPipes = 0;
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700298 const char *str = "\nOverlay State\n\n";
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800299 strncat(buf, str, strlen(str));
300 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
301 if(mPipeBook[i].valid()) {
302 mPipeBook[i].mPipe->getDump(buf, len);
303 char str[64] = {'\0'};
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700304 snprintf(str, 64, "Display=%d\n\n", mPipeBook[i].mDisplay);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800305 strncat(buf, str, strlen(str));
306 totalPipes++;
307 }
308 }
309 char str_pipes[64] = {'\0'};
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700310 snprintf(str_pipes, 64, "Pipes=%d\n\n", totalPipes);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800311 strncat(buf, str_pipes, strlen(str_pipes));
312}
313
Sushil Chauhanbd3ea922013-05-15 12:25:26 -0700314void Overlay::clear(int dpy) {
315 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
316 if (mPipeBook[i].mDisplay == dpy) {
317 // Mark as available for this round
318 PipeBook::resetUse(i);
319 PipeBook::resetAllocation(i);
320 }
321 }
322}
323
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500324void Overlay::PipeBook::init() {
325 mPipe = NULL;
326 mDisplay = DPY_UNUSED;
327}
328
329void Overlay::PipeBook::destroy() {
330 if(mPipe) {
331 delete mPipe;
332 mPipe = NULL;
333 }
334 mDisplay = DPY_UNUSED;
335}
336
337Overlay* Overlay::sInstance = 0;
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -0800338int Overlay::sExtFbIndex = 1;
Saurabh Shah85234ec2013-04-12 17:09:00 -0700339int Overlay::sDMAMode = DMA_LINE_MODE;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500340int Overlay::PipeBook::NUM_PIPES = 0;
341int Overlay::PipeBook::sPipeUsageBitmap = 0;
342int Overlay::PipeBook::sLastUsageBitmap = 0;
343int Overlay::PipeBook::sAllocatedBitmap = 0;
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800344utils::eMdpPipeType Overlay::PipeBook::pipeTypeLUT[utils::OV_MAX] =
345 {utils::OV_MDP_PIPE_ANY};
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500346
347}; // namespace overlay