/**
 * @file hv_drv_OsdWindow.c
 * @brief Osd Driver Window drawing c file.
 * @details This file provides the following functions: \n
 *          (1) Window Draw/Update/Erase functions \n
 *          (4) Rect Draw/Update/Erase functions \n
 *          (5) RectGrid Draw/Update/Erase functions \n
 *          (1) Line Draw/Update/Erase functions \n
 *          (2) LineGrid Draw/Update/Erase functions \n
 *
 * @author HiView SoC Software Team
 * @version 1.0.0
 * @date 2022-08-31
 * @copyright Copyright(c),2022-8, Hiview Software. All rights reserved.
 * @par History:
 * <table>
 * <tr><th>Author         <th>Date        <th>Change Description
 * <tr><td>OSD Group      <td>2022-08-31   <td>create
 * </table>
*/

#include "hv_drv_Osd.h"
#include "hv_cal_Osd.h"

UINT32 Hv_Drv_OsdWindow_PixelFormatConvert(OsdPixelFormat enSrcFormat, OsdPixelFormat enDstFormat, UINT32 uiColor)
{
    UINT32 uiRes = 0;

    uiRes = Hv_Cal_OsdFrame_PixelFormatConvert(enSrcFormat, enDstFormat, uiColor);

    return uiRes;
}

/* Rect Begin */
static VOID Hv_Drv_OsdWindow_SetCurrentRect(OsdRectPhyId enIndex)
{
    Hv_Cal_OsdRect_SetCurrentRect(enIndex);
    //OSD_DRV_LOG_DEBUG("Current Rect is Rect-%d", enIndex);
}

static VOID Hv_Drv_OsdWindow_SetRectProp(USHORT16 usX, USHORT16 usY, USHORT16 usWidth, USHORT16 usHeight,
                                                  BOOL bBgColorEnable, USHORT16 usBgColor)
{
    Hv_Cal_OsdRect_SetPos(usX, usY);
    Hv_Cal_OsdRect_SetSize(usWidth, usHeight);
    if (bBgColorEnable)
    {
        Hv_Cal_OsdRect_SetBackgroundEnable(HV_TRUE);
        Hv_Cal_OsdRect_SetBackgroundColor(usBgColor, usBgColor);
    }
    else
    {
        Hv_Cal_OsdRect_SetBackgroundEnable(HV_FALSE);
    }
}

static VOID Hv_Drv_OsdWindow_SetRectBorder(const OsdBorder *pstBorder)
{
    if (HV_TRUE == pstBorder->ucBorderEnable)
    {
        Hv_Cal_OsdRect_SetBorderType(pstBorder->ucBorderType);
        Hv_Cal_OsdRect_SetBorderSize(pstBorder->ucSizeX, pstBorder->ucSizeY);
        Hv_Cal_OsdRect_SetBorderColor(pstBorder->usColor0, pstBorder->usColor1, pstBorder->usColor2, pstBorder->usColor3);
        Hv_Cal_OsdRect_SetBorderEnable(HV_TRUE);
    }
    else
    {
        Hv_Cal_OsdRect_SetBorderEnable(HV_FALSE);
    }
}

static VOID Hv_Drv_OsdWindow_SetRectShadow(const OsdShadow *pstShadow)
{
    if (HV_TRUE == pstShadow->ucShadowEnable)
    {
        Hv_Cal_OsdRect_SetShadowType(pstShadow->ucShadowType);
        Hv_Cal_OsdRect_SetShadowSize(pstShadow->ucSizeX, pstShadow->ucSizeY);
        Hv_Cal_OsdRect_SetShadowColor(pstShadow->usShadowColor);
        Hv_Cal_OsdRect_SetShadowEnable(HV_TRUE);
    }
    else
    {
        Hv_Cal_OsdRect_SetShadowEnable(HV_FALSE);
    }
}

