2012-07-11 01:33:17 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 The Android Open Source Project
|
|
|
|
* Copyright (C) 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.
|
|
|
|
*/
|
|
|
|
|
2012-07-21 19:17:13 +00:00
|
|
|
#define VIDEO_DEBUG 0
|
|
|
|
#include <overlay.h>
|
|
|
|
#include "hwc_qbuf.h"
|
2012-07-11 01:33:17 +00:00
|
|
|
#include "hwc_video.h"
|
2012-07-21 19:17:13 +00:00
|
|
|
#include "hwc_external.h"
|
2012-10-05 13:14:05 +00:00
|
|
|
#include <mdp_version.h>
|
2012-07-11 01:33:17 +00:00
|
|
|
|
|
|
|
namespace qhwc {
|
|
|
|
|
|
|
|
//Static Members
|
|
|
|
ovutils::eOverlayState VideoOverlay::sState = ovutils::OV_CLOSED;
|
|
|
|
int VideoOverlay::sYuvCount = 0;
|
|
|
|
int VideoOverlay::sYuvLayerIndex = -1;
|
2012-07-22 02:06:55 +00:00
|
|
|
bool VideoOverlay::sIsYuvLayerSkip = false;
|
|
|
|
int VideoOverlay::sCCLayerIndex = -1;
|
2012-07-11 01:33:17 +00:00
|
|
|
bool VideoOverlay::sIsModeOn = false;
|
|
|
|
|
|
|
|
//Cache stats, figure out the state, config overlay
|
|
|
|
bool VideoOverlay::prepare(hwc_context_t *ctx, hwc_layer_list_t *list) {
|
|
|
|
sIsModeOn = false;
|
2012-10-05 13:14:05 +00:00
|
|
|
if((!ctx->mMDP.hasOverlay) ||
|
|
|
|
(qdutils::MDPVersion::getInstance().getMDPVersion()
|
|
|
|
<= qdutils::MDP_V4_0)) {
|
2012-07-19 09:33:29 +00:00
|
|
|
ALOGD_IF(VIDEO_DEBUG,"%s, this hw doesnt support overlay", __FUNCTION__);
|
|
|
|
return false;
|
|
|
|
}
|
2012-07-20 01:14:30 +00:00
|
|
|
if(sYuvLayerIndex == -1) {
|
|
|
|
return false;
|
|
|
|
}
|
2012-07-11 01:33:17 +00:00
|
|
|
chooseState(ctx);
|
|
|
|
//if the state chosen above is CLOSED, skip this block.
|
|
|
|
if(sState != ovutils::OV_CLOSED) {
|
2012-07-22 02:06:55 +00:00
|
|
|
hwc_layer_t *yuvLayer = &list->hwLayers[sYuvLayerIndex];
|
|
|
|
hwc_layer_t *ccLayer = NULL;
|
|
|
|
if(sCCLayerIndex != -1)
|
|
|
|
ccLayer = &list->hwLayers[sCCLayerIndex];
|
|
|
|
|
|
|
|
if(configure(ctx, yuvLayer, ccLayer)) {
|
2012-07-11 01:33:17 +00:00
|
|
|
markFlags(&list->hwLayers[sYuvLayerIndex]);
|
2012-07-20 01:14:30 +00:00
|
|
|
sIsModeOn = true;
|
2012-07-11 01:33:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ALOGD_IF(VIDEO_DEBUG, "%s: stats: yuvCount = %d, yuvIndex = %d,"
|
2012-07-22 02:06:55 +00:00
|
|
|
"IsYuvLayerSkip = %d, ccLayerIndex = %d, IsModeOn = %d",
|
|
|
|
__FUNCTION__, sYuvCount, sYuvLayerIndex,
|
|
|
|
sIsYuvLayerSkip, sCCLayerIndex, sIsModeOn);
|
2012-07-11 01:33:17 +00:00
|
|
|
|
|
|
|
return sIsModeOn;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VideoOverlay::chooseState(hwc_context_t *ctx) {
|
|
|
|
ALOGD_IF(VIDEO_DEBUG, "%s: old state = %s", __FUNCTION__,
|
|
|
|
ovutils::getStateString(sState));
|
|
|
|
|
|
|
|
ovutils::eOverlayState newState = ovutils::OV_CLOSED;
|
|
|
|
|
|
|
|
//Support 1 video layer
|
|
|
|
if(sYuvCount == 1) {
|
2012-06-26 00:34:58 +00:00
|
|
|
//Skip on primary, display on ext.
|
2012-07-22 02:06:55 +00:00
|
|
|
if(sIsYuvLayerSkip && ctx->mExtDisplay->getExternalDisplay()) {
|
2012-07-20 01:14:30 +00:00
|
|
|
newState = ovutils::OV_2D_VIDEO_ON_TV;
|
2012-07-22 02:06:55 +00:00
|
|
|
} else if(sIsYuvLayerSkip) { //skip on primary, no ext
|
2012-07-11 01:33:17 +00:00
|
|
|
newState = ovutils::OV_CLOSED;
|
2012-07-21 19:17:13 +00:00
|
|
|
} else if(ctx->mExtDisplay->getExternalDisplay()) {
|
2012-06-26 00:34:58 +00:00
|
|
|
//display on both
|
2012-07-11 01:33:17 +00:00
|
|
|
newState = ovutils::OV_2D_VIDEO_ON_PANEL_TV;
|
|
|
|
} else { //display on primary only
|
|
|
|
newState = ovutils::OV_2D_VIDEO_ON_PANEL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sState = newState;
|
|
|
|
ALOGD_IF(VIDEO_DEBUG, "%s: new chosen state = %s", __FUNCTION__,
|
|
|
|
ovutils::getStateString(sState));
|
|
|
|
}
|
|
|
|
|
|
|
|
void VideoOverlay::markFlags(hwc_layer_t *layer) {
|
|
|
|
switch(sState) {
|
|
|
|
case ovutils::OV_2D_VIDEO_ON_PANEL:
|
|
|
|
case ovutils::OV_2D_VIDEO_ON_PANEL_TV:
|
|
|
|
layer->compositionType = HWC_OVERLAY;
|
|
|
|
layer->hints |= HWC_HINT_CLEAR_FB;
|
|
|
|
break;
|
2012-07-20 01:14:30 +00:00
|
|
|
case ovutils::OV_2D_VIDEO_ON_TV:
|
|
|
|
break; //dont update flags.
|
2012-07-11 01:33:17 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-20 01:14:30 +00:00
|
|
|
/* Helpers */
|
|
|
|
bool configPrimVid(hwc_context_t *ctx, hwc_layer_t *layer) {
|
|
|
|
overlay::Overlay& ov = *(ctx->mOverlay);
|
|
|
|
private_handle_t *hnd = (private_handle_t *)layer->handle;
|
|
|
|
ovutils::Whf info(hnd->width, hnd->height, hnd->format, hnd->size);
|
2012-07-11 01:33:17 +00:00
|
|
|
|
2012-07-20 01:14:30 +00:00
|
|
|
ovutils::eMdpFlags mdpFlags = ovutils::OV_MDP_FLAGS_NONE;
|
|
|
|
if (hnd->flags & private_handle_t::PRIV_FLAGS_SECURE_BUFFER) {
|
|
|
|
ovutils::setMdpFlags(mdpFlags,
|
|
|
|
ovutils::OV_MDP_SECURE_OVERLAY_SESSION);
|
|
|
|
}
|
2012-08-20 22:25:28 +00:00
|
|
|
if(layer->blending == HWC_BLENDING_PREMULT) {
|
|
|
|
ovutils::setMdpFlags(mdpFlags,
|
|
|
|
ovutils::OV_MDP_BLEND_FG_PREMULT);
|
|
|
|
}
|
2012-07-11 01:33:17 +00:00
|
|
|
|
2012-07-20 01:14:30 +00:00
|
|
|
ovutils::eIsFg isFgFlag = ovutils::IS_FG_OFF;
|
|
|
|
if (ctx->numHwLayers == 1) {
|
|
|
|
isFgFlag = ovutils::IS_FG_SET;
|
|
|
|
}
|
2012-07-11 01:33:17 +00:00
|
|
|
|
2012-07-20 01:14:30 +00:00
|
|
|
ovutils::PipeArgs parg(mdpFlags,
|
|
|
|
info,
|
|
|
|
ovutils::ZORDER_0,
|
|
|
|
isFgFlag,
|
|
|
|
ovutils::ROT_FLAG_DISABLED);
|
|
|
|
ovutils::PipeArgs pargs[ovutils::MAX_PIPES] = { parg, parg, parg };
|
|
|
|
ov.setSource(pargs, ovutils::OV_PIPE0);
|
|
|
|
|
|
|
|
hwc_rect_t sourceCrop = layer->sourceCrop;
|
|
|
|
hwc_rect_t displayFrame = layer->displayFrame;
|
|
|
|
|
|
|
|
//Calculate the rect for primary based on whether the supplied position
|
|
|
|
//is within or outside bounds.
|
|
|
|
const int fbWidth =
|
2012-07-11 01:33:17 +00:00
|
|
|
ovutils::FrameBufferInfo::getInstance()->getWidth();
|
2012-07-20 01:14:30 +00:00
|
|
|
const int fbHeight =
|
2012-07-11 01:33:17 +00:00
|
|
|
ovutils::FrameBufferInfo::getInstance()->getHeight();
|
|
|
|
|
2012-07-20 01:14:30 +00:00
|
|
|
if( displayFrame.left < 0 ||
|
2012-07-11 01:33:17 +00:00
|
|
|
displayFrame.top < 0 ||
|
|
|
|
displayFrame.right > fbWidth ||
|
|
|
|
displayFrame.bottom > fbHeight) {
|
2012-07-20 01:14:30 +00:00
|
|
|
calculate_crop_rects(sourceCrop, displayFrame, fbWidth, fbHeight);
|
|
|
|
}
|
2012-07-11 01:33:17 +00:00
|
|
|
|
2012-09-06 01:45:59 +00:00
|
|
|
// source crop x,y,w,h
|
|
|
|
ovutils::Dim dcrop(sourceCrop.left, sourceCrop.top,
|
|
|
|
sourceCrop.right - sourceCrop.left,
|
|
|
|
sourceCrop.bottom - sourceCrop.top);
|
2012-07-20 01:14:30 +00:00
|
|
|
//Only for Primary
|
|
|
|
ov.setCrop(dcrop, ovutils::OV_PIPE0);
|
2012-07-11 01:33:17 +00:00
|
|
|
|
2012-07-20 01:14:30 +00:00
|
|
|
ovutils::eTransform orient =
|
2012-08-29 01:33:09 +00:00
|
|
|
static_cast<ovutils::eTransform>(layer->transform);
|
2012-07-20 01:14:30 +00:00
|
|
|
ov.setTransform(orient, ovutils::OV_PIPE0);
|
2012-07-11 01:33:17 +00:00
|
|
|
|
2012-09-06 01:45:59 +00:00
|
|
|
// position x,y,w,h
|
|
|
|
ovutils::Dim dpos(displayFrame.left,
|
|
|
|
displayFrame.top,
|
|
|
|
displayFrame.right - displayFrame.left,
|
|
|
|
displayFrame.bottom - displayFrame.top);
|
2012-07-20 01:14:30 +00:00
|
|
|
ov.setPosition(dpos, ovutils::OV_PIPE0);
|
2012-07-11 01:33:17 +00:00
|
|
|
|
2012-07-20 01:14:30 +00:00
|
|
|
if (!ov.commit(ovutils::OV_PIPE0)) {
|
|
|
|
ALOGE("%s: commit fails", __FUNCTION__);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2012-07-11 01:33:17 +00:00
|
|
|
|
2012-07-20 01:14:30 +00:00
|
|
|
bool configExtVid(hwc_context_t *ctx, hwc_layer_t *layer) {
|
|
|
|
overlay::Overlay& ov = *(ctx->mOverlay);
|
|
|
|
private_handle_t *hnd = (private_handle_t *)layer->handle;
|
|
|
|
ovutils::Whf info(hnd->width, hnd->height, hnd->format, hnd->size);
|
|
|
|
|
|
|
|
ovutils::eMdpFlags mdpFlags = ovutils::OV_MDP_FLAGS_NONE;
|
|
|
|
if (hnd->flags & private_handle_t::PRIV_FLAGS_SECURE_BUFFER) {
|
|
|
|
ovutils::setMdpFlags(mdpFlags,
|
|
|
|
ovutils::OV_MDP_SECURE_OVERLAY_SESSION);
|
2012-07-11 01:33:17 +00:00
|
|
|
}
|
2012-07-20 01:14:30 +00:00
|
|
|
|
|
|
|
ovutils::eIsFg isFgFlag = ovutils::IS_FG_OFF;
|
|
|
|
if (ctx->numHwLayers == 1) {
|
|
|
|
isFgFlag = ovutils::IS_FG_SET;
|
|
|
|
}
|
|
|
|
|
|
|
|
ovutils::PipeArgs parg(mdpFlags,
|
|
|
|
info,
|
|
|
|
ovutils::ZORDER_0,
|
|
|
|
isFgFlag,
|
|
|
|
ovutils::ROT_FLAG_DISABLED);
|
|
|
|
ovutils::PipeArgs pargs[ovutils::MAX_PIPES] = { parg, parg, parg };
|
|
|
|
ov.setSource(pargs, ovutils::OV_PIPE1);
|
|
|
|
|
|
|
|
hwc_rect_t sourceCrop = layer->sourceCrop;
|
|
|
|
// x,y,w,h
|
|
|
|
ovutils::Dim dcrop(sourceCrop.left, sourceCrop.top,
|
|
|
|
sourceCrop.right - sourceCrop.left,
|
|
|
|
sourceCrop.bottom - sourceCrop.top);
|
|
|
|
//Only for External
|
|
|
|
ov.setCrop(dcrop, ovutils::OV_PIPE1);
|
|
|
|
|
2012-08-29 01:33:09 +00:00
|
|
|
//use sourceTransform only for External
|
|
|
|
ov.setTransform(layer->sourceTransform, ovutils::OV_PIPE1);
|
2012-07-20 01:14:30 +00:00
|
|
|
|
|
|
|
ovutils::Dim dpos;
|
|
|
|
hwc_rect_t displayFrame = layer->displayFrame;
|
|
|
|
dpos.x = displayFrame.left;
|
|
|
|
dpos.y = displayFrame.top;
|
|
|
|
dpos.w = (displayFrame.right - displayFrame.left);
|
|
|
|
dpos.h = (displayFrame.bottom - displayFrame.top);
|
|
|
|
|
|
|
|
//Only for External
|
|
|
|
ov.setPosition(dpos, ovutils::OV_PIPE1);
|
|
|
|
|
|
|
|
if (!ov.commit(ovutils::OV_PIPE1)) {
|
|
|
|
ALOGE("%s: commit fails", __FUNCTION__);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-07-22 02:06:55 +00:00
|
|
|
bool configExtCC(hwc_context_t *ctx, hwc_layer_t *layer) {
|
|
|
|
if(layer == NULL)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
overlay::Overlay& ov = *(ctx->mOverlay);
|
|
|
|
private_handle_t *hnd = (private_handle_t *)layer->handle;
|
|
|
|
ovutils::Whf info(hnd->width, hnd->height, hnd->format, hnd->size);
|
|
|
|
ovutils::eIsFg isFgFlag = ovutils::IS_FG_OFF;
|
|
|
|
ovutils::eMdpFlags mdpFlags = ovutils::OV_MDP_FLAGS_NONE;
|
|
|
|
ovutils::PipeArgs parg(mdpFlags,
|
|
|
|
info,
|
|
|
|
ovutils::ZORDER_1,
|
|
|
|
isFgFlag,
|
|
|
|
ovutils::ROT_FLAG_DISABLED);
|
|
|
|
ovutils::PipeArgs pargs[ovutils::MAX_PIPES] = { parg, parg, parg };
|
|
|
|
ov.setSource(pargs, ovutils::OV_PIPE2);
|
|
|
|
|
|
|
|
hwc_rect_t sourceCrop = layer->sourceCrop;
|
|
|
|
// x,y,w,h
|
|
|
|
ovutils::Dim dcrop(sourceCrop.left, sourceCrop.top,
|
|
|
|
sourceCrop.right - sourceCrop.left,
|
|
|
|
sourceCrop.bottom - sourceCrop.top);
|
|
|
|
//Only for External
|
|
|
|
ov.setCrop(dcrop, ovutils::OV_PIPE2);
|
|
|
|
|
|
|
|
// FIXME: Use source orientation for TV when source is portrait
|
|
|
|
//Only for External
|
|
|
|
ov.setTransform(0, ovutils::OV_PIPE2);
|
|
|
|
|
|
|
|
//Setting position same as crop
|
|
|
|
//FIXME stretch to full screen
|
|
|
|
ov.setPosition(dcrop, ovutils::OV_PIPE2);
|
|
|
|
|
|
|
|
if (!ov.commit(ovutils::OV_PIPE2)) {
|
|
|
|
ALOGE("%s: commit fails", __FUNCTION__);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VideoOverlay::configure(hwc_context_t *ctx, hwc_layer_t *yuvLayer,
|
|
|
|
hwc_layer_t *ccLayer) {
|
|
|
|
|
2012-07-20 01:14:30 +00:00
|
|
|
bool ret = true;
|
|
|
|
if (LIKELY(ctx->mOverlay)) {
|
|
|
|
overlay::Overlay& ov = *(ctx->mOverlay);
|
|
|
|
// Set overlay state
|
|
|
|
ov.setState(sState);
|
|
|
|
switch(sState) {
|
|
|
|
case ovutils::OV_2D_VIDEO_ON_PANEL:
|
|
|
|
ret &= configPrimVid(ctx, yuvLayer);
|
|
|
|
break;
|
|
|
|
case ovutils::OV_2D_VIDEO_ON_PANEL_TV:
|
|
|
|
ret &= configExtVid(ctx, yuvLayer);
|
2012-07-22 02:06:55 +00:00
|
|
|
ret &= configExtCC(ctx, ccLayer);
|
2012-07-20 01:14:30 +00:00
|
|
|
ret &= configPrimVid(ctx, yuvLayer);
|
|
|
|
break;
|
|
|
|
case ovutils::OV_2D_VIDEO_ON_TV:
|
|
|
|
ret &= configExtVid(ctx, yuvLayer);
|
2012-07-22 02:06:55 +00:00
|
|
|
ret &= configExtCC(ctx, ccLayer);
|
2012-07-20 01:14:30 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
//Ov null
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return ret;
|
2012-07-11 01:33:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool VideoOverlay::draw(hwc_context_t *ctx, hwc_layer_list_t *list)
|
|
|
|
{
|
|
|
|
if(!sIsModeOn || sYuvLayerIndex == -1) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-07-22 02:06:55 +00:00
|
|
|
private_handle_t *hnd = (private_handle_t *)
|
|
|
|
list->hwLayers[sYuvLayerIndex].handle;
|
|
|
|
|
|
|
|
private_handle_t *cchnd = NULL;
|
|
|
|
if(sCCLayerIndex != -1) {
|
|
|
|
cchnd = (private_handle_t *)list->hwLayers[sCCLayerIndex].handle;
|
|
|
|
ctx->qbuf->lockAndAdd(cchnd);
|
|
|
|
}
|
2012-07-11 01:33:17 +00:00
|
|
|
|
|
|
|
// Lock this buffer for read.
|
|
|
|
ctx->qbuf->lockAndAdd(hnd);
|
2012-07-22 02:06:55 +00:00
|
|
|
|
2012-07-11 01:33:17 +00:00
|
|
|
bool ret = true;
|
|
|
|
overlay::Overlay& ov = *(ctx->mOverlay);
|
|
|
|
ovutils::eOverlayState state = ov.getState();
|
|
|
|
|
|
|
|
switch (state) {
|
|
|
|
case ovutils::OV_2D_VIDEO_ON_PANEL_TV:
|
|
|
|
// Play external
|
|
|
|
if (!ov.queueBuffer(hnd->fd, hnd->offset, ovutils::OV_PIPE1)) {
|
|
|
|
ALOGE("%s: queueBuffer failed for external", __FUNCTION__);
|
|
|
|
ret = false;
|
|
|
|
}
|
2012-07-22 02:06:55 +00:00
|
|
|
//Play CC on external
|
|
|
|
if (cchnd && !ov.queueBuffer(cchnd->fd, cchnd->offset,
|
|
|
|
ovutils::OV_PIPE2)) {
|
|
|
|
ALOGE("%s: queueBuffer failed for cc external", __FUNCTION__);
|
|
|
|
ret = false;
|
|
|
|
}
|
2012-07-11 01:33:17 +00:00
|
|
|
// Play primary
|
|
|
|
if (!ov.queueBuffer(hnd->fd, hnd->offset, ovutils::OV_PIPE0)) {
|
|
|
|
ALOGE("%s: queueBuffer failed for primary", __FUNCTION__);
|
|
|
|
ret = false;
|
|
|
|
}
|
|
|
|
break;
|
2012-07-20 01:14:30 +00:00
|
|
|
case ovutils::OV_2D_VIDEO_ON_PANEL:
|
|
|
|
// Play primary
|
|
|
|
if (!ov.queueBuffer(hnd->fd, hnd->offset, ovutils::OV_PIPE0)) {
|
|
|
|
ALOGE("%s: queueBuffer failed for primary", __FUNCTION__);
|
|
|
|
ret = false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ovutils::OV_2D_VIDEO_ON_TV:
|
|
|
|
// Play external
|
|
|
|
if (!ov.queueBuffer(hnd->fd, hnd->offset, ovutils::OV_PIPE1)) {
|
|
|
|
ALOGE("%s: queueBuffer failed for external", __FUNCTION__);
|
2012-07-11 01:33:17 +00:00
|
|
|
ret = false;
|
|
|
|
}
|
2012-07-22 02:06:55 +00:00
|
|
|
//Play CC on external
|
|
|
|
if (cchnd && !ov.queueBuffer(cchnd->fd, cchnd->offset,
|
|
|
|
ovutils::OV_PIPE2)) {
|
|
|
|
ALOGE("%s: queueBuffer failed for cc external", __FUNCTION__);
|
|
|
|
ret = false;
|
|
|
|
}
|
|
|
|
break;
|
2012-07-20 01:14:30 +00:00
|
|
|
default:
|
|
|
|
ALOGE("%s Unused state %s", __FUNCTION__,
|
|
|
|
ovutils::getStateString(state));
|
2012-07-11 01:33:17 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
}; //namespace qhwc
|