blob: d912dc77a4d9d0f081fcc1b433b5df1988606143 [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 Shahfc3652f2013-02-15 13:15:45 -080045uint32_t Rotator::calcOutputBufSize(const utils::Whf& destWhf) {
46 //dummy aligned w & h.
47 int alW = 0, alH = 0;
48 int halFormat = ovutils::getHALFormat(destWhf.format);
49 //A call into gralloc/memalloc
50 return getBufferSizeAndDimensions(
51 destWhf.w, destWhf.h, halFormat, alW, alH);
52}
53
Naseer Ahmed758bfc52012-11-28 17:02:08 -050054int Rotator::getRotatorHwType() {
Saurabh Shahe012f7a2012-08-18 15:11:57 -070055 int mdpVersion = qdutils::MDPVersion::getInstance().getMDPVersion();
56 if (mdpVersion == qdutils::MDSS_V5)
57 return TYPE_MDSS;
Naseer Ahmedf48aef62012-07-20 09:05:53 -070058 return TYPE_MDP;
Naseer Ahmed29a26812012-06-14 00:56:20 -070059}
60
Saurabh Shah23a813c2013-03-20 16:58:12 -070061
62//============RotMem=========================
63
Naseer Ahmedf48aef62012-07-20 09:05:53 -070064bool RotMem::close() {
65 bool ret = true;
66 for(uint32_t i=0; i < RotMem::MAX_ROT_MEM; ++i) {
67 // skip current, and if valid, close
68 if(m[i].valid()) {
69 if(m[i].close() == false) {
70 ALOGE("%s error in closing rot mem %d", __FUNCTION__, i);
71 ret = false;
72 }
73 }
Naseer Ahmed29a26812012-06-14 00:56:20 -070074 }
Naseer Ahmedf48aef62012-07-20 09:05:53 -070075 return ret;
Naseer Ahmed29a26812012-06-14 00:56:20 -070076}
77
Saurabh Shah23a813c2013-03-20 16:58:12 -070078RotMem::Mem::Mem() : mCurrOffset(0) {
79 utils::memset0(mRotOffset);
80 for(int i = 0; i < ROT_NUM_BUFS; i++) {
81 mRelFence[i] = -1;
82 }
83}
84
85RotMem::Mem::~Mem() {
86 for(int i = 0; i < ROT_NUM_BUFS; i++) {
87 ::close(mRelFence[i]);
88 mRelFence[i] = -1;
89 }
90}
91
92void RotMem::Mem::setReleaseFd(const int& fence) {
93 int ret = 0;
94
95 if(mRelFence[mCurrOffset] >= 0) {
96 //Wait for previous usage of this buffer to be over.
97 //Can happen if rotation takes > vsync and a fast producer. i.e queue
98 //happens in subsequent vsyncs either because content is 60fps or
99 //because the producer is hasty sometimes.
100 ret = sync_wait(mRelFence[mCurrOffset], 1000);
101 if(ret < 0) {
102 ALOGE("%s: sync_wait error!! error no = %d err str = %s",
103 __FUNCTION__, errno, strerror(errno));
104 }
105 ::close(mRelFence[mCurrOffset]);
106 }
107 mRelFence[mCurrOffset] = fence;
108}
109
110//============RotMgr=========================
Saurabh Shah7a606842013-12-11 14:36:04 -0800111RotMgr * RotMgr::sRotMgr = NULL;
112
113RotMgr* RotMgr::getInstance() {
114 if(sRotMgr == NULL) {
115 sRotMgr = new RotMgr();
116 }
117 return sRotMgr;
118}
Saurabh Shah23a813c2013-03-20 16:58:12 -0700119
Saurabh Shahacf10202013-02-26 10:15:15 -0800120RotMgr::RotMgr() {
121 for(int i = 0; i < MAX_ROT_SESS; i++) {
122 mRot[i] = 0;
123 }
124 mUseCount = 0;
Saurabh Shah23a813c2013-03-20 16:58:12 -0700125 mRotDevFd = -1;
Saurabh Shahacf10202013-02-26 10:15:15 -0800126}
127
128RotMgr::~RotMgr() {
129 clear();
130}
131
132void RotMgr::configBegin() {
133 //Reset the number of objects used
134 mUseCount = 0;
135}
136
137void RotMgr::configDone() {
138 //Remove the top most unused objects. Videos come and go.
139 for(int i = mUseCount; i < MAX_ROT_SESS; i++) {
140 if(mRot[i]) {
141 delete mRot[i];
142 mRot[i] = 0;
143 }
144 }
145}
146
147Rotator* RotMgr::getNext() {
148 //Return a rot object, creating one if necessary
149 overlay::Rotator *rot = NULL;
150 if(mUseCount >= MAX_ROT_SESS) {
151 ALOGE("%s, MAX rotator sessions reached", __func__);
152 } else {
153 if(mRot[mUseCount] == NULL)
154 mRot[mUseCount] = overlay::Rotator::getRotator();
155 rot = mRot[mUseCount++];
156 }
157 return rot;
158}
159
160void RotMgr::clear() {
161 //Brute force obj destruction, helpful in suspend.
162 for(int i = 0; i < MAX_ROT_SESS; i++) {
163 if(mRot[i]) {
164 delete mRot[i];
165 mRot[i] = 0;
166 }
167 }
168 mUseCount = 0;
Saurabh Shah23a813c2013-03-20 16:58:12 -0700169 ::close(mRotDevFd);
170 mRotDevFd = -1;
Saurabh Shahacf10202013-02-26 10:15:15 -0800171}
172
173void RotMgr::getDump(char *buf, size_t len) {
174 for(int i = 0; i < MAX_ROT_SESS; i++) {
175 if(mRot[i]) {
176 mRot[i]->getDump(buf, len);
177 }
178 }
Saurabh Shah7ef9ec92013-10-29 10:32:23 -0700179 char str[4] = {'\0'};
180 snprintf(str, 4, "\n");
Saurabh Shahacf10202013-02-26 10:15:15 -0800181 strncat(buf, str, strlen(str));
182}
183
Saurabh Shah23a813c2013-03-20 16:58:12 -0700184int RotMgr::getRotDevFd() {
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -0700185 if(mRotDevFd < 0 && Rotator::getRotatorHwType() == Rotator::TYPE_MDSS) {
186 mRotDevFd = ::open("/dev/graphics/fb0", O_RDWR, 0);
Saurabh Shah23a813c2013-03-20 16:58:12 -0700187 if(mRotDevFd < 0) {
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -0700188 ALOGE("%s failed to open fb0", __FUNCTION__);
Saurabh Shah23a813c2013-03-20 16:58:12 -0700189 }
190 }
191 return mRotDevFd;
192}
193
Naseer Ahmed29a26812012-06-14 00:56:20 -0700194}