static VOID Hv_Drv_OsdWindow_SetRectGradient(const OsdGradient *pstGradient)
{
    if (HV_TRUE == pstGradient->ucGradientEnable)
    {
        Hv_Cal_OsdRect_SetBackgroundGradientType(pstGradient->ucGradientType);
        Hv_Cal_OsdRect_SetBackgroundColor(pstGradient->usStartColor, pstGradient->usEndColor);
        Hv_Cal_OsdRect_SetBackgroundGradientStep(pstGradient->usStepR, pstGradient->usStepG, pstGradient->usStepB);
        Hv_Cal_OsdRect_SetBackgroundGradientEnable(HV_TRUE);
    }
    else
    {
        Hv_Cal_OsdRect_SetBackgroundGradientEnable(HV_FALSE);
    }
}

static VOID Hv_Drv_OsdWindow_ShowRect(VOID)
{
    Hv_Cal_OsdRect_SetEnable(HV_TRUE);
}

static VOID Hv_Drv_OsdWindow_HideRect(VOID)
{
    Hv_Cal_OsdRect_SetEnable(HV_FALSE);
}

VOID Hv_Drv_OsdWindow_DrawRect(OsdRect *pstRect, const OsdRectStyle *pstRectStyle)
{
    if (NULL == pstRect)
    {
        return;
    }

    OSD_DRV_LOG_DEBUG("Draw Rect-%d", pstRect->ucIndex);
    Hv_Drv_OsdWindow_SetCurrentRect(pstRect->ucIndex);
    if ((0 == pstRect->usWidth) || (0 == pstRect->usHeight))
    {
        Hv_Drv_OsdWindow_HideRect();
        return;
    }


    /* rect prop setting */
    Hv_Drv_OsdWindow_SetRectProp(pstRect->usX, pstRect->usY, pstRect->usWidth, pstRect->usHeight,
                                 pstRect->ucBgColorEnable, pstRect->usBgColor);

    /* rect style setting */
    if (NULL != pstRectStyle)
    {
        Hv_Drv_OsdWindow_SetRectBorder(&pstRectStyle->stBorder);
        Hv_Drv_OsdWindow_SetRectShadow(&pstRectStyle->stShadow);
        Hv_Drv_OsdWindow_SetRectGradient(&pstRectStyle->stGrad);
    }

    Hv_Drv_OsdWindow_ShowRect();
}

VOID Hv_Drv_OsdWindow_UpdateRect(OsdRect *pstRect, const OsdRectStyle *pstRectStyle)
{
    OSD_DRV_LOG_DEBUG("Update Rect-%d", pstRect->ucIndex);
    Hv_Drv_OsdWindow_DrawRect(pstRect, pstRectStyle);
}

VOID Hv_Drv_OsdWindow_EraseRect(OsdRect *pstRect)
{
    if (NULL != pstRect)
    {
        OSD_DRV_LOG_DEBUG("Erase Rect-%d", pstRect->ucIndex);
        Hv_Drv_OsdWindow_SetCurrentRect(pstRect->ucIndex);
        Hv_Drv_OsdWindow_HideRect();
    }
}
/* Rect End */

/* Grid Begin */
static VOID Hv_Drv_OsdWindow_SetCurrentRectGrid(OsdGridPhyId enIndex)
{
    Hv_Cal_OsdGrid_SetCurrentGrid(enIndex);
    //OSD_DRV_LOG_DEBUG("Current RectGrid is RectGrid-%d", enIndex);
}

static VOID Hv_Drv_OsdWindow_SetRectGridProp(USHORT16 usX, USHORT16 usY, USHORT16 usWidth, USHORT16 usHeight)
{
    Hv_Cal_OsdGrid_SetPos(usX, usY);
    Hv_Cal_OsdGrid_SetRectSize(usWidth, usHeight);
}

static VOID Hv_Drv_OsdWindow_SetRectGridNumber(UCHAR8 ucRectHCount, UCHAR8 ucRectVCount, UCHAR8 ucRectHSpace, UCHAR8 ucRectVSpace)
{
    Hv_Cal_OsdGrid_SetRectNum(ucRectHCount, ucRectVCount);
    Hv_Cal_OsdGrid_SetSpace(ucRectHSpace, ucRectVSpace);
}

static VOID Hv_Drv_OsdWindow_SetRectGridColor(OsdRegionType enType, BOOL bBgColorEnable, USHORT16 usBgColor)
{
    if (bBgColorEnable)
    {
        Hv_Cal_OsdGrid_SetRectBackgroundEnable(enType, HV_TRUE);
        Hv_Cal_OsdGrid_SetRectBackgroundColor(enType, usBgColor, usBgColor);
    }
    else
    {
        Hv_Cal_OsdGrid_SetRectBackgroundEnable(enType, HV_FALSE);
    }
}

