liboverlay: Refactor setting overlay flags.

Modify the overlay APIs to use only one parameter to set the overlay
flags, instead of adding a parameter per required flag.

Change-Id: Ia753e10b9e2c7a5ee1aabfd48f30c9b7583beaa1
(cherry picked from commit 5535a95c8f69891090a81dbd8ccdc11aa889a42c)
This commit is contained in:
Naomi Luis 2012-01-25 18:16:07 -08:00 committed by Andrew Sutherland
parent d8588e1c12
commit 38e11bf7d4
3 changed files with 123 additions and 64 deletions

@ -236,7 +236,7 @@ static void *hdmi_ui_loop(void *ptr)
float asWidthRatio = m->actionsafeWidthRatio/100.0f;
float asHeightRatio = m->actionsafeHeightRatio/100.0f;
bool waitForVsync = true;
int flags = WAIT_FOR_VSYNC;
if (m->pobjOverlay) {
Overlay* pTemp = m->pobjOverlay;
if (m->hdmiMirroringState == HDMI_NO_MIRRORING)
@ -254,11 +254,11 @@ static void *hdmi_ui_loop(void *ptr)
info.size = hnd->size;
if (m->trueMirrorSupport)
waitForVsync = false;
flags &= ~WAIT_FOR_VSYNC;
// start the overlay Channel for mirroring
// m->enableHDMIOutput corresponds to the fbnum
if (pTemp->startChannel(info, m->enableHDMIOutput,
false, true, 0, VG0_PIPE, waitForVsync)) {
false, true, 0, VG0_PIPE, flags)) {
pTemp->setFd(m->framebuffer->fd);
pTemp->setCrop(0, 0, m->info.xres, m->info.yres);
} else
@ -365,8 +365,8 @@ static void *hdmi_ui_loop(void *ptr)
}
if (m->trueMirrorSupport) {
// if video is started the UI channel should be NO_WAIT.
waitForVsync = !m->videoOverlay;
pTemp->updateWaitForVsyncFlags(waitForVsync);
flags = !m->videoOverlay ? WAIT_FOR_VSYNC : 0;
pTemp->updateOverlayFlags(flags);
}
pTemp->queueBuffer(m->currentOffset);
}

