blob: 2cdd003515f5aa86b5befc04a82199e7187ebe68 [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) {
100 mOrientation = orient;
101 int rot = utils::getMdpOrient(orient);
102 setUserData(rot);
103 //Rotator can be requested by client even if layer has 0 orientation.
104 mRotUsed = rotUsed;
105 return true;
106}
107
108void MdpCtrl::doTransform() {
109 adjustSrcWhf(mRotUsed);
110 setRotationFlags();
111 //180 will be H + V
112 //270 will be H + V + 90
113 if(mOrientation & utils::OVERLAY_TRANSFORM_FLIP_H) {
114 overlayTransFlipH();
115 }
116 if(mOrientation & utils::OVERLAY_TRANSFORM_FLIP_V) {
117 overlayTransFlipV();
118 }
119 if(mOrientation & utils::OVERLAY_TRANSFORM_ROT_90) {
120 overlayTransRot90();
121 }
122}
123
124bool MdpCtrl::set() {
125 //deferred calcs, so APIs could be called in any order.
126 doTransform();
127 if(!mdp_wrapper::setOverlay(mFd.getFD(), mOVInfo)) {
128 ALOGE("MdpCtrl failed to setOverlay, restoring last known "
129 "good ov info");
130 mdp_wrapper::dump("== Bad OVInfo is: ", mOVInfo);
131 mdp_wrapper::dump("== Last good known OVInfo is: ", mLkgo);
132 this->restore();
133 return false;
134 }
135 this->save();
136 return true;
137}
138
Naseer Ahmed29a26812012-06-14 00:56:20 -0700139bool MdpCtrl::getScreenInfo(overlay::utils::ScreenInfo& info) {
140 fb_fix_screeninfo finfo;
141 if (!mdp_wrapper::getFScreenInfo(mFd.getFD(), finfo)) {
142 return false;
143 }
144
145 fb_var_screeninfo vinfo;
146 if (!mdp_wrapper::getVScreenInfo(mFd.getFD(), vinfo)) {
147 return false;
148 }
149 info.mFBWidth = vinfo.xres;
150 info.mFBHeight = vinfo.yres;
151 info.mFBbpp = vinfo.bits_per_pixel;
152 info.mFBystride = finfo.line_length;
153 return true;
154}
155
156bool MdpCtrl::get() {
157 mdp_overlay ov;
158 ov.id = mOVInfo.id;
159 if (!mdp_wrapper::getOverlay(mFd.getFD(), ov)) {
160 ALOGE("MdpCtrl get failed");
161 return false;
162 }
163 mOVInfo = ov;
164 return true;
165}
166
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700167//Adjust width, height, format if rotator is used.
168void MdpCtrl::adjustSrcWhf(const bool& rotUsed) {
169 if(rotUsed) {
170 utils::Whf whf = getSrcWhf();
171 if(whf.format == MDP_Y_CRCB_H2V2_TILE ||
172 whf.format == MDP_Y_CBCR_H2V2_TILE) {
173 whf.w = utils::alignup(whf.w, 64);
174 whf.h = utils::alignup(whf.h, 32);
175 }
176 //For example: If original format is tiled, rotator outputs non-tiled,
177 //so update mdp's src fmt to that.
178 whf.format = utils::getRotOutFmt(whf.format);
179 setSrcWhf(whf);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700180 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700181}
182
183void MdpCtrl::dump() const {
184 ALOGE("== Dump MdpCtrl start ==");
Naseer Ahmed29a26812012-06-14 00:56:20 -0700185 mFd.dump();
186 mdp_wrapper::dump("mOVInfo", mOVInfo);
187 ALOGE("== Dump MdpCtrl end ==");
188}
189
190void MdpData::dump() const {
191 ALOGE("== Dump MdpData start ==");
192 mFd.dump();
193 mdp_wrapper::dump("mOvData", mOvData);
194 ALOGE("== Dump MdpData end ==");
195}
196
197void MdpCtrl3D::dump() const {
198 ALOGE("== Dump MdpCtrl start ==");
199 mFd.dump();
200 ALOGE("== Dump MdpCtrl end ==");
201}
202
203} // overlay