@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.
Files changed (674) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +307 -2
  3. package/README.zh-CN.md +310 -0
  4. package/THIRD_PARTY_NOTICES.md +98 -0
  5. package/android/build.gradle +19 -0
  6. package/android/src/main/AndroidManifest.xml +1 -0
  7. package/android/src/main/java/expo/modules/localglass/ExpoLocalGlassEngineModule.kt +141 -0
  8. package/android/src/main/java/expo/modules/localglass/ExpoLocalGlassModule.kt +341 -0
  9. package/android/src/main/java/expo/modules/localglass/LocalGlassShader.kt +59 -0
  10. package/android/src/main/java/expo/modules/newhuliquidglass/CoreLiquidGlassRegistry.kt +75 -0
  11. package/android/src/main/java/expo/modules/newhuliquidglass/EffectiveScrollInputBridge.kt +47 -0
  12. package/android/src/main/java/expo/modules/newhuliquidglass/ExpoGlassCoreModule.kt +226 -0
  13. package/android/src/main/java/expo/modules/newhuliquidglass/ExpoGlassProviderCoreView.kt +1125 -0
  14. package/android/src/main/java/expo/modules/newhuliquidglass/ExpoGlassSurfaceCoreView.kt +571 -0
  15. package/android/src/main/java/expo/modules/newhuliquidglass/PassSurfaceSuppression.kt +39 -0
  16. package/android/src/main/java/expo/modules/newhuliquidglass/SharedGlassPassProbeLog.kt +23 -0
  17. package/android/src/main/java/expo/modules/newhuliquidglass/SharedGlassPassWiring.kt +59 -0
  18. package/android-core/build.gradle +36 -0
  19. package/android-core/src/main/java/com/newhu/liquidglass/backdrop/BackdropRecorder.kt +930 -0
  20. package/android-core/src/main/java/com/newhu/liquidglass/backdrop/FrozenBackdrop.kt +66 -0
  21. package/android-core/src/main/java/com/newhu/liquidglass/backdrop/GlassBackdropCoordinator.kt +624 -0
  22. package/android-core/src/main/java/com/newhu/liquidglass/backdrop/GlassBackdropSourceHandle.kt +8 -0
  23. package/android-core/src/main/java/com/newhu/liquidglass/backdrop/GlassScrollSource.kt +13 -0
  24. package/android-core/src/main/java/com/newhu/liquidglass/backdrop/GlassViewController.kt +1605 -0
  25. package/android-core/src/main/java/com/newhu/liquidglass/backdrop/LiquidGlassProviderLayout.kt +340 -0
  26. package/android-core/src/main/java/com/newhu/liquidglass/backdrop/LiquidGlassView.kt +103 -0
  27. package/android-core/src/main/java/com/newhu/liquidglass/backdrop/ReferenceSourceWindowPolicy.kt +13 -0
  28. package/android-core/src/main/java/com/newhu/liquidglass/backdrop/StableSceneTexturePolicy.kt +43 -0
  29. package/android-core/src/main/java/com/newhu/liquidglass/backdrop/internal/GlassViewRenderer.kt +1459 -0
  30. package/android-core/src/main/java/com/newhu/liquidglass/backdrop/internal/ReferenceTabSampling.kt +15 -0
  31. package/android-core/src/main/java/com/newhu/liquidglass/backdrop/internal/SharedSceneCapture.kt +163 -0
  32. package/android-core/src/main/java/com/newhu/liquidglass/core/GlassCapabilities.kt +21 -0
  33. package/android-core/src/main/java/com/newhu/liquidglass/core/GlassEngine.kt +131 -0
  34. package/android-core/src/main/java/com/newhu/liquidglass/core/GlassMaterial.kt +89 -0
  35. package/android-core/src/main/java/com/newhu/liquidglass/core/GlassMath.kt +131 -0
  36. package/android-core/src/main/java/com/newhu/liquidglass/core/GlassOpticalInsets.kt +8 -0
  37. package/android-core/src/main/java/com/newhu/liquidglass/core/GlassRenderTier.kt +54 -0
  38. package/android-core/src/main/java/com/newhu/liquidglass/core/GlassShapePacker.kt +77 -0
  39. package/android-core/src/main/java/com/newhu/liquidglass/core/GlassSurfaceState.kt +11 -0
  40. package/android-core/src/main/java/com/newhu/liquidglass/core/GlassUniforms.kt +113 -0
  41. package/android-core/src/main/java/com/newhu/liquidglass/core/LiquidGlassShaders.kt +234 -0
  42. package/android-core/src/main/java/com/newhu/liquidglass/core/SharedGlassPass.kt +456 -0
  43. package/android-core/src/main/java/com/newhu/liquidglass/core/geometry/G2RoundedRectangle.kt +207 -0
  44. package/android-core/src/main/java/com/newhu/liquidglass/core/geometry/ReferenceG2MaskTexture.kt +334 -0
  45. package/android-core/src/main/java/com/newhu/liquidglass/core/shader/HeightFieldGlassShader.kt +7 -0
  46. package/android-core/src/main/java/com/newhu/liquidglass/core/shader/ReferenceBackdropBlurShader.kt +58 -0
  47. package/android-core/src/main/java/com/newhu/liquidglass/core/shader/ReferenceGaussianDiscBackdropBlur.kt +42 -0
  48. package/android-core/src/main/java/com/newhu/liquidglass/core/shader/ReferenceGlassUniforms.kt +111 -0
  49. package/android-core/src/main/java/com/newhu/liquidglass/core/shader/ReferenceParityGlassShader.kt +613 -0
  50. package/android-core/src/main/java/com/newhu/liquidglass/core/shader/ReferenceParityMultiShapeShader.kt +128 -0
  51. package/android-core/src/main/java/com/newhu/liquidglass/core/shader/SdfScaleLensShader.kt +144 -0
  52. package/android-core/src/main/java/com/newhu/liquidglass/local/LocalGlassHardwareLayerExperiment.kt +29 -0
  53. package/android-core/src/main/java/com/newhu/liquidglass/local/LocalGlassMaterial.kt +14 -0
  54. package/android-core/src/main/java/com/newhu/liquidglass/local/LocalGlassRenderer.kt +126 -0
  55. package/android-core/src/main/java/com/newhu/liquidglass/local/LocalGlassRuntimeShader.kt +50 -0
  56. package/android-core/src/main/java/com/newhu/liquidglass/local/LocalGlassShader.kt +59 -0
  57. package/android-core/src/main/java/com/newhu/liquidglass/local/LocalGlassView.kt +47 -0
  58. package/android-core/src/main/java/com/newhu/liquidglass/motion/GlassMotionDriver.kt +824 -0
  59. package/android-core/src/main/java/com/newhu/liquidglass/motion/GlassMotionState.kt +359 -0
  60. package/android-core/src/main/java/com/newhu/liquidglass/motion/PointerVelocityTracker.kt +109 -0
  61. package/android-core/src/main/java/com/newhu/liquidglass/motion/SpringSpec.kt +209 -0
  62. package/android-core/src/main/java/com/newhu/liquidglass/optics/G2Corner.kt +194 -0
  63. package/android-core/src/main/java/com/newhu/liquidglass/optics/GlassMaterial.kt +250 -0
  64. package/android-core/src/main/java/com/newhu/liquidglass/optics/GlassOpticsShader.kt +696 -0
  65. package/android-core/src/main/java/com/newhu/liquidglass/optics/GlassParityProbe.kt +342 -0
  66. package/android-core/src/main/java/com/newhu/liquidglass/optics/GlassShapeGeometry.kt +317 -0
  67. package/android-core/src/main/java/com/newhu/liquidglass/optics/GlassUniformBinder.kt +308 -0
  68. package/android-core/src/main/java/com/newhu/liquidglass/optics/PixelDiff.kt +363 -0
  69. package/android-core/src/main/java/com/newhu/liquidglass/optics/ReferenceOptics.kt +568 -0
  70. package/android-core/src/main/java/com/newhu/liquidglass/rendering/GlassEngineSelection.kt +30 -0
  71. package/android-core/src/main/java/com/newhu/liquidglass/rendering/GlassSurfaceHost.kt +317 -0
  72. package/android-core/src/main/java/com/newhu/liquidglass/rendering/GlassSurfaceRenderer.kt +847 -0
  73. package/android-core/src/main/java/com/newhu/liquidglass/rendering/RetainedBackdropLayer.kt +83 -0
  74. package/android-core/src/main/java/com/newhu/liquidglass/scheduler/GlassFrameScheduler.kt +27 -0
  75. package/android-core/src/main/java/com/newhu/liquidglass/telemetry/EffectiveScrollFpsProbe.kt +965 -0
  76. package/android-core/src/main/java/com/newhu/liquidglass/telemetry/GlassTelemetry.kt +16 -0
  77. package/android-core/src/main/java/com/newhu/liquidglass/telemetry/LiquidGlassPerfTelemetry.kt +676 -0
  78. package/android-core/src/main/java/com/newhu/liquidglass/telemetry/LiquidGlassTrace.kt +30 -0
  79. package/android-core/src/main/java/com/newhu/liquidglass/telemetry/LocalGlassTelemetry.kt +55 -0
  80. package/app.plugin.js +25 -0
  81. package/docs/images/buttons.webp +0 -0
  82. package/docs/images/controls.webp +0 -0
  83. package/docs/images/tabs.webp +0 -0
  84. package/docs/publishing.md +84 -0
  85. package/expo-module.config.json +10 -0
  86. package/lib/commonjs/GlassSurface.js +832 -0
  87. package/lib/commonjs/GlassSurface.js.map +1 -0
  88. package/lib/commonjs/GlassTabBar.js +976 -0
  89. package/lib/commonjs/GlassTabBar.js.map +1 -0
  90. package/lib/commonjs/GlassTabLens.js +67 -0
  91. package/lib/commonjs/GlassTabLens.js.map +1 -0
  92. package/lib/commonjs/LiquidGlassProvider.js +40 -0
  93. package/lib/commonjs/LiquidGlassProvider.js.map +1 -0
  94. package/lib/commonjs/LocalGlassMaterial.js +194 -0
  95. package/lib/commonjs/LocalGlassMaterial.js.map +1 -0
  96. package/lib/commonjs/adaptiveLuminance.js +14 -0
  97. package/lib/commonjs/adaptiveLuminance.js.map +1 -0
  98. package/lib/commonjs/badgePalette.js +46 -0
  99. package/lib/commonjs/badgePalette.js.map +1 -0
  100. package/lib/commonjs/buttonGesturePolicy.js +22 -0
  101. package/lib/commonjs/buttonGesturePolicy.js.map +1 -0
  102. package/lib/commonjs/components/AdaptiveLuminance.js +20 -0
  103. package/lib/commonjs/components/AdaptiveLuminance.js.map +1 -0
  104. package/lib/commonjs/components/BottomSheet.js +222 -0
  105. package/lib/commonjs/components/BottomSheet.js.map +1 -0
  106. package/lib/commonjs/components/Button.js +20 -0
  107. package/lib/commonjs/components/Button.js.map +1 -0
  108. package/lib/commonjs/components/Card.js +206 -0
  109. package/lib/commonjs/components/Card.js.map +1 -0
  110. package/lib/commonjs/components/Checkbox.js +123 -0
  111. package/lib/commonjs/components/Checkbox.js.map +1 -0
  112. package/lib/commonjs/components/ControlPressContext.js +8 -0
  113. package/lib/commonjs/components/ControlPressContext.js.map +1 -0
  114. package/lib/commonjs/components/Dialog.js +122 -0
  115. package/lib/commonjs/components/Dialog.js.map +1 -0
  116. package/lib/commonjs/components/DialogAction.js +124 -0
  117. package/lib/commonjs/components/DialogAction.js.map +1 -0
  118. package/lib/commonjs/components/DialogContent.js +23 -0
  119. package/lib/commonjs/components/DialogContent.js.map +1 -0
  120. package/lib/commonjs/components/GlassButton.js +96 -0
  121. package/lib/commonjs/components/GlassButton.js.map +1 -0
  122. package/lib/commonjs/components/GlassFab.js +43 -0
  123. package/lib/commonjs/components/GlassFab.js.map +1 -0
  124. package/lib/commonjs/components/GlassMagnifier.js +135 -0
  125. package/lib/commonjs/components/GlassMagnifier.js.map +1 -0
  126. package/lib/commonjs/components/GlassPlayground.js +158 -0
  127. package/lib/commonjs/components/GlassPlayground.js.map +1 -0
  128. package/lib/commonjs/components/GlassSlider.js +364 -0
  129. package/lib/commonjs/components/GlassSlider.js.map +1 -0
  130. package/lib/commonjs/components/GlassSwitch.js +334 -0
  131. package/lib/commonjs/components/GlassSwitch.js.map +1 -0
  132. package/lib/commonjs/components/GlassTabBar.js +387 -0
  133. package/lib/commonjs/components/GlassTabBar.js.map +1 -0
  134. package/lib/commonjs/components/Input.js +180 -0
  135. package/lib/commonjs/components/Input.js.map +1 -0
  136. package/lib/commonjs/components/ListRow.js +64 -0
  137. package/lib/commonjs/components/ListRow.js.map +1 -0
  138. package/lib/commonjs/components/Menu.js +214 -0
  139. package/lib/commonjs/components/Menu.js.map +1 -0
  140. package/lib/commonjs/components/NavigationBar.js +20 -0
  141. package/lib/commonjs/components/NavigationBar.js.map +1 -0
  142. package/lib/commonjs/components/NumberWheel.js +273 -0
  143. package/lib/commonjs/components/NumberWheel.js.map +1 -0
  144. package/lib/commonjs/components/PageFeedList.js +25 -0
  145. package/lib/commonjs/components/PageFeedList.js.map +1 -0
  146. package/lib/commonjs/components/PageScaffold.js +161 -0
  147. package/lib/commonjs/components/PageScaffold.js.map +1 -0
  148. package/lib/commonjs/components/PreferenceGroup.js +34 -0
  149. package/lib/commonjs/components/PreferenceGroup.js.map +1 -0
  150. package/lib/commonjs/components/ProgressIndicator.js +79 -0
  151. package/lib/commonjs/components/ProgressIndicator.js.map +1 -0
  152. package/lib/commonjs/components/ProgressiveBlur.js +29 -0
  153. package/lib/commonjs/components/ProgressiveBlur.js.map +1 -0
  154. package/lib/commonjs/components/ReferenceSlider.js +304 -0
  155. package/lib/commonjs/components/ReferenceSlider.js.map +1 -0
  156. package/lib/commonjs/components/ReferenceTabBar.js +381 -0
  157. package/lib/commonjs/components/ReferenceTabBar.js.map +1 -0
  158. package/lib/commonjs/components/SearchBar.js +200 -0
  159. package/lib/commonjs/components/SearchBar.js.map +1 -0
  160. package/lib/commonjs/components/SegmentedControl.js +62 -0
  161. package/lib/commonjs/components/SegmentedControl.js.map +1 -0
  162. package/lib/commonjs/components/Slider.js +12 -0
  163. package/lib/commonjs/components/Slider.js.map +1 -0
  164. package/lib/commonjs/components/Snackbar.js +11 -0
  165. package/lib/commonjs/components/Snackbar.js.map +1 -0
  166. package/lib/commonjs/components/SurfaceEnvironmentContext.js +35 -0
  167. package/lib/commonjs/components/SurfaceEnvironmentContext.js.map +1 -0
  168. package/lib/commonjs/components/SurfaceGroup.js +39 -0
  169. package/lib/commonjs/components/SurfaceGroup.js.map +1 -0
  170. package/lib/commonjs/components/Switch.js +11 -0
  171. package/lib/commonjs/components/Switch.js.map +1 -0
  172. package/lib/commonjs/components/Toast.js +110 -0
  173. package/lib/commonjs/components/Toast.js.map +1 -0
  174. package/lib/commonjs/components/TopAppBar.js +107 -0
  175. package/lib/commonjs/components/TopAppBar.js.map +1 -0
  176. package/lib/commonjs/components/bottomSheetMotion.js +14 -0
  177. package/lib/commonjs/components/bottomSheetMotion.js.map +1 -0
  178. package/lib/commonjs/components/glassControlMaterial.js +22 -0
  179. package/lib/commonjs/components/glassControlMaterial.js.map +1 -0
  180. package/lib/commonjs/components/menuPosition.js +42 -0
  181. package/lib/commonjs/components/menuPosition.js.map +1 -0
  182. package/lib/commonjs/components/pages/FeedPage.js +15 -0
  183. package/lib/commonjs/components/pages/FeedPage.js.map +1 -0
  184. package/lib/commonjs/components/pages/PageBenchmarkContext.js +123 -0
  185. package/lib/commonjs/components/pages/PageBenchmarkContext.js.map +1 -0
  186. package/lib/commonjs/components/pages/SettingsPage.js +47 -0
  187. package/lib/commonjs/components/pages/SettingsPage.js.map +1 -0
  188. package/lib/commonjs/components/pages/SettingsSection.js +14 -0
  189. package/lib/commonjs/components/pages/SettingsSection.js.map +1 -0
  190. package/lib/commonjs/components/pages/StaticSettingsPage.js +16 -0
  191. package/lib/commonjs/components/pages/StaticSettingsPage.js.map +1 -0
  192. package/lib/commonjs/fallbackKnobGeometry.js +19 -0
  193. package/lib/commonjs/fallbackKnobGeometry.js.map +1 -0
  194. package/lib/commonjs/glassController.js +65 -0
  195. package/lib/commonjs/glassController.js.map +1 -0
  196. package/lib/commonjs/glassNativeEngine.js +16 -0
  197. package/lib/commonjs/glassNativeEngine.js.map +1 -0
  198. package/lib/commonjs/glassRuntime.js +27 -0
  199. package/lib/commonjs/glassRuntime.js.map +1 -0
  200. package/lib/commonjs/index.js +218 -0
  201. package/lib/commonjs/index.js.map +1 -0
  202. package/lib/commonjs/inputPresentation.js +17 -0
  203. package/lib/commonjs/inputPresentation.js.map +1 -0
  204. package/lib/commonjs/localGlassTelemetry.js +113 -0
  205. package/lib/commonjs/localGlassTelemetry.js.map +1 -0
  206. package/lib/commonjs/motion/MotionProvider.js +15 -0
  207. package/lib/commonjs/motion/MotionProvider.js.map +1 -0
  208. package/lib/commonjs/motion/easings.js +71 -0
  209. package/lib/commonjs/motion/easings.js.map +1 -0
  210. package/lib/commonjs/motion/folmeSpring.js +24 -0
  211. package/lib/commonjs/motion/folmeSpring.js.map +1 -0
  212. package/lib/commonjs/motion/folmeSpringByResponse.js +22 -0
  213. package/lib/commonjs/motion/folmeSpringByResponse.js.map +1 -0
  214. package/lib/commonjs/motion/index.js +57 -0
  215. package/lib/commonjs/motion/index.js.map +1 -0
  216. package/lib/commonjs/motion/presets.js +101 -0
  217. package/lib/commonjs/motion/presets.js.map +1 -0
  218. package/lib/commonjs/nativeGlassViews.js +33 -0
  219. package/lib/commonjs/nativeGlassViews.js.map +1 -0
  220. package/lib/commonjs/performanceTelemetry.js +28 -0
  221. package/lib/commonjs/performanceTelemetry.js.map +1 -0
  222. package/lib/commonjs/pointerEventBridge.js +17 -0
  223. package/lib/commonjs/pointerEventBridge.js.map +1 -0
  224. package/lib/commonjs/pointerGeometry.js +12 -0
  225. package/lib/commonjs/pointerGeometry.js.map +1 -0
  226. package/lib/commonjs/pressVelocity.js +34 -0
  227. package/lib/commonjs/pressVelocity.js.map +1 -0
  228. package/lib/commonjs/primitives/Divider.js +32 -0
  229. package/lib/commonjs/primitives/Divider.js.map +1 -0
  230. package/lib/commonjs/primitives/Icon.js +22 -0
  231. package/lib/commonjs/primitives/Icon.js.map +1 -0
  232. package/lib/commonjs/primitives/PressIndication.js +58 -0
  233. package/lib/commonjs/primitives/PressIndication.js.map +1 -0
  234. package/lib/commonjs/primitives/Pressable.js +28 -0
  235. package/lib/commonjs/primitives/Pressable.js.map +1 -0
  236. package/lib/commonjs/primitives/PressableScale.js +64 -0
  237. package/lib/commonjs/primitives/PressableScale.js.map +1 -0
  238. package/lib/commonjs/primitives/Surface.js +122 -0
  239. package/lib/commonjs/primitives/Surface.js.map +1 -0
  240. package/lib/commonjs/primitives/Text.js +43 -0
  241. package/lib/commonjs/primitives/Text.js.map +1 -0
  242. package/lib/commonjs/primitives/index.js +18 -0
  243. package/lib/commonjs/primitives/index.js.map +1 -0
  244. package/lib/commonjs/renderer.js +58 -0
  245. package/lib/commonjs/renderer.js.map +1 -0
  246. package/lib/commonjs/sliderValue.js +28 -0
  247. package/lib/commonjs/sliderValue.js.map +1 -0
  248. package/lib/commonjs/surfaceRendererPolicy.js +32 -0
  249. package/lib/commonjs/surfaceRendererPolicy.js.map +1 -0
  250. package/lib/commonjs/theme/ThemeProvider.js +37 -0
  251. package/lib/commonjs/theme/ThemeProvider.js.map +1 -0
  252. package/lib/commonjs/theme/buildTheme.js +157 -0
  253. package/lib/commonjs/theme/buildTheme.js.map +1 -0
  254. package/lib/commonjs/theme/glassColors.js +17 -0
  255. package/lib/commonjs/theme/glassColors.js.map +1 -0
  256. package/lib/commonjs/theme/index.js +38 -0
  257. package/lib/commonjs/theme/index.js.map +1 -0
  258. package/lib/commonjs/theme/liquidGlass.js +24 -0
  259. package/lib/commonjs/theme/liquidGlass.js.map +1 -0
  260. package/lib/commonjs/theme/presentation.js +14 -0
  261. package/lib/commonjs/theme/presentation.js.map +1 -0
  262. package/lib/commonjs/theme/registry.js +17 -0
  263. package/lib/commonjs/theme/registry.js.map +1 -0
  264. package/lib/commonjs/theme/selectVariant.js +13 -0
  265. package/lib/commonjs/theme/selectVariant.js.map +1 -0
  266. package/lib/commonjs/theme/tokens.js +266 -0
  267. package/lib/commonjs/theme/tokens.js.map +1 -0
  268. package/lib/commonjs/theme/types.js +3 -0
  269. package/lib/commonjs/theme/types.js.map +1 -0
  270. package/lib/commonjs/theme/wallpaper.js +91 -0
  271. package/lib/commonjs/theme/wallpaper.js.map +1 -0
  272. package/lib/commonjs/types.js +3 -0
  273. package/lib/commonjs/types.js.map +1 -0
  274. package/lib/commonjs/useButtonGesture.js +135 -0
  275. package/lib/commonjs/useButtonGesture.js.map +1 -0
  276. package/lib/commonjs/useGlassKnobMotion.js +115 -0
  277. package/lib/commonjs/useGlassKnobMotion.js.map +1 -0
  278. package/lib/commonjs/useGlassPressMotion.js +147 -0
  279. package/lib/commonjs/useGlassPressMotion.js.map +1 -0
  280. package/lib/module/GlassSurface.js +782 -0
  281. package/lib/module/GlassSurface.js.map +1 -0
  282. package/lib/module/GlassTabBar.js +939 -0
  283. package/lib/module/GlassTabBar.js.map +1 -0
  284. package/lib/module/GlassTabLens.js +64 -0
  285. package/lib/module/GlassTabLens.js.map +1 -0
  286. package/lib/module/LiquidGlassProvider.js +37 -0
  287. package/lib/module/LiquidGlassProvider.js.map +1 -0
  288. package/lib/module/LocalGlassMaterial.js +191 -0
  289. package/lib/module/LocalGlassMaterial.js.map +1 -0
  290. package/lib/module/adaptiveLuminance.js +11 -0
  291. package/lib/module/adaptiveLuminance.js.map +1 -0
  292. package/lib/module/badgePalette.js +40 -0
  293. package/lib/module/badgePalette.js.map +1 -0
  294. package/lib/module/buttonGesturePolicy.js +17 -0
  295. package/lib/module/buttonGesturePolicy.js.map +1 -0
  296. package/lib/module/components/AdaptiveLuminance.js +16 -0
  297. package/lib/module/components/AdaptiveLuminance.js.map +1 -0
  298. package/lib/module/components/BottomSheet.js +186 -0
  299. package/lib/module/components/BottomSheet.js.map +1 -0
  300. package/lib/module/components/Button.js +17 -0
  301. package/lib/module/components/Button.js.map +1 -0
  302. package/lib/module/components/Card.js +170 -0
  303. package/lib/module/components/Card.js.map +1 -0
  304. package/lib/module/components/Checkbox.js +84 -0
  305. package/lib/module/components/Checkbox.js.map +1 -0
  306. package/lib/module/components/ControlPressContext.js +4 -0
  307. package/lib/module/components/ControlPressContext.js.map +1 -0
  308. package/lib/module/components/Dialog.js +86 -0
  309. package/lib/module/components/Dialog.js.map +1 -0
  310. package/lib/module/components/DialogAction.js +88 -0
  311. package/lib/module/components/DialogAction.js.map +1 -0
  312. package/lib/module/components/DialogContent.js +20 -0
  313. package/lib/module/components/DialogContent.js.map +1 -0
  314. package/lib/module/components/GlassButton.js +93 -0
  315. package/lib/module/components/GlassButton.js.map +1 -0
  316. package/lib/module/components/GlassFab.js +37 -0
  317. package/lib/module/components/GlassFab.js.map +1 -0
  318. package/lib/module/components/GlassMagnifier.js +99 -0
  319. package/lib/module/components/GlassMagnifier.js.map +1 -0
  320. package/lib/module/components/GlassPlayground.js +122 -0
  321. package/lib/module/components/GlassPlayground.js.map +1 -0
  322. package/lib/module/components/GlassSlider.js +328 -0
  323. package/lib/module/components/GlassSlider.js.map +1 -0
  324. package/lib/module/components/GlassSwitch.js +298 -0
  325. package/lib/module/components/GlassSwitch.js.map +1 -0
  326. package/lib/module/components/GlassTabBar.js +351 -0
  327. package/lib/module/components/GlassTabBar.js.map +1 -0
  328. package/lib/module/components/Input.js +144 -0
  329. package/lib/module/components/Input.js.map +1 -0
  330. package/lib/module/components/ListRow.js +61 -0
  331. package/lib/module/components/ListRow.js.map +1 -0
  332. package/lib/module/components/Menu.js +178 -0
  333. package/lib/module/components/Menu.js.map +1 -0
  334. package/lib/module/components/NavigationBar.js +14 -0
  335. package/lib/module/components/NavigationBar.js.map +1 -0
  336. package/lib/module/components/NumberWheel.js +238 -0
  337. package/lib/module/components/NumberWheel.js.map +1 -0
  338. package/lib/module/components/PageFeedList.js +19 -0
  339. package/lib/module/components/PageFeedList.js.map +1 -0
  340. package/lib/module/components/PageScaffold.js +114 -0
  341. package/lib/module/components/PageScaffold.js.map +1 -0
  342. package/lib/module/components/PreferenceGroup.js +28 -0
  343. package/lib/module/components/PreferenceGroup.js.map +1 -0
  344. package/lib/module/components/ProgressIndicator.js +44 -0
  345. package/lib/module/components/ProgressIndicator.js.map +1 -0
  346. package/lib/module/components/ProgressiveBlur.js +26 -0
  347. package/lib/module/components/ProgressiveBlur.js.map +1 -0
  348. package/lib/module/components/ReferenceSlider.js +268 -0
  349. package/lib/module/components/ReferenceSlider.js.map +1 -0
  350. package/lib/module/components/ReferenceTabBar.js +344 -0
  351. package/lib/module/components/ReferenceTabBar.js.map +1 -0
  352. package/lib/module/components/SearchBar.js +164 -0
  353. package/lib/module/components/SearchBar.js.map +1 -0
  354. package/lib/module/components/SegmentedControl.js +26 -0
  355. package/lib/module/components/SegmentedControl.js.map +1 -0
  356. package/lib/module/components/Slider.js +9 -0
  357. package/lib/module/components/Slider.js.map +1 -0
  358. package/lib/module/components/Snackbar.js +8 -0
  359. package/lib/module/components/Snackbar.js.map +1 -0
  360. package/lib/module/components/SurfaceEnvironmentContext.js +27 -0
  361. package/lib/module/components/SurfaceEnvironmentContext.js.map +1 -0
  362. package/lib/module/components/SurfaceGroup.js +33 -0
  363. package/lib/module/components/SurfaceGroup.js.map +1 -0
  364. package/lib/module/components/Switch.js +8 -0
  365. package/lib/module/components/Switch.js.map +1 -0
  366. package/lib/module/components/Toast.js +74 -0
  367. package/lib/module/components/Toast.js.map +1 -0
  368. package/lib/module/components/TopAppBar.js +68 -0
  369. package/lib/module/components/TopAppBar.js.map +1 -0
  370. package/lib/module/components/bottomSheetMotion.js +11 -0
  371. package/lib/module/components/bottomSheetMotion.js.map +1 -0
  372. package/lib/module/components/glassControlMaterial.js +19 -0
  373. package/lib/module/components/glassControlMaterial.js.map +1 -0
  374. package/lib/module/components/menuPosition.js +37 -0
  375. package/lib/module/components/menuPosition.js.map +1 -0
  376. package/lib/module/components/pages/FeedPage.js +12 -0
  377. package/lib/module/components/pages/FeedPage.js.map +1 -0
  378. package/lib/module/components/pages/PageBenchmarkContext.js +84 -0
  379. package/lib/module/components/pages/PageBenchmarkContext.js.map +1 -0
  380. package/lib/module/components/pages/SettingsPage.js +11 -0
  381. package/lib/module/components/pages/SettingsPage.js.map +1 -0
  382. package/lib/module/components/pages/SettingsSection.js +8 -0
  383. package/lib/module/components/pages/SettingsSection.js.map +1 -0
  384. package/lib/module/components/pages/StaticSettingsPage.js +10 -0
  385. package/lib/module/components/pages/StaticSettingsPage.js.map +1 -0
  386. package/lib/module/fallbackKnobGeometry.js +16 -0
  387. package/lib/module/fallbackKnobGeometry.js.map +1 -0
  388. package/lib/module/glassController.js +58 -0
  389. package/lib/module/glassController.js.map +1 -0
  390. package/lib/module/glassNativeEngine.js +11 -0
  391. package/lib/module/glassNativeEngine.js.map +1 -0
  392. package/lib/module/glassRuntime.js +22 -0
  393. package/lib/module/glassRuntime.js.map +1 -0
  394. package/lib/module/index.js +80 -0
  395. package/lib/module/index.js.map +1 -0
  396. package/lib/module/inputPresentation.js +14 -0
  397. package/lib/module/inputPresentation.js.map +1 -0
  398. package/lib/module/localGlassTelemetry.js +103 -0
  399. package/lib/module/localGlassTelemetry.js.map +1 -0
  400. package/lib/module/motion/MotionProvider.js +11 -0
  401. package/lib/module/motion/MotionProvider.js.map +1 -0
  402. package/lib/module/motion/easings.js +64 -0
  403. package/lib/module/motion/easings.js.map +1 -0
  404. package/lib/module/motion/folmeSpring.js +21 -0
  405. package/lib/module/motion/folmeSpring.js.map +1 -0
  406. package/lib/module/motion/folmeSpringByResponse.js +19 -0
  407. package/lib/module/motion/folmeSpringByResponse.js.map +1 -0
  408. package/lib/module/motion/index.js +6 -0
  409. package/lib/module/motion/index.js.map +1 -0
  410. package/lib/module/motion/presets.js +98 -0
  411. package/lib/module/motion/presets.js.map +1 -0
  412. package/lib/module/nativeGlassViews.js +27 -0
  413. package/lib/module/nativeGlassViews.js.map +1 -0
  414. package/lib/module/package.json +1 -0
  415. package/lib/module/performanceTelemetry.js +23 -0
  416. package/lib/module/performanceTelemetry.js.map +1 -0
  417. package/lib/module/pointerEventBridge.js +14 -0
  418. package/lib/module/pointerEventBridge.js.map +1 -0
  419. package/lib/module/pointerGeometry.js +9 -0
  420. package/lib/module/pointerGeometry.js.map +1 -0
  421. package/lib/module/pressVelocity.js +31 -0
  422. package/lib/module/pressVelocity.js.map +1 -0
  423. package/lib/module/primitives/Divider.js +29 -0
  424. package/lib/module/primitives/Divider.js.map +1 -0
  425. package/lib/module/primitives/Icon.js +19 -0
  426. package/lib/module/primitives/Icon.js.map +1 -0
  427. package/lib/module/primitives/PressIndication.js +22 -0
  428. package/lib/module/primitives/PressIndication.js.map +1 -0
  429. package/lib/module/primitives/Pressable.js +25 -0
  430. package/lib/module/primitives/Pressable.js.map +1 -0
  431. package/lib/module/primitives/PressableScale.js +28 -0
  432. package/lib/module/primitives/PressableScale.js.map +1 -0
  433. package/lib/module/primitives/Surface.js +83 -0
  434. package/lib/module/primitives/Surface.js.map +1 -0
  435. package/lib/module/primitives/Text.js +40 -0
  436. package/lib/module/primitives/Text.js.map +1 -0
  437. package/lib/module/primitives/index.js +8 -0
  438. package/lib/module/primitives/index.js.map +1 -0
  439. package/lib/module/renderer.js +22 -0
  440. package/lib/module/renderer.js.map +1 -0
  441. package/lib/module/sliderValue.js +25 -0
  442. package/lib/module/sliderValue.js.map +1 -0
  443. package/lib/module/surfaceRendererPolicy.js +27 -0
  444. package/lib/module/surfaceRendererPolicy.js.map +1 -0
  445. package/lib/module/theme/ThemeProvider.js +32 -0
  446. package/lib/module/theme/ThemeProvider.js.map +1 -0
  447. package/lib/module/theme/buildTheme.js +153 -0
  448. package/lib/module/theme/buildTheme.js.map +1 -0
  449. package/lib/module/theme/glassColors.js +14 -0
  450. package/lib/module/theme/glassColors.js.map +1 -0
  451. package/lib/module/theme/index.js +9 -0
  452. package/lib/module/theme/index.js.map +1 -0
  453. package/lib/module/theme/liquidGlass.js +21 -0
  454. package/lib/module/theme/liquidGlass.js.map +1 -0
  455. package/lib/module/theme/presentation.js +11 -0
  456. package/lib/module/theme/presentation.js.map +1 -0
  457. package/lib/module/theme/registry.js +13 -0
  458. package/lib/module/theme/registry.js.map +1 -0
  459. package/lib/module/theme/selectVariant.js +10 -0
  460. package/lib/module/theme/selectVariant.js.map +1 -0
  461. package/lib/module/theme/tokens.js +262 -0
  462. package/lib/module/theme/tokens.js.map +1 -0
  463. package/lib/module/theme/types.js +2 -0
  464. package/lib/module/theme/types.js.map +1 -0
  465. package/lib/module/theme/wallpaper.js +83 -0
  466. package/lib/module/theme/wallpaper.js.map +1 -0
  467. package/lib/module/types.js +2 -0
  468. package/lib/module/types.js.map +1 -0
  469. package/lib/module/useButtonGesture.js +132 -0
  470. package/lib/module/useButtonGesture.js.map +1 -0
  471. package/lib/module/useGlassKnobMotion.js +112 -0
  472. package/lib/module/useGlassKnobMotion.js.map +1 -0
  473. package/lib/module/useGlassPressMotion.js +143 -0
  474. package/lib/module/useGlassPressMotion.js.map +1 -0
  475. package/lib/types/GlassSurface.d.ts +216 -0
  476. package/lib/types/GlassTabBar.d.ts +35 -0
  477. package/lib/types/GlassTabLens.d.ts +11 -0
  478. package/lib/types/LiquidGlassProvider.d.ts +47 -0
  479. package/lib/types/LocalGlassMaterial.d.ts +21 -0
  480. package/lib/types/adaptiveLuminance.d.ts +2 -0
  481. package/lib/types/badgePalette.d.ts +9 -0
  482. package/lib/types/buttonGesturePolicy.d.ts +4 -0
  483. package/lib/types/components/AdaptiveLuminance.d.ts +23 -0
  484. package/lib/types/components/BottomSheet.d.ts +33 -0
  485. package/lib/types/components/Button.d.ts +16 -0
  486. package/lib/types/components/Card.d.ts +25 -0
  487. package/lib/types/components/Checkbox.d.ts +11 -0
  488. package/lib/types/components/ControlPressContext.d.ts +9 -0
  489. package/lib/types/components/Dialog.d.ts +12 -0
  490. package/lib/types/components/DialogAction.d.ts +4 -0
  491. package/lib/types/components/DialogContent.d.ts +12 -0
  492. package/lib/types/components/GlassButton.d.ts +38 -0
  493. package/lib/types/components/GlassFab.d.ts +15 -0
  494. package/lib/types/components/GlassMagnifier.d.ts +41 -0
  495. package/lib/types/components/GlassPlayground.d.ts +12 -0
  496. package/lib/types/components/GlassSlider.d.ts +48 -0
  497. package/lib/types/components/GlassSwitch.d.ts +46 -0
  498. package/lib/types/components/GlassTabBar.d.ts +44 -0
  499. package/lib/types/components/Input.d.ts +47 -0
  500. package/lib/types/components/ListRow.d.ts +17 -0
  501. package/lib/types/components/Menu.d.ts +41 -0
  502. package/lib/types/components/NavigationBar.d.ts +14 -0
  503. package/lib/types/components/NumberWheel.d.ts +11 -0
  504. package/lib/types/components/PageFeedList.d.ts +6 -0
  505. package/lib/types/components/PageScaffold.d.ts +64 -0
  506. package/lib/types/components/PreferenceGroup.d.ts +12 -0
  507. package/lib/types/components/ProgressIndicator.d.ts +9 -0
  508. package/lib/types/components/ProgressiveBlur.d.ts +12 -0
  509. package/lib/types/components/ReferenceSlider.d.ts +31 -0
  510. package/lib/types/components/ReferenceTabBar.d.ts +61 -0
  511. package/lib/types/components/SearchBar.d.ts +52 -0
  512. package/lib/types/components/SegmentedControl.d.ts +10 -0
  513. package/lib/types/components/Slider.d.ts +19 -0
  514. package/lib/types/components/Snackbar.d.ts +5 -0
  515. package/lib/types/components/SurfaceEnvironmentContext.d.ts +17 -0
  516. package/lib/types/components/SurfaceGroup.d.ts +17 -0
  517. package/lib/types/components/Switch.d.ts +12 -0
  518. package/lib/types/components/Toast.d.ts +14 -0
  519. package/lib/types/components/TopAppBar.d.ts +49 -0
  520. package/lib/types/components/bottomSheetMotion.d.ts +2 -0
  521. package/lib/types/components/glassControlMaterial.d.ts +3 -0
  522. package/lib/types/components/menuPosition.d.ts +22 -0
  523. package/lib/types/components/pages/FeedPage.d.ts +31 -0
  524. package/lib/types/components/pages/PageBenchmarkContext.d.ts +30 -0
  525. package/lib/types/components/pages/SettingsPage.d.ts +20 -0
  526. package/lib/types/components/pages/SettingsSection.d.ts +9 -0
  527. package/lib/types/components/pages/StaticSettingsPage.d.ts +18 -0
  528. package/lib/types/fallbackKnobGeometry.d.ts +7 -0
  529. package/lib/types/glassController.d.ts +20 -0
  530. package/lib/types/glassNativeEngine.d.ts +5 -0
  531. package/lib/types/glassRuntime.d.ts +7 -0
  532. package/lib/types/index.d.ts +124 -0
  533. package/lib/types/inputPresentation.d.ts +12 -0
  534. package/lib/types/localGlassTelemetry.d.ts +28 -0
  535. package/lib/types/motion/MotionProvider.d.ts +7 -0
  536. package/lib/types/motion/easings.d.ts +33 -0
  537. package/lib/types/motion/folmeSpring.d.ts +15 -0
  538. package/lib/types/motion/folmeSpringByResponse.d.ts +14 -0
  539. package/lib/types/motion/index.d.ts +7 -0
  540. package/lib/types/motion/presets.d.ts +103 -0
  541. package/lib/types/nativeGlassViews.d.ts +114 -0
  542. package/lib/types/performanceTelemetry.d.ts +65 -0
  543. package/lib/types/pointerEventBridge.d.ts +17 -0
  544. package/lib/types/pointerGeometry.d.ts +2 -0
  545. package/lib/types/pressVelocity.d.ts +11 -0
  546. package/lib/types/primitives/Divider.d.ts +19 -0
  547. package/lib/types/primitives/Icon.d.ts +29 -0
  548. package/lib/types/primitives/PressIndication.d.ts +26 -0
  549. package/lib/types/primitives/Pressable.d.ts +9 -0
  550. package/lib/types/primitives/PressableScale.d.ts +19 -0
  551. package/lib/types/primitives/Surface.d.ts +63 -0
  552. package/lib/types/primitives/Text.d.ts +35 -0
  553. package/lib/types/primitives/index.d.ts +14 -0
  554. package/lib/types/renderer.d.ts +32 -0
  555. package/lib/types/sliderValue.d.ts +2 -0
  556. package/lib/types/surfaceRendererPolicy.d.ts +14 -0
  557. package/lib/types/theme/ThemeProvider.d.ts +26 -0
  558. package/lib/types/theme/buildTheme.d.ts +6 -0
  559. package/lib/types/theme/glassColors.d.ts +13 -0
  560. package/lib/types/theme/index.d.ts +11 -0
  561. package/lib/types/theme/liquidGlass.d.ts +5 -0
  562. package/lib/types/theme/presentation.d.ts +3 -0
  563. package/lib/types/theme/registry.d.ts +7 -0
  564. package/lib/types/theme/selectVariant.d.ts +10 -0
  565. package/lib/types/theme/tokens.d.ts +18 -0
  566. package/lib/types/theme/types.d.ts +305 -0
  567. package/lib/types/theme/wallpaper.d.ts +32 -0
  568. package/lib/types/types.d.ts +127 -0
  569. package/lib/types/useButtonGesture.d.ts +30 -0
  570. package/lib/types/useGlassKnobMotion.d.ts +40 -0
  571. package/lib/types/useGlassPressMotion.d.ts +61 -0
  572. package/licenses/Apache-2.0-Kyant0-Shapes.txt +191 -0
  573. package/package.json +139 -4
  574. package/patches/liquid-glass-kit+1.0.0.patch +2015 -0
  575. package/patches/liquid-glass-kit-invalidation-coalescing.diff +249 -0
  576. package/patches/liquid-glass-kit-native-infra.diff +624 -0
  577. package/scripts/apply-legacy-patches.mjs +116 -0
  578. package/src/GlassSurface.tsx +1786 -0
  579. package/src/GlassTabBar.tsx +1304 -0
  580. package/src/GlassTabLens.tsx +92 -0
  581. package/src/LiquidGlassProvider.tsx +135 -0
  582. package/src/LocalGlassMaterial.tsx +262 -0
  583. package/src/adaptiveLuminance.ts +15 -0
  584. package/src/badgePalette.ts +54 -0
  585. package/src/buttonGesturePolicy.ts +15 -0
  586. package/src/components/AdaptiveLuminance.tsx +40 -0
  587. package/src/components/BottomSheet.tsx +291 -0
  588. package/src/components/Button.tsx +30 -0
  589. package/src/components/Card.tsx +343 -0
  590. package/src/components/Checkbox.tsx +141 -0
  591. package/src/components/ControlPressContext.ts +11 -0
  592. package/src/components/Dialog.tsx +129 -0
  593. package/src/components/DialogAction.tsx +109 -0
  594. package/src/components/DialogContent.tsx +52 -0
  595. package/src/components/GlassButton.tsx +225 -0
  596. package/src/components/GlassFab.tsx +98 -0
  597. package/src/components/GlassMagnifier.tsx +178 -0
  598. package/src/components/GlassPlayground.tsx +190 -0
  599. package/src/components/GlassSlider.tsx +448 -0
  600. package/src/components/GlassSwitch.tsx +391 -0
  601. package/src/components/GlassTabBar.tsx +522 -0
  602. package/src/components/Input.tsx +277 -0
  603. package/src/components/ListRow.tsx +124 -0
  604. package/src/components/Menu.tsx +322 -0
  605. package/src/components/NavigationBar.tsx +27 -0
  606. package/src/components/NumberWheel.tsx +344 -0
  607. package/src/components/PageFeedList.tsx +37 -0
  608. package/src/components/PageScaffold.tsx +266 -0
  609. package/src/components/PreferenceGroup.tsx +65 -0
  610. package/src/components/ProgressIndicator.tsx +63 -0
  611. package/src/components/ProgressiveBlur.tsx +56 -0
  612. package/src/components/ReferenceSlider.tsx +364 -0
  613. package/src/components/ReferenceTabBar.tsx +564 -0
  614. package/src/components/SearchBar.tsx +340 -0
  615. package/src/components/SegmentedControl.tsx +45 -0
  616. package/src/components/Slider.tsx +25 -0
  617. package/src/components/Snackbar.tsx +10 -0
  618. package/src/components/SurfaceEnvironmentContext.tsx +46 -0
  619. package/src/components/SurfaceGroup.tsx +60 -0
  620. package/src/components/Switch.tsx +18 -0
  621. package/src/components/Toast.tsx +110 -0
  622. package/src/components/TopAppBar.tsx +272 -0
  623. package/src/components/bottomSheetMotion.ts +10 -0
  624. package/src/components/glassControlMaterial.ts +20 -0
  625. package/src/components/menuPosition.ts +58 -0
  626. package/src/components/pages/FeedPage.tsx +96 -0
  627. package/src/components/pages/PageBenchmarkContext.tsx +105 -0
  628. package/src/components/pages/SettingsPage.tsx +55 -0
  629. package/src/components/pages/SettingsSection.tsx +20 -0
  630. package/src/components/pages/StaticSettingsPage.tsx +50 -0
  631. package/src/fallbackKnobGeometry.ts +15 -0
  632. package/src/glassController.ts +74 -0
  633. package/src/glassNativeEngine.ts +16 -0
  634. package/src/glassRuntime.ts +28 -0
  635. package/src/index.ts +199 -0
  636. package/src/inputPresentation.ts +32 -0
  637. package/src/localGlassTelemetry.ts +138 -0
  638. package/src/motion/MotionProvider.tsx +12 -0
  639. package/src/motion/easings.ts +71 -0
  640. package/src/motion/folmeSpring.ts +22 -0
  641. package/src/motion/folmeSpringByResponse.ts +19 -0
  642. package/src/motion/index.ts +47 -0
  643. package/src/motion/presets.ts +128 -0
  644. package/src/nativeGlassViews.ts +147 -0
  645. package/src/performanceTelemetry.ts +95 -0
  646. package/src/pointerEventBridge.ts +27 -0
  647. package/src/pointerGeometry.ts +8 -0
  648. package/src/pressVelocity.ts +36 -0
  649. package/src/primitives/Divider.tsx +42 -0
  650. package/src/primitives/Icon.tsx +44 -0
  651. package/src/primitives/PressIndication.tsx +43 -0
  652. package/src/primitives/Pressable.tsx +75 -0
  653. package/src/primitives/PressableScale.tsx +50 -0
  654. package/src/primitives/Surface.tsx +171 -0
  655. package/src/primitives/Text.tsx +80 -0
  656. package/src/primitives/index.ts +14 -0
  657. package/src/renderer.ts +70 -0
  658. package/src/sliderValue.ts +19 -0
  659. package/src/surfaceRendererPolicy.ts +32 -0
  660. package/src/theme/ThemeProvider.tsx +52 -0
  661. package/src/theme/buildTheme.ts +160 -0
  662. package/src/theme/glassColors.ts +13 -0
  663. package/src/theme/index.ts +34 -0
  664. package/src/theme/liquidGlass.ts +25 -0
  665. package/src/theme/presentation.ts +12 -0
  666. package/src/theme/registry.ts +16 -0
  667. package/src/theme/selectVariant.ts +12 -0
  668. package/src/theme/tokens.ts +309 -0
  669. package/src/theme/types.ts +345 -0
  670. package/src/theme/wallpaper.ts +94 -0
  671. package/src/types.ts +95 -0
  672. package/src/useButtonGesture.ts +134 -0
  673. package/src/useGlassKnobMotion.ts +155 -0
  674. package/src/useGlassPressMotion.ts +209 -0
