Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1 | /* |
| 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 Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 37 | #include "pipes/overlayVideoExtPipe.h" |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 38 | #include "pipes/overlayUIMirrorPipe.h" |
| 39 | #include "pipes/overlay3DPipe.h" |
| 40 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 41 | namespace overlay { |
| 42 | |
| 43 | /* |
| 44 | * Used by Overlay class. Invokes each event |
| 45 | * */ |
| 46 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 47 | class OverlayState : utils::NoCopy { |
| 48 | public: |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 49 | /*ctor*/ |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 50 | explicit OverlayState(); |
| 51 | |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 52 | /*dtor*/ |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 53 | ~OverlayState(); |
| 54 | |
| 55 | /* return current state */ |
| 56 | utils::eOverlayState state() const; |
| 57 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 58 | /* 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 Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 69 | /* Dump */ |
| 70 | void dump() const; |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 71 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 72 | private: |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 73 | |
| 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 Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 94 | /* States here */ |
| 95 | utils::eOverlayState mState; |
| 96 | }; |
| 97 | |
| 98 | //------------------------State Traits -------------------------- |
| 99 | |
| 100 | // primary has nothing |
| 101 | template <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 | |
| 109 | template <> struct StateTraits<utils::OV_2D_VIDEO_ON_PANEL> |
| 110 | { |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 111 | typedef overlay::GenericPipe<utils::PRIMARY> pipe0; //prim video |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 112 | 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 Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 119 | typedef overlay::OverlayImpl<pipe0, pipe1, pipe2> ovimpl; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 120 | }; |
| 121 | |
| 122 | template <> struct StateTraits<utils::OV_2D_VIDEO_ON_PANEL_TV> |
| 123 | { |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 124 | 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 Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 127 | |
| 128 | typedef Rotator rot0; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 129 | typedef Rotator rot1; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 130 | typedef NullRotator rot2; |
| 131 | |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 132 | typedef overlay::OverlayImpl<pipe0, pipe1, pipe2> ovimpl; |
| 133 | }; |
| 134 | |
| 135 | template <> 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 Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 146 | }; |
| 147 | |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 148 | template <> 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 Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 161 | template <> 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 | |
| 174 | template <> 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 | |
| 187 | template <> 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 | |
| 200 | template <> 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 | |
| 213 | template <> struct StateTraits<utils::OV_UI_MIRROR> |
| 214 | { |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 215 | typedef overlay::GenericPipe<ovutils::EXTERNAL> pipe0; //Ext UI |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 216 | 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 Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 223 | typedef overlay::OverlayImpl<pipe0, pipe1, pipe2> ovimpl; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 224 | }; |
| 225 | |
| 226 | template <> struct StateTraits<utils::OV_2D_TRUE_UI_MIRROR> |
| 227 | { |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 228 | typedef overlay::GenericPipe<utils::PRIMARY> pipe0; //Vid prim |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 229 | typedef overlay::VideoExtPipe pipe1; |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 230 | typedef overlay::GenericPipe<ovutils::EXTERNAL> pipe2; //EXT UI |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 231 | |
| 232 | typedef Rotator rot0; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 233 | typedef Rotator rot1; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 234 | typedef Rotator rot2; |
| 235 | |
| 236 | typedef overlay::OverlayImpl<pipe0, pipe1, pipe2> ovimpl; |
| 237 | }; |
| 238 | |
| 239 | template <> struct StateTraits<utils::OV_BYPASS_1_LAYER> |
| 240 | { |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 241 | typedef overlay::GenericPipe<utils::PRIMARY> pipe0; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 242 | 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 Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 249 | typedef overlay::OverlayImpl<pipe0, pipe1, pipe2> ovimpl; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 250 | }; |
| 251 | |
| 252 | template <> struct StateTraits<utils::OV_BYPASS_2_LAYER> |
| 253 | { |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 254 | typedef overlay::GenericPipe<utils::PRIMARY> pipe0; |
| 255 | typedef overlay::GenericPipe<utils::PRIMARY> pipe1; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 256 | typedef overlay::NullPipe pipe2; // place holder |
| 257 | |
| 258 | typedef NullRotator rot0; |
| 259 | typedef NullRotator rot1; |
| 260 | typedef NullRotator rot2; |
| 261 | |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 262 | typedef overlay::OverlayImpl<pipe0, pipe1, pipe2> ovimpl; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 263 | }; |
| 264 | |
| 265 | template <> struct StateTraits<utils::OV_BYPASS_3_LAYER> |
| 266 | { |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 267 | typedef overlay::GenericPipe<utils::PRIMARY> pipe0; |
| 268 | typedef overlay::GenericPipe<utils::PRIMARY> pipe1; |
| 269 | typedef overlay::GenericPipe<utils::PRIMARY> pipe2; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 270 | |
| 271 | typedef NullRotator rot0; |
| 272 | typedef NullRotator rot1; |
| 273 | typedef NullRotator rot2; |
| 274 | |
| 275 | typedef overlay::OverlayImpl<pipe0, pipe1, pipe2> ovimpl; |
| 276 | }; |
| 277 | |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 278 | template <> struct StateTraits<utils::OV_DUAL_DISP> |
| 279 | { |
| 280 | typedef overlay::GenericPipe<utils::EXTERNAL> pipe0; |
Naseer Ahmed | 4c588a2 | 2012-07-31 19:12:17 -0700 | [diff] [blame] | 281 | typedef overlay::NullPipe pipe1; |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 282 | 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 Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 291 | |
| 292 | //------------------------Inlines -------------------------------- |
| 293 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 294 | |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 295 | inline OverlayState::OverlayState() : mState(utils::OV_CLOSED){} |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 296 | inline OverlayState::~OverlayState() {} |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 297 | inline utils::eOverlayState OverlayState::state() const { return mState; } |
| 298 | inline OverlayImplBase* OverlayState::reset(utils::eOverlayState s) { |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 299 | return handleEvent(s, 0); |
| 300 | } |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 301 | inline void OverlayState::dump() const { |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 302 | ALOGE("== Dump state %d start/end ==", mState); |
| 303 | } |
| 304 | |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 305 | inline OverlayImplBase* OverlayState::handleEvent(utils::eOverlayState toState, |
| 306 | OverlayImplBase* ov) |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 307 | { |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 308 | 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 Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 351 | case utils::OV_UI_VIDEO_TV: |
| 352 | newov = handle_from<utils::OV_UI_VIDEO_TV>(toState, ov); |
| 353 | break; |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 354 | 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 | |
| 373 | template <utils::eOverlayState FROM_STATE> |
| 374 | inline 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 Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 410 | case utils::OV_UI_VIDEO_TV: |
| 411 | ov = handle_from_to<FROM_STATE, utils::OV_UI_VIDEO_TV>(ov); |
| 412 | break; |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 413 | 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 | */ |
| 436 | template<utils::eOverlayState FROM_STATE, utils::eOverlayState TO_STATE> |
| 437 | inline 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 */ |
| 446 | template<utils::eOverlayState TO_STATE> |
| 447 | inline 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 Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 458 | if(!ov->init(rot0, rot1, rot2)) { |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 459 | ALOGE("Overlay failed to init in state %d", TO_STATE); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 460 | return 0; |
| 461 | } |
| 462 | return ov; |
| 463 | } |
| 464 | |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 465 | /* Transition from ANY to CLOSED */ |
| 466 | template<utils::eOverlayState FROM_STATE> |
| 467 | inline OverlayImplBase* OverlayState::handle_xxx_to_CLOSED(OverlayImplBase* ov) |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 468 | { |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 469 | //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 Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 474 | OVASSERT(ov, "%s: ov is null", __FUNCTION__); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 475 | if(!ov->close()) { |
| 476 | ALOGE("%s: Failed to ov close", __FUNCTION__); |
| 477 | } |
| 478 | delete ov; |
| 479 | ov = 0; |
| 480 | return 0; |
| 481 | } |
| 482 | |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 483 | /* Transition from 2D_VIDEO_ON_PANEL to 2D_VIDEO_ON_PANEL_TV */ |
| 484 | template<> |
| 485 | inline OverlayImplBase* OverlayState::handle_from_to< |
| 486 | utils::OV_2D_VIDEO_ON_PANEL, |
| 487 | utils::OV_2D_VIDEO_ON_PANEL_TV>( |
| 488 | OverlayImplBase* ov) { |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 489 | OVASSERT(ov, "%s: ov is null", __FUNCTION__); |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 490 | 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 Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 496 | |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 497 | //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 Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 510 | return newov; |
| 511 | } |
| 512 | |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 513 | /* Transition from 2D_VIDEO_ON_PANEL_TV to 2D_VIDEO_ON_PANEL */ |
| 514 | template<> |
| 515 | inline 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 Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 523 | |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 524 | // 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 Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 541 | return newov; |
| 542 | } |
| 543 | |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 544 | /* Transition from 2D_VIDEO_ON_PANEL_TV to 2D_VIDEO_ON_TV */ |
| 545 | template<> |
| 546 | inline 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 Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 570 | return newov; |
| 571 | } |
| 572 | |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 573 | /* Transition from 2D_VIDEO_ON_TV to 2D_VIDEO_ON_PANEL_TV */ |
| 574 | template<> |
| 575 | inline 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 Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 599 | return newov; |
| 600 | } |
| 601 | |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 602 | /* Transition from OV_UI_MIRROR to OV_UI_VIDEO_TV */ |
| 603 | template<> |
| 604 | inline 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 */ |
| 635 | template<> |
| 636 | inline 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 Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 665 | } // overlay |
| 666 | |
| 667 | #endif // OVERLAY_STATE_H |