blob: c9a4949ee40e2e7203ed76bcaaa00cc57ad1012e [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 */
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
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -080084 /* Perform transformation calculations */
85 void doTransform();
86
87 /* Performs downscale calculations */
88 void doDownscale(int dscale_factor);
89
90 /* Get downscale factor */
91 int getDownscalefactor();
92
Raj kamal23f69b22012-11-17 00:20:55 +053093 /* Update the src format */
94 void updateSrcformat(const uint32_t& inputsrcFormat);
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -080095
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -080096 /* dump the state of the object */
97 void dump() const;
98
99 /* Return the dump in the specified buffer */
100 void getDump(char *buf, size_t len);
101
Naseer Ahmed29a26812012-06-14 00:56:20 -0700102private:
103 /* Retrieve screen info from underlying mdp */
104 bool getScreenInfo(utils::ScreenInfo& info);
105
Naseer Ahmed29a26812012-06-14 00:56:20 -0700106 // mdp ctrl struct(info e.g.)
107 MdpCtrl mMdp;
108
Naseer Ahmed29a26812012-06-14 00:56:20 -0700109 /* Screen info */
110 utils::ScreenInfo mInfo;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700111};
112
113
Naseer Ahmed29a26812012-06-14 00:56:20 -0700114class Data : utils::NoCopy {
115public:
116 /* init, reset */
117 explicit Data();
118
119 /* calls close */
120 ~Data();
121
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700122 /* init fd etc */
123 bool init(uint32_t fbnum);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700124
125 /* calls underlying mdp close */
126 bool close();
127
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700128 /* set overlay pipe id in the mdp struct */
129 void setPipeId(int id);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700130
131 /* get overlay id in the mdp struct */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700132 int getPipeId() const;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700133
134 /* queue buffer to the overlay */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700135 bool queueBuffer(int fd, uint32_t offset);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700136
Naseer Ahmed29a26812012-06-14 00:56:20 -0700137 /* sump the state of the obj */
138 void dump() const;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700139
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800140 /* Return the dump in the specified buffer */
141 void getDump(char *buf, size_t len);
142
Naseer Ahmed29a26812012-06-14 00:56:20 -0700143private:
Naseer Ahmed29a26812012-06-14 00:56:20 -0700144 // mdp data struct
145 MdpData mMdp;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700146};
147
148/* This class just creates a Ctrl Data pair to be used by a pipe.
149 * Although this was legacy design, this separation still makes sense, since we
150 * need to use the Ctrl channel in hwc_prepare (i.e config stage) and Data
151 * channel in hwc_set (i.e draw stage)
152 */
153struct CtrlData {
154 Ctrl ctrl;
155 Data data;
156};
157
158//-------------Inlines-------------------------------
159
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700160inline Ctrl::Ctrl() {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700161 mMdp.reset();
162}
163
164inline Ctrl::~Ctrl() {
165 close();
166}
167
168inline bool Ctrl::close() {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700169 if(!mMdp.close())
170 return false;
171 return true;
172}
173
174inline bool Ctrl::commit() {
175 if(!mMdp.set()) {
176 ALOGE("Ctrl commit failed set overlay");
177 return false;
178 }
179 return true;
180}
181
182inline bool Ctrl::getScreenInfo(utils::ScreenInfo& info) {
183 if(!mMdp.getScreenInfo(info)){
184 ALOGE("Ctrl failed to get screen info");
185 return false;
186 }
187 return true;
188}
189
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700190inline int Ctrl::getPipeId() const {
191 return mMdp.getPipeId();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700192}
193
194inline int Ctrl::getFd() const {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700195 return mMdp.getFd();
196}
197
Raj kamal23f69b22012-11-17 00:20:55 +0530198inline void Ctrl::updateSrcformat(const uint32_t& inputsrcFormat) {
199 mMdp.updateSrcformat(inputsrcFormat);
200}
201
Naseer Ahmed29a26812012-06-14 00:56:20 -0700202inline utils::ScreenInfo Ctrl::getScreenInfo() const {
203 return mInfo;
204}
205
206inline utils::Dim Ctrl::getCrop() const {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700207 return mMdp.getSrcRectDim();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700208}
209
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800210inline void Ctrl::doTransform() {
211 return mMdp.doTransform();
212}
213
214inline void Ctrl::doDownscale(int dscale_factor) {
215 mMdp.doDownscale(dscale_factor);
216}
217
218inline int Ctrl::getDownscalefactor() {
219 return mMdp.getDownscalefactor();
220}
221
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800222inline void Ctrl::getDump(char *buf, size_t len) {
223 mMdp.getDump(buf, len);
224}
225
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700226inline Data::Data() {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700227 mMdp.reset();
228}
229
230inline Data::~Data() { close(); }
231
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700232inline void Data::setPipeId(int id) { mMdp.setPipeId(id); }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700233
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700234inline int Data::getPipeId() const { return mMdp.getPipeId(); }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700235
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700236inline bool Data::init(uint32_t fbnum) {
237 if(!mMdp.init(fbnum)) {
238 ALOGE("Data cannot init mdp");
Naseer Ahmed29a26812012-06-14 00:56:20 -0700239 return false;
240 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700241 return true;
242}
243
244inline bool Data::close() {
245 if(!mMdp.close()) {
246 ALOGE("Data close failed");
247 return false;
248 }
249 return true;
250}
251
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700252inline bool Data::queueBuffer(int fd, uint32_t offset) {
253 return mMdp.play(fd, offset);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700254}
255
Naseer Ahmed29a26812012-06-14 00:56:20 -0700256inline void Data::dump() const {
257 ALOGE("== Dump Data MDP start ==");
258 mMdp.dump();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700259 ALOGE("== Dump Data MDP end ==");
260}
261
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800262inline void Data::getDump(char *buf, size_t len) {
263 mMdp.getDump(buf, len);
264}
Naseer Ahmed29a26812012-06-14 00:56:20 -0700265
266} // overlay
267
268#endif