API Review RT:17407 Canvas Node

joe andresen joseph.andresen at oracle.com
Wed Apr 25 15:30:20 PDT 2012

On 4/25/2012 2:35 PM, Daniel Zwolenski wrote:
> Is the Canvas going to be noticeable less performant than, say, painting in Swing?
> So for the things I listed would the recommendation be to use the Scene Graph and make everything out of Nodes, or use the new Canvas?
> If we are meant to use Nodes it would be great to get a better understanding on how to optimize for performance with respect to non-visible nodes (eg create/destroy them or just keep them around) as well as good examples of mouse handling when there are lots of contained nodes within nodes within nodes. Eg could the document team put together a detailed sample/tutorial on building something like a CAD editor, with panning, zoom, drag and drop, shape connectors, scribble annotations, etc?

This is a good question, when to use Canvas?

Canvas is not meant to be the end all solution for rendering in JavaFX. 
With the scenegraph and CSS, you can write a lot of high performance 
graphics applications. But not all rendering is best described via a 
scenegraph of primitives, and this is where canvas shines. Highly 
dynamic examples would include particle systems, visualizers, or solvers 
that need to simply "draw stuff" where "stuff" can vary dramatically 
*every frame*.

Ask yourself if what you want to draw is very dynamic. Grid lines? Not 
really dynamic. Brush/Scribble strokes, Dynamic. 2D Fluid Solver? 
Dynamic! Coverflow? Not dynamic. Music Visualizer? Very dynamic!

- a PDF viewer with ability to draw markup/scribble on it
how about use the scenegraph to implement the viewer and then a canvas on top of it to scribble with?

- a highly graphical custom component that looked like a 'clipboard' (actually a 'permit board' hanging from a wall)
Scenegraph and CSS would be great for this, see some of the stuff on the fxexperience blog

  - a 'flingable' carousel of the above components that the user can horizontally flip through (touch screen)
  anything that requires input is best done with the scenegraph.

- a scrollable site map showing a schematic of an industrial site
Not exactly sure what your input is like but since it is not dynamic rendering then I would use the scenegraph.

  - annotated images (ie markup/scribble on photos taken)
again, imageview with a canvas over it would be perfect.

  - simple CAD diagram rendering
Again, how dynamic is this? Not very? Then scenegraph.
Do you want to be able to click on each primitive and react to these input events?Then i would choose scenegraph.

We will be providing more examples of "when to use canvas" but this should hopefully give an idea of how it fits with the scenegraph.

Lastly, I concede that the ability to offload computation of commands for a GraphicsContext might be better done on a different thread, but I am not sure this is in the scope of the current iteration of this feature and this iteration does not (and should not) preclude us from accomplishing offloaded computation in the future.


More information about the openjfx-dev mailing list