layer.c
上传用户:fy98168
上传日期:2015-06-26
资源大小:13771k
文件大小:12k
源码类别:

DVD

开发平台:

C/C++

  1. /*****************************************************************************
  2.   File name: layer.c
  3. Description: LAYER functions
  4. COPYRIGHT (C) STMicroelectronics 2004.
  5. *****************************************************************************/
  6. /* Includes --------------------------------------------------------------- */
  7. #include <string.h>
  8. #include "stddefs.h"
  9. #include "stlite.h"
  10. #include "stdevice.h"
  11. #include "stgxobj.h"
  12. #include "sttbx.h"
  13. #include "section.h"   /* memory partitions */
  14. #include "errors.h"
  15. #include "avmem.h"
  16. #include "evt.h"
  17. #include "vtg.h"
  18. #include "layer.h"
  19. #include "osd.h"
  20. /* Private Types ------------------------------------------------------ */
  21. /* Private Constants -------------------------------------------------- */
  22. /* Private Variables -------------------------------------------------- */
  23. STLAYER_ViewPortHandle_t    LAYER_ViewPortHandle[NUM_VPORTS];
  24. STLAYER_ViewPortParams_t    LAYER_ViewPortParams[NUM_VPORTS];
  25. STLAYER_ViewPortSource_t    LAYER_ViewPortSource[NUM_VPORTS];
  26. /* Private Macros ----------------------------------------------------- */
  27. /* Private Function prototypes ---------------------------------------- */
  28. /* Functions ---------------------------------------------------------- */
  29. /* Global Variables ------------------------------------------------------- */
  30. ST_DeviceName_t  g_KB_LayerDeviceName[NUM_LAYERS] = {
  31.                                                     "VIDEO",
  32.                                                     "OSD",
  33.                                                     "STILL"
  34.                                                 };
  35. STLAYER_Handle_t g_KB_LayerHandle[NUM_LAYERS];
  36. /* Functions -------------------------------------------------------------- */
  37. /*-------------------------------------------------------------------------
  38.  * Function : KB_LayerSetup
  39.  * Input    : Instance
  40.  * Output   :
  41.  * Return   : Error Code
  42.  * ----------------------------------------------------------------------*/
  43. ST_ErrorCode_t KB_LayerSetup(void)
  44. {
  45.     ST_ErrorCode_t        ST_ErrorCode;
  46.     STLAYER_InitParams_t  STLAYER_InitParams;
  47.     STLAYER_LayerParams_t STLAYER_LayerParams;
  48.     STLAYER_OpenParams_t  STLAYER_OpenParams = { 0 }; /* Set dummy */
  49.     U8 Index;
  50.     STLAYER_LayerParams.AspectRatio = STGXOBJ_ASPECT_RATIO_4TO3;
  51.     STLAYER_LayerParams.ScanType    = STGXOBJ_INTERLACED_SCAN;
  52.     /* init vtg before layer! */
  53.     STLAYER_LayerParams.Width       = g_KB_VtgModeParams.ActiveAreaWidth;
  54.     STLAYER_LayerParams.Height      = g_KB_VtgModeParams.ActiveAreaHeight;
  55.     STLAYER_InitParams.LayerType                   = KB_LAYER_TYPE;
  56.     STLAYER_InitParams.DeviceBaseAddress_p         = (void *)KB_LAYER_DEVICE_BASE_ADDRESS;
  57.     STLAYER_InitParams.SharedMemoryBaseAddress_p   = (void *)SDRAM_BASE_ADDRESS;
  58.     STLAYER_InitParams.BaseAddress_p               = (void *)KB_LAYER_BASE_ADDRESS;
  59.     STLAYER_InitParams.BaseAddress2_p              = (void *)KB_LAYER_BASE_ADDRESS2;
  60.     STLAYER_InitParams.LayerParams_p               = &STLAYER_LayerParams;
  61.     STLAYER_InitParams.CPUPartition_p              = SystemPartition;
  62.     STLAYER_InitParams.CPUBigEndian                = TRUE;
  63.     STLAYER_InitParams.AVMEM_Partition             = (STAVMEM_PartitionHandle_t)g_KBAvmemPartitionHandle[0];
  64.     STLAYER_InitParams.NodeBufferUserAllocated     = FALSE;
  65.     STLAYER_InitParams.ViewPortNodeBuffer_p        = (void *)NULL;
  66.     STLAYER_InitParams.ViewPortBufferUserAllocated = FALSE;
  67.     STLAYER_InitParams.ViewPortBuffer_p            = (void *)NULL;
  68.     strcpy(STLAYER_InitParams.EventHandlerName, g_KB_EVTDeviceName[KB_EVT_VTG]);
  69.     STTBX_Print(("KB_LayerSetup NUM_LAYERS = %dn", NUM_LAYERS));
  70.     for (Index = 0; Index < NUM_LAYERS; Index++ )
  71.     {
  72.         switch (Index)
  73.         {
  74.             case LAYER_VIDEO:
  75.                 STLAYER_InitParams.MaxHandles          = KB_LAYER_MAX_HANDLES;
  76.                 STLAYER_InitParams.MaxViewPorts        = KB_LAYER_MAX_VIEWPORTS;
  77.                 break;
  78.              default:
  79.                 STLAYER_InitParams.MaxHandles          = KB_LAYER_MAX_HANDLES;
  80.                 STLAYER_InitParams.MaxViewPorts        = KB_LAYER_MAX_VIEWPORTS;
  81.                 break;
  82.         }
  83.         STTBX_Print(("KB_LayerSetup(%s)=", g_KB_LayerDeviceName[Index] ));
  84.         ST_ErrorCode = STLAYER_Init(g_KB_LayerDeviceName[Index], &STLAYER_InitParams);
  85.         if (ST_ErrorCode != ST_NO_ERROR)
  86.         {
  87.             STTBX_Print(("%sn", DBGError(ST_ErrorCode) ));
  88.             return( ST_ErrorCode );
  89.         }
  90.         STTBX_Print(("%sn", STLAYER_GetRevision() ));
  91.         STTBX_Print(("LAYER_Open="));
  92.         ST_ErrorCode = STLAYER_Open(g_KB_LayerDeviceName[Index], &STLAYER_OpenParams, &g_KB_LayerHandle[Index]);
  93.         STTBX_Print(("%sn", DBGError(ST_ErrorCode) ));
  94.         if (ST_ErrorCode != ST_NO_ERROR)
  95.             return( ST_ErrorCode );
  96.     }   /* for(Index) */
  97.     ST_ErrorCode = KB_LayerSetLayerParams();
  98.     if (ST_ErrorCode != ST_NO_ERROR)
  99.     {
  100.             STTBX_Print(("KB_LayerSetLayerParams=%sn", DBGError(ST_ErrorCode) ));
  101.             return( ST_ErrorCode );
  102.     }
  103.     return( ST_ErrorCode );
  104. }
  105. /*-------------------------------------------------------------------------
  106.  * Function : LAYER_SetScreenParams
  107.  * Input    : None
  108.  * Output   :
  109.  * Return   : Error Code
  110.  * ----------------------------------------------------------------------*/
  111. ST_ErrorCode_t KB_LayerSetLayerParams(void)
  112. {
  113.     ST_ErrorCode_t          ST_ErrorCode;
  114.     STLAYER_LayerParams_t   STLAYER_LayerParams;
  115.     U8                      Index;
  116.     ST_ErrorCode = KB_VtgGetMode();   /* get Active area */
  117.     if (ST_ErrorCode != ST_NO_ERROR)
  118.         return( ST_ErrorCode );
  119.     STTBX_Print(("KB_LayerSetLayerParams NUM_LAYERS = %dn", NUM_LAYERS));
  120.     
  121.     for (Index = 0; Index < NUM_LAYERS; Index++ )
  122.     {
  123.         STLAYER_LayerParams.AspectRatio = STGXOBJ_ASPECT_RATIO_4TO3;
  124.         STLAYER_LayerParams.ScanType    = g_KB_VtgModeParams.ScanType;
  125.         STLAYER_LayerParams.Width       = g_KB_VtgModeParams.ActiveAreaWidth;
  126.         STLAYER_LayerParams.Height      = g_KB_VtgModeParams.ActiveAreaHeight;
  127.         ST_ErrorCode = STLAYER_SetLayerParams(g_KB_LayerHandle[Index], &STLAYER_LayerParams);
  128.         if (ST_ErrorCode != ST_NO_ERROR)
  129.         {
  130.             STTBX_Print(("KB_LayerSetLayerParams=%sn", DBGError(ST_ErrorCode) ));
  131.             return( ST_ErrorCode );
  132.         }
  133.         STTBX_Print(("KB_LayerSetLayerParams(%d, %d,%d, %d,%d)n", Index,
  134.                 STLAYER_LayerParams.Width,       STLAYER_LayerParams.Height,
  135.                 STLAYER_LayerParams.AspectRatio, STLAYER_LayerParams.ScanType));
  136.     }
  137.     return( ST_ErrorCode );
  138. }
  139. INT32 KB_LayerOpenViewPort(UINT8               Layer, 
  140.                            UINT8               Vport, 
  141.                            STGXOBJ_Bitmap_t    *Bitmap_p,
  142.                            STGXOBJ_Rectangle_t *OutputRectangle_p)
  143. {
  144.     ST_ErrorCode_t ErrCode = ST_NO_ERROR;
  145.     U32 Width, Height;
  146.     Width = Bitmap_p->Width;
  147.     if ( Width > g_KB_VtgModeParams.ActiveAreaWidth )
  148.         Width = g_KB_VtgModeParams.ActiveAreaWidth;
  149.     Height = Bitmap_p->Height;
  150.     if ( Height > g_KB_VtgModeParams.ActiveAreaHeight )
  151.         Height = g_KB_VtgModeParams.ActiveAreaHeight;
  152.     LAYER_ViewPortParams[Vport].Source_p = &LAYER_ViewPortSource[Vport];
  153.     LAYER_ViewPortParams[Vport].InputRectangle.PositionX = 0;
  154.     LAYER_ViewPortParams[Vport].InputRectangle.PositionY = 0;
  155.     LAYER_ViewPortParams[Vport].InputRectangle.Width     = Width;
  156.     LAYER_ViewPortParams[Vport].InputRectangle.Height    = Height;
  157.     if ( OutputRectangle_p == NULL )
  158.             LAYER_ViewPortParams[Vport].OutputRectangle = LAYER_ViewPortParams[Vport].InputRectangle;
  159.         else
  160.             LAYER_ViewPortParams[Vport].OutputRectangle = *OutputRectangle_p;
  161.     LAYER_ViewPortSource[Vport].SourceType    = STLAYER_GRAPHIC_BITMAP;
  162.     LAYER_ViewPortSource[Vport].Data.BitMap_p = Bitmap_p;
  163.     LAYER_ViewPortSource[Vport].Palette_p     = NULL;
  164.     /* Open OSD Layer view port */
  165.     ErrCode = STLAYER_OpenViewPort(g_KB_LayerHandle[Layer],
  166.                                    &LAYER_ViewPortParams[Vport],
  167.                                    &LAYER_ViewPortHandle[Vport]);
  168.     if ( ErrCode != ST_NO_ERROR )
  169.     {
  170.         STTBX_Print(("KB_LayerOpenViewPort(%d, %d,%d,%d,%d)=%sn",
  171.                      Vport,
  172.                      LAYER_ViewPortParams[Vport].OutputRectangle.PositionX,
  173.                      LAYER_ViewPortParams[Vport].OutputRectangle.PositionY,
  174.                      LAYER_ViewPortParams[Vport].OutputRectangle.Width,
  175.                      LAYER_ViewPortParams[Vport].OutputRectangle.Height,
  176.                      DBGError(ErrCode) ));   
  177.         return RETFIAL1;
  178.     }
  179.     return KB_LayerEnableViewPort(Layer, Vport);  
  180. }
  181. /*-------------------------------------------------------------------------
  182.  * Function : KB_LayerSetOutParam
  183.               Opening a viewport
  184.  * Input    : U8 Layer, U8 Vport, STGXOBJ_Rectangle_t *OutputRectangle_p
  185.  * Output   :
  186.  * Return   : Error code
  187.  * ----------------------------------------------------------------------*/
  188. INT32 KB_LayerSetOutParam(UINT8 Layer, UINT8 Vport, 
  189.                           STGXOBJ_Rectangle_t *OutputRectangle_p)
  190. {
  191.     ST_ErrorCode_t ErrCode = ST_NO_ERROR;
  192.     if ( OutputRectangle_p == NULL )
  193.         LAYER_ViewPortParams[Vport].OutputRectangle = LAYER_ViewPortParams[Vport].InputRectangle;
  194.     else
  195.         LAYER_ViewPortParams[Vport].OutputRectangle = *OutputRectangle_p;
  196.     /* change view port parameters */
  197.     ErrCode = STLAYER_SetViewPortIORectangle(LAYER_ViewPortHandle[Vport], &LAYER_ViewPortParams[Vport].InputRectangle,
  198.                                              &LAYER_ViewPortParams[Vport].OutputRectangle);
  199.     if ( ErrCode != ST_NO_ERROR )
  200.     {
  201.         STTBX_Print(("STLAYER_SetViewPortParams(%d) failed %sn", Vport, KB_ErrorGetText(ErrCode) ));
  202.         return RETFIAL1;
  203.     }
  204.     else
  205.     {
  206.         return RETOK;
  207.     }
  208. } /* end KB_LayerSetOutParam() */
  209. INT32 KB_LayerEnableViewPort(UINT8 cLayer, UINT8 cVport)
  210. {
  211.     ST_ErrorCode_t ErrCode;
  212.     
  213.     ErrCode = STLAYER_EnableViewPortFilter(LAYER_ViewPortHandle[cVport], g_KB_LayerHandle[cLayer]);
  214.     if ( ErrCode != ST_NO_ERROR )
  215.     {
  216.         STTBX_Print(("STLAYER_EnableViewPortFilter(%d)=%sn", cVport, DBGError(ErrCode) ));
  217.         return RETFIAL1;
  218.     }
  219.     ErrCode = STLAYER_EnableViewPort(LAYER_ViewPortHandle[cVport]);
  220.     if ( ErrCode != ST_NO_ERROR )
  221.     {
  222.         STTBX_Print(("KB_LayerEnableViewPort(%d)=%sn", cVport, DBGError(ErrCode) ));
  223.         return RETFIAL1;
  224.     }
  225.     
  226.     return RETOK;
  227. }
  228. INT32 KB_LayerDisableViewPort(UINT8 cVport)
  229. {
  230.     ST_ErrorCode_t ErrCode;
  231.     
  232.     ErrCode = STLAYER_DisableViewPort(LAYER_ViewPortHandle[cVport]);
  233.     if ( ErrCode != ST_NO_ERROR )
  234.     {
  235.         STTBX_Print(("STLAYER_EnableViewPortFilter(%d)=%sn", cVport, DBGError(ErrCode) ));
  236.         return RETFIAL1;
  237.     }
  238.     
  239.     return RETOK;
  240. }
  241. INT32 KB_LayerSetViewPortAlpha(STLAYER_ViewPortHandle_t nVPHandle, INT32 nLevel)
  242. {
  243.     STLAYER_GlobalAlpha_t tAlpha;
  244.     ST_ErrorCode_t ErrCode;
  245.     INT32 nAlpha;
  246.     
  247.     #if (COLOR == KB_OSD_COLOR_ARGB_16_1555)
  248.     {
  249.         /* 对于Alpha位为1的颜色模式,只用A1起作用 */
  250.         nAlpha    = 128 * nLevel / 100 ;
  251.         tAlpha.A1 = (U8)nAlpha;
  252.     }
  253.     #else
  254.     {
  255.         nAlpha    = 128 * nLevel / 100 ;
  256.  tAlpha.A0 = (U8)nAlpha;
  257.         tAlpha.A1 = (U8)nAlpha;
  258.     }
  259.     #endif
  260.     
  261.     ErrCode = STLAYER_SetViewPortAlpha(LAYER_ViewPortHandle[nVPHandle], &tAlpha);
  262.     if ( ErrCode != ST_NO_ERROR )
  263.     {
  264.         STTBX_Print(("STLAYER_SetViewPortAlpha(%d)=%sn", LAYER_ViewPortHandle[nVPHandle], DBGError(ErrCode) ));
  265.         return RETFIAL1;
  266.     }
  267.     
  268.     return RETOK;
  269. }
  270. /* EOF --------------------------------------------------------------------- */