blob: 695657b1da4441050cf04dc2caba1fac6e87e15d [file] [log] [blame]
Naseer Ahmed29a26812012-06-14 00:56:20 -07001/*
2* Copyright (C) 2008 The Android Open Source Project
3* Copyright (c) 2010-2012, Code Aurora Forum. All rights reserved.
4*
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"
Naseer Ahmed29a26812012-06-14 00:56:20 -070025
26namespace overlay{
27
Naseer Ahmed29a26812012-06-14 00:56:20 -070028/*
29* Mdp Ctrl holds corresponding fd and MDP related struct.
30* It is simple wrapper to MDP services
31* */
32class MdpCtrl {
33public:
34 /* ctor reset */
35 explicit MdpCtrl();
36
37 /* dtor close */
38 ~MdpCtrl();
39
Naseer Ahmedf48aef62012-07-20 09:05:53 -070040 /* init underlying device using fbnum */
41 bool init(uint32_t fbnum);
Naseer Ahmed29a26812012-06-14 00:56:20 -070042
43 /* unset overlay, reset and close fd */
44 bool close();
45
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();
48
49 /* get orient / user_data[0] */
50 int getOrient() const;
51
52 /* returns session id */
Naseer Ahmedf48aef62012-07-20 09:05:53 -070053 int getPipeId() const;
Naseer Ahmed29a26812012-06-14 00:56:20 -070054
55 /* returns the fd associated to ctrl*/
56 int getFd() const;
57
58 /* Get screen info. out: info*/
59 bool getScreenInfo(utils::ScreenInfo& info);
60
61 /* overlay get */
62 bool get();
63
Naseer Ahmedf48aef62012-07-20 09:05:53 -070064 /* returns flags from mdp structure */
Naseer Ahmed29a26812012-06-14 00:56:20 -070065 int getFlags() const;
66
67 /* set flags to mdp structure */
68 void setFlags(int f);
69
Naseer Ahmed29a26812012-06-14 00:56:20 -070070 /* set z order */
71 void setZ(utils::eZorder z);
72
Naseer Ahmed29a26812012-06-14 00:56:20 -070073 /* set isFg flag */
74 void setIsFg(utils::eIsFg isFg);
75
76 /* calls overlay set
77 * Set would always consult last good known ov instance.
78 * Only if it is different, set would actually exectue ioctl.
79 * On a sucess ioctl. last good known ov instance is updated */
80 bool set();
81
82 /* return a copy of src whf*/
83 utils::Whf getSrcWhf() const;
84
85 /* set src whf */
86 void setSrcWhf(const utils::Whf& whf);
87
Naseer Ahmedf48aef62012-07-20 09:05:53 -070088 /* adjust source width height format based on rot info */
89 void adjustSrcWhf(const bool& rotUsed);
Naseer Ahmed29a26812012-06-14 00:56:20 -070090
91 /* swap src w/h*/
92 void swapSrcWH();
93
94 /* swap src rect w/h */
95 void swapSrcRectWH();
96
97 /* returns a copy to src rect dim */
98 utils::Dim getSrcRectDim() const;
99
100 /* set src/dst rect dim */
101 void setSrcRectDim(const utils::Dim d);
102 void setDstRectDim(const utils::Dim d);
103
104 /* returns a copy ro dst rect dim */
105 utils::Dim getDstRectDim() const;
106
107 /* returns user_data[0]*/
108 int getUserData() const;
109
110 /* sets user_data[0] */
111 void setUserData(int v);
112
113 /* return true if current overlay is different
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700114 * than last known good overlay */
Naseer Ahmed29a26812012-06-14 00:56:20 -0700115 bool ovChanged() const;
116
117 /* save mOVInfo to be last known good ov*/
118 void save();
119
120 /* restore last known good ov to be the current */
121 void restore();
122
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700123 /* Sets the source total width, height, format */
124 bool setSource(const utils::PipeArgs& pargs);
125
Naseer Ahmed29a26812012-06-14 00:56:20 -0700126 /*
127 * Sets ROI, the unpadded region, for source buffer.
128 * Should be called before a setPosition, for small clips.
129 * Dim - ROI dimensions.
130 */
131 bool setCrop(const utils::Dim& d);
132
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700133 bool setTransform(const utils::eTransform& orient, const bool& rotUsed);
134
Naseer Ahmed29a26812012-06-14 00:56:20 -0700135 /* given a dim and w/h, set overlay dim */
136 bool setPosition(const utils::Dim& dim, int w, int h);
137
138 /* using user_data, sets/unsets roationvalue in mdp flags */
139 void setRotationFlags();
140
141 /* dump state of the object */
142 void dump() const;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700143
Naseer Ahmed29a26812012-06-14 00:56:20 -0700144private:
145
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700146 /* helper functions for overlayTransform */
147 void doTransform();
148 void overlayTransFlipH();
149 void overlayTransFlipV();
150 void overlayTransRot90();
151
152 utils::eTransform mOrientation; //Holds requested orientation
153 bool mRotUsed; //whether rotator should be used even if requested
154 //orientation is 0.
155
Naseer Ahmed29a26812012-06-14 00:56:20 -0700156 /* last good known ov info */
157 mdp_overlay mLkgo;
158
159 /* Actual overlay mdp structure */
160 mdp_overlay mOVInfo;
161
162 /* FD for the mdp fbnum */
163 OvFD mFd;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700164};
165
166
167/* MDP 3D related ctrl */
168class MdpCtrl3D {
169public:
170 /* ctor reset data */
171 MdpCtrl3D();
172 /* calls MSMFB_OVERLAY_3D */
173 bool close();
174 /* set w/h. format is ignored*/
175 void setWh(const utils::Whf& whf);
176 /* set is_3d calls MSMFB_OVERLAY_3D */
177 bool useVirtualFB();
178 /* set fd to be used in ioctl */
179 void setFd(int fd);
180 /* dump */
181 void dump() const;
182private:
183 /* reset */
184 void reset();
185 /* actual MSM 3D info */
186 msmfb_overlay_3d m3DOVInfo;
187 /* FD for the mdp 3D */
188 OvFD mFd;
189};
190
191/* MDP data */
192class MdpData {
193public:
194 /* ctor reset data */
195 explicit MdpData();
196
197 /* dtor close*/
198 ~MdpData();
199
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700200 /* init FD */
201 bool init(uint32_t fbnum);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700202
203 /* memset0 the underlying mdp object */
204 void reset();
205
206 /* close fd, and reset */
207 bool close();
208
Naseer Ahmed29a26812012-06-14 00:56:20 -0700209 /* set id of mdp data */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700210 void setPipeId(int id);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700211
212 /* return ses id of data */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700213 int getPipeId() const;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700214
215 /* get underlying fd*/
216 int getFd() const;
217
218 /* get memory_id */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700219 int getSrcMemoryId() const;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700220
221 /* calls wrapper play */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700222 bool play(int fd, uint32_t offset);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700223
Naseer Ahmed29a26812012-06-14 00:56:20 -0700224 /* dump state of the object */
225 void dump() const;
226private:
227
228 /* actual overlay mdp data */
229 msmfb_overlay_data mOvData;
230
231 /* fd to mdp fbnum */
232 OvFD mFd;
233};
234
235//--------------Inlines---------------------------------
236namespace utils {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700237inline bool openDev(OvFD& fd, int fbnum,
238 const char* const devpath,
239 int flags) {
240 return overlay::open(fd, fbnum, devpath, flags);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700241}
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700242}
243namespace {
244// just a helper func for common operations x-(y+z)
245int compute(uint32_t x, uint32_t y, uint32_t z) {
246 return x-(y+z);
247}
248}
Naseer Ahmed29a26812012-06-14 00:56:20 -0700249
250///// MdpCtrl //////
251
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700252inline MdpCtrl::MdpCtrl() {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700253 reset();
254}
255
256inline MdpCtrl::~MdpCtrl() {
257 close();
258}
259
260inline int MdpCtrl::getOrient() const {
261 return getUserData();
262}
263
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700264inline int MdpCtrl::getPipeId() const {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700265 return mOVInfo.id;
266}
267
268inline int MdpCtrl::getFd() const {
269 return mFd.getFD();
270}
271
272inline int MdpCtrl::getFlags() const {
273 return mOVInfo.flags;
274}
275
276inline void MdpCtrl::setFlags(int f) {
277 mOVInfo.flags = f;
278}
279
280inline void MdpCtrl::setZ(overlay::utils::eZorder z) {
281 mOVInfo.z_order = z;
282}
283
Naseer Ahmed29a26812012-06-14 00:56:20 -0700284inline void MdpCtrl::setIsFg(overlay::utils::eIsFg isFg) {
285 mOVInfo.is_fg = isFg;
286}
287
288inline bool MdpCtrl::ovChanged() const {
289 // 0 means same
290 if(0 == ::memcmp(&mOVInfo, &mLkgo, sizeof (mdp_overlay))) {
291 return false;
292 }
293 return true;
294}
295
296inline void MdpCtrl::save() {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700297 if(static_cast<ssize_t>(mOVInfo.id) == MSMFB_NEW_REQUEST) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700298 ALOGE("MdpCtrl current ov has id -1, will not save");
Naseer Ahmed29a26812012-06-14 00:56:20 -0700299 return;
300 }
301 mLkgo = mOVInfo;
302}
303
304inline void MdpCtrl::restore() {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700305 if(static_cast<ssize_t>(mLkgo.id) == MSMFB_NEW_REQUEST) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700306 ALOGE("MdpCtrl Lkgo ov has id -1, will not restore");
Naseer Ahmed29a26812012-06-14 00:56:20 -0700307 return;
308 }
309 mOVInfo = mLkgo;
310}
311
312inline overlay::utils::Whf MdpCtrl::getSrcWhf() const {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700313 return utils::Whf( mOVInfo.src.width,
314 mOVInfo.src.height,
315 mOVInfo.src.format);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700316}
317
318inline void MdpCtrl::setSrcWhf(const overlay::utils::Whf& whf) {
319 mOVInfo.src.width = whf.w;
320 mOVInfo.src.height = whf.h;
321 mOVInfo.src.format = whf.format;
322}
323
324inline overlay::utils::Dim MdpCtrl::getSrcRectDim() const {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700325 return utils::Dim( mOVInfo.src_rect.x,
326 mOVInfo.src_rect.y,
327 mOVInfo.src_rect.w,
328 mOVInfo.src_rect.h);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700329}
330
331inline void MdpCtrl::setSrcRectDim(const overlay::utils::Dim d) {
332 mOVInfo.src_rect.x = d.x;
333 mOVInfo.src_rect.y = d.y;
334 mOVInfo.src_rect.w = d.w;
335 mOVInfo.src_rect.h = d.h;
336}
337
338inline overlay::utils::Dim MdpCtrl::getDstRectDim() const {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700339 return utils::Dim( mOVInfo.dst_rect.x,
340 mOVInfo.dst_rect.y,
341 mOVInfo.dst_rect.w,
342 mOVInfo.dst_rect.h);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700343}
344
345inline void MdpCtrl::setDstRectDim(const overlay::utils::Dim d) {
346 mOVInfo.dst_rect.x = d.x;
347 mOVInfo.dst_rect.y = d.y;
348 mOVInfo.dst_rect.w = d.w;
349 mOVInfo.dst_rect.h = d.h;
350}
351
352inline int MdpCtrl::getUserData() const { return mOVInfo.user_data[0]; }
353
354inline void MdpCtrl::setUserData(int v) { mOVInfo.user_data[0] = v; }
355
356inline void MdpCtrl::setRotationFlags() {
357 const int u = getUserData();
358 if (u == MDP_ROT_90 || u == MDP_ROT_270)
359 mOVInfo.flags |= MDP_SOURCE_ROTATED_90;
360 else
361 mOVInfo.flags &= ~MDP_SOURCE_ROTATED_90;
362}
363
Naseer Ahmed29a26812012-06-14 00:56:20 -0700364inline void MdpCtrl::swapSrcWH() {
365 utils::swap(mOVInfo.src.width,
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700366 mOVInfo.src.height);
367}
Naseer Ahmed29a26812012-06-14 00:56:20 -0700368
369inline void MdpCtrl::swapSrcRectWH() {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700370 utils::swap(mOVInfo.src_rect.w,
371 mOVInfo.src_rect.h);
372}
373
374inline void MdpCtrl::overlayTransFlipH()
375{
376 utils::Dim d = getSrcRectDim();
377 utils::Whf whf = getSrcWhf();
378 d.x = compute(whf.w, d.x, d.w);
379 setSrcRectDim(d);
380}
381
382inline void MdpCtrl::overlayTransFlipV()
383{
384 utils::Dim d = getSrcRectDim();
385 utils::Whf whf = getSrcWhf();
386 d.y = compute(whf.h, d.y, d.h);
387 setSrcRectDim(d);
388}
389
390inline void MdpCtrl::overlayTransRot90()
391{
392 utils::Dim d = getSrcRectDim();
393 utils::Whf whf = getSrcWhf();
394 int tmp = d.x;
395 d.x = compute(whf.h,
396 d.y,
397 d.h);
398 d.y = tmp;
399 setSrcRectDim(d);
400 swapSrcWH();
401 swapSrcRectWH();
402}
403
Naseer Ahmed29a26812012-06-14 00:56:20 -0700404
405/////// MdpCtrl3D //////
406
407inline MdpCtrl3D::MdpCtrl3D() { reset(); }
408inline bool MdpCtrl3D::close() {
409 if (m3DOVInfo.is_3d) {
410 m3DOVInfo.is_3d = 0;
411 if(!mdp_wrapper::set3D(mFd.getFD(), m3DOVInfo)) {
412 ALOGE("MdpCtrl3D close failed set3D with 0");
413 return false;
414 }
415 }
416 reset();
417 return true;
418}
419inline void MdpCtrl3D::reset() {
420 utils::memset0(m3DOVInfo);
421}
422
423inline void MdpCtrl3D::setFd(int fd) {
424 mFd.copy(fd);
425 OVASSERT(mFd.valid(), "MdpCtrl3D setFd, FD should be valid");
426}
427
428inline void MdpCtrl3D::setWh(const utils::Whf& whf) {
429 // ignore fmt. Needed for useVirtualFB callflow
430 m3DOVInfo.width = whf.w;
431 m3DOVInfo.height = whf.h;
432}
433
434inline bool MdpCtrl3D::useVirtualFB() {
435 if(!m3DOVInfo.is_3d) {
436 m3DOVInfo.is_3d = 1;
437 if(!mdp_wrapper::set3D(mFd.getFD(), m3DOVInfo)) {
438 ALOGE("MdpCtrl3D close failed set3D with 0");
439 return false;
440 }
441 }
442 return true;
443}
444
445/////// MdpData //////
446
447inline MdpData::MdpData() { reset(); }
448
449inline MdpData::~MdpData() { close(); }
450
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700451inline bool MdpData::init(uint32_t fbnum) {
452 // FD init
453 if(!utils::openDev(mFd, fbnum, Res::fbPath, O_RDWR)){
454 ALOGE("Ctrl failed to init fbnum=%d", fbnum);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700455 return false;
456 }
457 return true;
458}
459
460inline void MdpData::reset() {
461 overlay::utils::memset0(mOvData);
462 mOvData.data.memory_id = -1;
463}
464
465inline bool MdpData::close() {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700466 reset();
Saurabh Shah8e1ae952012-08-15 12:15:14 -0700467 return mFd.close();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700468}
469
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700470inline int MdpData::getSrcMemoryId() const { return mOvData.data.memory_id; }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700471
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700472inline void MdpData::setPipeId(int id) { mOvData.id = id; }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700473
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700474inline int MdpData::getPipeId() const { return mOvData.id; }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700475
476inline int MdpData::getFd() const { return mFd.getFD(); }
477
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700478inline bool MdpData::play(int fd, uint32_t offset) {
479 mOvData.data.memory_id = fd;
480 mOvData.data.offset = offset;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700481 if(!mdp_wrapper::play(mFd.getFD(), mOvData)){
482 ALOGE("MdpData failed to play");
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700483 dump();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700484 return false;
485 }
486 return true;
487}
488
Naseer Ahmed29a26812012-06-14 00:56:20 -0700489} // overlay
490
491#endif // OVERLAY_MDP_H