blob: 9d5699226f6de8ee83a7f8ac2f7ae42e42476fc1 [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"
Saurabh Shahfc3652f2013-02-15 13:15:45 -080023#include "gr.h"
Naseer Ahmed29a26812012-06-14 00:56:20 -070024
25namespace ovutils = overlay::utils;
26
27namespace overlay {
28
Saurabh Shah23a813c2013-03-20 16:58:12 -070029//============Rotator=========================
30
Naseer Ahmed758bfc52012-11-28 17:02:08 -050031Rotator::~Rotator() {}
32
33Rotator* Rotator::getRotator() {
34 int type = getRotatorHwType();
35 if(type == TYPE_MDP) {
36 return new MdpRot(); //will do reset
37 } else if(type == TYPE_MDSS) {
38 return new MdssRot();
39 } else {
40 ALOGE("%s Unknown h/w type %d", __FUNCTION__, type);
41 return NULL;
42 }
43}
44
Saurabh Shahc46cf9d2014-07-02 15:22:34 -070045int Rotator::getDownscaleFactor(const int& srcW, const int& srcH,
46 const int& dstW, const int& dstH, const uint32_t& mdpFormat,
47 const bool& isInterlaced) {
48 if(getRotatorHwType() == TYPE_MDSS) {
49 return MdssRot::getDownscaleFactor(srcW, srcH, dstW, dstH,
50 mdpFormat, isInterlaced);
51 }
52 return MdpRot::getDownscaleFactor(srcW, srcH, dstW, dstH,
53 mdpFormat, isInterlaced);
54}
55
Saurabh Shahfc3652f2013-02-15 13:15:45 -080056uint32_t Rotator::calcOutputBufSize(const utils::Whf& destWhf) {
57 //dummy aligned w & h.
58 int alW = 0, alH = 0;
59 int halFormat = ovutils::getHALFormat(destWhf.format);
60 //A call into gralloc/memalloc
61 return getBufferSizeAndDimensions(
62 destWhf.w, destWhf.h, halFormat, alW, alH);
63}
64
Naseer Ahmed758bfc52012-11-28 17:02:08 -050065int Rotator::getRotatorHwType() {
Saurabh Shahe012f7a2012-08-18 15:11:57 -070066 int mdpVersion = qdutils::MDPVersion::getInstance().getMDPVersion();
67 if (mdpVersion == qdutils::MDSS_V5)
68 return TYPE_MDSS;
Naseer Ahmedf48aef62012-07-20 09:05:53 -070069 return TYPE_MDP;
Naseer Ahmed29a26812012-06-14 00:56:20 -070070}
71
Saurabh Shah23a813c2013-03-20 16:58:12 -070072
73//============RotMem=========================
74
Naseer Ahmedf48aef62012-07-20 09:05:53 -070075bool RotMem::close() {
76 bool ret = true;
Saurabh Shah912c9482014-02-07 14:01:04 -080077 if(valid()) {
78 if(mem.close() == false) {
79 ALOGE("%s error in closing rot mem", __FUNCTION__);
80 ret = false;
Naseer Ahmedf48aef62012-07-20 09:05:53 -070081 }
Naseer Ahmed29a26812012-06-14 00:56:20 -070082 }
Naseer Ahmedf48aef62012-07-20 09:05:53 -070083 return ret;
Naseer Ahmed29a26812012-06-14 00:56:20 -070084}
85
Saurabh Shah912c9482014-02-07 14:01:04 -080086RotMem::RotMem() : mCurrIndex(0) {
Saurabh Shah23a813c2013-03-20 16:58:12 -070087 utils::memset0(mRotOffset);
88 for(int i = 0; i < ROT_NUM_BUFS; i++) {
89 mRelFence[i] = -1;
90 }
91}
92
Saurabh Shah912c9482014-02-07 14:01:04 -080093RotMem::~RotMem() {
Saurabh Shah23a813c2013-03-20 16:58:12 -070094 for(int i = 0; i < ROT_NUM_BUFS; i++) {
95 ::close(mRelFence[i]);
96 mRelFence[i] = -1;
97 }
98}
99
Saurabh Shah912c9482014-02-07 14:01:04 -0800100void RotMem::setReleaseFd(const int& fence) {
Saurabh Shah23a813c2013-03-20 16:58:12 -0700101 int ret = 0;
102
Saurabh Shah912c9482014-02-07 14:01:04 -0800103 if(mRelFence[mCurrIndex] >= 0) {
Saurabh Shah23a813c2013-03-20 16:58:12 -0700104 //Wait for previous usage of this buffer to be over.
105 //Can happen if rotation takes > vsync and a fast producer. i.e queue
106 //happens in subsequent vsyncs either because content is 60fps or
107 //because the producer is hasty sometimes.
Saurabh Shah912c9482014-02-07 14:01:04 -0800108 ret = sync_wait(mRelFence[mCurrIndex], 1000);
Saurabh Shah23a813c2013-03-20 16:58:12 -0700109 if(ret < 0) {
110 ALOGE("%s: sync_wait error!! error no = %d err str = %s",
111 __FUNCTION__, errno, strerror(errno));
112 }
Saurabh Shah912c9482014-02-07 14:01:04 -0800113 ::close(mRelFence[mCurrIndex]);
Saurabh Shah23a813c2013-03-20 16:58:12 -0700114 }
Saurabh Shah912c9482014-02-07 14:01:04 -0800115 mRelFence[mCurrIndex] = fence;
Saurabh Shah23a813c2013-03-20 16:58:12 -0700116}
117
118//============RotMgr=========================
Saurabh Shah7a606842013-12-11 14:36:04 -0800119RotMgr * RotMgr::sRotMgr = NULL;
120
121RotMgr* RotMgr::getInstance() {
122 if(sRotMgr == NULL) {
123 sRotMgr = new RotMgr();
124 }
125 return sRotMgr;
126}
Saurabh Shah23a813c2013-03-20 16:58:12 -0700127
Saurabh Shahacf10202013-02-26 10:15:15 -0800128RotMgr::RotMgr() {
129 for(int i = 0; i < MAX_ROT_SESS; i++) {
130 mRot[i] = 0;
131 }
132 mUseCount = 0;
Saurabh Shah23a813c2013-03-20 16:58:12 -0700133 mRotDevFd = -1;
Saurabh Shahacf10202013-02-26 10:15:15 -0800134}
135
136RotMgr::~RotMgr() {
137 clear();
138}
139
140void RotMgr::configBegin() {
141 //Reset the number of objects used
142 mUseCount = 0;
143}
144
145void RotMgr::configDone() {
146 //Remove the top most unused objects. Videos come and go.
147 for(int i = mUseCount; i < MAX_ROT_SESS; i++) {
148 if(mRot[i]) {
149 delete mRot[i];
150 mRot[i] = 0;
151 }
152 }
153}
154
155Rotator* RotMgr::getNext() {
156 //Return a rot object, creating one if necessary
157 overlay::Rotator *rot = NULL;
158 if(mUseCount >= MAX_ROT_SESS) {
Saurabh Shah54318572014-05-30 16:42:33 -0700159 ALOGW("%s, MAX rotator sessions reached, request rejected", __func__);
Saurabh Shahacf10202013-02-26 10:15:15 -0800160 } else {
161 if(mRot[mUseCount] == NULL)
162 mRot[mUseCount] = overlay::Rotator::getRotator();
163 rot = mRot[mUseCount++];
164 }
165 return rot;
166}
167
168void RotMgr::clear() {
169 //Brute force obj destruction, helpful in suspend.
170 for(int i = 0; i < MAX_ROT_SESS; i++) {
171 if(mRot[i]) {
172 delete mRot[i];
173 mRot[i] = 0;
174 }
175 }
176 mUseCount = 0;
Saurabh Shah23a813c2013-03-20 16:58:12 -0700177 ::close(mRotDevFd);
178 mRotDevFd = -1;
Saurabh Shahacf10202013-02-26 10:15:15 -0800179}
180
181void RotMgr::getDump(char *buf, size_t len) {
182 for(int i = 0; i < MAX_ROT_SESS; i++) {
183 if(mRot[i]) {
184 mRot[i]->getDump(buf, len);
185 }
186 }
Saurabh Shah7ef9ec92013-10-29 10:32:23 -0700187 char str[4] = {'\0'};
188 snprintf(str, 4, "\n");
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800189 strlcat(buf, str, len);
Saurabh Shahacf10202013-02-26 10:15:15 -0800190}
191
Saurabh Shah23a813c2013-03-20 16:58:12 -0700192int RotMgr::getRotDevFd() {
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -0700193 if(mRotDevFd < 0 && Rotator::getRotatorHwType() == Rotator::TYPE_MDSS) {
194 mRotDevFd = ::open("/dev/graphics/fb0", O_RDWR, 0);
Saurabh Shah23a813c2013-03-20 16:58:12 -0700195 if(mRotDevFd < 0) {
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -0700196 ALOGE("%s failed to open fb0", __FUNCTION__);
Saurabh Shah23a813c2013-03-20 16:58:12 -0700197 }
198 }
199 return mRotDevFd;
200}
201
Naseer Ahmed29a26812012-06-14 00:56:20 -0700202}