blob: 056d98273f70c29d68bd36eaf027c1f7f986aaa8 [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);
Saurabh Shahdf0be752013-05-23 14:40:00 -070084 void forceSet();
Naseer Ahmed29a26812012-06-14 00:56:20 -070085
Saurabh Shahacf10202013-02-26 10:15:15 -080086private:
87 /* Perform transformation calculations */
88 void doTransform();
89 void doDownscale();
90 /* get orient / user_data[0] */
91 int getOrient() const;
92 /* overlay get */
93 bool get();
94 /* returns flags from mdp structure */
95 int getFlags() const;
96 /* set flags to mdp structure */
97 void setFlags(int f);
98 /* set z order */
99 void setZ(utils::eZorder z);
100 /* set isFg flag */
101 void setIsFg(utils::eIsFg isFg);
102 /* return a copy of src whf*/
103 utils::Whf getSrcWhf() const;
104 /* set src whf */
105 void setSrcWhf(const utils::Whf& whf);
106 /* set src/dst rect dim */
107 void setSrcRectDim(const utils::Dim d);
108 void setDstRectDim(const utils::Dim d);
109 /* returns user_data[0]*/
110 int getUserData() const;
111 /* sets user_data[0] */
112 void setUserData(int v);
113 /* return true if current overlay is different
114 * than last known good overlay */
115 bool ovChanged() const;
116 /* save mOVInfo to be last known good ov*/
117 void save();
118 /* restore last known good ov to be the current */
119 void restore();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700120
121 utils::eTransform mOrientation; //Holds requested orientation
Naseer Ahmed29a26812012-06-14 00:56:20 -0700122 /* last good known ov info */
123 mdp_overlay mLkgo;
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 Shahdf0be752013-05-23 14:40:00 -0700129 bool mForceSet;
130
Saurabh Shah5daeee52013-01-23 16:52:26 +0800131#ifdef USES_POST_PROCESSING
132 /* PP Compute Params */
133 struct compute_params mParams;
134 /* indicate if PP params have been changed */
135 bool mPPChanged;
136#endif
Naseer Ahmed29a26812012-06-14 00:56:20 -0700137};
138
139
140/* MDP 3D related ctrl */
141class MdpCtrl3D {
142public:
143 /* ctor reset data */
144 MdpCtrl3D();
145 /* calls MSMFB_OVERLAY_3D */
146 bool close();
147 /* set w/h. format is ignored*/
148 void setWh(const utils::Whf& whf);
149 /* set is_3d calls MSMFB_OVERLAY_3D */
150 bool useVirtualFB();
151 /* set fd to be used in ioctl */
152 void setFd(int fd);
153 /* dump */
154 void dump() const;
155private:
156 /* reset */
157 void reset();
158 /* actual MSM 3D info */
159 msmfb_overlay_3d m3DOVInfo;
160 /* FD for the mdp 3D */
161 OvFD mFd;
162};
163
164/* MDP data */
165class MdpData {
166public:
167 /* ctor reset data */
168 explicit MdpData();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700169 /* dtor close*/
170 ~MdpData();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700171 /* init FD */
172 bool init(uint32_t fbnum);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700173 /* memset0 the underlying mdp object */
174 void reset();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700175 /* close fd, and reset */
176 bool close();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700177 /* set id of mdp data */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700178 void setPipeId(int id);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700179 /* return ses id of data */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700180 int getPipeId() const;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700181 /* get underlying fd*/
182 int getFd() const;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700183 /* get memory_id */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700184 int getSrcMemoryId() const;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700185 /* calls wrapper play */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700186 bool play(int fd, uint32_t offset);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700187 /* dump state of the object */
188 void dump() const;
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800189 /* Return the dump in the specified buffer */
190 void getDump(char *buf, size_t len);
191
Naseer Ahmed29a26812012-06-14 00:56:20 -0700192private:
193
194 /* actual overlay mdp data */
195 msmfb_overlay_data mOvData;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700196 /* fd to mdp fbnum */
197 OvFD mFd;
198};
199
200//--------------Inlines---------------------------------
Naseer Ahmed29a26812012-06-14 00:56:20 -0700201
202///// MdpCtrl //////
203
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700204inline MdpCtrl::MdpCtrl() {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700205 reset();
206}
207
208inline MdpCtrl::~MdpCtrl() {
209 close();
210}
211
212inline int MdpCtrl::getOrient() const {
213 return getUserData();
214}
215
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700216inline int MdpCtrl::getPipeId() const {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700217 return mOVInfo.id;
218}
219
220inline int MdpCtrl::getFd() const {
221 return mFd.getFD();
222}
223
224inline int MdpCtrl::getFlags() const {
225 return mOVInfo.flags;
226}
227
228inline void MdpCtrl::setFlags(int f) {
229 mOVInfo.flags = f;
230}
231
232inline void MdpCtrl::setZ(overlay::utils::eZorder z) {
233 mOVInfo.z_order = z;
234}
235
Naseer Ahmed29a26812012-06-14 00:56:20 -0700236inline void MdpCtrl::setIsFg(overlay::utils::eIsFg isFg) {
237 mOVInfo.is_fg = isFg;
238}
239
Saurabh Shahacf10202013-02-26 10:15:15 -0800240inline void MdpCtrl::setDownscale(int dscale) {
241 mDownscale = dscale;
242}
243
Naseer Ahmed29a26812012-06-14 00:56:20 -0700244inline bool MdpCtrl::ovChanged() const {
Saurabh Shah5daeee52013-01-23 16:52:26 +0800245#ifdef USES_POST_PROCESSING
246 // Some pp params are stored as pointer address,
247 // so can't compare their content directly.
248 if (mPPChanged) {
249 return true;
250 }
251#endif
Naseer Ahmed29a26812012-06-14 00:56:20 -0700252 // 0 means same
253 if(0 == ::memcmp(&mOVInfo, &mLkgo, sizeof (mdp_overlay))) {
254 return false;
255 }
256 return true;
257}
258
259inline void MdpCtrl::save() {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700260 if(static_cast<ssize_t>(mOVInfo.id) == MSMFB_NEW_REQUEST) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700261 ALOGE("MdpCtrl current ov has id -1, will not save");
Naseer Ahmed29a26812012-06-14 00:56:20 -0700262 return;
263 }
264 mLkgo = mOVInfo;
265}
266
267inline void MdpCtrl::restore() {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700268 if(static_cast<ssize_t>(mLkgo.id) == MSMFB_NEW_REQUEST) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700269 ALOGE("MdpCtrl Lkgo ov has id -1, will not restore");
Naseer Ahmed29a26812012-06-14 00:56:20 -0700270 return;
271 }
272 mOVInfo = mLkgo;
273}
274
275inline overlay::utils::Whf MdpCtrl::getSrcWhf() const {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700276 return utils::Whf( mOVInfo.src.width,
277 mOVInfo.src.height,
278 mOVInfo.src.format);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700279}
280
281inline void MdpCtrl::setSrcWhf(const overlay::utils::Whf& whf) {
282 mOVInfo.src.width = whf.w;
283 mOVInfo.src.height = whf.h;
284 mOVInfo.src.format = whf.format;
285}
286
287inline overlay::utils::Dim MdpCtrl::getSrcRectDim() const {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700288 return utils::Dim( mOVInfo.src_rect.x,
289 mOVInfo.src_rect.y,
290 mOVInfo.src_rect.w,
291 mOVInfo.src_rect.h);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700292}
293
294inline void MdpCtrl::setSrcRectDim(const overlay::utils::Dim d) {
295 mOVInfo.src_rect.x = d.x;
296 mOVInfo.src_rect.y = d.y;
297 mOVInfo.src_rect.w = d.w;
298 mOVInfo.src_rect.h = d.h;
299}
300
301inline overlay::utils::Dim MdpCtrl::getDstRectDim() const {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700302 return utils::Dim( mOVInfo.dst_rect.x,
303 mOVInfo.dst_rect.y,
304 mOVInfo.dst_rect.w,
305 mOVInfo.dst_rect.h);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700306}
307
308inline void MdpCtrl::setDstRectDim(const overlay::utils::Dim d) {
309 mOVInfo.dst_rect.x = d.x;
310 mOVInfo.dst_rect.y = d.y;
311 mOVInfo.dst_rect.w = d.w;
312 mOVInfo.dst_rect.h = d.h;
313}
314
315inline int MdpCtrl::getUserData() const { return mOVInfo.user_data[0]; }
316
317inline void MdpCtrl::setUserData(int v) { mOVInfo.user_data[0] = v; }
318
319inline void MdpCtrl::setRotationFlags() {
320 const int u = getUserData();
Saurabh Shah76fd6552013-03-14 14:45:38 -0700321 if (u & MDP_ROT_90)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700322 mOVInfo.flags |= MDP_SOURCE_ROTATED_90;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700323}
324
Saurabh Shahdf0be752013-05-23 14:40:00 -0700325inline void MdpCtrl::forceSet() {
326 mForceSet = true;
327}
328
Naseer Ahmed29a26812012-06-14 00:56:20 -0700329/////// MdpCtrl3D //////
330
331inline MdpCtrl3D::MdpCtrl3D() { reset(); }
332inline bool MdpCtrl3D::close() {
333 if (m3DOVInfo.is_3d) {
334 m3DOVInfo.is_3d = 0;
335 if(!mdp_wrapper::set3D(mFd.getFD(), m3DOVInfo)) {
336 ALOGE("MdpCtrl3D close failed set3D with 0");
337 return false;
338 }
339 }
340 reset();
341 return true;
342}
343inline void MdpCtrl3D::reset() {
344 utils::memset0(m3DOVInfo);
345}
346
347inline void MdpCtrl3D::setFd(int fd) {
348 mFd.copy(fd);
349 OVASSERT(mFd.valid(), "MdpCtrl3D setFd, FD should be valid");
350}
351
352inline void MdpCtrl3D::setWh(const utils::Whf& whf) {
353 // ignore fmt. Needed for useVirtualFB callflow
354 m3DOVInfo.width = whf.w;
355 m3DOVInfo.height = whf.h;
356}
357
358inline bool MdpCtrl3D::useVirtualFB() {
359 if(!m3DOVInfo.is_3d) {
360 m3DOVInfo.is_3d = 1;
361 if(!mdp_wrapper::set3D(mFd.getFD(), m3DOVInfo)) {
362 ALOGE("MdpCtrl3D close failed set3D with 0");
363 return false;
364 }
365 }
366 return true;
367}
368
369/////// MdpData //////
370
371inline MdpData::MdpData() { reset(); }
372
373inline MdpData::~MdpData() { close(); }
374
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700375inline bool MdpData::init(uint32_t fbnum) {
376 // FD init
377 if(!utils::openDev(mFd, fbnum, Res::fbPath, O_RDWR)){
378 ALOGE("Ctrl failed to init fbnum=%d", fbnum);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700379 return false;
380 }
381 return true;
382}
383
384inline void MdpData::reset() {
385 overlay::utils::memset0(mOvData);
386 mOvData.data.memory_id = -1;
387}
388
389inline bool MdpData::close() {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700390 reset();
Saurabh Shah8e1ae952012-08-15 12:15:14 -0700391 return mFd.close();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700392}
393
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700394inline int MdpData::getSrcMemoryId() const { return mOvData.data.memory_id; }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700395
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700396inline void MdpData::setPipeId(int id) { mOvData.id = id; }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700397
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700398inline int MdpData::getPipeId() const { return mOvData.id; }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700399
400inline int MdpData::getFd() const { return mFd.getFD(); }
401
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700402inline bool MdpData::play(int fd, uint32_t offset) {
403 mOvData.data.memory_id = fd;
404 mOvData.data.offset = offset;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700405 if(!mdp_wrapper::play(mFd.getFD(), mOvData)){
406 ALOGE("MdpData failed to play");
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700407 dump();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700408 return false;
409 }
410 return true;
411}
412
Naseer Ahmed29a26812012-06-14 00:56:20 -0700413} // overlay
414
415#endif // OVERLAY_MDP_H