blob: 843556b3cf1f2f584b17534accb2503869b9eb87 [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"
Saurabh Shah5daeee52013-01-23 16:52:26 +080025#include "qdMetaData.h"
26#ifdef USES_POST_PROCESSING
27#include "lib-postproc.h"
28#endif
Naseer Ahmed29a26812012-06-14 00:56:20 -070029
30namespace overlay{
31
Naseer Ahmed29a26812012-06-14 00:56:20 -070032/*
33* Mdp Ctrl holds corresponding fd and MDP related struct.
34* It is simple wrapper to MDP services
35* */
36class MdpCtrl {
37public:
38 /* ctor reset */
Saurabh Shahd18d88a2014-01-06 15:02:49 -080039 explicit MdpCtrl(const int& dpy);
Naseer Ahmed29a26812012-06-14 00:56:20 -070040 /* dtor close */
41 ~MdpCtrl();
Saurabh Shahb8f58e22013-09-26 16:20:07 -070042 /* init underlying device using fbnum for dpy */
Saurabh Shahd18d88a2014-01-06 15:02:49 -080043 bool init(const int& dpy);
Naseer Ahmed29a26812012-06-14 00:56:20 -070044 /* unset overlay, reset and close fd */
45 bool close();
Naseer Ahmedf48aef62012-07-20 09:05:53 -070046 /* reset and set ov id to -1 / MSMFB_NEW_REQUEST */
Naseer Ahmed29a26812012-06-14 00:56:20 -070047 void reset();
Naseer Ahmed29a26812012-06-14 00:56:20 -070048 /* calls overlay set
49 * Set would always consult last good known ov instance.
50 * Only if it is different, set would actually exectue ioctl.
51 * On a sucess ioctl. last good known ov instance is updated */
52 bool set();
Naseer Ahmedf48aef62012-07-20 09:05:53 -070053 /* Sets the source total width, height, format */
Saurabh Shahacf10202013-02-26 10:15:15 -080054 void setSource(const utils::PipeArgs& pargs);
Naseer Ahmed29a26812012-06-14 00:56:20 -070055 /*
56 * Sets ROI, the unpadded region, for source buffer.
Naseer Ahmed29a26812012-06-14 00:56:20 -070057 * Dim - ROI dimensions.
58 */
Saurabh Shahacf10202013-02-26 10:15:15 -080059 void setCrop(const utils::Dim& d);
Sushil Chauhan897a9c32013-07-18 11:09:55 -070060 /* set color for mdp pipe */
61 void setColor(const uint32_t color);
Saurabh Shahacf10202013-02-26 10:15:15 -080062 void setTransform(const utils::eTransform& orient);
Naseer Ahmed29a26812012-06-14 00:56:20 -070063 /* given a dim and w/h, set overlay dim */
Saurabh Shahacf10202013-02-26 10:15:15 -080064 void setPosition(const utils::Dim& dim);
Naseer Ahmed29a26812012-06-14 00:56:20 -070065 /* using user_data, sets/unsets roationvalue in mdp flags */
66 void setRotationFlags();
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -080067 /* Performs downscale calculations */
Saurabh Shahacf10202013-02-26 10:15:15 -080068 void setDownscale(int dscale_factor);
69 /* Update the src format with rotator's dest*/
70 void updateSrcFormat(const uint32_t& rotDstFormat);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -080071 /* dump state of the object */
72 void dump() const;
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -080073 /* Return the dump in the specified buffer */
74 void getDump(char *buf, size_t len);
Saurabh Shahacf10202013-02-26 10:15:15 -080075 /* returns session id */
76 int getPipeId() const;
77 /* returns the fd associated to ctrl*/
78 int getFd() const;
79 /* returns a copy ro dst rect dim */
80 utils::Dim getDstRectDim() const;
81 /* returns a copy to src rect dim */
82 utils::Dim getSrcRectDim() const;
Saurabh Shah5daeee52013-01-23 16:52:26 +080083 /* setVisualParam */
84 bool setVisualParams(const MetaData_t& data);
Naseer Ahmed29a26812012-06-14 00:56:20 -070085
Saurabh Shaha36be922013-12-16 18:18:39 -080086 static bool validateAndSet(MdpCtrl* mdpCtrlArray[], const int& count,
87 const int& fbFd);
Saurabh Shahacf10202013-02-26 10:15:15 -080088private:
89 /* Perform transformation calculations */
90 void doTransform();
91 void doDownscale();
92 /* get orient / user_data[0] */
Saurabh Shaha36be922013-12-16 18:18:39 -080093 int getOrient() const;
Saurabh Shahacf10202013-02-26 10:15:15 -080094 /* returns flags from mdp structure */
95 int getFlags() const;
96 /* set flags to mdp structure */
97 void setFlags(int f);
98 /* set z order */
99 void setZ(utils::eZorder z);
100 /* set isFg flag */
101 void setIsFg(utils::eIsFg isFg);
Naseer Ahmed522ce662013-03-18 20:14:05 -0400102 /* return a copy of src whf*/
Saurabh Shahacf10202013-02-26 10:15:15 -0800103 utils::Whf getSrcWhf() const;
Naseer Ahmed522ce662013-03-18 20:14:05 -0400104 /* set plane alpha */
105 void setPlaneAlpha(int planeAlpha);
106 /* set blending method */
107 void setBlending(overlay::utils::eBlending blending);
108
Saurabh Shahacf10202013-02-26 10:15:15 -0800109 /* set src whf */
110 void setSrcWhf(const utils::Whf& whf);
111 /* set src/dst rect dim */
112 void setSrcRectDim(const utils::Dim d);
113 void setDstRectDim(const utils::Dim d);
114 /* returns user_data[0]*/
115 int getUserData() const;
116 /* sets user_data[0] */
117 void setUserData(int v);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700118
119 utils::eTransform mOrientation; //Holds requested orientation
Naseer Ahmed29a26812012-06-14 00:56:20 -0700120 /* Actual overlay mdp structure */
121 mdp_overlay mOVInfo;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700122 /* FD for the mdp fbnum */
123 OvFD mFd;
Saurabh Shahacf10202013-02-26 10:15:15 -0800124 int mDownscale;
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700125 int mDpy;
Saurabh Shahdf0be752013-05-23 14:40:00 -0700126
Saurabh Shah5daeee52013-01-23 16:52:26 +0800127#ifdef USES_POST_PROCESSING
128 /* PP Compute Params */
129 struct compute_params mParams;
Saurabh Shah5daeee52013-01-23 16:52:26 +0800130#endif
Naseer Ahmed29a26812012-06-14 00:56:20 -0700131};
132
133
134/* MDP 3D related ctrl */
135class MdpCtrl3D {
136public:
137 /* ctor reset data */
138 MdpCtrl3D();
139 /* calls MSMFB_OVERLAY_3D */
140 bool close();
141 /* set w/h. format is ignored*/
142 void setWh(const utils::Whf& whf);
143 /* set is_3d calls MSMFB_OVERLAY_3D */
144 bool useVirtualFB();
145 /* set fd to be used in ioctl */
146 void setFd(int fd);
147 /* dump */
148 void dump() const;
149private:
150 /* reset */
151 void reset();
152 /* actual MSM 3D info */
153 msmfb_overlay_3d m3DOVInfo;
154 /* FD for the mdp 3D */
155 OvFD mFd;
156};
157
158/* MDP data */
159class MdpData {
160public:
161 /* ctor reset data */
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800162 explicit MdpData(const int& dpy);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700163 /* dtor close*/
164 ~MdpData();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700165 /* init FD */
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800166 bool init(const int& dpy);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700167 /* memset0 the underlying mdp object */
168 void reset();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700169 /* close fd, and reset */
170 bool close();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700171 /* set id of mdp data */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700172 void setPipeId(int id);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700173 /* return ses id of data */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700174 int getPipeId() const;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700175 /* get underlying fd*/
176 int getFd() const;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700177 /* get memory_id */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700178 int getSrcMemoryId() const;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700179 /* calls wrapper play */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700180 bool play(int fd, uint32_t offset);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700181 /* dump state of the object */
182 void dump() const;
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800183 /* Return the dump in the specified buffer */
184 void getDump(char *buf, size_t len);
185
Naseer Ahmed29a26812012-06-14 00:56:20 -0700186private:
187
188 /* actual overlay mdp data */
189 msmfb_overlay_data mOvData;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700190 /* fd to mdp fbnum */
191 OvFD mFd;
192};
193
194//--------------Inlines---------------------------------
Naseer Ahmed29a26812012-06-14 00:56:20 -0700195
196///// MdpCtrl //////
197
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800198inline MdpCtrl::MdpCtrl(const int& dpy) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700199 reset();
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800200 init(dpy);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700201}
202
203inline MdpCtrl::~MdpCtrl() {
204 close();
205}
206
207inline int MdpCtrl::getOrient() const {
208 return getUserData();
209}
210
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700211inline int MdpCtrl::getPipeId() const {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700212 return mOVInfo.id;
213}
214
215inline int MdpCtrl::getFd() const {
216 return mFd.getFD();
217}
218
219inline int MdpCtrl::getFlags() const {
220 return mOVInfo.flags;
221}
222
223inline void MdpCtrl::setFlags(int f) {
224 mOVInfo.flags = f;
225}
226
227inline void MdpCtrl::setZ(overlay::utils::eZorder z) {
228 mOVInfo.z_order = z;
229}
230
Naseer Ahmed29a26812012-06-14 00:56:20 -0700231inline void MdpCtrl::setIsFg(overlay::utils::eIsFg isFg) {
232 mOVInfo.is_fg = isFg;
233}
234
Saurabh Shahacf10202013-02-26 10:15:15 -0800235inline void MdpCtrl::setDownscale(int dscale) {
236 mDownscale = dscale;
237}
238
Naseer Ahmed522ce662013-03-18 20:14:05 -0400239inline void MdpCtrl::setPlaneAlpha(int planeAlpha) {
240 mOVInfo.alpha = planeAlpha;
241}
242
243inline void MdpCtrl::setBlending(overlay::utils::eBlending blending) {
244 switch((int) blending) {
245 case utils::OVERLAY_BLENDING_OPAQUE:
246 mOVInfo.blend_op = BLEND_OP_OPAQUE;
247 break;
248 case utils::OVERLAY_BLENDING_PREMULT:
249 mOVInfo.blend_op = BLEND_OP_PREMULTIPLIED;
250 break;
251 case utils::OVERLAY_BLENDING_COVERAGE:
252 default:
253 mOVInfo.blend_op = BLEND_OP_COVERAGE;
254 }
255}
256
Naseer Ahmed29a26812012-06-14 00:56:20 -0700257inline overlay::utils::Whf MdpCtrl::getSrcWhf() const {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700258 return utils::Whf( mOVInfo.src.width,
259 mOVInfo.src.height,
260 mOVInfo.src.format);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700261}
262
263inline void MdpCtrl::setSrcWhf(const overlay::utils::Whf& whf) {
264 mOVInfo.src.width = whf.w;
265 mOVInfo.src.height = whf.h;
266 mOVInfo.src.format = whf.format;
267}
268
269inline overlay::utils::Dim MdpCtrl::getSrcRectDim() const {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700270 return utils::Dim( mOVInfo.src_rect.x,
271 mOVInfo.src_rect.y,
272 mOVInfo.src_rect.w,
273 mOVInfo.src_rect.h);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700274}
275
276inline void MdpCtrl::setSrcRectDim(const overlay::utils::Dim d) {
277 mOVInfo.src_rect.x = d.x;
278 mOVInfo.src_rect.y = d.y;
279 mOVInfo.src_rect.w = d.w;
280 mOVInfo.src_rect.h = d.h;
281}
282
283inline overlay::utils::Dim MdpCtrl::getDstRectDim() const {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700284 return utils::Dim( mOVInfo.dst_rect.x,
285 mOVInfo.dst_rect.y,
286 mOVInfo.dst_rect.w,
287 mOVInfo.dst_rect.h);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700288}
289
290inline void MdpCtrl::setDstRectDim(const overlay::utils::Dim d) {
291 mOVInfo.dst_rect.x = d.x;
292 mOVInfo.dst_rect.y = d.y;
293 mOVInfo.dst_rect.w = d.w;
294 mOVInfo.dst_rect.h = d.h;
295}
296
297inline int MdpCtrl::getUserData() const { return mOVInfo.user_data[0]; }
298
299inline void MdpCtrl::setUserData(int v) { mOVInfo.user_data[0] = v; }
300
301inline void MdpCtrl::setRotationFlags() {
302 const int u = getUserData();
Saurabh Shah76fd6552013-03-14 14:45:38 -0700303 if (u & MDP_ROT_90)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700304 mOVInfo.flags |= MDP_SOURCE_ROTATED_90;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700305}
306
Naseer Ahmed29a26812012-06-14 00:56:20 -0700307/////// MdpCtrl3D //////
308
309inline MdpCtrl3D::MdpCtrl3D() { reset(); }
310inline bool MdpCtrl3D::close() {
311 if (m3DOVInfo.is_3d) {
312 m3DOVInfo.is_3d = 0;
313 if(!mdp_wrapper::set3D(mFd.getFD(), m3DOVInfo)) {
314 ALOGE("MdpCtrl3D close failed set3D with 0");
315 return false;
316 }
317 }
318 reset();
319 return true;
320}
321inline void MdpCtrl3D::reset() {
322 utils::memset0(m3DOVInfo);
323}
324
325inline void MdpCtrl3D::setFd(int fd) {
326 mFd.copy(fd);
327 OVASSERT(mFd.valid(), "MdpCtrl3D setFd, FD should be valid");
328}
329
330inline void MdpCtrl3D::setWh(const utils::Whf& whf) {
331 // ignore fmt. Needed for useVirtualFB callflow
332 m3DOVInfo.width = whf.w;
333 m3DOVInfo.height = whf.h;
334}
335
336inline bool MdpCtrl3D::useVirtualFB() {
337 if(!m3DOVInfo.is_3d) {
338 m3DOVInfo.is_3d = 1;
339 if(!mdp_wrapper::set3D(mFd.getFD(), m3DOVInfo)) {
340 ALOGE("MdpCtrl3D close failed set3D with 0");
341 return false;
342 }
343 }
344 return true;
345}
346
347/////// MdpData //////
348
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800349inline MdpData::MdpData(const int& dpy) {
350 reset();
351 init(dpy);
352}
Naseer Ahmed29a26812012-06-14 00:56:20 -0700353
354inline MdpData::~MdpData() { close(); }
355
Naseer Ahmed29a26812012-06-14 00:56:20 -0700356inline void MdpData::reset() {
357 overlay::utils::memset0(mOvData);
358 mOvData.data.memory_id = -1;
359}
360
361inline bool MdpData::close() {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700362 reset();
Saurabh Shah8e1ae952012-08-15 12:15:14 -0700363 return mFd.close();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700364}
365
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700366inline int MdpData::getSrcMemoryId() const { return mOvData.data.memory_id; }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700367
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700368inline void MdpData::setPipeId(int id) { mOvData.id = id; }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700369
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700370inline int MdpData::getPipeId() const { return mOvData.id; }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700371
372inline int MdpData::getFd() const { return mFd.getFD(); }
373
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700374inline bool MdpData::play(int fd, uint32_t offset) {
375 mOvData.data.memory_id = fd;
376 mOvData.data.offset = offset;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700377 if(!mdp_wrapper::play(mFd.getFD(), mOvData)){
378 ALOGE("MdpData failed to play");
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700379 dump();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700380 return false;
381 }
382 return true;
383}
384
Naseer Ahmed29a26812012-06-14 00:56:20 -0700385} // overlay
386
387#endif // OVERLAY_MDP_H