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 | |
| 37 | // FIXME make int to be uint32 whenever possible |
| 38 | |
| 39 | namespace overlay { |
| 40 | |
| 41 | template <int PANEL> |
| 42 | class GenericPipe : utils::NoCopy { |
| 43 | public: |
| 44 | /* ctor init */ |
| 45 | explicit GenericPipe(); |
| 46 | |
| 47 | /* dtor close */ |
| 48 | ~GenericPipe(); |
| 49 | |
| 50 | /* CTRL/DATA/ROT open */ |
| 51 | bool open(RotatorBase* rot); |
| 52 | |
| 53 | /* CTRL/DATA close. Not owning rotator, will not close it */ |
| 54 | bool close(); |
| 55 | |
| 56 | /* commit changes to the overlay "set"*/ |
| 57 | bool commit(); |
| 58 | |
| 59 | /* "Data" related interface */ |
| 60 | |
| 61 | /* set ID directly to data channel */ |
| 62 | void setId(int id); |
| 63 | |
| 64 | /* Set FD / memid */ |
| 65 | void setMemoryId(int id); |
| 66 | |
| 67 | /* queue buffer to the overlay */ |
| 68 | bool queueBuffer(uint32_t offset); |
| 69 | |
| 70 | /* dequeue buffer to the overlay NOTSUPPORTED */ |
| 71 | bool dequeueBuffer(void*& buf); |
| 72 | |
| 73 | /* wait for vsync to be done */ |
| 74 | bool waitForVsync(); |
| 75 | |
| 76 | /* set crop data FIXME setROI (Region Of Intrest) */ |
| 77 | bool setCrop(const utils::Dim& d); |
| 78 | |
| 79 | /* "Ctrl" related interface */ |
| 80 | |
| 81 | /* |
| 82 | * Start a session, opens the rotator |
| 83 | * FIXME, we might want to open the rotator separately |
| 84 | */ |
| 85 | bool start(const utils::PipeArgs& args); |
| 86 | |
| 87 | /* set mdp posision using dim */ |
| 88 | bool setPosition(const utils::Dim& dim); |
| 89 | |
| 90 | /* set param using Params (param,value pair) */ |
| 91 | bool setParameter(const utils::Params& param); |
| 92 | |
| 93 | /* set source using whf, orient and wait flag */ |
| 94 | bool setSource(const utils::PipeArgs& args); |
| 95 | |
| 96 | /* return cached startup args */ |
| 97 | const utils::PipeArgs& getArgs() const; |
| 98 | |
| 99 | /* retrieve screen info */ |
| 100 | utils::ScreenInfo getScreenInfo() const; |
| 101 | |
| 102 | /* retrieve cached crop data */ |
| 103 | utils::Dim getCrop() const; |
| 104 | |
| 105 | /* return aspect ratio from ctrl data */ |
| 106 | utils::Dim getAspectRatio(const utils::Whf& whf) const; |
| 107 | |
| 108 | /* return aspect ratio from ctrl data for true UI mirroring */ |
| 109 | utils::Dim getAspectRatio(const utils::Dim& dim) const; |
| 110 | |
| 111 | /* is closed */ |
| 112 | bool isClosed() const; |
| 113 | |
| 114 | /* is open */ |
| 115 | bool isOpen() const; |
| 116 | |
| 117 | /* return Ctrl fd. Used for S3D */ |
| 118 | int getCtrlFd() const; |
| 119 | |
| 120 | /* Get the overlay pipe type */ |
| 121 | utils::eOverlayPipeType getOvPipeType() const; |
| 122 | |
| 123 | /* dump the state of the object */ |
| 124 | void dump() const; |
| 125 | private: |
| 126 | /* set Closed channel */ |
| 127 | bool setClosed(); |
| 128 | // kick off rotator. |
| 129 | bool startRotator(); |
| 130 | |
| 131 | /* Ctrl/Data aggregator */ |
| 132 | CtrlData mCtrlData; |
| 133 | |
| 134 | /* caching startup params. useful when need |
| 135 | * to have the exact copy of that pipe. |
| 136 | * For example when HDMI is connected, and we would |
| 137 | * like to open/start the pipe with the args */ |
| 138 | utils::PipeArgs mArgs; |
| 139 | |
| 140 | /* rotator mdp base |
| 141 | * Can point to NullRotator or to Rotator*/ |
| 142 | RotatorBase* mRot; |
| 143 | |
| 144 | /* my flags */ |
| 145 | enum { CLOSED = 1<<0 }; |
| 146 | uint32_t mFlags; |
| 147 | }; |
| 148 | |
| 149 | //------------------------Inlines and Templates ---------------------- |
| 150 | |
| 151 | template <int PANEL> |
| 152 | GenericPipe<PANEL>::GenericPipe() : mRot(0), mFlags(CLOSED) {} |
| 153 | |
| 154 | template <int PANEL> |
| 155 | GenericPipe<PANEL>::~GenericPipe() { |
| 156 | close(); |
| 157 | } |
| 158 | |
| 159 | template <int PANEL> |
| 160 | bool GenericPipe<PANEL>::open(RotatorBase* rot) |
| 161 | { |
| 162 | OVASSERT(rot, "rot is null"); |
| 163 | // open ctrl and data |
| 164 | uint32_t fbnum = utils::getFBForPanel(PANEL); |
| 165 | ALOGE_IF(DEBUG_OVERLAY, "GenericPipe open"); |
| 166 | if(!mCtrlData.ctrl.open(fbnum, rot)) { |
| 167 | ALOGE("GenericPipe failed to open ctrl"); |
| 168 | return false; |
| 169 | } |
| 170 | if(!mCtrlData.data.open(fbnum, rot)) { |
| 171 | ALOGE("GenericPipe failed to open data"); |
| 172 | return false; |
| 173 | } |
| 174 | mRot = rot; |
| 175 | |
| 176 | // NOTE: we won't have the flags as non CLOSED since we |
| 177 | // consider the pipe opened for business only when we call |
| 178 | // start() |
| 179 | |
| 180 | return true; |
| 181 | } |
| 182 | |
| 183 | template <int PANEL> |
| 184 | bool GenericPipe<PANEL>::close() { |
| 185 | if(isClosed()) return true; |
| 186 | bool ret = true; |
| 187 | if(!mCtrlData.ctrl.close()) { |
| 188 | ALOGE("GenericPipe failed to close ctrl"); |
| 189 | ret = false; |
| 190 | } |
| 191 | if (!mCtrlData.data.close()) { |
| 192 | ALOGE("GenericPipe failed to close data"); |
| 193 | ret = false; |
| 194 | } |
| 195 | setClosed(); |
| 196 | return ret; |
| 197 | } |
| 198 | |
| 199 | template <int PANEL> |
| 200 | inline bool GenericPipe<PANEL>::commit(){ |
| 201 | OVASSERT(isOpen(), "State is closed, cannot commit"); |
| 202 | return mCtrlData.ctrl.commit(); |
| 203 | } |
| 204 | |
| 205 | template <int PANEL> |
| 206 | inline void GenericPipe<PANEL>::setMemoryId(int id) { |
| 207 | OVASSERT(isOpen(), "State is closed, cannot setMemoryId"); |
| 208 | mCtrlData.data.setMemoryId(id); |
| 209 | } |
| 210 | |
| 211 | template <int PANEL> |
| 212 | inline void GenericPipe<PANEL>::setId(int id) { |
| 213 | mCtrlData.data.setId(id); } |
| 214 | |
| 215 | template <int PANEL> |
| 216 | inline int GenericPipe<PANEL>::getCtrlFd() const { |
| 217 | return mCtrlData.ctrl.getFd(); |
| 218 | } |
| 219 | |
| 220 | template <int PANEL> |
| 221 | inline bool GenericPipe<PANEL>::setCrop( |
| 222 | const overlay::utils::Dim& d) { |
| 223 | OVASSERT(isOpen(), "State is closed, cannot setCrop"); |
| 224 | return mCtrlData.ctrl.setCrop(d); |
| 225 | } |
| 226 | |
| 227 | template <int PANEL> |
| 228 | bool GenericPipe<PANEL>::start(const utils::PipeArgs& args) |
| 229 | { |
| 230 | /* open before your start control rotator */ |
| 231 | uint32_t sz = args.whf.size; //utils::getSizeByMdp(args.whf); |
| 232 | OVASSERT(sz, "GenericPipe sz=%d", sz); |
| 233 | if(!mRot->open()) { |
| 234 | ALOGE("GenericPipe start failed to open rot"); |
| 235 | return false; |
| 236 | } |
| 237 | |
| 238 | if(!mCtrlData.ctrl.start(args)){ |
| 239 | ALOGE("GenericPipe failed to start"); |
| 240 | return false; |
| 241 | } |
| 242 | |
| 243 | int ctrlId = mCtrlData.ctrl.getId(); |
| 244 | OVASSERT(-1 != ctrlId, "Ctrl ID should not be -1"); |
| 245 | // set ID requeset to assoc ctrl to data |
| 246 | setId(ctrlId); |
| 247 | // set ID request to assoc MDP data to ROT MDP data |
| 248 | mRot->setDataReqId(mCtrlData.data.getId()); |
| 249 | |
| 250 | // cache the args for future reference. |
| 251 | mArgs = args; |
| 252 | |
| 253 | // we got here so we are open+start and good to go |
| 254 | mFlags = 0; // clear flags from CLOSED |
| 255 | // TODO make it more robust when more flags |
| 256 | // are added |
| 257 | |
| 258 | return true; |
| 259 | } |
| 260 | |
| 261 | template <int PANEL> |
| 262 | inline const utils::PipeArgs& GenericPipe<PANEL>::getArgs() const |
| 263 | { |
| 264 | return mArgs; |
| 265 | } |
| 266 | |
| 267 | template <int PANEL> |
| 268 | bool GenericPipe<PANEL>::startRotator() { |
| 269 | // kick off rotator |
| 270 | if(!mRot->start()) { |
| 271 | ALOGE("GenericPipe failed to start rotator"); |
| 272 | return false; |
| 273 | } |
| 274 | return true; |
| 275 | } |
| 276 | |
| 277 | template <int PANEL> |
| 278 | inline bool GenericPipe<PANEL>::queueBuffer(uint32_t offset) { |
| 279 | OVASSERT(isOpen(), "State is closed, cannot queueBuffer"); |
| 280 | return mCtrlData.data.queueBuffer(offset); |
| 281 | } |
| 282 | |
| 283 | template <int PANEL> |
| 284 | inline bool GenericPipe<PANEL>::dequeueBuffer(void*&) { |
| 285 | OVASSERT(isOpen(), "State is closed, cannot dequeueBuffer"); |
| 286 | // can also set error to NOTSUPPORTED in the future |
| 287 | return false; |
| 288 | } |
| 289 | |
| 290 | template <int PANEL> |
| 291 | inline bool GenericPipe<PANEL>::waitForVsync() { |
| 292 | OVASSERT(isOpen(), "State is closed, cannot waitForVsync"); |
| 293 | |
| 294 | return mCtrlData.data.waitForVsync(); |
| 295 | } |
| 296 | |
| 297 | template <int PANEL> |
| 298 | inline bool GenericPipe<PANEL>::setPosition(const utils::Dim& dim) |
| 299 | { |
| 300 | OVASSERT(isOpen(), "State is closed, cannot setPosition"); |
| 301 | return mCtrlData.ctrl.setPosition(dim); |
| 302 | } |
| 303 | |
| 304 | template <int PANEL> |
| 305 | inline bool GenericPipe<PANEL>::setParameter( |
| 306 | const utils::Params& param) |
| 307 | { |
| 308 | OVASSERT(isOpen(), "State is closed, cannot setParameter"); |
| 309 | // Currently setParameter would start rotator |
| 310 | if(!mCtrlData.ctrl.setParameter(param)) { |
| 311 | ALOGE("GenericPipe failed to setparam"); |
| 312 | return false; |
| 313 | } |
| 314 | // if rot flags are ENABLED it means we would always |
| 315 | // like to have rot. Even with 0 rot. (solves tearing) |
| 316 | if(utils::ROT_FLAG_ENABLED == mArgs.rotFlags) { |
| 317 | mRot->setEnable(); |
| 318 | } |
| 319 | return startRotator(); |
| 320 | } |
| 321 | |
| 322 | template <int PANEL> |
| 323 | inline bool GenericPipe<PANEL>::setSource( |
| 324 | const utils::PipeArgs& args) |
| 325 | { |
| 326 | // cache the recent args. |
| 327 | mArgs = args; |
| 328 | // setSource is the 1st thing that is being called on a pipe. |
| 329 | // If pipe is closed, we should start everything. |
| 330 | // we assume it is being opened with the correct FDs. |
| 331 | if(isClosed()) { |
| 332 | if(!this->start(args)) { |
| 333 | ALOGE("GenericPipe setSource failed to start"); |
| 334 | return false; |
| 335 | } |
| 336 | return true; |
| 337 | } |
| 338 | |
| 339 | return mCtrlData.ctrl.setSource(args); |
| 340 | } |
| 341 | |
| 342 | template <int PANEL> |
| 343 | inline utils::Dim GenericPipe<PANEL>::getAspectRatio( |
| 344 | const utils::Whf& whf) const |
| 345 | { |
| 346 | return mCtrlData.ctrl.getAspectRatio(whf); |
| 347 | } |
| 348 | |
| 349 | template <int PANEL> |
| 350 | inline utils::Dim GenericPipe<PANEL>::getAspectRatio( |
| 351 | const utils::Dim& dim) const |
| 352 | { |
| 353 | return mCtrlData.ctrl.getAspectRatio(dim); |
| 354 | } |
| 355 | |
| 356 | template <int PANEL> |
| 357 | inline utils::ScreenInfo GenericPipe<PANEL>::getScreenInfo() const |
| 358 | { |
| 359 | return mCtrlData.ctrl.getScreenInfo(); |
| 360 | } |
| 361 | |
| 362 | template <int PANEL> |
| 363 | inline utils::Dim GenericPipe<PANEL>::getCrop() const |
| 364 | { |
| 365 | return mCtrlData.ctrl.getCrop(); |
| 366 | } |
| 367 | |
| 368 | template <int PANEL> |
| 369 | inline utils::eOverlayPipeType GenericPipe<PANEL>::getOvPipeType() const { |
| 370 | return utils::OV_PIPE_TYPE_GENERIC; |
| 371 | } |
| 372 | |
| 373 | template <int PANEL> |
| 374 | void GenericPipe<PANEL>::dump() const |
| 375 | { |
| 376 | ALOGE("== Dump Generic pipe start =="); |
| 377 | ALOGE("flags=0x%x", mFlags); |
| 378 | OVASSERT(mRot, "GenericPipe should have a valid Rot"); |
| 379 | mCtrlData.ctrl.dump(); |
| 380 | mCtrlData.data.dump(); |
| 381 | mRot->dump(); |
| 382 | ALOGE("== Dump Generic pipe end =="); |
| 383 | } |
| 384 | |
| 385 | template <int PANEL> |
| 386 | inline bool GenericPipe<PANEL>::isClosed() const { |
| 387 | return utils::getBit(mFlags, CLOSED); |
| 388 | } |
| 389 | |
| 390 | template <int PANEL> |
| 391 | inline bool GenericPipe<PANEL>::isOpen() const { |
| 392 | return !isClosed(); |
| 393 | } |
| 394 | |
| 395 | template <int PANEL> |
| 396 | inline bool GenericPipe<PANEL>::setClosed() { |
| 397 | return utils::setBit(mFlags, CLOSED); |
| 398 | } |
| 399 | |
| 400 | |
| 401 | } //namespace overlay |
| 402 | |
| 403 | #endif // OVERLAY_GENERIC_PIPE_H |