blob: 7d3bbee8bfc6025d65e27397b69aa326c344f2db [file] [log] [blame]
Naseer Ahmed29a26812012-06-14 00:56:20 -07001/*
2* Copyright (C) 2008 The Android Open Source Project
Raj kamal23f69b22012-11-17 00:20:55 +05303* Copyright (c) 2010-2013, The Linux Foundation. All rights reserved.
Naseer Ahmed29a26812012-06-14 00:56:20 -07004*
5* Licensed under the Apache License, Version 2.0 (the "License");
6* you may not use this file except in compliance with the License.
7* You may obtain a copy of the License at
8*
9* http://www.apache.org/licenses/LICENSE-2.0
10*
11* Unless required by applicable law or agreed to in writing, software
12* distributed under the License is distributed on an "AS IS" BASIS,
13* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14* See the License for the specific language governing permissions and
15* limitations under the License.
16*/
17
18#ifndef OVERLAY_MDP_H
19#define OVERLAY_MDP_H
20
21#include <linux/msm_mdp.h>
22
23#include "overlayUtils.h"
24#include "mdpWrapper.h"
Naseer Ahmed29a26812012-06-14 00:56:20 -070025
26namespace overlay{
27
Naseer Ahmed29a26812012-06-14 00:56:20 -070028/*
29* Mdp Ctrl holds corresponding fd and MDP related struct.
30* It is simple wrapper to MDP services
31* */
32class MdpCtrl {
33public:
34 /* ctor reset */
35 explicit MdpCtrl();
Naseer Ahmed29a26812012-06-14 00:56:20 -070036 /* dtor close */
37 ~MdpCtrl();
Naseer Ahmedf48aef62012-07-20 09:05:53 -070038 /* init underlying device using fbnum */
39 bool init(uint32_t fbnum);
Naseer Ahmed29a26812012-06-14 00:56:20 -070040 /* unset overlay, reset and close fd */
41 bool close();
Naseer Ahmedf48aef62012-07-20 09:05:53 -070042 /* reset and set ov id to -1 / MSMFB_NEW_REQUEST */
Naseer Ahmed29a26812012-06-14 00:56:20 -070043 void reset();
Naseer Ahmed29a26812012-06-14 00:56:20 -070044 /* calls overlay set
45 * Set would always consult last good known ov instance.
46 * Only if it is different, set would actually exectue ioctl.
47 * On a sucess ioctl. last good known ov instance is updated */
48 bool set();
Naseer Ahmedf48aef62012-07-20 09:05:53 -070049 /* Sets the source total width, height, format */
Saurabh Shahacf10202013-02-26 10:15:15 -080050 void setSource(const utils::PipeArgs& pargs);
Naseer Ahmed29a26812012-06-14 00:56:20 -070051 /*
52 * Sets ROI, the unpadded region, for source buffer.
Naseer Ahmed29a26812012-06-14 00:56:20 -070053 * Dim - ROI dimensions.
54 */
Saurabh Shahacf10202013-02-26 10:15:15 -080055 void setCrop(const utils::Dim& d);
56 void setTransform(const utils::eTransform& orient);
Naseer Ahmed29a26812012-06-14 00:56:20 -070057 /* given a dim and w/h, set overlay dim */
Saurabh Shahacf10202013-02-26 10:15:15 -080058 void setPosition(const utils::Dim& dim);
Naseer Ahmed29a26812012-06-14 00:56:20 -070059 /* using user_data, sets/unsets roationvalue in mdp flags */
60 void setRotationFlags();
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -080061 /* Performs downscale calculations */
Saurabh Shahacf10202013-02-26 10:15:15 -080062 void setDownscale(int dscale_factor);
63 /* Update the src format with rotator's dest*/
64 void updateSrcFormat(const uint32_t& rotDstFormat);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -080065 /* dump state of the object */
66 void dump() const;
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -080067 /* Return the dump in the specified buffer */
68 void getDump(char *buf, size_t len);
69
Saurabh Shahacf10202013-02-26 10:15:15 -080070 /* returns session id */
71 int getPipeId() const;
72 /* returns the fd associated to ctrl*/
73 int getFd() const;
74 /* returns a copy ro dst rect dim */
75 utils::Dim getDstRectDim() const;
76 /* returns a copy to src rect dim */
77 utils::Dim getSrcRectDim() const;
Naseer Ahmed29a26812012-06-14 00:56:20 -070078
Saurabh Shahacf10202013-02-26 10:15:15 -080079private:
80 /* Perform transformation calculations */
81 void doTransform();
82 void doDownscale();
83 /* get orient / user_data[0] */
84 int getOrient() const;
85 /* overlay get */
86 bool get();
87 /* returns flags from mdp structure */
88 int getFlags() const;
89 /* set flags to mdp structure */
90 void setFlags(int f);
91 /* set z order */
92 void setZ(utils::eZorder z);
93 /* set isFg flag */
94 void setIsFg(utils::eIsFg isFg);
95 /* return a copy of src whf*/
96 utils::Whf getSrcWhf() const;
97 /* set src whf */
98 void setSrcWhf(const utils::Whf& whf);
99 /* set src/dst rect dim */
100 void setSrcRectDim(const utils::Dim d);
101 void setDstRectDim(const utils::Dim d);
102 /* returns user_data[0]*/
103 int getUserData() const;
104 /* sets user_data[0] */
105 void setUserData(int v);
106 /* return true if current overlay is different
107 * than last known good overlay */
108 bool ovChanged() const;
109 /* save mOVInfo to be last known good ov*/
110 void save();
111 /* restore last known good ov to be the current */
112 void restore();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700113
114 utils::eTransform mOrientation; //Holds requested orientation
Naseer Ahmed29a26812012-06-14 00:56:20 -0700115 /* last good known ov info */
116 mdp_overlay mLkgo;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700117 /* Actual overlay mdp structure */
118 mdp_overlay mOVInfo;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700119 /* FD for the mdp fbnum */
120 OvFD mFd;
Saurabh Shahacf10202013-02-26 10:15:15 -0800121 int mDownscale;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700122};
123
124
125/* MDP 3D related ctrl */
126class MdpCtrl3D {
127public:
128 /* ctor reset data */
129 MdpCtrl3D();
130 /* calls MSMFB_OVERLAY_3D */
131 bool close();
132 /* set w/h. format is ignored*/
133 void setWh(const utils::Whf& whf);
134 /* set is_3d calls MSMFB_OVERLAY_3D */
135 bool useVirtualFB();
136 /* set fd to be used in ioctl */
137 void setFd(int fd);
138 /* dump */
139 void dump() const;
140private:
141 /* reset */
142 void reset();
143 /* actual MSM 3D info */
144 msmfb_overlay_3d m3DOVInfo;
145 /* FD for the mdp 3D */
146 OvFD mFd;
147};
148
149/* MDP data */
150class MdpData {
151public:
152 /* ctor reset data */
153 explicit MdpData();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700154 /* dtor close*/
155 ~MdpData();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700156 /* init FD */
157 bool init(uint32_t fbnum);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700158 /* memset0 the underlying mdp object */
159 void reset();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700160 /* close fd, and reset */
161 bool close();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700162 /* set id of mdp data */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700163 void setPipeId(int id);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700164 /* return ses id of data */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700165 int getPipeId() const;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700166 /* get underlying fd*/
167 int getFd() const;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700168 /* get memory_id */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700169 int getSrcMemoryId() const;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700170 /* calls wrapper play */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700171 bool play(int fd, uint32_t offset);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700172 /* dump state of the object */
173 void dump() const;
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800174 /* Return the dump in the specified buffer */
175 void getDump(char *buf, size_t len);
176
Naseer Ahmed29a26812012-06-14 00:56:20 -0700177private:
178
179 /* actual overlay mdp data */
180 msmfb_overlay_data mOvData;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700181 /* fd to mdp fbnum */
182 OvFD mFd;
183};
184
185//--------------Inlines---------------------------------
Naseer Ahmed29a26812012-06-14 00:56:20 -0700186
187///// MdpCtrl //////
188
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700189inline MdpCtrl::MdpCtrl() {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700190 reset();
191}
192
193inline MdpCtrl::~MdpCtrl() {
194 close();
195}
196
197inline int MdpCtrl::getOrient() const {
198 return getUserData();
199}
200
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700201inline int MdpCtrl::getPipeId() const {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700202 return mOVInfo.id;
203}
204
205inline int MdpCtrl::getFd() const {
206 return mFd.getFD();
207}
208
209inline int MdpCtrl::getFlags() const {
210 return mOVInfo.flags;
211}
212
213inline void MdpCtrl::setFlags(int f) {
214 mOVInfo.flags = f;
215}
216
217inline void MdpCtrl::setZ(overlay::utils::eZorder z) {
218 mOVInfo.z_order = z;
219}
220
Naseer Ahmed29a26812012-06-14 00:56:20 -0700221inline void MdpCtrl::setIsFg(overlay::utils::eIsFg isFg) {
222 mOVInfo.is_fg = isFg;
223}
224
Saurabh Shahacf10202013-02-26 10:15:15 -0800225inline void MdpCtrl::setDownscale(int dscale) {
226 mDownscale = dscale;
227}
228
Naseer Ahmed29a26812012-06-14 00:56:20 -0700229inline bool MdpCtrl::ovChanged() const {
230 // 0 means same
231 if(0 == ::memcmp(&mOVInfo, &mLkgo, sizeof (mdp_overlay))) {
232 return false;
233 }
234 return true;
235}
236
237inline void MdpCtrl::save() {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700238 if(static_cast<ssize_t>(mOVInfo.id) == MSMFB_NEW_REQUEST) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700239 ALOGE("MdpCtrl current ov has id -1, will not save");
Naseer Ahmed29a26812012-06-14 00:56:20 -0700240 return;
241 }
242 mLkgo = mOVInfo;
243}
244
245inline void MdpCtrl::restore() {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700246 if(static_cast<ssize_t>(mLkgo.id) == MSMFB_NEW_REQUEST) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700247 ALOGE("MdpCtrl Lkgo ov has id -1, will not restore");
Naseer Ahmed29a26812012-06-14 00:56:20 -0700248 return;
249 }
250 mOVInfo = mLkgo;
251}
252
253inline overlay::utils::Whf MdpCtrl::getSrcWhf() const {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700254 return utils::Whf( mOVInfo.src.width,
255 mOVInfo.src.height,
256 mOVInfo.src.format);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700257}
258
259inline void MdpCtrl::setSrcWhf(const overlay::utils::Whf& whf) {
260 mOVInfo.src.width = whf.w;
261 mOVInfo.src.height = whf.h;
262 mOVInfo.src.format = whf.format;
263}
264
265inline overlay::utils::Dim MdpCtrl::getSrcRectDim() const {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700266 return utils::Dim( mOVInfo.src_rect.x,
267 mOVInfo.src_rect.y,
268 mOVInfo.src_rect.w,
269 mOVInfo.src_rect.h);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700270}
271
272inline void MdpCtrl::setSrcRectDim(const overlay::utils::Dim d) {
273 mOVInfo.src_rect.x = d.x;
274 mOVInfo.src_rect.y = d.y;
275 mOVInfo.src_rect.w = d.w;
276 mOVInfo.src_rect.h = d.h;
277}
278
279inline overlay::utils::Dim MdpCtrl::getDstRectDim() const {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700280 return utils::Dim( mOVInfo.dst_rect.x,
281 mOVInfo.dst_rect.y,
282 mOVInfo.dst_rect.w,
283 mOVInfo.dst_rect.h);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700284}
285
286inline void MdpCtrl::setDstRectDim(const overlay::utils::Dim d) {
287 mOVInfo.dst_rect.x = d.x;
288 mOVInfo.dst_rect.y = d.y;
289 mOVInfo.dst_rect.w = d.w;
290 mOVInfo.dst_rect.h = d.h;
291}
292
293inline int MdpCtrl::getUserData() const { return mOVInfo.user_data[0]; }
294
295inline void MdpCtrl::setUserData(int v) { mOVInfo.user_data[0] = v; }
296
297inline void MdpCtrl::setRotationFlags() {
298 const int u = getUserData();
299 if (u == MDP_ROT_90 || u == MDP_ROT_270)
300 mOVInfo.flags |= MDP_SOURCE_ROTATED_90;
301 else
302 mOVInfo.flags &= ~MDP_SOURCE_ROTATED_90;
303}
304
Naseer Ahmed29a26812012-06-14 00:56:20 -0700305/////// MdpCtrl3D //////
306
307inline MdpCtrl3D::MdpCtrl3D() { reset(); }
308inline bool MdpCtrl3D::close() {
309 if (m3DOVInfo.is_3d) {
310 m3DOVInfo.is_3d = 0;
311 if(!mdp_wrapper::set3D(mFd.getFD(), m3DOVInfo)) {
312 ALOGE("MdpCtrl3D close failed set3D with 0");
313 return false;
314 }
315 }
316 reset();
317 return true;
318}
319inline void MdpCtrl3D::reset() {
320 utils::memset0(m3DOVInfo);
321}
322
323inline void MdpCtrl3D::setFd(int fd) {
324 mFd.copy(fd);
325 OVASSERT(mFd.valid(), "MdpCtrl3D setFd, FD should be valid");
326}
327
328inline void MdpCtrl3D::setWh(const utils::Whf& whf) {
329 // ignore fmt. Needed for useVirtualFB callflow
330 m3DOVInfo.width = whf.w;
331 m3DOVInfo.height = whf.h;
332}
333
334inline bool MdpCtrl3D::useVirtualFB() {
335 if(!m3DOVInfo.is_3d) {
336 m3DOVInfo.is_3d = 1;
337 if(!mdp_wrapper::set3D(mFd.getFD(), m3DOVInfo)) {
338 ALOGE("MdpCtrl3D close failed set3D with 0");
339 return false;
340 }
341 }
342 return true;
343}
344
345/////// MdpData //////
346
347inline MdpData::MdpData() { reset(); }
348
349inline MdpData::~MdpData() { close(); }
350
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700351inline bool MdpData::init(uint32_t fbnum) {
352 // FD init
353 if(!utils::openDev(mFd, fbnum, Res::fbPath, O_RDWR)){
354 ALOGE("Ctrl failed to init fbnum=%d", fbnum);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700355 return false;
356 }
357 return true;
358}
359
360inline void MdpData::reset() {
361 overlay::utils::memset0(mOvData);
362 mOvData.data.memory_id = -1;
363}
364
365inline bool MdpData::close() {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700366 reset();
Saurabh Shah8e1ae952012-08-15 12:15:14 -0700367 return mFd.close();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700368}
369
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700370inline int MdpData::getSrcMemoryId() const { return mOvData.data.memory_id; }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700371
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700372inline void MdpData::setPipeId(int id) { mOvData.id = id; }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700373
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700374inline int MdpData::getPipeId() const { return mOvData.id; }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700375
376inline int MdpData::getFd() const { return mFd.getFD(); }
377
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700378inline bool MdpData::play(int fd, uint32_t offset) {
379 mOvData.data.memory_id = fd;
380 mOvData.data.offset = offset;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700381 if(!mdp_wrapper::play(mFd.getFD(), mOvData)){
382 ALOGE("MdpData failed to play");
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700383 dump();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700384 return false;
385 }
386 return true;
387}
388
Naseer Ahmed29a26812012-06-14 00:56:20 -0700389} // overlay
390
391#endif // OVERLAY_MDP_H