layer.c
上传用户:fy98168
上传日期:2015-06-26
资源大小:13771k
文件大小:12k
- /*****************************************************************************
- File name: layer.c
- Description: LAYER functions
- COPYRIGHT (C) STMicroelectronics 2004.
- *****************************************************************************/
- /* Includes --------------------------------------------------------------- */
- #include <string.h>
- #include "stddefs.h"
- #include "stlite.h"
- #include "stdevice.h"
- #include "stgxobj.h"
- #include "sttbx.h"
- #include "section.h" /* memory partitions */
- #include "errors.h"
- #include "avmem.h"
- #include "evt.h"
- #include "vtg.h"
- #include "layer.h"
- #include "osd.h"
- /* Private Types ------------------------------------------------------ */
- /* Private Constants -------------------------------------------------- */
- /* Private Variables -------------------------------------------------- */
- STLAYER_ViewPortHandle_t LAYER_ViewPortHandle[NUM_VPORTS];
- STLAYER_ViewPortParams_t LAYER_ViewPortParams[NUM_VPORTS];
- STLAYER_ViewPortSource_t LAYER_ViewPortSource[NUM_VPORTS];
- /* Private Macros ----------------------------------------------------- */
- /* Private Function prototypes ---------------------------------------- */
- /* Functions ---------------------------------------------------------- */
- /* Global Variables ------------------------------------------------------- */
- ST_DeviceName_t g_KB_LayerDeviceName[NUM_LAYERS] = {
- "VIDEO",
- "OSD",
- "STILL"
- };
- STLAYER_Handle_t g_KB_LayerHandle[NUM_LAYERS];
- /* Functions -------------------------------------------------------------- */
- /*-------------------------------------------------------------------------
- * Function : KB_LayerSetup
- * Input : Instance
- * Output :
- * Return : Error Code
- * ----------------------------------------------------------------------*/
- ST_ErrorCode_t KB_LayerSetup(void)
- {
- ST_ErrorCode_t ST_ErrorCode;
- STLAYER_InitParams_t STLAYER_InitParams;
- STLAYER_LayerParams_t STLAYER_LayerParams;
- STLAYER_OpenParams_t STLAYER_OpenParams = { 0 }; /* Set dummy */
- U8 Index;
- STLAYER_LayerParams.AspectRatio = STGXOBJ_ASPECT_RATIO_4TO3;
- STLAYER_LayerParams.ScanType = STGXOBJ_INTERLACED_SCAN;
- /* init vtg before layer! */
- STLAYER_LayerParams.Width = g_KB_VtgModeParams.ActiveAreaWidth;
- STLAYER_LayerParams.Height = g_KB_VtgModeParams.ActiveAreaHeight;
- STLAYER_InitParams.LayerType = KB_LAYER_TYPE;
- STLAYER_InitParams.DeviceBaseAddress_p = (void *)KB_LAYER_DEVICE_BASE_ADDRESS;
- STLAYER_InitParams.SharedMemoryBaseAddress_p = (void *)SDRAM_BASE_ADDRESS;
- STLAYER_InitParams.BaseAddress_p = (void *)KB_LAYER_BASE_ADDRESS;
- STLAYER_InitParams.BaseAddress2_p = (void *)KB_LAYER_BASE_ADDRESS2;
- STLAYER_InitParams.LayerParams_p = &STLAYER_LayerParams;
- STLAYER_InitParams.CPUPartition_p = SystemPartition;
- STLAYER_InitParams.CPUBigEndian = TRUE;
- STLAYER_InitParams.AVMEM_Partition = (STAVMEM_PartitionHandle_t)g_KBAvmemPartitionHandle[0];
- STLAYER_InitParams.NodeBufferUserAllocated = FALSE;
- STLAYER_InitParams.ViewPortNodeBuffer_p = (void *)NULL;
- STLAYER_InitParams.ViewPortBufferUserAllocated = FALSE;
- STLAYER_InitParams.ViewPortBuffer_p = (void *)NULL;
- strcpy(STLAYER_InitParams.EventHandlerName, g_KB_EVTDeviceName[KB_EVT_VTG]);
- STTBX_Print(("KB_LayerSetup NUM_LAYERS = %dn", NUM_LAYERS));
- for (Index = 0; Index < NUM_LAYERS; Index++ )
- {
- switch (Index)
- {
- case LAYER_VIDEO:
- STLAYER_InitParams.MaxHandles = KB_LAYER_MAX_HANDLES;
- STLAYER_InitParams.MaxViewPorts = KB_LAYER_MAX_VIEWPORTS;
- break;
- default:
- STLAYER_InitParams.MaxHandles = KB_LAYER_MAX_HANDLES;
- STLAYER_InitParams.MaxViewPorts = KB_LAYER_MAX_VIEWPORTS;
- break;
- }
- STTBX_Print(("KB_LayerSetup(%s)=", g_KB_LayerDeviceName[Index] ));
- ST_ErrorCode = STLAYER_Init(g_KB_LayerDeviceName[Index], &STLAYER_InitParams);
- if (ST_ErrorCode != ST_NO_ERROR)
- {
- STTBX_Print(("%sn", DBGError(ST_ErrorCode) ));
- return( ST_ErrorCode );
- }
- STTBX_Print(("%sn", STLAYER_GetRevision() ));
- STTBX_Print(("LAYER_Open="));
- ST_ErrorCode = STLAYER_Open(g_KB_LayerDeviceName[Index], &STLAYER_OpenParams, &g_KB_LayerHandle[Index]);
- STTBX_Print(("%sn", DBGError(ST_ErrorCode) ));
- if (ST_ErrorCode != ST_NO_ERROR)
- return( ST_ErrorCode );
- } /* for(Index) */
- ST_ErrorCode = KB_LayerSetLayerParams();
- if (ST_ErrorCode != ST_NO_ERROR)
- {
- STTBX_Print(("KB_LayerSetLayerParams=%sn", DBGError(ST_ErrorCode) ));
- return( ST_ErrorCode );
- }
- return( ST_ErrorCode );
- }
- /*-------------------------------------------------------------------------
- * Function : LAYER_SetScreenParams
- * Input : None
- * Output :
- * Return : Error Code
- * ----------------------------------------------------------------------*/
- ST_ErrorCode_t KB_LayerSetLayerParams(void)
- {
- ST_ErrorCode_t ST_ErrorCode;
- STLAYER_LayerParams_t STLAYER_LayerParams;
- U8 Index;
- ST_ErrorCode = KB_VtgGetMode(); /* get Active area */
- if (ST_ErrorCode != ST_NO_ERROR)
- return( ST_ErrorCode );
- STTBX_Print(("KB_LayerSetLayerParams NUM_LAYERS = %dn", NUM_LAYERS));
-
- for (Index = 0; Index < NUM_LAYERS; Index++ )
- {
- STLAYER_LayerParams.AspectRatio = STGXOBJ_ASPECT_RATIO_4TO3;
- STLAYER_LayerParams.ScanType = g_KB_VtgModeParams.ScanType;
- STLAYER_LayerParams.Width = g_KB_VtgModeParams.ActiveAreaWidth;
- STLAYER_LayerParams.Height = g_KB_VtgModeParams.ActiveAreaHeight;
- ST_ErrorCode = STLAYER_SetLayerParams(g_KB_LayerHandle[Index], &STLAYER_LayerParams);
- if (ST_ErrorCode != ST_NO_ERROR)
- {
- STTBX_Print(("KB_LayerSetLayerParams=%sn", DBGError(ST_ErrorCode) ));
- return( ST_ErrorCode );
- }
- STTBX_Print(("KB_LayerSetLayerParams(%d, %d,%d, %d,%d)n", Index,
- STLAYER_LayerParams.Width, STLAYER_LayerParams.Height,
- STLAYER_LayerParams.AspectRatio, STLAYER_LayerParams.ScanType));
- }
- return( ST_ErrorCode );
- }
- INT32 KB_LayerOpenViewPort(UINT8 Layer,
- UINT8 Vport,
- STGXOBJ_Bitmap_t *Bitmap_p,
- STGXOBJ_Rectangle_t *OutputRectangle_p)
- {
- ST_ErrorCode_t ErrCode = ST_NO_ERROR;
- U32 Width, Height;
- Width = Bitmap_p->Width;
- if ( Width > g_KB_VtgModeParams.ActiveAreaWidth )
- Width = g_KB_VtgModeParams.ActiveAreaWidth;
- Height = Bitmap_p->Height;
- if ( Height > g_KB_VtgModeParams.ActiveAreaHeight )
- Height = g_KB_VtgModeParams.ActiveAreaHeight;
- LAYER_ViewPortParams[Vport].Source_p = &LAYER_ViewPortSource[Vport];
- LAYER_ViewPortParams[Vport].InputRectangle.PositionX = 0;
- LAYER_ViewPortParams[Vport].InputRectangle.PositionY = 0;
- LAYER_ViewPortParams[Vport].InputRectangle.Width = Width;
- LAYER_ViewPortParams[Vport].InputRectangle.Height = Height;
- if ( OutputRectangle_p == NULL )
- LAYER_ViewPortParams[Vport].OutputRectangle = LAYER_ViewPortParams[Vport].InputRectangle;
- else
- LAYER_ViewPortParams[Vport].OutputRectangle = *OutputRectangle_p;
- LAYER_ViewPortSource[Vport].SourceType = STLAYER_GRAPHIC_BITMAP;
- LAYER_ViewPortSource[Vport].Data.BitMap_p = Bitmap_p;
- LAYER_ViewPortSource[Vport].Palette_p = NULL;
- /* Open OSD Layer view port */
- ErrCode = STLAYER_OpenViewPort(g_KB_LayerHandle[Layer],
- &LAYER_ViewPortParams[Vport],
- &LAYER_ViewPortHandle[Vport]);
- if ( ErrCode != ST_NO_ERROR )
- {
- STTBX_Print(("KB_LayerOpenViewPort(%d, %d,%d,%d,%d)=%sn",
- Vport,
- LAYER_ViewPortParams[Vport].OutputRectangle.PositionX,
- LAYER_ViewPortParams[Vport].OutputRectangle.PositionY,
- LAYER_ViewPortParams[Vport].OutputRectangle.Width,
- LAYER_ViewPortParams[Vport].OutputRectangle.Height,
- DBGError(ErrCode) ));
- return RETFIAL1;
- }
- return KB_LayerEnableViewPort(Layer, Vport);
- }
- /*-------------------------------------------------------------------------
- * Function : KB_LayerSetOutParam
- Opening a viewport
- * Input : U8 Layer, U8 Vport, STGXOBJ_Rectangle_t *OutputRectangle_p
- * Output :
- * Return : Error code
- * ----------------------------------------------------------------------*/
- INT32 KB_LayerSetOutParam(UINT8 Layer, UINT8 Vport,
- STGXOBJ_Rectangle_t *OutputRectangle_p)
- {
- ST_ErrorCode_t ErrCode = ST_NO_ERROR;
- if ( OutputRectangle_p == NULL )
- LAYER_ViewPortParams[Vport].OutputRectangle = LAYER_ViewPortParams[Vport].InputRectangle;
- else
- LAYER_ViewPortParams[Vport].OutputRectangle = *OutputRectangle_p;
- /* change view port parameters */
- ErrCode = STLAYER_SetViewPortIORectangle(LAYER_ViewPortHandle[Vport], &LAYER_ViewPortParams[Vport].InputRectangle,
- &LAYER_ViewPortParams[Vport].OutputRectangle);
- if ( ErrCode != ST_NO_ERROR )
- {
- STTBX_Print(("STLAYER_SetViewPortParams(%d) failed %sn", Vport, KB_ErrorGetText(ErrCode) ));
- return RETFIAL1;
- }
- else
- {
- return RETOK;
- }
- } /* end KB_LayerSetOutParam() */
- INT32 KB_LayerEnableViewPort(UINT8 cLayer, UINT8 cVport)
- {
- ST_ErrorCode_t ErrCode;
-
- ErrCode = STLAYER_EnableViewPortFilter(LAYER_ViewPortHandle[cVport], g_KB_LayerHandle[cLayer]);
- if ( ErrCode != ST_NO_ERROR )
- {
- STTBX_Print(("STLAYER_EnableViewPortFilter(%d)=%sn", cVport, DBGError(ErrCode) ));
- return RETFIAL1;
- }
- ErrCode = STLAYER_EnableViewPort(LAYER_ViewPortHandle[cVport]);
- if ( ErrCode != ST_NO_ERROR )
- {
- STTBX_Print(("KB_LayerEnableViewPort(%d)=%sn", cVport, DBGError(ErrCode) ));
- return RETFIAL1;
- }
-
- return RETOK;
- }
- INT32 KB_LayerDisableViewPort(UINT8 cVport)
- {
- ST_ErrorCode_t ErrCode;
-
- ErrCode = STLAYER_DisableViewPort(LAYER_ViewPortHandle[cVport]);
- if ( ErrCode != ST_NO_ERROR )
- {
- STTBX_Print(("STLAYER_EnableViewPortFilter(%d)=%sn", cVport, DBGError(ErrCode) ));
- return RETFIAL1;
- }
-
- return RETOK;
- }
- INT32 KB_LayerSetViewPortAlpha(STLAYER_ViewPortHandle_t nVPHandle, INT32 nLevel)
- {
- STLAYER_GlobalAlpha_t tAlpha;
- ST_ErrorCode_t ErrCode;
- INT32 nAlpha;
-
- #if (COLOR == KB_OSD_COLOR_ARGB_16_1555)
- {
- /* 对于Alpha位为1的颜色模式,只用A1起作用 */
- nAlpha = 128 * nLevel / 100 ;
- tAlpha.A1 = (U8)nAlpha;
- }
- #else
- {
- nAlpha = 128 * nLevel / 100 ;
- tAlpha.A0 = (U8)nAlpha;
- tAlpha.A1 = (U8)nAlpha;
- }
- #endif
-
- ErrCode = STLAYER_SetViewPortAlpha(LAYER_ViewPortHandle[nVPHandle], &tAlpha);
- if ( ErrCode != ST_NO_ERROR )
- {
- STTBX_Print(("STLAYER_SetViewPortAlpha(%d)=%sn", LAYER_ViewPortHandle[nVPHandle], DBGError(ErrCode) ));
- return RETFIAL1;
- }
-
- return RETOK;
- }
- /* EOF --------------------------------------------------------------------- */