blob: 53958344a6bfb144a9969724f243d39205020998 [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);
Naseer Ahmed29a26812012-06-14 00:56:20 -070068 /* mdp set overlay/commit changes */
69 bool commit();
70
71 /* ctrl id */
Naseer Ahmedf48aef62012-07-20 09:05:53 -070072 int getPipeId() const;
Naseer Ahmed29a26812012-06-14 00:56:20 -070073 /* ctrl fd */
74 int getFd() const;
Saurabh Shahacf10202013-02-26 10:15:15 -080075 /* retrieve crop data */
Naseer Ahmed29a26812012-06-14 00:56:20 -070076 utils::Dim getCrop() const;
Saurabh Shahacf10202013-02-26 10:15:15 -080077 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);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -080082 /* dump the state of the object */
83 void dump() const;
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -080084 /* Return the dump in the specified buffer */
85 void getDump(char *buf, size_t len);
86
Naseer Ahmed29a26812012-06-14 00:56:20 -070087private:
Naseer Ahmed29a26812012-06-14 00:56:20 -070088 // mdp ctrl struct(info e.g.)
89 MdpCtrl mMdp;
Naseer Ahmed29a26812012-06-14 00:56:20 -070090};
91
92
Naseer Ahmed29a26812012-06-14 00:56:20 -070093class Data : utils::NoCopy {
94public:
95 /* init, reset */
96 explicit Data();
Naseer Ahmed29a26812012-06-14 00:56:20 -070097 /* calls close */
98 ~Data();
Naseer Ahmedf48aef62012-07-20 09:05:53 -070099 /* init fd etc */
100 bool init(uint32_t fbnum);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700101 /* calls underlying mdp close */
102 bool close();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700103 /* set overlay pipe id in the mdp struct */
104 void setPipeId(int id);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700105 /* get overlay id in the mdp struct */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700106 int getPipeId() const;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700107 /* queue buffer to the overlay */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700108 bool queueBuffer(int fd, uint32_t offset);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700109 /* sump the state of the obj */
110 void dump() const;
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800111 /* Return the dump in the specified buffer */
112 void getDump(char *buf, size_t len);
113
Naseer Ahmed29a26812012-06-14 00:56:20 -0700114private:
Naseer Ahmed29a26812012-06-14 00:56:20 -0700115 // mdp data struct
116 MdpData mMdp;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700117};
118
119/* This class just creates a Ctrl Data pair to be used by a pipe.
120 * Although this was legacy design, this separation still makes sense, since we
121 * need to use the Ctrl channel in hwc_prepare (i.e config stage) and Data
122 * channel in hwc_set (i.e draw stage)
123 */
124struct CtrlData {
125 Ctrl ctrl;
126 Data data;
127};
128
129//-------------Inlines-------------------------------
130
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700131inline Ctrl::Ctrl() {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700132 mMdp.reset();
133}
134
135inline Ctrl::~Ctrl() {
136 close();
137}
138
139inline bool Ctrl::close() {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700140 if(!mMdp.close())
141 return false;
142 return true;
143}
144
Saurabh Shahacf10202013-02-26 10:15:15 -0800145inline bool Ctrl::init(uint32_t fbnum) {
146 // MDP/FD init
147 if(!mMdp.init(fbnum)) {
148 ALOGE("Ctrl failed to init fbnum=%d", fbnum);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700149 return false;
150 }
151 return true;
152}
153
Saurabh Shahacf10202013-02-26 10:15:15 -0800154inline void Ctrl::setSource(const utils::PipeArgs& args)
155{
156 mMdp.setSource(args);
157}
158
159inline void Ctrl::setPosition(const utils::Dim& dim)
160{
161 mMdp.setPosition(dim);
162}
163
164inline void Ctrl::setTransform(const utils::eTransform& orient)
165{
166 mMdp.setTransform(orient);
167}
168
169inline void Ctrl::setCrop(const utils::Dim& d)
170{
171 mMdp.setCrop(d);
172}
173
174inline void Ctrl::dump() const {
175 ALOGE("== Dump Ctrl start ==");
176 mMdp.dump();
177 ALOGE("== Dump Ctrl end ==");
178}
179
180inline bool Ctrl::commit() {
181 if(!mMdp.set()) {
182 ALOGE("Ctrl commit failed set overlay");
Naseer Ahmed29a26812012-06-14 00:56:20 -0700183 return false;
184 }
185 return true;
186}
187
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700188inline int Ctrl::getPipeId() const {
189 return mMdp.getPipeId();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700190}
191
192inline int Ctrl::getFd() const {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700193 return mMdp.getFd();
194}
195
Saurabh Shahacf10202013-02-26 10:15:15 -0800196inline void Ctrl::updateSrcFormat(const uint32_t& rotDstFmt) {
197 mMdp.updateSrcFormat(rotDstFmt);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700198}
199
200inline utils::Dim Ctrl::getCrop() const {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700201 return mMdp.getSrcRectDim();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700202}
203
Saurabh Shahacf10202013-02-26 10:15:15 -0800204inline utils::Dim Ctrl::getPosition() const {
205 return mMdp.getDstRectDim();
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800206}
207
Saurabh Shahacf10202013-02-26 10:15:15 -0800208inline void Ctrl::setDownscale(int dscale_factor) {
209 mMdp.setDownscale(dscale_factor);
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800210}
211
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800212inline void Ctrl::getDump(char *buf, size_t len) {
213 mMdp.getDump(buf, len);
214}
215
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700216inline Data::Data() {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700217 mMdp.reset();
218}
219
220inline Data::~Data() { close(); }
221
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700222inline void Data::setPipeId(int id) { mMdp.setPipeId(id); }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700223
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700224inline int Data::getPipeId() const { return mMdp.getPipeId(); }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700225
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700226inline bool Data::init(uint32_t fbnum) {
227 if(!mMdp.init(fbnum)) {
228 ALOGE("Data cannot init mdp");
Naseer Ahmed29a26812012-06-14 00:56:20 -0700229 return false;
230 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700231 return true;
232}
233
234inline bool Data::close() {
235 if(!mMdp.close()) {
236 ALOGE("Data close failed");
237 return false;
238 }
239 return true;
240}
241
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700242inline bool Data::queueBuffer(int fd, uint32_t offset) {
243 return mMdp.play(fd, offset);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700244}
245
Naseer Ahmed29a26812012-06-14 00:56:20 -0700246inline void Data::dump() const {
247 ALOGE("== Dump Data MDP start ==");
248 mMdp.dump();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700249 ALOGE("== Dump Data MDP end ==");
250}
251
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800252inline void Data::getDump(char *buf, size_t len) {
253 mMdp.getDump(buf, len);
254}
Naseer Ahmed29a26812012-06-14 00:56:20 -0700255
256} // overlay
257
258#endif