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 |
Saurabh Shah | 08c65b3 | 2012-12-18 14:23:43 -0800 | [diff] [blame] | 3 | * Copyright (c) 2010-2013, 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" |
| 22 | |
Sushil Chauhan | bab187a | 2013-01-30 17:44:15 -0800 | [diff] [blame] | 23 | #define DEBUG_MDSS_ROT 0 |
| 24 | |
Sushil Chauhan | c6bd6d9 | 2012-12-12 12:33:01 -0800 | [diff] [blame] | 25 | #ifdef VENUS_COLOR_FORMAT |
| 26 | #include <media/msm_media_info.h> |
| 27 | #else |
| 28 | #define VENUS_BUFFER_SIZE(args...) 0 |
| 29 | #endif |
| 30 | |
Naseer Ahmed | c21013b | 2012-11-19 12:44:41 -0500 | [diff] [blame] | 31 | #ifndef MDSS_MDP_ROT_ONLY |
| 32 | #define MDSS_MDP_ROT_ONLY 0x80 |
| 33 | #endif |
| 34 | |
Sushil Chauhan | 95e4c9f | 2013-01-14 18:44:14 -0800 | [diff] [blame] | 35 | #define MDSS_ROT_MASK (MDP_ROT_90 | MDP_FLIP_UD | MDP_FLIP_LR) |
Sushil Chauhan | 6e3fab8 | 2012-11-19 15:30:33 -0800 | [diff] [blame] | 36 | |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 37 | namespace ovutils = overlay::utils; |
| 38 | |
| 39 | namespace overlay { |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 40 | MdssRot::MdssRot() { |
| 41 | reset(); |
| 42 | init(); |
| 43 | } |
| 44 | |
| 45 | MdssRot::~MdssRot() { close(); } |
| 46 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 47 | bool MdssRot::enabled() const { return mEnabled; } |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 48 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 49 | void MdssRot::setRotations(uint32_t flags) { mRotInfo.flags |= flags; } |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 50 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 51 | int MdssRot::getDstMemId() const { |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 52 | return mRotData.dst_data.memory_id; |
| 53 | } |
| 54 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 55 | uint32_t MdssRot::getDstOffset() const { |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 56 | return mRotData.dst_data.offset; |
| 57 | } |
| 58 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 59 | uint32_t MdssRot::getDstFormat() const { |
Raj kamal | 23f69b2 | 2012-11-17 00:20:55 +0530 | [diff] [blame] | 60 | //For mdss src and dst formats are same |
| 61 | return mRotInfo.src.format; |
| 62 | } |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 63 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 64 | uint32_t MdssRot::getSessId() const { return mRotInfo.id; } |
Raj kamal | 23f69b2 | 2012-11-17 00:20:55 +0530 | [diff] [blame] | 65 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 66 | bool MdssRot::init() { |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 67 | if(!utils::openDev(mFd, 0, Res::fbPath, O_RDWR)) { |
| 68 | ALOGE("MdssRot failed to init fb0"); |
| 69 | return false; |
| 70 | } |
| 71 | return true; |
| 72 | } |
| 73 | |
| 74 | void MdssRot::setSource(const overlay::utils::Whf& awhf) { |
| 75 | utils::Whf whf(awhf); |
| 76 | |
| 77 | mRotInfo.src.format = whf.format; |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 78 | mRotInfo.src.width = whf.w; |
| 79 | mRotInfo.src.height = whf.h; |
Sushil Chauhan | 80fc1f9 | 2013-04-23 17:30:05 -0700 | [diff] [blame] | 80 | } |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 81 | |
Sushil Chauhan | 80fc1f9 | 2013-04-23 17:30:05 -0700 | [diff] [blame] | 82 | void MdssRot::setCrop(const utils::Dim& crop) { |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 83 | |
Sushil Chauhan | 80fc1f9 | 2013-04-23 17:30:05 -0700 | [diff] [blame] | 84 | mRotInfo.src_rect.x = crop.x; |
| 85 | mRotInfo.src_rect.y = crop.y; |
| 86 | mRotInfo.src_rect.w = crop.w; |
| 87 | mRotInfo.src_rect.h = crop.h; |
| 88 | |
| 89 | mRotInfo.dst_rect.x = 0; |
| 90 | mRotInfo.dst_rect.y = 0; |
| 91 | mRotInfo.dst_rect.w = crop.w; |
| 92 | mRotInfo.dst_rect.h = crop.h; |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 93 | } |
| 94 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 95 | void MdssRot::setDownscale(int ds) {} |
Ramkumar Radhakrishnan | 288f8c7 | 2013-01-15 11:37:54 -0800 | [diff] [blame] | 96 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 97 | void MdssRot::setFlags(const utils::eMdpFlags& flags) { |
Sushil Chauhan | 6dcffbf | 2013-05-13 19:11:11 -0700 | [diff] [blame] | 98 | mRotInfo.flags = flags; |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 99 | } |
| 100 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 101 | void MdssRot::setTransform(const utils::eTransform& rot) |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 102 | { |
Saurabh Shah | 78ad495 | 2013-04-05 09:38:01 -0700 | [diff] [blame] | 103 | // reset rotation flags to avoid stale orientation values |
| 104 | mRotInfo.flags &= ~MDSS_ROT_MASK; |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 105 | int flags = utils::getMdpOrient(rot); |
| 106 | if (flags != -1) |
| 107 | setRotations(flags); |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 108 | mOrientation = static_cast<utils::eTransform>(flags); |
| 109 | ALOGE_IF(DEBUG_OVERLAY, "%s: rot=%d", __FUNCTION__, flags); |
Ramkumar Radhakrishnan | 288f8c7 | 2013-01-15 11:37:54 -0800 | [diff] [blame] | 110 | } |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 111 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 112 | void MdssRot::doTransform() { |
Sushil Chauhan | 6dcffbf | 2013-05-13 19:11:11 -0700 | [diff] [blame] | 113 | mRotInfo.flags |= mOrientation; |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 114 | if(mOrientation & utils::OVERLAY_TRANSFORM_ROT_90) |
| 115 | utils::swap(mRotInfo.dst_rect.w, mRotInfo.dst_rect.h); |
| 116 | } |
| 117 | |
| 118 | bool MdssRot::commit() { |
| 119 | doTransform(); |
| 120 | mRotInfo.flags |= MDSS_MDP_ROT_ONLY; |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 121 | mEnabled = true; |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 122 | if(!overlay::mdp_wrapper::setOverlay(mFd.getFD(), mRotInfo)) { |
| 123 | ALOGE("MdssRot commit failed!"); |
| 124 | dump(); |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 125 | return (mEnabled = false); |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 126 | } |
| 127 | mRotData.id = mRotInfo.id; |
| 128 | return true; |
| 129 | } |
| 130 | |
| 131 | bool MdssRot::queueBuffer(int fd, uint32_t offset) { |
| 132 | if(enabled()) { |
| 133 | mRotData.data.memory_id = fd; |
| 134 | mRotData.data.offset = offset; |
| 135 | |
Saurabh Shah | 9acd8f7 | 2014-02-07 14:01:04 -0800 | [diff] [blame] | 136 | if(false == remap(RotMem::ROT_NUM_BUFS)) { |
| 137 | ALOGE("%s Remap failed, not queuing", __FUNCTION__); |
| 138 | return false; |
| 139 | } |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 140 | |
| 141 | mRotData.dst_data.offset = |
Saurabh Shah | 9acd8f7 | 2014-02-07 14:01:04 -0800 | [diff] [blame] | 142 | mMem.mRotOffset[mMem.mCurrIndex]; |
| 143 | mMem.mCurrIndex = |
| 144 | (mMem.mCurrIndex + 1) % mMem.mem.numBufs(); |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 145 | |
| 146 | if(!overlay::mdp_wrapper::play(mFd.getFD(), mRotData)) { |
| 147 | ALOGE("MdssRot play failed!"); |
| 148 | dump(); |
| 149 | return false; |
| 150 | } |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 151 | } |
| 152 | return true; |
| 153 | } |
| 154 | |
| 155 | bool MdssRot::open_i(uint32_t numbufs, uint32_t bufsz) |
| 156 | { |
| 157 | OvMem mem; |
| 158 | OVASSERT(MAP_FAILED == mem.addr(), "MAP failed in open_i"); |
Sushil Chauhan | faae042 | 2012-10-23 23:48:04 -0700 | [diff] [blame] | 159 | bool isSecure = mRotInfo.flags & utils::OV_MDP_SECURE_OVERLAY_SESSION; |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 160 | |
Sushil Chauhan | faae042 | 2012-10-23 23:48:04 -0700 | [diff] [blame] | 161 | if(!mem.open(numbufs, bufsz, isSecure)){ |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 162 | ALOGE("%s: Failed to open", __func__); |
| 163 | mem.close(); |
| 164 | return false; |
| 165 | } |
| 166 | |
| 167 | OVASSERT(MAP_FAILED != mem.addr(), "MAP failed"); |
| 168 | OVASSERT(mem.getFD() != -1, "getFd is -1"); |
| 169 | |
| 170 | mRotData.dst_data.memory_id = mem.getFD(); |
| 171 | mRotData.dst_data.offset = 0; |
Saurabh Shah | 9acd8f7 | 2014-02-07 14:01:04 -0800 | [diff] [blame] | 172 | mMem.mem = mem; |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 173 | return true; |
| 174 | } |
| 175 | |
| 176 | bool MdssRot::remap(uint32_t numbufs) { |
Saurabh Shah | fc3652f | 2013-02-15 13:15:45 -0800 | [diff] [blame] | 177 | // Calculate the size based on rotator's dst format, w and h. |
| 178 | uint32_t opBufSize = calcOutputBufSize(); |
| 179 | // If current size changed, remap |
Saurabh Shah | 9acd8f7 | 2014-02-07 14:01:04 -0800 | [diff] [blame] | 180 | if(opBufSize == mMem.size()) { |
Saurabh Shah | fc3652f | 2013-02-15 13:15:45 -0800 | [diff] [blame] | 181 | ALOGE_IF(DEBUG_OVERLAY, "%s: same size %d", __FUNCTION__, opBufSize); |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 182 | return true; |
| 183 | } |
| 184 | |
| 185 | ALOGE_IF(DEBUG_OVERLAY, "%s: size changed - remapping", __FUNCTION__); |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 186 | |
Saurabh Shah | 9acd8f7 | 2014-02-07 14:01:04 -0800 | [diff] [blame] | 187 | if(!mMem.close()) { |
| 188 | ALOGE("%s error in closing prev rot mem", __FUNCTION__); |
| 189 | return false; |
| 190 | } |
| 191 | |
Saurabh Shah | fc3652f | 2013-02-15 13:15:45 -0800 | [diff] [blame] | 192 | if(!open_i(numbufs, opBufSize)) { |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 193 | ALOGE("%s Error could not open", __FUNCTION__); |
| 194 | return false; |
| 195 | } |
Saurabh Shah | 9acd8f7 | 2014-02-07 14:01:04 -0800 | [diff] [blame] | 196 | |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 197 | for (uint32_t i = 0; i < numbufs; ++i) { |
Saurabh Shah | 9acd8f7 | 2014-02-07 14:01:04 -0800 | [diff] [blame] | 198 | mMem.mRotOffset[i] = i * opBufSize; |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 199 | } |
Saurabh Shah | 9acd8f7 | 2014-02-07 14:01:04 -0800 | [diff] [blame] | 200 | |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 201 | return true; |
| 202 | } |
| 203 | |
| 204 | bool MdssRot::close() { |
| 205 | bool success = true; |
Ken Zhang | ba48b01 | 2012-12-11 20:33:59 -0500 | [diff] [blame] | 206 | if(mFd.valid() && (getSessId() != (uint32_t) MSMFB_NEW_REQUEST)) { |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 207 | if(!mdp_wrapper::unsetOverlay(mFd.getFD(), getSessId())) { |
| 208 | ALOGE("MdssRot::close unsetOverlay failed, fd=%d sessId=%d", |
| 209 | mFd.getFD(), getSessId()); |
Ken Zhang | ba48b01 | 2012-12-11 20:33:59 -0500 | [diff] [blame] | 210 | success = false; |
| 211 | } |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | if (!mFd.close()) { |
| 215 | ALOGE("Mdss Rot error closing fd"); |
| 216 | success = false; |
| 217 | } |
| 218 | if (!mMem.close()) { |
| 219 | ALOGE("Mdss Rot error closing mem"); |
| 220 | success = false; |
| 221 | } |
| 222 | reset(); |
| 223 | return success; |
| 224 | } |
| 225 | |
| 226 | void MdssRot::reset() { |
| 227 | ovutils::memset0(mRotInfo); |
| 228 | ovutils::memset0(mRotData); |
| 229 | mRotData.data.memory_id = -1; |
| 230 | mRotInfo.id = MSMFB_NEW_REQUEST; |
Saurabh Shah | 9acd8f7 | 2014-02-07 14:01:04 -0800 | [diff] [blame] | 231 | ovutils::memset0(mMem.mRotOffset); |
| 232 | mMem.mCurrIndex = 0; |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 233 | mOrientation = utils::OVERLAY_TRANSFORM_0; |
| 234 | } |
| 235 | |
| 236 | void MdssRot::dump() const { |
| 237 | ALOGE("== Dump MdssRot start =="); |
| 238 | mFd.dump(); |
Saurabh Shah | 9acd8f7 | 2014-02-07 14:01:04 -0800 | [diff] [blame] | 239 | mMem.mem.dump(); |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 240 | mdp_wrapper::dump("mRotInfo", mRotInfo); |
| 241 | mdp_wrapper::dump("mRotData", mRotData); |
| 242 | ALOGE("== Dump MdssRot end =="); |
| 243 | } |
| 244 | |
Saurabh Shah | fc3652f | 2013-02-15 13:15:45 -0800 | [diff] [blame] | 245 | uint32_t MdssRot::calcOutputBufSize() { |
| 246 | uint32_t opBufSize = 0; |
| 247 | ovutils::Whf destWhf(mRotInfo.dst_rect.w, mRotInfo.dst_rect.h, |
| 248 | mRotInfo.src.format); //mdss src and dst formats are same. |
Sushil Chauhan | b4d184f | 2013-02-11 16:13:10 -0800 | [diff] [blame] | 249 | |
Sushil Chauhan | bab187a | 2013-01-30 17:44:15 -0800 | [diff] [blame] | 250 | if (mRotInfo.flags & ovutils::OV_MDSS_MDP_BWC_EN) { |
Sushil Chauhan | 466766f | 2013-07-31 11:21:07 -0700 | [diff] [blame] | 251 | opBufSize = calcCompressedBufSize(destWhf); |
Sushil Chauhan | bab187a | 2013-01-30 17:44:15 -0800 | [diff] [blame] | 252 | } else { |
| 253 | opBufSize = Rotator::calcOutputBufSize(destWhf); |
| 254 | } |
Sushil Chauhan | b4d184f | 2013-02-11 16:13:10 -0800 | [diff] [blame] | 255 | |
Saurabh Shah | fc3652f | 2013-02-15 13:15:45 -0800 | [diff] [blame] | 256 | return opBufSize; |
Sushil Chauhan | fbffad7 | 2012-11-06 13:05:42 -0800 | [diff] [blame] | 257 | } |
Saurabh Shah | 0d0a7cb | 2013-02-12 17:58:19 -0800 | [diff] [blame] | 258 | |
| 259 | void MdssRot::getDump(char *buf, size_t len) const { |
Saurabh Shah | ae61b2b | 2013-04-10 16:37:25 -0700 | [diff] [blame] | 260 | ovutils::getDump(buf, len, "MdssRotCtrl", mRotInfo); |
| 261 | ovutils::getDump(buf, len, "MdssRotData", mRotData); |
Saurabh Shah | 0d0a7cb | 2013-02-12 17:58:19 -0800 | [diff] [blame] | 262 | } |
| 263 | |
Sushil Chauhan | bab187a | 2013-01-30 17:44:15 -0800 | [diff] [blame] | 264 | // Calculate the compressed o/p buffer size for BWC |
Sushil Chauhan | 466766f | 2013-07-31 11:21:07 -0700 | [diff] [blame] | 265 | uint32_t MdssRot::calcCompressedBufSize(const ovutils::Whf& destWhf) { |
Sushil Chauhan | bab187a | 2013-01-30 17:44:15 -0800 | [diff] [blame] | 266 | uint32_t bufSize = 0; |
Sushil Chauhan | 466766f | 2013-07-31 11:21:07 -0700 | [diff] [blame] | 267 | int aWidth = ovutils::align(destWhf.w, 64); |
| 268 | int aHeight = ovutils::align(destWhf.h, 4); |
Sushil Chauhan | bab187a | 2013-01-30 17:44:15 -0800 | [diff] [blame] | 269 | int rau_cnt = aWidth/64; |
| 270 | int stride0 = (64 * 4 * rau_cnt) + rau_cnt/8; |
Sushil Chauhan | 3bdf9e5 | 2013-07-08 18:34:35 -0700 | [diff] [blame] | 271 | int stride1 = ((64 * 2 * rau_cnt) + rau_cnt/8) * 2; |
Sushil Chauhan | bab187a | 2013-01-30 17:44:15 -0800 | [diff] [blame] | 272 | int stride0_off = (aHeight/4); |
| 273 | int stride1_off = (aHeight/2); |
| 274 | |
| 275 | //New o/p size for BWC |
| 276 | bufSize = (stride0 * stride0_off + stride1 * stride1_off) + |
| 277 | (rau_cnt * 2 * (stride0_off + stride1_off)); |
| 278 | ALOGD_IF(DEBUG_MDSS_ROT, "%s: width = %d, height = %d raucount = %d" |
| 279 | "opBufSize = %d ", __FUNCTION__, aWidth, aHeight, rau_cnt, bufSize); |
| 280 | return bufSize; |
| 281 | } |
| 282 | |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 283 | } // namespace overlay |