blob: 58f46b353334feae0d522c2f4214e0fce0514a54 [file] [log] [blame]
Naseer Ahmed29a26812012-06-14 00:56:20 -07001/*
2* Copyright (c) 2012, Code Aurora Forum. 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 Code Aurora Forum, Inc. 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
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 */
61 bool setSource(const utils::PipeArgs& args);
Naseer Ahmed29a26812012-06-14 00:56:20 -070062 /* set crop info and pass it down to mdp */
63 bool setCrop(const utils::Dim& d);
Naseer Ahmedf48aef62012-07-20 09:05:53 -070064 /* set orientation */
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -080065 bool setTransform(const utils::eTransform& p);
66 /* set whether rotator can be used */
67 void setRotatorUsed(const bool& rotUsed);
Naseer Ahmedf48aef62012-07-20 09:05:53 -070068 /* set mdp position using dim */
69 bool setPosition(const utils::Dim& dim);
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;
Naseer Ahmed29a26812012-06-14 00:56:20 -070077
78 /* access for screen info */
79 utils::ScreenInfo getScreenInfo() const;
80
81 /* retrieve cached crop data */
82 utils::Dim getCrop() const;
83
84 /* dump the state of the object */
85 void dump() const;
86
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -080087 /* Perform transformation calculations */
88 void doTransform();
89
90 /* Performs downscale calculations */
91 void doDownscale(int dscale_factor);
92
93 /* Get downscale factor */
94 int getDownscalefactor();
95
96
Naseer Ahmed29a26812012-06-14 00:56:20 -070097private:
98 /* Retrieve screen info from underlying mdp */
99 bool getScreenInfo(utils::ScreenInfo& info);
100
Naseer Ahmed29a26812012-06-14 00:56:20 -0700101 // mdp ctrl struct(info e.g.)
102 MdpCtrl mMdp;
103
Naseer Ahmed29a26812012-06-14 00:56:20 -0700104 /* Screen info */
105 utils::ScreenInfo mInfo;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700106};
107
108
Naseer Ahmed29a26812012-06-14 00:56:20 -0700109class Data : utils::NoCopy {
110public:
111 /* init, reset */
112 explicit Data();
113
114 /* calls close */
115 ~Data();
116
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700117 /* init fd etc */
118 bool init(uint32_t fbnum);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700119
120 /* calls underlying mdp close */
121 bool close();
122
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700123 /* set overlay pipe id in the mdp struct */
124 void setPipeId(int id);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700125
126 /* get overlay id in the mdp struct */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700127 int getPipeId() const;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700128
129 /* queue buffer to the overlay */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700130 bool queueBuffer(int fd, uint32_t offset);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700131
Naseer Ahmed29a26812012-06-14 00:56:20 -0700132 /* sump the state of the obj */
133 void dump() const;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700134
Naseer Ahmed29a26812012-06-14 00:56:20 -0700135private:
Naseer Ahmed29a26812012-06-14 00:56:20 -0700136 // mdp data struct
137 MdpData mMdp;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700138};
139
140/* This class just creates a Ctrl Data pair to be used by a pipe.
141 * Although this was legacy design, this separation still makes sense, since we
142 * need to use the Ctrl channel in hwc_prepare (i.e config stage) and Data
143 * channel in hwc_set (i.e draw stage)
144 */
145struct CtrlData {
146 Ctrl ctrl;
147 Data data;
148};
149
150//-------------Inlines-------------------------------
151
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700152inline Ctrl::Ctrl() {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700153 mMdp.reset();
154}
155
156inline Ctrl::~Ctrl() {
157 close();
158}
159
160inline bool Ctrl::close() {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700161 if(!mMdp.close())
162 return false;
163 return true;
164}
165
166inline bool Ctrl::commit() {
167 if(!mMdp.set()) {
168 ALOGE("Ctrl commit failed set overlay");
169 return false;
170 }
171 return true;
172}
173
174inline bool Ctrl::getScreenInfo(utils::ScreenInfo& info) {
175 if(!mMdp.getScreenInfo(info)){
176 ALOGE("Ctrl failed to get screen info");
177 return false;
178 }
179 return true;
180}
181
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700182inline int Ctrl::getPipeId() const {
183 return mMdp.getPipeId();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700184}
185
186inline int Ctrl::getFd() const {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700187 return mMdp.getFd();
188}
189
Naseer Ahmed29a26812012-06-14 00:56:20 -0700190inline utils::ScreenInfo Ctrl::getScreenInfo() const {
191 return mInfo;
192}
193
194inline utils::Dim Ctrl::getCrop() const {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700195 return mMdp.getSrcRectDim();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700196}
197
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800198inline void Ctrl::doTransform() {
199 return mMdp.doTransform();
200}
201
202inline void Ctrl::doDownscale(int dscale_factor) {
203 mMdp.doDownscale(dscale_factor);
204}
205
206inline int Ctrl::getDownscalefactor() {
207 return mMdp.getDownscalefactor();
208}
209
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700210inline Data::Data() {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700211 mMdp.reset();
212}
213
214inline Data::~Data() { close(); }
215
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700216inline void Data::setPipeId(int id) { mMdp.setPipeId(id); }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700217
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700218inline int Data::getPipeId() const { return mMdp.getPipeId(); }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700219
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700220inline bool Data::init(uint32_t fbnum) {
221 if(!mMdp.init(fbnum)) {
222 ALOGE("Data cannot init mdp");
Naseer Ahmed29a26812012-06-14 00:56:20 -0700223 return false;
224 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700225 return true;
226}
227
228inline bool Data::close() {
229 if(!mMdp.close()) {
230 ALOGE("Data close failed");
231 return false;
232 }
233 return true;
234}
235
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700236inline bool Data::queueBuffer(int fd, uint32_t offset) {
237 return mMdp.play(fd, offset);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700238}
239
Naseer Ahmed29a26812012-06-14 00:56:20 -0700240inline void Data::dump() const {
241 ALOGE("== Dump Data MDP start ==");
242 mMdp.dump();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700243 ALOGE("== Dump Data MDP end ==");
244}
245
246
247} // overlay
248
249#endif