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" |
Saurabh Shah | fc3652f | 2013-02-15 13:15:45 -0800 | [diff] [blame] | 23 | #include "gr.h" |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 24 | |
| 25 | namespace ovutils = overlay::utils; |
| 26 | |
| 27 | namespace overlay { |
| 28 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 29 | Rotator::~Rotator() {} |
| 30 | |
| 31 | Rotator* Rotator::getRotator() { |
| 32 | int type = getRotatorHwType(); |
| 33 | if(type == TYPE_MDP) { |
| 34 | return new MdpRot(); //will do reset |
| 35 | } else if(type == TYPE_MDSS) { |
| 36 | return new MdssRot(); |
| 37 | } else { |
| 38 | ALOGE("%s Unknown h/w type %d", __FUNCTION__, type); |
| 39 | return NULL; |
| 40 | } |
| 41 | } |
| 42 | |
Saurabh Shah | fc3652f | 2013-02-15 13:15:45 -0800 | [diff] [blame] | 43 | uint32_t Rotator::calcOutputBufSize(const utils::Whf& destWhf) { |
| 44 | //dummy aligned w & h. |
| 45 | int alW = 0, alH = 0; |
| 46 | int halFormat = ovutils::getHALFormat(destWhf.format); |
| 47 | //A call into gralloc/memalloc |
| 48 | return getBufferSizeAndDimensions( |
| 49 | destWhf.w, destWhf.h, halFormat, alW, alH); |
| 50 | } |
| 51 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 52 | int Rotator::getRotatorHwType() { |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 53 | int mdpVersion = qdutils::MDPVersion::getInstance().getMDPVersion(); |
| 54 | if (mdpVersion == qdutils::MDSS_V5) |
| 55 | return TYPE_MDSS; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 56 | return TYPE_MDP; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 57 | } |
| 58 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 59 | bool RotMem::close() { |
| 60 | bool ret = true; |
| 61 | for(uint32_t i=0; i < RotMem::MAX_ROT_MEM; ++i) { |
| 62 | // skip current, and if valid, close |
| 63 | if(m[i].valid()) { |
| 64 | if(m[i].close() == false) { |
| 65 | ALOGE("%s error in closing rot mem %d", __FUNCTION__, i); |
| 66 | ret = false; |
| 67 | } |
| 68 | } |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 69 | } |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 70 | return ret; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 71 | } |
| 72 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 73 | RotMgr::RotMgr() { |
| 74 | for(int i = 0; i < MAX_ROT_SESS; i++) { |
| 75 | mRot[i] = 0; |
| 76 | } |
| 77 | mUseCount = 0; |
| 78 | } |
| 79 | |
| 80 | RotMgr::~RotMgr() { |
| 81 | clear(); |
| 82 | } |
| 83 | |
| 84 | void RotMgr::configBegin() { |
| 85 | //Reset the number of objects used |
| 86 | mUseCount = 0; |
| 87 | } |
| 88 | |
| 89 | void RotMgr::configDone() { |
| 90 | //Remove the top most unused objects. Videos come and go. |
| 91 | for(int i = mUseCount; i < MAX_ROT_SESS; i++) { |
| 92 | if(mRot[i]) { |
| 93 | delete mRot[i]; |
| 94 | mRot[i] = 0; |
| 95 | } |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | Rotator* RotMgr::getNext() { |
| 100 | //Return a rot object, creating one if necessary |
| 101 | overlay::Rotator *rot = NULL; |
| 102 | if(mUseCount >= MAX_ROT_SESS) { |
| 103 | ALOGE("%s, MAX rotator sessions reached", __func__); |
| 104 | } else { |
| 105 | if(mRot[mUseCount] == NULL) |
| 106 | mRot[mUseCount] = overlay::Rotator::getRotator(); |
| 107 | rot = mRot[mUseCount++]; |
| 108 | } |
| 109 | return rot; |
| 110 | } |
| 111 | |
| 112 | void RotMgr::clear() { |
| 113 | //Brute force obj destruction, helpful in suspend. |
| 114 | for(int i = 0; i < MAX_ROT_SESS; i++) { |
| 115 | if(mRot[i]) { |
| 116 | delete mRot[i]; |
| 117 | mRot[i] = 0; |
| 118 | } |
| 119 | } |
| 120 | mUseCount = 0; |
| 121 | } |
| 122 | |
| 123 | void RotMgr::getDump(char *buf, size_t len) { |
| 124 | for(int i = 0; i < MAX_ROT_SESS; i++) { |
| 125 | if(mRot[i]) { |
| 126 | mRot[i]->getDump(buf, len); |
| 127 | } |
| 128 | } |
| 129 | char str[32] = {'\0'}; |
| 130 | snprintf(str, 32, "\n================\n"); |
| 131 | strncat(buf, str, strlen(str)); |
| 132 | } |
| 133 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 134 | } |