blob: 4b6a8bc1449ae5205303f382230640555cbd8448 [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
Saurabh Shahda5b3ce2013-11-26 10:48:06 -0800110void RotMem::Mem::resetReleaseFd() {
111 //Will wait for previous offline rotation to finish, close fence fd
112 //and reset
113 setReleaseFd(-1);
114}
115
Saurabh Shah23a813c2013-03-20 16:58:12 -0700116//============RotMgr=========================
117
Saurabh Shahacf10202013-02-26 10:15:15 -0800118RotMgr::RotMgr() {
119 for(int i = 0; i < MAX_ROT_SESS; i++) {
120 mRot[i] = 0;
121 }
122 mUseCount = 0;
Saurabh Shah23a813c2013-03-20 16:58:12 -0700123 mRotDevFd = -1;
Saurabh Shahacf10202013-02-26 10:15:15 -0800124}
125
126RotMgr::~RotMgr() {
127 clear();
128}
129
130void RotMgr::configBegin() {
131 //Reset the number of objects used
132 mUseCount = 0;
133}
134
135void RotMgr::configDone() {
136 //Remove the top most unused objects. Videos come and go.
137 for(int i = mUseCount; i < MAX_ROT_SESS; i++) {
138 if(mRot[i]) {
139 delete mRot[i];
140 mRot[i] = 0;
141 }
142 }
143}
144
145Rotator* RotMgr::getNext() {
146 //Return a rot object, creating one if necessary
147 overlay::Rotator *rot = NULL;
148 if(mUseCount >= MAX_ROT_SESS) {
149 ALOGE("%s, MAX rotator sessions reached", __func__);
150 } else {
151 if(mRot[mUseCount] == NULL)
152 mRot[mUseCount] = overlay::Rotator::getRotator();
153 rot = mRot[mUseCount++];
154 }
155 return rot;
156}
157
158void RotMgr::clear() {
159 //Brute force obj destruction, helpful in suspend.
160 for(int i = 0; i < MAX_ROT_SESS; i++) {
161 if(mRot[i]) {
162 delete mRot[i];
163 mRot[i] = 0;
164 }
165 }
166 mUseCount = 0;
Saurabh Shah23a813c2013-03-20 16:58:12 -0700167 ::close(mRotDevFd);
168 mRotDevFd = -1;
Saurabh Shahacf10202013-02-26 10:15:15 -0800169}
170
171void RotMgr::getDump(char *buf, size_t len) {
172 for(int i = 0; i < MAX_ROT_SESS; i++) {
173 if(mRot[i]) {
174 mRot[i]->getDump(buf, len);
175 }
176 }
Saurabh Shah7ef9ec92013-10-29 10:32:23 -0700177 char str[4] = {'\0'};
178 snprintf(str, 4, "\n");
Saurabh Shahacf10202013-02-26 10:15:15 -0800179 strncat(buf, str, strlen(str));
180}
181
Saurabh Shah23a813c2013-03-20 16:58:12 -0700182int RotMgr::getRotDevFd() {
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -0700183 if(mRotDevFd < 0 && Rotator::getRotatorHwType() == Rotator::TYPE_MDSS) {
184 mRotDevFd = ::open("/dev/graphics/fb0", O_RDWR, 0);
Saurabh Shah23a813c2013-03-20 16:58:12 -0700185 if(mRotDevFd < 0) {
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -0700186 ALOGE("%s failed to open fb0", __FUNCTION__);
Saurabh Shah23a813c2013-03-20 16:58:12 -0700187 }
188 }
189 return mRotDevFd;
190}
191
Naseer Ahmed29a26812012-06-14 00:56:20 -0700192}