Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1 | /* |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 2 | * 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 Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | #include "overlayRotator.h" |
| 21 | #include "overlayUtils.h" |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 22 | #include "mdp_version.h" |
Raj Kamal | 389d6e3 | 2014-08-04 14:43:24 +0530 | [diff] [blame] | 23 | #include "sync/sync.h" |
Saurabh Shah | fc3652f | 2013-02-15 13:15:45 -0800 | [diff] [blame] | 24 | #include "gr.h" |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 25 | |
| 26 | namespace ovutils = overlay::utils; |
| 27 | |
| 28 | namespace overlay { |
| 29 | |
Saurabh Shah | 23a813c | 2013-03-20 16:58:12 -0700 | [diff] [blame] | 30 | //============Rotator========================= |
| 31 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 32 | Rotator::~Rotator() {} |
| 33 | |
| 34 | Rotator* 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 Shah | c46cf9d | 2014-07-02 15:22:34 -0700 | [diff] [blame] | 46 | int Rotator::getDownscaleFactor(const int& srcW, const int& srcH, |
| 47 | const int& dstW, const int& dstH, const uint32_t& mdpFormat, |
| 48 | const bool& isInterlaced) { |
| 49 | if(getRotatorHwType() == TYPE_MDSS) { |
| 50 | return MdssRot::getDownscaleFactor(srcW, srcH, dstW, dstH, |
| 51 | mdpFormat, isInterlaced); |
| 52 | } |
| 53 | return MdpRot::getDownscaleFactor(srcW, srcH, dstW, dstH, |
| 54 | mdpFormat, isInterlaced); |
| 55 | } |
| 56 | |
Saurabh Shah | fc3652f | 2013-02-15 13:15:45 -0800 | [diff] [blame] | 57 | uint32_t Rotator::calcOutputBufSize(const utils::Whf& destWhf) { |
| 58 | //dummy aligned w & h. |
| 59 | int alW = 0, alH = 0; |
| 60 | int halFormat = ovutils::getHALFormat(destWhf.format); |
| 61 | //A call into gralloc/memalloc |
| 62 | return getBufferSizeAndDimensions( |
| 63 | destWhf.w, destWhf.h, halFormat, alW, alH); |
| 64 | } |
| 65 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 66 | int Rotator::getRotatorHwType() { |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 67 | int mdpVersion = qdutils::MDPVersion::getInstance().getMDPVersion(); |
| 68 | if (mdpVersion == qdutils::MDSS_V5) |
| 69 | return TYPE_MDSS; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 70 | return TYPE_MDP; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 71 | } |
| 72 | |
Saurabh Shah | 23a813c | 2013-03-20 16:58:12 -0700 | [diff] [blame] | 73 | |
| 74 | //============RotMem========================= |
| 75 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 76 | bool RotMem::close() { |
| 77 | bool ret = true; |
Saurabh Shah | 912c948 | 2014-02-07 14:01:04 -0800 | [diff] [blame] | 78 | if(valid()) { |
| 79 | if(mem.close() == false) { |
| 80 | ALOGE("%s error in closing rot mem", __FUNCTION__); |
| 81 | ret = false; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 82 | } |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 83 | } |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 84 | return ret; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 85 | } |
| 86 | |
Saurabh Shah | 912c948 | 2014-02-07 14:01:04 -0800 | [diff] [blame] | 87 | RotMem::RotMem() : mCurrIndex(0) { |
Saurabh Shah | 23a813c | 2013-03-20 16:58:12 -0700 | [diff] [blame] | 88 | utils::memset0(mRotOffset); |
| 89 | for(int i = 0; i < ROT_NUM_BUFS; i++) { |
| 90 | mRelFence[i] = -1; |
| 91 | } |
| 92 | } |
| 93 | |
Saurabh Shah | 912c948 | 2014-02-07 14:01:04 -0800 | [diff] [blame] | 94 | RotMem::~RotMem() { |
Saurabh Shah | 23a813c | 2013-03-20 16:58:12 -0700 | [diff] [blame] | 95 | for(int i = 0; i < ROT_NUM_BUFS; i++) { |
| 96 | ::close(mRelFence[i]); |
| 97 | mRelFence[i] = -1; |
| 98 | } |
| 99 | } |
| 100 | |
Saurabh Shah | 912c948 | 2014-02-07 14:01:04 -0800 | [diff] [blame] | 101 | void RotMem::setReleaseFd(const int& fence) { |
Saurabh Shah | 23a813c | 2013-03-20 16:58:12 -0700 | [diff] [blame] | 102 | int ret = 0; |
| 103 | |
Saurabh Shah | 912c948 | 2014-02-07 14:01:04 -0800 | [diff] [blame] | 104 | if(mRelFence[mCurrIndex] >= 0) { |
Saurabh Shah | 23a813c | 2013-03-20 16:58:12 -0700 | [diff] [blame] | 105 | //Wait for previous usage of this buffer to be over. |
| 106 | //Can happen if rotation takes > vsync and a fast producer. i.e queue |
| 107 | //happens in subsequent vsyncs either because content is 60fps or |
| 108 | //because the producer is hasty sometimes. |
Saurabh Shah | 912c948 | 2014-02-07 14:01:04 -0800 | [diff] [blame] | 109 | ret = sync_wait(mRelFence[mCurrIndex], 1000); |
Saurabh Shah | 23a813c | 2013-03-20 16:58:12 -0700 | [diff] [blame] | 110 | if(ret < 0) { |
| 111 | ALOGE("%s: sync_wait error!! error no = %d err str = %s", |
| 112 | __FUNCTION__, errno, strerror(errno)); |
| 113 | } |
Saurabh Shah | 912c948 | 2014-02-07 14:01:04 -0800 | [diff] [blame] | 114 | ::close(mRelFence[mCurrIndex]); |
Saurabh Shah | 23a813c | 2013-03-20 16:58:12 -0700 | [diff] [blame] | 115 | } |
Saurabh Shah | 912c948 | 2014-02-07 14:01:04 -0800 | [diff] [blame] | 116 | mRelFence[mCurrIndex] = fence; |
Saurabh Shah | 23a813c | 2013-03-20 16:58:12 -0700 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | //============RotMgr========================= |
Saurabh Shah | 7a60684 | 2013-12-11 14:36:04 -0800 | [diff] [blame] | 120 | RotMgr * RotMgr::sRotMgr = NULL; |
| 121 | |
| 122 | RotMgr* RotMgr::getInstance() { |
| 123 | if(sRotMgr == NULL) { |
| 124 | sRotMgr = new RotMgr(); |
| 125 | } |
| 126 | return sRotMgr; |
| 127 | } |
Saurabh Shah | 23a813c | 2013-03-20 16:58:12 -0700 | [diff] [blame] | 128 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 129 | RotMgr::RotMgr() { |
| 130 | for(int i = 0; i < MAX_ROT_SESS; i++) { |
| 131 | mRot[i] = 0; |
| 132 | } |
| 133 | mUseCount = 0; |
Saurabh Shah | 23a813c | 2013-03-20 16:58:12 -0700 | [diff] [blame] | 134 | mRotDevFd = -1; |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | RotMgr::~RotMgr() { |
| 138 | clear(); |
| 139 | } |
| 140 | |
| 141 | void RotMgr::configBegin() { |
| 142 | //Reset the number of objects used |
| 143 | mUseCount = 0; |
| 144 | } |
| 145 | |
| 146 | void RotMgr::configDone() { |
| 147 | //Remove the top most unused objects. Videos come and go. |
| 148 | for(int i = mUseCount; i < MAX_ROT_SESS; i++) { |
| 149 | if(mRot[i]) { |
| 150 | delete mRot[i]; |
| 151 | mRot[i] = 0; |
| 152 | } |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | Rotator* RotMgr::getNext() { |
| 157 | //Return a rot object, creating one if necessary |
| 158 | overlay::Rotator *rot = NULL; |
| 159 | if(mUseCount >= MAX_ROT_SESS) { |
Saurabh Shah | 5431857 | 2014-05-30 16:42:33 -0700 | [diff] [blame] | 160 | ALOGW("%s, MAX rotator sessions reached, request rejected", __func__); |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 161 | } else { |
| 162 | if(mRot[mUseCount] == NULL) |
| 163 | mRot[mUseCount] = overlay::Rotator::getRotator(); |
| 164 | rot = mRot[mUseCount++]; |
| 165 | } |
| 166 | return rot; |
| 167 | } |
| 168 | |
| 169 | void RotMgr::clear() { |
| 170 | //Brute force obj destruction, helpful in suspend. |
| 171 | for(int i = 0; i < MAX_ROT_SESS; i++) { |
| 172 | if(mRot[i]) { |
| 173 | delete mRot[i]; |
| 174 | mRot[i] = 0; |
| 175 | } |
| 176 | } |
| 177 | mUseCount = 0; |
Saurabh Shah | 23a813c | 2013-03-20 16:58:12 -0700 | [diff] [blame] | 178 | ::close(mRotDevFd); |
| 179 | mRotDevFd = -1; |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | void RotMgr::getDump(char *buf, size_t len) { |
| 183 | for(int i = 0; i < MAX_ROT_SESS; i++) { |
| 184 | if(mRot[i]) { |
| 185 | mRot[i]->getDump(buf, len); |
| 186 | } |
| 187 | } |
Saurabh Shah | 7ef9ec9 | 2013-10-29 10:32:23 -0700 | [diff] [blame] | 188 | char str[4] = {'\0'}; |
| 189 | snprintf(str, 4, "\n"); |
Ramkumar Radhakrishnan | 36bd527 | 2014-01-31 20:03:01 -0800 | [diff] [blame] | 190 | strlcat(buf, str, len); |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 191 | } |
| 192 | |
Saurabh Shah | 23a813c | 2013-03-20 16:58:12 -0700 | [diff] [blame] | 193 | int RotMgr::getRotDevFd() { |
Saurabh Shah | e9b5a8f | 2013-06-28 11:33:25 -0700 | [diff] [blame] | 194 | if(mRotDevFd < 0 && Rotator::getRotatorHwType() == Rotator::TYPE_MDSS) { |
| 195 | mRotDevFd = ::open("/dev/graphics/fb0", O_RDWR, 0); |
Saurabh Shah | 23a813c | 2013-03-20 16:58:12 -0700 | [diff] [blame] | 196 | if(mRotDevFd < 0) { |
Saurabh Shah | e9b5a8f | 2013-06-28 11:33:25 -0700 | [diff] [blame] | 197 | ALOGE("%s failed to open fb0", __FUNCTION__); |
Saurabh Shah | 23a813c | 2013-03-20 16:58:12 -0700 | [diff] [blame] | 198 | } |
| 199 | } |
| 200 | return mRotDevFd; |
| 201 | } |
| 202 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 203 | } |