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 | |
Saurabh Shah | c46cf9d | 2014-07-02 15:22:34 -0700 | [diff] [blame^] | 20 | #include <math.h> |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 21 | #include "overlayUtils.h" |
| 22 | #include "overlayRotator.h" |
| 23 | |
Sushil Chauhan | bab187a | 2013-01-30 17:44:15 -0800 | [diff] [blame] | 24 | #define DEBUG_MDSS_ROT 0 |
| 25 | |
Sushil Chauhan | c6bd6d9 | 2012-12-12 12:33:01 -0800 | [diff] [blame] | 26 | #ifdef VENUS_COLOR_FORMAT |
| 27 | #include <media/msm_media_info.h> |
| 28 | #else |
| 29 | #define VENUS_BUFFER_SIZE(args...) 0 |
| 30 | #endif |
| 31 | |
Naseer Ahmed | c21013b | 2012-11-19 12:44:41 -0500 | [diff] [blame] | 32 | #ifndef MDSS_MDP_ROT_ONLY |
| 33 | #define MDSS_MDP_ROT_ONLY 0x80 |
| 34 | #endif |
| 35 | |
Sushil Chauhan | 95e4c9f | 2013-01-14 18:44:14 -0800 | [diff] [blame] | 36 | #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] | 37 | |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 38 | namespace ovutils = overlay::utils; |
| 39 | |
| 40 | namespace overlay { |
Saurabh Shah | 4b54c5b | 2014-05-01 18:36:51 -0700 | [diff] [blame] | 41 | using namespace utils; |
| 42 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 43 | MdssRot::MdssRot() { |
| 44 | reset(); |
| 45 | init(); |
| 46 | } |
| 47 | |
| 48 | MdssRot::~MdssRot() { close(); } |
| 49 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 50 | bool MdssRot::enabled() const { return mEnabled; } |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 51 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 52 | void MdssRot::setRotations(uint32_t flags) { mRotInfo.flags |= flags; } |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 53 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 54 | int MdssRot::getDstMemId() const { |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 55 | return mRotData.dst_data.memory_id; |
| 56 | } |
| 57 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 58 | uint32_t MdssRot::getDstOffset() const { |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 59 | return mRotData.dst_data.offset; |
| 60 | } |
| 61 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 62 | uint32_t MdssRot::getDstFormat() const { |
Raj kamal | 23f69b2 | 2012-11-17 00:20:55 +0530 | [diff] [blame] | 63 | //For mdss src and dst formats are same |
| 64 | return mRotInfo.src.format; |
| 65 | } |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 66 | |
Saurabh Shah | 8ec9b5e | 2014-06-30 14:37:17 -0700 | [diff] [blame] | 67 | utils::Whf MdssRot::getDstWhf() const { |
| 68 | //For Mdss dst_rect itself represents buffer dimensions. We ignore actual |
| 69 | //aligned values during buffer allocation. Also the driver overwrites the |
| 70 | //src.format field if destination format is different. |
| 71 | //This implementation detail makes it possible to retrieve w,h even before |
| 72 | //buffer allocation, which happens in queueBuffer. |
| 73 | return utils::Whf(mRotInfo.dst_rect.w, mRotInfo.dst_rect.h, |
| 74 | mRotInfo.src.format); |
| 75 | } |
| 76 | |
| 77 | utils::Dim MdssRot::getDstDimensions() const { |
| 78 | return utils::Dim(mRotInfo.dst_rect.x, mRotInfo.dst_rect.y, |
| 79 | mRotInfo.dst_rect.w, mRotInfo.dst_rect.h); |
| 80 | } |
| 81 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 82 | uint32_t MdssRot::getSessId() const { return mRotInfo.id; } |
Raj kamal | 23f69b2 | 2012-11-17 00:20:55 +0530 | [diff] [blame] | 83 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 84 | bool MdssRot::init() { |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 85 | if(!utils::openDev(mFd, 0, Res::fbPath, O_RDWR)) { |
| 86 | ALOGE("MdssRot failed to init fb0"); |
| 87 | return false; |
| 88 | } |
| 89 | return true; |
| 90 | } |
| 91 | |
| 92 | void MdssRot::setSource(const overlay::utils::Whf& awhf) { |
| 93 | utils::Whf whf(awhf); |
| 94 | |
| 95 | mRotInfo.src.format = whf.format; |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 96 | mRotInfo.src.width = whf.w; |
| 97 | mRotInfo.src.height = whf.h; |
Sushil Chauhan | 80fc1f9 | 2013-04-23 17:30:05 -0700 | [diff] [blame] | 98 | } |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 99 | |
Sushil Chauhan | 80fc1f9 | 2013-04-23 17:30:05 -0700 | [diff] [blame] | 100 | void MdssRot::setCrop(const utils::Dim& crop) { |
Sushil Chauhan | 80fc1f9 | 2013-04-23 17:30:05 -0700 | [diff] [blame] | 101 | mRotInfo.src_rect.x = crop.x; |
| 102 | mRotInfo.src_rect.y = crop.y; |
| 103 | mRotInfo.src_rect.w = crop.w; |
| 104 | mRotInfo.src_rect.h = crop.h; |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 105 | } |
| 106 | |
Saurabh Shah | c46cf9d | 2014-07-02 15:22:34 -0700 | [diff] [blame^] | 107 | void MdssRot::setDownscale(int downscale) { |
| 108 | mDownscale = downscale; |
Arun Kumar K.R | 7e5a1f8 | 2014-01-22 10:36:16 -0800 | [diff] [blame] | 109 | } |
Ramkumar Radhakrishnan | 288f8c7 | 2013-01-15 11:37:54 -0800 | [diff] [blame] | 110 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 111 | void MdssRot::setFlags(const utils::eMdpFlags& flags) { |
Sushil Chauhan | 6dcffbf | 2013-05-13 19:11:11 -0700 | [diff] [blame] | 112 | mRotInfo.flags = flags; |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 113 | } |
| 114 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 115 | void MdssRot::setTransform(const utils::eTransform& rot) |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 116 | { |
Saurabh Shah | 78ad495 | 2013-04-05 09:38:01 -0700 | [diff] [blame] | 117 | // reset rotation flags to avoid stale orientation values |
| 118 | mRotInfo.flags &= ~MDSS_ROT_MASK; |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 119 | int flags = utils::getMdpOrient(rot); |
| 120 | if (flags != -1) |
| 121 | setRotations(flags); |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 122 | mOrientation = static_cast<utils::eTransform>(flags); |
| 123 | ALOGE_IF(DEBUG_OVERLAY, "%s: rot=%d", __FUNCTION__, flags); |
Ramkumar Radhakrishnan | 288f8c7 | 2013-01-15 11:37:54 -0800 | [diff] [blame] | 124 | } |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 125 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 126 | void MdssRot::doTransform() { |
Sushil Chauhan | 6dcffbf | 2013-05-13 19:11:11 -0700 | [diff] [blame] | 127 | mRotInfo.flags |= mOrientation; |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 128 | if(mOrientation & utils::OVERLAY_TRANSFORM_ROT_90) |
| 129 | utils::swap(mRotInfo.dst_rect.w, mRotInfo.dst_rect.h); |
| 130 | } |
| 131 | |
| 132 | bool MdssRot::commit() { |
Saurabh Shah | c46cf9d | 2014-07-02 15:22:34 -0700 | [diff] [blame^] | 133 | Dim adjCrop(mRotInfo.src_rect.x,mRotInfo.src_rect.y, |
| 134 | mRotInfo.src_rect.w,mRotInfo.src_rect.h); |
| 135 | adjCrop = getFormatAdjustedCrop(adjCrop, mRotInfo.src.format, |
| 136 | mRotInfo.flags & utils::OV_MDP_DEINTERLACE); |
| 137 | adjCrop = getDownscaleAdjustedCrop(adjCrop, mDownscale); |
| 138 | |
| 139 | mRotInfo.src_rect.x = adjCrop.x; |
| 140 | mRotInfo.src_rect.y = adjCrop.y; |
| 141 | mRotInfo.src_rect.w = adjCrop.w; |
| 142 | mRotInfo.src_rect.h = adjCrop.h; |
Saurabh Shah | 8ec9b5e | 2014-06-30 14:37:17 -0700 | [diff] [blame] | 143 | |
| 144 | mRotInfo.dst_rect.x = 0; |
| 145 | mRotInfo.dst_rect.y = 0; |
Saurabh Shah | c46cf9d | 2014-07-02 15:22:34 -0700 | [diff] [blame^] | 146 | mRotInfo.dst_rect.w = mDownscale ? |
| 147 | mRotInfo.src_rect.w / mDownscale : mRotInfo.src_rect.w; |
| 148 | mRotInfo.dst_rect.h = mDownscale ? |
| 149 | mRotInfo.src_rect.h / mDownscale : mRotInfo.src_rect.h; |
| 150 | //Clear for next round |
| 151 | mDownscale = 0; |
Saurabh Shah | 8ec9b5e | 2014-06-30 14:37:17 -0700 | [diff] [blame] | 152 | |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 153 | doTransform(); |
Saurabh Shah | 8ec9b5e | 2014-06-30 14:37:17 -0700 | [diff] [blame] | 154 | |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 155 | mRotInfo.flags |= MDSS_MDP_ROT_ONLY; |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 156 | mEnabled = true; |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 157 | if(!overlay::mdp_wrapper::setOverlay(mFd.getFD(), mRotInfo)) { |
| 158 | ALOGE("MdssRot commit failed!"); |
| 159 | dump(); |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 160 | return (mEnabled = false); |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 161 | } |
| 162 | mRotData.id = mRotInfo.id; |
| 163 | return true; |
| 164 | } |
| 165 | |
| 166 | bool MdssRot::queueBuffer(int fd, uint32_t offset) { |
| 167 | if(enabled()) { |
| 168 | mRotData.data.memory_id = fd; |
| 169 | mRotData.data.offset = offset; |
| 170 | |
Saurabh Shah | 912c948 | 2014-02-07 14:01:04 -0800 | [diff] [blame] | 171 | if(false == remap(RotMem::ROT_NUM_BUFS)) { |
| 172 | ALOGE("%s Remap failed, not queuing", __FUNCTION__); |
| 173 | return false; |
| 174 | } |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 175 | |
| 176 | mRotData.dst_data.offset = |
Saurabh Shah | 912c948 | 2014-02-07 14:01:04 -0800 | [diff] [blame] | 177 | mMem.mRotOffset[mMem.mCurrIndex]; |
| 178 | mMem.mCurrIndex = |
| 179 | (mMem.mCurrIndex + 1) % mMem.mem.numBufs(); |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 180 | |
| 181 | if(!overlay::mdp_wrapper::play(mFd.getFD(), mRotData)) { |
| 182 | ALOGE("MdssRot play failed!"); |
| 183 | dump(); |
| 184 | return false; |
| 185 | } |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 186 | } |
| 187 | return true; |
| 188 | } |
| 189 | |
| 190 | bool MdssRot::open_i(uint32_t numbufs, uint32_t bufsz) |
| 191 | { |
| 192 | OvMem mem; |
| 193 | OVASSERT(MAP_FAILED == mem.addr(), "MAP failed in open_i"); |
Sushil Chauhan | faae042 | 2012-10-23 23:48:04 -0700 | [diff] [blame] | 194 | bool isSecure = mRotInfo.flags & utils::OV_MDP_SECURE_OVERLAY_SESSION; |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 195 | |
Sushil Chauhan | faae042 | 2012-10-23 23:48:04 -0700 | [diff] [blame] | 196 | if(!mem.open(numbufs, bufsz, isSecure)){ |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 197 | ALOGE("%s: Failed to open", __func__); |
| 198 | mem.close(); |
| 199 | return false; |
| 200 | } |
| 201 | |
| 202 | OVASSERT(MAP_FAILED != mem.addr(), "MAP failed"); |
| 203 | OVASSERT(mem.getFD() != -1, "getFd is -1"); |
| 204 | |
| 205 | mRotData.dst_data.memory_id = mem.getFD(); |
| 206 | mRotData.dst_data.offset = 0; |
Saurabh Shah | 912c948 | 2014-02-07 14:01:04 -0800 | [diff] [blame] | 207 | mMem.mem = mem; |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 208 | return true; |
| 209 | } |
| 210 | |
| 211 | bool MdssRot::remap(uint32_t numbufs) { |
Saurabh Shah | fc3652f | 2013-02-15 13:15:45 -0800 | [diff] [blame] | 212 | // Calculate the size based on rotator's dst format, w and h. |
| 213 | uint32_t opBufSize = calcOutputBufSize(); |
| 214 | // If current size changed, remap |
Saurabh Shah | 912c948 | 2014-02-07 14:01:04 -0800 | [diff] [blame] | 215 | if(opBufSize == mMem.size()) { |
Saurabh Shah | fc3652f | 2013-02-15 13:15:45 -0800 | [diff] [blame] | 216 | ALOGE_IF(DEBUG_OVERLAY, "%s: same size %d", __FUNCTION__, opBufSize); |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 217 | return true; |
| 218 | } |
| 219 | |
| 220 | ALOGE_IF(DEBUG_OVERLAY, "%s: size changed - remapping", __FUNCTION__); |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 221 | |
Saurabh Shah | 912c948 | 2014-02-07 14:01:04 -0800 | [diff] [blame] | 222 | if(!mMem.close()) { |
| 223 | ALOGE("%s error in closing prev rot mem", __FUNCTION__); |
| 224 | return false; |
| 225 | } |
| 226 | |
Saurabh Shah | fc3652f | 2013-02-15 13:15:45 -0800 | [diff] [blame] | 227 | if(!open_i(numbufs, opBufSize)) { |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 228 | ALOGE("%s Error could not open", __FUNCTION__); |
| 229 | return false; |
| 230 | } |
Saurabh Shah | 912c948 | 2014-02-07 14:01:04 -0800 | [diff] [blame] | 231 | |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 232 | for (uint32_t i = 0; i < numbufs; ++i) { |
Saurabh Shah | 912c948 | 2014-02-07 14:01:04 -0800 | [diff] [blame] | 233 | mMem.mRotOffset[i] = i * opBufSize; |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 234 | } |
Saurabh Shah | 912c948 | 2014-02-07 14:01:04 -0800 | [diff] [blame] | 235 | |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 236 | return true; |
| 237 | } |
| 238 | |
| 239 | bool MdssRot::close() { |
| 240 | bool success = true; |
Ken Zhang | ba48b01 | 2012-12-11 20:33:59 -0500 | [diff] [blame] | 241 | if(mFd.valid() && (getSessId() != (uint32_t) MSMFB_NEW_REQUEST)) { |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 242 | if(!mdp_wrapper::unsetOverlay(mFd.getFD(), getSessId())) { |
| 243 | ALOGE("MdssRot::close unsetOverlay failed, fd=%d sessId=%d", |
| 244 | mFd.getFD(), getSessId()); |
Ken Zhang | ba48b01 | 2012-12-11 20:33:59 -0500 | [diff] [blame] | 245 | success = false; |
| 246 | } |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | if (!mFd.close()) { |
| 250 | ALOGE("Mdss Rot error closing fd"); |
| 251 | success = false; |
| 252 | } |
| 253 | if (!mMem.close()) { |
| 254 | ALOGE("Mdss Rot error closing mem"); |
| 255 | success = false; |
| 256 | } |
| 257 | reset(); |
| 258 | return success; |
| 259 | } |
| 260 | |
| 261 | void MdssRot::reset() { |
| 262 | ovutils::memset0(mRotInfo); |
| 263 | ovutils::memset0(mRotData); |
| 264 | mRotData.data.memory_id = -1; |
| 265 | mRotInfo.id = MSMFB_NEW_REQUEST; |
Saurabh Shah | 912c948 | 2014-02-07 14:01:04 -0800 | [diff] [blame] | 266 | ovutils::memset0(mMem.mRotOffset); |
| 267 | mMem.mCurrIndex = 0; |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 268 | mOrientation = utils::OVERLAY_TRANSFORM_0; |
Saurabh Shah | c46cf9d | 2014-07-02 15:22:34 -0700 | [diff] [blame^] | 269 | mDownscale = 0; |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | void MdssRot::dump() const { |
| 273 | ALOGE("== Dump MdssRot start =="); |
| 274 | mFd.dump(); |
Saurabh Shah | 912c948 | 2014-02-07 14:01:04 -0800 | [diff] [blame] | 275 | mMem.mem.dump(); |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 276 | mdp_wrapper::dump("mRotInfo", mRotInfo); |
| 277 | mdp_wrapper::dump("mRotData", mRotData); |
| 278 | ALOGE("== Dump MdssRot end =="); |
| 279 | } |
| 280 | |
Saurabh Shah | fc3652f | 2013-02-15 13:15:45 -0800 | [diff] [blame] | 281 | uint32_t MdssRot::calcOutputBufSize() { |
| 282 | uint32_t opBufSize = 0; |
| 283 | ovutils::Whf destWhf(mRotInfo.dst_rect.w, mRotInfo.dst_rect.h, |
| 284 | mRotInfo.src.format); //mdss src and dst formats are same. |
Sushil Chauhan | b4d184f | 2013-02-11 16:13:10 -0800 | [diff] [blame] | 285 | |
Sushil Chauhan | bab187a | 2013-01-30 17:44:15 -0800 | [diff] [blame] | 286 | if (mRotInfo.flags & ovutils::OV_MDSS_MDP_BWC_EN) { |
Sushil Chauhan | 466766f | 2013-07-31 11:21:07 -0700 | [diff] [blame] | 287 | opBufSize = calcCompressedBufSize(destWhf); |
Sushil Chauhan | bab187a | 2013-01-30 17:44:15 -0800 | [diff] [blame] | 288 | } else { |
| 289 | opBufSize = Rotator::calcOutputBufSize(destWhf); |
| 290 | } |
Sushil Chauhan | b4d184f | 2013-02-11 16:13:10 -0800 | [diff] [blame] | 291 | |
Saurabh Shah | fc3652f | 2013-02-15 13:15:45 -0800 | [diff] [blame] | 292 | return opBufSize; |
Sushil Chauhan | fbffad7 | 2012-11-06 13:05:42 -0800 | [diff] [blame] | 293 | } |
Saurabh Shah | 0d0a7cb | 2013-02-12 17:58:19 -0800 | [diff] [blame] | 294 | |
| 295 | void MdssRot::getDump(char *buf, size_t len) const { |
Saurabh Shah | ae61b2b | 2013-04-10 16:37:25 -0700 | [diff] [blame] | 296 | ovutils::getDump(buf, len, "MdssRotCtrl", mRotInfo); |
| 297 | ovutils::getDump(buf, len, "MdssRotData", mRotData); |
Saurabh Shah | 0d0a7cb | 2013-02-12 17:58:19 -0800 | [diff] [blame] | 298 | } |
| 299 | |
Sushil Chauhan | bab187a | 2013-01-30 17:44:15 -0800 | [diff] [blame] | 300 | // Calculate the compressed o/p buffer size for BWC |
Sushil Chauhan | 466766f | 2013-07-31 11:21:07 -0700 | [diff] [blame] | 301 | uint32_t MdssRot::calcCompressedBufSize(const ovutils::Whf& destWhf) { |
Sushil Chauhan | bab187a | 2013-01-30 17:44:15 -0800 | [diff] [blame] | 302 | uint32_t bufSize = 0; |
Saurabh Shah | 4b54c5b | 2014-05-01 18:36:51 -0700 | [diff] [blame] | 303 | //Worst case alignments |
Sushil Chauhan | 466766f | 2013-07-31 11:21:07 -0700 | [diff] [blame] | 304 | int aWidth = ovutils::align(destWhf.w, 64); |
| 305 | int aHeight = ovutils::align(destWhf.h, 4); |
Saurabh Shah | 4b54c5b | 2014-05-01 18:36:51 -0700 | [diff] [blame] | 306 | /* |
| 307 | Format | RAU size (width x height) |
| 308 | ---------------------------------------------- |
| 309 | ARGB | 32 pixel x 4 line |
| 310 | RGB888 | 32 pixel x 4 line |
| 311 | Y (Luma) | 64 pixel x 4 line |
| 312 | CRCB 420 | 32 pixel x 2 line |
| 313 | CRCB 422 H2V1 | 32 pixel x 4 line |
| 314 | CRCB 422 H1V2 | 64 pixel x 2 line |
Sushil Chauhan | bab187a | 2013-01-30 17:44:15 -0800 | [diff] [blame] | 315 | |
Saurabh Shah | 4b54c5b | 2014-05-01 18:36:51 -0700 | [diff] [blame] | 316 | Metadata requirements:- |
| 317 | 1 byte meta data for every 8 RAUs |
| 318 | 2 byte meta data per RAU |
| 319 | */ |
| 320 | |
| 321 | //These blocks attempt to allocate for the worst case in each of the |
| 322 | //respective format classes, yuv/rgb. The table above is for reference |
| 323 | if(utils::isYuv(destWhf.format)) { |
| 324 | int yRauCount = aWidth / 64; //Y |
| 325 | int cRauCount = aWidth / 32; //C |
| 326 | int yStride = (64 * 4 * yRauCount) + alignup(yRauCount, 8) / 8; |
| 327 | int cStride = ((32 * 2 * cRauCount) + alignup(cRauCount, 8) / 8) * 2; |
| 328 | int yStrideOffset = (aHeight / 4); |
| 329 | int cStrideOffset = (aHeight / 2); |
| 330 | bufSize = (yStride * yStrideOffset + cStride * cStrideOffset) + |
| 331 | (yRauCount * yStrideOffset * 2) + |
| 332 | (cRauCount * cStrideOffset * 2) * 2; |
| 333 | ALOGD_IF(DEBUG_MDSS_ROT, "%s:YUV Y RAU Count = %d C RAU Count = %d", |
| 334 | __FUNCTION__, yRauCount, cRauCount); |
| 335 | } else { |
| 336 | int rauCount = aWidth / 32; |
| 337 | //Single plane |
| 338 | int stride = (32 * 4 * rauCount) + alignup(rauCount, 8) / 8; |
| 339 | int strideOffset = (aHeight / 4); |
| 340 | bufSize = (stride * strideOffset * 4 /*bpp*/) + |
| 341 | (rauCount * strideOffset * 2); |
| 342 | ALOGD_IF(DEBUG_MDSS_ROT, "%s:RGB RAU count = %d", __FUNCTION__, |
| 343 | rauCount); |
| 344 | } |
| 345 | |
| 346 | ALOGD_IF(DEBUG_MDSS_ROT, "%s: aligned width = %d, aligned height = %d " |
| 347 | "Buf Size = %d", __FUNCTION__, aWidth, aHeight, bufSize); |
| 348 | |
Sushil Chauhan | bab187a | 2013-01-30 17:44:15 -0800 | [diff] [blame] | 349 | return bufSize; |
| 350 | } |
| 351 | |
Saurabh Shah | c46cf9d | 2014-07-02 15:22:34 -0700 | [diff] [blame^] | 352 | int MdssRot::getDownscaleFactor(const int& srcW, const int& srcH, |
| 353 | const int& dstW, const int& dstH, const uint32_t& mdpFormat, |
| 354 | const bool& isInterlaced) { |
| 355 | if(not srcW or not srcH or not dstW or not dstH or isInterlaced) return 0; |
| 356 | |
| 357 | Dim crop(0, 0, srcW, srcH); |
| 358 | Dim adjCrop = getFormatAdjustedCrop(crop, mdpFormat, |
| 359 | false /*isInterlaced */); |
| 360 | |
| 361 | uint32_t downscale = min((adjCrop.w / dstW), (adjCrop.h / dstH)); |
| 362 | //Reduced to a power of 2 |
| 363 | downscale = (uint32_t) powf(2.0f, floorf(log2f((float)downscale))); |
| 364 | |
| 365 | if(downscale < 2 or downscale > 32) return 0; |
| 366 | |
| 367 | //Allow only 1 line or pixel to be chopped off since the source needs to |
| 368 | //be aligned to downscale. Progressively try with smaller downscale to see |
| 369 | //if we can satisfy the threshold |
| 370 | //For YUV the loop shouldnt be needed, unless in exceptional cases |
| 371 | Dim dsAdjCrop = getDownscaleAdjustedCrop(adjCrop, downscale); |
| 372 | while(downscale > 2 and (adjCrop.w > dsAdjCrop.w or |
| 373 | adjCrop.h > dsAdjCrop.h)) { |
| 374 | downscale /= 2; |
| 375 | dsAdjCrop = getDownscaleAdjustedCrop(adjCrop, downscale); |
| 376 | } |
| 377 | |
| 378 | if(not dsAdjCrop.w or not dsAdjCrop.h) return 0; |
| 379 | return downscale; |
| 380 | } |
| 381 | |
| 382 | Dim MdssRot::getFormatAdjustedCrop(const Dim& crop, |
| 383 | const uint32_t& mdpFormat, const bool& isInterlaced) { |
| 384 | Dim adjCrop = crop; |
| 385 | if (isYuv(mdpFormat)) { |
| 386 | normalizeCrop(adjCrop.x, adjCrop.w); |
| 387 | normalizeCrop(adjCrop.y, adjCrop.h); |
| 388 | // For interlaced, crop.h should be 4-aligned |
| 389 | if (isInterlaced and (adjCrop.h % 4)) |
| 390 | adjCrop.h = aligndown(adjCrop.h, 4); |
| 391 | } |
| 392 | return adjCrop; |
| 393 | } |
| 394 | |
| 395 | Dim MdssRot::getDownscaleAdjustedCrop(const Dim& crop, |
| 396 | const uint32_t& downscale) { |
| 397 | uint32_t alignedSrcW = aligndown(crop.w, downscale * 2); |
| 398 | uint32_t alignedSrcH = aligndown(crop.h, downscale * 2); |
| 399 | return Dim(crop.x, crop.y, alignedSrcW, alignedSrcH); |
| 400 | } |
| 401 | |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 402 | } // namespace overlay |