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