blob: e6da3c564bb93c29c2f654ae196d4f41859602f6 [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 }
Saurabh Shah784e9852013-08-21 16:51:21 -070071 sForceSetBitmap = 0;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050072 mDumpStr[0] = '\0';
Saurabh Shahb8f58e22013-09-26 16:20:07 -070073
74#ifdef USES_QSEED_SCALAR
75 Scale *scalar = getScalar();
76 if(scalar) {
77 scalar->configBegin();
78 }
79#endif
Naseer Ahmed758bfc52012-11-28 17:02:08 -050080}
81
82void Overlay::configDone() {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050083 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
Zohaib Alam4b0a9242013-11-20 23:54:12 -050084 if((PipeBook::isNotUsed(i) && !sessionInProgress((eDest)i)) ||
85 isSessionEnded((eDest)i)) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050086 //Forces UNSET on pipes, flushes rotator memory and session, closes
87 //fds
88 if(mPipeBook[i].valid()) {
89 char str[32];
Saurabh Shahaf5f5972013-07-30 13:56:35 -070090 sprintf(str, "Unset=%s dpy=%d mix=%d; ",
91 PipeBook::getDestStr((eDest)i),
92 mPipeBook[i].mDisplay, mPipeBook[i].mMixer);
Saurabh Shah9dc88fc2013-07-15 16:02:30 -070093#if PIPE_DEBUG
Naseer Ahmed758bfc52012-11-28 17:02:08 -050094 strncat(mDumpStr, str, strlen(str));
Saurabh Shah9dc88fc2013-07-15 16:02:30 -070095#endif
Naseer Ahmed758bfc52012-11-28 17:02:08 -050096 }
97 mPipeBook[i].destroy();
Naseer Ahmed1ddf3662012-07-31 19:14:18 -070098 }
Naseer Ahmed29a26812012-06-14 00:56:20 -070099 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500100 dump();
101 PipeBook::save();
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700102
103#ifdef USES_QSEED_SCALAR
104 Scale *scalar = getScalar();
105 if(scalar) {
106 scalar->configDone();
107 }
108#endif
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500109}
110
Zohaib Alam4b0a9242013-11-20 23:54:12 -0500111int Overlay::getPipeId(utils::eDest dest) {
112 return mPipeBook[(int)dest].mPipe->getPipeId();
113}
114
115eDest Overlay::getDest(int pipeid) {
116 eDest dest = OV_INVALID;
117 // finding the dest corresponding to the given pipe
118 for(int i=0; i < PipeBook::NUM_PIPES; ++i) {
119 if(mPipeBook[i].valid() && mPipeBook[i].mPipe->getPipeId() == pipeid) {
120 return (eDest)i;
121 }
122 }
123 return dest;
124}
125
126eDest Overlay::reservePipe(int pipeid) {
127 eDest dest = getDest(pipeid);
128 PipeBook::setAllocation((int)dest);
129 return dest;
130}
131
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700132eDest Overlay::nextPipe(eMdpPipeType type, int dpy, int mixer) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500133 eDest dest = OV_INVALID;
134
135 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700136 if( (type == OV_MDP_PIPE_ANY || //Pipe type match
137 type == PipeBook::getPipeType((eDest)i)) &&
138 (mPipeBook[i].mDisplay == DPY_UNUSED || //Free or same display
139 mPipeBook[i].mDisplay == dpy) &&
140 (mPipeBook[i].mMixer == MIXER_UNUSED || //Free or same mixer
141 mPipeBook[i].mMixer == mixer) &&
142 PipeBook::isNotAllocated(i) && //Free pipe
Raj Kamala8c065f2013-10-22 14:52:45 +0530143 ( (sDMAMultiplexingSupported && dpy) ||
144 !(sDMAMode == DMA_BLOCK_MODE && //DMA pipe in Line mode
145 PipeBook::getPipeType((eDest)i) == OV_MDP_PIPE_DMA)) ){
146 //DMA-Multiplexing is only supported for WB on 8x26
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700147 dest = (eDest)i;
148 PipeBook::setAllocation(i);
149 break;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500150 }
151 }
152
153 if(dest != OV_INVALID) {
154 int index = (int)dest;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500155 mPipeBook[index].mDisplay = dpy;
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700156 mPipeBook[index].mMixer = mixer;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500157 if(not mPipeBook[index].valid()) {
158 mPipeBook[index].mPipe = new GenericPipe(dpy);
Zohaib Alam4b0a9242013-11-20 23:54:12 -0500159 mPipeBook[index].mSession = PipeBook::NONE;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500160 char str[32];
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700161 snprintf(str, 32, "Set=%s dpy=%d mix=%d; ",
162 PipeBook::getDestStr(dest), dpy, mixer);
Saurabh Shah9dc88fc2013-07-15 16:02:30 -0700163#if PIPE_DEBUG
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500164 strncat(mDumpStr, str, strlen(str));
Saurabh Shah9dc88fc2013-07-15 16:02:30 -0700165#endif
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500166 }
167 } else {
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700168 ALOGD_IF(PIPE_DEBUG, "Pipe unavailable type=%d display=%d mixer=%d",
169 (int)type, dpy, mixer);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500170 }
171
172 return dest;
173}
174
Zohaib Alam4b0a9242013-11-20 23:54:12 -0500175void Overlay::endAllSessions() {
176 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
177 if(mPipeBook[i].valid() && mPipeBook[i].mSession==PipeBook::START)
178 mPipeBook[i].mSession = PipeBook::END;
179 }
180}
181
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700182bool Overlay::isPipeTypeAttached(eMdpPipeType type) {
183 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
184 if(type == PipeBook::getPipeType((eDest)i) &&
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700185 mPipeBook[i].mDisplay != DPY_UNUSED) {
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700186 return true;
187 }
188 }
189 return false;
190}
191
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500192bool Overlay::commit(utils::eDest dest) {
193 bool ret = false;
194 int index = (int)dest;
195 validate(index);
196
197 if(mPipeBook[index].mPipe->commit()) {
198 ret = true;
199 PipeBook::setUse((int)dest);
Saurabh Shah784e9852013-08-21 16:51:21 -0700200 if(sForceSetBitmap & (1 << mPipeBook[index].mDisplay)) {
201 mPipeBook[index].mPipe->forceSet();
202 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500203 } else {
Sushil Chauhane0dff932013-03-01 14:33:18 -0800204 int dpy = mPipeBook[index].mDisplay;
205 for(int i = 0; i < PipeBook::NUM_PIPES; i++)
Saurabh Shahdf0be752013-05-23 14:40:00 -0700206 if (mPipeBook[i].mDisplay == dpy) {
Sushil Chauhane0dff932013-03-01 14:33:18 -0800207 PipeBook::resetAllocation(i);
Saurabh Shahdf0be752013-05-23 14:40:00 -0700208 PipeBook::resetUse(i);
209 if(mPipeBook[i].valid()) {
210 mPipeBook[i].mPipe->forceSet();
211 }
212 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500213 }
214 return ret;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700215}
216
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700217bool Overlay::queueBuffer(int fd, uint32_t offset,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500218 utils::eDest dest) {
219 int index = (int)dest;
220 bool ret = false;
221 validate(index);
222 //Queue only if commit() has succeeded (and the bit set)
223 if(PipeBook::isUsed((int)dest)) {
224 ret = mPipeBook[index].mPipe->queueBuffer(fd, offset);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700225 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500226 return ret;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700227}
228
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500229void Overlay::setCrop(const utils::Dim& d,
230 utils::eDest dest) {
231 int index = (int)dest;
232 validate(index);
233 mPipeBook[index].mPipe->setCrop(d);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700234}
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700235
Sushil Chauhan897a9c32013-07-18 11:09:55 -0700236void Overlay::setColor(const uint32_t color,
237 utils::eDest dest) {
238 int index = (int)dest;
239 validate(index);
240 mPipeBook[index].mPipe->setColor(color);
241}
242
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500243void Overlay::setPosition(const utils::Dim& d,
244 utils::eDest dest) {
245 int index = (int)dest;
246 validate(index);
247 mPipeBook[index].mPipe->setPosition(d);
248}
249
250void Overlay::setTransform(const int orient,
251 utils::eDest dest) {
252 int index = (int)dest;
253 validate(index);
254
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700255 utils::eTransform transform =
256 static_cast<utils::eTransform>(orient);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500257 mPipeBook[index].mPipe->setTransform(transform);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700258
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500259}
260
261void Overlay::setSource(const utils::PipeArgs args,
262 utils::eDest dest) {
263 int index = (int)dest;
264 validate(index);
265
266 PipeArgs newArgs(args);
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800267 if(PipeBook::getPipeType(dest) == OV_MDP_PIPE_VG) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500268 setMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_SHARE);
269 } else {
270 clearMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_SHARE);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700271 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800272
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800273 if(PipeBook::getPipeType(dest) == OV_MDP_PIPE_DMA) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800274 setMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_FORCE_DMA);
275 } else {
276 clearMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_FORCE_DMA);
277 }
278
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500279 mPipeBook[index].mPipe->setSource(newArgs);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700280}
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700281
Saurabh Shah5daeee52013-01-23 16:52:26 +0800282void Overlay::setVisualParams(const MetaData_t& metadata, utils::eDest dest) {
283 int index = (int)dest;
284 validate(index);
285 mPipeBook[index].mPipe->setVisualParams(metadata);
286}
287
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500288Overlay* Overlay::getInstance() {
289 if(sInstance == NULL) {
290 sInstance = new Overlay();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700291 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500292 return sInstance;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700293}
294
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800295// Clears any VG pipes allocated to the fb devices
296// Generates a LUT for pipe types.
297int Overlay::initOverlay() {
298 int mdpVersion = qdutils::MDPVersion::getInstance().getMDPVersion();
299 int numPipesXType[OV_MDP_PIPE_ANY] = {0};
300 numPipesXType[OV_MDP_PIPE_RGB] =
301 qdutils::MDPVersion::getInstance().getRGBPipes();
302 numPipesXType[OV_MDP_PIPE_VG] =
303 qdutils::MDPVersion::getInstance().getVGPipes();
304 numPipesXType[OV_MDP_PIPE_DMA] =
305 qdutils::MDPVersion::getInstance().getDMAPipes();
306
307 int index = 0;
308 for(int X = 0; X < (int)OV_MDP_PIPE_ANY; X++) { //iterate over types
309 for(int j = 0; j < numPipesXType[X]; j++) { //iterate over num
310 PipeBook::pipeTypeLUT[index] = (utils::eMdpPipeType)X;
311 index++;
312 }
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700313 }
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800314
Xiaoming Zhou5eff8b62013-05-01 20:56:09 -0400315 if (mdpVersion < qdutils::MDSS_V5 && mdpVersion != qdutils::MDP_V3_0_4) {
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800316 msmfb_mixer_info_req req;
317 mdp_mixer_info *minfo = NULL;
318 char name[64];
319 int fd = -1;
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700320 for(int i = 0; i < MAX_FB_DEVICES; i++) {
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800321 snprintf(name, 64, FB_DEVICE_TEMPLATE, i);
322 ALOGD("initoverlay:: opening the device:: %s", name);
323 fd = ::open(name, O_RDWR, 0);
324 if(fd < 0) {
325 ALOGE("cannot open framebuffer(%d)", i);
326 return -1;
327 }
328 //Get the mixer configuration */
329 req.mixer_num = i;
330 if (ioctl(fd, MSMFB_MIXER_INFO, &req) == -1) {
331 ALOGE("ERROR: MSMFB_MIXER_INFO ioctl failed");
332 close(fd);
333 return -1;
334 }
335 minfo = req.info;
336 for (int j = 0; j < req.cnt; j++) {
337 ALOGD("ndx=%d num=%d z_order=%d", minfo->pndx, minfo->pnum,
338 minfo->z_order);
339 // except the RGB base layer with z_order of -1, clear any
340 // other pipes connected to mixer.
341 if((minfo->z_order) != -1) {
342 int index = minfo->pndx;
343 ALOGD("Unset overlay with index: %d at mixer %d", index, i);
344 if(ioctl(fd, MSMFB_OVERLAY_UNSET, &index) == -1) {
345 ALOGE("ERROR: MSMFB_OVERLAY_UNSET failed");
346 close(fd);
347 return -1;
348 }
349 }
350 minfo++;
351 }
352 close(fd);
353 fd = -1;
354 }
355 }
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700356
357 FILE *displayDeviceFP = NULL;
358 const int MAX_FRAME_BUFFER_NAME_SIZE = 128;
359 char fbType[MAX_FRAME_BUFFER_NAME_SIZE];
360 char msmFbTypePath[MAX_FRAME_BUFFER_NAME_SIZE];
361 const char *strDtvPanel = "dtv panel";
362 const char *strWbPanel = "writeback panel";
363
364 for(int num = 1; num < MAX_FB_DEVICES; num++) {
365 snprintf (msmFbTypePath, sizeof(msmFbTypePath),
366 "/sys/class/graphics/fb%d/msm_fb_type", num);
367 displayDeviceFP = fopen(msmFbTypePath, "r");
368
369 if(displayDeviceFP){
370 fread(fbType, sizeof(char), MAX_FRAME_BUFFER_NAME_SIZE,
371 displayDeviceFP);
372
373 if(strncmp(fbType, strDtvPanel, strlen(strDtvPanel)) == 0) {
374 sDpyFbMap[DPY_EXTERNAL] = num;
375 } else if(strncmp(fbType, strWbPanel, strlen(strWbPanel)) == 0) {
376 sDpyFbMap[DPY_WRITEBACK] = num;
377 }
378
379 fclose(displayDeviceFP);
380 }
381 }
382
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800383 return 0;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700384}
385
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700386bool Overlay::displayCommit(const int& fd) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700387 utils::Dim roi;
388 return displayCommit(fd, roi);
389}
390
391bool Overlay::displayCommit(const int& fd, const utils::Dim& roi) {
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700392 //Commit
393 struct mdp_display_commit info;
394 memset(&info, 0, sizeof(struct mdp_display_commit));
395 info.flags = MDP_DISPLAY_COMMIT_OVERLAY;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700396 info.roi.x = roi.x;
397 info.roi.y = roi.y;
398 info.roi.w = roi.w;
399 info.roi.h = roi.h;
400
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700401 if(!mdp_wrapper::displayCommit(fd, info)) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700402 ALOGE("%s: commit failed", __func__);
403 return false;
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700404 }
405 return true;
406}
407
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500408void Overlay::dump() const {
Saurabh Shah9dc88fc2013-07-15 16:02:30 -0700409#if PIPE_DEBUG
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500410 if(strlen(mDumpStr)) { //dump only on state change
Saurabh Shah9dc88fc2013-07-15 16:02:30 -0700411 ALOGD("%s\n", mDumpStr);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500412 }
Saurabh Shah9dc88fc2013-07-15 16:02:30 -0700413#endif
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500414}
415
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800416void Overlay::getDump(char *buf, size_t len) {
417 int totalPipes = 0;
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700418 const char *str = "\nOverlay State\n\n";
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800419 strncat(buf, str, strlen(str));
420 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
421 if(mPipeBook[i].valid()) {
422 mPipeBook[i].mPipe->getDump(buf, len);
423 char str[64] = {'\0'};
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700424 snprintf(str, 64, "Display=%d\n\n", mPipeBook[i].mDisplay);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800425 strncat(buf, str, strlen(str));
426 totalPipes++;
427 }
428 }
429 char str_pipes[64] = {'\0'};
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700430 snprintf(str_pipes, 64, "Pipes=%d\n\n", totalPipes);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800431 strncat(buf, str_pipes, strlen(str_pipes));
432}
433
Sushil Chauhanbd3ea922013-05-15 12:25:26 -0700434void Overlay::clear(int dpy) {
435 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
436 if (mPipeBook[i].mDisplay == dpy) {
437 // Mark as available for this round
438 PipeBook::resetUse(i);
439 PipeBook::resetAllocation(i);
Saurabh Shahdf0be752013-05-23 14:40:00 -0700440 if(mPipeBook[i].valid()) {
441 mPipeBook[i].mPipe->forceSet();
442 }
Sushil Chauhanbd3ea922013-05-15 12:25:26 -0700443 }
444 }
445}
446
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700447void Overlay::initScalar() {
448#ifdef USES_QSEED_SCALAR
449 if(sLibScaleHandle == NULL) {
450 sLibScaleHandle = dlopen("libscale.so", RTLD_NOW);
451 }
452
453 if(sLibScaleHandle) {
454 if(sScale == NULL) {
455 Scale* (*getInstance)();
456 *(void **) &getInstance = dlsym(sLibScaleHandle, "getInstance");
457 if(getInstance) {
458 sScale = getInstance();
459 }
460 }
461 }
462#endif
463}
464
465void Overlay::destroyScalar() {
466#ifdef USES_QSEED_SCALAR
467 if(sLibScaleHandle) {
468 if(sScale) {
469 void (*destroyInstance)(Scale*);
470 *(void **) &destroyInstance = dlsym(sLibScaleHandle,
471 "destroyInstance");
472 if(destroyInstance) {
473 destroyInstance(sScale);
474 sScale = NULL;
475 }
476 }
477 dlclose(sLibScaleHandle);
478 sLibScaleHandle = NULL;
479 }
480#endif
481}
482
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500483void Overlay::PipeBook::init() {
484 mPipe = NULL;
485 mDisplay = DPY_UNUSED;
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700486 mMixer = MIXER_UNUSED;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500487}
488
489void Overlay::PipeBook::destroy() {
490 if(mPipe) {
491 delete mPipe;
492 mPipe = NULL;
493 }
494 mDisplay = DPY_UNUSED;
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700495 mMixer = MIXER_UNUSED;
Zohaib Alam4b0a9242013-11-20 23:54:12 -0500496 mSession = NONE;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500497}
498
499Overlay* Overlay::sInstance = 0;
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700500int Overlay::sDpyFbMap[DPY_MAX] = {0, -1, -1};
Saurabh Shah85234ec2013-04-12 17:09:00 -0700501int Overlay::sDMAMode = DMA_LINE_MODE;
Raj Kamala8c065f2013-10-22 14:52:45 +0530502bool Overlay::sDMAMultiplexingSupported = false;
Saurabh Shah784e9852013-08-21 16:51:21 -0700503int Overlay::sForceSetBitmap = 0;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500504int Overlay::PipeBook::NUM_PIPES = 0;
505int Overlay::PipeBook::sPipeUsageBitmap = 0;
506int Overlay::PipeBook::sLastUsageBitmap = 0;
507int Overlay::PipeBook::sAllocatedBitmap = 0;
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800508utils::eMdpPipeType Overlay::PipeBook::pipeTypeLUT[utils::OV_MAX] =
509 {utils::OV_MDP_PIPE_ANY};
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700510void *Overlay::sLibScaleHandle = NULL;
511scale::Scale *Overlay::sScale = NULL;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500512
513}; // namespace overlay