@luckylca/react-native-liquid-glass 0.2.0 → 0.3.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/README.md +20 -33
- package/README.zh-CN.md +20 -33
- package/THIRD_PARTY_NOTICES.md +1 -1
- package/android/build.gradle +4 -4
- package/android/src/main/java/expo/modules/{newhuliquidglass → liquidglass}/EffectiveScrollInputBridge.kt +2 -2
- package/android/src/main/java/expo/modules/{newhuliquidglass/ExpoGlassProviderCoreView.kt → liquidglass/GlassCaptureView.kt} +39 -39
- package/android/src/main/java/expo/modules/{newhuliquidglass/CoreLiquidGlassRegistry.kt → liquidglass/GlassRegistry.kt} +7 -7
- package/android/src/main/java/expo/modules/{newhuliquidglass/ExpoGlassSurfaceCoreView.kt → liquidglass/GlassSurfaceView.kt} +17 -17
- package/android/src/main/java/expo/modules/liquidglass/LiquidGlassModule.kt +205 -0
- package/android/src/main/java/expo/modules/{localglass/ExpoLocalGlassEngineModule.kt → liquidglass/LocalMaterialView.kt} +24 -27
- package/android/src/main/java/expo/modules/{newhuliquidglass → liquidglass}/PassSurfaceSuppression.kt +1 -1
- package/android/src/main/java/expo/modules/{newhuliquidglass → liquidglass}/SharedGlassPassProbeLog.kt +1 -1
- package/android/src/main/java/expo/modules/{newhuliquidglass → liquidglass}/SharedGlassPassWiring.kt +3 -3
- package/android-core/build.gradle +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/backdrop/BackdropRecorder.kt +4 -4
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/backdrop/FrozenBackdrop.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/backdrop/GlassBackdropCoordinator.kt +5 -5
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/backdrop/GlassBackdropSourceHandle.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/backdrop/GlassScrollSource.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/backdrop/GlassViewController.kt +119 -722
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/backdrop/LiquidGlassProviderLayout.kt +2 -2
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/backdrop/LiquidGlassView.kt +2 -2
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/backdrop/ReferenceSourceWindowPolicy.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/backdrop/StableSceneTexturePolicy.kt +1 -1
- package/android-core/src/main/java/io/github/luckylca/liquidglass/backdrop/SurfaceFrameBuilder.kt +278 -0
- package/android-core/src/main/java/io/github/luckylca/liquidglass/backdrop/SurfaceInteraction.kt +359 -0
- package/android-core/src/main/java/io/github/luckylca/liquidglass/backdrop/internal/GlassFrame.kt +110 -0
- package/android-core/src/main/java/io/github/luckylca/liquidglass/backdrop/internal/GlassViewRenderer.kt +728 -0
- package/android-core/src/main/java/io/github/luckylca/liquidglass/backdrop/internal/ReferenceParityPasses.kt +705 -0
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/backdrop/internal/ReferenceTabSampling.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/backdrop/internal/SharedSceneCapture.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/core/GlassCapabilities.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/core/GlassEngine.kt +7 -7
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/core/GlassMaterial.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/core/GlassMath.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/core/GlassOpticalInsets.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/core/GlassRenderTier.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/core/GlassShapePacker.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/core/GlassSurfaceState.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/core/GlassUniforms.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/core/LiquidGlassShaders.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/core/SharedGlassPass.kt +6 -6
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/core/geometry/G2RoundedRectangle.kt +2 -2
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/core/geometry/ReferenceG2MaskTexture.kt +1 -1
- package/android-core/src/main/java/io/github/luckylca/liquidglass/core/shader/HeightFieldGlassShader.kt +7 -0
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/core/shader/ReferenceBackdropBlurShader.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/core/shader/ReferenceGaussianDiscBackdropBlur.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/core/shader/ReferenceGlassUniforms.kt +4 -4
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/core/shader/ReferenceParityGlassShader.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/core/shader/ReferenceParityMultiShapeShader.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/core/shader/SdfScaleLensShader.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/local/LocalGlassHardwareLayerExperiment.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/local/LocalGlassMaterial.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/local/LocalGlassRenderer.kt +2 -2
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/local/LocalGlassRuntimeShader.kt +2 -2
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/local/LocalGlassShader.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/local/LocalGlassView.kt +2 -2
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/motion/GlassMotionDriver.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/motion/GlassMotionState.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/motion/PointerVelocityTracker.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/motion/SpringSpec.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/optics/G2Corner.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/optics/GlassMaterial.kt +3 -3
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/optics/GlassOpticsShader.kt +3 -3
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/optics/GlassParityProbe.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/optics/GlassShapeGeometry.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/optics/GlassUniformBinder.kt +2 -2
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/optics/PixelDiff.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/optics/ReferenceOptics.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/rendering/GlassSurfaceHost.kt +17 -17
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/rendering/GlassSurfaceRenderer.kt +9 -9
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/rendering/RetainedBackdropLayer.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/scheduler/GlassFrameScheduler.kt +2 -2
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/telemetry/EffectiveScrollFpsProbe.kt +13 -13
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/telemetry/GlassTelemetry.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/telemetry/LiquidGlassPerfTelemetry.kt +13 -13
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/telemetry/LiquidGlassTrace.kt +3 -3
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/telemetry/LocalGlassTelemetry.kt +1 -1
- package/docs/architecture.md +61 -0
- package/docs/migration-0.3.md +19 -0
- package/docs/publishing.md +29 -7
- package/expo-module.config.json +4 -4
- package/lib/commonjs/GlassSurface.js +157 -585
- package/lib/commonjs/GlassSurface.js.map +1 -1
- package/lib/commonjs/GlassTabBar.js +18 -957
- package/lib/commonjs/GlassTabBar.js.map +1 -1
- package/lib/commonjs/LocalGlassMaterial.js +3 -9
- package/lib/commonjs/LocalGlassMaterial.js.map +1 -1
- package/lib/commonjs/glassController.js +3 -7
- package/lib/commonjs/glassController.js.map +1 -1
- package/lib/commonjs/glassRuntime.js +7 -19
- package/lib/commonjs/glassRuntime.js.map +1 -1
- package/lib/commonjs/localGlassTelemetry.js +4 -13
- package/lib/commonjs/localGlassTelemetry.js.map +1 -1
- package/lib/commonjs/nativeGlassViews.js +8 -11
- package/lib/commonjs/nativeGlassViews.js.map +1 -1
- package/lib/commonjs/performanceTelemetry.js +2 -6
- package/lib/commonjs/performanceTelemetry.js.map +1 -1
- package/lib/commonjs/surface/InlineSurface.js +134 -0
- package/lib/commonjs/surface/InlineSurface.js.map +1 -0
- package/lib/commonjs/surface/MaterialProvider.js +78 -0
- package/lib/commonjs/surface/MaterialProvider.js.map +1 -0
- package/lib/commonjs/surface/NativeSurface.js +55 -0
- package/lib/commonjs/surface/NativeSurface.js.map +1 -0
- package/lib/commonjs/surface/PortalLayers.js +331 -0
- package/lib/commonjs/surface/PortalLayers.js.map +1 -0
- package/lib/commonjs/surface/contexts.js +108 -0
- package/lib/commonjs/surface/contexts.js.map +1 -0
- package/lib/commonjs/surface/registry.js +113 -0
- package/lib/commonjs/surface/registry.js.map +1 -0
- package/lib/commonjs/surface/styles.js +34 -0
- package/lib/commonjs/surface/styles.js.map +1 -0
- package/lib/commonjs/surface/types.js +3 -0
- package/lib/commonjs/surface/types.js.map +1 -0
- package/lib/commonjs/tabs/GlassTabItem.js +66 -0
- package/lib/commonjs/tabs/GlassTabItem.js.map +1 -0
- package/lib/commonjs/tabs/InlineTabBar.js +867 -0
- package/lib/commonjs/tabs/InlineTabBar.js.map +1 -0
- package/lib/commonjs/tabs/tabConstants.js +22 -0
- package/lib/commonjs/tabs/tabConstants.js.map +1 -0
- package/lib/commonjs/tabs/tabDebug.js +50 -0
- package/lib/commonjs/tabs/tabDebug.js.map +1 -0
- package/lib/commonjs/tabs/tabStyles.js +107 -0
- package/lib/commonjs/tabs/tabStyles.js.map +1 -0
- package/lib/commonjs/tabs/useInlineTabGesture.js +227 -0
- package/lib/commonjs/tabs/useInlineTabGesture.js.map +1 -0
- package/lib/commonjs/theme/buildTheme.js +1 -1
- package/lib/commonjs/theme/buildTheme.js.map +1 -1
- package/lib/module/GlassSurface.js +135 -563
- package/lib/module/GlassSurface.js.map +1 -1
- package/lib/module/GlassTabBar.js +18 -925
- package/lib/module/GlassTabBar.js.map +1 -1
- package/lib/module/LocalGlassMaterial.js +5 -11
- package/lib/module/LocalGlassMaterial.js.map +1 -1
- package/lib/module/glassController.js +3 -7
- package/lib/module/glassController.js.map +1 -1
- package/lib/module/glassRuntime.js +7 -19
- package/lib/module/glassRuntime.js.map +1 -1
- package/lib/module/localGlassTelemetry.js +4 -13
- package/lib/module/localGlassTelemetry.js.map +1 -1
- package/lib/module/nativeGlassViews.js +7 -10
- package/lib/module/nativeGlassViews.js.map +1 -1
- package/lib/module/performanceTelemetry.js +2 -6
- package/lib/module/performanceTelemetry.js.map +1 -1
- package/lib/module/surface/InlineSurface.js +97 -0
- package/lib/module/surface/InlineSurface.js.map +1 -0
- package/lib/module/surface/MaterialProvider.js +74 -0
- package/lib/module/surface/MaterialProvider.js.map +1 -0
- package/lib/module/surface/NativeSurface.js +47 -0
- package/lib/module/surface/NativeSurface.js.map +1 -0
- package/lib/module/surface/PortalLayers.js +292 -0
- package/lib/module/surface/PortalLayers.js.map +1 -0
- package/lib/module/surface/contexts.js +96 -0
- package/lib/module/surface/contexts.js.map +1 -0
- package/lib/module/surface/registry.js +103 -0
- package/lib/module/surface/registry.js.map +1 -0
- package/lib/module/surface/styles.js +31 -0
- package/lib/module/surface/styles.js.map +1 -0
- package/lib/module/surface/types.js +2 -0
- package/lib/module/surface/types.js.map +1 -0
- package/lib/module/tabs/GlassTabItem.js +30 -0
- package/lib/module/tabs/GlassTabItem.js.map +1 -0
- package/lib/module/tabs/InlineTabBar.js +829 -0
- package/lib/module/tabs/InlineTabBar.js.map +1 -0
- package/lib/module/tabs/tabConstants.js +19 -0
- package/lib/module/tabs/tabConstants.js.map +1 -0
- package/lib/module/tabs/tabDebug.js +13 -0
- package/lib/module/tabs/tabDebug.js.map +1 -0
- package/lib/module/tabs/tabStyles.js +104 -0
- package/lib/module/tabs/tabStyles.js.map +1 -0
- package/lib/module/tabs/useInlineTabGesture.js +221 -0
- package/lib/module/tabs/useInlineTabGesture.js.map +1 -0
- package/lib/module/theme/buildTheme.js +1 -1
- package/lib/module/theme/buildTheme.js.map +1 -1
- package/lib/types/GlassSurface.d.ts +17 -86
- package/lib/types/GlassTabBar.d.ts +1 -0
- package/lib/types/glassNativeEngine.d.ts +1 -1
- package/lib/types/glassRuntime.d.ts +5 -2
- package/lib/types/localGlassTelemetry.d.ts +2 -2
- package/lib/types/nativeGlassViews.d.ts +2 -4
- package/lib/types/surface/InlineSurface.d.ts +42 -0
- package/lib/types/surface/MaterialProvider.d.ts +46 -0
- package/lib/types/surface/NativeSurface.d.ts +11 -0
- package/lib/types/surface/PortalLayers.d.ts +33 -0
- package/lib/types/surface/contexts.d.ts +66 -0
- package/lib/types/surface/registry.d.ts +6 -0
- package/lib/types/surface/styles.d.ts +74 -0
- package/lib/types/surface/types.d.ts +118 -0
- package/lib/types/tabs/GlassTabItem.d.ts +20 -0
- package/lib/types/tabs/InlineTabBar.d.ts +5 -0
- package/lib/types/tabs/tabConstants.d.ts +34 -0
- package/lib/types/tabs/tabDebug.d.ts +15 -0
- package/lib/types/tabs/tabStyles.d.ts +119 -0
- package/lib/types/tabs/useInlineTabGesture.d.ts +34 -0
- package/package.json +6 -14
- package/src/GlassSurface.tsx +227 -1337
- package/src/GlassTabBar.tsx +43 -1241
- package/src/LocalGlassMaterial.tsx +5 -11
- package/src/glassController.ts +3 -7
- package/src/glassRuntime.ts +9 -26
- package/src/localGlassTelemetry.ts +6 -15
- package/src/nativeGlassViews.ts +7 -10
- package/src/performanceTelemetry.ts +2 -6
- package/src/surface/InlineSurface.tsx +299 -0
- package/src/surface/MaterialProvider.tsx +235 -0
- package/src/surface/NativeSurface.tsx +115 -0
- package/src/surface/PortalLayers.tsx +574 -0
- package/src/surface/contexts.tsx +188 -0
- package/src/surface/registry.ts +109 -0
- package/src/surface/styles.ts +31 -0
- package/src/surface/types.ts +139 -0
- package/src/tabs/GlassTabItem.tsx +100 -0
- package/src/tabs/InlineTabBar.tsx +1193 -0
- package/src/tabs/tabConstants.ts +35 -0
- package/src/tabs/tabDebug.ts +29 -0
- package/src/tabs/tabStyles.ts +104 -0
- package/src/tabs/useInlineTabGesture.ts +306 -0
- package/src/theme/buildTheme.ts +1 -1
- package/android/src/main/java/expo/modules/localglass/ExpoLocalGlassModule.kt +0 -341
- package/android/src/main/java/expo/modules/localglass/LocalGlassShader.kt +0 -59
- package/android/src/main/java/expo/modules/newhuliquidglass/ExpoGlassCoreModule.kt +0 -226
- package/android-core/src/main/java/com/newhu/liquidglass/backdrop/internal/GlassViewRenderer.kt +0 -1459
- package/android-core/src/main/java/com/newhu/liquidglass/core/shader/HeightFieldGlassShader.kt +0 -7
- package/android-core/src/main/java/com/newhu/liquidglass/rendering/GlassEngineSelection.kt +0 -30
- package/patches/liquid-glass-kit+1.0.0.patch +0 -2015
- package/patches/liquid-glass-kit-invalidation-coalescing.diff +0 -249
- package/patches/liquid-glass-kit-native-infra.diff +0 -624
- package/scripts/apply-legacy-patches.mjs +0 -116
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
package
|
|
1
|
+
package io.github.luckylca.liquidglass.backdrop
|
|
2
2
|
|
|
3
3
|
import android.graphics.Canvas
|
|
4
4
|
import android.graphics.Color
|
|
@@ -8,13 +8,13 @@ import android.os.Build
|
|
|
8
8
|
import android.view.MotionEvent
|
|
9
9
|
import android.view.View
|
|
10
10
|
import androidx.annotation.ColorInt
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import
|
|
17
|
-
import
|
|
11
|
+
import io.github.luckylca.liquidglass.core.GlassRenderTier
|
|
12
|
+
import io.github.luckylca.liquidglass.core.GlassOpticsModel
|
|
13
|
+
import io.github.luckylca.liquidglass.core.SdfScaleLensConfig
|
|
14
|
+
import io.github.luckylca.liquidglass.backdrop.internal.GlassFrame
|
|
15
|
+
import io.github.luckylca.liquidglass.backdrop.internal.GlassViewRenderer
|
|
16
|
+
import io.github.luckylca.liquidglass.telemetry.LiquidGlassPerfTelemetry
|
|
17
|
+
import io.github.luckylca.liquidglass.telemetry.LiquidGlassTrace
|
|
18
18
|
import kotlin.math.abs
|
|
19
19
|
import kotlin.math.cos
|
|
20
20
|
import kotlin.math.exp
|
|
@@ -32,7 +32,7 @@ internal enum class GlassDirtyKind {
|
|
|
32
32
|
/** Sentinel corner radius: fully rounded capsule/circle. */
|
|
33
33
|
public const val CORNER_RADIUS_CAPSULE: Float = -1f
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
internal const val DEFAULT_SCRIM_COLOR = 0x59FFFFFF.toInt() // white @ 35%
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
38
|
* The embeddable Liquid Glass engine for the View system.
|
|
@@ -54,41 +54,26 @@ private const val DEFAULT_SCRIM_COLOR = 0x59FFFFFF.toInt() // white @ 35%
|
|
|
54
54
|
* artifact: full AGSL refraction on API 33+, frosted blur on 31–32, clipped
|
|
55
55
|
* backdrop + scrim on 29–30, plain scrim + rim everywhere else.
|
|
56
56
|
*/
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
internal val passSampleAuditDone = java.util.Collections.synchronizedSet(HashSet<Int>())
|
|
58
|
+
internal var passSampleAuditTick = 0
|
|
59
|
+
internal const val PASS_SAMPLE_AUDIT = false
|
|
60
60
|
|
|
61
|
-
public class GlassViewController(
|
|
61
|
+
public class GlassViewController(internal val host: View) {
|
|
62
62
|
|
|
63
|
-
|
|
63
|
+
internal val renderer = GlassViewRenderer()
|
|
64
64
|
|
|
65
|
-
/**
|
|
66
|
-
|
|
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
|
|
65
|
+
/** Native motion state, exposed for renderer instrumentation. */
|
|
66
|
+
public fun engineHostForInstrumentation(): io.github.luckylca.liquidglass.rendering.GlassSurfaceHost = engine
|
|
82
67
|
|
|
83
|
-
|
|
84
|
-
|
|
68
|
+
internal val engine by lazy {
|
|
69
|
+
io.github.luckylca.liquidglass.rendering.GlassSurfaceHost(host.resources.displayMetrics.density).also { engineHost ->
|
|
85
70
|
// Each spring step must paint. Invalidate is a coalesced request on the
|
|
86
71
|
// view, so several steps inside one frame still cost one traversal.
|
|
87
72
|
engineHost.onMotionFrame = {
|
|
88
73
|
val motionKind = engineHost.motion.kindOf()
|
|
89
|
-
val travelling = motionKind ==
|
|
90
|
-
motionKind ==
|
|
91
|
-
motionKind ==
|
|
74
|
+
val travelling = motionKind == io.github.luckylca.liquidglass.motion.GlassInteractionKind.TOGGLE_KNOB ||
|
|
75
|
+
motionKind == io.github.luckylca.liquidglass.motion.GlassInteractionKind.SLIDER_KNOB ||
|
|
76
|
+
motionKind == io.github.luckylca.liquidglass.motion.GlassInteractionKind.TAB_LENS
|
|
92
77
|
if (referenceInteractionProfile == REFERENCE_PROFILE_BUTTON || travelling) {
|
|
93
78
|
applyInteractionTransform()
|
|
94
79
|
}
|
|
@@ -97,50 +82,43 @@ public class GlassViewController(private val host: View) {
|
|
|
97
82
|
}
|
|
98
83
|
}
|
|
99
84
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
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 {
|
|
85
|
+
internal val supportsNativeOptics: Boolean get() = Build.VERSION.SDK_INT >= 33
|
|
86
|
+
internal val locationSelf = IntArray(2)
|
|
87
|
+
internal val locationProvider = IntArray(2)
|
|
88
|
+
internal val relativePosition = FloatArray(2)
|
|
89
|
+
internal val parentToWindow = Matrix()
|
|
90
|
+
internal val layoutOriginInWindow = FloatArray(2)
|
|
91
|
+
internal val frame = GlassFrame()
|
|
92
|
+
internal var pressAmount = 0f
|
|
93
|
+
internal var pressX = 0f
|
|
94
|
+
internal var pressY = 0f
|
|
95
|
+
internal var forwardedPointerX = 0f
|
|
96
|
+
internal var forwardedPointerY = 0f
|
|
97
|
+
internal var interactionPointXDp = 0f
|
|
98
|
+
internal var interactionPointYDp = 0f
|
|
99
|
+
internal var pointerVelocityXDpPerSecond = 0f
|
|
100
|
+
internal var pointerVelocityYDpPerSecond = 0f
|
|
101
|
+
internal var externalButtonProgress = 0f
|
|
102
|
+
internal var pressVelocity = 0f
|
|
103
|
+
internal var pressTarget = 0f
|
|
104
|
+
internal var pressStartedAtNanos = 0L
|
|
105
|
+
internal var pressStartValue = 0f
|
|
106
|
+
internal var pressStartVelocity = 0f
|
|
107
|
+
internal var pointerDown = false
|
|
108
|
+
internal var dragStartX = 0f
|
|
109
|
+
internal var dragStartY = 0f
|
|
110
|
+
internal var dragX = 0f
|
|
111
|
+
internal var dragY = 0f
|
|
112
|
+
internal var dragTargetX = 0f
|
|
113
|
+
internal var dragTargetY = 0f
|
|
114
|
+
internal var dragStartValueX = 0f
|
|
115
|
+
internal var dragStartValueY = 0f
|
|
116
|
+
internal var dragStartVelocityX = 0f
|
|
117
|
+
internal var dragStartVelocityY = 0f
|
|
118
|
+
internal var dragVelocityX = 0f
|
|
119
|
+
internal var dragVelocityY = 0f
|
|
120
|
+
internal var externalPressAwaitingPointerBaseline = false
|
|
121
|
+
internal val pressAnimationFrame = object : Runnable {
|
|
144
122
|
override fun run() {
|
|
145
123
|
val stillAnimating = advancePressAnimation(System.nanoTime())
|
|
146
124
|
applyInteractionTransform()
|
|
@@ -155,19 +133,19 @@ public class GlassViewController(private val host: View) {
|
|
|
155
133
|
* progress-first delivery cannot turn the pointer's initial position into
|
|
156
134
|
* a synthetic drag.
|
|
157
135
|
*/
|
|
158
|
-
|
|
136
|
+
internal val externalPressPointerBaselineFrame = Runnable {
|
|
159
137
|
if (!externalPressAwaitingPointerBaseline || !pointerDown || referenceInteractionProfile != 0) return@Runnable
|
|
160
138
|
captureExternalPressPointerBaseline()
|
|
161
139
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
140
|
+
internal var previousRelativeX: Float? = null
|
|
141
|
+
internal var previousRelativeY: Float? = null
|
|
142
|
+
internal var previousMotionAtNanos = 0L
|
|
143
|
+
internal var referenceSampleAuditLogged = false
|
|
144
|
+
internal var cachedOpticalMaterial: io.github.luckylca.liquidglass.optics.GlassMaterial? = null
|
|
145
|
+
internal var derivedMotionX = 0f
|
|
146
|
+
internal var derivedMotionY = 0f
|
|
147
|
+
internal var explicitMotionX: Float? = null
|
|
148
|
+
internal var explicitMotionY: Float? = null
|
|
171
149
|
/** Called whenever the surface transform changes for interaction deformation. */
|
|
172
150
|
public var onInteractionTransformUpdated: ((Float, Float, Float, Float) -> Unit)? = null
|
|
173
151
|
|
|
@@ -221,7 +199,7 @@ public class GlassViewController(private val host: View) {
|
|
|
221
199
|
* Sample the provider's single shared recording instead of a per-consumer
|
|
222
200
|
* crop. Region crops are re-recorded whenever a consumer moves, so a scrolling
|
|
223
201
|
* page pays one recording per visible surface per frame; the shared recording
|
|
224
|
-
* is reused.
|
|
202
|
+
* is reused. Enabled explicitly by diagnostic capture probes.
|
|
225
203
|
*/
|
|
226
204
|
public var sharedSourceSampling: Boolean = false
|
|
227
205
|
|
|
@@ -231,8 +209,8 @@ public class GlassViewController(private val host: View) {
|
|
|
231
209
|
* sampling path is rebuilt around it.
|
|
232
210
|
*/
|
|
233
211
|
public var sharedSceneCaptureProbe: Boolean = false
|
|
234
|
-
|
|
235
|
-
|
|
212
|
+
internal var captureProbe: io.github.luckylca.liquidglass.backdrop.internal.SharedSceneCapture? = null
|
|
213
|
+
internal var captureProbeBucket: Long = -1L
|
|
236
214
|
set(value) = invalidating(field, value, GlassDirtyKind.OPTICS_DIRTY) { field = it }
|
|
237
215
|
|
|
238
216
|
/** Full-body rounded-rect coordinate remapping in dp, separate from the rim bend. */
|
|
@@ -257,10 +235,10 @@ public class GlassViewController(private val host: View) {
|
|
|
257
235
|
// press-in/press-out and feeds velocity separately; the engine runs its
|
|
258
236
|
// own spring from the same touch. Letting both write the animated value
|
|
259
237
|
// is the old chain's defining defect — two systems fighting for one
|
|
260
|
-
// number, which reads as a doubled, stuttering response. When
|
|
238
|
+
// number, which reads as a doubled, stuttering response. When the native driver is
|
|
261
239
|
// drawing it owns the animation, so the JS value is recorded but does not
|
|
262
240
|
// command a second spring.
|
|
263
|
-
if (
|
|
241
|
+
if (supportsNativeOptics && (Build.VERSION.SDK_INT >= 33)) {
|
|
264
242
|
field = next
|
|
265
243
|
return
|
|
266
244
|
}
|
|
@@ -347,13 +325,13 @@ public class GlassViewController(private val host: View) {
|
|
|
347
325
|
public var referenceHighlightColor: Int = Color.WHITE
|
|
348
326
|
set(value) = invalidating(field, value, GlassDirtyKind.MATERIAL_DIRTY) { field = it }
|
|
349
327
|
|
|
350
|
-
/** 0=
|
|
328
|
+
/** 0=default, 1=toggle, 2=slider, 3=tab, 4=reference button. */
|
|
351
329
|
public var referenceInteractionProfile: Int = 0
|
|
352
330
|
set(value) {
|
|
353
331
|
val next = value.coerceIn(0, 4)
|
|
354
332
|
if (field == next) return
|
|
355
333
|
field = next
|
|
356
|
-
|
|
334
|
+
cachedOpticalMaterial = null
|
|
357
335
|
resetNativePress()
|
|
358
336
|
reportConsumerDirty(GlassBackdropDirtyReason.MATERIAL)
|
|
359
337
|
host.invalidate()
|
|
@@ -440,12 +418,12 @@ public class GlassViewController(private val host: View) {
|
|
|
440
418
|
/**
|
|
441
419
|
* Touch forwarded from the JS source: phase (0 down, 1 move, 2 up, 3 cancel)
|
|
442
420
|
* and the pointer position in this view's px. See
|
|
443
|
-
* [
|
|
421
|
+
* [io.github.luckylca.liquidglass.motion.GlassMotionDriver.applyPointerEvent] for why the
|
|
444
422
|
* event, and not a progress value, crosses the bridge.
|
|
445
423
|
*/
|
|
446
424
|
public fun forwardPointer(phase: Int, x: Float, y: Float, eventTimeMillis: Long) {
|
|
447
|
-
if (!
|
|
448
|
-
if (!
|
|
425
|
+
if (!supportsNativeOptics) return
|
|
426
|
+
if (!(Build.VERSION.SDK_INT >= 33)) return
|
|
449
427
|
forwardedPointerX = x
|
|
450
428
|
forwardedPointerY = y
|
|
451
429
|
engine.motion.applyPointerEvent(phase, x, y, eventTimeMillis)
|
|
@@ -461,13 +439,13 @@ public class GlassViewController(private val host: View) {
|
|
|
461
439
|
* and the renderer reads the result, which keeps the value's motion in the same
|
|
462
440
|
* integrator as the press and the shear.
|
|
463
441
|
*/
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
442
|
+
internal var pendingValueTravel = 0f
|
|
443
|
+
internal var pendingValueTrackLength = 0f
|
|
444
|
+
internal var pendingValueAnimate = true
|
|
445
|
+
internal var pendingValueKeepPressed = false
|
|
446
|
+
internal var pendingValueVelocity = 0f
|
|
447
|
+
internal var pendingValueDirty = false
|
|
448
|
+
internal var pendingValueSnap = false
|
|
471
449
|
|
|
472
450
|
/**
|
|
473
451
|
* Applies the last value the control reported, if a driver can take it yet.
|
|
@@ -476,10 +454,10 @@ public class GlassViewController(private val host: View) {
|
|
|
476
454
|
* controlled slider publishes its value during layout, which happens before the
|
|
477
455
|
* first draw installs the material that creates the driver.
|
|
478
456
|
*/
|
|
479
|
-
|
|
457
|
+
internal fun applyPendingValue() {
|
|
480
458
|
if (!pendingValueDirty) return
|
|
481
459
|
val motion = engine.motion
|
|
482
|
-
if (motion.kindOf() ==
|
|
460
|
+
if (motion.kindOf() == io.github.luckylca.liquidglass.motion.GlassInteractionKind.STATIC) return
|
|
483
461
|
pendingValueDirty = false
|
|
484
462
|
when {
|
|
485
463
|
pendingValueSnap -> motion.snapValueTravel(pendingValueTravel, pendingValueTrackLength)
|
|
@@ -506,13 +484,13 @@ public class GlassViewController(private val host: View) {
|
|
|
506
484
|
keepPressed: Boolean = false,
|
|
507
485
|
snap: Boolean = false,
|
|
508
486
|
) {
|
|
509
|
-
if (!
|
|
510
|
-
if (!
|
|
487
|
+
if (!supportsNativeOptics) return
|
|
488
|
+
if (!(Build.VERSION.SDK_INT >= 33)) return
|
|
511
489
|
// Recorded unconditionally. A prop can arrive before the first draw has
|
|
512
490
|
// installed the material, and the material is what gives the host a driver of
|
|
513
491
|
// the right kind; applying the value to a STATIC driver would be dropped and
|
|
514
492
|
// the control would open at rest and never correct itself. The pending value is
|
|
515
|
-
// replayed by
|
|
493
|
+
// replayed by drawNativeOptics once a driver for a travelling kind exists.
|
|
516
494
|
pendingValueTravel = travel
|
|
517
495
|
pendingValueTrackLength = trackLength
|
|
518
496
|
pendingValueAnimate = animate
|
|
@@ -567,43 +545,15 @@ public class GlassViewController(private val host: View) {
|
|
|
567
545
|
engine.release()
|
|
568
546
|
}
|
|
569
547
|
|
|
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
548
|
/** Observes (never consumes) touch for the gel press response. */
|
|
599
549
|
public fun handleTouch(event: MotionEvent) {
|
|
600
550
|
if (!isGlassInteractive) return
|
|
601
|
-
// The
|
|
551
|
+
// The native driver owns the motion on supported devices. Letting both run was the
|
|
602
552
|
// defect the previous chain had: the JS layer set its progress instantly while
|
|
603
553
|
// this controller ran its own spring, so two systems fought for the same
|
|
604
554
|
// value and the surface visibly doubled its response. Only one may own it.
|
|
605
|
-
if (
|
|
606
|
-
if (
|
|
555
|
+
if (supportsNativeOptics && (Build.VERSION.SDK_INT >= 33)) {
|
|
556
|
+
if (handleNativeTouch(event)) return
|
|
607
557
|
}
|
|
608
558
|
when (event.actionMasked) {
|
|
609
559
|
MotionEvent.ACTION_DOWN -> {
|
|
@@ -649,12 +599,12 @@ public class GlassViewController(private val host: View) {
|
|
|
649
599
|
}
|
|
650
600
|
|
|
651
601
|
/**
|
|
652
|
-
*
|
|
602
|
+
* Forwards a touch to the native motion driver.
|
|
653
603
|
*
|
|
654
604
|
* Returns false when the engine cannot run, so the caller falls through to the
|
|
655
605
|
* compatibility path rather than the surface going inert.
|
|
656
606
|
*/
|
|
657
|
-
|
|
607
|
+
internal fun handleNativeTouch(event: MotionEvent): Boolean {
|
|
658
608
|
val driver = engine.motion
|
|
659
609
|
when (event.actionMasked) {
|
|
660
610
|
MotionEvent.ACTION_DOWN -> {
|
|
@@ -673,77 +623,10 @@ public class GlassViewController(private val host: View) {
|
|
|
673
623
|
return true
|
|
674
624
|
}
|
|
675
625
|
|
|
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
626
|
/** Draws the glass into [canvas]; call before the host's children draw. */
|
|
744
627
|
/** Packs this surface's reference parameters for the shared multi-shape pass. */
|
|
745
|
-
|
|
746
|
-
|
|
628
|
+
internal val sharedPassSnapshot = FloatArray(io.github.luckylca.liquidglass.core.SharedGlassPass.VALUE_COUNT)
|
|
629
|
+
internal var sharedPassSnapshotReady = false
|
|
747
630
|
|
|
748
631
|
/**
|
|
749
632
|
* Recomputes this surface's shared-pass parameters without drawing anything.
|
|
@@ -753,11 +636,11 @@ public class GlassViewController(private val host: View) {
|
|
|
753
636
|
* nothing and the page falls back to per-surface rendering for good.
|
|
754
637
|
*/
|
|
755
638
|
fun refreshSharedPassSnapshot() {
|
|
756
|
-
if (!
|
|
639
|
+
if (!io.github.luckylca.liquidglass.core.SharedGlassPass.ENABLED) return
|
|
757
640
|
if (host.width <= 0 || host.height <= 0) return
|
|
758
641
|
val built = buildFrame()
|
|
759
642
|
if (built.widthPx <= 0f || built.heightPx <= 0f) return
|
|
760
|
-
|
|
643
|
+
io.github.luckylca.liquidglass.core.shader.ReferenceGlassUniforms.fill(
|
|
761
644
|
built,
|
|
762
645
|
renderer.opticalInsets(built),
|
|
763
646
|
sharedPassSnapshot,
|
|
@@ -772,11 +655,11 @@ public class GlassViewController(private val host: View) {
|
|
|
772
655
|
}
|
|
773
656
|
val frame = renderer.lastFrame ?: return false
|
|
774
657
|
val insets = renderer.lastInsets ?: return false
|
|
775
|
-
|
|
658
|
+
io.github.luckylca.liquidglass.core.shader.ReferenceGlassUniforms.fill(frame, insets, out)
|
|
776
659
|
return true
|
|
777
660
|
}
|
|
778
661
|
|
|
779
|
-
internal fun sharedPassFrame(): Pair<GlassFrame,
|
|
662
|
+
internal fun sharedPassFrame(): Pair<GlassFrame, io.github.luckylca.liquidglass.core.GlassOpticalInsets>? {
|
|
780
663
|
val frame = renderer.lastFrame ?: return null
|
|
781
664
|
val insets = renderer.lastInsets ?: return null
|
|
782
665
|
return frame to insets
|
|
@@ -793,7 +676,7 @@ public class GlassViewController(private val host: View) {
|
|
|
793
676
|
" scene=${provider?.contentRenderNode?.width}x${provider?.contentRenderNode?.height}" +
|
|
794
677
|
" region=${provider?.renderNodeFor(host)?.width}x${provider?.renderNodeFor(host)?.height}" +
|
|
795
678
|
" origin=${provider?.recordedOriginXFor(host)},${provider?.recordedOriginYFor(host)}" +
|
|
796
|
-
" pass=${
|
|
679
|
+
" pass=${io.github.luckylca.liquidglass.core.SharedGlassPass.ENABLED}",
|
|
797
680
|
)
|
|
798
681
|
}
|
|
799
682
|
LiquidGlassPerfTelemetry.consumerDraw()
|
|
@@ -896,13 +779,13 @@ public class GlassViewController(private val host: View) {
|
|
|
896
779
|
}
|
|
897
780
|
}
|
|
898
781
|
|
|
899
|
-
|
|
782
|
+
io.github.luckylca.liquidglass.backdrop.internal.ReferenceTabSampling.rebase(frame)
|
|
900
783
|
|
|
901
784
|
if (sharedSceneCaptureProbe && Build.VERSION.SDK_INT >= 29 && providerNode != null) {
|
|
902
785
|
val bucket = System.nanoTime() / 8_000_000L
|
|
903
786
|
if (bucket != captureProbeBucket) {
|
|
904
787
|
captureProbeBucket = bucket
|
|
905
|
-
val probe = captureProbe ?:
|
|
788
|
+
val probe = captureProbe ?: io.github.luckylca.liquidglass.backdrop.internal.SharedSceneCapture("probe", scale = 3)
|
|
906
789
|
.also {
|
|
907
790
|
captureProbe = it
|
|
908
791
|
android.util.Log.i("LiquidGlassCapture", "probe created, node=${providerNode.width}x${providerNode.height}")
|
|
@@ -921,11 +804,11 @@ public class GlassViewController(private val host: View) {
|
|
|
921
804
|
backdrop?.hasRecording == true && providerNode != null
|
|
922
805
|
if (canSample) LiquidGlassPerfTelemetry.backdropSample()
|
|
923
806
|
|
|
924
|
-
// The
|
|
807
|
+
// The native optical path returns false when it cannot run — an
|
|
925
808
|
// API level below 33, a shader that failed to link, or no scene to sample
|
|
926
809
|
// — and the older tiers below it stay as the compatibility path so a
|
|
927
810
|
// device that cannot run AGSL still shows a plausible surface.
|
|
928
|
-
if (canSample &&
|
|
811
|
+
if (canSample && supportsNativeOptics && drawNativeOptics(canvas, providerNode!!, frame, sceneRevision, sceneShader)) {
|
|
929
812
|
return
|
|
930
813
|
}
|
|
931
814
|
|
|
@@ -942,7 +825,7 @@ public class GlassViewController(private val host: View) {
|
|
|
942
825
|
}
|
|
943
826
|
|
|
944
827
|
/**
|
|
945
|
-
* Draws through the
|
|
828
|
+
* Draws through the native optical core.
|
|
946
829
|
*
|
|
947
830
|
* The controller still owns the coordinate story: it resolves where the
|
|
948
831
|
* recorded scene's origin sits relative to this surface and hands that to the
|
|
@@ -950,7 +833,7 @@ public class GlassViewController(private val host: View) {
|
|
|
950
833
|
* recorded-origin/scroll-offset conversions stay in one place instead of being
|
|
951
834
|
* re-derived in two.
|
|
952
835
|
*/
|
|
953
|
-
|
|
836
|
+
internal fun drawNativeOptics(
|
|
954
837
|
canvas: Canvas,
|
|
955
838
|
providerNode: RenderNode,
|
|
956
839
|
frame: GlassFrame,
|
|
@@ -962,18 +845,18 @@ public class GlassViewController(private val host: View) {
|
|
|
962
845
|
// shader path below; letting the core claim this frame silently paints
|
|
963
846
|
// the enclosing rectangle instead of the glyph silhouette.
|
|
964
847
|
if (frame.shapeMaskText != null || frame.progressiveBlurIntensity > 0.001f) return false
|
|
965
|
-
if (!
|
|
848
|
+
if (!(Build.VERSION.SDK_INT >= 33)) {
|
|
966
849
|
return false
|
|
967
850
|
}
|
|
968
851
|
val density = frame.densityScale.coerceAtLeast(0.01f)
|
|
969
852
|
engine.setSize(frame.widthPx, frame.heightPx)
|
|
970
853
|
val effectiveRadiusDp = if (cornerRadiusDp < 0f) {
|
|
971
|
-
|
|
854
|
+
io.github.luckylca.liquidglass.optics.GlassMaterial.RADIUS_CAPSULE
|
|
972
855
|
} else {
|
|
973
856
|
cornerRadiusDp
|
|
974
857
|
}
|
|
975
858
|
engine.setCornerRadiusDp(effectiveRadiusDp)
|
|
976
|
-
val material =
|
|
859
|
+
val material = cachedOpticalMaterial ?: engine.materialFromProperties(
|
|
977
860
|
cornerRadiusDp = effectiveRadiusDp,
|
|
978
861
|
blurRadiusDp = blurRadiusDp,
|
|
979
862
|
refractionHeightDp = refractionHeightDp,
|
|
@@ -996,12 +879,12 @@ public class GlassViewController(private val host: View) {
|
|
|
996
879
|
outerShadowRadiusDp = referenceOuterShadowRadiusDp,
|
|
997
880
|
outerShadowOffsetYDp = referenceOuterShadowOffsetYDp,
|
|
998
881
|
interactionProfile = referenceInteractionProfile,
|
|
999
|
-
).also {
|
|
882
|
+
).also { cachedOpticalMaterial = it }
|
|
1000
883
|
engine.setMaterial(material)
|
|
1001
884
|
// A toggle or slider surface asks for the reference's own composite: one pass
|
|
1002
885
|
// that lerps the rail colour by the value, places the thumb by it, samples a
|
|
1003
886
|
// scaled copy of the rail and fades the idle white overlay. That pass already
|
|
1004
|
-
// exists in `ReferenceParityGlassShader`, and the
|
|
887
|
+
// exists in `ReferenceParityGlassShader`, and the core implements a generic
|
|
1005
888
|
// single-shape optic with no notion of a value or a second layer.
|
|
1006
889
|
//
|
|
1007
890
|
// The material has been installed above on purpose: installing it is what
|
|
@@ -1017,7 +900,7 @@ public class GlassViewController(private val host: View) {
|
|
|
1017
900
|
val isButton = frame.referenceInteractionProfile == REFERENCE_PROFILE_BUTTON
|
|
1018
901
|
// A reference button's View is scaled/translated by Android; the sampled scene
|
|
1019
902
|
// must stay fixed on screen, so compensate inside the shader (same law as the
|
|
1020
|
-
//
|
|
903
|
+
// reference parity shader's layerScale / layerTranslation).
|
|
1021
904
|
if (isButton) {
|
|
1022
905
|
engine.setSceneScale(frame.layerScaleX, frame.layerScaleY)
|
|
1023
906
|
engine.setPressGlow(frame.pressAmount, frame.pressX, frame.pressY)
|
|
@@ -1071,498 +954,12 @@ public class GlassViewController(private val host: View) {
|
|
|
1071
954
|
return drew
|
|
1072
955
|
}
|
|
1073
956
|
|
|
1074
|
-
|
|
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 =
|
|
957
|
+
internal fun resolveScrimColor(): Int =
|
|
1328
958
|
if (Color.alpha(glassTintColor) > 0) glassTintColor else fallbackScrimColor
|
|
1329
959
|
|
|
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
960
|
/** 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
961
|
|
|
1565
|
-
|
|
962
|
+
internal companion object {
|
|
1566
963
|
const val REFERENCE_PROFILE_BUTTON = 4
|
|
1567
964
|
const val BUTTON_SPRING_STIFFNESS = 300f
|
|
1568
965
|
const val BUTTON_SPRING_DAMPING = 0.5f
|
|
@@ -1570,7 +967,7 @@ public class GlassViewController(private val host: View) {
|
|
|
1570
967
|
const val SPRING_SETTLE_THRESHOLD = 0.003f
|
|
1571
968
|
}
|
|
1572
969
|
|
|
1573
|
-
|
|
970
|
+
internal inline fun <T> invalidating(
|
|
1574
971
|
old: T,
|
|
1575
972
|
new: T,
|
|
1576
973
|
kind: GlassDirtyKind = GlassDirtyKind.MATERIAL_DIRTY,
|
|
@@ -1578,7 +975,7 @@ public class GlassViewController(private val host: View) {
|
|
|
1578
975
|
) {
|
|
1579
976
|
if (old != new) {
|
|
1580
977
|
assign(new)
|
|
1581
|
-
|
|
978
|
+
cachedOpticalMaterial = null
|
|
1582
979
|
when (kind) {
|
|
1583
980
|
GlassDirtyKind.SOURCE_CONTENT_DIRTY -> Unit
|
|
1584
981
|
GlassDirtyKind.CONSUMER_GEOMETRY_DIRTY -> reportConsumerDirty(GlassBackdropDirtyReason.CONSUMER_GEOMETRY)
|
|
@@ -1589,7 +986,7 @@ public class GlassViewController(private val host: View) {
|
|
|
1589
986
|
}
|
|
1590
987
|
}
|
|
1591
988
|
|
|
1592
|
-
|
|
989
|
+
internal fun reportConsumerDirty(reason: GlassBackdropDirtyReason) {
|
|
1593
990
|
val backdrop = provider
|
|
1594
991
|
if (backdrop != null) {
|
|
1595
992
|
backdrop.onConsumerDirty(host, reason)
|