diff --git a/lib/ui/hooks.dart b/lib/ui/hooks.dart index c391d273e1e59..7d31bd4f0c2f1 100644 --- a/lib/ui/hooks.dart +++ b/lib/ui/hooks.dart @@ -30,9 +30,98 @@ void _updateDisplays( PlatformDispatcher.instance._updateDisplays(displays); } +List _decodeDisplayFeatures({ + required List bounds, + required List type, + required List state, + required double devicePixelRatio, +}) { + assert(bounds.length / 4 == type.length, 'Bounds are rectangles, requiring 4 measurements each'); + assert(type.length == state.length); + final List result = []; + 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 displayFeaturesBounds, + List displayFeaturesType, + List 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, @@ -54,8 +143,7 @@ void _updateWindowMetrics( List displayFeaturesState, int displayId, ) { - PlatformDispatcher.instance._updateWindowMetrics( - id, + final _ViewConfiguration viewConfiguration = _buildViewConfiguration( devicePixelRatio, width, height, @@ -77,6 +165,7 @@ void _updateWindowMetrics( displayFeaturesState, displayId, ); + PlatformDispatcher.instance._updateWindowMetrics(viewId, viewConfiguration); } typedef _LocaleClosure = String Function(); diff --git a/lib/ui/platform_dispatcher.dart b/lib/ui/platform_dispatcher.dart index ebcc86456d00c..a8ff3144b6a28 100644 --- a/lib/ui/platform_dispatcher.dart +++ b/lib/ui/platform_dispatcher.dart @@ -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 displayFeaturesBounds, - List displayFeaturesType, - List 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 _decodeDisplayFeatures({ - required List bounds, - required List type, - required List state, - required double devicePixelRatio, - }) { - assert(bounds.length / 4 == type.length, 'Bounds are rectangles, requiring 4 measurements each'); - assert(type.length == state.length); - final List result = []; - 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. ///