Modules/VESA - Added cursor support (with blinking)
authorJohn Hodge <[email protected]>
Sat, 22 Oct 2011 07:08:14 +0000 (15:08 +0800)
committerJohn Hodge <[email protected]>
Sat, 22 Oct 2011 07:08:14 +0000 (15:08 +0800)
Kernel/drvutil.c
Modules/Display/VESA/main.c

index 00bfb78..8847ae2 100644 (file)
@@ -28,6 +28,28 @@ tDrvUtil_Video_2DHandlers    gDrvUtil_Stub_2DFunctions = {
        DrvUtil_Video_2D_Fill,
        DrvUtil_Video_2D_Blit
 };
+tVideo_IOCtl_Bitmap    gDrvUtil_TextModeCursor = {
+       8, 16,
+       0, 0,
+       {
+                0, 0         , 0, 0, 0, 0, 0, 0,
+               -1, 0xFF000000, 0, 0, 0, 0, 0, 0,
+               -1, 0xFF000000, 0, 0, 0, 0, 0, 0,
+               -1, 0xFF000000, 0, 0, 0, 0, 0, 0,
+               -1, 0xFF000000, 0, 0, 0, 0, 0, 0,
+               -1, 0xFF000000, 0, 0, 0, 0, 0, 0,
+               -1, 0xFF000000, 0, 0, 0, 0, 0, 0,
+               -1, 0xFF000000, 0, 0, 0, 0, 0, 0,
+               -1, 0xFF000000, 0, 0, 0, 0, 0, 0,
+               -1, 0xFF000000, 0, 0, 0, 0, 0, 0,
+               -1, 0xFF000000, 0, 0, 0, 0, 0, 0,
+               -1, 0xFF000000, 0, 0, 0, 0, 0, 0,
+               -1, 0xFF000000, 0, 0, 0, 0, 0, 0,
+               -1, 0xFF000000, 0, 0, 0, 0, 0, 0,
+               -1, 0xFF000000, 0, 0, 0, 0, 0, 0,
+                0, 0         , 0, 0, 0, 0, 0, 0
+       }
+};
 
 // === CODE ===
 // --- Video Driver Helpers ---
@@ -221,7 +243,8 @@ void DrvUtil_Video_SetCursor(tDrvUtil_Video_BufInfo *Buf, tVideo_IOCtl_Bitmap *B
                        free( Buf->CursorSaveBuf );
                        Buf->CursorSaveBuf = NULL;
                }
-               free(Buf->CursorBitmap);
+               if( Buf->CursorBitmap != &gDrvUtil_TextModeCursor)
+                       free(Buf->CursorBitmap);
                Buf->CursorBitmap = NULL;
        }
        
@@ -233,16 +256,23 @@ void DrvUtil_Video_SetCursor(tDrvUtil_Video_BufInfo *Buf, tVideo_IOCtl_Bitmap *B
                return ;
        }
 
-       // Check the new bitmap is valid
-       size = sizeof(tVideo_IOCtl_Bitmap) + Bitmap->W*Bitmap->H*4;
-       if( !CheckMem(Bitmap, size) ) {
-               Log_Warning("DrvUtil", "DrvUtil_Video_SetCursor: Bitmap (%p) is in invalid memory", Bitmap);
-               return;
+       if( Bitmap != &gDrvUtil_TextModeCursor )
+       {
+               // Check the new bitmap is valid
+               size = sizeof(tVideo_IOCtl_Bitmap) + Bitmap->W*Bitmap->H*4;
+               if( !CheckMem(Bitmap, size) ) {
+                       Log_Warning("DrvUtil", "DrvUtil_Video_SetCursor: Bitmap (%p) is in invalid memory", Bitmap);
+                       return;
+               }
+               
+               // Take a copy
+               Buf->CursorBitmap = malloc( size );
+               memcpy(Buf->CursorBitmap, Bitmap, size);
+       }
+       else
+       {
+               Buf->CursorBitmap = &gDrvUtil_TextModeCursor;
        }
-       
-       // Take a copy
-       Buf->CursorBitmap = malloc( size );
-       memcpy(Buf->CursorBitmap, Bitmap, size);
        
        // Restore cursor position
        DrvUtil_Video_DrawCursor(Buf, csrX, csrY);
@@ -252,9 +282,11 @@ void DrvUtil_Video_DrawCursor(tDrvUtil_Video_BufInfo *Buf, int X, int Y)
 {
         int    render_ox=0, render_oy=0, render_w, render_h;
 
+       DrvUtil_Video_RemoveCursor(Buf);
+
        // X < 0 disables the cursor
        if( X < 0 ) {
-               Render->CursorX = -1;
+               Buf->CursorX = -1;
                return ;
        }
 
@@ -300,6 +332,8 @@ 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;
        
@@ -348,6 +382,8 @@ void DrvUtil_Video_RemoveCursor(tDrvUtil_Video_BufInfo *Buf)
        if( !Buf->CursorBitmap || Buf->CursorX == -1 )  return ;
        if( !Buf->CursorSaveBuf )       return ;
 
+//     Debug("DrvUtil_Video_RemoveCursor: (Buf=%p) dest_x=%i, dest_y=%i", Buf, Buf->CursorDestX, Buf->CursorDestY);
+
        // Set up
        save_pitch = Buf->CursorBitmap->W * bytes_per_px;
        dest = (Uint8*)Buf->Framebuffer + Buf->CursorDestY * Buf->Pitch + Buf->CursorDestX*bytes_per_px;
index 02689ea..490e841 100644 (file)
@@ -30,9 +30,6 @@ Uint64        Vesa_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer);
  int   Vesa_Int_FindMode(tVideo_IOCtl_Mode *data);\r
  int   Vesa_Int_ModeInfo(tVideo_IOCtl_Mode *data);\r
 void   Vesa_FlipCursor(void *Arg);\r
-// --- 2D Acceleration Functions --\r
-void   Vesa_2D_Fill(void *Ent, Uint16 X, Uint16 Y, Uint16 W, Uint16 H, Uint32 Colour);\r
-void   Vesa_2D_Blit(void *Ent, Uint16 DstX, Uint16 DstY, Uint16 SrcX, Uint16 SrcY, Uint16 W, Uint16 H);\r
 \r
 // === GLOBALS ===\r
 MODULE_DEFINE(0, VERSION, Vesa, Vesa_Install, NULL, "PCI", "VM8086", NULL);\r
@@ -59,12 +56,8 @@ char *gpVesa_Framebuffer = (void*)VESA_DEFAULT_FRAMEBUFFER;
  int   giVesaCursorX = -1;\r
  int   giVesaCursorY = -1;\r
  int   giVesaCursorTimer = -1; // Invalid timer\r
+ int   gbVesa_CursorVisible = 0;\r
 // --- 2D Video Stream Handlers ---\r
-tDrvUtil_Video_2DHandlers      gVesa_2DFunctions = {\r
-       NULL,\r
-       Vesa_2D_Fill,\r
-       Vesa_2D_Blit\r
-};\r
 tDrvUtil_Video_BufInfo gVesa_BufInfo;\r
 \r
 // === CODE ===\r
@@ -197,42 +190,48 @@ int Vesa_IOCtl(tVFS_Node *Node, int ID, void *Data)
                return Vesa_Int_ModeInfo((tVideo_IOCtl_Mode*)Data);\r
        \r
        case VIDEO_IOCTL_SETBUFFORMAT:\r
+               DrvUtil_Video_DrawCursor( &gVesa_BufInfo, -1, -1 );\r
+               giVesaCursorX = -1;\r
+               #if BLINKING_CURSOR\r
+               if(giVesaCursorTimer != -1) {\r
+                       Time_RemoveTimer(giVesaCursorTimer);\r
+                       giVesaCursorTimer = -1;\r
+               }\r
+               #endif\r
                ret = gVesa_BufInfo.BufferFormat;\r
                if(Data)        gVesa_BufInfo.BufferFormat = *(int*)Data;\r
+               if(gVesa_BufInfo.BufferFormat == VIDEO_BUFFMT_TEXT)\r
+                       DrvUtil_Video_SetCursor( &gVesa_BufInfo, &gDrvUtil_TextModeCursor );\r
                return ret;\r
        \r
        case VIDEO_IOCTL_SETCURSOR:     // Set cursor position\r
-               #if !BLINKING_CURSOR\r
-               if(giVesaCursorX >= 0)\r
-                       Vesa_FlipCursor(Node);\r
+               DrvUtil_Video_RemoveCursor( &gVesa_BufInfo );\r
+               #if BLINKING_CURSOR\r
+               if(giVesaCursorTimer != -1) {\r
+                       Time_RemoveTimer(giVesaCursorTimer);\r
+                       giVesaCursorTimer = -1;\r
+               }\r
                #endif\r
                giVesaCursorX = ((tVideo_IOCtl_Pos*)Data)->x;\r
                giVesaCursorY = ((tVideo_IOCtl_Pos*)Data)->y;\r
-               //Log_Debug("VESA", "Cursor position (%i,%i)", giVesaCursorX, giVesaCursorY);\r
-               if(\r
-                       giVesaCursorX < 0 || giVesaCursorY < 0\r
-               ||      giVesaCursorX >= gpVesaCurMode->width/giVT_CharWidth\r
-               ||      giVesaCursorY >= gpVesaCurMode->height/giVT_CharHeight)\r
+               gbVesa_CursorVisible = (giVesaCursorX >= 0);\r
+               if(gVesa_BufInfo.BufferFormat == VIDEO_BUFFMT_TEXT)\r
                {\r
+                       DrvUtil_Video_DrawCursor(\r
+                               &gVesa_BufInfo,\r
+                               giVesaCursorX*giVT_CharWidth,\r
+                               giVesaCursorY*giVT_CharHeight\r
+                               );\r
                        #if BLINKING_CURSOR\r
-                       if(giVesaCursorTimer != -1) {\r
-                               Time_RemoveTimer(giVesaCursorTimer);\r
-                               giVesaCursorTimer = -1;\r
-                       }\r
-                       #endif\r
-                       giVesaCursorX = -1;\r
-                       giVesaCursorY = -1;\r
-               }\r
-               else {\r
-                       #if BLINKING_CURSOR\r
-               //      Log_Debug("VESA", "Updating timer %i?", giVesaCursorTimer);\r
-                       if(giVesaCursorTimer == -1)\r
-                               giVesaCursorTimer = Time_CreateTimer(VESA_CURSOR_PERIOD, Vesa_FlipCursor, Node);\r
-                       #else\r
-                       Vesa_FlipCursor(Node);\r
+                       giVesaCursorTimer = Time_CreateTimer(VESA_CURSOR_PERIOD, Vesa_FlipCursor, NULL);\r
                        #endif\r
                }\r
-               //Log_Debug("VESA", "Cursor position (%i,%i) Timer %i", giVesaCursorX, giVesaCursorY, giVesaCursorTimer);\r
+               else\r
+                       DrvUtil_Video_DrawCursor(\r
+                               &gVesa_BufInfo,\r
+                               giVesaCursorX,\r
+                               giVesaCursorY\r
+                               );\r
                return 0;\r
        }\r
        return 0;\r
@@ -368,120 +367,20 @@ int Vesa_Int_ModeInfo(tVideo_IOCtl_Mode *data)
  */\r
 void Vesa_FlipCursor(void *Arg)\r
 {\r
-        int    pitch = gpVesaCurMode->pitch;\r
-        int    bytes_per_px = (gpVesaCurMode->bpp + 7) / 8;\r
-        int    x = giVesaCursorX*giVT_CharWidth;\r
-        int    y = giVesaCursorY*giVT_CharHeight;\r
-        int    i;\r
-       Uint8   *fb = (void*)gpVesa_Framebuffer;\r
-       \r
-       //Debug("Cursor flip");\r
-       \r
-       // Sanity check\r
-       if(giVesaCursorX < 0 || giVesaCursorY < 0\r
-       || y*pitch + x + (giVT_CharHeight-1)*pitch > (int)gpVesaCurMode->fbSize) {\r
-               Log_Notice("VESA", "Cursor OOB (%i,%i)", x, y);\r
-               giVesaCursorTimer = -1;\r
-               return;\r
-       }\r
-       \r
-       // Draw cursor\r
-       fb += (y+1)*pitch + x*bytes_per_px;\r
-       \r
-       switch(bytes_per_px)\r
-       {\r
-       case 1:\r
-               for( i = 1; i < giVT_CharHeight-1; i++, fb += pitch )\r
-                       *fb = ~*fb;\r
-               break;\r
-       case 2:\r
-               for( i = 1; i < giVT_CharHeight-1; i++, fb += pitch ) {\r
-                       fb[0] = ~fb[0];\r
-                       fb[1] = ~fb[1];\r
-               }\r
-               break;\r
-       case 3:\r
-               for( i = 1; i < giVT_CharHeight-1; i++, fb += pitch ) {\r
-                       fb[0] = ~fb[0];\r
-                       fb[1] = ~fb[1];\r
-                       fb[2] = ~fb[2];\r
-               }\r
-               break;\r
-       case 4:\r
-               for( i = 1; i < giVT_CharHeight-1; i++, fb += pitch ) {\r
-                       fb[0] = ~fb[0];\r
-                       fb[1] = ~fb[1];\r
-                       fb[2] = ~fb[2];\r
-                       fb[3] = ~fb[3];\r
-               }\r
-               break;\r
-       default:\r
-               Log_Error("VESA", "Vesa_FlipCursor - Bug Report, unknown bytes_per_px (%i)", bytes_per_px);\r
-               giVesaCursorTimer = -1;\r
+       if( gVesa_BufInfo.BufferFormat != VIDEO_BUFFMT_TEXT )\r
                return ;\r
-       }\r
-       \r
+\r
+       if( gbVesa_CursorVisible )\r
+               DrvUtil_Video_RemoveCursor(&gVesa_BufInfo);\r
+       else\r
+               DrvUtil_Video_DrawCursor(&gVesa_BufInfo,\r
+                       giVesaCursorX*giVT_CharWidth,\r
+                       giVesaCursorY*giVT_CharHeight\r
+                       );\r
+       gbVesa_CursorVisible = !gbVesa_CursorVisible;\r
+               \r
        #if BLINKING_CURSOR\r
        giVesaCursorTimer = Time_CreateTimer(VESA_CURSOR_PERIOD, Vesa_FlipCursor, Arg);\r
        #endif\r
 }\r
 \r
-// ------------------------\r
-// --- 2D Accelleration ---\r
-// ------------------------\r
-void Vesa_2D_Fill(void *Ent, Uint16 X, Uint16 Y, Uint16 W, Uint16 H, Uint32 Colour)\r
-{\r
-       // TODO: Handle non-32bit modes\r
-        int    pitch = gpVesaCurMode->pitch/4;\r
-       Uint32  *buf = (Uint32*)gpVesa_Framebuffer + Y*pitch + X;\r
-       while( H -- ) {\r
-               memsetd(buf, Colour, W);\r
-               buf += pitch;\r
-       }\r
-}\r
-\r
-void Vesa_2D_Blit(void *Ent, Uint16 DstX, Uint16 DstY, Uint16 SrcX, Uint16 SrcY, Uint16 W, Uint16 H)\r
-{\r
-        int    scrnpitch = gpVesaCurMode->pitch;\r
-        int    bytes_per_px = (gpVesaCurMode->bpp + 7) / 8;\r
-        int    dst = DstY*scrnpitch + DstX;\r
-        int    src = SrcY*scrnpitch + SrcX;\r
-        int    tmp;\r
-       \r
-       //Log("Vesa_2D_Blit: (Ent=%p, DstX=%i, DstY=%i, SrcX=%i, SrcY=%i, W=%i, H=%i)",\r
-       //      Ent, DstX, DstY, SrcX, SrcY, W, H);\r
-       \r
-       if(SrcX + W > gpVesaCurMode->width)\r
-               W = gpVesaCurMode->width - SrcX;\r
-       if(DstX + W > gpVesaCurMode->width)\r
-               W = gpVesaCurMode->width - DstX;\r
-       if(SrcY + H > gpVesaCurMode->height)\r
-               H = gpVesaCurMode->height - SrcY;\r
-       if(DstY + H > gpVesaCurMode->height)\r
-               H = gpVesaCurMode->height - DstY;\r
-       \r
-       //Debug("W = %i, H = %i", W, H);\r
-       \r
-       if( dst > src ) {\r
-               // Reverse copy\r
-               dst += H*scrnpitch;\r
-               src += H*scrnpitch;\r
-               while( H -- ) {\r
-                       dst -= scrnpitch;\r
-                       src -= scrnpitch;\r
-                       tmp = W*bytes_per_px;\r
-                       for( tmp = W; tmp --; ) {\r
-                               *(Uint8*)(gpVesa_Framebuffer + dst + tmp) = *(Uint8*)(gpVesa_Framebuffer + src + tmp);\r
-                       }\r
-               }\r
-       }\r
-       else {\r
-               // Normal copy is OK\r
-               while( H -- ) {\r
-                       memcpy((void*)gpVesa_Framebuffer + dst, (void*)gpVesa_Framebuffer + src, W*bytes_per_px);\r
-                       dst += scrnpitch;\r
-                       src += scrnpitch;\r
-               }\r
-       }\r
-       //Log("Vesa_2D_Blit: RETURN");\r
-}\r

UCC git Repository :: git.ucc.asn.au