blob: d161f4ae67bbcd771837607cc30fa3f46dbc0852 [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
21#undef ALOG_TAG
22#define ALOG_TAG "overlay"
23
24namespace ovutils = overlay::utils;
25namespace overlay {
Naseer Ahmedf48aef62012-07-20 09:05:53 -070026bool MdpCtrl::init(uint32_t fbnum) {
27 // FD init
Naseer Ahmed29a26812012-06-14 00:56:20 -070028 if(!utils::openDev(mFd, fbnum,
Naseer Ahmedf48aef62012-07-20 09:05:53 -070029 Res::fbPath, O_RDWR)){
30 ALOGE("Ctrl failed to init fbnum=%d", fbnum);
Naseer Ahmed29a26812012-06-14 00:56:20 -070031 return false;
32 }
33 return true;
34}
35
36void MdpCtrl::reset() {
37 utils::memset0(mOVInfo);
38 utils::memset0(mLkgo);
Naseer Ahmedf48aef62012-07-20 09:05:53 -070039 mOVInfo.id = MSMFB_NEW_REQUEST;
40 mLkgo.id = MSMFB_NEW_REQUEST;
41 mOrientation = utils::OVERLAY_TRANSFORM_0;
42 mRotUsed = false;
Naseer Ahmed29a26812012-06-14 00:56:20 -070043}
44
45bool MdpCtrl::close() {
Saurabh Shah8e1ae952012-08-15 12:15:14 -070046 bool result = true;
47
48 if(MSMFB_NEW_REQUEST != static_cast<int>(mOVInfo.id)) {
49 if(!mdp_wrapper::unsetOverlay(mFd.getFD(), mOVInfo.id)) {
50 ALOGE("MdpCtrl close error in unset");
51 result = false;
52 }
Naseer Ahmed29a26812012-06-14 00:56:20 -070053 }
Saurabh Shah8e1ae952012-08-15 12:15:14 -070054
Naseer Ahmed29a26812012-06-14 00:56:20 -070055 reset();
56 if(!mFd.close()) {
Saurabh Shah8e1ae952012-08-15 12:15:14 -070057 result = false;
Naseer Ahmed29a26812012-06-14 00:56:20 -070058 }
Saurabh Shah8e1ae952012-08-15 12:15:14 -070059
60 return result;
Naseer Ahmed29a26812012-06-14 00:56:20 -070061}
62
Naseer Ahmedf48aef62012-07-20 09:05:53 -070063bool MdpCtrl::setSource(const utils::PipeArgs& args) {
64
65 setSrcWhf(args.whf);
66
67 //TODO These are hardcoded. Can be moved out of setSource.
68 mOVInfo.alpha = 0xff;
69 mOVInfo.transp_mask = 0xffffffff;
70
71 //TODO These calls should ideally be a part of setPipeParams API
72 setFlags(args.mdpFlags);
73 setZ(args.zorder);
74 setIsFg(args.isFg);
75 return true;
76}
77
78bool MdpCtrl::setCrop(const utils::Dim& d) {
79 setSrcRectDim(d);
80 return true;
81}
82
83bool MdpCtrl::setPosition(const overlay::utils::Dim& d,
84 int fbw, int fbh)
85{
86 ovutils::Dim dim(d);
87 ovutils::Dim ovsrcdim = getSrcRectDim();
88 // Scaling of upto a max of 20 times supported
89 if(dim.w >(ovsrcdim.w * ovutils::HW_OV_MAGNIFICATION_LIMIT)){
90 dim.w = ovutils::HW_OV_MAGNIFICATION_LIMIT * ovsrcdim.w;
91 dim.x = (fbw - dim.w) / 2;
92 }
93 if(dim.h >(ovsrcdim.h * ovutils::HW_OV_MAGNIFICATION_LIMIT)) {
94 dim.h = ovutils::HW_OV_MAGNIFICATION_LIMIT * ovsrcdim.h;
95 dim.y = (fbh - dim.h) / 2;
96 }
97
98 setDstRectDim(dim);
99 return true;
100}
101
102bool MdpCtrl::setTransform(const utils::eTransform& orient,
103 const bool& rotUsed) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700104 int rot = utils::getMdpOrient(orient);
105 setUserData(rot);
Saurabh Shaha73738d2012-08-09 18:15:18 -0700106 //getMdpOrient will switch the flips if the source is 90 rotated.
107 //Clients in Android dont factor in 90 rotation while deciding the flip.
108 mOrientation = static_cast<utils::eTransform>(rot);
109
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700110 //Rotator can be requested by client even if layer has 0 orientation.
111 mRotUsed = rotUsed;
112 return true;
113}
114
115void MdpCtrl::doTransform() {
116 adjustSrcWhf(mRotUsed);
117 setRotationFlags();
118 //180 will be H + V
119 //270 will be H + V + 90
120 if(mOrientation & utils::OVERLAY_TRANSFORM_FLIP_H) {
121 overlayTransFlipH();
122 }
123 if(mOrientation & utils::OVERLAY_TRANSFORM_FLIP_V) {
124 overlayTransFlipV();
125 }
126 if(mOrientation & utils::OVERLAY_TRANSFORM_ROT_90) {
127 overlayTransRot90();
128 }
129}
130
131bool MdpCtrl::set() {
132 //deferred calcs, so APIs could be called in any order.
133 doTransform();
Saurabh Shahfc2acbe2012-08-17 19:47:52 -0700134 if(this->ovChanged()) {
135 if(!mdp_wrapper::setOverlay(mFd.getFD(), mOVInfo)) {
136 ALOGE("MdpCtrl failed to setOverlay, restoring last known "
137 "good ov info");
138 mdp_wrapper::dump("== Bad OVInfo is: ", mOVInfo);
139 mdp_wrapper::dump("== Last good known OVInfo is: ", mLkgo);
140 this->restore();
141 return false;
142 }
143 this->save();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700144 }
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700145 return true;
146}
147
Naseer Ahmed29a26812012-06-14 00:56:20 -0700148bool MdpCtrl::getScreenInfo(overlay::utils::ScreenInfo& info) {
149 fb_fix_screeninfo finfo;
150 if (!mdp_wrapper::getFScreenInfo(mFd.getFD(), finfo)) {
151 return false;
152 }
153
154 fb_var_screeninfo vinfo;
155 if (!mdp_wrapper::getVScreenInfo(mFd.getFD(), vinfo)) {
156 return false;
157 }
158 info.mFBWidth = vinfo.xres;
159 info.mFBHeight = vinfo.yres;
160 info.mFBbpp = vinfo.bits_per_pixel;
161 info.mFBystride = finfo.line_length;
162 return true;
163}
164
165bool MdpCtrl::get() {
166 mdp_overlay ov;
167 ov.id = mOVInfo.id;
168 if (!mdp_wrapper::getOverlay(mFd.getFD(), ov)) {
169 ALOGE("MdpCtrl get failed");
170 return false;
171 }
172 mOVInfo = ov;
173 return true;
174}
175
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700176//Adjust width, height, format if rotator is used.
177void MdpCtrl::adjustSrcWhf(const bool& rotUsed) {
178 if(rotUsed) {
179 utils::Whf whf = getSrcWhf();
180 if(whf.format == MDP_Y_CRCB_H2V2_TILE ||
181 whf.format == MDP_Y_CBCR_H2V2_TILE) {
182 whf.w = utils::alignup(whf.w, 64);
183 whf.h = utils::alignup(whf.h, 32);
184 }
185 //For example: If original format is tiled, rotator outputs non-tiled,
186 //so update mdp's src fmt to that.
187 whf.format = utils::getRotOutFmt(whf.format);
188 setSrcWhf(whf);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700189 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700190}
191
192void MdpCtrl::dump() const {
193 ALOGE("== Dump MdpCtrl start ==");
Naseer Ahmed29a26812012-06-14 00:56:20 -0700194 mFd.dump();
195 mdp_wrapper::dump("mOVInfo", mOVInfo);
196 ALOGE("== Dump MdpCtrl end ==");
197}
198
199void MdpData::dump() const {
200 ALOGE("== Dump MdpData start ==");
201 mFd.dump();
202 mdp_wrapper::dump("mOvData", mOvData);
203 ALOGE("== Dump MdpData end ==");
204}
205
206void MdpCtrl3D::dump() const {
207 ALOGE("== Dump MdpCtrl start ==");
208 mFd.dump();
209 ALOGE("== Dump MdpCtrl end ==");
210}
211
212} // overlay