static VOID Hv_Drv_OsdWindow_SetRectGridBorder(OsdRegionType enType, const OsdBorder *pstBorder)
{
    if (HV_TRUE == pstBorder->ucBorderEnable)
    {
        Hv_Cal_OsdGrid_SetRectBorderType(pstBorder->ucBorderType);
        Hv_Cal_OsdGrid_SetRectBorderSize(pstBorder->ucSizeX, pstBorder->ucSizeY);
        Hv_Cal_OsdGrid_SetRectBorderColor(enType, pstBorder->usColor0, pstBorder->usColor1, pstBorder->usColor2, pstBorder->usColor3);
        Hv_Cal_OsdGrid_SetRectBorderEnable(enType, HV_TRUE);
    }
    else
    {
        Hv_Cal_OsdGrid_SetRectBorderEnable(enType, HV_FALSE);
    }
}

static VOID Hv_Drv_OsdWindow_SetRectGridShadow(OsdRegionType enType, const OsdShadow *pstShadow)
{
    if (HV_TRUE == pstShadow->ucShadowEnable)
    {
        Hv_Cal_OsdGrid_SetRectShadowType(pstShadow->ucShadowType);
        Hv_Cal_OsdGrid_SetRectShadowSize(pstShadow->ucSizeX, pstShadow->ucSizeY);
        Hv_Cal_OsdGrid_SetRectShadowColor(enType, pstShadow->usShadowColor);
        Hv_Cal_OsdGrid_SetRectShadowEnable(enType, HV_TRUE);
    }
    else
    {
        Hv_Cal_OsdGrid_SetRectShadowEnable(enType, HV_FALSE);
    }
}

static VOID Hv_Drv_OsdWindow_SetRectGridGradient(OsdRegionType enType, const OsdGradient *pstGradient)
{
    if (HV_TRUE == pstGradient->ucGradientEnable)
    {
        Hv_Cal_OsdGrid_SetRectGradientType(enType, pstGradient->ucGradientType);
        Hv_Cal_OsdGrid_SetRectBackgroundColor(enType, pstGradient->usStartColor, pstGradient->usEndColor);
        Hv_Cal_OsdGrid_SetRectGradientStep(enType, pstGradient->usStepR, pstGradient->usStepG, pstGradient->usStepB);
        Hv_Cal_OsdGrid_SetRectBackgroundGradientEnable(enType, HV_TRUE);
    }
    else
    {
        Hv_Cal_OsdGrid_SetRectBackgroundGradientEnable(enType, HV_FALSE);
    }
}

static VOID Hv_Drv_OsdWindow_SetRectGridHlProp(OsdHighLightMode ucHighlightMode, const OsdAxisHighlight *pstHOption, const OsdAxisHighlight *pstVOption)
{
    Hv_Cal_OsdGrid_SetHighlightMode(ucHighlightMode);
    Hv_Cal_OsdGrid_SetHighlightHMode(pstHOption->ucMode);
    Hv_Cal_OsdGrid_SetHighlightVMode(pstVOption->ucMode);
    Hv_Cal_OsdGrid_SetHighlightHRange(pstHOption->ucStartPos , pstHOption->ucStopPos);
    Hv_Cal_OsdGrid_SetHighlightVRange(pstVOption->ucStartPos, pstVOption->ucStopPos);
}

static VOID Hv_Drv_OsdWindow_SetRectGridHlInvalid(VOID)
{
    Hv_Cal_OsdGrid_SetHighlightHRange(2 , 1);
    Hv_Cal_OsdGrid_SetHighlightVRange(2, 1);
}

static VOID Hv_Drv_OsdWindow_ShowRectGrid(VOID)
{
    Hv_Cal_OsdGrid_SetEnable(OSD_REGION_NO_HIGHLIGHT, HV_TRUE);
}

static VOID Hv_Drv_OsdWindow_ShowRectGridHl(VOID)
{
    Hv_Cal_OsdGrid_SetEnable(OSD_REGION_HIGHLIGHT, HV_TRUE);
}

