blob: 3af9eaa3d9d1a7b699f03d444efd10e78c8d86dd [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
Naseer Ahmed29a26812012-06-14 00:56:20 -070038namespace ovutils = overlay::utils;
39namespace overlay {
Saurabh Shahb121e142012-08-20 17:59:13 -070040
Saurabh Shahd18d88a2014-01-06 15:02:49 -080041bool MdpCtrl::init(const int& dpy) {
Saurabh Shahb8f58e22013-09-26 16:20:07 -070042 int fbnum = Overlay::getFbForDpy(dpy);
43 if( fbnum < 0 ) {
44 ALOGE("%s: Invalid FB for the display: %d",__FUNCTION__, dpy);
45 return false;
46 }
47
Naseer Ahmedf48aef62012-07-20 09:05:53 -070048 // FD init
Naseer Ahmed29a26812012-06-14 00:56:20 -070049 if(!utils::openDev(mFd, fbnum,
Naseer Ahmedf48aef62012-07-20 09:05:53 -070050 Res::fbPath, O_RDWR)){
51 ALOGE("Ctrl failed to init fbnum=%d", fbnum);
Naseer Ahmed29a26812012-06-14 00:56:20 -070052 return false;
53 }
Saurabh Shahb8f58e22013-09-26 16:20:07 -070054 mDpy = dpy;
Naseer Ahmed29a26812012-06-14 00:56:20 -070055 return true;
56}
57
58void MdpCtrl::reset() {
59 utils::memset0(mOVInfo);
Naseer Ahmedf48aef62012-07-20 09:05:53 -070060 mOVInfo.id = MSMFB_NEW_REQUEST;
Naseer Ahmedf48aef62012-07-20 09:05:53 -070061 mOrientation = utils::OVERLAY_TRANSFORM_0;
Saurabh Shahacf10202013-02-26 10:15:15 -080062 mDownscale = 0;
Saurabh Shahb8f58e22013-09-26 16:20:07 -070063 mDpy = 0;
Saurabh Shah5daeee52013-01-23 16:52:26 +080064#ifdef USES_POST_PROCESSING
Saurabh Shah5daeee52013-01-23 16:52:26 +080065 memset(&mParams, 0, sizeof(struct compute_params));
66 mParams.params.conv_params.order = hsic_order_hsc_i;
67 mParams.params.conv_params.interface = interface_rec601;
68 mParams.params.conv_params.cc_matrix[0][0] = 1;
69 mParams.params.conv_params.cc_matrix[1][1] = 1;
70 mParams.params.conv_params.cc_matrix[2][2] = 1;
71#endif
Naseer Ahmed29a26812012-06-14 00:56:20 -070072}
73
74bool MdpCtrl::close() {
Saurabh Shah8e1ae952012-08-15 12:15:14 -070075 bool result = true;
Saurabh Shah8e1ae952012-08-15 12:15:14 -070076 if(MSMFB_NEW_REQUEST != static_cast<int>(mOVInfo.id)) {
77 if(!mdp_wrapper::unsetOverlay(mFd.getFD(), mOVInfo.id)) {
78 ALOGE("MdpCtrl close error in unset");
79 result = false;
80 }
Naseer Ahmed29a26812012-06-14 00:56:20 -070081 }
Saurabh Shah5daeee52013-01-23 16:52:26 +080082#ifdef USES_POST_PROCESSING
83 /* free allocated memory in PP */
84 if (mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data)
85 free(mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data);
86#endif
Naseer Ahmed29a26812012-06-14 00:56:20 -070087 reset();
Saurabh Shahacf10202013-02-26 10:15:15 -080088
Naseer Ahmed29a26812012-06-14 00:56:20 -070089 if(!mFd.close()) {
Saurabh Shah8e1ae952012-08-15 12:15:14 -070090 result = false;
Naseer Ahmed29a26812012-06-14 00:56:20 -070091 }
Saurabh Shah8e1ae952012-08-15 12:15:14 -070092
93 return result;
Naseer Ahmed29a26812012-06-14 00:56:20 -070094}
95
Saurabh Shahacf10202013-02-26 10:15:15 -080096void MdpCtrl::setSource(const utils::PipeArgs& args) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -070097 setSrcWhf(args.whf);
98
99 //TODO These are hardcoded. Can be moved out of setSource.
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700100 mOVInfo.transp_mask = 0xffffffff;
101
102 //TODO These calls should ideally be a part of setPipeParams API
103 setFlags(args.mdpFlags);
104 setZ(args.zorder);
105 setIsFg(args.isFg);
Naseer Ahmed522ce662013-03-18 20:14:05 -0400106 setPlaneAlpha(args.planeAlpha);
107 setBlending(args.blending);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700108}
109
Saurabh Shahacf10202013-02-26 10:15:15 -0800110void MdpCtrl::setCrop(const utils::Dim& d) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700111 setSrcRectDim(d);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700112}
113
Sushil Chauhan897a9c32013-07-18 11:09:55 -0700114void MdpCtrl::setColor(const uint32_t color) {
115 mOVInfo.bg_color = color;
116}
117
Saurabh Shahacf10202013-02-26 10:15:15 -0800118void MdpCtrl::setPosition(const overlay::utils::Dim& d) {
119 setDstRectDim(d);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700120}
121
Saurabh Shahacf10202013-02-26 10:15:15 -0800122void MdpCtrl::setTransform(const utils::eTransform& orient) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700123 int rot = utils::getMdpOrient(orient);
124 setUserData(rot);
Saurabh Shaha73738d2012-08-09 18:15:18 -0700125 mOrientation = static_cast<utils::eTransform>(rot);
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800126}
127
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700128void MdpCtrl::doTransform() {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700129 setRotationFlags();
Saurabh Shahacf10202013-02-26 10:15:15 -0800130 utils::Whf whf = getSrcWhf();
131 utils::Dim dim = getSrcRectDim();
132 utils::preRotateSource(mOrientation, whf, dim);
133 setSrcWhf(whf);
134 setSrcRectDim(dim);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700135}
136
Saurabh Shahacf10202013-02-26 10:15:15 -0800137void MdpCtrl::doDownscale() {
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700138 int mdpVersion = MDPVersion::getInstance().getMDPVersion();
139 if(mdpVersion < MDSS_V5) {
140 mOVInfo.src_rect.x >>= mDownscale;
141 mOVInfo.src_rect.y >>= mDownscale;
142 mOVInfo.src_rect.w >>= mDownscale;
143 mOVInfo.src_rect.h >>= mDownscale;
144 } else if(MDPVersion::getInstance().supportsDecimation()) {
145 //Decimation + MDP Downscale
146 mOVInfo.horz_deci = 0;
147 mOVInfo.vert_deci = 0;
148 int minHorDeci = 0;
149 if(mOVInfo.src_rect.w > 2048) {
150 //If the client sends us something > what a layer mixer supports
151 //then it means it doesn't want to use split-pipe but wants us to
152 //decimate. A minimum decimation of 2 will ensure that the width is
153 //always within layer mixer limits.
154 minHorDeci = 2;
155 }
156
Saurabh Shah1a03d482013-05-29 13:44:20 -0700157 float horDscale = 0.0f;
158 float verDscale = 0.0f;
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700159
Saurabh Shah1a03d482013-05-29 13:44:20 -0700160 utils::getDecimationFactor(mOVInfo.src_rect.w, mOVInfo.src_rect.h,
161 mOVInfo.dst_rect.w, mOVInfo.dst_rect.h, horDscale, verDscale);
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700162
163 if(horDscale < minHorDeci)
164 horDscale = minHorDeci;
165
166 if((int)horDscale)
167 mOVInfo.horz_deci = (int)log2f(horDscale);
168
169 if((int)verDscale)
170 mOVInfo.vert_deci = (int)log2f(verDscale);
171 }
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800172}
173
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700174bool MdpCtrl::set() {
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700175 int mdpVersion = MDPVersion::getInstance().getMDPVersion();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700176 //deferred calcs, so APIs could be called in any order.
Saurabh Shahacf10202013-02-26 10:15:15 -0800177 doTransform();
Saurabh Shahb121e142012-08-20 17:59:13 -0700178 utils::Whf whf = getSrcWhf();
179 if(utils::isYuv(whf.format)) {
Sushil Chauhan1cac8152013-05-08 15:53:51 -0700180 utils::normalizeCrop(mOVInfo.src_rect.x, mOVInfo.src_rect.w);
181 utils::normalizeCrop(mOVInfo.src_rect.y, mOVInfo.src_rect.h);
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700182 if(mdpVersion < MDSS_V5) {
Saurabh Shahce416f02013-04-10 13:33:09 -0700183 utils::even_floor(mOVInfo.dst_rect.w);
184 utils::even_floor(mOVInfo.dst_rect.h);
Sushil Chauhan5491c8a2013-05-24 10:15:30 -0700185 } else if (mOVInfo.flags & MDP_DEINTERLACE) {
186 // For interlaced, crop.h should be 4-aligned
187 if (!(mOVInfo.flags & MDP_SOURCE_ROTATED_90) &&
188 (mOVInfo.src_rect.h % 4))
189 mOVInfo.src_rect.h = utils::aligndown(mOVInfo.src_rect.h, 4);
Sravan Kumar D.V.Na34dc852014-03-26 19:13:11 +0530190 // For interlaced, width must be multiple of 4 when rotated 90deg.
191 else if ((mOVInfo.flags & MDP_SOURCE_ROTATED_90) &&
192 (mOVInfo.src_rect.w % 4))
193 mOVInfo.src_rect.w = utils::aligndown(mOVInfo.src_rect.w, 4);
Saurabh Shahce416f02013-04-10 13:33:09 -0700194 }
Sushil Chauhan35fc68b2013-06-19 14:08:56 -0700195 } else {
196 if (mdpVersion >= MDSS_V5) {
197 // Check for 1-pixel down-scaling
198 if (mOVInfo.src_rect.w - mOVInfo.dst_rect.w == 1)
199 mOVInfo.src_rect.w -= 1;
200 if (mOVInfo.src_rect.h - mOVInfo.dst_rect.h == 1)
201 mOVInfo.src_rect.h -= 1;
202 }
Saurabh Shahb121e142012-08-20 17:59:13 -0700203 }
204
Sushil Chauhan35fc68b2013-06-19 14:08:56 -0700205 doDownscale();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700206 return true;
207}
208
Saurabh Shahacf10202013-02-26 10:15:15 -0800209//Update src format based on rotator's destination format.
210void MdpCtrl::updateSrcFormat(const uint32_t& rotDestFmt) {
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800211 utils::Whf whf = getSrcWhf();
Saurabh Shahacf10202013-02-26 10:15:15 -0800212 whf.format = rotDestFmt;
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800213 setSrcWhf(whf);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700214}
215
216void MdpCtrl::dump() const {
217 ALOGE("== Dump MdpCtrl start ==");
Naseer Ahmed29a26812012-06-14 00:56:20 -0700218 mFd.dump();
219 mdp_wrapper::dump("mOVInfo", mOVInfo);
220 ALOGE("== Dump MdpCtrl end ==");
221}
222
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800223void MdpCtrl::getDump(char *buf, size_t len) {
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700224 ovutils::getDump(buf, len, "Ctrl", mOVInfo);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800225}
226
Naseer Ahmed29a26812012-06-14 00:56:20 -0700227void MdpData::dump() const {
228 ALOGE("== Dump MdpData start ==");
229 mFd.dump();
230 mdp_wrapper::dump("mOvData", mOvData);
231 ALOGE("== Dump MdpData end ==");
232}
233
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800234void MdpData::getDump(char *buf, size_t len) {
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700235 ovutils::getDump(buf, len, "Data", mOvData);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800236}
237
Naseer Ahmed29a26812012-06-14 00:56:20 -0700238void MdpCtrl3D::dump() const {
239 ALOGE("== Dump MdpCtrl start ==");
240 mFd.dump();
241 ALOGE("== Dump MdpCtrl end ==");
242}
243
Saurabh Shah5daeee52013-01-23 16:52:26 +0800244bool MdpCtrl::setVisualParams(const MetaData_t& data) {
Arun Kumar K.R7e5a1f82014-01-22 10:36:16 -0800245 ALOGD_IF(0, "In %s: data.operation = %d", __FUNCTION__, data.operation);
Saurabh Shah5daeee52013-01-23 16:52:26 +0800246#ifdef USES_POST_PROCESSING
Arun Kumar K.R7e5a1f82014-01-22 10:36:16 -0800247 bool needUpdate = false;
Saurabh Shah5daeee52013-01-23 16:52:26 +0800248 /* calculate the data */
249 if (data.operation & PP_PARAM_HSIC) {
250 if (mParams.params.pa_params.hue != data.hsicData.hue) {
251 ALOGD_IF(HSIC_SETTINGS_DEBUG,
252 "Hue has changed from %d to %d",
253 mParams.params.pa_params.hue,data.hsicData.hue);
254 needUpdate = true;
255 }
256
257 if (!isEqual(mParams.params.pa_params.sat,
258 data.hsicData.saturation)) {
259 ALOGD_IF(HSIC_SETTINGS_DEBUG,
260 "Saturation has changed from %f to %f",
261 mParams.params.pa_params.sat,
262 data.hsicData.saturation);
263 needUpdate = true;
264 }
265
266 if (mParams.params.pa_params.intensity != data.hsicData.intensity) {
267 ALOGD_IF(HSIC_SETTINGS_DEBUG,
268 "Intensity has changed from %d to %d",
269 mParams.params.pa_params.intensity,
270 data.hsicData.intensity);
271 needUpdate = true;
272 }
273
274 if (!isEqual(mParams.params.pa_params.contrast,
275 data.hsicData.contrast)) {
276 ALOGD_IF(HSIC_SETTINGS_DEBUG,
277 "Contrast has changed from %f to %f",
278 mParams.params.pa_params.contrast,
279 data.hsicData.contrast);
280 needUpdate = true;
281 }
282
283 if (needUpdate) {
284 mParams.params.pa_params.hue = data.hsicData.hue;
285 mParams.params.pa_params.sat = data.hsicData.saturation;
286 mParams.params.pa_params.intensity = data.hsicData.intensity;
287 mParams.params.pa_params.contrast = data.hsicData.contrast;
288 mParams.params.pa_params.ops = MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
289 mParams.operation |= PP_OP_PA;
290 }
291 }
292
293 if (data.operation & PP_PARAM_SHARP2) {
294 if (mParams.params.sharp_params.strength != data.Sharp2Data.strength) {
295 needUpdate = true;
296 }
297 if (mParams.params.sharp_params.edge_thr != data.Sharp2Data.edge_thr) {
298 needUpdate = true;
299 }
300 if (mParams.params.sharp_params.smooth_thr !=
301 data.Sharp2Data.smooth_thr) {
302 needUpdate = true;
303 }
304 if (mParams.params.sharp_params.noise_thr !=
305 data.Sharp2Data.noise_thr) {
306 needUpdate = true;
307 }
308
309 if (needUpdate) {
310 mParams.params.sharp_params.strength = data.Sharp2Data.strength;
311 mParams.params.sharp_params.edge_thr = data.Sharp2Data.edge_thr;
312 mParams.params.sharp_params.smooth_thr =
313 data.Sharp2Data.smooth_thr;
314 mParams.params.sharp_params.noise_thr = data.Sharp2Data.noise_thr;
315 mParams.params.sharp_params.ops =
316 MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
317 mParams.operation |= PP_OP_SHARP;
318 }
319 }
320
321 if (data.operation & PP_PARAM_IGC) {
322 if (mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data == NULL){
323 uint32_t *igcData
324 = (uint32_t *)malloc(2 * MAX_IGC_LUT_ENTRIES * sizeof(uint32_t));
325 if (!igcData) {
326 ALOGE("IGC storage allocated failed");
327 return false;
328 }
329 mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data = igcData;
330 mOVInfo.overlay_pp_cfg.igc_cfg.c2_data
331 = igcData + MAX_IGC_LUT_ENTRIES;
332 }
333
334 memcpy(mParams.params.igc_lut_params.c0,
335 data.igcData.c0, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
336 memcpy(mParams.params.igc_lut_params.c1,
337 data.igcData.c1, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
338 memcpy(mParams.params.igc_lut_params.c2,
339 data.igcData.c2, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
340
341 mParams.params.igc_lut_params.ops
342 = MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
343 mParams.operation |= PP_OP_IGC;
344 needUpdate = true;
345 }
346
347 if (data.operation & PP_PARAM_VID_INTFC) {
348 mParams.params.conv_params.interface =
349 (interface_type) data.video_interface;
350 needUpdate = true;
351 }
352
353 if (needUpdate) {
354 display_pp_compute_params(&mParams, &mOVInfo.overlay_pp_cfg);
Saurabh Shah5daeee52013-01-23 16:52:26 +0800355 }
356#endif
357 return true;
358}
359
Saurabh Shaha36be922013-12-16 18:18:39 -0800360bool MdpCtrl::validateAndSet(MdpCtrl* mdpCtrlArray[], const int& count,
361 const int& fbFd) {
362 mdp_overlay* ovArray[count];
363 memset(&ovArray, 0, sizeof(ovArray));
364
365 for(int i = 0; i < count; i++) {
366 ovArray[i] = &mdpCtrlArray[i]->mOVInfo;
367 }
368
369 struct mdp_overlay_list list;
370 memset(&list, 0, sizeof(struct mdp_overlay_list));
371 list.num_overlays = count;
372 list.overlay_list = ovArray;
373
374#ifdef USES_QSEED_SCALAR
375 Scale *scalar = Overlay::getScalar();
376 if(scalar) {
377 scalar->applyScale(&list);
378 }
379#endif
380
381 if(!mdp_wrapper::validateAndSet(fbFd, list)) {
Jeykumar Sankaran1d9fc082014-04-01 15:21:55 -0700382 /* No dump for failure due to insufficient resource */
383 if(errno != E2BIG) {
Saurabh Shaha36be922013-12-16 18:18:39 -0800384 mdp_wrapper::dump("Bad ov dump: ",
385 *list.overlay_list[list.processed_overlays]);
386 }
387 return false;
388 }
389
390 return true;
391}
392
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700393
394//// MdpData ////////////
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800395bool MdpData::init(const int& dpy) {
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700396 int fbnum = Overlay::getFbForDpy(dpy);
397 if( fbnum < 0 ) {
398 ALOGE("%s: Invalid FB for the display: %d",__FUNCTION__, dpy);
399 return false;
400 }
401
402 // FD init
403 if(!utils::openDev(mFd, fbnum, Res::fbPath, O_RDWR)){
404 ALOGE("Ctrl failed to init fbnum=%d", fbnum);
405 return false;
406 }
407 return true;
408}
409
Naseer Ahmed29a26812012-06-14 00:56:20 -0700410} // overlay