blob: 441b82254f4dcb6e60ce51cf58cb562d5a49d80c [file] [log] [blame]
Naseer Ahmed29a26812012-06-14 00:56:20 -07001/*
Naseer Ahmed758bfc52012-11-28 17:02:08 -05002* Copyright (c) 2011-2012, 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() {
40 int numPipes = 0;
41 int mdpVersion = qdutils::MDPVersion::getInstance().getMDPVersion();
42 if (mdpVersion > qdutils::MDP_V3_1) numPipes = 4;
43 if (mdpVersion >= qdutils::MDSS_V5) numPipes = 6;
44
45 PipeBook::NUM_PIPES = numPipes;
46 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
47 mPipeBook[i].init();
Naseer Ahmed1ddf3662012-07-31 19:14:18 -070048 }
Naseer Ahmed1ddf3662012-07-31 19:14:18 -070049
Naseer Ahmed758bfc52012-11-28 17:02:08 -050050 mDumpStr[0] = '\0';
Naseer Ahmed29a26812012-06-14 00:56:20 -070051}
52
53Overlay::~Overlay() {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050054 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
55 mPipeBook[i].destroy();
56 }
Naseer Ahmed29a26812012-06-14 00:56:20 -070057}
58
Naseer Ahmed758bfc52012-11-28 17:02:08 -050059void Overlay::configBegin() {
60 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
61 //Mark as available for this round.
62 PipeBook::resetUse(i);
63 PipeBook::resetAllocation(i);
64 }
65 mDumpStr[0] = '\0';
66}
67
68void Overlay::configDone() {
69 if(PipeBook::pipeUsageUnchanged()) return;
70
71 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
72 if(PipeBook::isNotUsed(i)) {
73 //Forces UNSET on pipes, flushes rotator memory and session, closes
74 //fds
75 if(mPipeBook[i].valid()) {
76 char str[32];
77 sprintf(str, "Unset pipe=%s dpy=%d; ", getDestStr((eDest)i),
78 mPipeBook[i].mDisplay);
79 strncat(mDumpStr, str, strlen(str));
80 }
81 mPipeBook[i].destroy();
Naseer Ahmed1ddf3662012-07-31 19:14:18 -070082 }
Naseer Ahmed29a26812012-06-14 00:56:20 -070083 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -050084 dump();
85 PipeBook::save();
86}
87
88eDest Overlay::nextPipe(eMdpPipeType type, int dpy) {
89 eDest dest = OV_INVALID;
90
91 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
92 //Match requested pipe type
93 if(type == OV_MDP_PIPE_ANY || type == getPipeType((eDest)i)) {
94 //If the pipe is not allocated to any display or used by the
95 //requesting display already in previous round.
96 if((mPipeBook[i].mDisplay == PipeBook::DPY_UNUSED ||
97 mPipeBook[i].mDisplay == dpy) &&
98 PipeBook::isNotAllocated(i)) {
99 dest = (eDest)i;
100 PipeBook::setAllocation(i);
101 break;
102 }
103 }
104 }
105
106 if(dest != OV_INVALID) {
107 int index = (int)dest;
108 //If the pipe is not registered with any display OR if the pipe is
109 //requested again by the same display using it, then go ahead.
110 mPipeBook[index].mDisplay = dpy;
111 if(not mPipeBook[index].valid()) {
112 mPipeBook[index].mPipe = new GenericPipe(dpy);
113 char str[32];
114 snprintf(str, 32, "Set pipe=%s dpy=%d; ", getDestStr(dest), dpy);
115 strncat(mDumpStr, str, strlen(str));
116 }
117 } else {
118 ALOGD_IF(PIPE_DEBUG, "Pipe unavailable type=%d display=%d",
119 (int)type, dpy);
120 }
121
122 return dest;
123}
124
125bool Overlay::commit(utils::eDest dest) {
126 bool ret = false;
127 int index = (int)dest;
128 validate(index);
129
130 if(mPipeBook[index].mPipe->commit()) {
131 ret = true;
132 PipeBook::setUse((int)dest);
133 } else {
134 PipeBook::resetUse((int)dest);
135 }
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);
182 if(dest == OV_VG0 || dest == OV_VG1) {
183 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 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500187 mPipeBook[index].mPipe->setSource(newArgs);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700188}
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700189
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500190Overlay* Overlay::getInstance() {
191 if(sInstance == NULL) {
192 sInstance = new Overlay();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700193 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500194 return sInstance;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700195}
196
197void Overlay::initOverlay() {
198 if(utils::initOverlay() == -1) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500199 ALOGE("%s failed", __FUNCTION__);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700200 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700201}
202
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500203void Overlay::dump() const {
204 if(strlen(mDumpStr)) { //dump only on state change
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800205 ALOGD_IF(PIPE_DEBUG, "%s\n", mDumpStr);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500206 }
207}
208
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800209void Overlay::getDump(char *buf, size_t len) {
210 int totalPipes = 0;
211 const char *str = "\nOverlay State\n==========================\n";
212 strncat(buf, str, strlen(str));
213 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
214 if(mPipeBook[i].valid()) {
215 mPipeBook[i].mPipe->getDump(buf, len);
216 char str[64] = {'\0'};
217 snprintf(str, 64, "Attached to dpy=%d\n\n", mPipeBook[i].mDisplay);
218 strncat(buf, str, strlen(str));
219 totalPipes++;
220 }
221 }
222 char str_pipes[64] = {'\0'};
223 snprintf(str_pipes, 64, "Pipes used=%d\n\n", totalPipes);
224 strncat(buf, str_pipes, strlen(str_pipes));
225}
226
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500227void Overlay::PipeBook::init() {
228 mPipe = NULL;
229 mDisplay = DPY_UNUSED;
230}
231
232void Overlay::PipeBook::destroy() {
233 if(mPipe) {
234 delete mPipe;
235 mPipe = NULL;
236 }
237 mDisplay = DPY_UNUSED;
238}
239
240Overlay* Overlay::sInstance = 0;
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -0800241int Overlay::sExtFbIndex = 1;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500242int Overlay::PipeBook::NUM_PIPES = 0;
243int Overlay::PipeBook::sPipeUsageBitmap = 0;
244int Overlay::PipeBook::sLastUsageBitmap = 0;
245int Overlay::PipeBook::sAllocatedBitmap = 0;
246
247}; // namespace overlay