blob: d96066bd456d93a6f847c46889f5f17a05f9fba6 [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"
21
Naseer Ahmed29a26812012-06-14 00:56:20 -070022namespace ovutils = overlay::utils;
23namespace overlay {
Saurabh Shahb121e142012-08-20 17:59:13 -070024
25//Helper to even out x,w and y,h pairs
26//x,y are always evened to ceil and w,h are evened to floor
27static void normalizeCrop(uint32_t& xy, uint32_t& wh) {
28 if(xy & 1) {
29 utils::even_ceil(xy);
30 if(wh & 1)
31 utils::even_floor(wh);
32 else
33 wh -= 2;
34 } else {
35 utils::even_floor(wh);
36 }
37}
38
Naseer Ahmedf48aef62012-07-20 09:05:53 -070039bool MdpCtrl::init(uint32_t fbnum) {
40 // FD init
Naseer Ahmed29a26812012-06-14 00:56:20 -070041 if(!utils::openDev(mFd, fbnum,
Naseer Ahmedf48aef62012-07-20 09:05:53 -070042 Res::fbPath, O_RDWR)){
43 ALOGE("Ctrl failed to init fbnum=%d", fbnum);
Naseer Ahmed29a26812012-06-14 00:56:20 -070044 return false;
45 }
46 return true;
47}
48
49void MdpCtrl::reset() {
50 utils::memset0(mOVInfo);
51 utils::memset0(mLkgo);
Naseer Ahmedf48aef62012-07-20 09:05:53 -070052 mOVInfo.id = MSMFB_NEW_REQUEST;
53 mLkgo.id = MSMFB_NEW_REQUEST;
54 mOrientation = utils::OVERLAY_TRANSFORM_0;
Saurabh Shahacf10202013-02-26 10:15:15 -080055 mDownscale = 0;
Naseer Ahmed29a26812012-06-14 00:56:20 -070056}
57
58bool MdpCtrl::close() {
Saurabh Shah8e1ae952012-08-15 12:15:14 -070059 bool result = true;
Saurabh Shah8e1ae952012-08-15 12:15:14 -070060 if(MSMFB_NEW_REQUEST != static_cast<int>(mOVInfo.id)) {
61 if(!mdp_wrapper::unsetOverlay(mFd.getFD(), mOVInfo.id)) {
62 ALOGE("MdpCtrl close error in unset");
63 result = false;
64 }
Naseer Ahmed29a26812012-06-14 00:56:20 -070065 }
Saurabh Shah8e1ae952012-08-15 12:15:14 -070066
Naseer Ahmed29a26812012-06-14 00:56:20 -070067 reset();
Saurabh Shahacf10202013-02-26 10:15:15 -080068
Naseer Ahmed29a26812012-06-14 00:56:20 -070069 if(!mFd.close()) {
Saurabh Shah8e1ae952012-08-15 12:15:14 -070070 result = false;
Naseer Ahmed29a26812012-06-14 00:56:20 -070071 }
Saurabh Shah8e1ae952012-08-15 12:15:14 -070072
73 return result;
Naseer Ahmed29a26812012-06-14 00:56:20 -070074}
75
Saurabh Shahacf10202013-02-26 10:15:15 -080076void MdpCtrl::setSource(const utils::PipeArgs& args) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -070077 setSrcWhf(args.whf);
78
79 //TODO These are hardcoded. Can be moved out of setSource.
80 mOVInfo.alpha = 0xff;
81 mOVInfo.transp_mask = 0xffffffff;
82
83 //TODO These calls should ideally be a part of setPipeParams API
84 setFlags(args.mdpFlags);
85 setZ(args.zorder);
86 setIsFg(args.isFg);
Naseer Ahmedf48aef62012-07-20 09:05:53 -070087}
88
Saurabh Shahacf10202013-02-26 10:15:15 -080089void MdpCtrl::setCrop(const utils::Dim& d) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -070090 setSrcRectDim(d);
Naseer Ahmedf48aef62012-07-20 09:05:53 -070091}
92
Saurabh Shahacf10202013-02-26 10:15:15 -080093void MdpCtrl::setPosition(const overlay::utils::Dim& d) {
94 setDstRectDim(d);
Naseer Ahmedf48aef62012-07-20 09:05:53 -070095}
96
Saurabh Shahacf10202013-02-26 10:15:15 -080097void MdpCtrl::setTransform(const utils::eTransform& orient) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -070098 int rot = utils::getMdpOrient(orient);
99 setUserData(rot);
Saurabh Shaha73738d2012-08-09 18:15:18 -0700100 //getMdpOrient will switch the flips if the source is 90 rotated.
101 //Clients in Android dont factor in 90 rotation while deciding the flip.
102 mOrientation = static_cast<utils::eTransform>(rot);
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800103}
104
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700105void MdpCtrl::doTransform() {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700106 setRotationFlags();
Saurabh Shahacf10202013-02-26 10:15:15 -0800107 utils::Whf whf = getSrcWhf();
108 utils::Dim dim = getSrcRectDim();
109 utils::preRotateSource(mOrientation, whf, dim);
110 setSrcWhf(whf);
111 setSrcRectDim(dim);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700112}
113
Saurabh Shahacf10202013-02-26 10:15:15 -0800114void MdpCtrl::doDownscale() {
115 mOVInfo.src_rect.x >>= mDownscale;
116 mOVInfo.src_rect.y >>= mDownscale;
117 mOVInfo.src_rect.w >>= mDownscale;
118 mOVInfo.src_rect.h >>= mDownscale;
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800119}
120
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700121bool MdpCtrl::set() {
122 //deferred calcs, so APIs could be called in any order.
Saurabh Shahacf10202013-02-26 10:15:15 -0800123 doTransform();
124 doDownscale();
Saurabh Shahb121e142012-08-20 17:59:13 -0700125 utils::Whf whf = getSrcWhf();
126 if(utils::isYuv(whf.format)) {
127 normalizeCrop(mOVInfo.src_rect.x, mOVInfo.src_rect.w);
128 normalizeCrop(mOVInfo.src_rect.y, mOVInfo.src_rect.h);
129 utils::even_floor(mOVInfo.dst_rect.w);
130 utils::even_floor(mOVInfo.dst_rect.h);
131 }
132
Saurabh Shahfc2acbe2012-08-17 19:47:52 -0700133 if(this->ovChanged()) {
134 if(!mdp_wrapper::setOverlay(mFd.getFD(), mOVInfo)) {
135 ALOGE("MdpCtrl failed to setOverlay, restoring last known "
136 "good ov info");
137 mdp_wrapper::dump("== Bad OVInfo is: ", mOVInfo);
138 mdp_wrapper::dump("== Last good known OVInfo is: ", mLkgo);
139 this->restore();
140 return false;
141 }
142 this->save();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700143 }
Saurabh Shahb121e142012-08-20 17:59:13 -0700144
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700145 return true;
146}
147
Naseer Ahmed29a26812012-06-14 00:56:20 -0700148bool MdpCtrl::get() {
149 mdp_overlay ov;
150 ov.id = mOVInfo.id;
151 if (!mdp_wrapper::getOverlay(mFd.getFD(), ov)) {
152 ALOGE("MdpCtrl get failed");
153 return false;
154 }
155 mOVInfo = ov;
156 return true;
157}
158
Saurabh Shahacf10202013-02-26 10:15:15 -0800159//Update src format based on rotator's destination format.
160void MdpCtrl::updateSrcFormat(const uint32_t& rotDestFmt) {
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800161 utils::Whf whf = getSrcWhf();
Saurabh Shahacf10202013-02-26 10:15:15 -0800162 whf.format = rotDestFmt;
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800163 setSrcWhf(whf);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700164}
165
166void MdpCtrl::dump() const {
167 ALOGE("== Dump MdpCtrl start ==");
Naseer Ahmed29a26812012-06-14 00:56:20 -0700168 mFd.dump();
169 mdp_wrapper::dump("mOVInfo", mOVInfo);
170 ALOGE("== Dump MdpCtrl end ==");
171}
172
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800173void MdpCtrl::getDump(char *buf, size_t len) {
174 ovutils::getDump(buf, len, "Ctrl(mdp_overlay)", mOVInfo);
175}
176
Naseer Ahmed29a26812012-06-14 00:56:20 -0700177void MdpData::dump() const {
178 ALOGE("== Dump MdpData start ==");
179 mFd.dump();
180 mdp_wrapper::dump("mOvData", mOvData);
181 ALOGE("== Dump MdpData end ==");
182}
183
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800184void MdpData::getDump(char *buf, size_t len) {
185 ovutils::getDump(buf, len, "Data(msmfb_overlay_data)", mOvData);
186}
187
Naseer Ahmed29a26812012-06-14 00:56:20 -0700188void MdpCtrl3D::dump() const {
189 ALOGE("== Dump MdpCtrl start ==");
190 mFd.dump();
191 ALOGE("== Dump MdpCtrl end ==");
192}
193
194} // overlay