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 */ |
| 52 | explicit Ctrl(); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 53 | /* dtor close */ |
| 54 | ~Ctrl(); |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 55 | /* init fd etc*/ |
| 56 | bool init(uint32_t fbnum); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 57 | /* close underlying mdp */ |
| 58 | bool close(); |
| 59 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 60 | /* set source using whf, orient and wait flag */ |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 61 | void setSource(const utils::PipeArgs& args); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 62 | /* set crop info and pass it down to mdp */ |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 63 | void setCrop(const utils::Dim& d); |
Sushil Chauhan | 897a9c3 | 2013-07-18 11:09:55 -0700 | [diff] [blame^] | 64 | /* set color for mdp pipe */ |
| 65 | void setColor(const uint32_t color); |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 66 | /* set orientation */ |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 67 | void setTransform(const utils::eTransform& p); |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 68 | /* set mdp position using dim */ |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 69 | void setPosition(const utils::Dim& dim); |
Saurabh Shah | 5daeee5 | 2013-01-23 16:52:26 +0800 | [diff] [blame] | 70 | /* set mdp visual params using metadata */ |
| 71 | bool setVisualParams(const MetaData_t &metadata); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 72 | /* mdp set overlay/commit changes */ |
| 73 | bool commit(); |
| 74 | |
| 75 | /* ctrl id */ |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 76 | int getPipeId() const; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 77 | /* ctrl fd */ |
| 78 | int getFd() const; |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 79 | /* retrieve crop data */ |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 80 | utils::Dim getCrop() const; |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 81 | utils::Dim getPosition() const; |
| 82 | /* Set downscale */ |
| 83 | void setDownscale(int dscale_factor); |
| 84 | /* Update the src format based on rotator's dest */ |
| 85 | void updateSrcFormat(const uint32_t& rotDstFormat); |
Saurabh Shah | 0d0a7cb | 2013-02-12 17:58:19 -0800 | [diff] [blame] | 86 | /* dump the state of the object */ |
| 87 | void dump() const; |
Saurabh Shah | 0d0a7cb | 2013-02-12 17:58:19 -0800 | [diff] [blame] | 88 | /* Return the dump in the specified buffer */ |
| 89 | void getDump(char *buf, size_t len); |
Saurabh Shah | df0be75 | 2013-05-23 14:40:00 -0700 | [diff] [blame] | 90 | void forceSet(); |
Saurabh Shah | 0d0a7cb | 2013-02-12 17:58:19 -0800 | [diff] [blame] | 91 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 92 | private: |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 93 | // mdp ctrl struct(info e.g.) |
| 94 | MdpCtrl mMdp; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 95 | }; |
| 96 | |
| 97 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 98 | class Data : utils::NoCopy { |
| 99 | public: |
| 100 | /* init, reset */ |
| 101 | explicit Data(); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 102 | /* calls close */ |
| 103 | ~Data(); |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 104 | /* init fd etc */ |
| 105 | bool init(uint32_t fbnum); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 106 | /* calls underlying mdp close */ |
| 107 | bool close(); |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 108 | /* set overlay pipe id in the mdp struct */ |
| 109 | void setPipeId(int id); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 110 | /* get overlay id in the mdp struct */ |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 111 | int getPipeId() const; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 112 | /* queue buffer to the overlay */ |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 113 | bool queueBuffer(int fd, uint32_t offset); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 114 | /* sump the state of the obj */ |
| 115 | void dump() const; |
Saurabh Shah | 0d0a7cb | 2013-02-12 17:58:19 -0800 | [diff] [blame] | 116 | /* Return the dump in the specified buffer */ |
| 117 | void getDump(char *buf, size_t len); |
| 118 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 119 | private: |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 120 | // mdp data struct |
| 121 | MdpData mMdp; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 122 | }; |
| 123 | |
| 124 | /* This class just creates a Ctrl Data pair to be used by a pipe. |
| 125 | * Although this was legacy design, this separation still makes sense, since we |
| 126 | * need to use the Ctrl channel in hwc_prepare (i.e config stage) and Data |
| 127 | * channel in hwc_set (i.e draw stage) |
| 128 | */ |
| 129 | struct CtrlData { |
| 130 | Ctrl ctrl; |
| 131 | Data data; |
| 132 | }; |
| 133 | |
| 134 | //-------------Inlines------------------------------- |
| 135 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 136 | inline Ctrl::Ctrl() { |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 137 | mMdp.reset(); |
| 138 | } |
| 139 | |
| 140 | inline Ctrl::~Ctrl() { |
| 141 | close(); |
| 142 | } |
| 143 | |
| 144 | inline bool Ctrl::close() { |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 145 | if(!mMdp.close()) |
| 146 | return false; |
| 147 | return true; |
| 148 | } |
| 149 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 150 | inline bool Ctrl::init(uint32_t fbnum) { |
| 151 | // MDP/FD init |
| 152 | if(!mMdp.init(fbnum)) { |
| 153 | ALOGE("Ctrl failed to init fbnum=%d", fbnum); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 154 | return false; |
| 155 | } |
| 156 | return true; |
| 157 | } |
| 158 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 159 | inline void Ctrl::setSource(const utils::PipeArgs& args) |
| 160 | { |
| 161 | mMdp.setSource(args); |
| 162 | } |
| 163 | |
| 164 | inline void Ctrl::setPosition(const utils::Dim& dim) |
| 165 | { |
| 166 | mMdp.setPosition(dim); |
| 167 | } |
| 168 | |
| 169 | inline void Ctrl::setTransform(const utils::eTransform& orient) |
| 170 | { |
| 171 | mMdp.setTransform(orient); |
| 172 | } |
| 173 | |
| 174 | inline void Ctrl::setCrop(const utils::Dim& d) |
| 175 | { |
| 176 | mMdp.setCrop(d); |
| 177 | } |
| 178 | |
Sushil Chauhan | 897a9c3 | 2013-07-18 11:09:55 -0700 | [diff] [blame^] | 179 | inline void Ctrl::setColor(const uint32_t color) |
| 180 | { |
| 181 | mMdp.setColor(color); |
| 182 | } |
| 183 | |
Saurabh Shah | 5daeee5 | 2013-01-23 16:52:26 +0800 | [diff] [blame] | 184 | inline bool Ctrl::setVisualParams(const MetaData_t &metadata) |
| 185 | { |
| 186 | if (!mMdp.setVisualParams(metadata)) { |
| 187 | ALOGE("Ctrl setVisualParams failed in MDP setVisualParams"); |
| 188 | return false; |
| 189 | } |
| 190 | return true; |
| 191 | } |
| 192 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 193 | inline void Ctrl::dump() const { |
| 194 | ALOGE("== Dump Ctrl start =="); |
| 195 | mMdp.dump(); |
| 196 | ALOGE("== Dump Ctrl end =="); |
| 197 | } |
| 198 | |
| 199 | inline bool Ctrl::commit() { |
| 200 | if(!mMdp.set()) { |
| 201 | ALOGE("Ctrl commit failed set overlay"); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 202 | return false; |
| 203 | } |
| 204 | return true; |
| 205 | } |
| 206 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 207 | inline int Ctrl::getPipeId() const { |
| 208 | return mMdp.getPipeId(); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | inline int Ctrl::getFd() const { |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 212 | return mMdp.getFd(); |
| 213 | } |
| 214 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 215 | inline void Ctrl::updateSrcFormat(const uint32_t& rotDstFmt) { |
| 216 | mMdp.updateSrcFormat(rotDstFmt); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | inline utils::Dim Ctrl::getCrop() const { |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 220 | return mMdp.getSrcRectDim(); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 221 | } |
| 222 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 223 | inline utils::Dim Ctrl::getPosition() const { |
| 224 | return mMdp.getDstRectDim(); |
Ramkumar Radhakrishnan | 288f8c7 | 2013-01-15 11:37:54 -0800 | [diff] [blame] | 225 | } |
| 226 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 227 | inline void Ctrl::setDownscale(int dscale_factor) { |
| 228 | mMdp.setDownscale(dscale_factor); |
Ramkumar Radhakrishnan | 288f8c7 | 2013-01-15 11:37:54 -0800 | [diff] [blame] | 229 | } |
| 230 | |
Saurabh Shah | 0d0a7cb | 2013-02-12 17:58:19 -0800 | [diff] [blame] | 231 | inline void Ctrl::getDump(char *buf, size_t len) { |
| 232 | mMdp.getDump(buf, len); |
| 233 | } |
| 234 | |
Saurabh Shah | df0be75 | 2013-05-23 14:40:00 -0700 | [diff] [blame] | 235 | inline void Ctrl::forceSet() { |
| 236 | mMdp.forceSet(); |
| 237 | } |
| 238 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 239 | inline Data::Data() { |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 240 | mMdp.reset(); |
| 241 | } |
| 242 | |
| 243 | inline Data::~Data() { close(); } |
| 244 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 245 | inline void Data::setPipeId(int id) { mMdp.setPipeId(id); } |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 246 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 247 | inline int Data::getPipeId() const { return mMdp.getPipeId(); } |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 248 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 249 | inline bool Data::init(uint32_t fbnum) { |
| 250 | if(!mMdp.init(fbnum)) { |
| 251 | ALOGE("Data cannot init mdp"); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 252 | return false; |
| 253 | } |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 254 | return true; |
| 255 | } |
| 256 | |
| 257 | inline bool Data::close() { |
| 258 | if(!mMdp.close()) { |
| 259 | ALOGE("Data close failed"); |
| 260 | return false; |
| 261 | } |
| 262 | return true; |
| 263 | } |
| 264 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 265 | inline bool Data::queueBuffer(int fd, uint32_t offset) { |
| 266 | return mMdp.play(fd, offset); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 267 | } |
| 268 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 269 | inline void Data::dump() const { |
| 270 | ALOGE("== Dump Data MDP start =="); |
| 271 | mMdp.dump(); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 272 | ALOGE("== Dump Data MDP end =="); |
| 273 | } |
| 274 | |
Saurabh Shah | 0d0a7cb | 2013-02-12 17:58:19 -0800 | [diff] [blame] | 275 | inline void Data::getDump(char *buf, size_t len) { |
| 276 | mMdp.getDump(buf, len); |
| 277 | } |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 278 | |
| 279 | } // overlay |
| 280 | |
| 281 | #endif |