blob: 2bf236936d27170d84a07128364249bc896463b6 [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
Jeykumar Sankaran27dee262013-08-01 17:09:54 -070050 int fbNum = Overlay::getFbForDpy(mDpy);
51 if( fbNum < 0 ) {
52 ALOGE("%s: Invalid FB for the display: %d",__FUNCTION__, mDpy);
53 return false;
Saurabh Shahc8118ac2013-06-27 10:03:19 -070054 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -050055
Saurabh Shahc8118ac2013-06-27 10:03:19 -070056 ALOGD_IF(DEBUG_OVERLAY,"%s: mFbNum:%d",__FUNCTION__, fbNum);
57
58 if(!mCtrlData.ctrl.init(fbNum)) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050059 ALOGE("GenericPipe failed to init ctrl");
60 return false;
61 }
62
Saurabh Shahc8118ac2013-06-27 10:03:19 -070063 if(!mCtrlData.data.init(fbNum)) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050064 ALOGE("GenericPipe failed to init data");
65 return false;
66 }
67
Naseer Ahmed758bfc52012-11-28 17:02:08 -050068 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
Naseer Ahmed758bfc52012-11-28 17:02:08 -050083 setClosed();
84 return ret;
85}
86
Saurabh Shahacf10202013-02-26 10:15:15 -080087void GenericPipe::setSource(const utils::PipeArgs& args) {
Saurabh Shahacf10202013-02-26 10:15:15 -080088 mRotDownscaleOpt = args.rotFlags & utils::ROT_DOWNSCALE_ENABLED;
Saurabh Shahacf10202013-02-26 10:15:15 -080089 mCtrlData.ctrl.setSource(args);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050090}
91
Saurabh Shahacf10202013-02-26 10:15:15 -080092void GenericPipe::setCrop(const overlay::utils::Dim& d) {
93 mCtrlData.ctrl.setCrop(d);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050094}
95
Sushil Chauhan897a9c32013-07-18 11:09:55 -070096void GenericPipe::setColor(const uint32_t color) {
97 mCtrlData.ctrl.setColor(color);
98}
99
Saurabh Shahacf10202013-02-26 10:15:15 -0800100void GenericPipe::setTransform(const utils::eTransform& orient) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800101 mCtrlData.ctrl.setTransform(orient);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500102}
103
Saurabh Shahacf10202013-02-26 10:15:15 -0800104void GenericPipe::setPosition(const utils::Dim& d) {
105 mCtrlData.ctrl.setPosition(d);
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800106}
107
Saurabh Shah5daeee52013-01-23 16:52:26 +0800108bool GenericPipe::setVisualParams(const MetaData_t &metadata)
109{
110 return mCtrlData.ctrl.setVisualParams(metadata);
111}
112
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500113bool GenericPipe::commit() {
114 bool ret = false;
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800115 int downscale_factor = utils::ROT_DS_NONE;
116
117 if(mRotDownscaleOpt) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800118 ovutils::Dim src(mCtrlData.ctrl.getCrop());
119 ovutils::Dim dst(mCtrlData.ctrl.getPosition());
120 downscale_factor = ovutils::getDownscaleFactor(
121 src.w, src.h, dst.w, dst.h);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500122 }
123
Saurabh Shahacf10202013-02-26 10:15:15 -0800124 mCtrlData.ctrl.setDownscale(downscale_factor);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500125 ret = mCtrlData.ctrl.commit();
126
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500127 pipeState = ret ? OPEN : CLOSED;
128 return ret;
129}
130
131bool GenericPipe::queueBuffer(int fd, uint32_t offset) {
132 //TODO Move pipe-id transfer to CtrlData class. Make ctrl and data private.
133 OVASSERT(isOpen(), "State is closed, cannot queueBuffer");
134 int pipeId = mCtrlData.ctrl.getPipeId();
135 OVASSERT(-1 != pipeId, "Ctrl ID should not be -1");
136 // set pipe id from ctrl to data
137 mCtrlData.data.setPipeId(pipeId);
138
Xiaoming Zhou912842a2013-07-03 13:16:56 -0400139 return mCtrlData.data.queueBuffer(fd, offset);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500140}
141
142int GenericPipe::getCtrlFd() const {
143 return mCtrlData.ctrl.getFd();
144}
145
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500146utils::Dim GenericPipe::getCrop() const
147{
148 return mCtrlData.ctrl.getCrop();
149}
150
151void GenericPipe::dump() const
152{
153 ALOGE("== Dump Generic pipe start ==");
154 ALOGE("pipe state = %d", (int)pipeState);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500155 mCtrlData.ctrl.dump();
156 mCtrlData.data.dump();
Xiaoming Zhou912842a2013-07-03 13:16:56 -0400157
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500158 ALOGE("== Dump Generic pipe end ==");
159}
160
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800161void GenericPipe::getDump(char *buf, size_t len) {
162 mCtrlData.ctrl.getDump(buf, len);
163 mCtrlData.data.getDump(buf, len);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800164}
165
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500166bool GenericPipe::isClosed() const {
167 return (pipeState == CLOSED);
168}
169
170bool GenericPipe::isOpen() const {
171 return (pipeState == OPEN);
172}
173
174bool GenericPipe::setClosed() {
175 pipeState = CLOSED;
176 return true;
177}
178
Saurabh Shahdf0be752013-05-23 14:40:00 -0700179void GenericPipe::forceSet() {
180 mCtrlData.ctrl.forceSet();
181}
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800182
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500183} //namespace overlay