blob: 4dea6ef5ebf225664e472b86904638279324b10d [file] [log] [blame]
Naseer Ahmed29a26812012-06-14 00:56:20 -07001/*
2* Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved.
3*
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.
13* * Neither the name of Code Aurora Forum, Inc. nor the names of its
14* 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
30#include "overlayUtils.h"
31#include "overlayImpl.h"
32#include "overlay.h"
33
Naseer Ahmed29a26812012-06-14 00:56:20 -070034#include "overlayMdp.h"
35#include "overlayCtrlData.h"
Naseer Ahmed29a26812012-06-14 00:56:20 -070036
37namespace overlay {
38
39Overlay::Overlay(): mOv(0) {
40}
41
42Overlay::~Overlay() {
Naseer Ahmedf48aef62012-07-20 09:05:53 -070043 mOv = mState.handleEvent(utils::OV_CLOSED, mOv);
Naseer Ahmed29a26812012-06-14 00:56:20 -070044 delete mOv;
45 mOv = 0;
46}
47
Naseer Ahmed29a26812012-06-14 00:56:20 -070048bool Overlay::commit(utils::eDest dest)
49{
50 OVASSERT(mOv,
51 "%s Overlay and Rotator should be init at this point",
52 __FUNCTION__);
Naseer Ahmed29a26812012-06-14 00:56:20 -070053 utils::eOverlayState st = mState.state();
54 switch (st) {
55 case utils::OV_2D_VIDEO_ON_PANEL:
56 case utils::OV_2D_VIDEO_ON_PANEL_TV:
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -070057 case utils::OV_2D_VIDEO_ON_TV:
Naseer Ahmed29a26812012-06-14 00:56:20 -070058 case utils::OV_3D_VIDEO_ON_2D_PANEL:
59 case utils::OV_3D_VIDEO_ON_3D_PANEL:
60 case utils::OV_3D_VIDEO_ON_3D_TV:
61 case utils::OV_3D_VIDEO_ON_2D_PANEL_2D_TV:
62 case utils::OV_UI_MIRROR:
63 case utils::OV_2D_TRUE_UI_MIRROR:
64 case utils::OV_BYPASS_1_LAYER:
65 case utils::OV_BYPASS_2_LAYER:
66 case utils::OV_BYPASS_3_LAYER:
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -070067 case utils::OV_DUAL_DISP:
Naseer Ahmed29a26812012-06-14 00:56:20 -070068 if(!mOv->commit(dest)) {
69 ALOGE("Overlay %s failed", __FUNCTION__);
70 return false;
71 }
72 break;
73 default:
74 OVASSERT(false, "%s Unknown state %d", __FUNCTION__, st);
75 return false;
76 }
77 return true;
78}
79
Naseer Ahmedf48aef62012-07-20 09:05:53 -070080bool Overlay::queueBuffer(int fd, uint32_t offset,
Naseer Ahmed29a26812012-06-14 00:56:20 -070081 utils::eDest dest)
82{
83 OVASSERT(mOv,
84 "%s Overlay and Rotator should be init at this point",
85 __FUNCTION__);
Naseer Ahmed29a26812012-06-14 00:56:20 -070086 utils::eOverlayState st = mState.state();
87 switch (st) {
88 case utils::OV_2D_VIDEO_ON_PANEL:
89 case utils::OV_2D_VIDEO_ON_PANEL_TV:
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -070090 case utils::OV_2D_VIDEO_ON_TV:
Naseer Ahmed29a26812012-06-14 00:56:20 -070091 case utils::OV_3D_VIDEO_ON_2D_PANEL:
92 case utils::OV_3D_VIDEO_ON_3D_PANEL:
93 case utils::OV_3D_VIDEO_ON_3D_TV:
94 case utils::OV_3D_VIDEO_ON_2D_PANEL_2D_TV:
95 case utils::OV_UI_MIRROR:
96 case utils::OV_2D_TRUE_UI_MIRROR:
97 case utils::OV_BYPASS_1_LAYER:
98 case utils::OV_BYPASS_2_LAYER:
99 case utils::OV_BYPASS_3_LAYER:
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -0700100 case utils::OV_DUAL_DISP:
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700101 if(!mOv->queueBuffer(fd, offset, dest)) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700102 ALOGE("Overlay %s failed", __FUNCTION__);
103 return false;
104 }
105 break;
106 default:
107 OVASSERT(false, "%s Unknown state %d", __FUNCTION__, st);
108 return false;
109 }
110 return true;
111}
112
113bool Overlay::waitForVsync(utils::eDest dest)
114{
115 OVASSERT(mOv,
116 "%s Overlay and Rotator should be init at this point",
117 __FUNCTION__);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700118 utils::eOverlayState st = mState.state();
119 switch (st) {
120 case utils::OV_2D_VIDEO_ON_PANEL:
121 case utils::OV_2D_VIDEO_ON_PANEL_TV:
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -0700122 case utils::OV_2D_VIDEO_ON_TV:
Naseer Ahmed29a26812012-06-14 00:56:20 -0700123 case utils::OV_3D_VIDEO_ON_2D_PANEL:
124 case utils::OV_3D_VIDEO_ON_3D_PANEL:
125 case utils::OV_3D_VIDEO_ON_3D_TV:
126 case utils::OV_3D_VIDEO_ON_2D_PANEL_2D_TV:
127 case utils::OV_UI_MIRROR:
128 case utils::OV_2D_TRUE_UI_MIRROR:
129 case utils::OV_BYPASS_1_LAYER:
130 case utils::OV_BYPASS_2_LAYER:
131 case utils::OV_BYPASS_3_LAYER:
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -0700132 case utils::OV_DUAL_DISP:
Naseer Ahmed29a26812012-06-14 00:56:20 -0700133 if(!mOv->waitForVsync(dest)) {
134 ALOGE("Overlay %s failed", __FUNCTION__);
135 return false;
136 }
137 break;
138 default:
139 OVASSERT(false, "%s Unknown state %d", __FUNCTION__, st);
140 return false;
141 }
142 return true;
143}
144
145bool Overlay::setCrop(const utils::Dim& d,
146 utils::eDest dest)
147{
148 OVASSERT(mOv,
149 "%s Overlay and Rotator should be init at this point",
150 __FUNCTION__);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700151 utils::eOverlayState st = mState.state();
152 switch (st) {
153 case utils::OV_2D_VIDEO_ON_PANEL:
154 case utils::OV_2D_VIDEO_ON_PANEL_TV:
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -0700155 case utils::OV_2D_VIDEO_ON_TV:
Naseer Ahmed29a26812012-06-14 00:56:20 -0700156 case utils::OV_3D_VIDEO_ON_2D_PANEL:
157 case utils::OV_3D_VIDEO_ON_3D_PANEL:
158 case utils::OV_3D_VIDEO_ON_3D_TV:
159 case utils::OV_3D_VIDEO_ON_2D_PANEL_2D_TV:
160 case utils::OV_UI_MIRROR:
161 case utils::OV_2D_TRUE_UI_MIRROR:
162 case utils::OV_BYPASS_1_LAYER:
163 case utils::OV_BYPASS_2_LAYER:
164 case utils::OV_BYPASS_3_LAYER:
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -0700165 case utils::OV_DUAL_DISP:
Naseer Ahmed29a26812012-06-14 00:56:20 -0700166 if(!mOv->setCrop(d, dest)) {
167 ALOGE("Overlay %s failed", __FUNCTION__);
168 return false;
169 }
170 break;
171 default:
172 OVASSERT(false, "%s Unknown state %d", __FUNCTION__, st);
173 return false;
174 }
175 return true;
176}
177bool Overlay::setPosition(const utils::Dim& d,
178 utils::eDest dest)
179{
180 OVASSERT(mOv,
181 "%s Overlay and Rotator should be init at this point",
182 __FUNCTION__);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700183 utils::eOverlayState st = mState.state();
184 switch (st) {
185 case utils::OV_2D_VIDEO_ON_PANEL:
186 case utils::OV_2D_VIDEO_ON_PANEL_TV:
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -0700187 case utils::OV_2D_VIDEO_ON_TV:
Naseer Ahmed29a26812012-06-14 00:56:20 -0700188 case utils::OV_3D_VIDEO_ON_2D_PANEL:
189 case utils::OV_3D_VIDEO_ON_3D_PANEL:
190 case utils::OV_3D_VIDEO_ON_3D_TV:
191 case utils::OV_3D_VIDEO_ON_2D_PANEL_2D_TV:
192 case utils::OV_UI_MIRROR:
193 case utils::OV_2D_TRUE_UI_MIRROR:
194 case utils::OV_BYPASS_1_LAYER:
195 case utils::OV_BYPASS_2_LAYER:
196 case utils::OV_BYPASS_3_LAYER:
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -0700197 case utils::OV_DUAL_DISP:
Naseer Ahmed29a26812012-06-14 00:56:20 -0700198 if(!mOv->setPosition(d, dest)) {
199 ALOGE("Overlay %s failed", __FUNCTION__);
200 return false;
201 }
202 break;
203 default:
204 OVASSERT(false, "setPos Unknown state %d", st);
205 return false;
206 }
207 return true;
208}
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700209
210bool Overlay::setTransform(const int orient,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700211 utils::eDest dest)
212{
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700213 utils::eTransform transform =
214 static_cast<utils::eTransform>(orient);
215
Naseer Ahmed29a26812012-06-14 00:56:20 -0700216 utils::eOverlayState st = mState.state();
217 switch (st) {
218 case utils::OV_2D_VIDEO_ON_PANEL:
219 case utils::OV_2D_VIDEO_ON_PANEL_TV:
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -0700220 case utils::OV_2D_VIDEO_ON_TV:
Naseer Ahmed29a26812012-06-14 00:56:20 -0700221 case utils::OV_3D_VIDEO_ON_2D_PANEL:
222 case utils::OV_3D_VIDEO_ON_3D_PANEL:
223 case utils::OV_3D_VIDEO_ON_3D_TV:
224 case utils::OV_3D_VIDEO_ON_2D_PANEL_2D_TV:
225 case utils::OV_UI_MIRROR:
226 case utils::OV_2D_TRUE_UI_MIRROR:
227 case utils::OV_BYPASS_1_LAYER:
228 case utils::OV_BYPASS_2_LAYER:
229 case utils::OV_BYPASS_3_LAYER:
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -0700230 case utils::OV_DUAL_DISP:
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700231 if(!mOv->setTransform(transform, dest)) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700232 ALOGE("Overlay %s failed", __FUNCTION__);
233 return false;
234 }
235 break;
236 default:
237 OVASSERT(false, "%s Unknown state %d", __FUNCTION__ , st);
238 return false;
239 }
240 return true;
241}
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700242
Naseer Ahmed29a26812012-06-14 00:56:20 -0700243bool Overlay::setSource(const utils::PipeArgs args[utils::MAX_PIPES],
244 utils::eDest dest)
245{
Naseer Ahmed29a26812012-06-14 00:56:20 -0700246 utils::PipeArgs margs[utils::MAX_PIPES] = {
247 args[0], args[1], args[2] };
248 utils::eOverlayState st = mState.state();
249
250 switch (st) {
251 case utils::OV_CLOSED:
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700252 ALOGE("Overlay %s failed, state is OV_CLOSED, set state first",
253 __FUNCTION__);
254 return false;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700255 break;
256 case utils::OV_2D_VIDEO_ON_PANEL:
257 case utils::OV_3D_VIDEO_ON_2D_PANEL:
258 case utils::OV_UI_MIRROR:
259 case utils::OV_BYPASS_1_LAYER:
260 case utils::OV_BYPASS_2_LAYER:
261 case utils::OV_BYPASS_3_LAYER:
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -0700262 case utils::OV_DUAL_DISP:
Naseer Ahmed29a26812012-06-14 00:56:20 -0700263 break;
264 case utils::OV_3D_VIDEO_ON_3D_PANEL:
265 case utils::OV_3D_VIDEO_ON_3D_TV:
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700266 //TODO set zorder for channel 1 as 1 in 3D pipe
Naseer Ahmed29a26812012-06-14 00:56:20 -0700267 case utils::OV_2D_VIDEO_ON_PANEL_TV:
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -0700268 case utils::OV_2D_VIDEO_ON_TV:
Naseer Ahmed29a26812012-06-14 00:56:20 -0700269 case utils::OV_3D_VIDEO_ON_2D_PANEL_2D_TV:
Naseer Ahmed29a26812012-06-14 00:56:20 -0700270 break;
271 case utils::OV_2D_TRUE_UI_MIRROR:
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700272 // TODO Set zorder, external VG pipe (video) gets 0, RGB pipe (UI) gets 1
Naseer Ahmed29a26812012-06-14 00:56:20 -0700273 break;
274 default:
275 OVASSERT(false, "%s Unknown state %d", __FUNCTION__, st);
276 return false;
277 }
278
279 if (!mOv->setSource(margs, dest)) {
280 ALOGE("Overlay %s failed", __FUNCTION__);
281 return false;
282 }
283
284 return true;
285}
Naseer Ahmed29a26812012-06-14 00:56:20 -0700286
287void Overlay::dump() const
288{
289 OVASSERT(mOv,
290 "%s Overlay and Rotator should be init at this point",
291 __FUNCTION__);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700292 ALOGE("== Dump Overlay start ==");
293 mState.dump();
294 mOv->dump();
295 ALOGE("== Dump Overlay end ==");
296}
297
298void Overlay::setState(utils::eOverlayState s) {
299 mOv = mState.handleEvent(s, mOv);
300}
301
302utils::eOverlayState Overlay::getState() const {
303 return mState.state();
304}
305
306Overlay *Overlay::sInstance = 0;
307
308Overlay* Overlay::getInstance() {
309 if(sInstance == NULL)
310 sInstance = new Overlay();
311 return sInstance;
312}
313
Naseer Ahmed29a26812012-06-14 00:56:20 -0700314} // overlay