blob: 2d88376585a4f5979978ad8e3d3b3005e0666faf [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();
Saurabh Shahb121e142012-08-20 17:59:13 -0700170 utils::Whf whf = getSrcWhf();
171 if(utils::isYuv(whf.format)) {
Sushil Chauhan1cac8152013-05-08 15:53:51 -0700172 utils::normalizeCrop(mOVInfo.src_rect.x, mOVInfo.src_rect.w);
173 utils::normalizeCrop(mOVInfo.src_rect.y, mOVInfo.src_rect.h);
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700174 if(mdpVersion < MDSS_V5) {
Saurabh Shahce416f02013-04-10 13:33:09 -0700175 utils::even_floor(mOVInfo.dst_rect.w);
176 utils::even_floor(mOVInfo.dst_rect.h);
Sushil Chauhan5491c8a2013-05-24 10:15:30 -0700177 } else if (mOVInfo.flags & MDP_DEINTERLACE) {
178 // For interlaced, crop.h should be 4-aligned
179 if (!(mOVInfo.flags & MDP_SOURCE_ROTATED_90) &&
180 (mOVInfo.src_rect.h % 4))
181 mOVInfo.src_rect.h = utils::aligndown(mOVInfo.src_rect.h, 4);
Saurabh Shahce416f02013-04-10 13:33:09 -0700182 }
Sushil Chauhan35fc68b2013-06-19 14:08:56 -0700183 } else {
184 if (mdpVersion >= MDSS_V5) {
185 // Check for 1-pixel down-scaling
186 if (mOVInfo.src_rect.w - mOVInfo.dst_rect.w == 1)
187 mOVInfo.src_rect.w -= 1;
188 if (mOVInfo.src_rect.h - mOVInfo.dst_rect.h == 1)
189 mOVInfo.src_rect.h -= 1;
190 }
Saurabh Shahb121e142012-08-20 17:59:13 -0700191 }
192
Sushil Chauhan35fc68b2013-06-19 14:08:56 -0700193 doDownscale();
194
Saurabh Shahdf0be752013-05-23 14:40:00 -0700195 if(this->ovChanged() || mForceSet) {
196 mForceSet = false;
Saurabh Shahfc2acbe2012-08-17 19:47:52 -0700197 if(!mdp_wrapper::setOverlay(mFd.getFD(), mOVInfo)) {
198 ALOGE("MdpCtrl failed to setOverlay, restoring last known "
199 "good ov info");
200 mdp_wrapper::dump("== Bad OVInfo is: ", mOVInfo);
201 mdp_wrapper::dump("== Last good known OVInfo is: ", mLkgo);
202 this->restore();
203 return false;
204 }
205 this->save();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700206 }
Saurabh Shahb121e142012-08-20 17:59:13 -0700207
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700208 return true;
209}
210
Naseer Ahmed29a26812012-06-14 00:56:20 -0700211bool MdpCtrl::get() {
212 mdp_overlay ov;
213 ov.id = mOVInfo.id;
214 if (!mdp_wrapper::getOverlay(mFd.getFD(), ov)) {
215 ALOGE("MdpCtrl get failed");
216 return false;
217 }
218 mOVInfo = ov;
219 return true;
220}
221
Saurabh Shahacf10202013-02-26 10:15:15 -0800222//Update src format based on rotator's destination format.
223void MdpCtrl::updateSrcFormat(const uint32_t& rotDestFmt) {
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800224 utils::Whf whf = getSrcWhf();
Saurabh Shahacf10202013-02-26 10:15:15 -0800225 whf.format = rotDestFmt;
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800226 setSrcWhf(whf);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700227}
228
229void MdpCtrl::dump() const {
230 ALOGE("== Dump MdpCtrl start ==");
Naseer Ahmed29a26812012-06-14 00:56:20 -0700231 mFd.dump();
232 mdp_wrapper::dump("mOVInfo", mOVInfo);
233 ALOGE("== Dump MdpCtrl end ==");
234}
235
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800236void MdpCtrl::getDump(char *buf, size_t len) {
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700237 ovutils::getDump(buf, len, "Ctrl", mOVInfo);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800238}
239
Naseer Ahmed29a26812012-06-14 00:56:20 -0700240void MdpData::dump() const {
241 ALOGE("== Dump MdpData start ==");
242 mFd.dump();
243 mdp_wrapper::dump("mOvData", mOvData);
244 ALOGE("== Dump MdpData end ==");
245}
246
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800247void MdpData::getDump(char *buf, size_t len) {
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700248 ovutils::getDump(buf, len, "Data", mOvData);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800249}
250
Naseer Ahmed29a26812012-06-14 00:56:20 -0700251void MdpCtrl3D::dump() const {
252 ALOGE("== Dump MdpCtrl start ==");
253 mFd.dump();
254 ALOGE("== Dump MdpCtrl end ==");
255}
256
Saurabh Shah5daeee52013-01-23 16:52:26 +0800257bool MdpCtrl::setVisualParams(const MetaData_t& data) {
258 bool needUpdate = false;
259#ifdef USES_POST_PROCESSING
260 /* calculate the data */
261 if (data.operation & PP_PARAM_HSIC) {
262 if (mParams.params.pa_params.hue != data.hsicData.hue) {
263 ALOGD_IF(HSIC_SETTINGS_DEBUG,
264 "Hue has changed from %d to %d",
265 mParams.params.pa_params.hue,data.hsicData.hue);
266 needUpdate = true;
267 }
268
269 if (!isEqual(mParams.params.pa_params.sat,
270 data.hsicData.saturation)) {
271 ALOGD_IF(HSIC_SETTINGS_DEBUG,
272 "Saturation has changed from %f to %f",
273 mParams.params.pa_params.sat,
274 data.hsicData.saturation);
275 needUpdate = true;
276 }
277
278 if (mParams.params.pa_params.intensity != data.hsicData.intensity) {
279 ALOGD_IF(HSIC_SETTINGS_DEBUG,
280 "Intensity has changed from %d to %d",
281 mParams.params.pa_params.intensity,
282 data.hsicData.intensity);
283 needUpdate = true;
284 }
285
286 if (!isEqual(mParams.params.pa_params.contrast,
287 data.hsicData.contrast)) {
288 ALOGD_IF(HSIC_SETTINGS_DEBUG,
289 "Contrast has changed from %f to %f",
290 mParams.params.pa_params.contrast,
291 data.hsicData.contrast);
292 needUpdate = true;
293 }
294
295 if (needUpdate) {
296 mParams.params.pa_params.hue = data.hsicData.hue;
297 mParams.params.pa_params.sat = data.hsicData.saturation;
298 mParams.params.pa_params.intensity = data.hsicData.intensity;
299 mParams.params.pa_params.contrast = data.hsicData.contrast;
300 mParams.params.pa_params.ops = MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
301 mParams.operation |= PP_OP_PA;
302 }
303 }
304
305 if (data.operation & PP_PARAM_SHARP2) {
306 if (mParams.params.sharp_params.strength != data.Sharp2Data.strength) {
307 needUpdate = true;
308 }
309 if (mParams.params.sharp_params.edge_thr != data.Sharp2Data.edge_thr) {
310 needUpdate = true;
311 }
312 if (mParams.params.sharp_params.smooth_thr !=
313 data.Sharp2Data.smooth_thr) {
314 needUpdate = true;
315 }
316 if (mParams.params.sharp_params.noise_thr !=
317 data.Sharp2Data.noise_thr) {
318 needUpdate = true;
319 }
320
321 if (needUpdate) {
322 mParams.params.sharp_params.strength = data.Sharp2Data.strength;
323 mParams.params.sharp_params.edge_thr = data.Sharp2Data.edge_thr;
324 mParams.params.sharp_params.smooth_thr =
325 data.Sharp2Data.smooth_thr;
326 mParams.params.sharp_params.noise_thr = data.Sharp2Data.noise_thr;
327 mParams.params.sharp_params.ops =
328 MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
329 mParams.operation |= PP_OP_SHARP;
330 }
331 }
332
333 if (data.operation & PP_PARAM_IGC) {
334 if (mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data == NULL){
335 uint32_t *igcData
336 = (uint32_t *)malloc(2 * MAX_IGC_LUT_ENTRIES * sizeof(uint32_t));
337 if (!igcData) {
338 ALOGE("IGC storage allocated failed");
339 return false;
340 }
341 mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data = igcData;
342 mOVInfo.overlay_pp_cfg.igc_cfg.c2_data
343 = igcData + MAX_IGC_LUT_ENTRIES;
344 }
345
346 memcpy(mParams.params.igc_lut_params.c0,
347 data.igcData.c0, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
348 memcpy(mParams.params.igc_lut_params.c1,
349 data.igcData.c1, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
350 memcpy(mParams.params.igc_lut_params.c2,
351 data.igcData.c2, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
352
353 mParams.params.igc_lut_params.ops
354 = MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
355 mParams.operation |= PP_OP_IGC;
356 needUpdate = true;
357 }
358
359 if (data.operation & PP_PARAM_VID_INTFC) {
360 mParams.params.conv_params.interface =
361 (interface_type) data.video_interface;
362 needUpdate = true;
363 }
364
365 if (needUpdate) {
366 display_pp_compute_params(&mParams, &mOVInfo.overlay_pp_cfg);
367 mPPChanged = true;
368 }
369#endif
370 return true;
371}
372
Naseer Ahmed29a26812012-06-14 00:56:20 -0700373} // overlay