/****************************************************************************** *_Copyright (c) 2009 Digital Stream Technology Inc. All Rights Reserved. * * Module: dsthalaud.c * * Description * This module wraps BCL library by DHL_GFX_XXX APIs. * * Notes * BCL calls be moved to platform-dependant layer. * * @version $Revision: 1.1 $ * ******************************************************************************/ #include #include "dsthalcommon.h" #include "dsthalgfx.h" #include "dstddgfx.h" #include "dhlfont.h" /****************************************************************************** * Global variable declaration ******************************************************************************/ /****************************************************************************** * Imported variable declaration ******************************************************************************/ /****************************************************************************** * Imported function declaration ******************************************************************************/ /****************************************************************************** * Local definitions ******************************************************************************/ /****************************************************************************** * Local typedefs ******************************************************************************/ /****************************************************************************** * Local variables declaration ******************************************************************************/ static OSDMAP_t s_OSDParam[DHL_VIDEO_END]; static int g_OSDFmt, s_OsdBpp[MAX_PLANE]; static DS_U32 primBuff, scndBuff; static DS_BOOL g_GfxInit[MAX_PLANE]; static DS_BOOL g_GfxEnable[MAX_PLANE]; static int gScreenWidth, gScreenHeight; /****************************************************************************** * Local function prototypes ******************************************************************************/ void DHL_GFX_UpdateScreen(int Plane); //int DMW_gVisualSurfaceWidth = 960; //int DMW_gVisualSurfaceHeight = 540; //int DMW_gVirtualSurfaceWidth = 960; //int DMW_gVirtualSurfaceHeight = 540; #if 0 ___Common_APIs___() #endif DHL_RESULT DHL_GFX_Init(int Plane, DS_U16 osd_x, DS_U16 osd_y, DS_U16 osd_w, DS_U16 osd_h, DS_U16 osd_wo, DS_U16 osd_ho, int Fmt, DS_U32 *pBufferId ) { DS_U32 bufferId; SysCHECK( (Fmt == PF_RGB32) || (Fmt == PF_INDEX8) || (Fmt == PF_RGB16) ); SysCHECK( Plane < MAX_PLANE ); switch (Fmt) { case PF_RGB32: s_OsdBpp[Plane] = 32; break; case PF_INDEX8: s_OsdBpp[Plane] = 8; break; case PF_RGB16: s_OsdBpp[Plane] = 16; break; default: printf("ERROR: %s:%d\n", __FUNCTION__, __LINE__); return DHL_FAIL; } bufferId = DD_GFX_SetPlane( Plane, osd_x, osd_y, osd_w, osd_h, osd_wo, osd_ho, s_OsdBpp[Plane] ); if ( bufferId == 0 ) { printf("|%s:%d|\n", __FUNCTION__, __LINE__); return DHL_FAIL; } g_GfxInit[Plane] = DS_TRUE; *pBufferId = bufferId; if (Plane == PLANE_OSD ) { primBuff = bufferId; gScreenWidth = osd_wo; gScreenHeight = osd_ho; } else { scndBuff = bufferId; } DHL_GFX_EnablePlane( Plane, 1 ); return DHL_OK; } DHL_RESULT DHL_GFX_Close(void) { int i; for (i=0; iDHL_VIDEO_1080p || iVidOutFmtMenuInRect.x = 0; p->MenuInRect.y = 0; p->MenuInRect.w = InHWidth; p->MenuInRect.h = InVLength; p->MenuOutRect.x = HStart; p->MenuOutRect.y = VStart; p->MenuOutRect.w = OutHWidth; p->MenuOutRect.h = OutVLength; p->bInterlaced = bInterlaced; p->bInit = 1; } break; case PLANE_CC: { p->CCInRect.x = 0; p->CCInRect.y = 0; p->CCInRect.w = InHWidth; p->CCInRect.h = InVLength; p->CCOutRect.x = HStart; p->CCOutRect.y = VStart; p->CCOutRect.w = OutHWidth; p->CCOutRect.h = OutVLength; p->bInterlaced = bInterlaced; p->bInit = 1; } break; case PLANE_PIP: { p->PIPInRect.x = 0; p->PIPInRect.y = 0; p->PIPInRect.w = InHWidth; p->PIPInRect.h = InVLength; p->PIPOutRect.x = HStart; p->PIPOutRect.y = VStart; p->PIPOutRect.w = OutHWidth; p->PIPOutRect.h = OutVLength; p->bInterlaced = bInterlaced; p->bInit = 1; } break; default: break; } return dhlResult; } DHL_RESULT DHL_GFX_PresetDefaultOSDParam(void) { DHL_RESULT dhlResult = DHL_OK; P_OSDMAP_t p; p = &s_OSDParam[DHL_VIDEO_480p]; if ( p->bInit != 1 ) { dhlResult = DHL_GFX_PresetOSDParam( DHL_VIDEO_480p, PLANE_OSD, 142, 43, 960, 540, 665, 460, 0 ); if ( dhlResult != DHL_OK ) { printf("|%s:%d| ERROR=%d\n", __FUNCTION__, __LINE__, dhlResult); return dhlResult; } dhlResult = DHL_GFX_PresetOSDParam( DHL_VIDEO_480p, PLANE_CC, 208, 89, 768, 432, 532, 368, 0 ); if ( dhlResult != DHL_OK ) { printf("|%s:%d| ERROR=%d\n", __FUNCTION__, __LINE__, dhlResult); return dhlResult; } } p = &s_OSDParam[DHL_VIDEO_720p]; if ( p->bInit != 1 ) { dhlResult = DHL_GFX_PresetOSDParam( DHL_VIDEO_720p, PLANE_OSD, 212, 25, 960, 540, 1280, 720, 0 ); if ( dhlResult != DHL_OK ) { printf("|%s:%d| ERROR=%d\n", __FUNCTION__, __LINE__, dhlResult); return dhlResult; } dhlResult = DHL_GFX_PresetOSDParam( DHL_VIDEO_720p, PLANE_CC, 340, 97, 768, 432, 1024, 576, 0 ); if ( dhlResult != DHL_OK ) { printf("|%s:%d| ERROR=%d\n", __FUNCTION__, __LINE__, dhlResult); return dhlResult; } } p = &s_OSDParam[DHL_VIDEO_1080i]; if ( p->bInit != 1 ) { dhlResult = DHL_GFX_PresetOSDParam( DHL_VIDEO_1080i, PLANE_OSD, 193, 16, 960, 540, 1920, 1080, 1 ); if ( dhlResult != DHL_OK ) { printf("|%s:%d| ERROR=%d\n", __FUNCTION__, __LINE__, dhlResult); return dhlResult; } dhlResult = DHL_GFX_PresetOSDParam( DHL_VIDEO_1080i, PLANE_CC, 385, 124, 768, 432, 768*2, 432*2, 1 ); if ( dhlResult != DHL_OK ) { printf("|%s:%d| ERROR=%d\n", __FUNCTION__, __LINE__, dhlResult); return dhlResult; } } return DHL_OK; } DHL_RESULT DHL_GFX_ChangeOSDParam(int Plane, DS_U16 HStart, DS_U16 VStart, DS_U16 InHWidth, DS_U16 InVLength, DS_U16 OutHWidth,DS_U16 OutVLength,DS_U8 bInterlaced) { DHL_RESULT dhlResult = DHL_OK; int ret; //ret = DD_GFX_SetPlaneEx(Plane, HStart, VStart, InHWidth, InVLength, OutHWidth, OutVLength, (DS_U32)DHL_GFX_GetFBRAM(Plane), (DS_U32)_GetVRAM(Plane), DHL_GFX_GetBPP(Plane), bInterlaced); if ( ret < 0 ) return DHL_FAIL_CORE_DRIVER; return dhlResult; } DHL_RESULT DHL_GFX_ApplyOSDVidOutFmt(DHL_VIDEO_FORMAT iVidOutFmt) { DHL_RESULT dhlResult = DHL_OK; P_OSDMAP_t p; int ret; if (iVidOutFmt>DHL_VIDEO_1080p || iVidOutFmtbInit == 0 ) { DHL_DbgPrintf( 0, DHLDBG_GFX, "[ERROR] Preset value is not applied yet.\n"); return DHL_FAIL_NOT_CONNECTED; } ret = DD_GFX_SetPlane(PLANE_OSD, p->MenuOutRect.x, p->MenuOutRect.y, p->MenuInRect.w, p->MenuInRect.h, p->MenuOutRect.w, p->MenuOutRect.h, s_OsdBpp[PLANE_OSD]); if ( ret < 0 ) return DHL_FAIL_CORE_DRIVER; ret = DD_GFX_SetPlane(PLANE_CC, p->CCOutRect.x, p->CCOutRect.y, p->CCInRect.w, p->CCInRect.h, p->CCOutRect.w, p->CCOutRect.h, s_OsdBpp[PLANE_CC]); if ( ret < 0 ) return DHL_FAIL_CORE_DRIVER; #if 0 ret = DD_GFX_SetPlane(PLANE_PIP, p->PIPOutRect.x, p->PIPOutRect.y, p->PIPInRect.w, p->PIPInRect.h, p->PIPOutRect.w, p->PIPOutRect.h, s_OsdBpp[PLANE_PIP]); if ( ret < 0 ) return DHL_FAIL_CORE_DRIVER; #endif return dhlResult; } #if 0 ___2D_APIs___() #endif void DHL_GFX_DrawBox( DS_U32 pBufferId, int offsetX, int offsetY, int w, int h, DS_PIXEL_t color ) { #if 0 int x, y; DS_PIXEL_t *p_dst; p_dst = (DS_PIXEL_t *)DD_GFX_GetFrameBuffer( pBufferId ); for (y=0; y%s(0x%08lX) %d %d %d %d %d %d %d %d\n", p_src_buffer_id == primBuff ? "Prim" : p_src_buffer_id == scndBuff ? "Scnd" : "Unknown", p_src_buffer_id, p_dst_buffer_id == DHL_GFX_GetPhysicalFrameBuffer() ? "Physical" : p_dst_buffer_id == primBuff ? "Prim" : p_dst_buffer_id == scndBuff ? "Scnd" : "Unknown", p_dst_buffer_id, src_x, src_y, src_w, src_h, dst_x, dst_y, dst_w, dst_h); #endif DD_GFX_CopyBlock( p_src_buffer_id, p_dst_buffer_id, src_x, src_y, src_w, src_h, dst_x, dst_y, dst_w, dst_h, p_dst_buffer_id == DHL_GFX_GetPhysicalFrameBuffer() ); } #if 0 ___Internal_APIs___() #endif #if 0 ___FONT_Function__________() #endif #define CHAR_WIDTH 13 #define CHAR_HEIGHT 23 #define LINE_WIDTH 224 #define FONT_HEIGHT 138 static DS_PIXEL_t *BitFont = (DS_PIXEL_t *)0; void DHL_GFX_InitFont(int BgColor, int FgColor) { int i, nPixel; int Idx, Mask, iLine; //nPixel = 138 /*lines*/ * ( (208/8) + 2 /*pads*/ ) * 8; nPixel = 224 * 138; if ( BitFont == (DS_PIXEL_t *)0 ) { // // (224 pixels + 2 pads) x 138 lines // BitFont = (DS_PIXEL_t *)malloc( nPixel * sizeof(DS_PIXEL_t) ); } if ( BitFont == (DS_PIXEL_t *)0 ) { printf("ERROR: Cannot allocate memory for FONT.\n"); return; } for (i=0; i>3; Mask = 7-(i%8); if ( DHL_font[Idx] & (1< 0x80 ) { printf("|%s| ERROR, LINE=%d, CharIdx: 0x%x\n", __FUNCTION__, __LINE__, CharIdx); return; } FontStart = (CharIdx%16) * CHAR_WIDTH + (CharIdx >>4) * LINE_WIDTH * CHAR_HEIGHT; for(h=0; h 147 ) /* Too many characters */ break; DHL_GFX_PutChar(bufferId, x+i*CHAR_WIDTH, y, str[i]); i++; } } #if 0 ___Test_APIs___() #endif void test_gfx(int mode) { static DS_U32 osdBuf=0; static DS_U32 ccBuf=0; static DS_U32 test_plane=0; int updatePlane = -1; if (DHL_GFX_IsInit(PLANE_OSD) == DS_FALSE) { SysCHECK( DHL_GFX_Init( PLANE_OSD, 0, 0, 1366, 768, 1366, 768, PF_RGB16, &osdBuf ) == DHL_OK ); } if (DHL_GFX_IsInit(PLANE_CC) == DS_FALSE) { SysCHECK( DHL_GFX_Init( PLANE_CC, 0, 0, 1366, 768, 1366, 768, PF_RGB16, &ccBuf ) == DHL_OK ); } if ( !test_plane ) SysCHECK( DHL_GFX_AllocFrameBuffer( &test_plane, 1366, 768, PF_RGB16 ) == DHL_OK ); if (!osdBuf || !ccBuf) { osdBuf = primBuff; ccBuf = scndBuff; } if ( DHL_GFX_IsInit(PLANE_OSD) == DS_FALSE ) { printf("[ERROR] Graphic is not initialized yet.\n"); return; } //DHL_GFX_EnablePlane(0,0); //DHL_GFX_EnablePlane(1,0); //mode = 2; switch( mode ) { #if 1//(DHL_GFX_FMT32 == DHL_GFX_FORMAT) case 10: DHL_GFX_DrawBox( osdBuf, 0, 0, 668, 456, 0xFF00); case 12: DHL_GFX_DrawBox( osdBuf, 1, 1, 668-2, 456-2, 0xF0F0); case 13: DHL_GFX_DrawBox( osdBuf, 2, 2, 668-4, 456-4, 0xFFF0); case 14: DHL_GFX_DrawBox( osdBuf, (668-1)/2, 0, 2, 456, 0xF0FF); case 15: DHL_GFX_DrawBox( osdBuf, 0, (456-1)/2, 668, 2, 0xF0FF); updatePlane = 0; break; #endif case 16: DHL_GFX_DrawBox( test_plane, 0, 0, 1366, 768, 0); DHL_GFX_CopyBlock( test_plane, osdBuf, 0, 0, 1366, 768, 0, 0, 1366, 768); updatePlane = 1; break; case 3: //DHL_GFX_InitFont(); DHL_GFX_PutString( ccBuf, 100, 60, "This is string message 1.\0" ); DHL_GFX_PutString( ccBuf, 100, 60+20, "This is string message 2. Digital Stream Technology.\0" ); DHL_GFX_PutString( ccBuf, 100, 60+40, "This is string message 3.\0" ); DHL_GFX_PutString( ccBuf, 100, 60+60, "This is string message 4.\0" ); updatePlane = 1; break; case 4: printf("Print test string into test image which copied to OSD plane.\n"); DHL_GFX_PutString( test_plane, 100, 60, "This is string message 1.\0" ); DHL_GFX_PutString( test_plane, 100, 60+20, "This is string message 2. Digital Stream Technology.\0" ); DHL_GFX_PutString( test_plane, 100, 60+40, "This is string message 3.\0" ); DHL_GFX_PutString( test_plane, 100, 60+60, "This is string message 4.\0" ); DHL_GFX_CopyBlock( test_plane, osdBuf, 0, 0, 1366, 768, 0, 0, 1366, 768); updatePlane = 1; break; } if ( updatePlane != -1 ) DHL_GFX_UpdateScreen(updatePlane); }