@ -395,7 +395,7 @@ int Overlay::getFBHeight(int channel) const {
bool Overlay::startChannel(const overlay_buffer_info& info, int fbnum,
bool norot, bool uichannel,
unsigned int format3D, int channel,
bool ignoreFB, int num_buffers) {
int flags, int num_buffers) {
int zorder = 0;
int format = getColorFormat(info.format);
mCroppedSrcWidth = info.width;
@ -408,7 +408,7 @@ bool Overlay::startChannel(const overlay_buffer_info& info, int fbnum,
mChannelUP = objOvCtrlChannel[channel].startControlChannel(info.width,
info.height, format, fbnum,
norot, uichannel,
format3D, zorder, ignoreFB);
format3D, zorder, flags);
if (!mChannelUP) {
LOGE("startChannel for fb%d failed", fbnum);
return mChannelUP;
@ -543,22 +543,13 @@ bool Overlay::setChannelPosition(int x, int y, uint32_t w, uint32_t h, int chann
}
bool Overlay::updateOverlaySource(const overlay_buffer_info& info, int orientation,
bool waitForVsync) {
int flags) {
bool ret = false;
int currentFlags = 0;
if (objOvCtrlChannel[0].isChannelUP()) {
currentFlags = objOvCtrlChannel[0].getOverlayFlags();
}
bool needUpdateFlags = false;
if (waitForVsync) {
if (currentFlags & MDP_OV_PLAY_NOWAIT) {
needUpdateFlags = true;
}
} else {
if (!(currentFlags & MDP_OV_PLAY_NOWAIT)) {
needUpdateFlags = true;
}
if (objOvCtrlChannel[0].isChannelUP()) {
needUpdateFlags = objOvCtrlChannel[0].doFlagsNeedUpdate(flags);
}
bool geometryChanged = true;
@ -581,10 +572,9 @@ bool Overlay::updateOverlaySource(const overlay_buffer_info& info, int orientati
int orientPrimary = sHDMIAsPrimary ? 0 : orientation;
int orient[2] = {orientPrimary, orientHdmi};
// disable waitForVsync on HDMI, since we call the wait ioctl
bool waitForHDMI = false;
bool waitForPrimary = sHDMIAsPrimary ? true : waitForVsync;
bool waitCond[2] = {waitForPrimary, waitForHDMI};
int ovFlagsExternal = 0;
int ovFlagsPrimary = sHDMIAsPrimary ? (flags |= WAIT_FOR_VSYNC): flags;
int ovFlags[2] = {flags, ovFlagsExternal};
switch(mState) {
case OV_3D_VIDEO_3D_PANEL:
orient[1] = sHDMIAsPrimary ? 0 : orientation;
@ -601,14 +591,14 @@ bool Overlay::updateOverlaySource(const overlay_buffer_info& info, int orientati
// Only update the primary channel - we only need to update the
// wait/no-wait flags
if (objOvCtrlChannel[0].isChannelUP()) {
return objOvCtrlChannel[0].updateWaitForVsyncFlags(waitForVsync);
return objOvCtrlChannel[0].updateOverlayFlags(flags);
}
}
// Set the overlay source info
for (int i = 0; i < NUM_CHANNELS; i++) {
if (objOvCtrlChannel[i].isChannelUP()) {
ret = objOvCtrlChannel[i].updateOverlaySource(info, orient[i], waitCond[i]);
ret = objOvCtrlChannel[i].updateOverlaySource(info, orient[i], ovFlags[i]);
if (!ret) {
LOGE("objOvCtrlChannel[%d].updateOverlaySource failed", i);
return false;
@ -645,7 +635,7 @@ int Overlay::getS3DFormat(int format) {
}
bool Overlay::setSource(const overlay_buffer_info& info, int orientation,
int hdmiConnected, bool waitForVsync, int num_buffers) {
int hdmiConnected, int flags, int num_buffers) {
// Separate the color format from the 3D format.
// If there is 3D content; the effective format passed by the client is:
// effectiveFormat = 3D_IN | 3D_OUT | ColorFormat
@ -682,18 +672,18 @@ bool Overlay::setSource(const overlay_buffer_info& info, int orientation,
case OV_3D_VIDEO_2D_PANEL:
closeChannel();
return startChannel(info, FRAMEBUFFER_0, noRot, false,
mS3DFormat, VG0_PIPE, waitForVsync, num_buffers);
mS3DFormat, VG0_PIPE, flags, num_buffers);
break;
case OV_3D_VIDEO_3D_PANEL:
closeChannel();
if (sHDMIAsPrimary) {
noRot = true;
waitForVsync = true;
flags |= WAIT_FOR_VSYNC;
send3DInfoPacket(mS3DFormat & OUTPUT_MASK_3D);
}
for (int i=0; i<NUM_CHANNELS; i++) {
if(!startChannel(info, FRAMEBUFFER_0, noRot, uiChannel,
mS3DFormat, i, waitForVsync, num_buffers)) {
mS3DFormat, i, flags, num_buffers)) {
LOGE("%s:failed to open channel %d", __FUNCTION__, i);
return false;
}
@ -722,12 +712,12 @@ bool Overlay::setSource(const overlay_buffer_info& info, int orientation,
if (fbnum) {
// Disable rotation for external
noRot = true;
waitForVsync = false;
//set fbnum to hdmiConnected, which holds the ext display
fbnum = hdmiConnected;
flags &= ~WAIT_FOR_VSYNC;
}
if(!startChannel(info, fbnum, noRot, false, mS3DFormat,
i, waitForVsync, num_buffers)) {
i, flags, num_buffers)) {
LOGE("%s:failed to open channel %d", __FUNCTION__, i);
return false;
}
@ -738,7 +728,7 @@ bool Overlay::setSource(const overlay_buffer_info& info, int orientation,
closeChannel();
for (int i=0; i<NUM_CHANNELS; i++) {
if(!startChannel(info, FRAMEBUFFER_1, true, false,
mS3DFormat, i, waitForVsync, num_buffers)) {
mS3DFormat, i, flags, num_buffers)) {
LOGE("%s:failed to open channel %d", __FUNCTION__, i);
return false;
}
@ -750,7 +740,7 @@ bool Overlay::setSource(const overlay_buffer_info& info, int orientation,
break;
}
} else {
ret = updateOverlaySource(info, orientation, waitForVsync);
ret = updateOverlaySource(info, orientation, flags);
}
return true;
}
@ -804,8 +794,8 @@ bool Overlay::setChannelCrop(uint32_t x, uint32_t y, uint32_t w, uint32_t h, int
return objOvDataChannel[channel].setCrop(x, y, w, h);
}
bool Overlay::updateWaitForVsyncFlags(bool waitForVsync) {
return objOvCtrlChannel[VG0_PIPE].updateWaitForVsyncFlags(waitForVsync);
bool Overlay::updateOverlayFlags(int flags) {
return objOvCtrlChannel[VG0_PIPE].updateOverlayFlags(flags);
}
bool Overlay::setTransform(int value) {
@ -1173,8 +1163,8 @@ bool OverlayControlChannel::openDevices(int fbnum) {
}
bool OverlayControlChannel::setOverlayInformation(const overlay_buffer_info& info,
int flags, int orientation, int zorder,
bool ignoreFB, int requestType) {
int orientation, int zorder,
int flags, int requestType) {
int w = info.width;
int h = info.height;
int format = info.format;
@ -1217,22 +1207,75 @@ bool OverlayControlChannel::setOverlayInformation(const overlay_buffer_info& inf
mOVInfo.alpha = 0xff;
mOVInfo.transp_mask = 0xffffffff;
}
mOVInfo.flags = flags;
if (!ignoreFB)
mOVInfo.flags = 0;
if (info.secure) {
flags |= SECURE_OVERLAY_SESSION;
} else {
flags &= ~SECURE_OVERLAY_SESSION;
}
setInformationFromFlags(flags, mOVInfo);
mOVInfo.dpp.sharp_strength = 0;
return true;
}
void OverlayControlChannel::setInformationFromFlags(int flags, mdp_overlay& ov)
{
if (flags & INTERLACED_CONTENT) {
mOVInfo.flags |= MDP_DEINTERLACE;
} else {
mOVInfo.flags &= ~MDP_DEINTERLACE;
}
if ((flags & WAIT_FOR_VSYNC) == 0)
mOVInfo.flags |= MDP_OV_PLAY_NOWAIT;
else
mOVInfo.flags &= ~MDP_OV_PLAY_NOWAIT;
if(info.secure)
if(flags & SECURE_OVERLAY_SESSION)
mOVInfo.flags |= MDP_SECURE_OVERLAY_SESSION;
else
mOVInfo.flags &= MDP_SECURE_OVERLAY_SESSION;
mOVInfo.flags &= ~MDP_SECURE_OVERLAY_SESSION;
//set the default sharpening settings
mOVInfo.flags |= MDP_SHARPENING;
mOVInfo.dpp.sharp_strength = 0;
return true;
if (flags & DISABLE_FRAMEBUFFER_FETCH)
mOVInfo.is_fg = 1;
else
mOVInfo.is_fg = 0;
if (flags & OVERLAY_PIPE_SHARE) {
mOVInfo.flags |= MDP_OV_PIPE_SHARE;
} else {
mOVInfo.flags &= ~MDP_OV_PIPE_SHARE;
}
}
bool OverlayControlChannel::doFlagsNeedUpdate(int flags) {
bool needUpdate = false;
if ((flags & WAIT_FOR_VSYNC) == 0) {
if (!(mOVInfo.flags & MDP_OV_PLAY_NOWAIT)) {
needUpdate = true;
}
}
if (flags & WAIT_FOR_VSYNC) {
if (mOVInfo.flags & MDP_OV_PLAY_NOWAIT) {
needUpdate = true;
}
}
if ((flags & DISABLE_FRAMEBUFFER_FETCH) == 0) {
if (mOVInfo.is_fg == 1) {
needUpdate = true;
}
}
if (flags & DISABLE_FRAMEBUFFER_FETCH) {
if (mOVInfo.is_fg == 0) {
needUpdate = true;
}
}
return needUpdate;
}
bool OverlayControlChannel::startOVRotatorSessions(
@ -1297,7 +1340,7 @@ bool OverlayControlChannel::startOVRotatorSessions(
}
bool OverlayControlChannel::updateOverlaySource(const overlay_buffer_info& info,
int orientation, bool waitForVsync)
int orientation, int flags)
{
int colorFormat = getColorFormat(info.format);
int hw_format = get_mdp_format(colorFormat);
@ -1306,8 +1349,10 @@ bool OverlayControlChannel::updateOverlaySource(const overlay_buffer_info& info,
ovBufInfo.height = info.height;
ovBufInfo.format = hw_format;
int flags = isInterlacedContent(info.format) ? MDP_DEINTERLACE : 0;
if (!setOverlayInformation(ovBufInfo, flags, orientation, 0, waitForVsync,
if (isInterlacedContent(info.format)) {
flags |= INTERLACED_CONTENT;
}
if (!setOverlayInformation(ovBufInfo, orientation, 0, flags,
UPDATE_REQUEST))
return false;
@ -1318,7 +1363,7 @@ bool OverlayControlChannel::startControlChannel(int w, int h,
int format, int fbnum, bool norot,
bool uichannel,
unsigned int format3D, int zorder,
bool ignoreFB) {
int flags) {
mNoRot = norot;
mFormat = format;
mUIChannel = uichannel;
@ -1326,7 +1371,6 @@ bool OverlayControlChannel::startControlChannel(int w, int h,
fb_fix_screeninfo finfo;
fb_var_screeninfo vinfo;
int hw_format;
int flags = 0;
int colorFormat = format;
// The interlace mask is part of the HAL_PIXEL_FORMAT_YV12 value. Add
// an explicit check for the format
@ -1345,11 +1389,11 @@ bool OverlayControlChannel::startControlChannel(int w, int h,
mFormat3D = format3D;
if ( !mFormat3D || (mFormat3D & HAL_3D_OUT_MONOSCOPIC_MASK) ) {
// Set the share bit for sharing the VG pipe
flags |= MDP_OV_PIPE_SHARE;
flags |= OVERLAY_PIPE_SHARE;
}
//do not set the PIPE SHARE bit for true mirroring
if(uichannel && FrameBufferInfo::getInstance()->canSupportTrueMirroring())
flags &= ~MDP_OV_PIPE_SHARE;
flags &= ~OVERLAY_PIPE_SHARE;
if (!openDevices(fbnum))
return false;
@ -1364,7 +1408,7 @@ bool OverlayControlChannel::startControlChannel(int w, int h,
ovBufInfo.width = w;
ovBufInfo.height = h;
ovBufInfo.format = hw_format;
if (!setOverlayInformation(ovBufInfo, flags, orientation, zorder, ignoreFB, NEW_REQUEST))
if (!setOverlayInformation(ovBufInfo, orientation, zorder, flags, NEW_REQUEST))
return false;
return startOVRotatorSessions(ovBufInfo, orientation, NEW_REQUEST);
@ -1402,12 +1446,17 @@ bool OverlayControlChannel::closeControlChannel() {
return true;
}
bool OverlayControlChannel::updateWaitForVsyncFlags(bool waitForVsync) {
if (!waitForVsync)
bool OverlayControlChannel::updateOverlayFlags(int flags) {
if ((flags & WAIT_FOR_VSYNC) == 0)
mOVInfo.flags |= MDP_OV_PLAY_NOWAIT;
else
mOVInfo.flags &= ~MDP_OV_PLAY_NOWAIT;
if (flags & DISABLE_FRAMEBUFFER_FETCH)
mOVInfo.is_fg = 1;
else
mOVInfo.is_fg = 0;
if (ioctl(mFD, MSMFB_OVERLAY_SET, &mOVInfo)) {
LOGE("%s: OVERLAY_SET failed", __FUNCTION__);
dump(mOVInfo);
@ -1906,11 +1955,11 @@ bool OverlayDataChannel::queue(uint32_t offset) {
#if 0
bool OverlayDataChannel::waitForHdmiVsync() {
if (!isChannelUP()) {
reportError("waitForHdmiVsync: channel not up");
LOGE("%s: channel not up", __FUNCTION__);
return false;
}
if (ioctl(mFD, MSMFB_OVERLAY_PLAY_WAIT, &mOvData)) {
reportError("waitForHdmiVsync: MSMFB_OVERLAY_PLAY_WAIT failed");
LOGE("%s: MSMFB_OVERLAY_PLAY_WAIT failed", __FUNCTION__);
return false;
}
return true;

@ -84,6 +84,15 @@ enum {
NEW_REQUEST,
UPDATE_REQUEST
};
enum {
WAIT_FOR_VSYNC = 1<<0,
DISABLE_FRAMEBUFFER_FETCH = 1<<1,
INTERLACED_CONTENT = 1<<2,
OVERLAY_PIPE_SHARE = 1<<3,
SECURE_OVERLAY_SESSION = 1<<4,
};
/* ------------------------------- 3D defines ---------------------------------------*/
// The compound format passed to the overlay is
// ABCCC where A is the input 3D format,
@ -297,11 +306,12 @@ enum {
bool mIsChannelUpdated;
bool openDevices(int fbnum = -1);
bool setOverlayInformation(const overlay_buffer_info& info,
int flags, int orientation, int zorder = 0, bool ignoreFB = false,
int orientation, int zorder = 0, int flags = 0,
int requestType = NEW_REQUEST);
bool startOVRotatorSessions(const overlay_buffer_info& info, int orientation, int requestType);
void swapOVRotWidthHeight();
int commitVisualParam(int8_t paramType, float paramValue);
void setInformationFromFlags(int flags, mdp_overlay& ov);
public:
OverlayControlChannel();
@ -310,7 +320,7 @@ public:
int fbnum, bool norot = false,
bool uichannel = false,
unsigned int format3D = 0, int zorder = 0,
bool ignoreFB = false);
int flags = 0);
bool closeControlChannel();
bool setPosition(int x, int y, uint32_t w, uint32_t h);
bool setTransform(int value, bool fetch = true);
@ -324,18 +334,18 @@ public:
int getFBHeight() const { return mFBHeight; }
int getFormat3D() const { return mFormat3D; }
bool getOrientation(int& orientation) const;
bool updateWaitForVsyncFlags(bool waitForVsync);
bool updateOverlayFlags(int flags);
bool getAspectRatioPosition(int w, int h, overlay_rect *rect);
// Calculates the aspect ratio for video on HDMI based on primary
// aspect ratio used in case of true mirroring
bool getAspectRatioPosition(int w, int h, int orientation,
overlay_rect *inRect, overlay_rect *outRect);
bool getPositionS3D(int channel, int format, overlay_rect *rect);
bool updateOverlaySource(const overlay_buffer_info& info, int orientation, bool waitForVsync);
bool updateOverlaySource(const overlay_buffer_info& info, int orientation, int flags);
bool getFormat() const { return mFormat; }
bool setVisualParam(int8_t paramType, float paramValue);
bool useVirtualFB ();
int getOverlayFlags() const { return mOVInfo.flags; }
bool doFlagsNeedUpdate(int flags);
};
class OverlayDataChannel {
@ -408,7 +418,7 @@ public:
static bool sHDMIAsPrimary;
bool startChannel(const overlay_buffer_info& info, int fbnum, bool norot = false,
bool uichannel = false, unsigned int format3D = 0,
int channel = 0, bool ignoreFB = false,
int channel = 0, int flags = 0,
int num_buffers = 2);
bool closeChannel();
bool setDeviceOrientation(int orientation);
@ -424,9 +434,9 @@ public:
bool getOrientation(int& orientation, int channel = 0) const;
bool queueBuffer(buffer_handle_t buffer);
bool setSource(const overlay_buffer_info& info, int orientation, int hdmiConnected,
bool ignoreFB = false, int numBuffers = 2);
int flags, int numBuffers = 2);
bool setCrop(uint32_t x, uint32_t y, uint32_t w, uint32_t h);
bool updateWaitForVsyncFlags(bool waitForVsync);
bool updateOverlayFlags(int flags);
void setVisualParam(int8_t paramType, float paramValue);
bool waitForHdmiVsync(int channel);
int getChannelStatus() const { return (mChannelUP ? OVERLAY_CHANNEL_UP: OVERLAY_CHANNEL_DOWN); }
@ -436,7 +446,7 @@ private:
bool setChannelPosition(int x, int y, uint32_t w, uint32_t h, int channel = 0);
bool setChannelCrop(uint32_t x, uint32_t y, uint32_t w, uint32_t h, int channel);
bool queueBuffer(int fd, uint32_t offset, int channel);
bool updateOverlaySource(const overlay_buffer_info& info, int orientation, bool waitForVsync);
bool updateOverlaySource(const overlay_buffer_info& info, int orientation, int flags);
int getS3DFormat(int format);
};