blob: 513ebb9d05178af04cd3c64e69ca5ccbd8abd786 [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);
Naseer Ahmedf48aef62012-07-20 09:05:53 -070064 /* set orientation */
Saurabh Shahacf10202013-02-26 10:15:15 -080065 void setTransform(const utils::eTransform& p);
Naseer Ahmedf48aef62012-07-20 09:05:53 -070066 /* set mdp position using dim */
Saurabh Shahacf10202013-02-26 10:15:15 -080067 void setPosition(const utils::Dim& dim);
Saurabh Shah5daeee52013-01-23 16:52:26 +080068 /* set mdp visual params using metadata */
69 bool setVisualParams(const MetaData_t &metadata);
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 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
Naseer Ahmed29a26812012-06-14 00:56:20 -070089private:
Naseer Ahmed29a26812012-06-14 00:56:20 -070090 // mdp ctrl struct(info e.g.)
91 MdpCtrl mMdp;
Naseer Ahmed29a26812012-06-14 00:56:20 -070092};
93
94
Naseer Ahmed29a26812012-06-14 00:56:20 -070095class Data : utils::NoCopy {
96public:
97 /* init, reset */
98 explicit Data();
Naseer Ahmed29a26812012-06-14 00:56:20 -070099 /* calls close */
100 ~Data();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700101 /* init fd etc */
102 bool init(uint32_t fbnum);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700103 /* calls underlying mdp close */
104 bool close();
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
118 MdpData mMdp;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700119};
120
121/* This class just creates a Ctrl Data pair to be used by a pipe.
122 * Although this was legacy design, this separation still makes sense, since we
123 * need to use the Ctrl channel in hwc_prepare (i.e config stage) and Data
124 * channel in hwc_set (i.e draw stage)
125 */
126struct CtrlData {
127 Ctrl ctrl;
128 Data data;
129};
130
131//-------------Inlines-------------------------------
132
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700133inline Ctrl::Ctrl() {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700134 mMdp.reset();
135}
136
137inline Ctrl::~Ctrl() {
138 close();
139}
140
141inline bool Ctrl::close() {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700142 if(!mMdp.close())
143 return false;
144 return true;
145}
146
Saurabh Shahacf10202013-02-26 10:15:15 -0800147inline bool Ctrl::init(uint32_t fbnum) {
148 // MDP/FD init
149 if(!mMdp.init(fbnum)) {
150 ALOGE("Ctrl failed to init fbnum=%d", fbnum);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700151 return false;
152 }
153 return true;
154}
155
Saurabh Shahacf10202013-02-26 10:15:15 -0800156inline void Ctrl::setSource(const utils::PipeArgs& args)
157{
158 mMdp.setSource(args);
159}
160
161inline void Ctrl::setPosition(const utils::Dim& dim)
162{
163 mMdp.setPosition(dim);
164}
165
166inline void Ctrl::setTransform(const utils::eTransform& orient)
167{
168 mMdp.setTransform(orient);
169}
170
171inline void Ctrl::setCrop(const utils::Dim& d)
172{
173 mMdp.setCrop(d);
174}
175
Saurabh Shah5daeee52013-01-23 16:52:26 +0800176inline bool Ctrl::setVisualParams(const MetaData_t &metadata)
177{
178 if (!mMdp.setVisualParams(metadata)) {
179 ALOGE("Ctrl setVisualParams failed in MDP setVisualParams");
180 return false;
181 }
182 return true;
183}
184
Saurabh Shahacf10202013-02-26 10:15:15 -0800185inline void Ctrl::dump() const {
186 ALOGE("== Dump Ctrl start ==");
187 mMdp.dump();
188 ALOGE("== Dump Ctrl end ==");
189}
190
191inline bool Ctrl::commit() {
192 if(!mMdp.set()) {
193 ALOGE("Ctrl commit failed set overlay");
Naseer Ahmed29a26812012-06-14 00:56:20 -0700194 return false;
195 }
196 return true;
197}
198
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700199inline int Ctrl::getPipeId() const {
200 return mMdp.getPipeId();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700201}
202
203inline int Ctrl::getFd() const {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700204 return mMdp.getFd();
205}
206
Saurabh Shahacf10202013-02-26 10:15:15 -0800207inline void Ctrl::updateSrcFormat(const uint32_t& rotDstFmt) {
208 mMdp.updateSrcFormat(rotDstFmt);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700209}
210
211inline utils::Dim Ctrl::getCrop() const {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700212 return mMdp.getSrcRectDim();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700213}
214
Saurabh Shahacf10202013-02-26 10:15:15 -0800215inline utils::Dim Ctrl::getPosition() const {
216 return mMdp.getDstRectDim();
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800217}
218
Saurabh Shahacf10202013-02-26 10:15:15 -0800219inline void Ctrl::setDownscale(int dscale_factor) {
220 mMdp.setDownscale(dscale_factor);
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800221}
222
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800223inline void Ctrl::getDump(char *buf, size_t len) {
224 mMdp.getDump(buf, len);
225}
226
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700227inline Data::Data() {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700228 mMdp.reset();
229}
230
231inline Data::~Data() { close(); }
232
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700233inline void Data::setPipeId(int id) { mMdp.setPipeId(id); }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700234
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700235inline int Data::getPipeId() const { return mMdp.getPipeId(); }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700236
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700237inline bool Data::init(uint32_t fbnum) {
238 if(!mMdp.init(fbnum)) {
239 ALOGE("Data cannot init mdp");
Naseer Ahmed29a26812012-06-14 00:56:20 -0700240 return false;
241 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700242 return true;
243}
244
245inline bool Data::close() {
246 if(!mMdp.close()) {
247 ALOGE("Data close failed");
248 return false;
249 }
250 return true;
251}
252
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700253inline bool Data::queueBuffer(int fd, uint32_t offset) {
254 return mMdp.play(fd, offset);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700255}
256
Naseer Ahmed29a26812012-06-14 00:56:20 -0700257inline void Data::dump() const {
258 ALOGE("== Dump Data MDP start ==");
259 mMdp.dump();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700260 ALOGE("== Dump Data MDP end ==");
261}
262
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800263inline void Data::getDump(char *buf, size_t len) {
264 mMdp.getDump(buf, len);
265}
Naseer Ahmed29a26812012-06-14 00:56:20 -0700266
267} // overlay
268
269#endif