blob: b8bb33ea5c62ef19e9f8cef99ef99a9999354b51 [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
Saurabh Shah5daeee52013-01-23 16:52:26 +080025#define HSIC_SETTINGS_DEBUG 0
26
Saurabh Shahbd2d0832013-04-04 14:33:08 -070027using namespace qdutils;
28
Saurabh Shah5daeee52013-01-23 16:52:26 +080029static inline bool isEqual(float f1, float f2) {
30 return ((int)(f1*100) == (int)(f2*100)) ? true : false;
31}
Naseer Ahmed29a26812012-06-14 00:56:20 -070032
Naseer Ahmed29a26812012-06-14 00:56:20 -070033namespace ovutils = overlay::utils;
34namespace overlay {
Saurabh Shahb121e142012-08-20 17:59:13 -070035
Saurabh Shahd18d88a2014-01-06 15:02:49 -080036bool MdpCtrl::init(const int& dpy) {
Saurabh Shahb8f58e22013-09-26 16:20:07 -070037 int fbnum = Overlay::getFbForDpy(dpy);
38 if( fbnum < 0 ) {
39 ALOGE("%s: Invalid FB for the display: %d",__FUNCTION__, dpy);
40 return false;
41 }
42
Naseer Ahmedf48aef62012-07-20 09:05:53 -070043 // FD init
Naseer Ahmed29a26812012-06-14 00:56:20 -070044 if(!utils::openDev(mFd, fbnum,
Naseer Ahmedf48aef62012-07-20 09:05:53 -070045 Res::fbPath, O_RDWR)){
46 ALOGE("Ctrl failed to init fbnum=%d", fbnum);
Naseer Ahmed29a26812012-06-14 00:56:20 -070047 return false;
48 }
Saurabh Shahb8f58e22013-09-26 16:20:07 -070049 mDpy = dpy;
Naseer Ahmed29a26812012-06-14 00:56:20 -070050 return true;
51}
52
53void MdpCtrl::reset() {
54 utils::memset0(mOVInfo);
Naseer Ahmedf48aef62012-07-20 09:05:53 -070055 mOVInfo.id = MSMFB_NEW_REQUEST;
Naseer Ahmedf48aef62012-07-20 09:05:53 -070056 mOrientation = utils::OVERLAY_TRANSFORM_0;
Saurabh Shahb8f58e22013-09-26 16:20:07 -070057 mDpy = 0;
Saurabh Shah5daeee52013-01-23 16:52:26 +080058#ifdef USES_POST_PROCESSING
Saurabh Shah5daeee52013-01-23 16:52:26 +080059 memset(&mParams, 0, sizeof(struct compute_params));
60 mParams.params.conv_params.order = hsic_order_hsc_i;
61 mParams.params.conv_params.interface = interface_rec601;
62 mParams.params.conv_params.cc_matrix[0][0] = 1;
63 mParams.params.conv_params.cc_matrix[1][1] = 1;
64 mParams.params.conv_params.cc_matrix[2][2] = 1;
65#endif
Naseer Ahmed29a26812012-06-14 00:56:20 -070066}
67
68bool MdpCtrl::close() {
Saurabh Shah8e1ae952012-08-15 12:15:14 -070069 bool result = true;
Saurabh Shah8e1ae952012-08-15 12:15:14 -070070 if(MSMFB_NEW_REQUEST != static_cast<int>(mOVInfo.id)) {
71 if(!mdp_wrapper::unsetOverlay(mFd.getFD(), mOVInfo.id)) {
72 ALOGE("MdpCtrl close error in unset");
73 result = false;
74 }
Naseer Ahmed29a26812012-06-14 00:56:20 -070075 }
Saurabh Shah5daeee52013-01-23 16:52:26 +080076#ifdef USES_POST_PROCESSING
77 /* free allocated memory in PP */
78 if (mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data)
79 free(mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data);
80#endif
Naseer Ahmed29a26812012-06-14 00:56:20 -070081 reset();
Saurabh Shahacf10202013-02-26 10:15:15 -080082
Naseer Ahmed29a26812012-06-14 00:56:20 -070083 if(!mFd.close()) {
Saurabh Shah8e1ae952012-08-15 12:15:14 -070084 result = false;
Naseer Ahmed29a26812012-06-14 00:56:20 -070085 }
Saurabh Shah8e1ae952012-08-15 12:15:14 -070086
87 return result;
Naseer Ahmed29a26812012-06-14 00:56:20 -070088}
89
Saurabh Shahacf10202013-02-26 10:15:15 -080090void MdpCtrl::setSource(const utils::PipeArgs& args) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -070091 setSrcWhf(args.whf);
92
93 //TODO These are hardcoded. Can be moved out of setSource.
Naseer Ahmedf48aef62012-07-20 09:05:53 -070094 mOVInfo.transp_mask = 0xffffffff;
95
96 //TODO These calls should ideally be a part of setPipeParams API
97 setFlags(args.mdpFlags);
98 setZ(args.zorder);
Naseer Ahmed522ce662013-03-18 20:14:05 -040099 setPlaneAlpha(args.planeAlpha);
100 setBlending(args.blending);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700101}
102
Saurabh Shahacf10202013-02-26 10:15:15 -0800103void MdpCtrl::setCrop(const utils::Dim& d) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700104 setSrcRectDim(d);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700105}
106
Sushil Chauhan897a9c32013-07-18 11:09:55 -0700107void MdpCtrl::setColor(const uint32_t color) {
108 mOVInfo.bg_color = color;
109}
110
Saurabh Shahacf10202013-02-26 10:15:15 -0800111void MdpCtrl::setPosition(const overlay::utils::Dim& d) {
112 setDstRectDim(d);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700113}
114
Saurabh Shahacf10202013-02-26 10:15:15 -0800115void MdpCtrl::setTransform(const utils::eTransform& orient) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700116 int rot = utils::getMdpOrient(orient);
117 setUserData(rot);
Saurabh Shaha73738d2012-08-09 18:15:18 -0700118 mOrientation = static_cast<utils::eTransform>(rot);
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800119}
120
radhakrishna8ccb9082014-05-09 16:18:43 +0530121void MdpCtrl::setPipeType(const utils::eMdpPipeType& pType){
122 switch((int) pType){
123 case utils::OV_MDP_PIPE_RGB:
124 mOVInfo.pipe_type = PIPE_TYPE_RGB;
125 break;
126 case utils::OV_MDP_PIPE_VG:
127 mOVInfo.pipe_type = PIPE_TYPE_VIG;
128 break;
129 case utils::OV_MDP_PIPE_DMA:
130 mOVInfo.pipe_type = PIPE_TYPE_DMA;
131 break;
132 default:
133 mOVInfo.pipe_type = PIPE_TYPE_AUTO;
134 break;
135 }
136}
137
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700138void MdpCtrl::doTransform() {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700139 setRotationFlags();
Saurabh Shahacf10202013-02-26 10:15:15 -0800140 utils::Whf whf = getSrcWhf();
141 utils::Dim dim = getSrcRectDim();
142 utils::preRotateSource(mOrientation, whf, dim);
143 setSrcWhf(whf);
144 setSrcRectDim(dim);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700145}
146
Saurabh Shahacf10202013-02-26 10:15:15 -0800147void MdpCtrl::doDownscale() {
Saurabh Shah958051e2014-06-27 16:15:42 -0700148 if(MDPVersion::getInstance().supportsDecimation()) {
Saurabh Shah1a03d482013-05-29 13:44:20 -0700149 utils::getDecimationFactor(mOVInfo.src_rect.w, mOVInfo.src_rect.h,
Saurabh Shahb6810df2014-06-17 16:00:22 -0700150 mOVInfo.dst_rect.w, mOVInfo.dst_rect.h, mOVInfo.horz_deci,
151 mOVInfo.vert_deci);
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700152 }
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800153}
154
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700155bool MdpCtrl::set() {
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700156 int mdpVersion = MDPVersion::getInstance().getMDPVersion();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700157 //deferred calcs, so APIs could be called in any order.
Saurabh Shahacf10202013-02-26 10:15:15 -0800158 doTransform();
Saurabh Shahb121e142012-08-20 17:59:13 -0700159 utils::Whf whf = getSrcWhf();
160 if(utils::isYuv(whf.format)) {
Sushil Chauhan1cac8152013-05-08 15:53:51 -0700161 utils::normalizeCrop(mOVInfo.src_rect.x, mOVInfo.src_rect.w);
162 utils::normalizeCrop(mOVInfo.src_rect.y, mOVInfo.src_rect.h);
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700163 if(mdpVersion < MDSS_V5) {
Saurabh Shahce416f02013-04-10 13:33:09 -0700164 utils::even_floor(mOVInfo.dst_rect.w);
165 utils::even_floor(mOVInfo.dst_rect.h);
Sushil Chauhan5491c8a2013-05-24 10:15:30 -0700166 } else if (mOVInfo.flags & MDP_DEINTERLACE) {
167 // For interlaced, crop.h should be 4-aligned
168 if (!(mOVInfo.flags & MDP_SOURCE_ROTATED_90) &&
169 (mOVInfo.src_rect.h % 4))
170 mOVInfo.src_rect.h = utils::aligndown(mOVInfo.src_rect.h, 4);
Sravan Kumar D.V.Na34dc852014-03-26 19:13:11 +0530171 // For interlaced, width must be multiple of 4 when rotated 90deg.
172 else if ((mOVInfo.flags & MDP_SOURCE_ROTATED_90) &&
173 (mOVInfo.src_rect.w % 4))
174 mOVInfo.src_rect.w = utils::aligndown(mOVInfo.src_rect.w, 4);
Saurabh Shahce416f02013-04-10 13:33:09 -0700175 }
Sushil Chauhan35fc68b2013-06-19 14:08:56 -0700176 } else {
177 if (mdpVersion >= MDSS_V5) {
178 // Check for 1-pixel down-scaling
179 if (mOVInfo.src_rect.w - mOVInfo.dst_rect.w == 1)
180 mOVInfo.src_rect.w -= 1;
181 if (mOVInfo.src_rect.h - mOVInfo.dst_rect.h == 1)
182 mOVInfo.src_rect.h -= 1;
183 }
Saurabh Shahb121e142012-08-20 17:59:13 -0700184 }
185
Sushil Chauhan35fc68b2013-06-19 14:08:56 -0700186 doDownscale();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700187 return true;
188}
189
Saurabh Shahacf10202013-02-26 10:15:15 -0800190//Update src format based on rotator's destination format.
191void MdpCtrl::updateSrcFormat(const uint32_t& rotDestFmt) {
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800192 utils::Whf whf = getSrcWhf();
Saurabh Shahacf10202013-02-26 10:15:15 -0800193 whf.format = rotDestFmt;
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800194 setSrcWhf(whf);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700195}
196
197void MdpCtrl::dump() const {
198 ALOGE("== Dump MdpCtrl start ==");
Naseer Ahmed29a26812012-06-14 00:56:20 -0700199 mFd.dump();
200 mdp_wrapper::dump("mOVInfo", mOVInfo);
201 ALOGE("== Dump MdpCtrl end ==");
202}
203
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800204void MdpCtrl::getDump(char *buf, size_t len) {
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700205 ovutils::getDump(buf, len, "Ctrl", mOVInfo);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800206}
207
Naseer Ahmed29a26812012-06-14 00:56:20 -0700208void MdpData::dump() const {
209 ALOGE("== Dump MdpData start ==");
210 mFd.dump();
211 mdp_wrapper::dump("mOvData", mOvData);
212 ALOGE("== Dump MdpData end ==");
213}
214
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800215void MdpData::getDump(char *buf, size_t len) {
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700216 ovutils::getDump(buf, len, "Data", mOvData);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800217}
218
Saurabh Shah5daeee52013-01-23 16:52:26 +0800219bool MdpCtrl::setVisualParams(const MetaData_t& data) {
Arun Kumar K.R7e5a1f82014-01-22 10:36:16 -0800220 ALOGD_IF(0, "In %s: data.operation = %d", __FUNCTION__, data.operation);
Sushil Chauhan0265c472014-10-01 16:39:02 -0700221
222 // Set Color Space for MDP to configure CSC matrix
223 mOVInfo.color_space = ITU_R_601;
224 if (data.operation & UPDATE_COLOR_SPACE) {
225 mOVInfo.color_space = data.colorSpace;
226 }
227
Saurabh Shah5daeee52013-01-23 16:52:26 +0800228#ifdef USES_POST_PROCESSING
Arun Kumar K.R7e5a1f82014-01-22 10:36:16 -0800229 bool needUpdate = false;
Saurabh Shah5daeee52013-01-23 16:52:26 +0800230 /* calculate the data */
231 if (data.operation & PP_PARAM_HSIC) {
232 if (mParams.params.pa_params.hue != data.hsicData.hue) {
233 ALOGD_IF(HSIC_SETTINGS_DEBUG,
234 "Hue has changed from %d to %d",
235 mParams.params.pa_params.hue,data.hsicData.hue);
236 needUpdate = true;
237 }
238
239 if (!isEqual(mParams.params.pa_params.sat,
240 data.hsicData.saturation)) {
241 ALOGD_IF(HSIC_SETTINGS_DEBUG,
242 "Saturation has changed from %f to %f",
243 mParams.params.pa_params.sat,
244 data.hsicData.saturation);
245 needUpdate = true;
246 }
247
248 if (mParams.params.pa_params.intensity != data.hsicData.intensity) {
249 ALOGD_IF(HSIC_SETTINGS_DEBUG,
250 "Intensity has changed from %d to %d",
251 mParams.params.pa_params.intensity,
252 data.hsicData.intensity);
253 needUpdate = true;
254 }
255
256 if (!isEqual(mParams.params.pa_params.contrast,
257 data.hsicData.contrast)) {
258 ALOGD_IF(HSIC_SETTINGS_DEBUG,
259 "Contrast has changed from %f to %f",
260 mParams.params.pa_params.contrast,
261 data.hsicData.contrast);
262 needUpdate = true;
263 }
264
265 if (needUpdate) {
266 mParams.params.pa_params.hue = data.hsicData.hue;
267 mParams.params.pa_params.sat = data.hsicData.saturation;
268 mParams.params.pa_params.intensity = data.hsicData.intensity;
269 mParams.params.pa_params.contrast = data.hsicData.contrast;
270 mParams.params.pa_params.ops = MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
271 mParams.operation |= PP_OP_PA;
272 }
273 }
274
275 if (data.operation & PP_PARAM_SHARP2) {
276 if (mParams.params.sharp_params.strength != data.Sharp2Data.strength) {
277 needUpdate = true;
278 }
279 if (mParams.params.sharp_params.edge_thr != data.Sharp2Data.edge_thr) {
280 needUpdate = true;
281 }
282 if (mParams.params.sharp_params.smooth_thr !=
283 data.Sharp2Data.smooth_thr) {
284 needUpdate = true;
285 }
286 if (mParams.params.sharp_params.noise_thr !=
287 data.Sharp2Data.noise_thr) {
288 needUpdate = true;
289 }
290
291 if (needUpdate) {
292 mParams.params.sharp_params.strength = data.Sharp2Data.strength;
293 mParams.params.sharp_params.edge_thr = data.Sharp2Data.edge_thr;
294 mParams.params.sharp_params.smooth_thr =
295 data.Sharp2Data.smooth_thr;
296 mParams.params.sharp_params.noise_thr = data.Sharp2Data.noise_thr;
297 mParams.params.sharp_params.ops =
298 MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
299 mParams.operation |= PP_OP_SHARP;
300 }
301 }
302
303 if (data.operation & PP_PARAM_IGC) {
304 if (mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data == NULL){
305 uint32_t *igcData
306 = (uint32_t *)malloc(2 * MAX_IGC_LUT_ENTRIES * sizeof(uint32_t));
307 if (!igcData) {
308 ALOGE("IGC storage allocated failed");
309 return false;
310 }
311 mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data = igcData;
312 mOVInfo.overlay_pp_cfg.igc_cfg.c2_data
313 = igcData + MAX_IGC_LUT_ENTRIES;
314 }
315
316 memcpy(mParams.params.igc_lut_params.c0,
317 data.igcData.c0, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
318 memcpy(mParams.params.igc_lut_params.c1,
319 data.igcData.c1, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
320 memcpy(mParams.params.igc_lut_params.c2,
321 data.igcData.c2, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
322
323 mParams.params.igc_lut_params.ops
324 = MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
325 mParams.operation |= PP_OP_IGC;
326 needUpdate = true;
327 }
328
329 if (data.operation & PP_PARAM_VID_INTFC) {
330 mParams.params.conv_params.interface =
331 (interface_type) data.video_interface;
332 needUpdate = true;
333 }
334
335 if (needUpdate) {
336 display_pp_compute_params(&mParams, &mOVInfo.overlay_pp_cfg);
Saurabh Shah5daeee52013-01-23 16:52:26 +0800337 }
338#endif
339 return true;
340}
341
Saurabh Shaha36be922013-12-16 18:18:39 -0800342bool MdpCtrl::validateAndSet(MdpCtrl* mdpCtrlArray[], const int& count,
343 const int& fbFd) {
344 mdp_overlay* ovArray[count];
345 memset(&ovArray, 0, sizeof(ovArray));
346
347 for(int i = 0; i < count; i++) {
348 ovArray[i] = &mdpCtrlArray[i]->mOVInfo;
349 }
350
351 struct mdp_overlay_list list;
352 memset(&list, 0, sizeof(struct mdp_overlay_list));
353 list.num_overlays = count;
354 list.overlay_list = ovArray;
355
Saurabh Shaheac146b2014-05-13 11:36:20 -0700356 int (*fnProgramScale)(struct mdp_overlay_list *) =
357 Overlay::getFnProgramScale();
358 if(fnProgramScale) {
359 fnProgramScale(&list);
Saurabh Shaha36be922013-12-16 18:18:39 -0800360 }
Saurabh Shaha36be922013-12-16 18:18:39 -0800361
362 if(!mdp_wrapper::validateAndSet(fbFd, list)) {
Jeykumar Sankaran1d9fc082014-04-01 15:21:55 -0700363 /* No dump for failure due to insufficient resource */
364 if(errno != E2BIG) {
Saurabh Shaha36be922013-12-16 18:18:39 -0800365 mdp_wrapper::dump("Bad ov dump: ",
366 *list.overlay_list[list.processed_overlays]);
367 }
368 return false;
369 }
370
371 return true;
372}
373
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700374
375//// MdpData ////////////
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800376bool MdpData::init(const int& dpy) {
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700377 int fbnum = Overlay::getFbForDpy(dpy);
378 if( fbnum < 0 ) {
379 ALOGE("%s: Invalid FB for the display: %d",__FUNCTION__, dpy);
380 return false;
381 }
382
383 // FD init
384 if(!utils::openDev(mFd, fbnum, Res::fbPath, O_RDWR)){
385 ALOGE("Ctrl failed to init fbnum=%d", fbnum);
386 return false;
387 }
388 return true;
389}
390
Naseer Ahmed29a26812012-06-14 00:56:20 -0700391} // overlay