Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the underlying *vector.Rasterizer.Draw() fast path when calling canvas.Draw() #151

Merged
merged 1 commit into from
Feb 21, 2022

Conversation

carbocation
Copy link
Contributor

@carbocation carbocation commented Feb 21, 2022

The underlying *vector.Rasterizer.Draw() function has a fast path that only applies when two things are true:

  1. The src is of type *image.Uniform
  2. The dst is of type *image.RGBA

The Rasterizer in the present package wraps a draw.Image of type *image.RGBA, but is not, itself, an *image.RGBA. Therefore, it gets shunted down the slow path.

This commit instead passes the Rasterizer.Image directly to the call to *vector.Rasterizer.Draw(), which allows the fast path to be used.

In my experiments with drawing a few hundred large (> 500 x 500px) images with go 1.18, this reduced the time spent on *vector.Rasterizer.Draw() calls from 80 seconds to 40 seconds. The call path now routes through vector (*Rasterizer) rasterizeDstRGBASrcUniformOpOver instead of the generic and slower vector (*Rasterizer) rasterizeOpOver.

(This may be related to #47 .)

that only applies when two things are true:
1. The src is of type *image.Uniform
2. The dst is of type *image.RGBA

The Rasterizer in the present package wraps a draw.Image of type
*image.RGBA, but is not, itself, an *image.RGBA. Therefore, it
gets shunted down the slow path.

This commit instead passes the Rasterizer.Image directly, which
allows the fast path to be used.
@tdewolff
Copy link
Owner

Excellent, thank you for the PR!

@tdewolff tdewolff merged commit 5fc7941 into tdewolff:master Feb 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants