blob: b4058bda4ba43733c344c17cafd339d04e62367f [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 Shahdf0be752013-05-23 14:40:00 -070072 mForceSet = false;
Saurabh Shahb8f58e22013-09-26 16:20:07 -070073 mDpy = 0;
Saurabh Shah5daeee52013-01-23 16:52:26 +080074#ifdef USES_POST_PROCESSING
75 mPPChanged = false;
76 memset(&mParams, 0, sizeof(struct compute_params));
77 mParams.params.conv_params.order = hsic_order_hsc_i;
78 mParams.params.conv_params.interface = interface_rec601;
79 mParams.params.conv_params.cc_matrix[0][0] = 1;
80 mParams.params.conv_params.cc_matrix[1][1] = 1;
81 mParams.params.conv_params.cc_matrix[2][2] = 1;
82#endif
Naseer Ahmed29a26812012-06-14 00:56:20 -070083}
84
85bool MdpCtrl::close() {
Saurabh Shah8e1ae952012-08-15 12:15:14 -070086 bool result = true;
Saurabh Shah8e1ae952012-08-15 12:15:14 -070087 if(MSMFB_NEW_REQUEST != static_cast<int>(mOVInfo.id)) {
88 if(!mdp_wrapper::unsetOverlay(mFd.getFD(), mOVInfo.id)) {
89 ALOGE("MdpCtrl close error in unset");
90 result = false;
91 }
Naseer Ahmed29a26812012-06-14 00:56:20 -070092 }
Saurabh Shah5daeee52013-01-23 16:52:26 +080093#ifdef USES_POST_PROCESSING
94 /* free allocated memory in PP */
95 if (mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data)
96 free(mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data);
97#endif
Naseer Ahmed29a26812012-06-14 00:56:20 -070098 reset();
Saurabh Shahacf10202013-02-26 10:15:15 -080099
Naseer Ahmed29a26812012-06-14 00:56:20 -0700100 if(!mFd.close()) {
Saurabh Shah8e1ae952012-08-15 12:15:14 -0700101 result = false;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700102 }
Saurabh Shah8e1ae952012-08-15 12:15:14 -0700103
104 return result;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700105}
106
Saurabh Shahacf10202013-02-26 10:15:15 -0800107void MdpCtrl::setSource(const utils::PipeArgs& args) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700108 setSrcWhf(args.whf);
109
110 //TODO These are hardcoded. Can be moved out of setSource.
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700111 mOVInfo.transp_mask = 0xffffffff;
112
113 //TODO These calls should ideally be a part of setPipeParams API
114 setFlags(args.mdpFlags);
115 setZ(args.zorder);
116 setIsFg(args.isFg);
Naseer Ahmed522ce662013-03-18 20:14:05 -0400117 setPlaneAlpha(args.planeAlpha);
118 setBlending(args.blending);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700119}
120
Saurabh Shahacf10202013-02-26 10:15:15 -0800121void MdpCtrl::setCrop(const utils::Dim& d) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700122 setSrcRectDim(d);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700123}
124
Saurabh Shahacf10202013-02-26 10:15:15 -0800125void MdpCtrl::setPosition(const overlay::utils::Dim& d) {
126 setDstRectDim(d);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700127}
128
Saurabh Shahacf10202013-02-26 10:15:15 -0800129void MdpCtrl::setTransform(const utils::eTransform& orient) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700130 int rot = utils::getMdpOrient(orient);
131 setUserData(rot);
Saurabh Shaha73738d2012-08-09 18:15:18 -0700132 mOrientation = static_cast<utils::eTransform>(rot);
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800133}
134
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700135void MdpCtrl::doTransform() {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700136 setRotationFlags();
Saurabh Shahacf10202013-02-26 10:15:15 -0800137 utils::Whf whf = getSrcWhf();
138 utils::Dim dim = getSrcRectDim();
139 utils::preRotateSource(mOrientation, whf, dim);
140 setSrcWhf(whf);
141 setSrcRectDim(dim);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700142}
143
Saurabh Shahacf10202013-02-26 10:15:15 -0800144void MdpCtrl::doDownscale() {
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700145 int mdpVersion = MDPVersion::getInstance().getMDPVersion();
146 if(mdpVersion < MDSS_V5) {
147 mOVInfo.src_rect.x >>= mDownscale;
148 mOVInfo.src_rect.y >>= mDownscale;
149 mOVInfo.src_rect.w >>= mDownscale;
150 mOVInfo.src_rect.h >>= mDownscale;
151 } else if(MDPVersion::getInstance().supportsDecimation()) {
152 //Decimation + MDP Downscale
153 mOVInfo.horz_deci = 0;
154 mOVInfo.vert_deci = 0;
155 int minHorDeci = 0;
156 if(mOVInfo.src_rect.w > 2048) {
157 //If the client sends us something > what a layer mixer supports
158 //then it means it doesn't want to use split-pipe but wants us to
159 //decimate. A minimum decimation of 2 will ensure that the width is
160 //always within layer mixer limits.
161 minHorDeci = 2;
162 }
163
Saurabh Shah1a03d482013-05-29 13:44:20 -0700164 float horDscale = 0.0f;
165 float verDscale = 0.0f;
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700166
Saurabh Shah1a03d482013-05-29 13:44:20 -0700167 utils::getDecimationFactor(mOVInfo.src_rect.w, mOVInfo.src_rect.h,
168 mOVInfo.dst_rect.w, mOVInfo.dst_rect.h, horDscale, verDscale);
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700169
170 if(horDscale < minHorDeci)
171 horDscale = minHorDeci;
172
173 if((int)horDscale)
174 mOVInfo.horz_deci = (int)log2f(horDscale);
175
176 if((int)verDscale)
177 mOVInfo.vert_deci = (int)log2f(verDscale);
178 }
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800179}
180
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700181bool MdpCtrl::set() {
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700182 int mdpVersion = MDPVersion::getInstance().getMDPVersion();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700183 //deferred calcs, so APIs could be called in any order.
Saurabh Shahacf10202013-02-26 10:15:15 -0800184 doTransform();
Saurabh Shahb121e142012-08-20 17:59:13 -0700185 utils::Whf whf = getSrcWhf();
186 if(utils::isYuv(whf.format)) {
Sushil Chauhan1cac8152013-05-08 15:53:51 -0700187 utils::normalizeCrop(mOVInfo.src_rect.x, mOVInfo.src_rect.w);
188 utils::normalizeCrop(mOVInfo.src_rect.y, mOVInfo.src_rect.h);
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700189 if(mdpVersion < MDSS_V5) {
Saurabh Shahce416f02013-04-10 13:33:09 -0700190 utils::even_floor(mOVInfo.dst_rect.w);
191 utils::even_floor(mOVInfo.dst_rect.h);
Sushil Chauhan5491c8a2013-05-24 10:15:30 -0700192 } else if (mOVInfo.flags & MDP_DEINTERLACE) {
193 // For interlaced, crop.h should be 4-aligned
194 if (!(mOVInfo.flags & MDP_SOURCE_ROTATED_90) &&
195 (mOVInfo.src_rect.h % 4))
196 mOVInfo.src_rect.h = utils::aligndown(mOVInfo.src_rect.h, 4);
Saurabh Shahce416f02013-04-10 13:33:09 -0700197 }
Sushil Chauhan35fc68b2013-06-19 14:08:56 -0700198 } else {
199 if (mdpVersion >= MDSS_V5) {
200 // Check for 1-pixel down-scaling
201 if (mOVInfo.src_rect.w - mOVInfo.dst_rect.w == 1)
202 mOVInfo.src_rect.w -= 1;
203 if (mOVInfo.src_rect.h - mOVInfo.dst_rect.h == 1)
204 mOVInfo.src_rect.h -= 1;
205 }
Saurabh Shahb121e142012-08-20 17:59:13 -0700206 }
207
Sushil Chauhan35fc68b2013-06-19 14:08:56 -0700208 doDownscale();
209
Saurabh Shahdf0be752013-05-23 14:40:00 -0700210 if(this->ovChanged() || mForceSet) {
211 mForceSet = false;
Saurabh Shahfc2acbe2012-08-17 19:47:52 -0700212 if(!mdp_wrapper::setOverlay(mFd.getFD(), mOVInfo)) {
213 ALOGE("MdpCtrl failed to setOverlay, restoring last known "
214 "good ov info");
215 mdp_wrapper::dump("== Bad OVInfo is: ", mOVInfo);
216 mdp_wrapper::dump("== Last good known OVInfo is: ", mLkgo);
217 this->restore();
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700218#ifdef USES_QSEED_SCALAR
219 if(Overlay::getScalar()) {
220 Overlay::getScalar()->configAbort(mDpy);
221 }
222#endif
Saurabh Shahfc2acbe2012-08-17 19:47:52 -0700223 return false;
224 }
225 this->save();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700226 }
Saurabh Shahb121e142012-08-20 17:59:13 -0700227
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700228#ifdef USES_QSEED_SCALAR
229 if(Overlay::getScalar()) {
230 Overlay::getScalar()->configSet(mOVInfo, mDpy, mFd.getFD());
231 }
232#endif
233
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700234 return true;
235}
236
Naseer Ahmed29a26812012-06-14 00:56:20 -0700237bool MdpCtrl::get() {
238 mdp_overlay ov;
239 ov.id = mOVInfo.id;
240 if (!mdp_wrapper::getOverlay(mFd.getFD(), ov)) {
241 ALOGE("MdpCtrl get failed");
242 return false;
243 }
244 mOVInfo = ov;
245 return true;
246}
247
Saurabh Shahacf10202013-02-26 10:15:15 -0800248//Update src format based on rotator's destination format.
249void MdpCtrl::updateSrcFormat(const uint32_t& rotDestFmt) {
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800250 utils::Whf whf = getSrcWhf();
Saurabh Shahacf10202013-02-26 10:15:15 -0800251 whf.format = rotDestFmt;
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800252 setSrcWhf(whf);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700253}
254
255void MdpCtrl::dump() const {
256 ALOGE("== Dump MdpCtrl start ==");
Naseer Ahmed29a26812012-06-14 00:56:20 -0700257 mFd.dump();
258 mdp_wrapper::dump("mOVInfo", mOVInfo);
259 ALOGE("== Dump MdpCtrl end ==");
260}
261
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800262void MdpCtrl::getDump(char *buf, size_t len) {
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700263 ovutils::getDump(buf, len, "Ctrl", mOVInfo);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800264}
265
Naseer Ahmed29a26812012-06-14 00:56:20 -0700266void MdpData::dump() const {
267 ALOGE("== Dump MdpData start ==");
268 mFd.dump();
269 mdp_wrapper::dump("mOvData", mOvData);
270 ALOGE("== Dump MdpData end ==");
271}
272
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800273void MdpData::getDump(char *buf, size_t len) {
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700274 ovutils::getDump(buf, len, "Data", mOvData);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800275}
276
Naseer Ahmed29a26812012-06-14 00:56:20 -0700277void MdpCtrl3D::dump() const {
278 ALOGE("== Dump MdpCtrl start ==");
279 mFd.dump();
280 ALOGE("== Dump MdpCtrl end ==");
281}
282
Saurabh Shah5daeee52013-01-23 16:52:26 +0800283bool MdpCtrl::setVisualParams(const MetaData_t& data) {
284 bool needUpdate = false;
285#ifdef USES_POST_PROCESSING
286 /* calculate the data */
287 if (data.operation & PP_PARAM_HSIC) {
288 if (mParams.params.pa_params.hue != data.hsicData.hue) {
289 ALOGD_IF(HSIC_SETTINGS_DEBUG,
290 "Hue has changed from %d to %d",
291 mParams.params.pa_params.hue,data.hsicData.hue);
292 needUpdate = true;
293 }
294
295 if (!isEqual(mParams.params.pa_params.sat,
296 data.hsicData.saturation)) {
297 ALOGD_IF(HSIC_SETTINGS_DEBUG,
298 "Saturation has changed from %f to %f",
299 mParams.params.pa_params.sat,
300 data.hsicData.saturation);
301 needUpdate = true;
302 }
303
304 if (mParams.params.pa_params.intensity != data.hsicData.intensity) {
305 ALOGD_IF(HSIC_SETTINGS_DEBUG,
306 "Intensity has changed from %d to %d",
307 mParams.params.pa_params.intensity,
308 data.hsicData.intensity);
309 needUpdate = true;
310 }
311
312 if (!isEqual(mParams.params.pa_params.contrast,
313 data.hsicData.contrast)) {
314 ALOGD_IF(HSIC_SETTINGS_DEBUG,
315 "Contrast has changed from %f to %f",
316 mParams.params.pa_params.contrast,
317 data.hsicData.contrast);
318 needUpdate = true;
319 }
320
321 if (needUpdate) {
322 mParams.params.pa_params.hue = data.hsicData.hue;
323 mParams.params.pa_params.sat = data.hsicData.saturation;
324 mParams.params.pa_params.intensity = data.hsicData.intensity;
325 mParams.params.pa_params.contrast = data.hsicData.contrast;
326 mParams.params.pa_params.ops = MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
327 mParams.operation |= PP_OP_PA;
328 }
329 }
330
331 if (data.operation & PP_PARAM_SHARP2) {
332 if (mParams.params.sharp_params.strength != data.Sharp2Data.strength) {
333 needUpdate = true;
334 }
335 if (mParams.params.sharp_params.edge_thr != data.Sharp2Data.edge_thr) {
336 needUpdate = true;
337 }
338 if (mParams.params.sharp_params.smooth_thr !=
339 data.Sharp2Data.smooth_thr) {
340 needUpdate = true;
341 }
342 if (mParams.params.sharp_params.noise_thr !=
343 data.Sharp2Data.noise_thr) {
344 needUpdate = true;
345 }
346
347 if (needUpdate) {
348 mParams.params.sharp_params.strength = data.Sharp2Data.strength;
349 mParams.params.sharp_params.edge_thr = data.Sharp2Data.edge_thr;
350 mParams.params.sharp_params.smooth_thr =
351 data.Sharp2Data.smooth_thr;
352 mParams.params.sharp_params.noise_thr = data.Sharp2Data.noise_thr;
353 mParams.params.sharp_params.ops =
354 MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
355 mParams.operation |= PP_OP_SHARP;
356 }
357 }
358
359 if (data.operation & PP_PARAM_IGC) {
360 if (mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data == NULL){
361 uint32_t *igcData
362 = (uint32_t *)malloc(2 * MAX_IGC_LUT_ENTRIES * sizeof(uint32_t));
363 if (!igcData) {
364 ALOGE("IGC storage allocated failed");
365 return false;
366 }
367 mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data = igcData;
368 mOVInfo.overlay_pp_cfg.igc_cfg.c2_data
369 = igcData + MAX_IGC_LUT_ENTRIES;
370 }
371
372 memcpy(mParams.params.igc_lut_params.c0,
373 data.igcData.c0, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
374 memcpy(mParams.params.igc_lut_params.c1,
375 data.igcData.c1, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
376 memcpy(mParams.params.igc_lut_params.c2,
377 data.igcData.c2, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
378
379 mParams.params.igc_lut_params.ops
380 = MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
381 mParams.operation |= PP_OP_IGC;
382 needUpdate = true;
383 }
384
385 if (data.operation & PP_PARAM_VID_INTFC) {
386 mParams.params.conv_params.interface =
387 (interface_type) data.video_interface;
388 needUpdate = true;
389 }
390
391 if (needUpdate) {
392 display_pp_compute_params(&mParams, &mOVInfo.overlay_pp_cfg);
393 mPPChanged = true;
394 }
395#endif
396 return true;
397}
398
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700399
400//// MdpData ////////////
401bool MdpData::init(uint32_t dpy) {
402 int fbnum = Overlay::getFbForDpy(dpy);
403 if( fbnum < 0 ) {
404 ALOGE("%s: Invalid FB for the display: %d",__FUNCTION__, dpy);
405 return false;
406 }
407
408 // FD init
409 if(!utils::openDev(mFd, fbnum, Res::fbPath, O_RDWR)){
410 ALOGE("Ctrl failed to init fbnum=%d", fbnum);
411 return false;
412 }
413 return true;
414}
415
Naseer Ahmed29a26812012-06-14 00:56:20 -0700416} // overlay