?? gfx_drawcontrol.c.svn-base
字號:
/* * * Copyright (c) Sigma Designs, Inc. 2004. All rights reserved. * *//** @file gfx_drawlib.c @brief Some drawing routines using the graphics accelerator @author Raul Chirinos */#define ALLOW_OS_CODE#include "../include/gfx_drawcontrol.h"#include <sys/time.h>#include <time.h>#include <stdlib.h>#if 0#define GFXDBG ENABLE#else#define GFXDBG DISABLE#endif#define TIMEOUT_US 1000000 // 1 sec#define MAX_DRAWING_BUFFER_PARTS 2 // cannot be 0 !!!#define PICTURE_DISPLAY_OFFSET 5// from gfx_drawlib.cextern GFXLib_data gdata;// localRMbitmapdata g_bitmaps[MAX_BITMAPS]; // to keep loaded bitmap(s) data (including fonts) -- background page at item 0static RMbool g_useCodePageConversion;static RMuint8 g_bitmapBufferIndex = 0;static RMuint8 g_last_palbpp = 0; // last palette set bppstatic RMuint8 g_textBufferIndex = 0;static struct GFXEngine_Palette_4BPP_type g_lastpal; // to compare some pal colors before setting new palette if same bppstatic RMcriticalsection blt_cs;static RMuint8 step_accell = 4, accell_step = 2;LIST_HEAD(listhead, task) tasks;typedef struct task{ RMascii* file; LIST_ENTRY(task) entries;} task;static RMthread g_preload = NULL;RMcriticalsection g_cs_media;RMcriticalsection g_cs;RMcriticalsection g_cstasks;RMbool end;RMstatus err;#define RuaSetProp(pRUA, moduleID, propertyID, pValue, ValueSize) \ err = RUASetProperty(pRUA, moduleID, propertyID, pValue, ValueSize, 0); \ \ if (err != RM_OK) { \ RMDBGLOG((ENABLE, "Cannot set Property %d on module %d, %d\n", propertyID, moduleID, err)); \ return err; \ }extern RMstatus gfxDrawHLine(struct RUA *pRua, RMuint16 x, RMuint16 y, RMuint16 length, RMuint16 thickness, RMuint32 color);void* PreloadThreadEntry(void *p);void* PreloadThreadEntry(void *p){ struct timespec time; task* tp; time.tv_sec = (RMuint32) 0; time.tv_nsec = ((RMuint32) 20000000); while (end) { if (tasks.lh_first) { RMuint8 bmpindex; RMEnterCriticalSection(g_cstasks); { tp = tasks.lh_first; LIST_REMOVE(&tasks, tp, entries); } RMLeaveCriticalSection(g_cstasks); nanosleep(&time, NULL); GetBitmapIndex(NULL, tp->file, &bmpindex, TRUE); RFREE(tp); tp = NULL; } else { nanosleep(&time, NULL); } } return NULL;}static void AddTask(RMascii* file){ task* tp; if (file) { tp = (task*) MALLOC(sizeof(task)); tp->file = file; RMEnterCriticalSection(g_cstasks); { LIST_INSERT_HEAD(&tasks, tp, entries); } RMLeaveCriticalSection(g_cstasks); }}RMstatus BitBlt(struct RUA *pRua){ struct GFXEngine_MoveReplaceRectangle_type replace_param; RMEnterCriticalSection(blt_cs); SetInputSurface(pRua, EMhwlibColorMode_TrueColor, gdata.backBuffer.baseAddr, gdata.osdWidth, GFX_SURFACE_ID_Y); SetOutputSurface(pRua); replace_param.SrcX = 0; replace_param.SrcY = 0; replace_param.DstX = 0; replace_param.DstY = 0; replace_param.Width = gdata.osdWidth; replace_param.Height = gdata.osdHeight; replace_param.AlphaX = 0; replace_param.AlphaY = 0; replace_param.Merge = FALSE; while ((err = RUASetProperty(pRua, gdata.gfx, RMGFXEnginePropertyID_MoveRectangle, &replace_param, sizeof(replace_param), 0)) == RM_PENDING) ; if (RMFAILED(err)) RMDBGLOG((ENABLE, "Error sending command move\n")); RMLeaveCriticalSection(blt_cs); //SetOutputSurfaceBuffer(pRua, gdata.backBuffer.baseAddr, gdata.osdWidth); return err;}void InitPrefetch(){ LIST_INIT(&tasks); end = TRUE; g_cs = RMCreateCriticalSection(); g_cstasks = RMCreateCriticalSection(); g_cs_media = RMCreateCriticalSection(); g_preload = RMCreateThread("PreloadThread", PreloadThreadEntry, NULL); blt_cs = RMCreateCriticalSection();}void ClosePrefetch(){ task* tp = NULL; if (g_preload) { end = FALSE; RMWaitForThreadToFinish(g_preload); g_preload = NULL; } RMDeleteCriticalSection(g_cs); RMDeleteCriticalSection(g_cstasks); RMDeleteCriticalSection(g_cs_media); while (tasks.lh_first) { tp = tasks.lh_first; LIST_REMOVE(&tasks, tp, entries); RFREE(tp); tp = NULL; } RMDeleteCriticalSection(blt_cs);}static inline RMstatus GFXColorFormatProperty(struct RUA *pRua, struct GFXEngine_ColorFormat_type *format_param){ RMstatus status; struct RUAEvent evt; RMuint8 trycount; trycount = 2; // try command only a couple of times then jump out tryagain: status = RUASetProperty(pRua, gdata.gfx, RMGFXEnginePropertyID_ColorFormat, format_param, sizeof(struct GFXEngine_ColorFormat_type), 0); if (status == RM_PENDING && trycount--) { evt.ModuleID = gdata.gfx; evt.Mask = RUAEVENT_COMMANDCOMPLETION; if (RUAWaitForMultipleEvents(pRua, &evt, 1, TIMEOUT_US, NULL) != RM_OK) RMDBGLOG((GFXDBG, "gfxColorFormat: FAILED WAITING FOR 1 second... TIMING ISSUE?\n")); goto tryagain; } return status;}static inline RMstatus GFX1BPPPaletteProperty(struct RUA *pRua, struct GFXEngine_Palette_1BPP_type *palette_param){ RMstatus status; struct RUAEvent evt; RMuint8 trycount; trycount = 2; // try command only a couple of times then jump out tryagain: status = RUASetProperty(pRua, gdata.gfx, RMGFXEnginePropertyID_Palette_1BPP, palette_param, sizeof(struct GFXEngine_Palette_1BPP_type), 0); if (status == RM_PENDING && trycount--) { evt.ModuleID = gdata.gfx; evt.Mask = RUAEVENT_COMMANDCOMPLETION; if (RUAWaitForMultipleEvents(pRua, &evt, 1, TIMEOUT_US, NULL) != RM_OK) RMDBGLOG((GFXDBG, "gfx1bppPalette: FAILED WAITING FOR 1 second... TIMING ISSUE?\n")); goto tryagain; } return status;}static inline RMstatus GFX2BPPPaletteProperty(struct RUA *pRua, struct GFXEngine_Palette_2BPP_type *palette_param){ RMstatus status; struct RUAEvent evt; RMuint8 trycount; trycount = 2; // try command only a couple of times then jump out tryagain: status = RUASetProperty(pRua, gdata.gfx, RMGFXEnginePropertyID_Palette_2BPP, palette_param, sizeof(struct GFXEngine_Palette_2BPP_type), 0); if (status == RM_PENDING && trycount--) { evt.ModuleID = gdata.gfx; evt.Mask = RUAEVENT_COMMANDCOMPLETION; if (RUAWaitForMultipleEvents(pRua, &evt, 1, TIMEOUT_US, NULL) != RM_OK) RMDBGLOG((GFXDBG, "gfx2bppPalette: FAILED WAITING FOR 1 second... TIMING ISSUE?\n")); goto tryagain; } return status;}static inline RMstatus GFX4BPPPaletteProperty(struct RUA *pRua, struct GFXEngine_Palette_4BPP_type *palette_param){ RMstatus status; struct RUAEvent evt; RMuint8 trycount; trycount = 2; // try command only a couple of times then jump out tryagain: status = RUASetProperty(pRua, gdata.gfx, RMGFXEnginePropertyID_Palette_4BPP, palette_param, sizeof(struct GFXEngine_Palette_4BPP_type), 0); if (status == RM_PENDING && trycount--) { evt.ModuleID = gdata.gfx; evt.Mask = RUAEVENT_COMMANDCOMPLETION; if (RUAWaitForMultipleEvents(pRua, &evt, 1, TIMEOUT_US, NULL) != RM_OK) RMDBGLOG((GFXDBG, "gfx4bppPalette: FAILED WAITING FOR 1 second... TIMING ISSUE?\n")); goto tryagain; } return status;}static inline RMstatus GFX8BPPPaletteProperty(struct RUA *pRua, struct GFXEngine_Palette_8BPP_type *palette_param){ RMstatus status; struct RUAEvent evt; RMuint8 trycount; trycount = 2; // try command only a couple of times then jump out tryagain: status = RUASetProperty(pRua, gdata.gfx, RMGFXEnginePropertyID_Palette_8BPP, palette_param, sizeof(struct GFXEngine_Palette_8BPP_type), 0); if (status == RM_PENDING && trycount--) { evt.ModuleID = gdata.gfx; evt.Mask = RUAEVENT_COMMANDCOMPLETION; if (RUAWaitForMultipleEvents(pRua, &evt, 1, TIMEOUT_US, NULL) != RM_OK) RMDBGLOG((GFXDBG, "gfx8bppPalette: FAILED WAITING FOR 1 second... TIMING ISSUE?\n")); goto tryagain; } return status;}static inline RMstatus GFXSurfaceProperty(struct RUA *pRua, struct GFXEngine_Surface_type *surface_param){ RMstatus status; struct RUAEvent evt; RMuint8 trycount; trycount = 2; // try command only a couple of times then jump out tryagain: status = RUASetProperty(pRua, gdata.gfx, RMGFXEnginePropertyID_Surface, surface_param, sizeof(struct GFXEngine_Surface_type), 0); if (status == RM_PENDING && trycount--) { evt.ModuleID = gdata.gfx; evt.Mask = RUAEVENT_COMMANDCOMPLETION; if (RUAWaitForMultipleEvents(pRua, &evt, 1, TIMEOUT_US, NULL) != RM_OK) RMDBGLOG((GFXDBG, "gfxSurface: FAILED WAITING FOR 1 second... TIMING ISSUE?\n")); goto tryagain; } return status;}static inline RMstatus GFXFillRectangleProperty(struct RUA *pRua, struct GFXEngine_FillRectangle_type *fill_param){ RMstatus status; struct RUAEvent evt; RMuint8 trycount; trycount = 2; // try command only a couple of times then jump out tryagain: status = RUASetProperty(pRua, gdata.gfx, RMGFXEnginePropertyID_FillRectangle, fill_param, sizeof(struct GFXEngine_FillRectangle_type), 0); if (status == RM_PENDING && trycount--) { evt.ModuleID = gdata.gfx; evt.Mask = RUAEVENT_COMMANDCOMPLETION; if (RUAWaitForMultipleEvents(pRua, &evt, 1, TIMEOUT_US, NULL) != RM_OK) { RMDBGLOG((GFXDBG, "gfxFill: FAILED WAITING FOR 1 second... TIMING ISSUE?")); } goto tryagain; } return status;}static inline RMstatus GFXMoveRectangleProperty(struct RUA *pRua, struct GFXEngine_MoveReplaceRectangle_type *move_param){ RMstatus status; struct RUAEvent evt; RMuint8 trycount; trycount = 2; // try command only a couple of times then jump out tryagain: status = RUASetProperty(pRua, gdata.gfx, RMGFXEnginePropertyID_MoveRectangle, move_param, sizeof(struct GFXEngine_MoveReplaceRectangle_type), 0); if (status == RM_PENDING && trycount--) { evt.ModuleID = gdata.gfx; evt.Mask = RUAEVENT_COMMANDCOMPLETION; if (RUAWaitForMultipleEvents(pRua, &evt, 1, TIMEOUT_US, NULL) != RM_OK) { RMDBGLOG((GFXDBG, "gfxReplace: FAILED WAITING FOR 1 second... TIMING ISSUE?\n")); } goto tryagain; } return status;}static inline RMstatus GFXReplaceRectangleProperty(struct RUA *pRua, struct GFXEngine_MoveReplaceRectangle_type *move_param){ RMstatus status; struct RUAEvent evt; RMuint8 trycount; trycount = 2; // try command only a couple of times then jump out tryagain: status = RUASetProperty(pRua, gdata.gfx, RMGFXEnginePropertyID_ReplaceRectangle, move_param, sizeof(struct GFXEngine_MoveReplaceRectangle_type), 0); if (status == RM_PENDING && trycount--) { evt.ModuleID = gdata.gfx; evt.Mask = RUAEVENT_COMMANDCOMPLETION; if (RUAWaitForMultipleEvents(pRua, &evt, 1, TIMEOUT_US, NULL) != RM_OK) { RMDBGLOG((GFXDBG, "gfxReplace: FAILED WAITING FOR 1 second... TIMING ISSUE?\n")); } goto tryagain; } return status;}static inline RMstatus GFXReplaceAndScaleRectangleProperty(struct RUA *pRua, struct GFXEngine_MoveReplaceScaleRectangle_type *move_param){ RMstatus status; struct RUAEvent evt; RMuint8 trycount; trycount = 2; // try command only a couple of times then jump out tryagain: status = RUASetProperty(pRua, gdata.gfx, RMGFXEnginePropertyID_ReplaceAndScaleRectangle, move_param, sizeof(struct GFXEngine_MoveReplaceScaleRectangle_type), 0); if (status == RM_PENDING && trycount--) { evt.ModuleID = gdata.gfx; evt.Mask = RUAEVENT_COMMANDCOMPLETION; if (RUAWaitForMultipleEvents(pRua, &evt, 1, TIMEOUT_US, NULL) != RM_OK) { RMDBGLOG((GFXDBG, "gfxReplaceAndScale: FAILED WAITING FOR 1 second... TIMING ISSUE?\n")); } goto tryagain; } return status;}static inline RMstatus GFXMoveAndScaleRectangleProperty(struct RUA *pRua, struct GFXEngine_MoveReplaceScaleRectangle_type *move_param){ RMstatus status; struct RUAEvent evt; RMuint8 trycount; trycount = 2; // try command only a couple of times then jump out tryagain: status = RUASetProperty(pRua, gdata.gfx, RMGFXEnginePropertyID_MoveAndScaleRectangle, move_param, sizeof(struct GFXEngine_MoveReplaceScaleRectangle_type), 0); if (status == RM_PENDING && trycount--) { evt.ModuleID = gdata.gfx; evt.Mask = RUAEVENT_COMMANDCOMPLETION; if (RUAWaitForMultipleEvents(pRua, &evt, 1, TIMEOUT_US, NULL) != RM_OK) { RMDBGLOG((GFXDBG, "gfxMoveAndScale: FAILED WAITING FOR 1 second... TIMING ISSUE?\n")); } goto tryagain; } return status;}static inline RMstatus GFXBlendRectanglesProperty(struct RUA *pRua, struct GFXEngine_BlendRectangles_type *blend_param){ RMstatus status; struct RUAEvent evt; RMuint8 trycount; trycount = 2; // try command only a couple of times then jump out tryagain: status = RUASetProperty(pRua, gdata.gfx, RMGFXEnginePropertyID_BlendRectangles, blend_param, sizeof(struct GFXEngine_BlendRectangles_type), 0); if (status == RM_PENDING && trycount--) { evt.ModuleID = gdata.gfx; evt.Mask = RUAEVENT_COMMANDCOMPLETION; if (RUAWaitForMultipleEvents(pRua, &evt, 1, TIMEOUT_US, NULL) != RM_OK) { RMDBGLOG((GFXDBG, "gfxBlend: FAILED WAITING FOR 1 second... TIMING ISSUE?\n")); } goto tryagain; } return status;}static inline RMstatus GFXBlendAndScaleRectanglesProperty(struct RUA *pRua, struct GFXEngine_BlendAndScaleRectangles_type *blend_param){ RMstatus status; struct RUAEvent evt; RMuint8 trycount; trycount = 2; // try command only a couple of times then jump out tryagain: status = RUASetProperty(pRua, gdata.gfx, RMGFXEnginePropertyID_BlendAndScaleRectangles, blend_param,
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -