blob: 48630a5cae5d689d5fb561041ded2b0da1d5f594 [file] [log] [blame]
Naseer Ahmed29a26812012-06-14 00:56:20 -07001/*
2* Copyright (C) 2008 The Android Open Source Project
3* Copyright (c) 2010-2012, Code Aurora Forum. All rights reserved.
4*
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
18#include "overlayUtils.h"
19#include "overlayMdp.h"
20
Naseer Ahmed29a26812012-06-14 00:56:20 -070021namespace ovutils = overlay::utils;
22namespace overlay {
Saurabh Shahb121e142012-08-20 17:59:13 -070023
24//Helper to even out x,w and y,h pairs
25//x,y are always evened to ceil and w,h are evened to floor
26static void normalizeCrop(uint32_t& xy, uint32_t& wh) {
27 if(xy & 1) {
28 utils::even_ceil(xy);
29 if(wh & 1)
30 utils::even_floor(wh);
31 else
32 wh -= 2;
33 } else {
34 utils::even_floor(wh);
35 }
36}
37
Naseer Ahmedf48aef62012-07-20 09:05:53 -070038bool MdpCtrl::init(uint32_t fbnum) {
39 // FD init
Naseer Ahmed29a26812012-06-14 00:56:20 -070040 if(!utils::openDev(mFd, fbnum,
Naseer Ahmedf48aef62012-07-20 09:05:53 -070041 Res::fbPath, O_RDWR)){
42 ALOGE("Ctrl failed to init fbnum=%d", fbnum);
Naseer Ahmed29a26812012-06-14 00:56:20 -070043 return false;
44 }
45 return true;
46}
47
48void MdpCtrl::reset() {
49 utils::memset0(mOVInfo);
50 utils::memset0(mLkgo);
Naseer Ahmedf48aef62012-07-20 09:05:53 -070051 mOVInfo.id = MSMFB_NEW_REQUEST;
52 mLkgo.id = MSMFB_NEW_REQUEST;
53 mOrientation = utils::OVERLAY_TRANSFORM_0;
54 mRotUsed = false;
Naseer Ahmed29a26812012-06-14 00:56:20 -070055}
56
57bool MdpCtrl::close() {
Saurabh Shah8e1ae952012-08-15 12:15:14 -070058 bool result = true;
59
60 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();
68 if(!mFd.close()) {
Saurabh Shah8e1ae952012-08-15 12:15:14 -070069 result = false;
Naseer Ahmed29a26812012-06-14 00:56:20 -070070 }
Saurabh Shah8e1ae952012-08-15 12:15:14 -070071
72 return result;
Naseer Ahmed29a26812012-06-14 00:56:20 -070073}
74
Naseer Ahmedf48aef62012-07-20 09:05:53 -070075bool MdpCtrl::setSource(const utils::PipeArgs& args) {
76
77 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);
87 return true;
88}
89
90bool MdpCtrl::setCrop(const utils::Dim& d) {
91 setSrcRectDim(d);
92 return true;
93}
94
95bool MdpCtrl::setPosition(const overlay::utils::Dim& d,
96 int fbw, int fbh)
97{
98 ovutils::Dim dim(d);
99 ovutils::Dim ovsrcdim = getSrcRectDim();
100 // Scaling of upto a max of 20 times supported
101 if(dim.w >(ovsrcdim.w * ovutils::HW_OV_MAGNIFICATION_LIMIT)){
102 dim.w = ovutils::HW_OV_MAGNIFICATION_LIMIT * ovsrcdim.w;
103 dim.x = (fbw - dim.w) / 2;
104 }
105 if(dim.h >(ovsrcdim.h * ovutils::HW_OV_MAGNIFICATION_LIMIT)) {
106 dim.h = ovutils::HW_OV_MAGNIFICATION_LIMIT * ovsrcdim.h;
107 dim.y = (fbh - dim.h) / 2;
108 }
109
110 setDstRectDim(dim);
111 return true;
112}
113
114bool MdpCtrl::setTransform(const utils::eTransform& orient,
115 const bool& rotUsed) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700116 int rot = utils::getMdpOrient(orient);
117 setUserData(rot);
Saurabh Shaha73738d2012-08-09 18:15:18 -0700118 //getMdpOrient will switch the flips if the source is 90 rotated.
119 //Clients in Android dont factor in 90 rotation while deciding the flip.
120 mOrientation = static_cast<utils::eTransform>(rot);
121
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700122 //Rotator can be requested by client even if layer has 0 orientation.
123 mRotUsed = rotUsed;
124 return true;
125}
126
127void MdpCtrl::doTransform() {
128 adjustSrcWhf(mRotUsed);
129 setRotationFlags();
130 //180 will be H + V
131 //270 will be H + V + 90
132 if(mOrientation & utils::OVERLAY_TRANSFORM_FLIP_H) {
133 overlayTransFlipH();
134 }
135 if(mOrientation & utils::OVERLAY_TRANSFORM_FLIP_V) {
136 overlayTransFlipV();
137 }
138 if(mOrientation & utils::OVERLAY_TRANSFORM_ROT_90) {
139 overlayTransRot90();
140 }
141}
142
143bool MdpCtrl::set() {
144 //deferred calcs, so APIs could be called in any order.
145 doTransform();
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);
150 utils::even_floor(mOVInfo.dst_rect.w);
151 utils::even_floor(mOVInfo.dst_rect.h);
152 }
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::getScreenInfo(overlay::utils::ScreenInfo& info) {
170 fb_fix_screeninfo finfo;
171 if (!mdp_wrapper::getFScreenInfo(mFd.getFD(), finfo)) {
172 return false;
173 }
174
175 fb_var_screeninfo vinfo;
176 if (!mdp_wrapper::getVScreenInfo(mFd.getFD(), vinfo)) {
177 return false;
178 }
179 info.mFBWidth = vinfo.xres;
180 info.mFBHeight = vinfo.yres;
181 info.mFBbpp = vinfo.bits_per_pixel;
182 info.mFBystride = finfo.line_length;
183 return true;
184}
185
186bool MdpCtrl::get() {
187 mdp_overlay ov;
188 ov.id = mOVInfo.id;
189 if (!mdp_wrapper::getOverlay(mFd.getFD(), ov)) {
190 ALOGE("MdpCtrl get failed");
191 return false;
192 }
193 mOVInfo = ov;
194 return true;
195}
196
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700197//Adjust width, height, format if rotator is used.
198void MdpCtrl::adjustSrcWhf(const bool& rotUsed) {
199 if(rotUsed) {
200 utils::Whf whf = getSrcWhf();
201 if(whf.format == MDP_Y_CRCB_H2V2_TILE ||
202 whf.format == MDP_Y_CBCR_H2V2_TILE) {
203 whf.w = utils::alignup(whf.w, 64);
204 whf.h = utils::alignup(whf.h, 32);
205 }
206 //For example: If original format is tiled, rotator outputs non-tiled,
207 //so update mdp's src fmt to that.
208 whf.format = utils::getRotOutFmt(whf.format);
209 setSrcWhf(whf);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700210 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700211}
212
213void MdpCtrl::dump() const {
214 ALOGE("== Dump MdpCtrl start ==");
Naseer Ahmed29a26812012-06-14 00:56:20 -0700215 mFd.dump();
216 mdp_wrapper::dump("mOVInfo", mOVInfo);
217 ALOGE("== Dump MdpCtrl end ==");
218}
219
220void MdpData::dump() const {
221 ALOGE("== Dump MdpData start ==");
222 mFd.dump();
223 mdp_wrapper::dump("mOvData", mOvData);
224 ALOGE("== Dump MdpData end ==");
225}
226
227void MdpCtrl3D::dump() const {
228 ALOGE("== Dump MdpCtrl start ==");
229 mFd.dump();
230 ALOGE("== Dump MdpCtrl end ==");
231}
232
233} // overlay