blob: daaeaf23ccacdd786e29eb6c2ed073b138817f07 [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);
75
Saurabh Shahacf10202013-02-26 10:15:15 -080076 /* returns session id */
77 int getPipeId() const;
78 /* returns the fd associated to ctrl*/
79 int getFd() const;
80 /* returns a copy ro dst rect dim */
81 utils::Dim getDstRectDim() const;
82 /* returns a copy to src rect dim */
83 utils::Dim getSrcRectDim() const;
Saurabh Shah5daeee52013-01-23 16:52:26 +080084 /* setVisualParam */
85 bool setVisualParams(const MetaData_t& data);
Naseer Ahmed29a26812012-06-14 00:56:20 -070086
Saurabh Shahacf10202013-02-26 10:15:15 -080087private:
88 /* Perform transformation calculations */
89 void doTransform();
90 void doDownscale();
91 /* get orient / user_data[0] */
92 int getOrient() const;
93 /* overlay get */
94 bool get();
95 /* returns flags from mdp structure */
96 int getFlags() const;
97 /* set flags to mdp structure */
98 void setFlags(int f);
99 /* set z order */
100 void setZ(utils::eZorder z);
101 /* set isFg flag */
102 void setIsFg(utils::eIsFg isFg);
Naseer Ahmed522ce662013-03-18 20:14:05 -0400103 /* return a copy of src whf*/
Saurabh Shahacf10202013-02-26 10:15:15 -0800104 utils::Whf getSrcWhf() const;
Naseer Ahmed522ce662013-03-18 20:14:05 -0400105 /* set plane alpha */
106 void setPlaneAlpha(int planeAlpha);
107 /* set blending method */
108 void setBlending(overlay::utils::eBlending blending);
109
Saurabh Shahacf10202013-02-26 10:15:15 -0800110 /* set src whf */
111 void setSrcWhf(const utils::Whf& whf);
112 /* set src/dst rect dim */
113 void setSrcRectDim(const utils::Dim d);
114 void setDstRectDim(const utils::Dim d);
115 /* returns user_data[0]*/
116 int getUserData() const;
117 /* sets user_data[0] */
118 void setUserData(int v);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700119
120 utils::eTransform mOrientation; //Holds requested orientation
Naseer Ahmed29a26812012-06-14 00:56:20 -0700121 /* Actual overlay mdp structure */
122 mdp_overlay mOVInfo;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700123 /* FD for the mdp fbnum */
124 OvFD mFd;
Saurabh Shahacf10202013-02-26 10:15:15 -0800125 int mDownscale;
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700126 int mDpy;
Saurabh Shahdf0be752013-05-23 14:40:00 -0700127
Saurabh Shah5daeee52013-01-23 16:52:26 +0800128#ifdef USES_POST_PROCESSING
129 /* PP Compute Params */
130 struct compute_params mParams;
Saurabh Shah5daeee52013-01-23 16:52:26 +0800131#endif
Naseer Ahmed29a26812012-06-14 00:56:20 -0700132};
133
134
135/* MDP 3D related ctrl */
136class MdpCtrl3D {
137public:
138 /* ctor reset data */
139 MdpCtrl3D();
140 /* calls MSMFB_OVERLAY_3D */
141 bool close();
142 /* set w/h. format is ignored*/
143 void setWh(const utils::Whf& whf);
144 /* set is_3d calls MSMFB_OVERLAY_3D */
145 bool useVirtualFB();
146 /* set fd to be used in ioctl */
147 void setFd(int fd);
148 /* dump */
149 void dump() const;
150private:
151 /* reset */
152 void reset();
153 /* actual MSM 3D info */
154 msmfb_overlay_3d m3DOVInfo;
155 /* FD for the mdp 3D */
156 OvFD mFd;
157};
158
159/* MDP data */
160class MdpData {
161public:
162 /* ctor reset data */
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800163 explicit MdpData(const int& dpy);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700164 /* dtor close*/
165 ~MdpData();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700166 /* init FD */
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800167 bool init(const int& dpy);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700168 /* memset0 the underlying mdp object */
169 void reset();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700170 /* close fd, and reset */
171 bool close();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700172 /* set id of mdp data */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700173 void setPipeId(int id);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700174 /* return ses id of data */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700175 int getPipeId() const;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700176 /* get underlying fd*/
177 int getFd() const;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700178 /* get memory_id */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700179 int getSrcMemoryId() const;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700180 /* calls wrapper play */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700181 bool play(int fd, uint32_t offset);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700182 /* dump state of the object */
183 void dump() const;
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800184 /* Return the dump in the specified buffer */
185 void getDump(char *buf, size_t len);
186
Naseer Ahmed29a26812012-06-14 00:56:20 -0700187private:
188
189 /* actual overlay mdp data */
190 msmfb_overlay_data mOvData;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700191 /* fd to mdp fbnum */
192 OvFD mFd;
193};
194
195//--------------Inlines---------------------------------
Naseer Ahmed29a26812012-06-14 00:56:20 -0700196
197///// MdpCtrl //////
198
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800199inline MdpCtrl::MdpCtrl(const int& dpy) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700200 reset();
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800201 init(dpy);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700202}
203
204inline MdpCtrl::~MdpCtrl() {
205 close();
206}
207
208inline int MdpCtrl::getOrient() const {
209 return getUserData();
210}
211
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700212inline int MdpCtrl::getPipeId() const {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700213 return mOVInfo.id;
214}
215
216inline int MdpCtrl::getFd() const {
217 return mFd.getFD();
218}
219
220inline int MdpCtrl::getFlags() const {
221 return mOVInfo.flags;
222}
223
224inline void MdpCtrl::setFlags(int f) {
225 mOVInfo.flags = f;
226}
227
228inline void MdpCtrl::setZ(overlay::utils::eZorder z) {
229 mOVInfo.z_order = z;
230}
231
Naseer Ahmed29a26812012-06-14 00:56:20 -0700232inline void MdpCtrl::setIsFg(overlay::utils::eIsFg isFg) {
233 mOVInfo.is_fg = isFg;
234}
235
Saurabh Shahacf10202013-02-26 10:15:15 -0800236inline void MdpCtrl::setDownscale(int dscale) {
237 mDownscale = dscale;
238}
239
Naseer Ahmed522ce662013-03-18 20:14:05 -0400240inline void MdpCtrl::setPlaneAlpha(int planeAlpha) {
241 mOVInfo.alpha = planeAlpha;
242}
243
244inline void MdpCtrl::setBlending(overlay::utils::eBlending blending) {
245 switch((int) blending) {
246 case utils::OVERLAY_BLENDING_OPAQUE:
247 mOVInfo.blend_op = BLEND_OP_OPAQUE;
248 break;
249 case utils::OVERLAY_BLENDING_PREMULT:
250 mOVInfo.blend_op = BLEND_OP_PREMULTIPLIED;
251 break;
252 case utils::OVERLAY_BLENDING_COVERAGE:
253 default:
254 mOVInfo.blend_op = BLEND_OP_COVERAGE;
255 }
256}
257
Naseer Ahmed29a26812012-06-14 00:56:20 -0700258inline overlay::utils::Whf MdpCtrl::getSrcWhf() const {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700259 return utils::Whf( mOVInfo.src.width,
260 mOVInfo.src.height,
261 mOVInfo.src.format);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700262}
263
264inline void MdpCtrl::setSrcWhf(const overlay::utils::Whf& whf) {
265 mOVInfo.src.width = whf.w;
266 mOVInfo.src.height = whf.h;
267 mOVInfo.src.format = whf.format;
268}
269
270inline overlay::utils::Dim MdpCtrl::getSrcRectDim() const {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700271 return utils::Dim( mOVInfo.src_rect.x,
272 mOVInfo.src_rect.y,
273 mOVInfo.src_rect.w,
274 mOVInfo.src_rect.h);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700275}
276
277inline void MdpCtrl::setSrcRectDim(const overlay::utils::Dim d) {
278 mOVInfo.src_rect.x = d.x;
279 mOVInfo.src_rect.y = d.y;
280 mOVInfo.src_rect.w = d.w;
281 mOVInfo.src_rect.h = d.h;
282}
283
284inline overlay::utils::Dim MdpCtrl::getDstRectDim() const {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700285 return utils::Dim( mOVInfo.dst_rect.x,
286 mOVInfo.dst_rect.y,
287 mOVInfo.dst_rect.w,
288 mOVInfo.dst_rect.h);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700289}
290
291inline void MdpCtrl::setDstRectDim(const overlay::utils::Dim d) {
292 mOVInfo.dst_rect.x = d.x;
293 mOVInfo.dst_rect.y = d.y;
294 mOVInfo.dst_rect.w = d.w;
295 mOVInfo.dst_rect.h = d.h;
296}
297
298inline int MdpCtrl::getUserData() const { return mOVInfo.user_data[0]; }
299
300inline void MdpCtrl::setUserData(int v) { mOVInfo.user_data[0] = v; }
301
302inline void MdpCtrl::setRotationFlags() {
303 const int u = getUserData();
Saurabh Shah76fd6552013-03-14 14:45:38 -0700304 if (u & MDP_ROT_90)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700305 mOVInfo.flags |= MDP_SOURCE_ROTATED_90;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700306}
307
Naseer Ahmed29a26812012-06-14 00:56:20 -0700308/////// MdpCtrl3D //////
309
310inline MdpCtrl3D::MdpCtrl3D() { reset(); }
311inline bool MdpCtrl3D::close() {
312 if (m3DOVInfo.is_3d) {
313 m3DOVInfo.is_3d = 0;
314 if(!mdp_wrapper::set3D(mFd.getFD(), m3DOVInfo)) {
315 ALOGE("MdpCtrl3D close failed set3D with 0");
316 return false;
317 }
318 }
319 reset();
320 return true;
321}
322inline void MdpCtrl3D::reset() {
323 utils::memset0(m3DOVInfo);
324}
325
326inline void MdpCtrl3D::setFd(int fd) {
327 mFd.copy(fd);
328 OVASSERT(mFd.valid(), "MdpCtrl3D setFd, FD should be valid");
329}
330
331inline void MdpCtrl3D::setWh(const utils::Whf& whf) {
332 // ignore fmt. Needed for useVirtualFB callflow
333 m3DOVInfo.width = whf.w;
334 m3DOVInfo.height = whf.h;
335}
336
337inline bool MdpCtrl3D::useVirtualFB() {
338 if(!m3DOVInfo.is_3d) {
339 m3DOVInfo.is_3d = 1;
340 if(!mdp_wrapper::set3D(mFd.getFD(), m3DOVInfo)) {
341 ALOGE("MdpCtrl3D close failed set3D with 0");
342 return false;
343 }
344 }
345 return true;
346}
347
348/////// MdpData //////
349
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800350inline MdpData::MdpData(const int& dpy) {
351 reset();
352 init(dpy);
353}
Naseer Ahmed29a26812012-06-14 00:56:20 -0700354
355inline MdpData::~MdpData() { close(); }
356
Naseer Ahmed29a26812012-06-14 00:56:20 -0700357inline void MdpData::reset() {
358 overlay::utils::memset0(mOvData);
359 mOvData.data.memory_id = -1;
360}
361
362inline bool MdpData::close() {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700363 reset();
Saurabh Shah8e1ae952012-08-15 12:15:14 -0700364 return mFd.close();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700365}
366
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700367inline int MdpData::getSrcMemoryId() const { return mOvData.data.memory_id; }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700368
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700369inline void MdpData::setPipeId(int id) { mOvData.id = id; }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700370
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700371inline int MdpData::getPipeId() const { return mOvData.id; }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700372
373inline int MdpData::getFd() const { return mFd.getFD(); }
374
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700375inline bool MdpData::play(int fd, uint32_t offset) {
376 mOvData.data.memory_id = fd;
377 mOvData.data.offset = offset;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700378 if(!mdp_wrapper::play(mFd.getFD(), mOvData)){
379 ALOGE("MdpData failed to play");
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700380 dump();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700381 return false;
382 }
383 return true;
384}
385
Naseer Ahmed29a26812012-06-14 00:56:20 -0700386} // overlay
387
388#endif // OVERLAY_MDP_H