blob: aaaa0f1b71b1badb655fa9edc712225dcc040cac [file] [log] [blame]
Naseer Ahmed758bfc52012-11-28 17:02:08 -05001/*
2* Copyright (c) 2012, 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"
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),
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -080037 mRotDownscaleOpt(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;
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -080050 if(mFbNum)
51 mFbNum = Overlay::getInstance()->getExtFbNum();
52
53 ALOGD_IF(DEBUG_OVERLAY,"%s: mFbNum:%d",__FUNCTION__, mFbNum);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050054
55 if(!mCtrlData.ctrl.init(mFbNum)) {
56 ALOGE("GenericPipe failed to init ctrl");
57 return false;
58 }
59
60 if(!mCtrlData.data.init(mFbNum)) {
61 ALOGE("GenericPipe failed to init data");
62 return false;
63 }
64
65 //get a new rotator object, take ownership
66 mRot = Rotator::getRotator();
67
68 return true;
69}
70
71bool 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 delete mRot;
84 mRot = 0;
85
86 setClosed();
87 return ret;
88}
89
90bool GenericPipe::setSource(
91 const utils::PipeArgs& args)
92{
93 utils::PipeArgs newargs(args);
94 //Interlace video handling.
95 if(newargs.whf.format & INTERLACE_MASK) {
96 setMdpFlags(newargs.mdpFlags, utils::OV_MDP_DEINTERLACE);
97 }
98 utils::Whf whf(newargs.whf);
99 //Extract HAL format from lower bytes. Deinterlace if interlaced.
100 whf.format = utils::getColorFormat(whf.format);
101 //Get MDP equivalent of HAL format.
102 whf.format = utils::getMdpFormat(whf.format);
103 newargs.whf = whf;
104
105 //Cache if user wants 0-rotation
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800106 mRotUsed = newargs.rotFlags & utils::ROT_0_ENABLED;
107 mRotDownscaleOpt = newargs.rotFlags & utils::ROT_DOWNSCALE_ENABLED;
108
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500109 mRot->setSource(newargs.whf);
110 mRot->setFlags(newargs.mdpFlags);
111 return mCtrlData.ctrl.setSource(newargs);
112}
113
114bool GenericPipe::setCrop(
115 const overlay::utils::Dim& d) {
116 return mCtrlData.ctrl.setCrop(d);
117}
118
119bool GenericPipe::setTransform(
120 const utils::eTransform& orient)
121{
122 //Rotation could be enabled by user for zero-rot or the layer could have
123 //some transform. Mark rotation enabled in either case.
124 mRotUsed |= (orient != utils::OVERLAY_TRANSFORM_0);
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800125 mRot->setTransform(orient);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500126
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800127 return mCtrlData.ctrl.setTransform(orient);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500128}
129
130bool GenericPipe::setPosition(const utils::Dim& d)
131{
132 return mCtrlData.ctrl.setPosition(d);
133}
134
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800135void GenericPipe::setRotatorUsed(const bool& rotUsed) {
136 mRot->setRotatorUsed(rotUsed);
137 mCtrlData.ctrl.setRotatorUsed(rotUsed);
138}
139
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500140bool GenericPipe::commit() {
141 bool ret = false;
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800142 int downscale_factor = utils::ROT_DS_NONE;
143
144 if(mRotDownscaleOpt) {
145 /* Can go ahead with calculation of downscale_factor since
146 * we consider area when calculating it */
147 downscale_factor = mCtrlData.ctrl.getDownscalefactor();
148 if(downscale_factor)
149 mRotUsed = true;
150 }
151
152 setRotatorUsed(mRotUsed);
153 mCtrlData.ctrl.doTransform();
154
155 mCtrlData.ctrl.doDownscale(downscale_factor);
156 mRot->setDownscale(downscale_factor);
157
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500158 if(mRotUsed) {
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800159 //If wanting to use rotator, start it.
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500160 if(!mRot->commit()) {
161 ALOGE("GenPipe Rotator commit failed");
162 //If rot commit fails, flush rotator session, memory, fd and create
163 //a hollow rotator object
164 delete mRot;
165 mRot = Rotator::getRotator();
166 pipeState = CLOSED;
167 return false;
168 }
169 }
170
171 ret = mCtrlData.ctrl.commit();
172
173 //If mdp commit fails, flush rotator session, memory, fd and create a hollow
174 //rotator object
175 if(ret == false) {
176 delete mRot;
177 mRot = Rotator::getRotator();
178 }
179
180 pipeState = ret ? OPEN : CLOSED;
181 return ret;
182}
183
184bool GenericPipe::queueBuffer(int fd, uint32_t offset) {
185 //TODO Move pipe-id transfer to CtrlData class. Make ctrl and data private.
186 OVASSERT(isOpen(), "State is closed, cannot queueBuffer");
187 int pipeId = mCtrlData.ctrl.getPipeId();
188 OVASSERT(-1 != pipeId, "Ctrl ID should not be -1");
189 // set pipe id from ctrl to data
190 mCtrlData.data.setPipeId(pipeId);
191
192 int finalFd = fd;
193 uint32_t finalOffset = offset;
194 //If rotator is to be used, queue to it, so it can ROTATE.
195 if(mRotUsed) {
196 if(!mRot->queueBuffer(fd, offset)) {
197 ALOGE("GenPipe Rotator play failed");
198 return false;
199 }
200 //Configure MDP's source buffer as the current output buffer of rotator
201 if(mRot->getDstMemId() != -1) {
202 finalFd = mRot->getDstMemId();
203 finalOffset = mRot->getDstOffset();
204 } else {
205 //Could be -1 for NullRotator, if queue above succeeds.
206 //Need an actual rotator. Modify overlay State Traits.
207 //Not fatal, keep queuing to MDP without rotation.
208 ALOGE("Null rotator in use, where an actual is required");
209 }
210 }
211 return mCtrlData.data.queueBuffer(finalFd, finalOffset);
212}
213
214int GenericPipe::getCtrlFd() const {
215 return mCtrlData.ctrl.getFd();
216}
217
218utils::ScreenInfo GenericPipe::getScreenInfo() const
219{
220 return mCtrlData.ctrl.getScreenInfo();
221}
222
223utils::Dim GenericPipe::getCrop() const
224{
225 return mCtrlData.ctrl.getCrop();
226}
227
228void GenericPipe::dump() const
229{
230 ALOGE("== Dump Generic pipe start ==");
231 ALOGE("pipe state = %d", (int)pipeState);
232 OVASSERT(mRot, "GenericPipe should have a valid Rot");
233 mCtrlData.ctrl.dump();
234 mCtrlData.data.dump();
235 mRot->dump();
236 ALOGE("== Dump Generic pipe end ==");
237}
238
239bool GenericPipe::isClosed() const {
240 return (pipeState == CLOSED);
241}
242
243bool GenericPipe::isOpen() const {
244 return (pipeState == OPEN);
245}
246
247bool GenericPipe::setClosed() {
248 pipeState = CLOSED;
249 return true;
250}
251
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800252
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500253} //namespace overlay