blob: 2abdc1950612d4d561e3267474c04fd33f36808a [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
Saurabh Shah1a03d482013-05-29 13:44:20 -0700147 float horDscale = 0.0f;
148 float verDscale = 0.0f;
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700149
Saurabh Shah1a03d482013-05-29 13:44:20 -0700150 utils::getDecimationFactor(mOVInfo.src_rect.w, mOVInfo.src_rect.h,
151 mOVInfo.dst_rect.w, mOVInfo.dst_rect.h, horDscale, verDscale);
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700152
153 if(horDscale < minHorDeci)
154 horDscale = minHorDeci;
155
156 if((int)horDscale)
157 mOVInfo.horz_deci = (int)log2f(horDscale);
158
159 if((int)verDscale)
160 mOVInfo.vert_deci = (int)log2f(verDscale);
161 }
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800162}
163
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700164bool MdpCtrl::set() {
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700165 int mdpVersion = MDPVersion::getInstance().getMDPVersion();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700166 //deferred calcs, so APIs could be called in any order.
Saurabh Shahacf10202013-02-26 10:15:15 -0800167 doTransform();
168 doDownscale();
Saurabh Shahb121e142012-08-20 17:59:13 -0700169 utils::Whf whf = getSrcWhf();
170 if(utils::isYuv(whf.format)) {
Sushil Chauhan1cac8152013-05-08 15:53:51 -0700171 utils::normalizeCrop(mOVInfo.src_rect.x, mOVInfo.src_rect.w);
172 utils::normalizeCrop(mOVInfo.src_rect.y, mOVInfo.src_rect.h);
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700173 if(mdpVersion < MDSS_V5) {
Saurabh Shahce416f02013-04-10 13:33:09 -0700174 utils::even_floor(mOVInfo.dst_rect.w);
175 utils::even_floor(mOVInfo.dst_rect.h);
176 }
Saurabh Shahb121e142012-08-20 17:59:13 -0700177 }
178
Saurabh Shahdf0be752013-05-23 14:40:00 -0700179 if(this->ovChanged() || mForceSet) {
180 mForceSet = false;
Saurabh Shahfc2acbe2012-08-17 19:47:52 -0700181 if(!mdp_wrapper::setOverlay(mFd.getFD(), mOVInfo)) {
182 ALOGE("MdpCtrl failed to setOverlay, restoring last known "
183 "good ov info");
184 mdp_wrapper::dump("== Bad OVInfo is: ", mOVInfo);
185 mdp_wrapper::dump("== Last good known OVInfo is: ", mLkgo);
186 this->restore();
187 return false;
188 }
189 this->save();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700190 }
Saurabh Shahb121e142012-08-20 17:59:13 -0700191
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700192 return true;
193}
194
Naseer Ahmed29a26812012-06-14 00:56:20 -0700195bool MdpCtrl::get() {
196 mdp_overlay ov;
197 ov.id = mOVInfo.id;
198 if (!mdp_wrapper::getOverlay(mFd.getFD(), ov)) {
199 ALOGE("MdpCtrl get failed");
200 return false;
201 }
202 mOVInfo = ov;
203 return true;
204}
205
Saurabh Shahacf10202013-02-26 10:15:15 -0800206//Update src format based on rotator's destination format.
207void MdpCtrl::updateSrcFormat(const uint32_t& rotDestFmt) {
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800208 utils::Whf whf = getSrcWhf();
Saurabh Shahacf10202013-02-26 10:15:15 -0800209 whf.format = rotDestFmt;
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800210 setSrcWhf(whf);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700211}
212
213void MdpCtrl::dump() const {
214 ALOGE("== Dump MdpCtrl start ==");
Naseer Ahmed29a26812012-06-14 00:56:20 -0700215 mFd.dump();
216 mdp_wrapper::dump("mOVInfo", mOVInfo);
217 ALOGE("== Dump MdpCtrl end ==");
218}
219
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800220void MdpCtrl::getDump(char *buf, size_t len) {
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700221 ovutils::getDump(buf, len, "Ctrl", mOVInfo);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800222}
223
Naseer Ahmed29a26812012-06-14 00:56:20 -0700224void MdpData::dump() const {
225 ALOGE("== Dump MdpData start ==");
226 mFd.dump();
227 mdp_wrapper::dump("mOvData", mOvData);
228 ALOGE("== Dump MdpData end ==");
229}
230
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800231void MdpData::getDump(char *buf, size_t len) {
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700232 ovutils::getDump(buf, len, "Data", mOvData);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800233}
234
Naseer Ahmed29a26812012-06-14 00:56:20 -0700235void MdpCtrl3D::dump() const {
236 ALOGE("== Dump MdpCtrl start ==");
237 mFd.dump();
238 ALOGE("== Dump MdpCtrl end ==");
239}
240
Saurabh Shah5daeee52013-01-23 16:52:26 +0800241bool MdpCtrl::setVisualParams(const MetaData_t& data) {
242 bool needUpdate = false;
243#ifdef USES_POST_PROCESSING
244 /* calculate the data */
245 if (data.operation & PP_PARAM_HSIC) {
246 if (mParams.params.pa_params.hue != data.hsicData.hue) {
247 ALOGD_IF(HSIC_SETTINGS_DEBUG,
248 "Hue has changed from %d to %d",
249 mParams.params.pa_params.hue,data.hsicData.hue);
250 needUpdate = true;
251 }
252
253 if (!isEqual(mParams.params.pa_params.sat,
254 data.hsicData.saturation)) {
255 ALOGD_IF(HSIC_SETTINGS_DEBUG,
256 "Saturation has changed from %f to %f",
257 mParams.params.pa_params.sat,
258 data.hsicData.saturation);
259 needUpdate = true;
260 }
261
262 if (mParams.params.pa_params.intensity != data.hsicData.intensity) {
263 ALOGD_IF(HSIC_SETTINGS_DEBUG,
264 "Intensity has changed from %d to %d",
265 mParams.params.pa_params.intensity,
266 data.hsicData.intensity);
267 needUpdate = true;
268 }
269
270 if (!isEqual(mParams.params.pa_params.contrast,
271 data.hsicData.contrast)) {
272 ALOGD_IF(HSIC_SETTINGS_DEBUG,
273 "Contrast has changed from %f to %f",
274 mParams.params.pa_params.contrast,
275 data.hsicData.contrast);
276 needUpdate = true;
277 }
278
279 if (needUpdate) {
280 mParams.params.pa_params.hue = data.hsicData.hue;
281 mParams.params.pa_params.sat = data.hsicData.saturation;
282 mParams.params.pa_params.intensity = data.hsicData.intensity;
283 mParams.params.pa_params.contrast = data.hsicData.contrast;
284 mParams.params.pa_params.ops = MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
285 mParams.operation |= PP_OP_PA;
286 }
287 }
288
289 if (data.operation & PP_PARAM_SHARP2) {
290 if (mParams.params.sharp_params.strength != data.Sharp2Data.strength) {
291 needUpdate = true;
292 }
293 if (mParams.params.sharp_params.edge_thr != data.Sharp2Data.edge_thr) {
294 needUpdate = true;
295 }
296 if (mParams.params.sharp_params.smooth_thr !=
297 data.Sharp2Data.smooth_thr) {
298 needUpdate = true;
299 }
300 if (mParams.params.sharp_params.noise_thr !=
301 data.Sharp2Data.noise_thr) {
302 needUpdate = true;
303 }
304
305 if (needUpdate) {
306 mParams.params.sharp_params.strength = data.Sharp2Data.strength;
307 mParams.params.sharp_params.edge_thr = data.Sharp2Data.edge_thr;
308 mParams.params.sharp_params.smooth_thr =
309 data.Sharp2Data.smooth_thr;
310 mParams.params.sharp_params.noise_thr = data.Sharp2Data.noise_thr;
311 mParams.params.sharp_params.ops =
312 MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
313 mParams.operation |= PP_OP_SHARP;
314 }
315 }
316
317 if (data.operation & PP_PARAM_IGC) {
318 if (mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data == NULL){
319 uint32_t *igcData
320 = (uint32_t *)malloc(2 * MAX_IGC_LUT_ENTRIES * sizeof(uint32_t));
321 if (!igcData) {
322 ALOGE("IGC storage allocated failed");
323 return false;
324 }
325 mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data = igcData;
326 mOVInfo.overlay_pp_cfg.igc_cfg.c2_data
327 = igcData + MAX_IGC_LUT_ENTRIES;
328 }
329
330 memcpy(mParams.params.igc_lut_params.c0,
331 data.igcData.c0, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
332 memcpy(mParams.params.igc_lut_params.c1,
333 data.igcData.c1, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
334 memcpy(mParams.params.igc_lut_params.c2,
335 data.igcData.c2, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
336
337 mParams.params.igc_lut_params.ops
338 = MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
339 mParams.operation |= PP_OP_IGC;
340 needUpdate = true;
341 }
342
343 if (data.operation & PP_PARAM_VID_INTFC) {
344 mParams.params.conv_params.interface =
345 (interface_type) data.video_interface;
346 needUpdate = true;
347 }
348
349 if (needUpdate) {
350 display_pp_compute_params(&mParams, &mOVInfo.overlay_pp_cfg);
351 mPPChanged = true;
352 }
353#endif
354 return true;
355}
356
Naseer Ahmed29a26812012-06-14 00:56:20 -0700357} // overlay