blob: 71e7e5bbbe3331502d22cdb42902a5ee127d7ea5 [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
Saurabh Shahbd2d0832013-04-04 14:33:08 -070032//Since this is unavailable on Android, defining it in terms of base 10
33static inline float log2f(const float& x) {
34 return log(x) / log(2);
35}
36
Naseer Ahmed29a26812012-06-14 00:56:20 -070037namespace ovutils = overlay::utils;
38namespace overlay {
Saurabh Shahb121e142012-08-20 17:59:13 -070039
Naseer Ahmedf48aef62012-07-20 09:05:53 -070040bool MdpCtrl::init(uint32_t fbnum) {
41 // FD init
Naseer Ahmed29a26812012-06-14 00:56:20 -070042 if(!utils::openDev(mFd, fbnum,
Naseer Ahmedf48aef62012-07-20 09:05:53 -070043 Res::fbPath, O_RDWR)){
44 ALOGE("Ctrl failed to init fbnum=%d", fbnum);
Naseer Ahmed29a26812012-06-14 00:56:20 -070045 return false;
46 }
47 return true;
48}
49
50void MdpCtrl::reset() {
51 utils::memset0(mOVInfo);
52 utils::memset0(mLkgo);
Naseer Ahmedf48aef62012-07-20 09:05:53 -070053 mOVInfo.id = MSMFB_NEW_REQUEST;
54 mLkgo.id = MSMFB_NEW_REQUEST;
55 mOrientation = utils::OVERLAY_TRANSFORM_0;
Saurabh Shahacf10202013-02-26 10:15:15 -080056 mDownscale = 0;
Saurabh Shahdf0be752013-05-23 14:40:00 -070057 mForceSet = false;
Saurabh Shah5daeee52013-01-23 16:52:26 +080058#ifdef USES_POST_PROCESSING
59 mPPChanged = false;
60 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.
95 mOVInfo.alpha = 0xff;
96 mOVInfo.transp_mask = 0xffffffff;
97
98 //TODO These calls should ideally be a part of setPipeParams API
99 setFlags(args.mdpFlags);
100 setZ(args.zorder);
101 setIsFg(args.isFg);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700102}
103
Saurabh Shahacf10202013-02-26 10:15:15 -0800104void MdpCtrl::setCrop(const utils::Dim& d) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700105 setSrcRectDim(d);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700106}
107
Saurabh Shahacf10202013-02-26 10:15:15 -0800108void MdpCtrl::setPosition(const overlay::utils::Dim& d) {
109 setDstRectDim(d);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700110}
111
Saurabh Shahacf10202013-02-26 10:15:15 -0800112void MdpCtrl::setTransform(const utils::eTransform& orient) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700113 int rot = utils::getMdpOrient(orient);
114 setUserData(rot);
Saurabh Shaha73738d2012-08-09 18:15:18 -0700115 mOrientation = static_cast<utils::eTransform>(rot);
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800116}
117
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700118void MdpCtrl::doTransform() {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700119 setRotationFlags();
Saurabh Shahacf10202013-02-26 10:15:15 -0800120 utils::Whf whf = getSrcWhf();
121 utils::Dim dim = getSrcRectDim();
122 utils::preRotateSource(mOrientation, whf, dim);
123 setSrcWhf(whf);
124 setSrcRectDim(dim);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700125}
126
Saurabh Shahacf10202013-02-26 10:15:15 -0800127void MdpCtrl::doDownscale() {
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700128 int mdpVersion = MDPVersion::getInstance().getMDPVersion();
129 if(mdpVersion < MDSS_V5) {
130 mOVInfo.src_rect.x >>= mDownscale;
131 mOVInfo.src_rect.y >>= mDownscale;
132 mOVInfo.src_rect.w >>= mDownscale;
133 mOVInfo.src_rect.h >>= mDownscale;
134 } else if(MDPVersion::getInstance().supportsDecimation()) {
135 //Decimation + MDP Downscale
136 mOVInfo.horz_deci = 0;
137 mOVInfo.vert_deci = 0;
138 int minHorDeci = 0;
139 if(mOVInfo.src_rect.w > 2048) {
140 //If the client sends us something > what a layer mixer supports
141 //then it means it doesn't want to use split-pipe but wants us to
142 //decimate. A minimum decimation of 2 will ensure that the width is
143 //always within layer mixer limits.
144 minHorDeci = 2;
145 }
146
Saurabh Shah1a03d482013-05-29 13:44:20 -0700147 float horDscale = 0.0f;
148 float verDscale = 0.0f;
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700149
Saurabh Shah1a03d482013-05-29 13:44:20 -0700150 utils::getDecimationFactor(mOVInfo.src_rect.w, mOVInfo.src_rect.h,
151 mOVInfo.dst_rect.w, mOVInfo.dst_rect.h, horDscale, verDscale);
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700152
153 if(horDscale < minHorDeci)
154 horDscale = minHorDeci;
155
156 if((int)horDscale)
157 mOVInfo.horz_deci = (int)log2f(horDscale);
158
159 if((int)verDscale)
160 mOVInfo.vert_deci = (int)log2f(verDscale);
161 }
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800162}
163
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700164bool MdpCtrl::set() {
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700165 int mdpVersion = MDPVersion::getInstance().getMDPVersion();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700166 //deferred calcs, so APIs could be called in any order.
Saurabh Shahacf10202013-02-26 10:15:15 -0800167 doTransform();
168 doDownscale();
Saurabh Shahb121e142012-08-20 17:59:13 -0700169 utils::Whf whf = getSrcWhf();
170 if(utils::isYuv(whf.format)) {
Sushil Chauhan1cac8152013-05-08 15:53:51 -0700171 utils::normalizeCrop(mOVInfo.src_rect.x, mOVInfo.src_rect.w);
172 utils::normalizeCrop(mOVInfo.src_rect.y, mOVInfo.src_rect.h);
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700173 if(mdpVersion < MDSS_V5) {
Saurabh Shahce416f02013-04-10 13:33:09 -0700174 utils::even_floor(mOVInfo.dst_rect.w);
175 utils::even_floor(mOVInfo.dst_rect.h);
Sushil Chauhan5491c8a2013-05-24 10:15:30 -0700176 } else if (mOVInfo.flags & MDP_DEINTERLACE) {
177 // For interlaced, crop.h should be 4-aligned
178 if (!(mOVInfo.flags & MDP_SOURCE_ROTATED_90) &&
179 (mOVInfo.src_rect.h % 4))
180 mOVInfo.src_rect.h = utils::aligndown(mOVInfo.src_rect.h, 4);
Saurabh Shahce416f02013-04-10 13:33:09 -0700181 }
Saurabh Shahb121e142012-08-20 17:59:13 -0700182 }
183
Saurabh Shahdf0be752013-05-23 14:40:00 -0700184 if(this->ovChanged() || mForceSet) {
185 mForceSet = false;
Saurabh Shahfc2acbe2012-08-17 19:47:52 -0700186 if(!mdp_wrapper::setOverlay(mFd.getFD(), mOVInfo)) {
187 ALOGE("MdpCtrl failed to setOverlay, restoring last known "
188 "good ov info");
189 mdp_wrapper::dump("== Bad OVInfo is: ", mOVInfo);
190 mdp_wrapper::dump("== Last good known OVInfo is: ", mLkgo);
191 this->restore();
192 return false;
193 }
194 this->save();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700195 }
Saurabh Shahb121e142012-08-20 17:59:13 -0700196
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700197 return true;
198}
199
Naseer Ahmed29a26812012-06-14 00:56:20 -0700200bool MdpCtrl::get() {
201 mdp_overlay ov;
202 ov.id = mOVInfo.id;
203 if (!mdp_wrapper::getOverlay(mFd.getFD(), ov)) {
204 ALOGE("MdpCtrl get failed");
205 return false;
206 }
207 mOVInfo = ov;
208 return true;
209}
210
Saurabh Shahacf10202013-02-26 10:15:15 -0800211//Update src format based on rotator's destination format.
212void MdpCtrl::updateSrcFormat(const uint32_t& rotDestFmt) {
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800213 utils::Whf whf = getSrcWhf();
Saurabh Shahacf10202013-02-26 10:15:15 -0800214 whf.format = rotDestFmt;
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800215 setSrcWhf(whf);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700216}
217
218void MdpCtrl::dump() const {
219 ALOGE("== Dump MdpCtrl start ==");
Naseer Ahmed29a26812012-06-14 00:56:20 -0700220 mFd.dump();
221 mdp_wrapper::dump("mOVInfo", mOVInfo);
222 ALOGE("== Dump MdpCtrl end ==");
223}
224
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800225void MdpCtrl::getDump(char *buf, size_t len) {
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700226 ovutils::getDump(buf, len, "Ctrl", mOVInfo);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800227}
228
Naseer Ahmed29a26812012-06-14 00:56:20 -0700229void MdpData::dump() const {
230 ALOGE("== Dump MdpData start ==");
231 mFd.dump();
232 mdp_wrapper::dump("mOvData", mOvData);
233 ALOGE("== Dump MdpData end ==");
234}
235
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800236void MdpData::getDump(char *buf, size_t len) {
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700237 ovutils::getDump(buf, len, "Data", mOvData);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800238}
239
Naseer Ahmed29a26812012-06-14 00:56:20 -0700240void MdpCtrl3D::dump() const {
241 ALOGE("== Dump MdpCtrl start ==");
242 mFd.dump();
243 ALOGE("== Dump MdpCtrl end ==");
244}
245
Saurabh Shah5daeee52013-01-23 16:52:26 +0800246bool MdpCtrl::setVisualParams(const MetaData_t& data) {
247 bool needUpdate = false;
248#ifdef USES_POST_PROCESSING
249 /* calculate the data */
250 if (data.operation & PP_PARAM_HSIC) {
251 if (mParams.params.pa_params.hue != data.hsicData.hue) {
252 ALOGD_IF(HSIC_SETTINGS_DEBUG,
253 "Hue has changed from %d to %d",
254 mParams.params.pa_params.hue,data.hsicData.hue);
255 needUpdate = true;
256 }
257
258 if (!isEqual(mParams.params.pa_params.sat,
259 data.hsicData.saturation)) {
260 ALOGD_IF(HSIC_SETTINGS_DEBUG,
261 "Saturation has changed from %f to %f",
262 mParams.params.pa_params.sat,
263 data.hsicData.saturation);
264 needUpdate = true;
265 }
266
267 if (mParams.params.pa_params.intensity != data.hsicData.intensity) {
268 ALOGD_IF(HSIC_SETTINGS_DEBUG,
269 "Intensity has changed from %d to %d",
270 mParams.params.pa_params.intensity,
271 data.hsicData.intensity);
272 needUpdate = true;
273 }
274
275 if (!isEqual(mParams.params.pa_params.contrast,
276 data.hsicData.contrast)) {
277 ALOGD_IF(HSIC_SETTINGS_DEBUG,
278 "Contrast has changed from %f to %f",
279 mParams.params.pa_params.contrast,
280 data.hsicData.contrast);
281 needUpdate = true;
282 }
283
284 if (needUpdate) {
285 mParams.params.pa_params.hue = data.hsicData.hue;
286 mParams.params.pa_params.sat = data.hsicData.saturation;
287 mParams.params.pa_params.intensity = data.hsicData.intensity;
288 mParams.params.pa_params.contrast = data.hsicData.contrast;
289 mParams.params.pa_params.ops = MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
290 mParams.operation |= PP_OP_PA;
291 }
292 }
293
294 if (data.operation & PP_PARAM_SHARP2) {
295 if (mParams.params.sharp_params.strength != data.Sharp2Data.strength) {
296 needUpdate = true;
297 }
298 if (mParams.params.sharp_params.edge_thr != data.Sharp2Data.edge_thr) {
299 needUpdate = true;
300 }
301 if (mParams.params.sharp_params.smooth_thr !=
302 data.Sharp2Data.smooth_thr) {
303 needUpdate = true;
304 }
305 if (mParams.params.sharp_params.noise_thr !=
306 data.Sharp2Data.noise_thr) {
307 needUpdate = true;
308 }
309
310 if (needUpdate) {
311 mParams.params.sharp_params.strength = data.Sharp2Data.strength;
312 mParams.params.sharp_params.edge_thr = data.Sharp2Data.edge_thr;
313 mParams.params.sharp_params.smooth_thr =
314 data.Sharp2Data.smooth_thr;
315 mParams.params.sharp_params.noise_thr = data.Sharp2Data.noise_thr;
316 mParams.params.sharp_params.ops =
317 MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
318 mParams.operation |= PP_OP_SHARP;
319 }
320 }
321
322 if (data.operation & PP_PARAM_IGC) {
323 if (mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data == NULL){
324 uint32_t *igcData
325 = (uint32_t *)malloc(2 * MAX_IGC_LUT_ENTRIES * sizeof(uint32_t));
326 if (!igcData) {
327 ALOGE("IGC storage allocated failed");
328 return false;
329 }
330 mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data = igcData;
331 mOVInfo.overlay_pp_cfg.igc_cfg.c2_data
332 = igcData + MAX_IGC_LUT_ENTRIES;
333 }
334
335 memcpy(mParams.params.igc_lut_params.c0,
336 data.igcData.c0, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
337 memcpy(mParams.params.igc_lut_params.c1,
338 data.igcData.c1, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
339 memcpy(mParams.params.igc_lut_params.c2,
340 data.igcData.c2, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
341
342 mParams.params.igc_lut_params.ops
343 = MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
344 mParams.operation |= PP_OP_IGC;
345 needUpdate = true;
346 }
347
348 if (data.operation & PP_PARAM_VID_INTFC) {
349 mParams.params.conv_params.interface =
350 (interface_type) data.video_interface;
351 needUpdate = true;
352 }
353
354 if (needUpdate) {
355 display_pp_compute_params(&mParams, &mOVInfo.overlay_pp_cfg);
356 mPPChanged = true;
357 }
358#endif
359 return true;
360}
361
Naseer Ahmed29a26812012-06-14 00:56:20 -0700362} // overlay