blob: e0b580b40ac38e95c5e94cf7e09e3adcfbc823fc [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"
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -080031#include "mdp_version.h"
Naseer Ahmed758bfc52012-11-28 17:02:08 -050032
33namespace overlay {
34
Saurabh Shahc8118ac2013-06-27 10:03:19 -070035GenericPipe::GenericPipe(int dpy) : mDpy(dpy), mRotDownscaleOpt(false),
Xiaoming Zhou912842a2013-07-03 13:16:56 -040036 pipeState(CLOSED) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050037 init();
38}
39
40GenericPipe::~GenericPipe() {
41 close();
42}
43
44bool GenericPipe::init()
45{
46 ALOGE_IF(DEBUG_OVERLAY, "GenericPipe init");
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -080047 mRotDownscaleOpt = false;
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -080048
Saurabh Shahb8f58e22013-09-26 16:20:07 -070049 if(!mCtrlData.ctrl.init(mDpy)) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050050 ALOGE("GenericPipe failed to init ctrl");
51 return false;
52 }
53
Saurabh Shahb8f58e22013-09-26 16:20:07 -070054 if(!mCtrlData.data.init(mDpy)) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050055 ALOGE("GenericPipe failed to init data");
56 return false;
57 }
58
Naseer Ahmed758bfc52012-11-28 17:02:08 -050059 return true;
60}
61
62bool GenericPipe::close() {
63 bool ret = true;
64
65 if(!mCtrlData.ctrl.close()) {
66 ALOGE("GenericPipe failed to close ctrl");
67 ret = false;
68 }
69 if (!mCtrlData.data.close()) {
70 ALOGE("GenericPipe failed to close data");
71 ret = false;
72 }
73
Naseer Ahmed758bfc52012-11-28 17:02:08 -050074 setClosed();
75 return ret;
76}
77
Saurabh Shahacf10202013-02-26 10:15:15 -080078void GenericPipe::setSource(const utils::PipeArgs& args) {
Saurabh Shahacf10202013-02-26 10:15:15 -080079 mRotDownscaleOpt = args.rotFlags & utils::ROT_DOWNSCALE_ENABLED;
Saurabh Shahacf10202013-02-26 10:15:15 -080080 mCtrlData.ctrl.setSource(args);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050081}
82
Saurabh Shahacf10202013-02-26 10:15:15 -080083void GenericPipe::setCrop(const overlay::utils::Dim& d) {
84 mCtrlData.ctrl.setCrop(d);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050085}
86
Sushil Chauhan897a9c32013-07-18 11:09:55 -070087void GenericPipe::setColor(const uint32_t color) {
88 mCtrlData.ctrl.setColor(color);
89}
90
Saurabh Shahacf10202013-02-26 10:15:15 -080091void GenericPipe::setTransform(const utils::eTransform& orient) {
Saurabh Shahacf10202013-02-26 10:15:15 -080092 mCtrlData.ctrl.setTransform(orient);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050093}
94
Saurabh Shahacf10202013-02-26 10:15:15 -080095void GenericPipe::setPosition(const utils::Dim& d) {
96 mCtrlData.ctrl.setPosition(d);
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -080097}
98
Saurabh Shah5daeee52013-01-23 16:52:26 +080099bool GenericPipe::setVisualParams(const MetaData_t &metadata)
100{
101 return mCtrlData.ctrl.setVisualParams(metadata);
102}
103
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500104bool GenericPipe::commit() {
105 bool ret = false;
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800106 int downscale_factor = utils::ROT_DS_NONE;
107
108 if(mRotDownscaleOpt) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800109 ovutils::Dim src(mCtrlData.ctrl.getCrop());
110 ovutils::Dim dst(mCtrlData.ctrl.getPosition());
111 downscale_factor = ovutils::getDownscaleFactor(
112 src.w, src.h, dst.w, dst.h);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500113 }
114
Saurabh Shahacf10202013-02-26 10:15:15 -0800115 mCtrlData.ctrl.setDownscale(downscale_factor);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500116 ret = mCtrlData.ctrl.commit();
117
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500118 pipeState = ret ? OPEN : CLOSED;
119 return ret;
120}
121
122bool GenericPipe::queueBuffer(int fd, uint32_t offset) {
123 //TODO Move pipe-id transfer to CtrlData class. Make ctrl and data private.
124 OVASSERT(isOpen(), "State is closed, cannot queueBuffer");
125 int pipeId = mCtrlData.ctrl.getPipeId();
126 OVASSERT(-1 != pipeId, "Ctrl ID should not be -1");
127 // set pipe id from ctrl to data
128 mCtrlData.data.setPipeId(pipeId);
129
Xiaoming Zhou912842a2013-07-03 13:16:56 -0400130 return mCtrlData.data.queueBuffer(fd, offset);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500131}
132
133int GenericPipe::getCtrlFd() const {
134 return mCtrlData.ctrl.getFd();
135}
136
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500137utils::Dim GenericPipe::getCrop() const
138{
139 return mCtrlData.ctrl.getCrop();
140}
141
142void GenericPipe::dump() const
143{
144 ALOGE("== Dump Generic pipe start ==");
145 ALOGE("pipe state = %d", (int)pipeState);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500146 mCtrlData.ctrl.dump();
147 mCtrlData.data.dump();
Xiaoming Zhou912842a2013-07-03 13:16:56 -0400148
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500149 ALOGE("== Dump Generic pipe end ==");
150}
151
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800152void GenericPipe::getDump(char *buf, size_t len) {
153 mCtrlData.ctrl.getDump(buf, len);
154 mCtrlData.data.getDump(buf, len);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800155}
156
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500157bool GenericPipe::isClosed() const {
158 return (pipeState == CLOSED);
159}
160
161bool GenericPipe::isOpen() const {
162 return (pipeState == OPEN);
163}
164
165bool GenericPipe::setClosed() {
166 pipeState = CLOSED;
167 return true;
168}
169
Zohaib Alam4b0a9242013-11-20 23:54:12 -0500170int GenericPipe::getPipeId() {
171 return mCtrlData.ctrl.getPipeId();
172}
173
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500174} //namespace overlay