blob: 5cadebdb1edd00c90753e77cf5f499d8dbf17bcf [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;
80 /* Set downscale */
81 void setDownscale(int dscale_factor);
82 /* Update the src format based on rotator's dest */
83 void updateSrcFormat(const uint32_t& rotDstFormat);
Saurabh Shahdd8237a2014-02-28 14:29:09 -080084 /* return pipe priority */
85 uint8_t getPriority() const;
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -080086 /* dump the state of the object */
87 void dump() const;
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -080088 /* Return the dump in the specified buffer */
89 void getDump(char *buf, size_t len);
90
Saurabh Shaha36be922013-12-16 18:18:39 -080091 static bool validateAndSet(Ctrl* ctrlArray[], const int& count,
92 const int& fbFd);
Naseer Ahmed29a26812012-06-14 00:56:20 -070093private:
Naseer Ahmed29a26812012-06-14 00:56:20 -070094 // mdp ctrl struct(info e.g.)
Saurabh Shahd18d88a2014-01-06 15:02:49 -080095 MdpCtrl *mMdp;
Naseer Ahmed29a26812012-06-14 00:56:20 -070096};
97
98
Naseer Ahmed29a26812012-06-14 00:56:20 -070099class Data : utils::NoCopy {
100public:
101 /* init, reset */
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800102 explicit Data(const int& dpy);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700103 /* calls close */
104 ~Data();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700105 /* set overlay pipe id in the mdp struct */
106 void setPipeId(int id);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700107 /* get overlay id in the mdp struct */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700108 int getPipeId() const;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700109 /* queue buffer to the overlay */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700110 bool queueBuffer(int fd, uint32_t offset);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700111 /* sump the state of the obj */
112 void dump() const;
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800113 /* Return the dump in the specified buffer */
114 void getDump(char *buf, size_t len);
115
Naseer Ahmed29a26812012-06-14 00:56:20 -0700116private:
Naseer Ahmed29a26812012-06-14 00:56:20 -0700117 // mdp data struct
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800118 MdpData *mMdp;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700119};
120
121//-------------Inlines-------------------------------
122
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800123inline Ctrl::Ctrl(const int& dpy) : mMdp(new MdpCtrl(dpy)) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700124}
125
126inline Ctrl::~Ctrl() {
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800127 delete mMdp;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700128}
129
Saurabh Shahacf10202013-02-26 10:15:15 -0800130inline void Ctrl::setSource(const utils::PipeArgs& args)
131{
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800132 mMdp->setSource(args);
Saurabh Shahacf10202013-02-26 10:15:15 -0800133}
134
135inline void Ctrl::setPosition(const utils::Dim& dim)
136{
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800137 mMdp->setPosition(dim);
Saurabh Shahacf10202013-02-26 10:15:15 -0800138}
139
140inline void Ctrl::setTransform(const utils::eTransform& orient)
141{
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800142 mMdp->setTransform(orient);
Saurabh Shahacf10202013-02-26 10:15:15 -0800143}
144
145inline void Ctrl::setCrop(const utils::Dim& d)
146{
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800147 mMdp->setCrop(d);
Saurabh Shahacf10202013-02-26 10:15:15 -0800148}
149
Sushil Chauhan897a9c32013-07-18 11:09:55 -0700150inline void Ctrl::setColor(const uint32_t color)
151{
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800152 mMdp->setColor(color);
Sushil Chauhan897a9c32013-07-18 11:09:55 -0700153}
154
Saurabh Shah5daeee52013-01-23 16:52:26 +0800155inline bool Ctrl::setVisualParams(const MetaData_t &metadata)
156{
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800157 if (!mMdp->setVisualParams(metadata)) {
Saurabh Shah5daeee52013-01-23 16:52:26 +0800158 ALOGE("Ctrl setVisualParams failed in MDP setVisualParams");
159 return false;
160 }
161 return true;
162}
163
radhakrishna8ccb9082014-05-09 16:18:43 +0530164inline void Ctrl::setPipeType(const utils::eMdpPipeType& pType)
165{
166 mMdp->setPipeType(pType);
167}
168
Saurabh Shahacf10202013-02-26 10:15:15 -0800169inline void Ctrl::dump() const {
170 ALOGE("== Dump Ctrl start ==");
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800171 mMdp->dump();
Saurabh Shahacf10202013-02-26 10:15:15 -0800172 ALOGE("== Dump Ctrl end ==");
173}
174
175inline bool Ctrl::commit() {
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800176 if(!mMdp->set()) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800177 ALOGE("Ctrl commit failed set overlay");
Naseer Ahmed29a26812012-06-14 00:56:20 -0700178 return false;
179 }
180 return true;
181}
182
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700183inline int Ctrl::getPipeId() const {
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800184 return mMdp->getPipeId();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700185}
186
187inline int Ctrl::getFd() const {
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800188 return mMdp->getFd();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700189}
190
Saurabh Shahacf10202013-02-26 10:15:15 -0800191inline void Ctrl::updateSrcFormat(const uint32_t& rotDstFmt) {
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800192 mMdp->updateSrcFormat(rotDstFmt);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700193}
194
Saurabh Shaha36be922013-12-16 18:18:39 -0800195inline bool Ctrl::validateAndSet(Ctrl* ctrlArray[], const int& count,
196 const int& fbFd) {
197 MdpCtrl* mdpCtrlArray[count];
198 memset(&mdpCtrlArray, 0, sizeof(mdpCtrlArray));
199
200 for(int i = 0; i < count; i++) {
201 mdpCtrlArray[i] = ctrlArray[i]->mMdp;
202 }
203
204 bool ret = MdpCtrl::validateAndSet(mdpCtrlArray, count, fbFd);
205 return ret;
206}
207
Naseer Ahmed29a26812012-06-14 00:56:20 -0700208inline utils::Dim Ctrl::getCrop() const {
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800209 return mMdp->getSrcRectDim();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700210}
211
Saurabh Shahacf10202013-02-26 10:15:15 -0800212inline utils::Dim Ctrl::getPosition() const {
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800213 return mMdp->getDstRectDim();
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800214}
215
Saurabh Shahacf10202013-02-26 10:15:15 -0800216inline void Ctrl::setDownscale(int dscale_factor) {
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800217 mMdp->setDownscale(dscale_factor);
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800218}
219
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800220inline uint8_t Ctrl::getPriority() const {
221 return mMdp->getPriority();
222}
223
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800224inline void Ctrl::getDump(char *buf, size_t len) {
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800225 mMdp->getDump(buf, len);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800226}
227
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800228inline Data::Data(const int& dpy) : mMdp(new MdpData(dpy)) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700229}
230
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800231inline Data::~Data() {
232 delete mMdp;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700233}
234
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800235inline void Data::setPipeId(int id) { mMdp->setPipeId(id); }
236
237inline int Data::getPipeId() const { return mMdp->getPipeId(); }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700238
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700239inline bool Data::queueBuffer(int fd, uint32_t offset) {
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800240 return mMdp->play(fd, offset);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700241}
242
Naseer Ahmed29a26812012-06-14 00:56:20 -0700243inline void Data::dump() const {
244 ALOGE("== Dump Data MDP start ==");
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800245 mMdp->dump();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700246 ALOGE("== Dump Data MDP end ==");
247}
248
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800249inline void Data::getDump(char *buf, size_t len) {
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800250 mMdp->getDump(buf, len);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800251}
Naseer Ahmed29a26812012-06-14 00:56:20 -0700252
253} // overlay
254
255#endif