svn commit: r346454 - head/lib/libvgl

2019-09-03 Thread Bruce Evans
Author: bde
Date: Sat Apr 20 20:29:03 2019
New Revision: 346454
URL: https://svnweb.freebsd.org/changeset/base/346454

Log:
  Make libvgl mostly work without superuser privilege in direct modes by
  not doing any unnecessary PIO instructions or refusing to start when the
  i/o privilege needed for these instructions cannot be acquired.
  
  This turns off useless palette management in direct modes.  Palette
  management had no useful effect since the hardware palette is not used
  in these modes.
  
  This transiently acquires i/o privilege if possible as needed to give
  VGLSetBorder() and VGLBlankDisplay() a chance of working.  Neither has
  much chance of working.  I was going to drop support for them in direct
  modes, but found that VGLBlankDisplay() still works with an old graphics
  card on a not so old LCD monitor.
  
  This has some good side effects: reduce glitches for managing the palette
  for screen switches, and speed up and reduce async-signal-unsafeness in
  mouse cursor drawing.

Modified:
  head/lib/libvgl/main.c
  head/lib/libvgl/mouse.c
  head/lib/libvgl/simple.c

Modified: head/lib/libvgl/main.c
==
--- head/lib/libvgl/main.c  Sat Apr 20 17:16:36 2019(r346453)
+++ head/lib/libvgl/main.c  Sat Apr 20 20:29:03 2019(r346454)
@@ -93,7 +93,8 @@ struct vt_mode smode;
 size[2] = VGLOldVInfo.font_size;;
 ioctl(0, KDRASTER, size);
   }
-  ioctl(0, KDDISABIO, 0);
+  if (VGLModeInfo.vi_mem_model != V_INFO_MM_DIRECT)
+ioctl(0, KDDISABIO, 0);
   ioctl(0, KDSETMODE, KD_TEXT);
   smode.mode = VT_AUTO;
   ioctl(0, VT_SETMODE, );
@@ -176,7 +177,7 @@ VGLInit(int mode)
   if (VGLDisplay == NULL)
 return -2;
 
-  if (ioctl(0, KDENABIO, 0)) {
+  if (VGLModeInfo.vi_mem_model != V_INFO_MM_DIRECT && ioctl(0, KDENABIO, 0)) {
 free(VGLDisplay);
 return -3;
   }
@@ -370,7 +371,8 @@ VGLCheckSwitch()
 
 VGLSwitchPending = 0;
 if (VGLOnDisplay) {
-  ioctl(0, KDENABIO, 0);
+  if (VGLModeInfo.vi_mem_model != V_INFO_MM_DIRECT)
+ioctl(0, KDENABIO, 0);
   ioctl(0, KDSETMODE, KD_GRAPHICS);
   ioctl(0, VGLMode, 0);
   VGLCurWindow = 0;
@@ -531,7 +533,8 @@ VGLCheckSwitch()
   munmap(VGLDisplay->Bitmap, VGLAdpInfo.va_window_size);
   ioctl(0, VGLOldMode, 0);
   ioctl(0, KDSETMODE, KD_TEXT);
-  ioctl(0, KDDISABIO, 0);
+  if (VGLModeInfo.vi_mem_model != V_INFO_MM_DIRECT)
+ioctl(0, KDDISABIO, 0);
   ioctl(0, VT_RELDISP, VT_TRUE);
   VGLDisplay->Bitmap = VGLBuf;
   VGLDisplay->Type = MEMBUF;

Modified: head/lib/libvgl/mouse.c
==
--- head/lib/libvgl/mouse.c Sat Apr 20 17:16:36 2019(r346453)
+++ head/lib/libvgl/mouse.c Sat Apr 20 20:29:03 2019(r346454)
@@ -111,10 +111,12 @@ VGLMousePointerShow()
   if (!VGLMouseVisible) {
 INTOFF();
 VGLMouseVisible = 1;
-crtcidx = inb(0x3c4);
-crtcval = inb(0x3c5);
-gdcidx = inb(0x3ce);
-gdcval = inb(0x3cf);
+if (VGLModeInfo.vi_mem_model != V_INFO_MM_DIRECT) {
+  crtcidx = inb(0x3c4);
+  crtcval = inb(0x3c5);
+  gdcidx = inb(0x3ce);
+  gdcval = inb(0x3cf);
+}
 __VGLBitmapCopy(VGLDisplay, VGLMouseXpos, VGLMouseYpos, 
  , 0, 0, MOUSE_IMG_SIZE, MOUSE_IMG_SIZE);
 bcopy(VGLMouseSave.Bitmap, buffer.Bitmap,
@@ -128,10 +130,12 @@ VGLMousePointerShow()
   }
 __VGLBitmapCopy(, 0, 0, VGLDisplay, 
  VGLMouseXpos, VGLMouseYpos, MOUSE_IMG_SIZE, MOUSE_IMG_SIZE);
-outb(0x3c4, crtcidx);
-outb(0x3c5, crtcval);
-outb(0x3ce, gdcidx);
-outb(0x3cf, gdcval);
+if (VGLModeInfo.vi_mem_model != V_INFO_MM_DIRECT) {
+  outb(0x3c4, crtcidx);
+  outb(0x3c5, crtcval);
+  outb(0x3ce, gdcidx);
+  outb(0x3cf, gdcval);
+}
 INTON();
   }
 }
@@ -144,16 +148,20 @@ VGLMousePointerHide()
   if (VGLMouseVisible) {
 INTOFF();
 VGLMouseVisible = 0;
-crtcidx = inb(0x3c4);
-crtcval = inb(0x3c5);
-gdcidx = inb(0x3ce);
-gdcval = inb(0x3cf);
+if (VGLModeInfo.vi_mem_model != V_INFO_MM_DIRECT) {
+  crtcidx = inb(0x3c4);
+  crtcval = inb(0x3c5);
+  gdcidx = inb(0x3ce);
+  gdcval = inb(0x3cf);
+}
 __VGLBitmapCopy(, 0, 0, VGLDisplay, 
  VGLMouseXpos, VGLMouseYpos, MOUSE_IMG_SIZE, MOUSE_IMG_SIZE);
-outb(0x3c4, crtcidx);
-outb(0x3c5, crtcval);
-outb(0x3ce, gdcidx);
-outb(0x3cf, gdcval);
+if (VGLModeInfo.vi_mem_model != V_INFO_MM_DIRECT) {
+  outb(0x3c4, crtcidx);
+  outb(0x3c5, crtcval);
+  outb(0x3ce, gdcidx);
+  outb(0x3cf, gdcval);
+}
 INTON();
   }
 }

