blob: ad23e848f396c2c5c0530ef1d54465f025493b0a [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();
Raj Kamala8c065f2013-10-22 14:52:45 +053055 setDMAMultiplexingSupported();
Naseer Ahmed29a26812012-06-14 00:56:20 -070056}
57
58Overlay::~Overlay() {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050059 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
60 mPipeBook[i].destroy();
61 }
Saurabh Shahb8f58e22013-09-26 16:20:07 -070062 destroyScalar();
Naseer Ahmed29a26812012-06-14 00:56:20 -070063}
64
Naseer Ahmed758bfc52012-11-28 17:02:08 -050065void Overlay::configBegin() {
66 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
67 //Mark as available for this round.
68 PipeBook::resetUse(i);
69 PipeBook::resetAllocation(i);
70 }
71 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
Raj Kamala8c065f2013-10-22 14:52:45 +0530142 ( (sDMAMultiplexingSupported && dpy) ||
143 !(sDMAMode == DMA_BLOCK_MODE && //DMA pipe in Line mode
144 PipeBook::getPipeType((eDest)i) == OV_MDP_PIPE_DMA)) ){
145 //DMA-Multiplexing is only supported for WB on 8x26
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700146 dest = (eDest)i;
147 PipeBook::setAllocation(i);
148 break;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500149 }
150 }
151
152 if(dest != OV_INVALID) {
153 int index = (int)dest;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500154 mPipeBook[index].mDisplay = dpy;
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700155 mPipeBook[index].mMixer = mixer;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500156 if(not mPipeBook[index].valid()) {
157 mPipeBook[index].mPipe = new GenericPipe(dpy);
Zohaib Alam4b0a9242013-11-20 23:54:12 -0500158 mPipeBook[index].mSession = PipeBook::NONE;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500159 char str[32];
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700160 snprintf(str, 32, "Set=%s dpy=%d mix=%d; ",
161 PipeBook::getDestStr(dest), dpy, mixer);
Saurabh Shah9dc88fc2013-07-15 16:02:30 -0700162#if PIPE_DEBUG
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500163 strncat(mDumpStr, str, strlen(str));
Saurabh Shah9dc88fc2013-07-15 16:02:30 -0700164#endif
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500165 }
166 } else {
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700167 ALOGD_IF(PIPE_DEBUG, "Pipe unavailable type=%d display=%d mixer=%d",
168 (int)type, dpy, mixer);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500169 }
170
171 return dest;
172}
173
Zohaib Alam4b0a9242013-11-20 23:54:12 -0500174void Overlay::endAllSessions() {
175 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
176 if(mPipeBook[i].valid() && mPipeBook[i].mSession==PipeBook::START)
177 mPipeBook[i].mSession = PipeBook::END;
178 }
179}
180
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700181bool Overlay::isPipeTypeAttached(eMdpPipeType type) {
182 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
183 if(type == PipeBook::getPipeType((eDest)i) &&
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700184 mPipeBook[i].mDisplay != DPY_UNUSED) {
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700185 return true;
186 }
187 }
188 return false;
189}
190
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500191bool Overlay::commit(utils::eDest dest) {
192 bool ret = false;
193 int index = (int)dest;
194 validate(index);
195
196 if(mPipeBook[index].mPipe->commit()) {
197 ret = true;
198 PipeBook::setUse((int)dest);
199 } else {
Sushil Chauhane0dff932013-03-01 14:33:18 -0800200 int dpy = mPipeBook[index].mDisplay;
Saurabh Shah7445d4b2013-12-05 17:24:45 -0800201 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
Saurabh Shahdf0be752013-05-23 14:40:00 -0700202 if (mPipeBook[i].mDisplay == dpy) {
Sushil Chauhane0dff932013-03-01 14:33:18 -0800203 PipeBook::resetAllocation(i);
Saurabh Shahdf0be752013-05-23 14:40:00 -0700204 PipeBook::resetUse(i);
Saurabh Shahdf0be752013-05-23 14:40:00 -0700205 }
Saurabh Shah7445d4b2013-12-05 17:24:45 -0800206 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500207 }
208 return ret;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700209}
210
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700211bool Overlay::queueBuffer(int fd, uint32_t offset,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500212 utils::eDest dest) {
213 int index = (int)dest;
214 bool ret = false;
215 validate(index);
216 //Queue only if commit() has succeeded (and the bit set)
217 if(PipeBook::isUsed((int)dest)) {
218 ret = mPipeBook[index].mPipe->queueBuffer(fd, offset);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700219 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500220 return ret;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700221}
222
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500223void Overlay::setCrop(const utils::Dim& d,
224 utils::eDest dest) {
225 int index = (int)dest;
226 validate(index);
227 mPipeBook[index].mPipe->setCrop(d);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700228}
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700229
Sushil Chauhan897a9c32013-07-18 11:09:55 -0700230void Overlay::setColor(const uint32_t color,
231 utils::eDest dest) {
232 int index = (int)dest;
233 validate(index);
234 mPipeBook[index].mPipe->setColor(color);
235}
236
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500237void Overlay::setPosition(const utils::Dim& d,
238 utils::eDest dest) {
239 int index = (int)dest;
240 validate(index);
241 mPipeBook[index].mPipe->setPosition(d);
242}
243
244void Overlay::setTransform(const int orient,
245 utils::eDest dest) {
246 int index = (int)dest;
247 validate(index);
248
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700249 utils::eTransform transform =
250 static_cast<utils::eTransform>(orient);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500251 mPipeBook[index].mPipe->setTransform(transform);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700252
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500253}
254
255void Overlay::setSource(const utils::PipeArgs args,
256 utils::eDest dest) {
257 int index = (int)dest;
258 validate(index);
259
260 PipeArgs newArgs(args);
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800261 if(PipeBook::getPipeType(dest) == OV_MDP_PIPE_VG) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500262 setMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_SHARE);
263 } else {
264 clearMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_SHARE);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700265 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800266
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800267 if(PipeBook::getPipeType(dest) == OV_MDP_PIPE_DMA) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800268 setMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_FORCE_DMA);
269 } else {
270 clearMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_FORCE_DMA);
271 }
272
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500273 mPipeBook[index].mPipe->setSource(newArgs);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700274}
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700275
Saurabh Shah5daeee52013-01-23 16:52:26 +0800276void Overlay::setVisualParams(const MetaData_t& metadata, utils::eDest dest) {
277 int index = (int)dest;
278 validate(index);
279 mPipeBook[index].mPipe->setVisualParams(metadata);
280}
281
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500282Overlay* Overlay::getInstance() {
283 if(sInstance == NULL) {
284 sInstance = new Overlay();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700285 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500286 return sInstance;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700287}
288
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800289// Clears any VG pipes allocated to the fb devices
290// Generates a LUT for pipe types.
291int Overlay::initOverlay() {
292 int mdpVersion = qdutils::MDPVersion::getInstance().getMDPVersion();
293 int numPipesXType[OV_MDP_PIPE_ANY] = {0};
294 numPipesXType[OV_MDP_PIPE_RGB] =
295 qdutils::MDPVersion::getInstance().getRGBPipes();
296 numPipesXType[OV_MDP_PIPE_VG] =
297 qdutils::MDPVersion::getInstance().getVGPipes();
298 numPipesXType[OV_MDP_PIPE_DMA] =
299 qdutils::MDPVersion::getInstance().getDMAPipes();
300
301 int index = 0;
302 for(int X = 0; X < (int)OV_MDP_PIPE_ANY; X++) { //iterate over types
303 for(int j = 0; j < numPipesXType[X]; j++) { //iterate over num
304 PipeBook::pipeTypeLUT[index] = (utils::eMdpPipeType)X;
305 index++;
306 }
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700307 }
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800308
Xiaoming Zhou5eff8b62013-05-01 20:56:09 -0400309 if (mdpVersion < qdutils::MDSS_V5 && mdpVersion != qdutils::MDP_V3_0_4) {
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800310 msmfb_mixer_info_req req;
311 mdp_mixer_info *minfo = NULL;
312 char name[64];
313 int fd = -1;
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700314 for(int i = 0; i < MAX_FB_DEVICES; i++) {
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800315 snprintf(name, 64, FB_DEVICE_TEMPLATE, i);
316 ALOGD("initoverlay:: opening the device:: %s", name);
317 fd = ::open(name, O_RDWR, 0);
318 if(fd < 0) {
319 ALOGE("cannot open framebuffer(%d)", i);
320 return -1;
321 }
322 //Get the mixer configuration */
323 req.mixer_num = i;
324 if (ioctl(fd, MSMFB_MIXER_INFO, &req) == -1) {
325 ALOGE("ERROR: MSMFB_MIXER_INFO ioctl failed");
326 close(fd);
327 return -1;
328 }
329 minfo = req.info;
330 for (int j = 0; j < req.cnt; j++) {
331 ALOGD("ndx=%d num=%d z_order=%d", minfo->pndx, minfo->pnum,
332 minfo->z_order);
333 // except the RGB base layer with z_order of -1, clear any
334 // other pipes connected to mixer.
335 if((minfo->z_order) != -1) {
336 int index = minfo->pndx;
337 ALOGD("Unset overlay with index: %d at mixer %d", index, i);
338 if(ioctl(fd, MSMFB_OVERLAY_UNSET, &index) == -1) {
339 ALOGE("ERROR: MSMFB_OVERLAY_UNSET failed");
340 close(fd);
341 return -1;
342 }
343 }
344 minfo++;
345 }
346 close(fd);
347 fd = -1;
348 }
349 }
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700350
351 FILE *displayDeviceFP = NULL;
352 const int MAX_FRAME_BUFFER_NAME_SIZE = 128;
353 char fbType[MAX_FRAME_BUFFER_NAME_SIZE];
354 char msmFbTypePath[MAX_FRAME_BUFFER_NAME_SIZE];
355 const char *strDtvPanel = "dtv panel";
356 const char *strWbPanel = "writeback panel";
357
358 for(int num = 1; num < MAX_FB_DEVICES; num++) {
359 snprintf (msmFbTypePath, sizeof(msmFbTypePath),
360 "/sys/class/graphics/fb%d/msm_fb_type", num);
361 displayDeviceFP = fopen(msmFbTypePath, "r");
362
363 if(displayDeviceFP){
364 fread(fbType, sizeof(char), MAX_FRAME_BUFFER_NAME_SIZE,
365 displayDeviceFP);
366
367 if(strncmp(fbType, strDtvPanel, strlen(strDtvPanel)) == 0) {
368 sDpyFbMap[DPY_EXTERNAL] = num;
369 } else if(strncmp(fbType, strWbPanel, strlen(strWbPanel)) == 0) {
370 sDpyFbMap[DPY_WRITEBACK] = num;
371 }
372
373 fclose(displayDeviceFP);
374 }
375 }
376
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800377 return 0;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700378}
379
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700380bool Overlay::displayCommit(const int& fd) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700381 utils::Dim roi;
382 return displayCommit(fd, roi);
383}
384
385bool Overlay::displayCommit(const int& fd, const utils::Dim& roi) {
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700386 //Commit
387 struct mdp_display_commit info;
388 memset(&info, 0, sizeof(struct mdp_display_commit));
389 info.flags = MDP_DISPLAY_COMMIT_OVERLAY;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700390 info.roi.x = roi.x;
391 info.roi.y = roi.y;
392 info.roi.w = roi.w;
393 info.roi.h = roi.h;
394
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700395 if(!mdp_wrapper::displayCommit(fd, info)) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700396 ALOGE("%s: commit failed", __func__);
397 return false;
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700398 }
399 return true;
400}
401
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500402void Overlay::dump() const {
Saurabh Shah9dc88fc2013-07-15 16:02:30 -0700403#if PIPE_DEBUG
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500404 if(strlen(mDumpStr)) { //dump only on state change
Saurabh Shah9dc88fc2013-07-15 16:02:30 -0700405 ALOGD("%s\n", mDumpStr);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500406 }
Saurabh Shah9dc88fc2013-07-15 16:02:30 -0700407#endif
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500408}
409
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800410void Overlay::getDump(char *buf, size_t len) {
411 int totalPipes = 0;
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700412 const char *str = "\nOverlay State\n\n";
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800413 strncat(buf, str, strlen(str));
414 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
415 if(mPipeBook[i].valid()) {
416 mPipeBook[i].mPipe->getDump(buf, len);
417 char str[64] = {'\0'};
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700418 snprintf(str, 64, "Display=%d\n\n", mPipeBook[i].mDisplay);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800419 strncat(buf, str, strlen(str));
420 totalPipes++;
421 }
422 }
423 char str_pipes[64] = {'\0'};
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700424 snprintf(str_pipes, 64, "Pipes=%d\n\n", totalPipes);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800425 strncat(buf, str_pipes, strlen(str_pipes));
426}
427
Sushil Chauhanbd3ea922013-05-15 12:25:26 -0700428void Overlay::clear(int dpy) {
429 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
430 if (mPipeBook[i].mDisplay == dpy) {
431 // Mark as available for this round
432 PipeBook::resetUse(i);
433 PipeBook::resetAllocation(i);
434 }
435 }
436}
437
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700438void Overlay::initScalar() {
439#ifdef USES_QSEED_SCALAR
440 if(sLibScaleHandle == NULL) {
441 sLibScaleHandle = dlopen("libscale.so", RTLD_NOW);
442 }
443
444 if(sLibScaleHandle) {
445 if(sScale == NULL) {
446 Scale* (*getInstance)();
447 *(void **) &getInstance = dlsym(sLibScaleHandle, "getInstance");
448 if(getInstance) {
449 sScale = getInstance();
450 }
451 }
452 }
453#endif
454}
455
456void Overlay::destroyScalar() {
457#ifdef USES_QSEED_SCALAR
458 if(sLibScaleHandle) {
459 if(sScale) {
460 void (*destroyInstance)(Scale*);
461 *(void **) &destroyInstance = dlsym(sLibScaleHandle,
462 "destroyInstance");
463 if(destroyInstance) {
464 destroyInstance(sScale);
465 sScale = NULL;
466 }
467 }
468 dlclose(sLibScaleHandle);
469 sLibScaleHandle = NULL;
470 }
471#endif
472}
473
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500474void Overlay::PipeBook::init() {
475 mPipe = NULL;
476 mDisplay = DPY_UNUSED;
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700477 mMixer = MIXER_UNUSED;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500478}
479
480void Overlay::PipeBook::destroy() {
481 if(mPipe) {
482 delete mPipe;
483 mPipe = NULL;
484 }
485 mDisplay = DPY_UNUSED;
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700486 mMixer = MIXER_UNUSED;
Zohaib Alam4b0a9242013-11-20 23:54:12 -0500487 mSession = NONE;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500488}
489
490Overlay* Overlay::sInstance = 0;
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700491int Overlay::sDpyFbMap[DPY_MAX] = {0, -1, -1};
Saurabh Shah85234ec2013-04-12 17:09:00 -0700492int Overlay::sDMAMode = DMA_LINE_MODE;
Raj Kamala8c065f2013-10-22 14:52:45 +0530493bool Overlay::sDMAMultiplexingSupported = false;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500494int Overlay::PipeBook::NUM_PIPES = 0;
495int Overlay::PipeBook::sPipeUsageBitmap = 0;
496int Overlay::PipeBook::sLastUsageBitmap = 0;
497int Overlay::PipeBook::sAllocatedBitmap = 0;
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800498utils::eMdpPipeType Overlay::PipeBook::pipeTypeLUT[utils::OV_MAX] =
499 {utils::OV_MDP_PIPE_ANY};
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700500void *Overlay::sLibScaleHandle = NULL;
501scale::Scale *Overlay::sScale = NULL;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500502
503}; // namespace overlay