⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gfx_drawlib.c

📁 sigmadesign smp8623 gui source code ,bingo
💻 C
📖 第 1 页 / 共 5 页
字号:
/* * * Copyright (c) Sigma Designs, Inc. 2004. All rights reserved. * *//** @file gfx_drawlib.c @brief  gfx_drawlib api @author Raul Chirinos */#define ALLOW_OS_CODE#include "../include/gfx_drawlib.h"#include "../include/gfx_drawcontrol.h"#include <stdlib.h>#include "../include/stream.h"#include "../include/subreader.h"//#include "rmalloc.h"#if 1#define GFXDBG ENABLE#else#define GFXDBG DISABLE#endifextern sub_context subs;// global dataGFXLib_data gdata;static int CompFunc(const void *p1, const void *p2){	return ((((GFXLib_objectdata*) p1)->zindex) - (((GFXLib_objectdata*) p2)->zindex));}/* initialize gfx */RMstatus gfxInit(struct RUA *pRua){	RMuint32 gfx_count;	struct GFXEngine_DRAMSize_in_type dramSizeIn;	struct GFXEngine_DRAMSize_out_type dramSizeOut;	RMuint32 i;//,j;	RMstatus status;	//	stream_t* fd;	//	RMascii buffer[10];	// init vars	RMMemset(&gdata, 0, sizeof(gdata));	gdata.gfx = 0xff;	gdata.tvType = TVTYPE_4_3;	ResetBmpBuffers();	dramSizeIn.CommandFIFOCount = GFX_FIFOCOUNT;	status = RUAExchangeProperty(pRua, EMHWLIB_MODULE(GFXEngine, 0), RMGFXEnginePropertyID_DRAMSize, &dramSizeIn, sizeof(dramSizeIn),			&dramSizeOut, sizeof(dramSizeOut));	if (RMFAILED(status))	{		RMDBGLOG((GFXDBG, "Error getting dram size for gfx engine\n"));		return RM_ERROR;	}	gdata.profile.CommandFIFOCount = dramSizeIn.CommandFIFOCount;	gdata.profile.Priority = 1;	gdata.profile.CachedSize = dramSizeOut.CachedSize;	gdata.profile.UncachedSize = dramSizeOut.UncachedSize;	if (gdata.profile.CachedSize > 0)	{		gdata.profile.CachedAddress = RUAMalloc(pRua, 0, RUA_DRAM_CACHED, gdata.profile.CachedSize);		//		printf("gfx cached addr: 0x%08lx, size 0x%08lx, end: 0x%08lx\n", gdata.profile.CachedAddress, gdata.profile.CachedSize, gdata.profile.CachedAddress + gdata.profile.CachedSize);	}	else	{		gdata.profile.CachedAddress = 0;	}	gdata.profile.UncachedSize = dramSizeOut.UncachedSize;	if (gdata.profile.UncachedSize > 0)	{		gdata.profile.UncachedAddress = RUAMalloc(pRua, 0, RUA_DRAM_UNCACHED, gdata.profile.UncachedSize);		//		printf("gfx uncached addr: 0x%08lx, size 0x%08lx, end: 0x%08lx\n", gdata.profile.UncachedAddress, gdata.profile.UncachedSize, gdata.profile.UncachedAddress + gdata.profile.UncachedSize);	}	else	{		gdata.profile.UncachedAddress = 0;	}	gdata.gfx = GFXEngine;	status = RUAExchangeProperty(pRua, EMHWLIB_MODULE(Enumerator, 0), RMEnumeratorPropertyID_CategoryIDToNumberOfInstances,			&gdata.gfx, sizeof(gdata.gfx), &gfx_count, sizeof(gfx_count));	if (RMFAILED(status))	{		RMDBGLOG((GFXDBG, "Error getting gfx engine count\n"));		return RM_ERROR;	}	for (i = 0; i < gfx_count; i++)	{		gdata.gfx = EMHWLIB_MODULE(GFXEngine, i);		status = RUASetProperty(pRua, gdata.gfx, RMGFXEnginePropertyID_Open, &gdata.profile, sizeof(gdata.profile), 0);		if (status == RM_OK)			break;	}	if (i == gfx_count)	{		RMDBGLOG((GFXDBG, "Cannot open a gfx engine [0..%lu[\n", gfx_count));		return RM_ERROR;	}	gdata.font_type = rtk_font_type_None;	//	i = 0;	//	fd=open_stream_gfx ("Revolution.OS.2001.DVDRip.XviD-RETRO.sub", NULL, &i);	//	stream_fill_buffer(fd);	//	//	for(i = 0; i < 65535; i ++){	//		buffer[0] = stream_read_char(fd);	//		printf("%c", buffer[0]);	//	}	//	//	free_stream(fd);	//[RC] NEED CLEAN UP JOB!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!	InitPrefetch();	return RM_OK;}/* unInitialize gfx */RMstatus gfxUnInit(struct RUA *pRua){	RMuint32 close_profile = 0;	RMstatus status;	ClosePrefetch();	if (pRua == NULL || gdata.gfx == 0xff)		return RM_ERROR;	status = RUASetProperty(pRua, gdata.gfx, RMGFXEnginePropertyID_Close, &close_profile, sizeof(close_profile), 0);	if (RMFAILED(status))	{		RMDBGLOG((GFXDBG, "Error cannot close gfx engine\n"));	}	if (gdata.profile.CachedAddress > 0)	{		RUAFree(pRua, gdata.profile.CachedAddress);		gdata.profile.CachedAddress = 0;	}	if (gdata.profile.UncachedAddress > 0)	{		RUAFree(pRua, gdata.profile.UncachedAddress);		gdata.profile.UncachedAddress = 0;	}	// free drawing buffer	FreeBaseBuffer(pRua);	FreeBackBuffer(pRua, &gdata.backBuffer);	printf("exit\n");	return RM_OK;}/* set osd parameters */RMstatus gfxSetOSDParams(struct RUA *pRua, RMuint32 OSDaddr, RMuint32 OSDwidth, RMuint32 OSDheight){	RMstatus status;	RMuint32 osdmemsize = 0;	RMuint32 drawbuffsize = 0; // taken from osdmem to aid drawing of multiple part objects	if (OSDaddr == 0 || OSDwidth <= 0)		return RM_ERROR;	// Calculate amount of memory to allocate	osdmemsize = OSDwidth + ((OSDwidth & 0x3F) ? (64 - (OSDwidth & 0x3F)) : 0);	osdmemsize *= OSDheight + ((OSDheight & 0x3F) ? (64 - (OSDheight & 0x3F)) : 0);	osdmemsize *= 11;	//	drawbuffsize = 147456;	drawbuffsize = OSDwidth + ((OSDwidth & 0x3F) ? (64 - (OSDwidth & 0x3F)) : 0);	drawbuffsize *= OSDheight + ((OSDheight & 0x3F) ? (64 - (OSDheight & 0x3F)) : 0);	//	drawbuffsize /= 2;	//	drawbuffsize = 40000;	//	drawbuffsize *= 6;	//	osdmemsize = (OSDwidth * OSDheight * 4) / 1024;	//	if(osdmemsize <= 1024){	//		osdmemsize = 2000000;	//		drawbuffsize = 10000;	//	}	//	else if(osdmemsize <= 2048){	//		osdmemsize = 4500000;	//		drawbuffsize = 1572864;	//	}	//	else{	//		osdmemsize = 4660000;	//		drawbuffsize = 40000;	//	}	// Allocate memory	RMMemset(&gdata.baseBuffer, 0, sizeof(RMdrawBuffer));	status = AllocateBaseBuffer(pRua, &gdata.baseBuffer, osdmemsize);	if (RMFAILED(status))	{		RMDBGLOG((GFXDBG, "Failed to allocate OSD buffer\n"));		return RM_ERROR;	}	else	{		RMDBGLOG((GFXDBG, "Allocated a %.3f MB OSD surface\n", ((double)osdmemsize) / 1000000.0));	}	RMMemset(&gdata.drawBuffer, 0, sizeof(RMdrawBuffer));	RMMemset(&gdata.backBuffer, 0, sizeof(RMdrawBuffer));	// Allocate extra buffer to help drawing -- no error in return since we may be ok without	// The usable part of the base buffer is set to the end of the drawing buffer (if any).	// When displaying pictures the begin of the base buffer will be set to 0 and will be restored	// to the drawing buffer size when a page is to be displayed	if (drawbuffsize)	{		if (RMSUCCEEDED(AllocateBuffer(&gdata.drawBuffer, drawbuffsize, TRUE)))		{			gdata.baseBuffer.offset = gdata.drawBuffer.size;		}		if (RMSUCCEEDED(AllocateBackBuffer(pRua, &gdata.backBuffer, drawbuffsize * 4)))		{			//gdata.baseBuffer.offset = gdata.backBuffer.size;		}	}	gdata.osdAddr = OSDaddr;	gdata.osdWidth = OSDwidth;	gdata.osdHeight = OSDheight;	// pass osd params to graphic loader	SetOsdSurfaceSize(gdata.osdWidth, gdata.osdHeight);	return RM_OK;}RMstatus gfxSetTvType(struct RUA *pRua, RMbool set4_3){	gdata.tvType = (set4_3 ? TVTYPE_4_3 : TVTYPE_16_9);	DoTVRatio(pRua, gdata.tvType);	return RM_OK;}/* draw a rectangle of a given color */RMstatus gfxDrawRect(struct RUA *pRua, RMuint16 x, RMuint16 y, RMuint16 width, RMuint16 height, RMuint32 color){	//	RMstatus status;	//	//	status = SetOutputSurfaceBuffer(pRua, gdata.backBuffer.baseAddr, gdata.osdWidth);	//	if(RMFAILED(status))	//		return status;	return Fill(pRua, x, y, width, height, color);	//return BitBlt(pRua);}/* draw a vertical line of a given length, color and thickness*/RMstatus gfxDrawVLine(struct RUA *pRua, RMuint16 x, RMuint16 y, RMuint16 length, RMuint16 thickness, RMuint32 color){	RMstatus status;	if (thickness <= 0 || length <= 0)		return RM_ERROR;	status = SetOutputSurfaceBuffer(pRua, gdata.backBuffer.baseAddr, gdata.osdWidth);	if (RMFAILED(status))		return status;	gfxDrawRect(pRua, x, y, thickness, length, color);	return BitBlt(pRua);}/* draw a horizontal line of a given length, color and thickness*/RMstatus gfxDrawHLine(struct RUA *pRua, RMuint16 x, RMuint16 y, RMuint16 length, RMuint16 thickness, RMuint32 color){	//	RMstatus status;	if (thickness <= 0 || length <= 0)		return RM_ERROR;	//	status = SetOutputSurfaceBuffer(pRua, gdata.backBuffer.baseAddr, gdata.osdWidth);	//	if(RMFAILED(status))	//		return status;	return gfxDrawRect(pRua, x, y, length, thickness, color);	//	return BitBlt(pRua);}RMstatus gfxDrawTransLine(struct RUA *pRua, RMuint16 x, RMuint16 y, RMuint16 length, RMuint16 thickness, RMuint32 color){	RMstatus status;	if (thickness <= 0 || length <= 0)		return RM_ERROR;	status = SetOutputSurfaceBuffer(pRua, gdata.backBuffer.baseAddr, gdata.osdWidth);	if (RMFAILED(status))		return status;	RoundRect(pRua, x, y, length, thickness, color, TRUE, 0);	return BitBlt(pRua);}/* draw a point of a given color*/RMstatus gfxDrawPoint(struct RUA *pRua, RMuint16 x, RMuint16 y, RMuint32 color){	return gfxDrawRect(pRua, x, y, 1, 1, color);}RMstatus gfxDrawButton(struct RUA *pRua, RMButtonObject *obj){	RMstatus status = SetOutputSurfaceBuffer(pRua, gdata.backBuffer.baseAddr, gdata.osdWidth);	if (RMFAILED(status))		return status;	DrawButton(pRua, 0, 0, obj, 0);	return BitBlt(pRua);}RMstatus gfxDrawPopupButton(struct RUA *pRua, RMBitmapObject *popup, RMuint16 x, RMuint16 y, RMButtonObject *obj){	RMstatus status;	RMuint8 bmpindex;	if (obj->visible == FALSE)		return RM_OK;	status = GetBitmapIndex(pRua, popup->file, &bmpindex, TRUE);	if (RMFAILED(status))		return status;	return DrawButton(pRua, x, y, obj, bmpindex);}/* draw text */RMstatus gfxDrawStringEvent(struct RUA *pRua, RMuint16 xOrigen, RMuint16 yOrigen, RMStringObject *obj){	RMstatus status = RM_OK;	//	RMuint8 fontindex;//, predeffontindex;	GFXLib_rect rect, rctext;//rc,	//	GFXLib_textdata txt;	//	RMtextitem lines[MAX_STR_LINES];	//	RMuint8 count = 0;	RMuint8 i;	//	RMuint16 maxwidth, maxheight;	//	RMuint8 fontheight;	//	RMuint32 color;	Prop prop;	prop.trunc = TRUNC_NONE;	if (obj->visible == FALSE)		return RM_OK;	status = SetOutputSurfaceBuffer(pRua, gdata.backBuffer.baseAddr, gdata.osdWidth);	if (RMFAILED(status))		return status;	rect.x = obj->x + xOrigen;	rect.y = obj->y + yOrigen;	rect.width = obj->width;	rect.height = obj->height;	gfxDrawRect(pRua, rect.x - 10, rect.y - 8, 250, 53, 0xAA000000);	//	status = GetFontIndex(pRua, obj->fontfile, obj->charwidth, &fontindex);	//	if(RMFAILED(status))	//		return status;	//	status = SetOutputSurface(pRua);	//	if(RMFAILED(status))	//		return status;	// fill the palette	//	SetTextPalette(pRua, obj->foregroundcolor, obj->backgroundcolor, obj->transparentbackground);	// [RC] assuming 1bpp	//	SetTextColorFormat(pRua);	//	status = getPredefinedFontIndex(GetBmpPath(fontindex), &predeffontindex);	//	if(RMFAILED(status))	//		return status;	//	fontheight = getFontHeight(predeffontindex);	//	gfxGetTextExtents(pRua, &prop, &rctext);	//	//	// break up string	//	maxwidth = rect.width;	//	maxheight = yOrigen + obj->y + obj->height;	//	//	rect.x = obj->x + xOrigen;	//	rect.width = maxwidth;	//	rect.height = rctext.height;	//	count = getTextLines(obj->text, predeffontindex, maxwidth, MAX_STR_LENGTH, MAX_STR_LINES, lines);	//	for(i = 0; i < count; i++){	RMMemset(&prop, 0, sizeof(Prop));	RMCopyAscii(prop.text, obj->text/*lines[0]*/);	prop.alignment = obj->textalign;	prop.fgColor = obj->backgroundcolor;	prop.bgColor = obj->foregroundcolor;// & 0x00FFFFFF;	//		txt.transparentbackground = obj->transparentbackground;	prop.scale = atoi(obj->fontfile);	gfxGetTextExtents(pRua, &prop, &rctext);	// break up string	//	maxwidth = rect.width;	//	maxheight = yOrigen + obj->y + obj->height;	//	rect.x = obj->x;// + xOrigen;	//	rect.width = maxwidth;	//	rect.height = rctext.height;	// calculate position and correct accordingly	//		rect.y = rect.height + obj->y + yOrigen;	//		printf("<<<<<<<<<<<<<<<<<<<<<<<(x, y, w, h) (%ld, %ld, %ld, %ld)\n", rect.x, rect.y, rect.width, rect.height);	// verify we are not going beyond clipping area	//		if((rect.y + rect.height) > maxheight){	//			status = RM_ERROR;	//			break;	//		}	//		txt.hasfocus = obj->hasfocus;	//		txt.outlinecolor = obj->outlinecolor;	//		txt.selectioncolor = obj->selectioncolor;	//		txt.inputchar = obj->inputchar;	//		txt.password = (obj->type == STRING_PASSWORD);	//		txt.input = (obj->type != STRING_UNKNOWN);	if (obj->type == STRING_PASSWORD)	{		for (i = 0; i < RMasciiLength(prop.text); i++)		{			prop.text[i] = ((prop.text[i] >= '0' && prop.text[i] <= '9') ? '*' : '\0');		}	}	rect.x += 5;	status = gfxTTDrawString(pRua, &rect, &prop, NULL);	//		status = DrawString(pRua, &rect, &txt, fontindex);	//	}	return BitBlt(pRua);}/* draw text */RMstatus gfxDrawString(struct RUA *pRua, RMuint16 xOrigen, RMuint16 yOrigen, RMStringObject *obj){	RMstatus status = RM_OK;	//	RMuint8 fontindex;//, predeffontindex;	GFXLib_rect rect, rc, rctext;	//	GFXLib_textdata txt;	//	RMtextitem lines[MAX_STR_LINES];	//	RMuint8 count = 0;	RMuint8 i;	//	RMuint16 maxwidth, maxheight;	//	RMuint8 fontheight;	RMuint32 color;	Prop prop;	prop.trunc = TRUNC_NONE;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -