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