blob: 0b864df4d391e887d1047bb9aa4234d625dfb50b [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),
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 }
Raj kamal23f69b22012-11-17 00:20:55 +0530169 /* Set the mdp src format to the output format of the rotator.
170 * The output format of the rotator might be different depending on
171 * whether fastyuv mode is enabled in the rotator.
172 */
173 mCtrlData.ctrl.updateSrcformat(mRot->getDstFormat());
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500174 }
175
176 ret = mCtrlData.ctrl.commit();
177
178 //If mdp commit fails, flush rotator session, memory, fd and create a hollow
179 //rotator object
180 if(ret == false) {
181 delete mRot;
182 mRot = Rotator::getRotator();
183 }
184
185 pipeState = ret ? OPEN : CLOSED;
186 return ret;
187}
188
189bool GenericPipe::queueBuffer(int fd, uint32_t offset) {
190 //TODO Move pipe-id transfer to CtrlData class. Make ctrl and data private.
191 OVASSERT(isOpen(), "State is closed, cannot queueBuffer");
192 int pipeId = mCtrlData.ctrl.getPipeId();
193 OVASSERT(-1 != pipeId, "Ctrl ID should not be -1");
194 // set pipe id from ctrl to data
195 mCtrlData.data.setPipeId(pipeId);
196
197 int finalFd = fd;
198 uint32_t finalOffset = offset;
199 //If rotator is to be used, queue to it, so it can ROTATE.
200 if(mRotUsed) {
201 if(!mRot->queueBuffer(fd, offset)) {
202 ALOGE("GenPipe Rotator play failed");
203 return false;
204 }
205 //Configure MDP's source buffer as the current output buffer of rotator
206 if(mRot->getDstMemId() != -1) {
207 finalFd = mRot->getDstMemId();
208 finalOffset = mRot->getDstOffset();
209 } else {
210 //Could be -1 for NullRotator, if queue above succeeds.
211 //Need an actual rotator. Modify overlay State Traits.
212 //Not fatal, keep queuing to MDP without rotation.
213 ALOGE("Null rotator in use, where an actual is required");
214 }
215 }
216 return mCtrlData.data.queueBuffer(finalFd, finalOffset);
217}
218
219int GenericPipe::getCtrlFd() const {
220 return mCtrlData.ctrl.getFd();
221}
222
223utils::ScreenInfo GenericPipe::getScreenInfo() const
224{
225 return mCtrlData.ctrl.getScreenInfo();
226}
227
228utils::Dim GenericPipe::getCrop() const
229{
230 return mCtrlData.ctrl.getCrop();
231}
232
233void GenericPipe::dump() const
234{
235 ALOGE("== Dump Generic pipe start ==");
236 ALOGE("pipe state = %d", (int)pipeState);
237 OVASSERT(mRot, "GenericPipe should have a valid Rot");
238 mCtrlData.ctrl.dump();
239 mCtrlData.data.dump();
240 mRot->dump();
241 ALOGE("== Dump Generic pipe end ==");
242}
243
244bool GenericPipe::isClosed() const {
245 return (pipeState == CLOSED);
246}
247
248bool GenericPipe::isOpen() const {
249 return (pipeState == OPEN);
250}
251
252bool GenericPipe::setClosed() {
253 pipeState = CLOSED;
254 return true;
255}
256
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800257
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500258} //namespace overlay