2012-06-14 07:56:20 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2008 The Android Open Source Project
|
|
|
|
* Copyright (c) 2010-2012, Code Aurora Forum. All rights reserved.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef OVERLAY_MDP_H
|
|
|
|
#define OVERLAY_MDP_H
|
|
|
|
|
|
|
|
#include <linux/msm_mdp.h>
|
|
|
|
|
|
|
|
#include "overlayUtils.h"
|
|
|
|
#include "mdpWrapper.h"
|
|
|
|
|
|
|
|
namespace overlay{
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Mdp Ctrl holds corresponding fd and MDP related struct.
|
|
|
|
* It is simple wrapper to MDP services
|
|
|
|
* */
|
|
|
|
class MdpCtrl {
|
|
|
|
public:
|
|
|
|
/* ctor reset */
|
|
|
|
explicit MdpCtrl();
|
|
|
|
|
|
|
|
/* dtor close */
|
|
|
|
~MdpCtrl();
|
|
|
|
|
2012-07-10 20:07:52 +00:00
|
|
|
/* init underlying device using fbnum */
|
|
|
|
bool init(uint32_t fbnum);
|
2012-06-14 07:56:20 +00:00
|
|
|
|
|
|
|
/* unset overlay, reset and close fd */
|
|
|
|
bool close();
|
|
|
|
|
2012-07-10 20:07:52 +00:00
|
|
|
/* reset and set ov id to -1 / MSMFB_NEW_REQUEST */
|
2012-06-14 07:56:20 +00:00
|
|
|
void reset();
|
|
|
|
|
|
|
|
/* get orient / user_data[0] */
|
|
|
|
int getOrient() const;
|
|
|
|
|
|
|
|
/* returns session id */
|
2012-07-10 20:07:52 +00:00
|
|
|
int getPipeId() const;
|
2012-06-14 07:56:20 +00:00
|
|
|
|
|
|
|
/* returns the fd associated to ctrl*/
|
|
|
|
int getFd() const;
|
|
|
|
|
|
|
|
/* Get screen info. out: info*/
|
|
|
|
bool getScreenInfo(utils::ScreenInfo& info);
|
|
|
|
|
|
|
|
/* overlay get */
|
|
|
|
bool get();
|
|
|
|
|
|
|
|
/* returns flags from mdp structure.
|
|
|
|
* Flags are WAIT/NOWAIT/PIPE SHARED*/
|
|
|
|
int getFlags() const;
|
|
|
|
|
|
|
|
/* set flags to mdp structure */
|
|
|
|
void setFlags(int f);
|
|
|
|
|
|
|
|
/* set z order */
|
|
|
|
void setZ(utils::eZorder z);
|
|
|
|
|
|
|
|
/* set Wait/nowait */
|
|
|
|
void setWait(utils::eWait wait);
|
|
|
|
|
|
|
|
/* set isFg flag */
|
|
|
|
void setIsFg(utils::eIsFg isFg);
|
|
|
|
|
|
|
|
/* calls overlay set
|
|
|
|
* Set would always consult last good known ov instance.
|
|
|
|
* Only if it is different, set would actually exectue ioctl.
|
|
|
|
* On a sucess ioctl. last good known ov instance is updated */
|
|
|
|
bool set();
|
|
|
|
|
|
|
|
/* return a copy of src whf*/
|
|
|
|
utils::Whf getSrcWhf() const;
|
|
|
|
|
|
|
|
/* set src whf */
|
|
|
|
void setSrcWhf(const utils::Whf& whf);
|
|
|
|
|
2012-07-10 20:07:52 +00:00
|
|
|
/* adjust source width height format based on rot info */
|
|
|
|
void adjustSrcWhf(const bool& rotUsed);
|
2012-06-14 07:56:20 +00:00
|
|
|
|
|
|
|
/* swap src w/h*/
|
|
|
|
void swapSrcWH();
|
|
|
|
|
|
|
|
/* swap src rect w/h */
|
|
|
|
void swapSrcRectWH();
|
|
|
|
|
|
|
|
/* returns a copy to src rect dim */
|
|
|
|
utils::Dim getSrcRectDim() const;
|
|
|
|
|
|
|
|
/* set src/dst rect dim */
|
|
|
|
void setSrcRectDim(const utils::Dim d);
|
|
|
|
void setDstRectDim(const utils::Dim d);
|
|
|
|
|
|
|
|
/* returns a copy ro dst rect dim */
|
|
|
|
utils::Dim getDstRectDim() const;
|
|
|
|
|
|
|
|
/* returns user_data[0]*/
|
|
|
|
int getUserData() const;
|
|
|
|
|
|
|
|
/* sets user_data[0] */
|
|
|
|
void setUserData(int v);
|
|
|
|
|
|
|
|
/* return true if current overlay is different
|
2012-07-10 20:07:52 +00:00
|
|
|
* than last known good overlay */
|
2012-06-14 07:56:20 +00:00
|
|
|
bool ovChanged() const;
|
|
|
|
|
|
|
|
/* save mOVInfo to be last known good ov*/
|
|
|
|
void save();
|
|
|
|
|
|
|
|
/* restore last known good ov to be the current */
|
|
|
|
void restore();
|
|
|
|
|
2012-07-10 20:07:52 +00:00
|
|
|
/* Sets the source total width, height, format */
|
|
|
|
bool setSource(const utils::PipeArgs& pargs);
|
|
|
|
|
2012-06-14 07:56:20 +00:00
|
|
|
/*
|
|
|
|
* Sets ROI, the unpadded region, for source buffer.
|
|
|
|
* Should be called before a setPosition, for small clips.
|
|
|
|
* Dim - ROI dimensions.
|
|
|
|
*/
|
|
|
|
bool setCrop(const utils::Dim& d);
|
|
|
|
|
2012-07-10 20:07:52 +00:00
|
|
|
bool setTransform(const utils::eTransform& orient, const bool& rotUsed);
|
|
|
|
|
2012-06-14 07:56:20 +00:00
|
|
|
/* given a dim and w/h, set overlay dim */
|
|
|
|
bool setPosition(const utils::Dim& dim, int w, int h);
|
|
|
|
|
|
|
|
/* using user_data, sets/unsets roationvalue in mdp flags */
|
|
|
|
void setRotationFlags();
|
|
|
|
|
|
|
|
/* dump state of the object */
|
|
|
|
void dump() const;
|
2012-07-10 20:07:52 +00:00
|
|
|
|
2012-06-14 07:56:20 +00:00
|
|
|
private:
|
|
|
|
|
2012-07-10 20:07:52 +00:00
|
|
|
/* helper functions for overlayTransform */
|
|
|
|
void overlayTransFlipRot90();
|
|
|
|
void overlayTransFlipRot270();
|
|
|
|
|
2012-06-14 07:56:20 +00:00
|
|
|
/* last good known ov info */
|
|
|
|
mdp_overlay mLkgo;
|
|
|
|
|
|
|
|
/* Actual overlay mdp structure */
|
|
|
|
mdp_overlay mOVInfo;
|
|
|
|
|
|
|
|
/* FD for the mdp fbnum */
|
|
|
|
OvFD mFd;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* MDP 3D related ctrl */
|
|
|
|
class MdpCtrl3D {
|
|
|
|
public:
|
|
|
|
/* ctor reset data */
|
|
|
|
MdpCtrl3D();
|
|
|
|
/* calls MSMFB_OVERLAY_3D */
|
|
|
|
bool close();
|
|
|
|
/* set w/h. format is ignored*/
|
|
|
|
void setWh(const utils::Whf& whf);
|
|
|
|
/* set is_3d calls MSMFB_OVERLAY_3D */
|
|
|
|
bool useVirtualFB();
|
|
|
|
/* set fd to be used in ioctl */
|
|
|
|
void setFd(int fd);
|
|
|
|
/* dump */
|
|
|
|
void dump() const;
|
|
|
|
private:
|
|
|
|
/* reset */
|
|
|
|
void reset();
|
|
|
|
/* actual MSM 3D info */
|
|
|
|
msmfb_overlay_3d m3DOVInfo;
|
|
|
|
/* FD for the mdp 3D */
|
|
|
|
OvFD mFd;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* MDP data */
|
|
|
|
class MdpData {
|
|
|
|
public:
|
|
|
|
/* ctor reset data */
|
|
|
|
explicit MdpData();
|
|
|
|
|
|
|
|
/* dtor close*/
|
|
|
|
~MdpData();
|
|
|
|
|
2012-07-10 20:07:52 +00:00
|
|
|
/* init FD */
|
|
|
|
bool init(uint32_t fbnum);
|
2012-06-14 07:56:20 +00:00
|
|
|
|
|
|
|
/* memset0 the underlying mdp object */
|
|
|
|
void reset();
|
|
|
|
|
|
|
|
/* close fd, and reset */
|
|
|
|
bool close();
|
|
|
|
|
|
|
|
/* set id of mdp data */
|
2012-07-10 20:07:52 +00:00
|
|
|
void setPipeId(int id);
|
2012-06-14 07:56:20 +00:00
|
|
|
|
|
|
|
/* return ses id of data */
|
2012-07-10 20:07:52 +00:00
|
|
|
int getPipeId() const;
|
2012-06-14 07:56:20 +00:00
|
|
|
|
|
|
|
/* get underlying fd*/
|
|
|
|
int getFd() const;
|
|
|
|
|
|
|
|
/* get memory_id */
|
2012-07-10 20:07:52 +00:00
|
|
|
int getSrcMemoryId() const;
|
2012-06-14 07:56:20 +00:00
|
|
|
|
|
|
|
/* calls wrapper play */
|
2012-07-10 20:07:52 +00:00
|
|
|
bool play(int fd, uint32_t offset);
|
2012-06-14 07:56:20 +00:00
|
|
|
|
2012-07-10 20:07:52 +00:00
|
|
|
/* calls wrapper waitForVsync */
|
|
|
|
bool waitForVsync();
|
2012-06-14 07:56:20 +00:00
|
|
|
|
|
|
|
/* dump state of the object */
|
|
|
|
void dump() const;
|
|
|
|
private:
|
|
|
|
|
|
|
|
/* actual overlay mdp data */
|
|
|
|
msmfb_overlay_data mOvData;
|
|
|
|
|
|
|
|
/* fd to mdp fbnum */
|
|
|
|
OvFD mFd;
|
|
|
|
};
|
|
|
|
|
|
|
|
//--------------Inlines---------------------------------
|
|
|
|
namespace utils {
|
2012-07-10 20:07:52 +00:00
|
|
|
inline bool openDev(OvFD& fd, int fbnum,
|
|
|
|
const char* const devpath,
|
|
|
|
int flags) {
|
|
|
|
return overlay::open(fd, fbnum, devpath, flags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
namespace {
|
|
|
|
// just a helper func for common operations x-(y+z)
|
|
|
|
int compute(uint32_t x, uint32_t y, uint32_t z) {
|
|
|
|
return x-(y+z);
|
|
|
|
}
|
2012-06-14 07:56:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
///// MdpCtrl //////
|
|
|
|
|
2012-07-10 20:07:52 +00:00
|
|
|
inline MdpCtrl::MdpCtrl() {
|
2012-06-14 07:56:20 +00:00
|
|
|
reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline MdpCtrl::~MdpCtrl() {
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline int MdpCtrl::getOrient() const {
|
|
|
|
return getUserData();
|
|
|
|
}
|
|
|
|
|
2012-07-10 20:07:52 +00:00
|
|
|
inline int MdpCtrl::getPipeId() const {
|
2012-06-14 07:56:20 +00:00
|
|
|
return mOVInfo.id;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline int MdpCtrl::getFd() const {
|
|
|
|
return mFd.getFD();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline int MdpCtrl::getFlags() const {
|
|
|
|
return mOVInfo.flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void MdpCtrl::setFlags(int f) {
|
|
|
|
mOVInfo.flags = f;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void MdpCtrl::setZ(overlay::utils::eZorder z) {
|
|
|
|
mOVInfo.z_order = z;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void MdpCtrl::setWait(overlay::utils::eWait wait) {
|
|
|
|
mOVInfo.flags = utils::setWait(wait, mOVInfo.flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void MdpCtrl::setIsFg(overlay::utils::eIsFg isFg) {
|
|
|
|
mOVInfo.is_fg = isFg;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool MdpCtrl::ovChanged() const {
|
|
|
|
// 0 means same
|
|
|
|
if(0 == ::memcmp(&mOVInfo, &mLkgo, sizeof (mdp_overlay))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void MdpCtrl::save() {
|
2012-07-10 20:07:52 +00:00
|
|
|
if(static_cast<ssize_t>(mOVInfo.id) == MSMFB_NEW_REQUEST) {
|
2012-06-14 07:56:20 +00:00
|
|
|
ALOGE("MdpCtrl current ov has id -1, will not save");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mLkgo = mOVInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void MdpCtrl::restore() {
|
2012-07-10 20:07:52 +00:00
|
|
|
if(static_cast<ssize_t>(mLkgo.id) == MSMFB_NEW_REQUEST) {
|
2012-06-14 07:56:20 +00:00
|
|
|
ALOGE("MdpCtrl Lkgo ov has id -1, will not restore");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mOVInfo = mLkgo;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline overlay::utils::Whf MdpCtrl::getSrcWhf() const {
|
2012-07-10 20:07:52 +00:00
|
|
|
return utils::Whf( mOVInfo.src.width,
|
|
|
|
mOVInfo.src.height,
|
|
|
|
mOVInfo.src.format);
|
2012-06-14 07:56:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void MdpCtrl::setSrcWhf(const overlay::utils::Whf& whf) {
|
|
|
|
mOVInfo.src.width = whf.w;
|
|
|
|
mOVInfo.src.height = whf.h;
|
|
|
|
mOVInfo.src.format = whf.format;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline overlay::utils::Dim MdpCtrl::getSrcRectDim() const {
|
2012-07-10 20:07:52 +00:00
|
|
|
return utils::Dim( mOVInfo.src_rect.x,
|
|
|
|
mOVInfo.src_rect.y,
|
|
|
|
mOVInfo.src_rect.w,
|
|
|
|
mOVInfo.src_rect.h);
|
2012-06-14 07:56:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void MdpCtrl::setSrcRectDim(const overlay::utils::Dim d) {
|
|
|
|
mOVInfo.src_rect.x = d.x;
|
|
|
|
mOVInfo.src_rect.y = d.y;
|
|
|
|
mOVInfo.src_rect.w = d.w;
|
|
|
|
mOVInfo.src_rect.h = d.h;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline overlay::utils::Dim MdpCtrl::getDstRectDim() const {
|
2012-07-10 20:07:52 +00:00
|
|
|
return utils::Dim( mOVInfo.dst_rect.x,
|
|
|
|
mOVInfo.dst_rect.y,
|
|
|
|
mOVInfo.dst_rect.w,
|
|
|
|
mOVInfo.dst_rect.h);
|
2012-06-14 07:56:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void MdpCtrl::setDstRectDim(const overlay::utils::Dim d) {
|
|
|
|
mOVInfo.dst_rect.x = d.x;
|
|
|
|
mOVInfo.dst_rect.y = d.y;
|
|
|
|
mOVInfo.dst_rect.w = d.w;
|
|
|
|
mOVInfo.dst_rect.h = d.h;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline int MdpCtrl::getUserData() const { return mOVInfo.user_data[0]; }
|
|
|
|
|
|
|
|
inline void MdpCtrl::setUserData(int v) { mOVInfo.user_data[0] = v; }
|
|
|
|
|
|
|
|
inline void MdpCtrl::setRotationFlags() {
|
|
|
|
const int u = getUserData();
|
|
|
|
if (u == MDP_ROT_90 || u == MDP_ROT_270)
|
|
|
|
mOVInfo.flags |= MDP_SOURCE_ROTATED_90;
|
|
|
|
else
|
|
|
|
mOVInfo.flags &= ~MDP_SOURCE_ROTATED_90;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void MdpCtrl::swapSrcWH() {
|
|
|
|
utils::swap(mOVInfo.src.width,
|
2012-07-10 20:07:52 +00:00
|
|
|
mOVInfo.src.height);
|
|
|
|
}
|
2012-06-14 07:56:20 +00:00
|
|
|
|
|
|
|
inline void MdpCtrl::swapSrcRectWH() {
|
2012-07-10 20:07:52 +00:00
|
|
|
utils::swap(mOVInfo.src_rect.w,
|
|
|
|
mOVInfo.src_rect.h);
|
|
|
|
}
|
2012-06-14 07:56:20 +00:00
|
|
|
|
|
|
|
/////// MdpCtrl3D //////
|
|
|
|
|
|
|
|
inline MdpCtrl3D::MdpCtrl3D() { reset(); }
|
|
|
|
inline bool MdpCtrl3D::close() {
|
|
|
|
if (m3DOVInfo.is_3d) {
|
|
|
|
m3DOVInfo.is_3d = 0;
|
|
|
|
if(!mdp_wrapper::set3D(mFd.getFD(), m3DOVInfo)) {
|
|
|
|
ALOGE("MdpCtrl3D close failed set3D with 0");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
reset();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
inline void MdpCtrl3D::reset() {
|
|
|
|
utils::memset0(m3DOVInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void MdpCtrl3D::setFd(int fd) {
|
|
|
|
mFd.copy(fd);
|
|
|
|
OVASSERT(mFd.valid(), "MdpCtrl3D setFd, FD should be valid");
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void MdpCtrl3D::setWh(const utils::Whf& whf) {
|
|
|
|
// ignore fmt. Needed for useVirtualFB callflow
|
|
|
|
m3DOVInfo.width = whf.w;
|
|
|
|
m3DOVInfo.height = whf.h;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool MdpCtrl3D::useVirtualFB() {
|
|
|
|
if(!m3DOVInfo.is_3d) {
|
|
|
|
m3DOVInfo.is_3d = 1;
|
|
|
|
if(!mdp_wrapper::set3D(mFd.getFD(), m3DOVInfo)) {
|
|
|
|
ALOGE("MdpCtrl3D close failed set3D with 0");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/////// MdpData //////
|
|
|
|
|
|
|
|
inline MdpData::MdpData() { reset(); }
|
|
|
|
|
|
|
|
inline MdpData::~MdpData() { close(); }
|
|
|
|
|
2012-07-10 20:07:52 +00:00
|
|
|
inline bool MdpData::init(uint32_t fbnum) {
|
|
|
|
// FD init
|
|
|
|
if(!utils::openDev(mFd, fbnum, Res::fbPath, O_RDWR)){
|
|
|
|
ALOGE("Ctrl failed to init fbnum=%d", fbnum);
|
2012-06-14 07:56:20 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void MdpData::reset() {
|
|
|
|
overlay::utils::memset0(mOvData);
|
|
|
|
mOvData.data.memory_id = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool MdpData::close() {
|
|
|
|
if(-1 == mOvData.data.memory_id) return true;
|
|
|
|
reset();
|
|
|
|
if(!mFd.close()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-07-10 20:07:52 +00:00
|
|
|
inline int MdpData::getSrcMemoryId() const { return mOvData.data.memory_id; }
|
2012-06-14 07:56:20 +00:00
|
|
|
|
2012-07-10 20:07:52 +00:00
|
|
|
inline void MdpData::setPipeId(int id) { mOvData.id = id; }
|
2012-06-14 07:56:20 +00:00
|
|
|
|
2012-07-10 20:07:52 +00:00
|
|
|
inline int MdpData::getPipeId() const { return mOvData.id; }
|
2012-06-14 07:56:20 +00:00
|
|
|
|
|
|
|
inline int MdpData::getFd() const { return mFd.getFD(); }
|
|
|
|
|
2012-07-10 20:07:52 +00:00
|
|
|
inline bool MdpData::play(int fd, uint32_t offset) {
|
|
|
|
mOvData.data.memory_id = fd;
|
|
|
|
mOvData.data.offset = offset;
|
2012-06-14 07:56:20 +00:00
|
|
|
if(!mdp_wrapper::play(mFd.getFD(), mOvData)){
|
|
|
|
ALOGE("MdpData failed to play");
|
2012-07-10 20:07:52 +00:00
|
|
|
dump();
|
2012-06-14 07:56:20 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-07-10 20:07:52 +00:00
|
|
|
inline bool MdpData::waitForVsync() {
|
|
|
|
if(!mdp_wrapper::waitForVsync(mFd.getFD(), mOvData)){
|
|
|
|
ALOGE("%s failed", __FUNCTION__);
|
|
|
|
dump();
|
2012-06-14 07:56:20 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // overlay
|
|
|
|
|
|
|
|
#endif // OVERLAY_MDP_H
|