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