Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Move viewConfiguration parsing from PlatformDispatcher to _hooks #44787

Merged
merged 3 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 92 additions & 3 deletions lib/ui/hooks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,98 @@ void _updateDisplays(
PlatformDispatcher.instance._updateDisplays(displays);
}

List<DisplayFeature> _decodeDisplayFeatures({
required List<double> bounds,
required List<int> type,
required List<int> state,
required double devicePixelRatio,
}) {
assert(bounds.length / 4 == type.length, 'Bounds are rectangles, requiring 4 measurements each');
assert(type.length == state.length);
final List<DisplayFeature> result = <DisplayFeature>[];
for(int i = 0; i < type.length; i++) {
final int rectOffset = i * 4;
result.add(DisplayFeature(
bounds: Rect.fromLTRB(
bounds[rectOffset] / devicePixelRatio,
bounds[rectOffset + 1] / devicePixelRatio,
bounds[rectOffset + 2] / devicePixelRatio,
bounds[rectOffset + 3] / devicePixelRatio,
),
type: DisplayFeatureType.values[type[i]],
state: state[i] < DisplayFeatureState.values.length
? DisplayFeatureState.values[state[i]]
: DisplayFeatureState.unknown,
));
}
return result;
}

_ViewConfiguration _buildViewConfiguration(
double devicePixelRatio,
double width,
double height,
double viewPaddingTop,
double viewPaddingRight,
double viewPaddingBottom,
double viewPaddingLeft,
double viewInsetTop,
double viewInsetRight,
double viewInsetBottom,
double viewInsetLeft,
double systemGestureInsetTop,
double systemGestureInsetRight,
double systemGestureInsetBottom,
double systemGestureInsetLeft,
double physicalTouchSlop,
List<double> displayFeaturesBounds,
List<int> displayFeaturesType,
List<int> displayFeaturesState,
int displayId,
) {
return _ViewConfiguration(
devicePixelRatio: devicePixelRatio,
geometry: Rect.fromLTWH(0.0, 0.0, width, height),
viewPadding: ViewPadding._(
top: viewPaddingTop,
right: viewPaddingRight,
bottom: viewPaddingBottom,
left: viewPaddingLeft,
),
viewInsets: ViewPadding._(
top: viewInsetTop,
right: viewInsetRight,
bottom: viewInsetBottom,
left: viewInsetLeft,
),
padding: ViewPadding._(
top: math.max(0.0, viewPaddingTop - viewInsetTop),
right: math.max(0.0, viewPaddingRight - viewInsetRight),
bottom: math.max(0.0, viewPaddingBottom - viewInsetBottom),
left: math.max(0.0, viewPaddingLeft - viewInsetLeft),
),
systemGestureInsets: ViewPadding._(
top: math.max(0.0, systemGestureInsetTop),
right: math.max(0.0, systemGestureInsetRight),
bottom: math.max(0.0, systemGestureInsetBottom),
left: math.max(0.0, systemGestureInsetLeft),
),
gestureSettings: GestureSettings(
physicalTouchSlop: physicalTouchSlop == _kUnsetGestureSetting ? null : physicalTouchSlop,
),
displayFeatures: _decodeDisplayFeatures(
bounds: displayFeaturesBounds,
type: displayFeaturesType,
state: displayFeaturesState,
devicePixelRatio: devicePixelRatio,
),
displayId: displayId,
);
}

