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 30 namespace overlay{ 31 32 /* 33 * Mdp Ctrl holds corresponding fd and MDP related struct. 34 * It is simple wrapper to MDP services 35 * */ 36 class MdpCtrl { 37 public: 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 /* setVisualParam */ 84 bool setVisualParams(const MetaData_t& data); 85 86 static bool validateAndSet(MdpCtrl* mdpCtrlArray[], const int& count, 87 const int& fbFd); 88 private: 89 /* Perform transformation calculations */ 90 void doTransform(); 91 void doDownscale(); 92 /* get orient / user_data[0] */ 93 int getOrient() const; 94 /* returns flags from mdp structure */ 95 int getFlags() const; 96 /* set flags to mdp structure */ 97 void setFlags(int f); 98 /* set z order */ 99 void setZ(utils::eZorder z); 100 /* set isFg flag */ 101 void setIsFg(utils::eIsFg isFg); 102 /* return a copy of src whf*/ 103 utils::Whf getSrcWhf() const; 104 /* set plane alpha */ 105 void setPlaneAlpha(int planeAlpha); 106 /* set blending method */ 107 void setBlending(overlay::utils::eBlending blending); 108 109 /* set src whf */ 110 void setSrcWhf(const utils::Whf& whf); 111 /* set src/dst rect dim */ 112 void setSrcRectDim(const utils::Dim d); 113 void setDstRectDim(const utils::Dim d); 114 /* returns user_data[0]*/ 115 int getUserData() const; 116 /* sets user_data[0] */ 117 void setUserData(int v); 118 119 utils::eTransform mOrientation; //Holds requested orientation 120 /* Actual overlay mdp structure */ 121 mdp_overlay mOVInfo; 122 /* FD for the mdp fbnum */ 123 OvFD mFd; 124 int mDownscale; 125 int mDpy; 126 127 #ifdef USES_POST_PROCESSING 128 /* PP Compute Params */ 129 struct compute_params mParams; 130 #endif 131 }; 132 133 134 /* MDP 3D related ctrl */ 135 class MdpCtrl3D { 136 public: 137 /* ctor reset data */ 138 MdpCtrl3D(); 139 /* calls MSMFB_OVERLAY_3D */ 140 bool close(); 141 /* set w/h. format is ignored*/ 142 void setWh(const utils::Whf& whf); 143 /* set is_3d calls MSMFB_OVERLAY_3D */ 144 bool useVirtualFB(); 145 /* set fd to be used in ioctl */ 146 void setFd(int fd); 147 /* dump */ 148 void dump() const; 149 private: 150 /* reset */ 151 void reset(); 152 /* actual MSM 3D info */ 153 msmfb_overlay_3d m3DOVInfo; 154 /* FD for the mdp 3D */ 155 OvFD mFd; 156 }; 157 158 /* MDP data */ 159 class MdpData { 160 public: 161 /* ctor reset data */ 162 explicit MdpData(const int& dpy); 163 /* dtor close*/ 164 ~MdpData(); 165 /* init FD */ 166 bool init(const int& dpy); 167 /* memset0 the underlying mdp object */ 168 void reset(); 169 /* close fd, and reset */ 170 bool close(); 171 /* set id of mdp data */ 172 void setPipeId(int id); 173 /* return ses id of data */ 174 int getPipeId() const; 175 /* get underlying fd*/ 176 int getFd() const; 177 /* get memory_id */ 178 int getSrcMemoryId() const; 179 /* calls wrapper play */ 180 bool play(int fd, uint32_t offset); 181 /* dump state of the object */ 182 void dump() const; 183 /* Return the dump in the specified buffer */ 184 void getDump(char *buf, size_t len); 185 186 private: 187 188 /* actual overlay mdp data */ 189 msmfb_overlay_data mOvData; 190 /* fd to mdp fbnum */ 191 OvFD mFd; 192 }; 193 194 //--------------Inlines--------------------------------- 195 196 ///// MdpCtrl ////// 197 198 inline MdpCtrl::MdpCtrl(const int& dpy) { 199 reset(); 200 init(dpy); 201 } 202 203 inline MdpCtrl::~MdpCtrl() { 204 close(); 205 } 206 207 inline int MdpCtrl::getOrient() const { 208 return getUserData(); 209 } 210 211 inline int MdpCtrl::getPipeId() const { 212 return mOVInfo.id; 213 } 214 215 inline int MdpCtrl::getFd() const { 216 return mFd.getFD(); 217 } 218 219 inline int MdpCtrl::getFlags() const { 220 return mOVInfo.flags; 221 } 222 223 inline void MdpCtrl::setFlags(int f) { 224 mOVInfo.flags = f; 225 } 226 227 inline void MdpCtrl::setZ(overlay::utils::eZorder z) { 228 mOVInfo.z_order = z; 229 } 230 231 inline void MdpCtrl::setIsFg(overlay::utils::eIsFg isFg) { 232 mOVInfo.is_fg = isFg; 233 } 234 235 inline void MdpCtrl::setDownscale(int dscale) { 236 mDownscale = dscale; 237 } 238 239 inline void MdpCtrl::setPlaneAlpha(int planeAlpha) { 240 mOVInfo.alpha = planeAlpha; 241 } 242 243 inline void MdpCtrl::setBlending(overlay::utils::eBlending blending) { 244 switch((int) blending) { 245 case utils::OVERLAY_BLENDING_OPAQUE: 246 mOVInfo.blend_op = BLEND_OP_OPAQUE; 247 break; 248 case utils::OVERLAY_BLENDING_PREMULT: 249 mOVInfo.blend_op = BLEND_OP_PREMULTIPLIED; 250 break; 251 case utils::OVERLAY_BLENDING_COVERAGE: 252 default: 253 mOVInfo.blend_op = BLEND_OP_COVERAGE; 254 } 255 } 256 257 inline overlay::utils::Whf MdpCtrl::getSrcWhf() const { 258 return utils::Whf( mOVInfo.src.width, 259 mOVInfo.src.height, 260 mOVInfo.src.format); 261 } 262 263 inline void MdpCtrl::setSrcWhf(const overlay::utils::Whf& whf) { 264 mOVInfo.src.width = whf.w; 265 mOVInfo.src.height = whf.h; 266 mOVInfo.src.format = whf.format; 267 } 268 269 inline overlay::utils::Dim MdpCtrl::getSrcRectDim() const { 270 return utils::Dim( mOVInfo.src_rect.x, 271 mOVInfo.src_rect.y, 272 mOVInfo.src_rect.w, 273 mOVInfo.src_rect.h); 274 } 275 276 inline void MdpCtrl::setSrcRectDim(const overlay::utils::Dim d) { 277 mOVInfo.src_rect.x = d.x; 278 mOVInfo.src_rect.y = d.y; 279 mOVInfo.src_rect.w = d.w; 280 mOVInfo.src_rect.h = d.h; 281 } 282 283 inline overlay::utils::Dim MdpCtrl::getDstRectDim() const { 284 return utils::Dim( mOVInfo.dst_rect.x, 285 mOVInfo.dst_rect.y, 286 mOVInfo.dst_rect.w, 287 mOVInfo.dst_rect.h); 288 } 289 290 inline void MdpCtrl::setDstRectDim(const overlay::utils::Dim d) { 291 mOVInfo.dst_rect.x = d.x; 292 mOVInfo.dst_rect.y = d.y; 293 mOVInfo.dst_rect.w = d.w; 294 mOVInfo.dst_rect.h = d.h; 295 } 296 297 inline int MdpCtrl::getUserData() const { return mOVInfo.user_data[0]; } 298 299 inline void MdpCtrl::setUserData(int v) { mOVInfo.user_data[0] = v; } 300 301 inline void MdpCtrl::setRotationFlags() { 302 const int u = getUserData(); 303 if (u & MDP_ROT_90) 304 mOVInfo.flags |= MDP_SOURCE_ROTATED_90; 305 } 306 307 /////// MdpCtrl3D ////// 308 309 inline MdpCtrl3D::MdpCtrl3D() { reset(); } 310 inline bool MdpCtrl3D::close() { 311 if (m3DOVInfo.is_3d) { 312 m3DOVInfo.is_3d = 0; 313 if(!mdp_wrapper::set3D(mFd.getFD(), m3DOVInfo)) { 314 ALOGE("MdpCtrl3D close failed set3D with 0"); 315 return false; 316 } 317 } 318 reset(); 319 return true; 320 } 321 inline void MdpCtrl3D::reset() { 322 utils::memset0(m3DOVInfo); 323 } 324 325 inline void MdpCtrl3D::setFd(int fd) { 326 mFd.copy(fd); 327 OVASSERT(mFd.valid(), "MdpCtrl3D setFd, FD should be valid"); 328 } 329 330 inline void MdpCtrl3D::setWh(const utils::Whf& whf) { 331 // ignore fmt. Needed for useVirtualFB callflow 332 m3DOVInfo.width = whf.w; 333 m3DOVInfo.height = whf.h; 334 } 335 336 inline bool MdpCtrl3D::useVirtualFB() { 337 if(!m3DOVInfo.is_3d) { 338 m3DOVInfo.is_3d = 1; 339 if(!mdp_wrapper::set3D(mFd.getFD(), m3DOVInfo)) { 340 ALOGE("MdpCtrl3D close failed set3D with 0"); 341 return false; 342 } 343 } 344 return true; 345 } 346 347 /////// MdpData ////// 348 349 inline MdpData::MdpData(const int& dpy) { 350 reset(); 351 init(dpy); 352 } 353 354 inline MdpData::~MdpData() { close(); } 355 356 inline void MdpData::reset() { 357 overlay::utils::memset0(mOvData); 358 mOvData.data.memory_id = -1; 359 } 360 361 inline bool MdpData::close() { 362 reset(); 363 return mFd.close(); 364 } 365 366 inline int MdpData::getSrcMemoryId() const { return mOvData.data.memory_id; } 367 368 inline void MdpData::setPipeId(int id) { mOvData.id = id; } 369 370 inline int MdpData::getPipeId() const { return mOvData.id; } 371 372 inline int MdpData::getFd() const { return mFd.getFD(); } 373 374 inline bool MdpData::play(int fd, uint32_t offset) { 375 mOvData.data.memory_id = fd; 376 mOvData.data.offset = offset; 377 if(!mdp_wrapper::play(mFd.getFD(), mOvData)){ 378 ALOGE("MdpData failed to play"); 379 dump(); 380 return false; 381 } 382 return true; 383 } 384 385 } // overlay 386 387 #endif // OVERLAY_MDP_H 388