@luckylca/react-native-liquid-glass 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +307 -2
- package/README.zh-CN.md +310 -0
- package/THIRD_PARTY_NOTICES.md +98 -0
- package/android/build.gradle +19 -0
- package/android/src/main/AndroidManifest.xml +1 -0
- package/android/src/main/java/expo/modules/localglass/ExpoLocalGlassEngineModule.kt +141 -0
- package/android/src/main/java/expo/modules/localglass/ExpoLocalGlassModule.kt +341 -0
- package/android/src/main/java/expo/modules/localglass/LocalGlassShader.kt +59 -0
- package/android/src/main/java/expo/modules/newhuliquidglass/CoreLiquidGlassRegistry.kt +75 -0
- package/android/src/main/java/expo/modules/newhuliquidglass/EffectiveScrollInputBridge.kt +47 -0
- package/android/src/main/java/expo/modules/newhuliquidglass/ExpoGlassCoreModule.kt +226 -0
- package/android/src/main/java/expo/modules/newhuliquidglass/ExpoGlassProviderCoreView.kt +1125 -0
- package/android/src/main/java/expo/modules/newhuliquidglass/ExpoGlassSurfaceCoreView.kt +571 -0
- package/android/src/main/java/expo/modules/newhuliquidglass/PassSurfaceSuppression.kt +39 -0
- package/android/src/main/java/expo/modules/newhuliquidglass/SharedGlassPassProbeLog.kt +23 -0
- package/android/src/main/java/expo/modules/newhuliquidglass/SharedGlassPassWiring.kt +59 -0
- package/android-core/build.gradle +36 -0
- package/android-core/src/main/java/com/newhu/liquidglass/backdrop/BackdropRecorder.kt +930 -0
- package/android-core/src/main/java/com/newhu/liquidglass/backdrop/FrozenBackdrop.kt +66 -0
- package/android-core/src/main/java/com/newhu/liquidglass/backdrop/GlassBackdropCoordinator.kt +624 -0
- package/android-core/src/main/java/com/newhu/liquidglass/backdrop/GlassBackdropSourceHandle.kt +8 -0
- package/android-core/src/main/java/com/newhu/liquidglass/backdrop/GlassScrollSource.kt +13 -0
- package/android-core/src/main/java/com/newhu/liquidglass/backdrop/GlassViewController.kt +1605 -0
- package/android-core/src/main/java/com/newhu/liquidglass/backdrop/LiquidGlassProviderLayout.kt +340 -0
- package/android-core/src/main/java/com/newhu/liquidglass/backdrop/LiquidGlassView.kt +103 -0
- package/android-core/src/main/java/com/newhu/liquidglass/backdrop/ReferenceSourceWindowPolicy.kt +13 -0
- package/android-core/src/main/java/com/newhu/liquidglass/backdrop/StableSceneTexturePolicy.kt +43 -0
- package/android-core/src/main/java/com/newhu/liquidglass/backdrop/internal/GlassViewRenderer.kt +1459 -0
- package/android-core/src/main/java/com/newhu/liquidglass/backdrop/internal/ReferenceTabSampling.kt +15 -0
- package/android-core/src/main/java/com/newhu/liquidglass/backdrop/internal/SharedSceneCapture.kt +163 -0
- package/android-core/src/main/java/com/newhu/liquidglass/core/GlassCapabilities.kt +21 -0
- package/android-core/src/main/java/com/newhu/liquidglass/core/GlassEngine.kt +131 -0
- package/android-core/src/main/java/com/newhu/liquidglass/core/GlassMaterial.kt +89 -0
- package/android-core/src/main/java/com/newhu/liquidglass/core/GlassMath.kt +131 -0
- package/android-core/src/main/java/com/newhu/liquidglass/core/GlassOpticalInsets.kt +8 -0
- package/android-core/src/main/java/com/newhu/liquidglass/core/GlassRenderTier.kt +54 -0
- package/android-core/src/main/java/com/newhu/liquidglass/core/GlassShapePacker.kt +77 -0
- package/android-core/src/main/java/com/newhu/liquidglass/core/GlassSurfaceState.kt +11 -0
- package/android-core/src/main/java/com/newhu/liquidglass/core/GlassUniforms.kt +113 -0
- package/android-core/src/main/java/com/newhu/liquidglass/core/LiquidGlassShaders.kt +234 -0
- package/android-core/src/main/java/com/newhu/liquidglass/core/SharedGlassPass.kt +456 -0
- package/android-core/src/main/java/com/newhu/liquidglass/core/geometry/G2RoundedRectangle.kt +207 -0
- package/android-core/src/main/java/com/newhu/liquidglass/core/geometry/ReferenceG2MaskTexture.kt +334 -0
- package/android-core/src/main/java/com/newhu/liquidglass/core/shader/HeightFieldGlassShader.kt +7 -0
- package/android-core/src/main/java/com/newhu/liquidglass/core/shader/ReferenceBackdropBlurShader.kt +58 -0
- package/android-core/src/main/java/com/newhu/liquidglass/core/shader/ReferenceGaussianDiscBackdropBlur.kt +42 -0
- package/android-core/src/main/java/com/newhu/liquidglass/core/shader/ReferenceGlassUniforms.kt +111 -0
- package/android-core/src/main/java/com/newhu/liquidglass/core/shader/ReferenceParityGlassShader.kt +613 -0
- package/android-core/src/main/java/com/newhu/liquidglass/core/shader/ReferenceParityMultiShapeShader.kt +128 -0
- package/android-core/src/main/java/com/newhu/liquidglass/core/shader/SdfScaleLensShader.kt +144 -0
- package/android-core/src/main/java/com/newhu/liquidglass/local/LocalGlassHardwareLayerExperiment.kt +29 -0
- package/android-core/src/main/java/com/newhu/liquidglass/local/LocalGlassMaterial.kt +14 -0
- package/android-core/src/main/java/com/newhu/liquidglass/local/LocalGlassRenderer.kt +126 -0
- package/android-core/src/main/java/com/newhu/liquidglass/local/LocalGlassRuntimeShader.kt +50 -0
- package/android-core/src/main/java/com/newhu/liquidglass/local/LocalGlassShader.kt +59 -0
- package/android-core/src/main/java/com/newhu/liquidglass/local/LocalGlassView.kt +47 -0
- package/android-core/src/main/java/com/newhu/liquidglass/motion/GlassMotionDriver.kt +824 -0
- package/android-core/src/main/java/com/newhu/liquidglass/motion/GlassMotionState.kt +359 -0
- package/android-core/src/main/java/com/newhu/liquidglass/motion/PointerVelocityTracker.kt +109 -0
- package/android-core/src/main/java/com/newhu/liquidglass/motion/SpringSpec.kt +209 -0
- package/android-core/src/main/java/com/newhu/liquidglass/optics/G2Corner.kt +194 -0
- package/android-core/src/main/java/com/newhu/liquidglass/optics/GlassMaterial.kt +250 -0
- package/android-core/src/main/java/com/newhu/liquidglass/optics/GlassOpticsShader.kt +696 -0
- package/android-core/src/main/java/com/newhu/liquidglass/optics/GlassParityProbe.kt +342 -0
- package/android-core/src/main/java/com/newhu/liquidglass/optics/GlassShapeGeometry.kt +317 -0
- package/android-core/src/main/java/com/newhu/liquidglass/optics/GlassUniformBinder.kt +308 -0
- package/android-core/src/main/java/com/newhu/liquidglass/optics/PixelDiff.kt +363 -0
- package/android-core/src/main/java/com/newhu/liquidglass/optics/ReferenceOptics.kt +568 -0
- package/android-core/src/main/java/com/newhu/liquidglass/rendering/GlassEngineSelection.kt +30 -0
- package/android-core/src/main/java/com/newhu/liquidglass/rendering/GlassSurfaceHost.kt +317 -0
- package/android-core/src/main/java/com/newhu/liquidglass/rendering/GlassSurfaceRenderer.kt +847 -0
- package/android-core/src/main/java/com/newhu/liquidglass/rendering/RetainedBackdropLayer.kt +83 -0
- package/android-core/src/main/java/com/newhu/liquidglass/scheduler/GlassFrameScheduler.kt +27 -0
- package/android-core/src/main/java/com/newhu/liquidglass/telemetry/EffectiveScrollFpsProbe.kt +965 -0
- package/android-core/src/main/java/com/newhu/liquidglass/telemetry/GlassTelemetry.kt +16 -0
- package/android-core/src/main/java/com/newhu/liquidglass/telemetry/LiquidGlassPerfTelemetry.kt +676 -0
- package/android-core/src/main/java/com/newhu/liquidglass/telemetry/LiquidGlassTrace.kt +30 -0
- package/android-core/src/main/java/com/newhu/liquidglass/telemetry/LocalGlassTelemetry.kt +55 -0
- package/app.plugin.js +25 -0
- package/docs/images/buttons.webp +0 -0
- package/docs/images/controls.webp +0 -0
- package/docs/images/tabs.webp +0 -0
- package/docs/publishing.md +84 -0
- package/expo-module.config.json +10 -0
- package/lib/commonjs/GlassSurface.js +832 -0
- package/lib/commonjs/GlassSurface.js.map +1 -0
- package/lib/commonjs/GlassTabBar.js +976 -0
- package/lib/commonjs/GlassTabBar.js.map +1 -0
- package/lib/commonjs/GlassTabLens.js +67 -0
- package/lib/commonjs/GlassTabLens.js.map +1 -0
- package/lib/commonjs/LiquidGlassProvider.js +40 -0
- package/lib/commonjs/LiquidGlassProvider.js.map +1 -0
- package/lib/commonjs/LocalGlassMaterial.js +194 -0
- package/lib/commonjs/LocalGlassMaterial.js.map +1 -0
- package/lib/commonjs/adaptiveLuminance.js +14 -0
- package/lib/commonjs/adaptiveLuminance.js.map +1 -0
- package/lib/commonjs/badgePalette.js +46 -0
- package/lib/commonjs/badgePalette.js.map +1 -0
- package/lib/commonjs/buttonGesturePolicy.js +22 -0
- package/lib/commonjs/buttonGesturePolicy.js.map +1 -0
- package/lib/commonjs/components/AdaptiveLuminance.js +20 -0
- package/lib/commonjs/components/AdaptiveLuminance.js.map +1 -0
- package/lib/commonjs/components/BottomSheet.js +222 -0
- package/lib/commonjs/components/BottomSheet.js.map +1 -0
- package/lib/commonjs/components/Button.js +20 -0
- package/lib/commonjs/components/Button.js.map +1 -0
- package/lib/commonjs/components/Card.js +206 -0
- package/lib/commonjs/components/Card.js.map +1 -0
- package/lib/commonjs/components/Checkbox.js +123 -0
- package/lib/commonjs/components/Checkbox.js.map +1 -0
- package/lib/commonjs/components/ControlPressContext.js +8 -0
- package/lib/commonjs/components/ControlPressContext.js.map +1 -0
- package/lib/commonjs/components/Dialog.js +122 -0
- package/lib/commonjs/components/Dialog.js.map +1 -0
- package/lib/commonjs/components/DialogAction.js +124 -0
- package/lib/commonjs/components/DialogAction.js.map +1 -0
- package/lib/commonjs/components/DialogContent.js +23 -0
- package/lib/commonjs/components/DialogContent.js.map +1 -0
- package/lib/commonjs/components/GlassButton.js +96 -0
- package/lib/commonjs/components/GlassButton.js.map +1 -0
- package/lib/commonjs/components/GlassFab.js +43 -0
- package/lib/commonjs/components/GlassFab.js.map +1 -0
- package/lib/commonjs/components/GlassMagnifier.js +135 -0
- package/lib/commonjs/components/GlassMagnifier.js.map +1 -0
- package/lib/commonjs/components/GlassPlayground.js +158 -0
- package/lib/commonjs/components/GlassPlayground.js.map +1 -0
- package/lib/commonjs/components/GlassSlider.js +364 -0
- package/lib/commonjs/components/GlassSlider.js.map +1 -0
- package/lib/commonjs/components/GlassSwitch.js +334 -0
- package/lib/commonjs/components/GlassSwitch.js.map +1 -0
- package/lib/commonjs/components/GlassTabBar.js +387 -0
- package/lib/commonjs/components/GlassTabBar.js.map +1 -0
- package/lib/commonjs/components/Input.js +180 -0
- package/lib/commonjs/components/Input.js.map +1 -0
- package/lib/commonjs/components/ListRow.js +64 -0
- package/lib/commonjs/components/ListRow.js.map +1 -0
- package/lib/commonjs/components/Menu.js +214 -0
- package/lib/commonjs/components/Menu.js.map +1 -0
- package/lib/commonjs/components/NavigationBar.js +20 -0
- package/lib/commonjs/components/NavigationBar.js.map +1 -0
- package/lib/commonjs/components/NumberWheel.js +273 -0
- package/lib/commonjs/components/NumberWheel.js.map +1 -0
- package/lib/commonjs/components/PageFeedList.js +25 -0
- package/lib/commonjs/components/PageFeedList.js.map +1 -0
- package/lib/commonjs/components/PageScaffold.js +161 -0
- package/lib/commonjs/components/PageScaffold.js.map +1 -0
- package/lib/commonjs/components/PreferenceGroup.js +34 -0
- package/lib/commonjs/components/PreferenceGroup.js.map +1 -0
- package/lib/commonjs/components/ProgressIndicator.js +79 -0
- package/lib/commonjs/components/ProgressIndicator.js.map +1 -0
- package/lib/commonjs/components/ProgressiveBlur.js +29 -0
- package/lib/commonjs/components/ProgressiveBlur.js.map +1 -0
- package/lib/commonjs/components/ReferenceSlider.js +304 -0
- package/lib/commonjs/components/ReferenceSlider.js.map +1 -0
- package/lib/commonjs/components/ReferenceTabBar.js +381 -0
- package/lib/commonjs/components/ReferenceTabBar.js.map +1 -0
- package/lib/commonjs/components/SearchBar.js +200 -0
- package/lib/commonjs/components/SearchBar.js.map +1 -0
- package/lib/commonjs/components/SegmentedControl.js +62 -0
- package/lib/commonjs/components/SegmentedControl.js.map +1 -0
- package/lib/commonjs/components/Slider.js +12 -0
- package/lib/commonjs/components/Slider.js.map +1 -0
- package/lib/commonjs/components/Snackbar.js +11 -0
- package/lib/commonjs/components/Snackbar.js.map +1 -0
- package/lib/commonjs/components/SurfaceEnvironmentContext.js +35 -0
- package/lib/commonjs/components/SurfaceEnvironmentContext.js.map +1 -0
- package/lib/commonjs/components/SurfaceGroup.js +39 -0
- package/lib/commonjs/components/SurfaceGroup.js.map +1 -0
- package/lib/commonjs/components/Switch.js +11 -0
- package/lib/commonjs/components/Switch.js.map +1 -0
- package/lib/commonjs/components/Toast.js +110 -0
- package/lib/commonjs/components/Toast.js.map +1 -0
- package/lib/commonjs/components/TopAppBar.js +107 -0
- package/lib/commonjs/components/TopAppBar.js.map +1 -0
- package/lib/commonjs/components/bottomSheetMotion.js +14 -0
- package/lib/commonjs/components/bottomSheetMotion.js.map +1 -0
- package/lib/commonjs/components/glassControlMaterial.js +22 -0
- package/lib/commonjs/components/glassControlMaterial.js.map +1 -0
- package/lib/commonjs/components/menuPosition.js +42 -0
- package/lib/commonjs/components/menuPosition.js.map +1 -0
- package/lib/commonjs/components/pages/FeedPage.js +15 -0
- package/lib/commonjs/components/pages/FeedPage.js.map +1 -0
- package/lib/commonjs/components/pages/PageBenchmarkContext.js +123 -0
- package/lib/commonjs/components/pages/PageBenchmarkContext.js.map +1 -0
- package/lib/commonjs/components/pages/SettingsPage.js +47 -0
- package/lib/commonjs/components/pages/SettingsPage.js.map +1 -0
- package/lib/commonjs/components/pages/SettingsSection.js +14 -0
- package/lib/commonjs/components/pages/SettingsSection.js.map +1 -0
- package/lib/commonjs/components/pages/StaticSettingsPage.js +16 -0
- package/lib/commonjs/components/pages/StaticSettingsPage.js.map +1 -0
- package/lib/commonjs/fallbackKnobGeometry.js +19 -0
- package/lib/commonjs/fallbackKnobGeometry.js.map +1 -0
- package/lib/commonjs/glassController.js +65 -0
- package/lib/commonjs/glassController.js.map +1 -0
- package/lib/commonjs/glassNativeEngine.js +16 -0
- package/lib/commonjs/glassNativeEngine.js.map +1 -0
- package/lib/commonjs/glassRuntime.js +27 -0
- package/lib/commonjs/glassRuntime.js.map +1 -0
- package/lib/commonjs/index.js +218 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/inputPresentation.js +17 -0
- package/lib/commonjs/inputPresentation.js.map +1 -0
- package/lib/commonjs/localGlassTelemetry.js +113 -0
- package/lib/commonjs/localGlassTelemetry.js.map +1 -0
- package/lib/commonjs/motion/MotionProvider.js +15 -0
- package/lib/commonjs/motion/MotionProvider.js.map +1 -0
- package/lib/commonjs/motion/easings.js +71 -0
- package/lib/commonjs/motion/easings.js.map +1 -0
- package/lib/commonjs/motion/folmeSpring.js +24 -0
- package/lib/commonjs/motion/folmeSpring.js.map +1 -0
- package/lib/commonjs/motion/folmeSpringByResponse.js +22 -0
- package/lib/commonjs/motion/folmeSpringByResponse.js.map +1 -0
- package/lib/commonjs/motion/index.js +57 -0
- package/lib/commonjs/motion/index.js.map +1 -0
- package/lib/commonjs/motion/presets.js +101 -0
- package/lib/commonjs/motion/presets.js.map +1 -0
- package/lib/commonjs/nativeGlassViews.js +33 -0
- package/lib/commonjs/nativeGlassViews.js.map +1 -0
- package/lib/commonjs/performanceTelemetry.js +28 -0
- package/lib/commonjs/performanceTelemetry.js.map +1 -0
- package/lib/commonjs/pointerEventBridge.js +17 -0
- package/lib/commonjs/pointerEventBridge.js.map +1 -0
- package/lib/commonjs/pointerGeometry.js +12 -0
- package/lib/commonjs/pointerGeometry.js.map +1 -0
- package/lib/commonjs/pressVelocity.js +34 -0
- package/lib/commonjs/pressVelocity.js.map +1 -0
- package/lib/commonjs/primitives/Divider.js +32 -0
- package/lib/commonjs/primitives/Divider.js.map +1 -0
- package/lib/commonjs/primitives/Icon.js +22 -0
- package/lib/commonjs/primitives/Icon.js.map +1 -0
- package/lib/commonjs/primitives/PressIndication.js +58 -0
- package/lib/commonjs/primitives/PressIndication.js.map +1 -0
- package/lib/commonjs/primitives/Pressable.js +28 -0
- package/lib/commonjs/primitives/Pressable.js.map +1 -0
- package/lib/commonjs/primitives/PressableScale.js +64 -0
- package/lib/commonjs/primitives/PressableScale.js.map +1 -0
- package/lib/commonjs/primitives/Surface.js +122 -0
- package/lib/commonjs/primitives/Surface.js.map +1 -0
- package/lib/commonjs/primitives/Text.js +43 -0
- package/lib/commonjs/primitives/Text.js.map +1 -0
- package/lib/commonjs/primitives/index.js +18 -0
- package/lib/commonjs/primitives/index.js.map +1 -0
- package/lib/commonjs/renderer.js +58 -0
- package/lib/commonjs/renderer.js.map +1 -0
- package/lib/commonjs/sliderValue.js +28 -0
- package/lib/commonjs/sliderValue.js.map +1 -0
- package/lib/commonjs/surfaceRendererPolicy.js +32 -0
- package/lib/commonjs/surfaceRendererPolicy.js.map +1 -0
- package/lib/commonjs/theme/ThemeProvider.js +37 -0
- package/lib/commonjs/theme/ThemeProvider.js.map +1 -0
- package/lib/commonjs/theme/buildTheme.js +157 -0
- package/lib/commonjs/theme/buildTheme.js.map +1 -0
- package/lib/commonjs/theme/glassColors.js +17 -0
- package/lib/commonjs/theme/glassColors.js.map +1 -0
- package/lib/commonjs/theme/index.js +38 -0
- package/lib/commonjs/theme/index.js.map +1 -0
- package/lib/commonjs/theme/liquidGlass.js +24 -0
- package/lib/commonjs/theme/liquidGlass.js.map +1 -0
- package/lib/commonjs/theme/presentation.js +14 -0
- package/lib/commonjs/theme/presentation.js.map +1 -0
- package/lib/commonjs/theme/registry.js +17 -0
- package/lib/commonjs/theme/registry.js.map +1 -0
- package/lib/commonjs/theme/selectVariant.js +13 -0
- package/lib/commonjs/theme/selectVariant.js.map +1 -0
- package/lib/commonjs/theme/tokens.js +266 -0
- package/lib/commonjs/theme/tokens.js.map +1 -0
- package/lib/commonjs/theme/types.js +3 -0
- package/lib/commonjs/theme/types.js.map +1 -0
- package/lib/commonjs/theme/wallpaper.js +91 -0
- package/lib/commonjs/theme/wallpaper.js.map +1 -0
- package/lib/commonjs/types.js +3 -0
- package/lib/commonjs/types.js.map +1 -0
- package/lib/commonjs/useButtonGesture.js +135 -0
- package/lib/commonjs/useButtonGesture.js.map +1 -0
- package/lib/commonjs/useGlassKnobMotion.js +115 -0
- package/lib/commonjs/useGlassKnobMotion.js.map +1 -0
- package/lib/commonjs/useGlassPressMotion.js +147 -0
- package/lib/commonjs/useGlassPressMotion.js.map +1 -0
- package/lib/module/GlassSurface.js +782 -0
- package/lib/module/GlassSurface.js.map +1 -0
- package/lib/module/GlassTabBar.js +939 -0
- package/lib/module/GlassTabBar.js.map +1 -0
- package/lib/module/GlassTabLens.js +64 -0
- package/lib/module/GlassTabLens.js.map +1 -0
- package/lib/module/LiquidGlassProvider.js +37 -0
- package/lib/module/LiquidGlassProvider.js.map +1 -0
- package/lib/module/LocalGlassMaterial.js +191 -0
- package/lib/module/LocalGlassMaterial.js.map +1 -0
- package/lib/module/adaptiveLuminance.js +11 -0
- package/lib/module/adaptiveLuminance.js.map +1 -0
- package/lib/module/badgePalette.js +40 -0
- package/lib/module/badgePalette.js.map +1 -0
- package/lib/module/buttonGesturePolicy.js +17 -0
- package/lib/module/buttonGesturePolicy.js.map +1 -0
- package/lib/module/components/AdaptiveLuminance.js +16 -0
- package/lib/module/components/AdaptiveLuminance.js.map +1 -0
- package/lib/module/components/BottomSheet.js +186 -0
- package/lib/module/components/BottomSheet.js.map +1 -0
- package/lib/module/components/Button.js +17 -0
- package/lib/module/components/Button.js.map +1 -0
- package/lib/module/components/Card.js +170 -0
- package/lib/module/components/Card.js.map +1 -0
- package/lib/module/components/Checkbox.js +84 -0
- package/lib/module/components/Checkbox.js.map +1 -0
- package/lib/module/components/ControlPressContext.js +4 -0
- package/lib/module/components/ControlPressContext.js.map +1 -0
- package/lib/module/components/Dialog.js +86 -0
- package/lib/module/components/Dialog.js.map +1 -0
- package/lib/module/components/DialogAction.js +88 -0
- package/lib/module/components/DialogAction.js.map +1 -0
- package/lib/module/components/DialogContent.js +20 -0
- package/lib/module/components/DialogContent.js.map +1 -0
- package/lib/module/components/GlassButton.js +93 -0
- package/lib/module/components/GlassButton.js.map +1 -0
- package/lib/module/components/GlassFab.js +37 -0
- package/lib/module/components/GlassFab.js.map +1 -0
- package/lib/module/components/GlassMagnifier.js +99 -0
- package/lib/module/components/GlassMagnifier.js.map +1 -0
- package/lib/module/components/GlassPlayground.js +122 -0
- package/lib/module/components/GlassPlayground.js.map +1 -0
- package/lib/module/components/GlassSlider.js +328 -0
- package/lib/module/components/GlassSlider.js.map +1 -0
- package/lib/module/components/GlassSwitch.js +298 -0
- package/lib/module/components/GlassSwitch.js.map +1 -0
- package/lib/module/components/GlassTabBar.js +351 -0
- package/lib/module/components/GlassTabBar.js.map +1 -0
- package/lib/module/components/Input.js +144 -0
- package/lib/module/components/Input.js.map +1 -0
- package/lib/module/components/ListRow.js +61 -0
- package/lib/module/components/ListRow.js.map +1 -0
- package/lib/module/components/Menu.js +178 -0
- package/lib/module/components/Menu.js.map +1 -0
- package/lib/module/components/NavigationBar.js +14 -0
- package/lib/module/components/NavigationBar.js.map +1 -0
- package/lib/module/components/NumberWheel.js +238 -0
- package/lib/module/components/NumberWheel.js.map +1 -0
- package/lib/module/components/PageFeedList.js +19 -0
- package/lib/module/components/PageFeedList.js.map +1 -0
- package/lib/module/components/PageScaffold.js +114 -0
- package/lib/module/components/PageScaffold.js.map +1 -0
- package/lib/module/components/PreferenceGroup.js +28 -0
- package/lib/module/components/PreferenceGroup.js.map +1 -0
- package/lib/module/components/ProgressIndicator.js +44 -0
- package/lib/module/components/ProgressIndicator.js.map +1 -0
- package/lib/module/components/ProgressiveBlur.js +26 -0
- package/lib/module/components/ProgressiveBlur.js.map +1 -0
- package/lib/module/components/ReferenceSlider.js +268 -0
- package/lib/module/components/ReferenceSlider.js.map +1 -0
- package/lib/module/components/ReferenceTabBar.js +344 -0
- package/lib/module/components/ReferenceTabBar.js.map +1 -0
- package/lib/module/components/SearchBar.js +164 -0
- package/lib/module/components/SearchBar.js.map +1 -0
- package/lib/module/components/SegmentedControl.js +26 -0
- package/lib/module/components/SegmentedControl.js.map +1 -0
- package/lib/module/components/Slider.js +9 -0
- package/lib/module/components/Slider.js.map +1 -0
- package/lib/module/components/Snackbar.js +8 -0
- package/lib/module/components/Snackbar.js.map +1 -0
- package/lib/module/components/SurfaceEnvironmentContext.js +27 -0
- package/lib/module/components/SurfaceEnvironmentContext.js.map +1 -0
- package/lib/module/components/SurfaceGroup.js +33 -0
- package/lib/module/components/SurfaceGroup.js.map +1 -0
- package/lib/module/components/Switch.js +8 -0
- package/lib/module/components/Switch.js.map +1 -0
- package/lib/module/components/Toast.js +74 -0
- package/lib/module/components/Toast.js.map +1 -0
- package/lib/module/components/TopAppBar.js +68 -0
- package/lib/module/components/TopAppBar.js.map +1 -0
- package/lib/module/components/bottomSheetMotion.js +11 -0
- package/lib/module/components/bottomSheetMotion.js.map +1 -0
- package/lib/module/components/glassControlMaterial.js +19 -0
- package/lib/module/components/glassControlMaterial.js.map +1 -0
- package/lib/module/components/menuPosition.js +37 -0
- package/lib/module/components/menuPosition.js.map +1 -0
- package/lib/module/components/pages/FeedPage.js +12 -0
- package/lib/module/components/pages/FeedPage.js.map +1 -0
- package/lib/module/components/pages/PageBenchmarkContext.js +84 -0
- package/lib/module/components/pages/PageBenchmarkContext.js.map +1 -0
- package/lib/module/components/pages/SettingsPage.js +11 -0
- package/lib/module/components/pages/SettingsPage.js.map +1 -0
- package/lib/module/components/pages/SettingsSection.js +8 -0
- package/lib/module/components/pages/SettingsSection.js.map +1 -0
- package/lib/module/components/pages/StaticSettingsPage.js +10 -0
- package/lib/module/components/pages/StaticSettingsPage.js.map +1 -0
- package/lib/module/fallbackKnobGeometry.js +16 -0
- package/lib/module/fallbackKnobGeometry.js.map +1 -0
- package/lib/module/glassController.js +58 -0
- package/lib/module/glassController.js.map +1 -0
- package/lib/module/glassNativeEngine.js +11 -0
- package/lib/module/glassNativeEngine.js.map +1 -0
- package/lib/module/glassRuntime.js +22 -0
- package/lib/module/glassRuntime.js.map +1 -0
- package/lib/module/index.js +80 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/inputPresentation.js +14 -0
- package/lib/module/inputPresentation.js.map +1 -0
- package/lib/module/localGlassTelemetry.js +103 -0
- package/lib/module/localGlassTelemetry.js.map +1 -0
- package/lib/module/motion/MotionProvider.js +11 -0
- package/lib/module/motion/MotionProvider.js.map +1 -0
- package/lib/module/motion/easings.js +64 -0
- package/lib/module/motion/easings.js.map +1 -0
- package/lib/module/motion/folmeSpring.js +21 -0
- package/lib/module/motion/folmeSpring.js.map +1 -0
- package/lib/module/motion/folmeSpringByResponse.js +19 -0
- package/lib/module/motion/folmeSpringByResponse.js.map +1 -0
- package/lib/module/motion/index.js +6 -0
- package/lib/module/motion/index.js.map +1 -0
- package/lib/module/motion/presets.js +98 -0
- package/lib/module/motion/presets.js.map +1 -0
- package/lib/module/nativeGlassViews.js +27 -0
- package/lib/module/nativeGlassViews.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/performanceTelemetry.js +23 -0
- package/lib/module/performanceTelemetry.js.map +1 -0
- package/lib/module/pointerEventBridge.js +14 -0
- package/lib/module/pointerEventBridge.js.map +1 -0
- package/lib/module/pointerGeometry.js +9 -0
- package/lib/module/pointerGeometry.js.map +1 -0
- package/lib/module/pressVelocity.js +31 -0
- package/lib/module/pressVelocity.js.map +1 -0
- package/lib/module/primitives/Divider.js +29 -0
- package/lib/module/primitives/Divider.js.map +1 -0
- package/lib/module/primitives/Icon.js +19 -0
- package/lib/module/primitives/Icon.js.map +1 -0
- package/lib/module/primitives/PressIndication.js +22 -0
- package/lib/module/primitives/PressIndication.js.map +1 -0
- package/lib/module/primitives/Pressable.js +25 -0
- package/lib/module/primitives/Pressable.js.map +1 -0
- package/lib/module/primitives/PressableScale.js +28 -0
- package/lib/module/primitives/PressableScale.js.map +1 -0
- package/lib/module/primitives/Surface.js +83 -0
- package/lib/module/primitives/Surface.js.map +1 -0
- package/lib/module/primitives/Text.js +40 -0
- package/lib/module/primitives/Text.js.map +1 -0
- package/lib/module/primitives/index.js +8 -0
- package/lib/module/primitives/index.js.map +1 -0
- package/lib/module/renderer.js +22 -0
- package/lib/module/renderer.js.map +1 -0
- package/lib/module/sliderValue.js +25 -0
- package/lib/module/sliderValue.js.map +1 -0
- package/lib/module/surfaceRendererPolicy.js +27 -0
- package/lib/module/surfaceRendererPolicy.js.map +1 -0
- package/lib/module/theme/ThemeProvider.js +32 -0
- package/lib/module/theme/ThemeProvider.js.map +1 -0
- package/lib/module/theme/buildTheme.js +153 -0
- package/lib/module/theme/buildTheme.js.map +1 -0
- package/lib/module/theme/glassColors.js +14 -0
- package/lib/module/theme/glassColors.js.map +1 -0
- package/lib/module/theme/index.js +9 -0
- package/lib/module/theme/index.js.map +1 -0
- package/lib/module/theme/liquidGlass.js +21 -0
- package/lib/module/theme/liquidGlass.js.map +1 -0
- package/lib/module/theme/presentation.js +11 -0
- package/lib/module/theme/presentation.js.map +1 -0
- package/lib/module/theme/registry.js +13 -0
- package/lib/module/theme/registry.js.map +1 -0
- package/lib/module/theme/selectVariant.js +10 -0
- package/lib/module/theme/selectVariant.js.map +1 -0
- package/lib/module/theme/tokens.js +262 -0
- package/lib/module/theme/tokens.js.map +1 -0
- package/lib/module/theme/types.js +2 -0
- package/lib/module/theme/types.js.map +1 -0
- package/lib/module/theme/wallpaper.js +83 -0
- package/lib/module/theme/wallpaper.js.map +1 -0
- package/lib/module/types.js +2 -0
- package/lib/module/types.js.map +1 -0
- package/lib/module/useButtonGesture.js +132 -0
- package/lib/module/useButtonGesture.js.map +1 -0
- package/lib/module/useGlassKnobMotion.js +112 -0
- package/lib/module/useGlassKnobMotion.js.map +1 -0
- package/lib/module/useGlassPressMotion.js +143 -0
- package/lib/module/useGlassPressMotion.js.map +1 -0
- package/lib/types/GlassSurface.d.ts +216 -0
- package/lib/types/GlassTabBar.d.ts +35 -0
- package/lib/types/GlassTabLens.d.ts +11 -0
- package/lib/types/LiquidGlassProvider.d.ts +47 -0
- package/lib/types/LocalGlassMaterial.d.ts +21 -0
- package/lib/types/adaptiveLuminance.d.ts +2 -0
- package/lib/types/badgePalette.d.ts +9 -0
- package/lib/types/buttonGesturePolicy.d.ts +4 -0
- package/lib/types/components/AdaptiveLuminance.d.ts +23 -0
- package/lib/types/components/BottomSheet.d.ts +33 -0
- package/lib/types/components/Button.d.ts +16 -0
- package/lib/types/components/Card.d.ts +25 -0
- package/lib/types/components/Checkbox.d.ts +11 -0
- package/lib/types/components/ControlPressContext.d.ts +9 -0
- package/lib/types/components/Dialog.d.ts +12 -0
- package/lib/types/components/DialogAction.d.ts +4 -0
- package/lib/types/components/DialogContent.d.ts +12 -0
- package/lib/types/components/GlassButton.d.ts +38 -0
- package/lib/types/components/GlassFab.d.ts +15 -0
- package/lib/types/components/GlassMagnifier.d.ts +41 -0
- package/lib/types/components/GlassPlayground.d.ts +12 -0
- package/lib/types/components/GlassSlider.d.ts +48 -0
- package/lib/types/components/GlassSwitch.d.ts +46 -0
- package/lib/types/components/GlassTabBar.d.ts +44 -0
- package/lib/types/components/Input.d.ts +47 -0
- package/lib/types/components/ListRow.d.ts +17 -0
- package/lib/types/components/Menu.d.ts +41 -0
- package/lib/types/components/NavigationBar.d.ts +14 -0
- package/lib/types/components/NumberWheel.d.ts +11 -0
- package/lib/types/components/PageFeedList.d.ts +6 -0
- package/lib/types/components/PageScaffold.d.ts +64 -0
- package/lib/types/components/PreferenceGroup.d.ts +12 -0
- package/lib/types/components/ProgressIndicator.d.ts +9 -0
- package/lib/types/components/ProgressiveBlur.d.ts +12 -0
- package/lib/types/components/ReferenceSlider.d.ts +31 -0
- package/lib/types/components/ReferenceTabBar.d.ts +61 -0
- package/lib/types/components/SearchBar.d.ts +52 -0
- package/lib/types/components/SegmentedControl.d.ts +10 -0
- package/lib/types/components/Slider.d.ts +19 -0
- package/lib/types/components/Snackbar.d.ts +5 -0
- package/lib/types/components/SurfaceEnvironmentContext.d.ts +17 -0
- package/lib/types/components/SurfaceGroup.d.ts +17 -0
- package/lib/types/components/Switch.d.ts +12 -0
- package/lib/types/components/Toast.d.ts +14 -0
- package/lib/types/components/TopAppBar.d.ts +49 -0
- package/lib/types/components/bottomSheetMotion.d.ts +2 -0
- package/lib/types/components/glassControlMaterial.d.ts +3 -0
- package/lib/types/components/menuPosition.d.ts +22 -0
- package/lib/types/components/pages/FeedPage.d.ts +31 -0
- package/lib/types/components/pages/PageBenchmarkContext.d.ts +30 -0
- package/lib/types/components/pages/SettingsPage.d.ts +20 -0
- package/lib/types/components/pages/SettingsSection.d.ts +9 -0
- package/lib/types/components/pages/StaticSettingsPage.d.ts +18 -0
- package/lib/types/fallbackKnobGeometry.d.ts +7 -0
- package/lib/types/glassController.d.ts +20 -0
- package/lib/types/glassNativeEngine.d.ts +5 -0
- package/lib/types/glassRuntime.d.ts +7 -0
- package/lib/types/index.d.ts +124 -0
- package/lib/types/inputPresentation.d.ts +12 -0
- package/lib/types/localGlassTelemetry.d.ts +28 -0
- package/lib/types/motion/MotionProvider.d.ts +7 -0
- package/lib/types/motion/easings.d.ts +33 -0
- package/lib/types/motion/folmeSpring.d.ts +15 -0
- package/lib/types/motion/folmeSpringByResponse.d.ts +14 -0
- package/lib/types/motion/index.d.ts +7 -0
- package/lib/types/motion/presets.d.ts +103 -0
- package/lib/types/nativeGlassViews.d.ts +114 -0
- package/lib/types/performanceTelemetry.d.ts +65 -0
- package/lib/types/pointerEventBridge.d.ts +17 -0
- package/lib/types/pointerGeometry.d.ts +2 -0
- package/lib/types/pressVelocity.d.ts +11 -0
- package/lib/types/primitives/Divider.d.ts +19 -0
- package/lib/types/primitives/Icon.d.ts +29 -0
- package/lib/types/primitives/PressIndication.d.ts +26 -0
- package/lib/types/primitives/Pressable.d.ts +9 -0
- package/lib/types/primitives/PressableScale.d.ts +19 -0
- package/lib/types/primitives/Surface.d.ts +63 -0
- package/lib/types/primitives/Text.d.ts +35 -0
- package/lib/types/primitives/index.d.ts +14 -0
- package/lib/types/renderer.d.ts +32 -0
- package/lib/types/sliderValue.d.ts +2 -0
- package/lib/types/surfaceRendererPolicy.d.ts +14 -0
- package/lib/types/theme/ThemeProvider.d.ts +26 -0
- package/lib/types/theme/buildTheme.d.ts +6 -0
- package/lib/types/theme/glassColors.d.ts +13 -0
- package/lib/types/theme/index.d.ts +11 -0
- package/lib/types/theme/liquidGlass.d.ts +5 -0
- package/lib/types/theme/presentation.d.ts +3 -0
- package/lib/types/theme/registry.d.ts +7 -0
- package/lib/types/theme/selectVariant.d.ts +10 -0
- package/lib/types/theme/tokens.d.ts +18 -0
- package/lib/types/theme/types.d.ts +305 -0
- package/lib/types/theme/wallpaper.d.ts +32 -0
- package/lib/types/types.d.ts +127 -0
- package/lib/types/useButtonGesture.d.ts +30 -0
- package/lib/types/useGlassKnobMotion.d.ts +40 -0
- package/lib/types/useGlassPressMotion.d.ts +61 -0
- package/licenses/Apache-2.0-Kyant0-Shapes.txt +191 -0
- package/package.json +139 -4
- package/patches/liquid-glass-kit+1.0.0.patch +2015 -0
- package/patches/liquid-glass-kit-invalidation-coalescing.diff +249 -0
- package/patches/liquid-glass-kit-native-infra.diff +624 -0
- package/scripts/apply-legacy-patches.mjs +116 -0
- package/src/GlassSurface.tsx +1786 -0
- package/src/GlassTabBar.tsx +1304 -0
- package/src/GlassTabLens.tsx +92 -0
- package/src/LiquidGlassProvider.tsx +135 -0
- package/src/LocalGlassMaterial.tsx +262 -0
- package/src/adaptiveLuminance.ts +15 -0
- package/src/badgePalette.ts +54 -0
- package/src/buttonGesturePolicy.ts +15 -0
- package/src/components/AdaptiveLuminance.tsx +40 -0
- package/src/components/BottomSheet.tsx +291 -0
- package/src/components/Button.tsx +30 -0
- package/src/components/Card.tsx +343 -0
- package/src/components/Checkbox.tsx +141 -0
- package/src/components/ControlPressContext.ts +11 -0
- package/src/components/Dialog.tsx +129 -0
- package/src/components/DialogAction.tsx +109 -0
- package/src/components/DialogContent.tsx +52 -0
- package/src/components/GlassButton.tsx +225 -0
- package/src/components/GlassFab.tsx +98 -0
- package/src/components/GlassMagnifier.tsx +178 -0
- package/src/components/GlassPlayground.tsx +190 -0
- package/src/components/GlassSlider.tsx +448 -0
- package/src/components/GlassSwitch.tsx +391 -0
- package/src/components/GlassTabBar.tsx +522 -0
- package/src/components/Input.tsx +277 -0
- package/src/components/ListRow.tsx +124 -0
- package/src/components/Menu.tsx +322 -0
- package/src/components/NavigationBar.tsx +27 -0
- package/src/components/NumberWheel.tsx +344 -0
- package/src/components/PageFeedList.tsx +37 -0
- package/src/components/PageScaffold.tsx +266 -0
- package/src/components/PreferenceGroup.tsx +65 -0
- package/src/components/ProgressIndicator.tsx +63 -0
- package/src/components/ProgressiveBlur.tsx +56 -0
- package/src/components/ReferenceSlider.tsx +364 -0
- package/src/components/ReferenceTabBar.tsx +564 -0
- package/src/components/SearchBar.tsx +340 -0
- package/src/components/SegmentedControl.tsx +45 -0
- package/src/components/Slider.tsx +25 -0
- package/src/components/Snackbar.tsx +10 -0
- package/src/components/SurfaceEnvironmentContext.tsx +46 -0
- package/src/components/SurfaceGroup.tsx +60 -0
- package/src/components/Switch.tsx +18 -0
- package/src/components/Toast.tsx +110 -0
- package/src/components/TopAppBar.tsx +272 -0
- package/src/components/bottomSheetMotion.ts +10 -0
- package/src/components/glassControlMaterial.ts +20 -0
- package/src/components/menuPosition.ts +58 -0
- package/src/components/pages/FeedPage.tsx +96 -0
- package/src/components/pages/PageBenchmarkContext.tsx +105 -0
- package/src/components/pages/SettingsPage.tsx +55 -0
- package/src/components/pages/SettingsSection.tsx +20 -0
- package/src/components/pages/StaticSettingsPage.tsx +50 -0
- package/src/fallbackKnobGeometry.ts +15 -0
- package/src/glassController.ts +74 -0
- package/src/glassNativeEngine.ts +16 -0
- package/src/glassRuntime.ts +28 -0
- package/src/index.ts +199 -0
- package/src/inputPresentation.ts +32 -0
- package/src/localGlassTelemetry.ts +138 -0
- package/src/motion/MotionProvider.tsx +12 -0
- package/src/motion/easings.ts +71 -0
- package/src/motion/folmeSpring.ts +22 -0
- package/src/motion/folmeSpringByResponse.ts +19 -0
- package/src/motion/index.ts +47 -0
- package/src/motion/presets.ts +128 -0
- package/src/nativeGlassViews.ts +147 -0
- package/src/performanceTelemetry.ts +95 -0
- package/src/pointerEventBridge.ts +27 -0
- package/src/pointerGeometry.ts +8 -0
- package/src/pressVelocity.ts +36 -0
- package/src/primitives/Divider.tsx +42 -0
- package/src/primitives/Icon.tsx +44 -0
- package/src/primitives/PressIndication.tsx +43 -0
- package/src/primitives/Pressable.tsx +75 -0
- package/src/primitives/PressableScale.tsx +50 -0
- package/src/primitives/Surface.tsx +171 -0
- package/src/primitives/Text.tsx +80 -0
- package/src/primitives/index.ts +14 -0
- package/src/renderer.ts +70 -0
- package/src/sliderValue.ts +19 -0
- package/src/surfaceRendererPolicy.ts +32 -0
- package/src/theme/ThemeProvider.tsx +52 -0
- package/src/theme/buildTheme.ts +160 -0
- package/src/theme/glassColors.ts +13 -0
- package/src/theme/index.ts +34 -0
- package/src/theme/liquidGlass.ts +25 -0
- package/src/theme/presentation.ts +12 -0
- package/src/theme/registry.ts +16 -0
- package/src/theme/selectVariant.ts +12 -0
- package/src/theme/tokens.ts +309 -0
- package/src/theme/types.ts +345 -0
- package/src/theme/wallpaper.ts +94 -0
- package/src/types.ts +95 -0
- package/src/useButtonGesture.ts +134 -0
- package/src/useGlassKnobMotion.ts +155 -0
- package/src/useGlassPressMotion.ts +209 -0
|
@@ -0,0 +1,1605 @@
|
|
|
1
|
+
package com.newhu.liquidglass.backdrop
|
|
2
|
+
|
|
3
|
+
import android.graphics.Canvas
|
|
4
|
+
import android.graphics.Color
|
|
5
|
+
import android.graphics.Matrix
|
|
6
|
+
import android.graphics.RenderNode
|
|
7
|
+
import android.os.Build
|
|
8
|
+
import android.view.MotionEvent
|
|
9
|
+
import android.view.View
|
|
10
|
+
import androidx.annotation.ColorInt
|
|
11
|
+
import com.newhu.liquidglass.core.GlassRenderTier
|
|
12
|
+
import com.newhu.liquidglass.core.GlassOpticsModel
|
|
13
|
+
import com.newhu.liquidglass.core.SdfScaleLensConfig
|
|
14
|
+
import com.newhu.liquidglass.backdrop.internal.GlassFrame
|
|
15
|
+
import com.newhu.liquidglass.backdrop.internal.GlassViewRenderer
|
|
16
|
+
import com.newhu.liquidglass.telemetry.LiquidGlassPerfTelemetry
|
|
17
|
+
import com.newhu.liquidglass.telemetry.LiquidGlassTrace
|
|
18
|
+
import kotlin.math.abs
|
|
19
|
+
import kotlin.math.cos
|
|
20
|
+
import kotlin.math.exp
|
|
21
|
+
import kotlin.math.min
|
|
22
|
+
import kotlin.math.sin
|
|
23
|
+
import kotlin.math.sqrt
|
|
24
|
+
|
|
25
|
+
internal enum class GlassDirtyKind {
|
|
26
|
+
SOURCE_CONTENT_DIRTY,
|
|
27
|
+
CONSUMER_GEOMETRY_DIRTY,
|
|
28
|
+
OPTICS_DIRTY,
|
|
29
|
+
MATERIAL_DIRTY,
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Sentinel corner radius: fully rounded capsule/circle. */
|
|
33
|
+
public const val CORNER_RADIUS_CAPSULE: Float = -1f
|
|
34
|
+
|
|
35
|
+
private const val DEFAULT_SCRIM_COLOR = 0x59FFFFFF.toInt() // white @ 35%
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The embeddable Liquid Glass engine for the View system.
|
|
39
|
+
*
|
|
40
|
+
* [LiquidGlassView] is a ready-made host, but any custom view (a React Native
|
|
41
|
+
* view, a launcher widget host, ...) gains glass by owning a controller and
|
|
42
|
+
* forwarding four calls:
|
|
43
|
+
*
|
|
44
|
+
* ```
|
|
45
|
+
* private val glass = GlassViewController(this) // setWillNotDraw(false)!
|
|
46
|
+
* override fun onDraw(canvas: Canvas) { super.onDraw(canvas); glass.draw(canvas) }
|
|
47
|
+
* override fun onAttachedToWindow() { super.onAttachedToWindow(); glass.onHostAttached() }
|
|
48
|
+
* override fun onDetachedFromWindow() { glass.onHostDetached(); super.onDetachedFromWindow() }
|
|
49
|
+
* override fun dispatchTouchEvent(e: MotionEvent): Boolean { glass.handleTouch(e); return super.dispatchTouchEvent(e) }
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* All dimension properties are in dp; every property change invalidates the
|
|
53
|
+
* host automatically. Rendering degrades through the same tiers as the Compose
|
|
54
|
+
* artifact: full AGSL refraction on API 33+, frosted blur on 31–32, clipped
|
|
55
|
+
* backdrop + scrim on 29–30, plain scrim + rim everywhere else.
|
|
56
|
+
*/
|
|
57
|
+
private val passSampleAuditDone = java.util.Collections.synchronizedSet(HashSet<Int>())
|
|
58
|
+
private var passSampleAuditTick = 0
|
|
59
|
+
private const val PASS_SAMPLE_AUDIT = false
|
|
60
|
+
|
|
61
|
+
public class GlassViewController(private val host: View) {
|
|
62
|
+
|
|
63
|
+
private val renderer = GlassViewRenderer()
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* The v3 engine for this surface.
|
|
67
|
+
*
|
|
68
|
+
* Selected per surface rather than globally so a page can be migrated one
|
|
69
|
+
* component at a time and an A/B run compares the two renderers on the same
|
|
70
|
+
* content in the same APK. [useV3Engine] off keeps the previous chain, which
|
|
71
|
+
* is what makes the performance comparison honest: the optimisation is
|
|
72
|
+
* measured against the code it replaced, not against a remembered number.
|
|
73
|
+
*/
|
|
74
|
+
/**
|
|
75
|
+
* The v3 engine host for this surface.
|
|
76
|
+
*
|
|
77
|
+
* Exposed for instrumentation, not for product code: the measured question
|
|
78
|
+
* "did this touch start an animation" can only be answered from the engine's own
|
|
79
|
+
* state, and a screenshot cannot distinguish a pressed spring from a moved page.
|
|
80
|
+
*/
|
|
81
|
+
public fun engineHostForInstrumentation(): com.newhu.liquidglass.rendering.GlassSurfaceHost = engine
|
|
82
|
+
|
|
83
|
+
private val engine by lazy {
|
|
84
|
+
com.newhu.liquidglass.rendering.GlassSurfaceHost(host.resources.displayMetrics.density).also { engineHost ->
|
|
85
|
+
// Each spring step must paint. Invalidate is a coalesced request on the
|
|
86
|
+
// view, so several steps inside one frame still cost one traversal.
|
|
87
|
+
engineHost.onMotionFrame = {
|
|
88
|
+
val motionKind = engineHost.motion.kindOf()
|
|
89
|
+
val travelling = motionKind == com.newhu.liquidglass.motion.GlassInteractionKind.TOGGLE_KNOB ||
|
|
90
|
+
motionKind == com.newhu.liquidglass.motion.GlassInteractionKind.SLIDER_KNOB ||
|
|
91
|
+
motionKind == com.newhu.liquidglass.motion.GlassInteractionKind.TAB_LENS
|
|
92
|
+
if (referenceInteractionProfile == REFERENCE_PROFILE_BUTTON || travelling) {
|
|
93
|
+
applyInteractionTransform()
|
|
94
|
+
}
|
|
95
|
+
host.invalidate()
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** True when this surface draws through the v3 optical core. */
|
|
101
|
+
public var useV3Engine: Boolean = com.newhu.liquidglass.rendering.GlassEngineSelection.useV3
|
|
102
|
+
set(value) {
|
|
103
|
+
if (field == value) return
|
|
104
|
+
field = value
|
|
105
|
+
if (!value) engine.release()
|
|
106
|
+
host.invalidate()
|
|
107
|
+
}
|
|
108
|
+
private val locationSelf = IntArray(2)
|
|
109
|
+
private val locationProvider = IntArray(2)
|
|
110
|
+
private val relativePosition = FloatArray(2)
|
|
111
|
+
private val parentToWindow = Matrix()
|
|
112
|
+
private val layoutOriginInWindow = FloatArray(2)
|
|
113
|
+
private val frame = GlassFrame()
|
|
114
|
+
private var pressAmount = 0f
|
|
115
|
+
private var pressX = 0f
|
|
116
|
+
private var pressY = 0f
|
|
117
|
+
private var forwardedPointerX = 0f
|
|
118
|
+
private var forwardedPointerY = 0f
|
|
119
|
+
private var interactionPointXDp = 0f
|
|
120
|
+
private var interactionPointYDp = 0f
|
|
121
|
+
private var pointerVelocityXDpPerSecond = 0f
|
|
122
|
+
private var pointerVelocityYDpPerSecond = 0f
|
|
123
|
+
private var externalButtonProgress = 0f
|
|
124
|
+
private var pressVelocity = 0f
|
|
125
|
+
private var pressTarget = 0f
|
|
126
|
+
private var pressStartedAtNanos = 0L
|
|
127
|
+
private var pressStartValue = 0f
|
|
128
|
+
private var pressStartVelocity = 0f
|
|
129
|
+
private var pointerDown = false
|
|
130
|
+
private var dragStartX = 0f
|
|
131
|
+
private var dragStartY = 0f
|
|
132
|
+
private var dragX = 0f
|
|
133
|
+
private var dragY = 0f
|
|
134
|
+
private var dragTargetX = 0f
|
|
135
|
+
private var dragTargetY = 0f
|
|
136
|
+
private var dragStartValueX = 0f
|
|
137
|
+
private var dragStartValueY = 0f
|
|
138
|
+
private var dragStartVelocityX = 0f
|
|
139
|
+
private var dragStartVelocityY = 0f
|
|
140
|
+
private var dragVelocityX = 0f
|
|
141
|
+
private var dragVelocityY = 0f
|
|
142
|
+
private var externalPressAwaitingPointerBaseline = false
|
|
143
|
+
private val pressAnimationFrame = object : Runnable {
|
|
144
|
+
override fun run() {
|
|
145
|
+
val stillAnimating = advancePressAnimation(System.nanoTime())
|
|
146
|
+
applyInteractionTransform()
|
|
147
|
+
reportConsumerDirty(GlassBackdropDirtyReason.OPTICS)
|
|
148
|
+
host.invalidate()
|
|
149
|
+
if (stillAnimating) host.postOnAnimation(this)
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Reanimated updates the progress and pointer coordinates as separate
|
|
154
|
+
* native props. Establish the initial press point on the next frame so a
|
|
155
|
+
* progress-first delivery cannot turn the pointer's initial position into
|
|
156
|
+
* a synthetic drag.
|
|
157
|
+
*/
|
|
158
|
+
private val externalPressPointerBaselineFrame = Runnable {
|
|
159
|
+
if (!externalPressAwaitingPointerBaseline || !pointerDown || referenceInteractionProfile != 0) return@Runnable
|
|
160
|
+
captureExternalPressPointerBaseline()
|
|
161
|
+
}
|
|
162
|
+
private var previousRelativeX: Float? = null
|
|
163
|
+
private var previousRelativeY: Float? = null
|
|
164
|
+
private var previousMotionAtNanos = 0L
|
|
165
|
+
private var referenceSampleAuditLogged = false
|
|
166
|
+
private var cachedV3Material: com.newhu.liquidglass.optics.GlassMaterial? = null
|
|
167
|
+
private var derivedMotionX = 0f
|
|
168
|
+
private var derivedMotionY = 0f
|
|
169
|
+
private var explicitMotionX: Float? = null
|
|
170
|
+
private var explicitMotionY: Float? = null
|
|
171
|
+
/** Called whenever the surface transform changes for interaction deformation. */
|
|
172
|
+
public var onInteractionTransformUpdated: ((Float, Float, Float, Float) -> Unit)? = null
|
|
173
|
+
|
|
174
|
+
/** The backdrop this glass refracts. Must be drawn below the host. */
|
|
175
|
+
public var provider: LiquidGlassBackdropSource? = null
|
|
176
|
+
set(value) {
|
|
177
|
+
if (field === value) return
|
|
178
|
+
field?.unregisterConsumer(host)
|
|
179
|
+
field = value
|
|
180
|
+
if (host.isAttachedToWindow) value?.registerConsumer(host)
|
|
181
|
+
host.invalidate()
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** Corner radius in dp, or [CORNER_RADIUS_CAPSULE] for a capsule/circle. */
|
|
185
|
+
public var cornerRadiusDp: Float = CORNER_RADIUS_CAPSULE
|
|
186
|
+
set(value) = invalidating(field, value, GlassDirtyKind.OPTICS_DIRTY) { field = it }
|
|
187
|
+
|
|
188
|
+
/** Optional bitmap SDF text silhouette used by custom text-glass shapes. */
|
|
189
|
+
public var shapeMaskText: String? = null
|
|
190
|
+
set(value) = invalidating(field, value, GlassDirtyKind.OPTICS_DIRTY) { field = it }
|
|
191
|
+
public var shapeMaskFontSizeDp: Float = 0f
|
|
192
|
+
set(value) = invalidating(field, value.coerceAtLeast(0f), GlassDirtyKind.OPTICS_DIRTY) { field = it }
|
|
193
|
+
public var shapeMaskFontWeight: Int = 700
|
|
194
|
+
set(value) = invalidating(field, value.coerceIn(100, 900), GlassDirtyKind.OPTICS_DIRTY) { field = it }
|
|
195
|
+
public var progressiveBlurIntensity: Float = 0f
|
|
196
|
+
set(value) = invalidating(field, value.coerceIn(0f, 1f), GlassDirtyKind.OPTICS_DIRTY) { field = it }
|
|
197
|
+
|
|
198
|
+
public var opticsModel: GlassOpticsModel = GlassOpticsModel.HEIGHT_FIELD
|
|
199
|
+
set(value) = invalidating(field, value, GlassDirtyKind.OPTICS_DIRTY) { field = it }
|
|
200
|
+
|
|
201
|
+
public var sdfScaleLens: SdfScaleLensConfig = SdfScaleLensConfig()
|
|
202
|
+
set(value) = invalidating(field, value, GlassDirtyKind.OPTICS_DIRTY) { field = it }
|
|
203
|
+
|
|
204
|
+
/** Backdrop blur radius in dp — the frostiness of the glass. */
|
|
205
|
+
public var blurRadiusDp: Float = 20f
|
|
206
|
+
set(value) = invalidating(field, value) { field = it }
|
|
207
|
+
|
|
208
|
+
/** Width of the refracting band along the rim, in dp. */
|
|
209
|
+
public var refractionHeightDp: Float = 10f
|
|
210
|
+
set(value) = invalidating(field, value, GlassDirtyKind.OPTICS_DIRTY) { field = it }
|
|
211
|
+
|
|
212
|
+
/** Peak refraction displacement in dp along the outward normal; negative samples inward. */
|
|
213
|
+
public var refractionAmountDp: Float = 12f
|
|
214
|
+
set(value) = invalidating(field, value, GlassDirtyKind.OPTICS_DIRTY) { field = it }
|
|
215
|
+
|
|
216
|
+
/** WebGL radial depth normal blended with the rounded-rect lens normal. */
|
|
217
|
+
public var referenceDepthEffect: Boolean = false
|
|
218
|
+
set(value) = invalidating(field, value, GlassDirtyKind.OPTICS_DIRTY) { field = it }
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Sample the provider's single shared recording instead of a per-consumer
|
|
222
|
+
* crop. Region crops are re-recorded whenever a consumer moves, so a scrolling
|
|
223
|
+
* page pays one recording per visible surface per frame; the shared recording
|
|
224
|
+
* is reused. Experimental until a visual A/B proves it equivalent.
|
|
225
|
+
*/
|
|
226
|
+
public var sharedSourceSampling: Boolean = false
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Probe: capture the provider scene into a GPU texture once per frame and
|
|
230
|
+
* discard it. Used to price the shared-texture design on device before the
|
|
231
|
+
* sampling path is rebuilt around it.
|
|
232
|
+
*/
|
|
233
|
+
public var sharedSceneCaptureProbe: Boolean = false
|
|
234
|
+
private var captureProbe: com.newhu.liquidglass.backdrop.internal.SharedSceneCapture? = null
|
|
235
|
+
private var captureProbeBucket: Long = -1L
|
|
236
|
+
set(value) = invalidating(field, value, GlassDirtyKind.OPTICS_DIRTY) { field = it }
|
|
237
|
+
|
|
238
|
+
/** Full-body rounded-rect coordinate remapping in dp, separate from the rim bend. */
|
|
239
|
+
public var bodyRefractionAmountDp: Float = 2.5f
|
|
240
|
+
set(value) = invalidating(field, value, GlassDirtyKind.OPTICS_DIRTY) { field = it }
|
|
241
|
+
|
|
242
|
+
/** Backdrop-space mapping for independent lens magnification. */
|
|
243
|
+
public var referenceContentScaleX: Float = 1f
|
|
244
|
+
set(value) = invalidating(field, value.coerceIn(0.1f, 4f), GlassDirtyKind.OPTICS_DIRTY) { field = it }
|
|
245
|
+
public var referenceContentScaleY: Float = 1f
|
|
246
|
+
set(value) = invalidating(field, value.coerceIn(0.1f, 4f), GlassDirtyKind.OPTICS_DIRTY) { field = it }
|
|
247
|
+
public var referenceSampleOffsetXDp: Float = 0f
|
|
248
|
+
set(value) = invalidating(field, value.coerceIn(-2000f, 2000f), GlassDirtyKind.OPTICS_DIRTY) { field = it }
|
|
249
|
+
public var referenceSampleOffsetYDp: Float = 0f
|
|
250
|
+
set(value) = invalidating(field, value.coerceIn(-2000f, 2000f), GlassDirtyKind.OPTICS_DIRTY) { field = it }
|
|
251
|
+
|
|
252
|
+
/** 0..1 animated material morph from idle to pressed/dragged optics. */
|
|
253
|
+
public var interactionProgress: Float = 0f
|
|
254
|
+
set(value) {
|
|
255
|
+
val next = value.coerceIn(0f, 1f)
|
|
256
|
+
// Single owner. The JS layer sets progress to 1 or 0 instantly on
|
|
257
|
+
// press-in/press-out and feeds velocity separately; the engine runs its
|
|
258
|
+
// own spring from the same touch. Letting both write the animated value
|
|
259
|
+
// is the old chain's defining defect — two systems fighting for one
|
|
260
|
+
// number, which reads as a doubled, stuttering response. When v3 is
|
|
261
|
+
// drawing it owns the animation, so the JS value is recorded but does not
|
|
262
|
+
// command a second spring.
|
|
263
|
+
if (useV3Engine && com.newhu.liquidglass.rendering.GlassEngineSelection.supportsEngine(Build.VERSION.SDK_INT)) {
|
|
264
|
+
field = next
|
|
265
|
+
return
|
|
266
|
+
}
|
|
267
|
+
if (referenceInteractionProfile != 0) {
|
|
268
|
+
invalidating(field, next, GlassDirtyKind.OPTICS_DIRTY) { field = it }
|
|
269
|
+
return
|
|
270
|
+
}
|
|
271
|
+
// Fabric can deliver progress before interactionProfile. Retain
|
|
272
|
+
// its value so a later profile switch sees the correct state.
|
|
273
|
+
// The optics read this value directly (both body shaders scale their
|
|
274
|
+
// displacement with it), so a change has to repaint even without a
|
|
275
|
+
// profile: without the dirty mark a one-shot progress set produced
|
|
276
|
+
// byte-identical frames at 0.25 and 0.5.
|
|
277
|
+
invalidating(field, next, GlassDirtyKind.OPTICS_DIRTY) { field = it }
|
|
278
|
+
val previous = externalButtonProgress
|
|
279
|
+
if (previous == next) return
|
|
280
|
+
externalButtonProgress = next
|
|
281
|
+
when {
|
|
282
|
+
previous <= 0.5f && next > 0.5f -> beginExternalButtonPress()
|
|
283
|
+
previous > 0.5f && next <= 0.5f -> endExternalButtonPress()
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/** UI-thread point in local dp, supplied by the actual RN gesture target. */
|
|
288
|
+
public var interactionPointX: Float = 0f
|
|
289
|
+
set(value) {
|
|
290
|
+
if (field == value) return
|
|
291
|
+
field = value
|
|
292
|
+
interactionPointXDp = value
|
|
293
|
+
updateExternalButtonPointer()
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/** UI-thread point in local dp, supplied by the actual RN gesture target. */
|
|
297
|
+
public var interactionPointY: Float = 0f
|
|
298
|
+
set(value) {
|
|
299
|
+
if (field == value) return
|
|
300
|
+
field = value
|
|
301
|
+
interactionPointYDp = value
|
|
302
|
+
updateExternalButtonPointer()
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/** UI-thread pointer velocity in local dp/s, supplied by the RN velocity tracker. */
|
|
306
|
+
public var interactionVelocityXDpPerSecond: Float = 0f
|
|
307
|
+
set(value) {
|
|
308
|
+
field = value.coerceIn(-12_000f, 12_000f)
|
|
309
|
+
pointerVelocityXDpPerSecond = field
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/** UI-thread pointer velocity in local dp/s, supplied by the RN velocity tracker. */
|
|
313
|
+
public var interactionVelocityYDpPerSecond: Float = 0f
|
|
314
|
+
set(value) {
|
|
315
|
+
field = value.coerceIn(-12_000f, 12_000f)
|
|
316
|
+
pointerVelocityYDpPerSecond = field
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/** Backdrop saturation boost; 1 leaves color untouched. */
|
|
320
|
+
public var saturation: Float = 1.5f
|
|
321
|
+
set(value) = invalidating(field, value) { field = it }
|
|
322
|
+
|
|
323
|
+
public var brightness: Float = 0f
|
|
324
|
+
set(value) = invalidating(field, value, GlassDirtyKind.OPTICS_DIRTY) { field = it }
|
|
325
|
+
|
|
326
|
+
public var contrast: Float = 1f
|
|
327
|
+
set(value) = invalidating(field, value, GlassDirtyKind.OPTICS_DIRTY) { field = it }
|
|
328
|
+
|
|
329
|
+
/** Surface tint; the alpha channel is the blend strength. */
|
|
330
|
+
@setparam:ColorInt
|
|
331
|
+
public var glassTintColor: Int = Color.TRANSPARENT
|
|
332
|
+
set(value) = invalidating(field, value) { field = it }
|
|
333
|
+
|
|
334
|
+
/** Surface-color overlay used by the pinned reference path, after Hue tint. */
|
|
335
|
+
@setparam:ColorInt
|
|
336
|
+
public var glassSurfaceColor: Int = Color.TRANSPARENT
|
|
337
|
+
set(value) = invalidating(field, value) { field = it }
|
|
338
|
+
|
|
339
|
+
/** 0=Default/Plus, 1=Ambient/SrcOver, 2=Plain/Plus. */
|
|
340
|
+
public var referenceHighlightStyle: Int = 0
|
|
341
|
+
set(value) = invalidating(field, value.coerceIn(0, 2), GlassDirtyKind.MATERIAL_DIRTY) { field = it }
|
|
342
|
+
|
|
343
|
+
public var referenceHighlightFalloff: Float = 1f
|
|
344
|
+
set(value) = invalidating(field, value.coerceAtLeast(0f), GlassDirtyKind.MATERIAL_DIRTY) { field = it }
|
|
345
|
+
|
|
346
|
+
@setparam:ColorInt
|
|
347
|
+
public var referenceHighlightColor: Int = Color.WHITE
|
|
348
|
+
set(value) = invalidating(field, value, GlassDirtyKind.MATERIAL_DIRTY) { field = it }
|
|
349
|
+
|
|
350
|
+
/** 0=legacy/default, 1=toggle, 2=slider, 3=tab, 4=reference button. */
|
|
351
|
+
public var referenceInteractionProfile: Int = 0
|
|
352
|
+
set(value) {
|
|
353
|
+
val next = value.coerceIn(0, 4)
|
|
354
|
+
if (field == next) return
|
|
355
|
+
field = next
|
|
356
|
+
cachedV3Material = null
|
|
357
|
+
resetNativePress()
|
|
358
|
+
reportConsumerDirty(GlassBackdropDirtyReason.MATERIAL)
|
|
359
|
+
host.invalidate()
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/** Animated thumb fraction used to place the independently scaled toggle track. */
|
|
363
|
+
public var referenceToggleFraction: Float = 0f
|
|
364
|
+
set(value) = invalidating(field, value.coerceIn(0f, 1f), GlassDirtyKind.OPTICS_DIRTY) { field = it }
|
|
365
|
+
|
|
366
|
+
@setparam:ColorInt
|
|
367
|
+
public var referenceToggleTrackColorOff: Int? = null
|
|
368
|
+
set(value) = invalidating(field, value, GlassDirtyKind.MATERIAL_DIRTY) { field = it }
|
|
369
|
+
|
|
370
|
+
@setparam:ColorInt
|
|
371
|
+
public var referenceToggleTrackColorOn: Int? = null
|
|
372
|
+
set(value) = invalidating(field, value, GlassDirtyKind.MATERIAL_DIRTY) { field = it }
|
|
373
|
+
|
|
374
|
+
public var referenceToggleTrackWidthDp: Float = 0f
|
|
375
|
+
set(value) = invalidating(field, value.coerceAtLeast(0f), GlassDirtyKind.CONSUMER_GEOMETRY_DIRTY) { field = it }
|
|
376
|
+
|
|
377
|
+
public var referenceToggleTrackHeightDp: Float = 0f
|
|
378
|
+
set(value) = invalidating(field, value.coerceAtLeast(0f), GlassDirtyKind.CONSUMER_GEOMETRY_DIRTY) { field = it }
|
|
379
|
+
|
|
380
|
+
@setparam:ColorInt
|
|
381
|
+
public var referenceToggleSolidBackdropColor: Int? = null
|
|
382
|
+
set(value) = invalidating(field, value, GlassDirtyKind.MATERIAL_DIRTY) { field = it }
|
|
383
|
+
|
|
384
|
+
/** Material-specific multiplier applied to the RGBA tint alpha. */
|
|
385
|
+
public var tintAlpha: Float = 1f
|
|
386
|
+
set(value) = invalidating(field, value.coerceIn(0f, 1f)) { field = it }
|
|
387
|
+
|
|
388
|
+
/** 0..1 RGB dispersion along the lens edge. */
|
|
389
|
+
public var chromaticAberration: Float = 0f
|
|
390
|
+
set(value) = invalidating(field, value) { field = it }
|
|
391
|
+
|
|
392
|
+
/** Strength of the anti-banding grain. */
|
|
393
|
+
public var noiseAlpha: Float = 0.015f
|
|
394
|
+
set(value) = invalidating(field, value) { field = it }
|
|
395
|
+
|
|
396
|
+
/** 0..1 intensity of the specular rim highlight. */
|
|
397
|
+
public var highlightAlpha: Float = 0.45f
|
|
398
|
+
set(value) = invalidating(field, value) { field = it }
|
|
399
|
+
|
|
400
|
+
/** Gain for the half-vector specular lobe. */
|
|
401
|
+
public var specularStrength: Float = 1f
|
|
402
|
+
set(value) = invalidating(field, value) { field = it }
|
|
403
|
+
|
|
404
|
+
/** Gain for the height-field Fresnel edge response. */
|
|
405
|
+
public var fresnelStrength: Float = 0.85f
|
|
406
|
+
set(value) = invalidating(field, value) { field = it }
|
|
407
|
+
|
|
408
|
+
/** Gain for the thin inner compression shadow near the rounded edge. */
|
|
409
|
+
public var innerShadowStrength: Float = 0.18f
|
|
410
|
+
set(value) = invalidating(field, value) { field = it }
|
|
411
|
+
|
|
412
|
+
public var referenceOuterShadowAlpha: Float = 0f
|
|
413
|
+
set(value) = invalidating(field, value.coerceIn(0f, 1f), GlassDirtyKind.MATERIAL_DIRTY) { field = it }
|
|
414
|
+
public var referenceOuterShadowRadiusDp: Float = 0f
|
|
415
|
+
set(value) = invalidating(field, value.coerceAtLeast(0f), GlassDirtyKind.OPTICS_DIRTY) { field = it }
|
|
416
|
+
public var referenceOuterShadowOffsetYDp: Float = 0f
|
|
417
|
+
set(value) = invalidating(field, value, GlassDirtyKind.OPTICS_DIRTY) { field = it }
|
|
418
|
+
|
|
419
|
+
/** Thickness of the specular rim in dp. */
|
|
420
|
+
public var highlightWidthDp: Float = 2f
|
|
421
|
+
set(value) = invalidating(field, value) { field = it }
|
|
422
|
+
|
|
423
|
+
/** Screen-space angle the rim light comes from, in degrees. */
|
|
424
|
+
public var lightAngleDegrees: Float = 245f
|
|
425
|
+
set(value) = invalidating(field, value) { field = it }
|
|
426
|
+
|
|
427
|
+
/** Scrim color used by the lowest tiers. */
|
|
428
|
+
@setparam:ColorInt
|
|
429
|
+
public var fallbackScrimColor: Int = DEFAULT_SCRIM_COLOR
|
|
430
|
+
set(value) = invalidating(field, value) { field = it }
|
|
431
|
+
|
|
432
|
+
/** When true the glass answers touch with the gel press response. */
|
|
433
|
+
public var isGlassInteractive: Boolean = false
|
|
434
|
+
set(value) {
|
|
435
|
+
if (field == value) return
|
|
436
|
+
field = value
|
|
437
|
+
if (!value) resetNativePress()
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* Touch forwarded from the JS source: phase (0 down, 1 move, 2 up, 3 cancel)
|
|
442
|
+
* and the pointer position in this view's px. See
|
|
443
|
+
* [com.newhu.liquidglass.motion.GlassMotionDriver.applyPointerEvent] for why the
|
|
444
|
+
* event, and not a progress value, crosses the bridge.
|
|
445
|
+
*/
|
|
446
|
+
public fun forwardPointer(phase: Int, x: Float, y: Float, eventTimeMillis: Long) {
|
|
447
|
+
if (!useV3Engine) return
|
|
448
|
+
if (!com.newhu.liquidglass.rendering.GlassEngineSelection.supportsEngine(Build.VERSION.SDK_INT)) return
|
|
449
|
+
forwardedPointerX = x
|
|
450
|
+
forwardedPointerY = y
|
|
451
|
+
engine.motion.applyPointerEvent(phase, x, y, eventTimeMillis)
|
|
452
|
+
if (referenceInteractionProfile == REFERENCE_PROFILE_BUTTON) applyInteractionTransform()
|
|
453
|
+
host.invalidate()
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* Knob value channel: travel along the track in px, and the track length.
|
|
458
|
+
*
|
|
459
|
+
* A switch or slider's lens is positioned by a value, not by where a pointer is,
|
|
460
|
+
* so it cannot use [forwardPointer]'s offset. The driver springs to the target
|
|
461
|
+
* and the renderer reads the result, which keeps the value's motion in the same
|
|
462
|
+
* integrator as the press and the shear.
|
|
463
|
+
*/
|
|
464
|
+
private var pendingValueTravel = 0f
|
|
465
|
+
private var pendingValueTrackLength = 0f
|
|
466
|
+
private var pendingValueAnimate = true
|
|
467
|
+
private var pendingValueKeepPressed = false
|
|
468
|
+
private var pendingValueVelocity = 0f
|
|
469
|
+
private var pendingValueDirty = false
|
|
470
|
+
private var pendingValueSnap = false
|
|
471
|
+
|
|
472
|
+
/**
|
|
473
|
+
* Applies the last value the control reported, if a driver can take it yet.
|
|
474
|
+
*
|
|
475
|
+
* Separated from [forwardValue] because the two can arrive in either order: a
|
|
476
|
+
* controlled slider publishes its value during layout, which happens before the
|
|
477
|
+
* first draw installs the material that creates the driver.
|
|
478
|
+
*/
|
|
479
|
+
private fun applyPendingValue() {
|
|
480
|
+
if (!pendingValueDirty) return
|
|
481
|
+
val motion = engine.motion
|
|
482
|
+
if (motion.kindOf() == com.newhu.liquidglass.motion.GlassInteractionKind.STATIC) return
|
|
483
|
+
pendingValueDirty = false
|
|
484
|
+
when {
|
|
485
|
+
pendingValueSnap -> motion.snapValueTravel(pendingValueTravel, pendingValueTrackLength)
|
|
486
|
+
pendingValueAnimate && pendingValueKeepPressed -> {
|
|
487
|
+
motion.press()
|
|
488
|
+
motion.animateValueTravel(pendingValueTravel, pendingValueTrackLength, pendingValueVelocity)
|
|
489
|
+
}
|
|
490
|
+
pendingValueAnimate -> {
|
|
491
|
+
motion.release()
|
|
492
|
+
motion.animateValueTravel(pendingValueTravel, pendingValueTrackLength, pendingValueVelocity)
|
|
493
|
+
}
|
|
494
|
+
else -> {
|
|
495
|
+
motion.press()
|
|
496
|
+
motion.dragValueTravel(pendingValueTravel, pendingValueTrackLength)
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
public fun forwardValue(
|
|
502
|
+
travel: Float,
|
|
503
|
+
trackLength: Float,
|
|
504
|
+
animate: Boolean,
|
|
505
|
+
velocity: Float = 0f,
|
|
506
|
+
keepPressed: Boolean = false,
|
|
507
|
+
snap: Boolean = false,
|
|
508
|
+
) {
|
|
509
|
+
if (!useV3Engine) return
|
|
510
|
+
if (!com.newhu.liquidglass.rendering.GlassEngineSelection.supportsEngine(Build.VERSION.SDK_INT)) return
|
|
511
|
+
// Recorded unconditionally. A prop can arrive before the first draw has
|
|
512
|
+
// installed the material, and the material is what gives the host a driver of
|
|
513
|
+
// the right kind; applying the value to a STATIC driver would be dropped and
|
|
514
|
+
// the control would open at rest and never correct itself. The pending value is
|
|
515
|
+
// replayed by drawWithV3Engine once a driver for a travelling kind exists.
|
|
516
|
+
pendingValueTravel = travel
|
|
517
|
+
pendingValueTrackLength = trackLength
|
|
518
|
+
pendingValueAnimate = animate
|
|
519
|
+
pendingValueKeepPressed = keepPressed
|
|
520
|
+
pendingValueVelocity = velocity
|
|
521
|
+
pendingValueDirty = true
|
|
522
|
+
pendingValueSnap = snap
|
|
523
|
+
applyPendingValue()
|
|
524
|
+
host.invalidate()
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
/** Keep a cropped backdrop region current while an interactive lens is mounted. */
|
|
528
|
+
public var continuousBackdrop: Boolean = false
|
|
529
|
+
set(value) {
|
|
530
|
+
if (field == value) return
|
|
531
|
+
field = value
|
|
532
|
+
host.invalidate()
|
|
533
|
+
if (value) provider?.requestCaptureFrame()
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
/** Optional UI-thread velocity overrides, normalized to -1..1. */
|
|
537
|
+
public var motionX: Float? = null
|
|
538
|
+
set(value) = invalidating(field, value?.coerceIn(-1f, 1f), GlassDirtyKind.OPTICS_DIRTY) { field = it }
|
|
539
|
+
public var motionY: Float? = null
|
|
540
|
+
set(value) = invalidating(field, value?.coerceIn(-1f, 1f), GlassDirtyKind.OPTICS_DIRTY) { field = it }
|
|
541
|
+
|
|
542
|
+
/** Development-only view of the displaced backdrop without material lighting. */
|
|
543
|
+
public var displacementOnlyDebug: Boolean = false
|
|
544
|
+
set(value) = invalidating(field, value, GlassDirtyKind.OPTICS_DIRTY) { field = it }
|
|
545
|
+
|
|
546
|
+
public var sdfDisplacementMapDebug: Boolean = false
|
|
547
|
+
set(value) = invalidating(field, value, GlassDirtyKind.OPTICS_DIRTY) { field = it }
|
|
548
|
+
|
|
549
|
+
/** Optional fidelity cap (accessibility, battery, tests). */
|
|
550
|
+
public var tierOverride: GlassRenderTier? = null
|
|
551
|
+
set(value) = invalidating(field, value) { field = it }
|
|
552
|
+
|
|
553
|
+
public fun onHostAttached() {
|
|
554
|
+
provider?.registerConsumer(host)
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
/** Rebuild host-linked RenderNode and RenderEffect state after window resume. */
|
|
558
|
+
public fun onHostBecameVisible() {
|
|
559
|
+
renderer.invalidateHostAttachment()
|
|
560
|
+
host.invalidate()
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
public fun onHostDetached() {
|
|
564
|
+
provider?.unregisterConsumer(host)
|
|
565
|
+
resetNativePress()
|
|
566
|
+
renderer.release()
|
|
567
|
+
engine.release()
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
private fun resetNativePress() {
|
|
571
|
+
host.removeCallbacks(pressAnimationFrame)
|
|
572
|
+
host.removeCallbacks(externalPressPointerBaselineFrame)
|
|
573
|
+
externalPressAwaitingPointerBaseline = false
|
|
574
|
+
pressStartedAtNanos = 0L
|
|
575
|
+
pointerDown = false
|
|
576
|
+
externalButtonProgress = 0f
|
|
577
|
+
pressAmount = 0f
|
|
578
|
+
pressVelocity = 0f
|
|
579
|
+
pressTarget = 0f
|
|
580
|
+
pressStartValue = 0f
|
|
581
|
+
pressStartVelocity = 0f
|
|
582
|
+
dragX = 0f
|
|
583
|
+
dragY = 0f
|
|
584
|
+
dragTargetX = 0f
|
|
585
|
+
dragTargetY = 0f
|
|
586
|
+
dragStartValueX = 0f
|
|
587
|
+
dragStartValueY = 0f
|
|
588
|
+
dragStartVelocityX = 0f
|
|
589
|
+
dragStartVelocityY = 0f
|
|
590
|
+
dragVelocityX = 0f
|
|
591
|
+
dragVelocityY = 0f
|
|
592
|
+
pointerVelocityXDpPerSecond = 0f
|
|
593
|
+
pointerVelocityYDpPerSecond = 0f
|
|
594
|
+
applyInteractionTransform()
|
|
595
|
+
host.invalidate()
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
/** Observes (never consumes) touch for the gel press response. */
|
|
599
|
+
public fun handleTouch(event: MotionEvent) {
|
|
600
|
+
if (!isGlassInteractive) return
|
|
601
|
+
// The v3 engine owns the motion when it is drawing. Letting both run was the
|
|
602
|
+
// defect the previous chain had: the JS layer set its progress instantly while
|
|
603
|
+
// this controller ran its own spring, so two systems fought for the same
|
|
604
|
+
// value and the surface visibly doubled its response. Only one may own it.
|
|
605
|
+
if (useV3Engine && com.newhu.liquidglass.rendering.GlassEngineSelection.supportsEngine(Build.VERSION.SDK_INT)) {
|
|
606
|
+
if (handleTouchWithV3Engine(event)) return
|
|
607
|
+
}
|
|
608
|
+
when (event.actionMasked) {
|
|
609
|
+
MotionEvent.ACTION_DOWN -> {
|
|
610
|
+
pointerDown = true
|
|
611
|
+
pressX = event.x
|
|
612
|
+
pressY = event.y
|
|
613
|
+
if (referenceInteractionProfile == 0) {
|
|
614
|
+
// The reference snaps the press position to the new
|
|
615
|
+
// pointer on down; only the later release springs home.
|
|
616
|
+
dragStartX = event.x
|
|
617
|
+
dragStartY = event.y
|
|
618
|
+
dragX = 0f
|
|
619
|
+
dragY = 0f
|
|
620
|
+
dragTargetX = 0f
|
|
621
|
+
dragTargetY = 0f
|
|
622
|
+
dragVelocityX = 0f
|
|
623
|
+
dragVelocityY = 0f
|
|
624
|
+
}
|
|
625
|
+
animatePress(target = 1f)
|
|
626
|
+
}
|
|
627
|
+
MotionEvent.ACTION_MOVE -> {
|
|
628
|
+
pressX = event.x
|
|
629
|
+
pressY = event.y
|
|
630
|
+
if (pointerDown && referenceInteractionProfile == 0) {
|
|
631
|
+
// InteractiveHighlight follows the finger directly while
|
|
632
|
+
// pressed. Its positional spring is only used on release.
|
|
633
|
+
dragX = event.x - dragStartX
|
|
634
|
+
dragY = event.y - dragStartY
|
|
635
|
+
dragTargetX = dragX
|
|
636
|
+
dragTargetY = dragY
|
|
637
|
+
dragVelocityX = 0f
|
|
638
|
+
dragVelocityY = 0f
|
|
639
|
+
applyInteractionTransform()
|
|
640
|
+
reportConsumerDirty(GlassBackdropDirtyReason.OPTICS)
|
|
641
|
+
host.invalidate()
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
|
|
645
|
+
pointerDown = false
|
|
646
|
+
animatePress(target = 0f)
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
/**
|
|
652
|
+
* Drives the v3 motion driver from a touch.
|
|
653
|
+
*
|
|
654
|
+
* Returns false when the engine cannot run, so the caller falls through to the
|
|
655
|
+
* compatibility path rather than the surface going inert.
|
|
656
|
+
*/
|
|
657
|
+
private fun handleTouchWithV3Engine(event: MotionEvent): Boolean {
|
|
658
|
+
val driver = engine.motion
|
|
659
|
+
when (event.actionMasked) {
|
|
660
|
+
MotionEvent.ACTION_DOWN -> {
|
|
661
|
+
driver.setSize(host.width.toFloat(), host.height.toFloat())
|
|
662
|
+
driver.onPointerDown(event.x, event.y, event.eventTime)
|
|
663
|
+
}
|
|
664
|
+
MotionEvent.ACTION_MOVE -> driver.onPointerMove(event.x, event.y, event.eventTime)
|
|
665
|
+
MotionEvent.ACTION_UP -> driver.onPointerUp(event.eventTime)
|
|
666
|
+
MotionEvent.ACTION_CANCEL -> driver.onPointerCancel()
|
|
667
|
+
else -> return false
|
|
668
|
+
}
|
|
669
|
+
// The driver advances on its own Choreographer callback and calls back here
|
|
670
|
+
// per frame; invalidating once per touch event keeps the surface live without
|
|
671
|
+
// making the traversal the animation clock.
|
|
672
|
+
host.invalidate()
|
|
673
|
+
return true
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
private fun beginExternalButtonPress() {
|
|
677
|
+
host.removeCallbacks(externalPressPointerBaselineFrame)
|
|
678
|
+
externalPressAwaitingPointerBaseline = true
|
|
679
|
+
dragX = 0f
|
|
680
|
+
dragY = 0f
|
|
681
|
+
dragTargetX = 0f
|
|
682
|
+
dragTargetY = 0f
|
|
683
|
+
dragVelocityX = 0f
|
|
684
|
+
dragVelocityY = 0f
|
|
685
|
+
pointerVelocityXDpPerSecond = 0f
|
|
686
|
+
pointerVelocityYDpPerSecond = 0f
|
|
687
|
+
pointerDown = true
|
|
688
|
+
// Keep the initial press stationary until the current Reanimated
|
|
689
|
+
// coordinates have both had a chance to reach the native view.
|
|
690
|
+
pressX = 0f
|
|
691
|
+
pressY = 0f
|
|
692
|
+
host.postOnAnimation(externalPressPointerBaselineFrame)
|
|
693
|
+
animatePress(1f)
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
private fun captureExternalPressPointerBaseline() {
|
|
697
|
+
externalPressAwaitingPointerBaseline = false
|
|
698
|
+
val density = host.resources.displayMetrics.density
|
|
699
|
+
pressX = interactionPointXDp * density
|
|
700
|
+
pressY = interactionPointYDp * density
|
|
701
|
+
dragStartX = pressX
|
|
702
|
+
dragStartY = pressY
|
|
703
|
+
dragX = 0f
|
|
704
|
+
dragY = 0f
|
|
705
|
+
dragTargetX = 0f
|
|
706
|
+
dragTargetY = 0f
|
|
707
|
+
dragVelocityX = 0f
|
|
708
|
+
dragVelocityY = 0f
|
|
709
|
+
pointerVelocityXDpPerSecond = 0f
|
|
710
|
+
pointerVelocityYDpPerSecond = 0f
|
|
711
|
+
applyInteractionTransform()
|
|
712
|
+
reportConsumerDirty(GlassBackdropDirtyReason.OPTICS)
|
|
713
|
+
host.invalidate()
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
private fun endExternalButtonPress() {
|
|
717
|
+
if (!pointerDown) return
|
|
718
|
+
if (externalPressAwaitingPointerBaseline) {
|
|
719
|
+
host.removeCallbacks(externalPressPointerBaselineFrame)
|
|
720
|
+
captureExternalPressPointerBaseline()
|
|
721
|
+
}
|
|
722
|
+
pointerDown = false
|
|
723
|
+
// The pinned reference snaps the pointer position during movement and
|
|
724
|
+
// releases it to a 300/0.5 spring with zero inherited pointer speed.
|
|
725
|
+
animatePress(target = 0f)
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
private fun updateExternalButtonPointer() {
|
|
729
|
+
if (!pointerDown || referenceInteractionProfile != 0) return
|
|
730
|
+
if (externalPressAwaitingPointerBaseline) return
|
|
731
|
+
val density = host.resources.displayMetrics.density
|
|
732
|
+
pressX = interactionPointXDp * density
|
|
733
|
+
pressY = interactionPointYDp * density
|
|
734
|
+
dragX = pressX - dragStartX
|
|
735
|
+
dragY = pressY - dragStartY
|
|
736
|
+
dragTargetX = dragX
|
|
737
|
+
dragTargetY = dragY
|
|
738
|
+
applyInteractionTransform()
|
|
739
|
+
reportConsumerDirty(GlassBackdropDirtyReason.OPTICS)
|
|
740
|
+
host.invalidate()
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
/** Draws the glass into [canvas]; call before the host's children draw. */
|
|
744
|
+
/** Packs this surface's reference parameters for the shared multi-shape pass. */
|
|
745
|
+
private val sharedPassSnapshot = FloatArray(com.newhu.liquidglass.core.SharedGlassPass.VALUE_COUNT)
|
|
746
|
+
private var sharedPassSnapshotReady = false
|
|
747
|
+
|
|
748
|
+
/**
|
|
749
|
+
* Recomputes this surface's shared-pass parameters without drawing anything.
|
|
750
|
+
*
|
|
751
|
+
* The pass needs the numbers before the surface has ever painted: on a page that
|
|
752
|
+
* draws once, waiting for a draw means the first - and only - pass attempt finds
|
|
753
|
+
* nothing and the page falls back to per-surface rendering for good.
|
|
754
|
+
*/
|
|
755
|
+
fun refreshSharedPassSnapshot() {
|
|
756
|
+
if (!com.newhu.liquidglass.core.SharedGlassPass.ENABLED) return
|
|
757
|
+
if (host.width <= 0 || host.height <= 0) return
|
|
758
|
+
val built = buildFrame()
|
|
759
|
+
if (built.widthPx <= 0f || built.heightPx <= 0f) return
|
|
760
|
+
com.newhu.liquidglass.core.shader.ReferenceGlassUniforms.fill(
|
|
761
|
+
built,
|
|
762
|
+
renderer.opticalInsets(built),
|
|
763
|
+
sharedPassSnapshot,
|
|
764
|
+
)
|
|
765
|
+
sharedPassSnapshotReady = true
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
fun sharedPassValues(out: FloatArray): Boolean {
|
|
769
|
+
if (sharedPassSnapshotReady) {
|
|
770
|
+
sharedPassSnapshot.copyInto(out)
|
|
771
|
+
return true
|
|
772
|
+
}
|
|
773
|
+
val frame = renderer.lastFrame ?: return false
|
|
774
|
+
val insets = renderer.lastInsets ?: return false
|
|
775
|
+
com.newhu.liquidglass.core.shader.ReferenceGlassUniforms.fill(frame, insets, out)
|
|
776
|
+
return true
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
internal fun sharedPassFrame(): Pair<GlassFrame, com.newhu.liquidglass.core.GlassOpticalInsets>? {
|
|
780
|
+
val frame = renderer.lastFrame ?: return null
|
|
781
|
+
val insets = renderer.lastInsets ?: return null
|
|
782
|
+
return frame to insets
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
public fun draw(canvas: Canvas) {
|
|
786
|
+
if (host.width < 1 || host.height < 1) return
|
|
787
|
+
if (PASS_SAMPLE_AUDIT && passSampleAuditDone.add(System.identityHashCode(host))) {
|
|
788
|
+
host.getLocationInWindow(locationSelf)
|
|
789
|
+
android.util.Log.i(
|
|
790
|
+
"GlassPassAudit",
|
|
791
|
+
"host=${locationSelf[0]},${locationSelf[1]} ${host.width}x${host.height}" +
|
|
792
|
+
" provider=${provider != null} recording=${provider?.hasRecording}" +
|
|
793
|
+
" scene=${provider?.contentRenderNode?.width}x${provider?.contentRenderNode?.height}" +
|
|
794
|
+
" region=${provider?.renderNodeFor(host)?.width}x${provider?.renderNodeFor(host)?.height}" +
|
|
795
|
+
" origin=${provider?.recordedOriginXFor(host)},${provider?.recordedOriginYFor(host)}" +
|
|
796
|
+
" pass=${com.newhu.liquidglass.core.SharedGlassPass.ENABLED}",
|
|
797
|
+
)
|
|
798
|
+
}
|
|
799
|
+
LiquidGlassPerfTelemetry.consumerDraw()
|
|
800
|
+
if (continuousBackdrop) provider?.requestCaptureFrame()
|
|
801
|
+
val frame = buildFrame()
|
|
802
|
+
val backdrop = provider
|
|
803
|
+
val needsExtendedReferenceSource = frame.opticsModel == GlassOpticsModel.REFERENCE_PARITY &&
|
|
804
|
+
ReferenceSourceWindowPolicy.requiresFullSource(
|
|
805
|
+
frame.referenceInteractionProfile, frame.interactionProgress,
|
|
806
|
+
frame.contentScaleX, frame.contentScaleY, frame.contentOffsetXPx, frame.contentOffsetYPx,
|
|
807
|
+
)
|
|
808
|
+
if (LiquidGlassTrace.isEnabled() && !referenceSampleAuditLogged && needsExtendedReferenceSource && backdrop?.hasRecording == true && backdrop.contentRenderNode != null) {
|
|
809
|
+
host.getLocationInWindow(locationSelf)
|
|
810
|
+
backdrop?.sourceView?.getLocationInWindow(locationProvider)
|
|
811
|
+
android.util.Log.i(
|
|
812
|
+
"GlassSampleAudit",
|
|
813
|
+
"host=${locationSelf[0]},${locationSelf[1]} ${host.width}x${host.height} provider=${locationProvider[0]},${locationProvider[1]} " +
|
|
814
|
+
"${backdrop?.sourceView?.width}x${backdrop?.sourceView?.height} recording=${backdrop.hasRecording} origin=${backdrop.recordedOriginXFor(host)},${backdrop.recordedOriginYFor(host)} " +
|
|
815
|
+
"frame=${frame.relativeX},${frame.relativeY} size=${frame.widthPx}x${frame.heightPx} " +
|
|
816
|
+
"contentScale=${frame.contentScaleX},${frame.contentScaleY} layerScale=${frame.layerScaleX},${frame.layerScaleY} " +
|
|
817
|
+
"hostScale=${host.scaleX},${host.scaleY} pressAmount=$pressAmount progress=${frame.interactionProgress} " +
|
|
818
|
+
"offsetPx=${frame.contentOffsetXPx},${frame.contentOffsetYPx} " +
|
|
819
|
+
"region=${backdrop?.renderNodeFor(host)?.width}x${backdrop?.renderNodeFor(host)?.height} " +
|
|
820
|
+
"full=${backdrop?.contentRenderNode?.width}x${backdrop?.contentRenderNode?.height}"
|
|
821
|
+
)
|
|
822
|
+
referenceSampleAuditLogged = true
|
|
823
|
+
}
|
|
824
|
+
val referenceBlurRequest =
|
|
825
|
+
Build.VERSION.SDK_INT >= 33 && frame.opticsModel == GlassOpticsModel.REFERENCE_PARITY
|
|
826
|
+
if (LiquidGlassTrace.isEnabled()) {
|
|
827
|
+
LiquidGlassTrace.counter("referenceBlurOpticsModel", if (frame.opticsModel == GlassOpticsModel.REFERENCE_PARITY) 1L else 0L)
|
|
828
|
+
LiquidGlassTrace.counter("referenceBlurRequestEnabled", if (referenceBlurRequest) 1L else 0L)
|
|
829
|
+
LiquidGlassTrace.counter("referenceBlurProviderPresent", if (backdrop != null) 1L else 0L)
|
|
830
|
+
LiquidGlassTrace.counter("referenceBlurRadiusMilliDp", (frame.blurRadiusPx / frame.densityScale * 1000f).toLong())
|
|
831
|
+
}
|
|
832
|
+
val sharedBlurredSource = if (referenceBlurRequest) {
|
|
833
|
+
backdrop?.referenceBlurredSourceFor(host, frame.blurRadiusPx)
|
|
834
|
+
} else {
|
|
835
|
+
null
|
|
836
|
+
}
|
|
837
|
+
if (LiquidGlassTrace.isEnabled()) {
|
|
838
|
+
LiquidGlassTrace.counter("referenceBlurSourceAvailable", if (sharedBlurredSource != null) 1L else 0L)
|
|
839
|
+
}
|
|
840
|
+
if (sharedBlurredSource != null) {
|
|
841
|
+
frame.relativeX = relativePosition[0] - sharedBlurredSource.originX
|
|
842
|
+
frame.relativeY = relativePosition[1] - sharedBlurredSource.originY
|
|
843
|
+
frame.backdropAlreadyBlurred = true
|
|
844
|
+
if (PASS_SAMPLE_AUDIT && passSampleAuditTick++ % 30 == 0) {
|
|
845
|
+
android.util.Log.i(
|
|
846
|
+
"GlassPassAudit",
|
|
847
|
+
"blur host=${host.width}x${host.height} rel=${relativePosition[0].toInt()},${relativePosition[1].toInt()} " +
|
|
848
|
+
"srcOrigin=${sharedBlurredSource.originX},${sharedBlurredSource.originY} " +
|
|
849
|
+
"src=${sharedBlurredSource.node.width}x${sharedBlurredSource.node.height} " +
|
|
850
|
+
"recOriginY=" + (provider?.recordedOriginYFor(host) ?: -1),
|
|
851
|
+
)
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
// CombinedBackdrop controls and explicit optical sample transforms can
|
|
855
|
+
// read outside a consumer-sized crop. Use the shared provider recording
|
|
856
|
+
// for those cases, with frame coordinates anchored to that node.
|
|
857
|
+
if (PASS_SAMPLE_AUDIT && sharedBlurredSource == null && passSampleAuditTick++ % 30 == 0) {
|
|
858
|
+
android.util.Log.i(
|
|
859
|
+
"GlassPassAudit",
|
|
860
|
+
"noblur host=${host.width}x${host.height} recording=${provider?.hasRecording} " +
|
|
861
|
+
"scene=${provider?.contentRenderNode?.width}x${provider?.contentRenderNode?.height} " +
|
|
862
|
+
"region=${provider?.renderNodeFor(host)?.width}x${provider?.renderNodeFor(host)?.height} " +
|
|
863
|
+
"fullRef=" + (needsExtendedReferenceSource || sharedSourceSampling),
|
|
864
|
+
)
|
|
865
|
+
}
|
|
866
|
+
val useFullReferenceSource = sharedBlurredSource == null && (needsExtendedReferenceSource || sharedSourceSampling)
|
|
867
|
+
if (useFullReferenceSource) {
|
|
868
|
+
frame.relativeX = relativePosition[0] - (backdrop?.recordedOriginX ?: 0)
|
|
869
|
+
frame.relativeY = relativePosition[1] - (backdrop?.recordedOriginY ?: 0)
|
|
870
|
+
}
|
|
871
|
+
var providerNode = when {
|
|
872
|
+
sharedBlurredSource != null -> sharedBlurredSource.node
|
|
873
|
+
Build.VERSION.SDK_INT < 29 -> null
|
|
874
|
+
useFullReferenceSource -> backdrop?.contentRenderNode
|
|
875
|
+
else -> backdrop?.renderNodeFor(host)
|
|
876
|
+
}
|
|
877
|
+
val sceneRevision = when {
|
|
878
|
+
sharedBlurredSource != null -> sharedBlurredSource.revision
|
|
879
|
+
else -> backdrop?.renderRevisionFor(host) ?: -1L
|
|
880
|
+
}
|
|
881
|
+
// GPU texture of the already-recorded scene: when it is ready the glass is
|
|
882
|
+
// drawn by one direct shader pass (no RenderNode re-record, no offscreen
|
|
883
|
+
// RenderEffect layers). Fall back silently to the node path otherwise.
|
|
884
|
+
var sceneShader: android.graphics.BitmapShader? = sharedBlurredSource?.shader
|
|
885
|
+
if (sceneShader == null && sharedBlurredSource == null && Build.VERSION.SDK_INT >= 33 &&
|
|
886
|
+
backdrop != null && frame.blurRadiusPx <= 0.05f && frame.shapeMaskText == null &&
|
|
887
|
+
frame.progressiveBlurIntensity <= 0.001f
|
|
888
|
+
) {
|
|
889
|
+
val contentShader = backdrop.contentShaderFor(host)
|
|
890
|
+
val fullNode = backdrop.contentRenderNode
|
|
891
|
+
if (contentShader != null && fullNode != null) {
|
|
892
|
+
sceneShader = contentShader
|
|
893
|
+
providerNode = fullNode
|
|
894
|
+
frame.relativeX = relativePosition[0] - backdrop.contentOriginXFor(host)
|
|
895
|
+
frame.relativeY = relativePosition[1] - backdrop.contentOriginYFor(host)
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
com.newhu.liquidglass.backdrop.internal.ReferenceTabSampling.rebase(frame)
|
|
900
|
+
|
|
901
|
+
if (sharedSceneCaptureProbe && Build.VERSION.SDK_INT >= 29 && providerNode != null) {
|
|
902
|
+
val bucket = System.nanoTime() / 8_000_000L
|
|
903
|
+
if (bucket != captureProbeBucket) {
|
|
904
|
+
captureProbeBucket = bucket
|
|
905
|
+
val probe = captureProbe ?: com.newhu.liquidglass.backdrop.internal.SharedSceneCapture("probe", scale = 3)
|
|
906
|
+
.also {
|
|
907
|
+
captureProbe = it
|
|
908
|
+
android.util.Log.i("LiquidGlassCapture", "probe created, node=${providerNode.width}x${providerNode.height}")
|
|
909
|
+
}
|
|
910
|
+
probe.capture(providerNode, providerNode.width, providerNode.height)
|
|
911
|
+
if (captureProbeBucket % 120L == 0L) {
|
|
912
|
+
android.util.Log.i(
|
|
913
|
+
"LiquidGlassCapture",
|
|
914
|
+
"probe captured=${probe.captured} empty=${probe.emptyCaptures} ready=${probe.isReady}",
|
|
915
|
+
)
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
val tier = GlassRenderTier.select(Build.VERSION.SDK_INT, tierOverride)
|
|
920
|
+
val canSample = canvas.isHardwareAccelerated &&
|
|
921
|
+
backdrop?.hasRecording == true && providerNode != null
|
|
922
|
+
if (canSample) LiquidGlassPerfTelemetry.backdropSample()
|
|
923
|
+
|
|
924
|
+
// The v3 engine is tried first. It returns false when it cannot run — an
|
|
925
|
+
// API level below 33, a shader that failed to link, or no scene to sample
|
|
926
|
+
// — and the older tiers below it stay as the compatibility path so a
|
|
927
|
+
// device that cannot run AGSL still shows a plausible surface.
|
|
928
|
+
if (canSample && useV3Engine && drawWithV3Engine(canvas, providerNode!!, frame, sceneRevision, sceneShader)) {
|
|
929
|
+
return
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
when {
|
|
933
|
+
canSample && tier == GlassRenderTier.SHADER && Build.VERSION.SDK_INT >= 33 ->
|
|
934
|
+
renderer.drawEffectGlass(canvas, providerNode!!, frame, useShader = true, sceneShader = sceneShader)
|
|
935
|
+
canSample && tier != GlassRenderTier.SCRIM && Build.VERSION.SDK_INT >= 31 ->
|
|
936
|
+
renderer.drawEffectGlass(canvas, providerNode!!, frame, useShader = false)
|
|
937
|
+
canSample && Build.VERSION.SDK_INT >= 29 ->
|
|
938
|
+
renderer.drawBackdropScrim(canvas, providerNode!!, frame, resolveScrimColor())
|
|
939
|
+
else ->
|
|
940
|
+
renderer.drawPlainScrim(canvas, frame, resolveScrimColor())
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
/**
|
|
945
|
+
* Draws through the v3 optical core.
|
|
946
|
+
*
|
|
947
|
+
* The controller still owns the coordinate story: it resolves where the
|
|
948
|
+
* recorded scene's origin sits relative to this surface and hands that to the
|
|
949
|
+
* engine. The engine never queries the ViewTree, so the window/provider/
|
|
950
|
+
* recorded-origin/scroll-offset conversions stay in one place instead of being
|
|
951
|
+
* re-derived in two.
|
|
952
|
+
*/
|
|
953
|
+
private fun drawWithV3Engine(
|
|
954
|
+
canvas: Canvas,
|
|
955
|
+
providerNode: RenderNode,
|
|
956
|
+
frame: GlassFrame,
|
|
957
|
+
sceneRevision: Long,
|
|
958
|
+
sceneShader: android.graphics.BitmapShader? = null,
|
|
959
|
+
): Boolean {
|
|
960
|
+
// The optical core currently renders only its analytic capsule/rounded
|
|
961
|
+
// rectangle geometry. Custom text masks are rasterized by the reference
|
|
962
|
+
// shader path below; letting the core claim this frame silently paints
|
|
963
|
+
// the enclosing rectangle instead of the glyph silhouette.
|
|
964
|
+
if (frame.shapeMaskText != null || frame.progressiveBlurIntensity > 0.001f) return false
|
|
965
|
+
if (!com.newhu.liquidglass.rendering.GlassEngineSelection.supportsEngine(Build.VERSION.SDK_INT)) {
|
|
966
|
+
return false
|
|
967
|
+
}
|
|
968
|
+
val density = frame.densityScale.coerceAtLeast(0.01f)
|
|
969
|
+
engine.setSize(frame.widthPx, frame.heightPx)
|
|
970
|
+
val effectiveRadiusDp = if (cornerRadiusDp < 0f) {
|
|
971
|
+
com.newhu.liquidglass.optics.GlassMaterial.RADIUS_CAPSULE
|
|
972
|
+
} else {
|
|
973
|
+
cornerRadiusDp
|
|
974
|
+
}
|
|
975
|
+
engine.setCornerRadiusDp(effectiveRadiusDp)
|
|
976
|
+
val material = cachedV3Material ?: engine.materialFromLegacy(
|
|
977
|
+
cornerRadiusDp = effectiveRadiusDp,
|
|
978
|
+
blurRadiusDp = blurRadiusDp,
|
|
979
|
+
refractionHeightDp = refractionHeightDp,
|
|
980
|
+
refractionAmountDp = refractionAmountDp,
|
|
981
|
+
depthEffect = referenceDepthEffect,
|
|
982
|
+
chromaticAberration = chromaticAberration > 0.5f,
|
|
983
|
+
saturation = saturation,
|
|
984
|
+
brightness = brightness,
|
|
985
|
+
contrast = contrast,
|
|
986
|
+
tintColor = glassTintColor,
|
|
987
|
+
surfaceColor = glassSurfaceColor,
|
|
988
|
+
highlightStyle = referenceHighlightStyle,
|
|
989
|
+
highlightColor = referenceHighlightColor,
|
|
990
|
+
highlightFalloff = referenceHighlightFalloff,
|
|
991
|
+
highlightWidthDp = highlightWidthDp,
|
|
992
|
+
highlightAlpha = highlightAlpha,
|
|
993
|
+
innerShadowAlpha = innerShadowStrength,
|
|
994
|
+
innerShadowRadiusDp = 4f,
|
|
995
|
+
outerShadowAlpha = referenceOuterShadowAlpha,
|
|
996
|
+
outerShadowRadiusDp = referenceOuterShadowRadiusDp,
|
|
997
|
+
outerShadowOffsetYDp = referenceOuterShadowOffsetYDp,
|
|
998
|
+
interactionProfile = referenceInteractionProfile,
|
|
999
|
+
).also { cachedV3Material = it }
|
|
1000
|
+
engine.setMaterial(material)
|
|
1001
|
+
// A toggle or slider surface asks for the reference's own composite: one pass
|
|
1002
|
+
// that lerps the rail colour by the value, places the thumb by it, samples a
|
|
1003
|
+
// scaled copy of the rail and fades the idle white overlay. That pass already
|
|
1004
|
+
// exists in `ReferenceParityGlassShader`, and the v3 core implements a generic
|
|
1005
|
+
// single-shape optic with no notion of a value or a second layer.
|
|
1006
|
+
//
|
|
1007
|
+
// The material has been installed above on purpose: installing it is what
|
|
1008
|
+
// creates this host's motion driver with the travelling kind, so the springs
|
|
1009
|
+
// that animate the value and the press are already running by the time the
|
|
1010
|
+
// parity shader reads them. Only the drawing is delegated.
|
|
1011
|
+
if (frame.opticsModel == GlassOpticsModel.REFERENCE_PARITY && frame.referenceInteractionProfile in 1..3) {
|
|
1012
|
+
applyPendingValue()
|
|
1013
|
+
return false
|
|
1014
|
+
}
|
|
1015
|
+
engine.setContentScale(frame.contentScaleX, frame.contentScaleY)
|
|
1016
|
+
engine.setContentOffset(frame.contentOffsetXPx, frame.contentOffsetYPx)
|
|
1017
|
+
val isButton = frame.referenceInteractionProfile == REFERENCE_PROFILE_BUTTON
|
|
1018
|
+
// A reference button's View is scaled/translated by Android; the sampled scene
|
|
1019
|
+
// must stay fixed on screen, so compensate inside the shader (same law as the
|
|
1020
|
+
// legacy parity shader's layerScale / layerTranslation).
|
|
1021
|
+
if (isButton) {
|
|
1022
|
+
engine.setSceneScale(frame.layerScaleX, frame.layerScaleY)
|
|
1023
|
+
engine.setPressGlow(frame.pressAmount, frame.pressX, frame.pressY)
|
|
1024
|
+
} else {
|
|
1025
|
+
engine.setSceneScale(1f, 1f)
|
|
1026
|
+
engine.setPressGlow(0f, 0f, 0f)
|
|
1027
|
+
}
|
|
1028
|
+
engine.setScene(
|
|
1029
|
+
providerNode,
|
|
1030
|
+
frame.relativeX + if (isButton) frame.layerTranslationXPx else 0f,
|
|
1031
|
+
frame.relativeY + if (isButton) frame.layerTranslationYPx else 0f,
|
|
1032
|
+
backdropAlreadyBlurred = frame.backdropAlreadyBlurred,
|
|
1033
|
+
sceneRevision = sceneRevision,
|
|
1034
|
+
sceneShader = sceneShader,
|
|
1035
|
+
)
|
|
1036
|
+
|
|
1037
|
+
// The engine's motion driver is the single owner of interaction state when
|
|
1038
|
+
// it is running. Overwriting its state from the controller's own springs — as
|
|
1039
|
+
// this method used to — meant the driver advanced correct values every frame
|
|
1040
|
+
// and they were discarded before the draw, so the AGSL path never saw its own
|
|
1041
|
+
// animation and the frame progress came from a second spring elsewhere.
|
|
1042
|
+
//
|
|
1043
|
+
// The controller's values are only used as a seed when the driver has never
|
|
1044
|
+
// been touched, which is the case for surfaces driven purely from JS props
|
|
1045
|
+
// (toggles, sliders, tab lenses) rather than from native touch.
|
|
1046
|
+
val driver = engine.motion
|
|
1047
|
+
if (!driver.hasInput) {
|
|
1048
|
+
val motionState = driver.state
|
|
1049
|
+
motionState.pressProgress = frame.interactionProgress.coerceIn(0f, 1f)
|
|
1050
|
+
motionState.opticalProgress = frame.interactionProgress.coerceIn(0f, 1f)
|
|
1051
|
+
motionState.pointerX = dragX / density
|
|
1052
|
+
motionState.pointerY = dragY / density
|
|
1053
|
+
motionState.velocityX = dragVelocityX / density
|
|
1054
|
+
motionState.velocityY = dragVelocityY / density
|
|
1055
|
+
}
|
|
1056
|
+
// The driver resolves the deformation (button tanh translation plus the
|
|
1057
|
+
// directional stretch, or the knob shear). Its scale is what the layer must
|
|
1058
|
+
// draw with so the silhouette matches the band and the highlight the shader
|
|
1059
|
+
// computes from the same press progress.
|
|
1060
|
+
// The canvas owns the deformation transform, so the shader must see an
|
|
1061
|
+
// unscaled layer or it would divide the scale out a second time and the
|
|
1062
|
+
// squash would cancel itself.
|
|
1063
|
+
engine.setLayerScale(1f, 1f)
|
|
1064
|
+
|
|
1065
|
+
val beforeCreations = engine.chainEffectCreations
|
|
1066
|
+
engine.drawShadow(canvas)
|
|
1067
|
+
val drew = engine.draw(canvas)
|
|
1068
|
+
if (drew && engine.chainEffectCreations != beforeCreations) {
|
|
1069
|
+
LiquidGlassPerfTelemetry.effectBuild()
|
|
1070
|
+
}
|
|
1071
|
+
return drew
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
private fun buildFrame(): GlassFrame {
|
|
1075
|
+
val density = host.resources.displayMetrics.density
|
|
1076
|
+
val width = host.width.toFloat()
|
|
1077
|
+
val height = host.height.toFloat()
|
|
1078
|
+
val maxRadius = min(width, height) / 2f
|
|
1079
|
+
val cornerRadiusPx = if (cornerRadiusDp < 0f) {
|
|
1080
|
+
maxRadius
|
|
1081
|
+
} else {
|
|
1082
|
+
min(cornerRadiusDp * density, maxRadius)
|
|
1083
|
+
}
|
|
1084
|
+
val relative = relativeToProvider()
|
|
1085
|
+
updateMotion(relative)
|
|
1086
|
+
val backdrop = provider
|
|
1087
|
+
val recordedOriginX = backdrop?.recordedOriginXFor(host) ?: 0
|
|
1088
|
+
val recordedOriginY = backdrop?.recordedOriginYFor(host) ?: 0
|
|
1089
|
+
frame.widthPx = width
|
|
1090
|
+
frame.heightPx = height
|
|
1091
|
+
frame.cornerRadiusPx = cornerRadiusPx
|
|
1092
|
+
frame.shapeMaskText = shapeMaskText
|
|
1093
|
+
frame.shapeMaskFontSizePx = shapeMaskFontSizeDp * density
|
|
1094
|
+
frame.shapeMaskFontWeight = shapeMaskFontWeight
|
|
1095
|
+
frame.progressiveBlurIntensity = progressiveBlurIntensity
|
|
1096
|
+
frame.densityScale = density
|
|
1097
|
+
frame.opticsModel = opticsModel
|
|
1098
|
+
frame.dispersion = chromaticAberration
|
|
1099
|
+
frame.sdfScaleLens = sdfScaleLens
|
|
1100
|
+
frame.blurRadiusPx = blurRadiusDp * density
|
|
1101
|
+
frame.backdropAlreadyBlurred = false
|
|
1102
|
+
frame.refractionHeightPx = refractionHeightDp * density
|
|
1103
|
+
frame.refractionAmountPx = refractionAmountDp * density
|
|
1104
|
+
frame.referenceDepthEffect = referenceDepthEffect
|
|
1105
|
+
frame.bodyRefractionAmountPx = bodyRefractionAmountDp * density
|
|
1106
|
+
frame.contentScaleX = referenceContentScaleX
|
|
1107
|
+
frame.contentScaleY = referenceContentScaleY
|
|
1108
|
+
frame.contentOffsetXPx = referenceSampleOffsetXDp * density
|
|
1109
|
+
frame.contentOffsetYPx = referenceSampleOffsetYDp * density
|
|
1110
|
+
// For a value-driven control the press belongs to the motion driver, which
|
|
1111
|
+
// integrates it alongside the value. Reading the controller's own press
|
|
1112
|
+
// spring here as well would give the same quantity two authors and make the
|
|
1113
|
+
// thumb's scale disagree with the rail it magnifies.
|
|
1114
|
+
val driverOwnsPress = useV3Engine &&
|
|
1115
|
+
com.newhu.liquidglass.rendering.GlassEngineSelection.supportsEngine(Build.VERSION.SDK_INT) &&
|
|
1116
|
+
referenceInteractionProfile != 0 && engine.motion.hasInput
|
|
1117
|
+
frame.interactionProgress = if (driverOwnsPress) {
|
|
1118
|
+
engine.motion.state.pressProgress
|
|
1119
|
+
} else {
|
|
1120
|
+
maxOf(interactionProgress, pressAmount)
|
|
1121
|
+
}
|
|
1122
|
+
val buttonDriverOwnsMotion = hasReferenceButtonMotion()
|
|
1123
|
+
val interactionScale = if (buttonDriverOwnsMotion) {
|
|
1124
|
+
Pair(engine.motion.state.deformationScaleX, engine.motion.state.deformationScaleY)
|
|
1125
|
+
} else {
|
|
1126
|
+
interactionScale()
|
|
1127
|
+
}
|
|
1128
|
+
if (buttonDriverOwnsMotion) applyInteractionTransform()
|
|
1129
|
+
frame.layerScaleX = interactionScale.first
|
|
1130
|
+
frame.layerScaleY = interactionScale.second
|
|
1131
|
+
// A travelling knob's offset belongs to the motion state, which is the single
|
|
1132
|
+
// writer of the value. Reading it here rather than trusting host.translationX
|
|
1133
|
+
// means a knob that was never touched still opens at its value: a controlled
|
|
1134
|
+
// slider publishes a value during layout, before any gesture exists.
|
|
1135
|
+
val motionKind = engine.motion.kindOf()
|
|
1136
|
+
// TAB_LENS belongs here with the other travelling knobs: its View moves by the
|
|
1137
|
+
// same motion state, and leaving it out pinned the tab lens to the first tab
|
|
1138
|
+
// forever — measured on device, native received travel=820.5 while the lens
|
|
1139
|
+
// stayed put and the accent copy showed through a glass parked at tab 0.
|
|
1140
|
+
val travels = motionKind == com.newhu.liquidglass.motion.GlassInteractionKind.SLIDER_KNOB ||
|
|
1141
|
+
motionKind == com.newhu.liquidglass.motion.GlassInteractionKind.TOGGLE_KNOB ||
|
|
1142
|
+
motionKind == com.newhu.liquidglass.motion.GlassInteractionKind.TAB_LENS
|
|
1143
|
+
if (travels && useV3Engine) {
|
|
1144
|
+
host.translationX = engine.motion.state.translationX
|
|
1145
|
+
host.translationY = engine.motion.state.translationY
|
|
1146
|
+
}
|
|
1147
|
+
frame.layerTranslationXPx = host.translationX
|
|
1148
|
+
frame.layerTranslationYPx = host.translationY
|
|
1149
|
+
frame.saturation = saturation
|
|
1150
|
+
frame.brightness = brightness
|
|
1151
|
+
frame.contrast = contrast
|
|
1152
|
+
frame.tintColor = glassTintColor
|
|
1153
|
+
frame.tintAlpha = tintAlpha
|
|
1154
|
+
frame.surfaceColor = glassSurfaceColor
|
|
1155
|
+
frame.referenceHighlightStyle = referenceHighlightStyle
|
|
1156
|
+
frame.referenceHighlightFalloff = referenceHighlightFalloff
|
|
1157
|
+
frame.referenceHighlightColor = referenceHighlightColor
|
|
1158
|
+
frame.referenceInteractionProfile = referenceInteractionProfile
|
|
1159
|
+
// The rail's colour, the thumb's offset and the magnified track all read this
|
|
1160
|
+
// one fraction. Taking it from the motion driver keeps them on the same spring
|
|
1161
|
+
// as the press: previously the fraction came from a JS shared value and the
|
|
1162
|
+
// press from a native spring, so a release animated the two independently and
|
|
1163
|
+
// the colour arrived before the thumb.
|
|
1164
|
+
frame.referenceToggleFraction = if (useV3Engine &&
|
|
1165
|
+
com.newhu.liquidglass.rendering.GlassEngineSelection.supportsEngine(Build.VERSION.SDK_INT) &&
|
|
1166
|
+
referenceInteractionProfile != 0 && engine.motion.hasInput
|
|
1167
|
+
) {
|
|
1168
|
+
engine.motion.state.selectionProgress
|
|
1169
|
+
} else {
|
|
1170
|
+
referenceToggleFraction
|
|
1171
|
+
}
|
|
1172
|
+
frame.referenceToggleTrackColorOff = referenceToggleTrackColorOff ?: Color.TRANSPARENT
|
|
1173
|
+
frame.referenceToggleTrackColorOn = referenceToggleTrackColorOn ?: Color.TRANSPARENT
|
|
1174
|
+
frame.referenceToggleTrackWidthPx = referenceToggleTrackWidthDp * density
|
|
1175
|
+
frame.referenceToggleTrackHeightPx = referenceToggleTrackHeightDp * density
|
|
1176
|
+
frame.referenceToggleUseSolidBackdropColor = referenceToggleSolidBackdropColor != null
|
|
1177
|
+
frame.referenceToggleSolidBackdropColor = referenceToggleSolidBackdropColor ?: Color.TRANSPARENT
|
|
1178
|
+
frame.referenceToggleBackdropEnabled = referenceInteractionProfile == 1 &&
|
|
1179
|
+
referenceToggleTrackColorOff != null && referenceToggleTrackColorOn != null &&
|
|
1180
|
+
referenceToggleTrackWidthDp > 0f && referenceToggleTrackHeightDp > 0f
|
|
1181
|
+
frame.referenceOverlayColor = Color.TRANSPARENT
|
|
1182
|
+
frame.referenceOverlayAlpha = 0f
|
|
1183
|
+
frame.referenceOverlayBlackAlpha = 0f
|
|
1184
|
+
frame.chromaticAberration = chromaticAberration
|
|
1185
|
+
frame.noiseAlpha = noiseAlpha
|
|
1186
|
+
frame.highlightAlpha = if (referenceInteractionProfile == REFERENCE_PROFILE_BUTTON) {
|
|
1187
|
+
highlightAlpha
|
|
1188
|
+
} else {
|
|
1189
|
+
highlightAlpha * (1f + pressAmount * 0.4f)
|
|
1190
|
+
}
|
|
1191
|
+
frame.specularStrength = specularStrength
|
|
1192
|
+
frame.fresnelStrength = fresnelStrength
|
|
1193
|
+
frame.innerShadowStrength = innerShadowStrength
|
|
1194
|
+
frame.outerShadowAlpha = referenceOuterShadowAlpha
|
|
1195
|
+
frame.outerShadowRadiusPx = referenceOuterShadowRadiusDp * density
|
|
1196
|
+
frame.outerShadowOffsetYPx = referenceOuterShadowOffsetYDp * density
|
|
1197
|
+
frame.highlightWidthPx = highlightWidthDp * density
|
|
1198
|
+
if (opticsModel == GlassOpticsModel.REFERENCE_PARITY) {
|
|
1199
|
+
val progress = frame.interactionProgress.coerceIn(0f, 1f)
|
|
1200
|
+
when (referenceInteractionProfile) {
|
|
1201
|
+
1, 2 -> {
|
|
1202
|
+
// Toggle and slider backdrops remain at scene coordinates;
|
|
1203
|
+
// the reference shader composites their optional scaled
|
|
1204
|
+
// track layer independently around the current thumb.
|
|
1205
|
+
frame.contentScaleX = 1f
|
|
1206
|
+
frame.contentScaleY = 1f
|
|
1207
|
+
frame.blurRadiusPx = blurRadiusDp * density * (1f - progress)
|
|
1208
|
+
frame.refractionHeightPx *= progress
|
|
1209
|
+
frame.refractionAmountPx *= progress
|
|
1210
|
+
frame.highlightAlpha = highlightAlpha * progress
|
|
1211
|
+
frame.innerShadowStrength *= progress
|
|
1212
|
+
// The reference body has surfaceAlpha=0. Its solid white
|
|
1213
|
+
// idle pebble is a POST-body SrcOver overlay, fading to
|
|
1214
|
+
// zero while pressed, after any backdrop/inner shadow.
|
|
1215
|
+
frame.referenceOverlayColor = Color.WHITE
|
|
1216
|
+
frame.referenceOverlayAlpha = 1f - progress
|
|
1217
|
+
frame.surfaceColor = Color.TRANSPARENT
|
|
1218
|
+
}
|
|
1219
|
+
3 -> {
|
|
1220
|
+
// Both pinned references multiply lens depth/amount by
|
|
1221
|
+
// press progress. Full refraction at rest pulled a second
|
|
1222
|
+
// copy of the selected glyph into the capsule's top edge.
|
|
1223
|
+
frame.blurRadiusPx = 0f
|
|
1224
|
+
frame.refractionHeightPx *= progress
|
|
1225
|
+
frame.refractionAmountPx *= progress
|
|
1226
|
+
frame.highlightAlpha = highlightAlpha * progress
|
|
1227
|
+
frame.innerShadowStrength *= progress
|
|
1228
|
+
frame.outerShadowAlpha *= progress
|
|
1229
|
+
// Reference indicator: 10% theme-aware idle dim overlay
|
|
1230
|
+
// fades out, with a 3% black wash fading in on press.
|
|
1231
|
+
frame.referenceOverlayColor = glassSurfaceColor
|
|
1232
|
+
frame.referenceOverlayAlpha = Color.alpha(glassSurfaceColor) / 255f * (1f - progress)
|
|
1233
|
+
frame.referenceOverlayBlackAlpha = 0.03f * progress
|
|
1234
|
+
frame.surfaceColor = Color.TRANSPARENT
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1237
|
+
}
|
|
1238
|
+
frame.displacementOnlyDebug = displacementOnlyDebug
|
|
1239
|
+
frame.sdfDisplacementMapDebug = sdfDisplacementMapDebug
|
|
1240
|
+
frame.lightAngleDegrees = lightAngleDegrees
|
|
1241
|
+
frame.pressAmount = if (buttonDriverOwnsMotion) engine.motion.state.pressProgress else pressAmount
|
|
1242
|
+
frame.pressX = if (referenceInteractionProfile == REFERENCE_PROFILE_BUTTON) forwardedPointerX else pressX
|
|
1243
|
+
frame.pressY = if (referenceInteractionProfile == REFERENCE_PROFILE_BUTTON) forwardedPointerY else pressY
|
|
1244
|
+
frame.relativeX = relative[0] - recordedOriginX
|
|
1245
|
+
frame.relativeY = relative[1] - recordedOriginY
|
|
1246
|
+
frame.motionX = motionX ?: derivedMotionX
|
|
1247
|
+
frame.motionY = motionY ?: derivedMotionY
|
|
1248
|
+
return frame
|
|
1249
|
+
}
|
|
1250
|
+
|
|
1251
|
+
private fun updateMotion(relative: FloatArray) {
|
|
1252
|
+
val now = System.nanoTime()
|
|
1253
|
+
val previousX = previousRelativeX
|
|
1254
|
+
val previousY = previousRelativeY
|
|
1255
|
+
val elapsedSeconds = (now - previousMotionAtNanos) / 1_000_000_000f
|
|
1256
|
+
if (previousX != null && previousY != null &&
|
|
1257
|
+
(abs(relative[0] - previousX) > 0.5f || abs(relative[1] - previousY) > 0.5f)
|
|
1258
|
+
) {
|
|
1259
|
+
// Cropped providers need a new recording when the consumer moves.
|
|
1260
|
+
// Full-scene providers (the Expo/RN host) only need new sampling
|
|
1261
|
+
// coordinates, so avoid an otherwise redundant full-page re-record.
|
|
1262
|
+
val backdrop = provider
|
|
1263
|
+
if (!continuousBackdrop && backdrop?.requiresCaptureOnConsumerMovement == true) {
|
|
1264
|
+
backdrop.requestCaptureFrame()
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
if (previousX != null && previousY != null && elapsedSeconds in 0.004f..0.12f) {
|
|
1268
|
+
val density = host.resources.displayMetrics.density.coerceAtLeast(1f)
|
|
1269
|
+
val targetX = (((relative[0] - previousX) / density) / elapsedSeconds / 1800f).coerceIn(-1f, 1f)
|
|
1270
|
+
val targetY = (((relative[1] - previousY) / density) / elapsedSeconds / 1800f).coerceIn(-1f, 1f)
|
|
1271
|
+
derivedMotionX = derivedMotionX * 0.62f + targetX * 0.38f
|
|
1272
|
+
derivedMotionY = derivedMotionY * 0.62f + targetY * 0.38f
|
|
1273
|
+
} else if (elapsedSeconds > 0.12f || previousX == null) {
|
|
1274
|
+
derivedMotionX = 0f
|
|
1275
|
+
derivedMotionY = 0f
|
|
1276
|
+
}
|
|
1277
|
+
previousRelativeX = relative[0]
|
|
1278
|
+
previousRelativeY = relative[1]
|
|
1279
|
+
previousMotionAtNanos = now
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1282
|
+
private fun relativeToProvider(): FloatArray {
|
|
1283
|
+
val backdrop = provider
|
|
1284
|
+
if (backdrop == null) {
|
|
1285
|
+
relativePosition[0] = 0f
|
|
1286
|
+
relativePosition[1] = 0f
|
|
1287
|
+
return relativePosition
|
|
1288
|
+
}
|
|
1289
|
+
val previousX = relativePosition[0]
|
|
1290
|
+
val previousY = relativePosition[1]
|
|
1291
|
+
LiquidGlassPerfTelemetry.geometryLookup()
|
|
1292
|
+
// Keep the consumer's layout origin separate from its own optical
|
|
1293
|
+
// press matrix. The shader maps samples through that matrix itself so
|
|
1294
|
+
// the sampled scene stays fixed while the glass layer grows.
|
|
1295
|
+
locationInWindowWithoutHostTransform(host, locationSelf)
|
|
1296
|
+
LiquidGlassPerfTelemetry.geometryLookup()
|
|
1297
|
+
backdrop.getCachedSourceWindowOrigin(locationProvider)
|
|
1298
|
+
relativePosition[0] = (locationSelf[0] - locationProvider[0]).toFloat()
|
|
1299
|
+
relativePosition[1] = (locationSelf[1] - locationProvider[1]).toFloat()
|
|
1300
|
+
if (previousX != relativePosition[0] || previousY != relativePosition[1]) {
|
|
1301
|
+
if (!continuousBackdrop) {
|
|
1302
|
+
backdrop.onConsumerGeometryChanged(
|
|
1303
|
+
host,
|
|
1304
|
+
relativePosition[0].toInt(),
|
|
1305
|
+
relativePosition[1].toInt(),
|
|
1306
|
+
)
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
return relativePosition
|
|
1310
|
+
}
|
|
1311
|
+
|
|
1312
|
+
private fun locationInWindowWithoutHostTransform(view: View, out: IntArray) {
|
|
1313
|
+
val parent = view.parent as? View
|
|
1314
|
+
if (parent == null) {
|
|
1315
|
+
view.getLocationInWindow(out)
|
|
1316
|
+
return
|
|
1317
|
+
}
|
|
1318
|
+
parentToWindow.reset()
|
|
1319
|
+
parent.transformMatrixToGlobal(parentToWindow)
|
|
1320
|
+
layoutOriginInWindow[0] = (view.left - parent.scrollX).toFloat()
|
|
1321
|
+
layoutOriginInWindow[1] = (view.top - parent.scrollY).toFloat()
|
|
1322
|
+
parentToWindow.mapPoints(layoutOriginInWindow)
|
|
1323
|
+
out[0] = kotlin.math.round(layoutOriginInWindow[0]).toInt()
|
|
1324
|
+
out[1] = kotlin.math.round(layoutOriginInWindow[1]).toInt()
|
|
1325
|
+
}
|
|
1326
|
+
|
|
1327
|
+
private fun resolveScrimColor(): Int =
|
|
1328
|
+
if (Color.alpha(glassTintColor) > 0) glassTintColor else fallbackScrimColor
|
|
1329
|
+
|
|
1330
|
+
private fun animatePress(target: Float, releaseDragVelocityX: Float? = null, releaseDragVelocityY: Float? = null) {
|
|
1331
|
+
val now = System.nanoTime()
|
|
1332
|
+
advancePressAnimation(now)
|
|
1333
|
+
host.removeCallbacks(pressAnimationFrame)
|
|
1334
|
+
pressTarget = target
|
|
1335
|
+
pressStartValue = pressAmount
|
|
1336
|
+
pressStartVelocity = pressVelocity
|
|
1337
|
+
pressStartedAtNanos = now
|
|
1338
|
+
if (referenceInteractionProfile == 0 && !pointerDown) {
|
|
1339
|
+
dragTargetX = 0f
|
|
1340
|
+
dragTargetY = 0f
|
|
1341
|
+
}
|
|
1342
|
+
dragStartValueX = dragX
|
|
1343
|
+
dragStartValueY = dragY
|
|
1344
|
+
dragStartVelocityX = releaseDragVelocityX ?: dragVelocityX
|
|
1345
|
+
dragStartVelocityY = releaseDragVelocityY ?: dragVelocityY
|
|
1346
|
+
dragVelocityX = dragStartVelocityX
|
|
1347
|
+
dragVelocityY = dragStartVelocityY
|
|
1348
|
+
val pressSettled = abs(pressStartValue - target) < SPRING_SETTLE_THRESHOLD && abs(pressVelocity) < SPRING_SETTLE_THRESHOLD
|
|
1349
|
+
val dragSettled = referenceInteractionProfile != 0 || (
|
|
1350
|
+
abs(dragStartValueX - dragTargetX) < SPRING_SETTLE_THRESHOLD &&
|
|
1351
|
+
abs(dragStartValueY - dragTargetY) < SPRING_SETTLE_THRESHOLD &&
|
|
1352
|
+
abs(dragVelocityX) < SPRING_SETTLE_THRESHOLD &&
|
|
1353
|
+
abs(dragVelocityY) < SPRING_SETTLE_THRESHOLD
|
|
1354
|
+
)
|
|
1355
|
+
if (pressSettled && dragSettled) {
|
|
1356
|
+
pressAmount = target
|
|
1357
|
+
pressVelocity = 0f
|
|
1358
|
+
pressStartedAtNanos = 0L
|
|
1359
|
+
if (referenceInteractionProfile == 0 && !pointerDown) {
|
|
1360
|
+
dragX = dragTargetX
|
|
1361
|
+
dragY = dragTargetY
|
|
1362
|
+
dragVelocityX = 0f
|
|
1363
|
+
dragVelocityY = 0f
|
|
1364
|
+
}
|
|
1365
|
+
applyInteractionTransform()
|
|
1366
|
+
reportConsumerDirty(GlassBackdropDirtyReason.OPTICS)
|
|
1367
|
+
host.invalidate()
|
|
1368
|
+
return
|
|
1369
|
+
}
|
|
1370
|
+
host.postOnAnimation(pressAnimationFrame)
|
|
1371
|
+
}
|
|
1372
|
+
|
|
1373
|
+
/** Closed-form spring; a second touch takes over the current velocity. */
|
|
1374
|
+
private fun advancePressAnimation(nowNanos: Long): Boolean {
|
|
1375
|
+
if (pressStartedAtNanos == 0L) return false
|
|
1376
|
+
val elapsed = ((nowNanos - pressStartedAtNanos).coerceAtLeast(0L) / 1_000_000_000.0).toFloat()
|
|
1377
|
+
val (stiffness, damping) = when (referenceInteractionProfile) {
|
|
1378
|
+
1, 2, 3 -> Pair(CONTROL_SPRING_STIFFNESS, 1f)
|
|
1379
|
+
else -> Pair(BUTTON_SPRING_STIFFNESS, BUTTON_SPRING_DAMPING)
|
|
1380
|
+
}
|
|
1381
|
+
val omega = sqrt(stiffness)
|
|
1382
|
+
val x0 = pressStartValue - pressTarget
|
|
1383
|
+
val v0 = pressStartVelocity
|
|
1384
|
+
val offset: Float
|
|
1385
|
+
val velocity: Float
|
|
1386
|
+
if (damping >= 1f) {
|
|
1387
|
+
val decay = exp(-omega * elapsed)
|
|
1388
|
+
offset = x0 * decay + (v0 + omega * x0) * elapsed * decay
|
|
1389
|
+
velocity = -omega * x0 * decay + (v0 + omega * x0) * (decay - omega * elapsed * decay)
|
|
1390
|
+
} else {
|
|
1391
|
+
val omegaD = omega * sqrt(1f - damping * damping)
|
|
1392
|
+
val decay = exp(-damping * omega * elapsed)
|
|
1393
|
+
val cosWd = cos(omegaD * elapsed)
|
|
1394
|
+
val sinWd = sin(omegaD * elapsed)
|
|
1395
|
+
val b0 = (v0 + damping * omega * x0) / omegaD
|
|
1396
|
+
offset = x0 * decay * cosWd + b0 * decay * sinWd
|
|
1397
|
+
velocity = -damping * omega * offset + decay * (-x0 * omegaD * sinWd + b0 * omegaD * cosWd)
|
|
1398
|
+
}
|
|
1399
|
+
pressAmount = pressTarget + offset
|
|
1400
|
+
pressVelocity = velocity
|
|
1401
|
+
var dragXSettled = true
|
|
1402
|
+
var dragYSettled = true
|
|
1403
|
+
if (referenceInteractionProfile == 0) {
|
|
1404
|
+
if (pointerDown) {
|
|
1405
|
+
// The reference snaps both axes to the active pointer. Do not
|
|
1406
|
+
// let the press spring's clock pull the drag point back toward
|
|
1407
|
+
// the stale down position while the finger is moving.
|
|
1408
|
+
dragX = dragTargetX
|
|
1409
|
+
dragY = dragTargetY
|
|
1410
|
+
dragVelocityX = 0f
|
|
1411
|
+
dragVelocityY = 0f
|
|
1412
|
+
} else {
|
|
1413
|
+
val dragXResult = springValue(
|
|
1414
|
+
dragStartValueX,
|
|
1415
|
+
dragStartVelocityX,
|
|
1416
|
+
dragTargetX,
|
|
1417
|
+
elapsed,
|
|
1418
|
+
BUTTON_SPRING_DAMPING,
|
|
1419
|
+
)
|
|
1420
|
+
dragX = dragXResult.first
|
|
1421
|
+
dragVelocityX = dragXResult.second
|
|
1422
|
+
val dragYResult = springValue(
|
|
1423
|
+
dragStartValueY,
|
|
1424
|
+
dragStartVelocityY,
|
|
1425
|
+
dragTargetY,
|
|
1426
|
+
elapsed,
|
|
1427
|
+
BUTTON_SPRING_DAMPING,
|
|
1428
|
+
)
|
|
1429
|
+
dragY = dragYResult.first
|
|
1430
|
+
dragVelocityY = dragYResult.second
|
|
1431
|
+
dragXSettled = abs(dragX - dragTargetX) < SPRING_SETTLE_THRESHOLD && abs(dragVelocityX) < SPRING_SETTLE_THRESHOLD
|
|
1432
|
+
dragYSettled = abs(dragY - dragTargetY) < SPRING_SETTLE_THRESHOLD && abs(dragVelocityY) < SPRING_SETTLE_THRESHOLD
|
|
1433
|
+
}
|
|
1434
|
+
}
|
|
1435
|
+
val pressSettled = abs(offset) < SPRING_SETTLE_THRESHOLD && abs(velocity) < SPRING_SETTLE_THRESHOLD
|
|
1436
|
+
if (pressSettled && dragXSettled && dragYSettled) {
|
|
1437
|
+
pressAmount = pressTarget
|
|
1438
|
+
pressVelocity = 0f
|
|
1439
|
+
if (referenceInteractionProfile == 0) {
|
|
1440
|
+
dragX = dragTargetX
|
|
1441
|
+
dragY = dragTargetY
|
|
1442
|
+
dragVelocityX = 0f
|
|
1443
|
+
dragVelocityY = 0f
|
|
1444
|
+
}
|
|
1445
|
+
pressStartedAtNanos = 0L
|
|
1446
|
+
return false
|
|
1447
|
+
}
|
|
1448
|
+
return true
|
|
1449
|
+
}
|
|
1450
|
+
|
|
1451
|
+
private fun applyInteractionTransform() {
|
|
1452
|
+
if (hasReferenceButtonMotion()) {
|
|
1453
|
+
val motion = engine.motion.state
|
|
1454
|
+
host.translationX = motion.translationX
|
|
1455
|
+
host.translationY = motion.translationY
|
|
1456
|
+
host.scaleX = motion.deformationScaleX
|
|
1457
|
+
host.scaleY = motion.deformationScaleY
|
|
1458
|
+
onInteractionTransformUpdated?.invoke(
|
|
1459
|
+
host.translationX,
|
|
1460
|
+
host.translationY,
|
|
1461
|
+
host.scaleX,
|
|
1462
|
+
host.scaleY,
|
|
1463
|
+
)
|
|
1464
|
+
return
|
|
1465
|
+
}
|
|
1466
|
+
val interactionScale = interactionScale()
|
|
1467
|
+
if (referenceInteractionProfile == 0) {
|
|
1468
|
+
val width = host.width.toFloat().coerceAtLeast(1f)
|
|
1469
|
+
val height = host.height.toFloat().coerceAtLeast(1f)
|
|
1470
|
+
val minDimension = min(width, height)
|
|
1471
|
+
val safeDimension = minDimension.coerceAtLeast(1f)
|
|
1472
|
+
host.translationX = minDimension * kotlin.math.tanh(0.05f * dragX / safeDimension)
|
|
1473
|
+
host.translationY = minDimension * kotlin.math.tanh(0.05f * dragY / safeDimension)
|
|
1474
|
+
host.scaleX = interactionScale.first
|
|
1475
|
+
host.scaleY = interactionScale.second
|
|
1476
|
+
} else {
|
|
1477
|
+
// A knob's position is the motion state's, not a fixed zero. This branch
|
|
1478
|
+
// used to clear the translation every frame, which is correct for a glass
|
|
1479
|
+
// that stays where layout put it and wrong for one that travels: the value,
|
|
1480
|
+
// the rail fill and the label all advanced while the lens stayed at the
|
|
1481
|
+
// rail's start, because this line rewrote what the spring had produced.
|
|
1482
|
+
val kindNow = engine.motion.kindOf()
|
|
1483
|
+
val travelling = kindNow == com.newhu.liquidglass.motion.GlassInteractionKind.SLIDER_KNOB ||
|
|
1484
|
+
kindNow == com.newhu.liquidglass.motion.GlassInteractionKind.TOGGLE_KNOB ||
|
|
1485
|
+
kindNow == com.newhu.liquidglass.motion.GlassInteractionKind.TAB_LENS
|
|
1486
|
+
if (travelling && useV3Engine) {
|
|
1487
|
+
host.translationX = engine.motion.state.translationX
|
|
1488
|
+
host.translationY = engine.motion.state.translationY
|
|
1489
|
+
} else {
|
|
1490
|
+
host.translationX = 0f
|
|
1491
|
+
host.translationY = 0f
|
|
1492
|
+
}
|
|
1493
|
+
host.scaleX = interactionScale.first
|
|
1494
|
+
host.scaleY = interactionScale.second
|
|
1495
|
+
}
|
|
1496
|
+
onInteractionTransformUpdated?.invoke(
|
|
1497
|
+
host.translationX,
|
|
1498
|
+
host.translationY,
|
|
1499
|
+
host.scaleX,
|
|
1500
|
+
host.scaleY,
|
|
1501
|
+
)
|
|
1502
|
+
}
|
|
1503
|
+
|
|
1504
|
+
private fun hasReferenceButtonMotion(): Boolean =
|
|
1505
|
+
referenceInteractionProfile == REFERENCE_PROFILE_BUTTON &&
|
|
1506
|
+
useV3Engine &&
|
|
1507
|
+
com.newhu.liquidglass.rendering.GlassEngineSelection.supportsEngine(Build.VERSION.SDK_INT) &&
|
|
1508
|
+
engine.motion.hasInput
|
|
1509
|
+
|
|
1510
|
+
/** Matches the View graphics-layer transform in applyInteractionTransform(). */
|
|
1511
|
+
private fun interactionScale(): Pair<Float, Float> {
|
|
1512
|
+
if (referenceInteractionProfile in 1..3) {
|
|
1513
|
+
// Toggle/slider (pressedScale = 1.5) and tab lens (78/56) share the
|
|
1514
|
+
// native DampedDragAnimation / VelocityTracker deformation spring.
|
|
1515
|
+
// Reading it keeps both the View layer and the shader sample map in sync.
|
|
1516
|
+
if (useV3Engine &&
|
|
1517
|
+
com.newhu.liquidglass.rendering.GlassEngineSelection.supportsEngine(Build.VERSION.SDK_INT) &&
|
|
1518
|
+
engine.motion.hasInput
|
|
1519
|
+
) {
|
|
1520
|
+
return Pair(engine.motion.state.deformationScaleX, engine.motion.state.deformationScaleY)
|
|
1521
|
+
}
|
|
1522
|
+
val progress = maxOf(interactionProgress, pressAmount).coerceIn(0f, 1f)
|
|
1523
|
+
val maxScale = if (referenceInteractionProfile == 3) 78f / 56f else 1.5f
|
|
1524
|
+
val scale = 1f + (maxScale - 1f) * progress
|
|
1525
|
+
return Pair(scale, scale)
|
|
1526
|
+
}
|
|
1527
|
+
if (referenceInteractionProfile != 0) {
|
|
1528
|
+
val scale = 1f + 0.025f * pressAmount
|
|
1529
|
+
return Pair(scale, scale)
|
|
1530
|
+
}
|
|
1531
|
+
val width = host.width.toFloat().coerceAtLeast(1f)
|
|
1532
|
+
val height = host.height.toFloat().coerceAtLeast(1f)
|
|
1533
|
+
val maxDimension = maxOf(width, height)
|
|
1534
|
+
val pressScaleRatio = 4f / 48f
|
|
1535
|
+
val scale = 1f + pressScaleRatio * pressAmount
|
|
1536
|
+
val distance = sqrt(dragX * dragX + dragY * dragY)
|
|
1537
|
+
val angle = kotlin.math.atan2(dragY, dragX)
|
|
1538
|
+
val widthHeightCap = min(width / height, 1f)
|
|
1539
|
+
val heightWidthCap = min(height / width, 1f)
|
|
1540
|
+
return Pair(
|
|
1541
|
+
scale + pressScaleRatio * abs(kotlin.math.cos(angle) * distance / maxDimension) * widthHeightCap,
|
|
1542
|
+
scale + pressScaleRatio * abs(kotlin.math.sin(angle) * distance / maxDimension) * heightWidthCap,
|
|
1543
|
+
)
|
|
1544
|
+
}
|
|
1545
|
+
|
|
1546
|
+
private fun springValue(
|
|
1547
|
+
start: Float,
|
|
1548
|
+
startVelocity: Float,
|
|
1549
|
+
target: Float,
|
|
1550
|
+
elapsed: Float,
|
|
1551
|
+
damping: Float,
|
|
1552
|
+
): Pair<Float, Float> {
|
|
1553
|
+
val omega = sqrt(BUTTON_SPRING_STIFFNESS)
|
|
1554
|
+
val omegaD = omega * sqrt(1f - damping * damping)
|
|
1555
|
+
val decay = exp(-damping * omega * elapsed)
|
|
1556
|
+
val cosWd = cos(omegaD * elapsed)
|
|
1557
|
+
val sinWd = sin(omegaD * elapsed)
|
|
1558
|
+
val x0 = start - target
|
|
1559
|
+
val b0 = (startVelocity + damping * omega * x0) / omegaD
|
|
1560
|
+
val offset = x0 * decay * cosWd + b0 * decay * sinWd
|
|
1561
|
+
val velocity = -damping * omega * offset + decay * (-x0 * omegaD * sinWd + b0 * omegaD * cosWd)
|
|
1562
|
+
return Pair(target + offset, velocity)
|
|
1563
|
+
}
|
|
1564
|
+
|
|
1565
|
+
private companion object {
|
|
1566
|
+
const val REFERENCE_PROFILE_BUTTON = 4
|
|
1567
|
+
const val BUTTON_SPRING_STIFFNESS = 300f
|
|
1568
|
+
const val BUTTON_SPRING_DAMPING = 0.5f
|
|
1569
|
+
const val CONTROL_SPRING_STIFFNESS = 1000f
|
|
1570
|
+
const val SPRING_SETTLE_THRESHOLD = 0.003f
|
|
1571
|
+
}
|
|
1572
|
+
|
|
1573
|
+
private inline fun <T> invalidating(
|
|
1574
|
+
old: T,
|
|
1575
|
+
new: T,
|
|
1576
|
+
kind: GlassDirtyKind = GlassDirtyKind.MATERIAL_DIRTY,
|
|
1577
|
+
assign: (T) -> Unit,
|
|
1578
|
+
) {
|
|
1579
|
+
if (old != new) {
|
|
1580
|
+
assign(new)
|
|
1581
|
+
cachedV3Material = null
|
|
1582
|
+
when (kind) {
|
|
1583
|
+
GlassDirtyKind.SOURCE_CONTENT_DIRTY -> Unit
|
|
1584
|
+
GlassDirtyKind.CONSUMER_GEOMETRY_DIRTY -> reportConsumerDirty(GlassBackdropDirtyReason.CONSUMER_GEOMETRY)
|
|
1585
|
+
GlassDirtyKind.OPTICS_DIRTY -> reportConsumerDirty(GlassBackdropDirtyReason.OPTICS)
|
|
1586
|
+
GlassDirtyKind.MATERIAL_DIRTY -> reportConsumerDirty(GlassBackdropDirtyReason.MATERIAL)
|
|
1587
|
+
}
|
|
1588
|
+
host.invalidate()
|
|
1589
|
+
}
|
|
1590
|
+
}
|
|
1591
|
+
|
|
1592
|
+
private fun reportConsumerDirty(reason: GlassBackdropDirtyReason) {
|
|
1593
|
+
val backdrop = provider
|
|
1594
|
+
if (backdrop != null) {
|
|
1595
|
+
backdrop.onConsumerDirty(host, reason)
|
|
1596
|
+
return
|
|
1597
|
+
}
|
|
1598
|
+
when (reason) {
|
|
1599
|
+
GlassBackdropDirtyReason.CONSUMER_GEOMETRY -> LiquidGlassPerfTelemetry.consumerGeometryDirty()
|
|
1600
|
+
GlassBackdropDirtyReason.OPTICS -> LiquidGlassPerfTelemetry.opticsDirty()
|
|
1601
|
+
GlassBackdropDirtyReason.MATERIAL -> LiquidGlassPerfTelemetry.materialDirty()
|
|
1602
|
+
else -> Unit
|
|
1603
|
+
}
|
|
1604
|
+
}
|
|
1605
|
+
}
|