blob: 4a648ef126b2d081a867318c11ca21882927a240 [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);
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);
75
Saurabh Shahacf10202013-02-26 10:15:15 -080076 /* returns session id */
77 int getPipeId() const;
78 /* returns the fd associated to ctrl*/
79 int getFd() const;
80 /* returns a copy ro dst rect dim */
81 utils::Dim getDstRectDim() const;
82 /* returns a copy to src rect dim */
83 utils::Dim getSrcRectDim() const;
Saurabh Shah5daeee52013-01-23 16:52:26 +080084 /* setVisualParam */
85 bool setVisualParams(const MetaData_t& data);
Saurabh Shahdf0be752013-05-23 14:40:00 -070086 void forceSet();
Naseer Ahmed29a26812012-06-14 00:56:20 -070087
Saurabh Shahacf10202013-02-26 10:15:15 -080088private:
89 /* Perform transformation calculations */
90 void doTransform();
91 void doDownscale();
92 /* get orient / user_data[0] */
93 int getOrient() const;
94 /* overlay get */
95 bool get();
96 /* 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);
120 /* return true if current overlay is different
121 * than last known good overlay */
122 bool ovChanged() const;
123 /* save mOVInfo to be last known good ov*/
124 void save();
125 /* restore last known good ov to be the current */
126 void restore();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700127
128 utils::eTransform mOrientation; //Holds requested orientation
Naseer Ahmed29a26812012-06-14 00:56:20 -0700129 /* last good known ov info */
130 mdp_overlay mLkgo;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700131 /* Actual overlay mdp structure */
132 mdp_overlay mOVInfo;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700133 /* FD for the mdp fbnum */
134 OvFD mFd;
Saurabh Shahacf10202013-02-26 10:15:15 -0800135 int mDownscale;
Saurabh Shahdf0be752013-05-23 14:40:00 -0700136 bool mForceSet;
137
Saurabh Shah5daeee52013-01-23 16:52:26 +0800138#ifdef USES_POST_PROCESSING
139 /* PP Compute Params */
140 struct compute_params mParams;
141 /* indicate if PP params have been changed */
142 bool mPPChanged;
143#endif
Naseer Ahmed29a26812012-06-14 00:56:20 -0700144};
145
146
147/* MDP 3D related ctrl */
148class MdpCtrl3D {
149public:
150 /* ctor reset data */
151 MdpCtrl3D();
152 /* calls MSMFB_OVERLAY_3D */
153 bool close();
154 /* set w/h. format is ignored*/
155 void setWh(const utils::Whf& whf);
156 /* set is_3d calls MSMFB_OVERLAY_3D */
157 bool useVirtualFB();
158 /* set fd to be used in ioctl */
159 void setFd(int fd);
160 /* dump */
161 void dump() const;
162private:
163 /* reset */
164 void reset();
165 /* actual MSM 3D info */
166 msmfb_overlay_3d m3DOVInfo;
167 /* FD for the mdp 3D */
168 OvFD mFd;
169};
170
171/* MDP data */
172class MdpData {
173public:
174 /* ctor reset data */
175 explicit MdpData();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700176 /* dtor close*/
177 ~MdpData();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700178 /* init FD */
179 bool init(uint32_t fbnum);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700180 /* memset0 the underlying mdp object */
181 void reset();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700182 /* close fd, and reset */
183 bool close();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700184 /* set id of mdp data */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700185 void setPipeId(int id);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700186 /* return ses id of data */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700187 int getPipeId() const;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700188 /* get underlying fd*/
189 int getFd() const;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700190 /* get memory_id */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700191 int getSrcMemoryId() const;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700192 /* calls wrapper play */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700193 bool play(int fd, uint32_t offset);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700194 /* dump state of the object */
195 void dump() const;
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800196 /* Return the dump in the specified buffer */
197 void getDump(char *buf, size_t len);
198
Naseer Ahmed29a26812012-06-14 00:56:20 -0700199private:
200
201 /* actual overlay mdp data */
202 msmfb_overlay_data mOvData;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700203 /* fd to mdp fbnum */
204 OvFD mFd;
205};
206
207//--------------Inlines---------------------------------
Naseer Ahmed29a26812012-06-14 00:56:20 -0700208
209///// MdpCtrl //////
210
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700211inline MdpCtrl::MdpCtrl() {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700212 reset();
213}
214
215inline MdpCtrl::~MdpCtrl() {
216 close();
217}
218
219inline int MdpCtrl::getOrient() const {
220 return getUserData();
221}
222
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700223inline int MdpCtrl::getPipeId() const {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700224 return mOVInfo.id;
225}
226
227inline int MdpCtrl::getFd() const {
228 return mFd.getFD();
229}
230
231inline int MdpCtrl::getFlags() const {
232 return mOVInfo.flags;
233}
234
235inline void MdpCtrl::setFlags(int f) {
236 mOVInfo.flags = f;
237}
238
239inline void MdpCtrl::setZ(overlay::utils::eZorder z) {
240 mOVInfo.z_order = z;
241}
242
Naseer Ahmed29a26812012-06-14 00:56:20 -0700243inline void MdpCtrl::setIsFg(overlay::utils::eIsFg isFg) {
244 mOVInfo.is_fg = isFg;
245}
246
Saurabh Shahacf10202013-02-26 10:15:15 -0800247inline void MdpCtrl::setDownscale(int dscale) {
248 mDownscale = dscale;
249}
250
Naseer Ahmed522ce662013-03-18 20:14:05 -0400251inline void MdpCtrl::setPlaneAlpha(int planeAlpha) {
252 mOVInfo.alpha = planeAlpha;
253}
254
255inline void MdpCtrl::setBlending(overlay::utils::eBlending blending) {
256 switch((int) blending) {
257 case utils::OVERLAY_BLENDING_OPAQUE:
258 mOVInfo.blend_op = BLEND_OP_OPAQUE;
259 break;
260 case utils::OVERLAY_BLENDING_PREMULT:
261 mOVInfo.blend_op = BLEND_OP_PREMULTIPLIED;
262 break;
263 case utils::OVERLAY_BLENDING_COVERAGE:
264 default:
265 mOVInfo.blend_op = BLEND_OP_COVERAGE;
266 }
267}
268
Naseer Ahmed29a26812012-06-14 00:56:20 -0700269inline bool MdpCtrl::ovChanged() const {
Saurabh Shah5daeee52013-01-23 16:52:26 +0800270#ifdef USES_POST_PROCESSING
271 // Some pp params are stored as pointer address,
272 // so can't compare their content directly.
273 if (mPPChanged) {
274 return true;
275 }
276#endif
Naseer Ahmed29a26812012-06-14 00:56:20 -0700277 // 0 means same
278 if(0 == ::memcmp(&mOVInfo, &mLkgo, sizeof (mdp_overlay))) {
279 return false;
280 }
281 return true;
282}
283
284inline void MdpCtrl::save() {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700285 if(static_cast<ssize_t>(mOVInfo.id) == MSMFB_NEW_REQUEST) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700286 ALOGE("MdpCtrl current ov has id -1, will not save");
Naseer Ahmed29a26812012-06-14 00:56:20 -0700287 return;
288 }
289 mLkgo = mOVInfo;
290}
291
292inline void MdpCtrl::restore() {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700293 if(static_cast<ssize_t>(mLkgo.id) == MSMFB_NEW_REQUEST) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700294 ALOGE("MdpCtrl Lkgo ov has id -1, will not restore");
Naseer Ahmed29a26812012-06-14 00:56:20 -0700295 return;
296 }
297 mOVInfo = mLkgo;
298}
299
300inline overlay::utils::Whf MdpCtrl::getSrcWhf() const {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700301 return utils::Whf( mOVInfo.src.width,
302 mOVInfo.src.height,
303 mOVInfo.src.format);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700304}
305
306inline void MdpCtrl::setSrcWhf(const overlay::utils::Whf& whf) {
307 mOVInfo.src.width = whf.w;
308 mOVInfo.src.height = whf.h;
309 mOVInfo.src.format = whf.format;
310}
311
312inline overlay::utils::Dim MdpCtrl::getSrcRectDim() const {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700313 return utils::Dim( mOVInfo.src_rect.x,
314 mOVInfo.src_rect.y,
315 mOVInfo.src_rect.w,
316 mOVInfo.src_rect.h);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700317}
318
319inline void MdpCtrl::setSrcRectDim(const overlay::utils::Dim d) {
320 mOVInfo.src_rect.x = d.x;
321 mOVInfo.src_rect.y = d.y;
322 mOVInfo.src_rect.w = d.w;
323 mOVInfo.src_rect.h = d.h;
324}
325
326inline overlay::utils::Dim MdpCtrl::getDstRectDim() const {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700327 return utils::Dim( mOVInfo.dst_rect.x,
328 mOVInfo.dst_rect.y,
329 mOVInfo.dst_rect.w,
330 mOVInfo.dst_rect.h);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700331}
332
333inline void MdpCtrl::setDstRectDim(const overlay::utils::Dim d) {
334 mOVInfo.dst_rect.x = d.x;
335 mOVInfo.dst_rect.y = d.y;
336 mOVInfo.dst_rect.w = d.w;
337 mOVInfo.dst_rect.h = d.h;
338}
339
340inline int MdpCtrl::getUserData() const { return mOVInfo.user_data[0]; }
341
342inline void MdpCtrl::setUserData(int v) { mOVInfo.user_data[0] = v; }
343
344inline void MdpCtrl::setRotationFlags() {
345 const int u = getUserData();
Saurabh Shah76fd6552013-03-14 14:45:38 -0700346 if (u & MDP_ROT_90)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700347 mOVInfo.flags |= MDP_SOURCE_ROTATED_90;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700348}
349
Saurabh Shahdf0be752013-05-23 14:40:00 -0700350inline void MdpCtrl::forceSet() {
351 mForceSet = true;
352}
353
Naseer Ahmed29a26812012-06-14 00:56:20 -0700354/////// MdpCtrl3D //////
355
356inline MdpCtrl3D::MdpCtrl3D() { reset(); }
357inline bool MdpCtrl3D::close() {
358 if (m3DOVInfo.is_3d) {
359 m3DOVInfo.is_3d = 0;
360 if(!mdp_wrapper::set3D(mFd.getFD(), m3DOVInfo)) {
361 ALOGE("MdpCtrl3D close failed set3D with 0");
362 return false;
363 }
364 }
365 reset();
366 return true;
367}
368inline void MdpCtrl3D::reset() {
369 utils::memset0(m3DOVInfo);
370}
371
372inline void MdpCtrl3D::setFd(int fd) {
373 mFd.copy(fd);
374 OVASSERT(mFd.valid(), "MdpCtrl3D setFd, FD should be valid");
375}
376
377inline void MdpCtrl3D::setWh(const utils::Whf& whf) {
378 // ignore fmt. Needed for useVirtualFB callflow
379 m3DOVInfo.width = whf.w;
380 m3DOVInfo.height = whf.h;
381}
382
383inline bool MdpCtrl3D::useVirtualFB() {
384 if(!m3DOVInfo.is_3d) {
385 m3DOVInfo.is_3d = 1;
386 if(!mdp_wrapper::set3D(mFd.getFD(), m3DOVInfo)) {
387 ALOGE("MdpCtrl3D close failed set3D with 0");
388 return false;
389 }
390 }
391 return true;
392}
393
394/////// MdpData //////
395
396inline MdpData::MdpData() { reset(); }
397
398inline MdpData::~MdpData() { close(); }
399
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700400inline bool MdpData::init(uint32_t fbnum) {
401 // FD init
402 if(!utils::openDev(mFd, fbnum, Res::fbPath, O_RDWR)){
403 ALOGE("Ctrl failed to init fbnum=%d", fbnum);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700404 return false;
405 }
406 return true;
407}
408
409inline void MdpData::reset() {
410 overlay::utils::memset0(mOvData);
411 mOvData.data.memory_id = -1;
412}
413
414inline bool MdpData::close() {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700415 reset();
Saurabh Shah8e1ae952012-08-15 12:15:14 -0700416 return mFd.close();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700417}
418
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700419inline int MdpData::getSrcMemoryId() const { return mOvData.data.memory_id; }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700420
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700421inline void MdpData::setPipeId(int id) { mOvData.id = id; }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700422
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700423inline int MdpData::getPipeId() const { return mOvData.id; }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700424
425inline int MdpData::getFd() const { return mFd.getFD(); }
426
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700427inline bool MdpData::play(int fd, uint32_t offset) {
428 mOvData.data.memory_id = fd;
429 mOvData.data.offset = offset;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700430 if(!mdp_wrapper::play(mFd.getFD(), mOvData)){
431 ALOGE("MdpData failed to play");
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700432 dump();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700433 return false;
434 }
435 return true;
436}
437
Naseer Ahmed29a26812012-06-14 00:56:20 -0700438} // overlay
439
440#endif // OVERLAY_MDP_H