Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 1 | /* |
Raj kamal | 23f69b2 | 2012-11-17 00:20:55 +0530 | [diff] [blame] | 2 | * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved. |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are |
| 6 | * met: |
| 7 | * * Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * * Redistributions in binary form must reproduce the above |
| 10 | * copyright notice, this list of conditions and the following |
| 11 | * disclaimer in the documentation and/or other materials provided |
| 12 | * with the distribution. |
| 13 | * * Neither the name of The Linux Foundation nor the names of its |
| 14 | * contributors may be used to endorse or promote products derived |
| 15 | * from this software without specific prior written permission. |
| 16 | * |
| 17 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 18 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 21 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 24 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 25 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 26 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 27 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | */ |
| 29 | |
| 30 | #include "overlayGenPipe.h" |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 31 | #include "overlay.h" |
Ramkumar Radhakrishnan | 288f8c7 | 2013-01-15 11:37:54 -0800 | [diff] [blame] | 32 | #include "mdp_version.h" |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 33 | |
| 34 | namespace overlay { |
| 35 | |
Xiaoming Zhou | 912842a | 2013-07-03 13:16:56 -0400 | [diff] [blame^] | 36 | GenericPipe::GenericPipe(int dpy) : mFbNum(dpy), mRotDownscaleOpt(false), |
| 37 | pipeState(CLOSED) { |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 38 | init(); |
| 39 | } |
| 40 | |
| 41 | GenericPipe::~GenericPipe() { |
| 42 | close(); |
| 43 | } |
| 44 | |
| 45 | bool GenericPipe::init() |
| 46 | { |
| 47 | ALOGE_IF(DEBUG_OVERLAY, "GenericPipe init"); |
Ramkumar Radhakrishnan | 288f8c7 | 2013-01-15 11:37:54 -0800 | [diff] [blame] | 48 | mRotDownscaleOpt = false; |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 49 | if(mFbNum) |
| 50 | mFbNum = Overlay::getInstance()->getExtFbNum(); |
| 51 | |
| 52 | ALOGD_IF(DEBUG_OVERLAY,"%s: mFbNum:%d",__FUNCTION__, mFbNum); |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 53 | |
| 54 | if(!mCtrlData.ctrl.init(mFbNum)) { |
| 55 | ALOGE("GenericPipe failed to init ctrl"); |
| 56 | return false; |
| 57 | } |
| 58 | |
| 59 | if(!mCtrlData.data.init(mFbNum)) { |
| 60 | ALOGE("GenericPipe failed to init data"); |
| 61 | return false; |
| 62 | } |
| 63 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 64 | return true; |
| 65 | } |
| 66 | |
| 67 | bool GenericPipe::close() { |
| 68 | bool ret = true; |
| 69 | |
| 70 | if(!mCtrlData.ctrl.close()) { |
| 71 | ALOGE("GenericPipe failed to close ctrl"); |
| 72 | ret = false; |
| 73 | } |
| 74 | if (!mCtrlData.data.close()) { |
| 75 | ALOGE("GenericPipe failed to close data"); |
| 76 | ret = false; |
| 77 | } |
| 78 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 79 | setClosed(); |
| 80 | return ret; |
| 81 | } |
| 82 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 83 | void GenericPipe::setSource(const utils::PipeArgs& args) { |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 84 | mRotDownscaleOpt = args.rotFlags & utils::ROT_DOWNSCALE_ENABLED; |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 85 | mCtrlData.ctrl.setSource(args); |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 86 | } |
| 87 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 88 | void GenericPipe::setCrop(const overlay::utils::Dim& d) { |
| 89 | mCtrlData.ctrl.setCrop(d); |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 90 | } |
| 91 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 92 | void GenericPipe::setTransform(const utils::eTransform& orient) { |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 93 | mCtrlData.ctrl.setTransform(orient); |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 94 | } |
| 95 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 96 | void GenericPipe::setPosition(const utils::Dim& d) { |
| 97 | mCtrlData.ctrl.setPosition(d); |
Ramkumar Radhakrishnan | 288f8c7 | 2013-01-15 11:37:54 -0800 | [diff] [blame] | 98 | } |
| 99 | |
Saurabh Shah | 5daeee5 | 2013-01-23 16:52:26 +0800 | [diff] [blame] | 100 | bool GenericPipe::setVisualParams(const MetaData_t &metadata) |
| 101 | { |
| 102 | return mCtrlData.ctrl.setVisualParams(metadata); |
| 103 | } |
| 104 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 105 | bool GenericPipe::commit() { |
| 106 | bool ret = false; |
Ramkumar Radhakrishnan | 288f8c7 | 2013-01-15 11:37:54 -0800 | [diff] [blame] | 107 | int downscale_factor = utils::ROT_DS_NONE; |
| 108 | |
| 109 | if(mRotDownscaleOpt) { |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 110 | ovutils::Dim src(mCtrlData.ctrl.getCrop()); |
| 111 | ovutils::Dim dst(mCtrlData.ctrl.getPosition()); |
| 112 | downscale_factor = ovutils::getDownscaleFactor( |
| 113 | src.w, src.h, dst.w, dst.h); |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 114 | } |
| 115 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 116 | mCtrlData.ctrl.setDownscale(downscale_factor); |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 117 | ret = mCtrlData.ctrl.commit(); |
| 118 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 119 | pipeState = ret ? OPEN : CLOSED; |
| 120 | return ret; |
| 121 | } |
| 122 | |
| 123 | bool GenericPipe::queueBuffer(int fd, uint32_t offset) { |
| 124 | //TODO Move pipe-id transfer to CtrlData class. Make ctrl and data private. |
| 125 | OVASSERT(isOpen(), "State is closed, cannot queueBuffer"); |
| 126 | int pipeId = mCtrlData.ctrl.getPipeId(); |
| 127 | OVASSERT(-1 != pipeId, "Ctrl ID should not be -1"); |
| 128 | // set pipe id from ctrl to data |
| 129 | mCtrlData.data.setPipeId(pipeId); |
| 130 | |
Xiaoming Zhou | 912842a | 2013-07-03 13:16:56 -0400 | [diff] [blame^] | 131 | return mCtrlData.data.queueBuffer(fd, offset); |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | int GenericPipe::getCtrlFd() const { |
| 135 | return mCtrlData.ctrl.getFd(); |
| 136 | } |
| 137 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 138 | utils::Dim GenericPipe::getCrop() const |
| 139 | { |
| 140 | return mCtrlData.ctrl.getCrop(); |
| 141 | } |
| 142 | |
| 143 | void GenericPipe::dump() const |
| 144 | { |
| 145 | ALOGE("== Dump Generic pipe start =="); |
| 146 | ALOGE("pipe state = %d", (int)pipeState); |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 147 | mCtrlData.ctrl.dump(); |
| 148 | mCtrlData.data.dump(); |
Xiaoming Zhou | 912842a | 2013-07-03 13:16:56 -0400 | [diff] [blame^] | 149 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 150 | ALOGE("== Dump Generic pipe end =="); |
| 151 | } |
| 152 | |
Saurabh Shah | 0d0a7cb | 2013-02-12 17:58:19 -0800 | [diff] [blame] | 153 | void GenericPipe::getDump(char *buf, size_t len) { |
| 154 | mCtrlData.ctrl.getDump(buf, len); |
| 155 | mCtrlData.data.getDump(buf, len); |
Saurabh Shah | 0d0a7cb | 2013-02-12 17:58:19 -0800 | [diff] [blame] | 156 | } |
| 157 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 158 | bool GenericPipe::isClosed() const { |
| 159 | return (pipeState == CLOSED); |
| 160 | } |
| 161 | |
| 162 | bool GenericPipe::isOpen() const { |
| 163 | return (pipeState == OPEN); |
| 164 | } |
| 165 | |
| 166 | bool GenericPipe::setClosed() { |
| 167 | pipeState = CLOSED; |
| 168 | return true; |
| 169 | } |
| 170 | |
Saurabh Shah | df0be75 | 2013-05-23 14:40:00 -0700 | [diff] [blame] | 171 | void GenericPipe::forceSet() { |
| 172 | mCtrlData.ctrl.forceSet(); |
| 173 | } |
Ramkumar Radhakrishnan | 288f8c7 | 2013-01-15 11:37:54 -0800 | [diff] [blame] | 174 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 175 | } //namespace overlay |