| 1 | /****************************************************************************** |
|---|
| 2 | *_Copyright (c) 2009 Digital Stream Technology Inc. All Rights Reserved. |
|---|
| 3 | * |
|---|
| 4 | * Module: dsthalaud.c |
|---|
| 5 | * |
|---|
| 6 | * Description |
|---|
| 7 | * This module wraps BCL library by DHL_GFX_XXX APIs. |
|---|
| 8 | * |
|---|
| 9 | * Notes |
|---|
| 10 | * BCL calls be moved to platform-dependant layer. |
|---|
| 11 | * |
|---|
| 12 | * @version $Revision: 1.1 $ |
|---|
| 13 | * |
|---|
| 14 | ******************************************************************************/ |
|---|
| 15 | |
|---|
| 16 | #include <stdlib.h> |
|---|
| 17 | |
|---|
| 18 | #include "dsthalcommon.h" |
|---|
| 19 | #include "dsthalgfx.h" |
|---|
| 20 | #include "dstddgfx.h" |
|---|
| 21 | #include "dhlfont.h" |
|---|
| 22 | |
|---|
| 23 | /****************************************************************************** |
|---|
| 24 | * Global variable declaration |
|---|
| 25 | ******************************************************************************/ |
|---|
| 26 | |
|---|
| 27 | /****************************************************************************** |
|---|
| 28 | * Imported variable declaration |
|---|
| 29 | ******************************************************************************/ |
|---|
| 30 | |
|---|
| 31 | /****************************************************************************** |
|---|
| 32 | * Imported function declaration |
|---|
| 33 | ******************************************************************************/ |
|---|
| 34 | |
|---|
| 35 | /****************************************************************************** |
|---|
| 36 | * Local definitions |
|---|
| 37 | ******************************************************************************/ |
|---|
| 38 | |
|---|
| 39 | /****************************************************************************** |
|---|
| 40 | * Local typedefs |
|---|
| 41 | ******************************************************************************/ |
|---|
| 42 | |
|---|
| 43 | /****************************************************************************** |
|---|
| 44 | * Local variables declaration |
|---|
| 45 | ******************************************************************************/ |
|---|
| 46 | static OSDMAP_t s_OSDParam[DHL_VIDEO_END]; |
|---|
| 47 | static int g_OSDFmt, s_OsdBpp[MAX_PLANE]; |
|---|
| 48 | static DS_U32 primBuff, scndBuff; |
|---|
| 49 | static DS_BOOL g_GfxInit[MAX_PLANE]; |
|---|
| 50 | static DS_BOOL g_GfxEnable[MAX_PLANE]; |
|---|
| 51 | static int gScreenWidth, gScreenHeight; |
|---|
| 52 | |
|---|
| 53 | /****************************************************************************** |
|---|
| 54 | * Local function prototypes |
|---|
| 55 | ******************************************************************************/ |
|---|
| 56 | void DHL_GFX_UpdateScreen(int Plane); |
|---|
| 57 | |
|---|
| 58 | //int DMW_gVisualSurfaceWidth = 960; |
|---|
| 59 | //int DMW_gVisualSurfaceHeight = 540; |
|---|
| 60 | //int DMW_gVirtualSurfaceWidth = 960; |
|---|
| 61 | //int DMW_gVirtualSurfaceHeight = 540; |
|---|
| 62 | |
|---|
| 63 | #if 0 |
|---|
| 64 | ___Common_APIs___() |
|---|
| 65 | #endif |
|---|
| 66 | DHL_RESULT DHL_GFX_Init(int Plane, DS_U16 osd_x, DS_U16 osd_y, DS_U16 osd_w, DS_U16 osd_h, |
|---|
| 67 | DS_U16 osd_wo, DS_U16 osd_ho, int Fmt, DS_U32 *pBufferId ) |
|---|
| 68 | { |
|---|
| 69 | DS_U32 bufferId; |
|---|
| 70 | |
|---|
| 71 | SysCHECK( (Fmt == PF_RGB32) || (Fmt == PF_INDEX8) || (Fmt == PF_RGB16) ); |
|---|
| 72 | SysCHECK( Plane < MAX_PLANE ); |
|---|
| 73 | |
|---|
| 74 | switch (Fmt) |
|---|
| 75 | { |
|---|
| 76 | case PF_RGB32: |
|---|
| 77 | s_OsdBpp[Plane] = 32; |
|---|
| 78 | break; |
|---|
| 79 | |
|---|
| 80 | case PF_INDEX8: |
|---|
| 81 | s_OsdBpp[Plane] = 8; |
|---|
| 82 | break; |
|---|
| 83 | |
|---|
| 84 | case PF_RGB16: |
|---|
| 85 | s_OsdBpp[Plane] = 16; |
|---|
| 86 | break; |
|---|
| 87 | |
|---|
| 88 | default: |
|---|
| 89 | printf("ERROR: %s:%d\n", __FUNCTION__, __LINE__); |
|---|
| 90 | return DHL_FAIL; |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 93 | bufferId = DD_GFX_SetPlane( Plane, osd_x, osd_y, osd_w, osd_h, osd_wo, osd_ho, s_OsdBpp[Plane] ); |
|---|
| 94 | if ( bufferId == 0 ) |
|---|
| 95 | { |
|---|
| 96 | printf("|%s:%d|\n", __FUNCTION__, __LINE__); |
|---|
| 97 | return DHL_FAIL; |
|---|
| 98 | } |
|---|
| 99 | |
|---|
| 100 | g_GfxInit[Plane] = DS_TRUE; |
|---|
| 101 | *pBufferId = bufferId; |
|---|
| 102 | |
|---|
| 103 | if (Plane == PLANE_OSD ) |
|---|
| 104 | { |
|---|
| 105 | primBuff = bufferId; |
|---|
| 106 | gScreenWidth = osd_wo; |
|---|
| 107 | gScreenHeight = osd_ho; |
|---|
| 108 | } |
|---|
| 109 | else |
|---|
| 110 | { |
|---|
| 111 | scndBuff = bufferId; |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | DHL_GFX_EnablePlane( Plane, 1 ); |
|---|
| 115 | |
|---|
| 116 | return DHL_OK; |
|---|
| 117 | } |
|---|
| 118 | |
|---|
| 119 | DHL_RESULT DHL_GFX_Close(void) |
|---|
| 120 | { |
|---|
| 121 | int i; |
|---|
| 122 | |
|---|
| 123 | for (i=0; i<MAX_PLANE; i++) |
|---|
| 124 | g_GfxInit[i] = DS_FALSE; |
|---|
| 125 | |
|---|
| 126 | return DHL_OK; |
|---|
| 127 | } |
|---|
| 128 | |
|---|
| 129 | int DHL_GFX_SetPallete(int Plane, int StartIdx, int Length, DS_PIXEL_t *pal) |
|---|
| 130 | { |
|---|
| 131 | |
|---|
| 132 | return 0; |
|---|
| 133 | } |
|---|
| 134 | |
|---|
| 135 | DHL_RESULT DHL_GFX_AllocFrameBuffer( DS_U32 *pBufferId, DS_U16 width, DS_U16 height, int fmt ) |
|---|
| 136 | { |
|---|
| 137 | DS_U32 bufferId; |
|---|
| 138 | int bpp; |
|---|
| 139 | |
|---|
| 140 | switch (fmt) |
|---|
| 141 | { |
|---|
| 142 | case PF_RGB32: bpp = 32; break; |
|---|
| 143 | case PF_INDEX8: bpp = 8; break; |
|---|
| 144 | case PF_RGB16: bpp = 16; break; |
|---|
| 145 | |
|---|
| 146 | case 32: |
|---|
| 147 | case 16: |
|---|
| 148 | case 8: |
|---|
| 149 | bpp = fmt; |
|---|
| 150 | break; |
|---|
| 151 | |
|---|
| 152 | default: |
|---|
| 153 | printf("ERROR: %s:%d\n", __FUNCTION__, __LINE__); |
|---|
| 154 | return DHL_FAIL; |
|---|
| 155 | } |
|---|
| 156 | bpp = DHL_GFX_FORMAT; |
|---|
| 157 | |
|---|
| 158 | bufferId = DD_GFX_AllocFrameBuffer( width, height, bpp ); |
|---|
| 159 | if ( bufferId ) |
|---|
| 160 | { |
|---|
| 161 | *pBufferId = bufferId; |
|---|
| 162 | return DHL_OK; |
|---|
| 163 | } |
|---|
| 164 | |
|---|
| 165 | SysASSERT( bufferId ); |
|---|
| 166 | |
|---|
| 167 | return DHL_FAIL; |
|---|
| 168 | } |
|---|
| 169 | |
|---|
| 170 | DHL_RESULT DHL_GFX_FreeFrameBuffer( DS_U32 pBufferId ) |
|---|
| 171 | { |
|---|
| 172 | if ( pBufferId ) |
|---|
| 173 | { |
|---|
| 174 | DD_GFX_FreeFrameBuffer( pBufferId ); |
|---|
| 175 | } |
|---|
| 176 | |
|---|
| 177 | return DHL_OK; |
|---|
| 178 | } |
|---|
| 179 | |
|---|
| 180 | DS_U32 DHL_GFX_GetBaseAddr(DS_U32 bufferId) |
|---|
| 181 | { |
|---|
| 182 | SysENSURE( bufferId ); |
|---|
| 183 | |
|---|
| 184 | return DD_GFX_GetFrameBuffer(bufferId); |
|---|
| 185 | } |
|---|
| 186 | |
|---|
| 187 | DS_U32 DHL_GFX_GetPhysicalFrameBuffer(void) |
|---|
| 188 | { |
|---|
| 189 | return DD_GFX_GetPhysicalFrameBuffer(); |
|---|
| 190 | } |
|---|
| 191 | |
|---|
| 192 | int DHL_GFX_EnablePlane(int Plane, int OnOff) |
|---|
| 193 | { |
|---|
| 194 | SysENSURE( Plane < MAX_PLANE ); |
|---|
| 195 | |
|---|
| 196 | if ( g_GfxEnable[Plane] != OnOff ) |
|---|
| 197 | { |
|---|
| 198 | g_GfxEnable[Plane] = OnOff; |
|---|
| 199 | DD_GFX_EnablePlane(Plane, OnOff); |
|---|
| 200 | DHL_GFX_UpdateScreen(Plane); |
|---|
| 201 | } |
|---|
| 202 | |
|---|
| 203 | return 0; |
|---|
| 204 | } |
|---|
| 205 | |
|---|
| 206 | DS_BOOL DHL_GFX_IsEnabled( int Plane ) |
|---|
| 207 | { |
|---|
| 208 | SysENSURE( Plane < MAX_PLANE ); |
|---|
| 209 | |
|---|
| 210 | return g_GfxEnable[Plane]; |
|---|
| 211 | } |
|---|
| 212 | |
|---|
| 213 | DS_BOOL DHL_GFX_IsInit(int Plane) |
|---|
| 214 | { |
|---|
| 215 | SysENSURE( Plane < MAX_PLANE ); |
|---|
| 216 | |
|---|
| 217 | return g_GfxInit[Plane]; |
|---|
| 218 | } |
|---|
| 219 | |
|---|
| 220 | void DHL_GFX_UpdateScreen(int Plane) |
|---|
| 221 | { |
|---|
| 222 | #if 0 |
|---|
| 223 | //DHL_GFX_DrawBox( DHL_GFX_GetPhysicalFrameBuffer(), 0, 0, gScreenWidth, gScreenHeight, 0x00 ); |
|---|
| 224 | DD_GFX_CopyBlock( DD_GFX_GetVideoFrameBuffer(), DHL_GFX_GetPhysicalFrameBuffer(), 0, 0, gScreenWidth, gScreenHeight, 0, 0, gScreenWidth, gScreenHeight, 0 ); |
|---|
| 225 | if ( DHL_GFX_IsEnabled(PLANE_CC) ) |
|---|
| 226 | { |
|---|
| 227 | DD_GFX_CopyBlock( scndBuff, DHL_GFX_GetPhysicalFrameBuffer(), 0, 0, gScreenWidth, gScreenHeight, 0, 0, gScreenWidth, gScreenHeight, 0 ); |
|---|
| 228 | } |
|---|
| 229 | |
|---|
| 230 | if ( DHL_GFX_IsEnabled(PLANE_OSD) ) |
|---|
| 231 | { |
|---|
| 232 | DD_GFX_CopyBlock( primBuff, DHL_GFX_GetPhysicalFrameBuffer(), 0, 0, gScreenWidth, gScreenHeight, 0, 0, gScreenWidth, gScreenHeight, 0 ); |
|---|
| 233 | } |
|---|
| 234 | DD_GFX_UpdateScreen(); |
|---|
| 235 | #else |
|---|
| 236 | DD_GFX_UpdateScreen(); |
|---|
| 237 | #endif |
|---|
| 238 | return; |
|---|
| 239 | } |
|---|
| 240 | |
|---|
| 241 | #if 0 |
|---|
| 242 | ___OSD_Param_APIs___() |
|---|
| 243 | #endif |
|---|
| 244 | DHL_RESULT DHL_GFX_PresetOSDParam(DHL_VIDEO_FORMAT iVidOutFmt, int Plane, DS_U16 HStart, DS_U16 VStart, DS_U16 InHWidth, DS_U16 InVLength, DS_U16 OutHWidth,DS_U16 OutVLength,DS_U8 bInterlaced) |
|---|
| 245 | { |
|---|
| 246 | DHL_RESULT dhlResult = DHL_OK; |
|---|
| 247 | P_OSDMAP_t p; |
|---|
| 248 | |
|---|
| 249 | if (iVidOutFmt>DHL_VIDEO_1080p || iVidOutFmt<DHL_VIDEO_480i) { |
|---|
| 250 | DHL_DbgPrintf( 0, DHLDBG_GFX, "[ERROR] INVALID PARAM. iVidOutFmt=%d\n",__LINE__, iVidOutFmt); |
|---|
| 251 | return DHL_FAIL_INVALID_PARAM; |
|---|
| 252 | } |
|---|
| 253 | |
|---|
| 254 | p = &s_OSDParam[iVidOutFmt]; |
|---|
| 255 | switch (Plane) { |
|---|
| 256 | case PLANE_OSD: |
|---|
| 257 | { |
|---|
| 258 | p->MenuInRect.x = 0; |
|---|
| 259 | p->MenuInRect.y = 0; |
|---|
| 260 | p->MenuInRect.w = InHWidth; |
|---|
| 261 | p->MenuInRect.h = InVLength; |
|---|
| 262 | p->MenuOutRect.x = HStart; |
|---|
| 263 | p->MenuOutRect.y = VStart; |
|---|
| 264 | p->MenuOutRect.w = OutHWidth; |
|---|
| 265 | p->MenuOutRect.h = OutVLength; |
|---|
| 266 | |
|---|
| 267 | p->bInterlaced = bInterlaced; |
|---|
| 268 | p->bInit = 1; |
|---|
| 269 | } |
|---|
| 270 | break; |
|---|
| 271 | |
|---|
| 272 | case PLANE_CC: |
|---|
| 273 | { |
|---|
| 274 | p->CCInRect.x = 0; |
|---|
| 275 | p->CCInRect.y = 0; |
|---|
| 276 | p->CCInRect.w = InHWidth; |
|---|
| 277 | p->CCInRect.h = InVLength; |
|---|
| 278 | p->CCOutRect.x = HStart; |
|---|
| 279 | p->CCOutRect.y = VStart; |
|---|
| 280 | p->CCOutRect.w = OutHWidth; |
|---|
| 281 | p->CCOutRect.h = OutVLength; |
|---|
| 282 | |
|---|
| 283 | p->bInterlaced = bInterlaced; |
|---|
| 284 | p->bInit = 1; |
|---|
| 285 | } |
|---|
| 286 | break; |
|---|
| 287 | |
|---|
| 288 | case PLANE_PIP: |
|---|
| 289 | { |
|---|
| 290 | p->PIPInRect.x = 0; |
|---|
| 291 | p->PIPInRect.y = 0; |
|---|
| 292 | p->PIPInRect.w = InHWidth; |
|---|
| 293 | p->PIPInRect.h = InVLength; |
|---|
| 294 | p->PIPOutRect.x = HStart; |
|---|
| 295 | p->PIPOutRect.y = VStart; |
|---|
| 296 | p->PIPOutRect.w = OutHWidth; |
|---|
| 297 | p->PIPOutRect.h = OutVLength; |
|---|
| 298 | |
|---|
| 299 | p->bInterlaced = bInterlaced; |
|---|
| 300 | p->bInit = 1; |
|---|
| 301 | } |
|---|
| 302 | break; |
|---|
| 303 | |
|---|
| 304 | default: |
|---|
| 305 | break; |
|---|
| 306 | } |
|---|
| 307 | |
|---|
| 308 | return dhlResult; |
|---|
| 309 | } |
|---|
| 310 | |
|---|
| 311 | DHL_RESULT DHL_GFX_PresetDefaultOSDParam(void) |
|---|
| 312 | { |
|---|
| 313 | DHL_RESULT dhlResult = DHL_OK; |
|---|
| 314 | P_OSDMAP_t p; |
|---|
| 315 | |
|---|
| 316 | p = &s_OSDParam[DHL_VIDEO_480p]; |
|---|
| 317 | if ( p->bInit != 1 ) { |
|---|
| 318 | dhlResult = DHL_GFX_PresetOSDParam( DHL_VIDEO_480p, PLANE_OSD, 142, 43, 960, 540, 665, 460, 0 ); |
|---|
| 319 | if ( dhlResult != DHL_OK ) { |
|---|
| 320 | printf("|%s:%d| ERROR=%d\n", __FUNCTION__, __LINE__, dhlResult); |
|---|
| 321 | return dhlResult; |
|---|
| 322 | } |
|---|
| 323 | |
|---|
| 324 | dhlResult = DHL_GFX_PresetOSDParam( DHL_VIDEO_480p, PLANE_CC, 208, 89, 768, 432, 532, 368, 0 ); |
|---|
| 325 | if ( dhlResult != DHL_OK ) { |
|---|
| 326 | printf("|%s:%d| ERROR=%d\n", __FUNCTION__, __LINE__, dhlResult); |
|---|
| 327 | return dhlResult; |
|---|
| 328 | } |
|---|
| 329 | } |
|---|
| 330 | |
|---|
| 331 | p = &s_OSDParam[DHL_VIDEO_720p]; |
|---|
| 332 | if ( p->bInit != 1 ) { |
|---|
| 333 | dhlResult = DHL_GFX_PresetOSDParam( DHL_VIDEO_720p, PLANE_OSD, 212, 25, 960, 540, 1280, 720, 0 ); |
|---|
| 334 | if ( dhlResult != DHL_OK ) { |
|---|
| 335 | printf("|%s:%d| ERROR=%d\n", __FUNCTION__, __LINE__, dhlResult); |
|---|
| 336 | return dhlResult; |
|---|
| 337 | } |
|---|
| 338 | |
|---|
| 339 | dhlResult = DHL_GFX_PresetOSDParam( DHL_VIDEO_720p, PLANE_CC, 340, 97, 768, 432, 1024, 576, 0 ); |
|---|
| 340 | if ( dhlResult != DHL_OK ) { |
|---|
| 341 | printf("|%s:%d| ERROR=%d\n", __FUNCTION__, __LINE__, dhlResult); |
|---|
| 342 | return dhlResult; |
|---|
| 343 | } |
|---|
| 344 | } |
|---|
| 345 | |
|---|
| 346 | p = &s_OSDParam[DHL_VIDEO_1080i]; |
|---|
| 347 | if ( p->bInit != 1 ) { |
|---|
| 348 | dhlResult = DHL_GFX_PresetOSDParam( DHL_VIDEO_1080i, PLANE_OSD, 193, 16, 960, 540, 1920, 1080, 1 ); |
|---|
| 349 | if ( dhlResult != DHL_OK ) { |
|---|
| 350 | printf("|%s:%d| ERROR=%d\n", __FUNCTION__, __LINE__, dhlResult); |
|---|
| 351 | return dhlResult; |
|---|
| 352 | } |
|---|
| 353 | |
|---|
| 354 | dhlResult = DHL_GFX_PresetOSDParam( DHL_VIDEO_1080i, PLANE_CC, 385, 124, 768, 432, 768*2, 432*2, 1 ); |
|---|
| 355 | if ( dhlResult != DHL_OK ) { |
|---|
| 356 | printf("|%s:%d| ERROR=%d\n", __FUNCTION__, __LINE__, dhlResult); |
|---|
| 357 | return dhlResult; |
|---|
| 358 | } |
|---|
| 359 | } |
|---|
| 360 | |
|---|
| 361 | return DHL_OK; |
|---|
| 362 | } |
|---|
| 363 | |
|---|
| 364 | 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) |
|---|
| 365 | { |
|---|
| 366 | DHL_RESULT dhlResult = DHL_OK; |
|---|
| 367 | int ret; |
|---|
| 368 | |
|---|
| 369 | //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); |
|---|
| 370 | if ( ret < 0 ) |
|---|
| 371 | return DHL_FAIL_CORE_DRIVER; |
|---|
| 372 | |
|---|
| 373 | return dhlResult; |
|---|
| 374 | } |
|---|
| 375 | |
|---|
| 376 | DHL_RESULT DHL_GFX_ApplyOSDVidOutFmt(DHL_VIDEO_FORMAT iVidOutFmt) |
|---|
| 377 | { |
|---|
| 378 | DHL_RESULT dhlResult = DHL_OK; |
|---|
| 379 | P_OSDMAP_t p; |
|---|
| 380 | int ret; |
|---|
| 381 | |
|---|
| 382 | if (iVidOutFmt>DHL_VIDEO_1080p || iVidOutFmt<DHL_VIDEO_480i) { |
|---|
| 383 | DHL_DbgPrintf( 0, DHLDBG_GFX, "[ERROR] INVALID PARAM. iVidOutFmt=%d\n", iVidOutFmt); |
|---|
| 384 | return DHL_FAIL_INVALID_PARAM; |
|---|
| 385 | } |
|---|
| 386 | |
|---|
| 387 | if ( !DHL_GFX_IsInit(0) || !DHL_GFX_IsInit(PLANE_CC) ) { |
|---|
| 388 | DHL_DbgPrintf( 0, DHLDBG_GFX, "[ERROR] Graphic Library is not initialized.\n"); |
|---|
| 389 | return DHL_FAIL_NOT_CONNECTED; |
|---|
| 390 | } |
|---|
| 391 | |
|---|
| 392 | p = &s_OSDParam[iVidOutFmt]; |
|---|
| 393 | g_OSDFmt = iVidOutFmt; |
|---|
| 394 | |
|---|
| 395 | if ( p->bInit == 0 ) { |
|---|
| 396 | DHL_DbgPrintf( 0, DHLDBG_GFX, "[ERROR] Preset value is not applied yet.\n"); |
|---|
| 397 | return DHL_FAIL_NOT_CONNECTED; |
|---|
| 398 | } |
|---|
| 399 | |
|---|
| 400 | 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]); |
|---|
| 401 | if ( ret < 0 ) |
|---|
| 402 | return DHL_FAIL_CORE_DRIVER; |
|---|
| 403 | |
|---|
| 404 | 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]); |
|---|
| 405 | if ( ret < 0 ) |
|---|
| 406 | return DHL_FAIL_CORE_DRIVER; |
|---|
| 407 | |
|---|
| 408 | #if 0 |
|---|
| 409 | 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]); |
|---|
| 410 | if ( ret < 0 ) |
|---|
| 411 | return DHL_FAIL_CORE_DRIVER; |
|---|
| 412 | #endif |
|---|
| 413 | |
|---|
| 414 | return dhlResult; |
|---|
| 415 | } |
|---|
| 416 | |
|---|
| 417 | #if 0 |
|---|
| 418 | ___2D_APIs___() |
|---|
| 419 | #endif |
|---|
| 420 | void DHL_GFX_DrawBox( DS_U32 pBufferId, int offsetX, int offsetY, int w, int h, DS_PIXEL_t color ) |
|---|
| 421 | { |
|---|
| 422 | #if 0 |
|---|
| 423 | int x, y; |
|---|
| 424 | DS_PIXEL_t *p_dst; |
|---|
| 425 | |
|---|
| 426 | p_dst = (DS_PIXEL_t *)DD_GFX_GetFrameBuffer( pBufferId ); |
|---|
| 427 | for (y=0; y<h; y++) |
|---|
| 428 | { |
|---|
| 429 | for (x=0; x<w; x++) |
|---|
| 430 | { |
|---|
| 431 | p_dst[(x+offsetX)+(y+offsetY)*gScreenWidth] = color; |
|---|
| 432 | } |
|---|
| 433 | } |
|---|
| 434 | #else |
|---|
| 435 | DD_GFX_DrawBox( pBufferId, offsetX, offsetY, w, h, color); |
|---|
| 436 | #endif |
|---|
| 437 | if ( pBufferId == DHL_GFX_GetPhysicalFrameBuffer() ) |
|---|
| 438 | DD_GFX_UpdateScreen(); |
|---|
| 439 | } |
|---|
| 440 | |
|---|
| 441 | void DHL_GFX_DrawPixel( DS_U32 pBufferId, int offsetX, int offsetY, DS_PIXEL_t Pixel ) |
|---|
| 442 | { |
|---|
| 443 | DHL_GFX_DrawImage(pBufferId, offsetX, offsetY, 1, 1, &Pixel); |
|---|
| 444 | } |
|---|
| 445 | |
|---|
| 446 | void DHL_GFX_DrawPixels( DS_U32 pBufferId, int offsetX, int offsetY, int w, DS_PIXEL_t *pPixels ) |
|---|
| 447 | { |
|---|
| 448 | DHL_GFX_DrawImage(pBufferId, offsetX, offsetY, w, 1, pPixels); |
|---|
| 449 | } |
|---|
| 450 | |
|---|
| 451 | void DHL_GFX_ReadPixels( DS_U32 pBufferId, int offsetX, int offsetY, int w, int h, DS_PIXEL_t *pPixels ) |
|---|
| 452 | { |
|---|
| 453 | DD_GFX_ReadPixels(pBufferId, offsetX, offsetY, w, h, pPixels); |
|---|
| 454 | } |
|---|
| 455 | |
|---|
| 456 | void DHL_GFX_DrawImage( DS_U32 pBufferId, int offsetX, int offsetY, int w, int h, DS_PIXEL_t *pPixels) |
|---|
| 457 | { |
|---|
| 458 | DD_GFX_DrawImage( pBufferId, offsetX, offsetY, w, h, pPixels ); |
|---|
| 459 | } |
|---|
| 460 | |
|---|
| 461 | void DHL_GFX_CopyBlock(DS_U32 p_src_buffer_id, DS_U32 p_dst_buffer_id, |
|---|
| 462 | int src_x, int src_y, int src_w, int src_h, |
|---|
| 463 | int dst_x, int dst_y, int dst_w, int dst_h) |
|---|
| 464 | { |
|---|
| 465 | #if 0 |
|---|
| 466 | printf("%s(0x%08lX)->%s(0x%08lX) %d %d %d %d %d %d %d %d\n", |
|---|
| 467 | p_src_buffer_id == primBuff ? "Prim" : p_src_buffer_id == scndBuff ? "Scnd" : "Unknown", p_src_buffer_id, |
|---|
| 468 | 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, |
|---|
| 469 | src_x, src_y, src_w, src_h, |
|---|
| 470 | dst_x, dst_y, dst_w, dst_h); |
|---|
| 471 | #endif |
|---|
| 472 | 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() ); |
|---|
| 473 | } |
|---|
| 474 | |
|---|
| 475 | #if 0 |
|---|
| 476 | ___Internal_APIs___() |
|---|
| 477 | #endif |
|---|
| 478 | |
|---|
| 479 | #if 0 |
|---|
| 480 | ___FONT_Function__________() |
|---|
| 481 | #endif |
|---|
| 482 | #define CHAR_WIDTH 13 |
|---|
| 483 | #define CHAR_HEIGHT 23 |
|---|
| 484 | #define LINE_WIDTH 224 |
|---|
| 485 | #define FONT_HEIGHT 138 |
|---|
| 486 | |
|---|
| 487 | static DS_PIXEL_t *BitFont = (DS_PIXEL_t *)0; |
|---|
| 488 | void DHL_GFX_InitFont(int BgColor, int FgColor) |
|---|
| 489 | { |
|---|
| 490 | int i, nPixel; |
|---|
| 491 | int Idx, Mask, iLine; |
|---|
| 492 | |
|---|
| 493 | //nPixel = 138 /*lines*/ * ( (208/8) + 2 /*pads*/ ) * 8; |
|---|
| 494 | nPixel = 224 * 138; |
|---|
| 495 | |
|---|
| 496 | if ( BitFont == (DS_PIXEL_t *)0 ) { |
|---|
| 497 | // |
|---|
| 498 | // (224 pixels + 2 pads) x 138 lines |
|---|
| 499 | // |
|---|
| 500 | BitFont = (DS_PIXEL_t *)malloc( nPixel * sizeof(DS_PIXEL_t) ); |
|---|
| 501 | } |
|---|
| 502 | |
|---|
| 503 | if ( BitFont == (DS_PIXEL_t *)0 ) { |
|---|
| 504 | printf("ERROR: Cannot allocate memory for FONT.\n"); |
|---|
| 505 | return; |
|---|
| 506 | } |
|---|
| 507 | |
|---|
| 508 | for (i=0; i<nPixel; i++) { |
|---|
| 509 | iLine = 137-i/LINE_WIDTH; |
|---|
| 510 | Idx = i>>3; |
|---|
| 511 | Mask = 7-(i%8); |
|---|
| 512 | if ( DHL_font[Idx] & (1<<Mask) ) |
|---|
| 513 | BitFont[iLine*LINE_WIDTH+(i%LINE_WIDTH)] = FgColor; |
|---|
| 514 | else |
|---|
| 515 | BitFont[iLine*LINE_WIDTH+(i%LINE_WIDTH)] = BgColor; |
|---|
| 516 | } |
|---|
| 517 | } |
|---|
| 518 | |
|---|
| 519 | void DHL_GFX_PutChar(DS_U32 bufferId, int x, int y, char c) |
|---|
| 520 | { |
|---|
| 521 | int w, h; |
|---|
| 522 | int CharIdx; |
|---|
| 523 | int FontStart; |
|---|
| 524 | |
|---|
| 525 | CharIdx = c - ' '; |
|---|
| 526 | |
|---|
| 527 | if ( BitFont == (DS_PIXEL_t *)0 ) |
|---|
| 528 | #if (DHL_GFX_FMT32 == DHL_GFX_FORMAT) |
|---|
| 529 | DHL_GFX_InitFont(0x00000000, 0xFFFFFFFF); |
|---|
| 530 | #elif (DHL_GFX_FMT16 == DHL_GFX_FORMAT) |
|---|
| 531 | DHL_GFX_InitFont(0x00000000, 0xFFFF); |
|---|
| 532 | #else |
|---|
| 533 | #error Shall define DHL_GFX_FORMAT. |
|---|
| 534 | #endif |
|---|
| 535 | |
|---|
| 536 | if ( CharIdx < 0 || CharIdx > 0x80 ) { |
|---|
| 537 | printf("|%s| ERROR, LINE=%d, CharIdx: 0x%x\n", __FUNCTION__, __LINE__, CharIdx); |
|---|
| 538 | return; |
|---|
| 539 | } |
|---|
| 540 | |
|---|
| 541 | FontStart = (CharIdx%16) * CHAR_WIDTH + (CharIdx >>4) * LINE_WIDTH * CHAR_HEIGHT; |
|---|
| 542 | for(h=0; h<CHAR_HEIGHT; h++) |
|---|
| 543 | { |
|---|
| 544 | for(w=0; w<CHAR_WIDTH; w++) { |
|---|
| 545 | DHL_GFX_DrawPixels( bufferId, x+w, y+h, 1, &BitFont[FontStart + w + h*LINE_WIDTH] ); |
|---|
| 546 | } |
|---|
| 547 | } |
|---|
| 548 | } |
|---|
| 549 | |
|---|
| 550 | void DHL_GFX_PutString(DS_U32 bufferId, int x, int y, const char *str) |
|---|
| 551 | { |
|---|
| 552 | int i; |
|---|
| 553 | |
|---|
| 554 | i=0; |
|---|
| 555 | while(str[i] != '\0') { |
|---|
| 556 | if ( i > 147 ) /* Too many characters */ |
|---|
| 557 | break; |
|---|
| 558 | DHL_GFX_PutChar(bufferId, x+i*CHAR_WIDTH, y, str[i]); |
|---|
| 559 | i++; |
|---|
| 560 | } |
|---|
| 561 | } |
|---|
| 562 | |
|---|
| 563 | |
|---|
| 564 | #if 0 |
|---|
| 565 | ___Test_APIs___() |
|---|
| 566 | #endif |
|---|
| 567 | |
|---|
| 568 | void test_gfx(int mode) |
|---|
| 569 | { |
|---|
| 570 | static DS_U32 osdBuf=0; |
|---|
| 571 | static DS_U32 ccBuf=0; |
|---|
| 572 | static DS_U32 test_plane=0; |
|---|
| 573 | int updatePlane = -1; |
|---|
| 574 | |
|---|
| 575 | if (DHL_GFX_IsInit(PLANE_OSD) == DS_FALSE) |
|---|
| 576 | { |
|---|
| 577 | SysCHECK( DHL_GFX_Init( PLANE_OSD, 0, 0, 1366, 768, 1366, 768, PF_RGB16, &osdBuf ) == DHL_OK ); |
|---|
| 578 | } |
|---|
| 579 | |
|---|
| 580 | if (DHL_GFX_IsInit(PLANE_CC) == DS_FALSE) |
|---|
| 581 | { |
|---|
| 582 | SysCHECK( DHL_GFX_Init( PLANE_CC, 0, 0, 1366, 768, 1366, 768, PF_RGB16, &ccBuf ) == DHL_OK ); |
|---|
| 583 | } |
|---|
| 584 | |
|---|
| 585 | if ( !test_plane ) |
|---|
| 586 | SysCHECK( DHL_GFX_AllocFrameBuffer( &test_plane, 1366, 768, PF_RGB16 ) == DHL_OK ); |
|---|
| 587 | |
|---|
| 588 | if (!osdBuf || !ccBuf) |
|---|
| 589 | { |
|---|
| 590 | osdBuf = primBuff; |
|---|
| 591 | ccBuf = scndBuff; |
|---|
| 592 | } |
|---|
| 593 | |
|---|
| 594 | if ( DHL_GFX_IsInit(PLANE_OSD) == DS_FALSE ) |
|---|
| 595 | { |
|---|
| 596 | printf("[ERROR] Graphic is not initialized yet.\n"); |
|---|
| 597 | return; |
|---|
| 598 | } |
|---|
| 599 | |
|---|
| 600 | //DHL_GFX_EnablePlane(0,0); |
|---|
| 601 | //DHL_GFX_EnablePlane(1,0); |
|---|
| 602 | |
|---|
| 603 | //mode = 2; |
|---|
| 604 | |
|---|
| 605 | switch( mode ) |
|---|
| 606 | { |
|---|
| 607 | #if 1//(DHL_GFX_FMT32 == DHL_GFX_FORMAT) |
|---|
| 608 | case 10: |
|---|
| 609 | DHL_GFX_DrawBox( osdBuf, 0, 0, 668, 456, 0xFF00); |
|---|
| 610 | case 12: |
|---|
| 611 | DHL_GFX_DrawBox( osdBuf, 1, 1, 668-2, 456-2, 0xF0F0); |
|---|
| 612 | case 13: |
|---|
| 613 | DHL_GFX_DrawBox( osdBuf, 2, 2, 668-4, 456-4, 0xFFF0); |
|---|
| 614 | case 14: |
|---|
| 615 | DHL_GFX_DrawBox( osdBuf, (668-1)/2, 0, 2, 456, 0xF0FF); |
|---|
| 616 | case 15: |
|---|
| 617 | DHL_GFX_DrawBox( osdBuf, 0, (456-1)/2, 668, 2, 0xF0FF); |
|---|
| 618 | updatePlane = 0; |
|---|
| 619 | break; |
|---|
| 620 | #endif |
|---|
| 621 | |
|---|
| 622 | case 16: |
|---|
| 623 | DHL_GFX_DrawBox( test_plane, 0, 0, 1366, 768, 0); |
|---|
| 624 | DHL_GFX_CopyBlock( test_plane, osdBuf, 0, 0, 1366, 768, 0, 0, 1366, 768); |
|---|
| 625 | updatePlane = 1; |
|---|
| 626 | break; |
|---|
| 627 | |
|---|
| 628 | case 3: |
|---|
| 629 | //DHL_GFX_InitFont(); |
|---|
| 630 | DHL_GFX_PutString( ccBuf, 100, 60, "This is string message 1.\0" ); |
|---|
| 631 | DHL_GFX_PutString( ccBuf, 100, 60+20, "This is string message 2. Digital Stream Technology.\0" ); |
|---|
| 632 | DHL_GFX_PutString( ccBuf, 100, 60+40, "This is string message 3.\0" ); |
|---|
| 633 | DHL_GFX_PutString( ccBuf, 100, 60+60, "This is string message 4.\0" ); |
|---|
| 634 | updatePlane = 1; |
|---|
| 635 | break; |
|---|
| 636 | |
|---|
| 637 | case 4: |
|---|
| 638 | printf("Print test string into test image which copied to OSD plane.\n"); |
|---|
| 639 | DHL_GFX_PutString( test_plane, 100, 60, "This is string message 1.\0" ); |
|---|
| 640 | DHL_GFX_PutString( test_plane, 100, 60+20, "This is string message 2. Digital Stream Technology.\0" ); |
|---|
| 641 | DHL_GFX_PutString( test_plane, 100, 60+40, "This is string message 3.\0" ); |
|---|
| 642 | DHL_GFX_PutString( test_plane, 100, 60+60, "This is string message 4.\0" ); |
|---|
| 643 | DHL_GFX_CopyBlock( test_plane, osdBuf, 0, 0, 1366, 768, 0, 0, 1366, 768); |
|---|
| 644 | |
|---|
| 645 | updatePlane = 1; |
|---|
| 646 | break; |
|---|
| 647 | } |
|---|
| 648 | |
|---|
| 649 | if ( updatePlane != -1 ) |
|---|
| 650 | DHL_GFX_UpdateScreen(updatePlane); |
|---|
| 651 | } |
|---|