blob: 5da8b5562129bf3fb3c8fef2431522b7449283dd [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"
23
24#define HSIC_SETTINGS_DEBUG 0
25
Saurabh Shahbd2d0832013-04-04 14:33:08 -070026using namespace qdutils;
27
Saurabh Shah5daeee52013-01-23 16:52:26 +080028static inline bool isEqual(float f1, float f2) {
29 return ((int)(f1*100) == (int)(f2*100)) ? true : false;
30}
Naseer Ahmed29a26812012-06-14 00:56:20 -070031
Arun Kumar K.Re1ffd3e2013-06-13 12:14:11 -070032#ifdef ANDROID_JELLYBEAN_MR1
33//Since this is unavailable on Android 4.2.2, defining it in terms of base 10
Saurabh Shahbd2d0832013-04-04 14:33:08 -070034static inline float log2f(const float& x) {
35 return log(x) / log(2);
36}
Arun Kumar K.Re1ffd3e2013-06-13 12:14:11 -070037#endif
Saurabh Shahbd2d0832013-04-04 14:33:08 -070038
Naseer Ahmed29a26812012-06-14 00:56:20 -070039namespace ovutils = overlay::utils;
40namespace overlay {
Saurabh Shahb121e142012-08-20 17:59:13 -070041
Naseer Ahmedf48aef62012-07-20 09:05:53 -070042bool MdpCtrl::init(uint32_t fbnum) {
43 // 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 }
49 return true;
50}
51
52void MdpCtrl::reset() {
53 utils::memset0(mOVInfo);
54 utils::memset0(mLkgo);
Naseer Ahmedf48aef62012-07-20 09:05:53 -070055 mOVInfo.id = MSMFB_NEW_REQUEST;
56 mLkgo.id = MSMFB_NEW_REQUEST;
57 mOrientation = utils::OVERLAY_TRANSFORM_0;
Saurabh Shahacf10202013-02-26 10:15:15 -080058 mDownscale = 0;
Saurabh Shahdf0be752013-05-23 14:40:00 -070059 mForceSet = false;
Saurabh Shah5daeee52013-01-23 16:52:26 +080060#ifdef USES_POST_PROCESSING
61 mPPChanged = false;
62 memset(&mParams, 0, sizeof(struct compute_params));
63 mParams.params.conv_params.order = hsic_order_hsc_i;
64 mParams.params.conv_params.interface = interface_rec601;
65 mParams.params.conv_params.cc_matrix[0][0] = 1;
66 mParams.params.conv_params.cc_matrix[1][1] = 1;
67 mParams.params.conv_params.cc_matrix[2][2] = 1;
68#endif
Naseer Ahmed29a26812012-06-14 00:56:20 -070069}
70
71bool MdpCtrl::close() {
Saurabh Shah8e1ae952012-08-15 12:15:14 -070072 bool result = true;
Saurabh Shah8e1ae952012-08-15 12:15:14 -070073 if(MSMFB_NEW_REQUEST != static_cast<int>(mOVInfo.id)) {
74 if(!mdp_wrapper::unsetOverlay(mFd.getFD(), mOVInfo.id)) {
75 ALOGE("MdpCtrl close error in unset");
76 result = false;
77 }
Naseer Ahmed29a26812012-06-14 00:56:20 -070078 }
Saurabh Shah5daeee52013-01-23 16:52:26 +080079#ifdef USES_POST_PROCESSING
80 /* free allocated memory in PP */
81 if (mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data)
82 free(mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data);
83#endif
Naseer Ahmed29a26812012-06-14 00:56:20 -070084 reset();
Saurabh Shahacf10202013-02-26 10:15:15 -080085
Naseer Ahmed29a26812012-06-14 00:56:20 -070086 if(!mFd.close()) {
Saurabh Shah8e1ae952012-08-15 12:15:14 -070087 result = false;
Naseer Ahmed29a26812012-06-14 00:56:20 -070088 }
Saurabh Shah8e1ae952012-08-15 12:15:14 -070089
90 return result;
Naseer Ahmed29a26812012-06-14 00:56:20 -070091}
92
Saurabh Shahacf10202013-02-26 10:15:15 -080093void MdpCtrl::setSource(const utils::PipeArgs& args) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -070094 setSrcWhf(args.whf);
95
96 //TODO These are hardcoded. Can be moved out of setSource.
Naseer Ahmedf48aef62012-07-20 09:05:53 -070097 mOVInfo.transp_mask = 0xffffffff;
98
99 //TODO These calls should ideally be a part of setPipeParams API
100 setFlags(args.mdpFlags);
101 setZ(args.zorder);
102 setIsFg(args.isFg);
Naseer Ahmed522ce662013-03-18 20:14:05 -0400103 setPlaneAlpha(args.planeAlpha);
104 setBlending(args.blending);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700105}
106
Saurabh Shahacf10202013-02-26 10:15:15 -0800107void MdpCtrl::setCrop(const utils::Dim& d) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700108 setSrcRectDim(d);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700109}
110
Sushil Chauhan897a9c32013-07-18 11:09:55 -0700111void MdpCtrl::setColor(const uint32_t color) {
112 mOVInfo.bg_color = color;
113}
114
Saurabh Shahacf10202013-02-26 10:15:15 -0800115void MdpCtrl::setPosition(const overlay::utils::Dim& d) {
116 setDstRectDim(d);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700117}
118
Saurabh Shahacf10202013-02-26 10:15:15 -0800119void MdpCtrl::setTransform(const utils::eTransform& orient) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700120 int rot = utils::getMdpOrient(orient);
121 setUserData(rot);
Saurabh Shaha73738d2012-08-09 18:15:18 -0700122 mOrientation = static_cast<utils::eTransform>(rot);
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800123}
124
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700125void MdpCtrl::doTransform() {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700126 setRotationFlags();
Saurabh Shahacf10202013-02-26 10:15:15 -0800127 utils::Whf whf = getSrcWhf();
128 utils::Dim dim = getSrcRectDim();
129 utils::preRotateSource(mOrientation, whf, dim);
130 setSrcWhf(whf);
131 setSrcRectDim(dim);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700132}
133
Saurabh Shahacf10202013-02-26 10:15:15 -0800134void MdpCtrl::doDownscale() {
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700135 int mdpVersion = MDPVersion::getInstance().getMDPVersion();
136 if(mdpVersion < MDSS_V5) {
137 mOVInfo.src_rect.x >>= mDownscale;
138 mOVInfo.src_rect.y >>= mDownscale;
139 mOVInfo.src_rect.w >>= mDownscale;
140 mOVInfo.src_rect.h >>= mDownscale;
141 } else if(MDPVersion::getInstance().supportsDecimation()) {
142 //Decimation + MDP Downscale
143 mOVInfo.horz_deci = 0;
144 mOVInfo.vert_deci = 0;
145 int minHorDeci = 0;
146 if(mOVInfo.src_rect.w > 2048) {
147 //If the client sends us something > what a layer mixer supports
148 //then it means it doesn't want to use split-pipe but wants us to
149 //decimate. A minimum decimation of 2 will ensure that the width is
150 //always within layer mixer limits.
151 minHorDeci = 2;
152 }
153
Saurabh Shah1a03d482013-05-29 13:44:20 -0700154 float horDscale = 0.0f;
155 float verDscale = 0.0f;
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700156
Saurabh Shah1a03d482013-05-29 13:44:20 -0700157 utils::getDecimationFactor(mOVInfo.src_rect.w, mOVInfo.src_rect.h,
158 mOVInfo.dst_rect.w, mOVInfo.dst_rect.h, horDscale, verDscale);
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700159
160 if(horDscale < minHorDeci)
161 horDscale = minHorDeci;
162
163 if((int)horDscale)
164 mOVInfo.horz_deci = (int)log2f(horDscale);
165
166 if((int)verDscale)
167 mOVInfo.vert_deci = (int)log2f(verDscale);
168 }
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800169}
170
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700171bool MdpCtrl::set() {
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700172 int mdpVersion = MDPVersion::getInstance().getMDPVersion();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700173 //deferred calcs, so APIs could be called in any order.
Saurabh Shahacf10202013-02-26 10:15:15 -0800174 doTransform();
Saurabh Shahb121e142012-08-20 17:59:13 -0700175 utils::Whf whf = getSrcWhf();
176 if(utils::isYuv(whf.format)) {
Sushil Chauhan1cac8152013-05-08 15:53:51 -0700177 utils::normalizeCrop(mOVInfo.src_rect.x, mOVInfo.src_rect.w);
178 utils::normalizeCrop(mOVInfo.src_rect.y, mOVInfo.src_rect.h);
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700179 if(mdpVersion < MDSS_V5) {
Saurabh Shahce416f02013-04-10 13:33:09 -0700180 utils::even_floor(mOVInfo.dst_rect.w);
181 utils::even_floor(mOVInfo.dst_rect.h);
Sushil Chauhan5491c8a2013-05-24 10:15:30 -0700182 } else if (mOVInfo.flags & MDP_DEINTERLACE) {
183 // For interlaced, crop.h should be 4-aligned
184 if (!(mOVInfo.flags & MDP_SOURCE_ROTATED_90) &&
185 (mOVInfo.src_rect.h % 4))
186 mOVInfo.src_rect.h = utils::aligndown(mOVInfo.src_rect.h, 4);
Saurabh Shahce416f02013-04-10 13:33:09 -0700187 }
Sushil Chauhan35fc68b2013-06-19 14:08:56 -0700188 } else {
189 if (mdpVersion >= MDSS_V5) {
190 // Check for 1-pixel down-scaling
191 if (mOVInfo.src_rect.w - mOVInfo.dst_rect.w == 1)
192 mOVInfo.src_rect.w -= 1;
193 if (mOVInfo.src_rect.h - mOVInfo.dst_rect.h == 1)
194 mOVInfo.src_rect.h -= 1;
195 }
Saurabh Shahb121e142012-08-20 17:59:13 -0700196 }
197
Sushil Chauhan35fc68b2013-06-19 14:08:56 -0700198 doDownscale();
199
Saurabh Shahdf0be752013-05-23 14:40:00 -0700200 if(this->ovChanged() || mForceSet) {
201 mForceSet = false;
Saurabh Shahfc2acbe2012-08-17 19:47:52 -0700202 if(!mdp_wrapper::setOverlay(mFd.getFD(), mOVInfo)) {
203 ALOGE("MdpCtrl failed to setOverlay, restoring last known "
204 "good ov info");
205 mdp_wrapper::dump("== Bad OVInfo is: ", mOVInfo);
206 mdp_wrapper::dump("== Last good known OVInfo is: ", mLkgo);
207 this->restore();
208 return false;
209 }
210 this->save();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700211 }
Saurabh Shahb121e142012-08-20 17:59:13 -0700212
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700213 return true;
214}
215
Naseer Ahmed29a26812012-06-14 00:56:20 -0700216bool MdpCtrl::get() {
217 mdp_overlay ov;
218 ov.id = mOVInfo.id;
219 if (!mdp_wrapper::getOverlay(mFd.getFD(), ov)) {
220 ALOGE("MdpCtrl get failed");
221 return false;
222 }
223 mOVInfo = ov;
224 return true;
225}
226
Saurabh Shahacf10202013-02-26 10:15:15 -0800227//Update src format based on rotator's destination format.
228void MdpCtrl::updateSrcFormat(const uint32_t& rotDestFmt) {
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800229 utils::Whf whf = getSrcWhf();
Saurabh Shahacf10202013-02-26 10:15:15 -0800230 whf.format = rotDestFmt;
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800231 setSrcWhf(whf);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700232}
233
234void MdpCtrl::dump() const {
235 ALOGE("== Dump MdpCtrl start ==");
Naseer Ahmed29a26812012-06-14 00:56:20 -0700236 mFd.dump();
237 mdp_wrapper::dump("mOVInfo", mOVInfo);
238 ALOGE("== Dump MdpCtrl end ==");
239}
240
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800241void MdpCtrl::getDump(char *buf, size_t len) {
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700242 ovutils::getDump(buf, len, "Ctrl", mOVInfo);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800243}
244
Naseer Ahmed29a26812012-06-14 00:56:20 -0700245void MdpData::dump() const {
246 ALOGE("== Dump MdpData start ==");
247 mFd.dump();
248 mdp_wrapper::dump("mOvData", mOvData);
249 ALOGE("== Dump MdpData end ==");
250}
251
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800252void MdpData::getDump(char *buf, size_t len) {
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700253 ovutils::getDump(buf, len, "Data", mOvData);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800254}
255
Naseer Ahmed29a26812012-06-14 00:56:20 -0700256void MdpCtrl3D::dump() const {
257 ALOGE("== Dump MdpCtrl start ==");
258 mFd.dump();
259 ALOGE("== Dump MdpCtrl end ==");
260}
261
Saurabh Shah5daeee52013-01-23 16:52:26 +0800262bool MdpCtrl::setVisualParams(const MetaData_t& data) {
263 bool needUpdate = false;
264#ifdef USES_POST_PROCESSING
265 /* calculate the data */
266 if (data.operation & PP_PARAM_HSIC) {
267 if (mParams.params.pa_params.hue != data.hsicData.hue) {
268 ALOGD_IF(HSIC_SETTINGS_DEBUG,
269 "Hue has changed from %d to %d",
270 mParams.params.pa_params.hue,data.hsicData.hue);
271 needUpdate = true;
272 }
273
274 if (!isEqual(mParams.params.pa_params.sat,
275 data.hsicData.saturation)) {
276 ALOGD_IF(HSIC_SETTINGS_DEBUG,
277 "Saturation has changed from %f to %f",
278 mParams.params.pa_params.sat,
279 data.hsicData.saturation);
280 needUpdate = true;
281 }
282
283 if (mParams.params.pa_params.intensity != data.hsicData.intensity) {
284 ALOGD_IF(HSIC_SETTINGS_DEBUG,
285 "Intensity has changed from %d to %d",
286 mParams.params.pa_params.intensity,
287 data.hsicData.intensity);
288 needUpdate = true;
289 }
290
291 if (!isEqual(mParams.params.pa_params.contrast,
292 data.hsicData.contrast)) {
293 ALOGD_IF(HSIC_SETTINGS_DEBUG,
294 "Contrast has changed from %f to %f",
295 mParams.params.pa_params.contrast,
296 data.hsicData.contrast);
297 needUpdate = true;
298 }
299
300 if (needUpdate) {
301 mParams.params.pa_params.hue = data.hsicData.hue;
302 mParams.params.pa_params.sat = data.hsicData.saturation;
303 mParams.params.pa_params.intensity = data.hsicData.intensity;
304 mParams.params.pa_params.contrast = data.hsicData.contrast;
305 mParams.params.pa_params.ops = MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
306 mParams.operation |= PP_OP_PA;
307 }
308 }
309
310 if (data.operation & PP_PARAM_SHARP2) {
311 if (mParams.params.sharp_params.strength != data.Sharp2Data.strength) {
312 needUpdate = true;
313 }
314 if (mParams.params.sharp_params.edge_thr != data.Sharp2Data.edge_thr) {
315 needUpdate = true;
316 }
317 if (mParams.params.sharp_params.smooth_thr !=
318 data.Sharp2Data.smooth_thr) {
319 needUpdate = true;
320 }
321 if (mParams.params.sharp_params.noise_thr !=
322 data.Sharp2Data.noise_thr) {
323 needUpdate = true;
324 }
325
326 if (needUpdate) {
327 mParams.params.sharp_params.strength = data.Sharp2Data.strength;
328 mParams.params.sharp_params.edge_thr = data.Sharp2Data.edge_thr;
329 mParams.params.sharp_params.smooth_thr =
330 data.Sharp2Data.smooth_thr;
331 mParams.params.sharp_params.noise_thr = data.Sharp2Data.noise_thr;
332 mParams.params.sharp_params.ops =
333 MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
334 mParams.operation |= PP_OP_SHARP;
335 }
336 }
337
338 if (data.operation & PP_PARAM_IGC) {
339 if (mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data == NULL){
340 uint32_t *igcData
341 = (uint32_t *)malloc(2 * MAX_IGC_LUT_ENTRIES * sizeof(uint32_t));
342 if (!igcData) {
343 ALOGE("IGC storage allocated failed");
344 return false;
345 }
346 mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data = igcData;
347 mOVInfo.overlay_pp_cfg.igc_cfg.c2_data
348 = igcData + MAX_IGC_LUT_ENTRIES;
349 }
350
351 memcpy(mParams.params.igc_lut_params.c0,
352 data.igcData.c0, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
353 memcpy(mParams.params.igc_lut_params.c1,
354 data.igcData.c1, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
355 memcpy(mParams.params.igc_lut_params.c2,
356 data.igcData.c2, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
357
358 mParams.params.igc_lut_params.ops
359 = MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
360 mParams.operation |= PP_OP_IGC;
361 needUpdate = true;
362 }
363
364 if (data.operation & PP_PARAM_VID_INTFC) {
365 mParams.params.conv_params.interface =
366 (interface_type) data.video_interface;
367 needUpdate = true;
368 }
369
370 if (needUpdate) {
371 display_pp_compute_params(&mParams, &mOVInfo.overlay_pp_cfg);
372 mPPChanged = true;
373 }
374#endif
375 return true;
376}
377
Naseer Ahmed29a26812012-06-14 00:56:20 -0700378} // overlay