blob: 3836f9e9d578f1e2ad68b4dda489d92426c2470c [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];
Saurabh Shah9dc88fc2013-07-15 16:02:30 -070073 sprintf(str, "Unset=%s dpy=%d; ",
Sushil Chauhan07a2c762013-03-06 15:36:49 -080074 PipeBook::getDestStr((eDest)i), mPipeBook[i].mDisplay);
Saurabh Shah9dc88fc2013-07-15 16:02:30 -070075#if PIPE_DEBUG
Naseer Ahmed758bfc52012-11-28 17:02:08 -050076 strncat(mDumpStr, str, strlen(str));
Saurabh Shah9dc88fc2013-07-15 16:02:30 -070077#endif
Naseer Ahmed758bfc52012-11-28 17:02:08 -050078 }
79 mPipeBook[i].destroy();
Naseer Ahmed1ddf3662012-07-31 19:14:18 -070080 }
Naseer Ahmed29a26812012-06-14 00:56:20 -070081 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -050082 dump();
83 PipeBook::save();
84}
85
86eDest Overlay::nextPipe(eMdpPipeType type, int dpy) {
87 eDest dest = OV_INVALID;
88
89 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
90 //Match requested pipe type
Sushil Chauhan07a2c762013-03-06 15:36:49 -080091 if(type == OV_MDP_PIPE_ANY || type == PipeBook::getPipeType((eDest)i)) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050092 //If the pipe is not allocated to any display or used by the
93 //requesting display already in previous round.
94 if((mPipeBook[i].mDisplay == PipeBook::DPY_UNUSED ||
95 mPipeBook[i].mDisplay == dpy) &&
96 PipeBook::isNotAllocated(i)) {
Saurabh Shah85234ec2013-04-12 17:09:00 -070097 //In block mode we don't allow line operations
98 if(sDMAMode == DMA_BLOCK_MODE &&
99 PipeBook::getPipeType((eDest)i) == OV_MDP_PIPE_DMA)
100 continue;
101
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500102 dest = (eDest)i;
103 PipeBook::setAllocation(i);
104 break;
105 }
106 }
107 }
108
109 if(dest != OV_INVALID) {
110 int index = (int)dest;
111 //If the pipe is not registered with any display OR if the pipe is
112 //requested again by the same display using it, then go ahead.
113 mPipeBook[index].mDisplay = dpy;
114 if(not mPipeBook[index].valid()) {
115 mPipeBook[index].mPipe = new GenericPipe(dpy);
116 char str[32];
Saurabh Shah9dc88fc2013-07-15 16:02:30 -0700117 snprintf(str, 32, "Set=%s dpy=%d; ",
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800118 PipeBook::getDestStr(dest), dpy);
Saurabh Shah9dc88fc2013-07-15 16:02:30 -0700119#if PIPE_DEBUG
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500120 strncat(mDumpStr, str, strlen(str));
Saurabh Shah9dc88fc2013-07-15 16:02:30 -0700121#endif
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500122 }
123 } else {
124 ALOGD_IF(PIPE_DEBUG, "Pipe unavailable type=%d display=%d",
125 (int)type, dpy);
126 }
127
128 return dest;
129}
130
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700131bool Overlay::isPipeTypeAttached(eMdpPipeType type) {
132 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
133 if(type == PipeBook::getPipeType((eDest)i) &&
134 mPipeBook[i].mDisplay != PipeBook::DPY_UNUSED) {
135 return true;
136 }
137 }
138 return false;
139}
140
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500141bool Overlay::commit(utils::eDest dest) {
142 bool ret = false;
143 int index = (int)dest;
144 validate(index);
145
146 if(mPipeBook[index].mPipe->commit()) {
147 ret = true;
148 PipeBook::setUse((int)dest);
149 } else {
Sushil Chauhane0dff932013-03-01 14:33:18 -0800150 int dpy = mPipeBook[index].mDisplay;
151 for(int i = 0; i < PipeBook::NUM_PIPES; i++)
Saurabh Shahdf0be752013-05-23 14:40:00 -0700152 if (mPipeBook[i].mDisplay == dpy) {
Sushil Chauhane0dff932013-03-01 14:33:18 -0800153 PipeBook::resetAllocation(i);
Saurabh Shahdf0be752013-05-23 14:40:00 -0700154 PipeBook::resetUse(i);
155 if(mPipeBook[i].valid()) {
156 mPipeBook[i].mPipe->forceSet();
157 }
158 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500159 }
160 return ret;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700161}
162
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700163bool Overlay::queueBuffer(int fd, uint32_t offset,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500164 utils::eDest dest) {
165 int index = (int)dest;
166 bool ret = false;
167 validate(index);
168 //Queue only if commit() has succeeded (and the bit set)
169 if(PipeBook::isUsed((int)dest)) {
170 ret = mPipeBook[index].mPipe->queueBuffer(fd, offset);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700171 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500172 return ret;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700173}
174
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500175void Overlay::setCrop(const utils::Dim& d,
176 utils::eDest dest) {
177 int index = (int)dest;
178 validate(index);
179 mPipeBook[index].mPipe->setCrop(d);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700180}
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700181
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500182void Overlay::setPosition(const utils::Dim& d,
183 utils::eDest dest) {
184 int index = (int)dest;
185 validate(index);
186 mPipeBook[index].mPipe->setPosition(d);
187}
188
189void Overlay::setTransform(const int orient,
190 utils::eDest dest) {
191 int index = (int)dest;
192 validate(index);
193
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700194 utils::eTransform transform =
195 static_cast<utils::eTransform>(orient);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500196 mPipeBook[index].mPipe->setTransform(transform);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700197
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500198}
199
200void Overlay::setSource(const utils::PipeArgs args,
201 utils::eDest dest) {
202 int index = (int)dest;
203 validate(index);
204
205 PipeArgs newArgs(args);
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800206 if(PipeBook::getPipeType(dest) == OV_MDP_PIPE_VG) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500207 setMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_SHARE);
208 } else {
209 clearMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_SHARE);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700210 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800211
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800212 if(PipeBook::getPipeType(dest) == OV_MDP_PIPE_DMA) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800213 setMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_FORCE_DMA);
214 } else {
215 clearMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_FORCE_DMA);
216 }
217
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500218 mPipeBook[index].mPipe->setSource(newArgs);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700219}
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700220
Saurabh Shah5daeee52013-01-23 16:52:26 +0800221void Overlay::setVisualParams(const MetaData_t& metadata, utils::eDest dest) {
222 int index = (int)dest;
223 validate(index);
224 mPipeBook[index].mPipe->setVisualParams(metadata);
225}
226
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500227Overlay* Overlay::getInstance() {
228 if(sInstance == NULL) {
229 sInstance = new Overlay();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700230 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500231 return sInstance;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700232}
233
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800234// Clears any VG pipes allocated to the fb devices
235// Generates a LUT for pipe types.
236int Overlay::initOverlay() {
237 int mdpVersion = qdutils::MDPVersion::getInstance().getMDPVersion();
238 int numPipesXType[OV_MDP_PIPE_ANY] = {0};
239 numPipesXType[OV_MDP_PIPE_RGB] =
240 qdutils::MDPVersion::getInstance().getRGBPipes();
241 numPipesXType[OV_MDP_PIPE_VG] =
242 qdutils::MDPVersion::getInstance().getVGPipes();
243 numPipesXType[OV_MDP_PIPE_DMA] =
244 qdutils::MDPVersion::getInstance().getDMAPipes();
245
246 int index = 0;
247 for(int X = 0; X < (int)OV_MDP_PIPE_ANY; X++) { //iterate over types
248 for(int j = 0; j < numPipesXType[X]; j++) { //iterate over num
249 PipeBook::pipeTypeLUT[index] = (utils::eMdpPipeType)X;
250 index++;
251 }
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700252 }
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800253
Xiaoming Zhou5eff8b62013-05-01 20:56:09 -0400254 if (mdpVersion < qdutils::MDSS_V5 && mdpVersion != qdutils::MDP_V3_0_4) {
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800255 msmfb_mixer_info_req req;
256 mdp_mixer_info *minfo = NULL;
257 char name[64];
258 int fd = -1;
259 for(int i = 0; i < NUM_FB_DEVICES; i++) {
260 snprintf(name, 64, FB_DEVICE_TEMPLATE, i);
261 ALOGD("initoverlay:: opening the device:: %s", name);
262 fd = ::open(name, O_RDWR, 0);
263 if(fd < 0) {
264 ALOGE("cannot open framebuffer(%d)", i);
265 return -1;
266 }
267 //Get the mixer configuration */
268 req.mixer_num = i;
269 if (ioctl(fd, MSMFB_MIXER_INFO, &req) == -1) {
270 ALOGE("ERROR: MSMFB_MIXER_INFO ioctl failed");
271 close(fd);
272 return -1;
273 }
274 minfo = req.info;
275 for (int j = 0; j < req.cnt; j++) {
276 ALOGD("ndx=%d num=%d z_order=%d", minfo->pndx, minfo->pnum,
277 minfo->z_order);
278 // except the RGB base layer with z_order of -1, clear any
279 // other pipes connected to mixer.
280 if((minfo->z_order) != -1) {
281 int index = minfo->pndx;
282 ALOGD("Unset overlay with index: %d at mixer %d", index, i);
283 if(ioctl(fd, MSMFB_OVERLAY_UNSET, &index) == -1) {
284 ALOGE("ERROR: MSMFB_OVERLAY_UNSET failed");
285 close(fd);
286 return -1;
287 }
288 }
289 minfo++;
290 }
291 close(fd);
292 fd = -1;
293 }
294 }
295 return 0;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700296}
297
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500298void Overlay::dump() const {
Saurabh Shah9dc88fc2013-07-15 16:02:30 -0700299#if PIPE_DEBUG
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500300 if(strlen(mDumpStr)) { //dump only on state change
Saurabh Shah9dc88fc2013-07-15 16:02:30 -0700301 ALOGD("%s\n", mDumpStr);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500302 }
Saurabh Shah9dc88fc2013-07-15 16:02:30 -0700303#endif
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500304}
305
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800306void Overlay::getDump(char *buf, size_t len) {
307 int totalPipes = 0;
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700308 const char *str = "\nOverlay State\n\n";
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800309 strncat(buf, str, strlen(str));
310 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
311 if(mPipeBook[i].valid()) {
312 mPipeBook[i].mPipe->getDump(buf, len);
313 char str[64] = {'\0'};
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700314 snprintf(str, 64, "Display=%d\n\n", mPipeBook[i].mDisplay);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800315 strncat(buf, str, strlen(str));
316 totalPipes++;
317 }
318 }
319 char str_pipes[64] = {'\0'};
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700320 snprintf(str_pipes, 64, "Pipes=%d\n\n", totalPipes);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800321 strncat(buf, str_pipes, strlen(str_pipes));
322}
323
Sushil Chauhanbd3ea922013-05-15 12:25:26 -0700324void Overlay::clear(int dpy) {
325 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
326 if (mPipeBook[i].mDisplay == dpy) {
327 // Mark as available for this round
328 PipeBook::resetUse(i);
329 PipeBook::resetAllocation(i);
Saurabh Shahdf0be752013-05-23 14:40:00 -0700330 if(mPipeBook[i].valid()) {
331 mPipeBook[i].mPipe->forceSet();
332 }
Sushil Chauhanbd3ea922013-05-15 12:25:26 -0700333 }
334 }
335}
336
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500337void Overlay::PipeBook::init() {
338 mPipe = NULL;
339 mDisplay = DPY_UNUSED;
340}
341
342void Overlay::PipeBook::destroy() {
343 if(mPipe) {
344 delete mPipe;
345 mPipe = NULL;
346 }
347 mDisplay = DPY_UNUSED;
348}
349
350Overlay* Overlay::sInstance = 0;
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -0800351int Overlay::sExtFbIndex = 1;
Saurabh Shah85234ec2013-04-12 17:09:00 -0700352int Overlay::sDMAMode = DMA_LINE_MODE;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500353int Overlay::PipeBook::NUM_PIPES = 0;
354int Overlay::PipeBook::sPipeUsageBitmap = 0;
355int Overlay::PipeBook::sLastUsageBitmap = 0;
356int Overlay::PipeBook::sAllocatedBitmap = 0;
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800357utils::eMdpPipeType Overlay::PipeBook::pipeTypeLUT[utils::OV_MAX] =
358 {utils::OV_MDP_PIPE_ANY};
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500359
360}; // namespace overlay