blob: d415b9dbfa1655b281dfe14a39abce2b8b1f71d5 [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);
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 Shahb8f58e22013-09-26 16:20:07 -0700124 int mDpy;
Saurabh Shahdf0be752013-05-23 14:40:00 -0700125
Saurabh Shah5daeee52013-01-23 16:52:26 +0800126#ifdef USES_POST_PROCESSING
127 /* PP Compute Params */
128 struct compute_params mParams;
Saurabh Shah5daeee52013-01-23 16:52:26 +0800129#endif
Naseer Ahmed29a26812012-06-14 00:56:20 -0700130};
131
Naseer Ahmed29a26812012-06-14 00:56:20 -0700132/* MDP data */
133class MdpData {
134public:
135 /* ctor reset data */
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800136 explicit MdpData(const int& dpy);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700137 /* dtor close*/
138 ~MdpData();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700139 /* init FD */
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800140 bool init(const int& dpy);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700141 /* memset0 the underlying mdp object */
142 void reset();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700143 /* close fd, and reset */
144 bool close();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700145 /* set id of mdp data */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700146 void setPipeId(int id);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700147 /* return ses id of data */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700148 int getPipeId() const;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700149 /* get underlying fd*/
150 int getFd() const;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700151 /* get memory_id */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700152 int getSrcMemoryId() const;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700153 /* calls wrapper play */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700154 bool play(int fd, uint32_t offset);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700155 /* dump state of the object */
156 void dump() const;
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800157 /* Return the dump in the specified buffer */
158 void getDump(char *buf, size_t len);
159
Naseer Ahmed29a26812012-06-14 00:56:20 -0700160private:
161
162 /* actual overlay mdp data */
163 msmfb_overlay_data mOvData;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700164 /* fd to mdp fbnum */
165 OvFD mFd;
166};
167
168//--------------Inlines---------------------------------
Naseer Ahmed29a26812012-06-14 00:56:20 -0700169
170///// MdpCtrl //////
171
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800172inline MdpCtrl::MdpCtrl(const int& dpy) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700173 reset();
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800174 init(dpy);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700175}
176
177inline MdpCtrl::~MdpCtrl() {
178 close();
179}
180
181inline int MdpCtrl::getOrient() const {
182 return getUserData();
183}
184
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700185inline int MdpCtrl::getPipeId() const {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700186 return mOVInfo.id;
187}
188
189inline int MdpCtrl::getFd() const {
190 return mFd.getFD();
191}
192
193inline int MdpCtrl::getFlags() const {
194 return mOVInfo.flags;
195}
196
197inline void MdpCtrl::setFlags(int f) {
198 mOVInfo.flags = f;
199}
200
201inline void MdpCtrl::setZ(overlay::utils::eZorder z) {
202 mOVInfo.z_order = z;
203}
204
Naseer Ahmed522ce662013-03-18 20:14:05 -0400205inline void MdpCtrl::setPlaneAlpha(int planeAlpha) {
206 mOVInfo.alpha = planeAlpha;
207}
208
209inline void MdpCtrl::setBlending(overlay::utils::eBlending blending) {
210 switch((int) blending) {
211 case utils::OVERLAY_BLENDING_OPAQUE:
212 mOVInfo.blend_op = BLEND_OP_OPAQUE;
213 break;
214 case utils::OVERLAY_BLENDING_PREMULT:
215 mOVInfo.blend_op = BLEND_OP_PREMULTIPLIED;
216 break;
217 case utils::OVERLAY_BLENDING_COVERAGE:
218 default:
219 mOVInfo.blend_op = BLEND_OP_COVERAGE;
220 }
221}
222
Naseer Ahmed29a26812012-06-14 00:56:20 -0700223inline overlay::utils::Whf MdpCtrl::getSrcWhf() const {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700224 return utils::Whf( mOVInfo.src.width,
225 mOVInfo.src.height,
226 mOVInfo.src.format);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700227}
228
229inline void MdpCtrl::setSrcWhf(const overlay::utils::Whf& whf) {
230 mOVInfo.src.width = whf.w;
231 mOVInfo.src.height = whf.h;
232 mOVInfo.src.format = whf.format;
233}
234
235inline overlay::utils::Dim MdpCtrl::getSrcRectDim() const {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700236 return utils::Dim( mOVInfo.src_rect.x,
237 mOVInfo.src_rect.y,
238 mOVInfo.src_rect.w,
239 mOVInfo.src_rect.h);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700240}
241
242inline void MdpCtrl::setSrcRectDim(const overlay::utils::Dim d) {
243 mOVInfo.src_rect.x = d.x;
244 mOVInfo.src_rect.y = d.y;
245 mOVInfo.src_rect.w = d.w;
246 mOVInfo.src_rect.h = d.h;
247}
248
249inline overlay::utils::Dim MdpCtrl::getDstRectDim() const {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700250 return utils::Dim( mOVInfo.dst_rect.x,
251 mOVInfo.dst_rect.y,
252 mOVInfo.dst_rect.w,
253 mOVInfo.dst_rect.h);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700254}
255
256inline void MdpCtrl::setDstRectDim(const overlay::utils::Dim d) {
257 mOVInfo.dst_rect.x = d.x;
258 mOVInfo.dst_rect.y = d.y;
259 mOVInfo.dst_rect.w = d.w;
260 mOVInfo.dst_rect.h = d.h;
261}
262
263inline int MdpCtrl::getUserData() const { return mOVInfo.user_data[0]; }
264
265inline void MdpCtrl::setUserData(int v) { mOVInfo.user_data[0] = v; }
266
267inline void MdpCtrl::setRotationFlags() {
268 const int u = getUserData();
Saurabh Shah76fd6552013-03-14 14:45:38 -0700269 if (u & MDP_ROT_90)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700270 mOVInfo.flags |= MDP_SOURCE_ROTATED_90;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700271}
272
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800273inline uint8_t MdpCtrl::getPriority() const {
274 return mOVInfo.priority;
275}
276
Naseer Ahmed29a26812012-06-14 00:56:20 -0700277/////// MdpData //////
278
Saurabh Shahd18d88a2014-01-06 15:02:49 -0800279inline MdpData::MdpData(const int& dpy) {
280 reset();
281 init(dpy);
282}
Naseer Ahmed29a26812012-06-14 00:56:20 -0700283
284inline MdpData::~MdpData() { close(); }
285
Naseer Ahmed29a26812012-06-14 00:56:20 -0700286inline void MdpData::reset() {
287 overlay::utils::memset0(mOvData);
288 mOvData.data.memory_id = -1;
289}
290
291inline bool MdpData::close() {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700292 reset();
Saurabh Shah8e1ae952012-08-15 12:15:14 -0700293 return mFd.close();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700294}
295
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700296inline int MdpData::getSrcMemoryId() const { return mOvData.data.memory_id; }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700297
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700298inline void MdpData::setPipeId(int id) { mOvData.id = id; }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700299
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700300inline int MdpData::getPipeId() const { return mOvData.id; }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700301
302inline int MdpData::getFd() const { return mFd.getFD(); }
303
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700304inline bool MdpData::play(int fd, uint32_t offset) {
305 mOvData.data.memory_id = fd;
306 mOvData.data.offset = offset;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700307 if(!mdp_wrapper::play(mFd.getFD(), mOvData)){
308 ALOGE("MdpData failed to play");
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700309 dump();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700310 return false;
311 }
312 return true;
313}
314
Naseer Ahmed29a26812012-06-14 00:56:20 -0700315} // overlay
316
317#endif // OVERLAY_MDP_H