Class OptimizedShapeRendering
It optimizes shape filling specifically by turning antialiasing off strategically for parts which do not need it because the result looks identical.
Filling anti-aliased shapes can be extremely slow. This is because a Graphics2D rasterizer asked
to antialias computes a computest multiple pixels internal for every visual pixel of a shape, including
the great majority which lie well inside it and come out fully covered. Over a rounded
rectangle the size of a scroll bar's thumb or a progress bar's fill, that is a few hundred
pixels of genuine curve and tens of thousands of pixels of arithmetic arriving at "opaque". A
fill without antialiasing on the other hand writes those directly: So much, much faster!
Support for such optimized routines is worth having in a custom look and feel because a
ComponentUI still needs to draw most of the visible primitives like
scroll bars itself (which SwingTree will not do for you).
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidfill(Graphics2D g2d, Shape shape) Fills a shape with the graphics context's current paint, in as few antialiased pixels as the shape allows, writing exactly the pixelsGraphics2D.fill(Shape)would write.static voidfillWithoutAntialiasing(Graphics2D g2d, Shape... shapes) Fills the given shapes with antialiasing switched off and then switches it back on.
-
Method Details
-
fill
Fills a shape with the graphics context's current paint, in as few antialiased pixels as the shape allows, writing exactly the pixelsGraphics2D.fill(Shape)would write.Two kinds of shape get a faster treatment:
- A
Rectangleis integer valued by its very type and so has no soft edge anywhere. Only the transform could still put one between two pixels, which is why that is checked before filling it in one go, without antialiasing. - A
RoundRectangle2Dcurves only inside its four corner boxes, so it is filled as antialiasing-free bands plus antialiased corners.
Rectangle2Dor a rotated transform, keeps antialiasing and is filled in one go.- Parameters:
g2d- the graphics context to fill on, whose paint, clip and transform are all used and none of which are changed by this callshape- the shape to fill
- A
-
fillWithoutAntialiasing
Fills the given shapes with antialiasing switched off and then switches it back on.- Parameters:
g2d- the graphics context to fill onshapes- the shapes to fill, none of which has a soft edge worth computing
-