Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 22 Jan 2001 20:45:19 +0200
From:      Maxim Sobolev <sobomax@FreeBSD.org>
To:        current@FreeBSD.org, sos@FreeBSD.org, nsouch@alcove.fr
Subject:   [RFC] New features for libvgl
Message-ID:  <3A6C7FBF.251B4C89@FreeBSD.org>

next in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format.
--------------3933D2980D4C5D0799F56951
Content-Type: text/plain; charset=x-user-defined
Content-Transfer-Encoding: 7bit

Hi folks,

Now I'm in process of  writing a libvgl driver for SDL (almost finished - I'm
testing it right now) and found that two handy features are currently missed
from the libvgl: ability to query video modes supported by the video hardware
and ability to install custom mouse eventhandler. So I extended libvgl
attaching patches with this message. I would like that someone review/comment
attached patches. Please also note that VGLListModes() part of these patches
are not optimal right now (it largely duplicates VGLInit()), so please
concentrate on concept rather than on implementation details.

Thanks!

-Maxim

--------------3933D2980D4C5D0799F56951
Content-Type: text/plain; charset=x-user-defined;
 name="libvgl.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="libvgl.patch"

Index: bitmap.c
===================================================================
RCS file: /home/ncvs/src/lib/libvgl/bitmap.c,v
retrieving revision 1.6
diff -d -u -r1.6 bitmap.c
--- bitmap.c	2001/01/13 11:30:12	1.6
+++ bitmap.c	2001/01/22 18:25:23
@@ -30,6 +30,7 @@
 
 #include <sys/types.h>
 #include <signal.h>
+#include <sys/consio.h>
 #include <sys/fbio.h>
 #include "vgl.h"
 
Index: keyboard.c
===================================================================
RCS file: /home/ncvs/src/lib/libvgl/keyboard.c,v
retrieving revision 1.4
diff -d -u -r1.4 keyboard.c
--- keyboard.c	2000/10/08 21:33:46	1.4
+++ keyboard.c	2001/01/22 18:25:23
@@ -33,6 +33,7 @@
 #include <sys/ioctl.h>
 #include <termios.h>
 #include <sys/time.h>
+#include <sys/consio.h>
 #include <sys/fbio.h>
 #include <sys/kbio.h>
 #include "vgl.h"
Index: main.c
===================================================================
RCS file: /home/ncvs/src/lib/libvgl/main.c,v
retrieving revision 1.8
diff -d -u -r1.8 main.c
--- main.c	2001/01/13 11:30:16	1.8
+++ main.c	2001/01/22 18:25:23
@@ -49,7 +49,7 @@
 video_adapter_info_t VGLAdpInfo;
 byte *VGLBuf;
 
-static int VGLMode;
+static int VGLCurModeId;
 static int VGLOldMode;
 static size_t VGLBufSize;
 static byte *VGLMem = MAP_FAILED;
@@ -159,6 +159,7 @@
    * vi_mem_model specifies the memory model of the current video mode
    * in -CURRENT.
    */
+  VGLDisplay->PixelBytes = 1;
   switch (VGLModeInfo.vi_mem_model) {
   case V_INFO_MM_PLANAR:
     /* we can handle EGA/VGA planner modes only */
@@ -267,7 +268,7 @@
     }
   }
 
-  VGLMode = mode;
+  VGLCurModeId = mode;
   VGLCurWindow = 0;
 
   VGLDisplay->Xsize = VGLModeInfo.vi_width;
@@ -290,9 +291,10 @@
 
 #ifdef LIBVGL_DEBUG
   fprintf(stderr, "va_line_width:%d\n", VGLAdpInfo.va_line_width);
-  fprintf(stderr, "VGLXsize:%d, Ysize:%d, VXsize:%d, VYsize:%d\n",
+  fprintf(stderr, "VGLXsize:%d, Ysize:%d, VXsize:%d, VYsize:%d, Type:%d\n",
 	  VGLDisplay->Xsize, VGLDisplay->Ysize, 
-	  VGLDisplay->VXsize, VGLDisplay->VYsize);
+	  VGLDisplay->VXsize, VGLDisplay->VYsize,
+	  VGLDisplay->Type);
 #endif
 
   smode.mode = VT_PROCESS;
