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_IMPL_H |
| 31 | #define OVERLAY_IMPL_H |
| 32 | |
| 33 | #include "overlayUtils.h" |
| 34 | #include "overlayRotator.h" |
| 35 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 36 | namespace overlay { |
| 37 | |
| 38 | // Interface only. No member, no definiton (except ~ which can |
| 39 | // also be =0 with impl in cpp) |
| 40 | class OverlayImplBase { |
| 41 | public: |
| 42 | /* empty dtor. can be =0 with cpp impl*/ |
| 43 | virtual ~OverlayImplBase() {} |
| 44 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 45 | /* Init pipe/rot for one dest */ |
| 46 | virtual bool initPipe(RotatorBase* rot, utils::eDest dest) = 0; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 47 | |
| 48 | /* Close pipe/rot for all specified dest */ |
| 49 | virtual bool closePipe(utils::eDest dest) = 0; |
| 50 | |
| 51 | /* Copy specified pipe/rot from ov passed in (used by state machine only) */ |
| 52 | virtual bool copyOvPipe(OverlayImplBase* ov, utils::eDest dest) = 0; |
| 53 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 54 | /* Init all pipes |
| 55 | * To init just one pipe, use initPipe() |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 56 | * */ |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 57 | virtual bool init(RotatorBase* rot0, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 58 | RotatorBase* rot1, |
| 59 | RotatorBase* rot2) = 0; |
| 60 | |
| 61 | /* Close all pipes |
| 62 | * To close just one pipe, use closePipe() |
| 63 | * */ |
| 64 | virtual bool close() = 0; |
| 65 | |
| 66 | /* |
| 67 | * Commit changes to the overlay |
| 68 | * */ |
| 69 | virtual bool commit(utils::eDest dest = utils::OV_PIPE_ALL) = 0; |
| 70 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 71 | /* Queue buffer with fd from an offset*/ |
| 72 | virtual bool queueBuffer(int fd, uint32_t offset, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 73 | utils::eDest dest = utils::OV_PIPE_ALL) = 0; |
| 74 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 75 | /* Crop existing destination using Dim coordinates */ |
| 76 | virtual bool setCrop(const utils::Dim& d, |
| 77 | utils::eDest dest = utils::OV_PIPE_ALL) = 0; |
| 78 | |
| 79 | /* Set new position using Dim */ |
| 80 | virtual bool setPosition(const utils::Dim& dim, |
| 81 | utils::eDest dest = utils::OV_PIPE_ALL) = 0; |
| 82 | |
| 83 | /* Set parameters - usually needed for Rotator, but would |
| 84 | * be passed down the stack as well */ |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 85 | virtual bool setTransform(const utils::eTransform& param, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 86 | utils::eDest dest = utils::OV_PIPE_ALL) = 0; |
| 87 | |
| 88 | /* Set new source including orientation */ |
| 89 | virtual bool setSource(const utils::PipeArgs[utils::MAX_PIPES], |
| 90 | utils::eDest dest = utils::OV_PIPE_ALL) = 0; |
| 91 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 92 | /* Dump underlying state */ |
| 93 | virtual void dump() const = 0; |
| 94 | }; |
| 95 | |
| 96 | class NullPipe { |
| 97 | public: |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 98 | bool init(RotatorBase* rot) { return true; } |
| 99 | bool close() { return true; } |
| 100 | bool start(const utils::PipeArgs& args) { return true; } |
| 101 | bool commit() { return true; } |
| 102 | bool setCrop(const utils::Dim& d) { return true; } |
| 103 | bool setPosition(const utils::Dim& dim) { return true; } |
| 104 | bool setTransform(const utils::eTransform& param) { return true; } |
| 105 | bool setSource(const utils::PipeArgs& args) { return true; } |
| 106 | bool queueBuffer(int fd, uint32_t offset) { return true; } |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 107 | void dump() const {} |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 108 | }; |
| 109 | |
| 110 | /* |
| 111 | * Each pipe is not specific to a display (primary/external). The order in the |
| 112 | * template params, will setup the priorities of the pipes. |
| 113 | * */ |
| 114 | template <class P0, class P1=NullPipe, class P2=NullPipe> |
| 115 | class OverlayImpl : public OverlayImplBase { |
| 116 | public: |
| 117 | typedef P0 pipe0; |
| 118 | typedef P1 pipe1; |
| 119 | typedef P2 pipe2; |
| 120 | |
| 121 | /* ctor */ |
| 122 | OverlayImpl(); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 123 | |
| 124 | /* |
| 125 | * Comments of the below functions are the same as the one |
| 126 | * in OverlayImplBase. |
| 127 | * */ |
| 128 | virtual ~OverlayImpl(); |
| 129 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 130 | virtual bool initPipe(RotatorBase* rot, utils::eDest dest); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 131 | virtual bool closePipe(utils::eDest dest); |
| 132 | virtual bool copyOvPipe(OverlayImplBase* ov, utils::eDest dest); |
| 133 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 134 | virtual bool init(RotatorBase* rot0, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 135 | RotatorBase* rot1, |
| 136 | RotatorBase* rot2); |
| 137 | virtual bool close(); |
| 138 | virtual bool commit(utils::eDest dest = utils::OV_PIPE_ALL); |
| 139 | virtual bool setCrop(const utils::Dim& d, |
| 140 | utils::eDest dest = utils::OV_PIPE_ALL); |
| 141 | virtual bool setPosition(const utils::Dim& dim, |
| 142 | utils::eDest dest = utils::OV_PIPE_ALL); |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 143 | virtual bool setTransform(const utils::eTransform& param, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 144 | utils::eDest dest = utils::OV_PIPE_ALL); |
| 145 | virtual bool setSource(const utils::PipeArgs[utils::MAX_PIPES], |
| 146 | utils::eDest dest = utils::OV_PIPE_ALL); |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 147 | virtual bool queueBuffer(int fd, uint32_t offset, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 148 | utils::eDest dest = utils::OV_PIPE_ALL); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 149 | virtual void dump() const; |
| 150 | |
| 151 | private: |
| 152 | P0* mPipe0; |
| 153 | P1* mPipe1; |
| 154 | P2* mPipe2; |
| 155 | // More Px here in the future as needed |
| 156 | |
| 157 | /* */ |
| 158 | |
| 159 | /* Each Px has it's own Rotator here. |
| 160 | * will pass rotator to the lower layer in stack |
| 161 | * but only overlay is allowed to control the lifetime |
| 162 | * of the rotator instace */ |
| 163 | RotatorBase* mRotP0; |
| 164 | RotatorBase* mRotP1; |
| 165 | RotatorBase* mRotP2; |
| 166 | }; |
| 167 | |
| 168 | |
| 169 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 170 | //-----------Inlines and Template defn--------------------------------- |
| 171 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 172 | /**** OverlayImpl ****/ |
| 173 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 174 | template <class P0, class P1, class P2> |
| 175 | OverlayImpl<P0, P1, P2>::OverlayImpl() : |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 176 | mPipe0(0), mPipe1(0), mPipe2(0), |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 177 | mRotP0(0), mRotP1(0), mRotP2(0) |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 178 | { |
| 179 | //Do not create a pipe here. |
| 180 | //Either initPipe can create a pipe OR |
| 181 | //copyOvPipe can assign a pipe. |
| 182 | } |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 183 | |
| 184 | template <class P0, class P1, class P2> |
| 185 | OverlayImpl<P0, P1, P2>::~OverlayImpl() |
| 186 | { |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 187 | //Do not delete pipes. |
| 188 | //closePipe will close and delete. |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 189 | } |
| 190 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 191 | /* Init only one pipe/rot pair per call */ |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 192 | template <class P0, class P1, class P2> |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 193 | bool OverlayImpl<P0, P1, P2>::initPipe(RotatorBase* rot, utils::eDest dest) |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 194 | { |
| 195 | OVASSERT(rot, "%s: OverlayImpl rot is null", __FUNCTION__); |
| 196 | OVASSERT(utils::isValidDest(dest), "%s: OverlayImpl invalid dest=%d", |
| 197 | __FUNCTION__, dest); |
| 198 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 199 | bool ret = true; |
| 200 | |
| 201 | if (utils::OV_PIPE0 & dest) { |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 202 | ALOGE_IF(DEBUG_OVERLAY, "init pipe0"); |
| 203 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 204 | mRotP0 = rot; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 205 | ret = mRotP0->init(); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 206 | if(!ret) { |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 207 | ALOGE("%s: OverlayImpl rot0 failed to init", __FUNCTION__); |
| 208 | return false; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 209 | } |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 210 | |
| 211 | mPipe0 = new P0(); |
| 212 | OVASSERT(mPipe0, "%s: OverlayImpl pipe0 is null", __FUNCTION__); |
| 213 | ret = mPipe0->init(rot); |
| 214 | if(!ret) { |
| 215 | ALOGE("%s: OverlayImpl pipe0 failed to init", __FUNCTION__); |
| 216 | return false; |
| 217 | } |
| 218 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 219 | return ret; |
| 220 | } |
| 221 | |
| 222 | if (utils::OV_PIPE1 & dest) { |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 223 | ALOGE_IF(DEBUG_OVERLAY, "init pipe1"); |
| 224 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 225 | mRotP1 = rot; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 226 | ret = mRotP1->init(); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 227 | if(!ret) { |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 228 | ALOGE("%s: OverlayImpl rot1 failed to init", __FUNCTION__); |
| 229 | return false; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 230 | } |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 231 | |
| 232 | mPipe1 = new P1(); |
| 233 | OVASSERT(mPipe1, "%s: OverlayImpl pipe1 is null", __FUNCTION__); |
| 234 | ret = mPipe1->init(rot); |
| 235 | if(!ret) { |
| 236 | ALOGE("%s: OverlayImpl pipe1 failed to init", __FUNCTION__); |
| 237 | return false; |
| 238 | } |
| 239 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 240 | return ret; |
| 241 | } |
| 242 | |
| 243 | if (utils::OV_PIPE2 & dest) { |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 244 | ALOGE_IF(DEBUG_OVERLAY, "init pipe2"); |
| 245 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 246 | mRotP2 = rot; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 247 | ret = mRotP2->init(); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 248 | if(!ret) { |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 249 | ALOGE("%s: OverlayImpl rot2 failed to init", __FUNCTION__); |
| 250 | return false; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 251 | } |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 252 | |
| 253 | mPipe2 = new P2(); |
| 254 | OVASSERT(mPipe2, "%s: OverlayImpl pipe2 is null", __FUNCTION__); |
| 255 | ret = mPipe2->init(rot); |
| 256 | if(!ret) { |
| 257 | ALOGE("%s: OverlayImpl pipe2 failed to init", __FUNCTION__); |
| 258 | return false; |
| 259 | } |
| 260 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 261 | return ret; |
| 262 | } |
| 263 | |
| 264 | // Should have returned by here |
| 265 | return false; |
| 266 | } |
| 267 | |
| 268 | /* Close pipe/rot for all specified dest */ |
| 269 | template <class P0, class P1, class P2> |
| 270 | bool OverlayImpl<P0, P1, P2>::closePipe(utils::eDest dest) |
| 271 | { |
| 272 | OVASSERT(utils::isValidDest(dest), "%s: OverlayImpl invalid dest=%d", |
| 273 | __FUNCTION__, dest); |
| 274 | |
| 275 | if (utils::OV_PIPE0 & dest) { |
| 276 | // Close pipe0 |
| 277 | OVASSERT(mPipe0, "%s: OverlayImpl pipe0 is null", __FUNCTION__); |
| 278 | ALOGE_IF(DEBUG_OVERLAY, "Close pipe0"); |
| 279 | if (!mPipe0->close()) { |
| 280 | ALOGE("%s: OverlayImpl failed to close pipe0", __FUNCTION__); |
| 281 | return false; |
| 282 | } |
| 283 | delete mPipe0; |
| 284 | mPipe0 = 0; |
| 285 | |
| 286 | // Close the rotator for pipe0 |
| 287 | OVASSERT(mRotP0, "%s: OverlayImpl rot0 is null", __FUNCTION__); |
| 288 | if (!mRotP0->close()) { |
| 289 | ALOGE("%s: OverlayImpl failed to close rot for pipe0", __FUNCTION__); |
| 290 | } |
| 291 | delete mRotP0; |
| 292 | mRotP0 = 0; |
| 293 | } |
| 294 | |
| 295 | if (utils::OV_PIPE1 & dest) { |
| 296 | // Close pipe1 |
| 297 | OVASSERT(mPipe1, "%s: OverlayImpl pipe1 is null", __FUNCTION__); |
| 298 | ALOGE_IF(DEBUG_OVERLAY, "Close pipe1"); |
| 299 | if (!mPipe1->close()) { |
| 300 | ALOGE("%s: OverlayImpl failed to close pipe1", __FUNCTION__); |
| 301 | return false; |
| 302 | } |
| 303 | delete mPipe1; |
| 304 | mPipe1 = 0; |
| 305 | |
| 306 | // Close the rotator for pipe1 |
| 307 | OVASSERT(mRotP1, "%s: OverlayImpl rot1 is null", __FUNCTION__); |
| 308 | if (!mRotP1->close()) { |
| 309 | ALOGE("%s: OverlayImpl failed to close rot for pipe1", __FUNCTION__); |
| 310 | } |
| 311 | delete mRotP1; |
| 312 | mRotP1 = 0; |
| 313 | } |
| 314 | |
| 315 | if (utils::OV_PIPE2 & dest) { |
| 316 | // Close pipe2 |
| 317 | OVASSERT(mPipe2, "%s: OverlayImpl pipe2 is null", __FUNCTION__); |
| 318 | ALOGE_IF(DEBUG_OVERLAY, "Close pipe2"); |
| 319 | if (!mPipe2->close()) { |
| 320 | ALOGE("%s: OverlayImpl failed to close pipe2", __FUNCTION__); |
| 321 | return false; |
| 322 | } |
| 323 | delete mPipe2; |
| 324 | mPipe2 = 0; |
| 325 | |
| 326 | // Close the rotator for pipe2 |
| 327 | OVASSERT(mRotP2, "%s: OverlayImpl rot2 is null", __FUNCTION__); |
| 328 | if (!mRotP2->close()) { |
| 329 | ALOGE("%s: OverlayImpl failed to close rot for pipe2", __FUNCTION__); |
| 330 | } |
| 331 | delete mRotP2; |
| 332 | mRotP2 = 0; |
| 333 | } |
| 334 | |
| 335 | return true; |
| 336 | } |
| 337 | |
| 338 | /* Copy pipe/rot from ov for all specified dest */ |
| 339 | template <class P0, class P1, class P2> |
| 340 | bool OverlayImpl<P0, P1, P2>::copyOvPipe(OverlayImplBase* ov, |
| 341 | utils::eDest dest) |
| 342 | { |
| 343 | OVASSERT(ov, "%s: OverlayImpl ov is null", __FUNCTION__); |
| 344 | OVASSERT(utils::isValidDest(dest), "%s: OverlayImpl invalid dest=%d", |
| 345 | __FUNCTION__, dest); |
| 346 | |
| 347 | OverlayImpl<P0, P1, P2>* ovimpl = static_cast<OverlayImpl<P0, P1, P2>*>(ov); |
| 348 | |
| 349 | if (utils::OV_PIPE0 & dest) { |
| 350 | mPipe0 = ovimpl->mPipe0; |
| 351 | mRotP0 = ovimpl->mRotP0; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 352 | ovimpl->mPipe0 = 0; |
| 353 | ovimpl->mRotP0 = 0; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | if (utils::OV_PIPE1 & dest) { |
| 357 | mPipe1 = ovimpl->mPipe1; |
| 358 | mRotP1 = ovimpl->mRotP1; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 359 | ovimpl->mPipe1 = 0; |
| 360 | ovimpl->mRotP1 = 0; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | if (utils::OV_PIPE2 & dest) { |
| 364 | mPipe2 = ovimpl->mPipe2; |
| 365 | mRotP2 = ovimpl->mRotP2; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 366 | ovimpl->mPipe2 = 0; |
| 367 | ovimpl->mRotP2 = 0; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | return true; |
| 371 | } |
| 372 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 373 | /* Init all pipes/rot */ |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 374 | template <class P0, class P1, class P2> |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 375 | bool OverlayImpl<P0, P1, P2>::init(RotatorBase* rot0, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 376 | RotatorBase* rot1, |
| 377 | RotatorBase* rot2) |
| 378 | { |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 379 | if (!this->initPipe(rot0, utils::OV_PIPE0)) { |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 380 | if (!this->close()) { |
| 381 | ALOGE("%s: failed to close at least one pipe", __FUNCTION__); |
| 382 | } |
| 383 | return false; |
| 384 | } |
| 385 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 386 | if (!this->initPipe(rot1, utils::OV_PIPE1)) { |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 387 | if (!this->close()) { |
| 388 | ALOGE("%s: failed to close at least one pipe", __FUNCTION__); |
| 389 | } |
| 390 | return false; |
| 391 | } |
| 392 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 393 | if (!this->initPipe(rot2, utils::OV_PIPE2)) { |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 394 | if (!this->close()) { |
| 395 | ALOGE("%s: failed to close at least one pipe", __FUNCTION__); |
| 396 | } |
| 397 | return false; |
| 398 | } |
| 399 | |
| 400 | return true; |
| 401 | } |
| 402 | |
| 403 | /* Close all pipes/rot */ |
| 404 | template <class P0, class P1, class P2> |
| 405 | bool OverlayImpl<P0, P1, P2>::close() |
| 406 | { |
| 407 | if (!this->closePipe(utils::OV_PIPE_ALL)) { |
| 408 | return false; |
| 409 | } |
| 410 | |
| 411 | return true; |
| 412 | } |
| 413 | |
| 414 | template <class P0, class P1, class P2> |
| 415 | bool OverlayImpl<P0, P1, P2>::commit(utils::eDest dest) |
| 416 | { |
| 417 | OVASSERT(mPipe0 && mPipe1 && mPipe2, |
| 418 | "%s: Pipes are null p0=%p p1=%p p2=%p", |
| 419 | __FUNCTION__, mPipe0, mPipe1, mPipe2); |
| 420 | |
| 421 | if (utils::OV_PIPE0 & dest) { |
| 422 | if(!mPipe0->commit()) { |
| 423 | ALOGE("OverlayImpl p0 failed to commit"); |
| 424 | return false; |
| 425 | } |
| 426 | } |
| 427 | |
| 428 | if (utils::OV_PIPE1 & dest) { |
| 429 | if(!mPipe1->commit()) { |
| 430 | ALOGE("OverlayImpl p1 failed to commit"); |
| 431 | return false; |
| 432 | } |
| 433 | } |
| 434 | |
| 435 | if (utils::OV_PIPE2 & dest) { |
| 436 | if(!mPipe2->commit()) { |
| 437 | ALOGE("OverlayImpl p2 failed to commit"); |
| 438 | return false; |
| 439 | } |
| 440 | } |
| 441 | |
| 442 | return true; |
| 443 | } |
| 444 | |
| 445 | template <class P0, class P1, class P2> |
| 446 | bool OverlayImpl<P0, P1, P2>::setCrop(const utils::Dim& d, utils::eDest dest) |
| 447 | { |
| 448 | OVASSERT(mPipe0 && mPipe1 && mPipe2, |
| 449 | "%s: Pipes are null p0=%p p1=%p p2=%p", |
| 450 | __FUNCTION__, mPipe0, mPipe1, mPipe2); |
| 451 | |
| 452 | if (utils::OV_PIPE0 & dest) { |
| 453 | if(!mPipe0->setCrop(d)) { |
| 454 | ALOGE("OverlayImpl p0 failed to crop"); |
| 455 | return false; |
| 456 | } |
| 457 | } |
| 458 | |
| 459 | if (utils::OV_PIPE1 & dest) { |
| 460 | if(!mPipe1->setCrop(d)) { |
| 461 | ALOGE("OverlayImpl p1 failed to crop"); |
| 462 | return false; |
| 463 | } |
| 464 | } |
| 465 | |
| 466 | if (utils::OV_PIPE2 & dest) { |
| 467 | if(!mPipe2->setCrop(d)) { |
| 468 | ALOGE("OverlayImpl p2 failed to crop"); |
| 469 | return false; |
| 470 | } |
| 471 | } |
| 472 | |
| 473 | return true; |
| 474 | } |
| 475 | |
| 476 | template <class P0, class P1, class P2> |
| 477 | bool OverlayImpl<P0, P1, P2>::setPosition(const utils::Dim& d, |
| 478 | utils::eDest dest) |
| 479 | { |
| 480 | OVASSERT(mPipe0 && mPipe1 && mPipe2, |
| 481 | "%s: Pipes are null p0=%p p1=%p p2=%p", |
| 482 | __FUNCTION__, mPipe0, mPipe1, mPipe2); |
| 483 | |
| 484 | if (utils::OV_PIPE0 & dest) { |
| 485 | if(!mPipe0->setPosition(d)) { |
| 486 | ALOGE("OverlayImpl p0 failed to setpos"); |
| 487 | return false; |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | if (utils::OV_PIPE1 & dest) { |
| 492 | if(!mPipe1->setPosition(d)) { |
| 493 | ALOGE("OverlayImpl p1 failed to setpos"); |
| 494 | return false; |
| 495 | } |
| 496 | } |
| 497 | |
| 498 | if (utils::OV_PIPE2 & dest) { |
| 499 | if(!mPipe2->setPosition(d)) { |
| 500 | ALOGE("OverlayImpl p2 failed to setpos"); |
| 501 | return false; |
| 502 | } |
| 503 | } |
| 504 | |
| 505 | return true; |
| 506 | } |
| 507 | |
| 508 | template <class P0, class P1, class P2> |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 509 | bool OverlayImpl<P0, P1, P2>::setTransform(const utils::eTransform& param, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 510 | utils::eDest dest) |
| 511 | { |
| 512 | OVASSERT(mPipe0 && mPipe1 && mPipe2, |
| 513 | "%s: Pipes are null p0=%p p1=%p p2=%p", |
| 514 | __FUNCTION__, mPipe0, mPipe1, mPipe2); |
| 515 | |
| 516 | if (utils::OV_PIPE0 & dest) { |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 517 | if(!mPipe0->setTransform(param)) { |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 518 | ALOGE("OverlayImpl p0 failed to setparam"); |
| 519 | return false; |
| 520 | } |
| 521 | } |
| 522 | |
| 523 | if (utils::OV_PIPE1 & dest) { |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 524 | if(!mPipe1->setTransform(param)) { |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 525 | ALOGE("OverlayImpl p1 failed to setparam"); |
| 526 | return false; |
| 527 | } |
| 528 | } |
| 529 | |
| 530 | if (utils::OV_PIPE2 & dest) { |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 531 | if(!mPipe2->setTransform(param)) { |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 532 | ALOGE("OverlayImpl p2 failed to setparam"); |
| 533 | return false; |
| 534 | } |
| 535 | } |
| 536 | |
| 537 | return true; |
| 538 | } |
| 539 | |
| 540 | template <class P0, class P1, class P2> |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 541 | bool OverlayImpl<P0, P1, P2>::setSource( |
| 542 | const utils::PipeArgs args[utils::MAX_PIPES], |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 543 | utils::eDest dest) |
| 544 | { |
| 545 | OVASSERT(mPipe0 && mPipe1 && mPipe2, |
| 546 | "%s: Pipes are null p0=%p p1=%p p2=%p", |
| 547 | __FUNCTION__, mPipe0, mPipe1, mPipe2); |
| 548 | |
| 549 | if (utils::OV_PIPE0 & dest) { |
| 550 | if(!mPipe0->setSource(args[0])) { |
| 551 | ALOGE("OverlayImpl p0 failed to setsrc"); |
| 552 | return false; |
| 553 | } |
| 554 | } |
| 555 | |
| 556 | if (utils::OV_PIPE1 & dest) { |
| 557 | if(!mPipe1->setSource(args[1])) { |
| 558 | ALOGE("OverlayImpl p1 failed to setsrc"); |
| 559 | return false; |
| 560 | } |
| 561 | } |
| 562 | |
| 563 | if (utils::OV_PIPE2 & dest) { |
| 564 | if(!mPipe2->setSource(args[2])) { |
| 565 | ALOGE("OverlayImpl p2 failed to setsrc"); |
| 566 | return false; |
| 567 | } |
| 568 | } |
| 569 | |
| 570 | return true; |
| 571 | } |
| 572 | |
| 573 | template <class P0, class P1, class P2> |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 574 | bool OverlayImpl<P0, P1, P2>::queueBuffer(int fd, uint32_t offset, |
| 575 | utils::eDest dest) |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 576 | { |
| 577 | OVASSERT(mPipe0 && mPipe1 && mPipe2, |
| 578 | "%s: Pipes are null p0=%p p1=%p p2=%p", |
| 579 | __FUNCTION__, mPipe0, mPipe1, mPipe2); |
| 580 | |
| 581 | if (utils::OV_PIPE0 & dest) { |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 582 | if(!mPipe0->queueBuffer(fd, offset)) { |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 583 | ALOGE("OverlayImpl p0 failed to queueBuffer"); |
| 584 | return false; |
| 585 | } |
| 586 | } |
| 587 | |
| 588 | if (utils::OV_PIPE1 & dest) { |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 589 | if(!mPipe1->queueBuffer(fd, offset)) { |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 590 | ALOGE("OverlayImpl p1 failed to queueBuffer"); |
| 591 | return false; |
| 592 | } |
| 593 | } |
| 594 | |
| 595 | if (utils::OV_PIPE2 & dest) { |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 596 | if(!mPipe2->queueBuffer(fd, offset)) { |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 597 | ALOGE("OverlayImpl p2 failed to queueBuffer"); |
| 598 | return false; |
| 599 | } |
| 600 | } |
| 601 | |
| 602 | return true; |
| 603 | } |
| 604 | |
| 605 | template <class P0, class P1, class P2> |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 606 | void OverlayImpl<P0, P1, P2>::dump() const |
| 607 | { |
| 608 | OVASSERT(mPipe0 && mPipe1 && mPipe2, |
| 609 | "%s: Pipes are null p0=%p p1=%p p2=%p", |
| 610 | __FUNCTION__, mPipe0, mPipe1, mPipe2); |
| 611 | ALOGE("== Dump OverlayImpl dump start ROT p0 =="); |
| 612 | mRotP0->dump(); |
| 613 | ALOGE("== Dump OverlayImpl dump end ROT p0 =="); |
| 614 | ALOGE("== Dump OverlayImpl dump start ROT p1 =="); |
| 615 | mRotP1->dump(); |
| 616 | ALOGE("== Dump OverlayImpl dump end ROT p1 =="); |
| 617 | ALOGE("== Dump OverlayImpl dump start ROT p2 =="); |
| 618 | mRotP2->dump(); |
| 619 | ALOGE("== Dump OverlayImpl dump end ROT p2 =="); |
| 620 | ALOGE("== Dump OverlayImpl dump start p0 =="); |
| 621 | mPipe0->dump(); |
| 622 | ALOGE("== Dump OverlayImpl dump end p0 =="); |
| 623 | ALOGE("== Dump OverlayImpl dump start p1 =="); |
| 624 | mPipe1->dump(); |
| 625 | ALOGE("== Dump OverlayImpl dump end p1 =="); |
| 626 | ALOGE("== Dump OverlayImpl dump start p2 =="); |
| 627 | mPipe2->dump(); |
| 628 | ALOGE("== Dump OverlayImpl dump end p2 =="); |
| 629 | } |
| 630 | |
| 631 | |
| 632 | } // overlay |
| 633 | |
| 634 | #endif // OVERLAY_IMPL_H |