X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Kernel%2Fdrvutil.c;h=d19a050464806f72a58eb638a90e04a509d3893c;hb=61cfad415a64c52ca253460231046f47fcb7fb15;hp=6de004bcff138dfe0aed8132b43b77513e80bdf9;hpb=800a321284a80799330ecf59be3a117c61babdb5;p=tpg%2Facess2.git diff --git a/Kernel/drvutil.c b/Kernel/drvutil.c index 6de004bc..d19a0504 100644 --- a/Kernel/drvutil.c +++ b/Kernel/drvutil.c @@ -53,17 +53,17 @@ tVideo_IOCtl_Bitmap gDrvUtil_TextModeCursor = { // === CODE === // --- Video Driver Helpers --- -int DrvUtil_Video_2DStream(void *Ent, void *Buffer, int Length, +int DrvUtil_Video_2DStream(void *Ent, const void *Buffer, int Length, tDrvUtil_Video_2DHandlers *Handlers, int SizeofHandlers) { - void *stream = Buffer; + const Uint8 *stream = Buffer; int rem = Length; int op; while( rem ) { rem --; - op = *(Uint8*)stream; - stream = (void*)((tVAddr)stream + 1); + op = *stream; + stream ++; if(op > NUM_VIDEO_2DOPS) { Log_Warning("DrvUtil", @@ -84,7 +84,7 @@ int DrvUtil_Video_2DStream(void *Ent, void *Buffer, int Length, case VIDEO_2DOP_NOP: break; case VIDEO_2DOP_FILL: - if(rem < 12) return Length-rem; + if(rem < 10) return Length-rem; if(!Handlers->Fill) { Log_Warning("DrvUtil", "DrvUtil_Video_2DStream: Driver" @@ -94,13 +94,13 @@ int DrvUtil_Video_2DStream(void *Ent, void *Buffer, int Length, Handlers->Fill( Ent, - ((Uint16*)stream)[0], ((Uint16*)stream)[1], - ((Uint16*)stream)[2], ((Uint16*)stream)[3], - ((Uint32*)stream)[2] + ((const Uint16*)stream)[0], ((const Uint16*)stream)[1], + ((const Uint16*)stream)[2], ((const Uint16*)stream)[3], + ((const Uint32*)stream)[4] ); - rem -= 12; - stream = (void*)((tVAddr)stream + 12); + rem -= 10; + stream += 10; break; case VIDEO_2DOP_BLIT: @@ -114,13 +114,13 @@ int DrvUtil_Video_2DStream(void *Ent, void *Buffer, int Length, Handlers->Blit( Ent, - ((Uint16*)stream)[0], ((Uint16*)stream)[1], - ((Uint16*)stream)[2], ((Uint16*)stream)[3], - ((Uint16*)stream)[4], ((Uint16*)stream)[5] + ((const Uint16*)stream)[0], ((const Uint16*)stream)[1], + ((const Uint16*)stream)[2], ((const Uint16*)stream)[3], + ((const Uint16*)stream)[4], ((const Uint16*)stream)[5] ); rem -= 12; - stream = (void*)((tVAddr)stream + 12); + stream += 12; break; } @@ -128,10 +128,13 @@ int DrvUtil_Video_2DStream(void *Ent, void *Buffer, int Length, return 0; } -int DrvUtil_Video_WriteLFB(tDrvUtil_Video_BufInfo *FBInfo, size_t Offset, size_t Length, void *Buffer) +int DrvUtil_Video_WriteLFB(tDrvUtil_Video_BufInfo *FBInfo, size_t Offset, size_t Length, const void *Buffer) { Uint8 *dest; + const Uint32 *src = Buffer; int csr_x, csr_y; + int x, y; + int bytes_per_px = (FBInfo->Depth + 7) / 8; ENTER("pFBInfo xOffset xLength pBuffer", Mode, FBInfo, Offset, Length, Buffer); @@ -144,11 +147,10 @@ int DrvUtil_Video_WriteLFB(tDrvUtil_Video_BufInfo *FBInfo, size_t Offset, size_t { case VIDEO_BUFFMT_TEXT: { - tVT_Char *chars = Buffer; - int bytes_per_px = (FBInfo->Depth + 7) / 8; + const tVT_Char *chars = Buffer; int widthInChars = FBInfo->Width/giVT_CharWidth; int heightInChars = FBInfo->Height/giVT_CharHeight; - int x, y, i; + int i; LOG("bytes_per_px = %i", bytes_per_px); LOG("widthInChars = %i, heightInChars = %i", widthInChars, heightInChars); @@ -208,17 +210,58 @@ int DrvUtil_Video_WriteLFB(tDrvUtil_Video_BufInfo *FBInfo, size_t Offset, size_t return 0; } - //TODO: Handle non 32-bpp framebuffer modes - if( FBInfo->Depth != 32 ) { - Log_Warning("DrvUtil", "DrvUtil_Video_WriteLFB - Don't support non 32-bpp FB mode"); - return 0; - } - - - //TODO: Handle pitch != Width*BytesPerPixel - // Copy to Frambuffer - dest = (Uint8 *)FBInfo->Framebuffer + Offset; - memcpy(dest, Buffer, Length); + switch(FBInfo->Depth) + { + case 15: + case 16: + Log_Warning("DrvUtil", "TODO: Support 15/16 bpp modes in LFB write"); + break; + case 24: + x = Offset % FBInfo->Width; + y = Offset / FBInfo->Width; + dest = (Uint8*)FBInfo->Framebuffer + y*FBInfo->Pitch; + for( ; Length >= 4; Length -= 4 ) + { + dest[x*3+0] = *src & 0xFF; + dest[x*3+1] = (*src >> 8) & 0xFF; + dest[x*3+2] = (*src >> 16) & 0xFF; + x ++; + if(x == FBInfo->Width) { + dest += FBInfo->Pitch; + x = 0; + } + } + break; + case 32: + // Copy to Frambuffer + if( FBInfo->Pitch != FBInfo->Width*4 ) + { + Uint32 *px; + // Pitch isn't 4*Width + x = Offset % FBInfo->Width; + y = Offset / FBInfo->Height; + + px = (Uint32*)FBInfo->Framebuffer + y*FBInfo->Pitch/4; + + for( ; Length >= 4; Length -= 4, x ) + { + px[x++] = *src ++; + if( x == FBInfo->Width ) { + x = 0; + px += FBInfo->Pitch; + } + } + } + else + { + dest = (Uint8 *)FBInfo->Framebuffer + Offset; + memcpy(dest, Buffer, Length); + } + break; + default: + Log_Warning("DrvUtil", "DrvUtil_Video_WriteLFB - Unknown bit depthn %i", FBInfo->Depth); + break; + } break; case VIDEO_BUFFMT_2DSTREAM: @@ -347,8 +390,6 @@ void DrvUtil_Video_RenderCursor(tDrvUtil_Video_BufInfo *Buf) Uint32 *src; int x, y; -// Debug("DrvUtil_Video_RenderCursor: (Buf=%p) dest_x=%i, dest_y=%i", Buf, dest_x, dest_y); - dest = (Uint8*)Buf->Framebuffer + dest_y*Buf->Pitch + dest_x*bytes_per_px; src = Buf->CursorBitmap->Data + src_y * Buf->CursorBitmap->W + src_x; @@ -363,17 +404,47 @@ void DrvUtil_Video_RenderCursor(tDrvUtil_Video_BufInfo *Buf) (Uint8*)dest + y*Buf->Pitch, render_w*bytes_per_px ); + // Draw the cursor switch(Buf->Depth) { + case 15: + case 16: + Log_Warning("DrvUtil", "TODO: Support 15/16 bpp modes in cursor draw"); + break; + case 24: + for( y = 0; y < render_h; y ++ ) + { + Uint8 *px; + px = dest; + for(x = 0; x < render_w; x ++, px += 3) + { + Uint32 value = src[x]; + // TODO: Should I implement alpha blending? + if(value & 0xFF000000) + { + px[0] = value & 0xFF; + px[1] = (value >> 8) & 0xFF; + px[2] = (value >> 16) & 0xFF; + } + else + ; + } + src += Buf->CursorBitmap->W; + dest = (Uint8*)dest + Buf->Pitch; + } + break; case 32: for( y = 0; y < render_h; y ++ ) { - for(x = 0; x < render_w; x ++ ) + Uint32 *px; + px = dest; + for(x = 0; x < render_w; x ++, px ++) { + Uint32 value = src[x]; // TODO: Should I implement alpha blending? - if(src[x] & 0xFF000000) - ((Uint32*)dest)[x] = src[x]; + if(value & 0xFF000000) + *px = value; else ; // NOP, completely transparent } @@ -382,7 +453,8 @@ void DrvUtil_Video_RenderCursor(tDrvUtil_Video_BufInfo *Buf) } break; default: - Log_Error("DrvUtil", "TODO: Implement non 32-bpp cursor"); + Log_Error("DrvUtil", "RenderCursor - Unknown bit depth %i", Buf->Depth); + Buf->CursorX = -1; break; } } @@ -467,6 +539,9 @@ void DrvUtil_Video_2D_Blit(void *Ent, Uint16 DstX, Uint16 DstY, Uint16 SrcX, Uin } } } + else if(W == FBInfo->Width && FBInfo->Pitch == FBInfo->Width*bytes_per_px) { + memmove((Uint8*)FBInfo->Framebuffer + dst, (Uint8*)FBInfo->Framebuffer + src, H*FBInfo->Pitch); + } else { // Normal copy is OK while( H -- ) { @@ -481,7 +556,7 @@ void DrvUtil_Video_2D_Blit(void *Ent, Uint16 DstX, Uint16 DstY, Uint16 SrcX, Uin // --- Disk Driver Helpers --- Uint64 DrvUtil_ReadBlock(Uint64 Start, Uint64 Length, void *Buffer, - tDrvUtil_Callback ReadBlocks, Uint64 BlockSize, Uint Argument) + tDrvUtil_Read_Callback ReadBlocks, Uint64 BlockSize, Uint Argument) { Uint8 tmp[BlockSize]; // C99 Uint64 block = Start / BlockSize; @@ -550,8 +625,8 @@ Uint64 DrvUtil_ReadBlock(Uint64 Start, Uint64 Length, void *Buffer, return Length; } -Uint64 DrvUtil_WriteBlock(Uint64 Start, Uint64 Length, void *Buffer, - tDrvUtil_Callback ReadBlocks, tDrvUtil_Callback WriteBlocks, +Uint64 DrvUtil_WriteBlock(Uint64 Start, Uint64 Length, const void *Buffer, + tDrvUtil_Read_Callback ReadBlocks, tDrvUtil_Write_Callback WriteBlocks, Uint64 BlockSize, Uint Argument) { Uint8 tmp[BlockSize]; // C99