Skip to content
Petro Kostandy edited this page Aug 29, 2017 · 3 revisions

The rendering loop make use of the requestAnimationFrame (RAF) method in most modern browser. If RAF is not available, it is shimmed with a 16 ms timer.

The rendering loop is enable on an element basis when cornerstone.enable(element) and disabled on cornerstone.disable(element).

The execution is as follow:

  • A draw() callback is registered with RAF;
  • draw() is called by the browser just after a frame is displayed on screen;
  • Once called,
    • if the element was scheduled for re-rendering, it is rendered and draw() is re-registered with RAF;
    • if the element was not scheduled for re-rendering, no work is performed and the callback re-registered with RAF;
    • if the element was disabled(), the callback is not re-registered ending the rendering loop.

This means that:

  • cornerstone.draw() and cornerstone.invalidate() no longer trigger immediate rendering the viewport, instead, it flags the image as needing re-rendering;
  • each cornerstone element register its own RAF loop;
  • if the rendering time exceeds 16 ms on a 60 Hz system, rendering frames are skipped;
  • only one render per frame is possible, even if render time is much lower than 16 ms;
  • all interactions (pan, zoom, etc.) are combined and rendered in the next frame.