|
1 | 1 | # flutter-pi
|
2 |
| -A light-weight Flutter Engine Embedder for Raspberry Pi that's using the broadcom APIs. Inspired by https://github.com/chinmaygarde/flutter_from_scratch. |
| 2 | +A light-weight Flutter Engine Embedder for Raspberry Pi. Inspired by https://github.com/chinmaygarde/flutter_from_scratch. |
| 3 | +Flutter-pi also runs without X11, so you don't need to boot into Raspbian Desktop & have X11 and LXDE load up; just boot into the command-line. |
3 | 4 |
|
4 |
| -Currently supported are basic, pure-dart Apps & mouse input (no mouse cursor yet). |
5 |
| -Not yet supported are Method & Platform-channels, touchscreen input; and probably a lot more. |
| 5 | +Currently supported are basic, pure-dart Apps (not using any plugins), mouse input (no mouse cursor yet), touchscreen input, and the StandardMethodCodec method-channels (currently needs fixing). |
| 6 | +Not yet supported are JSON method-channels. Generally, flutter-pi is not yet ready to be used as a base for your project. |
6 | 7 |
|
7 | 8 | ## Running
|
| 9 | +This branch (feature-v3d-anholt) doesn't support the legacy GL driver anymore. You need to activate the anholt v3d driver in raspi-config. Go to raspi-config -> Advanced -> GL Driver -> and select fake-KMS. Full-KMS is a bit buggy and doesn't work with the Raspberry Pi 7" display (or generally, any DSI display). |
| 10 | + |
| 11 | +For some reason performance is much better when I gave the GPU only 16M RAM in fake-kms. I don't know why. |
| 12 | + |
| 13 | +Also, you need to tell flutter-pi which input device to use and whether it's a touchscreen or mouse. Input devices are typically located at `/dev/input/...`. Just run `evtest` (`sudo apt install evtest`) to find out which exact path you should use. Currently only one input device is supported by flutter-pi. |
| 14 | + |
8 | 15 | Run using
|
9 | 16 | ```bash
|
10 |
| -./flutter-pi /path/without/trailing/slash [flutter arguments...] |
| 17 | +./flutter-pi [flutter-pi options...] /path/without/trailing/slash [flutter engine arguments...] |
11 | 18 | ```
|
12 |
| -where `/path/without/trailing/slash` is the path of the flutter asset bundle directory (i.e. the directory containing the kernel_blob.bin) |
| 19 | + |
| 20 | +`[flutter-pi options...]` are: |
| 21 | +- `-t /path/to/device` where `/path/to/device` is a path to a touchscreen input device (typically `/dev/input/event0` or similiar) |
| 22 | +- `-m /path/to/device` where `/path/to/device` is a path to a mouse input device (typically `/dev/input/mouse0` or `/dev/input/event0` or similiar) |
| 23 | + |
| 24 | +`/path/without/trailing/slash` is the path of the flutter asset bundle directory (i.e. the directory containing the kernel_blob.bin) |
13 | 25 | of the flutter app you're trying to run.
|
14 | 26 |
|
15 |
| -The `[flutter arguments...]` will be passed as commandline arguments to the flutter engine. |
| 27 | +`[flutter engine arguments...]` will be passed as commandline arguments to the flutter engine. You can find a list of commandline options for the flutter engine [Here](https://github.com/flutter/engine/blob/master/shell/common/switches.h); |
16 | 28 |
|
17 | 29 | ## Building the asset bundle
|
| 30 | +You need a correctly installed flutter SDK. (i.e. the `flutter` tool must be in your PATH) |
| 31 | + |
18 | 32 | Example for flutter_gallery: (note that the flutter_gallery example doesn't work with flutter-pi, since it requires plugins)
|
19 | 33 | ```bash
|
20 |
| -cd ./flutter/examples/flutter_gallery |
21 |
| -../../bin/flutter build bundle |
| 34 | +cd flutter/examples/flutter_gallery |
| 35 | +flutter build bundle |
22 | 36 | ```
|
23 |
| -After that `./flutter/examples/flutter_gallery/build/flutter_assets` would be a valid path to pass as an argument to flutter-pi. |
| 37 | +After that `flutter/examples/flutter_gallery/build/flutter_assets` would be a valid path to pass as an argument to flutter-pi. |
| 38 | + |
| 39 | +## Compiling (on the Raspberry Pi) |
| 40 | +You first need a `libflutter_engine.so` and `flutter_embedder.h`. [Here](https://medium.com/flutter/flutter-on-raspberry-pi-mostly-from-scratch-2824c5e7dcb1) |
| 41 | +are some rough guidelines on how to build it. (Note: the icudtl.dat that is generated during the engine compilation needs to be on the RPi too, but it's not needed for compilation of flutter-pi) |
24 | 42 |
|
25 |
| -## Compiling |
26 |
| -You first need a valid `libflutter_engine.so`. [Here](https://medium.com/flutter/flutter-on-raspberry-pi-mostly-from-scratch-2824c5e7dcb1) |
27 |
| -are some rough guidelines on how to build it. |
| 43 | +You also need some dependencies; run `sudo apt install libgl1-mesa-dev libgles2-mesa-dev libegl-meso0 libdrm-dev libgbm-dev`. |
28 | 44 |
|
29 | 45 | Compiling the embedder:
|
30 | 46 | ```bash
|
31 | 47 | mkdir out
|
32 | 48 | cc -D_GNU_SOURCE \
|
33 |
| - -lrt -lbrcmGLESv2 -lflutter_engine -lpthread -ldl -lbcm_host -lvcos -lvchiq_arm -lm \ |
| 49 | + `pkg-config --cflags --libs dri gbm libdrm glesv2 egl` -lrt -lflutter_engine -lpthread -ldl \ |
34 | 50 | ./src/flutter-pi.c ./src/methodchannel.c -o ./out/flutter-pi
|
35 | 51 | ```
|
36 | 52 |
|
37 |
| -## Cross-Compiling |
38 |
| -You need a valid `libflutter_engine.so`, `flutter_embedder.h`, a valid raspberry pi sysroot including the /opt directory, and a valid toolchain targeting |
39 |
| -arm-linux-gnueabihf. Then execute: |
40 |
| -```bash |
41 |
| -mkdir out |
42 |
| -/path/to/cross_c_compiler \ |
43 |
| - -D_GNU_SOURCE \ |
44 |
| - --sysroot /path/to/sysroot \ |
45 |
| - -I/path/to/sysroot/opt/vc/include \ |
46 |
| - -I/directory/containing/flutter_embedder.h/ \ |
47 |
| - -L/path/to/sysroot/opt/vc/lib \ |
48 |
| - -L/directory/containing/libflutter_engine.so/ \ |
49 |
| - -lrt -lbrcmEGL -lbrcmGLESv2 -lflutter_engine -lpthread -ldl -lbcm_host -lvcos -lvchiq_arm -lm \ |
50 |
| - ./src/flutter-pi.c ./src/methodchannel.c -o ./out/flutter-rpi |
51 |
| -``` |
| 53 | +## Performance |
| 54 | +Performance is actually better than I expected. With most of the apps inside the `flutter SDK -> examples -> catalog` directory I get smooth 50-60fps. |
| 55 | + |
| 56 | +## Touchscreen Bug |
| 57 | +~~If you use the official 7 inch touchscreen, performance will feel much worse while dragging something. This seems to be some bug in the touchscreen driver. The embedder / userspace only gets around 25 touch events a second, meaning that while dragging something (like in tabbed_app_bar.dart), the position of the object being dragged is only updated 25 times a second. This results in the app looking like it runs at 25fps. The touchscreen could do up to 100 touch updates a second though.~~ |
| 58 | + |
| 59 | +[This has been fixed.](https://github.com/raspberrypi/linux/issues/3227) If you want to get the fix, you can run (rpi-update)[https://github.com/hexxeh/rpi-update], which will update your system to the newest version. |
| 60 | + |
0 commit comments