1 /* 2 * Copyright (c) 2012-2013, The Linux Foundation. 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 The Linux Foundation 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_CTRLDATA_H 31 #define OVERLAY_CTRLDATA_H 32 33 #include "overlayUtils.h" 34 #include "overlayMdp.h" 35 #include "gralloc_priv.h" // INTERLACE_MASK 36 37 namespace ovutils = overlay::utils; 38 39 namespace overlay { 40 41 /* 42 * Sequence to use: 43 * init 44 * start 45 * setXXX 46 * close 47 * */ 48 class Ctrl : utils::NoCopy { 49 public: 50 51 /* ctor */ 52 explicit Ctrl(const int& dpy); 53 /* dtor close */ 54 ~Ctrl(); 55 56 /* set source using whf, orient and wait flag */ 57 void setSource(const utils::PipeArgs& args); 58 /* set crop info and pass it down to mdp */ 59 void setCrop(const utils::Dim& d); 60 /* set color for mdp pipe */ 61 void setColor(const uint32_t color); 62 /* set orientation */ 63 void setTransform(const utils::eTransform& p); 64 /* set mdp position using dim */ 65 void setPosition(const utils::Dim& dim); 66 /* set mdp visual params using metadata */ 67 bool setVisualParams(const MetaData_t &metadata); 68 /* mdp set overlay/commit changes */ 69 bool commit(); 70 71 /* ctrl id */ 72 int getPipeId() const; 73 /* ctrl fd */ 74 int getFd() const; 75 /* retrieve crop data */ 76 utils::Dim getCrop() const; 77 utils::Dim getPosition() const; 78 /* Set downscale */ 79 void setDownscale(int dscale_factor); 80 /* Update the src format based on rotator's dest */ 81 void updateSrcFormat(const uint32_t& rotDstFormat); 82 /* return pipe priority */ 83 uint8_t getPriority() const; 84 /* dump the state of the object */ 85 void dump() const; 86 /* Return the dump in the specified buffer */ 87 void getDump(char *buf, size_t len); 88 89 static bool validateAndSet(Ctrl* ctrlArray[], const int& count, 90 const int& fbFd); 91 private: 92 // mdp ctrl struct(info e.g.) 93 MdpCtrl *mMdp; 94 }; 95 96 97 class Data : utils::NoCopy { 98 public: 99 /* init, reset */ 100 explicit Data(const int& dpy); 101 /* calls close */ 102 ~Data(); 103 /* set overlay pipe id in the mdp struct */ 104 void setPipeId(int id); 105 /* get overlay id in the mdp struct */ 106 int getPipeId() const; 107 /* queue buffer to the overlay */ 108 bool queueBuffer(int fd, uint32_t offset); 109 /* sump the state of the obj */ 110 void dump() const; 111 /* Return the dump in the specified buffer */ 112 void getDump(char *buf, size_t len); 113 114 private: 115 // mdp data struct 116 MdpData *mMdp; 117 }; 118 119 //-------------Inlines------------------------------- 120 121 inline Ctrl::Ctrl(const int& dpy) : mMdp(new MdpCtrl(dpy)) { 122 } 123 124 inline Ctrl::~Ctrl() { 125 delete mMdp; 126 } 127 128 inline void Ctrl::setSource(const utils::PipeArgs& args) 129 { 130 mMdp->setSource(args); 131 } 132 133 inline void Ctrl::setPosition(const utils::Dim& dim) 134 { 135 mMdp->setPosition(dim); 136 } 137 138 inline void Ctrl::setTransform(const utils::eTransform& orient) 139 { 140 mMdp->setTransform(orient); 141 } 142 143 inline void Ctrl::setCrop(const utils::Dim& d) 144 { 145 mMdp->setCrop(d); 146 } 147 148 inline void Ctrl::setColor(const uint32_t color) 149 { 150 mMdp->setColor(color); 151 } 152 153 inline bool Ctrl::setVisualParams(const MetaData_t &metadata) 154 { 155 if (!mMdp->setVisualParams(metadata)) { 156 ALOGE("Ctrl setVisualParams failed in MDP setVisualParams"); 157 return false; 158 } 159 return true; 160 } 161 162 inline void Ctrl::dump() const { 163 ALOGE("== Dump Ctrl start =="); 164 mMdp->dump(); 165 ALOGE("== Dump Ctrl end =="); 166 } 167 168 inline bool Ctrl::commit() { 169 if(!mMdp->set()) { 170 ALOGE("Ctrl commit failed set overlay"); 171 return false; 172 } 173 return true; 174 } 175 176 inline int Ctrl::getPipeId() const { 177 return mMdp->getPipeId(); 178 } 179 180 inline int Ctrl::getFd() const { 181 return mMdp->getFd(); 182 } 183 184 inline void Ctrl::updateSrcFormat(const uint32_t& rotDstFmt) { 185 mMdp->updateSrcFormat(rotDstFmt); 186 } 187 188 inline bool Ctrl::validateAndSet(Ctrl* ctrlArray[], const int& count, 189 const int& fbFd) { 190 MdpCtrl* mdpCtrlArray[count]; 191 memset(&mdpCtrlArray, 0, sizeof(mdpCtrlArray)); 192 193 for(int i = 0; i < count; i++) { 194 mdpCtrlArray[i] = ctrlArray[i]->mMdp; 195 } 196 197 bool ret = MdpCtrl::validateAndSet(mdpCtrlArray, count, fbFd); 198 return ret; 199 } 200 201 inline utils::Dim Ctrl::getCrop() const { 202 return mMdp->getSrcRectDim(); 203 } 204 205 inline utils::Dim Ctrl::getPosition() const { 206 return mMdp->getDstRectDim(); 207 } 208 209 inline void Ctrl::setDownscale(int dscale_factor) { 210 mMdp->setDownscale(dscale_factor); 211 } 212 213 inline uint8_t Ctrl::getPriority() const { 214 return mMdp->getPriority(); 215 } 216 217 inline void Ctrl::getDump(char *buf, size_t len) { 218 mMdp->getDump(buf, len); 219 } 220 221 inline Data::Data(const int& dpy) : mMdp(new MdpData(dpy)) { 222 } 223 224 inline Data::~Data() { 225 delete mMdp; 226 } 227 228 inline void Data::setPipeId(int id) { mMdp->setPipeId(id); } 229 230 inline int Data::getPipeId() const { return mMdp->getPipeId(); } 231 232 inline bool Data::queueBuffer(int fd, uint32_t offset) { 233 return mMdp->play(fd, offset); 234 } 235 236 inline void Data::dump() const { 237 ALOGE("== Dump Data MDP start =="); 238 mMdp->dump(); 239 ALOGE("== Dump Data MDP end =="); 240 } 241 242 inline void Data::getDump(char *buf, size_t len) { 243 mMdp->getDump(buf, len); 244 } 245 246 } // overlay 247 248 #endif 249