This seems like a good enhancement to me. I might suggest the following
naming for the restore method:
void restore(int index)
Would it be useful to other app developers?
-- Kevin
On 2/12/2023 1:21 AM, Laurent Bourgès wrote:
Hi,
For jfree.FXGraphics2D, I implemented the proposed approach in the new
GCHandler:
https://github.com/jfree/fxgraphics2d/blob/1994b9cb3a9bff93bf95100d398756d7f9f626c2/src/main/java/org/jfree/fx/GCStateHandler.java
It boosts fxG2D performance & correctness.
Ideally, such methods getSavePoint(), restoreToCount() should be added
to GraphicsContext API...
Cheers,
Laurent
Le ven. 3 févr. 2023, 23:31, Laurent Bourgès
<[email protected]> a écrit :
Hi,
While working with skia & jfree's skijaGraphics2D wrapper, I
observed skia offers nice methods in SkCanvas missing in javafx
Canvas/GraphicsContext to deal with save/restore state:
- int getSaveCount ()
Returns the number of saved states, each containing: SkMatrix
and clip.
- void restoreToCount (int saveCount)
Restores state to SkMatrix and clip values when save(), returned
saveCount.
As javafx canvas also maintains s stack of saved states, such
methods are trivial to implement to allow resetting completely the
canvas state by restoreToCount(0).
Moreover, clip(shape) + save/restore are really tricky to allows
ensure clip is reset to previous state ...
Would you agree to add such methods to have more predictive
behaviour than counting all save() calls to ensure to call
restore() the same number of times to reset the canvas to its
initial state ?
See SkijaGraphics2d implementation that saves / restore skCanvas
clip using such index property:
https://github.com/jfree/skijagraphics2d/blob/main/src/main/java/org/jfree/skija/SkijaGraphics2D.java
Cheers,
Laurent