From 5a9ac6e780d5ff085478a52e2311c0d6b56dbdeb Mon Sep 17 00:00:00 2001 From: Dan Field Date: Fri, 2 Aug 2019 20:37:24 -0700 Subject: [PATCH] expose max depth on Window (flutter/engine#10414) --- engine/src/flutter/lib/ui/hooks.dart | 2 + engine/src/flutter/lib/ui/window.dart | 14 +++++ .../flutter/lib/ui/window/viewport_metrics.h | 6 ++- engine/src/flutter/lib/ui/window/window.cc | 1 + .../dart/window_hooks_integration_test.dart | 51 +++++++++++-------- 5 files changed, 53 insertions(+), 21 deletions(-) diff --git a/engine/src/flutter/lib/ui/hooks.dart b/engine/src/flutter/lib/ui/hooks.dart index 305dde4721..6f0fa3a2d8 100644 --- a/engine/src/flutter/lib/ui/hooks.dart +++ b/engine/src/flutter/lib/ui/hooks.dart @@ -21,6 +21,7 @@ dynamic _decodeJSON(String message) { void _updateWindowMetrics(double devicePixelRatio, double width, double height, + double depth, double viewPaddingTop, double viewPaddingRight, double viewPaddingBottom, @@ -32,6 +33,7 @@ void _updateWindowMetrics(double devicePixelRatio, window .._devicePixelRatio = devicePixelRatio .._physicalSize = Size(width, height) + .._physicalDepth = depth .._viewPadding = WindowPadding._( top: viewPaddingTop, right: viewPaddingRight, diff --git a/engine/src/flutter/lib/ui/window.dart b/engine/src/flutter/lib/ui/window.dart index de20416af3..2858b422a3 100644 --- a/engine/src/flutter/lib/ui/window.dart +++ b/engine/src/flutter/lib/ui/window.dart @@ -618,6 +618,20 @@ class Window { Size get physicalSize => _physicalSize; Size _physicalSize = Size.zero; + /// The physical depth is the maximum elevation that the Window allows. + /// + /// Physical layers drawn at or above this elevation will have their elevation + /// clamped to this value. This can happen if the physical layer itself has + /// an elevation larger than available depth, or if some ancestor of the layer + /// causes it to have a cumulative elevation that is larger than the available + /// depth. + /// + /// The default value is [double.maxFinite], which is used for platforms that + /// do not specify a maximum elevation. This property is currently on expected + /// to be set to a non-default value on Fuchsia. + double get physicalDepth => _physicalDepth; + double _physicalDepth = double.maxFinite; + /// The number of physical pixels on each side of the display rectangle into /// which the application can render, but over which the operating system /// will likely place system UI, such as the keyboard, that fully obscures diff --git a/engine/src/flutter/lib/ui/window/viewport_metrics.h b/engine/src/flutter/lib/ui/window/viewport_metrics.h index aa0d7dc8ea..578dbcf664 100644 --- a/engine/src/flutter/lib/ui/window/viewport_metrics.h +++ b/engine/src/flutter/lib/ui/window/viewport_metrics.h @@ -9,7 +9,11 @@ namespace flutter { -static const double kUnsetDepth = -1; +// This is the value of double.maxFinite from dart:core. +// Platforms that do not explicitly set a depth will use this value, which +// avoids the need to special case logic that wants to check the max depth on +// the Dart side. +static const double kUnsetDepth = 1.7976931348623157e+308; struct ViewportMetrics { ViewportMetrics(); diff --git a/engine/src/flutter/lib/ui/window/window.cc b/engine/src/flutter/lib/ui/window/window.cc index 64fb076daa..86c050f25e 100644 --- a/engine/src/flutter/lib/ui/window/window.cc +++ b/engine/src/flutter/lib/ui/window/window.cc @@ -185,6 +185,7 @@ void Window::UpdateWindowMetrics(const ViewportMetrics& metrics) { tonic::ToDart(metrics.device_pixel_ratio), tonic::ToDart(metrics.physical_width), tonic::ToDart(metrics.physical_height), + tonic::ToDart(metrics.physical_depth), tonic::ToDart(metrics.physical_padding_top), tonic::ToDart(metrics.physical_padding_right), tonic::ToDart(metrics.physical_padding_bottom), diff --git a/engine/src/flutter/testing/dart/window_hooks_integration_test.dart b/engine/src/flutter/testing/dart/window_hooks_integration_test.dart index d516a3a583..25812fad24 100644 --- a/engine/src/flutter/testing/dart/window_hooks_integration_test.dart +++ b/engine/src/flutter/testing/dart/window_hooks_integration_test.dart @@ -43,7 +43,19 @@ void main() { PlatformMessageCallback originalOnPlatformMessage; VoidCallback originalOnTextScaleFactorChanged; + double oldDPR; + Size oldSize; + double oldDepth; + WindowPadding oldPadding; + WindowPadding oldInsets; + setUp(() { + oldDPR = window.devicePixelRatio; + oldSize = window.physicalSize; + oldDepth = window.physicalDepth; + oldPadding = window.viewPadding; + oldInsets = window.viewInsets; + originalOnMetricsChanged = window.onMetricsChanged; originalOnLocaleChanged = window.onLocaleChanged; originalOnBeginFrame = window.onBeginFrame; @@ -57,6 +69,20 @@ void main() { }); tearDown(() { + _updateWindowMetrics( + oldDPR, // DPR + oldSize.width, // width + oldSize.height, // height + oldDepth, // depth + oldPadding.top, // padding top + oldPadding.right, // padding right + oldPadding.bottom, // padding bottom + oldPadding.left, // padding left + oldInsets.top, // inset top + oldInsets.right, // inset right + oldInsets.bottom, // inset bottom + oldInsets.left, // inset left + ); window.onMetricsChanged = originalOnMetricsChanged; window.onLocaleChanged = originalOnLocaleChanged; window.onBeginFrame = originalOnBeginFrame; @@ -89,7 +115,7 @@ void main() { }); window.onMetricsChanged(); - _updateWindowMetrics(0.1234, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0); + _updateWindowMetrics(0.1234, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0); expect(runZone, isNotNull); expect(runZone, same(innerZone)); expect(devicePixelRatio, equals(0.1234)); @@ -290,15 +316,11 @@ void main() { test('Window padding/insets/viewPadding', () { - final double oldDPR = window.devicePixelRatio; - final Size oldSize = window.physicalSize; - final WindowPadding oldPadding = window.viewPadding; - final WindowPadding oldInsets = window.viewInsets; - _updateWindowMetrics( 1.0, // DPR 800.0, // width 600.0, // height + 100.0, // depth 50.0, // padding top 0.0, // padding right 40.0, // padding bottom @@ -312,11 +334,13 @@ void main() { expect(window.viewInsets.bottom, 0.0); expect(window.viewPadding.bottom, 40.0); expect(window.padding.bottom, 40.0); + expect(window.physicalDepth, 100.0); _updateWindowMetrics( 1.0, // DPR 800.0, // width 600.0, // height + 100.0, // depth 50.0, // padding top 0.0, // padding right 40.0, // padding bottom @@ -330,20 +354,7 @@ void main() { expect(window.viewInsets.bottom, 400.0); expect(window.viewPadding.bottom, 40.0); expect(window.padding.bottom, 0.0); - - _updateWindowMetrics( - oldDPR, // DPR - oldSize.width, // width - oldSize.height, // height - oldPadding.top, // padding top - oldPadding.right, // padding right - oldPadding.bottom, // padding bottom - oldPadding.left, // padding left - oldInsets.top, // inset top - oldInsets.right, // inset right - oldInsets.bottom, // inset bottom - oldInsets.left, // inset left - ); + expect(window.physicalDepth, 100.0); }); }); }