blob: 4bdefc5c5b24d55d06b92b0d1126b2e4e2a9aa1f [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 Shahacf10202013-02-26 10:15:15 -080057 mDownscale = 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);
100 setIsFg(args.isFg);
Naseer Ahmed522ce662013-03-18 20:14:05 -0400101 setPlaneAlpha(args.planeAlpha);
102 setBlending(args.blending);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700103}
104
Saurabh Shahacf10202013-02-26 10:15:15 -0800105void MdpCtrl::setCrop(const utils::Dim& d) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700106 setSrcRectDim(d);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700107}
108
Sushil Chauhan897a9c32013-07-18 11:09:55 -0700109void MdpCtrl::setColor(const uint32_t color) {
110 mOVInfo.bg_color = color;
111}
112
Saurabh Shahacf10202013-02-26 10:15:15 -0800113void MdpCtrl::setPosition(const overlay::utils::Dim& d) {
114 setDstRectDim(d);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700115}
116
Saurabh Shahacf10202013-02-26 10:15:15 -0800117void MdpCtrl::setTransform(const utils::eTransform& orient) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700118 int rot = utils::getMdpOrient(orient);
119 setUserData(rot);
Saurabh Shaha73738d2012-08-09 18:15:18 -0700120 mOrientation = static_cast<utils::eTransform>(rot);
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800121}
122
radhakrishna8ccb9082014-05-09 16:18:43 +0530123void MdpCtrl::setPipeType(const utils::eMdpPipeType& pType){
124 switch((int) pType){
125 case utils::OV_MDP_PIPE_RGB:
126 mOVInfo.pipe_type = PIPE_TYPE_RGB;
127 break;
128 case utils::OV_MDP_PIPE_VG:
129 mOVInfo.pipe_type = PIPE_TYPE_VIG;
130 break;
131 case utils::OV_MDP_PIPE_DMA:
132 mOVInfo.pipe_type = PIPE_TYPE_DMA;
133 break;
134 default:
135 mOVInfo.pipe_type = PIPE_TYPE_AUTO;
136 break;
137 }
138}
139
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700140void MdpCtrl::doTransform() {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700141 setRotationFlags();
Saurabh Shahacf10202013-02-26 10:15:15 -0800142 utils::Whf whf = getSrcWhf();
143 utils::Dim dim = getSrcRectDim();
144 utils::preRotateSource(mOrientation, whf, dim);
145 setSrcWhf(whf);
146 setSrcRectDim(dim);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700147}
148
Saurabh Shahacf10202013-02-26 10:15:15 -0800149void MdpCtrl::doDownscale() {
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700150 int mdpVersion = MDPVersion::getInstance().getMDPVersion();
151 if(mdpVersion < MDSS_V5) {
152 mOVInfo.src_rect.x >>= mDownscale;
153 mOVInfo.src_rect.y >>= mDownscale;
154 mOVInfo.src_rect.w >>= mDownscale;
155 mOVInfo.src_rect.h >>= mDownscale;
156 } else if(MDPVersion::getInstance().supportsDecimation()) {
Saurabh Shah1a03d482013-05-29 13:44:20 -0700157 utils::getDecimationFactor(mOVInfo.src_rect.w, mOVInfo.src_rect.h,
Saurabh Shahb6810df2014-06-17 16:00:22 -0700158 mOVInfo.dst_rect.w, mOVInfo.dst_rect.h, mOVInfo.horz_deci,
159 mOVInfo.vert_deci);
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700160 }
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800161}
162
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700163bool MdpCtrl::set() {
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700164 int mdpVersion = MDPVersion::getInstance().getMDPVersion();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700165 //deferred calcs, so APIs could be called in any order.
Saurabh Shahacf10202013-02-26 10:15:15 -0800166 doTransform();
Saurabh Shahb121e142012-08-20 17:59:13 -0700167 utils::Whf whf = getSrcWhf();
168 if(utils::isYuv(whf.format)) {
Sushil Chauhan1cac8152013-05-08 15:53:51 -0700169 utils::normalizeCrop(mOVInfo.src_rect.x, mOVInfo.src_rect.w);
170 utils::normalizeCrop(mOVInfo.src_rect.y, mOVInfo.src_rect.h);
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700171 if(mdpVersion < MDSS_V5) {
Saurabh Shahce416f02013-04-10 13:33:09 -0700172 utils::even_floor(mOVInfo.dst_rect.w);
173 utils::even_floor(mOVInfo.dst_rect.h);
Sushil Chauhan5491c8a2013-05-24 10:15:30 -0700174 } else if (mOVInfo.flags & MDP_DEINTERLACE) {
175 // For interlaced, crop.h should be 4-aligned
176 if (!(mOVInfo.flags & MDP_SOURCE_ROTATED_90) &&
177 (mOVInfo.src_rect.h % 4))
178 mOVInfo.src_rect.h = utils::aligndown(mOVInfo.src_rect.h, 4);
Sravan Kumar D.V.Na34dc852014-03-26 19:13:11 +0530179 // For interlaced, width must be multiple of 4 when rotated 90deg.
180 else if ((mOVInfo.flags & MDP_SOURCE_ROTATED_90) &&
181 (mOVInfo.src_rect.w % 4))
182 mOVInfo.src_rect.w = utils::aligndown(mOVInfo.src_rect.w, 4);
Saurabh Shahce416f02013-04-10 13:33:09 -0700183 }
Sushil Chauhan35fc68b2013-06-19 14:08:56 -0700184 } else {
185 if (mdpVersion >= MDSS_V5) {
186 // Check for 1-pixel down-scaling
187 if (mOVInfo.src_rect.w - mOVInfo.dst_rect.w == 1)
188 mOVInfo.src_rect.w -= 1;
189 if (mOVInfo.src_rect.h - mOVInfo.dst_rect.h == 1)
190 mOVInfo.src_rect.h -= 1;
191 }
Saurabh Shahb121e142012-08-20 17:59:13 -0700192 }
193
Sushil Chauhan35fc68b2013-06-19 14:08:56 -0700194 doDownscale();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700195 return true;
196}
197
Saurabh Shahacf10202013-02-26 10:15:15 -0800198//Update src format based on rotator's destination format.
199void MdpCtrl::updateSrcFormat(const uint32_t& rotDestFmt) {
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800200 utils::Whf whf = getSrcWhf();
Saurabh Shahacf10202013-02-26 10:15:15 -0800201 whf.format = rotDestFmt;
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800202 setSrcWhf(whf);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700203}
204
205void MdpCtrl::dump() const {
206 ALOGE("== Dump MdpCtrl start ==");
Naseer Ahmed29a26812012-06-14 00:56:20 -0700207 mFd.dump();
208 mdp_wrapper::dump("mOVInfo", mOVInfo);
209 ALOGE("== Dump MdpCtrl end ==");
210}
211
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800212void MdpCtrl::getDump(char *buf, size_t len) {
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700213 ovutils::getDump(buf, len, "Ctrl", mOVInfo);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800214}
215
Naseer Ahmed29a26812012-06-14 00:56:20 -0700216void MdpData::dump() const {
217 ALOGE("== Dump MdpData start ==");
218 mFd.dump();
219 mdp_wrapper::dump("mOvData", mOvData);
220 ALOGE("== Dump MdpData end ==");
221}
222
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800223void MdpData::getDump(char *buf, size_t len) {
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700224 ovutils::getDump(buf, len, "Data", mOvData);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800225}
226
Naseer Ahmed29a26812012-06-14 00:56:20 -0700227void MdpCtrl3D::dump() const {
228 ALOGE("== Dump MdpCtrl start ==");
229 mFd.dump();
230 ALOGE("== Dump MdpCtrl end ==");
231}
232
Saurabh Shah5daeee52013-01-23 16:52:26 +0800233bool MdpCtrl::setVisualParams(const MetaData_t& data) {
Arun Kumar K.R7e5a1f82014-01-22 10:36:16 -0800234 ALOGD_IF(0, "In %s: data.operation = %d", __FUNCTION__, data.operation);
Saurabh Shah5daeee52013-01-23 16:52:26 +0800235#ifdef USES_POST_PROCESSING
Arun Kumar K.R7e5a1f82014-01-22 10:36:16 -0800236 bool needUpdate = false;
Saurabh Shah5daeee52013-01-23 16:52:26 +0800237 /* calculate the data */
238 if (data.operation & PP_PARAM_HSIC) {
239 if (mParams.params.pa_params.hue != data.hsicData.hue) {
240 ALOGD_IF(HSIC_SETTINGS_DEBUG,
241 "Hue has changed from %d to %d",
242 mParams.params.pa_params.hue,data.hsicData.hue);
243 needUpdate = true;
244 }
245
246 if (!isEqual(mParams.params.pa_params.sat,
247 data.hsicData.saturation)) {
248 ALOGD_IF(HSIC_SETTINGS_DEBUG,
249 "Saturation has changed from %f to %f",
250 mParams.params.pa_params.sat,
251 data.hsicData.saturation);
252 needUpdate = true;
253 }
254
255 if (mParams.params.pa_params.intensity != data.hsicData.intensity) {
256 ALOGD_IF(HSIC_SETTINGS_DEBUG,
257 "Intensity has changed from %d to %d",
258 mParams.params.pa_params.intensity,
259 data.hsicData.intensity);
260 needUpdate = true;
261 }
262
263 if (!isEqual(mParams.params.pa_params.contrast,
264 data.hsicData.contrast)) {
265 ALOGD_IF(HSIC_SETTINGS_DEBUG,
266 "Contrast has changed from %f to %f",
267 mParams.params.pa_params.contrast,
268 data.hsicData.contrast);
269 needUpdate = true;
270 }
271
272 if (needUpdate) {
273 mParams.params.pa_params.hue = data.hsicData.hue;
274 mParams.params.pa_params.sat = data.hsicData.saturation;
275 mParams.params.pa_params.intensity = data.hsicData.intensity;
276 mParams.params.pa_params.contrast = data.hsicData.contrast;
277 mParams.params.pa_params.ops = MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
278 mParams.operation |= PP_OP_PA;
279 }
280 }
281
282 if (data.operation & PP_PARAM_SHARP2) {
283 if (mParams.params.sharp_params.strength != data.Sharp2Data.strength) {
284 needUpdate = true;
285 }
286 if (mParams.params.sharp_params.edge_thr != data.Sharp2Data.edge_thr) {
287 needUpdate = true;
288 }
289 if (mParams.params.sharp_params.smooth_thr !=
290 data.Sharp2Data.smooth_thr) {
291 needUpdate = true;
292 }
293 if (mParams.params.sharp_params.noise_thr !=
294 data.Sharp2Data.noise_thr) {
295 needUpdate = true;
296 }
297
298 if (needUpdate) {
299 mParams.params.sharp_params.strength = data.Sharp2Data.strength;
300 mParams.params.sharp_params.edge_thr = data.Sharp2Data.edge_thr;
301 mParams.params.sharp_params.smooth_thr =
302 data.Sharp2Data.smooth_thr;
303 mParams.params.sharp_params.noise_thr = data.Sharp2Data.noise_thr;
304 mParams.params.sharp_params.ops =
305 MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
306 mParams.operation |= PP_OP_SHARP;
307 }
308 }
309
310 if (data.operation & PP_PARAM_IGC) {
311 if (mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data == NULL){
312 uint32_t *igcData
313 = (uint32_t *)malloc(2 * MAX_IGC_LUT_ENTRIES * sizeof(uint32_t));
314 if (!igcData) {
315 ALOGE("IGC storage allocated failed");
316 return false;
317 }
318 mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data = igcData;
319 mOVInfo.overlay_pp_cfg.igc_cfg.c2_data
320 = igcData + MAX_IGC_LUT_ENTRIES;
321 }
322
323 memcpy(mParams.params.igc_lut_params.c0,
324 data.igcData.c0, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
325 memcpy(mParams.params.igc_lut_params.c1,
326 data.igcData.c1, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
327 memcpy(mParams.params.igc_lut_params.c2,
328 data.igcData.c2, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
329
330 mParams.params.igc_lut_params.ops
331 = MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
332 mParams.operation |= PP_OP_IGC;
333 needUpdate = true;
334 }
335
336 if (data.operation & PP_PARAM_VID_INTFC) {
337 mParams.params.conv_params.interface =
338 (interface_type) data.video_interface;
339 needUpdate = true;
340 }
341
342 if (needUpdate) {
343 display_pp_compute_params(&mParams, &mOVInfo.overlay_pp_cfg);
Saurabh Shah5daeee52013-01-23 16:52:26 +0800344 }
345#endif
346 return true;
347}
348
Saurabh Shaha36be922013-12-16 18:18:39 -0800349bool MdpCtrl::validateAndSet(MdpCtrl* mdpCtrlArray[], const int& count,
350 const int& fbFd) {
351 mdp_overlay* ovArray[count];
352 memset(&ovArray, 0, sizeof(ovArray));
353
354 for(int i = 0; i < count; i++) {
355 ovArray[i] = &mdpCtrlArray[i]->mOVInfo;
356 }
357
358 struct mdp_overlay_list list;
359 memset(&list, 0, sizeof(struct mdp_overlay_list));
360 list.num_overlays = count;
361 list.overlay_list = ovArray;
362
Saurabh Shaheac146b2014-05-13 11:36:20 -0700363 int (*fnProgramScale)(struct mdp_overlay_list *) =
364 Overlay::getFnProgramScale();
365 if(fnProgramScale) {
366 fnProgramScale(&list);
Saurabh Shaha36be922013-12-16 18:18:39 -0800367 }
Saurabh Shaha36be922013-12-16 18:18:39 -0800368
369 if(!mdp_wrapper::validateAndSet(fbFd, list)) {
Jeykumar Sankaran1d9fc082014-04-01 15:21:55 -0700370 /* No dump for failure due to insufficient resource */
371 if(errno != E2BIG) {
Saurabh Shaha36be922013-12-16 18:18:39 -0800372 mdp_wrapper::dump("Bad ov dump: ",
373 *list.overlay_list[list.processed_overlays]);
374 }
375 return false;
376 }
377
378 return true;
379}
380
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700381
382//// MdpData ////////////
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800383bool MdpData::init(const int& dpy) {
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700384 int fbnum = Overlay::getFbForDpy(dpy);
385 if( fbnum < 0 ) {
386 ALOGE("%s: Invalid FB for the display: %d",__FUNCTION__, dpy);
387 return false;
388 }
389
390 // FD init
391 if(!utils::openDev(mFd, fbnum, Res::fbPath, O_RDWR)){
392 ALOGE("Ctrl failed to init fbnum=%d", fbnum);
393 return false;
394 }
395 return true;
396}
397
Naseer Ahmed29a26812012-06-14 00:56:20 -0700398} // overlay