@@ -0,0 +1,965 @@
1
+ package com.newhu.liquidglass.telemetry
2
+
3
+ import android.os.SystemClock
4
+ import android.os.Build
5
+ import android.os.Trace
6
+ import android.util.Log
7
+ import android.app.Activity
8
+ import android.content.Context
9
+ import android.content.ContextWrapper
10
+ import android.view.Choreographer
11
+ import android.view.FrameMetrics
12
+ import android.view.MotionEvent
13
+ import android.view.View
14
+ import android.view.ViewGroup
15
+ import android.view.ViewTreeObserver
16
+ import android.view.Window
17
+ import android.widget.HorizontalScrollView
18
+ import android.widget.OverScroller
19
+ import android.widget.ScrollView
20
+ import java.util.IdentityHashMap
21
+ import java.util.concurrent.CountDownLatch
22
+ import java.util.concurrent.TimeUnit
23
+ import kotlin.math.max
24
+ import kotlin.math.roundToInt
25
+
26
+ /**
27
+ * Debug benchmark probe for the actual offset rendered by native scroll containers.
28
+ * It deliberately runs independently of Glass consumers and records both a
29
+ * Choreographer sample and a root draw sample. Release code never enables it.
30
+ */
31
+ public object EffectiveScrollFpsProbe {
32
+ private const val TAG = "LiquidGlassPerf"
33
+ private const val MAX_SAMPLES = 24_000
34
+ private const val ACTIVE_TAIL_NS = 100_000_000L
35
+ private const val POST_TOUCH_CAPTURE_WINDOW_NS = 3_000_000_000L
36
+
37
+ private data class OffsetFrameSample(
38
+ val frameTimeNs: Long,
39
+ val x: Int,
40
+ val y: Int,
41
+ val deltaX: Int,
42
+ val deltaY: Int,
43
+ val changed: Boolean,
44
+ )
45
+
46
+ private class TargetState(val view: View, val identity: String) {
47
+ var previousX = view.scrollX
48
+ var previousY = view.scrollY
49
+ var nativeX = view.scrollX
50
+ var nativeY = view.scrollY
51
+ var sampledX = view.scrollX
52
+ var sampledY = view.scrollY
53
+ var sampledWidth = view.width
54
+ var sampledHeight = view.height
55
+ val nativeViewId = view.id
56
+ var lastChangedNs = 0L
57
+ var lastActiveSampleNs = 0L
58
+ var lastDrawFrameNs = 0L
59
+ var previousDrawX = view.scrollX
60
+ var previousDrawY = view.scrollY
61
+ var drawLastChangedNs = 0L
62
+ var previousWindowFrameX = view.scrollX
63
+ var previousWindowFrameY = view.scrollY
64
+ var windowFrameLastChangedNs = 0L
65
+ val updateIntervalsNs = ArrayList<Long>()
66
+ val drawUpdateIntervalsNs = ArrayList<Long>()
67
+ val windowFrameUpdateIntervalsNs = ArrayList<Long>()
68
+ val dragUpdateIntervalsNs = ArrayList<Long>()
69
+ val postTouchUpdateIntervalsNs = ArrayList<Long>()
70
+ val nativeScrollIntervalsNs = ArrayList<Long>()
71
+ val nativeDragScrollIntervalsNs = ArrayList<Long>()
72
+ val nativePostTouchScrollIntervalsNs = ArrayList<Long>()
73
+ val touchMoveIntervalsNs = ArrayList<Long>()
74
+ val touchMoveDispatchIntervalsNs = ArrayList<Long>()
75
+ val offsetSamples = ArrayList<OffsetFrameSample>()
76
+ var lastDragChangedNs = 0L
77
+ var lastPostTouchChangedNs = 0L
78
+ var lastNativeScrollChangedNs = 0L
79
+ var lastNativeDragScrollChangedNs = 0L
80
+ var lastNativePostTouchScrollChangedNs = 0L
81
+ var lastTouchMoveEventNs = 0L
82
+ var lastTouchMoveDispatchNs = 0L
83
+ var touchDownEventNs = 0L
84
+ var touchUpEventNs = 0L
85
+ var touchMoveEventCount = 0L
86
+ var touchMoveDispatchCount = 0L
87
+ var touchHistoricalSampleCount = 0L
88
+ var nativeScrollChangeCount = 0L
89
+ var firstNativeScrollChangedNs = 0L
90
+ var lastNativeScrollEventNs = 0L
91
+ var postUpScrollerCaptured = false
92
+ var postUpScrollerPresent = false
93
+ var postUpScrollerFinished = false
94
+ var postUpScrollerCurrentY = 0
95
+ var postUpScrollerFinalY = 0
96
+ var postUpScrollerVelocityPxPerSec = 0f
97
+ var postUpMaxScrollY = 0
98
+ var postUpViewScrollY = 0
99
+ var postTouchScrollerFrameSamples = 0L
100
+ var postTouchScrollerActiveFrameSamples = 0L
101
+ var postTouchScrollerFirstCurrentY = 0
102
+ var postTouchScrollerLastCurrentY = 0
103
+ var postTouchScrollerLastFinalY = 0
104
+ var postTouchScrollerMaxCurrentDeltaPx = 0
105
+ var postTouchViewFirstY = 0
106
+ var postTouchViewLastY = 0
107
+ var updateIntervalCount = 0L
108
+ var drawUpdateIntervalCount = 0L
109
+ var windowFrameUpdateIntervalCount = 0L
110
+ var activeVsyncSamples = 0L
111
+ var changedVsyncSamples = 0L
112
+ var repeatedVsyncSamples = 0L
113
+ var activeDrawSamples = 0L
114
+ var changedDrawSamples = 0L
115
+ var repeatedDrawSamples = 0L
116
+ var activeWindowFrameSamples = 0L
117
+ var changedWindowFrameSamples = 0L
118
+ var repeatedWindowFrameSamples = 0L
119
+ var activeDurationNs = 0L
120
+ var drawActiveDurationNs = 0L
121
+ var windowFrameActiveDurationNs = 0L
122
+ var maxStallNs = 0L
123
+ var drawMaxStallNs = 0L
124
+ var windowFrameMaxStallNs = 0L
125
+ }
126
+
127
+ private val states = IdentityHashMap<View, TargetState>()
128
+ private val providerTargets = IdentityHashMap<View, Boolean>()
129
+ private val activeTargets = ArrayList<View>()
130
+ private val frameTimesNs = ArrayList<Long>()
131
+ private val windowFrameTimesNs = ArrayList<Long>()
132
+ private val mainHandler by lazy(LazyThreadSafetyMode.NONE) { android.os.Handler(android.os.Looper.getMainLooper()) }
133
+ private var root: View? = null
134
+ private var frameMetricsWindow: Window? = null
135
+ private var pageLabel = "unlabeled"
136
+ private var running = false
137
+ private var touchActive = false
138
+ private var touchTarget: View? = null
139
+ private var postTouchTarget: View? = null
140
+ private var touchUpEventNs = 0L
141
+ private var lastFocusTarget: View? = null
142
+ private var sessionStartNs = 0L
143
+ private var lastFrameTimeNs = 0L
144
+ private var lastDrawFrameNs = 0L
145
+ private var estimatedVsyncSlots = 0L
146
+ private var missedVsyncSlots = 0L
147
+ private var windowFrameDroppedCallbacks = 0L
148
+ private var displayRefreshHz = 0f
149
+ private var layoutRefreshPosted = false
150
+ private var scrollerFieldLookupComplete = false
151
+ private var scrollerField: java.lang.reflect.Field? = null
152
+
153
+ private val frameCallback = object : Choreographer.FrameCallback {
154
+ override fun doFrame(frameTimeNanos: Long) {
155
+ if (!running) return
156
+ sampleVsync(frameTimeNanos)
157
+ Choreographer.getInstance().postFrameCallback(this)
158
+ }
159
+ }
160
+
161
+ private val drawListener = ViewTreeObserver.OnDrawListener {
162
+ if (running) sampleRootDraw(lastFrameTimeNs)
163
+ }
164
+
165
+ /** Captures the actual native scroll callback, before frame-level sampling. */
166
+ private val scrollChangedListener = ViewTreeObserver.OnScrollChangedListener {
167
+ if (running) sampleNativeScrollChanged(System.nanoTime())
168
+ }
169
+
170
+ private val frameMetricsListener = Window.OnFrameMetricsAvailableListener { _, metrics, dropped ->
171
+ if (running) sampleWindowFrame(metrics, dropped)
172
+ }
173
+
174
+ private val globalLayoutListener = ViewTreeObserver.OnGlobalLayoutListener {
175
+ if (running && !layoutRefreshPosted) {
176
+ layoutRefreshPosted = true
177
+ mainHandler.postDelayed({
178
+ layoutRefreshPosted = false
179
+ if (running) refreshTargets()
180
+ }, 80L)
181
+ }
182
+ }
183
+
184
+ private val attachListener = object : View.OnAttachStateChangeListener {
185
+ override fun onViewAttachedToWindow(view: View) {
186
+ if (running) refreshTargets()
187
+ }
188
+
189
+ override fun onViewDetachedFromWindow(view: View) = Unit
190
+ }
191
+
192
+ /** Start sampling against the Activity's decor root. Must be called on main. */
193
+ @JvmStatic
194
+ public fun start(rootView: View, refreshRateHz: Float, activityWindow: Window? = null) {
195
+ runOnMain {
196
+ if (root === rootView && running) {
197
+ displayRefreshHz = refreshRateHz
198
+ return@runOnMain
199
+ }
200
+ stopOnMain()
201
+ root = rootView
202
+ displayRefreshHz = refreshRateHz
203
+ rootView.addOnAttachStateChangeListener(attachListener)
204
+ frameMetricsWindow = activityWindow ?: findActivityWindow(rootView.context)
205
+ frameMetricsWindow?.addOnFrameMetricsAvailableListener(frameMetricsListener, mainHandler)
206
+ val observer = rootView.viewTreeObserver
207
+ if (observer.isAlive) {
208
+ observer.addOnGlobalLayoutListener(globalLayoutListener)
209
+ observer.addOnDrawListener(drawListener)
210
+ observer.addOnScrollChangedListener(scrollChangedListener)
211
+ }
212
+ running = true
213
+ beginSessionOnMain("benchmark")
214
+ Choreographer.getInstance().postFrameCallback(frameCallback)
215
+ }
216
+ }
217
+
218
+ /** Begin an isolated page measurement after route warmup and before navigation. */
219
+ @JvmStatic
220
+ public fun beginSession(page: String) {
221
+ if (android.os.Looper.myLooper() == android.os.Looper.getMainLooper()) {
222
+ if (running) beginSessionOnMain(page)
223
+ return
224
+ }
225
+ val completed = CountDownLatch(1)
226
+ mainHandler.post {
227
+ try {
228
+ if (running) beginSessionOnMain(page)
229
+ } finally {
230
+ completed.countDown()
231
+ }
232
+ }
233
+ completed.await(2, TimeUnit.SECONDS)
234
+ }
235
+
236
+ /** Receives Activity-dispatched MotionEvents before child views, without intercepting them. */
237
+ @JvmStatic
238
+ public fun onMotionEvent(event: MotionEvent) {
239
+ if (!running) return
240
+ val eventTimeNs = event.eventTime * 1_000_000L
241
+ when (event.actionMasked) {
242
+ MotionEvent.ACTION_DOWN -> {
243
+ touchTarget = findTargetAt(event.rawX.toInt(), event.rawY.toInt())
244
+ postTouchTarget = null
245
+ touchUpEventNs = 0L
246
+ lastFocusTarget = touchTarget
247
+ touchActive = touchTarget != null
248
+ touchTarget?.let { target ->
249
+ synchronized(states) {
250
+ states[target]?.let { state ->
251
+ // Separate drags must not inherit the idle gap between ADB/user gestures
252
+ // as if content had stalled while continuously moving.
253
+ state.lastChangedNs = 0L
254
+ state.drawLastChangedNs = 0L
255
+ state.windowFrameLastChangedNs = 0L
256
+ state.lastDragChangedNs = 0L
257
+ state.lastPostTouchChangedNs = 0L
258
+ state.lastNativeScrollChangedNs = 0L
259
+ state.lastNativeDragScrollChangedNs = 0L
260
+ state.lastNativePostTouchScrollChangedNs = 0L
261
+ state.lastTouchMoveEventNs = 0L
262
+ state.lastTouchMoveDispatchNs = 0L
263
+ state.touchDownEventNs = eventTimeNs
264
+ state.touchUpEventNs = 0L
265
+ }
266
+ }
267
+ }
268
+ }
269
+ MotionEvent.ACTION_MOVE -> {
270
+ val target = touchTarget
271
+ if (touchActive && target != null) {
272
+ synchronized(states) {
273
+ states[target]?.let { state ->
274
+ recordTouchMoveDispatch(state, eventTimeNs)
275
+ for (historyIndex in 0 until event.historySize) {
276
+ recordTouchMove(state, event.getHistoricalEventTime(historyIndex) * 1_000_000L, historical = true)
277
+ }
278
+ recordTouchMove(state, eventTimeNs, historical = false)
279
+ if (Build.VERSION.SDK_INT >= 29) {
280
+ val traceId = "${traceSafe(pageLabel)}.${traceSafe(state.identity)}"
281
+ Trace.setCounter("NewHu.EffectiveScroll.$traceId.touchEventNs", eventTimeNs)
282
+ Trace.setCounter("NewHu.EffectiveScroll.$traceId.touchX", event.rawX.toLong())
283
+ Trace.setCounter("NewHu.EffectiveScroll.$traceId.touchY", event.rawY.toLong())
284
+ }
285
+ }
286
+ }
287
+ }
288
+ }
289
+ MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
290
+ val target = touchTarget
291
+ if (target != null) {
292
+ synchronized(states) {
293
+ states[target]?.touchUpEventNs = eventTimeNs
294
+ }
295
+ postTouchTarget = target
296
+ touchUpEventNs = eventTimeNs
297
+ // dispatchTouchEvent runs before the native ScrollView sees ACTION_UP.
298
+ // Capture on the next main-loop turn so the scroller reflects the
299
+ // velocity decision made by ReactScrollView for this release.
300
+ mainHandler.post { capturePostUpScroller(target) }
301
+ }
302
+ touchActive = false
303
+ }
304
+ }
305
+ }
306
+
307
+ /** Merge the provider adapter's already-discovered RN scroll descendants into the window probe. */
308
+ @JvmStatic
309
+ public fun registerProviderTargets(views: Collection<View>) {
310
+ if (!running) return
311
+ runOnMain {
312
+ if (!running) return@runOnMain
313
+ synchronized(states) {
314
+ views.forEach { view ->
315
+ if (view.parent != null && isScrollContainer(view)) {
316
+ providerTargets[view] = true
317
+ if (!activeTargets.contains(view)) activeTargets.add(view)
318
+ if (!states.containsKey(view)) states[view] = TargetState(view, identityFor(view))
319
+ }
320
+ }
321
+ }
322
+ }
323
+ }
324
+
325
+ /** Numeric map is safe for the existing Expo telemetry bridge. */
326
+ @JvmStatic
327
+ public fun snapshot(): Map<String, Number> = synchronized(states) {
328
+ val result = linkedMapOf<String, Number>()
329
+ val durationNs = (SystemClock.elapsedRealtimeNanos() - sessionStartNs).coerceAtLeast(1L)
330
+ result["effectiveScrollProbe.enabled"] = if (running) 1 else 0
331
+ result["effectiveScrollProbe.displayRefreshHz"] = displayRefreshHz
332
+ result["effectiveScrollProbe.elapsedMs"] = durationNs / 1_000_000.0
333
+ result["effectiveScrollProbe.vsyncSamples"] = estimatedVsyncSlots
334
+ result["effectiveScrollProbe.vsyncFps"] = estimatedVsyncSlots * 1_000_000_000.0 / durationNs
335
+ result["effectiveScrollProbe.missedVsyncSlots"] = missedVsyncSlots
336
+ result["effectiveScrollProbe.choreographerCallbackSamples"] = frameTimesNs.size
337
+ result["effectiveScrollProbe.choreographerCallbackFps"] = frameTimesNs.size * 1_000_000_000.0 / durationNs
338
+ result["effectiveScrollProbe.choreographerCallbackIntervalP50Ms"] = percentile(frameIntervals(frameTimesNs), 0.50) / 1_000_000.0
339
+ result["effectiveScrollProbe.choreographerCallbackIntervalP95Ms"] = percentile(frameIntervals(frameTimesNs), 0.95) / 1_000_000.0
340
+ result["effectiveScrollProbe.windowFrameSamples"] = windowFrameTimesNs.size
341
+ result["effectiveScrollProbe.windowFrameFps"] = windowFrameTimesNs.size * 1_000_000_000.0 / durationNs
342
+ result["effectiveScrollProbe.windowFrameIntervalP50Ms"] = percentile(frameIntervals(windowFrameTimesNs), 0.50) / 1_000_000.0
343
+ result["effectiveScrollProbe.windowFrameIntervalP95Ms"] = percentile(frameIntervals(windowFrameTimesNs), 0.95) / 1_000_000.0
344
+ result["effectiveScrollProbe.windowFrameDroppedCallbacks"] = windowFrameDroppedCallbacks
345
+ result["effectiveScrollProbe.windowFrameProbeAttached"] = if (frameMetricsWindow != null) 1 else 0
346
+ result["effectiveScrollProbe.targetCount"] = states.values.count {
347
+ it.activeVsyncSamples > 0L || it.activeWindowFrameSamples > 0L
348
+ }
349
+ var index = 0
350
+ states.values
351
+ .filter { it.activeVsyncSamples > 0L || it.activeDrawSamples > 0L || it.activeWindowFrameSamples > 0L }
352
+ .sortedBy { it.identity }
353
+ .forEach { state ->
354
+ val prefix = "effectiveScrollProbe.target$index."
355
+ val vsyncIntervals = state.updateIntervalsNs
356
+ val drawIntervals = state.drawUpdateIntervalsNs
357
+ val dragIntervals = state.dragUpdateIntervalsNs
358
+ val postTouchIntervals = state.postTouchUpdateIntervalsNs
359
+ val touchIntervals = state.touchMoveIntervalsNs
360
+ val touchDispatchIntervals = state.touchMoveDispatchIntervalsNs
361
+ val nativeIntervals = state.nativeScrollIntervalsNs
362
+ val nativeDragIntervals = state.nativeDragScrollIntervalsNs
363
+ val nativePostTouchIntervals = state.nativePostTouchScrollIntervalsNs
364
+ val activeFps = fps(state.updateIntervalCount, state.activeDurationNs)
365
+ val drawFps = fps(state.drawUpdateIntervalCount, state.drawActiveDurationNs)
366
+ val windowFrameFps = fps(state.windowFrameUpdateIntervalCount, state.windowFrameActiveDurationNs)
367
+ val dragFps = fpsFromIntervals(dragIntervals)
368
+ val postTouchFps = fpsFromIntervals(postTouchIntervals)
369
+ val touchMoveFps = fpsFromIntervals(touchIntervals)
370
+ val touchMoveDispatchFps = fpsFromIntervals(touchDispatchIntervals)
371
+ val nativeScrollFps = fpsFromIntervals(nativeIntervals)
372
+ val nativeDragScrollFps = fpsFromIntervals(nativeDragIntervals)
373
+ val nativePostTouchScrollFps = fpsFromIntervals(nativePostTouchIntervals)
374
+ val oneVsyncCadenceLimitNs = if (displayRefreshHz > 0f) {
375
+ // Allow 5% timestamp jitter around one display period; the old
376
+ // 1.25x window mislabeled intervals up to 10.4ms as "8ms" at 120Hz.
377
+ (1_000_000_000.0 / displayRefreshHz * 1.05).toLong()
378
+ } else 8_750_000L
379
+ result[prefix + "identityHash"] = System.identityHashCode(state.view)
380
+ result[prefix + "nativeViewId"] = state.nativeViewId
381
+ result[prefix + "scrollX"] = state.sampledX
382
+ result[prefix + "scrollY"] = state.sampledY
383
+ result[prefix + "viewportWidth"] = state.sampledWidth
384
+ result[prefix + "viewportHeight"] = state.sampledHeight
385
+ result[prefix + "vsyncSamples"] = state.activeVsyncSamples
386
+ result[prefix + "recordedOffsetSamples"] = state.offsetSamples.size
387
+ result[prefix + "effectiveContentFrames"] = state.changedVsyncSamples
388
+ result[prefix + "duplicateContentFrames"] = state.repeatedVsyncSamples
389
+ result[prefix + "effectiveScrollFps"] = activeFps
390
+ result[prefix + "activeScrollDurationMs"] = state.activeDurationNs / 1_000_000.0
391
+ result[prefix + "dragContentFps"] = dragFps
392
+ result[prefix + "dragOffsetIntervalCount"] = dragIntervals.size
393
+ result[prefix + "dragOffsetIntervalP50Ms"] = percentile(dragIntervals, 0.50) / 1_000_000.0
394
+ result[prefix + "dragOffsetIntervalP95Ms"] = percentile(dragIntervals, 0.95) / 1_000_000.0
395
+ result[prefix + "postTouchContentFps"] = postTouchFps
396
+ result[prefix + "postTouchOffsetIntervalCount"] = postTouchIntervals.size
397
+ result[prefix + "postTouchOffsetIntervalP50Ms"] = percentile(postTouchIntervals, 0.50) / 1_000_000.0
398
+ result[prefix + "postTouchOffsetIntervalP95Ms"] = percentile(postTouchIntervals, 0.95) / 1_000_000.0
399
+ result[prefix + "touchDownEventTimeNs"] = state.touchDownEventNs
400
+ result[prefix + "touchUpEventTimeNs"] = state.touchUpEventNs
401
+ result[prefix + "touchMoveEventCount"] = state.touchMoveEventCount
402
+ result[prefix + "touchMoveEventFps"] = touchMoveFps
403
+ result[prefix + "touchMoveDispatchCount"] = state.touchMoveDispatchCount
404
+ result[prefix + "touchMoveDispatchFps"] = touchMoveDispatchFps
405
+ result[prefix + "touchMoveDispatchIntervalP50Ms"] = percentile(touchDispatchIntervals, 0.50) / 1_000_000.0
406
+ result[prefix + "touchMoveDispatchIntervalP95Ms"] = percentile(touchDispatchIntervals, 0.95) / 1_000_000.0
407
+ result[prefix + "touchHistoricalSampleCount"] = state.touchHistoricalSampleCount
408
+ result[prefix + "touchMoveIntervalCount"] = touchIntervals.size
409
+ result[prefix + "touchMoveIntervalP50Ms"] = percentile(touchIntervals, 0.50) / 1_000_000.0
410
+ result[prefix + "touchMoveIntervalP95Ms"] = percentile(touchIntervals, 0.95) / 1_000_000.0
411
+ result[prefix + "touchMoveMaxIntervalMs"] = (touchIntervals.maxOrNull() ?: 0L) / 1_000_000.0
412
+ result[prefix + "nativeScrollChangeCount"] = state.nativeScrollChangeCount
413
+ result[prefix + "nativeScrollEventFps"] = nativeScrollFps
414
+ result[prefix + "nativeScrollEventIntervalP50Ms"] = percentile(nativeIntervals, 0.50) / 1_000_000.0
415
+ result[prefix + "nativeScrollEventIntervalP95Ms"] = percentile(nativeIntervals, 0.95) / 1_000_000.0
416
+ result[prefix + "nativeDragScrollEventFps"] = nativeDragScrollFps
417
+ result[prefix + "nativeDragScrollEventIntervalP50Ms"] = percentile(nativeDragIntervals, 0.50) / 1_000_000.0
418
+ result[prefix + "nativeDragScrollEventIntervalP95Ms"] = percentile(nativeDragIntervals, 0.95) / 1_000_000.0
419
+ result[prefix + "nativePostTouchScrollEventFps"] = nativePostTouchScrollFps
420
+ result[prefix + "nativePostTouchScrollEventIntervalP50Ms"] = percentile(nativePostTouchIntervals, 0.50) / 1_000_000.0
421
+ result[prefix + "nativePostTouchScrollEventIntervalP95Ms"] = percentile(nativePostTouchIntervals, 0.95) / 1_000_000.0
422
+ result[prefix + "nativeScrollFirstEventTimeNs"] = state.firstNativeScrollChangedNs
423
+ result[prefix + "nativeScrollLastEventTimeNs"] = state.lastNativeScrollEventNs
424
+ result[prefix + "postUpScrollerCaptured"] = if (state.postUpScrollerCaptured) 1 else 0
425
+ result[prefix + "postUpScrollerPresent"] = if (state.postUpScrollerPresent) 1 else 0
426
+ result[prefix + "postUpScrollerFinished"] = if (state.postUpScrollerFinished) 1 else 0
427
+ result[prefix + "postUpScrollerCurrentY"] = state.postUpScrollerCurrentY
428
+ result[prefix + "postUpScrollerFinalY"] = state.postUpScrollerFinalY
429
+ result[prefix + "postUpScrollerDistancePx"] = state.postUpScrollerFinalY - state.postUpScrollerCurrentY
430
+ result[prefix + "postUpScrollerVelocityPxPerSec"] = state.postUpScrollerVelocityPxPerSec
431
+ result[prefix + "postUpMaxScrollY"] = state.postUpMaxScrollY
432
+ result[prefix + "postUpViewScrollY"] = state.postUpViewScrollY
433
+ result[prefix + "postTouchScrollerFrameSamples"] = state.postTouchScrollerFrameSamples
434
+ result[prefix + "postTouchScrollerActiveFrameSamples"] = state.postTouchScrollerActiveFrameSamples
435
+ result[prefix + "postTouchScrollerFirstCurrentY"] = state.postTouchScrollerFirstCurrentY
436
+ result[prefix + "postTouchScrollerLastCurrentY"] = state.postTouchScrollerLastCurrentY
437
+ result[prefix + "postTouchScrollerLastFinalY"] = state.postTouchScrollerLastFinalY
438
+ result[prefix + "postTouchScrollerMaxCurrentDeltaPx"] = state.postTouchScrollerMaxCurrentDeltaPx
439
+ result[prefix + "postTouchViewFirstY"] = state.postTouchViewFirstY
440
+ result[prefix + "postTouchViewLastY"] = state.postTouchViewLastY
441
+ result[prefix + "contentIntervalCount"] = state.updateIntervalCount
442
+ result[prefix + "contentIntervalWithinOneVsyncRatio"] = ratio(vsyncIntervals.count { it <= oneVsyncCadenceLimitNs }, vsyncIntervals.size)
443
+ result[prefix + "interval16_67msPlusRatio"] = ratio(vsyncIntervals.count { it >= 16_670_000L }, vsyncIntervals.size)
444
+ result[prefix + "interval25msPlusRatio"] = ratio(vsyncIntervals.count { it >= 25_000_000L }, vsyncIntervals.size)
445
+ result[prefix + "interval33_3msPlusRatio"] = ratio(vsyncIntervals.count { it >= 33_300_000L }, vsyncIntervals.size)
446
+ result[prefix + "interval50msPlusRatio"] = ratio(vsyncIntervals.count { it >= 50_000_000L }, vsyncIntervals.size)
447
+ result[prefix + "interval100msPlusRatio"] = ratio(vsyncIntervals.count { it >= 100_000_000L }, vsyncIntervals.size)
448
+ result[prefix + "contentIntervalP50Ms"] = percentile(vsyncIntervals, 0.50) / 1_000_000.0
449
+ result[prefix + "contentIntervalP90Ms"] = percentile(vsyncIntervals, 0.90) / 1_000_000.0
450
+ result[prefix + "contentIntervalP95Ms"] = percentile(vsyncIntervals, 0.95) / 1_000_000.0
451
+ result[prefix + "contentIntervalP99Ms"] = percentile(vsyncIntervals, 0.99) / 1_000_000.0
452
+ result[prefix + "maxContentStallMs"] = state.maxStallNs / 1_000_000.0
453
+ result[prefix + "drawSamples"] = state.activeDrawSamples
454
+ result[prefix + "drawChangedFrames"] = state.changedDrawSamples
455
+ result[prefix + "drawRepeatedFrames"] = state.repeatedDrawSamples
456
+ result[prefix + "drawEffectiveFps"] = drawFps
457
+ result[prefix + "drawActiveScrollDurationMs"] = state.drawActiveDurationNs / 1_000_000.0
458
+ result[prefix + "drawContentIntervalCount"] = state.drawUpdateIntervalCount
459
+ result[prefix + "drawContentIntervalP50Ms"] = percentile(drawIntervals, 0.50) / 1_000_000.0
460
+ result[prefix + "drawContentIntervalP95Ms"] = percentile(drawIntervals, 0.95) / 1_000_000.0
461
+ result[prefix + "drawMaxContentStallMs"] = state.drawMaxStallNs / 1_000_000.0
462
+ result[prefix + "windowFrameSamples"] = state.activeWindowFrameSamples
463
+ result[prefix + "windowFrameChangedFrames"] = state.changedWindowFrameSamples
464
+ result[prefix + "windowFrameDuplicateFrames"] = state.repeatedWindowFrameSamples
465
+ result[prefix + "windowFrameEffectiveFps"] = windowFrameFps
466
+ result[prefix + "windowFrameActiveDurationMs"] = state.windowFrameActiveDurationNs / 1_000_000.0
467
+ result[prefix + "windowFrameIntervalCount"] = state.windowFrameUpdateIntervalCount
468
+ result[prefix + "windowFrameContentIntervalP50Ms"] = percentile(state.windowFrameUpdateIntervalsNs, 0.50) / 1_000_000.0
469
+ result[prefix + "windowFrameContentIntervalP95Ms"] = percentile(state.windowFrameUpdateIntervalsNs, 0.95) / 1_000_000.0
470
+ result[prefix + "windowFrameMaxContentStallMs"] = state.windowFrameMaxStallNs / 1_000_000.0
471
+ Log.i(TAG, "[EFFECTIVE_SCROLL_FPS] page=$pageLabel target=${state.identity} " +
472
+ "contentFPS=${activeFps.format1()} drawFPS=${drawFps.format1()} " +
473
+ "changed=${state.changedVsyncSamples} duplicate=${state.repeatedVsyncSamples} " +
474
+ "p95Ms=${(percentile(vsyncIntervals, 0.95) / 1_000_000.0).format1()} " +
475
+ "maxStallMs=${(state.maxStallNs / 1_000_000.0).format1()}")
476
+ index += 1
477
+ }
478
+ result["effectiveScrollProbe.targetCount"] = index
479
+ result
480
+ }
481
+
482
+ private fun beginSessionOnMain(page: String) {
483
+ synchronized(states) {
484
+ pageLabel = page.replace(Regex("[^A-Za-z0-9_. -]"), "_")
485
+ states.clear()
486
+ providerTargets.clear()
487
+ frameTimesNs.clear()
488
+ windowFrameTimesNs.clear()
489
+ estimatedVsyncSlots = 0L
490
+ missedVsyncSlots = 0L
491
+ windowFrameDroppedCallbacks = 0L
492
+ sessionStartNs = SystemClock.elapsedRealtimeNanos()
493
+ lastFrameTimeNs = 0L
494
+ lastDrawFrameNs = 0L
495
+ touchActive = false
496
+ touchTarget = null
497
+ postTouchTarget = null
498
+ touchUpEventNs = 0L
499
+ lastFocusTarget = null
500
+ }
501
+ refreshTargets()
502
+ }
503
+
504
+ private fun refreshTargets() {
505
+ val rootView = root ?: return
506
+ activeTargets.clear()
507
+ collectTargets(rootView)
508
+ providerTargets.keys.forEach { view ->
509
+ if (view.parent != null && view.isShown && !activeTargets.contains(view)) {
510
+ activeTargets.add(view)
511
+ synchronized(states) {
512
+ if (!states.containsKey(view)) states[view] = TargetState(view, identityFor(view))
513
+ }
514
+ }
515
+ }
516
+ }
517
+
518
+ private fun collectTargets(view: View) {
519
+ if (view !== root && isScrollContainer(view)) {
520
+ if (view.isShown && view.windowVisibility == View.VISIBLE) {
521
+ activeTargets.add(view)
522
+ synchronized(states) {
523
+ if (!states.containsKey(view)) states[view] = TargetState(view, identityFor(view))
524
+ }
525
+ }
526
+ }
527
+ if (view is ViewGroup) {
528
+ for (index in 0 until view.childCount) collectTargets(view.getChildAt(index))
529
+ }
530
+ }
531
+
532
+ private fun sampleVsync(frameTimeNs: Long) {
533
+ val visible = activeTargets
534
+ val moved = ArrayList<View>()
535
+ visible.forEach { view ->
536
+ val state = synchronized(states) { states[view] } ?: return@forEach
537
+ val x = view.scrollX
538
+ val y = view.scrollY
539
+ if (x != state.previousX || y != state.previousY) moved.add(view)
540
+ }
541
+ val focus = chooseFocusTarget(moved, frameTimeNs)
542
+ synchronized(states) {
543
+ if (frameTimesNs.size < MAX_SAMPLES) frameTimesNs.add(frameTimeNs)
544
+ val frameDelta = if (lastFrameTimeNs > 0L) frameTimeNs - lastFrameTimeNs else 0L
545
+ val displayPeriodNs = if (displayRefreshHz > 0f) 1_000_000_000.0 / displayRefreshHz else 0.0
546
+ val frameSlots = if (frameDelta > 0L && displayPeriodNs > 0.0) {
547
+ max(1, (frameDelta / displayPeriodNs).roundToInt())
548
+ } else {
549
+ 1
550
+ }
551
+ estimatedVsyncSlots += frameSlots
552
+ missedVsyncSlots += (frameSlots - 1).toLong()
553
+ lastFrameTimeNs = frameTimeNs
554
+ visible.forEach { view ->
555
+ val state = states[view] ?: return@forEach
556
+ val x = view.scrollX
557
+ val y = view.scrollY
558
+ val deltaX = x - state.previousX
559
+ val deltaY = y - state.previousY
560
+ val changed = deltaX != 0 || deltaY != 0
561
+ val isDraggedTarget = touchActive && touchTarget === view
562
+ val isPostTouchTarget = isPostTouchCaptureActive(view, frameTimeNs)
563
+ if (isPostTouchTarget) {
564
+ samplePostTouchScroller(view, state, frameTimeNs)
565
+ }
566
+ state.sampledX = x
567
+ state.sampledY = y
568
+ state.sampledWidth = view.width
569
+ state.sampledHeight = view.height
570
+ if (changed) {
571
+ val previousChange = state.lastChangedNs
572
+ if (previousChange > 0L) {
573
+ val interval = frameTimeNs - previousChange
574
+ if (interval > 0L && (interval <= ACTIVE_TAIL_NS || isDraggedTarget || isPostTouchTarget)) {
575
+ addBounded(state.updateIntervalsNs, interval)
576
+ state.updateIntervalCount += 1L
577
+ state.activeDurationNs += interval
578
+ state.maxStallNs = max(state.maxStallNs, interval)
579
+ }
580
+ }
581
+ if (isDraggedTarget && state.lastDragChangedNs > 0L) {
582
+ addBounded(state.dragUpdateIntervalsNs, frameTimeNs - state.lastDragChangedNs)
583
+ } else if (isPostTouchTarget && state.lastPostTouchChangedNs > 0L) {
584
+ addBounded(state.postTouchUpdateIntervalsNs, frameTimeNs - state.lastPostTouchChangedNs)
585
+ }
586
+ if (isDraggedTarget) state.lastDragChangedNs = frameTimeNs
587
+ if (isPostTouchTarget) state.lastPostTouchChangedNs = frameTimeNs
588
+ state.lastChangedNs = frameTimeNs
589
+ state.previousX = x
590
+ state.previousY = y
591
+ lastFocusTarget = view
592
+ }
593
+ val withinActiveTail = state.lastChangedNs > 0L && frameTimeNs - state.lastChangedNs <= ACTIVE_TAIL_NS
594
+ val active = isDraggedTarget || view === focus || withinActiveTail
595
+ if (active) {
596
+ state.activeVsyncSamples += frameSlots.toLong()
597
+ if (changed) {
598
+ state.changedVsyncSamples += 1L
599
+ state.repeatedVsyncSamples += (frameSlots - 1).toLong()
600
+ } else {
601
+ state.repeatedVsyncSamples += frameSlots.toLong()
602
+ }
603
+ addBounded(state.offsetSamples, OffsetFrameSample(frameTimeNs, x, y, deltaX, deltaY, changed))
604
+ if (Build.VERSION.SDK_INT >= 29) {
605
+ val traceId = "${traceSafe(pageLabel)}.${traceSafe(state.identity)}"
606
+ Trace.setCounter("NewHu.EffectiveScroll.$traceId.offsetY", y.toLong())
607
+ Trace.setCounter("NewHu.EffectiveScroll.$traceId.deltaY", deltaY.toLong())
608
+ Trace.setCounter("NewHu.EffectiveScroll.$traceId.changed", if (changed) 1L else 0L)
609
+ }
610
+ if (isDraggedTarget && state.lastChangedNs > 0L) {
611
+ state.maxStallNs = max(state.maxStallNs, frameTimeNs - state.lastChangedNs)
612
+ }
613
+ if (state.lastActiveSampleNs > 0L && frameDelta > 0L && (frameDelta <= ACTIVE_TAIL_NS || isDraggedTarget)) {
614
+ // The sample cadence is also useful when a scroll is visibly stationary during a drag.
615
+ if (frameDelta > ACTIVE_TAIL_NS) state.maxStallNs = max(state.maxStallNs, frameDelta)
616
+ }
617
+ state.lastActiveSampleNs = frameTimeNs
618
+ }
619
+ }
620
+ }
621
+ }
622
+
623
+ private fun sampleNativeScrollChanged(eventTimeNs: Long) {
624
+ val visible = activeTargets
625
+ synchronized(states) {
626
+ visible.forEach { view ->
627
+ val state = states[view] ?: return@forEach
628
+ val x = view.scrollX
629
+ val y = view.scrollY
630
+ if (x == state.nativeX && y == state.nativeY) return@forEach
631
+ state.nativeX = x
632
+ state.nativeY = y
633
+ state.nativeScrollChangeCount += 1L
634
+ if (state.firstNativeScrollChangedNs == 0L) state.firstNativeScrollChangedNs = eventTimeNs
635
+ state.lastNativeScrollEventNs = eventTimeNs
636
+ val interval = if (state.lastNativeScrollChangedNs > 0L) eventTimeNs - state.lastNativeScrollChangedNs else 0L
637
+ val dragged = touchActive && touchTarget === view
638
+ val postTouch = isPostTouchCaptureActive(view, eventTimeNs)
639
+ if (interval > 0L && (interval <= ACTIVE_TAIL_NS || dragged || postTouch)) {
640
+ addBounded(state.nativeScrollIntervalsNs, interval)
641
+ if (dragged && state.lastNativeDragScrollChangedNs > 0L) {
642
+ addBounded(state.nativeDragScrollIntervalsNs, eventTimeNs - state.lastNativeDragScrollChangedNs)
643
+ } else if (postTouch && state.lastNativePostTouchScrollChangedNs > 0L) {
644
+ addBounded(state.nativePostTouchScrollIntervalsNs, eventTimeNs - state.lastNativePostTouchScrollChangedNs)
645
+ }
646
+ }
647
+ if (dragged) state.lastNativeDragScrollChangedNs = eventTimeNs
648
+ if (postTouch) state.lastNativePostTouchScrollChangedNs = eventTimeNs
649
+ state.lastNativeScrollChangedNs = eventTimeNs
650
+ if (Build.VERSION.SDK_INT >= 29) {
651
+ val traceId = "${traceSafe(pageLabel)}.${traceSafe(state.identity)}"
652
+ Trace.setCounter("NewHu.EffectiveScroll.$traceId.nativeOffsetY", y.toLong())
653
+ Trace.setCounter("NewHu.EffectiveScroll.$traceId.nativeScrollEventNs", eventTimeNs)
654
+ }
655
+ }
656
+ }
657
+ }
658
+
659
+ private fun capturePostUpScroller(view: View) {
660
+ val state = synchronized(states) { states[view] } ?: return
661
+ val scroller = findScroller(view)
662
+ val contentHeight = if (view is ViewGroup && view.childCount > 0) view.getChildAt(0).height else 0
663
+ val maxScrollY = (contentHeight - view.height + view.paddingTop + view.paddingBottom).coerceAtLeast(0)
664
+ synchronized(states) {
665
+ state.postUpScrollerCaptured = true
666
+ state.postUpScrollerPresent = scroller != null
667
+ state.postUpScrollerFinished = scroller?.isFinished ?: true
668
+ state.postUpScrollerCurrentY = scroller?.currY ?: view.scrollY
669
+ state.postUpScrollerFinalY = scroller?.finalY ?: view.scrollY
670
+ state.postUpScrollerVelocityPxPerSec = scroller?.currVelocity ?: 0f
671
+ state.postUpMaxScrollY = maxScrollY
672
+ state.postUpViewScrollY = view.scrollY
673
+ }
674
+ }
675
+
676
+ private fun samplePostTouchScroller(view: View, state: TargetState, frameTimeNs: Long) {
677
+ if (state.postTouchScrollerFrameSamples >= 60L || frameTimeNs - touchUpEventNs > 500_000_000L) return
678
+ val scroller = findScroller(view) ?: return
679
+ val currentY = scroller.currY
680
+ val finished = scroller.isFinished
681
+ synchronized(states) {
682
+ if (state.postTouchScrollerFrameSamples == 0L) {
683
+ state.postTouchScrollerFirstCurrentY = currentY
684
+ state.postTouchViewFirstY = view.scrollY
685
+ }
686
+ state.postTouchScrollerFrameSamples += 1L
687
+ if (!finished) state.postTouchScrollerActiveFrameSamples += 1L
688
+ state.postTouchScrollerLastCurrentY = currentY
689
+ state.postTouchScrollerLastFinalY = scroller.finalY
690
+ state.postTouchScrollerMaxCurrentDeltaPx = max(
691
+ state.postTouchScrollerMaxCurrentDeltaPx,
692
+ kotlin.math.abs(currentY - state.postUpScrollerCurrentY),
693
+ )
694
+ state.postTouchViewLastY = view.scrollY
695
+ }
696
+ if (Build.VERSION.SDK_INT >= 29) {
697
+ val traceId = "${traceSafe(pageLabel)}.${traceSafe(state.identity)}"
698
+ Trace.setCounter("NewHu.EffectiveScroll.$traceId.scrollerCurrentY", currentY.toLong())
699
+ Trace.setCounter("NewHu.EffectiveScroll.$traceId.scrollerFinalY", scroller.finalY.toLong())
700
+ Trace.setCounter("NewHu.EffectiveScroll.$traceId.scrollerFinished", if (finished) 1L else 0L)
701
+ Trace.setCounter("NewHu.EffectiveScroll.$traceId.viewScrollY", view.scrollY.toLong())
702
+ }
703
+ }
704
+
705
+ private fun findScroller(view: View): OverScroller? {
706
+ val field = synchronized(this) {
707
+ if (!scrollerFieldLookupComplete) {
708
+ var type: Class<*>? = view.javaClass
709
+ while (type != null && scrollerField == null) {
710
+ val currentType = type
711
+ scrollerField = runCatching { currentType.getDeclaredField("mScroller").apply { isAccessible = true } }.getOrNull()
712
+ type = currentType.superclass
713
+ }
714
+ scrollerFieldLookupComplete = true
715
+ }
716
+ scrollerField
717
+ } ?: return null
718
+ return runCatching { field.get(view) as? OverScroller }.getOrNull()
719
+ }
720
+
721
+ private fun sampleRootDraw(frameTimeNsRaw: Long) {
722
+ val frameTimeNs = frameTimeNsRaw.takeIf { it > 0L } ?: System.nanoTime()
723
+ if (frameTimeNs == lastDrawFrameNs) return
724
+ lastDrawFrameNs = frameTimeNs
725
+ val visible = activeTargets
726
+ synchronized(states) {
727
+ visible.forEach { view ->
728
+ val state = states[view] ?: return@forEach
729
+ val x = view.scrollX
730
+ val y = view.scrollY
731
+ val deltaX = x - state.previousDrawX
732
+ val deltaY = y - state.previousDrawY
733
+ val changed = deltaX != 0 || deltaY != 0
734
+ state.sampledX = x
735
+ state.sampledY = y
736
+ state.sampledWidth = view.width
737
+ state.sampledHeight = view.height
738
+ val isDraggedTarget = touchActive && touchTarget === view
739
+ val isPostTouchTarget = isPostTouchCaptureActive(view, frameTimeNs)
740
+ if (changed) {
741
+ val previousChange = state.drawLastChangedNs
742
+ if (previousChange > 0L) {
743
+ val interval = frameTimeNs - previousChange
744
+ if (interval > 0L && (interval <= ACTIVE_TAIL_NS || isDraggedTarget || isPostTouchTarget)) {
745
+ addBounded(state.drawUpdateIntervalsNs, interval)
746
+ state.drawUpdateIntervalCount += 1L
747
+ state.drawActiveDurationNs += interval
748
+ state.drawMaxStallNs = max(state.drawMaxStallNs, interval)
749
+ }
750
+ }
751
+ state.drawLastChangedNs = frameTimeNs
752
+ state.previousDrawX = x
753
+ state.previousDrawY = y
754
+ lastFocusTarget = view
755
+ }
756
+ val withinActiveTail = state.drawLastChangedNs > 0L && frameTimeNs - state.drawLastChangedNs <= ACTIVE_TAIL_NS
757
+ val active = isDraggedTarget || view === lastFocusTarget || withinActiveTail
758
+ if (active) {
759
+ state.activeDrawSamples += 1L
760
+ if (changed) state.changedDrawSamples += 1L else state.repeatedDrawSamples += 1L
761
+ if (isDraggedTarget && state.drawLastChangedNs > 0L) {
762
+ state.drawMaxStallNs = max(state.drawMaxStallNs, frameTimeNs - state.drawLastChangedNs)
763
+ }
764
+ }
765
+ }
766
+ }
767
+ }
768
+
769
+ /** Samples the view offset only when Android reports a completed Window frame. */
770
+ private fun sampleWindowFrame(metrics: FrameMetrics, droppedSinceLast: Int) {
771
+ val intendedVsyncNs = metrics.getMetric(FrameMetrics.INTENDED_VSYNC_TIMESTAMP)
772
+ val frameTimeNs = metrics.getMetric(FrameMetrics.VSYNC_TIMESTAMP).takeIf { it > 0L }
773
+ ?: intendedVsyncNs.takeIf { it > 0L }
774
+ ?: System.nanoTime()
775
+ if (windowFrameTimesNs.size < MAX_SAMPLES) windowFrameTimesNs.add(frameTimeNs)
776
+ if (droppedSinceLast > 0) windowFrameDroppedCallbacks += droppedSinceLast.toLong()
777
+
778
+ val visible = activeTargets
779
+ val moved = visible.filter { view ->
780
+ val state = synchronized(states) { states[view] } ?: return@filter false
781
+ view.scrollX != state.previousWindowFrameX || view.scrollY != state.previousWindowFrameY
782
+ }
783
+ val focus = chooseFocusTarget(moved, frameTimeNs)
784
+ synchronized(states) {
785
+ visible.forEach { view ->
786
+ val state = states[view] ?: return@forEach
787
+ val x = view.scrollX
788
+ val y = view.scrollY
789
+ val changed = x != state.previousWindowFrameX || y != state.previousWindowFrameY
790
+ val dragged = touchActive && touchTarget === view
791
+ val postTouch = isPostTouchCaptureActive(view, frameTimeNs)
792
+ if (changed) {
793
+ val previousChange = state.windowFrameLastChangedNs
794
+ if (previousChange > 0L) {
795
+ val interval = frameTimeNs - previousChange
796
+ if (interval > 0L && (interval <= ACTIVE_TAIL_NS || dragged || postTouch)) {
797
+ addBounded(state.windowFrameUpdateIntervalsNs, interval)
798
+ state.windowFrameUpdateIntervalCount += 1L
799
+ state.windowFrameActiveDurationNs += interval
800
+ state.windowFrameMaxStallNs = max(state.windowFrameMaxStallNs, interval)
801
+ }
802
+ }
803
+ state.windowFrameLastChangedNs = frameTimeNs
804
+ state.previousWindowFrameX = x
805
+ state.previousWindowFrameY = y
806
+ }
807
+ val withinActiveTail = state.windowFrameLastChangedNs > 0L &&
808
+ frameTimeNs - state.windowFrameLastChangedNs <= ACTIVE_TAIL_NS
809
+ if (dragged || view === focus || withinActiveTail) {
810
+ state.activeWindowFrameSamples += 1L
811
+ if (changed) state.changedWindowFrameSamples += 1L
812
+ else state.repeatedWindowFrameSamples += 1L
813
+ }
814
+ }
815
+ }
816
+ }
817
+
818
+ private fun chooseFocusTarget(moved: List<View>, nowNs: Long): View? {
819
+ val dragged = touchTarget?.takeIf { touchActive && activeTargets.contains(it) }
820
+ if (dragged != null) return dragged
821
+ if (moved.isNotEmpty()) return moved.maxByOrNull(::viewDepth)
822
+ val previous = lastFocusTarget ?: return null
823
+ val state = synchronized(states) { states[previous] }
824
+ return previous.takeIf { state != null && state.lastChangedNs > 0L && nowNs - state.lastChangedNs <= ACTIVE_TAIL_NS }
825
+ }
826
+
827
+ private fun recordTouchMoveDispatch(state: TargetState, eventTimeNs: Long) {
828
+ if (state.lastTouchMoveDispatchNs > 0L) {
829
+ val interval = eventTimeNs - state.lastTouchMoveDispatchNs
830
+ if (interval > 0L) addBounded(state.touchMoveDispatchIntervalsNs, interval)
831
+ }
832
+ state.lastTouchMoveDispatchNs = eventTimeNs
833
+ state.touchMoveDispatchCount += 1L
834
+ }
835
+
836
+ private fun recordTouchMove(state: TargetState, eventTimeNs: Long, historical: Boolean) {
837
+ if (state.lastTouchMoveEventNs > 0L) {
838
+ val interval = eventTimeNs - state.lastTouchMoveEventNs
839
+ if (interval > 0L) addBounded(state.touchMoveIntervalsNs, interval)
840
+ }
841
+ state.lastTouchMoveEventNs = eventTimeNs
842
+ state.touchMoveEventCount += 1L
843
+ if (historical) state.touchHistoricalSampleCount += 1L
844
+ }
845
+
846
+ private fun isPostTouchCaptureActive(view: View, frameTimeNs: Long): Boolean =
847
+ postTouchTarget === view && touchUpEventNs > 0L &&
848
+ frameTimeNs >= touchUpEventNs && frameTimeNs - touchUpEventNs <= POST_TOUCH_CAPTURE_WINDOW_NS
849
+
850
+ private fun findTargetAt(rawX: Int, rawY: Int): View? {
851
+ var best: View? = null
852
+ var bestDepth = -1
853
+ var bestArea = Long.MAX_VALUE
854
+ val rect = android.graphics.Rect()
855
+ for (view in activeTargets) {
856
+ if (!view.isShown || !view.getGlobalVisibleRect(rect) || !rect.contains(rawX, rawY) || !canScroll(view)) continue
857
+ val depth = viewDepth(view)
858
+ val area = rect.width().toLong() * rect.height().toLong()
859
+ if (depth > bestDepth || (depth == bestDepth && area < bestArea)) {
860
+ best = view
861
+ bestDepth = depth
862
+ bestArea = area
863
+ }
864
+ }
865
+ return best
866
+ }
867
+
868
+ private fun viewDepth(view: View): Int {
869
+ var depth = 0
870
+ var parent = view.parent
871
+ while (parent is View && parent !== root) {
872
+ depth += 1
873
+ parent = parent.parent
874
+ }
875
+ return depth
876
+ }
877
+
878
+ private fun isScrollContainer(view: View): Boolean {
879
+ if (view is ScrollView || view is HorizontalScrollView) return true
880
+ var type: Class<*>? = view.javaClass
881
+ while (type != null && type != Any::class.java) {
882
+ val name = type.simpleName
883
+ if (name.endsWith("ScrollView") || name == "RecyclerView") return true
884
+ type = type.superclass
885
+ }
886
+ return false
887
+ }
888
+
889
+ private fun canScroll(view: View): Boolean =
890
+ view.canScrollVertically(-1) || view.canScrollVertically(1) ||
891
+ view.canScrollHorizontally(-1) || view.canScrollHorizontally(1)
892
+
893
+ private fun identityFor(view: View): String =
894
+ "${view.javaClass.simpleName.ifEmpty { "View" }}_id${view.id}_h${Integer.toHexString(System.identityHashCode(view))}"
895
+
896
+ private fun findActivityWindow(context: Context): Window? {
897
+ var current: Context? = context
898
+ while (current != null) {
899
+ if (current is Activity) return current.window
900
+ val wrapper = current as? ContextWrapper ?: return null
901
+ val next = wrapper.baseContext
902
+ if (next === current) return null
903
+ current = next
904
+ }
905
+ return null
906
+ }
907
+
908
+ private fun stopOnMain() {
909
+ if (!running) return
910
+ running = false
911
+ Choreographer.getInstance().removeFrameCallback(frameCallback)
912
+ frameMetricsWindow?.removeOnFrameMetricsAvailableListener(frameMetricsListener)
913
+ frameMetricsWindow = null
914
+ root?.removeOnAttachStateChangeListener(attachListener)
915
+ root?.viewTreeObserver?.takeIf { it.isAlive }?.let {
916
+ it.removeOnGlobalLayoutListener(globalLayoutListener)
917
+ it.removeOnDrawListener(drawListener)
918
+ it.removeOnScrollChangedListener(scrollChangedListener)
919
+ }
920
+ touchTarget = null
921
+ touchActive = false
922
+ activeTargets.clear()
923
+ root = null
924
+ }
925
+
926
+ @JvmStatic
927
+ public fun stop() { runOnMain(::stopOnMain) }
928
+
929
+ private fun runOnMain(action: () -> Unit) {
930
+ if (android.os.Looper.myLooper() == android.os.Looper.getMainLooper()) action()
931
+ else mainHandler.post(action)
932
+ }
933
+
934
+ private fun frameIntervals(times: List<Long>): List<Long> =
935
+ times.zipWithNext { first, second -> second - first }.filter { it > 0L }
936
+
937
+ private fun addBounded(values: MutableList<Long>, value: Long) {
938
+ if (values.size < MAX_SAMPLES) values.add(value)
939
+ }
940
+
941
+ private fun addBounded(values: MutableList<OffsetFrameSample>, value: OffsetFrameSample) {
942
+ if (values.size < MAX_SAMPLES) values.add(value)
943
+ }
944
+
945
+ private fun traceSafe(value: String): String = value.replace(Regex("[^A-Za-z0-9_.-]"), "_")
946
+
947
+ private fun percentile(values: List<Long>, p: Double): Double {
948
+ if (values.isEmpty()) return 0.0
949
+ val sorted = values.sorted()
950
+ return sorted[((sorted.size - 1) * p).toInt()].toDouble()
951
+ }
952
+
953
+ private fun fps(intervalCount: Long, durationNs: Long): Double =
954
+ if (intervalCount <= 0L || durationNs <= 0L) 0.0 else intervalCount * 1_000_000_000.0 / durationNs
955
+
956
+ private fun fpsFromIntervals(intervals: List<Long>): Double {
957
+ val durationNs = intervals.sum()
958
+ return if (intervals.isEmpty() || durationNs <= 0L) 0.0
959
+ else intervals.size * 1_000_000_000.0 / durationNs
960
+ }
961
+
962
+ private fun ratio(part: Int, total: Int): Double = if (total <= 0) 0.0 else part.toDouble() * 100.0 / total
963
+
964
+ private fun Double.format1(): String = String.format(java.util.Locale.US, "%.1f", this)
965
+ }