blob: 432ba8165fbda494a75b71604f7f7291f5fb9eb8 [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
Saurabh Shahb8f58e22013-09-26 16:20:07 -070030#include <dlfcn.h>
Naseer Ahmed29a26812012-06-14 00:56:20 -070031#include "overlay.h"
Naseer Ahmed758bfc52012-11-28 17:02:08 -050032#include "pipes/overlayGenPipe.h"
33#include "mdp_version.h"
Saurabh Shah5daeee52013-01-23 16:52:26 +080034#include "qdMetaData.h"
Naseer Ahmed29a26812012-06-14 00:56:20 -070035
Saurabh Shahb8f58e22013-09-26 16:20:07 -070036#ifdef USES_QSEED_SCALAR
37#include <scale/scale.h>
38using namespace scale;
39#endif
40
Naseer Ahmed758bfc52012-11-28 17:02:08 -050041#define PIPE_DEBUG 0
Naseer Ahmed29a26812012-06-14 00:56:20 -070042
43namespace overlay {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050044using namespace utils;
Naseer Ahmed29a26812012-06-14 00:56:20 -070045
Saurabh Shahb8f58e22013-09-26 16:20:07 -070046
Naseer Ahmed758bfc52012-11-28 17:02:08 -050047Overlay::Overlay() {
Sushil Chauhan07a2c762013-03-06 15:36:49 -080048 PipeBook::NUM_PIPES = qdutils::MDPVersion::getInstance().getTotalPipes();
Naseer Ahmed758bfc52012-11-28 17:02:08 -050049 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
50 mPipeBook[i].init();
Naseer Ahmed1ddf3662012-07-31 19:14:18 -070051 }
Naseer Ahmed1ddf3662012-07-31 19:14:18 -070052
Naseer Ahmed758bfc52012-11-28 17:02:08 -050053 mDumpStr[0] = '\0';
Saurabh Shahb8f58e22013-09-26 16:20:07 -070054 initScalar();
Naseer Ahmed29a26812012-06-14 00:56:20 -070055}
56
57Overlay::~Overlay() {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050058 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
59 mPipeBook[i].destroy();
60 }
Saurabh Shahb8f58e22013-09-26 16:20:07 -070061 destroyScalar();
Naseer Ahmed29a26812012-06-14 00:56:20 -070062}
63
Naseer Ahmed758bfc52012-11-28 17:02:08 -050064void Overlay::configBegin() {
65 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
66 //Mark as available for this round.
67 PipeBook::resetUse(i);
68 PipeBook::resetAllocation(i);
69 }
Saurabh Shah784e9852013-08-21 16:51:21 -070070 sForceSetBitmap = 0;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050071 mDumpStr[0] = '\0';
Saurabh Shahb8f58e22013-09-26 16:20:07 -070072
73#ifdef USES_QSEED_SCALAR
74 Scale *scalar = getScalar();
75 if(scalar) {
76 scalar->configBegin();
77 }
78#endif
Naseer Ahmed758bfc52012-11-28 17:02:08 -050079}
80
81void Overlay::configDone() {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050082 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
Zohaib Alam4b0a9242013-11-20 23:54:12 -050083 if((PipeBook::isNotUsed(i) && !sessionInProgress((eDest)i)) ||
84 isSessionEnded((eDest)i)) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050085 //Forces UNSET on pipes, flushes rotator memory and session, closes
86 //fds
87 if(mPipeBook[i].valid()) {
88 char str[32];
Saurabh Shahaf5f5972013-07-30 13:56:35 -070089 sprintf(str, "Unset=%s dpy=%d mix=%d; ",
90 PipeBook::getDestStr((eDest)i),
91 mPipeBook[i].mDisplay, mPipeBook[i].mMixer);
Saurabh Shah9dc88fc2013-07-15 16:02:30 -070092#if PIPE_DEBUG
Naseer Ahmed758bfc52012-11-28 17:02:08 -050093 strncat(mDumpStr, str, strlen(str));
Saurabh Shah9dc88fc2013-07-15 16:02:30 -070094#endif
Naseer Ahmed758bfc52012-11-28 17:02:08 -050095 }
96 mPipeBook[i].destroy();
Naseer Ahmed1ddf3662012-07-31 19:14:18 -070097 }
Naseer Ahmed29a26812012-06-14 00:56:20 -070098 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -050099 dump();
100 PipeBook::save();
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700101
102#ifdef USES_QSEED_SCALAR
103 Scale *scalar = getScalar();
104 if(scalar) {
105 scalar->configDone();
106 }
107#endif
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500108}
109
Zohaib Alam4b0a9242013-11-20 23:54:12 -0500110int Overlay::getPipeId(utils::eDest dest) {
111 return mPipeBook[(int)dest].mPipe->getPipeId();
112}
113
114eDest Overlay::getDest(int pipeid) {
115 eDest dest = OV_INVALID;
116 // finding the dest corresponding to the given pipe
117 for(int i=0; i < PipeBook::NUM_PIPES; ++i) {
118 if(mPipeBook[i].valid() && mPipeBook[i].mPipe->getPipeId() == pipeid) {
119 return (eDest)i;
120 }
121 }
122 return dest;
123}
124
125eDest Overlay::reservePipe(int pipeid) {
126 eDest dest = getDest(pipeid);
127 PipeBook::setAllocation((int)dest);
128 return dest;
129}
130
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700131eDest Overlay::nextPipe(eMdpPipeType type, int dpy, int mixer) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500132 eDest dest = OV_INVALID;
133
134 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700135 if( (type == OV_MDP_PIPE_ANY || //Pipe type match
136 type == PipeBook::getPipeType((eDest)i)) &&
137 (mPipeBook[i].mDisplay == DPY_UNUSED || //Free or same display
138 mPipeBook[i].mDisplay == dpy) &&
139 (mPipeBook[i].mMixer == MIXER_UNUSED || //Free or same mixer
140 mPipeBook[i].mMixer == mixer) &&
141 PipeBook::isNotAllocated(i) && //Free pipe
142 !(sDMAMode == DMA_BLOCK_MODE && //DMA pipe in Line mode
143 PipeBook::getPipeType((eDest)i) == OV_MDP_PIPE_DMA)) {
144 dest = (eDest)i;
145 PipeBook::setAllocation(i);
146 break;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500147 }
148 }
149
150 if(dest != OV_INVALID) {
151 int index = (int)dest;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500152 mPipeBook[index].mDisplay = dpy;
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700153 mPipeBook[index].mMixer = mixer;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500154 if(not mPipeBook[index].valid()) {
155 mPipeBook[index].mPipe = new GenericPipe(dpy);
Zohaib Alam4b0a9242013-11-20 23:54:12 -0500156 mPipeBook[index].mSession = PipeBook::NONE;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500157 char str[32];
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700158 snprintf(str, 32, "Set=%s dpy=%d mix=%d; ",
159 PipeBook::getDestStr(dest), dpy, mixer);
Saurabh Shah9dc88fc2013-07-15 16:02:30 -0700160#if PIPE_DEBUG
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500161 strncat(mDumpStr, str, strlen(str));
Saurabh Shah9dc88fc2013-07-15 16:02:30 -0700162#endif
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500163 }
164 } else {
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700165 ALOGD_IF(PIPE_DEBUG, "Pipe unavailable type=%d display=%d mixer=%d",
166 (int)type, dpy, mixer);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500167 }
168
169 return dest;
170}
171
Zohaib Alam4b0a9242013-11-20 23:54:12 -0500172void Overlay::endAllSessions() {
173 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
174 if(mPipeBook[i].valid() && mPipeBook[i].mSession==PipeBook::START)
175 mPipeBook[i].mSession = PipeBook::END;
176 }
177}
178
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700179bool Overlay::isPipeTypeAttached(eMdpPipeType type) {
180 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
181 if(type == PipeBook::getPipeType((eDest)i) &&
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700182 mPipeBook[i].mDisplay != DPY_UNUSED) {
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700183 return true;
184 }
185 }
186 return false;
187}
188
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500189bool Overlay::commit(utils::eDest dest) {
190 bool ret = false;
191 int index = (int)dest;
192 validate(index);
193
194 if(mPipeBook[index].mPipe->commit()) {
195 ret = true;
196 PipeBook::setUse((int)dest);
Saurabh Shah784e9852013-08-21 16:51:21 -0700197 if(sForceSetBitmap & (1 << mPipeBook[index].mDisplay)) {
198 mPipeBook[index].mPipe->forceSet();
199 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500200 } else {
Sushil Chauhane0dff932013-03-01 14:33:18 -0800201 int dpy = mPipeBook[index].mDisplay;
202 for(int i = 0; i < PipeBook::NUM_PIPES; i++)
Saurabh Shahdf0be752013-05-23 14:40:00 -0700203 if (mPipeBook[i].mDisplay == dpy) {
Sushil Chauhane0dff932013-03-01 14:33:18 -0800204 PipeBook::resetAllocation(i);
Saurabh Shahdf0be752013-05-23 14:40:00 -0700205 PipeBook::resetUse(i);
206 if(mPipeBook[i].valid()) {
207 mPipeBook[i].mPipe->forceSet();
208 }
209 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500210 }
211 return ret;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700212}
213
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700214bool Overlay::queueBuffer(int fd, uint32_t offset,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500215 utils::eDest dest) {
216 int index = (int)dest;
217 bool ret = false;
218 validate(index);
219 //Queue only if commit() has succeeded (and the bit set)
220 if(PipeBook::isUsed((int)dest)) {
221 ret = mPipeBook[index].mPipe->queueBuffer(fd, offset);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700222 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500223 return ret;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700224}
225
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500226void Overlay::setCrop(const utils::Dim& d,
227 utils::eDest dest) {
228 int index = (int)dest;
229 validate(index);
230 mPipeBook[index].mPipe->setCrop(d);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700231}
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700232
Sushil Chauhan897a9c32013-07-18 11:09:55 -0700233void Overlay::setColor(const uint32_t color,
234 utils::eDest dest) {
235 int index = (int)dest;
236 validate(index);
237 mPipeBook[index].mPipe->setColor(color);
238}
239
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500240void Overlay::setPosition(const utils::Dim& d,
241 utils::eDest dest) {
242 int index = (int)dest;
243 validate(index);
244 mPipeBook[index].mPipe->setPosition(d);
245}
246
247void Overlay::setTransform(const int orient,
248 utils::eDest dest) {
249 int index = (int)dest;
250 validate(index);
251
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700252 utils::eTransform transform =
253 static_cast<utils::eTransform>(orient);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500254 mPipeBook[index].mPipe->setTransform(transform);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700255
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500256}
257
258void Overlay::setSource(const utils::PipeArgs args,
259 utils::eDest dest) {
260 int index = (int)dest;
261 validate(index);
262
263 PipeArgs newArgs(args);
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800264 if(PipeBook::getPipeType(dest) == OV_MDP_PIPE_VG) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500265 setMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_SHARE);
266 } else {
267 clearMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_SHARE);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700268 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800269
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800270 if(PipeBook::getPipeType(dest) == OV_MDP_PIPE_DMA) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800271 setMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_FORCE_DMA);
272 } else {
273 clearMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_FORCE_DMA);
274 }
275
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500276 mPipeBook[index].mPipe->setSource(newArgs);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700277}
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700278
Saurabh Shah5daeee52013-01-23 16:52:26 +0800279void Overlay::setVisualParams(const MetaData_t& metadata, utils::eDest dest) {
280 int index = (int)dest;
281 validate(index);
282 mPipeBook[index].mPipe->setVisualParams(metadata);
283}
284
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500285Overlay* Overlay::getInstance() {
286 if(sInstance == NULL) {
287 sInstance = new Overlay();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700288 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500289 return sInstance;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700290}
291
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800292// Clears any VG pipes allocated to the fb devices
293// Generates a LUT for pipe types.
294int Overlay::initOverlay() {
295 int mdpVersion = qdutils::MDPVersion::getInstance().getMDPVersion();
296 int numPipesXType[OV_MDP_PIPE_ANY] = {0};
297 numPipesXType[OV_MDP_PIPE_RGB] =
298 qdutils::MDPVersion::getInstance().getRGBPipes();
299 numPipesXType[OV_MDP_PIPE_VG] =
300 qdutils::MDPVersion::getInstance().getVGPipes();
301 numPipesXType[OV_MDP_PIPE_DMA] =
302 qdutils::MDPVersion::getInstance().getDMAPipes();
303
304 int index = 0;
305 for(int X = 0; X < (int)OV_MDP_PIPE_ANY; X++) { //iterate over types
306 for(int j = 0; j < numPipesXType[X]; j++) { //iterate over num
307 PipeBook::pipeTypeLUT[index] = (utils::eMdpPipeType)X;
308 index++;
309 }
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700310 }
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800311
Xiaoming Zhou5eff8b62013-05-01 20:56:09 -0400312 if (mdpVersion < qdutils::MDSS_V5 && mdpVersion != qdutils::MDP_V3_0_4) {
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800313 msmfb_mixer_info_req req;
314 mdp_mixer_info *minfo = NULL;
315 char name[64];
316 int fd = -1;
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700317 for(int i = 0; i < MAX_FB_DEVICES; i++) {
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800318 snprintf(name, 64, FB_DEVICE_TEMPLATE, i);
319 ALOGD("initoverlay:: opening the device:: %s", name);
320 fd = ::open(name, O_RDWR, 0);
321 if(fd < 0) {
322 ALOGE("cannot open framebuffer(%d)", i);
323 return -1;
324 }
325 //Get the mixer configuration */
326 req.mixer_num = i;
327 if (ioctl(fd, MSMFB_MIXER_INFO, &req) == -1) {
328 ALOGE("ERROR: MSMFB_MIXER_INFO ioctl failed");
329 close(fd);
330 return -1;
331 }
332 minfo = req.info;
333 for (int j = 0; j < req.cnt; j++) {
334 ALOGD("ndx=%d num=%d z_order=%d", minfo->pndx, minfo->pnum,
335 minfo->z_order);
336 // except the RGB base layer with z_order of -1, clear any
337 // other pipes connected to mixer.
338 if((minfo->z_order) != -1) {
339 int index = minfo->pndx;
340 ALOGD("Unset overlay with index: %d at mixer %d", index, i);
341 if(ioctl(fd, MSMFB_OVERLAY_UNSET, &index) == -1) {
342 ALOGE("ERROR: MSMFB_OVERLAY_UNSET failed");
343 close(fd);
344 return -1;
345 }
346 }
347 minfo++;
348 }
349 close(fd);
350 fd = -1;
351 }
352 }
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700353
354 FILE *displayDeviceFP = NULL;
355 const int MAX_FRAME_BUFFER_NAME_SIZE = 128;
356 char fbType[MAX_FRAME_BUFFER_NAME_SIZE];
357 char msmFbTypePath[MAX_FRAME_BUFFER_NAME_SIZE];
358 const char *strDtvPanel = "dtv panel";
359 const char *strWbPanel = "writeback panel";
360
361 for(int num = 1; num < MAX_FB_DEVICES; num++) {
362 snprintf (msmFbTypePath, sizeof(msmFbTypePath),
363 "/sys/class/graphics/fb%d/msm_fb_type", num);
364 displayDeviceFP = fopen(msmFbTypePath, "r");
365
366 if(displayDeviceFP){
367 fread(fbType, sizeof(char), MAX_FRAME_BUFFER_NAME_SIZE,
368 displayDeviceFP);
369
370 if(strncmp(fbType, strDtvPanel, strlen(strDtvPanel)) == 0) {
371 sDpyFbMap[DPY_EXTERNAL] = num;
372 } else if(strncmp(fbType, strWbPanel, strlen(strWbPanel)) == 0) {
373 sDpyFbMap[DPY_WRITEBACK] = num;
374 }
375
376 fclose(displayDeviceFP);
377 }
378 }
379
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800380 return 0;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700381}
382
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700383bool Overlay::displayCommit(const int& fd) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700384 utils::Dim roi;
385 return displayCommit(fd, roi);
386}
387
388bool Overlay::displayCommit(const int& fd, const utils::Dim& roi) {
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700389 //Commit
390 struct mdp_display_commit info;
391 memset(&info, 0, sizeof(struct mdp_display_commit));
392 info.flags = MDP_DISPLAY_COMMIT_OVERLAY;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700393 info.roi.x = roi.x;
394 info.roi.y = roi.y;
395 info.roi.w = roi.w;
396 info.roi.h = roi.h;
397
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700398 if(!mdp_wrapper::displayCommit(fd, info)) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700399 ALOGE("%s: commit failed", __func__);
400 return false;
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700401 }
402 return true;
403}
404
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500405void Overlay::dump() const {
Saurabh Shah9dc88fc2013-07-15 16:02:30 -0700406#if PIPE_DEBUG
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500407 if(strlen(mDumpStr)) { //dump only on state change
Saurabh Shah9dc88fc2013-07-15 16:02:30 -0700408 ALOGD("%s\n", mDumpStr);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500409 }
Saurabh Shah9dc88fc2013-07-15 16:02:30 -0700410#endif
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500411}
412
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800413void Overlay::getDump(char *buf, size_t len) {
414 int totalPipes = 0;
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700415 const char *str = "\nOverlay State\n\n";
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800416 strncat(buf, str, strlen(str));
417 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
418 if(mPipeBook[i].valid()) {
419 mPipeBook[i].mPipe->getDump(buf, len);
420 char str[64] = {'\0'};
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700421 snprintf(str, 64, "Display=%d\n\n", mPipeBook[i].mDisplay);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800422 strncat(buf, str, strlen(str));
423 totalPipes++;
424 }
425 }
426 char str_pipes[64] = {'\0'};
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700427 snprintf(str_pipes, 64, "Pipes=%d\n\n", totalPipes);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800428 strncat(buf, str_pipes, strlen(str_pipes));
429}
430
Sushil Chauhanbd3ea922013-05-15 12:25:26 -0700431void Overlay::clear(int dpy) {
432 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
433 if (mPipeBook[i].mDisplay == dpy) {
434 // Mark as available for this round
435 PipeBook::resetUse(i);
436 PipeBook::resetAllocation(i);
Saurabh Shahdf0be752013-05-23 14:40:00 -0700437 if(mPipeBook[i].valid()) {
438 mPipeBook[i].mPipe->forceSet();
439 }
Sushil Chauhanbd3ea922013-05-15 12:25:26 -0700440 }
441 }
442}
443
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700444void Overlay::initScalar() {
445#ifdef USES_QSEED_SCALAR
446 if(sLibScaleHandle == NULL) {
447 sLibScaleHandle = dlopen("libscale.so", RTLD_NOW);
448 }
449
450 if(sLibScaleHandle) {
451 if(sScale == NULL) {
452 Scale* (*getInstance)();
453 *(void **) &getInstance = dlsym(sLibScaleHandle, "getInstance");
454 if(getInstance) {
455 sScale = getInstance();
456 }
457 }
458 }
459#endif
460}
461
462void Overlay::destroyScalar() {
463#ifdef USES_QSEED_SCALAR
464 if(sLibScaleHandle) {
465 if(sScale) {
466 void (*destroyInstance)(Scale*);
467 *(void **) &destroyInstance = dlsym(sLibScaleHandle,
468 "destroyInstance");
469 if(destroyInstance) {
470 destroyInstance(sScale);
471 sScale = NULL;
472 }
473 }
474 dlclose(sLibScaleHandle);
475 sLibScaleHandle = NULL;
476 }
477#endif
478}
479
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500480void Overlay::PipeBook::init() {
481 mPipe = NULL;
482 mDisplay = DPY_UNUSED;
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700483 mMixer = MIXER_UNUSED;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500484}
485
486void Overlay::PipeBook::destroy() {
487 if(mPipe) {
488 delete mPipe;
489 mPipe = NULL;
490 }
491 mDisplay = DPY_UNUSED;
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700492 mMixer = MIXER_UNUSED;
Zohaib Alam4b0a9242013-11-20 23:54:12 -0500493 mSession = NONE;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500494}
495
496Overlay* Overlay::sInstance = 0;
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700497int Overlay::sDpyFbMap[DPY_MAX] = {0, -1, -1};
Saurabh Shah85234ec2013-04-12 17:09:00 -0700498int Overlay::sDMAMode = DMA_LINE_MODE;
Saurabh Shah784e9852013-08-21 16:51:21 -0700499int Overlay::sForceSetBitmap = 0;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500500int Overlay::PipeBook::NUM_PIPES = 0;
501int Overlay::PipeBook::sPipeUsageBitmap = 0;
502int Overlay::PipeBook::sLastUsageBitmap = 0;
503int Overlay::PipeBook::sAllocatedBitmap = 0;
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800504utils::eMdpPipeType Overlay::PipeBook::pipeTypeLUT[utils::OV_MAX] =
505 {utils::OV_MDP_PIPE_ANY};
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700506void *Overlay::sLibScaleHandle = NULL;
507scale::Scale *Overlay::sScale = NULL;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500508
509}; // namespace overlay