blob: 5a8b0678087732069faefbad213752e98e12af19 [file] [log] [blame]
Naseer Ahmed29a26812012-06-14 00:56:20 -07001/*
2* 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 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 Shahd18d88a2014-01-06 15:02:49 -080048bool MdpCtrl::init(const int& dpy) {
Saurabh Shahb8f58e22013-09-26 16:20:07 -070049 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);
Naseer Ahmedf48aef62012-07-20 09:05:53 -070067 mOVInfo.id = MSMFB_NEW_REQUEST;
Naseer Ahmedf48aef62012-07-20 09:05:53 -070068 mOrientation = utils::OVERLAY_TRANSFORM_0;
Saurabh Shahacf10202013-02-26 10:15:15 -080069 mDownscale = 0;
Saurabh Shahb8f58e22013-09-26 16:20:07 -070070 mDpy = 0;
Saurabh Shah5daeee52013-01-23 16:52:26 +080071#ifdef USES_POST_PROCESSING
Saurabh Shah5daeee52013-01-23 16:52:26 +080072 memset(&mParams, 0, sizeof(struct compute_params));
73 mParams.params.conv_params.order = hsic_order_hsc_i;
74 mParams.params.conv_params.interface = interface_rec601;
75 mParams.params.conv_params.cc_matrix[0][0] = 1;
76 mParams.params.conv_params.cc_matrix[1][1] = 1;
77 mParams.params.conv_params.cc_matrix[2][2] = 1;
78#endif
Naseer Ahmed29a26812012-06-14 00:56:20 -070079}
80
81bool MdpCtrl::close() {
Saurabh Shah8e1ae952012-08-15 12:15:14 -070082 bool result = true;
Saurabh Shah8e1ae952012-08-15 12:15:14 -070083 if(MSMFB_NEW_REQUEST != static_cast<int>(mOVInfo.id)) {
84 if(!mdp_wrapper::unsetOverlay(mFd.getFD(), mOVInfo.id)) {
85 ALOGE("MdpCtrl close error in unset");
86 result = false;
87 }
Naseer Ahmed29a26812012-06-14 00:56:20 -070088 }
Saurabh Shah5daeee52013-01-23 16:52:26 +080089#ifdef USES_POST_PROCESSING
90 /* free allocated memory in PP */
91 if (mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data)
92 free(mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data);
93#endif
Naseer Ahmed29a26812012-06-14 00:56:20 -070094 reset();
Saurabh Shahacf10202013-02-26 10:15:15 -080095
Naseer Ahmed29a26812012-06-14 00:56:20 -070096 if(!mFd.close()) {
Saurabh Shah8e1ae952012-08-15 12:15:14 -070097 result = false;
Naseer Ahmed29a26812012-06-14 00:56:20 -070098 }
Saurabh Shah8e1ae952012-08-15 12:15:14 -070099
100 return result;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700101}
102
Saurabh Shahacf10202013-02-26 10:15:15 -0800103void MdpCtrl::setSource(const utils::PipeArgs& args) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700104 setSrcWhf(args.whf);
105
106 //TODO These are hardcoded. Can be moved out of setSource.
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700107 mOVInfo.transp_mask = 0xffffffff;
108
109 //TODO These calls should ideally be a part of setPipeParams API
110 setFlags(args.mdpFlags);
111 setZ(args.zorder);
112 setIsFg(args.isFg);
Naseer Ahmed522ce662013-03-18 20:14:05 -0400113 setPlaneAlpha(args.planeAlpha);
114 setBlending(args.blending);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700115}
116
Saurabh Shahacf10202013-02-26 10:15:15 -0800117void MdpCtrl::setCrop(const utils::Dim& d) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700118 setSrcRectDim(d);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700119}
120
Sushil Chauhan897a9c32013-07-18 11:09:55 -0700121void MdpCtrl::setColor(const uint32_t color) {
122 mOVInfo.bg_color = color;
123}
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);
Sravan Kumar D.V.Na34dc852014-03-26 19:13:11 +0530197 // For interlaced, width must be multiple of 4 when rotated 90deg.
198 else if ((mOVInfo.flags & MDP_SOURCE_ROTATED_90) &&
199 (mOVInfo.src_rect.w % 4))
200 mOVInfo.src_rect.w = utils::aligndown(mOVInfo.src_rect.w, 4);
Saurabh Shahce416f02013-04-10 13:33:09 -0700201 }
Sushil Chauhan35fc68b2013-06-19 14:08:56 -0700202 } else {
203 if (mdpVersion >= MDSS_V5) {
204 // Check for 1-pixel down-scaling
205 if (mOVInfo.src_rect.w - mOVInfo.dst_rect.w == 1)
206 mOVInfo.src_rect.w -= 1;
207 if (mOVInfo.src_rect.h - mOVInfo.dst_rect.h == 1)
208 mOVInfo.src_rect.h -= 1;
209 }
Saurabh Shahb121e142012-08-20 17:59:13 -0700210 }
211
Sushil Chauhan35fc68b2013-06-19 14:08:56 -0700212 doDownscale();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700213 return true;
214}
215
Saurabh Shahacf10202013-02-26 10:15:15 -0800216//Update src format based on rotator's destination format.
217void MdpCtrl::updateSrcFormat(const uint32_t& rotDestFmt) {
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800218 utils::Whf whf = getSrcWhf();
Saurabh Shahacf10202013-02-26 10:15:15 -0800219 whf.format = rotDestFmt;
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800220 setSrcWhf(whf);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700221}
222
223void MdpCtrl::dump() const {
224 ALOGE("== Dump MdpCtrl start ==");
Naseer Ahmed29a26812012-06-14 00:56:20 -0700225 mFd.dump();
226 mdp_wrapper::dump("mOVInfo", mOVInfo);
227 ALOGE("== Dump MdpCtrl end ==");
228}
229
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800230void MdpCtrl::getDump(char *buf, size_t len) {
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700231 ovutils::getDump(buf, len, "Ctrl", mOVInfo);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800232}
233
Naseer Ahmed29a26812012-06-14 00:56:20 -0700234void MdpData::dump() const {
235 ALOGE("== Dump MdpData start ==");
236 mFd.dump();
237 mdp_wrapper::dump("mOvData", mOvData);
238 ALOGE("== Dump MdpData end ==");
239}
240
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800241void MdpData::getDump(char *buf, size_t len) {
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700242 ovutils::getDump(buf, len, "Data", mOvData);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800243}
244
Naseer Ahmed29a26812012-06-14 00:56:20 -0700245void MdpCtrl3D::dump() const {
246 ALOGE("== Dump MdpCtrl start ==");
247 mFd.dump();
248 ALOGE("== Dump MdpCtrl end ==");
249}
250
Saurabh Shah5daeee52013-01-23 16:52:26 +0800251bool MdpCtrl::setVisualParams(const MetaData_t& data) {
Arun Kumar K.R7e5a1f82014-01-22 10:36:16 -0800252 ALOGD_IF(0, "In %s: data.operation = %d", __FUNCTION__, data.operation);
Saurabh Shah5daeee52013-01-23 16:52:26 +0800253#ifdef USES_POST_PROCESSING
Arun Kumar K.R7e5a1f82014-01-22 10:36:16 -0800254 bool needUpdate = false;
Saurabh Shah5daeee52013-01-23 16:52:26 +0800255 /* calculate the data */
256 if (data.operation & PP_PARAM_HSIC) {
257 if (mParams.params.pa_params.hue != data.hsicData.hue) {
258 ALOGD_IF(HSIC_SETTINGS_DEBUG,
259 "Hue has changed from %d to %d",
260 mParams.params.pa_params.hue,data.hsicData.hue);
261 needUpdate = true;
262 }
263
264 if (!isEqual(mParams.params.pa_params.sat,
265 data.hsicData.saturation)) {
266 ALOGD_IF(HSIC_SETTINGS_DEBUG,
267 "Saturation has changed from %f to %f",
268 mParams.params.pa_params.sat,
269 data.hsicData.saturation);
270 needUpdate = true;
271 }
272
273 if (mParams.params.pa_params.intensity != data.hsicData.intensity) {
274 ALOGD_IF(HSIC_SETTINGS_DEBUG,
275 "Intensity has changed from %d to %d",
276 mParams.params.pa_params.intensity,
277 data.hsicData.intensity);
278 needUpdate = true;
279 }
280
281 if (!isEqual(mParams.params.pa_params.contrast,
282 data.hsicData.contrast)) {
283 ALOGD_IF(HSIC_SETTINGS_DEBUG,
284 "Contrast has changed from %f to %f",
285 mParams.params.pa_params.contrast,
286 data.hsicData.contrast);
287 needUpdate = true;
288 }
289
290 if (needUpdate) {
291 mParams.params.pa_params.hue = data.hsicData.hue;
292 mParams.params.pa_params.sat = data.hsicData.saturation;
293 mParams.params.pa_params.intensity = data.hsicData.intensity;
294 mParams.params.pa_params.contrast = data.hsicData.contrast;
295 mParams.params.pa_params.ops = MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
296 mParams.operation |= PP_OP_PA;
297 }
298 }
299
300 if (data.operation & PP_PARAM_SHARP2) {
301 if (mParams.params.sharp_params.strength != data.Sharp2Data.strength) {
302 needUpdate = true;
303 }
304 if (mParams.params.sharp_params.edge_thr != data.Sharp2Data.edge_thr) {
305 needUpdate = true;
306 }
307 if (mParams.params.sharp_params.smooth_thr !=
308 data.Sharp2Data.smooth_thr) {
309 needUpdate = true;
310 }
311 if (mParams.params.sharp_params.noise_thr !=
312 data.Sharp2Data.noise_thr) {
313 needUpdate = true;
314 }
315
316 if (needUpdate) {
317 mParams.params.sharp_params.strength = data.Sharp2Data.strength;
318 mParams.params.sharp_params.edge_thr = data.Sharp2Data.edge_thr;
319 mParams.params.sharp_params.smooth_thr =
320 data.Sharp2Data.smooth_thr;
321 mParams.params.sharp_params.noise_thr = data.Sharp2Data.noise_thr;
322 mParams.params.sharp_params.ops =
323 MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
324 mParams.operation |= PP_OP_SHARP;
325 }
326 }
327
328 if (data.operation & PP_PARAM_IGC) {
329 if (mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data == NULL){
330 uint32_t *igcData
331 = (uint32_t *)malloc(2 * MAX_IGC_LUT_ENTRIES * sizeof(uint32_t));
332 if (!igcData) {
333 ALOGE("IGC storage allocated failed");
334 return false;
335 }
336 mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data = igcData;
337 mOVInfo.overlay_pp_cfg.igc_cfg.c2_data
338 = igcData + MAX_IGC_LUT_ENTRIES;
339 }
340
341 memcpy(mParams.params.igc_lut_params.c0,
342 data.igcData.c0, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
343 memcpy(mParams.params.igc_lut_params.c1,
344 data.igcData.c1, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
345 memcpy(mParams.params.igc_lut_params.c2,
346 data.igcData.c2, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
347
348 mParams.params.igc_lut_params.ops
349 = MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
350 mParams.operation |= PP_OP_IGC;
351 needUpdate = true;
352 }
353
354 if (data.operation & PP_PARAM_VID_INTFC) {
355 mParams.params.conv_params.interface =
356 (interface_type) data.video_interface;
357 needUpdate = true;
358 }
359
360 if (needUpdate) {
361 display_pp_compute_params(&mParams, &mOVInfo.overlay_pp_cfg);
Saurabh Shah5daeee52013-01-23 16:52:26 +0800362 }
363#endif
364 return true;
365}
366
Saurabh Shaha36be922013-12-16 18:18:39 -0800367bool MdpCtrl::validateAndSet(MdpCtrl* mdpCtrlArray[], const int& count,
368 const int& fbFd) {
369 mdp_overlay* ovArray[count];
370 memset(&ovArray, 0, sizeof(ovArray));
371
372 for(int i = 0; i < count; i++) {
373 ovArray[i] = &mdpCtrlArray[i]->mOVInfo;
374 }
375
376 struct mdp_overlay_list list;
377 memset(&list, 0, sizeof(struct mdp_overlay_list));
378 list.num_overlays = count;
379 list.overlay_list = ovArray;
380
381#ifdef USES_QSEED_SCALAR
382 Scale *scalar = Overlay::getScalar();
383 if(scalar) {
384 scalar->applyScale(&list);
385 }
386#endif
387
388 if(!mdp_wrapper::validateAndSet(fbFd, list)) {
389 if(list.processed_overlays < list.num_overlays) {
390 mdp_wrapper::dump("Bad ov dump: ",
391 *list.overlay_list[list.processed_overlays]);
392 }
393 return false;
394 }
395
396 return true;
397}
398
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700399
400//// MdpData ////////////
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800401bool MdpData::init(const int& dpy) {
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700402 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