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

feature: Support all Canvas2D APIs by wrapping CanvasRenderer in a Proxy #324

Closed
wants to merge 2 commits into from

Conversation

zplata
Copy link
Contributor

@zplata zplata commented Jun 13, 2023

We recently exposed drawImage() support from our CanvasRenderer, which naturally led to seeing if we can support the rest of the Canvas2D context APIs by approaching a similar strategy (simply adding the call to our deferred drawList).

We may be able to just return a Proxy from makeRenderer() which would intercept the calls to CanvasRenderer and route each API function call either to our CanvasRenderer if the API the user wants to call exists on it, OR the ._ctx (the actual Canvas2D context) from CanvasRenderer. This should allow us to support our custom save(), restore(), _drawImageMesh(), etc. calls, while any non-overriden API we've wrapped in CanvasRenderer would go straight to the context itself.

From a consumer perspective, nothing should change here. They call const renderer = rive.makeRenderer(canvas-element) and use renderer.save(), renderer.restore(), etc. in a render loop as expected.

rive-engineering pushed a commit that referenced this pull request Aug 16, 2023
Ported over from public wasm repo: #324

We recently exposed `drawImage()` support from our `CanvasRenderer`, which naturally led to seeing if we can support the rest of the Canvas2D context APIs by approaching a similar strategy (simply adding the call to our deferred `drawList`).

We may be able to just return a `Proxy` from `makeRenderer()` which would intercept the calls to `CanvasRenderer` and route each API function call either to our `CanvasRenderer` if the API the user wants to call exists on it, OR the `._ctx` (the actual Canvas2D context) from `CanvasRenderer`. This should allow us to support our custom `save()`, `restore()`, `_drawImageMesh()`, etc. calls, while any non-overriden API we've wrapped in `CanvasRenderer` would go straight to the context itself.

From a consumer perspective, nothing should change here. They call `const renderer = rive.makeRenderer(canvas-element)` and use  `renderer.save()`, `renderer.restore()`, etc. in a render loop as expected.

Diffs=
65156867f feature: wrap renderer in a Proxy to expose Canvas2d context (#5491)

Co-authored-by: Zachary Plata <[email protected]>
@zplata
Copy link
Contributor Author

zplata commented Sep 13, 2023

closing since this was addressed in v2.2.0

@zplata zplata closed this Sep 13, 2023
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.

1 participant