blob: 674e62dc68b1577cc1b0598a462ddd79b14e1211 [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
Saurabh Shahacf10202013-02-26 10:15:15 -0800111void MdpCtrl::setPosition(const overlay::utils::Dim& d) {
112 setDstRectDim(d);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700113}
114
Saurabh Shahacf10202013-02-26 10:15:15 -0800115void MdpCtrl::setTransform(const utils::eTransform& orient) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700116 int rot = utils::getMdpOrient(orient);
117 setUserData(rot);
Saurabh Shaha73738d2012-08-09 18:15:18 -0700118 mOrientation = static_cast<utils::eTransform>(rot);
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800119}
120
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700121void MdpCtrl::doTransform() {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700122 setRotationFlags();
Saurabh Shahacf10202013-02-26 10:15:15 -0800123 utils::Whf whf = getSrcWhf();
124 utils::Dim dim = getSrcRectDim();
125 utils::preRotateSource(mOrientation, whf, dim);
126 setSrcWhf(whf);
127 setSrcRectDim(dim);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700128}
129
Saurabh Shahacf10202013-02-26 10:15:15 -0800130void MdpCtrl::doDownscale() {
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700131 int mdpVersion = MDPVersion::getInstance().getMDPVersion();
132 if(mdpVersion < MDSS_V5) {
133 mOVInfo.src_rect.x >>= mDownscale;
134 mOVInfo.src_rect.y >>= mDownscale;
135 mOVInfo.src_rect.w >>= mDownscale;
136 mOVInfo.src_rect.h >>= mDownscale;
137 } else if(MDPVersion::getInstance().supportsDecimation()) {
138 //Decimation + MDP Downscale
139 mOVInfo.horz_deci = 0;
140 mOVInfo.vert_deci = 0;
141 int minHorDeci = 0;
142 if(mOVInfo.src_rect.w > 2048) {
143 //If the client sends us something > what a layer mixer supports
144 //then it means it doesn't want to use split-pipe but wants us to
145 //decimate. A minimum decimation of 2 will ensure that the width is
146 //always within layer mixer limits.
147 minHorDeci = 2;
148 }
149
Saurabh Shah1a03d482013-05-29 13:44:20 -0700150 float horDscale = 0.0f;
151 float verDscale = 0.0f;
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700152
Saurabh Shah1a03d482013-05-29 13:44:20 -0700153 utils::getDecimationFactor(mOVInfo.src_rect.w, mOVInfo.src_rect.h,
154 mOVInfo.dst_rect.w, mOVInfo.dst_rect.h, horDscale, verDscale);
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700155
156 if(horDscale < minHorDeci)
157 horDscale = minHorDeci;
158
159 if((int)horDscale)
160 mOVInfo.horz_deci = (int)log2f(horDscale);
161
162 if((int)verDscale)
163 mOVInfo.vert_deci = (int)log2f(verDscale);
164 }
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800165}
166
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700167bool MdpCtrl::set() {
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700168 int mdpVersion = MDPVersion::getInstance().getMDPVersion();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700169 //deferred calcs, so APIs could be called in any order.
Saurabh Shahacf10202013-02-26 10:15:15 -0800170 doTransform();
Saurabh Shahb121e142012-08-20 17:59:13 -0700171 utils::Whf whf = getSrcWhf();
172 if(utils::isYuv(whf.format)) {
Sushil Chauhan1cac8152013-05-08 15:53:51 -0700173 utils::normalizeCrop(mOVInfo.src_rect.x, mOVInfo.src_rect.w);
174 utils::normalizeCrop(mOVInfo.src_rect.y, mOVInfo.src_rect.h);
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700175 if(mdpVersion < MDSS_V5) {
Saurabh Shahce416f02013-04-10 13:33:09 -0700176 utils::even_floor(mOVInfo.dst_rect.w);
177 utils::even_floor(mOVInfo.dst_rect.h);
Sushil Chauhan5491c8a2013-05-24 10:15:30 -0700178 } else if (mOVInfo.flags & MDP_DEINTERLACE) {
179 // For interlaced, crop.h should be 4-aligned
180 if (!(mOVInfo.flags & MDP_SOURCE_ROTATED_90) &&
181 (mOVInfo.src_rect.h % 4))
182 mOVInfo.src_rect.h = utils::aligndown(mOVInfo.src_rect.h, 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();
195
Saurabh Shahdf0be752013-05-23 14:40:00 -0700196 if(this->ovChanged() || mForceSet) {
197 mForceSet = false;
Saurabh Shahfc2acbe2012-08-17 19:47:52 -0700198 if(!mdp_wrapper::setOverlay(mFd.getFD(), mOVInfo)) {
199 ALOGE("MdpCtrl failed to setOverlay, restoring last known "
200 "good ov info");
201 mdp_wrapper::dump("== Bad OVInfo is: ", mOVInfo);
202 mdp_wrapper::dump("== Last good known OVInfo is: ", mLkgo);
203 this->restore();
204 return false;
205 }
206 this->save();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700207 }
Saurabh Shahb121e142012-08-20 17:59:13 -0700208
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700209 return true;
210}
211
Naseer Ahmed29a26812012-06-14 00:56:20 -0700212bool MdpCtrl::get() {
213 mdp_overlay ov;
214 ov.id = mOVInfo.id;
215 if (!mdp_wrapper::getOverlay(mFd.getFD(), ov)) {
216 ALOGE("MdpCtrl get failed");
217 return false;
218 }
219 mOVInfo = ov;
220 return true;
221}
222
Saurabh Shahacf10202013-02-26 10:15:15 -0800223//Update src format based on rotator's destination format.
224void MdpCtrl::updateSrcFormat(const uint32_t& rotDestFmt) {
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800225 utils::Whf whf = getSrcWhf();
Saurabh Shahacf10202013-02-26 10:15:15 -0800226 whf.format = rotDestFmt;
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800227 setSrcWhf(whf);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700228}
229
230void MdpCtrl::dump() const {
231 ALOGE("== Dump MdpCtrl start ==");
Naseer Ahmed29a26812012-06-14 00:56:20 -0700232 mFd.dump();
233 mdp_wrapper::dump("mOVInfo", mOVInfo);
234 ALOGE("== Dump MdpCtrl end ==");
235}
236
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800237void MdpCtrl::getDump(char *buf, size_t len) {
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700238 ovutils::getDump(buf, len, "Ctrl", mOVInfo);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800239}
240
Naseer Ahmed29a26812012-06-14 00:56:20 -0700241void MdpData::dump() const {
242 ALOGE("== Dump MdpData start ==");
243 mFd.dump();
244 mdp_wrapper::dump("mOvData", mOvData);
245 ALOGE("== Dump MdpData end ==");
246}
247
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800248void MdpData::getDump(char *buf, size_t len) {
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700249 ovutils::getDump(buf, len, "Data", mOvData);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800250}
251
Naseer Ahmed29a26812012-06-14 00:56:20 -0700252void MdpCtrl3D::dump() const {
253 ALOGE("== Dump MdpCtrl start ==");
254 mFd.dump();
255 ALOGE("== Dump MdpCtrl end ==");
256}
257
Saurabh Shah5daeee52013-01-23 16:52:26 +0800258bool MdpCtrl::setVisualParams(const MetaData_t& data) {
259 bool needUpdate = false;
260#ifdef USES_POST_PROCESSING
261 /* calculate the data */
262 if (data.operation & PP_PARAM_HSIC) {
263 if (mParams.params.pa_params.hue != data.hsicData.hue) {
264 ALOGD_IF(HSIC_SETTINGS_DEBUG,
265 "Hue has changed from %d to %d",
266 mParams.params.pa_params.hue,data.hsicData.hue);
267 needUpdate = true;
268 }
269
270 if (!isEqual(mParams.params.pa_params.sat,
271 data.hsicData.saturation)) {
272 ALOGD_IF(HSIC_SETTINGS_DEBUG,
273 "Saturation has changed from %f to %f",
274 mParams.params.pa_params.sat,
275 data.hsicData.saturation);
276 needUpdate = true;
277 }
278
279 if (mParams.params.pa_params.intensity != data.hsicData.intensity) {
280 ALOGD_IF(HSIC_SETTINGS_DEBUG,
281 "Intensity has changed from %d to %d",
282 mParams.params.pa_params.intensity,
283 data.hsicData.intensity);
284 needUpdate = true;
285 }
286
287 if (!isEqual(mParams.params.pa_params.contrast,
288 data.hsicData.contrast)) {
289 ALOGD_IF(HSIC_SETTINGS_DEBUG,
290 "Contrast has changed from %f to %f",
291 mParams.params.pa_params.contrast,
292 data.hsicData.contrast);
293 needUpdate = true;
294 }
295
296 if (needUpdate) {
297 mParams.params.pa_params.hue = data.hsicData.hue;
298 mParams.params.pa_params.sat = data.hsicData.saturation;
299 mParams.params.pa_params.intensity = data.hsicData.intensity;
300 mParams.params.pa_params.contrast = data.hsicData.contrast;
301 mParams.params.pa_params.ops = MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
302 mParams.operation |= PP_OP_PA;
303 }
304 }
305
306 if (data.operation & PP_PARAM_SHARP2) {
307 if (mParams.params.sharp_params.strength != data.Sharp2Data.strength) {
308 needUpdate = true;
309 }
310 if (mParams.params.sharp_params.edge_thr != data.Sharp2Data.edge_thr) {
311 needUpdate = true;
312 }
313 if (mParams.params.sharp_params.smooth_thr !=
314 data.Sharp2Data.smooth_thr) {
315 needUpdate = true;
316 }
317 if (mParams.params.sharp_params.noise_thr !=
318 data.Sharp2Data.noise_thr) {
319 needUpdate = true;
320 }
321
322 if (needUpdate) {
323 mParams.params.sharp_params.strength = data.Sharp2Data.strength;
324 mParams.params.sharp_params.edge_thr = data.Sharp2Data.edge_thr;
325 mParams.params.sharp_params.smooth_thr =
326 data.Sharp2Data.smooth_thr;
327 mParams.params.sharp_params.noise_thr = data.Sharp2Data.noise_thr;
328 mParams.params.sharp_params.ops =
329 MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
330 mParams.operation |= PP_OP_SHARP;
331 }
332 }
333
334 if (data.operation & PP_PARAM_IGC) {
335 if (mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data == NULL){
336 uint32_t *igcData
337 = (uint32_t *)malloc(2 * MAX_IGC_LUT_ENTRIES * sizeof(uint32_t));
338 if (!igcData) {
339 ALOGE("IGC storage allocated failed");
340 return false;
341 }
342 mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data = igcData;
343 mOVInfo.overlay_pp_cfg.igc_cfg.c2_data
344 = igcData + MAX_IGC_LUT_ENTRIES;
345 }
346
347 memcpy(mParams.params.igc_lut_params.c0,
348 data.igcData.c0, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
349 memcpy(mParams.params.igc_lut_params.c1,
350 data.igcData.c1, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
351 memcpy(mParams.params.igc_lut_params.c2,
352 data.igcData.c2, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
353
354 mParams.params.igc_lut_params.ops
355 = MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
356 mParams.operation |= PP_OP_IGC;
357 needUpdate = true;
358 }
359
360 if (data.operation & PP_PARAM_VID_INTFC) {
361 mParams.params.conv_params.interface =
362 (interface_type) data.video_interface;
363 needUpdate = true;
364 }
365
366 if (needUpdate) {
367 display_pp_compute_params(&mParams, &mOVInfo.overlay_pp_cfg);
368 mPPChanged = true;
369 }
370#endif
371 return true;
372}
373
Naseer Ahmed29a26812012-06-14 00:56:20 -0700374} // overlay