blob: 1290f329e097cf750c13a1cc796d3abc2abc4a42 [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>
Praveena Pachipulusu734118a2014-12-04 14:53:12 +053024#include <dlfcn.h>
Saurabh Shahb8f58e22013-09-26 16:20:07 -070025
Saurabh Shah5daeee52013-01-23 16:52:26 +080026#define HSIC_SETTINGS_DEBUG 0
27
Saurabh Shahbd2d0832013-04-04 14:33:08 -070028using namespace qdutils;
29
Saurabh Shah5daeee52013-01-23 16:52:26 +080030static inline bool isEqual(float f1, float f2) {
31 return ((int)(f1*100) == (int)(f2*100)) ? true : false;
32}
Naseer Ahmed29a26812012-06-14 00:56:20 -070033
Naseer Ahmed29a26812012-06-14 00:56:20 -070034namespace ovutils = overlay::utils;
35namespace overlay {
Saurabh Shahb121e142012-08-20 17:59:13 -070036
Saurabh Shahd18d88a2014-01-06 15:02:49 -080037bool MdpCtrl::init(const int& dpy) {
Saurabh Shahb8f58e22013-09-26 16:20:07 -070038 int fbnum = Overlay::getFbForDpy(dpy);
39 if( fbnum < 0 ) {
40 ALOGE("%s: Invalid FB for the display: %d",__FUNCTION__, dpy);
41 return false;
42 }
43
Naseer Ahmedf48aef62012-07-20 09:05:53 -070044 // FD init
Naseer Ahmed29a26812012-06-14 00:56:20 -070045 if(!utils::openDev(mFd, fbnum,
Naseer Ahmedf48aef62012-07-20 09:05:53 -070046 Res::fbPath, O_RDWR)){
47 ALOGE("Ctrl failed to init fbnum=%d", fbnum);
Naseer Ahmed29a26812012-06-14 00:56:20 -070048 return false;
49 }
Saurabh Shahb8f58e22013-09-26 16:20:07 -070050 mDpy = dpy;
Naseer Ahmed29a26812012-06-14 00:56:20 -070051 return true;
52}
53
54void MdpCtrl::reset() {
55 utils::memset0(mOVInfo);
Naseer Ahmedf48aef62012-07-20 09:05:53 -070056 mOVInfo.id = MSMFB_NEW_REQUEST;
Naseer Ahmedf48aef62012-07-20 09:05:53 -070057 mOrientation = utils::OVERLAY_TRANSFORM_0;
Saurabh Shahb8f58e22013-09-26 16:20:07 -070058 mDpy = 0;
Saurabh Shah5daeee52013-01-23 16:52:26 +080059#ifdef USES_POST_PROCESSING
Saurabh Shah5daeee52013-01-23 16:52:26 +080060 memset(&mParams, 0, sizeof(struct compute_params));
61 mParams.params.conv_params.order = hsic_order_hsc_i;
62 mParams.params.conv_params.interface = interface_rec601;
63 mParams.params.conv_params.cc_matrix[0][0] = 1;
64 mParams.params.conv_params.cc_matrix[1][1] = 1;
65 mParams.params.conv_params.cc_matrix[2][2] = 1;
66#endif
Naseer Ahmed29a26812012-06-14 00:56:20 -070067}
68
69bool MdpCtrl::close() {
Saurabh Shah8e1ae952012-08-15 12:15:14 -070070 bool result = true;
Saurabh Shah8e1ae952012-08-15 12:15:14 -070071 if(MSMFB_NEW_REQUEST != static_cast<int>(mOVInfo.id)) {
72 if(!mdp_wrapper::unsetOverlay(mFd.getFD(), mOVInfo.id)) {
73 ALOGE("MdpCtrl close error in unset");
74 result = false;
75 }
Naseer Ahmed29a26812012-06-14 00:56:20 -070076 }
Saurabh Shah5daeee52013-01-23 16:52:26 +080077#ifdef USES_POST_PROCESSING
78 /* free allocated memory in PP */
79 if (mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data)
80 free(mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data);
81#endif
Naseer Ahmed29a26812012-06-14 00:56:20 -070082 reset();
Saurabh Shahacf10202013-02-26 10:15:15 -080083
Naseer Ahmed29a26812012-06-14 00:56:20 -070084 if(!mFd.close()) {
Saurabh Shah8e1ae952012-08-15 12:15:14 -070085 result = false;
Naseer Ahmed29a26812012-06-14 00:56:20 -070086 }
Saurabh Shah8e1ae952012-08-15 12:15:14 -070087
88 return result;
Naseer Ahmed29a26812012-06-14 00:56:20 -070089}
90
Saurabh Shahacf10202013-02-26 10:15:15 -080091void MdpCtrl::setSource(const utils::PipeArgs& args) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -070092 setSrcWhf(args.whf);
93
94 //TODO These are hardcoded. Can be moved out of setSource.
Naseer Ahmedf48aef62012-07-20 09:05:53 -070095 mOVInfo.transp_mask = 0xffffffff;
96
97 //TODO These calls should ideally be a part of setPipeParams API
98 setFlags(args.mdpFlags);
99 setZ(args.zorder);
Naseer Ahmed522ce662013-03-18 20:14:05 -0400100 setPlaneAlpha(args.planeAlpha);
101 setBlending(args.blending);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700102}
103
Saurabh Shahacf10202013-02-26 10:15:15 -0800104void MdpCtrl::setCrop(const utils::Dim& d) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700105 setSrcRectDim(d);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700106}
107
Sushil Chauhan897a9c32013-07-18 11:09:55 -0700108void MdpCtrl::setColor(const uint32_t color) {
109 mOVInfo.bg_color = color;
110}
111
Saurabh Shahacf10202013-02-26 10:15:15 -0800112void MdpCtrl::setPosition(const overlay::utils::Dim& d) {
113 setDstRectDim(d);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700114}
115
Saurabh Shahacf10202013-02-26 10:15:15 -0800116void MdpCtrl::setTransform(const utils::eTransform& orient) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700117 int rot = utils::getMdpOrient(orient);
118 setUserData(rot);
Saurabh Shaha73738d2012-08-09 18:15:18 -0700119 mOrientation = static_cast<utils::eTransform>(rot);
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800120}
121
radhakrishna8ccb9082014-05-09 16:18:43 +0530122void MdpCtrl::setPipeType(const utils::eMdpPipeType& pType){
123 switch((int) pType){
124 case utils::OV_MDP_PIPE_RGB:
125 mOVInfo.pipe_type = PIPE_TYPE_RGB;
126 break;
127 case utils::OV_MDP_PIPE_VG:
128 mOVInfo.pipe_type = PIPE_TYPE_VIG;
129 break;
130 case utils::OV_MDP_PIPE_DMA:
131 mOVInfo.pipe_type = PIPE_TYPE_DMA;
132 break;
133 default:
134 mOVInfo.pipe_type = PIPE_TYPE_AUTO;
135 break;
136 }
137}
138
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700139void MdpCtrl::doTransform() {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700140 setRotationFlags();
Saurabh Shahacf10202013-02-26 10:15:15 -0800141 utils::Whf whf = getSrcWhf();
142 utils::Dim dim = getSrcRectDim();
143 utils::preRotateSource(mOrientation, whf, dim);
144 setSrcWhf(whf);
145 setSrcRectDim(dim);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700146}
147
Saurabh Shahacf10202013-02-26 10:15:15 -0800148void MdpCtrl::doDownscale() {
Saurabh Shah958051e2014-06-27 16:15:42 -0700149 if(MDPVersion::getInstance().supportsDecimation()) {
Saurabh Shah1a03d482013-05-29 13:44:20 -0700150 utils::getDecimationFactor(mOVInfo.src_rect.w, mOVInfo.src_rect.h,
Saurabh Shahb6810df2014-06-17 16:00:22 -0700151 mOVInfo.dst_rect.w, mOVInfo.dst_rect.h, mOVInfo.horz_deci,
152 mOVInfo.vert_deci);
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700153 }
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800154}
155
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700156bool MdpCtrl::set() {
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700157 int mdpVersion = MDPVersion::getInstance().getMDPVersion();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700158 //deferred calcs, so APIs could be called in any order.
Saurabh Shahacf10202013-02-26 10:15:15 -0800159 doTransform();
Saurabh Shahb121e142012-08-20 17:59:13 -0700160 utils::Whf whf = getSrcWhf();
161 if(utils::isYuv(whf.format)) {
Sushil Chauhan1cac8152013-05-08 15:53:51 -0700162 utils::normalizeCrop(mOVInfo.src_rect.x, mOVInfo.src_rect.w);
163 utils::normalizeCrop(mOVInfo.src_rect.y, mOVInfo.src_rect.h);
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700164 if(mdpVersion < MDSS_V5) {
Saurabh Shahce416f02013-04-10 13:33:09 -0700165 utils::even_floor(mOVInfo.dst_rect.w);
166 utils::even_floor(mOVInfo.dst_rect.h);
Sushil Chauhan5491c8a2013-05-24 10:15:30 -0700167 } else if (mOVInfo.flags & MDP_DEINTERLACE) {
168 // For interlaced, crop.h should be 4-aligned
169 if (!(mOVInfo.flags & MDP_SOURCE_ROTATED_90) &&
170 (mOVInfo.src_rect.h % 4))
171 mOVInfo.src_rect.h = utils::aligndown(mOVInfo.src_rect.h, 4);
Sravan Kumar D.V.Na34dc852014-03-26 19:13:11 +0530172 // For interlaced, width must be multiple of 4 when rotated 90deg.
173 else if ((mOVInfo.flags & MDP_SOURCE_ROTATED_90) &&
174 (mOVInfo.src_rect.w % 4))
175 mOVInfo.src_rect.w = utils::aligndown(mOVInfo.src_rect.w, 4);
Saurabh Shahce416f02013-04-10 13:33:09 -0700176 }
Sushil Chauhan35fc68b2013-06-19 14:08:56 -0700177 } else {
178 if (mdpVersion >= MDSS_V5) {
179 // Check for 1-pixel down-scaling
180 if (mOVInfo.src_rect.w - mOVInfo.dst_rect.w == 1)
181 mOVInfo.src_rect.w -= 1;
182 if (mOVInfo.src_rect.h - mOVInfo.dst_rect.h == 1)
183 mOVInfo.src_rect.h -= 1;
184 }
Saurabh Shahb121e142012-08-20 17:59:13 -0700185 }
186
Sushil Chauhan35fc68b2013-06-19 14:08:56 -0700187 doDownscale();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700188 return true;
189}
190
Saurabh Shahacf10202013-02-26 10:15:15 -0800191//Update src format based on rotator's destination format.
192void MdpCtrl::updateSrcFormat(const uint32_t& rotDestFmt) {
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800193 utils::Whf whf = getSrcWhf();
Saurabh Shahacf10202013-02-26 10:15:15 -0800194 whf.format = rotDestFmt;
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800195 setSrcWhf(whf);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700196}
197
198void MdpCtrl::dump() const {
199 ALOGE("== Dump MdpCtrl start ==");
Naseer Ahmed29a26812012-06-14 00:56:20 -0700200 mFd.dump();
201 mdp_wrapper::dump("mOVInfo", mOVInfo);
202 ALOGE("== Dump MdpCtrl end ==");
203}
204
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800205void MdpCtrl::getDump(char *buf, size_t len) {
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700206 ovutils::getDump(buf, len, "Ctrl", mOVInfo);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800207}
208
Naseer Ahmed29a26812012-06-14 00:56:20 -0700209void MdpData::dump() const {
210 ALOGE("== Dump MdpData start ==");
211 mFd.dump();
212 mdp_wrapper::dump("mOvData", mOvData);
213 ALOGE("== Dump MdpData end ==");
214}
215
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800216void MdpData::getDump(char *buf, size_t len) {
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700217 ovutils::getDump(buf, len, "Data", mOvData);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800218}
219
Saurabh Shah5daeee52013-01-23 16:52:26 +0800220bool MdpCtrl::setVisualParams(const MetaData_t& data) {
Arun Kumar K.R7e5a1f82014-01-22 10:36:16 -0800221 ALOGD_IF(0, "In %s: data.operation = %d", __FUNCTION__, data.operation);
Sushil Chauhan0265c472014-10-01 16:39:02 -0700222
223 // Set Color Space for MDP to configure CSC matrix
224 mOVInfo.color_space = ITU_R_601;
225 if (data.operation & UPDATE_COLOR_SPACE) {
226 mOVInfo.color_space = data.colorSpace;
227 }
228
Saurabh Shah5daeee52013-01-23 16:52:26 +0800229#ifdef USES_POST_PROCESSING
Arun Kumar K.R7e5a1f82014-01-22 10:36:16 -0800230 bool needUpdate = false;
Saurabh Shah5daeee52013-01-23 16:52:26 +0800231 /* calculate the data */
232 if (data.operation & PP_PARAM_HSIC) {
233 if (mParams.params.pa_params.hue != data.hsicData.hue) {
234 ALOGD_IF(HSIC_SETTINGS_DEBUG,
235 "Hue has changed from %d to %d",
236 mParams.params.pa_params.hue,data.hsicData.hue);
237 needUpdate = true;
238 }
239
240 if (!isEqual(mParams.params.pa_params.sat,
241 data.hsicData.saturation)) {
242 ALOGD_IF(HSIC_SETTINGS_DEBUG,
243 "Saturation has changed from %f to %f",
244 mParams.params.pa_params.sat,
245 data.hsicData.saturation);
246 needUpdate = true;
247 }
248
249 if (mParams.params.pa_params.intensity != data.hsicData.intensity) {
250 ALOGD_IF(HSIC_SETTINGS_DEBUG,
251 "Intensity has changed from %d to %d",
252 mParams.params.pa_params.intensity,
253 data.hsicData.intensity);
254 needUpdate = true;
255 }
256
257 if (!isEqual(mParams.params.pa_params.contrast,
258 data.hsicData.contrast)) {
259 ALOGD_IF(HSIC_SETTINGS_DEBUG,
260 "Contrast has changed from %f to %f",
261 mParams.params.pa_params.contrast,
262 data.hsicData.contrast);
263 needUpdate = true;
264 }
265
266 if (needUpdate) {
Praveena Pachipulusu734118a2014-12-04 14:53:12 +0530267 mParams.params.pa_params.hue = (float)data.hsicData.hue;
Saurabh Shah5daeee52013-01-23 16:52:26 +0800268 mParams.params.pa_params.sat = data.hsicData.saturation;
269 mParams.params.pa_params.intensity = data.hsicData.intensity;
270 mParams.params.pa_params.contrast = data.hsicData.contrast;
271 mParams.params.pa_params.ops = MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
272 mParams.operation |= PP_OP_PA;
273 }
274 }
275
276 if (data.operation & PP_PARAM_SHARP2) {
277 if (mParams.params.sharp_params.strength != data.Sharp2Data.strength) {
278 needUpdate = true;
279 }
280 if (mParams.params.sharp_params.edge_thr != data.Sharp2Data.edge_thr) {
281 needUpdate = true;
282 }
283 if (mParams.params.sharp_params.smooth_thr !=
284 data.Sharp2Data.smooth_thr) {
285 needUpdate = true;
286 }
287 if (mParams.params.sharp_params.noise_thr !=
288 data.Sharp2Data.noise_thr) {
289 needUpdate = true;
290 }
291
292 if (needUpdate) {
293 mParams.params.sharp_params.strength = data.Sharp2Data.strength;
294 mParams.params.sharp_params.edge_thr = data.Sharp2Data.edge_thr;
295 mParams.params.sharp_params.smooth_thr =
296 data.Sharp2Data.smooth_thr;
297 mParams.params.sharp_params.noise_thr = data.Sharp2Data.noise_thr;
298 mParams.params.sharp_params.ops =
299 MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
300 mParams.operation |= PP_OP_SHARP;
301 }
302 }
303
304 if (data.operation & PP_PARAM_IGC) {
305 if (mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data == NULL){
306 uint32_t *igcData
307 = (uint32_t *)malloc(2 * MAX_IGC_LUT_ENTRIES * sizeof(uint32_t));
308 if (!igcData) {
309 ALOGE("IGC storage allocated failed");
310 return false;
311 }
312 mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data = igcData;
313 mOVInfo.overlay_pp_cfg.igc_cfg.c2_data
314 = igcData + MAX_IGC_LUT_ENTRIES;
315 }
316
317 memcpy(mParams.params.igc_lut_params.c0,
318 data.igcData.c0, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
319 memcpy(mParams.params.igc_lut_params.c1,
320 data.igcData.c1, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
321 memcpy(mParams.params.igc_lut_params.c2,
322 data.igcData.c2, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
323
324 mParams.params.igc_lut_params.ops
325 = MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
326 mParams.operation |= PP_OP_IGC;
327 needUpdate = true;
328 }
329
330 if (data.operation & PP_PARAM_VID_INTFC) {
331 mParams.params.conv_params.interface =
332 (interface_type) data.video_interface;
333 needUpdate = true;
334 }
335
336 if (needUpdate) {
Praveena Pachipulusu734118a2014-12-04 14:53:12 +0530337 int (*sFnppParams)(const struct compute_params *,
338 struct mdp_overlay_pp_params *) =
339 Overlay::getFnPpParams();
340 if(sFnppParams) {
341 int ret = sFnppParams(&mParams, &mOVInfo.overlay_pp_cfg);
342 if (ret) {
343 ALOGE("%s: Unable to set PP params", __FUNCTION__);
344 }
345 }
Saurabh Shah5daeee52013-01-23 16:52:26 +0800346 }
347#endif
348 return true;
349}
350
Saurabh Shaha36be922013-12-16 18:18:39 -0800351bool MdpCtrl::validateAndSet(MdpCtrl* mdpCtrlArray[], const int& count,
352 const int& fbFd) {
353 mdp_overlay* ovArray[count];
354 memset(&ovArray, 0, sizeof(ovArray));
355
356 for(int i = 0; i < count; i++) {
357 ovArray[i] = &mdpCtrlArray[i]->mOVInfo;
358 }
359
360 struct mdp_overlay_list list;
361 memset(&list, 0, sizeof(struct mdp_overlay_list));
362 list.num_overlays = count;
363 list.overlay_list = ovArray;
364
Saurabh Shaheac146b2014-05-13 11:36:20 -0700365 int (*fnProgramScale)(struct mdp_overlay_list *) =
366 Overlay::getFnProgramScale();
367 if(fnProgramScale) {
368 fnProgramScale(&list);
Saurabh Shaha36be922013-12-16 18:18:39 -0800369 }
Saurabh Shaha36be922013-12-16 18:18:39 -0800370
Praveena Pachipulusubb89fa62014-11-26 12:34:16 +0530371 // Error value is based on file errno-base.h
372 // 0 - indicates no error.
373 int errVal = mdp_wrapper::validateAndSet(fbFd, list);
374 if(errVal) {
Jeykumar Sankaran1d9fc082014-04-01 15:21:55 -0700375 /* No dump for failure due to insufficient resource */
Praveena Pachipulusubb89fa62014-11-26 12:34:16 +0530376 if(errVal != E2BIG) {
Saurabh Shah15455aa2015-01-28 13:54:48 -0800377 //ENODEV is returned when the driver cannot satisfy a pipe request.
378 //This could happen if previous round's UNSET hasn't been commited
379 //yet, either because of a missed vsync or because of difference in
380 //vsyncs of primary and external. This is expected during
381 //transition scenarios, but should be considered fatal if seen
382 //continuously.
383 if(errVal == ENODEV) {
384 ALOGW("%s: Pipe unavailable. Likely previous UNSET pending. "
385 "Fatal if seen continuously.", __FUNCTION__);
386 } else {
387 ALOGE("%s failed, error %d: %s", __FUNCTION__, errVal,
388 strerror(errVal));
389 mdp_wrapper::dump("Bad ov dump: ",
390 *list.overlay_list[list.processed_overlays]);
391 }
Saurabh Shaha36be922013-12-16 18:18:39 -0800392 }
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