[racket] limiting refresh rate of scroll bar calls to canvas%'s 'draw'

From: David Vanderson (david.vanderson at gmail.com)
Date: Fri Mar 21 18:19:57 EDT 2014

On 03/21/2014 02:16 PM, John Clements wrote:
> 2) upstream, inherit from canvas% and add code to limit the rate of calls to draw. I haven’t looked at the code yet, but this might be my best bet.
I tried overriding "refresh", and there's a tempting mention in the docs 
that "(Multiple refresh requests before on-paint 
can be called are coaleced into a single on-paint 
call.)" This does work if you have code that is explicitly calling 

Unfortunately it looks like "refresh" doesn't get called by lower-level 
stuff like scrollbars.  Can anyone confirm this?
> 3) one other thing occurs to me, though; it looks to me like calls to ‘draw’ are stacking up in an eventspace queue, and that seems like a mistake; if there’s a draw in progress, and calls to draw in the queue, it seems like another ‘draw’ should at a minimum squash the ones in the queue. Perhaps that’s painful to implement, or there’s a good reason for allowing all of the queued calls to complete?
I'm also seeing this (on Linux), or at least, it seems like many paints 
are happening but the back buffer is not being flushed to the screen.  
When I run the attached code, and then scroll a lot, then I see more 
dots printed to the console than frames being shown.

When I run it on Windows (from console) then things look much better, 
and it looks like I'm seeing every paint.

When I run it inside DrRacket on Windows I see no updates while 
scrolling until letting go of the scrollbar (different issue?)

What do you see on Mac?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20140321/545f7265/attachment.html>
-------------- next part --------------
#lang racket/gui

(define num-refresh 0)
(define num-on-paint 0)

(define frame
  (new frame%
       (label "Refresh")
       (width 500)
       (height 500)))

(define (draw-screen canvas dc)
  (set! num-on-paint (add1 num-on-paint))
  (sleep 0.1)
  (send dc draw-text (~a num-refresh " refreshes") 400 50)
  (send dc draw-text (~a num-on-paint " paints") 400 70))

(define my-canvas%
  (class canvas%
    (define/override (refresh)
      (set! num-refresh (add1 num-refresh))
      (super refresh))
    (define/override (on-paint)
      (printf ".")
      (super on-paint))
(define canvas
  (new my-canvas%
       (parent frame)
       (paint-callback draw-screen)
       (style '(no-autoclear hscroll))))

(send frame show #t)

(send canvas init-auto-scrollbars 700 #f 0.0 0.0)

(define (loop)
  (send canvas refresh)
  (send canvas refresh)
  (send canvas refresh)
  (send canvas refresh)
  (send canvas refresh)
  (send canvas refresh)
  (send canvas refresh)
  (sleep 1)

(thread loop)

Posted on the users mailing list.