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 #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
37 namespace ovutils = overlay::utils;
38
39 namespace overlay {
40
41 /*
42 * Sequence to use:
43 * init
44 * start
45 * setXXX
46 * close
47 * */
48 class Ctrl : utils::NoCopy {
49 public:
50
51 /* ctor */
52 explicit Ctrl(const int& dpy);
53 /* dtor close */
54 ~Ctrl();
55
56 /* set source using whf, orient and wait flag */
57 void setSource(const utils::PipeArgs& args);
58 /* set crop info and pass it down to mdp */
59 void setCrop(const utils::Dim& d);
60 /* set color for mdp pipe */
61 void setColor(const uint32_t color);
62 /* set orientation */
63 void setTransform(const utils::eTransform& p);
64 /* set mdp position using dim */
65 void setPosition(const utils::Dim& dim);
66 /* set mdp visual params using metadata */
67 bool setVisualParams(const MetaData_t &metadata);
68 /* mdp set overlay/commit changes */
69 bool commit();
70
71 /* ctrl id */
72 int getPipeId() const;
73 /* ctrl fd */
74 int getFd() const;
75 /* retrieve crop data */
76 utils::Dim getCrop() const;
77 utils::Dim getPosition() const;
78 /* Set downscale */
79 void setDownscale(int dscale_factor);
80 /* Update the src format based on rotator's dest */
81 void updateSrcFormat(const uint32_t& rotDstFormat);
82 /* dump the state of the object */
83 void dump() const;
84 /* Return the dump in the specified buffer */
85 void getDump(char *buf, size_t len);
86
87 static bool validateAndSet(Ctrl* ctrlArray[], const int& count,
88 const int& fbFd);
89 private:
90 // mdp ctrl struct(info e.g.)
91 MdpCtrl *mMdp;
92 };
93
94
95 class Data : utils::NoCopy {
96 public:
97 /* init, reset */
98 explicit Data(const int& dpy);
99 /* calls close */
100 ~Data();
101 /* set overlay pipe id in the mdp struct */
102 void setPipeId(int id);
103 /* get overlay id in the mdp struct */
104 int getPipeId() const;
105 /* queue buffer to the overlay */
106 bool queueBuffer(int fd, uint32_t offset);
107 /* sump the state of the obj */
108 void dump() const;
109 /* Return the dump in the specified buffer */
110 void getDump(char *buf, size_t len);
111
112 private:
113 // mdp data struct
114 MdpData *mMdp;
115 };
116
117 //-------------Inlines-------------------------------
118
Ctrl(const int & dpy)119 inline Ctrl::Ctrl(const int& dpy) : mMdp(new MdpCtrl(dpy)) {
120 }
121
~Ctrl()122 inline Ctrl::~Ctrl() {
123 delete mMdp;
124 }
125
setSource(const utils::PipeArgs & args)126 inline void Ctrl::setSource(const utils::PipeArgs& args)
127 {
128 mMdp->setSource(args);
129 }
130
setPosition(const utils::Dim & dim)131 inline void Ctrl::setPosition(const utils::Dim& dim)
132 {
133 mMdp->setPosition(dim);
134 }
135
setTransform(const utils::eTransform & orient)136 inline void Ctrl::setTransform(const utils::eTransform& orient)
137 {
138 mMdp->setTransform(orient);
139 }
140
setCrop(const utils::Dim & d)141 inline void Ctrl::setCrop(const utils::Dim& d)
142 {
143 mMdp->setCrop(d);
144 }
145
setColor(const uint32_t color)146 inline void Ctrl::setColor(const uint32_t color)
147 {
148 mMdp->setColor(color);
149 }
150
setVisualParams(const MetaData_t & metadata)151 inline bool Ctrl::setVisualParams(const MetaData_t &metadata)
152 {
153 if (!mMdp->setVisualParams(metadata)) {
154 ALOGE("Ctrl setVisualParams failed in MDP setVisualParams");
155 return false;
156 }
157 return true;
158 }
159
dump()160 inline void Ctrl::dump() const {
161 ALOGE("== Dump Ctrl start ==");
162 mMdp->dump();
163 ALOGE("== Dump Ctrl end ==");
164 }
165
commit()166 inline bool Ctrl::commit() {
167 if(!mMdp->set()) {
168 ALOGE("Ctrl commit failed set overlay");
169 return false;
170 }
171 return true;
172 }
173
getPipeId()174 inline int Ctrl::getPipeId() const {
175 return mMdp->getPipeId();
176 }
177
getFd()178 inline int Ctrl::getFd() const {
179 return mMdp->getFd();
180 }
181
updateSrcFormat(const uint32_t & rotDstFmt)182 inline void Ctrl::updateSrcFormat(const uint32_t& rotDstFmt) {
183 mMdp->updateSrcFormat(rotDstFmt);
184 }
185
validateAndSet(Ctrl * ctrlArray[],const int & count,const int & fbFd)186 inline bool Ctrl::validateAndSet(Ctrl* ctrlArray[], const int& count,
187 const int& fbFd) {
188 MdpCtrl* mdpCtrlArray[count];
189 memset(&mdpCtrlArray, 0, sizeof(mdpCtrlArray));
190
191 for(int i = 0; i < count; i++) {
192 mdpCtrlArray[i] = ctrlArray[i]->mMdp;
193 }
194
195 bool ret = MdpCtrl::validateAndSet(mdpCtrlArray, count, fbFd);
196 return ret;
197 }
198
getCrop()199 inline utils::Dim Ctrl::getCrop() const {
200 return mMdp->getSrcRectDim();
201 }
202
getPosition()203 inline utils::Dim Ctrl::getPosition() const {
204 return mMdp->getDstRectDim();
205 }
206
setDownscale(int dscale_factor)207 inline void Ctrl::setDownscale(int dscale_factor) {
208 mMdp->setDownscale(dscale_factor);
209 }
210
getDump(char * buf,size_t len)211 inline void Ctrl::getDump(char *buf, size_t len) {
212 mMdp->getDump(buf, len);
213 }
214
Data(const int & dpy)215 inline Data::Data(const int& dpy) : mMdp(new MdpData(dpy)) {
216 }
217
~Data()218 inline Data::~Data() {
219 delete mMdp;
220 }
221
setPipeId(int id)222 inline void Data::setPipeId(int id) { mMdp->setPipeId(id); }
223
getPipeId()224 inline int Data::getPipeId() const { return mMdp->getPipeId(); }
225
queueBuffer(int fd,uint32_t offset)226 inline bool Data::queueBuffer(int fd, uint32_t offset) {
227 return mMdp->play(fd, offset);
228 }
229
dump()230 inline void Data::dump() const {
231 ALOGE("== Dump Data MDP start ==");
232 mMdp->dump();
233 ALOGE("== Dump Data MDP end ==");
234 }
235
getDump(char * buf,size_t len)236 inline void Data::getDump(char *buf, size_t len) {
237 mMdp->getDump(buf, len);
238 }
239
240 } // overlay
241
242 #endif
243