blob: d312c2ef83b2ecb1a2c28c0cda771edf03e3befd [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 Shahdd8237a2014-02-28 14:29:09 -080083 /* return pipe priority */
84 uint8_t getPriority() const;
Saurabh Shah5daeee52013-01-23 16:52:26 +080085 /* setVisualParam */
86 bool setVisualParams(const MetaData_t& data);
Naseer Ahmed29a26812012-06-14 00:56:20 -070087
Saurabh Shaha36be922013-12-16 18:18:39 -080088 static bool validateAndSet(MdpCtrl* mdpCtrlArray[], const int& count,
89 const int& fbFd);
Saurabh Shahacf10202013-02-26 10:15:15 -080090private:
91 /* Perform transformation calculations */
92 void doTransform();
93 void doDownscale();
94 /* get orient / user_data[0] */
Saurabh Shaha36be922013-12-16 18:18:39 -080095 int getOrient() const;
Saurabh Shahacf10202013-02-26 10:15:15 -080096 /* returns flags from mdp structure */
97 int getFlags() const;
98 /* set flags to mdp structure */
99 void setFlags(int f);
100 /* set z order */
101 void setZ(utils::eZorder z);
102 /* set isFg flag */
103 void setIsFg(utils::eIsFg isFg);
Naseer Ahmed522ce662013-03-18 20:14:05 -0400104 /* return a copy of src whf*/
Saurabh Shahacf10202013-02-26 10:15:15 -0800105 utils::Whf getSrcWhf() const;
Naseer Ahmed522ce662013-03-18 20:14:05 -0400106 /* set plane alpha */
107 void setPlaneAlpha(int planeAlpha);
108 /* set blending method */
109 void setBlending(overlay::utils::eBlending blending);
110
Saurabh Shahacf10202013-02-26 10:15:15 -0800111 /* set src whf */
112 void setSrcWhf(const utils::Whf& whf);
113 /* set src/dst rect dim */
114 void setSrcRectDim(const utils::Dim d);
115 void setDstRectDim(const utils::Dim d);
116 /* returns user_data[0]*/
117 int getUserData() const;
118 /* sets user_data[0] */
119 void setUserData(int v);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700120
121 utils::eTransform mOrientation; //Holds requested orientation
Naseer Ahmed29a26812012-06-14 00:56:20 -0700122 /* Actual overlay mdp structure */
123 mdp_overlay mOVInfo;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700124 /* FD for the mdp fbnum */
125 OvFD mFd;
Saurabh Shahacf10202013-02-26 10:15:15 -0800126 int mDownscale;
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700127 int mDpy;
Saurabh Shahdf0be752013-05-23 14:40:00 -0700128
Saurabh Shah5daeee52013-01-23 16:52:26 +0800129#ifdef USES_POST_PROCESSING
130 /* PP Compute Params */
131 struct compute_params mParams;
Saurabh Shah5daeee52013-01-23 16:52:26 +0800132#endif
Naseer Ahmed29a26812012-06-14 00:56:20 -0700133};
134
135
136/* MDP 3D related ctrl */
137class MdpCtrl3D {
138public:
139 /* ctor reset data */
140 MdpCtrl3D();
141 /* calls MSMFB_OVERLAY_3D */
142 bool close();
143 /* set w/h. format is ignored*/
144 void setWh(const utils::Whf& whf);
145 /* set is_3d calls MSMFB_OVERLAY_3D */
146 bool useVirtualFB();
147 /* set fd to be used in ioctl */
148 void setFd(int fd);
149 /* dump */
150 void dump() const;
151private:
152 /* reset */
153 void reset();
154 /* actual MSM 3D info */
155 msmfb_overlay_3d m3DOVInfo;
156 /* FD for the mdp 3D */
157 OvFD mFd;
158};
159
160/* MDP data */
161class MdpData {
162public:
163 /* ctor reset data */
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800164 explicit MdpData(const int& dpy);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700165 /* dtor close*/
166 ~MdpData();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700167 /* init FD */
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800168 bool init(const int& dpy);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700169 /* memset0 the underlying mdp object */
170 void reset();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700171 /* close fd, and reset */
172 bool close();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700173 /* set id of mdp data */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700174 void setPipeId(int id);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700175 /* return ses id of data */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700176 int getPipeId() const;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700177 /* get underlying fd*/
178 int getFd() const;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700179 /* get memory_id */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700180 int getSrcMemoryId() const;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700181 /* calls wrapper play */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700182 bool play(int fd, uint32_t offset);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700183 /* dump state of the object */
184 void dump() const;
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800185 /* Return the dump in the specified buffer */
186 void getDump(char *buf, size_t len);
187
Naseer Ahmed29a26812012-06-14 00:56:20 -0700188private:
189
190 /* actual overlay mdp data */
191 msmfb_overlay_data mOvData;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700192 /* fd to mdp fbnum */
193 OvFD mFd;
194};
195
196//--------------Inlines---------------------------------
Naseer Ahmed29a26812012-06-14 00:56:20 -0700197
198///// MdpCtrl //////
199
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800200inline MdpCtrl::MdpCtrl(const int& dpy) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700201 reset();
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800202 init(dpy);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700203}
204
205inline MdpCtrl::~MdpCtrl() {
206 close();
207}
208
209inline int MdpCtrl::getOrient() const {
210 return getUserData();
211}
212
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700213inline int MdpCtrl::getPipeId() const {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700214 return mOVInfo.id;
215}
216
217inline int MdpCtrl::getFd() const {
218 return mFd.getFD();
219}
220
221inline int MdpCtrl::getFlags() const {
222 return mOVInfo.flags;
223}
224
225inline void MdpCtrl::setFlags(int f) {
226 mOVInfo.flags = f;
227}
228
229inline void MdpCtrl::setZ(overlay::utils::eZorder z) {
230 mOVInfo.z_order = z;
231}
232
Naseer Ahmed29a26812012-06-14 00:56:20 -0700233inline void MdpCtrl::setIsFg(overlay::utils::eIsFg isFg) {
234 mOVInfo.is_fg = isFg;
235}
236
Saurabh Shahacf10202013-02-26 10:15:15 -0800237inline void MdpCtrl::setDownscale(int dscale) {
238 mDownscale = dscale;
239}
240
Naseer Ahmed522ce662013-03-18 20:14:05 -0400241inline void MdpCtrl::setPlaneAlpha(int planeAlpha) {
242 mOVInfo.alpha = planeAlpha;
243}
244
245inline void MdpCtrl::setBlending(overlay::utils::eBlending blending) {
246 switch((int) blending) {
247 case utils::OVERLAY_BLENDING_OPAQUE:
248 mOVInfo.blend_op = BLEND_OP_OPAQUE;
249 break;
250 case utils::OVERLAY_BLENDING_PREMULT:
251 mOVInfo.blend_op = BLEND_OP_PREMULTIPLIED;
252 break;
253 case utils::OVERLAY_BLENDING_COVERAGE:
254 default:
255 mOVInfo.blend_op = BLEND_OP_COVERAGE;
256 }
257}
258
Naseer Ahmed29a26812012-06-14 00:56:20 -0700259inline overlay::utils::Whf MdpCtrl::getSrcWhf() const {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700260 return utils::Whf( mOVInfo.src.width,
261 mOVInfo.src.height,
262 mOVInfo.src.format);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700263}
264
265inline void MdpCtrl::setSrcWhf(const overlay::utils::Whf& whf) {
266 mOVInfo.src.width = whf.w;
267 mOVInfo.src.height = whf.h;
268 mOVInfo.src.format = whf.format;
269}
270
271inline overlay::utils::Dim MdpCtrl::getSrcRectDim() const {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700272 return utils::Dim( mOVInfo.src_rect.x,
273 mOVInfo.src_rect.y,
274 mOVInfo.src_rect.w,
275 mOVInfo.src_rect.h);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700276}
277
278inline void MdpCtrl::setSrcRectDim(const overlay::utils::Dim d) {
279 mOVInfo.src_rect.x = d.x;
280 mOVInfo.src_rect.y = d.y;
281 mOVInfo.src_rect.w = d.w;
282 mOVInfo.src_rect.h = d.h;
283}
284
285inline overlay::utils::Dim MdpCtrl::getDstRectDim() const {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700286 return utils::Dim( mOVInfo.dst_rect.x,
287 mOVInfo.dst_rect.y,
288 mOVInfo.dst_rect.w,
289 mOVInfo.dst_rect.h);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700290}
291
292inline void MdpCtrl::setDstRectDim(const overlay::utils::Dim d) {
293 mOVInfo.dst_rect.x = d.x;
294 mOVInfo.dst_rect.y = d.y;
295 mOVInfo.dst_rect.w = d.w;
296 mOVInfo.dst_rect.h = d.h;
297}
298
299inline int MdpCtrl::getUserData() const { return mOVInfo.user_data[0]; }
300
301inline void MdpCtrl::setUserData(int v) { mOVInfo.user_data[0] = v; }
302
303inline void MdpCtrl::setRotationFlags() {
304 const int u = getUserData();
Saurabh Shah76fd6552013-03-14 14:45:38 -0700305 if (u & MDP_ROT_90)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700306 mOVInfo.flags |= MDP_SOURCE_ROTATED_90;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700307}
308
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800309inline uint8_t MdpCtrl::getPriority() const {
310 return mOVInfo.priority;
311}
312
Naseer Ahmed29a26812012-06-14 00:56:20 -0700313/////// MdpCtrl3D //////
314
315inline MdpCtrl3D::MdpCtrl3D() { reset(); }
316inline bool MdpCtrl3D::close() {
317 if (m3DOVInfo.is_3d) {
318 m3DOVInfo.is_3d = 0;
319 if(!mdp_wrapper::set3D(mFd.getFD(), m3DOVInfo)) {
320 ALOGE("MdpCtrl3D close failed set3D with 0");
321 return false;
322 }
323 }
324 reset();
325 return true;
326}
327inline void MdpCtrl3D::reset() {
328 utils::memset0(m3DOVInfo);
329}
330
331inline void MdpCtrl3D::setFd(int fd) {
332 mFd.copy(fd);
333 OVASSERT(mFd.valid(), "MdpCtrl3D setFd, FD should be valid");
334}
335
336inline void MdpCtrl3D::setWh(const utils::Whf& whf) {
337 // ignore fmt. Needed for useVirtualFB callflow
338 m3DOVInfo.width = whf.w;
339 m3DOVInfo.height = whf.h;
340}
341
342inline bool MdpCtrl3D::useVirtualFB() {
343 if(!m3DOVInfo.is_3d) {
344 m3DOVInfo.is_3d = 1;
345 if(!mdp_wrapper::set3D(mFd.getFD(), m3DOVInfo)) {
346 ALOGE("MdpCtrl3D close failed set3D with 0");
347 return false;
348 }
349 }
350 return true;
351}
352
353/////// MdpData //////
354
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800355inline MdpData::MdpData(const int& dpy) {
356 reset();
357 init(dpy);
358}
Naseer Ahmed29a26812012-06-14 00:56:20 -0700359
360inline MdpData::~MdpData() { close(); }
361
Naseer Ahmed29a26812012-06-14 00:56:20 -0700362inline void MdpData::reset() {
363 overlay::utils::memset0(mOvData);
364 mOvData.data.memory_id = -1;
365}
366
367inline bool MdpData::close() {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700368 reset();
Saurabh Shah8e1ae952012-08-15 12:15:14 -0700369 return mFd.close();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700370}
371
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700372inline int MdpData::getSrcMemoryId() const { return mOvData.data.memory_id; }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700373
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700374inline void MdpData::setPipeId(int id) { mOvData.id = id; }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700375
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700376inline int MdpData::getPipeId() const { return mOvData.id; }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700377
378inline int MdpData::getFd() const { return mFd.getFD(); }
379
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700380inline bool MdpData::play(int fd, uint32_t offset) {
381 mOvData.data.memory_id = fd;
382 mOvData.data.offset = offset;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700383 if(!mdp_wrapper::play(mFd.getFD(), mOvData)){
384 ALOGE("MdpData failed to play");
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700385 dump();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700386 return false;
387 }
388 return true;
389}
390
Naseer Ahmed29a26812012-06-14 00:56:20 -0700391} // overlay
392
393#endif // OVERLAY_MDP_H