blob: ee8bf51350d184e800f9f72f7a71fcde702e7bdf [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 //getMdpOrient will switch the flips if the source is 90 rotated.
121 //Clients in Android dont factor in 90 rotation while deciding the flip.
122 mOrientation = static_cast<utils::eTransform>(rot);
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800123}
124
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700125void MdpCtrl::doTransform() {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700126 setRotationFlags();
Saurabh Shahacf10202013-02-26 10:15:15 -0800127 utils::Whf whf = getSrcWhf();
128 utils::Dim dim = getSrcRectDim();
129 utils::preRotateSource(mOrientation, whf, dim);
130 setSrcWhf(whf);
131 setSrcRectDim(dim);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700132}
133
Saurabh Shahacf10202013-02-26 10:15:15 -0800134void MdpCtrl::doDownscale() {
135 mOVInfo.src_rect.x >>= mDownscale;
136 mOVInfo.src_rect.y >>= mDownscale;
137 mOVInfo.src_rect.w >>= mDownscale;
138 mOVInfo.src_rect.h >>= mDownscale;
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800139}
140
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700141bool MdpCtrl::set() {
142 //deferred calcs, so APIs could be called in any order.
Saurabh Shahacf10202013-02-26 10:15:15 -0800143 doTransform();
144 doDownscale();
Saurabh Shahb121e142012-08-20 17:59:13 -0700145 utils::Whf whf = getSrcWhf();
146 if(utils::isYuv(whf.format)) {
147 normalizeCrop(mOVInfo.src_rect.x, mOVInfo.src_rect.w);
148 normalizeCrop(mOVInfo.src_rect.y, mOVInfo.src_rect.h);
149 utils::even_floor(mOVInfo.dst_rect.w);
150 utils::even_floor(mOVInfo.dst_rect.h);
151 }
152
Saurabh Shahfc2acbe2012-08-17 19:47:52 -0700153 if(this->ovChanged()) {
154 if(!mdp_wrapper::setOverlay(mFd.getFD(), mOVInfo)) {
155 ALOGE("MdpCtrl failed to setOverlay, restoring last known "
156 "good ov info");
157 mdp_wrapper::dump("== Bad OVInfo is: ", mOVInfo);
158 mdp_wrapper::dump("== Last good known OVInfo is: ", mLkgo);
159 this->restore();
160 return false;
161 }
162 this->save();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700163 }
Saurabh Shahb121e142012-08-20 17:59:13 -0700164
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700165 return true;
166}
167
Naseer Ahmed29a26812012-06-14 00:56:20 -0700168bool MdpCtrl::get() {
169 mdp_overlay ov;
170 ov.id = mOVInfo.id;
171 if (!mdp_wrapper::getOverlay(mFd.getFD(), ov)) {
172 ALOGE("MdpCtrl get failed");
173 return false;
174 }
175 mOVInfo = ov;
176 return true;
177}
178
Saurabh Shahacf10202013-02-26 10:15:15 -0800179//Update src format based on rotator's destination format.
180void MdpCtrl::updateSrcFormat(const uint32_t& rotDestFmt) {
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800181 utils::Whf whf = getSrcWhf();
Saurabh Shahacf10202013-02-26 10:15:15 -0800182 whf.format = rotDestFmt;
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800183 setSrcWhf(whf);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700184}
185
186void MdpCtrl::dump() const {
187 ALOGE("== Dump MdpCtrl start ==");
Naseer Ahmed29a26812012-06-14 00:56:20 -0700188 mFd.dump();
189 mdp_wrapper::dump("mOVInfo", mOVInfo);
190 ALOGE("== Dump MdpCtrl end ==");
191}
192
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800193void MdpCtrl::getDump(char *buf, size_t len) {
194 ovutils::getDump(buf, len, "Ctrl(mdp_overlay)", mOVInfo);
195}
196
Naseer Ahmed29a26812012-06-14 00:56:20 -0700197void MdpData::dump() const {
198 ALOGE("== Dump MdpData start ==");
199 mFd.dump();
200 mdp_wrapper::dump("mOvData", mOvData);
201 ALOGE("== Dump MdpData end ==");
202}
203
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800204void MdpData::getDump(char *buf, size_t len) {
205 ovutils::getDump(buf, len, "Data(msmfb_overlay_data)", mOvData);
206}
207
Naseer Ahmed29a26812012-06-14 00:56:20 -0700208void MdpCtrl3D::dump() const {
209 ALOGE("== Dump MdpCtrl start ==");
210 mFd.dump();
211 ALOGE("== Dump MdpCtrl end ==");
212}
213
Saurabh Shah5daeee52013-01-23 16:52:26 +0800214bool MdpCtrl::setVisualParams(const MetaData_t& data) {
215 bool needUpdate = false;
216#ifdef USES_POST_PROCESSING
217 /* calculate the data */
218 if (data.operation & PP_PARAM_HSIC) {
219 if (mParams.params.pa_params.hue != data.hsicData.hue) {
220 ALOGD_IF(HSIC_SETTINGS_DEBUG,
221 "Hue has changed from %d to %d",
222 mParams.params.pa_params.hue,data.hsicData.hue);
223 needUpdate = true;
224 }
225
226 if (!isEqual(mParams.params.pa_params.sat,
227 data.hsicData.saturation)) {
228 ALOGD_IF(HSIC_SETTINGS_DEBUG,
229 "Saturation has changed from %f to %f",
230 mParams.params.pa_params.sat,
231 data.hsicData.saturation);
232 needUpdate = true;
233 }
234
235 if (mParams.params.pa_params.intensity != data.hsicData.intensity) {
236 ALOGD_IF(HSIC_SETTINGS_DEBUG,
237 "Intensity has changed from %d to %d",
238 mParams.params.pa_params.intensity,
239 data.hsicData.intensity);
240 needUpdate = true;
241 }
242
243 if (!isEqual(mParams.params.pa_params.contrast,
244 data.hsicData.contrast)) {
245 ALOGD_IF(HSIC_SETTINGS_DEBUG,
246 "Contrast has changed from %f to %f",
247 mParams.params.pa_params.contrast,
248 data.hsicData.contrast);
249 needUpdate = true;
250 }
251
252 if (needUpdate) {
253 mParams.params.pa_params.hue = data.hsicData.hue;
254 mParams.params.pa_params.sat = data.hsicData.saturation;
255 mParams.params.pa_params.intensity = data.hsicData.intensity;
256 mParams.params.pa_params.contrast = data.hsicData.contrast;
257 mParams.params.pa_params.ops = MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
258 mParams.operation |= PP_OP_PA;
259 }
260 }
261
262 if (data.operation & PP_PARAM_SHARP2) {
263 if (mParams.params.sharp_params.strength != data.Sharp2Data.strength) {
264 needUpdate = true;
265 }
266 if (mParams.params.sharp_params.edge_thr != data.Sharp2Data.edge_thr) {
267 needUpdate = true;
268 }
269 if (mParams.params.sharp_params.smooth_thr !=
270 data.Sharp2Data.smooth_thr) {
271 needUpdate = true;
272 }
273 if (mParams.params.sharp_params.noise_thr !=
274 data.Sharp2Data.noise_thr) {
275 needUpdate = true;
276 }
277
278 if (needUpdate) {
279 mParams.params.sharp_params.strength = data.Sharp2Data.strength;
280 mParams.params.sharp_params.edge_thr = data.Sharp2Data.edge_thr;
281 mParams.params.sharp_params.smooth_thr =
282 data.Sharp2Data.smooth_thr;
283 mParams.params.sharp_params.noise_thr = data.Sharp2Data.noise_thr;
284 mParams.params.sharp_params.ops =
285 MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
286 mParams.operation |= PP_OP_SHARP;
287 }
288 }
289
290 if (data.operation & PP_PARAM_IGC) {
291 if (mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data == NULL){
292 uint32_t *igcData
293 = (uint32_t *)malloc(2 * MAX_IGC_LUT_ENTRIES * sizeof(uint32_t));
294 if (!igcData) {
295 ALOGE("IGC storage allocated failed");
296 return false;
297 }
298 mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data = igcData;
299 mOVInfo.overlay_pp_cfg.igc_cfg.c2_data
300 = igcData + MAX_IGC_LUT_ENTRIES;
301 }
302
303 memcpy(mParams.params.igc_lut_params.c0,
304 data.igcData.c0, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
305 memcpy(mParams.params.igc_lut_params.c1,
306 data.igcData.c1, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
307 memcpy(mParams.params.igc_lut_params.c2,
308 data.igcData.c2, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
309
310 mParams.params.igc_lut_params.ops
311 = MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
312 mParams.operation |= PP_OP_IGC;
313 needUpdate = true;
314 }
315
316 if (data.operation & PP_PARAM_VID_INTFC) {
317 mParams.params.conv_params.interface =
318 (interface_type) data.video_interface;
319 needUpdate = true;
320 }
321
322 if (needUpdate) {
323 display_pp_compute_params(&mParams, &mOVInfo.overlay_pp_cfg);
324 mPPChanged = true;
325 }
326#endif
327 return true;
328}
329
Naseer Ahmed29a26812012-06-14 00:56:20 -0700330} // overlay