Skip to content

Commit 07cc419

Browse files
authored
Merge pull request #76 from ardera/develop
add cmdline option for specifying physical screen dimensions
2 parents 1213b16 + 2588d82 commit 07cc419

File tree

2 files changed

+63
-18
lines changed

2 files changed

+63
-18
lines changed

README.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
## 📰 NEWS
2+
- the physical dimensions of the screen can now be specified via cmdline, using the `--dimensions` option.
23
- the layout of the engine-binaries branch has changed again. The symbolic link from `libflutter_engine.so` to the fitting `libflutter_engine.so.release` or `libflutter_engine.so.debug` is no longer needed, flutter-pi will now dynamically load the engine fitting the the runtime mode that was specified via cmdline. (if `--release` is given, flutter-pi will load `libflutter_engine.so.release`, else `libflutter_engine.so.debug`)
34
- flutter-pi now requires `libsystemd-dev`, `libinput-dev` and `libudev-dev` at compile-time. (`libudev-dev` is actually optional. To build without udev support, use cmake.)
45
- flutter-pi and the engine binaries updated for flutter 1.20.
@@ -120,9 +121,11 @@ OPTIONS:
120121
pattern you use as a parameter so it isn't
121122
implicitly expanded by your shell.
122123
123-
--aot Run the app in AOT mode. The AOT snapshot
124+
--release Run the app in release mode. The AOT snapshot
124125
of the app ("app.so") must be located inside the
125126
asset bundle directory.
127+
This also requires a libflutter_engine.so that was
128+
built with --runtime-mode=release.
126129
127130
-o, --orientation <orientation> Start the app in this orientation. Valid
128131
for <orientation> are: portrait_up, landscape_left,
@@ -139,6 +142,13 @@ OPTIONS:
139142
clock-wise.
140143
Valid values are 0, 90, 180 and 270.
141144
145+
-d, --dimensions "width_mm,height_mm" The width & height of your display in
146+
millimeters. Useful if your GPU doesn't provide
147+
valid physical dimensions for your display.
148+
The physical dimensions of your display are used
149+
to calculate the flutter device-pixel-ratio, which
150+
in turn basically "scales" the UI.
151+
142152
--no-text-input Disable text input from the console.
143153
This means flutter-pi won't configure the console
144154
to raw/non-canonical mode.
@@ -150,7 +160,18 @@ EXAMPLES:
150160
flutter-pi -i "/dev/input/mouse*" /home/pi/helloworld_flutterassets
151161
flutter-pi -o portrait_up ./flutter_assets
152162
flutter-pi -r 90 ./flutter_assets
163+
flutter-pi -d "155, 86" ./flutter_assets
153164
flutter-pi /home/pi/helloworld_flutterassets
165+
166+
SEE ALSO:
167+
Author: Hannes Winkler, a.k.a ardera
168+
Source: https://github.com/ardera/flutter-pi
169+
License: MIT
170+
171+
For instructions on how to build an asset bundle or an AOT snapshot
172+
of your app, please see the linked git repository.
173+
For a list of options you can pass to the flutter engine, look here:
174+
https://github.com/flutter/engine/blob/master/shell/common/switches.h
154175
```
155176

156177
`<asset bundle path>` is the path of the flutter asset bundle directory (i.e. the directory containing `kernel_blob.bin`)

src/flutter-pi.c

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,13 @@ OPTIONS:\n\
9898
clock-wise.\n\
9999
Valid values are 0, 90, 180 and 270.\n\
100100
\n\
101+
-d, --dimensions \"width_mm,height_mm\" The width & height of your display in\n\
102+
millimeters. Useful if your GPU doesn't provide\n\
103+
valid physical dimensions for your display.\n\
104+
The physical dimensions of your display are used\n\
105+
to calculate the flutter device-pixel-ratio, which\n\
106+
in turn basically \"scales\" the UI.\n\
107+
\n\
101108
--no-text-input Disable text input from the console.\n\
102109
This means flutter-pi won't configure the console\n\
103110
to raw/non-canonical mode.\n\
@@ -109,6 +116,7 @@ EXAMPLES:\n\
109116
flutter-pi -i \"/dev/input/mouse*\" /home/pi/helloworld_flutterassets\n\
110117
flutter-pi -o portrait_up ./flutter_assets\n\
111118
flutter-pi -r 90 ./flutter_assets\n\
119+
flutter-pi -d \"155, 86\" ./flutter_assets\n\
112120
flutter-pi /home/pi/helloworld_flutterassets\n\
113121
\n\
114122
SEE ALSO:\n\
@@ -1189,26 +1197,26 @@ static int init_display(void) {
11891197
}
11901198

11911199
// find a connected connector
1192-
flutterpi.display.width_mm = 0;
1193-
flutterpi.display.height_mm = 0;
11941200
for_each_connector_in_drmdev(flutterpi.drm.drmdev, connector) {
11951201
if (connector->connector->connection == DRM_MODE_CONNECTED) {
11961202
// only update the physical size of the display if the values
11971203
// are not yet initialized / not set with a commandline option
1198-
if ((connector->connector->connector_type == DRM_MODE_CONNECTOR_DSI) &&
1199-
(connector->connector->mmWidth == 0) &&
1200-
(connector->connector->mmHeight == 0))
1201-
{
1202-
// if it's connected via DSI, and the width & height are 0,
1203-
// it's probably the official 7 inch touchscreen.
1204-
flutterpi.display.width_mm = 155;
1205-
flutterpi.display.height_mm = 86;
1206-
} else if ((connector->connector->mmHeight % 10 == 0) &&
1207-
(connector->connector->mmWidth % 10 == 0)) {
1208-
// don't change anything.
1209-
} else {
1210-
flutterpi.display.width_mm = connector->connector->mmWidth;
1211-
flutterpi.display.height_mm = connector->connector->mmHeight;
1204+
if ((flutterpi.display.width_mm == 0) || (flutterpi.display.height_mm == 0)) {
1205+
if ((connector->connector->connector_type == DRM_MODE_CONNECTOR_DSI) &&
1206+
(connector->connector->mmWidth == 0) &&
1207+
(connector->connector->mmHeight == 0))
1208+
{
1209+
// if it's connected via DSI, and the width & height are 0,
1210+
// it's probably the official 7 inch touchscreen.
1211+
flutterpi.display.width_mm = 155;
1212+
flutterpi.display.height_mm = 86;
1213+
} else if ((connector->connector->mmHeight % 10 == 0) &&
1214+
(connector->connector->mmWidth % 10 == 0)) {
1215+
// don't change anything.
1216+
} else {
1217+
flutterpi.display.width_mm = connector->connector->mmWidth;
1218+
flutterpi.display.height_mm = connector->connector->mmHeight;
1219+
}
12121220
}
12131221

12141222
break;
@@ -2394,21 +2402,23 @@ static bool parse_cmd_args(int argc, char **argv) {
23942402
int longopt_index = 0;
23952403
int runtime_mode_int = kDebug;
23962404
int disable_text_input_int = false;
2405+
int ok;
23972406

23982407
struct option long_options[] = {
23992408
{"release", no_argument, &runtime_mode_int, kRelease},
24002409
{"input", required_argument, NULL, 'i'},
24012410
{"orientation", required_argument, NULL, 'o'},
24022411
{"rotation", required_argument, NULL, 'r'},
24032412
{"no-text-input", no_argument, &disable_text_input_int, true},
2413+
{"dimensions", required_argument, NULL, 'd'},
24042414
{"help", no_argument, 0, 'h'},
24052415
{0, 0, 0, 0}
24062416
};
24072417

24082418
bool finished_parsing_options = false;
24092419
while (!finished_parsing_options) {
24102420
longopt_index = 0;
2411-
opt = getopt_long(argc, argv, "+i:o:r:h", long_options, &longopt_index);
2421+
opt = getopt_long(argc, argv, "+i:o:r:d:h", long_options, &longopt_index);
24122422

24132423
switch (opt) {
24142424
case 0:
@@ -2461,6 +2471,20 @@ static bool parse_cmd_args(int argc, char **argv) {
24612471
flutterpi.view.rotation = rotation;
24622472
break;
24632473

2474+
case 'd': ;
2475+
unsigned int width_mm, height_mm;
2476+
2477+
ok = sscanf(optarg, "%u,%u", &width_mm, &height_mm);
2478+
if ((ok == 0) || (ok == EOF)) {
2479+
fprintf(stderr, "ERROR: Invalid argument for --dimensions passed.\n%s", usage);
2480+
return false;
2481+
}
2482+
2483+
flutterpi.display.width_mm = width_mm;
2484+
flutterpi.display.height_mm = height_mm;
2485+
2486+
break;
2487+
24642488
case 'h':
24652489
printf("%s", usage);
24662490
return false;

0 commit comments

Comments
 (0)