blob: 1faeadf454ff1a6874a604ab55ae9fb81469ea0e [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)) {
95 dest = (eDest)i;
96 PipeBook::setAllocation(i);
97 break;
98 }
99 }
100 }
101
102 if(dest != OV_INVALID) {
103 int index = (int)dest;
104 //If the pipe is not registered with any display OR if the pipe is
105 //requested again by the same display using it, then go ahead.
106 mPipeBook[index].mDisplay = dpy;
107 if(not mPipeBook[index].valid()) {
108 mPipeBook[index].mPipe = new GenericPipe(dpy);
109 char str[32];
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800110 snprintf(str, 32, "Set pipe=%s dpy=%d; ",
111 PipeBook::getDestStr(dest), dpy);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500112 strncat(mDumpStr, str, strlen(str));
113 }
114 } else {
115 ALOGD_IF(PIPE_DEBUG, "Pipe unavailable type=%d display=%d",
116 (int)type, dpy);
117 }
118
119 return dest;
120}
121
122bool Overlay::commit(utils::eDest dest) {
123 bool ret = false;
124 int index = (int)dest;
125 validate(index);
126
127 if(mPipeBook[index].mPipe->commit()) {
128 ret = true;
129 PipeBook::setUse((int)dest);
130 } else {
131 PipeBook::resetUse((int)dest);
Sushil Chauhane0dff932013-03-01 14:33:18 -0800132 int dpy = mPipeBook[index].mDisplay;
133 for(int i = 0; i < PipeBook::NUM_PIPES; i++)
134 if (mPipeBook[i].mDisplay == dpy)
135 PipeBook::resetAllocation(i);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500136 }
137 return ret;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700138}
139
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700140bool Overlay::queueBuffer(int fd, uint32_t offset,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500141 utils::eDest dest) {
142 int index = (int)dest;
143 bool ret = false;
144 validate(index);
145 //Queue only if commit() has succeeded (and the bit set)
146 if(PipeBook::isUsed((int)dest)) {
147 ret = mPipeBook[index].mPipe->queueBuffer(fd, offset);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700148 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500149 return ret;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700150}
151
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500152void Overlay::setCrop(const utils::Dim& d,
153 utils::eDest dest) {
154 int index = (int)dest;
155 validate(index);
156 mPipeBook[index].mPipe->setCrop(d);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700157}
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700158
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500159void Overlay::setPosition(const utils::Dim& d,
160 utils::eDest dest) {
161 int index = (int)dest;
162 validate(index);
163 mPipeBook[index].mPipe->setPosition(d);
164}
165
166void Overlay::setTransform(const int orient,
167 utils::eDest dest) {
168 int index = (int)dest;
169 validate(index);
170
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700171 utils::eTransform transform =
172 static_cast<utils::eTransform>(orient);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500173 mPipeBook[index].mPipe->setTransform(transform);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700174
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500175}
176
177void Overlay::setSource(const utils::PipeArgs args,
178 utils::eDest dest) {
179 int index = (int)dest;
180 validate(index);
181
182 PipeArgs newArgs(args);
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800183 if(PipeBook::getPipeType(dest) == OV_MDP_PIPE_VG) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500184 setMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_SHARE);
185 } else {
186 clearMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_SHARE);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700187 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800188
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800189 if(PipeBook::getPipeType(dest) == OV_MDP_PIPE_DMA) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800190 setMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_FORCE_DMA);
191 } else {
192 clearMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_FORCE_DMA);
193 }
194
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500195 mPipeBook[index].mPipe->setSource(newArgs);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700196}
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700197
Saurabh Shah5daeee52013-01-23 16:52:26 +0800198void Overlay::setVisualParams(const MetaData_t& metadata, utils::eDest dest) {
199 int index = (int)dest;
200 validate(index);
201 mPipeBook[index].mPipe->setVisualParams(metadata);
202}
203
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500204Overlay* Overlay::getInstance() {
205 if(sInstance == NULL) {
206 sInstance = new Overlay();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700207 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500208 return sInstance;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700209}
210
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800211// Clears any VG pipes allocated to the fb devices
212// Generates a LUT for pipe types.
213int Overlay::initOverlay() {
214 int mdpVersion = qdutils::MDPVersion::getInstance().getMDPVersion();
215 int numPipesXType[OV_MDP_PIPE_ANY] = {0};
216 numPipesXType[OV_MDP_PIPE_RGB] =
217 qdutils::MDPVersion::getInstance().getRGBPipes();
218 numPipesXType[OV_MDP_PIPE_VG] =
219 qdutils::MDPVersion::getInstance().getVGPipes();
220 numPipesXType[OV_MDP_PIPE_DMA] =
221 qdutils::MDPVersion::getInstance().getDMAPipes();
222
223 int index = 0;
224 for(int X = 0; X < (int)OV_MDP_PIPE_ANY; X++) { //iterate over types
225 for(int j = 0; j < numPipesXType[X]; j++) { //iterate over num
226 PipeBook::pipeTypeLUT[index] = (utils::eMdpPipeType)X;
227 index++;
228 }
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700229 }
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800230
231 if (mdpVersion < qdutils::MDSS_V5) {
232 msmfb_mixer_info_req req;
233 mdp_mixer_info *minfo = NULL;
234 char name[64];
235 int fd = -1;
236 for(int i = 0; i < NUM_FB_DEVICES; i++) {
237 snprintf(name, 64, FB_DEVICE_TEMPLATE, i);
238 ALOGD("initoverlay:: opening the device:: %s", name);
239 fd = ::open(name, O_RDWR, 0);
240 if(fd < 0) {
241 ALOGE("cannot open framebuffer(%d)", i);
242 return -1;
243 }
244 //Get the mixer configuration */
245 req.mixer_num = i;
246 if (ioctl(fd, MSMFB_MIXER_INFO, &req) == -1) {
247 ALOGE("ERROR: MSMFB_MIXER_INFO ioctl failed");
248 close(fd);
249 return -1;
250 }
251 minfo = req.info;
252 for (int j = 0; j < req.cnt; j++) {
253 ALOGD("ndx=%d num=%d z_order=%d", minfo->pndx, minfo->pnum,
254 minfo->z_order);
255 // except the RGB base layer with z_order of -1, clear any
256 // other pipes connected to mixer.
257 if((minfo->z_order) != -1) {
258 int index = minfo->pndx;
259 ALOGD("Unset overlay with index: %d at mixer %d", index, i);
260 if(ioctl(fd, MSMFB_OVERLAY_UNSET, &index) == -1) {
261 ALOGE("ERROR: MSMFB_OVERLAY_UNSET failed");
262 close(fd);
263 return -1;
264 }
265 }
266 minfo++;
267 }
268 close(fd);
269 fd = -1;
270 }
271 }
272 return 0;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700273}
274
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500275void Overlay::dump() const {
276 if(strlen(mDumpStr)) { //dump only on state change
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800277 ALOGD_IF(PIPE_DEBUG, "%s\n", mDumpStr);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500278 }
279}
280
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800281void Overlay::getDump(char *buf, size_t len) {
282 int totalPipes = 0;
283 const char *str = "\nOverlay State\n==========================\n";
284 strncat(buf, str, strlen(str));
285 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
286 if(mPipeBook[i].valid()) {
287 mPipeBook[i].mPipe->getDump(buf, len);
288 char str[64] = {'\0'};
289 snprintf(str, 64, "Attached to dpy=%d\n\n", mPipeBook[i].mDisplay);
290 strncat(buf, str, strlen(str));
291 totalPipes++;
292 }
293 }
294 char str_pipes[64] = {'\0'};
295 snprintf(str_pipes, 64, "Pipes used=%d\n\n", totalPipes);
296 strncat(buf, str_pipes, strlen(str_pipes));
297}
298
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500299void Overlay::PipeBook::init() {
300 mPipe = NULL;
301 mDisplay = DPY_UNUSED;
302}
303
304void Overlay::PipeBook::destroy() {
305 if(mPipe) {
306 delete mPipe;
307 mPipe = NULL;
308 }
309 mDisplay = DPY_UNUSED;
310}
311
312Overlay* Overlay::sInstance = 0;
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -0800313int Overlay::sExtFbIndex = 1;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500314int Overlay::PipeBook::NUM_PIPES = 0;
315int Overlay::PipeBook::sPipeUsageBitmap = 0;
316int Overlay::PipeBook::sLastUsageBitmap = 0;
317int Overlay::PipeBook::sAllocatedBitmap = 0;
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800318utils::eMdpPipeType Overlay::PipeBook::pipeTypeLUT[utils::OV_MAX] =
319 {utils::OV_MDP_PIPE_ANY};
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500320
321}; // namespace overlay