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