blob: a05a307eb9850f27e59b512d273a4d9f43985840 [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:
57 case utils::OV_3D_VIDEO_ON_2D_PANEL:
58 case utils::OV_3D_VIDEO_ON_3D_PANEL:
59 case utils::OV_3D_VIDEO_ON_3D_TV:
60 case utils::OV_3D_VIDEO_ON_2D_PANEL_2D_TV:
61 case utils::OV_UI_MIRROR:
62 case utils::OV_2D_TRUE_UI_MIRROR:
63 case utils::OV_BYPASS_1_LAYER:
64 case utils::OV_BYPASS_2_LAYER:
65 case utils::OV_BYPASS_3_LAYER:
66 if(!mOv->commit(dest)) {
67 ALOGE("Overlay %s failed", __FUNCTION__);
68 return false;
69 }
70 break;
71 default:
72 OVASSERT(false, "%s Unknown state %d", __FUNCTION__, st);
73 return false;
74 }
75 return true;
76}
77
Naseer Ahmedf48aef62012-07-20 09:05:53 -070078bool Overlay::queueBuffer(int fd, uint32_t offset,
Naseer Ahmed29a26812012-06-14 00:56:20 -070079 utils::eDest dest)
80{
81 OVASSERT(mOv,
82 "%s Overlay and Rotator should be init at this point",
83 __FUNCTION__);
Naseer Ahmed29a26812012-06-14 00:56:20 -070084 utils::eOverlayState st = mState.state();
85 switch (st) {
86 case utils::OV_2D_VIDEO_ON_PANEL:
87 case utils::OV_2D_VIDEO_ON_PANEL_TV:
88 case utils::OV_3D_VIDEO_ON_2D_PANEL:
89 case utils::OV_3D_VIDEO_ON_3D_PANEL:
90 case utils::OV_3D_VIDEO_ON_3D_TV:
91 case utils::OV_3D_VIDEO_ON_2D_PANEL_2D_TV:
92 case utils::OV_UI_MIRROR:
93 case utils::OV_2D_TRUE_UI_MIRROR:
94 case utils::OV_BYPASS_1_LAYER:
95 case utils::OV_BYPASS_2_LAYER:
96 case utils::OV_BYPASS_3_LAYER:
Naseer Ahmedf48aef62012-07-20 09:05:53 -070097 if(!mOv->queueBuffer(fd, offset, dest)) {
Naseer Ahmed29a26812012-06-14 00:56:20 -070098 ALOGE("Overlay %s failed", __FUNCTION__);
99 return false;
100 }
101 break;
102 default:
103 OVASSERT(false, "%s Unknown state %d", __FUNCTION__, st);
104 return false;
105 }
106 return true;
107}
108
109bool Overlay::waitForVsync(utils::eDest dest)
110{
111 OVASSERT(mOv,
112 "%s Overlay and Rotator should be init at this point",
113 __FUNCTION__);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700114 utils::eOverlayState st = mState.state();
115 switch (st) {
116 case utils::OV_2D_VIDEO_ON_PANEL:
117 case utils::OV_2D_VIDEO_ON_PANEL_TV:
118 case utils::OV_3D_VIDEO_ON_2D_PANEL:
119 case utils::OV_3D_VIDEO_ON_3D_PANEL:
120 case utils::OV_3D_VIDEO_ON_3D_TV:
121 case utils::OV_3D_VIDEO_ON_2D_PANEL_2D_TV:
122 case utils::OV_UI_MIRROR:
123 case utils::OV_2D_TRUE_UI_MIRROR:
124 case utils::OV_BYPASS_1_LAYER:
125 case utils::OV_BYPASS_2_LAYER:
126 case utils::OV_BYPASS_3_LAYER:
127 if(!mOv->waitForVsync(dest)) {
128 ALOGE("Overlay %s failed", __FUNCTION__);
129 return false;
130 }
131 break;
132 default:
133 OVASSERT(false, "%s Unknown state %d", __FUNCTION__, st);
134 return false;
135 }
136 return true;
137}
138
139bool Overlay::setCrop(const utils::Dim& d,
140 utils::eDest dest)
141{
142 OVASSERT(mOv,
143 "%s Overlay and Rotator should be init at this point",
144 __FUNCTION__);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700145 utils::eOverlayState st = mState.state();
146 switch (st) {
147 case utils::OV_2D_VIDEO_ON_PANEL:
148 case utils::OV_2D_VIDEO_ON_PANEL_TV:
149 case utils::OV_3D_VIDEO_ON_2D_PANEL:
150 case utils::OV_3D_VIDEO_ON_3D_PANEL:
151 case utils::OV_3D_VIDEO_ON_3D_TV:
152 case utils::OV_3D_VIDEO_ON_2D_PANEL_2D_TV:
153 case utils::OV_UI_MIRROR:
154 case utils::OV_2D_TRUE_UI_MIRROR:
155 case utils::OV_BYPASS_1_LAYER:
156 case utils::OV_BYPASS_2_LAYER:
157 case utils::OV_BYPASS_3_LAYER:
158 if(!mOv->setCrop(d, dest)) {
159 ALOGE("Overlay %s failed", __FUNCTION__);
160 return false;
161 }
162 break;
163 default:
164 OVASSERT(false, "%s Unknown state %d", __FUNCTION__, st);
165 return false;
166 }
167 return true;
168}
169bool Overlay::setPosition(const utils::Dim& d,
170 utils::eDest dest)
171{
172 OVASSERT(mOv,
173 "%s Overlay and Rotator should be init at this point",
174 __FUNCTION__);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700175 utils::eOverlayState st = mState.state();
176 switch (st) {
177 case utils::OV_2D_VIDEO_ON_PANEL:
178 case utils::OV_2D_VIDEO_ON_PANEL_TV:
179 case utils::OV_3D_VIDEO_ON_2D_PANEL:
180 case utils::OV_3D_VIDEO_ON_3D_PANEL:
181 case utils::OV_3D_VIDEO_ON_3D_TV:
182 case utils::OV_3D_VIDEO_ON_2D_PANEL_2D_TV:
183 case utils::OV_UI_MIRROR:
184 case utils::OV_2D_TRUE_UI_MIRROR:
185 case utils::OV_BYPASS_1_LAYER:
186 case utils::OV_BYPASS_2_LAYER:
187 case utils::OV_BYPASS_3_LAYER:
188 if(!mOv->setPosition(d, dest)) {
189 ALOGE("Overlay %s failed", __FUNCTION__);
190 return false;
191 }
192 break;
193 default:
194 OVASSERT(false, "setPos Unknown state %d", st);
195 return false;
196 }
197 return true;
198}
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700199
200bool Overlay::setTransform(const int orient,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700201 utils::eDest dest)
202{
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700203 utils::eTransform transform =
204 static_cast<utils::eTransform>(orient);
205
Naseer Ahmed29a26812012-06-14 00:56:20 -0700206 utils::eOverlayState st = mState.state();
207 switch (st) {
208 case utils::OV_2D_VIDEO_ON_PANEL:
209 case utils::OV_2D_VIDEO_ON_PANEL_TV:
210 case utils::OV_3D_VIDEO_ON_2D_PANEL:
211 case utils::OV_3D_VIDEO_ON_3D_PANEL:
212 case utils::OV_3D_VIDEO_ON_3D_TV:
213 case utils::OV_3D_VIDEO_ON_2D_PANEL_2D_TV:
214 case utils::OV_UI_MIRROR:
215 case utils::OV_2D_TRUE_UI_MIRROR:
216 case utils::OV_BYPASS_1_LAYER:
217 case utils::OV_BYPASS_2_LAYER:
218 case utils::OV_BYPASS_3_LAYER:
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700219 if(!mOv->setTransform(transform, dest)) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700220 ALOGE("Overlay %s failed", __FUNCTION__);
221 return false;
222 }
223 break;
224 default:
225 OVASSERT(false, "%s Unknown state %d", __FUNCTION__ , st);
226 return false;
227 }
228 return true;
229}
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700230
Naseer Ahmed29a26812012-06-14 00:56:20 -0700231bool Overlay::setSource(const utils::PipeArgs args[utils::MAX_PIPES],
232 utils::eDest dest)
233{
Naseer Ahmed29a26812012-06-14 00:56:20 -0700234 utils::PipeArgs margs[utils::MAX_PIPES] = {
235 args[0], args[1], args[2] };
236 utils::eOverlayState st = mState.state();
237
238 switch (st) {
239 case utils::OV_CLOSED:
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700240 ALOGE("Overlay %s failed, state is OV_CLOSED, set state first",
241 __FUNCTION__);
242 return false;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700243 break;
244 case utils::OV_2D_VIDEO_ON_PANEL:
245 case utils::OV_3D_VIDEO_ON_2D_PANEL:
246 case utils::OV_UI_MIRROR:
247 case utils::OV_BYPASS_1_LAYER:
248 case utils::OV_BYPASS_2_LAYER:
249 case utils::OV_BYPASS_3_LAYER:
Naseer Ahmed29a26812012-06-14 00:56:20 -0700250 break;
251 case utils::OV_3D_VIDEO_ON_3D_PANEL:
252 case utils::OV_3D_VIDEO_ON_3D_TV:
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700253 //TODO set zorder for channel 1 as 1 in 3D pipe
Naseer Ahmed29a26812012-06-14 00:56:20 -0700254 case utils::OV_2D_VIDEO_ON_PANEL_TV:
255 case utils::OV_3D_VIDEO_ON_2D_PANEL_2D_TV:
Naseer Ahmed29a26812012-06-14 00:56:20 -0700256 break;
257 case utils::OV_2D_TRUE_UI_MIRROR:
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700258 // TODO Set zorder, external VG pipe (video) gets 0, RGB pipe (UI) gets 1
Naseer Ahmed29a26812012-06-14 00:56:20 -0700259 break;
260 default:
261 OVASSERT(false, "%s Unknown state %d", __FUNCTION__, st);
262 return false;
263 }
264
265 if (!mOv->setSource(margs, dest)) {
266 ALOGE("Overlay %s failed", __FUNCTION__);
267 return false;
268 }
269
270 return true;
271}
Naseer Ahmed29a26812012-06-14 00:56:20 -0700272
273void Overlay::dump() const
274{
275 OVASSERT(mOv,
276 "%s Overlay and Rotator should be init at this point",
277 __FUNCTION__);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700278 ALOGE("== Dump Overlay start ==");
279 mState.dump();
280 mOv->dump();
281 ALOGE("== Dump Overlay end ==");
282}
283
284void Overlay::setState(utils::eOverlayState s) {
285 mOv = mState.handleEvent(s, mOv);
286}
287
288utils::eOverlayState Overlay::getState() const {
289 return mState.state();
290}
291
292Overlay *Overlay::sInstance = 0;
293
294Overlay* Overlay::getInstance() {
295 if(sInstance == NULL)
296 sInstance = new Overlay();
297 return sInstance;
298}
299
Naseer Ahmed29a26812012-06-14 00:56:20 -0700300} // overlay