@@ -321,7 +323,7 @@
     if (VGLOnDisplay) {
       ioctl(0, KDENABIO, 0);
       ioctl(0, KDSETMODE, KD_GRAPHICS);
-      ioctl(0, VGLMode, 0);
+      ioctl(0, VGLCurModeId, 0);
       VGLCurWindow = 0;
       VGLMem = (byte*)mmap(0, VGLAdpInfo.va_window_size, PROT_READ|PROT_WRITE,
 			   MAP_FILE, 0, 0);
@@ -547,4 +549,118 @@
 #endif
 
   return 0;
+}
+
+VGLMode **
+VGLListModes(int depth, int mem_model)
+{
+  static VGLMode **modes = NULL;
+
+  VGLBitmap *vminfop;
+  VGLMode **modesp, *modescp;
+  video_info_t minfo;
+  int adptype, i, modenum;
+
+  if (modes == NULL) {
+    modes = malloc(sizeof(VGLMode *) * M_VESA_MODE_MAX);
+    bzero(modes, sizeof(VGLMode *) * M_VESA_MODE_MAX);
+  }
+  modesp = modes;
+
+  for (modenum = 0; modenum < M_VESA_MODE_MAX; modenum++) {
+    minfo.vi_mode = modenum;
+    if (ioctl(0, CONS_MODEINFO, &minfo) || ioctl(0, CONS_CURRENT, &adptype))
+      continue;
+    if (minfo.vi_mode != modenum)
+      continue;
+    if ((minfo.vi_flags & V_INFO_GRAPHICS) == 0)
+      continue;
+    if ((mem_model != -1) && ((minfo.vi_mem_model & mem_model) == 0))
+      continue;
+    if ((depth > 1) && (minfo.vi_depth != depth))
+      continue;
+
+    /* reallocf can fail */
+    if ((*modesp = reallocf(*modesp, sizeof(VGLMode))) == NULL)
+      return NULL;
+    modescp = *modesp;
+
+    vminfop = &(modescp->ModeInfo);
+    bzero(vminfop, sizeof(VGLBitmap));
+
+    vminfop->Type = NOBUF;
+
+    vminfop->PixelBytes = 1;	/* Good default value */
+    switch (minfo.vi_mem_model) {
+    case V_INFO_MM_PLANAR:
+      /* we can handle EGA/VGA planar modes only */
+      if (!(minfo.vi_depth != 4 || minfo.vi_planes != 4
+	    || (adptype != KD_EGA && adptype != KD_VGA)))
+	vminfop->Type = VIDBUF4;
+      break;
+    case V_INFO_MM_PACKED:
+      /* we can do only 256 color packed modes */
+      if (minfo.vi_depth == 8)
+	vminfop->Type = VIDBUF8;
+      break;
+    case V_INFO_MM_VGAX:
+      vminfop->Type = VIDBUF8X;
+      break;
+    case V_INFO_MM_DIRECT:
+      vminfop->PixelBytes = minfo.vi_pixel_size;
+      switch (vminfop->PixelBytes) {
+      case 2:
+	vminfop->Type = VIDBUF16;
+	break;
+#if notyet
+      case 3:
+	vminfop->Type = VIDBUF24;
+	break;
+#endif
+      case 4:
+	vminfop->Type = VIDBUF32;
+	break;
+      default:
+	break;
+      }
+    default:
+      break;
+    }
+    if (vminfop->Type == NOBUF)
+      continue;
+
+    vminfop->Xsize = minfo.vi_width;
+    vminfop->Ysize = minfo.vi_height;
+    modescp->Depth = minfo.vi_depth;
+
+    /* XXX */
+    if (minfo.vi_mode >= M_VESA_BASE)
+      modescp->ModeId = _IO('V', minfo.vi_mode - M_VESA_BASE);
+    else
+      modescp->ModeId = _IO('S', minfo.vi_mode);
+
+    /* Sort list */
+    for (i = 0; modes + i < modesp ; i++) {
+      if (modes[i]->ModeInfo.Xsize * modes[i]->ModeInfo.Ysize >
+	  vminfop->Xsize * modes[i]->ModeInfo.Ysize)
+	continue;
+      if ((modes[i]->ModeInfo.Xsize * modes[i]->ModeInfo.Ysize ==
+	   vminfop->Xsize * vminfop->Ysize) &&
+	  (modes[i]->Depth >= modescp->Depth))
+	continue;
+      *modesp = modes[i];
+      modes[i] = modescp;
+      modescp = *modesp;
+      vminfop = &(modescp->ModeInfo);
+    }
+
+    modesp++;
+  }
+
+  if (*modesp != NULL) {
+    free(*modesp);
+    *modesp = NULL;
+  }
+
+  return modes;
 }
