[haiku-development] Re: Reading the Mouse Cursor and Dirty Screen

  • From: "Alexander G. M. Smith" <agmsmith@xxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Sat, 28 Mar 2015 16:02:06 -0400 EDT

looncraz <looncraz@xxxxxxxxxxx> wrote on Fri, 27 Mar 2015 12:10:21 -0500:
> Do you try to calculate the changes in the screen, or you just send the
> whole thing as fast as you can?

There's a dirty rectangle algorithm in the VNC library code that compares
rectangular areas from the current bitmap with the previously transmitted
data and only sends the changed pixels.  However, reading the whole screen
to find those dirty areas is slow on some video boards (it's actually done
in smaller segments to improve response time), and even slower with the
BScreen copy-the-whole-screen-to-a-bitmap technique.

> An ideal client-side solution would require a bit work, but it would, in
> the end, just be a BRegion and bitmap snapshot.  The BRegion would be
> reset each time the client took a snapshot.  BScreenStream, perhaps?  It
> would only take three protocol messages CREATE_*_STREAM, READ_*_STREAM,
> DELETE_*_STREAM on the server side, and would require the HWInterface
> CopyBackToFront() to manage two regions - one for server-side uses, and
> one for client uses.  This, of course, would only occur when a client is
> actually attached - the first update a client gets is a full-update
> region.

Just the dirty rectangles are needed (a BRegion would work); it can always
read the current screen memory for the pixels.  Would need some sort of
locking to let the BRegion be written by one thread and read by another.
Having the bitmap would make it easier to code the screen scraping, but
wouldn't that involve more memory usage and an extra copy for all screen
updates?  Currently it locks the screen via BDirectWindow (works so long as
you only lock for a short time - BeOS kicks you out after 4 seconds, Haiku
0.5 seconds) and uses the BDirectWindow API to get a pointer to video
memory which it then reads.

If dirty rectangles and pixels aren't synchronized, it's not a problem.  It
just wastes a bit of time with a double update of pixels, and those two
dirty updates will often have identical pixels (the ones from the more
recent update), resulting in less data transmitted at the cost of missing
some inbetween graphics (but then for VNC, that just means the connection
is too slow and the extra picture data would be dropped anyway).

> Setting this up should be easy, I'd be willing to spend a few hours on it
> if something like this is appealing.

Sounds good.  If it's not too much trouble, you set it up and I'll update
VNCServer to use it.  And like Daniel <headbulb@xxxxxxxxx> suggested, dirty
rectangles would also be good for VirtualBox.

- Alex

Other related posts: