blob: 4622d16b9aa2624527834f9bfe5dab938dd2630a [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()) {
157 //Decimation + MDP Downscale
158 mOVInfo.horz_deci = 0;
159 mOVInfo.vert_deci = 0;
160 int minHorDeci = 0;
161 if(mOVInfo.src_rect.w > 2048) {
162 //If the client sends us something > what a layer mixer supports
163 //then it means it doesn't want to use split-pipe but wants us to
164 //decimate. A minimum decimation of 2 will ensure that the width is
165 //always within layer mixer limits.
166 minHorDeci = 2;
167 }
168
Saurabh Shah1a03d482013-05-29 13:44:20 -0700169 float horDscale = 0.0f;
170 float verDscale = 0.0f;
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700171
Saurabh Shah1a03d482013-05-29 13:44:20 -0700172 utils::getDecimationFactor(mOVInfo.src_rect.w, mOVInfo.src_rect.h,
173 mOVInfo.dst_rect.w, mOVInfo.dst_rect.h, horDscale, verDscale);
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700174
175 if(horDscale < minHorDeci)
176 horDscale = minHorDeci;
177
178 if((int)horDscale)
179 mOVInfo.horz_deci = (int)log2f(horDscale);
180
181 if((int)verDscale)
182 mOVInfo.vert_deci = (int)log2f(verDscale);
183 }
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800184}
185
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700186bool MdpCtrl::set() {
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700187 int mdpVersion = MDPVersion::getInstance().getMDPVersion();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700188 //deferred calcs, so APIs could be called in any order.
Saurabh Shahacf10202013-02-26 10:15:15 -0800189 doTransform();
Saurabh Shahb121e142012-08-20 17:59:13 -0700190 utils::Whf whf = getSrcWhf();
191 if(utils::isYuv(whf.format)) {
Sushil Chauhan1cac8152013-05-08 15:53:51 -0700192 utils::normalizeCrop(mOVInfo.src_rect.x, mOVInfo.src_rect.w);
193 utils::normalizeCrop(mOVInfo.src_rect.y, mOVInfo.src_rect.h);
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700194 if(mdpVersion < MDSS_V5) {
Saurabh Shahce416f02013-04-10 13:33:09 -0700195 utils::even_floor(mOVInfo.dst_rect.w);
196 utils::even_floor(mOVInfo.dst_rect.h);
Sushil Chauhan5491c8a2013-05-24 10:15:30 -0700197 } else if (mOVInfo.flags & MDP_DEINTERLACE) {
198 // For interlaced, crop.h should be 4-aligned
199 if (!(mOVInfo.flags & MDP_SOURCE_ROTATED_90) &&
200 (mOVInfo.src_rect.h % 4))
201 mOVInfo.src_rect.h = utils::aligndown(mOVInfo.src_rect.h, 4);
Sravan Kumar D.V.Na34dc852014-03-26 19:13:11 +0530202 // For interlaced, width must be multiple of 4 when rotated 90deg.
203 else if ((mOVInfo.flags & MDP_SOURCE_ROTATED_90) &&
204 (mOVInfo.src_rect.w % 4))
205 mOVInfo.src_rect.w = utils::aligndown(mOVInfo.src_rect.w, 4);
Saurabh Shahce416f02013-04-10 13:33:09 -0700206 }
Sushil Chauhan35fc68b2013-06-19 14:08:56 -0700207 } else {
208 if (mdpVersion >= MDSS_V5) {
209 // Check for 1-pixel down-scaling
210 if (mOVInfo.src_rect.w - mOVInfo.dst_rect.w == 1)
211 mOVInfo.src_rect.w -= 1;
212 if (mOVInfo.src_rect.h - mOVInfo.dst_rect.h == 1)
213 mOVInfo.src_rect.h -= 1;
214 }
Saurabh Shahb121e142012-08-20 17:59:13 -0700215 }
216
Sushil Chauhan35fc68b2013-06-19 14:08:56 -0700217 doDownscale();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700218 return true;
219}
220
Saurabh Shahacf10202013-02-26 10:15:15 -0800221//Update src format based on rotator's destination format.
222void MdpCtrl::updateSrcFormat(const uint32_t& rotDestFmt) {
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800223 utils::Whf whf = getSrcWhf();
Saurabh Shahacf10202013-02-26 10:15:15 -0800224 whf.format = rotDestFmt;
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800225 setSrcWhf(whf);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700226}
227
228void MdpCtrl::dump() const {
229 ALOGE("== Dump MdpCtrl start ==");
Naseer Ahmed29a26812012-06-14 00:56:20 -0700230 mFd.dump();
231 mdp_wrapper::dump("mOVInfo", mOVInfo);
232 ALOGE("== Dump MdpCtrl end ==");
233}
234
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800235void MdpCtrl::getDump(char *buf, size_t len) {
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700236 ovutils::getDump(buf, len, "Ctrl", mOVInfo);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800237}
238
Naseer Ahmed29a26812012-06-14 00:56:20 -0700239void MdpData::dump() const {
240 ALOGE("== Dump MdpData start ==");
241 mFd.dump();
242 mdp_wrapper::dump("mOvData", mOvData);
243 ALOGE("== Dump MdpData end ==");
244}
245
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800246void MdpData::getDump(char *buf, size_t len) {
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700247 ovutils::getDump(buf, len, "Data", mOvData);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800248}
249
Naseer Ahmed29a26812012-06-14 00:56:20 -0700250void MdpCtrl3D::dump() const {
251 ALOGE("== Dump MdpCtrl start ==");
252 mFd.dump();
253 ALOGE("== Dump MdpCtrl end ==");
254}
255
Saurabh Shah5daeee52013-01-23 16:52:26 +0800256bool MdpCtrl::setVisualParams(const MetaData_t& data) {
Arun Kumar K.R7e5a1f82014-01-22 10:36:16 -0800257 ALOGD_IF(0, "In %s: data.operation = %d", __FUNCTION__, data.operation);
Saurabh Shah5daeee52013-01-23 16:52:26 +0800258#ifdef USES_POST_PROCESSING
Arun Kumar K.R7e5a1f82014-01-22 10:36:16 -0800259 bool needUpdate = false;
Saurabh Shah5daeee52013-01-23 16:52:26 +0800260 /* calculate the data */
261 if (data.operation & PP_PARAM_HSIC) {
262 if (mParams.params.pa_params.hue != data.hsicData.hue) {
263 ALOGD_IF(HSIC_SETTINGS_DEBUG,
264 "Hue has changed from %d to %d",
265 mParams.params.pa_params.hue,data.hsicData.hue);
266 needUpdate = true;
267 }
268
269 if (!isEqual(mParams.params.pa_params.sat,
270 data.hsicData.saturation)) {
271 ALOGD_IF(HSIC_SETTINGS_DEBUG,
272 "Saturation has changed from %f to %f",
273 mParams.params.pa_params.sat,
274 data.hsicData.saturation);
275 needUpdate = true;
276 }
277
278 if (mParams.params.pa_params.intensity != data.hsicData.intensity) {
279 ALOGD_IF(HSIC_SETTINGS_DEBUG,
280 "Intensity has changed from %d to %d",
281 mParams.params.pa_params.intensity,
282 data.hsicData.intensity);
283 needUpdate = true;
284 }
285
286 if (!isEqual(mParams.params.pa_params.contrast,
287 data.hsicData.contrast)) {
288 ALOGD_IF(HSIC_SETTINGS_DEBUG,
289 "Contrast has changed from %f to %f",
290 mParams.params.pa_params.contrast,
291 data.hsicData.contrast);
292 needUpdate = true;
293 }
294
295 if (needUpdate) {
296 mParams.params.pa_params.hue = data.hsicData.hue;
297 mParams.params.pa_params.sat = data.hsicData.saturation;
298 mParams.params.pa_params.intensity = data.hsicData.intensity;
299 mParams.params.pa_params.contrast = data.hsicData.contrast;
300 mParams.params.pa_params.ops = MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
301 mParams.operation |= PP_OP_PA;
302 }
303 }
304
305 if (data.operation & PP_PARAM_SHARP2) {
306 if (mParams.params.sharp_params.strength != data.Sharp2Data.strength) {
307 needUpdate = true;
308 }
309 if (mParams.params.sharp_params.edge_thr != data.Sharp2Data.edge_thr) {
310 needUpdate = true;
311 }
312 if (mParams.params.sharp_params.smooth_thr !=
313 data.Sharp2Data.smooth_thr) {
314 needUpdate = true;
315 }
316 if (mParams.params.sharp_params.noise_thr !=
317 data.Sharp2Data.noise_thr) {
318 needUpdate = true;
319 }
320
321 if (needUpdate) {
322 mParams.params.sharp_params.strength = data.Sharp2Data.strength;
323 mParams.params.sharp_params.edge_thr = data.Sharp2Data.edge_thr;
324 mParams.params.sharp_params.smooth_thr =
325 data.Sharp2Data.smooth_thr;
326 mParams.params.sharp_params.noise_thr = data.Sharp2Data.noise_thr;
327 mParams.params.sharp_params.ops =
328 MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
329 mParams.operation |= PP_OP_SHARP;
330 }
331 }
332
333 if (data.operation & PP_PARAM_IGC) {
334 if (mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data == NULL){
335 uint32_t *igcData
336 = (uint32_t *)malloc(2 * MAX_IGC_LUT_ENTRIES * sizeof(uint32_t));
337 if (!igcData) {
338 ALOGE("IGC storage allocated failed");
339 return false;
340 }
341 mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data = igcData;
342 mOVInfo.overlay_pp_cfg.igc_cfg.c2_data
343 = igcData + MAX_IGC_LUT_ENTRIES;
344 }
345
346 memcpy(mParams.params.igc_lut_params.c0,
347 data.igcData.c0, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
348 memcpy(mParams.params.igc_lut_params.c1,
349 data.igcData.c1, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
350 memcpy(mParams.params.igc_lut_params.c2,
351 data.igcData.c2, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
352
353 mParams.params.igc_lut_params.ops
354 = MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
355 mParams.operation |= PP_OP_IGC;
356 needUpdate = true;
357 }
358
359 if (data.operation & PP_PARAM_VID_INTFC) {
360 mParams.params.conv_params.interface =
361 (interface_type) data.video_interface;
362 needUpdate = true;
363 }
364
365 if (needUpdate) {
366 display_pp_compute_params(&mParams, &mOVInfo.overlay_pp_cfg);
Saurabh Shah5daeee52013-01-23 16:52:26 +0800367 }
368#endif
369 return true;
370}
371
Saurabh Shaha36be922013-12-16 18:18:39 -0800372bool MdpCtrl::validateAndSet(MdpCtrl* mdpCtrlArray[], const int& count,
373 const int& fbFd) {
374 mdp_overlay* ovArray[count];
375 memset(&ovArray, 0, sizeof(ovArray));
376
377 for(int i = 0; i < count; i++) {
378 ovArray[i] = &mdpCtrlArray[i]->mOVInfo;
379 }
380
381 struct mdp_overlay_list list;
382 memset(&list, 0, sizeof(struct mdp_overlay_list));
383 list.num_overlays = count;
384 list.overlay_list = ovArray;
385
Saurabh Shaheac146b2014-05-13 11:36:20 -0700386 int (*fnProgramScale)(struct mdp_overlay_list *) =
387 Overlay::getFnProgramScale();
388 if(fnProgramScale) {
389 fnProgramScale(&list);
Saurabh Shaha36be922013-12-16 18:18:39 -0800390 }
Saurabh Shaha36be922013-12-16 18:18:39 -0800391
392 if(!mdp_wrapper::validateAndSet(fbFd, list)) {
Jeykumar Sankaran1d9fc082014-04-01 15:21:55 -0700393 /* No dump for failure due to insufficient resource */
394 if(errno != E2BIG) {
Saurabh Shaha36be922013-12-16 18:18:39 -0800395 mdp_wrapper::dump("Bad ov dump: ",
396 *list.overlay_list[list.processed_overlays]);
397 }
398 return false;
399 }
400
401 return true;
402}
403
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700404
405//// MdpData ////////////
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800406bool MdpData::init(const int& dpy) {
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700407 int fbnum = Overlay::getFbForDpy(dpy);
408 if( fbnum < 0 ) {
409 ALOGE("%s: Invalid FB for the display: %d",__FUNCTION__, dpy);
410 return false;
411 }
412
413 // FD init
414 if(!utils::openDev(mFd, fbnum, Res::fbPath, O_RDWR)){
415 ALOGE("Ctrl failed to init fbnum=%d", fbnum);
416 return false;
417 }
418 return true;
419}
420
Naseer Ahmed29a26812012-06-14 00:56:20 -0700421} // overlay