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 */ |
| 61 | bool 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 */ |
| 63 | bool setCrop(const utils::Dim& d); |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 64 | /* set orientation */ |
Ramkumar Radhakrishnan | 288f8c7 | 2013-01-15 11:37:54 -0800 | [diff] [blame] | 65 | bool setTransform(const utils::eTransform& p); |
| 66 | /* set whether rotator can be used */ |
| 67 | void setRotatorUsed(const bool& rotUsed); |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 68 | /* set mdp position using dim */ |
| 69 | bool setPosition(const utils::Dim& dim); |
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; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 77 | |
| 78 | /* access for screen info */ |
| 79 | utils::ScreenInfo getScreenInfo() const; |
| 80 | |
| 81 | /* retrieve cached crop data */ |
| 82 | utils::Dim getCrop() const; |
| 83 | |
| 84 | /* dump the state of the object */ |
| 85 | void dump() const; |
| 86 | |
Ramkumar Radhakrishnan | 288f8c7 | 2013-01-15 11:37:54 -0800 | [diff] [blame] | 87 | /* Perform transformation calculations */ |
| 88 | void doTransform(); |
| 89 | |
| 90 | /* Performs downscale calculations */ |
| 91 | void doDownscale(int dscale_factor); |
| 92 | |
| 93 | /* Get downscale factor */ |
| 94 | int getDownscalefactor(); |
| 95 | |
Raj kamal | 23f69b2 | 2012-11-17 00:20:55 +0530 | [diff] [blame] | 96 | /* Update the src format */ |
| 97 | void updateSrcformat(const uint32_t& inputsrcFormat); |
Ramkumar Radhakrishnan | 288f8c7 | 2013-01-15 11:37:54 -0800 | [diff] [blame] | 98 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 99 | private: |
| 100 | /* Retrieve screen info from underlying mdp */ |
| 101 | bool getScreenInfo(utils::ScreenInfo& info); |
| 102 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 103 | // mdp ctrl struct(info e.g.) |
| 104 | MdpCtrl mMdp; |
| 105 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 106 | /* Screen info */ |
| 107 | utils::ScreenInfo mInfo; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 108 | }; |
| 109 | |
| 110 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 111 | class Data : utils::NoCopy { |
| 112 | public: |
| 113 | /* init, reset */ |
| 114 | explicit Data(); |
| 115 | |
| 116 | /* calls close */ |
| 117 | ~Data(); |
| 118 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 119 | /* init fd etc */ |
| 120 | bool init(uint32_t fbnum); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 121 | |
| 122 | /* calls underlying mdp close */ |
| 123 | bool close(); |
| 124 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 125 | /* set overlay pipe id in the mdp struct */ |
| 126 | void setPipeId(int id); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 127 | |
| 128 | /* get overlay id in the mdp struct */ |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 129 | int getPipeId() const; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 130 | |
| 131 | /* queue buffer to the overlay */ |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 132 | bool queueBuffer(int fd, uint32_t offset); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 133 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 134 | /* sump the state of the obj */ |
| 135 | void dump() const; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 136 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 137 | private: |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 138 | // mdp data struct |
| 139 | MdpData mMdp; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 140 | }; |
| 141 | |
| 142 | /* This class just creates a Ctrl Data pair to be used by a pipe. |
| 143 | * Although this was legacy design, this separation still makes sense, since we |
| 144 | * need to use the Ctrl channel in hwc_prepare (i.e config stage) and Data |
| 145 | * channel in hwc_set (i.e draw stage) |
| 146 | */ |
| 147 | struct CtrlData { |
| 148 | Ctrl ctrl; |
| 149 | Data data; |
| 150 | }; |
| 151 | |
| 152 | //-------------Inlines------------------------------- |
| 153 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 154 | inline Ctrl::Ctrl() { |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 155 | mMdp.reset(); |
| 156 | } |
| 157 | |
| 158 | inline Ctrl::~Ctrl() { |
| 159 | close(); |
| 160 | } |
| 161 | |
| 162 | inline bool Ctrl::close() { |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 163 | if(!mMdp.close()) |
| 164 | return false; |
| 165 | return true; |
| 166 | } |
| 167 | |
| 168 | inline bool Ctrl::commit() { |
| 169 | if(!mMdp.set()) { |
| 170 | ALOGE("Ctrl commit failed set overlay"); |
| 171 | return false; |
| 172 | } |
| 173 | return true; |
| 174 | } |
| 175 | |
| 176 | inline bool Ctrl::getScreenInfo(utils::ScreenInfo& info) { |
| 177 | if(!mMdp.getScreenInfo(info)){ |
| 178 | ALOGE("Ctrl failed to get screen info"); |
| 179 | return false; |
| 180 | } |
| 181 | return true; |
| 182 | } |
| 183 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 184 | inline int Ctrl::getPipeId() const { |
| 185 | return mMdp.getPipeId(); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | inline int Ctrl::getFd() const { |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 189 | return mMdp.getFd(); |
| 190 | } |
| 191 | |
Raj kamal | 23f69b2 | 2012-11-17 00:20:55 +0530 | [diff] [blame] | 192 | inline void Ctrl::updateSrcformat(const uint32_t& inputsrcFormat) { |
| 193 | mMdp.updateSrcformat(inputsrcFormat); |
| 194 | } |
| 195 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 196 | inline utils::ScreenInfo Ctrl::getScreenInfo() const { |
| 197 | return mInfo; |
| 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 | |
Ramkumar Radhakrishnan | 288f8c7 | 2013-01-15 11:37:54 -0800 | [diff] [blame] | 204 | inline void Ctrl::doTransform() { |
| 205 | return mMdp.doTransform(); |
| 206 | } |
| 207 | |
| 208 | inline void Ctrl::doDownscale(int dscale_factor) { |
| 209 | mMdp.doDownscale(dscale_factor); |
| 210 | } |
| 211 | |
| 212 | inline int Ctrl::getDownscalefactor() { |
| 213 | return mMdp.getDownscalefactor(); |
| 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 | |
| 252 | |
| 253 | } // overlay |
| 254 | |
| 255 | #endif |