blob: 0671b622a97e3038509e9ff1d7dd6ec09cb38d7d [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;
Saurabh Shah912c9482014-02-07 14:01:04 -080066 if(valid()) {
67 if(mem.close() == false) {
68 ALOGE("%s error in closing rot mem", __FUNCTION__);
69 ret = false;
Naseer Ahmedf48aef62012-07-20 09:05:53 -070070 }
Naseer Ahmed29a26812012-06-14 00:56:20 -070071 }
Naseer Ahmedf48aef62012-07-20 09:05:53 -070072 return ret;
Naseer Ahmed29a26812012-06-14 00:56:20 -070073}
74
Saurabh Shah912c9482014-02-07 14:01:04 -080075RotMem::RotMem() : mCurrIndex(0) {
Saurabh Shah23a813c2013-03-20 16:58:12 -070076 utils::memset0(mRotOffset);
77 for(int i = 0; i < ROT_NUM_BUFS; i++) {
78 mRelFence[i] = -1;
79 }
80}
81
Saurabh Shah912c9482014-02-07 14:01:04 -080082RotMem::~RotMem() {
Saurabh Shah23a813c2013-03-20 16:58:12 -070083 for(int i = 0; i < ROT_NUM_BUFS; i++) {
84 ::close(mRelFence[i]);
85 mRelFence[i] = -1;
86 }
87}
88
Saurabh Shah912c9482014-02-07 14:01:04 -080089void RotMem::setReleaseFd(const int& fence) {
Saurabh Shah23a813c2013-03-20 16:58:12 -070090 int ret = 0;
91
Saurabh Shah912c9482014-02-07 14:01:04 -080092 if(mRelFence[mCurrIndex] >= 0) {
Saurabh Shah23a813c2013-03-20 16:58:12 -070093 //Wait for previous usage of this buffer to be over.
94 //Can happen if rotation takes > vsync and a fast producer. i.e queue
95 //happens in subsequent vsyncs either because content is 60fps or
96 //because the producer is hasty sometimes.
Saurabh Shah912c9482014-02-07 14:01:04 -080097 ret = sync_wait(mRelFence[mCurrIndex], 1000);
Saurabh Shah23a813c2013-03-20 16:58:12 -070098 if(ret < 0) {
99 ALOGE("%s: sync_wait error!! error no = %d err str = %s",
100 __FUNCTION__, errno, strerror(errno));
101 }
Saurabh Shah912c9482014-02-07 14:01:04 -0800102 ::close(mRelFence[mCurrIndex]);
Saurabh Shah23a813c2013-03-20 16:58:12 -0700103 }
Saurabh Shah912c9482014-02-07 14:01:04 -0800104 mRelFence[mCurrIndex] = fence;
Saurabh Shah23a813c2013-03-20 16:58:12 -0700105}
106
107//============RotMgr=========================
Saurabh Shah7a606842013-12-11 14:36:04 -0800108RotMgr * RotMgr::sRotMgr = NULL;
109
110RotMgr* RotMgr::getInstance() {
111 if(sRotMgr == NULL) {
112 sRotMgr = new RotMgr();
113 }
114 return sRotMgr;
115}
Saurabh Shah23a813c2013-03-20 16:58:12 -0700116
Saurabh Shahacf10202013-02-26 10:15:15 -0800117RotMgr::RotMgr() {
118 for(int i = 0; i < MAX_ROT_SESS; i++) {
119 mRot[i] = 0;
120 }
121 mUseCount = 0;
Saurabh Shah23a813c2013-03-20 16:58:12 -0700122 mRotDevFd = -1;
Saurabh Shahacf10202013-02-26 10:15:15 -0800123}
124
125RotMgr::~RotMgr() {
126 clear();
127}
128
129void RotMgr::configBegin() {
130 //Reset the number of objects used
131 mUseCount = 0;
132}
133
134void RotMgr::configDone() {
135 //Remove the top most unused objects. Videos come and go.
136 for(int i = mUseCount; i < MAX_ROT_SESS; i++) {
137 if(mRot[i]) {
138 delete mRot[i];
139 mRot[i] = 0;
140 }
141 }
142}
143
144Rotator* RotMgr::getNext() {
145 //Return a rot object, creating one if necessary
146 overlay::Rotator *rot = NULL;
147 if(mUseCount >= MAX_ROT_SESS) {
Saurabh Shah54318572014-05-30 16:42:33 -0700148 ALOGW("%s, MAX rotator sessions reached, request rejected", __func__);
Saurabh Shahacf10202013-02-26 10:15:15 -0800149 } else {
150 if(mRot[mUseCount] == NULL)
151 mRot[mUseCount] = overlay::Rotator::getRotator();
152 rot = mRot[mUseCount++];
153 }
154 return rot;
155}
156
157void RotMgr::clear() {
158 //Brute force obj destruction, helpful in suspend.
159 for(int i = 0; i < MAX_ROT_SESS; i++) {
160 if(mRot[i]) {
161 delete mRot[i];
162 mRot[i] = 0;
163 }
164 }
165 mUseCount = 0;
Saurabh Shah23a813c2013-03-20 16:58:12 -0700166 ::close(mRotDevFd);
167 mRotDevFd = -1;
Saurabh Shahacf10202013-02-26 10:15:15 -0800168}
169
170void RotMgr::getDump(char *buf, size_t len) {
171 for(int i = 0; i < MAX_ROT_SESS; i++) {
172 if(mRot[i]) {
173 mRot[i]->getDump(buf, len);
174 }
175 }
Saurabh Shah7ef9ec92013-10-29 10:32:23 -0700176 char str[4] = {'\0'};
177 snprintf(str, 4, "\n");
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800178 strlcat(buf, str, len);
Saurabh Shahacf10202013-02-26 10:15:15 -0800179}
180
Saurabh Shah23a813c2013-03-20 16:58:12 -0700181int RotMgr::getRotDevFd() {
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -0700182 if(mRotDevFd < 0 && Rotator::getRotatorHwType() == Rotator::TYPE_MDSS) {
183 mRotDevFd = ::open("/dev/graphics/fb0", O_RDWR, 0);
Saurabh Shah23a813c2013-03-20 16:58:12 -0700184 if(mRotDevFd < 0) {
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -0700185 ALOGE("%s failed to open fb0", __FUNCTION__);
Saurabh Shah23a813c2013-03-20 16:58:12 -0700186 }
187 }
188 return mRotDevFd;
189}
190
Naseer Ahmed29a26812012-06-14 00:56:20 -0700191}