blob: 87e134a9e096ecf9b60afe10b7bd2df2fce056d4 [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
Saurabh Shahacf10202013-02-26 10:15:15 -0800132void MdssRot::setFlags(const utils::eMdpFlags& flags) {
Sushil Chauhan6dcffbf2013-05-13 19:11:11 -0700133 mRotInfo.flags = flags;
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700134}
135
Saurabh Shahacf10202013-02-26 10:15:15 -0800136void MdssRot::setTransform(const utils::eTransform& rot)
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700137{
Saurabh Shah78ad4952013-04-05 09:38:01 -0700138 // reset rotation flags to avoid stale orientation values
139 mRotInfo.flags &= ~MDSS_ROT_MASK;
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700140 int flags = utils::getMdpOrient(rot);
141 if (flags != -1)
142 setRotations(flags);
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700143 mOrientation = static_cast<utils::eTransform>(flags);
144 ALOGE_IF(DEBUG_OVERLAY, "%s: rot=%d", __FUNCTION__, flags);
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800145}
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700146
Saurabh Shahacf10202013-02-26 10:15:15 -0800147void MdssRot::doTransform() {
Sushil Chauhan6dcffbf2013-05-13 19:11:11 -0700148 mRotInfo.flags |= mOrientation;
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700149 if(mOrientation & utils::OVERLAY_TRANSFORM_ROT_90)
150 utils::swap(mRotInfo.dst_rect.w, mRotInfo.dst_rect.h);
151}
152
153bool MdssRot::commit() {
Saurabh Shahc46cf9d2014-07-02 15:22:34 -0700154 Dim adjCrop(mRotInfo.src_rect.x,mRotInfo.src_rect.y,
155 mRotInfo.src_rect.w,mRotInfo.src_rect.h);
156 adjCrop = getFormatAdjustedCrop(adjCrop, mRotInfo.src.format,
157 mRotInfo.flags & utils::OV_MDP_DEINTERLACE);
158 adjCrop = getDownscaleAdjustedCrop(adjCrop, mDownscale);
159
160 mRotInfo.src_rect.x = adjCrop.x;
161 mRotInfo.src_rect.y = adjCrop.y;
162 mRotInfo.src_rect.w = adjCrop.w;
163 mRotInfo.src_rect.h = adjCrop.h;
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -0700164
165 mRotInfo.dst_rect.x = 0;
166 mRotInfo.dst_rect.y = 0;
Saurabh Shahc46cf9d2014-07-02 15:22:34 -0700167 mRotInfo.dst_rect.w = mDownscale ?
168 mRotInfo.src_rect.w / mDownscale : mRotInfo.src_rect.w;
169 mRotInfo.dst_rect.h = mDownscale ?
170 mRotInfo.src_rect.h / mDownscale : mRotInfo.src_rect.h;
171 //Clear for next round
172 mDownscale = 0;
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -0700173
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700174 doTransform();
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -0700175
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700176 mRotInfo.flags |= MDSS_MDP_ROT_ONLY;
Saurabh Shahacf10202013-02-26 10:15:15 -0800177 mEnabled = true;
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700178 if(!overlay::mdp_wrapper::setOverlay(mFd.getFD(), mRotInfo)) {
179 ALOGE("MdssRot commit failed!");
180 dump();
Saurabh Shahacf10202013-02-26 10:15:15 -0800181 return (mEnabled = false);
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700182 }
183 mRotData.id = mRotInfo.id;
184 return true;
185}
186
187bool MdssRot::queueBuffer(int fd, uint32_t offset) {
Raj Kamalbd3bdc62014-08-05 18:52:49 +0530188 if(enabled() and (not isRotCached(fd,offset))) {
189 int prev_fd = getSrcMemId();
190 uint32_t prev_offset = getSrcOffset();
191
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700192 mRotData.data.memory_id = fd;
193 mRotData.data.offset = offset;
194
Saurabh Shah912c9482014-02-07 14:01:04 -0800195 if(false == remap(RotMem::ROT_NUM_BUFS)) {
196 ALOGE("%s Remap failed, not queuing", __FUNCTION__);
197 return false;
198 }
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700199
200 mRotData.dst_data.offset =
Saurabh Shah912c9482014-02-07 14:01:04 -0800201 mMem.mRotOffset[mMem.mCurrIndex];
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700202
203 if(!overlay::mdp_wrapper::play(mFd.getFD(), mRotData)) {
204 ALOGE("MdssRot play failed!");
205 dump();
Raj Kamalbd3bdc62014-08-05 18:52:49 +0530206 mRotData.data.memory_id = prev_fd;
207 mRotData.data.offset = prev_offset;
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700208 return false;
209 }
Raj Kamalbd3bdc62014-08-05 18:52:49 +0530210 save();
211 mMem.mCurrIndex =
212 (mMem.mCurrIndex + 1) % mMem.mem.numBufs();
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700213 }
214 return true;
215}
216
217bool MdssRot::open_i(uint32_t numbufs, uint32_t bufsz)
218{
219 OvMem mem;
220 OVASSERT(MAP_FAILED == mem.addr(), "MAP failed in open_i");
Sushil Chauhanfaae0422012-10-23 23:48:04 -0700221 bool isSecure = mRotInfo.flags & utils::OV_MDP_SECURE_OVERLAY_SESSION;
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700222
Sushil Chauhanfaae0422012-10-23 23:48:04 -0700223 if(!mem.open(numbufs, bufsz, isSecure)){
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700224 ALOGE("%s: Failed to open", __func__);
225 mem.close();
226 return false;
227 }
228
229 OVASSERT(MAP_FAILED != mem.addr(), "MAP failed");
230 OVASSERT(mem.getFD() != -1, "getFd is -1");
231
232 mRotData.dst_data.memory_id = mem.getFD();
233 mRotData.dst_data.offset = 0;
Saurabh Shah912c9482014-02-07 14:01:04 -0800234 mMem.mem = mem;
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700235 return true;
236}
237
238bool MdssRot::remap(uint32_t numbufs) {
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800239 // Calculate the size based on rotator's dst format, w and h.
240 uint32_t opBufSize = calcOutputBufSize();
241 // If current size changed, remap
Saurabh Shah912c9482014-02-07 14:01:04 -0800242 if(opBufSize == mMem.size()) {
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800243 ALOGE_IF(DEBUG_OVERLAY, "%s: same size %d", __FUNCTION__, opBufSize);
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700244 return true;
245 }
246
247 ALOGE_IF(DEBUG_OVERLAY, "%s: size changed - remapping", __FUNCTION__);
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700248
Saurabh Shah912c9482014-02-07 14:01:04 -0800249 if(!mMem.close()) {
250 ALOGE("%s error in closing prev rot mem", __FUNCTION__);
251 return false;
252 }
253
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800254 if(!open_i(numbufs, opBufSize)) {
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700255 ALOGE("%s Error could not open", __FUNCTION__);
256 return false;
257 }
Saurabh Shah912c9482014-02-07 14:01:04 -0800258
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700259 for (uint32_t i = 0; i < numbufs; ++i) {
Saurabh Shah912c9482014-02-07 14:01:04 -0800260 mMem.mRotOffset[i] = i * opBufSize;
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700261 }
Saurabh Shah912c9482014-02-07 14:01:04 -0800262
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700263 return true;
264}
265
266bool MdssRot::close() {
267 bool success = true;
Ken Zhangba48b012012-12-11 20:33:59 -0500268 if(mFd.valid() && (getSessId() != (uint32_t) MSMFB_NEW_REQUEST)) {
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700269 if(!mdp_wrapper::unsetOverlay(mFd.getFD(), getSessId())) {
270 ALOGE("MdssRot::close unsetOverlay failed, fd=%d sessId=%d",
271 mFd.getFD(), getSessId());
Ken Zhangba48b012012-12-11 20:33:59 -0500272 success = false;
273 }
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700274 }
275
276 if (!mFd.close()) {
277 ALOGE("Mdss Rot error closing fd");
278 success = false;
279 }
280 if (!mMem.close()) {
281 ALOGE("Mdss Rot error closing mem");
282 success = false;
283 }
284 reset();
285 return success;
286}
287
288void MdssRot::reset() {
289 ovutils::memset0(mRotInfo);
Raj Kamalbd3bdc62014-08-05 18:52:49 +0530290 ovutils::memset0(mLSRotInfo);
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700291 ovutils::memset0(mRotData);
292 mRotData.data.memory_id = -1;
293 mRotInfo.id = MSMFB_NEW_REQUEST;
Saurabh Shah912c9482014-02-07 14:01:04 -0800294 ovutils::memset0(mMem.mRotOffset);
295 mMem.mCurrIndex = 0;
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700296 mOrientation = utils::OVERLAY_TRANSFORM_0;
Saurabh Shahc46cf9d2014-07-02 15:22:34 -0700297 mDownscale = 0;
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700298}
299
300void MdssRot::dump() const {
301 ALOGE("== Dump MdssRot start ==");
302 mFd.dump();
Saurabh Shah912c9482014-02-07 14:01:04 -0800303 mMem.mem.dump();
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700304 mdp_wrapper::dump("mRotInfo", mRotInfo);
305 mdp_wrapper::dump("mRotData", mRotData);
306 ALOGE("== Dump MdssRot end ==");
307}
308
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800309uint32_t MdssRot::calcOutputBufSize() {
310 uint32_t opBufSize = 0;
311 ovutils::Whf destWhf(mRotInfo.dst_rect.w, mRotInfo.dst_rect.h,
312 mRotInfo.src.format); //mdss src and dst formats are same.
Sushil Chauhanb4d184f2013-02-11 16:13:10 -0800313
Sushil Chauhanbab187a2013-01-30 17:44:15 -0800314 if (mRotInfo.flags & ovutils::OV_MDSS_MDP_BWC_EN) {
Sushil Chauhan466766f2013-07-31 11:21:07 -0700315 opBufSize = calcCompressedBufSize(destWhf);
Sushil Chauhanbab187a2013-01-30 17:44:15 -0800316 } else {
317 opBufSize = Rotator::calcOutputBufSize(destWhf);
318 }
Sushil Chauhanb4d184f2013-02-11 16:13:10 -0800319
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800320 return opBufSize;
Sushil Chauhanfbffad72012-11-06 13:05:42 -0800321}
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800322
323void MdssRot::getDump(char *buf, size_t len) const {
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700324 ovutils::getDump(buf, len, "MdssRotCtrl", mRotInfo);
325 ovutils::getDump(buf, len, "MdssRotData", mRotData);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800326}
327
Sushil Chauhanbab187a2013-01-30 17:44:15 -0800328// Calculate the compressed o/p buffer size for BWC
Sushil Chauhan466766f2013-07-31 11:21:07 -0700329uint32_t MdssRot::calcCompressedBufSize(const ovutils::Whf& destWhf) {
Sushil Chauhanbab187a2013-01-30 17:44:15 -0800330 uint32_t bufSize = 0;
Saurabh Shah4b54c5b2014-05-01 18:36:51 -0700331 //Worst case alignments
Sushil Chauhan466766f2013-07-31 11:21:07 -0700332 int aWidth = ovutils::align(destWhf.w, 64);
333 int aHeight = ovutils::align(destWhf.h, 4);
Saurabh Shah4b54c5b2014-05-01 18:36:51 -0700334 /*
335 Format | RAU size (width x height)
336 ----------------------------------------------
337 ARGB | 32 pixel x 4 line
338 RGB888 | 32 pixel x 4 line
339 Y (Luma) | 64 pixel x 4 line
340 CRCB 420 | 32 pixel x 2 line
341 CRCB 422 H2V1 | 32 pixel x 4 line
342 CRCB 422 H1V2 | 64 pixel x 2 line
Sushil Chauhanbab187a2013-01-30 17:44:15 -0800343
Saurabh Shah4b54c5b2014-05-01 18:36:51 -0700344 Metadata requirements:-
345 1 byte meta data for every 8 RAUs
346 2 byte meta data per RAU
347 */
348
349 //These blocks attempt to allocate for the worst case in each of the
350 //respective format classes, yuv/rgb. The table above is for reference
351 if(utils::isYuv(destWhf.format)) {
352 int yRauCount = aWidth / 64; //Y
353 int cRauCount = aWidth / 32; //C
354 int yStride = (64 * 4 * yRauCount) + alignup(yRauCount, 8) / 8;
355 int cStride = ((32 * 2 * cRauCount) + alignup(cRauCount, 8) / 8) * 2;
356 int yStrideOffset = (aHeight / 4);
357 int cStrideOffset = (aHeight / 2);
358 bufSize = (yStride * yStrideOffset + cStride * cStrideOffset) +
359 (yRauCount * yStrideOffset * 2) +
360 (cRauCount * cStrideOffset * 2) * 2;
361 ALOGD_IF(DEBUG_MDSS_ROT, "%s:YUV Y RAU Count = %d C RAU Count = %d",
362 __FUNCTION__, yRauCount, cRauCount);
363 } else {
364 int rauCount = aWidth / 32;
365 //Single plane
366 int stride = (32 * 4 * rauCount) + alignup(rauCount, 8) / 8;
367 int strideOffset = (aHeight / 4);
368 bufSize = (stride * strideOffset * 4 /*bpp*/) +
369 (rauCount * strideOffset * 2);
370 ALOGD_IF(DEBUG_MDSS_ROT, "%s:RGB RAU count = %d", __FUNCTION__,
371 rauCount);
372 }
373
374 ALOGD_IF(DEBUG_MDSS_ROT, "%s: aligned width = %d, aligned height = %d "
375 "Buf Size = %d", __FUNCTION__, aWidth, aHeight, bufSize);
376
Sushil Chauhanbab187a2013-01-30 17:44:15 -0800377 return bufSize;
378}
379
Saurabh Shahc46cf9d2014-07-02 15:22:34 -0700380int MdssRot::getDownscaleFactor(const int& srcW, const int& srcH,
381 const int& dstW, const int& dstH, const uint32_t& mdpFormat,
382 const bool& isInterlaced) {
383 if(not srcW or not srcH or not dstW or not dstH or isInterlaced) return 0;
384
385 Dim crop(0, 0, srcW, srcH);
386 Dim adjCrop = getFormatAdjustedCrop(crop, mdpFormat,
387 false /*isInterlaced */);
388
389 uint32_t downscale = min((adjCrop.w / dstW), (adjCrop.h / dstH));
390 //Reduced to a power of 2
391 downscale = (uint32_t) powf(2.0f, floorf(log2f((float)downscale)));
392
393 if(downscale < 2 or downscale > 32) return 0;
394
395 //Allow only 1 line or pixel to be chopped off since the source needs to
396 //be aligned to downscale. Progressively try with smaller downscale to see
397 //if we can satisfy the threshold
398 //For YUV the loop shouldnt be needed, unless in exceptional cases
399 Dim dsAdjCrop = getDownscaleAdjustedCrop(adjCrop, downscale);
400 while(downscale > 2 and (adjCrop.w > dsAdjCrop.w or
401 adjCrop.h > dsAdjCrop.h)) {
402 downscale /= 2;
403 dsAdjCrop = getDownscaleAdjustedCrop(adjCrop, downscale);
404 }
405
406 if(not dsAdjCrop.w or not dsAdjCrop.h) return 0;
407 return downscale;
408}
409
410Dim MdssRot::getFormatAdjustedCrop(const Dim& crop,
411 const uint32_t& mdpFormat, const bool& isInterlaced) {
412 Dim adjCrop = crop;
413 if (isYuv(mdpFormat)) {
414 normalizeCrop(adjCrop.x, adjCrop.w);
415 normalizeCrop(adjCrop.y, adjCrop.h);
416 // For interlaced, crop.h should be 4-aligned
417 if (isInterlaced and (adjCrop.h % 4))
418 adjCrop.h = aligndown(adjCrop.h, 4);
419 }
420 return adjCrop;
421}
422
423Dim MdssRot::getDownscaleAdjustedCrop(const Dim& crop,
424 const uint32_t& downscale) {
425 uint32_t alignedSrcW = aligndown(crop.w, downscale * 2);
426 uint32_t alignedSrcH = aligndown(crop.h, downscale * 2);
427 return Dim(crop.x, crop.y, alignedSrcW, alignedSrcH);
428}
429
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700430} // namespace overlay