static VOID Hv_Drv_OsdWindow_HideRectGrid(VOID)
{
    Hv_Cal_OsdGrid_SetEnable(OSD_REGION_NO_HIGHLIGHT, HV_FALSE);
}

static VOID Hv_Drv_OsdWindow_HideRectGridHl(VOID)
{
    Hv_Cal_OsdGrid_SetEnable(OSD_REGION_HIGHLIGHT, HV_FALSE);
}

VOID Hv_Drv_OsdWindow_DrawRectGrid(OsdRectGrid* pstGrid,
                                   const OsdRectStyle *pstNonHlRectStyle,
                                   const OsdRectHighlight *pstRectHighlight,
                                   const OsdRectStyle *pstHlRectStyle)
{
    if (NULL == pstGrid)
    {
        return;
    }

    OSD_DRV_LOG_DEBUG("Draw Grid-%d", pstGrid->ucIndex);
    Hv_Drv_OsdWindow_SetCurrentRectGrid(pstGrid->ucIndex);
    if ((0 == pstGrid->usWidth) || (0 == pstGrid->usHeight))
    {
        Hv_Drv_OsdWindow_HideRectGrid();
        Hv_Drv_OsdWindow_HideRectGridHl();
        return;
    }

    /* non highlight prop setting */
    Hv_Drv_OsdWindow_SetRectGridProp( pstGrid->usX, pstGrid->usY, pstGrid->usWidth, pstGrid->usHeight);
    Hv_Drv_OsdWindow_SetRectGridNumber(pstGrid->ucRectHCount, pstGrid->ucRectVCount, pstGrid->ucRectHSpace, pstGrid->ucRectVSpace);
    Hv_Drv_OsdWindow_SetRectGridColor(OSD_REGION_NO_HIGHLIGHT, pstGrid->ucBgColorEnable, pstGrid->usBgColor);

    /* non highlight style setting */
    if (NULL != pstNonHlRectStyle)
    {
        Hv_Drv_OsdWindow_SetRectGridBorder(OSD_REGION_NO_HIGHLIGHT, &pstNonHlRectStyle->stBorder);
        Hv_Drv_OsdWindow_SetRectGridShadow(OSD_REGION_NO_HIGHLIGHT, &pstNonHlRectStyle->stShadow);
        Hv_Drv_OsdWindow_SetRectGridGradient(OSD_REGION_NO_HIGHLIGHT, &pstNonHlRectStyle->stGrad);
    }
    Hv_Drv_OsdWindow_ShowRectGrid();

    if (NULL != pstRectHighlight)
    {
        if (0 != pstGrid->ucHlOptionIndex)
        {
            /* highlight prop setting */
            Hv_Drv_OsdWindow_SetRectGridHlProp(pstRectHighlight->ucHighlightMode, &pstRectHighlight->stHOption, &pstRectHighlight->stVOption);
            Hv_Drv_OsdWindow_SetRectGridColor(OSD_REGION_HIGHLIGHT, pstRectHighlight->ucBgColorEnable, pstRectHighlight->usBgColor);

            /* highlight style setting */
            if (NULL != pstHlRectStyle)
            {
                Hv_Drv_OsdWindow_SetRectGridBorder(OSD_REGION_HIGHLIGHT, &pstHlRectStyle->stBorder);
                Hv_Drv_OsdWindow_SetRectGridShadow(OSD_REGION_HIGHLIGHT, &pstHlRectStyle->stShadow);
                Hv_Drv_OsdWindow_SetRectGridGradient(OSD_REGION_HIGHLIGHT, &pstHlRectStyle->stGrad);
            }

            Hv_Drv_OsdWindow_ShowRectGridHl();
        }
        else
        {
            Hv_Drv_OsdWindow_SetRectGridHlInvalid();
            Hv_Drv_OsdWindow_HideRectGridHl();
        }
    }
    else
    {
        Hv_Drv_OsdWindow_SetRectGridHlInvalid();
        Hv_Drv_OsdWindow_HideRectGridHl();
    }
}

