blob: d34fd2d3916a96851542ba1abe529f22b5de28c4 [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*/
56 bool init(uint32_t fbnum);
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);
Saurabh Shahdf0be752013-05-23 14:40:00 -070090 void forceSet();
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -080091
Naseer Ahmed29a26812012-06-14 00:56:20 -070092private:
Naseer Ahmed29a26812012-06-14 00:56:20 -070093 // mdp ctrl struct(info e.g.)
94 MdpCtrl mMdp;
Naseer Ahmed29a26812012-06-14 00:56:20 -070095};
96
97
Naseer Ahmed29a26812012-06-14 00:56:20 -070098class Data : utils::NoCopy {
99public:
100 /* init, reset */
101 explicit Data();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700102 /* calls close */
103 ~Data();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700104 /* init fd etc */
105 bool init(uint32_t fbnum);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700106 /* calls underlying mdp close */
107 bool close();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700108 /* set overlay pipe id in the mdp struct */
109 void setPipeId(int id);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700110 /* get overlay id in the mdp struct */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700111 int getPipeId() const;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700112 /* queue buffer to the overlay */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700113 bool queueBuffer(int fd, uint32_t offset);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700114 /* sump the state of the obj */
115 void dump() const;
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800116 /* Return the dump in the specified buffer */
117 void getDump(char *buf, size_t len);
118
Naseer Ahmed29a26812012-06-14 00:56:20 -0700119private:
Naseer Ahmed29a26812012-06-14 00:56:20 -0700120 // mdp data struct
121 MdpData mMdp;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700122};
123
124/* This class just creates a Ctrl Data pair to be used by a pipe.
125 * Although this was legacy design, this separation still makes sense, since we
126 * need to use the Ctrl channel in hwc_prepare (i.e config stage) and Data
127 * channel in hwc_set (i.e draw stage)
128 */
129struct CtrlData {
130 Ctrl ctrl;
131 Data data;
132};
133
134//-------------Inlines-------------------------------
135
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700136inline Ctrl::Ctrl() {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700137 mMdp.reset();
138}
139
140inline Ctrl::~Ctrl() {
141 close();
142}
143
144inline bool Ctrl::close() {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700145 if(!mMdp.close())
146 return false;
147 return true;
148}
149
Saurabh Shahacf10202013-02-26 10:15:15 -0800150inline bool Ctrl::init(uint32_t fbnum) {
151 // MDP/FD init
152 if(!mMdp.init(fbnum)) {
153 ALOGE("Ctrl failed to init fbnum=%d", fbnum);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700154 return false;
155 }
156 return true;
157}
158
Saurabh Shahacf10202013-02-26 10:15:15 -0800159inline void Ctrl::setSource(const utils::PipeArgs& args)
160{
161 mMdp.setSource(args);
162}
163
164inline void Ctrl::setPosition(const utils::Dim& dim)
165{
166 mMdp.setPosition(dim);
167}
168
169inline void Ctrl::setTransform(const utils::eTransform& orient)
170{
171 mMdp.setTransform(orient);
172}
173
174inline void Ctrl::setCrop(const utils::Dim& d)
175{
176 mMdp.setCrop(d);
177}
178
Sushil Chauhan897a9c32013-07-18 11:09:55 -0700179inline void Ctrl::setColor(const uint32_t color)
180{
181 mMdp.setColor(color);
182}
183
Saurabh Shah5daeee52013-01-23 16:52:26 +0800184inline bool Ctrl::setVisualParams(const MetaData_t &metadata)
185{
186 if (!mMdp.setVisualParams(metadata)) {
187 ALOGE("Ctrl setVisualParams failed in MDP setVisualParams");
188 return false;
189 }
190 return true;
191}
192
Saurabh Shahacf10202013-02-26 10:15:15 -0800193inline void Ctrl::dump() const {
194 ALOGE("== Dump Ctrl start ==");
195 mMdp.dump();
196 ALOGE("== Dump Ctrl end ==");
197}
198
199inline bool Ctrl::commit() {
200 if(!mMdp.set()) {
201 ALOGE("Ctrl commit failed set overlay");
Naseer Ahmed29a26812012-06-14 00:56:20 -0700202 return false;
203 }
204 return true;
205}
206
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700207inline int Ctrl::getPipeId() const {
208 return mMdp.getPipeId();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700209}
210
211inline int Ctrl::getFd() const {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700212 return mMdp.getFd();
213}
214
Saurabh Shahacf10202013-02-26 10:15:15 -0800215inline void Ctrl::updateSrcFormat(const uint32_t& rotDstFmt) {
216 mMdp.updateSrcFormat(rotDstFmt);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700217}
218
219inline utils::Dim Ctrl::getCrop() const {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700220 return mMdp.getSrcRectDim();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700221}
222
Saurabh Shahacf10202013-02-26 10:15:15 -0800223inline utils::Dim Ctrl::getPosition() const {
224 return mMdp.getDstRectDim();
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800225}
226
Saurabh Shahacf10202013-02-26 10:15:15 -0800227inline void Ctrl::setDownscale(int dscale_factor) {
228 mMdp.setDownscale(dscale_factor);
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800229}
230
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800231inline void Ctrl::getDump(char *buf, size_t len) {
232 mMdp.getDump(buf, len);
233}
234
Saurabh Shahdf0be752013-05-23 14:40:00 -0700235inline void Ctrl::forceSet() {
236 mMdp.forceSet();
237}
238
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700239inline Data::Data() {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700240 mMdp.reset();
241}
242
243inline Data::~Data() { close(); }
244
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700245inline void Data::setPipeId(int id) { mMdp.setPipeId(id); }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700246
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700247inline int Data::getPipeId() const { return mMdp.getPipeId(); }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700248
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700249inline bool Data::init(uint32_t fbnum) {
250 if(!mMdp.init(fbnum)) {
251 ALOGE("Data cannot init mdp");
Naseer Ahmed29a26812012-06-14 00:56:20 -0700252 return false;
253 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700254 return true;
255}
256
257inline bool Data::close() {
258 if(!mMdp.close()) {
259 ALOGE("Data close failed");
260 return false;
261 }
262 return true;
263}
264
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700265inline bool Data::queueBuffer(int fd, uint32_t offset) {
266 return mMdp.play(fd, offset);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700267}
268
Naseer Ahmed29a26812012-06-14 00:56:20 -0700269inline void Data::dump() const {
270 ALOGE("== Dump Data MDP start ==");
271 mMdp.dump();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700272 ALOGE("== Dump Data MDP end ==");
273}
274
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800275inline void Data::getDump(char *buf, size_t len) {
276 mMdp.getDump(buf, len);
277}
Naseer Ahmed29a26812012-06-14 00:56:20 -0700278
279} // overlay
280
281#endif