blob: 6fd1eb8fbfc74eb626a4e22446fa388d0b013baa [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() {
Naseer Ahmedf48aef62012-07-20 09:05:53 -070046 if(MSMFB_NEW_REQUEST == static_cast<int>(mOVInfo.id))
47 return true;
Naseer Ahmed29a26812012-06-14 00:56:20 -070048 if(!mdp_wrapper::unsetOverlay(mFd.getFD(), mOVInfo.id)) {
49 ALOGE("MdpCtrl close error in unset");
50 return false;
51 }
52 reset();
53 if(!mFd.close()) {
54 return false;
55 }
56 return true;
57}
58
Naseer Ahmedf48aef62012-07-20 09:05:53 -070059bool MdpCtrl::setSource(const utils::PipeArgs& args) {
60
61 setSrcWhf(args.whf);
62
63 //TODO These are hardcoded. Can be moved out of setSource.
64 mOVInfo.alpha = 0xff;
65 mOVInfo.transp_mask = 0xffffffff;
66
67 //TODO These calls should ideally be a part of setPipeParams API
68 setFlags(args.mdpFlags);
69 setZ(args.zorder);
70 setIsFg(args.isFg);
71 return true;
72}
73
74bool MdpCtrl::setCrop(const utils::Dim& d) {
75 setSrcRectDim(d);
76 return true;
77}
78
79bool MdpCtrl::setPosition(const overlay::utils::Dim& d,
80 int fbw, int fbh)
81{
82 ovutils::Dim dim(d);
83 ovutils::Dim ovsrcdim = getSrcRectDim();
84 // Scaling of upto a max of 20 times supported
85 if(dim.w >(ovsrcdim.w * ovutils::HW_OV_MAGNIFICATION_LIMIT)){
86 dim.w = ovutils::HW_OV_MAGNIFICATION_LIMIT * ovsrcdim.w;
87 dim.x = (fbw - dim.w) / 2;
88 }
89 if(dim.h >(ovsrcdim.h * ovutils::HW_OV_MAGNIFICATION_LIMIT)) {
90 dim.h = ovutils::HW_OV_MAGNIFICATION_LIMIT * ovsrcdim.h;
91 dim.y = (fbh - dim.h) / 2;
92 }
93
94 setDstRectDim(dim);
95 return true;
96}
97
98bool MdpCtrl::setTransform(const utils::eTransform& orient,
99 const bool& rotUsed) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700100 int rot = utils::getMdpOrient(orient);
101 setUserData(rot);
Saurabh Shaha73738d2012-08-09 18:15:18 -0700102 //getMdpOrient will switch the flips if the source is 90 rotated.
103 //Clients in Android dont factor in 90 rotation while deciding the flip.
104 mOrientation = static_cast<utils::eTransform>(rot);
105
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700106 //Rotator can be requested by client even if layer has 0 orientation.
107 mRotUsed = rotUsed;
108 return true;
109}
110
111void MdpCtrl::doTransform() {
112 adjustSrcWhf(mRotUsed);
113 setRotationFlags();
114 //180 will be H + V
115 //270 will be H + V + 90
116 if(mOrientation & utils::OVERLAY_TRANSFORM_FLIP_H) {
117 overlayTransFlipH();
118 }
119 if(mOrientation & utils::OVERLAY_TRANSFORM_FLIP_V) {
120 overlayTransFlipV();
121 }
122 if(mOrientation & utils::OVERLAY_TRANSFORM_ROT_90) {
123 overlayTransRot90();
124 }
125}
126
127bool MdpCtrl::set() {
128 //deferred calcs, so APIs could be called in any order.
129 doTransform();
130 if(!mdp_wrapper::setOverlay(mFd.getFD(), mOVInfo)) {
131 ALOGE("MdpCtrl failed to setOverlay, restoring last known "
132 "good ov info");
133 mdp_wrapper::dump("== Bad OVInfo is: ", mOVInfo);
134 mdp_wrapper::dump("== Last good known OVInfo is: ", mLkgo);
135 this->restore();
136 return false;
137 }
138 this->save();
139 return true;
140}
141
Naseer Ahmed29a26812012-06-14 00:56:20 -0700142bool MdpCtrl::getScreenInfo(overlay::utils::ScreenInfo& info) {
143 fb_fix_screeninfo finfo;
144 if (!mdp_wrapper::getFScreenInfo(mFd.getFD(), finfo)) {
145 return false;
146 }
147
148 fb_var_screeninfo vinfo;
149 if (!mdp_wrapper::getVScreenInfo(mFd.getFD(), vinfo)) {
150 return false;
151 }
152 info.mFBWidth = vinfo.xres;
153 info.mFBHeight = vinfo.yres;
154 info.mFBbpp = vinfo.bits_per_pixel;
155 info.mFBystride = finfo.line_length;
156 return true;
157}
158
159bool MdpCtrl::get() {
160 mdp_overlay ov;
161 ov.id = mOVInfo.id;
162 if (!mdp_wrapper::getOverlay(mFd.getFD(), ov)) {
163 ALOGE("MdpCtrl get failed");
164 return false;
165 }
166 mOVInfo = ov;
167 return true;
168}
169
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700170//Adjust width, height, format if rotator is used.
171void MdpCtrl::adjustSrcWhf(const bool& rotUsed) {
172 if(rotUsed) {
173 utils::Whf whf = getSrcWhf();
174 if(whf.format == MDP_Y_CRCB_H2V2_TILE ||
175 whf.format == MDP_Y_CBCR_H2V2_TILE) {
176 whf.w = utils::alignup(whf.w, 64);
177 whf.h = utils::alignup(whf.h, 32);
178 }
179 //For example: If original format is tiled, rotator outputs non-tiled,
180 //so update mdp's src fmt to that.
181 whf.format = utils::getRotOutFmt(whf.format);
182 setSrcWhf(whf);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700183 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700184}
185
186void MdpCtrl::dump() const {
187 ALOGE("== Dump MdpCtrl start ==");
Naseer Ahmed29a26812012-06-14 00:56:20 -0700188 mFd.dump();
189 mdp_wrapper::dump("mOVInfo", mOVInfo);
190 ALOGE("== Dump MdpCtrl end ==");
191}
192
193void MdpData::dump() const {
194 ALOGE("== Dump MdpData start ==");
195 mFd.dump();
196 mdp_wrapper::dump("mOvData", mOvData);
197 ALOGE("== Dump MdpData end ==");
198}
199
200void MdpCtrl3D::dump() const {
201 ALOGE("== Dump MdpCtrl start ==");
202 mFd.dump();
203 ALOGE("== Dump MdpCtrl end ==");
204}
205
206} // overlay