Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Current rendering stack and possible improvements.
First I will describe the current renderAll situation.
We start with a _renderBackground.
renderBackgrond calls _draw(backgroundImage).
_draw function has this scheme:
save context
apply viewportTransform
check if the object should be rendered and actually render it
(this means object !== activeGroup || this.preserveObjectStacking)
restore context
renderObjectControls ( exit if not !this.active or render the controls )
_renderObjects ( rendering of all objects )
render all the objects in stack, or exclude the one in activeGroup depending on preserveObjectStacking and checking if active group contains them
Every object is drawn with _draw, so again save context, apply viewportTransform, again check if the object is in activeGroup,
restore context, renderControls.
_renderActiveGroup (rendering objects of activeGroup) with the
_draw procedure already described.
_renderOverlay mirrored from _renderBackgroundImage
_renderControls if controlsAboveOverlay, make a global call for rendering controls.
Because objects in activeGroup are still present on canvas, in the objects array, so we need to be careful to do not draw them twice.
All the checks are about being in the activeGroup, so useless for activeGroup itself, useless for background and overlay images.
Proposed changes in this PR.
background image and overlay image are rendered with their render method.
ViewportTransform get applied once for renderAll, with one save and restore context.
Objects are divided into two groups immediately, and then we render the groups one after the other without additional checks.
Because of this changes take over _draw functionality, the _draw function disappear.
All the controls in the canvas are drawn with canvas.drawcontrols.
What actually changes in the rendering stack? controls are always on top of the object pile, (not above overaly ) regardless if the object is on top.
But consider that we have this bug as of now, and this new situation would solve it.
The bug is that when controls are drawn during the stack, they are present on canvas when the objects after the 'active index' are rendered, so any eventual global composite operataion get influenced by them
So in my opinion moving the control in the top of the stack is a good move, also code reduction is noticiable and we should see minor performance improvements.
Example of bug: