overlayGenPipe.cpp revision 072cc46edd38e61fd21757c4725dbcef431bef08
1/*
2* Copyright (c) 2012-2013, 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"
31#include "mdp_version.h"
32
33namespace overlay {
34
35GenericPipe::GenericPipe(int dpy) : mDpy(dpy), mRotDownscaleOpt(false),
36    pipeState(CLOSED) {
37    init();
38}
39
40GenericPipe::~GenericPipe() {
41    close();
42}
43
44bool GenericPipe::init()
45{
46    ALOGE_IF(DEBUG_OVERLAY, "GenericPipe init");
47    mRotDownscaleOpt = false;
48
49    if(!mCtrlData.ctrl.init(mDpy)) {
50        ALOGE("GenericPipe failed to init ctrl");
51        return false;
52    }
53
54    if(!mCtrlData.data.init(mDpy)) {
55        ALOGE("GenericPipe failed to init data");
56        return false;
57    }
58
59    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
74    setClosed();
75    return ret;
76}
77
78void GenericPipe::setSource(const utils::PipeArgs& args) {
79    mRotDownscaleOpt = args.rotFlags & utils::ROT_DOWNSCALE_ENABLED;
80    mCtrlData.ctrl.setSource(args);
81}
82
83void GenericPipe::setCrop(const overlay::utils::Dim& d) {
84    mCtrlData.ctrl.setCrop(d);
85}
86
87void GenericPipe::setTransform(const utils::eTransform& orient) {
88    mCtrlData.ctrl.setTransform(orient);
89}
90
91void GenericPipe::setPosition(const utils::Dim& d) {
92    mCtrlData.ctrl.setPosition(d);
93}
94
95bool GenericPipe::setVisualParams(const MetaData_t &metadata)
96{
97        return mCtrlData.ctrl.setVisualParams(metadata);
98}
99
100bool GenericPipe::commit() {
101    bool ret = false;
102    int downscale_factor = utils::ROT_DS_NONE;
103
104    if(mRotDownscaleOpt) {
105        ovutils::Dim src(mCtrlData.ctrl.getCrop());
106        ovutils::Dim dst(mCtrlData.ctrl.getPosition());
107        downscale_factor = ovutils::getDownscaleFactor(
108                src.w, src.h, dst.w, dst.h);
109    }
110
111    mCtrlData.ctrl.setDownscale(downscale_factor);
112    ret = mCtrlData.ctrl.commit();
113
114    pipeState = ret ? OPEN : CLOSED;
115    return ret;
116}
117
118bool GenericPipe::queueBuffer(int fd, uint32_t offset) {
119    //TODO Move pipe-id transfer to CtrlData class. Make ctrl and data private.
120    OVASSERT(isOpen(), "State is closed, cannot queueBuffer");
121    int pipeId = mCtrlData.ctrl.getPipeId();
122    OVASSERT(-1 != pipeId, "Ctrl ID should not be -1");
123    // set pipe id from ctrl to data
124    mCtrlData.data.setPipeId(pipeId);
125
126    return mCtrlData.data.queueBuffer(fd, offset);
127}
128
129int GenericPipe::getCtrlFd() const {
130    return mCtrlData.ctrl.getFd();
131}
132
133utils::Dim GenericPipe::getCrop() const
134{
135    return mCtrlData.ctrl.getCrop();
136}
137
138void GenericPipe::dump() const
139{
140    ALOGE("== Dump Generic pipe start ==");
141    ALOGE("pipe state = %d", (int)pipeState);
142    mCtrlData.ctrl.dump();
143    mCtrlData.data.dump();
144
145    ALOGE("== Dump Generic pipe end ==");
146}
147
148void GenericPipe::getDump(char *buf, size_t len) {
149    mCtrlData.ctrl.getDump(buf, len);
150    mCtrlData.data.getDump(buf, len);
151}
152
153bool GenericPipe::isClosed() const  {
154    return (pipeState == CLOSED);
155}
156
157bool GenericPipe::isOpen() const  {
158    return (pipeState == OPEN);
159}
160
161bool GenericPipe::setClosed() {
162    pipeState = CLOSED;
163    return true;
164}
165
166void GenericPipe::forceSet() {
167    mCtrlData.ctrl.forceSet();
168}
169
170} //namespace overlay
171