VOID Hv_Drv_OsdWindow_UpdateRectGrid(OsdRectGrid* pstGrid,
                                     const OsdRectStyle *pstNonHlRectStyle,
                                     const OsdRectHighlight *pstRectHighlight,
                                     const OsdRectStyle *pstHlRectStyle)
{
    OSD_DRV_LOG_DEBUG("Update RectGrid-%d", pstGrid->ucIndex);
    Hv_Drv_OsdWindow_DrawRectGrid(pstGrid, pstNonHlRectStyle, pstRectHighlight, pstHlRectStyle);
}

VOID Hv_Drv_OsdWindow_EraseRectGrid(OsdRectGrid* pstGrid)
{
    if (pstGrid)
    {
        OSD_DRV_LOG_DEBUG("Erase RectGrid-%d", pstGrid->ucIndex);
        Hv_Drv_OsdWindow_SetCurrentRectGrid(pstGrid->ucIndex);
        Hv_Drv_OsdWindow_HideRectGrid();
        Hv_Drv_OsdWindow_HideRectGridHl();
    }
}
/* Grid End */

/* Line Begin */
static VOID Hv_Drv_OsdWindow_SetCurrentLine(OsdLinePhyId enIndex)
{
    Hv_Cal_OsdLine_SetCurrentLine(enIndex);
    //OSD_DRV_LOG_DEBUG("Current Line is Line-%d", enIndex);
}

static VOID Hv_Drv_OsdWindow_SetCurrentLineGrid(OsdLinePhyId enIndex)
{
    Hv_Cal_OsdLine_SetCurrentLine(enIndex);
    //OSD_DRV_LOG_DEBUG("Current LineGrid is LineGrid-%d", enIndex);
}

static VOID Hv_Drv_OsdWindow_SetLineGridColor(OsdRegionType enType, BOOL bBgColorEnable, USHORT16 usBgColor, USHORT16 usBorderColor)
{
    if (bBgColorEnable)
    {
        Hv_Cal_OsdLine_SetLineBackgroundEnable(enType, HV_TRUE);
        Hv_Cal_OsdLine_SetLineBackgroundColor(enType, usBgColor);
    }
    else
    {
        Hv_Cal_OsdLine_SetLineBackgroundEnable(enType, HV_FALSE);
    }

    Hv_Cal_OsdLine_SetLineBorderColor(enType, usBorderColor);
}

static VOID Hv_Drv_OsdWindow_SetLineGridNumber(UCHAR8 ucLineHCount, UCHAR8 ucLineVCount, UCHAR8 ucLineHSpace, UCHAR8 ucLineVSpace)
{
    Hv_Cal_OsdLine_SetLineNum(ucLineHCount, ucLineVCount);
    Hv_Cal_OsdLine_SetSpace(ucLineHSpace, ucLineVSpace);
}

static VOID Hv_Drv_OsdWindow_SetLineGridHlProp(OsdHighLightMode ucHighlightMode, const OsdAxisHighlight *pstHOption, const OsdAxisHighlight *pstVOption)
{
    Hv_Cal_OsdLine_SetHighlightMode(ucHighlightMode);
    Hv_Cal_OsdLine_SetHighlightHMode(pstHOption->ucMode);
    Hv_Cal_OsdLine_SetHighlightVMode(pstVOption->ucMode);
    Hv_Cal_OsdLine_SetHighlightHRange(pstHOption->ucStartPos , pstHOption->ucStopPos);
    Hv_Cal_OsdLine_SetHighlightVRange(pstVOption->ucStartPos, pstVOption->ucStopPos);
}

static VOID Hv_Drv_OsdWindow_SetLineGridHlInvalid(VOID)
{
    Hv_Cal_OsdLine_SetHighlightHRange(2 , 1);
    Hv_Cal_OsdLine_SetHighlightVRange(2, 1);
}

static VOID Hv_Drv_OsdWindow_HideLineGrid(VOID)
{
    Hv_Cal_OsdLine_SetEnable(OSD_REGION_NO_HIGHLIGHT, HV_FALSE);
}

static VOID Hv_Drv_OsdWindow_HideLineGridHl(VOID)
{
    Hv_Cal_OsdLine_SetEnable(OSD_REGION_HIGHLIGHT, HV_FALSE);
}

static VOID Hv_Drv_OsdWindow_ShowLineGrid(VOID)
{
    Hv_Cal_OsdLine_SetEnable(OSD_REGION_NO_HIGHLIGHT, HV_TRUE);
}

static VOID Hv_Drv_OsdWindow_ShowLineGridHl(VOID)
{
    Hv_Cal_OsdLine_SetEnable(OSD_REGION_HIGHLIGHT, HV_TRUE);
}

static VOID Hv_Drv_OsdWindow_SetLineColor(BOOL bBgColorEnable, USHORT16 usBgColor, USHORT16 usBorderColor)
{
    Hv_Drv_OsdWindow_SetLineGridColor(OSD_REGION_NO_HIGHLIGHT, bBgColorEnable, usBgColor, usBorderColor);
}

static VOID Hv_Drv_OsdWindow_SetLineProp(USHORT16 usX, USHORT16 usY, USHORT16 usWidth, USHORT16 usHeight)
{
    Hv_Cal_OsdLine_SetPos(usX, usY);
    Hv_Cal_OsdLine_SetLineSize(usWidth, usHeight);
}

static VOID Hv_Drv_OsdWindow_ShowLine(VOID)
{
    Hv_Cal_OsdLine_SetLineNum(1, 1);
    Hv_Cal_OsdLine_SetSpace(0, 0);
    Hv_Cal_OsdLine_SetEnable(OSD_REGION_NO_HIGHLIGHT, HV_TRUE);
    Hv_Cal_OsdLine_SetEnable(OSD_REGION_HIGHLIGHT, HV_FALSE);
}

static VOID Hv_Drv_OsdWindow_HideLine(VOID)
{
    Hv_Cal_OsdLine_SetEnable(OSD_REGION_NO_HIGHLIGHT, HV_FALSE);
    Hv_Cal_OsdLine_SetEnable(OSD_REGION_HIGHLIGHT, HV_FALSE);
}

VOID Hv_Drv_OsdWindow_DrawLineGrid(OsdLineGrid* pstLineGrid, const OsdLineHighlight *pstLineHighlight)
{
    if (NULL == pstLineGrid)
    {
        return;
    }

    OSD_DRV_LOG_DEBUG("Draw LineGrid-%d", pstLineGrid->ucIndex);
    Hv_Drv_OsdWindow_SetCurrentLineGrid(pstLineGrid->ucIndex);
    if ((0 == pstLineGrid->usWidth) || (0 == pstLineGrid->usHeight))
    {
        Hv_Drv_OsdWindow_HideLineGrid();
        Hv_Drv_OsdWindow_HideLineGridHl();
        return;
    }

    /* non highlight prop setting */
    Hv_Drv_OsdWindow_SetLineProp(pstLineGrid->usX, pstLineGrid->usY, pstLineGrid->usWidth, pstLineGrid->usHeight);
    Hv_Drv_OsdWindow_SetLineGridColor(OSD_REGION_NO_HIGHLIGHT, pstLineGrid->ucBgColorEnable, pstLineGrid->usBgColor, pstLineGrid->usBorderColor);
    Hv_Drv_OsdWindow_SetLineGridNumber(pstLineGrid->ucLineHCount, pstLineGrid->ucLineVCount, pstLineGrid->ucLineHSpace, pstLineGrid->ucLineVSpace);
    Hv_Drv_OsdWindow_ShowLineGrid();

    /* highlight prop setting */
    if (NULL != pstLineHighlight)
    {
        if (0 != pstLineGrid->ucHlOptionIndex)
        {
            Hv_Drv_OsdWindow_SetLineGridHlProp(pstLineHighlight->ucHighlightMode, &pstLineHighlight->stHOption, &pstLineHighlight->stVOption);
            Hv_Drv_OsdWindow_SetLineGridColor(OSD_REGION_HIGHLIGHT, pstLineHighlight->ucBgColorEnable, pstLineHighlight->usBgColor, pstLineHighlight->usBorderColor);
            Hv_Drv_OsdWindow_ShowLineGridHl();
        }
        else
        {
            Hv_Drv_OsdWindow_SetLineGridHlInvalid();
            Hv_Drv_OsdWindow_HideLineGridHl();
        }
    }
    else
    {
        Hv_Drv_OsdWindow_SetLineGridHlInvalid();
        Hv_Drv_OsdWindow_HideLineGridHl();
    }
}

VOID Hv_Drv_OsdWindow_UpdateLineGrid(OsdLineGrid* pstLineGrid, const OsdLineHighlight *pstLineHighlight)
{
    OSD_DRV_LOG_DEBUG("Update LineGrid-%d", pstLineGrid->ucIndex);
    Hv_Drv_OsdWindow_DrawLineGrid(pstLineGrid, pstLineHighlight);
}

VOID Hv_Drv_OsdWindow_EraseLineGrid(OsdLineGrid* pstLineGrid)
{
    if (NULL != pstLineGrid)
    {
        OSD_DRV_LOG_DEBUG("Erase LineGrid-%d", pstLineGrid->ucIndex);
        Hv_Drv_OsdWindow_SetCurrentLineGrid(pstLineGrid->ucIndex);
        Hv_Drv_OsdWindow_HideLineGrid();
        Hv_Drv_OsdWindow_HideLineGridHl();
    }
}

VOID Hv_Drv_OsdWindow_DrawLine(OsdLine* pstLine)
{
    if (NULL == pstLine)
    {
        return;
    }

    OSD_DRV_LOG_DEBUG("Draw Line-%d", pstLine->ucIndex);
    Hv_Drv_OsdWindow_SetCurrentLine(pstLine->ucIndex);
    if ((0 == pstLine->usWidth) || (0 == pstLine->usHeight))
    {
        Hv_Drv_OsdWindow_HideLine();
        return;
    }

    Hv_Drv_OsdWindow_SetLineProp(pstLine->usX, pstLine->usY, pstLine->usWidth, pstLine->usHeight);
    Hv_Drv_OsdWindow_SetLineColor(pstLine->ucBgColorEnable, pstLine->usBgColor, pstLine->usBorderColor);

    Hv_Drv_OsdWindow_SetLineGridHlInvalid();
    Hv_Drv_OsdWindow_ShowLine();
}

VOID Hv_Drv_OsdWindow_UpdateLine(OsdLine* pstLine)
{
    OSD_DRV_LOG_DEBUG("Update Line-%d", pstLine->ucIndex);
    Hv_Drv_OsdWindow_DrawLine(pstLine);
}

VOID Hv_Drv_OsdWindow_EraseLine(OsdLine* pstLine)
{
    if (NULL != pstLine)
    {
        OSD_DRV_LOG_DEBUG("Erase Line-%d", pstLine->ucIndex);
        Hv_Drv_OsdWindow_SetCurrentLine(pstLine->ucIndex);
        Hv_Drv_OsdWindow_HideLine();
    }
}
/* Line End */

/* Window Begin */
VOID Hv_Drv_OsdWindow_SetCurrentWindow(OsdWindowPhyId enIndex)
{
    Hv_Cal_OsdWindow_SetCurrentWindow(enIndex);
    //OSD_DRV_LOG_DEBUG("Starting Draw window %u", enIndex);
}

OsdWindowPhyId Hv_Drv_OsdWindow_GetCurrentWindow(VOID)
{
    return Hv_Cal_OsdWindow_GetCurrentWindow();
}

VOID Hv_Drv_OsdWindow_SetAllFontEnable(BOOL bEnable)
{
    for (OsdWindowPhyId enWinIndex = PHY_WIN_0; enWinIndex <= PHY_WIN_3; ++enWinIndex)
    {
        Hv_Cal_OsdWindow_SetCurrentWindow(enWinIndex);
        Hv_Cal_OsdWindow_SetFontEnable(bEnable);
    }
}

