blob: 1b26b66a86c5dee0b8b954445cb8a50f9550b942 [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 */
52 explicit Ctrl();
Naseer Ahmed29a26812012-06-14 00:56:20 -070053 /* dtor close */
54 ~Ctrl();
Naseer Ahmedf48aef62012-07-20 09:05:53 -070055 /* init fd etc*/
Saurabh Shahb8f58e22013-09-26 16:20:07 -070056 bool init(uint32_t dpy);
Naseer Ahmed29a26812012-06-14 00:56:20 -070057 /* close underlying mdp */
58 bool close();
59
Naseer Ahmed29a26812012-06-14 00:56:20 -070060 /* set source using whf, orient and wait flag */
Saurabh Shahacf10202013-02-26 10:15:15 -080061 void setSource(const utils::PipeArgs& args);
Naseer Ahmed29a26812012-06-14 00:56:20 -070062 /* set crop info and pass it down to mdp */
Saurabh Shahacf10202013-02-26 10:15:15 -080063 void setCrop(const utils::Dim& d);
Sushil Chauhan897a9c32013-07-18 11:09:55 -070064 /* set color for mdp pipe */
65 void setColor(const uint32_t color);
Naseer Ahmedf48aef62012-07-20 09:05:53 -070066 /* set orientation */
Saurabh Shahacf10202013-02-26 10:15:15 -080067 void setTransform(const utils::eTransform& p);
Naseer Ahmedf48aef62012-07-20 09:05:53 -070068 /* set mdp position using dim */
Saurabh Shahacf10202013-02-26 10:15:15 -080069 void setPosition(const utils::Dim& dim);
Saurabh Shah5daeee52013-01-23 16:52:26 +080070 /* set mdp visual params using metadata */
71 bool setVisualParams(const MetaData_t &metadata);
Naseer Ahmed29a26812012-06-14 00:56:20 -070072 /* mdp set overlay/commit changes */
73 bool commit();
74
75 /* ctrl id */
Naseer Ahmedf48aef62012-07-20 09:05:53 -070076 int getPipeId() const;
Naseer Ahmed29a26812012-06-14 00:56:20 -070077 /* ctrl fd */
78 int getFd() const;
Saurabh Shahacf10202013-02-26 10:15:15 -080079 /* retrieve crop data */
Naseer Ahmed29a26812012-06-14 00:56:20 -070080 utils::Dim getCrop() const;
Saurabh Shahacf10202013-02-26 10:15:15 -080081 utils::Dim getPosition() const;
82 /* Set downscale */
83 void setDownscale(int dscale_factor);
84 /* Update the src format based on rotator's dest */
85 void updateSrcFormat(const uint32_t& rotDstFormat);
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
Naseer Ahmed29a26812012-06-14 00:56:20 -070091private:
Naseer Ahmed29a26812012-06-14 00:56:20 -070092 // mdp ctrl struct(info e.g.)
93 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 */
100 explicit Data();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700101 /* calls close */
102 ~Data();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700103 /* init fd etc */
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700104 bool init(uint32_t dpy);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700105 /* calls underlying mdp close */
106 bool close();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700107 /* set overlay pipe id in the mdp struct */
108 void setPipeId(int id);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700109 /* get overlay id in the mdp struct */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700110 int getPipeId() const;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700111 /* queue buffer to the overlay */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700112 bool queueBuffer(int fd, uint32_t offset);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700113 /* sump the state of the obj */
114 void dump() const;
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800115 /* Return the dump in the specified buffer */
116 void getDump(char *buf, size_t len);
117
Naseer Ahmed29a26812012-06-14 00:56:20 -0700118private:
Naseer Ahmed29a26812012-06-14 00:56:20 -0700119 // mdp data struct
120 MdpData mMdp;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700121};
122
123/* This class just creates a Ctrl Data pair to be used by a pipe.
124 * Although this was legacy design, this separation still makes sense, since we
125 * need to use the Ctrl channel in hwc_prepare (i.e config stage) and Data
126 * channel in hwc_set (i.e draw stage)
127 */
128struct CtrlData {
129 Ctrl ctrl;
130 Data data;
131};
132
133//-------------Inlines-------------------------------
134
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700135inline Ctrl::Ctrl() {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700136 mMdp.reset();
137}
138
139inline Ctrl::~Ctrl() {
140 close();
141}
142
143inline bool Ctrl::close() {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700144 if(!mMdp.close())
145 return false;
146 return true;
147}
148
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700149inline bool Ctrl::init(uint32_t dpy) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800150 // MDP/FD init
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700151 if(!mMdp.init(dpy)) {
152 ALOGE("Ctrl failed to init dpy=%d", dpy);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700153 return false;
154 }
155 return true;
156}
157
Saurabh Shahacf10202013-02-26 10:15:15 -0800158inline void Ctrl::setSource(const utils::PipeArgs& args)
159{
160 mMdp.setSource(args);
161}
162
163inline void Ctrl::setPosition(const utils::Dim& dim)
164{
165 mMdp.setPosition(dim);
166}
167
168inline void Ctrl::setTransform(const utils::eTransform& orient)
169{
170 mMdp.setTransform(orient);
171}
172
173inline void Ctrl::setCrop(const utils::Dim& d)
174{
175 mMdp.setCrop(d);
176}
177
Sushil Chauhan897a9c32013-07-18 11:09:55 -0700178inline void Ctrl::setColor(const uint32_t color)
179{
180 mMdp.setColor(color);
181}
182
Saurabh Shah5daeee52013-01-23 16:52:26 +0800183inline bool Ctrl::setVisualParams(const MetaData_t &metadata)
184{
185 if (!mMdp.setVisualParams(metadata)) {
186 ALOGE("Ctrl setVisualParams failed in MDP setVisualParams");
187 return false;
188 }
189 return true;
190}
191
Saurabh Shahacf10202013-02-26 10:15:15 -0800192inline void Ctrl::dump() const {
193 ALOGE("== Dump Ctrl start ==");
194 mMdp.dump();
195 ALOGE("== Dump Ctrl end ==");
196}
197
198inline bool Ctrl::commit() {
199 if(!mMdp.set()) {
200 ALOGE("Ctrl commit failed set overlay");
Naseer Ahmed29a26812012-06-14 00:56:20 -0700201 return false;
202 }
203 return true;
204}
205
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700206inline int Ctrl::getPipeId() const {
207 return mMdp.getPipeId();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700208}
209
210inline int Ctrl::getFd() const {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700211 return mMdp.getFd();
212}
213
Saurabh Shahacf10202013-02-26 10:15:15 -0800214inline void Ctrl::updateSrcFormat(const uint32_t& rotDstFmt) {
215 mMdp.updateSrcFormat(rotDstFmt);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700216}
217
218inline utils::Dim Ctrl::getCrop() const {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700219 return mMdp.getSrcRectDim();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700220}
221
Saurabh Shahacf10202013-02-26 10:15:15 -0800222inline utils::Dim Ctrl::getPosition() const {
223 return mMdp.getDstRectDim();
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800224}
225
Saurabh Shahacf10202013-02-26 10:15:15 -0800226inline void Ctrl::setDownscale(int dscale_factor) {
227 mMdp.setDownscale(dscale_factor);
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800228}
229
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800230inline void Ctrl::getDump(char *buf, size_t len) {
231 mMdp.getDump(buf, len);
232}
233
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700234inline Data::Data() {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700235 mMdp.reset();
236}
237
238inline Data::~Data() { close(); }
239
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700240inline void Data::setPipeId(int id) { mMdp.setPipeId(id); }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700241
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700242inline int Data::getPipeId() const { return mMdp.getPipeId(); }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700243
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700244inline bool Data::init(uint32_t dpy) {
245 if(!mMdp.init(dpy)) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700246 ALOGE("Data cannot init mdp");
Naseer Ahmed29a26812012-06-14 00:56:20 -0700247 return false;
248 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700249 return true;
250}
251
252inline bool Data::close() {
253 if(!mMdp.close()) {
254 ALOGE("Data close failed");
255 return false;
256 }
257 return true;
258}
259
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700260inline bool Data::queueBuffer(int fd, uint32_t offset) {
261 return mMdp.play(fd, offset);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700262}
263
Naseer Ahmed29a26812012-06-14 00:56:20 -0700264inline void Data::dump() const {
265 ALOGE("== Dump Data MDP start ==");
266 mMdp.dump();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700267 ALOGE("== Dump Data MDP end ==");
268}
269
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800270inline void Data::getDump(char *buf, size_t len) {
271 mMdp.getDump(buf, len);
272}
Naseer Ahmed29a26812012-06-14 00:56:20 -0700273
274} // overlay
275
276#endif