blob: f4c95f9d125c23cbd69906d36c439e4b7fa7056c [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 */
65 bool setTransform(const utils::eTransform& p, const bool&);
66 /* set mdp position using dim */
67 bool 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;
Naseer Ahmed29a26812012-06-14 00:56:20 -070075
76 /* access for screen info */
77 utils::ScreenInfo getScreenInfo() const;
78
79 /* retrieve cached crop data */
80 utils::Dim getCrop() const;
81
82 /* dump the state of the object */
83 void dump() const;
84
85private:
86 /* Retrieve screen info from underlying mdp */
87 bool getScreenInfo(utils::ScreenInfo& info);
88
Naseer Ahmed29a26812012-06-14 00:56:20 -070089 // mdp ctrl struct(info e.g.)
90 MdpCtrl mMdp;
91
Naseer Ahmed29a26812012-06-14 00:56:20 -070092 /* Screen info */
93 utils::ScreenInfo mInfo;
Naseer Ahmed29a26812012-06-14 00:56:20 -070094};
95
96
Naseer Ahmed29a26812012-06-14 00:56:20 -070097class Data : utils::NoCopy {
98public:
99 /* init, reset */
100 explicit Data();
101
102 /* calls close */
103 ~Data();
104
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700105 /* init fd etc */
106 bool init(uint32_t fbnum);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700107
108 /* calls underlying mdp close */
109 bool close();
110
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700111 /* set overlay pipe id in the mdp struct */
112 void setPipeId(int id);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700113
114 /* get overlay id in the mdp struct */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700115 int getPipeId() const;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700116
117 /* queue buffer to the overlay */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700118 bool queueBuffer(int fd, uint32_t offset);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700119
Naseer Ahmed29a26812012-06-14 00:56:20 -0700120 /* sump the state of the obj */
121 void dump() const;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700122
Naseer Ahmed29a26812012-06-14 00:56:20 -0700123private:
Naseer Ahmed29a26812012-06-14 00:56:20 -0700124 // mdp data struct
125 MdpData mMdp;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700126};
127
128/* This class just creates a Ctrl Data pair to be used by a pipe.
129 * Although this was legacy design, this separation still makes sense, since we
130 * need to use the Ctrl channel in hwc_prepare (i.e config stage) and Data
131 * channel in hwc_set (i.e draw stage)
132 */
133struct CtrlData {
134 Ctrl ctrl;
135 Data data;
136};
137
138//-------------Inlines-------------------------------
139
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700140inline Ctrl::Ctrl() {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700141 mMdp.reset();
142}
143
144inline Ctrl::~Ctrl() {
145 close();
146}
147
148inline bool Ctrl::close() {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700149 if(!mMdp.close())
150 return false;
151 return true;
152}
153
154inline bool Ctrl::commit() {
155 if(!mMdp.set()) {
156 ALOGE("Ctrl commit failed set overlay");
157 return false;
158 }
159 return true;
160}
161
162inline bool Ctrl::getScreenInfo(utils::ScreenInfo& info) {
163 if(!mMdp.getScreenInfo(info)){
164 ALOGE("Ctrl failed to get screen info");
165 return false;
166 }
167 return true;
168}
169
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700170inline int Ctrl::getPipeId() const {
171 return mMdp.getPipeId();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700172}
173
174inline int Ctrl::getFd() const {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700175 return mMdp.getFd();
176}
177
Naseer Ahmed29a26812012-06-14 00:56:20 -0700178inline utils::ScreenInfo Ctrl::getScreenInfo() const {
179 return mInfo;
180}
181
182inline utils::Dim Ctrl::getCrop() const {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700183 return mMdp.getSrcRectDim();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700184}
185
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700186inline Data::Data() {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700187 mMdp.reset();
188}
189
190inline Data::~Data() { close(); }
191
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700192inline void Data::setPipeId(int id) { mMdp.setPipeId(id); }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700193
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700194inline int Data::getPipeId() const { return mMdp.getPipeId(); }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700195
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700196inline bool Data::init(uint32_t fbnum) {
197 if(!mMdp.init(fbnum)) {
198 ALOGE("Data cannot init mdp");
Naseer Ahmed29a26812012-06-14 00:56:20 -0700199 return false;
200 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700201 return true;
202}
203
204inline bool Data::close() {
205 if(!mMdp.close()) {
206 ALOGE("Data close failed");
207 return false;
208 }
209 return true;
210}
211
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700212inline bool Data::queueBuffer(int fd, uint32_t offset) {
213 return mMdp.play(fd, offset);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700214}
215
Naseer Ahmed29a26812012-06-14 00:56:20 -0700216inline void Data::dump() const {
217 ALOGE("== Dump Data MDP start ==");
218 mMdp.dump();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700219 ALOGE("== Dump Data MDP end ==");
220}
221
222
223} // overlay
224
225#endif