seb42
Posts: 4
Joined: Sun Nov 15, 2015 10:36 am

Running Flutter, Google’s Portable UI Toolkit, on a rpi

Tue Jan 22, 2019 8:18 am

Haven't had a play with Flutter yet on my rpi, might get a screen this week and give it a go.
Flutter currently only has official support only for andorid and ios devices, it has also been used for UI stuff on Google's new OS, Fuchsia. So am interested to see where they go with Flutter this year.

Here is article about getting a flutter app running on the pi.
https://medium.com/flutter-io/flutter-o ... 24c5e7dcb1

IF you aren't across Flutter, here is a 11 minute recap of the Flutter live 1.0 event from December 2018.
https://youtu.be/D-o4BqJxmJE

Robbiedobbie
Posts: 5
Joined: Thu Jan 03, 2013 7:27 pm

Re: Running Flutter, Google’s Portable UI Toolkit, on a rpi

Wed Mar 20, 2019 2:47 pm

Did you happen to try this?
I'm currently trying to write an app for the raspi in flutter. I managed to get it up and running, however display elements keep disappearing at random. To me it looks like the gpu can't handle the amount of textures (Running on raspi3, with a 50/50 memory split, so it should have enough memory).

Maybe we can exchange notes?

Andyroo
Posts: 4491
Joined: Sat Jun 16, 2018 12:49 am
Location: Lincs U.K.

Re: Running Flutter, Google’s Portable UI Toolkit, on a rpi

Wed Mar 20, 2019 3:24 pm

The OP has not been back here since Jan. You can check by clicking on their user name in the post.
Need Pi spray - these things are breeding in my house...

Robbiedobbie
Posts: 5
Joined: Thu Jan 03, 2013 7:27 pm

Re: Running Flutter, Google’s Portable UI Toolkit, on a rpi

Thu Mar 21, 2019 7:48 am

Always worth a try. He might have a subsciption on this topic, with an email alert...

gedw99
Posts: 1
Joined: Sun Apr 07, 2019 3:06 pm

Re: Running Flutter, Google’s Portable UI Toolkit, on a rpi

Sun Apr 07, 2019 3:14 pm

If anyone gets a GitHub repo up with the build of flutter on rasp pi please list it.

I run flutter on desktops with golang and can help port plugins etc to get it all ticking along on a rasp pi.

Pretty exciting stuff btw !

Robbiedobbie
Posts: 5
Joined: Thu Jan 03, 2013 7:27 pm

Re: Running Flutter, Google’s Portable UI Toolkit, on a rpi

Mon Apr 08, 2019 7:48 am

It's not too hard to start from scratch. Basically you just use your hello triangle example but link against a self build (Which is the hardest part) libflutter_engine.so, and call the FlutterEngineRun function with a config for opengl backends. You then implement 5 callbacks that should refer back to opengl functions, et voila, it runs. (If you try release mode builds for the engine, you'll also have to prepare an AOT binary blob from your app, and map that into (partly executable memory).

I'm currently working on a photobooth in this framework, and will be releasing it as opensource when it's finished. It will have the code to run on raspberry pi, but I'm not sure that it will actually run on it. I still haven't managed to solve the texture issue, but it sure looks like it's just a limit on the very limited gpu of the raspberry pi.

I suspect that a raspi clone with a more modern (mali?) gpu would work much better for flutter.

ardera
Posts: 10
Joined: Wed Jul 18, 2018 9:49 am

Re: Running Flutter, Google’s Portable UI Toolkit, on a rpi

Fri Jun 07, 2019 9:08 am

Got it working too, including mouse support (but not mouse cursor support!). Code for the embedder is here: https://github.com/ardera/flutter-pi
And I, too, got the same weird texture problem; could be that it's because I didn't implement the make_resource_current callback, but that should be optional.
I don't think it's the VRAM either, cause the behaviour is the same with 64MB or 256MB VRAM. There are definitely points where all textures are loaded and visible, so maybe it's not the amount of textures that's causing this. I really hope it's just some kind of inconsistency in the raspberry pi's graphics implementation that we can hack around.

Performance is not that bad, 50-60fps with the default "flutter create" app, and I didn't even compile the engine in release mode yet.

