blob: 39b240d5a15e5aa9b92385e8e7db804f00c27f9a [file] [log] [blame]
Saurabh Shahe012f7a2012-08-18 15:11:57 -07001/*
Naseer Ahmed758bfc52012-11-28 17:02:08 -05002 * Copyright (C) 2008 The Android Open Source Project
Arun Kumar K.R7e5a1f82014-01-22 10:36:16 -08003 * Copyright (c) 2010-2014, The Linux Foundation. All rights reserved.
Naseer Ahmed758bfc52012-11-28 17:02:08 -05004 * 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 Shahe012f7a2012-08-18 15:11:57 -070018*/
19
Saurabh Shahc46cf9d2014-07-02 15:22:34 -070020#include <math.h>
Saurabh Shahe012f7a2012-08-18 15:11:57 -070021#include "overlayUtils.h"
22#include "overlayRotator.h"
23
Sushil Chauhanbab187a2013-01-30 17:44:15 -080024#define DEBUG_MDSS_ROT 0
25
Sushil Chauhanc6bd6d92012-12-12 12:33:01 -080026#ifdef VENUS_COLOR_FORMAT
27#include <media/msm_media_info.h>
28#else
29#define VENUS_BUFFER_SIZE(args...) 0
30#endif
31
Naseer Ahmedc21013b2012-11-19 12:44:41 -050032#ifndef MDSS_MDP_ROT_ONLY
33#define MDSS_MDP_ROT_ONLY 0x80
34#endif
35
Sushil Chauhan95e4c9f2013-01-14 18:44:14 -080036#define MDSS_ROT_MASK (MDP_ROT_90 | MDP_FLIP_UD | MDP_FLIP_LR)
Sushil Chauhan6e3fab82012-11-19 15:30:33 -080037
Saurabh Shahe012f7a2012-08-18 15:11:57 -070038namespace ovutils = overlay::utils;
39
40namespace overlay {
Saurabh Shah4b54c5b2014-05-01 18:36:51 -070041using namespace utils;
42
Naseer Ahmed758bfc52012-11-28 17:02:08 -050043MdssRot::MdssRot() {
44 reset();
45 init();
46}
47
48MdssRot::~MdssRot() { close(); }
49
Saurabh Shahacf10202013-02-26 10:15:15 -080050bool MdssRot::enabled() const { return mEnabled; }
Naseer Ahmed758bfc52012-11-28 17:02:08 -050051
Saurabh Shahacf10202013-02-26 10:15:15 -080052void MdssRot::setRotations(uint32_t flags) { mRotInfo.flags |= flags; }
Naseer Ahmed758bfc52012-11-28 17:02:08 -050053
Raj Kamalbd3bdc62014-08-05 18:52:49 +053054int MdssRot::getSrcMemId() const {
55 return mRotData.data.memory_id;
56}
57
Saurabh Shahacf10202013-02-26 10:15:15 -080058int MdssRot::getDstMemId() const {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050059 return mRotData.dst_data.memory_id;
60}
61
Raj Kamalbd3bdc62014-08-05 18:52:49 +053062uint32_t MdssRot::getSrcOffset() const {
63 return mRotData.data.offset;
64}
65
Saurabh Shahacf10202013-02-26 10:15:15 -080066uint32_t MdssRot::getDstOffset() const {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050067 return mRotData.dst_data.offset;
68}
69
Saurabh Shahacf10202013-02-26 10:15:15 -080070uint32_t MdssRot::getDstFormat() const {
Raj kamal23f69b22012-11-17 00:20:55 +053071 //For mdss src and dst formats are same
72 return mRotInfo.src.format;
73}
Naseer Ahmed758bfc52012-11-28 17:02:08 -050074
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -070075utils::Whf MdssRot::getDstWhf() const {
76 //For Mdss dst_rect itself represents buffer dimensions. We ignore actual
77 //aligned values during buffer allocation. Also the driver overwrites the
78 //src.format field if destination format is different.
79 //This implementation detail makes it possible to retrieve w,h even before
80 //buffer allocation, which happens in queueBuffer.
81 return utils::Whf(mRotInfo.dst_rect.w, mRotInfo.dst_rect.h,
82 mRotInfo.src.format);
83}
84
85utils::Dim MdssRot::getDstDimensions() const {
86 return utils::Dim(mRotInfo.dst_rect.x, mRotInfo.dst_rect.y,
87 mRotInfo.dst_rect.w, mRotInfo.dst_rect.h);
88}
89
Saurabh Shahacf10202013-02-26 10:15:15 -080090uint32_t MdssRot::getSessId() const { return mRotInfo.id; }
Raj kamal23f69b22012-11-17 00:20:55 +053091
Raj Kamalbd3bdc62014-08-05 18:52:49 +053092void MdssRot::save() {
93 mLSRotInfo = mRotInfo;
94}
95
96bool MdssRot::rotConfChanged() const {
97 // 0 means same
98 if(0 == ::memcmp(&mRotInfo, &mLSRotInfo,
99 sizeof (mdp_overlay))) {
100 return false;
101 }
102 return true;
103}
104
Saurabh Shahacf10202013-02-26 10:15:15 -0800105bool MdssRot::init() {
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700106 if(!utils::openDev(mFd, 0, Res::fbPath, O_RDWR)) {
107 ALOGE("MdssRot failed to init fb0");
108 return false;
109 }
110 return true;
111}
112
113void MdssRot::setSource(const overlay::utils::Whf& awhf) {
114 utils::Whf whf(awhf);
115
116 mRotInfo.src.format = whf.format;
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700117 mRotInfo.src.width = whf.w;
118 mRotInfo.src.height = whf.h;
Sushil Chauhan80fc1f92013-04-23 17:30:05 -0700119}
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700120
Sushil Chauhan80fc1f92013-04-23 17:30:05 -0700121void MdssRot::setCrop(const utils::Dim& crop) {
Sushil Chauhan80fc1f92013-04-23 17:30:05 -0700122 mRotInfo.src_rect.x = crop.x;
123 mRotInfo.src_rect.y = crop.y;
124 mRotInfo.src_rect.w = crop.w;
125 mRotInfo.src_rect.h = crop.h;
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700126}
127
Saurabh Shahc46cf9d2014-07-02 15:22:34 -0700128void MdssRot::setDownscale(int downscale) {
129 mDownscale = downscale;
Arun Kumar K.R7e5a1f82014-01-22 10:36:16 -0800130}
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800131
radhakrishnab8e2c952015-06-04 16:09:16 +0530132void MdssRot::setFrameRate(uint32_t frame_rate) {
133 mRotInfo.frame_rate = frame_rate;
134}
135
Saurabh Shahacf10202013-02-26 10:15:15 -0800136void MdssRot::setFlags(const utils::eMdpFlags& flags) {
Sushil Chauhan6dcffbf2013-05-13 19:11:11 -0700137 mRotInfo.flags = flags;
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700138}
139
Saurabh Shahacf10202013-02-26 10:15:15 -0800140void MdssRot::setTransform(const utils::eTransform& rot)
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700141{
Saurabh Shah78ad4952013-04-05 09:38:01 -0700142 // reset rotation flags to avoid stale orientation values
143 mRotInfo.flags &= ~MDSS_ROT_MASK;
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700144 int flags = utils::getMdpOrient(rot);
145 if (flags != -1)
146 setRotations(flags);
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700147 mOrientation = static_cast<utils::eTransform>(flags);
148 ALOGE_IF(DEBUG_OVERLAY, "%s: rot=%d", __FUNCTION__, flags);
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800149}
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700150
Saurabh Shahacf10202013-02-26 10:15:15 -0800151void MdssRot::doTransform() {
Sushil Chauhan6dcffbf2013-05-13 19:11:11 -0700152 mRotInfo.flags |= mOrientation;
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700153 if(mOrientation & utils::OVERLAY_TRANSFORM_ROT_90)
154 utils::swap(mRotInfo.dst_rect.w, mRotInfo.dst_rect.h);
155}
156
157bool MdssRot::commit() {
Saurabh Shahc46cf9d2014-07-02 15:22:34 -0700158 Dim adjCrop(mRotInfo.src_rect.x,mRotInfo.src_rect.y,
159 mRotInfo.src_rect.w,mRotInfo.src_rect.h);
160 adjCrop = getFormatAdjustedCrop(adjCrop, mRotInfo.src.format,
161 mRotInfo.flags & utils::OV_MDP_DEINTERLACE);
162 adjCrop = getDownscaleAdjustedCrop(adjCrop, mDownscale);
163
164 mRotInfo.src_rect.x = adjCrop.x;
165 mRotInfo.src_rect.y = adjCrop.y;
166 mRotInfo.src_rect.w = adjCrop.w;
167 mRotInfo.src_rect.h = adjCrop.h;
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -0700168
169 mRotInfo.dst_rect.x = 0;
170 mRotInfo.dst_rect.y = 0;
Saurabh Shahc46cf9d2014-07-02 15:22:34 -0700171 mRotInfo.dst_rect.w = mDownscale ?
172 mRotInfo.src_rect.w / mDownscale : mRotInfo.src_rect.w;
173 mRotInfo.dst_rect.h = mDownscale ?
174 mRotInfo.src_rect.h / mDownscale : mRotInfo.src_rect.h;
175 //Clear for next round
176 mDownscale = 0;
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -0700177
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700178 doTransform();
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -0700179
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700180 mRotInfo.flags |= MDSS_MDP_ROT_ONLY;
Saurabh Shahacf10202013-02-26 10:15:15 -0800181 mEnabled = true;
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700182 if(!overlay::mdp_wrapper::setOverlay(mFd.getFD(), mRotInfo)) {
183 ALOGE("MdssRot commit failed!");
184 dump();
Saurabh Shahacf10202013-02-26 10:15:15 -0800185 return (mEnabled = false);
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700186 }
187 mRotData.id = mRotInfo.id;
188 return true;
189}
190
191bool MdssRot::queueBuffer(int fd, uint32_t offset) {
Raj Kamalbd3bdc62014-08-05 18:52:49 +0530192 if(enabled() and (not isRotCached(fd,offset))) {
193 int prev_fd = getSrcMemId();
194 uint32_t prev_offset = getSrcOffset();
195
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700196 mRotData.data.memory_id = fd;
197 mRotData.data.offset = offset;
198
Saurabh Shah912c9482014-02-07 14:01:04 -0800199 if(false == remap(RotMem::ROT_NUM_BUFS)) {
200 ALOGE("%s Remap failed, not queuing", __FUNCTION__);
201 return false;
202 }
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700203
204 mRotData.dst_data.offset =
Saurabh Shah912c9482014-02-07 14:01:04 -0800205 mMem.mRotOffset[mMem.mCurrIndex];
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700206
207 if(!overlay::mdp_wrapper::play(mFd.getFD(), mRotData)) {
208 ALOGE("MdssRot play failed!");
209 dump();
Raj Kamalbd3bdc62014-08-05 18:52:49 +0530210 mRotData.data.memory_id = prev_fd;
211 mRotData.data.offset = prev_offset;
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700212 return false;
213 }
Raj Kamalbd3bdc62014-08-05 18:52:49 +0530214 save();
215 mMem.mCurrIndex =
216 (mMem.mCurrIndex + 1) % mMem.mem.numBufs();
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700217 }
218 return true;
219}
220
221bool MdssRot::open_i(uint32_t numbufs, uint32_t bufsz)
222{
223 OvMem mem;
224 OVASSERT(MAP_FAILED == mem.addr(), "MAP failed in open_i");
Sushil Chauhanfaae0422012-10-23 23:48:04 -0700225 bool isSecure = mRotInfo.flags & utils::OV_MDP_SECURE_OVERLAY_SESSION;
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700226
Sushil Chauhanfaae0422012-10-23 23:48:04 -0700227 if(!mem.open(numbufs, bufsz, isSecure)){
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700228 ALOGE("%s: Failed to open", __func__);
229 mem.close();
230 return false;
231 }
232
233 OVASSERT(MAP_FAILED != mem.addr(), "MAP failed");
234 OVASSERT(mem.getFD() != -1, "getFd is -1");
235
236 mRotData.dst_data.memory_id = mem.getFD();
237 mRotData.dst_data.offset = 0;
Saurabh Shah912c9482014-02-07 14:01:04 -0800238 mMem.mem = mem;
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700239 return true;
240}
241
242bool MdssRot::remap(uint32_t numbufs) {
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800243 // Calculate the size based on rotator's dst format, w and h.
244 uint32_t opBufSize = calcOutputBufSize();
245 // If current size changed, remap
Saurabh Shah912c9482014-02-07 14:01:04 -0800246 if(opBufSize == mMem.size()) {
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800247 ALOGE_IF(DEBUG_OVERLAY, "%s: same size %d", __FUNCTION__, opBufSize);
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700248 return true;
249 }
250
251 ALOGE_IF(DEBUG_OVERLAY, "%s: size changed - remapping", __FUNCTION__);
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700252
Saurabh Shah912c9482014-02-07 14:01:04 -0800253 if(!mMem.close()) {
254 ALOGE("%s error in closing prev rot mem", __FUNCTION__);
255 return false;
256 }
257
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800258 if(!open_i(numbufs, opBufSize)) {
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700259 ALOGE("%s Error could not open", __FUNCTION__);
260 return false;
261 }
Saurabh Shah912c9482014-02-07 14:01:04 -0800262
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700263 for (uint32_t i = 0; i < numbufs; ++i) {
Saurabh Shah912c9482014-02-07 14:01:04 -0800264 mMem.mRotOffset[i] = i * opBufSize;
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700265 }
Saurabh Shah912c9482014-02-07 14:01:04 -0800266
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700267 return true;
268}
269
270bool MdssRot::close() {
271 bool success = true;
Ken Zhangba48b012012-12-11 20:33:59 -0500272 if(mFd.valid() && (getSessId() != (uint32_t) MSMFB_NEW_REQUEST)) {
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700273 if(!mdp_wrapper::unsetOverlay(mFd.getFD(), getSessId())) {
274 ALOGE("MdssRot::close unsetOverlay failed, fd=%d sessId=%d",
275 mFd.getFD(), getSessId());
Ken Zhangba48b012012-12-11 20:33:59 -0500276 success = false;
277 }
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700278 }
279
280 if (!mFd.close()) {
281 ALOGE("Mdss Rot error closing fd");
282 success = false;
283 }
284 if (!mMem.close()) {
285 ALOGE("Mdss Rot error closing mem");
286 success = false;
287 }
288 reset();
289 return success;
290}
291
292void MdssRot::reset() {
293 ovutils::memset0(mRotInfo);
Raj Kamalbd3bdc62014-08-05 18:52:49 +0530294 ovutils::memset0(mLSRotInfo);
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700295 ovutils::memset0(mRotData);
296 mRotData.data.memory_id = -1;
297 mRotInfo.id = MSMFB_NEW_REQUEST;
Saurabh Shah912c9482014-02-07 14:01:04 -0800298 ovutils::memset0(mMem.mRotOffset);
299 mMem.mCurrIndex = 0;
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700300 mOrientation = utils::OVERLAY_TRANSFORM_0;
Saurabh Shahc46cf9d2014-07-02 15:22:34 -0700301 mDownscale = 0;
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700302}
303
304void MdssRot::dump() const {
305 ALOGE("== Dump MdssRot start ==");
306 mFd.dump();
Saurabh Shah912c9482014-02-07 14:01:04 -0800307 mMem.mem.dump();
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700308 mdp_wrapper::dump("mRotInfo", mRotInfo);
309 mdp_wrapper::dump("mRotData", mRotData);
310 ALOGE("== Dump MdssRot end ==");
311}
312
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800313uint32_t MdssRot::calcOutputBufSize() {
314 uint32_t opBufSize = 0;
315 ovutils::Whf destWhf(mRotInfo.dst_rect.w, mRotInfo.dst_rect.h,
316 mRotInfo.src.format); //mdss src and dst formats are same.
Sushil Chauhanb4d184f2013-02-11 16:13:10 -0800317
Sushil Chauhanbab187a2013-01-30 17:44:15 -0800318 if (mRotInfo.flags & ovutils::OV_MDSS_MDP_BWC_EN) {
Sushil Chauhan466766f2013-07-31 11:21:07 -0700319 opBufSize = calcCompressedBufSize(destWhf);
Sushil Chauhanbab187a2013-01-30 17:44:15 -0800320 } else {
321 opBufSize = Rotator::calcOutputBufSize(destWhf);
322 }
Sushil Chauhanb4d184f2013-02-11 16:13:10 -0800323
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800324 return opBufSize;
Sushil Chauhanfbffad72012-11-06 13:05:42 -0800325}
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800326
327void MdssRot::getDump(char *buf, size_t len) const {
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700328 ovutils::getDump(buf, len, "MdssRotCtrl", mRotInfo);
329 ovutils::getDump(buf, len, "MdssRotData", mRotData);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800330}
331
Sushil Chauhanbab187a2013-01-30 17:44:15 -0800332// Calculate the compressed o/p buffer size for BWC
Sushil Chauhan466766f2013-07-31 11:21:07 -0700333uint32_t MdssRot::calcCompressedBufSize(const ovutils::Whf& destWhf) {
Sushil Chauhanbab187a2013-01-30 17:44:15 -0800334 uint32_t bufSize = 0;
Saurabh Shah4b54c5b2014-05-01 18:36:51 -0700335 //Worst case alignments
Sushil Chauhan466766f2013-07-31 11:21:07 -0700336 int aWidth = ovutils::align(destWhf.w, 64);
337 int aHeight = ovutils::align(destWhf.h, 4);
Saurabh Shah4b54c5b2014-05-01 18:36:51 -0700338 /*
339 Format | RAU size (width x height)
340 ----------------------------------------------
341 ARGB | 32 pixel x 4 line
342 RGB888 | 32 pixel x 4 line
343 Y (Luma) | 64 pixel x 4 line
344 CRCB 420 | 32 pixel x 2 line
345 CRCB 422 H2V1 | 32 pixel x 4 line
346 CRCB 422 H1V2 | 64 pixel x 2 line
Sushil Chauhanbab187a2013-01-30 17:44:15 -0800347
Saurabh Shah4b54c5b2014-05-01 18:36:51 -0700348 Metadata requirements:-
349 1 byte meta data for every 8 RAUs
350 2 byte meta data per RAU
351 */
352
353 //These blocks attempt to allocate for the worst case in each of the
354 //respective format classes, yuv/rgb. The table above is for reference
355 if(utils::isYuv(destWhf.format)) {
356 int yRauCount = aWidth / 64; //Y
357 int cRauCount = aWidth / 32; //C
358 int yStride = (64 * 4 * yRauCount) + alignup(yRauCount, 8) / 8;
359 int cStride = ((32 * 2 * cRauCount) + alignup(cRauCount, 8) / 8) * 2;
360 int yStrideOffset = (aHeight / 4);
361 int cStrideOffset = (aHeight / 2);
362 bufSize = (yStride * yStrideOffset + cStride * cStrideOffset) +
363 (yRauCount * yStrideOffset * 2) +
364 (cRauCount * cStrideOffset * 2) * 2;
365 ALOGD_IF(DEBUG_MDSS_ROT, "%s:YUV Y RAU Count = %d C RAU Count = %d",
366 __FUNCTION__, yRauCount, cRauCount);
367 } else {
368 int rauCount = aWidth / 32;
369 //Single plane
370 int stride = (32 * 4 * rauCount) + alignup(rauCount, 8) / 8;
371 int strideOffset = (aHeight / 4);
372 bufSize = (stride * strideOffset * 4 /*bpp*/) +
373 (rauCount * strideOffset * 2);
374 ALOGD_IF(DEBUG_MDSS_ROT, "%s:RGB RAU count = %d", __FUNCTION__,
375 rauCount);
376 }
377
378 ALOGD_IF(DEBUG_MDSS_ROT, "%s: aligned width = %d, aligned height = %d "
379 "Buf Size = %d", __FUNCTION__, aWidth, aHeight, bufSize);
380
Sushil Chauhanbab187a2013-01-30 17:44:15 -0800381 return bufSize;
382}
383
Saurabh Shahc46cf9d2014-07-02 15:22:34 -0700384int MdssRot::getDownscaleFactor(const int& srcW, const int& srcH,
385 const int& dstW, const int& dstH, const uint32_t& mdpFormat,
386 const bool& isInterlaced) {
387 if(not srcW or not srcH or not dstW or not dstH or isInterlaced) return 0;
388
389 Dim crop(0, 0, srcW, srcH);
390 Dim adjCrop = getFormatAdjustedCrop(crop, mdpFormat,
391 false /*isInterlaced */);
392
393 uint32_t downscale = min((adjCrop.w / dstW), (adjCrop.h / dstH));
394 //Reduced to a power of 2
395 downscale = (uint32_t) powf(2.0f, floorf(log2f((float)downscale)));
396
397 if(downscale < 2 or downscale > 32) return 0;
398
399 //Allow only 1 line or pixel to be chopped off since the source needs to
400 //be aligned to downscale. Progressively try with smaller downscale to see
401 //if we can satisfy the threshold
402 //For YUV the loop shouldnt be needed, unless in exceptional cases
403 Dim dsAdjCrop = getDownscaleAdjustedCrop(adjCrop, downscale);
404 while(downscale > 2 and (adjCrop.w > dsAdjCrop.w or
405 adjCrop.h > dsAdjCrop.h)) {
406 downscale /= 2;
407 dsAdjCrop = getDownscaleAdjustedCrop(adjCrop, downscale);
408 }
409
410 if(not dsAdjCrop.w or not dsAdjCrop.h) return 0;
411 return downscale;
412}
413
414Dim MdssRot::getFormatAdjustedCrop(const Dim& crop,
415 const uint32_t& mdpFormat, const bool& isInterlaced) {
416 Dim adjCrop = crop;
417 if (isYuv(mdpFormat)) {
418 normalizeCrop(adjCrop.x, adjCrop.w);
419 normalizeCrop(adjCrop.y, adjCrop.h);
420 // For interlaced, crop.h should be 4-aligned
421 if (isInterlaced and (adjCrop.h % 4))
422 adjCrop.h = aligndown(adjCrop.h, 4);
423 }
424 return adjCrop;
425}
426
427Dim MdssRot::getDownscaleAdjustedCrop(const Dim& crop,
428 const uint32_t& downscale) {
429 uint32_t alignedSrcW = aligndown(crop.w, downscale * 2);
430 uint32_t alignedSrcH = aligndown(crop.h, downscale * 2);
431 return Dim(crop.x, crop.y, alignedSrcW, alignedSrcH);
432}
433
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700434} // namespace overlay