blob: 3ec0405f769c1778768808ac843fbb89c4e1209e [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);
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
Raj Kamal0cb57762013-12-31 09:14:26 +0530210 if(!mdp_wrapper::setOverlay(mFd.getFD(), mOVInfo)) {
211 ALOGE("MdpCtrl failed to setOverlay");
212 mdp_wrapper::dump("== Bad OVInfo is: ", mOVInfo);
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700213#ifdef USES_QSEED_SCALAR
Raj Kamal0cb57762013-12-31 09:14:26 +0530214 if(Overlay::getScalar()) {
215 Overlay::getScalar()->configAbort(mDpy);
Saurabh Shahfc2acbe2012-08-17 19:47:52 -0700216 }
Raj Kamal0cb57762013-12-31 09:14:26 +0530217#endif
218 return false;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700219 }
Saurabh Shahb121e142012-08-20 17:59:13 -0700220
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700221#ifdef USES_QSEED_SCALAR
222 if(Overlay::getScalar()) {
223 Overlay::getScalar()->configSet(mOVInfo, mDpy, mFd.getFD());
224 }
225#endif
226
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700227 return true;
228}
229
Naseer Ahmed29a26812012-06-14 00:56:20 -0700230bool MdpCtrl::get() {
231 mdp_overlay ov;
232 ov.id = mOVInfo.id;
233 if (!mdp_wrapper::getOverlay(mFd.getFD(), ov)) {
234 ALOGE("MdpCtrl get failed");
235 return false;
236 }
237 mOVInfo = ov;
238 return true;
239}
240
Saurabh Shahacf10202013-02-26 10:15:15 -0800241//Update src format based on rotator's destination format.
242void MdpCtrl::updateSrcFormat(const uint32_t& rotDestFmt) {
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800243 utils::Whf whf = getSrcWhf();
Saurabh Shahacf10202013-02-26 10:15:15 -0800244 whf.format = rotDestFmt;
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800245 setSrcWhf(whf);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700246}
247
248void MdpCtrl::dump() const {
249 ALOGE("== Dump MdpCtrl start ==");
Naseer Ahmed29a26812012-06-14 00:56:20 -0700250 mFd.dump();
251 mdp_wrapper::dump("mOVInfo", mOVInfo);
252 ALOGE("== Dump MdpCtrl end ==");
253}
254
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800255void MdpCtrl::getDump(char *buf, size_t len) {
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700256 ovutils::getDump(buf, len, "Ctrl", mOVInfo);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800257}
258
Naseer Ahmed29a26812012-06-14 00:56:20 -0700259void MdpData::dump() const {
260 ALOGE("== Dump MdpData start ==");
261 mFd.dump();
262 mdp_wrapper::dump("mOvData", mOvData);
263 ALOGE("== Dump MdpData end ==");
264}
265
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800266void MdpData::getDump(char *buf, size_t len) {
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700267 ovutils::getDump(buf, len, "Data", mOvData);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800268}
269
Naseer Ahmed29a26812012-06-14 00:56:20 -0700270void MdpCtrl3D::dump() const {
271 ALOGE("== Dump MdpCtrl start ==");
272 mFd.dump();
273 ALOGE("== Dump MdpCtrl end ==");
274}
275
Saurabh Shah5daeee52013-01-23 16:52:26 +0800276bool MdpCtrl::setVisualParams(const MetaData_t& data) {
Arun Kumar K.R7e5a1f82014-01-22 10:36:16 -0800277 ALOGD_IF(0, "In %s: data.operation = %d", __FUNCTION__, data.operation);
Saurabh Shah5daeee52013-01-23 16:52:26 +0800278#ifdef USES_POST_PROCESSING
Arun Kumar K.R7e5a1f82014-01-22 10:36:16 -0800279 bool needUpdate = false;
Saurabh Shah5daeee52013-01-23 16:52:26 +0800280 /* calculate the data */
281 if (data.operation & PP_PARAM_HSIC) {
282 if (mParams.params.pa_params.hue != data.hsicData.hue) {
283 ALOGD_IF(HSIC_SETTINGS_DEBUG,
284 "Hue has changed from %d to %d",
285 mParams.params.pa_params.hue,data.hsicData.hue);
286 needUpdate = true;
287 }
288
289 if (!isEqual(mParams.params.pa_params.sat,
290 data.hsicData.saturation)) {
291 ALOGD_IF(HSIC_SETTINGS_DEBUG,
292 "Saturation has changed from %f to %f",
293 mParams.params.pa_params.sat,
294 data.hsicData.saturation);
295 needUpdate = true;
296 }
297
298 if (mParams.params.pa_params.intensity != data.hsicData.intensity) {
299 ALOGD_IF(HSIC_SETTINGS_DEBUG,
300 "Intensity has changed from %d to %d",
301 mParams.params.pa_params.intensity,
302 data.hsicData.intensity);
303 needUpdate = true;
304 }
305
306 if (!isEqual(mParams.params.pa_params.contrast,
307 data.hsicData.contrast)) {
308 ALOGD_IF(HSIC_SETTINGS_DEBUG,
309 "Contrast has changed from %f to %f",
310 mParams.params.pa_params.contrast,
311 data.hsicData.contrast);
312 needUpdate = true;
313 }
314
315 if (needUpdate) {
316 mParams.params.pa_params.hue = data.hsicData.hue;
317 mParams.params.pa_params.sat = data.hsicData.saturation;
318 mParams.params.pa_params.intensity = data.hsicData.intensity;
319 mParams.params.pa_params.contrast = data.hsicData.contrast;
320 mParams.params.pa_params.ops = MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
321 mParams.operation |= PP_OP_PA;
322 }
323 }
324
325 if (data.operation & PP_PARAM_SHARP2) {
326 if (mParams.params.sharp_params.strength != data.Sharp2Data.strength) {
327 needUpdate = true;
328 }
329 if (mParams.params.sharp_params.edge_thr != data.Sharp2Data.edge_thr) {
330 needUpdate = true;
331 }
332 if (mParams.params.sharp_params.smooth_thr !=
333 data.Sharp2Data.smooth_thr) {
334 needUpdate = true;
335 }
336 if (mParams.params.sharp_params.noise_thr !=
337 data.Sharp2Data.noise_thr) {
338 needUpdate = true;
339 }
340
341 if (needUpdate) {
342 mParams.params.sharp_params.strength = data.Sharp2Data.strength;
343 mParams.params.sharp_params.edge_thr = data.Sharp2Data.edge_thr;
344 mParams.params.sharp_params.smooth_thr =
345 data.Sharp2Data.smooth_thr;
346 mParams.params.sharp_params.noise_thr = data.Sharp2Data.noise_thr;
347 mParams.params.sharp_params.ops =
348 MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
349 mParams.operation |= PP_OP_SHARP;
350 }
351 }
352
353 if (data.operation & PP_PARAM_IGC) {
354 if (mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data == NULL){
355 uint32_t *igcData
356 = (uint32_t *)malloc(2 * MAX_IGC_LUT_ENTRIES * sizeof(uint32_t));
357 if (!igcData) {
358 ALOGE("IGC storage allocated failed");
359 return false;
360 }
361 mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data = igcData;
362 mOVInfo.overlay_pp_cfg.igc_cfg.c2_data
363 = igcData + MAX_IGC_LUT_ENTRIES;
364 }
365
366 memcpy(mParams.params.igc_lut_params.c0,
367 data.igcData.c0, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
368 memcpy(mParams.params.igc_lut_params.c1,
369 data.igcData.c1, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
370 memcpy(mParams.params.igc_lut_params.c2,
371 data.igcData.c2, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
372
373 mParams.params.igc_lut_params.ops
374 = MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
375 mParams.operation |= PP_OP_IGC;
376 needUpdate = true;
377 }
378
379 if (data.operation & PP_PARAM_VID_INTFC) {
380 mParams.params.conv_params.interface =
381 (interface_type) data.video_interface;
382 needUpdate = true;
383 }
384
385 if (needUpdate) {
386 display_pp_compute_params(&mParams, &mOVInfo.overlay_pp_cfg);
Saurabh Shah5daeee52013-01-23 16:52:26 +0800387 }
388#endif
389 return true;
390}
391
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700392
393//// MdpData ////////////
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800394bool MdpData::init(const int& dpy) {
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700395 int fbnum = Overlay::getFbForDpy(dpy);
396 if( fbnum < 0 ) {
397 ALOGE("%s: Invalid FB for the display: %d",__FUNCTION__, dpy);
398 return false;
399 }
400
401 // FD init
402 if(!utils::openDev(mFd, fbnum, Res::fbPath, O_RDWR)){
403 ALOGE("Ctrl failed to init fbnum=%d", fbnum);
404 return false;
405 }
406 return true;
407}
408
Naseer Ahmed29a26812012-06-14 00:56:20 -0700409} // overlay