blob: 0c49bdd80f90c1cf7e60f0edb4cb50c69e2b543b [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
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
Raj kamal23f69b22012-11-17 00:20:55 +053096 /* Update the src format */
97 void updateSrcformat(const uint32_t& inputsrcFormat);
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -080098
Naseer Ahmed29a26812012-06-14 00:56:20 -070099private:
100 /* Retrieve screen info from underlying mdp */
101 bool getScreenInfo(utils::ScreenInfo& info);
102
Naseer Ahmed29a26812012-06-14 00:56:20 -0700103 // mdp ctrl struct(info e.g.)
104 MdpCtrl mMdp;
105
Naseer Ahmed29a26812012-06-14 00:56:20 -0700106 /* Screen info */
107 utils::ScreenInfo mInfo;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700108};
109
110
Naseer Ahmed29a26812012-06-14 00:56:20 -0700111class Data : utils::NoCopy {
112public:
113 /* init, reset */
114 explicit Data();
115
116 /* calls close */
117 ~Data();
118
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700119 /* init fd etc */
120 bool init(uint32_t fbnum);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700121
122 /* calls underlying mdp close */
123 bool close();
124
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700125 /* set overlay pipe id in the mdp struct */
126 void setPipeId(int id);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700127
128 /* get overlay id in the mdp struct */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700129 int getPipeId() const;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700130
131 /* queue buffer to the overlay */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700132 bool queueBuffer(int fd, uint32_t offset);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700133
Naseer Ahmed29a26812012-06-14 00:56:20 -0700134 /* sump the state of the obj */
135 void dump() const;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700136
Naseer Ahmed29a26812012-06-14 00:56:20 -0700137private:
Naseer Ahmed29a26812012-06-14 00:56:20 -0700138 // mdp data struct
139 MdpData mMdp;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700140};
141
142/* This class just creates a Ctrl Data pair to be used by a pipe.
143 * Although this was legacy design, this separation still makes sense, since we
144 * need to use the Ctrl channel in hwc_prepare (i.e config stage) and Data
145 * channel in hwc_set (i.e draw stage)
146 */
147struct CtrlData {
148 Ctrl ctrl;
149 Data data;
150};
151
152//-------------Inlines-------------------------------
153
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700154inline Ctrl::Ctrl() {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700155 mMdp.reset();
156}
157
158inline Ctrl::~Ctrl() {
159 close();
160}
161
162inline bool Ctrl::close() {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700163 if(!mMdp.close())
164 return false;
165 return true;
166}
167
168inline bool Ctrl::commit() {
169 if(!mMdp.set()) {
170 ALOGE("Ctrl commit failed set overlay");
171 return false;
172 }
173 return true;
174}
175
176inline bool Ctrl::getScreenInfo(utils::ScreenInfo& info) {
177 if(!mMdp.getScreenInfo(info)){
178 ALOGE("Ctrl failed to get screen info");
179 return false;
180 }
181 return true;
182}
183
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700184inline int Ctrl::getPipeId() const {
185 return mMdp.getPipeId();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700186}
187
188inline int Ctrl::getFd() const {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700189 return mMdp.getFd();
190}
191
Raj kamal23f69b22012-11-17 00:20:55 +0530192inline void Ctrl::updateSrcformat(const uint32_t& inputsrcFormat) {
193 mMdp.updateSrcformat(inputsrcFormat);
194}
195
Naseer Ahmed29a26812012-06-14 00:56:20 -0700196inline utils::ScreenInfo Ctrl::getScreenInfo() const {
197 return mInfo;
198}
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
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800204inline void Ctrl::doTransform() {
205 return mMdp.doTransform();
206}
207
208inline void Ctrl::doDownscale(int dscale_factor) {
209 mMdp.doDownscale(dscale_factor);
210}
211
212inline int Ctrl::getDownscalefactor() {
213 return mMdp.getDownscalefactor();
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
252
253} // overlay
254
255#endif