blob: cb8e057ab5f6ae3e0b2fe8da02cd73c25eacb270 [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();
Saurabh Shahacf10202013-02-26 10:15:15 -080067 /* Update the src format with rotator's dest*/
68 void updateSrcFormat(const uint32_t& rotDstFormat);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -080069 /* dump state of the object */
70 void dump() const;
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -080071 /* Return the dump in the specified buffer */
72 void getDump(char *buf, size_t len);
Saurabh Shahacf10202013-02-26 10:15:15 -080073 /* returns session id */
74 int getPipeId() const;
75 /* returns the fd associated to ctrl*/
76 int getFd() const;
77 /* returns a copy ro dst rect dim */
78 utils::Dim getDstRectDim() const;
79 /* returns a copy to src rect dim */
80 utils::Dim getSrcRectDim() const;
Saurabh Shahdd8237a2014-02-28 14:29:09 -080081 /* return pipe priority */
82 uint8_t getPriority() const;
Saurabh Shah5daeee52013-01-23 16:52:26 +080083 /* setVisualParam */
84 bool setVisualParams(const MetaData_t& data);
radhakrishna8ccb9082014-05-09 16:18:43 +053085 /* sets pipe type RGB/DMA/VG */
86 void setPipeType(const utils::eMdpPipeType& pType);
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 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
Naseer Ahmed29a26812012-06-14 00:56:20 -0700134/* MDP data */
135class MdpData {
136public:
137 /* ctor reset data */
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800138 explicit MdpData(const int& dpy);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700139 /* dtor close*/
140 ~MdpData();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700141 /* init FD */
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800142 bool init(const int& dpy);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700143 /* memset0 the underlying mdp object */
144 void reset();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700145 /* close fd, and reset */
146 bool close();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700147 /* set id of mdp data */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700148 void setPipeId(int id);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700149 /* return ses id of data */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700150 int getPipeId() const;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700151 /* get underlying fd*/
152 int getFd() const;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700153 /* get memory_id */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700154 int getSrcMemoryId() const;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700155 /* calls wrapper play */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700156 bool play(int fd, uint32_t offset);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700157 /* dump state of the object */
158 void dump() const;
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800159 /* Return the dump in the specified buffer */
160 void getDump(char *buf, size_t len);
161
Naseer Ahmed29a26812012-06-14 00:56:20 -0700162private:
163
164 /* actual overlay mdp data */
165 msmfb_overlay_data mOvData;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700166 /* fd to mdp fbnum */
167 OvFD mFd;
168};
169
170//--------------Inlines---------------------------------
Naseer Ahmed29a26812012-06-14 00:56:20 -0700171
172///// MdpCtrl //////
173
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800174inline MdpCtrl::MdpCtrl(const int& dpy) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700175 reset();
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800176 init(dpy);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700177}
178
179inline MdpCtrl::~MdpCtrl() {
180 close();
181}
182
183inline int MdpCtrl::getOrient() const {
184 return getUserData();
185}
186
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700187inline int MdpCtrl::getPipeId() const {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700188 return mOVInfo.id;
189}
190
191inline int MdpCtrl::getFd() const {
192 return mFd.getFD();
193}
194
195inline int MdpCtrl::getFlags() const {
196 return mOVInfo.flags;
197}
198
199inline void MdpCtrl::setFlags(int f) {
200 mOVInfo.flags = f;
201}
202
203inline void MdpCtrl::setZ(overlay::utils::eZorder z) {
204 mOVInfo.z_order = z;
205}
206
Naseer Ahmed29a26812012-06-14 00:56:20 -0700207inline void MdpCtrl::setIsFg(overlay::utils::eIsFg isFg) {
208 mOVInfo.is_fg = isFg;
209}
210
Naseer Ahmed522ce662013-03-18 20:14:05 -0400211inline void MdpCtrl::setPlaneAlpha(int planeAlpha) {
212 mOVInfo.alpha = planeAlpha;
213}
214
215inline void MdpCtrl::setBlending(overlay::utils::eBlending blending) {
216 switch((int) blending) {
217 case utils::OVERLAY_BLENDING_OPAQUE:
218 mOVInfo.blend_op = BLEND_OP_OPAQUE;
219 break;
220 case utils::OVERLAY_BLENDING_PREMULT:
221 mOVInfo.blend_op = BLEND_OP_PREMULTIPLIED;
222 break;
223 case utils::OVERLAY_BLENDING_COVERAGE:
224 default:
225 mOVInfo.blend_op = BLEND_OP_COVERAGE;
226 }
227}
228
Naseer Ahmed29a26812012-06-14 00:56:20 -0700229inline overlay::utils::Whf MdpCtrl::getSrcWhf() const {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700230 return utils::Whf( mOVInfo.src.width,
231 mOVInfo.src.height,
232 mOVInfo.src.format);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700233}
234
235inline void MdpCtrl::setSrcWhf(const overlay::utils::Whf& whf) {
236 mOVInfo.src.width = whf.w;
237 mOVInfo.src.height = whf.h;
238 mOVInfo.src.format = whf.format;
239}
240
241inline overlay::utils::Dim MdpCtrl::getSrcRectDim() const {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700242 return utils::Dim( mOVInfo.src_rect.x,
243 mOVInfo.src_rect.y,
244 mOVInfo.src_rect.w,
245 mOVInfo.src_rect.h);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700246}
247
248inline void MdpCtrl::setSrcRectDim(const overlay::utils::Dim d) {
249 mOVInfo.src_rect.x = d.x;
250 mOVInfo.src_rect.y = d.y;
251 mOVInfo.src_rect.w = d.w;
252 mOVInfo.src_rect.h = d.h;
253}
254
255inline overlay::utils::Dim MdpCtrl::getDstRectDim() const {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700256 return utils::Dim( mOVInfo.dst_rect.x,
257 mOVInfo.dst_rect.y,
258 mOVInfo.dst_rect.w,
259 mOVInfo.dst_rect.h);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700260}
261
262inline void MdpCtrl::setDstRectDim(const overlay::utils::Dim d) {
263 mOVInfo.dst_rect.x = d.x;
264 mOVInfo.dst_rect.y = d.y;
265 mOVInfo.dst_rect.w = d.w;
266 mOVInfo.dst_rect.h = d.h;
267}
268
269inline int MdpCtrl::getUserData() const { return mOVInfo.user_data[0]; }
270
271inline void MdpCtrl::setUserData(int v) { mOVInfo.user_data[0] = v; }
272
273inline void MdpCtrl::setRotationFlags() {
274 const int u = getUserData();
Saurabh Shah76fd6552013-03-14 14:45:38 -0700275 if (u & MDP_ROT_90)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700276 mOVInfo.flags |= MDP_SOURCE_ROTATED_90;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700277}
278
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800279inline uint8_t MdpCtrl::getPriority() const {
280 return mOVInfo.priority;
281}
282
Naseer Ahmed29a26812012-06-14 00:56:20 -0700283/////// MdpData //////
284
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800285inline MdpData::MdpData(const int& dpy) {
286 reset();
287 init(dpy);
288}
Naseer Ahmed29a26812012-06-14 00:56:20 -0700289
290inline MdpData::~MdpData() { close(); }
291
Naseer Ahmed29a26812012-06-14 00:56:20 -0700292inline void MdpData::reset() {
293 overlay::utils::memset0(mOvData);
294 mOvData.data.memory_id = -1;
295}
296
297inline bool MdpData::close() {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700298 reset();
Saurabh Shah8e1ae952012-08-15 12:15:14 -0700299 return mFd.close();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700300}
301
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700302inline int MdpData::getSrcMemoryId() const { return mOvData.data.memory_id; }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700303
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700304inline void MdpData::setPipeId(int id) { mOvData.id = id; }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700305
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700306inline int MdpData::getPipeId() const { return mOvData.id; }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700307
308inline int MdpData::getFd() const { return mFd.getFD(); }
309
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700310inline bool MdpData::play(int fd, uint32_t offset) {
311 mOvData.data.memory_id = fd;
312 mOvData.data.offset = offset;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700313 if(!mdp_wrapper::play(mFd.getFD(), mOvData)){
314 ALOGE("MdpData failed to play");
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700315 dump();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700316 return false;
317 }
318 return true;
319}
320
Naseer Ahmed29a26812012-06-14 00:56:20 -0700321} // overlay
322
323#endif // OVERLAY_MDP_H