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" |
Saurabh Shah | 8ec9b5e | 2014-06-30 14:37:17 -0700 | [diff] [blame] | 23 | #include "gr.h" |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 24 | |
| 25 | namespace ovutils = overlay::utils; |
| 26 | |
| 27 | namespace overlay { |
| 28 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 29 | MdpRot::MdpRot() { |
| 30 | reset(); |
| 31 | init(); |
| 32 | } |
| 33 | |
| 34 | MdpRot::~MdpRot() { close(); } |
| 35 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 36 | bool MdpRot::enabled() const { return mRotImgInfo.enable; } |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 37 | |
Shalaj Jain | a70b435 | 2014-06-15 13:47:47 -0700 | [diff] [blame] | 38 | void MdpRot::setRotations(uint32_t r) { mRotImgInfo.rotations = (uint8_t)r; } |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 39 | |
Raj Kamal | bd3bdc6 | 2014-08-05 18:52:49 +0530 | [diff] [blame] | 40 | int MdpRot::getSrcMemId() const { |
| 41 | return mRotDataInfo.src.memory_id; |
| 42 | } |
| 43 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 44 | int MdpRot::getDstMemId() const { |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 45 | return mRotDataInfo.dst.memory_id; |
| 46 | } |
| 47 | |
Raj Kamal | bd3bdc6 | 2014-08-05 18:52:49 +0530 | [diff] [blame] | 48 | uint32_t MdpRot::getSrcOffset() const { |
| 49 | return mRotDataInfo.src.offset; |
| 50 | } |
| 51 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 52 | uint32_t MdpRot::getDstOffset() const { |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 53 | return mRotDataInfo.dst.offset; |
| 54 | } |
| 55 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 56 | uint32_t MdpRot::getDstFormat() const { |
Raj kamal | 23f69b2 | 2012-11-17 00:20:55 +0530 | [diff] [blame] | 57 | return mRotImgInfo.dst.format; |
| 58 | } |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 59 | |
Saurabh Shah | 8ec9b5e | 2014-06-30 14:37:17 -0700 | [diff] [blame] | 60 | //Added for completeness. Not expected to be called. |
| 61 | utils::Whf MdpRot::getDstWhf() 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::Whf(alW, alH, mRotImgInfo.dst.format); |
| 67 | } |
| 68 | |
| 69 | //Added for completeness. Not expected to be called. |
| 70 | utils::Dim MdpRot::getDstDimensions() const { |
| 71 | int alW = 0, alH = 0; |
| 72 | int halFormat = ovutils::getHALFormat(mRotImgInfo.dst.format); |
| 73 | getBufferSizeAndDimensions(mRotImgInfo.dst.width, mRotImgInfo.dst.height, |
| 74 | halFormat, alW, alH); |
| 75 | return utils::Dim(0, 0, alW, alH); |
| 76 | } |
| 77 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 78 | uint32_t MdpRot::getSessId() const { return mRotImgInfo.session_id; } |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 79 | |
Ramkumar Radhakrishnan | 288f8c7 | 2013-01-15 11:37:54 -0800 | [diff] [blame] | 80 | void MdpRot::setDownscale(int ds) { |
Ramkumar Radhakrishnan | 4ca8f3a | 2013-02-14 18:56:50 -0800 | [diff] [blame] | 81 | if ((utils::ROT_DS_EIGHTH == ds) && (mRotImgInfo.src_rect.h & 0xF)) { |
Ramkumar Radhakrishnan | 288f8c7 | 2013-01-15 11:37:54 -0800 | [diff] [blame] | 82 | // Ensure src_rect.h is a multiple of 16 for 1/8 downscaling. |
| 83 | // This is an undocumented MDP Rotator constraint. |
Ramkumar Radhakrishnan | 4ca8f3a | 2013-02-14 18:56:50 -0800 | [diff] [blame] | 84 | mRotImgInfo.src_rect.h = utils::aligndown(mRotImgInfo.src_rect.h, 16); |
Ramkumar Radhakrishnan | 288f8c7 | 2013-01-15 11:37:54 -0800 | [diff] [blame] | 85 | } |
| 86 | mRotImgInfo.downscale_ratio = ds; |
| 87 | } |
| 88 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 89 | void MdpRot::save() { |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 90 | mLSRotImgInfo = mRotImgInfo; |
| 91 | } |
| 92 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 93 | bool MdpRot::rotConfChanged() const { |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 94 | // 0 means same |
| 95 | if(0 == ::memcmp(&mRotImgInfo, &mLSRotImgInfo, |
| 96 | sizeof (msm_rotator_img_info))) { |
| 97 | return false; |
| 98 | } |
| 99 | return true; |
| 100 | } |
| 101 | |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 102 | bool MdpRot::init() |
| 103 | { |
| 104 | if(!mFd.open(Res::rotPath, O_RDWR)){ |
| 105 | ALOGE("MdpRot failed to init %s", Res::rotPath); |
| 106 | return false; |
| 107 | } |
| 108 | return true; |
| 109 | } |
| 110 | |
| 111 | void MdpRot::setSource(const overlay::utils::Whf& awhf) { |
| 112 | utils::Whf whf(awhf); |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 113 | mRotImgInfo.src.format = whf.format; |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 114 | |
| 115 | mRotImgInfo.src.width = whf.w; |
| 116 | mRotImgInfo.src.height = whf.h; |
| 117 | |
| 118 | mRotImgInfo.src_rect.w = whf.w; |
| 119 | mRotImgInfo.src_rect.h = whf.h; |
| 120 | |
| 121 | mRotImgInfo.dst.width = whf.w; |
| 122 | mRotImgInfo.dst.height = whf.h; |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 123 | } |
| 124 | |
Arun Kumar K.R | 7e5a1f8 | 2014-01-22 10:36:16 -0800 | [diff] [blame] | 125 | void MdpRot::setCrop(const utils::Dim& /*crop*/) { |
Sushil Chauhan | 80fc1f9 | 2013-04-23 17:30:05 -0700 | [diff] [blame] | 126 | // NO-OP for non-mdss rotator due to possible h/w limitations |
| 127 | } |
| 128 | |
radhakrishna | b8e2c95 | 2015-06-04 16:09:16 +0530 | [diff] [blame^] | 129 | void MdpRot::setFrameRate(uint32_t /*frame_rate*/) { |
| 130 | // NO-OP for non-mdss rotator |
| 131 | } |
| 132 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 133 | void MdpRot::setFlags(const utils::eMdpFlags& flags) { |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 134 | mRotImgInfo.secure = 0; |
| 135 | if(flags & utils::OV_MDP_SECURE_OVERLAY_SESSION) |
| 136 | mRotImgInfo.secure = 1; |
| 137 | } |
| 138 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 139 | void MdpRot::setTransform(const utils::eTransform& rot) |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 140 | { |
| 141 | int r = utils::getMdpOrient(rot); |
| 142 | setRotations(r); |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 143 | mOrientation = static_cast<utils::eTransform>(r); |
| 144 | ALOGE_IF(DEBUG_OVERLAY, "%s: r=%d", __FUNCTION__, r); |
Ramkumar Radhakrishnan | 288f8c7 | 2013-01-15 11:37:54 -0800 | [diff] [blame] | 145 | } |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 146 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 147 | void MdpRot::doTransform() { |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 148 | if(mOrientation & utils::OVERLAY_TRANSFORM_ROT_90) |
| 149 | utils::swap(mRotImgInfo.dst.width, mRotImgInfo.dst.height); |
| 150 | } |
| 151 | |
| 152 | bool MdpRot::commit() { |
| 153 | doTransform(); |
Saurabh Shah | c23b380 | 2012-08-31 11:11:30 -0700 | [diff] [blame] | 154 | if(rotConfChanged()) { |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 155 | mRotImgInfo.enable = 1; |
Saurabh Shah | c23b380 | 2012-08-31 11:11:30 -0700 | [diff] [blame] | 156 | if(!overlay::mdp_wrapper::startRotator(mFd.getFD(), mRotImgInfo)) { |
| 157 | ALOGE("MdpRot commit failed"); |
| 158 | dump(); |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 159 | mRotImgInfo.enable = 0; |
Saurabh Shah | c23b380 | 2012-08-31 11:11:30 -0700 | [diff] [blame] | 160 | return false; |
| 161 | } |
Saurabh Shah | c23b380 | 2012-08-31 11:11:30 -0700 | [diff] [blame] | 162 | mRotDataInfo.session_id = mRotImgInfo.session_id; |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 163 | } |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 164 | return true; |
| 165 | } |
| 166 | |
Saurabh Shah | fc3652f | 2013-02-15 13:15:45 -0800 | [diff] [blame] | 167 | uint32_t MdpRot::calcOutputBufSize() { |
| 168 | ovutils::Whf destWhf(mRotImgInfo.dst.width, |
| 169 | mRotImgInfo.dst.height, mRotImgInfo.dst.format); |
| 170 | return Rotator::calcOutputBufSize(destWhf); |
| 171 | } |
| 172 | |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 173 | bool MdpRot::open_i(uint32_t numbufs, uint32_t bufsz) |
| 174 | { |
| 175 | OvMem mem; |
| 176 | |
| 177 | OVASSERT(MAP_FAILED == mem.addr(), "MAP failed in open_i"); |
| 178 | |
| 179 | if(!mem.open(numbufs, bufsz, mRotImgInfo.secure)){ |
| 180 | ALOGE("%s: Failed to open", __func__); |
| 181 | mem.close(); |
| 182 | return false; |
| 183 | } |
| 184 | |
| 185 | OVASSERT(MAP_FAILED != mem.addr(), "MAP failed"); |
| 186 | OVASSERT(mem.getFD() != -1, "getFd is -1"); |
| 187 | |
| 188 | mRotDataInfo.dst.memory_id = mem.getFD(); |
| 189 | mRotDataInfo.dst.offset = 0; |
Saurabh Shah | 912c948 | 2014-02-07 14:01:04 -0800 | [diff] [blame] | 190 | mMem.mem = mem; |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 191 | return true; |
| 192 | } |
| 193 | |
| 194 | bool MdpRot::close() { |
| 195 | bool success = true; |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 196 | if(mFd.valid() && (getSessId() != 0)) { |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 197 | if(!mdp_wrapper::endRotator(mFd.getFD(), getSessId())) { |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 198 | ALOGE("Mdp Rot error endRotator, fd=%d sessId=%u", |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 199 | mFd.getFD(), getSessId()); |
| 200 | success = false; |
| 201 | } |
| 202 | } |
| 203 | if (!mFd.close()) { |
| 204 | ALOGE("Mdp Rot error closing fd"); |
| 205 | success = false; |
| 206 | } |
| 207 | if (!mMem.close()) { |
| 208 | ALOGE("Mdp Rot error closing mem"); |
| 209 | success = false; |
| 210 | } |
| 211 | reset(); |
| 212 | return success; |
| 213 | } |
| 214 | |
| 215 | bool MdpRot::remap(uint32_t numbufs) { |
| 216 | // if current size changed, remap |
Saurabh Shah | fc3652f | 2013-02-15 13:15:45 -0800 | [diff] [blame] | 217 | uint32_t opBufSize = calcOutputBufSize(); |
Saurabh Shah | 912c948 | 2014-02-07 14:01:04 -0800 | [diff] [blame] | 218 | if(opBufSize == mMem.size()) { |
Saurabh Shah | fc3652f | 2013-02-15 13:15:45 -0800 | [diff] [blame] | 219 | ALOGE_IF(DEBUG_OVERLAY, "%s: same size %d", __FUNCTION__, opBufSize); |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 220 | return true; |
| 221 | } |
| 222 | |
Saurabh Shah | 912c948 | 2014-02-07 14:01:04 -0800 | [diff] [blame] | 223 | if(!mMem.close()) { |
| 224 | ALOGE("%s error in closing prev rot mem", __FUNCTION__); |
| 225 | return false; |
| 226 | } |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 227 | |
Saurabh Shah | 912c948 | 2014-02-07 14:01:04 -0800 | [diff] [blame] | 228 | ALOGE_IF(DEBUG_OVERLAY, "%s: size changed - remapping", __FUNCTION__); |
| 229 | |
Saurabh Shah | fc3652f | 2013-02-15 13:15:45 -0800 | [diff] [blame] | 230 | if(!open_i(numbufs, opBufSize)) { |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 231 | ALOGE("%s Error could not open", __FUNCTION__); |
| 232 | return false; |
| 233 | } |
Saurabh Shah | 912c948 | 2014-02-07 14:01:04 -0800 | [diff] [blame] | 234 | |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 235 | for (uint32_t i = 0; i < numbufs; ++i) { |
Saurabh Shah | 912c948 | 2014-02-07 14:01:04 -0800 | [diff] [blame] | 236 | mMem.mRotOffset[i] = i * opBufSize; |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 237 | } |
Saurabh Shah | 912c948 | 2014-02-07 14:01:04 -0800 | [diff] [blame] | 238 | |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 239 | return true; |
| 240 | } |
| 241 | |
| 242 | void MdpRot::reset() { |
| 243 | ovutils::memset0(mRotImgInfo); |
Saurabh Shah | c23b380 | 2012-08-31 11:11:30 -0700 | [diff] [blame] | 244 | ovutils::memset0(mLSRotImgInfo); |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 245 | ovutils::memset0(mRotDataInfo); |
Saurabh Shah | 912c948 | 2014-02-07 14:01:04 -0800 | [diff] [blame] | 246 | ovutils::memset0(mMem.mRotOffset); |
| 247 | mMem.mCurrIndex = 0; |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 248 | mOrientation = utils::OVERLAY_TRANSFORM_0; |
| 249 | } |
| 250 | |
| 251 | bool MdpRot::queueBuffer(int fd, uint32_t offset) { |
Raj Kamal | bd3bdc6 | 2014-08-05 18:52:49 +0530 | [diff] [blame] | 252 | if(enabled() and (not isRotCached(fd,offset))) { |
| 253 | int prev_fd = getSrcMemId(); |
| 254 | uint32_t prev_offset = getSrcOffset(); |
| 255 | |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 256 | mRotDataInfo.src.memory_id = fd; |
| 257 | mRotDataInfo.src.offset = offset; |
| 258 | |
Saurabh Shah | 912c948 | 2014-02-07 14:01:04 -0800 | [diff] [blame] | 259 | if(false == remap(RotMem::ROT_NUM_BUFS)) { |
| 260 | ALOGE("%s Remap failed, not queueing", __FUNCTION__); |
| 261 | return false; |
| 262 | } |
| 263 | |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 264 | mRotDataInfo.dst.offset = |
Saurabh Shah | 912c948 | 2014-02-07 14:01:04 -0800 | [diff] [blame] | 265 | mMem.mRotOffset[mMem.mCurrIndex]; |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 266 | |
| 267 | if(!overlay::mdp_wrapper::rotate(mFd.getFD(), mRotDataInfo)) { |
| 268 | ALOGE("MdpRot failed rotate"); |
| 269 | dump(); |
Raj Kamal | bd3bdc6 | 2014-08-05 18:52:49 +0530 | [diff] [blame] | 270 | mRotDataInfo.src.memory_id = prev_fd; |
| 271 | mRotDataInfo.src.offset = prev_offset; |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 272 | return false; |
| 273 | } |
Raj Kamal | bd3bdc6 | 2014-08-05 18:52:49 +0530 | [diff] [blame] | 274 | save(); |
| 275 | mMem.mCurrIndex = |
| 276 | (mMem.mCurrIndex + 1) % mMem.mem.numBufs(); |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 277 | } |
| 278 | return true; |
| 279 | } |
| 280 | |
| 281 | void MdpRot::dump() const { |
| 282 | ALOGE("== Dump MdpRot start =="); |
| 283 | mFd.dump(); |
Saurabh Shah | 912c948 | 2014-02-07 14:01:04 -0800 | [diff] [blame] | 284 | mMem.mem.dump(); |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 285 | mdp_wrapper::dump("mRotImgInfo", mRotImgInfo); |
| 286 | mdp_wrapper::dump("mRotDataInfo", mRotDataInfo); |
| 287 | ALOGE("== Dump MdpRot end =="); |
| 288 | } |
| 289 | |
Saurabh Shah | 0d0a7cb | 2013-02-12 17:58:19 -0800 | [diff] [blame] | 290 | void MdpRot::getDump(char *buf, size_t len) const { |
Saurabh Shah | ae61b2b | 2013-04-10 16:37:25 -0700 | [diff] [blame] | 291 | ovutils::getDump(buf, len, "MdpRotCtrl", mRotImgInfo); |
| 292 | ovutils::getDump(buf, len, "MdpRotData", mRotDataInfo); |
Saurabh Shah | 0d0a7cb | 2013-02-12 17:58:19 -0800 | [diff] [blame] | 293 | } |
| 294 | |
Saurabh Shah | c46cf9d | 2014-07-02 15:22:34 -0700 | [diff] [blame] | 295 | int MdpRot::getDownscaleFactor(const int& src_w, const int& src_h, |
| 296 | const int& dst_w, const int& dst_h, const uint32_t& /*mdpFormat*/, |
| 297 | const bool& /*isInterlaced*/) { |
| 298 | int dscale_factor = utils::ROT_DS_NONE; |
| 299 | // We need this check to engage the rotator whenever possible to assist MDP |
| 300 | // in performing video downscale. |
| 301 | // This saves bandwidth and avoids causing the driver to make too many panel |
| 302 | // -mode switches between BLT (writeback) and non-BLT (Direct) modes. |
| 303 | // Use-case: Video playback [with downscaling and rotation]. |
| 304 | if (dst_w && dst_h) |
| 305 | { |
| 306 | float fDscale = (float)(src_w * src_h) / (float)(dst_w * dst_h); |
| 307 | uint32_t dscale = (int)sqrtf(fDscale); |
| 308 | |
| 309 | if(dscale < 2) { |
| 310 | // Down-scale to > 50% of orig. |
| 311 | dscale_factor = utils::ROT_DS_NONE; |
| 312 | } else if(dscale < 4) { |
| 313 | // Down-scale to between > 25% to <= 50% of orig. |
| 314 | dscale_factor = utils::ROT_DS_HALF; |
| 315 | } else if(dscale < 8) { |
| 316 | // Down-scale to between > 12.5% to <= 25% of orig. |
| 317 | dscale_factor = utils::ROT_DS_FOURTH; |
| 318 | } else { |
| 319 | // Down-scale to <= 12.5% of orig. |
| 320 | dscale_factor = utils::ROT_DS_EIGHTH; |
| 321 | } |
| 322 | } |
| 323 | return dscale_factor; |
| 324 | } |
| 325 | |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 326 | } // namespace overlay |