4

Rendering takes a lot of computational power in many cases. Thus, it can happen that frames are being skipped as the UI needs to wait for the rendering to finish.

I was wondering how I could implement rendering or painting asynchronously, i.e. isolated.

Functions like compute are not an option because SendPort only works with primitive types and painting will require a PaintingContext or Canvas.

There are Flutter plugins that require heavy rendering. Hence, I thought that I could find answers in the video_player plugin, but it uses Texture, i.e. does not render in Dart.

I am wondering if there are any idioms or example implementations regarding this.

I you are wondering how I implement rendering, you can take a look at FlareActor. It turns out that they handle painting exactly like I do. Now I am wondering why I am running into bottlenecks and Flare is not. Are there any guides on optimizing painting?

creativecreatorormaybenot
  • 114,516
  • 58
  • 291
  • 402
  • 1
    It’s good question and I want to know about that too. Now I optimize as follows. 1)Limit not to overlap canvases that need repaining. 2)Do not use animation that have multiple frames of image... I guess flutter is not able to optimize preloading multiple frames and calculating overwrapped canvases especially with image. I will read FlareActor’s code! Thanks for your good information! – HeavenOSK Feb 17 '19 at 20:20
  • Good question, but pretty broad. Can you define what "expensive rendering" is? Because the optimization will definitely depend on what you do. One example: https://stackoverflow.com/questions/46702376/how-to-ensure-my-custompaint-widget-painting-is-stored-in-the-raster-cache/46706868#46706868 – Rémi Rousselet Feb 17 '19 at 20:56
  • 1
    You can split your slow renderobject into multiple ones. And repaint them partially – Rémi Rousselet Feb 17 '19 at 21:36

1 Answers1

2

I solved it by writing all my required pixels to the BMP file format and then using Canvas.drawImage instead as the Flutter canvas cannot handle many Canvas operations: https://stackoverflow.com/a/55855735/6509751

creativecreatorormaybenot
  • 114,516
  • 58
  • 291
  • 402