blob: 4c77f2e91a9a60e08b3c8cd1a8a0894f03fb9b6b [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 Shah5daeee52013-01-23 16:52:26 +080057#ifdef USES_POST_PROCESSING
58 mPPChanged = false;
59 memset(&mParams, 0, sizeof(struct compute_params));
60 mParams.params.conv_params.order = hsic_order_hsc_i;
61 mParams.params.conv_params.interface = interface_rec601;
62 mParams.params.conv_params.cc_matrix[0][0] = 1;
63 mParams.params.conv_params.cc_matrix[1][1] = 1;
64 mParams.params.conv_params.cc_matrix[2][2] = 1;
65#endif
Naseer Ahmed29a26812012-06-14 00:56:20 -070066}
67
68bool MdpCtrl::close() {
Saurabh Shah8e1ae952012-08-15 12:15:14 -070069 bool result = true;
Saurabh Shah8e1ae952012-08-15 12:15:14 -070070 if(MSMFB_NEW_REQUEST != static_cast<int>(mOVInfo.id)) {
71 if(!mdp_wrapper::unsetOverlay(mFd.getFD(), mOVInfo.id)) {
72 ALOGE("MdpCtrl close error in unset");
73 result = false;
74 }
Naseer Ahmed29a26812012-06-14 00:56:20 -070075 }
Saurabh Shah5daeee52013-01-23 16:52:26 +080076#ifdef USES_POST_PROCESSING
77 /* free allocated memory in PP */
78 if (mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data)
79 free(mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data);
80#endif
Naseer Ahmed29a26812012-06-14 00:56:20 -070081 reset();
Saurabh Shahacf10202013-02-26 10:15:15 -080082
Naseer Ahmed29a26812012-06-14 00:56:20 -070083 if(!mFd.close()) {
Saurabh Shah8e1ae952012-08-15 12:15:14 -070084 result = false;
Naseer Ahmed29a26812012-06-14 00:56:20 -070085 }
Saurabh Shah8e1ae952012-08-15 12:15:14 -070086
87 return result;
Naseer Ahmed29a26812012-06-14 00:56:20 -070088}
89
Saurabh Shahacf10202013-02-26 10:15:15 -080090void MdpCtrl::setSource(const utils::PipeArgs& args) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -070091 setSrcWhf(args.whf);
92
93 //TODO These are hardcoded. Can be moved out of setSource.
94 mOVInfo.alpha = 0xff;
95 mOVInfo.transp_mask = 0xffffffff;
96
97 //TODO These calls should ideally be a part of setPipeParams API
98 setFlags(args.mdpFlags);
99 setZ(args.zorder);
100 setIsFg(args.isFg);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700101}
102
Saurabh Shahacf10202013-02-26 10:15:15 -0800103void MdpCtrl::setCrop(const utils::Dim& d) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700104 setSrcRectDim(d);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700105}
106
Saurabh Shahacf10202013-02-26 10:15:15 -0800107void MdpCtrl::setPosition(const overlay::utils::Dim& d) {
108 setDstRectDim(d);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700109}
110
Saurabh Shahacf10202013-02-26 10:15:15 -0800111void MdpCtrl::setTransform(const utils::eTransform& orient) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700112 int rot = utils::getMdpOrient(orient);
113 setUserData(rot);
Saurabh Shaha73738d2012-08-09 18:15:18 -0700114 mOrientation = static_cast<utils::eTransform>(rot);
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800115}
116
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700117void MdpCtrl::doTransform() {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700118 setRotationFlags();
Saurabh Shahacf10202013-02-26 10:15:15 -0800119 utils::Whf whf = getSrcWhf();
120 utils::Dim dim = getSrcRectDim();
121 utils::preRotateSource(mOrientation, whf, dim);
122 setSrcWhf(whf);
123 setSrcRectDim(dim);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700124}
125
Saurabh Shahacf10202013-02-26 10:15:15 -0800126void MdpCtrl::doDownscale() {
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700127 int mdpVersion = MDPVersion::getInstance().getMDPVersion();
128 if(mdpVersion < MDSS_V5) {
129 mOVInfo.src_rect.x >>= mDownscale;
130 mOVInfo.src_rect.y >>= mDownscale;
131 mOVInfo.src_rect.w >>= mDownscale;
132 mOVInfo.src_rect.h >>= mDownscale;
133 } else if(MDPVersion::getInstance().supportsDecimation()) {
134 //Decimation + MDP Downscale
135 mOVInfo.horz_deci = 0;
136 mOVInfo.vert_deci = 0;
137 int minHorDeci = 0;
138 if(mOVInfo.src_rect.w > 2048) {
139 //If the client sends us something > what a layer mixer supports
140 //then it means it doesn't want to use split-pipe but wants us to
141 //decimate. A minimum decimation of 2 will ensure that the width is
142 //always within layer mixer limits.
143 minHorDeci = 2;
144 }
145
146 float horDscale = ceilf((float)mOVInfo.src_rect.w /
147 (float)mOVInfo.dst_rect.w);
148 float verDscale = ceilf((float)mOVInfo.src_rect.h /
149 (float)mOVInfo.dst_rect.h);
150
151 //Next power of 2, if not already
152 horDscale = powf(2.0f, ceilf(log2f(horDscale)));
153 verDscale = powf(2.0f, ceilf(log2f(verDscale)));
154
155 //Since MDP can do 1/4 dscale and has better quality, split the task
156 //between decimator and MDP downscale
157 horDscale /= 4.0f;
158 verDscale /= 4.0f;
159
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();
175 doDownscale();
Saurabh Shahb121e142012-08-20 17:59:13 -0700176 utils::Whf whf = getSrcWhf();
177 if(utils::isYuv(whf.format)) {
Sushil Chauhan1cac8152013-05-08 15:53:51 -0700178 utils::normalizeCrop(mOVInfo.src_rect.x, mOVInfo.src_rect.w);
179 utils::normalizeCrop(mOVInfo.src_rect.y, mOVInfo.src_rect.h);
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700180 if(mdpVersion < MDSS_V5) {
Saurabh Shahce416f02013-04-10 13:33:09 -0700181 utils::even_floor(mOVInfo.dst_rect.w);
182 utils::even_floor(mOVInfo.dst_rect.h);
183 }
Saurabh Shahb121e142012-08-20 17:59:13 -0700184 }
185
Saurabh Shahfc2acbe2012-08-17 19:47:52 -0700186 if(this->ovChanged()) {
187 if(!mdp_wrapper::setOverlay(mFd.getFD(), mOVInfo)) {
188 ALOGE("MdpCtrl failed to setOverlay, restoring last known "
189 "good ov info");
190 mdp_wrapper::dump("== Bad OVInfo is: ", mOVInfo);
191 mdp_wrapper::dump("== Last good known OVInfo is: ", mLkgo);
192 this->restore();
193 return false;
194 }
195 this->save();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700196 }
Saurabh Shahb121e142012-08-20 17:59:13 -0700197
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700198 return true;
199}
200
Naseer Ahmed29a26812012-06-14 00:56:20 -0700201bool MdpCtrl::get() {
202 mdp_overlay ov;
203 ov.id = mOVInfo.id;
204 if (!mdp_wrapper::getOverlay(mFd.getFD(), ov)) {
205 ALOGE("MdpCtrl get failed");
206 return false;
207 }
208 mOVInfo = ov;
209 return true;
210}
211
Saurabh Shahacf10202013-02-26 10:15:15 -0800212//Update src format based on rotator's destination format.
213void MdpCtrl::updateSrcFormat(const uint32_t& rotDestFmt) {
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800214 utils::Whf whf = getSrcWhf();
Saurabh Shahacf10202013-02-26 10:15:15 -0800215 whf.format = rotDestFmt;
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800216 setSrcWhf(whf);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700217}
218
219void MdpCtrl::dump() const {
220 ALOGE("== Dump MdpCtrl start ==");
Naseer Ahmed29a26812012-06-14 00:56:20 -0700221 mFd.dump();
222 mdp_wrapper::dump("mOVInfo", mOVInfo);
223 ALOGE("== Dump MdpCtrl end ==");
224}
225
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800226void MdpCtrl::getDump(char *buf, size_t len) {
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700227 ovutils::getDump(buf, len, "Ctrl", mOVInfo);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800228}
229
Naseer Ahmed29a26812012-06-14 00:56:20 -0700230void MdpData::dump() const {
231 ALOGE("== Dump MdpData start ==");
232 mFd.dump();
233 mdp_wrapper::dump("mOvData", mOvData);
234 ALOGE("== Dump MdpData end ==");
235}
236
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800237void MdpData::getDump(char *buf, size_t len) {
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700238 ovutils::getDump(buf, len, "Data", mOvData);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800239}
240
Naseer Ahmed29a26812012-06-14 00:56:20 -0700241void MdpCtrl3D::dump() const {
242 ALOGE("== Dump MdpCtrl start ==");
243 mFd.dump();
244 ALOGE("== Dump MdpCtrl end ==");
245}
246
Saurabh Shah5daeee52013-01-23 16:52:26 +0800247bool MdpCtrl::setVisualParams(const MetaData_t& data) {
248 bool needUpdate = false;
249#ifdef USES_POST_PROCESSING
250 /* calculate the data */
251 if (data.operation & PP_PARAM_HSIC) {
252 if (mParams.params.pa_params.hue != data.hsicData.hue) {
253 ALOGD_IF(HSIC_SETTINGS_DEBUG,
254 "Hue has changed from %d to %d",
255 mParams.params.pa_params.hue,data.hsicData.hue);
256 needUpdate = true;
257 }
258
259 if (!isEqual(mParams.params.pa_params.sat,
260 data.hsicData.saturation)) {
261 ALOGD_IF(HSIC_SETTINGS_DEBUG,
262 "Saturation has changed from %f to %f",
263 mParams.params.pa_params.sat,
264 data.hsicData.saturation);
265 needUpdate = true;
266 }
267
268 if (mParams.params.pa_params.intensity != data.hsicData.intensity) {
269 ALOGD_IF(HSIC_SETTINGS_DEBUG,
270 "Intensity has changed from %d to %d",
271 mParams.params.pa_params.intensity,
272 data.hsicData.intensity);
273 needUpdate = true;
274 }
275
276 if (!isEqual(mParams.params.pa_params.contrast,
277 data.hsicData.contrast)) {
278 ALOGD_IF(HSIC_SETTINGS_DEBUG,
279 "Contrast has changed from %f to %f",
280 mParams.params.pa_params.contrast,
281 data.hsicData.contrast);
282 needUpdate = true;
283 }
284
285 if (needUpdate) {
286 mParams.params.pa_params.hue = data.hsicData.hue;
287 mParams.params.pa_params.sat = data.hsicData.saturation;
288 mParams.params.pa_params.intensity = data.hsicData.intensity;
289 mParams.params.pa_params.contrast = data.hsicData.contrast;
290 mParams.params.pa_params.ops = MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
291 mParams.operation |= PP_OP_PA;
292 }
293 }
294
295 if (data.operation & PP_PARAM_SHARP2) {
296 if (mParams.params.sharp_params.strength != data.Sharp2Data.strength) {
297 needUpdate = true;
298 }
299 if (mParams.params.sharp_params.edge_thr != data.Sharp2Data.edge_thr) {
300 needUpdate = true;
301 }
302 if (mParams.params.sharp_params.smooth_thr !=
303 data.Sharp2Data.smooth_thr) {
304 needUpdate = true;
305 }
306 if (mParams.params.sharp_params.noise_thr !=
307 data.Sharp2Data.noise_thr) {
308 needUpdate = true;
309 }
310
311 if (needUpdate) {
312 mParams.params.sharp_params.strength = data.Sharp2Data.strength;
313 mParams.params.sharp_params.edge_thr = data.Sharp2Data.edge_thr;
314 mParams.params.sharp_params.smooth_thr =
315 data.Sharp2Data.smooth_thr;
316 mParams.params.sharp_params.noise_thr = data.Sharp2Data.noise_thr;
317 mParams.params.sharp_params.ops =
318 MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
319 mParams.operation |= PP_OP_SHARP;
320 }
321 }
322
323 if (data.operation & PP_PARAM_IGC) {
324 if (mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data == NULL){
325 uint32_t *igcData
326 = (uint32_t *)malloc(2 * MAX_IGC_LUT_ENTRIES * sizeof(uint32_t));
327 if (!igcData) {
328 ALOGE("IGC storage allocated failed");
329 return false;
330 }
331 mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data = igcData;
332 mOVInfo.overlay_pp_cfg.igc_cfg.c2_data
333 = igcData + MAX_IGC_LUT_ENTRIES;
334 }
335
336 memcpy(mParams.params.igc_lut_params.c0,
337 data.igcData.c0, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
338 memcpy(mParams.params.igc_lut_params.c1,
339 data.igcData.c1, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
340 memcpy(mParams.params.igc_lut_params.c2,
341 data.igcData.c2, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
342
343 mParams.params.igc_lut_params.ops
344 = MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
345 mParams.operation |= PP_OP_IGC;
346 needUpdate = true;
347 }
348
349 if (data.operation & PP_PARAM_VID_INTFC) {
350 mParams.params.conv_params.interface =
351 (interface_type) data.video_interface;
352 needUpdate = true;
353 }
354
355 if (needUpdate) {
356 display_pp_compute_params(&mParams, &mOVInfo.overlay_pp_cfg);
357 mPPChanged = true;
358 }
359#endif
360 return true;
361}
362
Naseer Ahmed29a26812012-06-14 00:56:20 -0700363} // overlay