Index: mouse.c
===================================================================
RCS file: /home/ncvs/src/lib/libvgl/mouse.c,v
retrieving revision 1.4
diff -d -u -r1.4 mouse.c
--- mouse.c	2000/10/08 21:33:46	1.4
+++ mouse.c	2001/01/22 18:25:28
@@ -89,6 +89,8 @@
 static int VGLMouseYpos = 0;
 static int VGLMouseButtons = 0;
 
+static mouse_handler_t VGLMouseHandler = NULL;
+
 void
 VGLMousePointerShow()
 {
@@ -161,12 +163,17 @@
 {
   struct mouse_info mouseinfo;
 
+  mouseinfo.operation = MOUSE_GETINFO;
+  ioctl(0, CONS_MOUSECTL, &mouseinfo);
+
+  if (VGLMouseHandler != NULL) {
+    VGLMouseHandler(mouseinfo);
+  }
+
   if (VGLMouseFrozen) {
     VGLMouseFrozen++;
     return;
   }
-  mouseinfo.operation = MOUSE_GETINFO;
-  ioctl(0, CONS_MOUSECTL, &mouseinfo);
   if (VGLMouseShown == VGL_MOUSESHOW)
     VGLMousePointerHide();
   VGLMouseXpos = mouseinfo.u.data.x;
@@ -281,4 +288,10 @@
     if (VGLMouseShown == VGL_MOUSESHOW && !VGLMouseVisible)
       VGLMousePointerShow();
   }
+}
+
+void
+VGLSetMouseHandler(mouse_handler_t mousehandler)
+{
+  VGLMouseHandler = mousehandler;
 }
Index: simple.c
===================================================================
RCS file: /home/ncvs/src/lib/libvgl/simple.c,v
retrieving revision 1.6
diff -d -u -r1.6 simple.c
--- simple.c	2001/01/13 11:30:16	1.6
+++ simple.c	2001/01/22 18:25:28
@@ -29,6 +29,7 @@
  */
 
 #include <signal.h>
+#include <sys/consio.h>
 #include <sys/fbio.h>
 #include "vgl.h"
 
Index: text.c
===================================================================
RCS file: /home/ncvs/src/lib/libvgl/text.c,v
retrieving revision 1.5
diff -d -u -r1.5 text.c
--- text.c	2000/10/08 21:33:46	1.5
+++ text.c	2001/01/22 18:25:28
@@ -29,6 +29,7 @@
  */
 
 #include <stdio.h>
+#include <sys/consio.h>
 #include <sys/fbio.h>
 #include "vgl.h"
 
Index: vgl.h
===================================================================
RCS file: /home/ncvs/src/lib/libvgl/vgl.h,v
retrieving revision 1.6
diff -d -u -r1.6 vgl.h
--- vgl.h	2001/01/13 11:30:17	1.6
+++ vgl.h	2001/01/22 18:25:28
@@ -79,6 +79,15 @@
   int		(*CallBackFunction)();
 } VGLObject;
 
+typedef struct {
+  int ModeId;
+  int Depth;
+  VGLBitmap ModeInfo;
+} VGLMode;
+
+/* Type for the custom mouse handling function */
+typedef void (*mouse_handler_t)(mouse_info_t info);
+
 #define MOUSE_IMG_SIZE		16
 #define VGL_MOUSEHIDE		0
 #define VGL_MOUSESHOW		1
@@ -117,6 +126,7 @@
 int VGLSetVScreenSize(VGLBitmap *object, int VXsize, int VYsize);
 int VGLPanScreen(VGLBitmap *object, int x, int y);
 int VGLSetSegment(unsigned int offset);
+VGLMode ** VGLListModes(int depth, int mem_model);
 /* mouse.c */
 void VGLMousePointerShow(void);
 void VGLMousePointerHide(void);
@@ -128,6 +138,7 @@
 int VGLMouseStatus(int *x, int *y, char *buttons);
 int VGLMouseFreeze(int x, int y, int width, int hight, byte color);
 void VGLMouseUnFreeze(void);
+void VGLSetMouseHandler(mouse_handler_t mousehandler);
 /* simple.c */
 void VGLSetXY(VGLBitmap *object, int x, int y, u_long color);
 u_long VGLGetXY(VGLBitmap *object, int x, int y);

--------------3933D2980D4C5D0799F56951--



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3A6C7FBF.251B4C89>