blob: 61bfb198b9ff946b63f940c26dc7f3acc24801cd [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.
97 mOVInfo.alpha = 0xff;
98 mOVInfo.transp_mask = 0xffffffff;
99
100 //TODO These calls should ideally be a part of setPipeParams API
101 setFlags(args.mdpFlags);
102 setZ(args.zorder);
103 setIsFg(args.isFg);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700104}
105
Saurabh Shahacf10202013-02-26 10:15:15 -0800106void MdpCtrl::setCrop(const utils::Dim& d) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700107 setSrcRectDim(d);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700108}
109
Saurabh Shahacf10202013-02-26 10:15:15 -0800110void MdpCtrl::setPosition(const overlay::utils::Dim& d) {
111 setDstRectDim(d);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700112}
113
Saurabh Shahacf10202013-02-26 10:15:15 -0800114void MdpCtrl::setTransform(const utils::eTransform& orient) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700115 int rot = utils::getMdpOrient(orient);
116 setUserData(rot);
Saurabh Shaha73738d2012-08-09 18:15:18 -0700117 mOrientation = static_cast<utils::eTransform>(rot);
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800118}
119
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700120void MdpCtrl::doTransform() {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700121 setRotationFlags();
Saurabh Shahacf10202013-02-26 10:15:15 -0800122 utils::Whf whf = getSrcWhf();
123 utils::Dim dim = getSrcRectDim();
124 utils::preRotateSource(mOrientation, whf, dim);
125 setSrcWhf(whf);
126 setSrcRectDim(dim);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700127}
128
Saurabh Shahacf10202013-02-26 10:15:15 -0800129void MdpCtrl::doDownscale() {
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700130 int mdpVersion = MDPVersion::getInstance().getMDPVersion();
131 if(mdpVersion < MDSS_V5) {
132 mOVInfo.src_rect.x >>= mDownscale;
133 mOVInfo.src_rect.y >>= mDownscale;
134 mOVInfo.src_rect.w >>= mDownscale;
135 mOVInfo.src_rect.h >>= mDownscale;
136 } else if(MDPVersion::getInstance().supportsDecimation()) {
137 //Decimation + MDP Downscale
138 mOVInfo.horz_deci = 0;
139 mOVInfo.vert_deci = 0;
140 int minHorDeci = 0;
141 if(mOVInfo.src_rect.w > 2048) {
142 //If the client sends us something > what a layer mixer supports
143 //then it means it doesn't want to use split-pipe but wants us to
144 //decimate. A minimum decimation of 2 will ensure that the width is
145 //always within layer mixer limits.
146 minHorDeci = 2;
147 }
148
Saurabh Shah1a03d482013-05-29 13:44:20 -0700149 float horDscale = 0.0f;
150 float verDscale = 0.0f;
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700151
Saurabh Shah1a03d482013-05-29 13:44:20 -0700152 utils::getDecimationFactor(mOVInfo.src_rect.w, mOVInfo.src_rect.h,
153 mOVInfo.dst_rect.w, mOVInfo.dst_rect.h, horDscale, verDscale);
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700154
155 if(horDscale < minHorDeci)
156 horDscale = minHorDeci;
157
158 if((int)horDscale)
159 mOVInfo.horz_deci = (int)log2f(horDscale);
160
161 if((int)verDscale)
162 mOVInfo.vert_deci = (int)log2f(verDscale);
163 }
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800164}
165
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700166bool MdpCtrl::set() {
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700167 int mdpVersion = MDPVersion::getInstance().getMDPVersion();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700168 //deferred calcs, so APIs could be called in any order.
Saurabh Shahacf10202013-02-26 10:15:15 -0800169 doTransform();
170 doDownscale();
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 }
Saurabh Shahb121e142012-08-20 17:59:13 -0700184 }
185
Saurabh Shahdf0be752013-05-23 14:40:00 -0700186 if(this->ovChanged() || mForceSet) {
187 mForceSet = false;
Saurabh Shahfc2acbe2012-08-17 19:47:52 -0700188 if(!mdp_wrapper::setOverlay(mFd.getFD(), mOVInfo)) {
189 ALOGE("MdpCtrl failed to setOverlay, restoring last known "
190 "good ov info");
191 mdp_wrapper::dump("== Bad OVInfo is: ", mOVInfo);
192 mdp_wrapper::dump("== Last good known OVInfo is: ", mLkgo);
193 this->restore();
194 return false;
195 }
196 this->save();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700197 }
Saurabh Shahb121e142012-08-20 17:59:13 -0700198
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700199 return true;
200}
201
Naseer Ahmed29a26812012-06-14 00:56:20 -0700202bool MdpCtrl::get() {
203 mdp_overlay ov;
204 ov.id = mOVInfo.id;
205 if (!mdp_wrapper::getOverlay(mFd.getFD(), ov)) {
206 ALOGE("MdpCtrl get failed");
207 return false;
208 }
209 mOVInfo = ov;
210 return true;
211}
212
Saurabh Shahacf10202013-02-26 10:15:15 -0800213//Update src format based on rotator's destination format.
214void MdpCtrl::updateSrcFormat(const uint32_t& rotDestFmt) {
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800215 utils::Whf whf = getSrcWhf();
Saurabh Shahacf10202013-02-26 10:15:15 -0800216 whf.format = rotDestFmt;
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800217 setSrcWhf(whf);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700218}
219
220void MdpCtrl::dump() const {
221 ALOGE("== Dump MdpCtrl start ==");
Naseer Ahmed29a26812012-06-14 00:56:20 -0700222 mFd.dump();
223 mdp_wrapper::dump("mOVInfo", mOVInfo);
224 ALOGE("== Dump MdpCtrl end ==");
225}
226
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800227void MdpCtrl::getDump(char *buf, size_t len) {
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700228 ovutils::getDump(buf, len, "Ctrl", mOVInfo);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800229}
230
Naseer Ahmed29a26812012-06-14 00:56:20 -0700231void MdpData::dump() const {
232 ALOGE("== Dump MdpData start ==");
233 mFd.dump();
234 mdp_wrapper::dump("mOvData", mOvData);
235 ALOGE("== Dump MdpData end ==");
236}
237
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800238void MdpData::getDump(char *buf, size_t len) {
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700239 ovutils::getDump(buf, len, "Data", mOvData);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800240}
241
Naseer Ahmed29a26812012-06-14 00:56:20 -0700242void MdpCtrl3D::dump() const {
243 ALOGE("== Dump MdpCtrl start ==");
244 mFd.dump();
245 ALOGE("== Dump MdpCtrl end ==");
246}
247
Saurabh Shah5daeee52013-01-23 16:52:26 +0800248bool MdpCtrl::setVisualParams(const MetaData_t& data) {
249 bool needUpdate = false;
250#ifdef USES_POST_PROCESSING
251 /* calculate the data */
252 if (data.operation & PP_PARAM_HSIC) {
253 if (mParams.params.pa_params.hue != data.hsicData.hue) {
254 ALOGD_IF(HSIC_SETTINGS_DEBUG,
255 "Hue has changed from %d to %d",
256 mParams.params.pa_params.hue,data.hsicData.hue);
257 needUpdate = true;
258 }
259
260 if (!isEqual(mParams.params.pa_params.sat,
261 data.hsicData.saturation)) {
262 ALOGD_IF(HSIC_SETTINGS_DEBUG,
263 "Saturation has changed from %f to %f",
264 mParams.params.pa_params.sat,
265 data.hsicData.saturation);
266 needUpdate = true;
267 }
268
269 if (mParams.params.pa_params.intensity != data.hsicData.intensity) {
270 ALOGD_IF(HSIC_SETTINGS_DEBUG,
271 "Intensity has changed from %d to %d",
272 mParams.params.pa_params.intensity,
273 data.hsicData.intensity);
274 needUpdate = true;
275 }
276
277 if (!isEqual(mParams.params.pa_params.contrast,
278 data.hsicData.contrast)) {
279 ALOGD_IF(HSIC_SETTINGS_DEBUG,
280 "Contrast has changed from %f to %f",
281 mParams.params.pa_params.contrast,
282 data.hsicData.contrast);
283 needUpdate = true;
284 }
285
286 if (needUpdate) {
287 mParams.params.pa_params.hue = data.hsicData.hue;
288 mParams.params.pa_params.sat = data.hsicData.saturation;
289 mParams.params.pa_params.intensity = data.hsicData.intensity;
290 mParams.params.pa_params.contrast = data.hsicData.contrast;
291 mParams.params.pa_params.ops = MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
292 mParams.operation |= PP_OP_PA;
293 }
294 }
295
296 if (data.operation & PP_PARAM_SHARP2) {
297 if (mParams.params.sharp_params.strength != data.Sharp2Data.strength) {
298 needUpdate = true;
299 }
300 if (mParams.params.sharp_params.edge_thr != data.Sharp2Data.edge_thr) {
301 needUpdate = true;
302 }
303 if (mParams.params.sharp_params.smooth_thr !=
304 data.Sharp2Data.smooth_thr) {
305 needUpdate = true;
306 }
307 if (mParams.params.sharp_params.noise_thr !=
308 data.Sharp2Data.noise_thr) {
309 needUpdate = true;
310 }
311
312 if (needUpdate) {
313 mParams.params.sharp_params.strength = data.Sharp2Data.strength;
314 mParams.params.sharp_params.edge_thr = data.Sharp2Data.edge_thr;
315 mParams.params.sharp_params.smooth_thr =
316 data.Sharp2Data.smooth_thr;
317 mParams.params.sharp_params.noise_thr = data.Sharp2Data.noise_thr;
318 mParams.params.sharp_params.ops =
319 MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
320 mParams.operation |= PP_OP_SHARP;
321 }
322 }
323
324 if (data.operation & PP_PARAM_IGC) {
325 if (mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data == NULL){
326 uint32_t *igcData
327 = (uint32_t *)malloc(2 * MAX_IGC_LUT_ENTRIES * sizeof(uint32_t));
328 if (!igcData) {
329 ALOGE("IGC storage allocated failed");
330 return false;
331 }
332 mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data = igcData;
333 mOVInfo.overlay_pp_cfg.igc_cfg.c2_data
334 = igcData + MAX_IGC_LUT_ENTRIES;
335 }
336
337 memcpy(mParams.params.igc_lut_params.c0,
338 data.igcData.c0, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
339 memcpy(mParams.params.igc_lut_params.c1,
340 data.igcData.c1, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
341 memcpy(mParams.params.igc_lut_params.c2,
342 data.igcData.c2, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
343
344 mParams.params.igc_lut_params.ops
345 = MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
346 mParams.operation |= PP_OP_IGC;
347 needUpdate = true;
348 }
349
350 if (data.operation & PP_PARAM_VID_INTFC) {
351 mParams.params.conv_params.interface =
352 (interface_type) data.video_interface;
353 needUpdate = true;
354 }
355
356 if (needUpdate) {
357 display_pp_compute_params(&mParams, &mOVInfo.overlay_pp_cfg);
358 mPPChanged = true;
359 }
360#endif
361 return true;
362}
363
Naseer Ahmed29a26812012-06-14 00:56:20 -0700364} // overlay