blob: 9108acdd18e10ef3c7ce363f4430d444d5a03150 [file] [log] [blame]
Naseer Ahmed758bfc52012-11-28 17:02:08 -05001/*
Raj kamal23f69b22012-11-17 00:20:55 +05302* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
Naseer Ahmed758bfc52012-11-28 17:02:08 -05003*
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 Kumar5182a782012-12-03 12:08:48 -080031#include "overlay.h"
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -080032#include "mdp_version.h"
Naseer Ahmed758bfc52012-11-28 17:02:08 -050033
34namespace overlay {
35
36GenericPipe::GenericPipe(int dpy) : mFbNum(dpy), mRot(0), mRotUsed(false),
Saurabh Shahacf10202013-02-26 10:15:15 -080037 mRotDownscaleOpt(false), mPreRotated(false), pipeState(CLOSED) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050038 init();
39}
40
41GenericPipe::~GenericPipe() {
42 close();
43}
44
45bool GenericPipe::init()
46{
47 ALOGE_IF(DEBUG_OVERLAY, "GenericPipe init");
48 mRotUsed = false;
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -080049 mRotDownscaleOpt = false;
Saurabh Shahacf10202013-02-26 10:15:15 -080050 mPreRotated = false;
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -080051 if(mFbNum)
52 mFbNum = Overlay::getInstance()->getExtFbNum();
53
54 ALOGD_IF(DEBUG_OVERLAY,"%s: mFbNum:%d",__FUNCTION__, mFbNum);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050055
56 if(!mCtrlData.ctrl.init(mFbNum)) {
57 ALOGE("GenericPipe failed to init ctrl");
58 return false;
59 }
60
61 if(!mCtrlData.data.init(mFbNum)) {
62 ALOGE("GenericPipe failed to init data");
63 return false;
64 }
65
66 //get a new rotator object, take ownership
67 mRot = Rotator::getRotator();
68
69 return true;
70}
71
72bool GenericPipe::close() {
73 bool ret = true;
74
75 if(!mCtrlData.ctrl.close()) {
76 ALOGE("GenericPipe failed to close ctrl");
77 ret = false;
78 }
79 if (!mCtrlData.data.close()) {
80 ALOGE("GenericPipe failed to close data");
81 ret = false;
82 }
83
84 delete mRot;
85 mRot = 0;
86
87 setClosed();
88 return ret;
89}
90
Saurabh Shahacf10202013-02-26 10:15:15 -080091void GenericPipe::setSource(const utils::PipeArgs& args) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050092 //Cache if user wants 0-rotation
Saurabh Shahacf10202013-02-26 10:15:15 -080093 mRotUsed = args.rotFlags & utils::ROT_0_ENABLED;
94 mRotDownscaleOpt = args.rotFlags & utils::ROT_DOWNSCALE_ENABLED;
95 mPreRotated = args.rotFlags & utils::ROT_PREROTATED;
96 if(mPreRotated) mRotUsed = false;
97 mRot->setSource(args.whf);
98 mRot->setFlags(args.mdpFlags);
99 mCtrlData.ctrl.setSource(args);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500100}
101
Saurabh Shahacf10202013-02-26 10:15:15 -0800102void GenericPipe::setCrop(const overlay::utils::Dim& d) {
103 mCtrlData.ctrl.setCrop(d);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500104}
105
Saurabh Shahacf10202013-02-26 10:15:15 -0800106void GenericPipe::setTransform(const utils::eTransform& orient) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500107 //Rotation could be enabled by user for zero-rot or the layer could have
108 //some transform. Mark rotation enabled in either case.
Saurabh Shahacf10202013-02-26 10:15:15 -0800109 mRotUsed |= ((orient & utils::OVERLAY_TRANSFORM_ROT_90) && !mPreRotated);
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800110 mRot->setTransform(orient);
Saurabh Shahacf10202013-02-26 10:15:15 -0800111 mCtrlData.ctrl.setTransform(orient);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500112}
113
Saurabh Shahacf10202013-02-26 10:15:15 -0800114void GenericPipe::setPosition(const utils::Dim& d) {
115 mCtrlData.ctrl.setPosition(d);
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800116}
117
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500118bool GenericPipe::commit() {
119 bool ret = false;
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800120 int downscale_factor = utils::ROT_DS_NONE;
121
122 if(mRotDownscaleOpt) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800123 ovutils::Dim src(mCtrlData.ctrl.getCrop());
124 ovutils::Dim dst(mCtrlData.ctrl.getPosition());
125 downscale_factor = ovutils::getDownscaleFactor(
126 src.w, src.h, dst.w, dst.h);
127 mRotUsed |= (downscale_factor && !mPreRotated);
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800128 }
129
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800130
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500131 if(mRotUsed) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800132 mRot->setDownscale(downscale_factor);
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800133 //If wanting to use rotator, start it.
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500134 if(!mRot->commit()) {
135 ALOGE("GenPipe Rotator commit failed");
136 //If rot commit fails, flush rotator session, memory, fd and create
137 //a hollow rotator object
138 delete mRot;
139 mRot = Rotator::getRotator();
140 pipeState = CLOSED;
141 return false;
142 }
Raj kamal23f69b22012-11-17 00:20:55 +0530143 /* Set the mdp src format to the output format of the rotator.
144 * The output format of the rotator might be different depending on
145 * whether fastyuv mode is enabled in the rotator.
146 */
Saurabh Shahacf10202013-02-26 10:15:15 -0800147 mCtrlData.ctrl.updateSrcFormat(mRot->getDstFormat());
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500148 }
149
Saurabh Shahacf10202013-02-26 10:15:15 -0800150 mCtrlData.ctrl.setDownscale(downscale_factor);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500151 ret = mCtrlData.ctrl.commit();
152
153 //If mdp commit fails, flush rotator session, memory, fd and create a hollow
154 //rotator object
155 if(ret == false) {
156 delete mRot;
157 mRot = Rotator::getRotator();
158 }
159
160 pipeState = ret ? OPEN : CLOSED;
161 return ret;
162}
163
164bool GenericPipe::queueBuffer(int fd, uint32_t offset) {
165 //TODO Move pipe-id transfer to CtrlData class. Make ctrl and data private.
166 OVASSERT(isOpen(), "State is closed, cannot queueBuffer");
167 int pipeId = mCtrlData.ctrl.getPipeId();
168 OVASSERT(-1 != pipeId, "Ctrl ID should not be -1");
169 // set pipe id from ctrl to data
170 mCtrlData.data.setPipeId(pipeId);
171
172 int finalFd = fd;
173 uint32_t finalOffset = offset;
174 //If rotator is to be used, queue to it, so it can ROTATE.
175 if(mRotUsed) {
176 if(!mRot->queueBuffer(fd, offset)) {
177 ALOGE("GenPipe Rotator play failed");
178 return false;
179 }
180 //Configure MDP's source buffer as the current output buffer of rotator
181 if(mRot->getDstMemId() != -1) {
182 finalFd = mRot->getDstMemId();
183 finalOffset = mRot->getDstOffset();
184 } else {
185 //Could be -1 for NullRotator, if queue above succeeds.
186 //Need an actual rotator. Modify overlay State Traits.
187 //Not fatal, keep queuing to MDP without rotation.
188 ALOGE("Null rotator in use, where an actual is required");
189 }
190 }
191 return mCtrlData.data.queueBuffer(finalFd, finalOffset);
192}
193
194int GenericPipe::getCtrlFd() const {
195 return mCtrlData.ctrl.getFd();
196}
197
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500198utils::Dim GenericPipe::getCrop() const
199{
200 return mCtrlData.ctrl.getCrop();
201}
202
203void GenericPipe::dump() const
204{
205 ALOGE("== Dump Generic pipe start ==");
206 ALOGE("pipe state = %d", (int)pipeState);
207 OVASSERT(mRot, "GenericPipe should have a valid Rot");
208 mCtrlData.ctrl.dump();
209 mCtrlData.data.dump();
210 mRot->dump();
211 ALOGE("== Dump Generic pipe end ==");
212}
213
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800214void GenericPipe::getDump(char *buf, size_t len) {
215 mCtrlData.ctrl.getDump(buf, len);
216 mCtrlData.data.getDump(buf, len);
217 if(mRotUsed && mRot)
218 mRot->getDump(buf, len);
219}
220
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500221bool GenericPipe::isClosed() const {
222 return (pipeState == CLOSED);
223}
224
225bool GenericPipe::isOpen() const {
226 return (pipeState == OPEN);
227}
228
229bool GenericPipe::setClosed() {
230 pipeState = CLOSED;
231 return true;
232}
233
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800234
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500235} //namespace overlay