blob: f77ffae59c74a2babdc97fcd45506b787852479b [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 */
39 explicit MdpCtrl();
Naseer Ahmed29a26812012-06-14 00:56:20 -070040 /* dtor close */
41 ~MdpCtrl();
Naseer Ahmedf48aef62012-07-20 09:05:53 -070042 /* init underlying device using fbnum */
43 bool init(uint32_t fbnum);
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);
60 void setTransform(const utils::eTransform& orient);
Naseer Ahmed29a26812012-06-14 00:56:20 -070061 /* given a dim and w/h, set overlay dim */
Saurabh Shahacf10202013-02-26 10:15:15 -080062 void setPosition(const utils::Dim& dim);
Naseer Ahmed29a26812012-06-14 00:56:20 -070063 /* using user_data, sets/unsets roationvalue in mdp flags */
64 void setRotationFlags();
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -080065 /* Performs downscale calculations */
Saurabh Shahacf10202013-02-26 10:15:15 -080066 void setDownscale(int dscale_factor);
67 /* 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);
73
Saurabh Shahacf10202013-02-26 10:15:15 -080074 /* returns session id */
75 int getPipeId() const;
76 /* returns the fd associated to ctrl*/
77 int getFd() const;
78 /* returns a copy ro dst rect dim */
79 utils::Dim getDstRectDim() const;
80 /* returns a copy to src rect dim */
81 utils::Dim getSrcRectDim() const;
Saurabh Shah5daeee52013-01-23 16:52:26 +080082 /* setVisualParam */
83 bool setVisualParams(const MetaData_t& data);
Naseer Ahmed29a26812012-06-14 00:56:20 -070084
Saurabh Shahacf10202013-02-26 10:15:15 -080085private:
86 /* Perform transformation calculations */
87 void doTransform();
88 void doDownscale();
89 /* get orient / user_data[0] */
90 int getOrient() const;
91 /* overlay get */
92 bool get();
93 /* returns flags from mdp structure */
94 int getFlags() const;
95 /* set flags to mdp structure */
96 void setFlags(int f);
97 /* set z order */
98 void setZ(utils::eZorder z);
99 /* set isFg flag */
100 void setIsFg(utils::eIsFg isFg);
101 /* return a copy of src whf*/
102 utils::Whf getSrcWhf() const;
103 /* set src whf */
104 void setSrcWhf(const utils::Whf& whf);
105 /* set src/dst rect dim */
106 void setSrcRectDim(const utils::Dim d);
107 void setDstRectDim(const utils::Dim d);
108 /* returns user_data[0]*/
109 int getUserData() const;
110 /* sets user_data[0] */
111 void setUserData(int v);
112 /* return true if current overlay is different
113 * than last known good overlay */
114 bool ovChanged() const;
115 /* save mOVInfo to be last known good ov*/
116 void save();
117 /* restore last known good ov to be the current */
118 void restore();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700119
120 utils::eTransform mOrientation; //Holds requested orientation
Naseer Ahmed29a26812012-06-14 00:56:20 -0700121 /* last good known ov info */
122 mdp_overlay mLkgo;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700123 /* Actual overlay mdp structure */
124 mdp_overlay mOVInfo;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700125 /* FD for the mdp fbnum */
126 OvFD mFd;
Saurabh Shahacf10202013-02-26 10:15:15 -0800127 int mDownscale;
Saurabh Shah5daeee52013-01-23 16:52:26 +0800128#ifdef USES_POST_PROCESSING
129 /* PP Compute Params */
130 struct compute_params mParams;
131 /* indicate if PP params have been changed */
132 bool mPPChanged;
133#endif
Naseer Ahmed29a26812012-06-14 00:56:20 -0700134};
135
136
137/* MDP 3D related ctrl */
138class MdpCtrl3D {
139public:
140 /* ctor reset data */
141 MdpCtrl3D();
142 /* calls MSMFB_OVERLAY_3D */
143 bool close();
144 /* set w/h. format is ignored*/
145 void setWh(const utils::Whf& whf);
146 /* set is_3d calls MSMFB_OVERLAY_3D */
147 bool useVirtualFB();
148 /* set fd to be used in ioctl */
149 void setFd(int fd);
150 /* dump */
151 void dump() const;
152private:
153 /* reset */
154 void reset();
155 /* actual MSM 3D info */
156 msmfb_overlay_3d m3DOVInfo;
157 /* FD for the mdp 3D */
158 OvFD mFd;
159};
160
161/* MDP data */
162class MdpData {
163public:
164 /* ctor reset data */
165 explicit MdpData();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700166 /* dtor close*/
167 ~MdpData();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700168 /* init FD */
169 bool init(uint32_t fbnum);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700170 /* memset0 the underlying mdp object */
171 void reset();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700172 /* close fd, and reset */
173 bool close();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700174 /* set id of mdp data */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700175 void setPipeId(int id);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700176 /* return ses id of data */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700177 int getPipeId() const;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700178 /* get underlying fd*/
179 int getFd() const;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700180 /* get memory_id */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700181 int getSrcMemoryId() const;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700182 /* calls wrapper play */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700183 bool play(int fd, uint32_t offset);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700184 /* dump state of the object */
185 void dump() const;
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800186 /* Return the dump in the specified buffer */
187 void getDump(char *buf, size_t len);
188
Naseer Ahmed29a26812012-06-14 00:56:20 -0700189private:
190
191 /* actual overlay mdp data */
192 msmfb_overlay_data mOvData;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700193 /* fd to mdp fbnum */
194 OvFD mFd;
195};
196
197//--------------Inlines---------------------------------
Naseer Ahmed29a26812012-06-14 00:56:20 -0700198
199///// MdpCtrl //////
200
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700201inline MdpCtrl::MdpCtrl() {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700202 reset();
203}
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 Ahmed29a26812012-06-14 00:56:20 -0700241inline bool MdpCtrl::ovChanged() const {
Saurabh Shah5daeee52013-01-23 16:52:26 +0800242#ifdef USES_POST_PROCESSING
243 // Some pp params are stored as pointer address,
244 // so can't compare their content directly.
245 if (mPPChanged) {
246 return true;
247 }
248#endif
Naseer Ahmed29a26812012-06-14 00:56:20 -0700249 // 0 means same
250 if(0 == ::memcmp(&mOVInfo, &mLkgo, sizeof (mdp_overlay))) {
251 return false;
252 }
253 return true;
254}
255
256inline void MdpCtrl::save() {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700257 if(static_cast<ssize_t>(mOVInfo.id) == MSMFB_NEW_REQUEST) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700258 ALOGE("MdpCtrl current ov has id -1, will not save");
Naseer Ahmed29a26812012-06-14 00:56:20 -0700259 return;
260 }
261 mLkgo = mOVInfo;
262}
263
264inline void MdpCtrl::restore() {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700265 if(static_cast<ssize_t>(mLkgo.id) == MSMFB_NEW_REQUEST) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700266 ALOGE("MdpCtrl Lkgo ov has id -1, will not restore");
Naseer Ahmed29a26812012-06-14 00:56:20 -0700267 return;
268 }
269 mOVInfo = mLkgo;
270}
271
272inline overlay::utils::Whf MdpCtrl::getSrcWhf() const {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700273 return utils::Whf( mOVInfo.src.width,
274 mOVInfo.src.height,
275 mOVInfo.src.format);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700276}
277
278inline void MdpCtrl::setSrcWhf(const overlay::utils::Whf& whf) {
279 mOVInfo.src.width = whf.w;
280 mOVInfo.src.height = whf.h;
281 mOVInfo.src.format = whf.format;
282}
283
284inline overlay::utils::Dim MdpCtrl::getSrcRectDim() const {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700285 return utils::Dim( mOVInfo.src_rect.x,
286 mOVInfo.src_rect.y,
287 mOVInfo.src_rect.w,
288 mOVInfo.src_rect.h);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700289}
290
291inline void MdpCtrl::setSrcRectDim(const overlay::utils::Dim d) {
292 mOVInfo.src_rect.x = d.x;
293 mOVInfo.src_rect.y = d.y;
294 mOVInfo.src_rect.w = d.w;
295 mOVInfo.src_rect.h = d.h;
296}
297
298inline overlay::utils::Dim MdpCtrl::getDstRectDim() const {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700299 return utils::Dim( mOVInfo.dst_rect.x,
300 mOVInfo.dst_rect.y,
301 mOVInfo.dst_rect.w,
302 mOVInfo.dst_rect.h);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700303}
304
305inline void MdpCtrl::setDstRectDim(const overlay::utils::Dim d) {
306 mOVInfo.dst_rect.x = d.x;
307 mOVInfo.dst_rect.y = d.y;
308 mOVInfo.dst_rect.w = d.w;
309 mOVInfo.dst_rect.h = d.h;
310}
311
312inline int MdpCtrl::getUserData() const { return mOVInfo.user_data[0]; }
313
314inline void MdpCtrl::setUserData(int v) { mOVInfo.user_data[0] = v; }
315
316inline void MdpCtrl::setRotationFlags() {
317 const int u = getUserData();
Saurabh Shah76fd6552013-03-14 14:45:38 -0700318 if (u & MDP_ROT_90)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700319 mOVInfo.flags |= MDP_SOURCE_ROTATED_90;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700320}
321
Naseer Ahmed29a26812012-06-14 00:56:20 -0700322/////// MdpCtrl3D //////
323
324inline MdpCtrl3D::MdpCtrl3D() { reset(); }
325inline bool MdpCtrl3D::close() {
326 if (m3DOVInfo.is_3d) {
327 m3DOVInfo.is_3d = 0;
328 if(!mdp_wrapper::set3D(mFd.getFD(), m3DOVInfo)) {
329 ALOGE("MdpCtrl3D close failed set3D with 0");
330 return false;
331 }
332 }
333 reset();
334 return true;
335}
336inline void MdpCtrl3D::reset() {
337 utils::memset0(m3DOVInfo);
338}
339
340inline void MdpCtrl3D::setFd(int fd) {
341 mFd.copy(fd);
342 OVASSERT(mFd.valid(), "MdpCtrl3D setFd, FD should be valid");
343}
344
345inline void MdpCtrl3D::setWh(const utils::Whf& whf) {
346 // ignore fmt. Needed for useVirtualFB callflow
347 m3DOVInfo.width = whf.w;
348 m3DOVInfo.height = whf.h;
349}
350
351inline bool MdpCtrl3D::useVirtualFB() {
352 if(!m3DOVInfo.is_3d) {
353 m3DOVInfo.is_3d = 1;
354 if(!mdp_wrapper::set3D(mFd.getFD(), m3DOVInfo)) {
355 ALOGE("MdpCtrl3D close failed set3D with 0");
356 return false;
357 }
358 }
359 return true;
360}
361
362/////// MdpData //////
363
364inline MdpData::MdpData() { reset(); }
365
366inline MdpData::~MdpData() { close(); }
367
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700368inline bool MdpData::init(uint32_t fbnum) {
369 // FD init
370 if(!utils::openDev(mFd, fbnum, Res::fbPath, O_RDWR)){
371 ALOGE("Ctrl failed to init fbnum=%d", fbnum);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700372 return false;
373 }
374 return true;
375}
376
377inline void MdpData::reset() {
378 overlay::utils::memset0(mOvData);
379 mOvData.data.memory_id = -1;
380}
381
382inline bool MdpData::close() {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700383 reset();
Saurabh Shah8e1ae952012-08-15 12:15:14 -0700384 return mFd.close();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700385}
386
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700387inline int MdpData::getSrcMemoryId() const { return mOvData.data.memory_id; }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700388
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700389inline void MdpData::setPipeId(int id) { mOvData.id = id; }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700390
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700391inline int MdpData::getPipeId() const { return mOvData.id; }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700392
393inline int MdpData::getFd() const { return mFd.getFD(); }
394
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700395inline bool MdpData::play(int fd, uint32_t offset) {
396 mOvData.data.memory_id = fd;
397 mOvData.data.offset = offset;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700398 if(!mdp_wrapper::play(mFd.getFD(), mOvData)){
399 ALOGE("MdpData failed to play");
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700400 dump();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700401 return false;
402 }
403 return true;
404}
405
Naseer Ahmed29a26812012-06-14 00:56:20 -0700406} // overlay
407
408#endif // OVERLAY_MDP_H