blob: 0de62769e7ad23629a10cb0e7c937bb030b31989 [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
147 float horDscale = ceilf((float)mOVInfo.src_rect.w /
148 (float)mOVInfo.dst_rect.w);
149 float verDscale = ceilf((float)mOVInfo.src_rect.h /
150 (float)mOVInfo.dst_rect.h);
151
152 //Next power of 2, if not already
153 horDscale = powf(2.0f, ceilf(log2f(horDscale)));
154 verDscale = powf(2.0f, ceilf(log2f(verDscale)));
155
156 //Since MDP can do 1/4 dscale and has better quality, split the task
157 //between decimator and MDP downscale
158 horDscale /= 4.0f;
159 verDscale /= 4.0f;
160
161 if(horDscale < minHorDeci)
162 horDscale = minHorDeci;
163
164 if((int)horDscale)
165 mOVInfo.horz_deci = (int)log2f(horDscale);
166
167 if((int)verDscale)
168 mOVInfo.vert_deci = (int)log2f(verDscale);
169 }
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800170}
171
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700172bool MdpCtrl::set() {
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700173 int mdpVersion = MDPVersion::getInstance().getMDPVersion();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700174 //deferred calcs, so APIs could be called in any order.
Saurabh Shahacf10202013-02-26 10:15:15 -0800175 doTransform();
176 doDownscale();
Saurabh Shahb121e142012-08-20 17:59:13 -0700177 utils::Whf whf = getSrcWhf();
178 if(utils::isYuv(whf.format)) {
Sushil Chauhan1cac8152013-05-08 15:53:51 -0700179 utils::normalizeCrop(mOVInfo.src_rect.x, mOVInfo.src_rect.w);
180 utils::normalizeCrop(mOVInfo.src_rect.y, mOVInfo.src_rect.h);
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700181 if(mdpVersion < MDSS_V5) {
Saurabh Shahce416f02013-04-10 13:33:09 -0700182 utils::even_floor(mOVInfo.dst_rect.w);
183 utils::even_floor(mOVInfo.dst_rect.h);
Sushil Chauhan5491c8a2013-05-24 10:15:30 -0700184 } else if (mOVInfo.flags & MDP_DEINTERLACE) {
185 // For interlaced, crop.h should be 4-aligned
186 if (!(mOVInfo.flags & MDP_SOURCE_ROTATED_90) &&
187 (mOVInfo.src_rect.h % 4))
188 mOVInfo.src_rect.h = utils::aligndown(mOVInfo.src_rect.h, 4);
Saurabh Shahce416f02013-04-10 13:33:09 -0700189 }
Saurabh Shahb121e142012-08-20 17:59:13 -0700190 }
191
Saurabh Shahdf0be752013-05-23 14:40:00 -0700192 if(this->ovChanged() || mForceSet) {
193 mForceSet = false;
Saurabh Shahfc2acbe2012-08-17 19:47:52 -0700194 if(!mdp_wrapper::setOverlay(mFd.getFD(), mOVInfo)) {
195 ALOGE("MdpCtrl failed to setOverlay, restoring last known "
196 "good ov info");
197 mdp_wrapper::dump("== Bad OVInfo is: ", mOVInfo);
198 mdp_wrapper::dump("== Last good known OVInfo is: ", mLkgo);
199 this->restore();
200 return false;
201 }
202 this->save();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700203 }
Saurabh Shahb121e142012-08-20 17:59:13 -0700204
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700205 return true;
206}
207
Naseer Ahmed29a26812012-06-14 00:56:20 -0700208bool MdpCtrl::get() {
209 mdp_overlay ov;
210 ov.id = mOVInfo.id;
211 if (!mdp_wrapper::getOverlay(mFd.getFD(), ov)) {
212 ALOGE("MdpCtrl get failed");
213 return false;
214 }
215 mOVInfo = ov;
216 return true;
217}
218
Saurabh Shahacf10202013-02-26 10:15:15 -0800219//Update src format based on rotator's destination format.
220void MdpCtrl::updateSrcFormat(const uint32_t& rotDestFmt) {
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800221 utils::Whf whf = getSrcWhf();
Saurabh Shahacf10202013-02-26 10:15:15 -0800222 whf.format = rotDestFmt;
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800223 setSrcWhf(whf);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700224}
225
226void MdpCtrl::dump() const {
227 ALOGE("== Dump MdpCtrl start ==");
Naseer Ahmed29a26812012-06-14 00:56:20 -0700228 mFd.dump();
229 mdp_wrapper::dump("mOVInfo", mOVInfo);
230 ALOGE("== Dump MdpCtrl end ==");
231}
232
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800233void MdpCtrl::getDump(char *buf, size_t len) {
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700234 ovutils::getDump(buf, len, "Ctrl", mOVInfo);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800235}
236
Naseer Ahmed29a26812012-06-14 00:56:20 -0700237void MdpData::dump() const {
238 ALOGE("== Dump MdpData start ==");
239 mFd.dump();
240 mdp_wrapper::dump("mOvData", mOvData);
241 ALOGE("== Dump MdpData end ==");
242}
243
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800244void MdpData::getDump(char *buf, size_t len) {
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700245 ovutils::getDump(buf, len, "Data", mOvData);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800246}
247
Naseer Ahmed29a26812012-06-14 00:56:20 -0700248void MdpCtrl3D::dump() const {
249 ALOGE("== Dump MdpCtrl start ==");
250 mFd.dump();
251 ALOGE("== Dump MdpCtrl end ==");
252}
253
Saurabh Shah5daeee52013-01-23 16:52:26 +0800254bool MdpCtrl::setVisualParams(const MetaData_t& data) {
255 bool needUpdate = false;
256#ifdef USES_POST_PROCESSING
257 /* calculate the data */
258 if (data.operation & PP_PARAM_HSIC) {
259 if (mParams.params.pa_params.hue != data.hsicData.hue) {
260 ALOGD_IF(HSIC_SETTINGS_DEBUG,
261 "Hue has changed from %d to %d",
262 mParams.params.pa_params.hue,data.hsicData.hue);
263 needUpdate = true;
264 }
265
266 if (!isEqual(mParams.params.pa_params.sat,
267 data.hsicData.saturation)) {
268 ALOGD_IF(HSIC_SETTINGS_DEBUG,
269 "Saturation has changed from %f to %f",
270 mParams.params.pa_params.sat,
271 data.hsicData.saturation);
272 needUpdate = true;
273 }
274
275 if (mParams.params.pa_params.intensity != data.hsicData.intensity) {
276 ALOGD_IF(HSIC_SETTINGS_DEBUG,
277 "Intensity has changed from %d to %d",
278 mParams.params.pa_params.intensity,
279 data.hsicData.intensity);
280 needUpdate = true;
281 }
282
283 if (!isEqual(mParams.params.pa_params.contrast,
284 data.hsicData.contrast)) {
285 ALOGD_IF(HSIC_SETTINGS_DEBUG,
286 "Contrast has changed from %f to %f",
287 mParams.params.pa_params.contrast,
288 data.hsicData.contrast);
289 needUpdate = true;
290 }
291
292 if (needUpdate) {
293 mParams.params.pa_params.hue = data.hsicData.hue;
294 mParams.params.pa_params.sat = data.hsicData.saturation;
295 mParams.params.pa_params.intensity = data.hsicData.intensity;
296 mParams.params.pa_params.contrast = data.hsicData.contrast;
297 mParams.params.pa_params.ops = MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
298 mParams.operation |= PP_OP_PA;
299 }
300 }
301
302 if (data.operation & PP_PARAM_SHARP2) {
303 if (mParams.params.sharp_params.strength != data.Sharp2Data.strength) {
304 needUpdate = true;
305 }
306 if (mParams.params.sharp_params.edge_thr != data.Sharp2Data.edge_thr) {
307 needUpdate = true;
308 }
309 if (mParams.params.sharp_params.smooth_thr !=
310 data.Sharp2Data.smooth_thr) {
311 needUpdate = true;
312 }
313 if (mParams.params.sharp_params.noise_thr !=
314 data.Sharp2Data.noise_thr) {
315 needUpdate = true;
316 }
317
318 if (needUpdate) {
319 mParams.params.sharp_params.strength = data.Sharp2Data.strength;
320 mParams.params.sharp_params.edge_thr = data.Sharp2Data.edge_thr;
321 mParams.params.sharp_params.smooth_thr =
322 data.Sharp2Data.smooth_thr;
323 mParams.params.sharp_params.noise_thr = data.Sharp2Data.noise_thr;
324 mParams.params.sharp_params.ops =
325 MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
326 mParams.operation |= PP_OP_SHARP;
327 }
328 }
329
330 if (data.operation & PP_PARAM_IGC) {
331 if (mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data == NULL){
332 uint32_t *igcData
333 = (uint32_t *)malloc(2 * MAX_IGC_LUT_ENTRIES * sizeof(uint32_t));
334 if (!igcData) {
335 ALOGE("IGC storage allocated failed");
336 return false;
337 }
338 mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data = igcData;
339 mOVInfo.overlay_pp_cfg.igc_cfg.c2_data
340 = igcData + MAX_IGC_LUT_ENTRIES;
341 }
342
343 memcpy(mParams.params.igc_lut_params.c0,
344 data.igcData.c0, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
345 memcpy(mParams.params.igc_lut_params.c1,
346 data.igcData.c1, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
347 memcpy(mParams.params.igc_lut_params.c2,
348 data.igcData.c2, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
349
350 mParams.params.igc_lut_params.ops
351 = MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
352 mParams.operation |= PP_OP_IGC;
353 needUpdate = true;
354 }
355
356 if (data.operation & PP_PARAM_VID_INTFC) {
357 mParams.params.conv_params.interface =
358 (interface_type) data.video_interface;
359 needUpdate = true;
360 }
361
362 if (needUpdate) {
363 display_pp_compute_params(&mParams, &mOVInfo.overlay_pp_cfg);
364 mPPChanged = true;
365 }
366#endif
367 return true;
368}
369
Naseer Ahmed29a26812012-06-14 00:56:20 -0700370} // overlay