blob: e5d7d9864d450c8990bd5777fa94443b9066b989 [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);
Sushil Chauhan5491c8a2013-05-24 10:15:30 -0700183 } else if (mOVInfo.flags & MDP_DEINTERLACE) {
184 // For interlaced, crop.h should be 4-aligned
185 if (!(mOVInfo.flags & MDP_SOURCE_ROTATED_90) &&
186 (mOVInfo.src_rect.h % 4))
187 mOVInfo.src_rect.h = utils::aligndown(mOVInfo.src_rect.h, 4);
Saurabh Shahce416f02013-04-10 13:33:09 -0700188 }
Saurabh Shahb121e142012-08-20 17:59:13 -0700189 }
190
Saurabh Shahfc2acbe2012-08-17 19:47:52 -0700191 if(this->ovChanged()) {
192 if(!mdp_wrapper::setOverlay(mFd.getFD(), mOVInfo)) {
193 ALOGE("MdpCtrl failed to setOverlay, restoring last known "
194 "good ov info");
195 mdp_wrapper::dump("== Bad OVInfo is: ", mOVInfo);
196 mdp_wrapper::dump("== Last good known OVInfo is: ", mLkgo);
197 this->restore();
198 return false;
199 }
200 this->save();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700201 }
Saurabh Shahb121e142012-08-20 17:59:13 -0700202
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700203 return true;
204}
205
Naseer Ahmed29a26812012-06-14 00:56:20 -0700206bool MdpCtrl::get() {
207 mdp_overlay ov;
208 ov.id = mOVInfo.id;
209 if (!mdp_wrapper::getOverlay(mFd.getFD(), ov)) {
210 ALOGE("MdpCtrl get failed");
211 return false;
212 }
213 mOVInfo = ov;
214 return true;
215}
216
Saurabh Shahacf10202013-02-26 10:15:15 -0800217//Update src format based on rotator's destination format.
218void MdpCtrl::updateSrcFormat(const uint32_t& rotDestFmt) {
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800219 utils::Whf whf = getSrcWhf();
Saurabh Shahacf10202013-02-26 10:15:15 -0800220 whf.format = rotDestFmt;
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800221 setSrcWhf(whf);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700222}
223
224void MdpCtrl::dump() const {
225 ALOGE("== Dump MdpCtrl start ==");
Naseer Ahmed29a26812012-06-14 00:56:20 -0700226 mFd.dump();
227 mdp_wrapper::dump("mOVInfo", mOVInfo);
228 ALOGE("== Dump MdpCtrl end ==");
229}
230
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800231void MdpCtrl::getDump(char *buf, size_t len) {
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700232 ovutils::getDump(buf, len, "Ctrl", mOVInfo);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800233}
234
Naseer Ahmed29a26812012-06-14 00:56:20 -0700235void MdpData::dump() const {
236 ALOGE("== Dump MdpData start ==");
237 mFd.dump();
238 mdp_wrapper::dump("mOvData", mOvData);
239 ALOGE("== Dump MdpData end ==");
240}
241
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800242void MdpData::getDump(char *buf, size_t len) {
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700243 ovutils::getDump(buf, len, "Data", mOvData);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800244}
245
Naseer Ahmed29a26812012-06-14 00:56:20 -0700246void MdpCtrl3D::dump() const {
247 ALOGE("== Dump MdpCtrl start ==");
248 mFd.dump();
249 ALOGE("== Dump MdpCtrl end ==");
250}
251
Saurabh Shah5daeee52013-01-23 16:52:26 +0800252bool MdpCtrl::setVisualParams(const MetaData_t& data) {
253 bool needUpdate = false;
254#ifdef USES_POST_PROCESSING
255 /* calculate the data */
256 if (data.operation & PP_PARAM_HSIC) {
257 if (mParams.params.pa_params.hue != data.hsicData.hue) {
258 ALOGD_IF(HSIC_SETTINGS_DEBUG,
259 "Hue has changed from %d to %d",
260 mParams.params.pa_params.hue,data.hsicData.hue);
261 needUpdate = true;
262 }
263
264 if (!isEqual(mParams.params.pa_params.sat,
265 data.hsicData.saturation)) {
266 ALOGD_IF(HSIC_SETTINGS_DEBUG,
267 "Saturation has changed from %f to %f",
268 mParams.params.pa_params.sat,
269 data.hsicData.saturation);
270 needUpdate = true;
271 }
272
273 if (mParams.params.pa_params.intensity != data.hsicData.intensity) {
274 ALOGD_IF(HSIC_SETTINGS_DEBUG,
275 "Intensity has changed from %d to %d",
276 mParams.params.pa_params.intensity,
277 data.hsicData.intensity);
278 needUpdate = true;
279 }
280
281 if (!isEqual(mParams.params.pa_params.contrast,
282 data.hsicData.contrast)) {
283 ALOGD_IF(HSIC_SETTINGS_DEBUG,
284 "Contrast has changed from %f to %f",
285 mParams.params.pa_params.contrast,
286 data.hsicData.contrast);
287 needUpdate = true;
288 }
289
290 if (needUpdate) {
291 mParams.params.pa_params.hue = data.hsicData.hue;
292 mParams.params.pa_params.sat = data.hsicData.saturation;
293 mParams.params.pa_params.intensity = data.hsicData.intensity;
294 mParams.params.pa_params.contrast = data.hsicData.contrast;
295 mParams.params.pa_params.ops = MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
296 mParams.operation |= PP_OP_PA;
297 }
298 }
299
300 if (data.operation & PP_PARAM_SHARP2) {
301 if (mParams.params.sharp_params.strength != data.Sharp2Data.strength) {
302 needUpdate = true;
303 }
304 if (mParams.params.sharp_params.edge_thr != data.Sharp2Data.edge_thr) {
305 needUpdate = true;
306 }
307 if (mParams.params.sharp_params.smooth_thr !=
308 data.Sharp2Data.smooth_thr) {
309 needUpdate = true;
310 }
311 if (mParams.params.sharp_params.noise_thr !=
312 data.Sharp2Data.noise_thr) {
313 needUpdate = true;
314 }
315
316 if (needUpdate) {
317 mParams.params.sharp_params.strength = data.Sharp2Data.strength;
318 mParams.params.sharp_params.edge_thr = data.Sharp2Data.edge_thr;
319 mParams.params.sharp_params.smooth_thr =
320 data.Sharp2Data.smooth_thr;
321 mParams.params.sharp_params.noise_thr = data.Sharp2Data.noise_thr;
322 mParams.params.sharp_params.ops =
323 MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
324 mParams.operation |= PP_OP_SHARP;
325 }
326 }
327
328 if (data.operation & PP_PARAM_IGC) {
329 if (mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data == NULL){
330 uint32_t *igcData
331 = (uint32_t *)malloc(2 * MAX_IGC_LUT_ENTRIES * sizeof(uint32_t));
332 if (!igcData) {
333 ALOGE("IGC storage allocated failed");
334 return false;
335 }
336 mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data = igcData;
337 mOVInfo.overlay_pp_cfg.igc_cfg.c2_data
338 = igcData + MAX_IGC_LUT_ENTRIES;
339 }
340
341 memcpy(mParams.params.igc_lut_params.c0,
342 data.igcData.c0, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
343 memcpy(mParams.params.igc_lut_params.c1,
344 data.igcData.c1, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
345 memcpy(mParams.params.igc_lut_params.c2,
346 data.igcData.c2, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
347
348 mParams.params.igc_lut_params.ops
349 = MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
350 mParams.operation |= PP_OP_IGC;
351 needUpdate = true;
352 }
353
354 if (data.operation & PP_PARAM_VID_INTFC) {
355 mParams.params.conv_params.interface =
356 (interface_type) data.video_interface;
357 needUpdate = true;
358 }
359
360 if (needUpdate) {
361 display_pp_compute_params(&mParams, &mOVInfo.overlay_pp_cfg);
362 mPPChanged = true;
363 }
364#endif
365 return true;
366}
367
Naseer Ahmed29a26812012-06-14 00:56:20 -0700368} // overlay