VOID Hv_Drv_OsdWindow_DisableAll(VOID)
{

    OsdWindowPhyId enWinIndex = PHY_WIN_0;
    UCHAR8 ucIndex = 0;

    for (ucIndex = 0; ucIndex < PHY_RECT_ID_MAX; ++ucIndex)
    {
        Hv_Drv_OsdWindow_SetCurrentRect(ucIndex);
        Hv_Drv_OsdWindow_HideRect();
    }

    for (ucIndex = 0; ucIndex < PHY_GRID_ID_MAX; ++ucIndex)
    {
        Hv_Drv_OsdWindow_SetCurrentRectGrid(ucIndex);
        Hv_Drv_OsdWindow_HideRectGrid();
        Hv_Drv_OsdWindow_HideRectGridHl();
    }

    for (ucIndex = 0; ucIndex < PHY_LINE_ID_MAX; ++ucIndex)
    {
        Hv_Drv_OsdWindow_SetCurrentLine(ucIndex);
        Hv_Drv_OsdWindow_HideLine();
    }

    for (enWinIndex = PHY_WIN_0; enWinIndex < PHY_WIN_ID_MAX; ++enWinIndex)
    {
        Hv_Drv_OsdWindow_SetCurrentWindow(enWinIndex);

        if (OSD_WINDOW_IS_NORMAL(enWinIndex))
        {
            Hv_Drv_OsdFont_SetFontEnable(0);
        }
        Hv_Cal_OsdWindow_SetEnable(0);
    }
}

VOID Hv_Drv_OsdWindow_DrawWindow(OsdWindowProp *pstWindowProp)
{
    UINT32 uiColor = 0;

    HV_ASSERT_TRUE_VOID(pstWindowProp != NULL);

    Hv_Drv_OsdWindow_SetCurrentWindow(pstWindowProp->ucWindowID);
    if ((0 == pstWindowProp->usWidth) || (0 == pstWindowProp->usHeight))
    {
        Hv_Cal_OsdWindow_SetEnable(HV_FALSE);
        return;
    }

    /* area */
    OSD_DRV_LOG_DEBUG("window %u position set to (%u, %u)",
            pstWindowProp->ucWindowID, pstWindowProp->usX, pstWindowProp->usY);
    Hv_Cal_OsdWindow_SetPos(pstWindowProp->usX, pstWindowProp->usY);
    OSD_DRV_LOG_DEBUG("size set to (%u, %u)", pstWindowProp->usWidth,
            pstWindowProp->usHeight);
    Hv_Cal_OsdWindow_SetSize(pstWindowProp->usWidth, pstWindowProp->usHeight);

    /* border */
    Hv_Cal_OsdWindow_SetBorderEnable(pstWindowProp->ucBorderEnable);
    if (pstWindowProp->ucBorderEnable)
    {
        uiColor = Hv_Drv_OsdWindow_PixelFormatConvert(OSD_PIXEL_FORMAT_RGB565,
                        OSD_PIXEL_FORMAT_RGB888, pstWindowProp->usBorderColor);
        Hv_Cal_OsdWindow_SetBorderColor(uiColor);
    }

    /* background */
    Hv_Cal_OsdBlend_SetBackground(OSD_BLENDING_STAGE_RECT_FONT,
            pstWindowProp->ucBgEnable, pstWindowProp->usBgColor);
    if (pstWindowProp->ucBgEnable)
    {
        //Hv_Cal_OsdBlend_SetBackgroundAlpha(OSD_BLENDING_STAGE_RECT_FONT, pstWindowProp->ucAlpha);
        Hv_Cal_OsdBlend_SetBackgroundAlpha(OSD_BLENDING_STAGE_RECT_FONT, 255);
    }

    /* alpha */
    //Hv_Cal_OsdBlend_SetForegroundAlpha(OSD_BLENDING_STAGE_RECT_GROUP, 255);  //TODO: pstWindowProp->ucAlpha

    Hv_Cal_OsdWindow_SetEnable(1);
}

VOID Hv_Drv_OsdWindow_UpdateWindow(OsdWindowProp *pstWindowProp)
{
    HV_ASSERT_TRUE_VOID(pstWindowProp != NULL);

    OSD_DRV_LOG_DEBUG("update window-%u", pstWindowProp->ucWindowID);
    Hv_Drv_OsdWindow_DrawWindow(pstWindowProp);
}

VOID Hv_Drv_OsdWindow_EraseWindow(OsdWindowProp *pstWindowProp)
{
    HV_ASSERT_TRUE_VOID(pstWindowProp != NULL);

    OSD_DRV_LOG_DEBUG("Hide window-%u", pstWindowProp->ucWindowID);

    Hv_Drv_OsdWindow_SetCurrentWindow(pstWindowProp->ucWindowID);

    Hv_Cal_OsdWindow_SetEnable(0);
}
/* Window End */
