blob: 0de7129ea6a2f860b47c3ceff4ce17f6a38eb52f [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
Saurabh Shahc8118ac2013-06-27 10:03:19 -070036GenericPipe::GenericPipe(int dpy) : mDpy(dpy), mRotDownscaleOpt(false),
Xiaoming Zhou912842a2013-07-03 13:16:56 -040037 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");
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -080048 mRotDownscaleOpt = false;
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -080049
Saurabh Shahc8118ac2013-06-27 10:03:19 -070050 int fbNum = 0;
51 //TODO Remove the if block. What's in else block should be the standard way
52 //EXTERNAL's meaning has been overloaded in hwc to mean WFD also!
53 if(mDpy == Overlay::DPY_EXTERNAL) {
54 fbNum = Overlay::getInstance()->getExtFbNum();
55 } else if(mDpy == Overlay::DPY_WRITEBACK) {
56 fbNum = Overlay::getFbForDpy(mDpy);
57 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -050058
Saurabh Shahc8118ac2013-06-27 10:03:19 -070059 ALOGD_IF(DEBUG_OVERLAY,"%s: mFbNum:%d",__FUNCTION__, fbNum);
60
61 if(!mCtrlData.ctrl.init(fbNum)) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050062 ALOGE("GenericPipe failed to init ctrl");
63 return false;
64 }
65
Saurabh Shahc8118ac2013-06-27 10:03:19 -070066 if(!mCtrlData.data.init(fbNum)) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050067 ALOGE("GenericPipe failed to init data");
68 return false;
69 }
70
Naseer Ahmed758bfc52012-11-28 17:02:08 -050071 return true;
72}
73
74bool GenericPipe::close() {
75 bool ret = true;
76
77 if(!mCtrlData.ctrl.close()) {
78 ALOGE("GenericPipe failed to close ctrl");
79 ret = false;
80 }
81 if (!mCtrlData.data.close()) {
82 ALOGE("GenericPipe failed to close data");
83 ret = false;
84 }
85
Naseer Ahmed758bfc52012-11-28 17:02:08 -050086 setClosed();
87 return ret;
88}
89
Saurabh Shahacf10202013-02-26 10:15:15 -080090void GenericPipe::setSource(const utils::PipeArgs& args) {
Saurabh Shahacf10202013-02-26 10:15:15 -080091 mRotDownscaleOpt = args.rotFlags & utils::ROT_DOWNSCALE_ENABLED;
Saurabh Shahacf10202013-02-26 10:15:15 -080092 mCtrlData.ctrl.setSource(args);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050093}
94
Saurabh Shahacf10202013-02-26 10:15:15 -080095void GenericPipe::setCrop(const overlay::utils::Dim& d) {
96 mCtrlData.ctrl.setCrop(d);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050097}
98
Saurabh Shahacf10202013-02-26 10:15:15 -080099void GenericPipe::setTransform(const utils::eTransform& orient) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800100 mCtrlData.ctrl.setTransform(orient);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500101}
102
Saurabh Shahacf10202013-02-26 10:15:15 -0800103void GenericPipe::setPosition(const utils::Dim& d) {
104 mCtrlData.ctrl.setPosition(d);
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800105}
106
Saurabh Shah5daeee52013-01-23 16:52:26 +0800107bool GenericPipe::setVisualParams(const MetaData_t &metadata)
108{
109 return mCtrlData.ctrl.setVisualParams(metadata);
110}
111
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500112bool GenericPipe::commit() {
113 bool ret = false;
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800114 int downscale_factor = utils::ROT_DS_NONE;
115
116 if(mRotDownscaleOpt) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800117 ovutils::Dim src(mCtrlData.ctrl.getCrop());
118 ovutils::Dim dst(mCtrlData.ctrl.getPosition());
119 downscale_factor = ovutils::getDownscaleFactor(
120 src.w, src.h, dst.w, dst.h);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500121 }
122
Saurabh Shahacf10202013-02-26 10:15:15 -0800123 mCtrlData.ctrl.setDownscale(downscale_factor);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500124 ret = mCtrlData.ctrl.commit();
125
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500126 pipeState = ret ? OPEN : CLOSED;
127 return ret;
128}
129
130bool GenericPipe::queueBuffer(int fd, uint32_t offset) {
131 //TODO Move pipe-id transfer to CtrlData class. Make ctrl and data private.
132 OVASSERT(isOpen(), "State is closed, cannot queueBuffer");
133 int pipeId = mCtrlData.ctrl.getPipeId();
134 OVASSERT(-1 != pipeId, "Ctrl ID should not be -1");
135 // set pipe id from ctrl to data
136 mCtrlData.data.setPipeId(pipeId);
137
Xiaoming Zhou912842a2013-07-03 13:16:56 -0400138 return mCtrlData.data.queueBuffer(fd, offset);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500139}
140
141int GenericPipe::getCtrlFd() const {
142 return mCtrlData.ctrl.getFd();
143}
144
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500145utils::Dim GenericPipe::getCrop() const
146{
147 return mCtrlData.ctrl.getCrop();
148}
149
150void GenericPipe::dump() const
151{
152 ALOGE("== Dump Generic pipe start ==");
153 ALOGE("pipe state = %d", (int)pipeState);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500154 mCtrlData.ctrl.dump();
155 mCtrlData.data.dump();
Xiaoming Zhou912842a2013-07-03 13:16:56 -0400156
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500157 ALOGE("== Dump Generic pipe end ==");
158}
159
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800160void GenericPipe::getDump(char *buf, size_t len) {
161 mCtrlData.ctrl.getDump(buf, len);
162 mCtrlData.data.getDump(buf, len);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800163}
164
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500165bool GenericPipe::isClosed() const {
166 return (pipeState == CLOSED);
167}
168
169bool GenericPipe::isOpen() const {
170 return (pipeState == OPEN);
171}
172
173bool GenericPipe::setClosed() {
174 pipeState = CLOSED;
175 return true;
176}
177
Saurabh Shahdf0be752013-05-23 14:40:00 -0700178void GenericPipe::forceSet() {
179 mCtrlData.ctrl.forceSet();
180}
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800181
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500182} //namespace overlay