Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012, Code Aurora Forum. All rights reserved. |
| 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. |
| 13 | * * Neither the name of Code Aurora Forum, Inc. nor the names of its |
| 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 */ |
| 65 | bool setTransform(const utils::eTransform& p, const bool&); |
| 66 | /* set mdp position using dim */ |
| 67 | bool 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; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 75 | utils::Dim getAspectRatio(const utils::Whf& whf) const; |
| 76 | utils::Dim getAspectRatio(const utils::Dim& dim) const; |
| 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 | |
| 87 | private: |
| 88 | /* Retrieve screen info from underlying mdp */ |
| 89 | bool getScreenInfo(utils::ScreenInfo& info); |
| 90 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 91 | // mdp ctrl struct(info e.g.) |
| 92 | MdpCtrl mMdp; |
| 93 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 94 | /* Screen info */ |
| 95 | utils::ScreenInfo mInfo; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 99 | class Data : utils::NoCopy { |
| 100 | public: |
| 101 | /* init, reset */ |
| 102 | explicit Data(); |
| 103 | |
| 104 | /* calls close */ |
| 105 | ~Data(); |
| 106 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame^] | 107 | /* init fd etc */ |
| 108 | bool init(uint32_t fbnum); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 109 | |
| 110 | /* calls underlying mdp close */ |
| 111 | bool close(); |
| 112 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame^] | 113 | /* set overlay pipe id in the mdp struct */ |
| 114 | void setPipeId(int id); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 115 | |
| 116 | /* get overlay id in the mdp struct */ |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame^] | 117 | int getPipeId() const; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 118 | |
| 119 | /* queue buffer to the overlay */ |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame^] | 120 | bool queueBuffer(int fd, uint32_t offset); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 121 | |
| 122 | /* wait for vsync to be done */ |
| 123 | bool waitForVsync(); |
| 124 | |
| 125 | /* sump the state of the obj */ |
| 126 | void dump() const; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame^] | 127 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 128 | private: |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 129 | // mdp data struct |
| 130 | MdpData mMdp; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 131 | }; |
| 132 | |
| 133 | /* This class just creates a Ctrl Data pair to be used by a pipe. |
| 134 | * Although this was legacy design, this separation still makes sense, since we |
| 135 | * need to use the Ctrl channel in hwc_prepare (i.e config stage) and Data |
| 136 | * channel in hwc_set (i.e draw stage) |
| 137 | */ |
| 138 | struct CtrlData { |
| 139 | Ctrl ctrl; |
| 140 | Data data; |
| 141 | }; |
| 142 | |
| 143 | //-------------Inlines------------------------------- |
| 144 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame^] | 145 | inline Ctrl::Ctrl() { |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 146 | mMdp.reset(); |
| 147 | } |
| 148 | |
| 149 | inline Ctrl::~Ctrl() { |
| 150 | close(); |
| 151 | } |
| 152 | |
| 153 | inline bool Ctrl::close() { |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 154 | if(!mMdp.close()) |
| 155 | return false; |
| 156 | return true; |
| 157 | } |
| 158 | |
| 159 | inline bool Ctrl::commit() { |
| 160 | if(!mMdp.set()) { |
| 161 | ALOGE("Ctrl commit failed set overlay"); |
| 162 | return false; |
| 163 | } |
| 164 | return true; |
| 165 | } |
| 166 | |
| 167 | inline bool Ctrl::getScreenInfo(utils::ScreenInfo& info) { |
| 168 | if(!mMdp.getScreenInfo(info)){ |
| 169 | ALOGE("Ctrl failed to get screen info"); |
| 170 | return false; |
| 171 | } |
| 172 | return true; |
| 173 | } |
| 174 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame^] | 175 | inline int Ctrl::getPipeId() const { |
| 176 | return mMdp.getPipeId(); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | inline int Ctrl::getFd() const { |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 180 | return mMdp.getFd(); |
| 181 | } |
| 182 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 183 | inline utils::ScreenInfo Ctrl::getScreenInfo() const { |
| 184 | return mInfo; |
| 185 | } |
| 186 | |
| 187 | inline utils::Dim Ctrl::getCrop() const { |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame^] | 188 | return mMdp.getSrcRectDim(); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 189 | } |
| 190 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame^] | 191 | inline Data::Data() { |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 192 | mMdp.reset(); |
| 193 | } |
| 194 | |
| 195 | inline Data::~Data() { close(); } |
| 196 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame^] | 197 | inline void Data::setPipeId(int id) { mMdp.setPipeId(id); } |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 198 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame^] | 199 | inline int Data::getPipeId() const { return mMdp.getPipeId(); } |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 200 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame^] | 201 | inline bool Data::init(uint32_t fbnum) { |
| 202 | if(!mMdp.init(fbnum)) { |
| 203 | ALOGE("Data cannot init mdp"); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 204 | return false; |
| 205 | } |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 206 | return true; |
| 207 | } |
| 208 | |
| 209 | inline bool Data::close() { |
| 210 | if(!mMdp.close()) { |
| 211 | ALOGE("Data close failed"); |
| 212 | return false; |
| 213 | } |
| 214 | return true; |
| 215 | } |
| 216 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame^] | 217 | inline bool Data::queueBuffer(int fd, uint32_t offset) { |
| 218 | return mMdp.play(fd, offset); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | inline bool Data::waitForVsync() { |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame^] | 222 | // Call mdp waitForVsync |
| 223 | if(!mMdp.waitForVsync()){ |
| 224 | ALOGE("Error in MDP %s", __FUNCTION__); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 225 | return false; |
| 226 | } |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 227 | return true; |
| 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 =="); |
| 232 | mMdp.dump(); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 233 | ALOGE("== Dump Data MDP end =="); |
| 234 | } |
| 235 | |
| 236 | |
| 237 | } // overlay |
| 238 | |
| 239 | #endif |