1
+ #define _GNU_SOURCE
1
2
#include <stdio.h>
2
3
#include <errno.h>
3
4
#include <sys/mman.h>
5
+ #include <math.h>
4
6
5
7
#include <xf86drm.h>
6
8
#include <xf86drmMode.h>
@@ -950,6 +952,89 @@ static int execute_simulate_page_flip_event(void *userdata) {
950
952
return 0 ;
951
953
}
952
954
955
+ static void fill_platform_view_params (
956
+ struct platform_view_params * params_out ,
957
+ const FlutterPoint * offset ,
958
+ const FlutterSize * size ,
959
+ const FlutterPlatformViewMutation * * mutations ,
960
+ size_t n_mutations ,
961
+ const FlutterTransformation * display_to_view_transform ,
962
+ const FlutterTransformation * view_to_display_transform ,
963
+ double device_pixel_ratio
964
+ ) {
965
+ /**
966
+ * inversion for
967
+ * ```
968
+ * const auto transformed_layer_bounds =
969
+ * root_surface_transformation_.mapRect(layer_bounds);
970
+ * ```
971
+ */
972
+
973
+ struct quad quad = apply_transform_to_aa_rect (
974
+ * display_to_view_transform ,
975
+ (struct aa_rect ) {
976
+ .offset .x = offset -> x ,
977
+ .offset .y = offset -> y ,
978
+ .size .x = size -> width ,
979
+ .size .y = size -> height
980
+ }
981
+ );
982
+
983
+ struct aa_rect rect = get_aa_bounding_rect (quad );
984
+
985
+ /**
986
+ * inversion for
987
+ * ```
988
+ * const auto layer_bounds =
989
+ * SkRect::MakeXYWH(params.finalBoundingRect().x(),
990
+ * params.finalBoundingRect().y(),
991
+ * params.sizePoints().width() * device_pixel_ratio_,
992
+ * params.sizePoints().height() * device_pixel_ratio_
993
+ * );
994
+ * ```
995
+ */
996
+
997
+ rect .size .x /= device_pixel_ratio ;
998
+ rect .size .y /= device_pixel_ratio ;
999
+
1000
+ // okay, now we have the params.finalBoundingRect().x() in aa_back_transformed.x and
1001
+ // params.finalBoundingRect().y() in aa_back_transformed.y.
1002
+ // those are flutter view coordinates, so we still need to transform them to display coordinates.
1003
+
1004
+ // However, there are also calculated as a side-product of calculating the size of the quadrangle.
1005
+ // So we'll avoid calculating them for now. Calculation of the size may fail when the offset
1006
+ // given to `SceneBuilder.addPlatformView` (https://api.flutter.dev/flutter/dart-ui/SceneBuilder/addPlatformView.html)
1007
+ // is not zero. (Don't really know what to do in that case)
1008
+
1009
+ rect .offset .x = 0 ;
1010
+ rect .offset .y = 0 ;
1011
+ quad = get_quad (rect );
1012
+
1013
+ double rotation = 0 , opacity = 1 ;
1014
+ for (int i = n_mutations - 1 ; i >= 0 ; i -- ) {
1015
+ if (mutations [i ]-> type == kFlutterPlatformViewMutationTypeTransformation ) {
1016
+ apply_transform_to_quad (mutations [i ]-> transformation , & quad );
1017
+
1018
+ double rotz = atan2 (mutations [i ]-> transformation .skewX , mutations [i ]-> transformation .scaleX ) * 180.0 / M_PI ;
1019
+ if (rotz < 0 ) {
1020
+ rotz += 360 ;
1021
+ }
1022
+
1023
+ rotation += rotz ;
1024
+ } else if (mutations [i ]-> type == kFlutterPlatformViewMutationTypeOpacity ) {
1025
+ opacity *= mutations [i ]-> opacity ;
1026
+ }
1027
+ }
1028
+
1029
+ rotation = fmod (rotation , 360.0 );
1030
+
1031
+ params_out -> rect = quad ;
1032
+ params_out -> opacity = 0 ;
1033
+ params_out -> rotation = rotation ;
1034
+ params_out -> clip_rects = NULL ;
1035
+ params_out -> n_clip_rects = 0 ;
1036
+ }
1037
+
953
1038
/// PRESENT FUNCS
954
1039
static bool on_present_layers (
955
1040
const FlutterLayer * * layers ,
@@ -1140,6 +1225,8 @@ static bool on_present_layers(
1140
1225
if (ok != 0 ) {
1141
1226
fprintf (stderr , "[compositor] Could not unmount platform view. unmount: %s\n" , strerror (ok ));
1142
1227
}
1228
+
1229
+ cb_data -> was_present_last_frame = false;
1143
1230
}
1144
1231
}
1145
1232
@@ -1156,15 +1243,22 @@ static bool on_present_layers(
1156
1243
}
1157
1244
}
1158
1245
1246
+ struct platform_view_params params ;
1247
+ fill_platform_view_params (
1248
+ & params ,
1249
+ & layer -> offset ,
1250
+ & layer -> size ,
1251
+ layer -> platform_view -> mutations ,
1252
+ layer -> platform_view -> mutations_count ,
1253
+ & flutterpi .view .display_to_view_transform ,
1254
+ & flutterpi .view .view_to_display_transform ,
1255
+ flutterpi .display .pixel_ratio
1256
+ );
1257
+
1159
1258
ok = cb_data -> update_view (
1160
1259
cb_data -> view_id ,
1161
1260
req ,
1162
- layer -> platform_view -> mutations ,
1163
- layer -> platform_view -> mutations_count ,
1164
- (int ) round (layer -> offset .x ),
1165
- (int ) round (layer -> offset .y ),
1166
- (int ) round (layer -> size .width ),
1167
- (int ) round (layer -> size .height ),
1261
+ & params ,
1168
1262
zpos ,
1169
1263
cb_data -> userdata
1170
1264
);
@@ -1194,16 +1288,23 @@ static bool on_present_layers(
1194
1288
}
1195
1289
}
1196
1290
1291
+ struct platform_view_params params ;
1292
+ fill_platform_view_params (
1293
+ & params ,
1294
+ & layer -> offset ,
1295
+ & layer -> size ,
1296
+ layer -> platform_view -> mutations ,
1297
+ layer -> platform_view -> mutations_count ,
1298
+ & flutterpi .view .display_to_view_transform ,
1299
+ & flutterpi .view .view_to_display_transform ,
1300
+ flutterpi .display .pixel_ratio
1301
+ );
1302
+
1197
1303
if (cb_data -> mount != NULL ) {
1198
1304
ok = cb_data -> mount (
1199
1305
layer -> platform_view -> identifier ,
1200
1306
req ,
1201
- layer -> platform_view -> mutations ,
1202
- layer -> platform_view -> mutations_count ,
1203
- (int ) round (layer -> offset .x ),
1204
- (int ) round (layer -> offset .y ),
1205
- (int ) round (layer -> size .width ),
1206
- (int ) round (layer -> size .height ),
1307
+ & params ,
1207
1308
zpos ,
1208
1309
cb_data -> userdata
1209
1310
);
@@ -1212,6 +1313,7 @@ static bool on_present_layers(
1212
1313
}
1213
1314
}
1214
1315
1316
+ cb_data -> was_present_last_frame = true;
1215
1317
cb_data -> last_zpos = zpos ;
1216
1318
cb_data -> last_size = layer -> size ;
1217
1319
cb_data -> last_offset = layer -> offset ;
@@ -1314,15 +1416,22 @@ static bool on_present_layers(
1314
1416
cb_data = get_cbs_for_view_id_locked (layers [i ]-> platform_view -> identifier );
1315
1417
1316
1418
if ((cb_data != NULL ) && (cb_data -> present != NULL )) {
1419
+ struct platform_view_params params ;
1420
+ fill_platform_view_params (
1421
+ & params ,
1422
+ & layers [i ]-> offset ,
1423
+ & layers [i ]-> size ,
1424
+ layers [i ]-> platform_view -> mutations ,
1425
+ layers [i ]-> platform_view -> mutations_count ,
1426
+ & flutterpi .view .display_to_view_transform ,
1427
+ & flutterpi .view .view_to_display_transform ,
1428
+ flutterpi .display .pixel_ratio
1429
+ );
1430
+
1317
1431
ok = cb_data -> present (
1318
1432
cb_data -> view_id ,
1319
1433
req ,
1320
- layers [i ]-> platform_view -> mutations ,
1321
- layers [i ]-> platform_view -> mutations_count ,
1322
- (int ) round (layers [i ]-> offset .x ),
1323
- (int ) round (layers [i ]-> offset .y ),
1324
- (int ) round (layers [i ]-> size .width ),
1325
- (int ) round (layers [i ]-> size .height ),
1434
+ & params ,
1326
1435
i + min_zpos ,
1327
1436
cb_data -> userdata
1328
1437
);
0 commit comments