overlayMdp.h revision ab05b00fefd34a761dfaf1ccaf8ad14d325873f4
1/* 2* Copyright (C) 2008 The Android Open Source Project 3* Copyright (c) 2010-2013, The Linux Foundation. All rights reserved. 4* 5* Licensed under the Apache License, Version 2.0 (the "License"); 6* you may not use this file except in compliance with the License. 7* You may obtain a copy of the License at 8* 9* http://www.apache.org/licenses/LICENSE-2.0 10* 11* Unless required by applicable law or agreed to in writing, software 12* distributed under the License is distributed on an "AS IS" BASIS, 13* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14* See the License for the specific language governing permissions and 15* limitations under the License. 16*/ 17 18#ifndef OVERLAY_MDP_H 19#define OVERLAY_MDP_H 20 21#include <linux/msm_mdp.h> 22 23#include "overlayUtils.h" 24#include "mdpWrapper.h" 25#include "qdMetaData.h" 26#ifdef USES_POST_PROCESSING 27#include "lib-postproc.h" 28#endif 29 30namespace overlay{ 31 32/* 33* Mdp Ctrl holds corresponding fd and MDP related struct. 34* It is simple wrapper to MDP services 35* */ 36class MdpCtrl { 37public: 38 /* ctor reset */ 39 explicit MdpCtrl(const int& dpy); 40 /* dtor close */ 41 ~MdpCtrl(); 42 /* init underlying device using fbnum for dpy */ 43 bool init(const int& dpy); 44 /* unset overlay, reset and close fd */ 45 bool close(); 46 /* reset and set ov id to -1 / MSMFB_NEW_REQUEST */ 47 void reset(); 48 /* calls overlay set 49 * Set would always consult last good known ov instance. 50 * Only if it is different, set would actually exectue ioctl. 51 * On a sucess ioctl. last good known ov instance is updated */ 52 bool set(); 53 /* Sets the source total width, height, format */ 54 void setSource(const utils::PipeArgs& pargs); 55 /* 56 * Sets ROI, the unpadded region, for source buffer. 57 * Dim - ROI dimensions. 58 */ 59 void setCrop(const utils::Dim& d); 60 /* set color for mdp pipe */ 61 void setColor(const uint32_t color); 62 void setTransform(const utils::eTransform& orient); 63 /* given a dim and w/h, set overlay dim */ 64 void setPosition(const utils::Dim& dim); 65 /* using user_data, sets/unsets roationvalue in mdp flags */ 66 void setRotationFlags(); 67 /* Performs downscale calculations */ 68 void setDownscale(int dscale_factor); 69 /* Update the src format with rotator's dest*/ 70 void updateSrcFormat(const uint32_t& rotDstFormat); 71 /* dump state of the object */ 72 void dump() const; 73 /* Return the dump in the specified buffer */ 74 void getDump(char *buf, size_t len); 75 /* returns session id */ 76 int getPipeId() const; 77 /* returns the fd associated to ctrl*/ 78 int getFd() const; 79 /* returns a copy ro dst rect dim */ 80 utils::Dim getDstRectDim() const; 81 /* returns a copy to src rect dim */ 82 utils::Dim getSrcRectDim() const; 83 /* return pipe priority */ 84 uint8_t getPriority() const; 85 /* setVisualParam */ 86 bool setVisualParams(const MetaData_t& data); 87 /* sets pipe type RGB/DMA/VG */ 88 void setPipeType(const utils::eMdpPipeType& pType); 89 90 static bool validateAndSet(MdpCtrl* mdpCtrlArray[], const int& count, 91 const int& fbFd); 92private: 93 /* Perform transformation calculations */ 94 void doTransform(); 95 void doDownscale(); 96 /* get orient / user_data[0] */ 97 int getOrient() const; 98 /* returns flags from mdp structure */ 99 int getFlags() const; 100 /* set flags to mdp structure */ 101 void setFlags(int f); 102 /* set z order */ 103 void setZ(utils::eZorder z); 104 /* set isFg flag */ 105 void setIsFg(utils::eIsFg isFg); 106 /* return a copy of src whf*/ 107 utils::Whf getSrcWhf() const; 108 /* set plane alpha */ 109 void setPlaneAlpha(int planeAlpha); 110 /* set blending method */ 111 void setBlending(overlay::utils::eBlending blending); 112 113 /* set src whf */ 114 void setSrcWhf(const utils::Whf& whf); 115 /* set src/dst rect dim */ 116 void setSrcRectDim(const utils::Dim d); 117 void setDstRectDim(const utils::Dim d); 118 /* returns user_data[0]*/ 119 int getUserData() const; 120 /* sets user_data[0] */ 121 void setUserData(int v); 122 123 utils::eTransform mOrientation; //Holds requested orientation 124 /* Actual overlay mdp structure */ 125 mdp_overlay mOVInfo; 126 /* FD for the mdp fbnum */ 127 OvFD mFd; 128 int mDownscale; 129 int mDpy; 130 131#ifdef USES_POST_PROCESSING 132 /* PP Compute Params */ 133 struct compute_params mParams; 134#endif 135}; 136 137 138/* MDP 3D related ctrl */ 139class MdpCtrl3D { 140public: 141 /* ctor reset data */ 142 MdpCtrl3D(); 143 /* calls MSMFB_OVERLAY_3D */ 144 bool close(); 145 /* set w/h. format is ignored*/ 146 void setWh(const utils::Whf& whf); 147 /* set is_3d calls MSMFB_OVERLAY_3D */ 148 bool useVirtualFB(); 149 /* set fd to be used in ioctl */ 150 void setFd(int fd); 151 /* dump */ 152 void dump() const; 153private: 154 /* reset */ 155 void reset(); 156 /* actual MSM 3D info */ 157 msmfb_overlay_3d m3DOVInfo; 158 /* FD for the mdp 3D */ 159 OvFD mFd; 160}; 161 162/* MDP data */ 163class MdpData { 164public: 165 /* ctor reset data */ 166 explicit MdpData(const int& dpy); 167 /* dtor close*/ 168 ~MdpData(); 169 /* init FD */ 170 bool init(const int& dpy); 171 /* memset0 the underlying mdp object */ 172 void reset(); 173 /* close fd, and reset */ 174 bool close(); 175 /* set id of mdp data */ 176 void setPipeId(int id); 177 /* return ses id of data */ 178 int getPipeId() const; 179 /* get underlying fd*/ 180 int getFd() const; 181 /* get memory_id */ 182 int getSrcMemoryId() const; 183 /* calls wrapper play */ 184 bool play(int fd, uint32_t offset); 185 /* dump state of the object */ 186 void dump() const; 187 /* Return the dump in the specified buffer */ 188 void getDump(char *buf, size_t len); 189 190private: 191 192 /* actual overlay mdp data */ 193 msmfb_overlay_data mOvData; 194 /* fd to mdp fbnum */ 195 OvFD mFd; 196}; 197 198//--------------Inlines--------------------------------- 199 200///// MdpCtrl ////// 201 202inline MdpCtrl::MdpCtrl(const int& dpy) { 203 reset(); 204 init(dpy); 205} 206 207inline MdpCtrl::~MdpCtrl() { 208 close(); 209} 210 211inline int MdpCtrl::getOrient() const { 212 return getUserData(); 213} 214 215inline int MdpCtrl::getPipeId() const { 216 return mOVInfo.id; 217} 218 219inline int MdpCtrl::getFd() const { 220 return mFd.getFD(); 221} 222 223inline int MdpCtrl::getFlags() const { 224 return mOVInfo.flags; 225} 226 227inline void MdpCtrl::setFlags(int f) { 228 mOVInfo.flags = f; 229} 230 231inline void MdpCtrl::setZ(overlay::utils::eZorder z) { 232 mOVInfo.z_order = z; 233} 234 235inline void MdpCtrl::setIsFg(overlay::utils::eIsFg isFg) { 236 mOVInfo.is_fg = isFg; 237} 238 239inline void MdpCtrl::setDownscale(int dscale) { 240 mDownscale = dscale; 241} 242 243inline void MdpCtrl::setPlaneAlpha(int planeAlpha) { 244 mOVInfo.alpha = planeAlpha; 245} 246 247inline void MdpCtrl::setBlending(overlay::utils::eBlending blending) { 248 switch((int) blending) { 249 case utils::OVERLAY_BLENDING_OPAQUE: 250 mOVInfo.blend_op = BLEND_OP_OPAQUE; 251 break; 252 case utils::OVERLAY_BLENDING_PREMULT: 253 mOVInfo.blend_op = BLEND_OP_PREMULTIPLIED; 254 break; 255 case utils::OVERLAY_BLENDING_COVERAGE: 256 default: 257 mOVInfo.blend_op = BLEND_OP_COVERAGE; 258 } 259} 260 261inline overlay::utils::Whf MdpCtrl::getSrcWhf() const { 262 return utils::Whf( mOVInfo.src.width, 263 mOVInfo.src.height, 264 mOVInfo.src.format); 265} 266 267inline void MdpCtrl::setSrcWhf(const overlay::utils::Whf& whf) { 268 mOVInfo.src.width = whf.w; 269 mOVInfo.src.height = whf.h; 270 mOVInfo.src.format = whf.format; 271} 272 273inline overlay::utils::Dim MdpCtrl::getSrcRectDim() const { 274 return utils::Dim( mOVInfo.src_rect.x, 275 mOVInfo.src_rect.y, 276 mOVInfo.src_rect.w, 277 mOVInfo.src_rect.h); 278} 279 280inline void MdpCtrl::setSrcRectDim(const overlay::utils::Dim d) { 281 mOVInfo.src_rect.x = d.x; 282 mOVInfo.src_rect.y = d.y; 283 mOVInfo.src_rect.w = d.w; 284 mOVInfo.src_rect.h = d.h; 285} 286 287inline overlay::utils::Dim MdpCtrl::getDstRectDim() const { 288 return utils::Dim( mOVInfo.dst_rect.x, 289 mOVInfo.dst_rect.y, 290 mOVInfo.dst_rect.w, 291 mOVInfo.dst_rect.h); 292} 293 294inline void MdpCtrl::setDstRectDim(const overlay::utils::Dim d) { 295 mOVInfo.dst_rect.x = d.x; 296 mOVInfo.dst_rect.y = d.y; 297 mOVInfo.dst_rect.w = d.w; 298 mOVInfo.dst_rect.h = d.h; 299} 300 301inline int MdpCtrl::getUserData() const { return mOVInfo.user_data[0]; } 302 303inline void MdpCtrl::setUserData(int v) { mOVInfo.user_data[0] = v; } 304 305inline void MdpCtrl::setRotationFlags() { 306 const int u = getUserData(); 307 if (u & MDP_ROT_90) 308 mOVInfo.flags |= MDP_SOURCE_ROTATED_90; 309} 310 311inline uint8_t MdpCtrl::getPriority() const { 312 return mOVInfo.priority; 313} 314 315/////// MdpCtrl3D ////// 316 317inline MdpCtrl3D::MdpCtrl3D() { reset(); } 318inline bool MdpCtrl3D::close() { 319 if (m3DOVInfo.is_3d) { 320 m3DOVInfo.is_3d = 0; 321 if(!mdp_wrapper::set3D(mFd.getFD(), m3DOVInfo)) { 322 ALOGE("MdpCtrl3D close failed set3D with 0"); 323 return false; 324 } 325 } 326 reset(); 327 return true; 328} 329inline void MdpCtrl3D::reset() { 330 utils::memset0(m3DOVInfo); 331} 332 333inline void MdpCtrl3D::setFd(int fd) { 334 mFd.copy(fd); 335 OVASSERT(mFd.valid(), "MdpCtrl3D setFd, FD should be valid"); 336} 337 338inline void MdpCtrl3D::setWh(const utils::Whf& whf) { 339 // ignore fmt. Needed for useVirtualFB callflow 340 m3DOVInfo.width = whf.w; 341 m3DOVInfo.height = whf.h; 342} 343 344inline bool MdpCtrl3D::useVirtualFB() { 345 if(!m3DOVInfo.is_3d) { 346 m3DOVInfo.is_3d = 1; 347 if(!mdp_wrapper::set3D(mFd.getFD(), m3DOVInfo)) { 348 ALOGE("MdpCtrl3D close failed set3D with 0"); 349 return false; 350 } 351 } 352 return true; 353} 354 355/////// MdpData ////// 356 357inline MdpData::MdpData(const int& dpy) { 358 reset(); 359 init(dpy); 360} 361 362inline MdpData::~MdpData() { close(); } 363 364inline void MdpData::reset() { 365 overlay::utils::memset0(mOvData); 366 mOvData.data.memory_id = -1; 367} 368 369inline bool MdpData::close() { 370 reset(); 371 return mFd.close(); 372} 373 374inline int MdpData::getSrcMemoryId() const { return mOvData.data.memory_id; } 375 376inline void MdpData::setPipeId(int id) { mOvData.id = id; } 377 378inline int MdpData::getPipeId() const { return mOvData.id; } 379 380inline int MdpData::getFd() const { return mFd.getFD(); } 381 382inline bool MdpData::play(int fd, uint32_t offset) { 383 mOvData.data.memory_id = fd; 384 mOvData.data.offset = offset; 385 if(!mdp_wrapper::play(mFd.getFD(), mOvData)){ 386 ALOGE("MdpData failed to play"); 387 dump(); 388 return false; 389 } 390 return true; 391} 392 393} // overlay 394 395#endif // OVERLAY_MDP_H 396