1 /*
2 * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
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"
31 #include "overlay.h"
32 #include "mdp_version.h"
33
34 namespace overlay {
35
GenericPipe(int dpy)36 GenericPipe::GenericPipe(int dpy) : mDpy(dpy), mRotDownscaleOpt(false),
37 pipeState(CLOSED) {
38 init();
39 }
40
~GenericPipe()41 GenericPipe::~GenericPipe() {
42 close();
43 }
44
init()45 bool GenericPipe::init()
46 {
47 ALOGE_IF(DEBUG_OVERLAY, "GenericPipe init");
48 mRotDownscaleOpt = false;
49
50 int fbNum = Overlay::getFbForDpy(mDpy);
51 if(fbNum < 0) {
52 ALOGE("%s: Invalid FB for the display: %d",__FUNCTION__, mDpy);
53 return false;
54 }
55
56 ALOGD_IF(DEBUG_OVERLAY,"%s: mFbNum:%d",__FUNCTION__, fbNum);
57
58 if(!mCtrlData.ctrl.init(fbNum)) {
59 ALOGE("GenericPipe failed to init ctrl");
60 return false;
61 }
62
63 if(!mCtrlData.data.init(fbNum)) {
64 ALOGE("GenericPipe failed to init data");
65 return false;
66 }
67
68 return true;
69 }
70
close()71 bool GenericPipe::close() {
72 bool ret = true;
73
74 if(!mCtrlData.ctrl.close()) {
75 ALOGE("GenericPipe failed to close ctrl");
76 ret = false;
77 }
78 if (!mCtrlData.data.close()) {
79 ALOGE("GenericPipe failed to close data");
80 ret = false;
81 }
82
83 setClosed();
84 return ret;
85 }
86
setSource(const utils::PipeArgs & args)87 void GenericPipe::setSource(const utils::PipeArgs& args) {
88 mRotDownscaleOpt = args.rotFlags & utils::ROT_DOWNSCALE_ENABLED;
89 mCtrlData.ctrl.setSource(args);
90 }
91
setCrop(const overlay::utils::Dim & d)92 void GenericPipe::setCrop(const overlay::utils::Dim& d) {
93 mCtrlData.ctrl.setCrop(d);
94 }
95
setTransform(const utils::eTransform & orient)96 void GenericPipe::setTransform(const utils::eTransform& orient) {
97 mCtrlData.ctrl.setTransform(orient);
98 }
99
setPosition(const utils::Dim & d)100 void GenericPipe::setPosition(const utils::Dim& d) {
101 mCtrlData.ctrl.setPosition(d);
102 }
103
setVisualParams(const MetaData_t & metadata)104 bool GenericPipe::setVisualParams(const MetaData_t &metadata)
105 {
106 return mCtrlData.ctrl.setVisualParams(metadata);
107 }
108
commit()109 bool GenericPipe::commit() {
110 bool ret = false;
111 int downscale_factor = utils::ROT_DS_NONE;
112
113 if(mRotDownscaleOpt) {
114 ovutils::Dim src(mCtrlData.ctrl.getCrop());
115 ovutils::Dim dst(mCtrlData.ctrl.getPosition());
116 downscale_factor = ovutils::getDownscaleFactor(
117 src.w, src.h, dst.w, dst.h);
118 }
119
120 mCtrlData.ctrl.setDownscale(downscale_factor);
121 ret = mCtrlData.ctrl.commit();
122
123 pipeState = ret ? OPEN : CLOSED;
124 return ret;
125 }
126
queueBuffer(int fd,uint32_t offset)127 bool GenericPipe::queueBuffer(int fd, uint32_t offset) {
128 //TODO Move pipe-id transfer to CtrlData class. Make ctrl and data private.
129 OVASSERT(isOpen(), "State is closed, cannot queueBuffer");
130 int pipeId = mCtrlData.ctrl.getPipeId();
131 OVASSERT(-1 != pipeId, "Ctrl ID should not be -1");
132 // set pipe id from ctrl to data
133 mCtrlData.data.setPipeId(pipeId);
134
135 return mCtrlData.data.queueBuffer(fd, offset);
136 }
137
getCtrlFd() const138 int GenericPipe::getCtrlFd() const {
139 return mCtrlData.ctrl.getFd();
140 }
141
getCrop() const142 utils::Dim GenericPipe::getCrop() const
143 {
144 return mCtrlData.ctrl.getCrop();
145 }
146
dump() const147 void GenericPipe::dump() const
148 {
149 ALOGE("== Dump Generic pipe start ==");
150 ALOGE("pipe state = %d", (int)pipeState);
151 mCtrlData.ctrl.dump();
152 mCtrlData.data.dump();
153
154 ALOGE("== Dump Generic pipe end ==");
155 }
156
getDump(char * buf,size_t len)157 void GenericPipe::getDump(char *buf, size_t len) {
158 mCtrlData.ctrl.getDump(buf, len);
159 mCtrlData.data.getDump(buf, len);
160 }
161
isClosed() const162 bool GenericPipe::isClosed() const {
163 return (pipeState == CLOSED);
164 }
165
isOpen() const166 bool GenericPipe::isOpen() const {
167 return (pipeState == OPEN);
168 }
169
setClosed()170 bool GenericPipe::setClosed() {
171 pipeState = CLOSED;
172 return true;
173 }
174
forceSet()175 void GenericPipe::forceSet() {
176 mCtrlData.ctrl.forceSet();
177 }
178
179 } //namespace overlay
180