blob: f7d64f0d6d0124388a57cb3f7a6814edbf47dc83 [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);
radhakrishna8ccb9082014-05-09 16:18:43 +053087 /* sets pipe type RGB/DMA/VG */
88 void setPipeType(const utils::eMdpPipeType& pType);
Naseer Ahmed29a26812012-06-14 00:56:20 -070089
Saurabh Shaha36be922013-12-16 18:18:39 -080090 static bool validateAndSet(MdpCtrl* mdpCtrlArray[], const int& count,
91 const int& fbFd);
Saurabh Shahacf10202013-02-26 10:15:15 -080092private:
93 /* Perform transformation calculations */
94 void doTransform();
95 void doDownscale();
96 /* get orient / user_data[0] */
Saurabh Shaha36be922013-12-16 18:18:39 -080097 int getOrient() const;
Saurabh Shahacf10202013-02-26 10:15:15 -080098 /* returns flags from mdp structure */
99 int getFlags() const;
100 /* set flags to mdp structure */
101 void setFlags(int f);
102 /* set z order */
103 void setZ(utils::eZorder z);
104 /* set isFg flag */
105 void setIsFg(utils::eIsFg isFg);
Naseer Ahmed522ce662013-03-18 20:14:05 -0400106 /* return a copy of src whf*/
Saurabh Shahacf10202013-02-26 10:15:15 -0800107 utils::Whf getSrcWhf() const;
Naseer Ahmed522ce662013-03-18 20:14:05 -0400108 /* set plane alpha */
109 void setPlaneAlpha(int planeAlpha);
110 /* set blending method */
111 void setBlending(overlay::utils::eBlending blending);
112
Saurabh Shahacf10202013-02-26 10:15:15 -0800113 /* set src whf */
114 void setSrcWhf(const utils::Whf& whf);
115 /* set src/dst rect dim */
116 void setSrcRectDim(const utils::Dim d);
117 void setDstRectDim(const utils::Dim d);
118 /* returns user_data[0]*/
119 int getUserData() const;
120 /* sets user_data[0] */
121 void setUserData(int v);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700122
123 utils::eTransform mOrientation; //Holds requested orientation
Naseer Ahmed29a26812012-06-14 00:56:20 -0700124 /* Actual overlay mdp structure */
125 mdp_overlay mOVInfo;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700126 /* FD for the mdp fbnum */
127 OvFD mFd;
Saurabh Shahacf10202013-02-26 10:15:15 -0800128 int mDownscale;
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700129 int mDpy;
Saurabh Shahdf0be752013-05-23 14:40:00 -0700130
Saurabh Shah5daeee52013-01-23 16:52:26 +0800131#ifdef USES_POST_PROCESSING
132 /* PP Compute Params */
133 struct compute_params mParams;
Saurabh Shah5daeee52013-01-23 16:52:26 +0800134#endif
Naseer Ahmed29a26812012-06-14 00:56:20 -0700135};
136
137
138/* MDP 3D related ctrl */
139class MdpCtrl3D {
140public:
141 /* ctor reset data */
142 MdpCtrl3D();
143 /* calls MSMFB_OVERLAY_3D */
144 bool close();
145 /* set w/h. format is ignored*/
146 void setWh(const utils::Whf& whf);
147 /* set is_3d calls MSMFB_OVERLAY_3D */
148 bool useVirtualFB();
149 /* set fd to be used in ioctl */
150 void setFd(int fd);
151 /* dump */
152 void dump() const;
153private:
154 /* reset */
155 void reset();
156 /* actual MSM 3D info */
157 msmfb_overlay_3d m3DOVInfo;
158 /* FD for the mdp 3D */
159 OvFD mFd;
160};
161
162/* MDP data */
163class MdpData {
164public:
165 /* ctor reset data */
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800166 explicit MdpData(const int& dpy);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700167 /* dtor close*/
168 ~MdpData();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700169 /* init FD */
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800170 bool init(const int& dpy);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700171 /* memset0 the underlying mdp object */
172 void reset();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700173 /* close fd, and reset */
174 bool close();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700175 /* set id of mdp data */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700176 void setPipeId(int id);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700177 /* return ses id of data */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700178 int getPipeId() const;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700179 /* get underlying fd*/
180 int getFd() const;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700181 /* get memory_id */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700182 int getSrcMemoryId() const;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700183 /* calls wrapper play */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700184 bool play(int fd, uint32_t offset);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700185 /* dump state of the object */
186 void dump() const;
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800187 /* Return the dump in the specified buffer */
188 void getDump(char *buf, size_t len);
189
Naseer Ahmed29a26812012-06-14 00:56:20 -0700190private:
191
192 /* actual overlay mdp data */
193 msmfb_overlay_data mOvData;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700194 /* fd to mdp fbnum */
195 OvFD mFd;
196};
197
198//--------------Inlines---------------------------------
Naseer Ahmed29a26812012-06-14 00:56:20 -0700199
200///// MdpCtrl //////
201
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800202inline MdpCtrl::MdpCtrl(const int& dpy) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700203 reset();
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800204 init(dpy);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700205}
206
207inline MdpCtrl::~MdpCtrl() {
208 close();
209}
210
211inline int MdpCtrl::getOrient() const {
212 return getUserData();
213}
214
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700215inline int MdpCtrl::getPipeId() const {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700216 return mOVInfo.id;
217}
218
219inline int MdpCtrl::getFd() const {
220 return mFd.getFD();
221}
222
223inline int MdpCtrl::getFlags() const {
224 return mOVInfo.flags;
225}
226
227inline void MdpCtrl::setFlags(int f) {
228 mOVInfo.flags = f;
229}
230
231inline void MdpCtrl::setZ(overlay::utils::eZorder z) {
232 mOVInfo.z_order = z;
233}
234
Naseer Ahmed29a26812012-06-14 00:56:20 -0700235inline void MdpCtrl::setIsFg(overlay::utils::eIsFg isFg) {
236 mOVInfo.is_fg = isFg;
237}
238
Saurabh Shahacf10202013-02-26 10:15:15 -0800239inline void MdpCtrl::setDownscale(int dscale) {
240 mDownscale = dscale;
241}
242
Naseer Ahmed522ce662013-03-18 20:14:05 -0400243inline void MdpCtrl::setPlaneAlpha(int planeAlpha) {
244 mOVInfo.alpha = planeAlpha;
245}
246
247inline void MdpCtrl::setBlending(overlay::utils::eBlending blending) {
248 switch((int) blending) {
249 case utils::OVERLAY_BLENDING_OPAQUE:
250 mOVInfo.blend_op = BLEND_OP_OPAQUE;
251 break;
252 case utils::OVERLAY_BLENDING_PREMULT:
253 mOVInfo.blend_op = BLEND_OP_PREMULTIPLIED;
254 break;
255 case utils::OVERLAY_BLENDING_COVERAGE:
256 default:
257 mOVInfo.blend_op = BLEND_OP_COVERAGE;
258 }
259}
260
Naseer Ahmed29a26812012-06-14 00:56:20 -0700261inline overlay::utils::Whf MdpCtrl::getSrcWhf() const {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700262 return utils::Whf( mOVInfo.src.width,
263 mOVInfo.src.height,
264 mOVInfo.src.format);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700265}
266
267inline void MdpCtrl::setSrcWhf(const overlay::utils::Whf& whf) {
268 mOVInfo.src.width = whf.w;
269 mOVInfo.src.height = whf.h;
270 mOVInfo.src.format = whf.format;
271}
272
273inline overlay::utils::Dim MdpCtrl::getSrcRectDim() const {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700274 return utils::Dim( mOVInfo.src_rect.x,
275 mOVInfo.src_rect.y,
276 mOVInfo.src_rect.w,
277 mOVInfo.src_rect.h);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700278}
279
280inline void MdpCtrl::setSrcRectDim(const overlay::utils::Dim d) {
281 mOVInfo.src_rect.x = d.x;
282 mOVInfo.src_rect.y = d.y;
283 mOVInfo.src_rect.w = d.w;
284 mOVInfo.src_rect.h = d.h;
285}
286
287inline overlay::utils::Dim MdpCtrl::getDstRectDim() const {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700288 return utils::Dim( mOVInfo.dst_rect.x,
289 mOVInfo.dst_rect.y,
290 mOVInfo.dst_rect.w,
291 mOVInfo.dst_rect.h);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700292}
293
294inline void MdpCtrl::setDstRectDim(const overlay::utils::Dim d) {
295 mOVInfo.dst_rect.x = d.x;
296 mOVInfo.dst_rect.y = d.y;
297 mOVInfo.dst_rect.w = d.w;
298 mOVInfo.dst_rect.h = d.h;
299}
300
301inline int MdpCtrl::getUserData() const { return mOVInfo.user_data[0]; }
302
303inline void MdpCtrl::setUserData(int v) { mOVInfo.user_data[0] = v; }
304
305inline void MdpCtrl::setRotationFlags() {
306 const int u = getUserData();
Saurabh Shah76fd6552013-03-14 14:45:38 -0700307 if (u & MDP_ROT_90)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700308 mOVInfo.flags |= MDP_SOURCE_ROTATED_90;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700309}
310
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800311inline uint8_t MdpCtrl::getPriority() const {
312 return mOVInfo.priority;
313}
314
Naseer Ahmed29a26812012-06-14 00:56:20 -0700315/////// MdpCtrl3D //////
316
317inline MdpCtrl3D::MdpCtrl3D() { reset(); }
318inline bool MdpCtrl3D::close() {
319 if (m3DOVInfo.is_3d) {
320 m3DOVInfo.is_3d = 0;
321 if(!mdp_wrapper::set3D(mFd.getFD(), m3DOVInfo)) {
322 ALOGE("MdpCtrl3D close failed set3D with 0");
323 return false;
324 }
325 }
326 reset();
327 return true;
328}
329inline void MdpCtrl3D::reset() {
330 utils::memset0(m3DOVInfo);
331}
332
333inline void MdpCtrl3D::setFd(int fd) {
334 mFd.copy(fd);
335 OVASSERT(mFd.valid(), "MdpCtrl3D setFd, FD should be valid");
336}
337
338inline void MdpCtrl3D::setWh(const utils::Whf& whf) {
339 // ignore fmt. Needed for useVirtualFB callflow
340 m3DOVInfo.width = whf.w;
341 m3DOVInfo.height = whf.h;
342}
343
344inline bool MdpCtrl3D::useVirtualFB() {
345 if(!m3DOVInfo.is_3d) {
346 m3DOVInfo.is_3d = 1;
347 if(!mdp_wrapper::set3D(mFd.getFD(), m3DOVInfo)) {
348 ALOGE("MdpCtrl3D close failed set3D with 0");
349 return false;
350 }
351 }
352 return true;
353}
354
355/////// MdpData //////
356
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800357inline MdpData::MdpData(const int& dpy) {
358 reset();
359 init(dpy);
360}
Naseer Ahmed29a26812012-06-14 00:56:20 -0700361
362inline MdpData::~MdpData() { close(); }
363
Naseer Ahmed29a26812012-06-14 00:56:20 -0700364inline void MdpData::reset() {
365 overlay::utils::memset0(mOvData);
366 mOvData.data.memory_id = -1;
367}
368
369inline bool MdpData::close() {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700370 reset();
Saurabh Shah8e1ae952012-08-15 12:15:14 -0700371 return mFd.close();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700372}
373
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700374inline int MdpData::getSrcMemoryId() const { return mOvData.data.memory_id; }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700375
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700376inline void MdpData::setPipeId(int id) { mOvData.id = id; }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700377
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700378inline int MdpData::getPipeId() const { return mOvData.id; }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700379
380inline int MdpData::getFd() const { return mFd.getFD(); }
381
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700382inline bool MdpData::play(int fd, uint32_t offset) {
383 mOvData.data.memory_id = fd;
384 mOvData.data.offset = offset;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700385 if(!mdp_wrapper::play(mFd.getFD(), mOvData)){
386 ALOGE("MdpData failed to play");
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700387 dump();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700388 return false;
389 }
390 return true;
391}
392
Naseer Ahmed29a26812012-06-14 00:56:20 -0700393} // overlay
394
395#endif // OVERLAY_MDP_H