blob: d22aedb117a8501ee328315d02668f386c4ded6a [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"
Naseer Ahmed29a26812012-06-14 00:56:20 -070033
Naseer Ahmed758bfc52012-11-28 17:02:08 -050034#define PIPE_DEBUG 0
Naseer Ahmed29a26812012-06-14 00:56:20 -070035
36namespace overlay {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050037using namespace utils;
Naseer Ahmed29a26812012-06-14 00:56:20 -070038
Naseer Ahmed758bfc52012-11-28 17:02:08 -050039Overlay::Overlay() {
Sushil Chauhan07a2c762013-03-06 15:36:49 -080040 PipeBook::NUM_PIPES = qdutils::MDPVersion::getInstance().getTotalPipes();
Naseer Ahmed758bfc52012-11-28 17:02:08 -050041 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
42 mPipeBook[i].init();
Naseer Ahmed1ddf3662012-07-31 19:14:18 -070043 }
Naseer Ahmed1ddf3662012-07-31 19:14:18 -070044
Naseer Ahmed758bfc52012-11-28 17:02:08 -050045 mDumpStr[0] = '\0';
Naseer Ahmed29a26812012-06-14 00:56:20 -070046}
47
48Overlay::~Overlay() {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050049 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
50 mPipeBook[i].destroy();
51 }
Naseer Ahmed29a26812012-06-14 00:56:20 -070052}
53
Naseer Ahmed758bfc52012-11-28 17:02:08 -050054void Overlay::configBegin() {
55 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
56 //Mark as available for this round.
57 PipeBook::resetUse(i);
58 PipeBook::resetAllocation(i);
59 }
60 mDumpStr[0] = '\0';
61}
62
63void Overlay::configDone() {
64 if(PipeBook::pipeUsageUnchanged()) return;
65
66 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
67 if(PipeBook::isNotUsed(i)) {
68 //Forces UNSET on pipes, flushes rotator memory and session, closes
69 //fds
70 if(mPipeBook[i].valid()) {
71 char str[32];
Sushil Chauhan07a2c762013-03-06 15:36:49 -080072 sprintf(str, "Unset pipe=%s dpy=%d; ",
73 PipeBook::getDestStr((eDest)i), mPipeBook[i].mDisplay);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050074 strncat(mDumpStr, str, strlen(str));
75 }
76 mPipeBook[i].destroy();
Naseer Ahmed1ddf3662012-07-31 19:14:18 -070077 }
Naseer Ahmed29a26812012-06-14 00:56:20 -070078 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -050079 dump();
80 PipeBook::save();
81}
82
83eDest Overlay::nextPipe(eMdpPipeType type, int dpy) {
84 eDest dest = OV_INVALID;
85
86 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
87 //Match requested pipe type
Sushil Chauhan07a2c762013-03-06 15:36:49 -080088 if(type == OV_MDP_PIPE_ANY || type == PipeBook::getPipeType((eDest)i)) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050089 //If the pipe is not allocated to any display or used by the
90 //requesting display already in previous round.
91 if((mPipeBook[i].mDisplay == PipeBook::DPY_UNUSED ||
92 mPipeBook[i].mDisplay == dpy) &&
93 PipeBook::isNotAllocated(i)) {
94 dest = (eDest)i;
95 PipeBook::setAllocation(i);
96 break;
97 }
98 }
99 }
100
101 if(dest != OV_INVALID) {
102 int index = (int)dest;
103 //If the pipe is not registered with any display OR if the pipe is
104 //requested again by the same display using it, then go ahead.
105 mPipeBook[index].mDisplay = dpy;
106 if(not mPipeBook[index].valid()) {
107 mPipeBook[index].mPipe = new GenericPipe(dpy);
108 char str[32];
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800109 snprintf(str, 32, "Set pipe=%s dpy=%d; ",
110 PipeBook::getDestStr(dest), dpy);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500111 strncat(mDumpStr, str, strlen(str));
112 }
113 } else {
114 ALOGD_IF(PIPE_DEBUG, "Pipe unavailable type=%d display=%d",
115 (int)type, dpy);
116 }
117
118 return dest;
119}
120
121bool Overlay::commit(utils::eDest dest) {
122 bool ret = false;
123 int index = (int)dest;
124 validate(index);
125
126 if(mPipeBook[index].mPipe->commit()) {
127 ret = true;
128 PipeBook::setUse((int)dest);
129 } else {
130 PipeBook::resetUse((int)dest);
Sushil Chauhane0dff932013-03-01 14:33:18 -0800131 int dpy = mPipeBook[index].mDisplay;
132 for(int i = 0; i < PipeBook::NUM_PIPES; i++)
133 if (mPipeBook[i].mDisplay == dpy)
134 PipeBook::resetAllocation(i);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500135 }
136 return ret;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700137}
138
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700139bool Overlay::queueBuffer(int fd, uint32_t offset,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500140 utils::eDest dest) {
141 int index = (int)dest;
142 bool ret = false;
143 validate(index);
144 //Queue only if commit() has succeeded (and the bit set)
145 if(PipeBook::isUsed((int)dest)) {
146 ret = mPipeBook[index].mPipe->queueBuffer(fd, offset);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700147 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500148 return ret;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700149}
150
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500151void Overlay::setCrop(const utils::Dim& d,
152 utils::eDest dest) {
153 int index = (int)dest;
154 validate(index);
155 mPipeBook[index].mPipe->setCrop(d);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700156}
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700157
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500158void Overlay::setPosition(const utils::Dim& d,
159 utils::eDest dest) {
160 int index = (int)dest;
161 validate(index);
162 mPipeBook[index].mPipe->setPosition(d);
163}
164
165void Overlay::setTransform(const int orient,
166 utils::eDest dest) {
167 int index = (int)dest;
168 validate(index);
169
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700170 utils::eTransform transform =
171 static_cast<utils::eTransform>(orient);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500172 mPipeBook[index].mPipe->setTransform(transform);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700173
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500174}
175
176void Overlay::setSource(const utils::PipeArgs args,
177 utils::eDest dest) {
178 int index = (int)dest;
179 validate(index);
180
181 PipeArgs newArgs(args);
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800182 if(PipeBook::getPipeType(dest) == OV_MDP_PIPE_VG) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500183 setMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_SHARE);
184 } else {
185 clearMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_SHARE);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700186 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800187
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800188 if(PipeBook::getPipeType(dest) == OV_MDP_PIPE_DMA) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800189 setMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_FORCE_DMA);
190 } else {
191 clearMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_FORCE_DMA);
192 }
193
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500194 mPipeBook[index].mPipe->setSource(newArgs);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700195}
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700196
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500197Overlay* Overlay::getInstance() {
198 if(sInstance == NULL) {
199 sInstance = new Overlay();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700200 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500201 return sInstance;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700202}
203
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800204// Clears any VG pipes allocated to the fb devices
205// Generates a LUT for pipe types.
206int Overlay::initOverlay() {
207 int mdpVersion = qdutils::MDPVersion::getInstance().getMDPVersion();
208 int numPipesXType[OV_MDP_PIPE_ANY] = {0};
209 numPipesXType[OV_MDP_PIPE_RGB] =
210 qdutils::MDPVersion::getInstance().getRGBPipes();
211 numPipesXType[OV_MDP_PIPE_VG] =
212 qdutils::MDPVersion::getInstance().getVGPipes();
213 numPipesXType[OV_MDP_PIPE_DMA] =
214 qdutils::MDPVersion::getInstance().getDMAPipes();
215
216 int index = 0;
217 for(int X = 0; X < (int)OV_MDP_PIPE_ANY; X++) { //iterate over types
218 for(int j = 0; j < numPipesXType[X]; j++) { //iterate over num
219 PipeBook::pipeTypeLUT[index] = (utils::eMdpPipeType)X;
220 index++;
221 }
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700222 }
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800223
224 if (mdpVersion < qdutils::MDSS_V5) {
225 msmfb_mixer_info_req req;
226 mdp_mixer_info *minfo = NULL;
227 char name[64];
228 int fd = -1;
229 for(int i = 0; i < NUM_FB_DEVICES; i++) {
230 snprintf(name, 64, FB_DEVICE_TEMPLATE, i);
231 ALOGD("initoverlay:: opening the device:: %s", name);
232 fd = ::open(name, O_RDWR, 0);
233 if(fd < 0) {
234 ALOGE("cannot open framebuffer(%d)", i);
235 return -1;
236 }
237 //Get the mixer configuration */
238 req.mixer_num = i;
239 if (ioctl(fd, MSMFB_MIXER_INFO, &req) == -1) {
240 ALOGE("ERROR: MSMFB_MIXER_INFO ioctl failed");
241 close(fd);
242 return -1;
243 }
244 minfo = req.info;
245 for (int j = 0; j < req.cnt; j++) {
246 ALOGD("ndx=%d num=%d z_order=%d", minfo->pndx, minfo->pnum,
247 minfo->z_order);
248 // except the RGB base layer with z_order of -1, clear any
249 // other pipes connected to mixer.
250 if((minfo->z_order) != -1) {
251 int index = minfo->pndx;
252 ALOGD("Unset overlay with index: %d at mixer %d", index, i);
253 if(ioctl(fd, MSMFB_OVERLAY_UNSET, &index) == -1) {
254 ALOGE("ERROR: MSMFB_OVERLAY_UNSET failed");
255 close(fd);
256 return -1;
257 }
258 }
259 minfo++;
260 }
261 close(fd);
262 fd = -1;
263 }
264 }
265 return 0;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700266}
267
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500268void Overlay::dump() const {
269 if(strlen(mDumpStr)) { //dump only on state change
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800270 ALOGD_IF(PIPE_DEBUG, "%s\n", mDumpStr);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500271 }
272}
273
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800274void Overlay::getDump(char *buf, size_t len) {
275 int totalPipes = 0;
276 const char *str = "\nOverlay State\n==========================\n";
277 strncat(buf, str, strlen(str));
278 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
279 if(mPipeBook[i].valid()) {
280 mPipeBook[i].mPipe->getDump(buf, len);
281 char str[64] = {'\0'};
282 snprintf(str, 64, "Attached to dpy=%d\n\n", mPipeBook[i].mDisplay);
283 strncat(buf, str, strlen(str));
284 totalPipes++;
285 }
286 }
287 char str_pipes[64] = {'\0'};
288 snprintf(str_pipes, 64, "Pipes used=%d\n\n", totalPipes);
289 strncat(buf, str_pipes, strlen(str_pipes));
290}
291
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500292void Overlay::PipeBook::init() {
293 mPipe = NULL;
294 mDisplay = DPY_UNUSED;
295}
296
297void Overlay::PipeBook::destroy() {
298 if(mPipe) {
299 delete mPipe;
300 mPipe = NULL;
301 }
302 mDisplay = DPY_UNUSED;
303}
304
305Overlay* Overlay::sInstance = 0;
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -0800306int Overlay::sExtFbIndex = 1;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500307int Overlay::PipeBook::NUM_PIPES = 0;
308int Overlay::PipeBook::sPipeUsageBitmap = 0;
309int Overlay::PipeBook::sLastUsageBitmap = 0;
310int Overlay::PipeBook::sAllocatedBitmap = 0;
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800311utils::eMdpPipeType Overlay::PipeBook::pipeTypeLUT[utils::OV_MAX] =
312 {utils::OV_MDP_PIPE_ANY};
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500313
314}; // namespace overlay