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