blob: 7f9f1362f52c28bee164230039d0c978b114c85d [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);
99 setIsFg(args.isFg);
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);
Saurabh Shah5daeee52013-01-23 16:52:26 +0800222#ifdef USES_POST_PROCESSING
Arun Kumar K.R7e5a1f82014-01-22 10:36:16 -0800223 bool needUpdate = false;
Saurabh Shah5daeee52013-01-23 16:52:26 +0800224 /* calculate the data */
225 if (data.operation & PP_PARAM_HSIC) {
226 if (mParams.params.pa_params.hue != data.hsicData.hue) {
227 ALOGD_IF(HSIC_SETTINGS_DEBUG,
228 "Hue has changed from %d to %d",
229 mParams.params.pa_params.hue,data.hsicData.hue);
230 needUpdate = true;
231 }
232
233 if (!isEqual(mParams.params.pa_params.sat,
234 data.hsicData.saturation)) {
235 ALOGD_IF(HSIC_SETTINGS_DEBUG,
236 "Saturation has changed from %f to %f",
237 mParams.params.pa_params.sat,
238 data.hsicData.saturation);
239 needUpdate = true;
240 }
241
242 if (mParams.params.pa_params.intensity != data.hsicData.intensity) {
243 ALOGD_IF(HSIC_SETTINGS_DEBUG,
244 "Intensity has changed from %d to %d",
245 mParams.params.pa_params.intensity,
246 data.hsicData.intensity);
247 needUpdate = true;
248 }
249
250 if (!isEqual(mParams.params.pa_params.contrast,
251 data.hsicData.contrast)) {
252 ALOGD_IF(HSIC_SETTINGS_DEBUG,
253 "Contrast has changed from %f to %f",
254 mParams.params.pa_params.contrast,
255 data.hsicData.contrast);
256 needUpdate = true;
257 }
258
259 if (needUpdate) {
260 mParams.params.pa_params.hue = data.hsicData.hue;
261 mParams.params.pa_params.sat = data.hsicData.saturation;
262 mParams.params.pa_params.intensity = data.hsicData.intensity;
263 mParams.params.pa_params.contrast = data.hsicData.contrast;
264 mParams.params.pa_params.ops = MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
265 mParams.operation |= PP_OP_PA;
266 }
267 }
268
269 if (data.operation & PP_PARAM_SHARP2) {
270 if (mParams.params.sharp_params.strength != data.Sharp2Data.strength) {
271 needUpdate = true;
272 }
273 if (mParams.params.sharp_params.edge_thr != data.Sharp2Data.edge_thr) {
274 needUpdate = true;
275 }
276 if (mParams.params.sharp_params.smooth_thr !=
277 data.Sharp2Data.smooth_thr) {
278 needUpdate = true;
279 }
280 if (mParams.params.sharp_params.noise_thr !=
281 data.Sharp2Data.noise_thr) {
282 needUpdate = true;
283 }
284
285 if (needUpdate) {
286 mParams.params.sharp_params.strength = data.Sharp2Data.strength;
287 mParams.params.sharp_params.edge_thr = data.Sharp2Data.edge_thr;
288 mParams.params.sharp_params.smooth_thr =
289 data.Sharp2Data.smooth_thr;
290 mParams.params.sharp_params.noise_thr = data.Sharp2Data.noise_thr;
291 mParams.params.sharp_params.ops =
292 MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
293 mParams.operation |= PP_OP_SHARP;
294 }
295 }
296
297 if (data.operation & PP_PARAM_IGC) {
298 if (mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data == NULL){
299 uint32_t *igcData
300 = (uint32_t *)malloc(2 * MAX_IGC_LUT_ENTRIES * sizeof(uint32_t));
301 if (!igcData) {
302 ALOGE("IGC storage allocated failed");
303 return false;
304 }
305 mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data = igcData;
306 mOVInfo.overlay_pp_cfg.igc_cfg.c2_data
307 = igcData + MAX_IGC_LUT_ENTRIES;
308 }
309
310 memcpy(mParams.params.igc_lut_params.c0,
311 data.igcData.c0, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
312 memcpy(mParams.params.igc_lut_params.c1,
313 data.igcData.c1, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
314 memcpy(mParams.params.igc_lut_params.c2,
315 data.igcData.c2, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
316
317 mParams.params.igc_lut_params.ops
318 = MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
319 mParams.operation |= PP_OP_IGC;
320 needUpdate = true;
321 }
322
323 if (data.operation & PP_PARAM_VID_INTFC) {
324 mParams.params.conv_params.interface =
325 (interface_type) data.video_interface;
326 needUpdate = true;
327 }
328
329 if (needUpdate) {
330 display_pp_compute_params(&mParams, &mOVInfo.overlay_pp_cfg);
Saurabh Shah5daeee52013-01-23 16:52:26 +0800331 }
332#endif
333 return true;
334}
335
Saurabh Shaha36be922013-12-16 18:18:39 -0800336bool MdpCtrl::validateAndSet(MdpCtrl* mdpCtrlArray[], const int& count,
337 const int& fbFd) {
338 mdp_overlay* ovArray[count];
339 memset(&ovArray, 0, sizeof(ovArray));
340
341 for(int i = 0; i < count; i++) {
342 ovArray[i] = &mdpCtrlArray[i]->mOVInfo;
343 }
344
345 struct mdp_overlay_list list;
346 memset(&list, 0, sizeof(struct mdp_overlay_list));
347 list.num_overlays = count;
348 list.overlay_list = ovArray;
349
Saurabh Shaheac146b2014-05-13 11:36:20 -0700350 int (*fnProgramScale)(struct mdp_overlay_list *) =
351 Overlay::getFnProgramScale();
352 if(fnProgramScale) {
353 fnProgramScale(&list);
Saurabh Shaha36be922013-12-16 18:18:39 -0800354 }
Saurabh Shaha36be922013-12-16 18:18:39 -0800355
356 if(!mdp_wrapper::validateAndSet(fbFd, list)) {
Jeykumar Sankaran1d9fc082014-04-01 15:21:55 -0700357 /* No dump for failure due to insufficient resource */
358 if(errno != E2BIG) {
Saurabh Shaha36be922013-12-16 18:18:39 -0800359 mdp_wrapper::dump("Bad ov dump: ",
360 *list.overlay_list[list.processed_overlays]);
361 }
362 return false;
363 }
364
365 return true;
366}
367
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700368
369//// MdpData ////////////
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800370bool MdpData::init(const int& dpy) {
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700371 int fbnum = Overlay::getFbForDpy(dpy);
372 if( fbnum < 0 ) {
373 ALOGE("%s: Invalid FB for the display: %d",__FUNCTION__, dpy);
374 return false;
375 }
376
377 // FD init
378 if(!utils::openDev(mFd, fbnum, Res::fbPath, O_RDWR)){
379 ALOGE("Ctrl failed to init fbnum=%d", fbnum);
380 return false;
381 }
382 return true;
383}
384
Naseer Ahmed29a26812012-06-14 00:56:20 -0700385} // overlay