Robbiedobbie
Posts: 5
Joined: Thu Jan 03, 2013 7:27 pm

Re: Running Flutter, Google’s Portable UI Toolkit, on a rpi

Fri Jun 07, 2019 9:12 am

I did implement make_resource_current since I also thought it might be related to that. It is not :(

I still think it is either memory related (It does seem to display just a little bit more with more vram). However, it might also have to do with the lack of power of 2 textures, however, I haven't looked into this...

ardera
Posts: 10
Joined: Wed Jul 18, 2018 9:49 am

Re: Running Flutter, Google’s Portable UI Toolkit, on a rpi

Fri Jun 07, 2019 8:04 pm

I still don't think it's memory related. You can get the amount of free gpu ram usage with

Code: Select all

vcgencmd get_mem malloc
+

Code: Select all

vcgencmd get_mem reloc
(Which is the amount of free-mem in the VideoCore malloc heap + VideoCore reloc heap)
For me, there were always 10MB (of 12MB total) malloc heap and ~190 (of ~245MB total) reloc heap free.

Also, there are a lot of basic OpenGL games that run under the VC IV. They probably use more textures that the basic "flutter create" app. So I don't think (and hope) it's hitting a VRAM limit here.

But how do you even start debugging this? I thought of hooking the procedures returned by the proc_resolver callback to trace the GL calls, but that's so much work.


EDIT: added VRAM numbers

bbt
Posts: 3
Joined: Tue Jul 09, 2019 3:15 am

Re: Running Flutter, Google’s Portable UI Toolkit, on a rpi

Tue Jul 09, 2019 3:19 am

Hi, I'm apologize to bring this topic up.
I'm trying to get the flutter to work on a RPi 3B without the desktop, it ran, but the touchscreen is not working (It works under desktop)
Here's what I have so far in the video

https://www.youtube.com/watch?v=3hmxaH_z7mY

Can someone give a idea what I should try next? Many thanks!

ardera
Posts: 10
Joined: Wed Jul 18, 2018 9:49 am

Re: Running Flutter, Google’s Portable UI Toolkit, on a rpi

Tue Jul 09, 2019 8:19 pm

I assume you built the flutter engine & flutter engine embedder using https://medium.com/flutter/flutter-on-r ... 24c5e7dcb1 and https://github.com/jwinarske/flutter_embedded/. I say that because that's definitely not the only way to get flutter running on Pi. Flutter on Pi is HIGHLY experimental. It's not at all production-ready.

The only reason the flutter_gallery app doesn't crash like 1 second after it's started is because flutter for raspberry pi is so unfinished, the callback that'd enable the app to talk to the platform-side is not implemented. If you implement it, that app crashes because it tries to talk with the platform side but there is no platform side. (I didn't test it, but that's my hypothesis)

In your case though, I think the fix is simple. You need the specify which input device flutter should use. Do

Code: Select all

TSLIB_TSDEVICE=/dev/input/event0 ./run.sh
If that doesn't work, try with /dev/input/event1, etc until you find a number that works.

You can also avoid the trial-and-error if you execute

Code: Select all

evtest
and use the input device path where it says ... memory-based driver ...


EDIT: Rewrote my response after I found out which embedder you were using.

bbt
Posts: 3
Joined: Tue Jul 09, 2019 3:15 am

Re: Running Flutter, Google’s Portable UI Toolkit, on a rpi

Wed Jul 10, 2019 9:06 am

Hi, ardera thanks for reply!

Yes, I'm using the guide and jwinarske's Github as reference.
I did try

Code: Select all

TSLIB_TSDEVICE=/dev/input/event0 ./run.sh
, but still nothing happened, also re-compiled libts and the touch testing works under CLI.
Would you mind to share the compiled flutter binary and libflutter_engine.so and the sample you're using for me to test?

Here's the output from the console:

Code: Select all

LOG: ../flutter/main.cc:66: Display Size: 800 x 480
[ERROR:flutter/shell/platform/embedder/embedder_surface_gl.cc(95)] Could not create a resource context for async texture uploads. Expect degraded performance. Set a valid make_resource_current callback on FlutterOpenGLRendererConfig.
[ERROR:flutter/shell/platform/embedder/embedder_surface_gl.cc(95)] Could not create a resource context for async texture uploads. Expect degraded performance. Set a valid make_resource_current callback on FlutterOpenGLRendererConfig.
flutter: Observatory listening on http://127.0.0.1:32935/Skd_3ihL700=/
[ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: Exception: operation failed
#0      ShaderWarmUp.execute (package:flutter/src/painting/shader_warm_up.dart:90:5)
<asynchronous suspension>
#1      _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding.initInstances (package:flutter/src/painting/binding.dart:25:20)
#2      _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding.initInstances (package:flutter/src/semantics/binding.dart:22:11)
#3      _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding.initInstances (package:flutter/src/rendering/binding.dart:29:11)
#4      _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding.initInstances (package:flutter/src/widgets/binding.dart:252:11)
#5      new BindingBase (package:flutter/src/foundation/binding.dart:56:5)
#6      new _WidgetsFlutterBinding&BindingBase&GestureBinding (package:flutter/src/widgets/binding.dart)
#7      new _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding (package:flutter/src/widgets/binding.dart)
#8      new _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding (package:flutter/src/widgets/binding.dart)
#9      new _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding (package:flutter/src/widgets/binding.dart)
#10     new _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding (package:flutter/src/widgets/binding.dart)
#11     new _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding (package:flutter/src/widgets/binding.dart)
#12     new _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding (package:flutter/src/widgets/binding.dart)
#13     new WidgetsFlutterBinding (package:flutter/src/widgets/binding.dart)
#14     WidgetsFlutterBinding.ensureInitialized (package:flutter/src/widgets/binding.dart:994:7)
#15     runApp (package:flutter/src/widgets/binding.dart:785:25)
#16     main (package:example_flutter/main.dart:23:3)
#17     _runMainZoned.<anonymous closure>.<anonymous closure> (dart:ui/hooks.dart:216:25)
#18     _rootRun (dart:async/zone.dart:1124:13)
#19     _CustomZone.run (dart:async/zone.dart:1021:19)
#20     _runZoned (dart:async/zone.dart:1516:10)
#21     runZoned (dart:async/zone.dart:1500:12)
#22     _runMainZoned.<anonymous closure> (dart:ui/hooks.dart:208:5)
#23     _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:305:19)
#24     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:172:12)
ardera wrote:
Tue Jul 09, 2019 8:19 pm
I assume you built the flutter engine & flutter engine embedder using https://medium.com/flutter/flutter-on-r ... 24c5e7dcb1 and https://github.com/jwinarske/flutter_embedded/. I say that because that's definitely not the only way to get flutter running on Pi. Flutter on Pi is HIGHLY experimental. It's not at all production-ready.

The only reason the flutter_gallery app doesn't crash like 1 second after it's started is because flutter for raspberry pi is so unfinished, the callback that'd enable the app to talk to the platform-side is not implemented. If you implement it, that app crashes because it tries to talk with the platform side but there is no platform side. (I didn't test it, but that's my hypothesis)

In your case though, I think the fix is simple. You need the specify which input device flutter should use. Do

Code: Select all

TSLIB_TSDEVICE=/dev/input/event0 ./run.sh
If that doesn't work, try with /dev/input/event1, etc until you find a number that works.

You can also avoid the trial-and-error if you execute

Code: Select all

evtest
and use the input device path where it says ... memory-based driver ...


EDIT: Rewrote my response after I found out which embedder you were using.

ardera
Posts: 10
Joined: Wed Jul 18, 2018 9:49 am

Re: Running Flutter, Google’s Portable UI Toolkit, on a rpi

Wed Jul 10, 2019 8:03 pm

I don't have a working "flutter binary" either. I use my own embedder
I can share my libflutter_engine.so with you but im 200% positive we got the exact same one, and even if we don't, the engine is not responsible for fetching touchscreen input.

Are you really sure you tried not only with

Code: Select all

TSLIB_TSDEVICE=/dev/input/event0
, but also with

Code: Select all

TSLIB_TSDEVICE=/dev/input/event1
and

Code: Select all

TSLIB_TSDEVICE=/dev/input/event2
and so forth?

I'm 95% sure it has to do with configuration. Could you please execute

Code: Select all

evtest
and show me the output?

ardera
Posts: 10
Joined: Wed Jul 18, 2018 9:49 am

Re: Running Flutter, Google’s Portable UI Toolkit, on a rpi

Mon Sep 09, 2019 4:18 pm

I FINALLY got it working. (with hardware acceleration)

Some other guy on reddit told me flutter has general problems with older graphics chips and graphics drivers. Both the broadcom driver and the VideoCore 4 are probably about 10 years old.

So I decided I'd try using the open-source graphics driver for the VC4 and VC6 made by http://www.anholt.net/. (https://gitlab.freedesktop.org/mesa/kmscube helped a lot for this, in fact my code is very heavily inspired by that implementation)

I'll publish the code on my github repo (https://github.com/ardera/flutter-pi) soon.

The disadvantage of anholts driver is that it's not as fast as the official Broadcom one (that's my impression); though it seems the failing shader warmup does cost a lot of performance. Performance gets a lot better when you've clicked the button (in the default flutter application) a few times. I expect the performance to be a lot better for the Raspberry Pi 4 though; and my code should work on the Pi4 without modifications.

Additionally, I tested my implementation with a 1920x1080 display; you should get more performance if you use the official 7" touchscreen for example (since it has a lower resolution)


EDIT: Performance is as good as with the broadcom driver, maybe even better. My issues were due to misconfiguration.
Last edited by ardera on Wed Sep 18, 2019 10:01 am, edited 1 time in total.

bbt
Posts: 3
Joined: Tue Jul 09, 2019 3:15 am

Re: Running Flutter, Google’s Portable UI Toolkit, on a rpi

Tue Sep 17, 2019 5:48 am

Hi Arera,

Thanks for the update!
For quick test, could you share the out/flutter-rpi binary file, thanks!


ardera wrote:
Mon Sep 09, 2019 4:18 pm
I FINALLY got it working. (with hardware acceleration)

Some other guy on reddit told me flutter has general problems with older graphics chips and graphics drivers. Both the broadcom driver and the VideoCore 4 are probably about 10 years old.

So I decided I'd try using the open-source graphics driver for the VC4 and VC6 made by http://www.anholt.net/. (https://gitlab.freedesktop.org/mesa/kmscube helped a lot for this, in fact my code is very heavily inspired by that implementation)

I'll publish the code on my github repo (https://github.com/ardera/flutter-pi) soon.

The disadvantage of anholts driver is that it's not as fast as the official Broadcom one (that's my impression); though it seems the failing shader warmup does cost a lot of performance. Performance gets a lot better when you've clicked the button (in the default flutter application) a few times. I expect the performance to be a lot better for the Raspberry Pi 4 though; and my code should work on the Pi4 without modifications.

