blob: 46d7ce192e0a14256ae981c475711aadb24e795e [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 Shahfc3652f2013-02-15 13:15:45 -080046uint32_t Rotator::calcOutputBufSize(const utils::Whf& destWhf) {
47 //dummy aligned w & h.
48 int alW = 0, alH = 0;
49 int halFormat = ovutils::getHALFormat(destWhf.format);
50 //A call into gralloc/memalloc
51 return getBufferSizeAndDimensions(
52 destWhf.w, destWhf.h, halFormat, alW, alH);
53}
54
Naseer Ahmed758bfc52012-11-28 17:02:08 -050055int Rotator::getRotatorHwType() {
Saurabh Shahe012f7a2012-08-18 15:11:57 -070056 int mdpVersion = qdutils::MDPVersion::getInstance().getMDPVersion();
57 if (mdpVersion == qdutils::MDSS_V5)
58 return TYPE_MDSS;
Naseer Ahmedf48aef62012-07-20 09:05:53 -070059 return TYPE_MDP;
Naseer Ahmed29a26812012-06-14 00:56:20 -070060}
61
Saurabh Shah23a813c2013-03-20 16:58:12 -070062
63//============RotMem=========================
64
Naseer Ahmedf48aef62012-07-20 09:05:53 -070065bool RotMem::close() {
66 bool ret = true;
Saurabh Shah912c9482014-02-07 14:01:04 -080067 if(valid()) {
68 if(mem.close() == false) {
69 ALOGE("%s error in closing rot mem", __FUNCTION__);
70 ret = false;
Naseer Ahmedf48aef62012-07-20 09:05:53 -070071 }
Naseer Ahmed29a26812012-06-14 00:56:20 -070072 }
Naseer Ahmedf48aef62012-07-20 09:05:53 -070073 return ret;
Naseer Ahmed29a26812012-06-14 00:56:20 -070074}
75
Saurabh Shah912c9482014-02-07 14:01:04 -080076RotMem::RotMem() : mCurrIndex(0) {
Saurabh Shah23a813c2013-03-20 16:58:12 -070077 utils::memset0(mRotOffset);
78 for(int i = 0; i < ROT_NUM_BUFS; i++) {
79 mRelFence[i] = -1;
80 }
81}
82
Saurabh Shah912c9482014-02-07 14:01:04 -080083RotMem::~RotMem() {
Saurabh Shah23a813c2013-03-20 16:58:12 -070084 for(int i = 0; i < ROT_NUM_BUFS; i++) {
85 ::close(mRelFence[i]);
86 mRelFence[i] = -1;
87 }
88}
89
Saurabh Shah912c9482014-02-07 14:01:04 -080090void RotMem::setReleaseFd(const int& fence) {
Saurabh Shah23a813c2013-03-20 16:58:12 -070091 int ret = 0;
92
Saurabh Shah912c9482014-02-07 14:01:04 -080093 if(mRelFence[mCurrIndex] >= 0) {
Saurabh Shah23a813c2013-03-20 16:58:12 -070094 //Wait for previous usage of this buffer to be over.
95 //Can happen if rotation takes > vsync and a fast producer. i.e queue
96 //happens in subsequent vsyncs either because content is 60fps or
97 //because the producer is hasty sometimes.
Saurabh Shah912c9482014-02-07 14:01:04 -080098 ret = sync_wait(mRelFence[mCurrIndex], 1000);
Saurabh Shah23a813c2013-03-20 16:58:12 -070099 if(ret < 0) {
100 ALOGE("%s: sync_wait error!! error no = %d err str = %s",
101 __FUNCTION__, errno, strerror(errno));
102 }
Saurabh Shah912c9482014-02-07 14:01:04 -0800103 ::close(mRelFence[mCurrIndex]);
Saurabh Shah23a813c2013-03-20 16:58:12 -0700104 }
Saurabh Shah912c9482014-02-07 14:01:04 -0800105 mRelFence[mCurrIndex] = fence;
Saurabh Shah23a813c2013-03-20 16:58:12 -0700106}
107
108//============RotMgr=========================
Saurabh Shah7a606842013-12-11 14:36:04 -0800109RotMgr * RotMgr::sRotMgr = NULL;
110
111RotMgr* RotMgr::getInstance() {
112 if(sRotMgr == NULL) {
113 sRotMgr = new RotMgr();
114 }
115 return sRotMgr;
116}
Saurabh Shah23a813c2013-03-20 16:58:12 -0700117
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) {
Saurabh Shah54318572014-05-30 16:42:33 -0700149 ALOGW("%s, MAX rotator sessions reached, request rejected", __func__);
Saurabh Shahacf10202013-02-26 10:15:15 -0800150 } 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");
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800179 strlcat(buf, str, len);
Saurabh Shahacf10202013-02-26 10:15:15 -0800180}
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}