blob: 2eec98c9684f0b8f88d375832b6b9c66c49070ca [file] [log] [blame]
Naseer Ahmed29a26812012-06-14 00:56:20 -07001/*
Raj kamal23f69b22012-11-17 00:20:55 +05302* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
Naseer Ahmed29a26812012-06-14 00:56:20 -07003*
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.
Duy Truong73d36df2013-02-09 20:33:23 -080013* * Neither the name of The Linux Foundation nor the names of its
Naseer Ahmed29a26812012-06-14 00:56:20 -070014* 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#ifndef OVERLAY_CTRLDATA_H
31#define OVERLAY_CTRLDATA_H
32
33#include "overlayUtils.h"
34#include "overlayMdp.h"
35#include "gralloc_priv.h" // INTERLACE_MASK
36
37namespace ovutils = overlay::utils;
38
39namespace overlay {
40
Naseer Ahmed29a26812012-06-14 00:56:20 -070041/*
Naseer Ahmed29a26812012-06-14 00:56:20 -070042* Sequence to use:
Naseer Ahmedf48aef62012-07-20 09:05:53 -070043* init
Naseer Ahmed29a26812012-06-14 00:56:20 -070044* start
45* setXXX
46* close
Naseer Ahmed29a26812012-06-14 00:56:20 -070047* */
48class Ctrl : utils::NoCopy {
49public:
50
51 /* ctor */
Saurabh Shahd18d88a2014-01-06 15:02:49 -080052 explicit Ctrl(const int& dpy);
Naseer Ahmed29a26812012-06-14 00:56:20 -070053 /* dtor close */
54 ~Ctrl();
Naseer Ahmed29a26812012-06-14 00:56:20 -070055
Naseer Ahmed29a26812012-06-14 00:56:20 -070056 /* set source using whf, orient and wait flag */
Saurabh Shahacf10202013-02-26 10:15:15 -080057 void setSource(const utils::PipeArgs& args);
Naseer Ahmed29a26812012-06-14 00:56:20 -070058 /* set crop info and pass it down to mdp */
Saurabh Shahacf10202013-02-26 10:15:15 -080059 void setCrop(const utils::Dim& d);
Sushil Chauhan897a9c32013-07-18 11:09:55 -070060 /* set color for mdp pipe */
61 void setColor(const uint32_t color);
Naseer Ahmedf48aef62012-07-20 09:05:53 -070062 /* set orientation */
Saurabh Shahacf10202013-02-26 10:15:15 -080063 void setTransform(const utils::eTransform& p);
Naseer Ahmedf48aef62012-07-20 09:05:53 -070064 /* set mdp position using dim */
Saurabh Shahacf10202013-02-26 10:15:15 -080065 void setPosition(const utils::Dim& dim);
Saurabh Shah5daeee52013-01-23 16:52:26 +080066 /* set mdp visual params using metadata */
67 bool setVisualParams(const MetaData_t &metadata);
radhakrishna8ccb9082014-05-09 16:18:43 +053068 /* set pipe type RGB/DMA/VG */
69 void setPipeType(const utils::eMdpPipeType& pType);
Naseer Ahmed29a26812012-06-14 00:56:20 -070070 /* mdp set overlay/commit changes */
71 bool commit();
72
73 /* ctrl id */
Naseer Ahmedf48aef62012-07-20 09:05:53 -070074 int getPipeId() const;
Naseer Ahmed29a26812012-06-14 00:56:20 -070075 /* ctrl fd */
76 int getFd() const;
Saurabh Shahacf10202013-02-26 10:15:15 -080077 /* retrieve crop data */
Naseer Ahmed29a26812012-06-14 00:56:20 -070078 utils::Dim getCrop() const;
Saurabh Shahacf10202013-02-26 10:15:15 -080079 utils::Dim getPosition() const;
Saurabh Shahacf10202013-02-26 10:15:15 -080080 /* Update the src format based on rotator's dest */
81 void updateSrcFormat(const uint32_t& rotDstFormat);
Saurabh Shahdd8237a2014-02-28 14:29:09 -080082 /* return pipe priority */
83 uint8_t getPriority() const;
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -080084 /* dump the state of the object */
85 void dump() const;
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -080086 /* Return the dump in the specified buffer */
87 void getDump(char *buf, size_t len);
88
Saurabh Shaha36be922013-12-16 18:18:39 -080089 static bool validateAndSet(Ctrl* ctrlArray[], const int& count,
90 const int& fbFd);
Naseer Ahmed29a26812012-06-14 00:56:20 -070091private:
Naseer Ahmed29a26812012-06-14 00:56:20 -070092 // mdp ctrl struct(info e.g.)
Saurabh Shahd18d88a2014-01-06 15:02:49 -080093 MdpCtrl *mMdp;
Naseer Ahmed29a26812012-06-14 00:56:20 -070094};
95
96
Naseer Ahmed29a26812012-06-14 00:56:20 -070097class Data : utils::NoCopy {
98public:
99 /* init, reset */
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800100 explicit Data(const int& dpy);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700101 /* calls close */
102 ~Data();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700103 /* set overlay pipe id in the mdp struct */
104 void setPipeId(int id);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700105 /* get overlay id in the mdp struct */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700106 int getPipeId() const;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700107 /* queue buffer to the overlay */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700108 bool queueBuffer(int fd, uint32_t offset);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700109 /* sump the state of the obj */
110 void dump() const;
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800111 /* Return the dump in the specified buffer */
112 void getDump(char *buf, size_t len);
113
Naseer Ahmed29a26812012-06-14 00:56:20 -0700114private:
Naseer Ahmed29a26812012-06-14 00:56:20 -0700115 // mdp data struct
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800116 MdpData *mMdp;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700117};
118
119//-------------Inlines-------------------------------
120
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800121inline Ctrl::Ctrl(const int& dpy) : mMdp(new MdpCtrl(dpy)) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700122}
123
124inline Ctrl::~Ctrl() {
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800125 delete mMdp;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700126}
127
Saurabh Shahacf10202013-02-26 10:15:15 -0800128inline void Ctrl::setSource(const utils::PipeArgs& args)
129{
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800130 mMdp->setSource(args);
Saurabh Shahacf10202013-02-26 10:15:15 -0800131}
132
133inline void Ctrl::setPosition(const utils::Dim& dim)
134{
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800135 mMdp->setPosition(dim);
Saurabh Shahacf10202013-02-26 10:15:15 -0800136}
137
138inline void Ctrl::setTransform(const utils::eTransform& orient)
139{
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800140 mMdp->setTransform(orient);
Saurabh Shahacf10202013-02-26 10:15:15 -0800141}
142
143inline void Ctrl::setCrop(const utils::Dim& d)
144{
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800145 mMdp->setCrop(d);
Saurabh Shahacf10202013-02-26 10:15:15 -0800146}
147
Sushil Chauhan897a9c32013-07-18 11:09:55 -0700148inline void Ctrl::setColor(const uint32_t color)
149{
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800150 mMdp->setColor(color);
Sushil Chauhan897a9c32013-07-18 11:09:55 -0700151}
152
Saurabh Shah5daeee52013-01-23 16:52:26 +0800153inline bool Ctrl::setVisualParams(const MetaData_t &metadata)
154{
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800155 if (!mMdp->setVisualParams(metadata)) {
Saurabh Shah5daeee52013-01-23 16:52:26 +0800156 ALOGE("Ctrl setVisualParams failed in MDP setVisualParams");
157 return false;
158 }
159 return true;
160}
161
radhakrishna8ccb9082014-05-09 16:18:43 +0530162inline void Ctrl::setPipeType(const utils::eMdpPipeType& pType)
163{
164 mMdp->setPipeType(pType);
165}
166
Saurabh Shahacf10202013-02-26 10:15:15 -0800167inline void Ctrl::dump() const {
168 ALOGE("== Dump Ctrl start ==");
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800169 mMdp->dump();
Saurabh Shahacf10202013-02-26 10:15:15 -0800170 ALOGE("== Dump Ctrl end ==");
171}
172
173inline bool Ctrl::commit() {
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800174 if(!mMdp->set()) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800175 ALOGE("Ctrl commit failed set overlay");
Naseer Ahmed29a26812012-06-14 00:56:20 -0700176 return false;
177 }
178 return true;
179}
180
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700181inline int Ctrl::getPipeId() const {
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800182 return mMdp->getPipeId();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700183}
184
185inline int Ctrl::getFd() const {
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800186 return mMdp->getFd();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700187}
188
Saurabh Shahacf10202013-02-26 10:15:15 -0800189inline void Ctrl::updateSrcFormat(const uint32_t& rotDstFmt) {
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800190 mMdp->updateSrcFormat(rotDstFmt);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700191}
192
Saurabh Shaha36be922013-12-16 18:18:39 -0800193inline bool Ctrl::validateAndSet(Ctrl* ctrlArray[], const int& count,
194 const int& fbFd) {
195 MdpCtrl* mdpCtrlArray[count];
196 memset(&mdpCtrlArray, 0, sizeof(mdpCtrlArray));
197
198 for(int i = 0; i < count; i++) {
199 mdpCtrlArray[i] = ctrlArray[i]->mMdp;
200 }
201
202 bool ret = MdpCtrl::validateAndSet(mdpCtrlArray, count, fbFd);
203 return ret;
204}
205
Naseer Ahmed29a26812012-06-14 00:56:20 -0700206inline utils::Dim Ctrl::getCrop() const {
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800207 return mMdp->getSrcRectDim();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700208}
209
Saurabh Shahacf10202013-02-26 10:15:15 -0800210inline utils::Dim Ctrl::getPosition() const {
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800211 return mMdp->getDstRectDim();
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800212}
213
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800214inline uint8_t Ctrl::getPriority() const {
215 return mMdp->getPriority();
216}
217
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800218inline void Ctrl::getDump(char *buf, size_t len) {
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800219 mMdp->getDump(buf, len);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800220}
221
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800222inline Data::Data(const int& dpy) : mMdp(new MdpData(dpy)) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700223}
224
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800225inline Data::~Data() {
226 delete mMdp;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700227}
228
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800229inline void Data::setPipeId(int id) { mMdp->setPipeId(id); }
230
231inline int Data::getPipeId() const { return mMdp->getPipeId(); }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700232
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700233inline bool Data::queueBuffer(int fd, uint32_t offset) {
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800234 return mMdp->play(fd, offset);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700235}
236
Naseer Ahmed29a26812012-06-14 00:56:20 -0700237inline void Data::dump() const {
238 ALOGE("== Dump Data MDP start ==");
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800239 mMdp->dump();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700240 ALOGE("== Dump Data MDP end ==");
241}
242
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800243inline void Data::getDump(char *buf, size_t len) {
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800244 mMdp->getDump(buf, len);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800245}
Naseer Ahmed29a26812012-06-14 00:56:20 -0700246
247} // overlay
248
249#endif