Modified: head/lib/libvgl/simple.c
==
--- head/lib/libvgl/simple.cSat Apr 20 17:16:36 2019(r346453)
+++ head/lib/libvgl/simple.cSat Apr 20 20:29:03 2019

svn commit: r346454 - head/lib/libvgl

2019-04-20 Thread Bruce Evans
Author: bde
Date: Sat Apr 20 20:29:03 2019
New Revision: 346454
URL: https://svnweb.freebsd.org/changeset/base/346454

Log:
  Make libvgl mostly work without superuser privilege in direct modes by
  not doing any unnecessary PIO instructions or refusing to start when the
  i/o privilege needed for these instructions cannot be acquired.
  
  This turns off useless palette management in direct modes.  Palette
  management had no useful effect since the hardware palette is not used
  in these modes.
  
  This transiently acquires i/o privilege if possible as needed to give
  VGLSetBorder() and VGLBlankDisplay() a chance of working.  Neither has
  much chance of working.  I was going to drop support for them in direct
  modes, but found that VGLBlankDisplay() still works with an old graphics
  card on a not so old LCD monitor.
  
  This has some good side effects: reduce glitches for managing the palette
  for screen switches, and speed up and reduce async-signal-unsafeness in
  mouse cursor drawing.

Modified:
  head/lib/libvgl/main.c
  head/lib/libvgl/mouse.c
  head/lib/libvgl/simple.c

Modified: head/lib/libvgl/main.c
==
--- head/lib/libvgl/main.c  Sat Apr 20 17:16:36 2019(r346453)
+++ head/lib/libvgl/main.c  Sat Apr 20 20:29:03 2019(r346454)
@@ -93,7 +93,8 @@ struct vt_mode smode;
 size[2] = VGLOldVInfo.font_size;;
 ioctl(0, KDRASTER, size);
   }
-  ioctl(0, KDDISABIO, 0);
+  if (VGLModeInfo.vi_mem_model != V_INFO_MM_DIRECT)
+ioctl(0, KDDISABIO, 0);
   ioctl(0, KDSETMODE, KD_TEXT);
   smode.mode = VT_AUTO;
   ioctl(0, VT_SETMODE, );
@@ -176,7 +177,7 @@ VGLInit(int mode)
   if (VGLDisplay == NULL)
 return -2;
 