Additionally, I tested my implementation with a 1920x1080 display; you should get more performance if you use the official 7" touchscreen for example (since it has a lower resolution)

ardera
Posts: 10
Joined: Wed Jul 18, 2018 9:49 am

Re: Running Flutter, Google’s Portable UI Toolkit, on a rpi

Wed Sep 18, 2019 9:59 am

bbt wrote:
Tue Sep 17, 2019 5:48 am
For quick test, could you share the out/flutter-rpi binary file, thanks!
Yep, file is located here: https://github.com/ardera/flutter-pi/re ... flutter-pi
I also attached the file to a Release on the github repo.

When you want to run it, please switch the Pi into fake-KMS mode and set the gpu-memory to 16. (somehow it runs unbelievably slow when using large GPU memory, with 16MB it works fine.)

aminoo
Posts: 3
Joined: Sun Sep 22, 2019 6:44 pm

Re: Running Flutter, Google’s Portable UI Toolkit, on a rpi

Sun Sep 22, 2019 7:49 pm

ardera wrote:
Wed Sep 18, 2019 9:59 am
bbt wrote:
Tue Sep 17, 2019 5:48 am
For quick test, could you share the out/flutter-rpi binary file, thanks!
Yep, file is located here: https://github.com/ardera/flutter-pi/re ... flutter-pi
I also attached the file to a Release on the github repo.

When you want to run it, please switch the Pi into fake-KMS mode and set the gpu-memory to 16. (somehow it runs unbelievably slow when using large GPU memory, with 16MB it works fine.)
thank you brother

Return to “Other programming languages”