@pragma('vm:entry-point')
void _updateWindowMetrics(
int id,
int viewId,
double devicePixelRatio,
double width,
double height,
Expand All @@ -54,8 +143,7 @@ void _updateWindowMetrics(
List<int> displayFeaturesState,
int displayId,
) {
PlatformDispatcher.instance._updateWindowMetrics(
id,
final _ViewConfiguration viewConfiguration = _buildViewConfiguration(
devicePixelRatio,
width,
height,
Expand All @@ -77,6 +165,7 @@ void _updateWindowMetrics(
displayFeaturesState,
displayId,
);
PlatformDispatcher.instance._updateWindowMetrics(viewId, viewConfiguration);
}

typedef _LocaleClosure = String Function();
Expand Down
96 changes: 4 additions & 92 deletions lib/ui/platform_dispatcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -263,107 +263,19 @@ class PlatformDispatcher {
// Called from the engine, via hooks.dart
//
// Updates the metrics of the window with the given id.
void _updateWindowMetrics(
int id,
double devicePixelRatio,
double width,
double height,
double viewPaddingTop,
double viewPaddingRight,
double viewPaddingBottom,
double viewPaddingLeft,
double viewInsetTop,
double viewInsetRight,
double viewInsetBottom,
double viewInsetLeft,
double systemGestureInsetTop,
double systemGestureInsetRight,
double systemGestureInsetBottom,
double systemGestureInsetLeft,
double physicalTouchSlop,
List<double> displayFeaturesBounds,
List<int> displayFeaturesType,
List<int> displayFeaturesState,
int displayId,
) {
final _ViewConfiguration viewConfiguration = _ViewConfiguration(
devicePixelRatio: devicePixelRatio,
geometry: Rect.fromLTWH(0.0, 0.0, width, height),
viewPadding: ViewPadding._(
top: viewPaddingTop,
right: viewPaddingRight,
bottom: viewPaddingBottom,
left: viewPaddingLeft,
),
viewInsets: ViewPadding._(
top: viewInsetTop,
right: viewInsetRight,
bottom: viewInsetBottom,
left: viewInsetLeft,
),
padding: ViewPadding._(
top: math.max(0.0, viewPaddingTop - viewInsetTop),
right: math.max(0.0, viewPaddingRight - viewInsetRight),
bottom: math.max(0.0, viewPaddingBottom - viewInsetBottom),
left: math.max(0.0, viewPaddingLeft - viewInsetLeft),
),
systemGestureInsets: ViewPadding._(
top: math.max(0.0, systemGestureInsetTop),
right: math.max(0.0, systemGestureInsetRight),
bottom: math.max(0.0, systemGestureInsetBottom),
left: math.max(0.0, systemGestureInsetLeft),
),
gestureSettings: GestureSettings(
physicalTouchSlop: physicalTouchSlop == _kUnsetGestureSetting ? null : physicalTouchSlop,
),
displayFeatures: _decodeDisplayFeatures(
bounds: displayFeaturesBounds,
type: displayFeaturesType,
state: displayFeaturesState,
devicePixelRatio: devicePixelRatio,
),
displayId: displayId,
);

final FlutterView? view = _views[id];
if (id == _kImplicitViewId && view == null) {
void _updateWindowMetrics(int viewId, _ViewConfiguration viewConfiguration) {
final FlutterView? view = _views[viewId];
if (viewId == _kImplicitViewId && view == null) {
// TODO(goderbauer): Remove the implicit creation of the implicit view
// when we have an addView API and the implicit view is added via that.
_views[id] = FlutterView._(id, this, viewConfiguration);
_views[viewId] = FlutterView._(viewId, this, viewConfiguration);
} else {
assert(view != null);
view!._viewConfiguration = viewConfiguration;
}

_invoke(onMetricsChanged, _onMetricsChangedZone);
}

List<DisplayFeature> _decodeDisplayFeatures({
required List<double> bounds,
required List<int> type,
required List<int> state,
required double devicePixelRatio,
}) {
assert(bounds.length / 4 == type.length, 'Bounds are rectangles, requiring 4 measurements each');
assert(type.length == state.length);
final List<DisplayFeature> result = <DisplayFeature>[];
for(int i = 0; i < type.length; i++) {
final int rectOffset = i * 4;
result.add(DisplayFeature(
bounds: Rect.fromLTRB(
bounds[rectOffset] / devicePixelRatio,
bounds[rectOffset + 1] / devicePixelRatio,
bounds[rectOffset + 2] / devicePixelRatio,
bounds[rectOffset + 3] / devicePixelRatio,
),
type: DisplayFeatureType.values[type[i]],
state: state[i] < DisplayFeatureState.values.length
? DisplayFeatureState.values[state[i]]
: DisplayFeatureState.unknown,
));
}
return result;
}

/// A callback invoked when any view begins a frame.
///
Expand Down