blob: 006e05d660d106ce6bb515e905a2e4622932fee4 [file] [log] [blame]
Naseer Ahmed29a26812012-06-14 00:56:20 -07001/*
2* Copyright (C) 2008 The Android Open Source Project
Raj kamal23f69b22012-11-17 00:20:55 +05303* Copyright (c) 2010-2013, The Linux Foundation. All rights reserved.
Naseer Ahmed29a26812012-06-14 00:56:20 -07004*
5* Licensed under the Apache License, Version 2.0 (the "License");
6* you may not use this file except in compliance with the License.
7* You may obtain a copy of the License at
8*
9* http://www.apache.org/licenses/LICENSE-2.0
10*
11* Unless required by applicable law or agreed to in writing, software
12* distributed under the License is distributed on an "AS IS" BASIS,
13* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14* See the License for the specific language governing permissions and
15* limitations under the License.
16*/
17
Saurabh Shahbd2d0832013-04-04 14:33:08 -070018#include <math.h>
Raj kamal23f69b22012-11-17 00:20:55 +053019#include <mdp_version.h>
Naseer Ahmed29a26812012-06-14 00:56:20 -070020#include "overlayUtils.h"
21#include "overlayMdp.h"
Saurabh Shah5daeee52013-01-23 16:52:26 +080022#include "mdp_version.h"
Saurabh Shahb8f58e22013-09-26 16:20:07 -070023#include <overlay.h>
24
25#ifdef USES_QSEED_SCALAR
26#include <scale/scale.h>
27using namespace scale;
28#endif
Saurabh Shah5daeee52013-01-23 16:52:26 +080029
30#define HSIC_SETTINGS_DEBUG 0
31
Saurabh Shahbd2d0832013-04-04 14:33:08 -070032using namespace qdutils;
33
Saurabh Shah5daeee52013-01-23 16:52:26 +080034static inline bool isEqual(float f1, float f2) {
35 return ((int)(f1*100) == (int)(f2*100)) ? true : false;
36}
Naseer Ahmed29a26812012-06-14 00:56:20 -070037
Arun Kumar K.Re1ffd3e2013-06-13 12:14:11 -070038#ifdef ANDROID_JELLYBEAN_MR1
39//Since this is unavailable on Android 4.2.2, defining it in terms of base 10
Saurabh Shahbd2d0832013-04-04 14:33:08 -070040static inline float log2f(const float& x) {
41 return log(x) / log(2);
42}
Arun Kumar K.Re1ffd3e2013-06-13 12:14:11 -070043#endif
Saurabh Shahbd2d0832013-04-04 14:33:08 -070044
Naseer Ahmed29a26812012-06-14 00:56:20 -070045namespace ovutils = overlay::utils;
46namespace overlay {
Saurabh Shahb121e142012-08-20 17:59:13 -070047
Saurabh Shahb8f58e22013-09-26 16:20:07 -070048bool MdpCtrl::init(uint32_t dpy) {
49 int fbnum = Overlay::getFbForDpy(dpy);
50 if( fbnum < 0 ) {
51 ALOGE("%s: Invalid FB for the display: %d",__FUNCTION__, dpy);
52 return false;
53 }
54
Naseer Ahmedf48aef62012-07-20 09:05:53 -070055 // FD init
Naseer Ahmed29a26812012-06-14 00:56:20 -070056 if(!utils::openDev(mFd, fbnum,
Naseer Ahmedf48aef62012-07-20 09:05:53 -070057 Res::fbPath, O_RDWR)){
58 ALOGE("Ctrl failed to init fbnum=%d", fbnum);
Naseer Ahmed29a26812012-06-14 00:56:20 -070059 return false;
60 }
Saurabh Shahb8f58e22013-09-26 16:20:07 -070061 mDpy = dpy;
Naseer Ahmed29a26812012-06-14 00:56:20 -070062 return true;
63}
64
65void MdpCtrl::reset() {
66 utils::memset0(mOVInfo);
67 utils::memset0(mLkgo);
Naseer Ahmedf48aef62012-07-20 09:05:53 -070068 mOVInfo.id = MSMFB_NEW_REQUEST;
69 mLkgo.id = MSMFB_NEW_REQUEST;
70 mOrientation = utils::OVERLAY_TRANSFORM_0;
Saurabh Shahacf10202013-02-26 10:15:15 -080071 mDownscale = 0;
Saurabh Shahb8f58e22013-09-26 16:20:07 -070072 mDpy = 0;
Saurabh Shah5daeee52013-01-23 16:52:26 +080073#ifdef USES_POST_PROCESSING
74 mPPChanged = false;
75 memset(&mParams, 0, sizeof(struct compute_params));
76 mParams.params.conv_params.order = hsic_order_hsc_i;
77 mParams.params.conv_params.interface = interface_rec601;
78 mParams.params.conv_params.cc_matrix[0][0] = 1;
79 mParams.params.conv_params.cc_matrix[1][1] = 1;
80 mParams.params.conv_params.cc_matrix[2][2] = 1;
81#endif
Naseer Ahmed29a26812012-06-14 00:56:20 -070082}
83
84bool MdpCtrl::close() {
Saurabh Shah8e1ae952012-08-15 12:15:14 -070085 bool result = true;
Saurabh Shah8e1ae952012-08-15 12:15:14 -070086 if(MSMFB_NEW_REQUEST != static_cast<int>(mOVInfo.id)) {
87 if(!mdp_wrapper::unsetOverlay(mFd.getFD(), mOVInfo.id)) {
88 ALOGE("MdpCtrl close error in unset");
89 result = false;
90 }
Naseer Ahmed29a26812012-06-14 00:56:20 -070091 }
Saurabh Shah5daeee52013-01-23 16:52:26 +080092#ifdef USES_POST_PROCESSING
93 /* free allocated memory in PP */
94 if (mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data)
95 free(mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data);
96#endif
Naseer Ahmed29a26812012-06-14 00:56:20 -070097 reset();
Saurabh Shahacf10202013-02-26 10:15:15 -080098
Naseer Ahmed29a26812012-06-14 00:56:20 -070099 if(!mFd.close()) {
Saurabh Shah8e1ae952012-08-15 12:15:14 -0700100 result = false;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700101 }
Saurabh Shah8e1ae952012-08-15 12:15:14 -0700102
103 return result;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700104}
105
Saurabh Shahacf10202013-02-26 10:15:15 -0800106void MdpCtrl::setSource(const utils::PipeArgs& args) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700107 setSrcWhf(args.whf);
108
109 //TODO These are hardcoded. Can be moved out of setSource.
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700110 mOVInfo.transp_mask = 0xffffffff;
111
112 //TODO These calls should ideally be a part of setPipeParams API
113 setFlags(args.mdpFlags);
114 setZ(args.zorder);
115 setIsFg(args.isFg);
Naseer Ahmed522ce662013-03-18 20:14:05 -0400116 setPlaneAlpha(args.planeAlpha);
117 setBlending(args.blending);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700118}
119
Saurabh Shahacf10202013-02-26 10:15:15 -0800120void MdpCtrl::setCrop(const utils::Dim& d) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700121 setSrcRectDim(d);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700122}
123
Sushil Chauhan897a9c32013-07-18 11:09:55 -0700124void MdpCtrl::setColor(const uint32_t color) {
125 mOVInfo.bg_color = color;
126}
127
Saurabh Shahacf10202013-02-26 10:15:15 -0800128void MdpCtrl::setPosition(const overlay::utils::Dim& d) {
129 setDstRectDim(d);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700130}
131
Saurabh Shahacf10202013-02-26 10:15:15 -0800132void MdpCtrl::setTransform(const utils::eTransform& orient) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700133 int rot = utils::getMdpOrient(orient);
134 setUserData(rot);
Saurabh Shaha73738d2012-08-09 18:15:18 -0700135 mOrientation = static_cast<utils::eTransform>(rot);
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800136}
137
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700138void MdpCtrl::doTransform() {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700139 setRotationFlags();
Saurabh Shahacf10202013-02-26 10:15:15 -0800140 utils::Whf whf = getSrcWhf();
141 utils::Dim dim = getSrcRectDim();
142 utils::preRotateSource(mOrientation, whf, dim);
143 setSrcWhf(whf);
144 setSrcRectDim(dim);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700145}
146
Saurabh Shahacf10202013-02-26 10:15:15 -0800147void MdpCtrl::doDownscale() {
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700148 int mdpVersion = MDPVersion::getInstance().getMDPVersion();
149 if(mdpVersion < MDSS_V5) {
150 mOVInfo.src_rect.x >>= mDownscale;
151 mOVInfo.src_rect.y >>= mDownscale;
152 mOVInfo.src_rect.w >>= mDownscale;
153 mOVInfo.src_rect.h >>= mDownscale;
154 } else if(MDPVersion::getInstance().supportsDecimation()) {
155 //Decimation + MDP Downscale
156 mOVInfo.horz_deci = 0;
157 mOVInfo.vert_deci = 0;
158 int minHorDeci = 0;
159 if(mOVInfo.src_rect.w > 2048) {
160 //If the client sends us something > what a layer mixer supports
161 //then it means it doesn't want to use split-pipe but wants us to
162 //decimate. A minimum decimation of 2 will ensure that the width is
163 //always within layer mixer limits.
164 minHorDeci = 2;
165 }
166
Saurabh Shah1a03d482013-05-29 13:44:20 -0700167 float horDscale = 0.0f;
168 float verDscale = 0.0f;
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700169
Saurabh Shah1a03d482013-05-29 13:44:20 -0700170 utils::getDecimationFactor(mOVInfo.src_rect.w, mOVInfo.src_rect.h,
171 mOVInfo.dst_rect.w, mOVInfo.dst_rect.h, horDscale, verDscale);
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700172
173 if(horDscale < minHorDeci)
174 horDscale = minHorDeci;
175
176 if((int)horDscale)
177 mOVInfo.horz_deci = (int)log2f(horDscale);
178
179 if((int)verDscale)
180 mOVInfo.vert_deci = (int)log2f(verDscale);
181 }
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800182}
183
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700184bool MdpCtrl::set() {
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700185 int mdpVersion = MDPVersion::getInstance().getMDPVersion();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700186 //deferred calcs, so APIs could be called in any order.
Saurabh Shahacf10202013-02-26 10:15:15 -0800187 doTransform();
Saurabh Shahb121e142012-08-20 17:59:13 -0700188 utils::Whf whf = getSrcWhf();
189 if(utils::isYuv(whf.format)) {
Sushil Chauhan1cac8152013-05-08 15:53:51 -0700190 utils::normalizeCrop(mOVInfo.src_rect.x, mOVInfo.src_rect.w);
191 utils::normalizeCrop(mOVInfo.src_rect.y, mOVInfo.src_rect.h);
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700192 if(mdpVersion < MDSS_V5) {
Saurabh Shahce416f02013-04-10 13:33:09 -0700193 utils::even_floor(mOVInfo.dst_rect.w);
194 utils::even_floor(mOVInfo.dst_rect.h);
Sushil Chauhan5491c8a2013-05-24 10:15:30 -0700195 } else if (mOVInfo.flags & MDP_DEINTERLACE) {
196 // For interlaced, crop.h should be 4-aligned
197 if (!(mOVInfo.flags & MDP_SOURCE_ROTATED_90) &&
198 (mOVInfo.src_rect.h % 4))
199 mOVInfo.src_rect.h = utils::aligndown(mOVInfo.src_rect.h, 4);
Saurabh Shahce416f02013-04-10 13:33:09 -0700200 }
Sushil Chauhan35fc68b2013-06-19 14:08:56 -0700201 } else {
202 if (mdpVersion >= MDSS_V5) {
203 // Check for 1-pixel down-scaling
204 if (mOVInfo.src_rect.w - mOVInfo.dst_rect.w == 1)
205 mOVInfo.src_rect.w -= 1;
206 if (mOVInfo.src_rect.h - mOVInfo.dst_rect.h == 1)
207 mOVInfo.src_rect.h -= 1;
208 }
Saurabh Shahb121e142012-08-20 17:59:13 -0700209 }
210
Sushil Chauhan35fc68b2013-06-19 14:08:56 -0700211 doDownscale();
212
Saurabh Shah7445d4b2013-12-05 17:24:45 -0800213 if(this->ovChanged()) {
Saurabh Shahfc2acbe2012-08-17 19:47:52 -0700214 if(!mdp_wrapper::setOverlay(mFd.getFD(), mOVInfo)) {
215 ALOGE("MdpCtrl failed to setOverlay, restoring last known "
216 "good ov info");
217 mdp_wrapper::dump("== Bad OVInfo is: ", mOVInfo);
218 mdp_wrapper::dump("== Last good known OVInfo is: ", mLkgo);
219 this->restore();
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700220#ifdef USES_QSEED_SCALAR
221 if(Overlay::getScalar()) {
222 Overlay::getScalar()->configAbort(mDpy);
223 }
224#endif
Saurabh Shahfc2acbe2012-08-17 19:47:52 -0700225 return false;
226 }
227 this->save();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700228 }
Saurabh Shahb121e142012-08-20 17:59:13 -0700229
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700230#ifdef USES_QSEED_SCALAR
231 if(Overlay::getScalar()) {
232 Overlay::getScalar()->configSet(mOVInfo, mDpy, mFd.getFD());
233 }
234#endif
235
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700236 return true;
237}
238
Naseer Ahmed29a26812012-06-14 00:56:20 -0700239bool MdpCtrl::get() {
240 mdp_overlay ov;
241 ov.id = mOVInfo.id;
242 if (!mdp_wrapper::getOverlay(mFd.getFD(), ov)) {
243 ALOGE("MdpCtrl get failed");
244 return false;
245 }
246 mOVInfo = ov;
247 return true;
248}
249
Saurabh Shahacf10202013-02-26 10:15:15 -0800250//Update src format based on rotator's destination format.
251void MdpCtrl::updateSrcFormat(const uint32_t& rotDestFmt) {
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800252 utils::Whf whf = getSrcWhf();
Saurabh Shahacf10202013-02-26 10:15:15 -0800253 whf.format = rotDestFmt;
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800254 setSrcWhf(whf);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700255}
256
257void MdpCtrl::dump() const {
258 ALOGE("== Dump MdpCtrl start ==");
Naseer Ahmed29a26812012-06-14 00:56:20 -0700259 mFd.dump();
260 mdp_wrapper::dump("mOVInfo", mOVInfo);
261 ALOGE("== Dump MdpCtrl end ==");
262}
263
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800264void MdpCtrl::getDump(char *buf, size_t len) {
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700265 ovutils::getDump(buf, len, "Ctrl", mOVInfo);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800266}
267
Naseer Ahmed29a26812012-06-14 00:56:20 -0700268void MdpData::dump() const {
269 ALOGE("== Dump MdpData start ==");
270 mFd.dump();
271 mdp_wrapper::dump("mOvData", mOvData);
272 ALOGE("== Dump MdpData end ==");
273}
274
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800275void MdpData::getDump(char *buf, size_t len) {
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700276 ovutils::getDump(buf, len, "Data", mOvData);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800277}
278
Naseer Ahmed29a26812012-06-14 00:56:20 -0700279void MdpCtrl3D::dump() const {
280 ALOGE("== Dump MdpCtrl start ==");
281 mFd.dump();
282 ALOGE("== Dump MdpCtrl end ==");
283}
284
Saurabh Shah5daeee52013-01-23 16:52:26 +0800285bool MdpCtrl::setVisualParams(const MetaData_t& data) {
286 bool needUpdate = false;
287#ifdef USES_POST_PROCESSING
288 /* calculate the data */
289 if (data.operation & PP_PARAM_HSIC) {
290 if (mParams.params.pa_params.hue != data.hsicData.hue) {
291 ALOGD_IF(HSIC_SETTINGS_DEBUG,
292 "Hue has changed from %d to %d",
293 mParams.params.pa_params.hue,data.hsicData.hue);
294 needUpdate = true;
295 }
296
297 if (!isEqual(mParams.params.pa_params.sat,
298 data.hsicData.saturation)) {
299 ALOGD_IF(HSIC_SETTINGS_DEBUG,
300 "Saturation has changed from %f to %f",
301 mParams.params.pa_params.sat,
302 data.hsicData.saturation);
303 needUpdate = true;
304 }
305
306 if (mParams.params.pa_params.intensity != data.hsicData.intensity) {
307 ALOGD_IF(HSIC_SETTINGS_DEBUG,
308 "Intensity has changed from %d to %d",
309 mParams.params.pa_params.intensity,
310 data.hsicData.intensity);
311 needUpdate = true;
312 }
313
314 if (!isEqual(mParams.params.pa_params.contrast,
315 data.hsicData.contrast)) {
316 ALOGD_IF(HSIC_SETTINGS_DEBUG,
317 "Contrast has changed from %f to %f",
318 mParams.params.pa_params.contrast,
319 data.hsicData.contrast);
320 needUpdate = true;
321 }
322
323 if (needUpdate) {
324 mParams.params.pa_params.hue = data.hsicData.hue;
325 mParams.params.pa_params.sat = data.hsicData.saturation;
326 mParams.params.pa_params.intensity = data.hsicData.intensity;
327 mParams.params.pa_params.contrast = data.hsicData.contrast;
328 mParams.params.pa_params.ops = MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
329 mParams.operation |= PP_OP_PA;
330 }
331 }
332
333 if (data.operation & PP_PARAM_SHARP2) {
334 if (mParams.params.sharp_params.strength != data.Sharp2Data.strength) {
335 needUpdate = true;
336 }
337 if (mParams.params.sharp_params.edge_thr != data.Sharp2Data.edge_thr) {
338 needUpdate = true;
339 }
340 if (mParams.params.sharp_params.smooth_thr !=
341 data.Sharp2Data.smooth_thr) {
342 needUpdate = true;
343 }
344 if (mParams.params.sharp_params.noise_thr !=
345 data.Sharp2Data.noise_thr) {
346 needUpdate = true;
347 }
348
349 if (needUpdate) {
350 mParams.params.sharp_params.strength = data.Sharp2Data.strength;
351 mParams.params.sharp_params.edge_thr = data.Sharp2Data.edge_thr;
352 mParams.params.sharp_params.smooth_thr =
353 data.Sharp2Data.smooth_thr;
354 mParams.params.sharp_params.noise_thr = data.Sharp2Data.noise_thr;
355 mParams.params.sharp_params.ops =
356 MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
357 mParams.operation |= PP_OP_SHARP;
358 }
359 }
360
361 if (data.operation & PP_PARAM_IGC) {
362 if (mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data == NULL){
363 uint32_t *igcData
364 = (uint32_t *)malloc(2 * MAX_IGC_LUT_ENTRIES * sizeof(uint32_t));
365 if (!igcData) {
366 ALOGE("IGC storage allocated failed");
367 return false;
368 }
369 mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data = igcData;
370 mOVInfo.overlay_pp_cfg.igc_cfg.c2_data
371 = igcData + MAX_IGC_LUT_ENTRIES;
372 }
373
374 memcpy(mParams.params.igc_lut_params.c0,
375 data.igcData.c0, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
376 memcpy(mParams.params.igc_lut_params.c1,
377 data.igcData.c1, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
378 memcpy(mParams.params.igc_lut_params.c2,
379 data.igcData.c2, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
380
381 mParams.params.igc_lut_params.ops
382 = MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
383 mParams.operation |= PP_OP_IGC;
384 needUpdate = true;
385 }
386
387 if (data.operation & PP_PARAM_VID_INTFC) {
388 mParams.params.conv_params.interface =
389 (interface_type) data.video_interface;
390 needUpdate = true;
391 }
392
393 if (needUpdate) {
394 display_pp_compute_params(&mParams, &mOVInfo.overlay_pp_cfg);
395 mPPChanged = true;
396 }
397#endif
398 return true;
399}
400
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700401
402//// MdpData ////////////
403bool MdpData::init(uint32_t dpy) {
404 int fbnum = Overlay::getFbForDpy(dpy);
405 if( fbnum < 0 ) {
406 ALOGE("%s: Invalid FB for the display: %d",__FUNCTION__, dpy);
407 return false;
408 }
409
410 // FD init
411 if(!utils::openDev(mFd, fbnum, Res::fbPath, O_RDWR)){
412 ALOGE("Ctrl failed to init fbnum=%d", fbnum);
413 return false;
414 }
415 return true;
416}
417
Naseer Ahmed29a26812012-06-14 00:56:20 -0700418} // overlay