8000 Ability to use Canvas in Isolates · Issue #75755 · flutter/flutter · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Ability to use Canvas in Isolates #75755

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

Closed
nfriend opened this issue Feb 10, 2021 · 10 comments
Closed

Ability to use Canvas in Isolates #75755

nfriend opened this issue Feb 10, 2021 · 10 comments
Labels
a: images Loading, displaying, rendering images c: new feature Nothing broken; request for a new capability c: proposal A detailed proposal for a change to Flutter c: rendering UI glitches reported at the engine/skia or impeller rendering level engine flutter/engine repository. See also e: labels. P3 Issues that are less important to the Flutter project team-engine Owned by Engine team triaged-engine Triaged by Engine team

Comments

@nfriend
Copy link
nfriend commented Feb 10, 2021

Use case

I'm building a drawing application that renders lots of lines:

Since each of these designs can include hundreds of thousands of points, I regularly (every 1000 points) rasterize the line, set the result as the background image of the drawing canvas, and remove the captured points. This keeps the total number of non-rasterized lines low and keeps the frame-rate high even after lots of drawing.

The problem

However, there's a noticeable jank when I perform this rasterization process. (You can see it happen about 5 times in the GIF above.)

I've already optimized this process a bit by breaking the background canvas into tiles and only updating the tiles that have changed. This helps tremendously, but it's still not enough to avoid noticeable jank.

My attempt at a solution

I thought moving this rasterization process to an Isolate might help smooth the frame rate a bit. However, dart:ui isn't available in Isolates (source).

Proposal

Allow a Canvas to be instantiated and rendered in a Isolate. This would allow computationally complex image manipulations to be performed off the main Isolate.

Related issues

Disclaimer

I'm not actually sure if this would solve my problem - perhaps copying the image data between Isolates would be just as expensive as the render itself 🤷

Source code

In case it's useful, the source code for my Flutter app can be found here: https://gitlab.com/nfriend/inspiral

@pedromassangocode pedromassangocode added a: images Loading, displaying, rendering images framework flutter/packages/flutter repository. See also f: labels. passed first triage c: proposal A detailed proposal for a change to Flutter c: new feature Nothing broken; request for a new capability c: rendering UI glitches reported at the engine/skia or impeller rendering level labels Feb 10, 2021
@goderbauer goderbauer added the engine flutter/engine repository. See also e: labels. label Feb 10, 2021
@chinmaygarde chinmaygarde added the P3 Issues that are less important to the Flutter project label Feb 17, 2021
@Solido
Copy link
Contributor
Solido commented Mar 10, 2021

Follow-up on this since I am stuck with the same problem for advanced rendering.

@steffenSuess
Copy link

I could also use this feature very well when generating images for PDFs.

@JonLatane
Copy link

This would be immensely useful for my app BeatScratch.

@rlueders
Copy link

@nfriend , how did you work around this, or is the rasterization jank unavoidable with Flutter?

@nfriend
Copy link
Author
nfriend commented Sep 29, 2022

@rlueders If I remember correctly, I did not find a solution 😞 The jank shown in the screenshot above is still present in the production version of my app.

@FaFre
Copy link
FaFre commented Feb 17, 2023

Right now this is a huge bottleneck for rendering vector tiles directly in dart, which would massively benefit from this feature. A lot of users are waiting for a performance improvement (https://github.com/greensopinion/flutter-vector-map-tiles)

@rlueders
Copy link

Right now this is a huge bottleneck for rendering vector tiles directly in dart, which would massively benefit from this feature. A lot of users are waiting for a performance improvement (https://github.com/greensopinion/flutter-vector-map-tiles)

FYI, you can use most of dart.UI from Flutter Isolates. I have been using it for a while with dramatic improvements when generating hundreds of thousands of images from Canvas. However, use with caution as calls dart.ui from Flutter Isolates seems to have broken after I enable Impeller on IOS. Still works with on Android and with Impeller disabled.

@Medit8r
Copy link
Medit8r commented Apr 6, 2023

Perhaps the issue could be addressed by allowing the creation of lightweight Flutter engines in isolates in a pure Flutter app (not Add-to-app)? Since the lightweight Flutter engines share some context they would start up quickly, but would allow the developer to generate images in background isolates. This would open up so many GIS use cases, given the amount of data and rendering which is required!! Restricting the use of writing to the Canvas to a single thread, means for all intents and purposes, a Flutter GIS solution is an order of magnitude slower than a native GIS implementation. (Even in Xamarin you can draw to the canvas in background threads).

@flutter-triage-bot flutter-triage-bot bot added team-engine Owned by Engine team triaged-engine Triaged by Engine team labels Jul 8, 2023
@jonahwilliams
Copy link
Member

Duplicate of #13343

@jonahwilliams jonahwilliams marked this as a duplicate of #13343 Sep 18, 2024
@jonahwilliams jonahwilliams closed this as not planned Won't fix, can't repro, duplicate, stale Sep 18, 2024
Copy link
github-actions bot commented Oct 2, 2024

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a: images Loading, displaying, rendering images c: new feature Nothing broken; request for a new capability c: proposal A detailed proposal for a change to Flutter c: rendering UI glitches reported at the engine/skia or impeller rendering level engine flutter/engine repository. See also e: labels. P3 Issues that are less important to the Flutter project team-engine Owned by Engine team triaged-engine Triaged by Engine team
Projects
None yet
Development

No branches or pull requests

0