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_GENERIC_PIPE_H |
| 31 | #define OVERLAY_GENERIC_PIPE_H |
| 32 | |
| 33 | #include "overlayUtils.h" |
| 34 | #include "overlayRotator.h" |
| 35 | #include "overlayCtrlData.h" |
| 36 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 37 | namespace overlay { |
| 38 | |
| 39 | template <int PANEL> |
| 40 | class GenericPipe : utils::NoCopy { |
| 41 | public: |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame^] | 42 | /* ctor */ |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 43 | explicit GenericPipe(); |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame^] | 44 | /* dtor */ |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 45 | ~GenericPipe(); |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame^] | 46 | /* CTRL/DATA init. Not owning rotator, will not init it */ |
| 47 | bool init(RotatorBase* rot); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 48 | /* CTRL/DATA close. Not owning rotator, will not close it */ |
| 49 | bool close(); |
| 50 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame^] | 51 | /* Control APIs */ |
| 52 | /* set source using whf, orient and wait flag */ |
| 53 | bool setSource(const utils::PipeArgs& args); |
| 54 | /* set crop a.k.a the region of interest */ |
| 55 | bool setCrop(const utils::Dim& d); |
| 56 | /* set orientation*/ |
| 57 | bool setTransform(const utils::eTransform& param); |
| 58 | /* set mdp posision using dim */ |
| 59 | bool setPosition(const utils::Dim& dim); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 60 | /* commit changes to the overlay "set"*/ |
| 61 | bool commit(); |
| 62 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame^] | 63 | /* Data APIs */ |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 64 | /* queue buffer to the overlay */ |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame^] | 65 | bool queueBuffer(int fd, uint32_t offset); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 66 | /* wait for vsync to be done */ |
| 67 | bool waitForVsync(); |
| 68 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 69 | /* return cached startup args */ |
| 70 | const utils::PipeArgs& getArgs() const; |
| 71 | |
| 72 | /* retrieve screen info */ |
| 73 | utils::ScreenInfo getScreenInfo() const; |
| 74 | |
| 75 | /* retrieve cached crop data */ |
| 76 | utils::Dim getCrop() const; |
| 77 | |
| 78 | /* return aspect ratio from ctrl data */ |
| 79 | utils::Dim getAspectRatio(const utils::Whf& whf) const; |
| 80 | |
| 81 | /* return aspect ratio from ctrl data for true UI mirroring */ |
| 82 | utils::Dim getAspectRatio(const utils::Dim& dim) const; |
| 83 | |
| 84 | /* is closed */ |
| 85 | bool isClosed() const; |
| 86 | |
| 87 | /* is open */ |
| 88 | bool isOpen() const; |
| 89 | |
| 90 | /* return Ctrl fd. Used for S3D */ |
| 91 | int getCtrlFd() const; |
| 92 | |
| 93 | /* Get the overlay pipe type */ |
| 94 | utils::eOverlayPipeType getOvPipeType() const; |
| 95 | |
| 96 | /* dump the state of the object */ |
| 97 | void dump() const; |
| 98 | private: |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame^] | 99 | /* set Closed pipe */ |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 100 | bool setClosed(); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 101 | |
| 102 | /* Ctrl/Data aggregator */ |
| 103 | CtrlData mCtrlData; |
| 104 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 105 | /* rotator mdp base |
| 106 | * Can point to NullRotator or to Rotator*/ |
| 107 | RotatorBase* mRot; |
| 108 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame^] | 109 | //Whether rotator is used for 0-rot or otherwise |
| 110 | bool mRotUsed; |
| 111 | |
| 112 | /* Pipe open or closed */ |
| 113 | enum ePipeState { |
| 114 | CLOSED, |
| 115 | OPEN |
| 116 | }; |
| 117 | ePipeState pipeState; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 118 | }; |
| 119 | |
| 120 | //------------------------Inlines and Templates ---------------------- |
| 121 | |
| 122 | template <int PANEL> |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame^] | 123 | GenericPipe<PANEL>::GenericPipe() : mRot(0), mRotUsed(false), |
| 124 | pipeState(CLOSED) { |
| 125 | } |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 126 | |
| 127 | template <int PANEL> |
| 128 | GenericPipe<PANEL>::~GenericPipe() { |
| 129 | close(); |
| 130 | } |
| 131 | |
| 132 | template <int PANEL> |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame^] | 133 | bool GenericPipe<PANEL>::init(RotatorBase* rot) |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 134 | { |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame^] | 135 | ALOGE_IF(DEBUG_OVERLAY, "GenericPipe init"); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 136 | OVASSERT(rot, "rot is null"); |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame^] | 137 | |
| 138 | // init ctrl and data |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 139 | uint32_t fbnum = utils::getFBForPanel(PANEL); |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame^] | 140 | |
| 141 | if(!mCtrlData.ctrl.init(fbnum)) { |
| 142 | ALOGE("GenericPipe failed to init ctrl"); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 143 | return false; |
| 144 | } |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame^] | 145 | |
| 146 | if(!mCtrlData.data.init(fbnum)) { |
| 147 | ALOGE("GenericPipe failed to init data"); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 148 | return false; |
| 149 | } |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame^] | 150 | |
| 151 | //Cache the rot ref. Ownership is with OverlayImpl. |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 152 | mRot = rot; |
| 153 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame^] | 154 | mRotUsed = false; |
| 155 | |
| 156 | // NOTE:init() on the rot is called by OverlayImpl |
| 157 | // Pipes only have to worry about using rot, and not init or close. |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 158 | |
| 159 | return true; |
| 160 | } |
| 161 | |
| 162 | template <int PANEL> |
| 163 | bool GenericPipe<PANEL>::close() { |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame^] | 164 | if(isClosed()) |
| 165 | return true; |
| 166 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 167 | bool ret = true; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame^] | 168 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 169 | if(!mCtrlData.ctrl.close()) { |
| 170 | ALOGE("GenericPipe failed to close ctrl"); |
| 171 | ret = false; |
| 172 | } |
| 173 | if (!mCtrlData.data.close()) { |
| 174 | ALOGE("GenericPipe failed to close data"); |
| 175 | ret = false; |
| 176 | } |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame^] | 177 | |
| 178 | // NOTE:close() on the rot is called by OverlayImpl |
| 179 | // Pipes only have to worry about using rot, and not init or close. |
| 180 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 181 | setClosed(); |
| 182 | return ret; |
| 183 | } |
| 184 | |
| 185 | template <int PANEL> |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame^] | 186 | inline bool GenericPipe<PANEL>::setSource( |
| 187 | const utils::PipeArgs& args) |
| 188 | { |
| 189 | utils::PipeArgs newargs(args); |
| 190 | //Interlace video handling. |
| 191 | if(newargs.whf.format & INTERLACE_MASK) { |
| 192 | setMdpFlags(newargs.mdpFlags, utils::OV_MDP_DEINTERLACE); |
| 193 | } |
| 194 | utils::Whf whf(newargs.whf); |
| 195 | //Extract HAL format from lower bytes. Deinterlace if interlaced. |
| 196 | whf.format = utils::getColorFormat(whf.format); |
| 197 | //Get MDP equivalent of HAL format. |
| 198 | whf.format = utils::getMdpFormat(whf.format); |
| 199 | newargs.whf = whf; |
| 200 | |
| 201 | //Cache if user wants 0-rotation |
| 202 | mRotUsed = newargs.rotFlags & utils::ROT_FLAG_ENABLED; |
| 203 | mRot->setSource(newargs.whf); |
| 204 | mRot->setFlags(newargs.mdpFlags); |
| 205 | return mCtrlData.ctrl.setSource(newargs); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | template <int PANEL> |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame^] | 209 | inline bool GenericPipe<PANEL>::setCrop( |
| 210 | const overlay::utils::Dim& d) { |
| 211 | return mCtrlData.ctrl.setCrop(d); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | template <int PANEL> |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame^] | 215 | inline bool GenericPipe<PANEL>::setTransform( |
| 216 | const utils::eTransform& orient) |
| 217 | { |
| 218 | //Rotation could be enabled by user for zero-rot or the layer could have |
| 219 | //some transform. Mark rotation enabled in either case. |
| 220 | mRotUsed |= (orient != utils::OVERLAY_TRANSFORM_0); |
| 221 | mRot->setTransform(orient, mRotUsed); |
| 222 | |
| 223 | return mCtrlData.ctrl.setTransform(orient, mRotUsed); |
| 224 | } |
| 225 | |
| 226 | template <int PANEL> |
| 227 | inline bool GenericPipe<PANEL>::setPosition(const utils::Dim& d) |
| 228 | { |
| 229 | return mCtrlData.ctrl.setPosition(d); |
| 230 | } |
| 231 | |
| 232 | template <int PANEL> |
| 233 | inline bool GenericPipe<PANEL>::commit() { |
| 234 | bool ret = false; |
| 235 | //If wanting to use rotator, start it. |
| 236 | if(mRotUsed) { |
| 237 | if(!mRot->commit()) { |
| 238 | ALOGE("GenPipe Rotator commit failed"); |
| 239 | return false; |
| 240 | } |
| 241 | } |
| 242 | ret = mCtrlData.ctrl.commit(); |
| 243 | pipeState = ret ? OPEN : CLOSED; |
| 244 | return ret; |
| 245 | } |
| 246 | |
| 247 | template <int PANEL> |
| 248 | inline bool GenericPipe<PANEL>::queueBuffer(int fd, uint32_t offset) { |
| 249 | //TODO Move pipe-id transfer to CtrlData class. Make ctrl and data private. |
| 250 | OVASSERT(isOpen(), "State is closed, cannot queueBuffer"); |
| 251 | int pipeId = mCtrlData.ctrl.getPipeId(); |
| 252 | OVASSERT(-1 != pipeId, "Ctrl ID should not be -1"); |
| 253 | // set pipe id from ctrl to data |
| 254 | mCtrlData.data.setPipeId(pipeId); |
| 255 | |
| 256 | int finalFd = fd; |
| 257 | uint32_t finalOffset = offset; |
| 258 | //If rotator is to be used, queue to it, so it can ROTATE. |
| 259 | if(mRotUsed) { |
| 260 | if(!mRot->queueBuffer(fd, offset)) { |
| 261 | ALOGE("GenPipe Rotator play failed"); |
| 262 | return false; |
| 263 | } |
| 264 | //Configure MDP's source buffer as the current output buffer of rotator |
| 265 | if(mRot->getDstMemId() != -1) { |
| 266 | finalFd = mRot->getDstMemId(); |
| 267 | finalOffset = mRot->getDstOffset(); |
| 268 | } else { |
| 269 | //Could be -1 for NullRotator, if queue above succeeds. |
| 270 | //Need an actual rotator. Modify overlay State Traits. |
| 271 | //Not fatal, keep queuing to MDP without rotation. |
| 272 | ALOGE("Null rotator in use, where an actual is required"); |
| 273 | } |
| 274 | } |
| 275 | return mCtrlData.data.queueBuffer(finalFd, finalOffset); |
| 276 | } |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 277 | |
| 278 | template <int PANEL> |
| 279 | inline int GenericPipe<PANEL>::getCtrlFd() const { |
| 280 | return mCtrlData.ctrl.getFd(); |
| 281 | } |
| 282 | |
| 283 | template <int PANEL> |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 284 | inline bool GenericPipe<PANEL>::waitForVsync() { |
| 285 | OVASSERT(isOpen(), "State is closed, cannot waitForVsync"); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 286 | return mCtrlData.data.waitForVsync(); |
| 287 | } |
| 288 | |
| 289 | template <int PANEL> |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 290 | inline utils::Dim GenericPipe<PANEL>::getAspectRatio( |
| 291 | const utils::Whf& whf) const |
| 292 | { |
| 293 | return mCtrlData.ctrl.getAspectRatio(whf); |
| 294 | } |
| 295 | |
| 296 | template <int PANEL> |
| 297 | inline utils::Dim GenericPipe<PANEL>::getAspectRatio( |
| 298 | const utils::Dim& dim) const |
| 299 | { |
| 300 | return mCtrlData.ctrl.getAspectRatio(dim); |
| 301 | } |
| 302 | |
| 303 | template <int PANEL> |
| 304 | inline utils::ScreenInfo GenericPipe<PANEL>::getScreenInfo() const |
| 305 | { |
| 306 | return mCtrlData.ctrl.getScreenInfo(); |
| 307 | } |
| 308 | |
| 309 | template <int PANEL> |
| 310 | inline utils::Dim GenericPipe<PANEL>::getCrop() const |
| 311 | { |
| 312 | return mCtrlData.ctrl.getCrop(); |
| 313 | } |
| 314 | |
| 315 | template <int PANEL> |
| 316 | inline utils::eOverlayPipeType GenericPipe<PANEL>::getOvPipeType() const { |
| 317 | return utils::OV_PIPE_TYPE_GENERIC; |
| 318 | } |
| 319 | |
| 320 | template <int PANEL> |
| 321 | void GenericPipe<PANEL>::dump() const |
| 322 | { |
| 323 | ALOGE("== Dump Generic pipe start =="); |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame^] | 324 | ALOGE("pipe state = %d", (int)pipeState); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 325 | OVASSERT(mRot, "GenericPipe should have a valid Rot"); |
| 326 | mCtrlData.ctrl.dump(); |
| 327 | mCtrlData.data.dump(); |
| 328 | mRot->dump(); |
| 329 | ALOGE("== Dump Generic pipe end =="); |
| 330 | } |
| 331 | |
| 332 | template <int PANEL> |
| 333 | inline bool GenericPipe<PANEL>::isClosed() const { |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame^] | 334 | return (pipeState == CLOSED); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | template <int PANEL> |
| 338 | inline bool GenericPipe<PANEL>::isOpen() const { |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame^] | 339 | return (pipeState == OPEN); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | template <int PANEL> |
| 343 | inline bool GenericPipe<PANEL>::setClosed() { |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame^] | 344 | pipeState = CLOSED; |
| 345 | return true; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 346 | } |
| 347 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 348 | } //namespace overlay |
| 349 | |
| 350 | #endif // OVERLAY_GENERIC_PIPE_H |