blob: 06e907458dfa1abfacae38bf826d6cd2a0703293 [file] [log] [blame]
Naseer Ahmed29a26812012-06-14 00:56:20 -07001/*
Naseer Ahmed758bfc52012-11-28 17:02:08 -05002 * Copyright (C) 2008 The Android Open Source Project
3 * Copyright (c) 2010-2012, The Linux Foundation. All rights reserved.
4 * Not a Contribution, Apache license notifications and license are retained
5 * for attribution purposes only.
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
Naseer Ahmed29a26812012-06-14 00:56:20 -070018*/
19
20#include "overlayRotator.h"
21#include "overlayUtils.h"
Saurabh Shahe012f7a2012-08-18 15:11:57 -070022#include "mdp_version.h"
Raj Kamal389d6e32014-08-04 14:43:24 +053023#include "sync/sync.h"
Saurabh Shahfc3652f2013-02-15 13:15:45 -080024#include "gr.h"
Naseer Ahmed29a26812012-06-14 00:56:20 -070025
26namespace ovutils = overlay::utils;
27
28namespace overlay {
29
Saurabh Shah23a813c2013-03-20 16:58:12 -070030//============Rotator=========================
31
Naseer Ahmed758bfc52012-11-28 17:02:08 -050032Rotator::~Rotator() {}
33
34Rotator* Rotator::getRotator() {
35 int type = getRotatorHwType();
36 if(type == TYPE_MDP) {
37 return new MdpRot(); //will do reset
38 } else if(type == TYPE_MDSS) {
39 return new MdssRot();
40 } else {
41 ALOGE("%s Unknown h/w type %d", __FUNCTION__, type);
42 return NULL;
43 }
44}
45
Saurabh Shahc46cf9d2014-07-02 15:22:34 -070046int Rotator::getDownscaleFactor(const int& srcW, const int& srcH,
47 const int& dstW, const int& dstH, const uint32_t& mdpFormat,
48 const bool& isInterlaced) {
49 if(getRotatorHwType() == TYPE_MDSS) {
50 return MdssRot::getDownscaleFactor(srcW, srcH, dstW, dstH,
51 mdpFormat, isInterlaced);
52 }
53 return MdpRot::getDownscaleFactor(srcW, srcH, dstW, dstH,
54 mdpFormat, isInterlaced);
55}
56
Saurabh Shahfc3652f2013-02-15 13:15:45 -080057uint32_t Rotator::calcOutputBufSize(const utils::Whf& destWhf) {
58 //dummy aligned w & h.
59 int alW = 0, alH = 0;
60 int halFormat = ovutils::getHALFormat(destWhf.format);
61 //A call into gralloc/memalloc
62 return getBufferSizeAndDimensions(
63 destWhf.w, destWhf.h, halFormat, alW, alH);
64}
65
Naseer Ahmed758bfc52012-11-28 17:02:08 -050066int Rotator::getRotatorHwType() {
Saurabh Shahe012f7a2012-08-18 15:11:57 -070067 int mdpVersion = qdutils::MDPVersion::getInstance().getMDPVersion();
68 if (mdpVersion == qdutils::MDSS_V5)
69 return TYPE_MDSS;
Naseer Ahmedf48aef62012-07-20 09:05:53 -070070 return TYPE_MDP;
Naseer Ahmed29a26812012-06-14 00:56:20 -070071}
72
Saurabh Shah23a813c2013-03-20 16:58:12 -070073
74//============RotMem=========================
75
Naseer Ahmedf48aef62012-07-20 09:05:53 -070076bool RotMem::close() {
77 bool ret = true;
Saurabh Shah912c9482014-02-07 14:01:04 -080078 if(valid()) {
79 if(mem.close() == false) {
80 ALOGE("%s error in closing rot mem", __FUNCTION__);
81 ret = false;
Naseer Ahmedf48aef62012-07-20 09:05:53 -070082 }
Naseer Ahmed29a26812012-06-14 00:56:20 -070083 }
Naseer Ahmedf48aef62012-07-20 09:05:53 -070084 return ret;
Naseer Ahmed29a26812012-06-14 00:56:20 -070085}
86
Saurabh Shah912c9482014-02-07 14:01:04 -080087RotMem::RotMem() : mCurrIndex(0) {
Saurabh Shah23a813c2013-03-20 16:58:12 -070088 utils::memset0(mRotOffset);
89 for(int i = 0; i < ROT_NUM_BUFS; i++) {
90 mRelFence[i] = -1;
91 }
92}
93
Saurabh Shah912c9482014-02-07 14:01:04 -080094RotMem::~RotMem() {
Saurabh Shah23a813c2013-03-20 16:58:12 -070095 for(int i = 0; i < ROT_NUM_BUFS; i++) {
96 ::close(mRelFence[i]);
97 mRelFence[i] = -1;
98 }
99}
100
Saurabh Shah912c9482014-02-07 14:01:04 -0800101void RotMem::setReleaseFd(const int& fence) {
Saurabh Shah23a813c2013-03-20 16:58:12 -0700102 int ret = 0;
103
Saurabh Shah912c9482014-02-07 14:01:04 -0800104 if(mRelFence[mCurrIndex] >= 0) {
Saurabh Shah23a813c2013-03-20 16:58:12 -0700105 //Wait for previous usage of this buffer to be over.
106 //Can happen if rotation takes > vsync and a fast producer. i.e queue
107 //happens in subsequent vsyncs either because content is 60fps or
108 //because the producer is hasty sometimes.
Saurabh Shah912c9482014-02-07 14:01:04 -0800109 ret = sync_wait(mRelFence[mCurrIndex], 1000);
Saurabh Shah23a813c2013-03-20 16:58:12 -0700110 if(ret < 0) {
111 ALOGE("%s: sync_wait error!! error no = %d err str = %s",
112 __FUNCTION__, errno, strerror(errno));
113 }
Saurabh Shah912c9482014-02-07 14:01:04 -0800114 ::close(mRelFence[mCurrIndex]);
Saurabh Shah23a813c2013-03-20 16:58:12 -0700115 }
Saurabh Shah912c9482014-02-07 14:01:04 -0800116 mRelFence[mCurrIndex] = fence;
Saurabh Shah23a813c2013-03-20 16:58:12 -0700117}
118
119//============RotMgr=========================
Saurabh Shah7a606842013-12-11 14:36:04 -0800120RotMgr * RotMgr::sRotMgr = NULL;
121
122RotMgr* RotMgr::getInstance() {
123 if(sRotMgr == NULL) {
124 sRotMgr = new RotMgr();
125 }
126 return sRotMgr;
127}
Saurabh Shah23a813c2013-03-20 16:58:12 -0700128
Saurabh Shahacf10202013-02-26 10:15:15 -0800129RotMgr::RotMgr() {
130 for(int i = 0; i < MAX_ROT_SESS; i++) {
131 mRot[i] = 0;
132 }
133 mUseCount = 0;
Saurabh Shah23a813c2013-03-20 16:58:12 -0700134 mRotDevFd = -1;
Saurabh Shahacf10202013-02-26 10:15:15 -0800135}
136
137RotMgr::~RotMgr() {
138 clear();
139}
140
141void RotMgr::configBegin() {
142 //Reset the number of objects used
143 mUseCount = 0;
144}
145
146void RotMgr::configDone() {
147 //Remove the top most unused objects. Videos come and go.
148 for(int i = mUseCount; i < MAX_ROT_SESS; i++) {
149 if(mRot[i]) {
150 delete mRot[i];
151 mRot[i] = 0;
152 }
153 }
154}
155
156Rotator* RotMgr::getNext() {
157 //Return a rot object, creating one if necessary
158 overlay::Rotator *rot = NULL;
159 if(mUseCount >= MAX_ROT_SESS) {
Saurabh Shah54318572014-05-30 16:42:33 -0700160 ALOGW("%s, MAX rotator sessions reached, request rejected", __func__);
Saurabh Shahacf10202013-02-26 10:15:15 -0800161 } else {
162 if(mRot[mUseCount] == NULL)
163 mRot[mUseCount] = overlay::Rotator::getRotator();
164 rot = mRot[mUseCount++];
165 }
166 return rot;
167}
168
169void RotMgr::clear() {
170 //Brute force obj destruction, helpful in suspend.
171 for(int i = 0; i < MAX_ROT_SESS; i++) {
172 if(mRot[i]) {
173 delete mRot[i];
174 mRot[i] = 0;
175 }
176 }
177 mUseCount = 0;
Saurabh Shah23a813c2013-03-20 16:58:12 -0700178 ::close(mRotDevFd);
179 mRotDevFd = -1;
Saurabh Shahacf10202013-02-26 10:15:15 -0800180}
181
182void RotMgr::getDump(char *buf, size_t len) {
183 for(int i = 0; i < MAX_ROT_SESS; i++) {
184 if(mRot[i]) {
185 mRot[i]->getDump(buf, len);
186 }
187 }
Saurabh Shah7ef9ec92013-10-29 10:32:23 -0700188 char str[4] = {'\0'};
189 snprintf(str, 4, "\n");
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800190 strlcat(buf, str, len);
Saurabh Shahacf10202013-02-26 10:15:15 -0800191}
192
Saurabh Shah23a813c2013-03-20 16:58:12 -0700193int RotMgr::getRotDevFd() {
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -0700194 if(mRotDevFd < 0 && Rotator::getRotatorHwType() == Rotator::TYPE_MDSS) {
195 mRotDevFd = ::open("/dev/graphics/fb0", O_RDWR, 0);
Saurabh Shah23a813c2013-03-20 16:58:12 -0700196 if(mRotDevFd < 0) {
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -0700197 ALOGE("%s failed to open fb0", __FUNCTION__);
Saurabh Shah23a813c2013-03-20 16:58:12 -0700198 }
199 }
200 return mRotDevFd;
201}
202
Naseer Ahmed29a26812012-06-14 00:56:20 -0700203}