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); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 68 | /* mdp set overlay/commit changes */ |
| 69 | bool commit(); |
| 70 | |
| 71 | /* ctrl id */ |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 72 | int getPipeId() const; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 73 | /* ctrl fd */ |
| 74 | int getFd() const; |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 75 | /* retrieve crop data */ |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 76 | utils::Dim getCrop() const; |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 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); |
Saurabh Shah | 0d0a7cb | 2013-02-12 17:58:19 -0800 | [diff] [blame] | 82 | /* dump the state of the object */ |
| 83 | void dump() const; |
Saurabh Shah | 0d0a7cb | 2013-02-12 17:58:19 -0800 | [diff] [blame] | 84 | /* Return the dump in the specified buffer */ |
| 85 | void getDump(char *buf, size_t len); |
| 86 | |
Saurabh Shah | a36be92 | 2013-12-16 18:18:39 -0800 | [diff] [blame^] | 87 | static bool validateAndSet(Ctrl* ctrlArray[], const int& count, |
| 88 | const int& fbFd); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 89 | private: |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 90 | // mdp ctrl struct(info e.g.) |
Saurabh Shah | d18d88a | 2014-01-06 15:02:49 -0800 | [diff] [blame] | 91 | MdpCtrl *mMdp; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 92 | }; |
| 93 | |
| 94 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 95 | class Data : utils::NoCopy { |
| 96 | public: |
| 97 | /* init, reset */ |
Saurabh Shah | d18d88a | 2014-01-06 15:02:49 -0800 | [diff] [blame] | 98 | explicit Data(const int& dpy); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 99 | /* calls close */ |
| 100 | ~Data(); |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 101 | /* set overlay pipe id in the mdp struct */ |
| 102 | void setPipeId(int id); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 103 | /* get overlay id in the mdp struct */ |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 104 | int getPipeId() const; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 105 | /* queue buffer to the overlay */ |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 106 | bool queueBuffer(int fd, uint32_t offset); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 107 | /* sump the state of the obj */ |
| 108 | void dump() const; |
Saurabh Shah | 0d0a7cb | 2013-02-12 17:58:19 -0800 | [diff] [blame] | 109 | /* Return the dump in the specified buffer */ |
| 110 | void getDump(char *buf, size_t len); |
| 111 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 112 | private: |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 113 | // mdp data struct |
Saurabh Shah | d18d88a | 2014-01-06 15:02:49 -0800 | [diff] [blame] | 114 | MdpData *mMdp; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 115 | }; |
| 116 | |
| 117 | //-------------Inlines------------------------------- |
| 118 | |
Saurabh Shah | d18d88a | 2014-01-06 15:02:49 -0800 | [diff] [blame] | 119 | inline Ctrl::Ctrl(const int& dpy) : mMdp(new MdpCtrl(dpy)) { |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | inline Ctrl::~Ctrl() { |
Saurabh Shah | d18d88a | 2014-01-06 15:02:49 -0800 | [diff] [blame] | 123 | delete mMdp; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 124 | } |
| 125 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 126 | inline void Ctrl::setSource(const utils::PipeArgs& args) |
| 127 | { |
Saurabh Shah | d18d88a | 2014-01-06 15:02:49 -0800 | [diff] [blame] | 128 | mMdp->setSource(args); |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | inline void Ctrl::setPosition(const utils::Dim& dim) |
| 132 | { |
Saurabh Shah | d18d88a | 2014-01-06 15:02:49 -0800 | [diff] [blame] | 133 | mMdp->setPosition(dim); |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | inline void Ctrl::setTransform(const utils::eTransform& orient) |
| 137 | { |
Saurabh Shah | d18d88a | 2014-01-06 15:02:49 -0800 | [diff] [blame] | 138 | mMdp->setTransform(orient); |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | inline void Ctrl::setCrop(const utils::Dim& d) |
| 142 | { |
Saurabh Shah | d18d88a | 2014-01-06 15:02:49 -0800 | [diff] [blame] | 143 | mMdp->setCrop(d); |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 144 | } |
| 145 | |
Sushil Chauhan | 897a9c3 | 2013-07-18 11:09:55 -0700 | [diff] [blame] | 146 | inline void Ctrl::setColor(const uint32_t color) |
| 147 | { |
Saurabh Shah | d18d88a | 2014-01-06 15:02:49 -0800 | [diff] [blame] | 148 | mMdp->setColor(color); |
Sushil Chauhan | 897a9c3 | 2013-07-18 11:09:55 -0700 | [diff] [blame] | 149 | } |
| 150 | |
Saurabh Shah | 5daeee5 | 2013-01-23 16:52:26 +0800 | [diff] [blame] | 151 | inline bool Ctrl::setVisualParams(const MetaData_t &metadata) |
| 152 | { |
Saurabh Shah | d18d88a | 2014-01-06 15:02:49 -0800 | [diff] [blame] | 153 | if (!mMdp->setVisualParams(metadata)) { |
Saurabh Shah | 5daeee5 | 2013-01-23 16:52:26 +0800 | [diff] [blame] | 154 | ALOGE("Ctrl setVisualParams failed in MDP setVisualParams"); |
| 155 | return false; |
| 156 | } |
| 157 | return true; |
| 158 | } |
| 159 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 160 | inline void Ctrl::dump() const { |
| 161 | ALOGE("== Dump Ctrl start =="); |
Saurabh Shah | d18d88a | 2014-01-06 15:02:49 -0800 | [diff] [blame] | 162 | mMdp->dump(); |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 163 | ALOGE("== Dump Ctrl end =="); |
| 164 | } |
| 165 | |
| 166 | inline bool Ctrl::commit() { |
Saurabh Shah | d18d88a | 2014-01-06 15:02:49 -0800 | [diff] [blame] | 167 | if(!mMdp->set()) { |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 168 | ALOGE("Ctrl commit failed set overlay"); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 169 | return false; |
| 170 | } |
| 171 | return true; |
| 172 | } |
| 173 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 174 | inline int Ctrl::getPipeId() const { |
Saurabh Shah | d18d88a | 2014-01-06 15:02:49 -0800 | [diff] [blame] | 175 | return mMdp->getPipeId(); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | inline int Ctrl::getFd() const { |
Saurabh Shah | d18d88a | 2014-01-06 15:02:49 -0800 | [diff] [blame] | 179 | return mMdp->getFd(); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 180 | } |
| 181 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 182 | inline void Ctrl::updateSrcFormat(const uint32_t& rotDstFmt) { |
Saurabh Shah | d18d88a | 2014-01-06 15:02:49 -0800 | [diff] [blame] | 183 | mMdp->updateSrcFormat(rotDstFmt); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 184 | } |
| 185 | |
Saurabh Shah | a36be92 | 2013-12-16 18:18:39 -0800 | [diff] [blame^] | 186 | inline bool Ctrl::validateAndSet(Ctrl* ctrlArray[], const int& count, |
| 187 | const int& fbFd) { |
| 188 | MdpCtrl* mdpCtrlArray[count]; |
| 189 | memset(&mdpCtrlArray, 0, sizeof(mdpCtrlArray)); |
| 190 | |
| 191 | for(int i = 0; i < count; i++) { |
| 192 | mdpCtrlArray[i] = ctrlArray[i]->mMdp; |
| 193 | } |
| 194 | |
| 195 | bool ret = MdpCtrl::validateAndSet(mdpCtrlArray, count, fbFd); |
| 196 | return ret; |
| 197 | } |
| 198 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 199 | inline utils::Dim Ctrl::getCrop() const { |
Saurabh Shah | d18d88a | 2014-01-06 15:02:49 -0800 | [diff] [blame] | 200 | return mMdp->getSrcRectDim(); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 201 | } |
| 202 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 203 | inline utils::Dim Ctrl::getPosition() const { |
Saurabh Shah | d18d88a | 2014-01-06 15:02:49 -0800 | [diff] [blame] | 204 | return mMdp->getDstRectDim(); |
Ramkumar Radhakrishnan | 288f8c7 | 2013-01-15 11:37:54 -0800 | [diff] [blame] | 205 | } |
| 206 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 207 | inline void Ctrl::setDownscale(int dscale_factor) { |
Saurabh Shah | d18d88a | 2014-01-06 15:02:49 -0800 | [diff] [blame] | 208 | mMdp->setDownscale(dscale_factor); |
Ramkumar Radhakrishnan | 288f8c7 | 2013-01-15 11:37:54 -0800 | [diff] [blame] | 209 | } |
| 210 | |
Saurabh Shah | 0d0a7cb | 2013-02-12 17:58:19 -0800 | [diff] [blame] | 211 | inline void Ctrl::getDump(char *buf, size_t len) { |
Saurabh Shah | d18d88a | 2014-01-06 15:02:49 -0800 | [diff] [blame] | 212 | mMdp->getDump(buf, len); |
Saurabh Shah | 0d0a7cb | 2013-02-12 17:58:19 -0800 | [diff] [blame] | 213 | } |
| 214 | |
Saurabh Shah | d18d88a | 2014-01-06 15:02:49 -0800 | [diff] [blame] | 215 | inline Data::Data(const int& dpy) : mMdp(new MdpData(dpy)) { |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 216 | } |
| 217 | |
Saurabh Shah | d18d88a | 2014-01-06 15:02:49 -0800 | [diff] [blame] | 218 | inline Data::~Data() { |
| 219 | delete mMdp; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 220 | } |
| 221 | |
Saurabh Shah | d18d88a | 2014-01-06 15:02:49 -0800 | [diff] [blame] | 222 | inline void Data::setPipeId(int id) { mMdp->setPipeId(id); } |
| 223 | |
| 224 | inline int Data::getPipeId() const { return mMdp->getPipeId(); } |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 225 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 226 | inline bool Data::queueBuffer(int fd, uint32_t offset) { |
Saurabh Shah | d18d88a | 2014-01-06 15:02:49 -0800 | [diff] [blame] | 227 | return mMdp->play(fd, offset); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 228 | } |
| 229 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 230 | inline void Data::dump() const { |
| 231 | ALOGE("== Dump Data MDP start =="); |
Saurabh Shah | d18d88a | 2014-01-06 15:02:49 -0800 | [diff] [blame] | 232 | mMdp->dump(); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 233 | ALOGE("== Dump Data MDP end =="); |
| 234 | } |
| 235 | |
Saurabh Shah | 0d0a7cb | 2013-02-12 17:58:19 -0800 | [diff] [blame] | 236 | inline void Data::getDump(char *buf, size_t len) { |
Saurabh Shah | d18d88a | 2014-01-06 15:02:49 -0800 | [diff] [blame] | 237 | mMdp->getDump(buf, len); |
Saurabh Shah | 0d0a7cb | 2013-02-12 17:58:19 -0800 | [diff] [blame] | 238 | } |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 239 | |
| 240 | } // overlay |
| 241 | |
| 242 | #endif |