blob: fbb173e53ef06f77a1f8bf9b5070f97c728e0136 [file] [log] [blame]
Naseer Ahmed29a26812012-06-14 00:56:20 -07001/*
2* Copyright (C) 2008 The Android Open Source Project
Raj kamal23f69b22012-11-17 00:20:55 +05303* Copyright (c) 2010-2013, 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
25#ifdef USES_QSEED_SCALAR
26#include <scale/scale.h>
27using namespace scale;
28#endif
Saurabh Shah5daeee52013-01-23 16:52:26 +080029
30#define HSIC_SETTINGS_DEBUG 0
31
Saurabh Shahbd2d0832013-04-04 14:33:08 -070032using namespace qdutils;
33
Saurabh Shah5daeee52013-01-23 16:52:26 +080034static inline bool isEqual(float f1, float f2) {
35 return ((int)(f1*100) == (int)(f2*100)) ? true : false;
36}
Naseer Ahmed29a26812012-06-14 00:56:20 -070037
Arun Kumar K.Re1ffd3e2013-06-13 12:14:11 -070038#ifdef ANDROID_JELLYBEAN_MR1
39//Since this is unavailable on Android 4.2.2, defining it in terms of base 10
Saurabh Shahbd2d0832013-04-04 14:33:08 -070040static inline float log2f(const float& x) {
41 return log(x) / log(2);
42}
Arun Kumar K.Re1ffd3e2013-06-13 12:14:11 -070043#endif
Saurabh Shahbd2d0832013-04-04 14:33:08 -070044
Naseer Ahmed29a26812012-06-14 00:56:20 -070045namespace ovutils = overlay::utils;
46namespace overlay {
Saurabh Shahb121e142012-08-20 17:59:13 -070047
Saurabh Shahb8f58e22013-09-26 16:20:07 -070048bool MdpCtrl::init(uint32_t dpy) {
49 int fbnum = Overlay::getFbForDpy(dpy);
50 if( fbnum < 0 ) {
51 ALOGE("%s: Invalid FB for the display: %d",__FUNCTION__, dpy);
52 return false;
53 }
54
Naseer Ahmedf48aef62012-07-20 09:05:53 -070055 // FD init
Naseer Ahmed29a26812012-06-14 00:56:20 -070056 if(!utils::openDev(mFd, fbnum,
Naseer Ahmedf48aef62012-07-20 09:05:53 -070057 Res::fbPath, O_RDWR)){
58 ALOGE("Ctrl failed to init fbnum=%d", fbnum);
Naseer Ahmed29a26812012-06-14 00:56:20 -070059 return false;
60 }
Saurabh Shahb8f58e22013-09-26 16:20:07 -070061 mDpy = dpy;
Naseer Ahmed29a26812012-06-14 00:56:20 -070062 return true;
63}
64
65void MdpCtrl::reset() {
66 utils::memset0(mOVInfo);
67 utils::memset0(mLkgo);
Naseer Ahmedf48aef62012-07-20 09:05:53 -070068 mOVInfo.id = MSMFB_NEW_REQUEST;
69 mLkgo.id = MSMFB_NEW_REQUEST;
70 mOrientation = utils::OVERLAY_TRANSFORM_0;
Saurabh Shahacf10202013-02-26 10:15:15 -080071 mDownscale = 0;
Saurabh Shahdf0be752013-05-23 14:40:00 -070072 mForceSet = false;
Saurabh Shahb8f58e22013-09-26 16:20:07 -070073 mDpy = 0;
Saurabh Shah5daeee52013-01-23 16:52:26 +080074#ifdef USES_POST_PROCESSING
75 mPPChanged = false;
76 memset(&mParams, 0, sizeof(struct compute_params));
77 mParams.params.conv_params.order = hsic_order_hsc_i;
78 mParams.params.conv_params.interface = interface_rec601;
79 mParams.params.conv_params.cc_matrix[0][0] = 1;
80 mParams.params.conv_params.cc_matrix[1][1] = 1;
81 mParams.params.conv_params.cc_matrix[2][2] = 1;
82#endif
Naseer Ahmed29a26812012-06-14 00:56:20 -070083}
84
85bool MdpCtrl::close() {
Saurabh Shah8e1ae952012-08-15 12:15:14 -070086 bool result = true;
Saurabh Shah8e1ae952012-08-15 12:15:14 -070087 if(MSMFB_NEW_REQUEST != static_cast<int>(mOVInfo.id)) {
88 if(!mdp_wrapper::unsetOverlay(mFd.getFD(), mOVInfo.id)) {
89 ALOGE("MdpCtrl close error in unset");
90 result = false;
91 }
Naseer Ahmed29a26812012-06-14 00:56:20 -070092 }
Saurabh Shah5daeee52013-01-23 16:52:26 +080093#ifdef USES_POST_PROCESSING
94 /* free allocated memory in PP */
95 if (mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data)
96 free(mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data);
97#endif
Naseer Ahmed29a26812012-06-14 00:56:20 -070098 reset();
Saurabh Shahacf10202013-02-26 10:15:15 -080099
Naseer Ahmed29a26812012-06-14 00:56:20 -0700100 if(!mFd.close()) {
Saurabh Shah8e1ae952012-08-15 12:15:14 -0700101 result = false;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700102 }
Saurabh Shah8e1ae952012-08-15 12:15:14 -0700103
104 return result;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700105}
106
Saurabh Shahacf10202013-02-26 10:15:15 -0800107void MdpCtrl::setSource(const utils::PipeArgs& args) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700108 setSrcWhf(args.whf);
109
110 //TODO These are hardcoded. Can be moved out of setSource.
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700111 mOVInfo.transp_mask = 0xffffffff;
112
113 //TODO These calls should ideally be a part of setPipeParams API
114 setFlags(args.mdpFlags);
115 setZ(args.zorder);
116 setIsFg(args.isFg);
Naseer Ahmed522ce662013-03-18 20:14:05 -0400117 setPlaneAlpha(args.planeAlpha);
118 setBlending(args.blending);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700119}
120
Saurabh Shahacf10202013-02-26 10:15:15 -0800121void MdpCtrl::setCrop(const utils::Dim& d) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700122 setSrcRectDim(d);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700123}
124
Sushil Chauhan897a9c32013-07-18 11:09:55 -0700125void MdpCtrl::setColor(const uint32_t color) {
126 mOVInfo.bg_color = color;
127}
128
Saurabh Shahacf10202013-02-26 10:15:15 -0800129void MdpCtrl::setPosition(const overlay::utils::Dim& d) {
130 setDstRectDim(d);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700131}
132
Saurabh Shahacf10202013-02-26 10:15:15 -0800133void MdpCtrl::setTransform(const utils::eTransform& orient) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700134 int rot = utils::getMdpOrient(orient);
135 setUserData(rot);
Saurabh Shaha73738d2012-08-09 18:15:18 -0700136 mOrientation = static_cast<utils::eTransform>(rot);
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800137}
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 Shahbd2d0832013-04-04 14:33:08 -0700149 int mdpVersion = MDPVersion::getInstance().getMDPVersion();
150 if(mdpVersion < MDSS_V5) {
151 mOVInfo.src_rect.x >>= mDownscale;
152 mOVInfo.src_rect.y >>= mDownscale;
153 mOVInfo.src_rect.w >>= mDownscale;
154 mOVInfo.src_rect.h >>= mDownscale;
155 } else if(MDPVersion::getInstance().supportsDecimation()) {
156 //Decimation + MDP Downscale
157 mOVInfo.horz_deci = 0;
158 mOVInfo.vert_deci = 0;
159 int minHorDeci = 0;
160 if(mOVInfo.src_rect.w > 2048) {
161 //If the client sends us something > what a layer mixer supports
162 //then it means it doesn't want to use split-pipe but wants us to
163 //decimate. A minimum decimation of 2 will ensure that the width is
164 //always within layer mixer limits.
165 minHorDeci = 2;
166 }
167
Saurabh Shah1a03d482013-05-29 13:44:20 -0700168 float horDscale = 0.0f;
169 float verDscale = 0.0f;
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700170
Saurabh Shah1a03d482013-05-29 13:44:20 -0700171 utils::getDecimationFactor(mOVInfo.src_rect.w, mOVInfo.src_rect.h,
172 mOVInfo.dst_rect.w, mOVInfo.dst_rect.h, horDscale, verDscale);
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700173
174 if(horDscale < minHorDeci)
175 horDscale = minHorDeci;
176
177 if((int)horDscale)
178 mOVInfo.horz_deci = (int)log2f(horDscale);
179
180 if((int)verDscale)
181 mOVInfo.vert_deci = (int)log2f(verDscale);
182 }
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800183}
184
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700185bool MdpCtrl::set() {
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700186 int mdpVersion = MDPVersion::getInstance().getMDPVersion();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700187 //deferred calcs, so APIs could be called in any order.
Saurabh Shahacf10202013-02-26 10:15:15 -0800188 doTransform();
Saurabh Shahb121e142012-08-20 17:59:13 -0700189 utils::Whf whf = getSrcWhf();
190 if(utils::isYuv(whf.format)) {
Sushil Chauhan1cac8152013-05-08 15:53:51 -0700191 utils::normalizeCrop(mOVInfo.src_rect.x, mOVInfo.src_rect.w);
192 utils::normalizeCrop(mOVInfo.src_rect.y, mOVInfo.src_rect.h);
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700193 if(mdpVersion < MDSS_V5) {
Saurabh Shahce416f02013-04-10 13:33:09 -0700194 utils::even_floor(mOVInfo.dst_rect.w);
195 utils::even_floor(mOVInfo.dst_rect.h);
Sushil Chauhan5491c8a2013-05-24 10:15:30 -0700196 } else if (mOVInfo.flags & MDP_DEINTERLACE) {
197 // For interlaced, crop.h should be 4-aligned
198 if (!(mOVInfo.flags & MDP_SOURCE_ROTATED_90) &&
199 (mOVInfo.src_rect.h % 4))
200 mOVInfo.src_rect.h = utils::aligndown(mOVInfo.src_rect.h, 4);
Saurabh Shahce416f02013-04-10 13:33:09 -0700201 }
Sushil Chauhan35fc68b2013-06-19 14:08:56 -0700202 } else {
203 if (mdpVersion >= MDSS_V5) {
204 // Check for 1-pixel down-scaling
205 if (mOVInfo.src_rect.w - mOVInfo.dst_rect.w == 1)
206 mOVInfo.src_rect.w -= 1;
207 if (mOVInfo.src_rect.h - mOVInfo.dst_rect.h == 1)
208 mOVInfo.src_rect.h -= 1;
209 }
Saurabh Shahb121e142012-08-20 17:59:13 -0700210 }
211
Sushil Chauhan35fc68b2013-06-19 14:08:56 -0700212 doDownscale();
213
Saurabh Shahdf0be752013-05-23 14:40:00 -0700214 if(this->ovChanged() || mForceSet) {
215 mForceSet = false;
Saurabh Shahfc2acbe2012-08-17 19:47:52 -0700216 if(!mdp_wrapper::setOverlay(mFd.getFD(), mOVInfo)) {
217 ALOGE("MdpCtrl failed to setOverlay, restoring last known "
218 "good ov info");
219 mdp_wrapper::dump("== Bad OVInfo is: ", mOVInfo);
220 mdp_wrapper::dump("== Last good known OVInfo is: ", mLkgo);
221 this->restore();
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700222#ifdef USES_QSEED_SCALAR
223 if(Overlay::getScalar()) {
224 Overlay::getScalar()->configAbort(mDpy);
225 }
226#endif
Saurabh Shahfc2acbe2012-08-17 19:47:52 -0700227 return false;
228 }
229 this->save();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700230 }
Saurabh Shahb121e142012-08-20 17:59:13 -0700231
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700232#ifdef USES_QSEED_SCALAR
233 if(Overlay::getScalar()) {
234 Overlay::getScalar()->configSet(mOVInfo, mDpy, mFd.getFD());
235 }
236#endif
237
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700238 return true;
239}
240
Naseer Ahmed29a26812012-06-14 00:56:20 -0700241bool MdpCtrl::get() {
242 mdp_overlay ov;
243 ov.id = mOVInfo.id;
244 if (!mdp_wrapper::getOverlay(mFd.getFD(), ov)) {
245 ALOGE("MdpCtrl get failed");
246 return false;
247 }
248 mOVInfo = ov;
249 return true;
250}
251
Saurabh Shahacf10202013-02-26 10:15:15 -0800252//Update src format based on rotator's destination format.
253void MdpCtrl::updateSrcFormat(const uint32_t& rotDestFmt) {
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800254 utils::Whf whf = getSrcWhf();
Saurabh Shahacf10202013-02-26 10:15:15 -0800255 whf.format = rotDestFmt;
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800256 setSrcWhf(whf);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700257}
258
259void MdpCtrl::dump() const {
260 ALOGE("== Dump MdpCtrl start ==");
Naseer Ahmed29a26812012-06-14 00:56:20 -0700261 mFd.dump();
262 mdp_wrapper::dump("mOVInfo", mOVInfo);
263 ALOGE("== Dump MdpCtrl end ==");
264}
265
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800266void MdpCtrl::getDump(char *buf, size_t len) {
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700267 ovutils::getDump(buf, len, "Ctrl", mOVInfo);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800268}
269
Naseer Ahmed29a26812012-06-14 00:56:20 -0700270void MdpData::dump() const {
271 ALOGE("== Dump MdpData start ==");
272 mFd.dump();
273 mdp_wrapper::dump("mOvData", mOvData);
274 ALOGE("== Dump MdpData end ==");
275}
276
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800277void MdpData::getDump(char *buf, size_t len) {
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700278 ovutils::getDump(buf, len, "Data", mOvData);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800279}
280
Naseer Ahmed29a26812012-06-14 00:56:20 -0700281void MdpCtrl3D::dump() const {
282 ALOGE("== Dump MdpCtrl start ==");
283 mFd.dump();
284 ALOGE("== Dump MdpCtrl end ==");
285}
286
Saurabh Shah5daeee52013-01-23 16:52:26 +0800287bool MdpCtrl::setVisualParams(const MetaData_t& data) {
288 bool needUpdate = false;
289#ifdef USES_POST_PROCESSING
290 /* calculate the data */
291 if (data.operation & PP_PARAM_HSIC) {
292 if (mParams.params.pa_params.hue != data.hsicData.hue) {
293 ALOGD_IF(HSIC_SETTINGS_DEBUG,
294 "Hue has changed from %d to %d",
295 mParams.params.pa_params.hue,data.hsicData.hue);
296 needUpdate = true;
297 }
298
299 if (!isEqual(mParams.params.pa_params.sat,
300 data.hsicData.saturation)) {
301 ALOGD_IF(HSIC_SETTINGS_DEBUG,
302 "Saturation has changed from %f to %f",
303 mParams.params.pa_params.sat,
304 data.hsicData.saturation);
305 needUpdate = true;
306 }
307
308 if (mParams.params.pa_params.intensity != data.hsicData.intensity) {
309 ALOGD_IF(HSIC_SETTINGS_DEBUG,
310 "Intensity has changed from %d to %d",
311 mParams.params.pa_params.intensity,
312 data.hsicData.intensity);
313 needUpdate = true;
314 }
315
316 if (!isEqual(mParams.params.pa_params.contrast,
317 data.hsicData.contrast)) {
318 ALOGD_IF(HSIC_SETTINGS_DEBUG,
319 "Contrast has changed from %f to %f",
320 mParams.params.pa_params.contrast,
321 data.hsicData.contrast);
322 needUpdate = true;
323 }
324
325 if (needUpdate) {
326 mParams.params.pa_params.hue = data.hsicData.hue;
327 mParams.params.pa_params.sat = data.hsicData.saturation;
328 mParams.params.pa_params.intensity = data.hsicData.intensity;
329 mParams.params.pa_params.contrast = data.hsicData.contrast;
330 mParams.params.pa_params.ops = MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
331 mParams.operation |= PP_OP_PA;
332 }
333 }
334
335 if (data.operation & PP_PARAM_SHARP2) {
336 if (mParams.params.sharp_params.strength != data.Sharp2Data.strength) {
337 needUpdate = true;
338 }
339 if (mParams.params.sharp_params.edge_thr != data.Sharp2Data.edge_thr) {
340 needUpdate = true;
341 }
342 if (mParams.params.sharp_params.smooth_thr !=
343 data.Sharp2Data.smooth_thr) {
344 needUpdate = true;
345 }
346 if (mParams.params.sharp_params.noise_thr !=
347 data.Sharp2Data.noise_thr) {
348 needUpdate = true;
349 }
350
351 if (needUpdate) {
352 mParams.params.sharp_params.strength = data.Sharp2Data.strength;
353 mParams.params.sharp_params.edge_thr = data.Sharp2Data.edge_thr;
354 mParams.params.sharp_params.smooth_thr =
355 data.Sharp2Data.smooth_thr;
356 mParams.params.sharp_params.noise_thr = data.Sharp2Data.noise_thr;
357 mParams.params.sharp_params.ops =
358 MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
359 mParams.operation |= PP_OP_SHARP;
360 }
361 }
362
363 if (data.operation & PP_PARAM_IGC) {
364 if (mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data == NULL){
365 uint32_t *igcData
366 = (uint32_t *)malloc(2 * MAX_IGC_LUT_ENTRIES * sizeof(uint32_t));
367 if (!igcData) {
368 ALOGE("IGC storage allocated failed");
369 return false;
370 }
371 mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data = igcData;
372 mOVInfo.overlay_pp_cfg.igc_cfg.c2_data
373 = igcData + MAX_IGC_LUT_ENTRIES;
374 }
375
376 memcpy(mParams.params.igc_lut_params.c0,
377 data.igcData.c0, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
378 memcpy(mParams.params.igc_lut_params.c1,
379 data.igcData.c1, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
380 memcpy(mParams.params.igc_lut_params.c2,
381 data.igcData.c2, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
382
383 mParams.params.igc_lut_params.ops
384 = MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
385 mParams.operation |= PP_OP_IGC;
386 needUpdate = true;
387 }
388
389 if (data.operation & PP_PARAM_VID_INTFC) {
390 mParams.params.conv_params.interface =
391 (interface_type) data.video_interface;
392 needUpdate = true;
393 }
394
395 if (needUpdate) {
396 display_pp_compute_params(&mParams, &mOVInfo.overlay_pp_cfg);
397 mPPChanged = true;
398 }
399#endif
400 return true;
401}
402
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700403
404//// MdpData ////////////
405bool MdpData::init(uint32_t dpy) {
406 int fbnum = Overlay::getFbForDpy(dpy);
407 if( fbnum < 0 ) {
408 ALOGE("%s: Invalid FB for the display: %d",__FUNCTION__, dpy);
409 return false;
410 }
411
412 // FD init
413 if(!utils::openDev(mFd, fbnum, Res::fbPath, O_RDWR)){
414 ALOGE("Ctrl failed to init fbnum=%d", fbnum);
415 return false;
416 }
417 return true;
418}
419
Naseer Ahmed29a26812012-06-14 00:56:20 -0700420} // overlay