blob: 3e75d4e9b1787a5d6391ebee0b6ff068cd34a443 [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);
184 }
Saurabh Shahb121e142012-08-20 17:59:13 -0700185 }
186
Saurabh Shahdf0be752013-05-23 14:40:00 -0700187 if(this->ovChanged() || mForceSet) {
188 mForceSet = false;
Saurabh Shahfc2acbe2012-08-17 19:47:52 -0700189 if(!mdp_wrapper::setOverlay(mFd.getFD(), mOVInfo)) {
190 ALOGE("MdpCtrl failed to setOverlay, restoring last known "
191 "good ov info");
192 mdp_wrapper::dump("== Bad OVInfo is: ", mOVInfo);
193 mdp_wrapper::dump("== Last good known OVInfo is: ", mLkgo);
194 this->restore();
195 return false;
196 }
197 this->save();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700198 }
Saurabh Shahb121e142012-08-20 17:59:13 -0700199
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700200 return true;
201}
202
Naseer Ahmed29a26812012-06-14 00:56:20 -0700203bool MdpCtrl::get() {
204 mdp_overlay ov;
205 ov.id = mOVInfo.id;
206 if (!mdp_wrapper::getOverlay(mFd.getFD(), ov)) {
207 ALOGE("MdpCtrl get failed");
208 return false;
209 }
210 mOVInfo = ov;
211 return true;
212}
213
Saurabh Shahacf10202013-02-26 10:15:15 -0800214//Update src format based on rotator's destination format.
215void MdpCtrl::updateSrcFormat(const uint32_t& rotDestFmt) {
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800216 utils::Whf whf = getSrcWhf();
Saurabh Shahacf10202013-02-26 10:15:15 -0800217 whf.format = rotDestFmt;
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800218 setSrcWhf(whf);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700219}
220
221void MdpCtrl::dump() const {
222 ALOGE("== Dump MdpCtrl start ==");
Naseer Ahmed29a26812012-06-14 00:56:20 -0700223 mFd.dump();
224 mdp_wrapper::dump("mOVInfo", mOVInfo);
225 ALOGE("== Dump MdpCtrl end ==");
226}
227
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800228void MdpCtrl::getDump(char *buf, size_t len) {
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700229 ovutils::getDump(buf, len, "Ctrl", mOVInfo);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800230}
231
Naseer Ahmed29a26812012-06-14 00:56:20 -0700232void MdpData::dump() const {
233 ALOGE("== Dump MdpData start ==");
234 mFd.dump();
235 mdp_wrapper::dump("mOvData", mOvData);
236 ALOGE("== Dump MdpData end ==");
237}
238
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800239void MdpData::getDump(char *buf, size_t len) {
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700240 ovutils::getDump(buf, len, "Data", mOvData);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800241}
242
Naseer Ahmed29a26812012-06-14 00:56:20 -0700243void MdpCtrl3D::dump() const {
244 ALOGE("== Dump MdpCtrl start ==");
245 mFd.dump();
246 ALOGE("== Dump MdpCtrl end ==");
247}
248
Saurabh Shah5daeee52013-01-23 16:52:26 +0800249bool MdpCtrl::setVisualParams(const MetaData_t& data) {
250 bool needUpdate = false;
251#ifdef USES_POST_PROCESSING
252 /* calculate the data */
253 if (data.operation & PP_PARAM_HSIC) {
254 if (mParams.params.pa_params.hue != data.hsicData.hue) {
255 ALOGD_IF(HSIC_SETTINGS_DEBUG,
256 "Hue has changed from %d to %d",
257 mParams.params.pa_params.hue,data.hsicData.hue);
258 needUpdate = true;
259 }
260
261 if (!isEqual(mParams.params.pa_params.sat,
262 data.hsicData.saturation)) {
263 ALOGD_IF(HSIC_SETTINGS_DEBUG,
264 "Saturation has changed from %f to %f",
265 mParams.params.pa_params.sat,
266 data.hsicData.saturation);
267 needUpdate = true;
268 }
269
270 if (mParams.params.pa_params.intensity != data.hsicData.intensity) {
271 ALOGD_IF(HSIC_SETTINGS_DEBUG,
272 "Intensity has changed from %d to %d",
273 mParams.params.pa_params.intensity,
274 data.hsicData.intensity);
275 needUpdate = true;
276 }
277
278 if (!isEqual(mParams.params.pa_params.contrast,
279 data.hsicData.contrast)) {
280 ALOGD_IF(HSIC_SETTINGS_DEBUG,
281 "Contrast has changed from %f to %f",
282 mParams.params.pa_params.contrast,
283 data.hsicData.contrast);
284 needUpdate = true;
285 }
286
287 if (needUpdate) {
288 mParams.params.pa_params.hue = data.hsicData.hue;
289 mParams.params.pa_params.sat = data.hsicData.saturation;
290 mParams.params.pa_params.intensity = data.hsicData.intensity;
291 mParams.params.pa_params.contrast = data.hsicData.contrast;
292 mParams.params.pa_params.ops = MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
293 mParams.operation |= PP_OP_PA;
294 }
295 }
296
297 if (data.operation & PP_PARAM_SHARP2) {
298 if (mParams.params.sharp_params.strength != data.Sharp2Data.strength) {
299 needUpdate = true;
300 }
301 if (mParams.params.sharp_params.edge_thr != data.Sharp2Data.edge_thr) {
302 needUpdate = true;
303 }
304 if (mParams.params.sharp_params.smooth_thr !=
305 data.Sharp2Data.smooth_thr) {
306 needUpdate = true;
307 }
308 if (mParams.params.sharp_params.noise_thr !=
309 data.Sharp2Data.noise_thr) {
310 needUpdate = true;
311 }
312
313 if (needUpdate) {
314 mParams.params.sharp_params.strength = data.Sharp2Data.strength;
315 mParams.params.sharp_params.edge_thr = data.Sharp2Data.edge_thr;
316 mParams.params.sharp_params.smooth_thr =
317 data.Sharp2Data.smooth_thr;
318 mParams.params.sharp_params.noise_thr = data.Sharp2Data.noise_thr;
319 mParams.params.sharp_params.ops =
320 MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
321 mParams.operation |= PP_OP_SHARP;
322 }
323 }
324
325 if (data.operation & PP_PARAM_IGC) {
326 if (mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data == NULL){
327 uint32_t *igcData
328 = (uint32_t *)malloc(2 * MAX_IGC_LUT_ENTRIES * sizeof(uint32_t));
329 if (!igcData) {
330 ALOGE("IGC storage allocated failed");
331 return false;
332 }
333 mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data = igcData;
334 mOVInfo.overlay_pp_cfg.igc_cfg.c2_data
335 = igcData + MAX_IGC_LUT_ENTRIES;
336 }
337
338 memcpy(mParams.params.igc_lut_params.c0,
339 data.igcData.c0, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
340 memcpy(mParams.params.igc_lut_params.c1,
341 data.igcData.c1, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
342 memcpy(mParams.params.igc_lut_params.c2,
343 data.igcData.c2, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
344
345 mParams.params.igc_lut_params.ops
346 = MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
347 mParams.operation |= PP_OP_IGC;
348 needUpdate = true;
349 }
350
351 if (data.operation & PP_PARAM_VID_INTFC) {
352 mParams.params.conv_params.interface =
353 (interface_type) data.video_interface;
354 needUpdate = true;
355 }
356
357 if (needUpdate) {
358 display_pp_compute_params(&mParams, &mOVInfo.overlay_pp_cfg);
359 mPPChanged = true;
360 }
361#endif
362 return true;
363}
364
Naseer Ahmed29a26812012-06-14 00:56:20 -0700365} // overlay