Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 1 | /* |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 2 | * Copyright (C) 2008 The Android Open Source Project |
Arun Kumar K.R | 7e5a1f8 | 2014-01-22 10:36:16 -0800 | [diff] [blame] | 3 | * Copyright (c) 2010-2014, The Linux Foundation. All rights reserved. |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 4 | * Not a Contribution, Apache license notifications and license are retained |
| 5 | * for attribution purposes only. |
| 6 | * |
| 7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | * you may not use this file except in compliance with the License. |
| 9 | * You may obtain a copy of the License at |
| 10 | * |
| 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | * |
| 13 | * Unless required by applicable law or agreed to in writing, software |
| 14 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | * See the License for the specific language governing permissions and |
| 17 | * limitations under the License. |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | #include "overlayUtils.h" |
| 21 | #include "overlayRotator.h" |
Saurabh Shah | 8ec9b5e | 2014-06-30 14:37:17 -0700 | [diff] [blame^] | 22 | #include "gr.h" |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 23 | |
| 24 | namespace ovutils = overlay::utils; |
| 25 | |
| 26 | namespace overlay { |
| 27 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 28 | MdpRot::MdpRot() { |
| 29 | reset(); |
| 30 | init(); |
| 31 | } |
| 32 | |
| 33 | MdpRot::~MdpRot() { close(); } |
| 34 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 35 | bool MdpRot::enabled() const { return mRotImgInfo.enable; } |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 36 | |
Shalaj Jain | a70b435 | 2014-06-15 13:47:47 -0700 | [diff] [blame] | 37 | void MdpRot::setRotations(uint32_t r) { mRotImgInfo.rotations = (uint8_t)r; } |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 38 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 39 | int MdpRot::getDstMemId() const { |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 40 | return mRotDataInfo.dst.memory_id; |
| 41 | } |
| 42 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 43 | uint32_t MdpRot::getDstOffset() const { |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 44 | return mRotDataInfo.dst.offset; |
| 45 | } |
| 46 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 47 | uint32_t MdpRot::getDstFormat() const { |
Raj kamal | 23f69b2 | 2012-11-17 00:20:55 +0530 | [diff] [blame] | 48 | return mRotImgInfo.dst.format; |
| 49 | } |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 50 | |
Saurabh Shah | 8ec9b5e | 2014-06-30 14:37:17 -0700 | [diff] [blame^] | 51 | //Added for completeness. Not expected to be called. |
| 52 | utils::Whf MdpRot::getDstWhf() const { |
| 53 | int alW = 0, alH = 0; |
| 54 | int halFormat = ovutils::getHALFormat(mRotImgInfo.dst.format); |
| 55 | getBufferSizeAndDimensions(mRotImgInfo.dst.width, mRotImgInfo.dst.height, |
| 56 | halFormat, alW, alH); |
| 57 | return utils::Whf(alW, alH, mRotImgInfo.dst.format); |
| 58 | } |
| 59 | |
| 60 | //Added for completeness. Not expected to be called. |
| 61 | utils::Dim MdpRot::getDstDimensions() const { |
| 62 | int alW = 0, alH = 0; |
| 63 | int halFormat = ovutils::getHALFormat(mRotImgInfo.dst.format); |
| 64 | getBufferSizeAndDimensions(mRotImgInfo.dst.width, mRotImgInfo.dst.height, |
| 65 | halFormat, alW, alH); |
| 66 | return utils::Dim(0, 0, alW, alH); |
| 67 | } |
| 68 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 69 | uint32_t MdpRot::getSessId() const { return mRotImgInfo.session_id; } |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 70 | |
Ramkumar Radhakrishnan | 288f8c7 | 2013-01-15 11:37:54 -0800 | [diff] [blame] | 71 | void MdpRot::setDownscale(int ds) { |
Ramkumar Radhakrishnan | 4ca8f3a | 2013-02-14 18:56:50 -0800 | [diff] [blame] | 72 | if ((utils::ROT_DS_EIGHTH == ds) && (mRotImgInfo.src_rect.h & 0xF)) { |
Ramkumar Radhakrishnan | 288f8c7 | 2013-01-15 11:37:54 -0800 | [diff] [blame] | 73 | // Ensure src_rect.h is a multiple of 16 for 1/8 downscaling. |
| 74 | // This is an undocumented MDP Rotator constraint. |
Ramkumar Radhakrishnan | 4ca8f3a | 2013-02-14 18:56:50 -0800 | [diff] [blame] | 75 | mRotImgInfo.src_rect.h = utils::aligndown(mRotImgInfo.src_rect.h, 16); |
Ramkumar Radhakrishnan | 288f8c7 | 2013-01-15 11:37:54 -0800 | [diff] [blame] | 76 | } |
| 77 | mRotImgInfo.downscale_ratio = ds; |
| 78 | } |
| 79 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 80 | void MdpRot::save() { |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 81 | mLSRotImgInfo = mRotImgInfo; |
| 82 | } |
| 83 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 84 | bool MdpRot::rotConfChanged() const { |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 85 | // 0 means same |
| 86 | if(0 == ::memcmp(&mRotImgInfo, &mLSRotImgInfo, |
| 87 | sizeof (msm_rotator_img_info))) { |
| 88 | return false; |
| 89 | } |
| 90 | return true; |
| 91 | } |
| 92 | |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 93 | bool MdpRot::init() |
| 94 | { |
| 95 | if(!mFd.open(Res::rotPath, O_RDWR)){ |
| 96 | ALOGE("MdpRot failed to init %s", Res::rotPath); |
| 97 | return false; |
| 98 | } |
| 99 | return true; |
| 100 | } |
| 101 | |
| 102 | void MdpRot::setSource(const overlay::utils::Whf& awhf) { |
| 103 | utils::Whf whf(awhf); |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 104 | mRotImgInfo.src.format = whf.format; |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 105 | |
| 106 | mRotImgInfo.src.width = whf.w; |
| 107 | mRotImgInfo.src.height = whf.h; |
| 108 | |
| 109 | mRotImgInfo.src_rect.w = whf.w; |
| 110 | mRotImgInfo.src_rect.h = whf.h; |
| 111 | |
| 112 | mRotImgInfo.dst.width = whf.w; |
| 113 | mRotImgInfo.dst.height = whf.h; |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 114 | } |
| 115 | |
Arun Kumar K.R | 7e5a1f8 | 2014-01-22 10:36:16 -0800 | [diff] [blame] | 116 | void MdpRot::setCrop(const utils::Dim& /*crop*/) { |
Sushil Chauhan | 80fc1f9 | 2013-04-23 17:30:05 -0700 | [diff] [blame] | 117 | // NO-OP for non-mdss rotator due to possible h/w limitations |
| 118 | } |
| 119 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 120 | void MdpRot::setFlags(const utils::eMdpFlags& flags) { |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 121 | mRotImgInfo.secure = 0; |
| 122 | if(flags & utils::OV_MDP_SECURE_OVERLAY_SESSION) |
| 123 | mRotImgInfo.secure = 1; |
| 124 | } |
| 125 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 126 | void MdpRot::setTransform(const utils::eTransform& rot) |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 127 | { |
| 128 | int r = utils::getMdpOrient(rot); |
| 129 | setRotations(r); |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 130 | mOrientation = static_cast<utils::eTransform>(r); |
| 131 | ALOGE_IF(DEBUG_OVERLAY, "%s: r=%d", __FUNCTION__, r); |
Ramkumar Radhakrishnan | 288f8c7 | 2013-01-15 11:37:54 -0800 | [diff] [blame] | 132 | } |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 133 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 134 | void MdpRot::doTransform() { |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 135 | if(mOrientation & utils::OVERLAY_TRANSFORM_ROT_90) |
| 136 | utils::swap(mRotImgInfo.dst.width, mRotImgInfo.dst.height); |
| 137 | } |
| 138 | |
| 139 | bool MdpRot::commit() { |
| 140 | doTransform(); |
Saurabh Shah | c23b380 | 2012-08-31 11:11:30 -0700 | [diff] [blame] | 141 | if(rotConfChanged()) { |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 142 | mRotImgInfo.enable = 1; |
Saurabh Shah | c23b380 | 2012-08-31 11:11:30 -0700 | [diff] [blame] | 143 | if(!overlay::mdp_wrapper::startRotator(mFd.getFD(), mRotImgInfo)) { |
| 144 | ALOGE("MdpRot commit failed"); |
| 145 | dump(); |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 146 | mRotImgInfo.enable = 0; |
Saurabh Shah | c23b380 | 2012-08-31 11:11:30 -0700 | [diff] [blame] | 147 | return false; |
| 148 | } |
| 149 | save(); |
| 150 | mRotDataInfo.session_id = mRotImgInfo.session_id; |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 151 | } |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 152 | return true; |
| 153 | } |
| 154 | |
Saurabh Shah | fc3652f | 2013-02-15 13:15:45 -0800 | [diff] [blame] | 155 | uint32_t MdpRot::calcOutputBufSize() { |
| 156 | ovutils::Whf destWhf(mRotImgInfo.dst.width, |
| 157 | mRotImgInfo.dst.height, mRotImgInfo.dst.format); |
| 158 | return Rotator::calcOutputBufSize(destWhf); |
| 159 | } |
| 160 | |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 161 | bool MdpRot::open_i(uint32_t numbufs, uint32_t bufsz) |
| 162 | { |
| 163 | OvMem mem; |
| 164 | |
| 165 | OVASSERT(MAP_FAILED == mem.addr(), "MAP failed in open_i"); |
| 166 | |
| 167 | if(!mem.open(numbufs, bufsz, mRotImgInfo.secure)){ |
| 168 | ALOGE("%s: Failed to open", __func__); |
| 169 | mem.close(); |
| 170 | return false; |
| 171 | } |
| 172 | |
| 173 | OVASSERT(MAP_FAILED != mem.addr(), "MAP failed"); |
| 174 | OVASSERT(mem.getFD() != -1, "getFd is -1"); |
| 175 | |
| 176 | mRotDataInfo.dst.memory_id = mem.getFD(); |
| 177 | mRotDataInfo.dst.offset = 0; |
Saurabh Shah | 912c948 | 2014-02-07 14:01:04 -0800 | [diff] [blame] | 178 | mMem.mem = mem; |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 179 | return true; |
| 180 | } |
| 181 | |
| 182 | bool MdpRot::close() { |
| 183 | bool success = true; |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 184 | if(mFd.valid() && (getSessId() != 0)) { |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 185 | if(!mdp_wrapper::endRotator(mFd.getFD(), getSessId())) { |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 186 | ALOGE("Mdp Rot error endRotator, fd=%d sessId=%u", |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 187 | mFd.getFD(), getSessId()); |
| 188 | success = false; |
| 189 | } |
| 190 | } |
| 191 | if (!mFd.close()) { |
| 192 | ALOGE("Mdp Rot error closing fd"); |
| 193 | success = false; |
| 194 | } |
| 195 | if (!mMem.close()) { |
| 196 | ALOGE("Mdp Rot error closing mem"); |
| 197 | success = false; |
| 198 | } |
| 199 | reset(); |
| 200 | return success; |
| 201 | } |
| 202 | |
| 203 | bool MdpRot::remap(uint32_t numbufs) { |
| 204 | // if current size changed, remap |
Saurabh Shah | fc3652f | 2013-02-15 13:15:45 -0800 | [diff] [blame] | 205 | uint32_t opBufSize = calcOutputBufSize(); |
Saurabh Shah | 912c948 | 2014-02-07 14:01:04 -0800 | [diff] [blame] | 206 | if(opBufSize == mMem.size()) { |
Saurabh Shah | fc3652f | 2013-02-15 13:15:45 -0800 | [diff] [blame] | 207 | ALOGE_IF(DEBUG_OVERLAY, "%s: same size %d", __FUNCTION__, opBufSize); |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 208 | return true; |
| 209 | } |
| 210 | |
Saurabh Shah | 912c948 | 2014-02-07 14:01:04 -0800 | [diff] [blame] | 211 | if(!mMem.close()) { |
| 212 | ALOGE("%s error in closing prev rot mem", __FUNCTION__); |
| 213 | return false; |
| 214 | } |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 215 | |
Saurabh Shah | 912c948 | 2014-02-07 14:01:04 -0800 | [diff] [blame] | 216 | ALOGE_IF(DEBUG_OVERLAY, "%s: size changed - remapping", __FUNCTION__); |
| 217 | |
Saurabh Shah | fc3652f | 2013-02-15 13:15:45 -0800 | [diff] [blame] | 218 | if(!open_i(numbufs, opBufSize)) { |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 219 | ALOGE("%s Error could not open", __FUNCTION__); |
| 220 | return false; |
| 221 | } |
Saurabh Shah | 912c948 | 2014-02-07 14:01:04 -0800 | [diff] [blame] | 222 | |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 223 | for (uint32_t i = 0; i < numbufs; ++i) { |
Saurabh Shah | 912c948 | 2014-02-07 14:01:04 -0800 | [diff] [blame] | 224 | mMem.mRotOffset[i] = i * opBufSize; |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 225 | } |
Saurabh Shah | 912c948 | 2014-02-07 14:01:04 -0800 | [diff] [blame] | 226 | |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 227 | return true; |
| 228 | } |
| 229 | |
| 230 | void MdpRot::reset() { |
| 231 | ovutils::memset0(mRotImgInfo); |
Saurabh Shah | c23b380 | 2012-08-31 11:11:30 -0700 | [diff] [blame] | 232 | ovutils::memset0(mLSRotImgInfo); |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 233 | ovutils::memset0(mRotDataInfo); |
Saurabh Shah | 912c948 | 2014-02-07 14:01:04 -0800 | [diff] [blame] | 234 | ovutils::memset0(mMem.mRotOffset); |
| 235 | mMem.mCurrIndex = 0; |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 236 | mOrientation = utils::OVERLAY_TRANSFORM_0; |
| 237 | } |
| 238 | |
| 239 | bool MdpRot::queueBuffer(int fd, uint32_t offset) { |
| 240 | if(enabled()) { |
| 241 | mRotDataInfo.src.memory_id = fd; |
| 242 | mRotDataInfo.src.offset = offset; |
| 243 | |
Saurabh Shah | 912c948 | 2014-02-07 14:01:04 -0800 | [diff] [blame] | 244 | if(false == remap(RotMem::ROT_NUM_BUFS)) { |
| 245 | ALOGE("%s Remap failed, not queueing", __FUNCTION__); |
| 246 | return false; |
| 247 | } |
| 248 | |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 249 | mRotDataInfo.dst.offset = |
Saurabh Shah | 912c948 | 2014-02-07 14:01:04 -0800 | [diff] [blame] | 250 | mMem.mRotOffset[mMem.mCurrIndex]; |
| 251 | mMem.mCurrIndex = |
| 252 | (mMem.mCurrIndex + 1) % mMem.mem.numBufs(); |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 253 | |
| 254 | if(!overlay::mdp_wrapper::rotate(mFd.getFD(), mRotDataInfo)) { |
| 255 | ALOGE("MdpRot failed rotate"); |
| 256 | dump(); |
| 257 | return false; |
| 258 | } |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 259 | } |
| 260 | return true; |
| 261 | } |
| 262 | |
| 263 | void MdpRot::dump() const { |
| 264 | ALOGE("== Dump MdpRot start =="); |
| 265 | mFd.dump(); |
Saurabh Shah | 912c948 | 2014-02-07 14:01:04 -0800 | [diff] [blame] | 266 | mMem.mem.dump(); |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 267 | mdp_wrapper::dump("mRotImgInfo", mRotImgInfo); |
| 268 | mdp_wrapper::dump("mRotDataInfo", mRotDataInfo); |
| 269 | ALOGE("== Dump MdpRot end =="); |
| 270 | } |
| 271 | |
Saurabh Shah | 0d0a7cb | 2013-02-12 17:58:19 -0800 | [diff] [blame] | 272 | void MdpRot::getDump(char *buf, size_t len) const { |
Saurabh Shah | ae61b2b | 2013-04-10 16:37:25 -0700 | [diff] [blame] | 273 | ovutils::getDump(buf, len, "MdpRotCtrl", mRotImgInfo); |
| 274 | ovutils::getDump(buf, len, "MdpRotData", mRotDataInfo); |
Saurabh Shah | 0d0a7cb | 2013-02-12 17:58:19 -0800 | [diff] [blame] | 275 | } |
| 276 | |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 277 | } // namespace overlay |