blob: 84c0e2cbb08557edfe01ee63ea0caad5959dfdee [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() {
Saurabh Shahce416f02013-04-10 13:33:09 -0700142 int mdpVersion = qdutils::MDPVersion::getInstance().getMDPVersion();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700143 //deferred calcs, so APIs could be called in any order.
Saurabh Shahacf10202013-02-26 10:15:15 -0800144 doTransform();
145 doDownscale();
Saurabh Shahb121e142012-08-20 17:59:13 -0700146 utils::Whf whf = getSrcWhf();
147 if(utils::isYuv(whf.format)) {
148 normalizeCrop(mOVInfo.src_rect.x, mOVInfo.src_rect.w);
149 normalizeCrop(mOVInfo.src_rect.y, mOVInfo.src_rect.h);
Saurabh Shahce416f02013-04-10 13:33:09 -0700150 if(mdpVersion < qdutils::MDSS_V5) {
151 utils::even_floor(mOVInfo.dst_rect.w);
152 utils::even_floor(mOVInfo.dst_rect.h);
153 }
Saurabh Shahb121e142012-08-20 17:59:13 -0700154 }
155
Saurabh Shahfc2acbe2012-08-17 19:47:52 -0700156 if(this->ovChanged()) {
157 if(!mdp_wrapper::setOverlay(mFd.getFD(), mOVInfo)) {
158 ALOGE("MdpCtrl failed to setOverlay, restoring last known "
159 "good ov info");
160 mdp_wrapper::dump("== Bad OVInfo is: ", mOVInfo);
161 mdp_wrapper::dump("== Last good known OVInfo is: ", mLkgo);
162 this->restore();
163 return false;
164 }
165 this->save();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700166 }
Saurabh Shahb121e142012-08-20 17:59:13 -0700167
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700168 return true;
169}
170
Naseer Ahmed29a26812012-06-14 00:56:20 -0700171bool MdpCtrl::get() {
172 mdp_overlay ov;
173 ov.id = mOVInfo.id;
174 if (!mdp_wrapper::getOverlay(mFd.getFD(), ov)) {
175 ALOGE("MdpCtrl get failed");
176 return false;
177 }
178 mOVInfo = ov;
179 return true;
180}
181
Saurabh Shahacf10202013-02-26 10:15:15 -0800182//Update src format based on rotator's destination format.
183void MdpCtrl::updateSrcFormat(const uint32_t& rotDestFmt) {
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800184 utils::Whf whf = getSrcWhf();
Saurabh Shahacf10202013-02-26 10:15:15 -0800185 whf.format = rotDestFmt;
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800186 setSrcWhf(whf);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700187}
188
189void MdpCtrl::dump() const {
190 ALOGE("== Dump MdpCtrl start ==");
Naseer Ahmed29a26812012-06-14 00:56:20 -0700191 mFd.dump();
192 mdp_wrapper::dump("mOVInfo", mOVInfo);
193 ALOGE("== Dump MdpCtrl end ==");
194}
195
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800196void MdpCtrl::getDump(char *buf, size_t len) {
197 ovutils::getDump(buf, len, "Ctrl(mdp_overlay)", mOVInfo);
198}
199
Naseer Ahmed29a26812012-06-14 00:56:20 -0700200void MdpData::dump() const {
201 ALOGE("== Dump MdpData start ==");
202 mFd.dump();
203 mdp_wrapper::dump("mOvData", mOvData);
204 ALOGE("== Dump MdpData end ==");
205}
206
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800207void MdpData::getDump(char *buf, size_t len) {
208 ovutils::getDump(buf, len, "Data(msmfb_overlay_data)", mOvData);
209}
210
Naseer Ahmed29a26812012-06-14 00:56:20 -0700211void MdpCtrl3D::dump() const {
212 ALOGE("== Dump MdpCtrl start ==");
213 mFd.dump();
214 ALOGE("== Dump MdpCtrl end ==");
215}
216
Saurabh Shah5daeee52013-01-23 16:52:26 +0800217bool MdpCtrl::setVisualParams(const MetaData_t& data) {
218 bool needUpdate = false;
219#ifdef USES_POST_PROCESSING
220 /* calculate the data */
221 if (data.operation & PP_PARAM_HSIC) {
222 if (mParams.params.pa_params.hue != data.hsicData.hue) {
223 ALOGD_IF(HSIC_SETTINGS_DEBUG,
224 "Hue has changed from %d to %d",
225 mParams.params.pa_params.hue,data.hsicData.hue);
226 needUpdate = true;
227 }
228
229 if (!isEqual(mParams.params.pa_params.sat,
230 data.hsicData.saturation)) {
231 ALOGD_IF(HSIC_SETTINGS_DEBUG,
232 "Saturation has changed from %f to %f",
233 mParams.params.pa_params.sat,
234 data.hsicData.saturation);
235 needUpdate = true;
236 }
237
238 if (mParams.params.pa_params.intensity != data.hsicData.intensity) {
239 ALOGD_IF(HSIC_SETTINGS_DEBUG,
240 "Intensity has changed from %d to %d",
241 mParams.params.pa_params.intensity,
242 data.hsicData.intensity);
243 needUpdate = true;
244 }
245
246 if (!isEqual(mParams.params.pa_params.contrast,
247 data.hsicData.contrast)) {
248 ALOGD_IF(HSIC_SETTINGS_DEBUG,
249 "Contrast has changed from %f to %f",
250 mParams.params.pa_params.contrast,
251 data.hsicData.contrast);
252 needUpdate = true;
253 }
254
255 if (needUpdate) {
256 mParams.params.pa_params.hue = data.hsicData.hue;
257 mParams.params.pa_params.sat = data.hsicData.saturation;
258 mParams.params.pa_params.intensity = data.hsicData.intensity;
259 mParams.params.pa_params.contrast = data.hsicData.contrast;
260 mParams.params.pa_params.ops = MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
261 mParams.operation |= PP_OP_PA;
262 }
263 }
264
265 if (data.operation & PP_PARAM_SHARP2) {
266 if (mParams.params.sharp_params.strength != data.Sharp2Data.strength) {
267 needUpdate = true;
268 }
269 if (mParams.params.sharp_params.edge_thr != data.Sharp2Data.edge_thr) {
270 needUpdate = true;
271 }
272 if (mParams.params.sharp_params.smooth_thr !=
273 data.Sharp2Data.smooth_thr) {
274 needUpdate = true;
275 }
276 if (mParams.params.sharp_params.noise_thr !=
277 data.Sharp2Data.noise_thr) {
278 needUpdate = true;
279 }
280
281 if (needUpdate) {
282 mParams.params.sharp_params.strength = data.Sharp2Data.strength;
283 mParams.params.sharp_params.edge_thr = data.Sharp2Data.edge_thr;
284 mParams.params.sharp_params.smooth_thr =
285 data.Sharp2Data.smooth_thr;
286 mParams.params.sharp_params.noise_thr = data.Sharp2Data.noise_thr;
287 mParams.params.sharp_params.ops =
288 MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
289 mParams.operation |= PP_OP_SHARP;
290 }
291 }
292
293 if (data.operation & PP_PARAM_IGC) {
294 if (mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data == NULL){
295 uint32_t *igcData
296 = (uint32_t *)malloc(2 * MAX_IGC_LUT_ENTRIES * sizeof(uint32_t));
297 if (!igcData) {
298 ALOGE("IGC storage allocated failed");
299 return false;
300 }
301 mOVInfo.overlay_pp_cfg.igc_cfg.c0_c1_data = igcData;
302 mOVInfo.overlay_pp_cfg.igc_cfg.c2_data
303 = igcData + MAX_IGC_LUT_ENTRIES;
304 }
305
306 memcpy(mParams.params.igc_lut_params.c0,
307 data.igcData.c0, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
308 memcpy(mParams.params.igc_lut_params.c1,
309 data.igcData.c1, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
310 memcpy(mParams.params.igc_lut_params.c2,
311 data.igcData.c2, sizeof(uint16_t) * MAX_IGC_LUT_ENTRIES);
312
313 mParams.params.igc_lut_params.ops
314 = MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE;
315 mParams.operation |= PP_OP_IGC;
316 needUpdate = true;
317 }
318
319 if (data.operation & PP_PARAM_VID_INTFC) {
320 mParams.params.conv_params.interface =
321 (interface_type) data.video_interface;
322 needUpdate = true;
323 }
324
325 if (needUpdate) {
326 display_pp_compute_params(&mParams, &mOVInfo.overlay_pp_cfg);
327 mPPChanged = true;
328 }
329#endif
330 return true;
331}
332
Naseer Ahmed29a26812012-06-14 00:56:20 -0700333} // overlay