#include #include #include "gdebug.h" #include "gfbdev.h" static unsigned char *g_pMainBuffer = NULL; static struct fb_info *info = NULL; static tCoord GetWidth( struct sGC *GC ) { return info->var.xres; } static tCoord GetHeight( struct sGC *GC ) { return info->var.yres; } static unsigned long ConvColorToBytesYUV(struct sGC *GC, tColor color) { unsigned long rv = 0; tColor yuv = RGBToYUV( color ); int Y = GetColorRed(yuv); int U = GetColorGreen(yuv); int V = GetColorBlue(yuv); rv = (Y<<24)|(U<<16)|(Y<<8)|V; //_D("color=%08x -> Y=%d,U=%d,V=%d -> uyvy=%08x\n",color,Y,U,V,rv); return rv; } static unsigned long ConvColorToBytes(struct sGC *GC, tColor color) { unsigned long rv = 0; rv = ((GetColorRed(color)>>3)<<11) | ((GetColorGreen(color)>>2)<<5) | (GetColorBlue(color)>>3); return rv; } static tColor ConvBytesToColorYUV(struct sGC *GC, unsigned long color) { tColor rv = 0; rv = SetColorRGB( (color>>11)&0x1f, (color>>5)&0x3f, color&0x1f ); return rv; } static tColor ConvBytesToColor(struct sGC *GC, unsigned long color) { tColor rv = 0; rv = SetColorRGB( (color>>11)&0x1f, (color>>5)&0x3f, color&0x1f ); return rv; } static void DrawBegin( struct sGC *GC ) { } static void DrawEnd( struct sGC *GC ) { /* flip buffer */ } static __inline unsigned int CalcByteIndex( tCoord x, tCoord y ) { return (unsigned int)(((y+info->var.yoffset) * info->fix.line_length) + ((x + info->var.xoffset) *info->var.bits_per_pixel/8)); } static void DrawPixelDirectCBB1(struct sGC *GC, tCoord x, tCoord y, unsigned long color ) { unsigned int byteIndex = CalcByteIndex(x,y); // Mask off the appropriate 1 bits, then or it in from the color. g_pMainBuffer[byteIndex] &= ~(0x80 >> ((x & 0x07))); g_pMainBuffer[byteIndex] |= ((color & 0x01) << 8) >> ((x & 0x07)); } static void DrawPixelDirectCBB2(struct sGC *GC, tCoord x, tCoord y, unsigned long color ) { unsigned int byteIndex = CalcByteIndex(x,y); // Mask off the appropriate g_gxdp.cBPP (2) bits, then or it in from the color. g_pMainBuffer[byteIndex] &= ~(0xC0 >> ((x & 0x03) * 2)); g_pMainBuffer[byteIndex] |= ((color & 0x03) << 6) >> ((x & 0x03) * 2); } static void DrawPixelDirectCBB4(struct sGC *GC, tCoord x, tCoord y, unsigned long color ) { unsigned int byteIndex = CalcByteIndex(x,y); // If the nX is even the top g_gxdp.cBPP (4) bits need to be set. g_pMainBuffer[byteIndex] &= 0x0F << ((x & 0x01) * 4); g_pMainBuffer[byteIndex] |= (color & 0x0F) << ((!(x & 0x01)) * 4); } static void DrawPixelDirectCBB8(struct sGC *GC, tCoord x, tCoord y, unsigned long color ) { unsigned int byteIndex = CalcByteIndex(x,y); g_pMainBuffer[byteIndex] = (unsigned char)color & 0xFF; } static void DrawPixelDirectYUV16(struct sGC *GC, tCoord x, tCoord y, unsigned long color ) { unsigned int byteIndex = CalcByteIndex(x,y); if( !(x & 1) ) color >>=16; *(unsigned short*)(&g_pMainBuffer[byteIndex]) = (unsigned short)(color & 0xFFFF); } static void DrawPixelDirectCBB16(struct sGC *GC, tCoord x, tCoord y, unsigned long color ) { unsigned int byteIndex = CalcByteIndex(x,y); *(unsigned short*)(&g_pMainBuffer[byteIndex]) = (unsigned short)(color & 0xFFFF); } static void DrawPixelDirectCBB32(struct sGC *GC, tCoord x, tCoord y, unsigned long color ) { unsigned int byteIndex = CalcByteIndex(x,y); *(unsigned int*)(&g_pMainBuffer[byteIndex]) = color; } static void DrawPixelDirect(struct sGC *GC, tCoord x, tCoord y, unsigned long color ) { int bpp=0; unsigned int nX = x; unsigned int nY = y; unsigned int byteIndex = CalcByteIndex(x,y); bpp = info->var.bits_per_pixel; switch( bpp ) { case 1: // Mask off the appropriate 1 bits, then or it in from the color. g_pMainBuffer[byteIndex] &= ~(0x80 >> ((nX & 0x07))); g_pMainBuffer[byteIndex] |= ((color & 0x01) << 8) >> ((nX & 0x07)); break; case 2: // Mask off the appropriate g_gxdp.cBPP (2) bits, then or it in from the color. g_pMainBuffer[byteIndex] &= ~(0xC0 >> ((nX & 0x03) * bpp)); g_pMainBuffer[byteIndex] |= ((color & 0x03) << 6) >> ((nX & 0x03) * bpp); break; case 4: // If the nX is even the top g_gxdp.cBPP (4) bits need to be set. g_pMainBuffer[byteIndex] &= 0x0F << ((nX & 0x01) * bpp); g_pMainBuffer[byteIndex] |= (color & 0x0F) << ((!(nX & 0x01)) * bpp); break; case 8: g_pMainBuffer[byteIndex] = (unsigned char)color & 0xFF; break; case 16: *(unsigned short*)(&g_pMainBuffer[byteIndex]) = (unsigned short)color & 0xFFFF; break; case 32: *(unsigned int*)(&g_pMainBuffer[byteIndex]) = color; break; } } static int OnOpen(struct sGC *GC, void *param) { int rv=-EIO; int bpp=0; info = (struct fb_info *)param; g_pMainBuffer = info->screen_base; bpp = info->var.bits_per_pixel; if( !strcmp(info->fix.id,"dm_vid1_fb") ) { switch( bpp ) { case 16: if( RegisterGCMethod(GC,gcDrawPixelDirect,DrawPixelDirectYUV16) ) goto error; if( RegisterGCMethod(GC,gcConvColorToBytes,ConvColorToBytesYUV) ) goto error; if( RegisterGCMethod(GC,gcConvBytesToColor,ConvBytesToColorYUV) ) goto error; break; } } else { switch( bpp ) { case 1: if( RegisterGCMethod(GC,gcDrawPixelDirect,DrawPixelDirectCBB1) ) goto error; break; case 2: if( RegisterGCMethod(GC,gcDrawPixelDirect,DrawPixelDirectCBB2) ) goto error; break; case 4: if( RegisterGCMethod(GC,gcDrawPixelDirect,DrawPixelDirectCBB4) ) goto error; break; case 8: if( RegisterGCMethod(GC,gcDrawPixelDirect,DrawPixelDirectCBB8) ) goto error; break; case 16: if( RegisterGCMethod(GC,gcDrawPixelDirect,DrawPixelDirectCBB16) ) goto error; break; case 32: if( RegisterGCMethod(GC,gcDrawPixelDirect,DrawPixelDirectCBB32) ) goto error; break; } } return 0; error: _E("Error register Method\n"); return rv; } static void OnClose( struct sGC *GC ) { } /* register methods */ static int OnRegister( tGC *pGC ) { if( RegisterGCMethod(pGC,gcConvColorToBytes,ConvColorToBytes) ) return -1; if( RegisterGCMethod(pGC,gcConvBytesToColor,ConvBytesToColor) ) return -1; if( RegisterGCMethod(pGC,gcDrawPixelDirect,DrawPixelDirect) ) return -1; if( RegisterGCMethod(pGC,gcGetWidth,GetWidth) ) return -1; if( RegisterGCMethod(pGC,gcGetHeight,GetHeight) ) return -1; if( RegisterGCMethod(pGC,gcOnOpen,OnOpen) ) return -1; if( RegisterGCMethod(pGC,gcOnClose,OnClose) ) return -1; if( RegisterGCMethod(pGC,gcDrawBegin,DrawBegin) ) return -1; if( RegisterGCMethod(pGC,gcDrawEnd,DrawEnd) ) return -1; return 0; } /* export device */ extern tGDC gfbdev = { "FB", OnRegister };