blob: e6dcbe986a2d1ca0c83db504c0add49805f68e30 [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
Raj kamal23f69b22012-11-17 00:20:55 +053018#include <mdp_version.h>
Naseer Ahmed29a26812012-06-14 00:56:20 -070019#include "overlayUtils.h"
20#include "overlayMdp.h"
Saurabh Shah5daeee52013-01-23 16:52:26 +080021#include "mdp_version.h"
22
23#define HSIC_SETTINGS_DEBUG 0
24
25static inline bool isEqual(float f1, float f2) {
26 return ((int)(f1*100) == (int)(f2*100)) ? true : false;
27}
Naseer Ahmed29a26812012-06-14 00:56:20 -070028
Naseer Ahmed29a26812012-06-14 00:56:20 -070029namespace ovutils = overlay::utils;
30namespace overlay {
Saurabh Shahb121e142012-08-20 17:59:13 -070031
32//Helper to even out x,w and y,h pairs
33//x,y are always evened to ceil and w,h are evened to floor
34static void normalizeCrop(uint32_t& xy, uint32_t& wh) {
35 if(xy & 1) {
36 utils::even_ceil(xy);
37 if(wh & 1)
38 utils::even_floor(wh);
39 else
40 wh -= 2;
41 } else {
42 utils::even_floor(wh);
43 }
44}
45
Naseer Ahmedf48aef62012-07-20 09:05:53 -070046bool MdpCtrl::init(uint32_t fbnum) {
47 // FD init
Naseer Ahmed29a26812012-06-14 00:56:20 -070048 if(!utils::openDev(mFd, fbnum,
Naseer Ahmedf48aef62012-07-20 09:05:53 -070049 Res::fbPath, O_RDWR)){
50 ALOGE("Ctrl failed to init fbnum=%d", fbnum);
Naseer Ahmed29a26812012-06-14 00:56:20 -070051 return false;
52 }
53 return true;
54}
55
56void MdpCtrl::reset() {
57 utils::memset0(mOVInfo);
58 utils::memset0(mLkgo);
Naseer Ahmedf48aef62012-07-20 09:05:53 -070059 mOVInfo.id = MSMFB_NEW_REQUEST;
60 mLkgo.id = MSMFB_NEW_REQUEST;
61 mOrientation = utils::OVERLAY_TRANSFORM_0;
Saurabh Shahacf10202013-02-26 10:15:15 -080062 mDownscale = 0;
Saurabh Shah5daeee52013-01-23 16:52:26 +080063#ifdef USES_POST_PROCESSING
64 mPPChanged = false;
65 memset(&mParams, 0, sizeof(struct compute_params));
66 mParams.params.conv_params.order = hsic_order_hsc_i;
67 mParams.params.conv_params.interface = interface_rec601;
68 mParams.params.conv_params.cc_matrix[0][0] = 1;
69 mParams.params.conv_params.cc_matrix[1][1] = 1;
70 mParams.params.conv_params.cc_matrix[2][2] = 1;
71#endif
Naseer Ahmed29a26812012-06-14 00:56:20 -070072}
73
74bool MdpCtrl::close() {
Saurabh Shah8e1ae952012-08-15 12:15:14 -070075 bool result = true;
Saurabh Shah8e1ae952012-08-15 12:15:14 -070076 if(MSMFB_NEW_REQUEST != static_cast<int>(mOVInfo.id)) {
77 if(!mdp_wrapper::unsetOverlay(mFd.getFD(), mOVInfo.id)) {
78 ALOGE("MdpCtrl close error in unset");
79 result = false;
80 }
Naseer Ahmed29a26812012-06-14 00:56:20 -070081 }
Saurabh Shah5daeee52013-01-23 16:52:26 +080082#ifdef USES_POST_PROCESSING
83 /* free allocated memory in PP */
84 if (mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data)
85 free(mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data);
86#endif
Naseer Ahmed29a26812012-06-14 00:56:20 -070087 reset();
Saurabh Shahacf10202013-02-26 10:15:15 -080088
Naseer Ahmed29a26812012-06-14 00:56:20 -070089 if(!mFd.close()) {
Saurabh Shah8e1ae952012-08-15 12:15:14 -070090 result = false;
Naseer Ahmed29a26812012-06-14 00:56:20 -070091 }
Saurabh Shah8e1ae952012-08-15 12:15:14 -070092
93 return result;
Naseer Ahmed29a26812012-06-14 00:56:20 -070094}
95
Saurabh Shahacf10202013-02-26 10:15:15 -080096void MdpCtrl::setSource(const utils::PipeArgs& args) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -070097 setSrcWhf(args.whf);
98
99 //TODO These are hardcoded. Can be moved out of setSource.
100 mOVInfo.alpha = 0xff;
101 mOVInfo.transp_mask = 0xffffffff;
102
103 //TODO These calls should ideally be a part of setPipeParams API
104 setFlags(args.mdpFlags);
105 setZ(args.zorder);
106 setIsFg(args.isFg);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700107}
108
Saurabh Shahacf10202013-02-26 10:15:15 -0800109void MdpCtrl::setCrop(const utils::Dim& d) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700110 setSrcRectDim(d);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700111}
112
Saurabh Shahacf10202013-02-26 10:15:15 -0800113void MdpCtrl::setPosition(const overlay::utils::Dim& d) {
114 setDstRectDim(d);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700115}
116
Saurabh Shahacf10202013-02-26 10:15:15 -0800117void MdpCtrl::setTransform(const utils::eTransform& orient) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700118 int rot = utils::getMdpOrient(orient);
119 setUserData(rot);
Saurabh Shaha73738d2012-08-09 18:15:18 -0700120 mOrientation = static_cast<utils::eTransform>(rot);
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800121}
122
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700123void MdpCtrl::doTransform() {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700124 setRotationFlags();
Saurabh Shahacf10202013-02-26 10:15:15 -0800125 utils::Whf whf = getSrcWhf();
126 utils::Dim dim = getSrcRectDim();
127 utils::preRotateSource(mOrientation, whf, dim);
128 setSrcWhf(whf);
129 setSrcRectDim(dim);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700130}
131
Saurabh Shahacf10202013-02-26 10:15:15 -0800132void MdpCtrl::doDownscale() {
133 mOVInfo.src_rect.x >>= mDownscale;
134 mOVInfo.src_rect.y >>= mDownscale;
135 mOVInfo.src_rect.w >>= mDownscale;
136 mOVInfo.src_rect.h >>= mDownscale;
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800137}
138
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700139bool MdpCtrl::set() {
140 //deferred calcs, so APIs could be called in any order.
Saurabh Shahacf10202013-02-26 10:15:15 -0800141 doTransform();
142 doDownscale();
Saurabh Shahb121e142012-08-20 17:59:13 -0700143 utils::Whf whf = getSrcWhf();
144 if(utils::isYuv(whf.format)) {
145 normalizeCrop(mOVInfo.src_rect.x, mOVInfo.src_rect.w);
146 normalizeCrop(mOVInfo.src_rect.y, mOVInfo.src_rect.h);
147 utils::even_floor(mOVInfo.dst_rect.w);
148 utils::even_floor(mOVInfo.dst_rect.h);
149 }
150
Saurabh Shahfc2acbe2012-08-17 19:47:52 -0700151 if(this->ovChanged()) {
152 if(!mdp_wrapper::setOverlay(mFd.getFD(), mOVInfo)) {
153 ALOGE("MdpCtrl failed to setOverlay, restoring last known "
154 "good ov info");
155 mdp_wrapper::dump("== Bad OVInfo is: ", mOVInfo);
156 mdp_wrapper::dump("== Last good known OVInfo is: ", mLkgo);
157 this->restore();
158 return false;
159 }
160 this->save();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700161 }
Saurabh Shahb121e142012-08-20 17:59:13 -0700162
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700163 return true;
164}
165
Naseer Ahmed29a26812012-06-14 00:56:20 -0700166bool MdpCtrl::get() {
167 mdp_overlay ov;
168 ov.id = mOVInfo.id;
169 if (!mdp_wrapper::getOverlay(mFd.getFD(), ov)) {
170 ALOGE("MdpCtrl get failed");
171 return false;
172 }
173 mOVInfo = ov;
174 return true;
175}
176
Saurabh Shahacf10202013-02-26 10:15:15 -0800177//Update src format based on rotator's destination format.
178void MdpCtrl::updateSrcFormat(const uint32_t& rotDestFmt) {
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800179 utils::Whf whf = getSrcWhf();
Saurabh Shahacf10202013-02-26 10:15:15 -0800180 whf.format = rotDestFmt;
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800181 setSrcWhf(whf);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700182}
183
184void MdpCtrl::dump() const {
185 ALOGE("== Dump MdpCtrl start ==");
Naseer Ahmed29a26812012-06-14 00:56:20 -0700186 mFd.dump();
187 mdp_wrapper::dump("mOVInfo", mOVInfo);
188 ALOGE("== Dump MdpCtrl end ==");
189}
190
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800191void MdpCtrl::getDump(char *buf, size_t len) {
192 ovutils::getDump(buf, len, "Ctrl(mdp_overlay)", mOVInfo);
193}
194
Naseer Ahmed29a26812012-06-14 00:56:20 -0700195void MdpData::dump() const {
196 ALOGE("== Dump MdpData start ==");
197 mFd.dump();
198 mdp_wrapper::dump("mOvData", mOvData);
199 ALOGE("== Dump MdpData end ==");
200}
201
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800202void MdpData::getDump(char *buf, size_t len) {
203 ovutils::getDump(buf, len, "Data(msmfb_overlay_data)", mOvData);
204}
205
Naseer Ahmed29a26812012-06-14 00:56:20 -0700206void MdpCtrl3D::dump() const {
207 ALOGE("== Dump MdpCtrl start ==");
208 mFd.dump();
209 ALOGE("== Dump MdpCtrl end ==");
210}
211
Saurabh Shah5daeee52013-01-23 16:52:26 +0800212bool MdpCtrl::setVisualParams(const MetaData_t& data) {
213 bool needUpdate = false;
214#ifdef USES_POST_PROCESSING
215 /* calculate the data */
216 if (data.operation & PP_PARAM_HSIC) {
217 if (mParams.params.pa_params.hue != data.hsicData.hue) {
218 ALOGD_IF(HSIC_SETTINGS_DEBUG,
219 "Hue has changed from %d to %d",
220 mParams.params.pa_params.hue,data.hsicData.hue);
221 needUpdate = true;
222 }
223
224 if (!isEqual(mParams.params.pa_params.sat,
225 data.hsicData.saturation)) {
226 ALOGD_IF(HSIC_SETTINGS_DEBUG,
227 "Saturation has changed from %f to %f",
228 mParams.params.pa_params.sat,
229 data.hsicData.saturation);
230 needUpdate = true;
231 }
232
233 if (mParams.params.pa_params.intensity != data.hsicData.intensity) {
234 ALOGD_IF(HSIC_SETTINGS_DEBUG,
235 "Intensity has changed from %d to %d",
236 mParams.params.pa_params.intensity,
237 data.hsicData.intensity);
238 needUpdate = true;
239 }
240
241 if (!isEqual(mParams.params.pa_params.contrast,
242 data.hsicData.contrast)) {
243 ALOGD_IF(HSIC_SETTINGS_DEBUG,
244 "Contrast has changed from %f to %f",
245 mParams.params.pa_params.contrast,
246 data.hsicData.contrast);
247 needUpdate = true;
248 }
249
250 if (needUpdate) {
251 mParams.params.pa_params.hue = data.hsicData.hue;
252 mParams.params.pa_params.sat = data.hsicData.saturation;
253 mParams.params.pa_params.intensity = data.hsicData.intensity;
254 mParams.params.pa_params.contrast = data.hsicData.contrast;
255 mParams.params.pa_params.ops = MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
256 mParams.operation |= PP_OP_PA;
257 }
258 }
259
260 if (data.operation & PP_PARAM_SHARP2) {
261 if (mParams.params.sharp_params.strength != data.Sharp2Data.strength) {
262 needUpdate = true;
263 }
264 if (mParams.params.sharp_params.edge_thr != data.Sharp2Data.edge_thr) {
265 needUpdate = true;
266 }
267 if (mParams.params.sharp_params.smooth_thr !=
268 data.Sharp2Data.smooth_thr) {
269 needUpdate = true;
270 }
271 if (mParams.params.sharp_params.noise_thr !=
272 data.Sharp2Data.noise_thr) {
273 needUpdate = true;
274 }
275
276 if (needUpdate) {
277 mParams.params.sharp_params.strength = data.Sharp2Data.strength;
278 mParams.params.sharp_params.edge_thr = data.Sharp2Data.edge_thr;
279 mParams.params.sharp_params.smooth_thr =
280 data.Sharp2Data.smooth_thr;
281 mParams.params.sharp_params.noise_thr = data.Sharp2Data.noise_thr;
282 mParams.params.sharp_params.ops =
283 MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
284 mParams.operation |= PP_OP_SHARP;
285 }
286 }
287
288 if (data.operation & PP_PARAM_IGC) {
289 if (mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data == NULL){
290 uint32_t *igcData
291 = (uint32_t *)malloc(2 * MAX_IGC_LUT_ENTRIES * sizeof(uint32_t));
292 if (!igcData) {
293 ALOGE("IGC storage allocated failed");
294 return false;
295 }
296 mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data = igcData;
297 mOVInfo.overlay_pp_cfg.igc_cfg.c2_data
298 = igcData + MAX_IGC_LUT_ENTRIES;
299 }
300
301 memcpy(mParams.params.igc_lut_params.c0,
302 data.igcData.c0, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
303 memcpy(mParams.params.igc_lut_params.c1,
304 data.igcData.c1, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
305 memcpy(mParams.params.igc_lut_params.c2,
306 data.igcData.c2, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
307
308 mParams.params.igc_lut_params.ops
309 = MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
310 mParams.operation |= PP_OP_IGC;
311 needUpdate = true;
312 }
313
314 if (data.operation & PP_PARAM_VID_INTFC) {
315 mParams.params.conv_params.interface =
316 (interface_type) data.video_interface;
317 needUpdate = true;
318 }
319
320 if (needUpdate) {
321 display_pp_compute_params(&mParams, &mOVInfo.overlay_pp_cfg);
322 mPPChanged = true;
323 }
324#endif
325 return true;
326}
327
Naseer Ahmed29a26812012-06-14 00:56:20 -0700328} // overlay