-  if (ioctl(0, KDENABIO, 0)) {
+  if (VGLModeInfo.vi_mem_model != V_INFO_MM_DIRECT && ioctl(0, KDENABIO, 0)) {
 free(VGLDisplay);
 return -3;
   }
@@ -370,7 +371,8 @@ VGLCheckSwitch()
 
 VGLSwitchPending = 0;
 if (VGLOnDisplay) {
-  ioctl(0, KDENABIO, 0);
+  if (VGLModeInfo.vi_mem_model != V_INFO_MM_DIRECT)
+ioctl(0, KDENABIO, 0);
   ioctl(0, KDSETMODE, KD_GRAPHICS);
   ioctl(0, VGLMode, 0);
   VGLCurWindow = 0;
@@ -531,7 +533,8 @@ VGLCheckSwitch()
   munmap(VGLDisplay->Bitmap, VGLAdpInfo.va_window_size);
   ioctl(0, VGLOldMode, 0);
   ioctl(0, KDSETMODE, KD_TEXT);
-  ioctl(0, KDDISABIO, 0);
+  if (VGLModeInfo.vi_mem_model != V_INFO_MM_DIRECT)
+ioctl(0, KDDISABIO, 0);
   ioctl(0, VT_RELDISP, VT_TRUE);
   VGLDisplay->Bitmap = VGLBuf;
   VGLDisplay->Type = MEMBUF;

Modified: head/lib/libvgl/mouse.c
==
--- head/lib/libvgl/mouse.c Sat Apr 20 17:16:36 2019(r346453)
+++ head/lib/libvgl/mouse.c Sat Apr 20 20:29:03 2019(r346454)
@@ -111,10 +111,12 @@ VGLMousePointerShow()
   if (!VGLMouseVisible) {
 INTOFF();
 VGLMouseVisible = 1;
-crtcidx = inb(0x3c4);
-crtcval = inb(0x3c5);
-gdcidx = inb(0x3ce);
-gdcval = inb(0x3cf);
+if (VGLModeInfo.vi_mem_model != V_INFO_MM_DIRECT) {
+  crtcidx = inb(0x3c4);
+  crtcval = inb(0x3c5);
+  gdcidx = inb(0x3ce);
+  gdcval = inb(0x3cf);
+}
 __VGLBitmapCopy(VGLDisplay, VGLMouseXpos, VGLMouseYpos, 
  , 0, 0, MOUSE_IMG_SIZE, MOUSE_IMG_SIZE);
 bcopy(VGLMouseSave.Bitmap, buffer.Bitmap,
@@ -128,10 +130,12 @@ VGLMousePointerShow()
   }
 __VGLBitmapCopy(, 0, 0, VGLDisplay, 
  VGLMouseXpos, VGLMouseYpos, MOUSE_IMG_SIZE, MOUSE_IMG_SIZE);
-outb(0x3c4, crtcidx);
-outb(0x3c5, crtcval);
-outb(0x3ce, gdcidx);
-outb(0x3cf, gdcval);
+if (VGLModeInfo.vi_mem_model != V_INFO_MM_DIRECT) {
+  outb(0x3c4, crtcidx);
+  outb(0x3c5, crtcval);
+  outb(0x3ce, gdcidx);
+  outb(0x3cf, gdcval);
+}
 INTON();
   }
 }
@@ -144,16 +148,20 @@ VGLMousePointerHide()
   if (VGLMouseVisible) {
 INTOFF();
 VGLMouseVisible = 0;
-crtcidx = inb(0x3c4);
-crtcval = inb(0x3c5);
-gdcidx = inb(0x3ce);
-gdcval = inb(0x3cf);
+if (VGLModeInfo.vi_mem_model != V_INFO_MM_DIRECT) {
+  crtcidx = inb(0x3c4);
+  crtcval = inb(0x3c5);
+  gdcidx = inb(0x3ce);
+  gdcval = inb(0x3cf);
+}
 __VGLBitmapCopy(, 0, 0, VGLDisplay, 
  VGLMouseXpos, VGLMouseYpos, MOUSE_IMG_SIZE, MOUSE_IMG_SIZE);
-outb(0x3c4, crtcidx);
-outb(0x3c5, crtcval);
-outb(0x3ce, gdcidx);
-outb(0x3cf, gdcval);
+if (VGLModeInfo.vi_mem_model != V_INFO_MM_DIRECT) {
+  outb(0x3c4, crtcidx);
+  outb(0x3c5, crtcval);
+  outb(0x3ce, gdcidx);
+  outb(0x3cf, gdcval);
+}
 INTON();
   }
 }

Modified: head/lib/libvgl/simple.c
==
--- head/lib/libvgl/simple.cSat Apr 20 17:16:36 2019(r346453)
+++ head/lib/libvgl/simple.cSat Apr 20 20:29:03 2019