blob: 85d61d5b5202bfbfe97f7baf7adb4fecd099844c [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#ifndef OVERLAY_STATE_H
31#define OVERLAY_STATE_H
32
33#include "overlayUtils.h"
34#include "overlayImpl.h"
35#include "overlayRotator.h"
36#include "pipes/overlayGenPipe.h"
Naseer Ahmedf48aef62012-07-20 09:05:53 -070037#include "pipes/overlayVideoExtPipe.h"
Naseer Ahmed29a26812012-06-14 00:56:20 -070038#include "pipes/overlayUIMirrorPipe.h"
39#include "pipes/overlay3DPipe.h"
40
Naseer Ahmed29a26812012-06-14 00:56:20 -070041namespace overlay {
42
43/*
44* Used by Overlay class. Invokes each event
45* */
46
Naseer Ahmed29a26812012-06-14 00:56:20 -070047class OverlayState : utils::NoCopy {
48public:
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -070049 /*ctor*/
Naseer Ahmed29a26812012-06-14 00:56:20 -070050 explicit OverlayState();
51
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -070052 /*dtor*/
Naseer Ahmed29a26812012-06-14 00:56:20 -070053 ~OverlayState();
54
55 /* return current state */
56 utils::eOverlayState state() const;
57
Naseer Ahmed29a26812012-06-14 00:56:20 -070058 /* Hard reset to a new state. If the state is the same
59 * as the current one, it would be a no-op */
60 OverlayImplBase* reset(utils::eOverlayState s);
61
62 /* Caller pass the state to the handleEvent function.
63 * The input is the current OverlayImplBase*, and output is
64 * a pointer to (possibly new) instance of OverlayImplBase
65 * The eFormat can be 2D/3D etc. */
66 OverlayImplBase* handleEvent(utils::eOverlayState s,
67 OverlayImplBase* ov);
68
Naseer Ahmed29a26812012-06-14 00:56:20 -070069 /* Dump */
70 void dump() const;
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -070071
Naseer Ahmed29a26812012-06-14 00:56:20 -070072private:
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -070073
74 /* Transitions from a state to a state. Default behavior is to move from an
75 * old state to CLOSED and from CLOSED to a new state. Any impl wishing to
76 * copy pipes should specialize this call */
77 template<utils::eOverlayState FROM_STATE, utils::eOverlayState TO_STATE>
78 OverlayImplBase* handle_from_to(OverlayImplBase* ov);
79
80 /* Just a convenient intermediate function to bring down the number of
81 * combinations arising from multiple states */
82 template<utils::eOverlayState FROM_STATE>
83 OverlayImplBase* handle_from(utils::eOverlayState toState,
84 OverlayImplBase* ov);
85
86 /* Substitues for partially specialized templated handle functions since the
87 * standard doesn't allow partial specialization of functions */
88 template<utils::eOverlayState FROM_STATE>
89 OverlayImplBase* handle_xxx_to_CLOSED(OverlayImplBase* ov);
90
91 template<utils::eOverlayState TO_STATE>
92 OverlayImplBase* handle_CLOSED_to_xxx(OverlayImplBase* ov);
93
Naseer Ahmed29a26812012-06-14 00:56:20 -070094 /* States here */
95 utils::eOverlayState mState;
96};
97
98//------------------------State Traits --------------------------
99
100// primary has nothing
101template <int STATE> struct StateTraits {};
102
103/*
104 * For 3D_xxx we need channel ID besides the FBx since
105 * get crop/position 3D need that to determine pos/crop
106 * info.
107 * */
108
109template <> struct StateTraits<utils::OV_2D_VIDEO_ON_PANEL>
110{
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -0700111 typedef overlay::GenericPipe<utils::PRIMARY> pipe0; //prim video
Naseer Ahmed29a26812012-06-14 00:56:20 -0700112 typedef overlay::NullPipe pipe1; // place holder
113 typedef overlay::NullPipe pipe2; // place holder
114
115 typedef Rotator rot0;
116 typedef NullRotator rot1;
117 typedef NullRotator rot2;
118
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -0700119 typedef overlay::OverlayImpl<pipe0, pipe1, pipe2> ovimpl;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700120};
121
122template <> struct StateTraits<utils::OV_2D_VIDEO_ON_PANEL_TV>
123{
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -0700124 typedef overlay::GenericPipe<utils::PRIMARY> pipe0; //prim video
125 typedef overlay::VideoExtPipe pipe1; //ext video
126 typedef overlay::GenericPipe<utils::EXTERNAL> pipe2; //ext subtitle
Naseer Ahmed29a26812012-06-14 00:56:20 -0700127
128 typedef Rotator rot0;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700129 typedef Rotator rot1;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700130 typedef NullRotator rot2;
131
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -0700132 typedef overlay::OverlayImpl<pipe0, pipe1, pipe2> ovimpl;
133};
134
135template <> struct StateTraits<utils::OV_2D_VIDEO_ON_TV>
136{
137 typedef overlay::NullPipe pipe0; //nothing on primary with mdp
138 typedef overlay::VideoExtPipe pipe1; //ext video
139 typedef overlay::GenericPipe<utils::EXTERNAL> pipe2; //ext subtitle
140
141 typedef NullRotator rot0;
142 typedef Rotator rot1;
143 typedef NullRotator rot2;
144
145 typedef overlay::OverlayImpl<pipe0, pipe1, pipe2> ovimpl;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700146};
147
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700148template <> struct StateTraits<utils::OV_UI_VIDEO_TV>
149{
150 typedef overlay::GenericPipe<utils::EXTERNAL> pipe0; //ext UI
151 typedef overlay::GenericPipe<utils::EXTERNAL> pipe1; //ext video
152 typedef overlay::NullPipe pipe2;
153
154 typedef Rotator rot0;
155 typedef Rotator rot1;
156 typedef NullRotator rot2;
157
158 typedef overlay::OverlayImpl<pipe0, pipe1, pipe2> ovimpl;
159};
160
Naseer Ahmed29a26812012-06-14 00:56:20 -0700161template <> struct StateTraits<utils::OV_3D_VIDEO_ON_2D_PANEL>
162{
163 typedef overlay::M3DPrimaryPipe<utils::OV_PIPE0> pipe0;
164 typedef overlay::NullPipe pipe1; // place holder
165 typedef overlay::NullPipe pipe2; // place holder
166
167 typedef Rotator rot0;
168 typedef NullRotator rot1;
169 typedef NullRotator rot2;
170
171 typedef overlay::OverlayImpl<pipe0> ovimpl;
172};
173
174template <> struct StateTraits<utils::OV_3D_VIDEO_ON_3D_PANEL>
175{
176 typedef overlay::S3DPrimaryPipe<utils::OV_PIPE0> pipe0;
177 typedef overlay::S3DPrimaryPipe<utils::OV_PIPE1> pipe1;
178 typedef overlay::NullPipe pipe2; // place holder
179
180 typedef Rotator rot0;
181 typedef Rotator rot1;
182 typedef NullRotator rot2;
183
184 typedef overlay::OverlayImpl<pipe0, pipe1> ovimpl;
185};
186
187template <> struct StateTraits<utils::OV_3D_VIDEO_ON_3D_TV>
188{
189 typedef overlay::S3DExtPipe<utils::OV_PIPE0> pipe0;
190 typedef overlay::S3DExtPipe<utils::OV_PIPE1> pipe1;
191 typedef overlay::NullPipe pipe2; // place holder
192
193 typedef NullRotator rot0;
194 typedef NullRotator rot1;
195 typedef NullRotator rot2;
196
197 typedef overlay::OverlayImpl<pipe0, pipe1> ovimpl;
198};
199
200template <> struct StateTraits<utils::OV_3D_VIDEO_ON_2D_PANEL_2D_TV>
201{
202 typedef overlay::M3DPrimaryPipe<utils::OV_PIPE0> pipe0;
203 typedef overlay::M3DExtPipe<utils::OV_PIPE1> pipe1;
204 typedef overlay::NullPipe pipe2; // place holder
205
206 typedef Rotator rot0;
207 typedef NullRotator rot1;
208 typedef NullRotator rot2;
209
210 typedef overlay::OverlayImpl<pipe0, pipe1> ovimpl;
211};
212
213template <> struct StateTraits<utils::OV_UI_MIRROR>
214{
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700215 typedef overlay::GenericPipe<ovutils::EXTERNAL> pipe0; //Ext UI
Naseer Ahmed29a26812012-06-14 00:56:20 -0700216 typedef overlay::NullPipe pipe1; // place holder
217 typedef overlay::NullPipe pipe2; // place holder
218
219 typedef Rotator rot0;
220 typedef NullRotator rot1;
221 typedef NullRotator rot2;
222
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -0700223 typedef overlay::OverlayImpl<pipe0, pipe1, pipe2> ovimpl;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700224};
225
226template <> struct StateTraits<utils::OV_2D_TRUE_UI_MIRROR>
227{
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700228 typedef overlay::GenericPipe<utils::PRIMARY> pipe0; //Vid prim
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700229 typedef overlay::VideoExtPipe pipe1;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700230 typedef overlay::GenericPipe<ovutils::EXTERNAL> pipe2; //EXT UI
Naseer Ahmed29a26812012-06-14 00:56:20 -0700231
232 typedef Rotator rot0;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700233 typedef Rotator rot1;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700234 typedef Rotator rot2;
235
236 typedef overlay::OverlayImpl<pipe0, pipe1, pipe2> ovimpl;
237};
238
239template <> struct StateTraits<utils::OV_BYPASS_1_LAYER>
240{
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700241 typedef overlay::GenericPipe<utils::PRIMARY> pipe0;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700242 typedef overlay::NullPipe pipe1; // place holder
243 typedef overlay::NullPipe pipe2; // place holder
244
245 typedef NullRotator rot0;
246 typedef NullRotator rot1;
247 typedef NullRotator rot2;
248
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -0700249 typedef overlay::OverlayImpl<pipe0, pipe1, pipe2> ovimpl;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700250};
251
252template <> struct StateTraits<utils::OV_BYPASS_2_LAYER>
253{
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700254 typedef overlay::GenericPipe<utils::PRIMARY> pipe0;
255 typedef overlay::GenericPipe<utils::PRIMARY> pipe1;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700256 typedef overlay::NullPipe pipe2; // place holder
257
258 typedef NullRotator rot0;
259 typedef NullRotator rot1;
260 typedef NullRotator rot2;
261
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -0700262 typedef overlay::OverlayImpl<pipe0, pipe1, pipe2> ovimpl;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700263};
264
265template <> struct StateTraits<utils::OV_BYPASS_3_LAYER>
266{
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700267 typedef overlay::GenericPipe<utils::PRIMARY> pipe0;
268 typedef overlay::GenericPipe<utils::PRIMARY> pipe1;
269 typedef overlay::GenericPipe<utils::PRIMARY> pipe2;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700270
271 typedef NullRotator rot0;
272 typedef NullRotator rot1;
273 typedef NullRotator rot2;
274
275 typedef overlay::OverlayImpl<pipe0, pipe1, pipe2> ovimpl;
276};
277
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -0700278template <> struct StateTraits<utils::OV_DUAL_DISP>
279{
280 typedef overlay::GenericPipe<utils::EXTERNAL> pipe0;
Naseer Ahmed4c588a22012-07-31 19:12:17 -0700281 typedef overlay::NullPipe pipe1;
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -0700282 typedef overlay::NullPipe pipe2;
283
284 typedef NullRotator rot0;
285 typedef NullRotator rot1;
286 typedef NullRotator rot2;
287
288 typedef overlay::OverlayImpl<pipe0, pipe1, pipe2> ovimpl;
289};
290
Naseer Ahmed29a26812012-06-14 00:56:20 -0700291
292//------------------------Inlines --------------------------------
293
Naseer Ahmed29a26812012-06-14 00:56:20 -0700294
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -0700295inline OverlayState::OverlayState() : mState(utils::OV_CLOSED){}
Naseer Ahmed29a26812012-06-14 00:56:20 -0700296inline OverlayState::~OverlayState() {}
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -0700297inline utils::eOverlayState OverlayState::state() const { return mState; }
298inline OverlayImplBase* OverlayState::reset(utils::eOverlayState s) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700299 return handleEvent(s, 0);
300}
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -0700301inline void OverlayState::dump() const {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700302 ALOGE("== Dump state %d start/end ==", mState);
303}
304
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -0700305inline OverlayImplBase* OverlayState::handleEvent(utils::eOverlayState toState,
306 OverlayImplBase* ov)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700307{
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -0700308 OverlayImplBase* newov = ov; // at least, we return the same
309 if (mState != toState) {
310 ALOGD_IF(DEBUG_OVERLAY, "%s: state changed %s-->%s",
311 __FUNCTION__, getStateString(mState), getStateString(toState));
312 } else {
313 ALOGD_IF(DEBUG_OVERLAY, "%s: no state change, state=%s",
314 __FUNCTION__, getStateString(toState));
315 return newov;
316 }
317
318 switch(mState)
319 {
320 case utils::OV_CLOSED:
321 newov = handle_from<utils::OV_CLOSED>(toState, ov);
322 break;
323 case utils::OV_2D_VIDEO_ON_PANEL:
324 newov = handle_from<utils::OV_2D_VIDEO_ON_PANEL>(toState, ov);
325 break;
326 case utils::OV_2D_VIDEO_ON_PANEL_TV:
327 newov = handle_from<utils::OV_2D_VIDEO_ON_PANEL_TV>(toState, ov);
328 break;
329 case utils::OV_2D_VIDEO_ON_TV:
330 newov = handle_from<utils::OV_2D_VIDEO_ON_TV>(toState, ov);
331 break;
332 case utils::OV_3D_VIDEO_ON_2D_PANEL:
333 newov = handle_from<utils::OV_3D_VIDEO_ON_2D_PANEL>(toState, ov);
334 break;
335 case utils::OV_3D_VIDEO_ON_3D_PANEL:
336 newov = handle_from<utils::OV_3D_VIDEO_ON_3D_PANEL>(toState, ov);
337 break;
338 case utils::OV_3D_VIDEO_ON_3D_TV:
339 newov = handle_from<utils::OV_3D_VIDEO_ON_3D_TV>(toState, ov);
340 break;
341 case utils::OV_3D_VIDEO_ON_2D_PANEL_2D_TV:
342 newov = handle_from<utils::OV_3D_VIDEO_ON_2D_PANEL_2D_TV>(toState,
343 ov);
344 break;
345 case utils::OV_UI_MIRROR:
346 newov = handle_from<utils::OV_UI_MIRROR>(toState, ov);
347 break;
348 case utils::OV_2D_TRUE_UI_MIRROR:
349 newov = handle_from<utils::OV_2D_TRUE_UI_MIRROR>(toState, ov);
350 break;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700351 case utils::OV_UI_VIDEO_TV:
352 newov = handle_from<utils::OV_UI_VIDEO_TV>(toState, ov);
353 break;
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -0700354 case utils::OV_BYPASS_1_LAYER:
355 newov = handle_from<utils::OV_BYPASS_1_LAYER>(toState, ov);
356 break;
357 case utils::OV_BYPASS_2_LAYER:
358 newov = handle_from<utils::OV_BYPASS_2_LAYER>(toState, ov);
359 break;
360 case utils::OV_BYPASS_3_LAYER:
361 newov = handle_from<utils::OV_BYPASS_3_LAYER>(toState, ov);
362 break;
363 case utils::OV_DUAL_DISP:
364 newov = handle_from<utils::OV_DUAL_DISP>(toState, ov);
365 break;
366 default:
367 OVASSERT(1 == 0, "%s: unknown state = %d", __FUNCTION__, mState);
368
369 }
370 return newov;
371}
372
373template <utils::eOverlayState FROM_STATE>
374inline OverlayImplBase* OverlayState::handle_from(utils::eOverlayState toState,
375 OverlayImplBase* ov) {
376
377 switch(toState)
378 {
379 case utils::OV_CLOSED:
380 ov = handle_xxx_to_CLOSED<FROM_STATE>(ov);
381 break;
382 case utils::OV_2D_VIDEO_ON_PANEL:
383 ov = handle_from_to<FROM_STATE, utils::OV_2D_VIDEO_ON_PANEL>(ov);
384 break;
385 case utils::OV_2D_VIDEO_ON_PANEL_TV:
386 ov = handle_from_to<FROM_STATE, utils::OV_2D_VIDEO_ON_PANEL_TV>(ov);
387 break;
388 case utils::OV_2D_VIDEO_ON_TV:
389 ov = handle_from_to<FROM_STATE, utils::OV_2D_VIDEO_ON_TV>(ov);
390 break;
391 case utils::OV_3D_VIDEO_ON_2D_PANEL:
392 ov = handle_from_to<FROM_STATE, utils::OV_3D_VIDEO_ON_2D_PANEL>(ov);
393 break;
394 case utils::OV_3D_VIDEO_ON_3D_PANEL:
395 ov = handle_from_to<FROM_STATE, utils::OV_3D_VIDEO_ON_3D_PANEL>(ov);
396 break;
397 case utils::OV_3D_VIDEO_ON_3D_TV:
398 ov = handle_from_to<FROM_STATE, utils::OV_3D_VIDEO_ON_3D_TV>(ov);
399 break;
400 case utils::OV_3D_VIDEO_ON_2D_PANEL_2D_TV:
401 ov = handle_from_to<FROM_STATE,
402 utils::OV_3D_VIDEO_ON_2D_PANEL_2D_TV>(ov);
403 break;
404 case utils::OV_UI_MIRROR:
405 ov = handle_from_to<FROM_STATE, utils::OV_UI_MIRROR>(ov);
406 break;
407 case utils::OV_2D_TRUE_UI_MIRROR:
408 ov = handle_from_to<FROM_STATE, utils::OV_2D_TRUE_UI_MIRROR>(ov);
409 break;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700410 case utils::OV_UI_VIDEO_TV:
411 ov = handle_from_to<FROM_STATE, utils::OV_UI_VIDEO_TV>(ov);
412 break;
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -0700413 case utils::OV_BYPASS_1_LAYER:
414 ov = handle_from_to<FROM_STATE, utils::OV_BYPASS_1_LAYER>(ov);
415 break;
416 case utils::OV_BYPASS_2_LAYER:
417 ov = handle_from_to<FROM_STATE, utils::OV_BYPASS_2_LAYER>(ov);
418 break;
419 case utils::OV_BYPASS_3_LAYER:
420 ov = handle_from_to<FROM_STATE, utils::OV_BYPASS_3_LAYER>(ov);
421 break;
422 case utils::OV_DUAL_DISP:
423 ov = handle_from_to<FROM_STATE, utils::OV_DUAL_DISP>(ov);
424 break;
425 default:
426 OVASSERT(1 == 0, "%s: unknown state = %d", __FUNCTION__, toState);
427 }
428 mState = toState;
429 return ov;
430}
431
432
433/* Transition default from any to any. Does in two steps.
434 * Moves from OLD to CLOSED and then from CLOSED to NEW
435 */
436template<utils::eOverlayState FROM_STATE, utils::eOverlayState TO_STATE>
437inline OverlayImplBase* OverlayState::handle_from_to(OverlayImplBase* ov) {
438 handle_xxx_to_CLOSED<FROM_STATE>(ov);
439 return handle_CLOSED_to_xxx<TO_STATE>(ov);
440}
441
442//---------------Specializations-------------
443
444
445/* Transition from CLOSED to ANY */
446template<utils::eOverlayState TO_STATE>
447inline OverlayImplBase* OverlayState::handle_CLOSED_to_xxx(
448 OverlayImplBase* /*ignored*/) {
449 //If going from CLOSED to CLOSED, nothing to do.
450 if(TO_STATE == utils::OV_CLOSED) return NULL;
451 ALOGD("FROM_STATE = %s TO_STATE = %s",
452 utils::getStateString(utils::OV_CLOSED),
453 utils::getStateString(TO_STATE));
454 OverlayImplBase* ov = new typename StateTraits<TO_STATE>::ovimpl;
455 RotatorBase* rot0 = new typename StateTraits<TO_STATE>::rot0;
456 RotatorBase* rot1 = new typename StateTraits<TO_STATE>::rot1;
457 RotatorBase* rot2 = new typename StateTraits<TO_STATE>::rot2;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700458 if(!ov->init(rot0, rot1, rot2)) {
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -0700459 ALOGE("Overlay failed to init in state %d", TO_STATE);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700460 return 0;
461 }
462 return ov;
463}
464
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -0700465/* Transition from ANY to CLOSED */
466template<utils::eOverlayState FROM_STATE>
467inline OverlayImplBase* OverlayState::handle_xxx_to_CLOSED(OverlayImplBase* ov)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700468{
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -0700469 //If going from CLOSED to CLOSED, nothing to do.
470 if(FROM_STATE == utils::OV_CLOSED) return NULL;
471 ALOGD("FROM_STATE = %s TO_STATE = %s",
472 utils::getStateString(FROM_STATE),
473 utils::getStateString(utils::OV_CLOSED));
Naseer Ahmed29a26812012-06-14 00:56:20 -0700474 OVASSERT(ov, "%s: ov is null", __FUNCTION__);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700475 if(!ov->close()) {
476 ALOGE("%s: Failed to ov close", __FUNCTION__);
477 }
478 delete ov;
479 ov = 0;
480 return 0;
481}
482
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -0700483/* Transition from 2D_VIDEO_ON_PANEL to 2D_VIDEO_ON_PANEL_TV */
484template<>
485inline OverlayImplBase* OverlayState::handle_from_to<
486 utils::OV_2D_VIDEO_ON_PANEL,
487 utils::OV_2D_VIDEO_ON_PANEL_TV>(
488 OverlayImplBase* ov) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700489 OVASSERT(ov, "%s: ov is null", __FUNCTION__);
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -0700490 ALOGD("FROM_STATE = %s TO_STATE = %s",
491 utils::getStateString(utils::OV_2D_VIDEO_ON_PANEL),
492 utils::getStateString(utils::OV_2D_VIDEO_ON_PANEL_TV));
493 // Create new ovimpl based on new state
494 typedef StateTraits<utils::OV_2D_VIDEO_ON_PANEL_TV> NewState;
495 OverlayImplBase* newov = new NewState::ovimpl;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700496
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -0700497 //copy pipe0/rot0 (primary video)
498 newov->copyOvPipe(ov, utils::OV_PIPE0);
499 //close old pipe1, create new pipe1
500 ov->closePipe(utils::OV_PIPE1);
501 RotatorBase* rot1 = new NewState::rot1;
502 newov->initPipe(rot1, utils::OV_PIPE1);
503 //close old pipe2, create new pipe2
504 ov->closePipe(utils::OV_PIPE2);
505 RotatorBase* rot2 = new NewState::rot2;
506 newov->initPipe(rot2, utils::OV_PIPE2);
507 // All pipes are copied or deleted so no more need for previous ovimpl
508 delete ov;
509 ov = 0;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700510 return newov;
511}
512
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -0700513/* Transition from 2D_VIDEO_ON_PANEL_TV to 2D_VIDEO_ON_PANEL */
514template<>
515inline OverlayImplBase* OverlayState::handle_from_to<
516 utils::OV_2D_VIDEO_ON_PANEL_TV,
517 utils::OV_2D_VIDEO_ON_PANEL>(
518 OverlayImplBase* ov) {
519 OVASSERT(ov, "%s: ov is null", __FUNCTION__);
520 ALOGD("FROM_STATE = %s TO_STATE = %s",
521 utils::getStateString(utils::OV_2D_VIDEO_ON_PANEL_TV),
522 utils::getStateString(utils::OV_2D_VIDEO_ON_PANEL));
Naseer Ahmed29a26812012-06-14 00:56:20 -0700523
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -0700524 // Create new ovimpl based on new state
525 typedef StateTraits<utils::OV_2D_VIDEO_ON_PANEL> NewState;
526 OverlayImplBase* newov = new NewState::ovimpl;
527
528 //copy pipe0/rot0 (primary video)
529 newov->copyOvPipe(ov, utils::OV_PIPE0);
530 //close old pipe1, create new pipe1
531 ov->closePipe(utils::OV_PIPE1);
532 RotatorBase* rot1 = new NewState::rot1;
533 newov->initPipe(rot1, utils::OV_PIPE1);
534 //close old pipe2, create new pipe2
535 ov->closePipe(utils::OV_PIPE2);
536 RotatorBase* rot2 = new NewState::rot2;
537 newov->initPipe(rot2, utils::OV_PIPE2);
538 // All pipes are copied or deleted so no more need for previous ovimpl
539 delete ov;
540 ov = 0;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700541 return newov;
542}
543
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -0700544/* Transition from 2D_VIDEO_ON_PANEL_TV to 2D_VIDEO_ON_TV */
545template<>
546inline OverlayImplBase* OverlayState::handle_from_to<
547 utils::OV_2D_VIDEO_ON_PANEL_TV,
548 utils::OV_2D_VIDEO_ON_TV>(
549 OverlayImplBase* ov) {
550 OVASSERT(ov, "%s: ov is null", __FUNCTION__);
551 ALOGD("FROM_STATE = %s TO_STATE = %s",
552 utils::getStateString(utils::OV_2D_VIDEO_ON_PANEL_TV),
553 utils::getStateString(utils::OV_2D_VIDEO_ON_TV));
554
555 // Create new ovimpl based on new state
556 typedef StateTraits<utils::OV_2D_VIDEO_ON_TV> NewState;
557 OverlayImplBase* newov = new NewState::ovimpl;
558
559 //close old pipe0, create new pipe0
560 ov->closePipe(utils::OV_PIPE0);
561 RotatorBase* rot0 = new NewState::rot0;
562 newov->initPipe(rot0, utils::OV_PIPE0);
563 //copy pipe1/rot1 (ext video)
564 newov->copyOvPipe(ov, utils::OV_PIPE1);
565 //copy pipe2/rot2 (ext cc)
566 newov->copyOvPipe(ov, utils::OV_PIPE2);
567 // All pipes are copied or deleted so no more need for previous ovimpl
568 delete ov;
569 ov = 0;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700570 return newov;
571}
572
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -0700573/* Transition from 2D_VIDEO_ON_TV to 2D_VIDEO_ON_PANEL_TV */
574template<>
575inline OverlayImplBase* OverlayState::handle_from_to<
576 utils::OV_2D_VIDEO_ON_TV,
577 utils::OV_2D_VIDEO_ON_PANEL_TV>(
578 OverlayImplBase* ov) {
579 OVASSERT(ov, "%s: ov is null", __FUNCTION__);
580 ALOGD("FROM_STATE = %s TO_STATE = %s",
581 utils::getStateString(utils::OV_2D_VIDEO_ON_TV),
582 utils::getStateString(utils::OV_2D_VIDEO_ON_PANEL_TV));
583
584 // Create new ovimpl based on new state
585 typedef StateTraits<utils::OV_2D_VIDEO_ON_PANEL_TV> NewState;
586 OverlayImplBase* newov = new NewState::ovimpl;
587
588 //close old pipe0, create new pipe0
589 ov->closePipe(utils::OV_PIPE0);
590 RotatorBase* rot0 = new NewState::rot0;
591 newov->initPipe(rot0, utils::OV_PIPE0);
592 //copy pipe1/rot1 (ext video)
593 newov->copyOvPipe(ov, utils::OV_PIPE1);
594 //copy pipe2/rot2 (ext cc)
595 newov->copyOvPipe(ov, utils::OV_PIPE2);
596 // All pipes are copied or deleted so no more need for previous ovimpl
597 delete ov;
598 ov = 0;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700599 return newov;
600}
601
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700602/* Transition from OV_UI_MIRROR to OV_UI_VIDEO_TV */
603template<>
604inline OverlayImplBase* OverlayState::handle_from_to<
605 utils::OV_UI_MIRROR,
606 utils::OV_UI_VIDEO_TV>(
607 OverlayImplBase* ov) {
608 OVASSERT(ov, "%s: ov is null", __FUNCTION__);
609 ALOGD("FROM_STATE = %s TO_STATE = %s",
610 utils::getStateString(utils::OV_UI_MIRROR),
611 utils::getStateString(utils::OV_UI_VIDEO_TV));
612
613 // Create new ovimpl based on new state
614 typedef StateTraits<utils::OV_UI_VIDEO_TV> NewState;
615 OverlayImplBase* newov = new NewState::ovimpl;
616
617 //copy pipe0/rot0 (ext video)
618 newov->copyOvPipe(ov, utils::OV_PIPE0);
619
620 ov->closePipe(utils::OV_PIPE1);
621 RotatorBase* rot1 = new NewState::rot1;
622 newov->initPipe(rot1, utils::OV_PIPE1);
623
624 ov->closePipe(utils::OV_PIPE2);
625 RotatorBase* rot2 = new NewState::rot2;
626 newov->initPipe(rot2, utils::OV_PIPE2);
627
628 // All pipes are copied or deleted so no more need for previous ovimpl
629 delete ov;
630 ov = 0;
631 return newov;
632}
633
634/* Transition from OV_UI_VIDEO_TV to OV_UI_MIRROR */
635template<>
636inline OverlayImplBase* OverlayState::handle_from_to<
637 utils::OV_UI_VIDEO_TV,
638 utils::OV_UI_MIRROR>(
639 OverlayImplBase* ov) {
640 OVASSERT(ov, "%s: ov is null", __FUNCTION__);
641 ALOGD("FROM_STATE = %s TO_STATE = %s",
642 utils::getStateString(utils::OV_UI_VIDEO_TV),
643 utils::getStateString(utils::OV_UI_MIRROR));
644
645 // Create new ovimpl based on new state
646 typedef StateTraits<utils::OV_UI_MIRROR> NewState;
647 OverlayImplBase* newov = new NewState::ovimpl;
648
649 //copy pipe0/rot0 (ext video)
650 newov->copyOvPipe(ov, utils::OV_PIPE0);
651
652 ov->closePipe(utils::OV_PIPE1);
653 RotatorBase* rot1 = new NewState::rot1;
654 newov->initPipe(rot1, utils::OV_PIPE1);
655
656 ov->closePipe(utils::OV_PIPE2);
657 RotatorBase* rot2 = new NewState::rot2;
658 newov->initPipe(rot2, utils::OV_PIPE2);
659
660 // All pipes are copied or deleted so no more need for previous ovimpl
661 delete ov;
662 ov = 0;
663 return newov;
664}
Naseer Ahmed29a26812012-06-14 00:56:20 -0700665} // overlay
666
667#endif // OVERLAY_STATE_H