blob: 4578115af153b74d5ce69afcd7e27f3096ba0e37 [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
40//Helper to even out x,w and y,h pairs
41//x,y are always evened to ceil and w,h are evened to floor
42static void normalizeCrop(uint32_t& xy, uint32_t& wh) {
43 if(xy & 1) {
44 utils::even_ceil(xy);
45 if(wh & 1)
46 utils::even_floor(wh);
47 else
48 wh -= 2;
49 } else {
50 utils::even_floor(wh);
51 }
52}
53
Naseer Ahmedf48aef62012-07-20 09:05:53 -070054bool MdpCtrl::init(uint32_t fbnum) {
55 // FD init
Naseer Ahmed29a26812012-06-14 00:56:20 -070056 if(!utils::openDev(mFd, fbnum,
Naseer Ahmedf48aef62012-07-20 09:05:53 -070057 Res::fbPath, O_RDWR)){
58 ALOGE("Ctrl failed to init fbnum=%d", fbnum);
Naseer Ahmed29a26812012-06-14 00:56:20 -070059 return false;
60 }
61 return true;
62}
63
64void MdpCtrl::reset() {
65 utils::memset0(mOVInfo);
66 utils::memset0(mLkgo);
Naseer Ahmedf48aef62012-07-20 09:05:53 -070067 mOVInfo.id = MSMFB_NEW_REQUEST;
68 mLkgo.id = MSMFB_NEW_REQUEST;
69 mOrientation = utils::OVERLAY_TRANSFORM_0;
Saurabh Shahacf10202013-02-26 10:15:15 -080070 mDownscale = 0;
Saurabh Shah5daeee52013-01-23 16:52:26 +080071#ifdef USES_POST_PROCESSING
72 mPPChanged = false;
73 memset(&mParams, 0, sizeof(struct compute_params));
74 mParams.params.conv_params.order = hsic_order_hsc_i;
75 mParams.params.conv_params.interface = interface_rec601;
76 mParams.params.conv_params.cc_matrix[0][0] = 1;
77 mParams.params.conv_params.cc_matrix[1][1] = 1;
78 mParams.params.conv_params.cc_matrix[2][2] = 1;
79#endif
Naseer Ahmed29a26812012-06-14 00:56:20 -070080}
81
82bool MdpCtrl::close() {
Saurabh Shah8e1ae952012-08-15 12:15:14 -070083 bool result = true;
Saurabh Shah8e1ae952012-08-15 12:15:14 -070084 if(MSMFB_NEW_REQUEST != static_cast<int>(mOVInfo.id)) {
85 if(!mdp_wrapper::unsetOverlay(mFd.getFD(), mOVInfo.id)) {
86 ALOGE("MdpCtrl close error in unset");
87 result = false;
88 }
Naseer Ahmed29a26812012-06-14 00:56:20 -070089 }
Saurabh Shah5daeee52013-01-23 16:52:26 +080090#ifdef USES_POST_PROCESSING
91 /* free allocated memory in PP */
92 if (mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data)
93 free(mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data);
94#endif
Naseer Ahmed29a26812012-06-14 00:56:20 -070095 reset();
Saurabh Shahacf10202013-02-26 10:15:15 -080096
Naseer Ahmed29a26812012-06-14 00:56:20 -070097 if(!mFd.close()) {
Saurabh Shah8e1ae952012-08-15 12:15:14 -070098 result = false;
Naseer Ahmed29a26812012-06-14 00:56:20 -070099 }
Saurabh Shah8e1ae952012-08-15 12:15:14 -0700100
101 return result;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700102}
103
Saurabh Shahacf10202013-02-26 10:15:15 -0800104void MdpCtrl::setSource(const utils::PipeArgs& args) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700105 setSrcWhf(args.whf);
106
107 //TODO These are hardcoded. Can be moved out of setSource.
108 mOVInfo.alpha = 0xff;
109 mOVInfo.transp_mask = 0xffffffff;
110
111 //TODO These calls should ideally be a part of setPipeParams API
112 setFlags(args.mdpFlags);
113 setZ(args.zorder);
114 setIsFg(args.isFg);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700115}
116
Saurabh Shahacf10202013-02-26 10:15:15 -0800117void MdpCtrl::setCrop(const utils::Dim& d) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700118 setSrcRectDim(d);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700119}
120
Saurabh Shahacf10202013-02-26 10:15:15 -0800121void MdpCtrl::setPosition(const overlay::utils::Dim& d) {
122 setDstRectDim(d);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700123}
124
Saurabh Shahacf10202013-02-26 10:15:15 -0800125void MdpCtrl::setTransform(const utils::eTransform& orient) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700126 int rot = utils::getMdpOrient(orient);
127 setUserData(rot);
Saurabh Shaha73738d2012-08-09 18:15:18 -0700128 mOrientation = static_cast<utils::eTransform>(rot);
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800129}
130
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700131void MdpCtrl::doTransform() {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700132 setRotationFlags();
Saurabh Shahacf10202013-02-26 10:15:15 -0800133 utils::Whf whf = getSrcWhf();
134 utils::Dim dim = getSrcRectDim();
135 utils::preRotateSource(mOrientation, whf, dim);
136 setSrcWhf(whf);
137 setSrcRectDim(dim);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700138}
139
Saurabh Shahacf10202013-02-26 10:15:15 -0800140void MdpCtrl::doDownscale() {
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700141 int mdpVersion = MDPVersion::getInstance().getMDPVersion();
142 if(mdpVersion < MDSS_V5) {
143 mOVInfo.src_rect.x >>= mDownscale;
144 mOVInfo.src_rect.y >>= mDownscale;
145 mOVInfo.src_rect.w >>= mDownscale;
146 mOVInfo.src_rect.h >>= mDownscale;
147 } else if(MDPVersion::getInstance().supportsDecimation()) {
148 //Decimation + MDP Downscale
149 mOVInfo.horz_deci = 0;
150 mOVInfo.vert_deci = 0;
151 int minHorDeci = 0;
152 if(mOVInfo.src_rect.w > 2048) {
153 //If the client sends us something > what a layer mixer supports
154 //then it means it doesn't want to use split-pipe but wants us to
155 //decimate. A minimum decimation of 2 will ensure that the width is
156 //always within layer mixer limits.
157 minHorDeci = 2;
158 }
159
160 float horDscale = ceilf((float)mOVInfo.src_rect.w /
161 (float)mOVInfo.dst_rect.w);
162 float verDscale = ceilf((float)mOVInfo.src_rect.h /
163 (float)mOVInfo.dst_rect.h);
164
165 //Next power of 2, if not already
166 horDscale = powf(2.0f, ceilf(log2f(horDscale)));
167 verDscale = powf(2.0f, ceilf(log2f(verDscale)));
168
169 //Since MDP can do 1/4 dscale and has better quality, split the task
170 //between decimator and MDP downscale
171 horDscale /= 4.0f;
172 verDscale /= 4.0f;
173
174 if(horDscale < minHorDeci)
175 horDscale = minHorDeci;
176
177 if((int)horDscale)
178 mOVInfo.horz_deci = (int)log2f(horDscale);
179
180 if((int)verDscale)
181 mOVInfo.vert_deci = (int)log2f(verDscale);
182 }
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800183}
184
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700185bool MdpCtrl::set() {
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700186 int mdpVersion = MDPVersion::getInstance().getMDPVersion();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700187 //deferred calcs, so APIs could be called in any order.
Saurabh Shahacf10202013-02-26 10:15:15 -0800188 doTransform();
189 doDownscale();
Saurabh Shahb121e142012-08-20 17:59:13 -0700190 utils::Whf whf = getSrcWhf();
191 if(utils::isYuv(whf.format)) {
192 normalizeCrop(mOVInfo.src_rect.x, mOVInfo.src_rect.w);
193 normalizeCrop(mOVInfo.src_rect.y, mOVInfo.src_rect.h);
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700194 if(mdpVersion < MDSS_V5) {
Saurabh Shahce416f02013-04-10 13:33:09 -0700195 utils::even_floor(mOVInfo.dst_rect.w);
196 utils::even_floor(mOVInfo.dst_rect.h);
197 }
Saurabh Shahb121e142012-08-20 17:59:13 -0700198 }
199
Saurabh Shahfc2acbe2012-08-17 19:47:52 -0700200 if(this->ovChanged()) {
201 if(!mdp_wrapper::setOverlay(mFd.getFD(), mOVInfo)) {
202 ALOGE("MdpCtrl failed to setOverlay, restoring last known "
203 "good ov info");
204 mdp_wrapper::dump("== Bad OVInfo is: ", mOVInfo);
205 mdp_wrapper::dump("== Last good known OVInfo is: ", mLkgo);
206 this->restore();
207 return false;
208 }
209 this->save();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700210 }
Saurabh Shahb121e142012-08-20 17:59:13 -0700211
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700212 return true;
213}
214
Naseer Ahmed29a26812012-06-14 00:56:20 -0700215bool MdpCtrl::get() {
216 mdp_overlay ov;
217 ov.id = mOVInfo.id;
218 if (!mdp_wrapper::getOverlay(mFd.getFD(), ov)) {
219 ALOGE("MdpCtrl get failed");
220 return false;
221 }
222 mOVInfo = ov;
223 return true;
224}
225
Saurabh Shahacf10202013-02-26 10:15:15 -0800226//Update src format based on rotator's destination format.
227void MdpCtrl::updateSrcFormat(const uint32_t& rotDestFmt) {
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800228 utils::Whf whf = getSrcWhf();
Saurabh Shahacf10202013-02-26 10:15:15 -0800229 whf.format = rotDestFmt;
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800230 setSrcWhf(whf);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700231}
232
233void MdpCtrl::dump() const {
234 ALOGE("== Dump MdpCtrl start ==");
Naseer Ahmed29a26812012-06-14 00:56:20 -0700235 mFd.dump();
236 mdp_wrapper::dump("mOVInfo", mOVInfo);
237 ALOGE("== Dump MdpCtrl end ==");
238}
239
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800240void MdpCtrl::getDump(char *buf, size_t len) {
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700241 ovutils::getDump(buf, len, "Ctrl", mOVInfo);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800242}
243
Naseer Ahmed29a26812012-06-14 00:56:20 -0700244void MdpData::dump() const {
245 ALOGE("== Dump MdpData start ==");
246 mFd.dump();
247 mdp_wrapper::dump("mOvData", mOvData);
248 ALOGE("== Dump MdpData end ==");
249}
250
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800251void MdpData::getDump(char *buf, size_t len) {
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700252 ovutils::getDump(buf, len, "Data", mOvData);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800253}
254
Naseer Ahmed29a26812012-06-14 00:56:20 -0700255void MdpCtrl3D::dump() const {
256 ALOGE("== Dump MdpCtrl start ==");
257 mFd.dump();
258 ALOGE("== Dump MdpCtrl end ==");
259}
260
Saurabh Shah5daeee52013-01-23 16:52:26 +0800261bool MdpCtrl::setVisualParams(const MetaData_t& data) {
262 bool needUpdate = false;
263#ifdef USES_POST_PROCESSING
264 /* calculate the data */
265 if (data.operation & PP_PARAM_HSIC) {
266 if (mParams.params.pa_params.hue != data.hsicData.hue) {
267 ALOGD_IF(HSIC_SETTINGS_DEBUG,
268 "Hue has changed from %d to %d",
269 mParams.params.pa_params.hue,data.hsicData.hue);
270 needUpdate = true;
271 }
272
273 if (!isEqual(mParams.params.pa_params.sat,
274 data.hsicData.saturation)) {
275 ALOGD_IF(HSIC_SETTINGS_DEBUG,
276 "Saturation has changed from %f to %f",
277 mParams.params.pa_params.sat,
278 data.hsicData.saturation);
279 needUpdate = true;
280 }
281
282 if (mParams.params.pa_params.intensity != data.hsicData.intensity) {
283 ALOGD_IF(HSIC_SETTINGS_DEBUG,
284 "Intensity has changed from %d to %d",
285 mParams.params.pa_params.intensity,
286 data.hsicData.intensity);
287 needUpdate = true;
288 }
289
290 if (!isEqual(mParams.params.pa_params.contrast,
291 data.hsicData.contrast)) {
292 ALOGD_IF(HSIC_SETTINGS_DEBUG,
293 "Contrast has changed from %f to %f",
294 mParams.params.pa_params.contrast,
295 data.hsicData.contrast);
296 needUpdate = true;
297 }
298
299 if (needUpdate) {
300 mParams.params.pa_params.hue = data.hsicData.hue;
301 mParams.params.pa_params.sat = data.hsicData.saturation;
302 mParams.params.pa_params.intensity = data.hsicData.intensity;
303 mParams.params.pa_params.contrast = data.hsicData.contrast;
304 mParams.params.pa_params.ops = MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
305 mParams.operation |= PP_OP_PA;
306 }
307 }
308
309 if (data.operation & PP_PARAM_SHARP2) {
310 if (mParams.params.sharp_params.strength != data.Sharp2Data.strength) {
311 needUpdate = true;
312 }
313 if (mParams.params.sharp_params.edge_thr != data.Sharp2Data.edge_thr) {
314 needUpdate = true;
315 }
316 if (mParams.params.sharp_params.smooth_thr !=
317 data.Sharp2Data.smooth_thr) {
318 needUpdate = true;
319 }
320 if (mParams.params.sharp_params.noise_thr !=
321 data.Sharp2Data.noise_thr) {
322 needUpdate = true;
323 }
324
325 if (needUpdate) {
326 mParams.params.sharp_params.strength = data.Sharp2Data.strength;
327 mParams.params.sharp_params.edge_thr = data.Sharp2Data.edge_thr;
328 mParams.params.sharp_params.smooth_thr =
329 data.Sharp2Data.smooth_thr;
330 mParams.params.sharp_params.noise_thr = data.Sharp2Data.noise_thr;
331 mParams.params.sharp_params.ops =
332 MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
333 mParams.operation |= PP_OP_SHARP;
334 }
335 }
336
337 if (data.operation & PP_PARAM_IGC) {
338 if (mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data == NULL){
339 uint32_t *igcData
340 = (uint32_t *)malloc(2 * MAX_IGC_LUT_ENTRIES * sizeof(uint32_t));
341 if (!igcData) {
342 ALOGE("IGC storage allocated failed");
343 return false;
344 }
345 mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data = igcData;
346 mOVInfo.overlay_pp_cfg.igc_cfg.c2_data
347 = igcData + MAX_IGC_LUT_ENTRIES;
348 }
349
350 memcpy(mParams.params.igc_lut_params.c0,
351 data.igcData.c0, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
352 memcpy(mParams.params.igc_lut_params.c1,
353 data.igcData.c1, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
354 memcpy(mParams.params.igc_lut_params.c2,
355 data.igcData.c2, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
356
357 mParams.params.igc_lut_params.ops
358 = MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
359 mParams.operation |= PP_OP_IGC;
360 needUpdate = true;
361 }
362
363 if (data.operation & PP_PARAM_VID_INTFC) {
364 mParams.params.conv_params.interface =
365 (interface_type) data.video_interface;
366 needUpdate = true;
367 }
368
369 if (needUpdate) {
370 display_pp_compute_params(&mParams, &mOVInfo.overlay_pp_cfg);
371 mPPChanged = true;
372 }
373#endif
374 return true;
375}
376
Naseer Ahmed29a26812012-06-14 00:56:20 -0700377} // overlay