@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,1459 @@
1
+ package com.newhu.liquidglass.backdrop.internal
2
+
3
+ import android.graphics.BitmapShader
4
+ import android.graphics.Canvas
5
+ import android.graphics.Color
6
+ import android.graphics.ColorMatrix
7
+ import android.graphics.ColorMatrixColorFilter
8
+ import android.graphics.LinearGradient
9
+ import android.graphics.Paint
10
+ import android.graphics.Path
11
+ import android.graphics.PorterDuff
12
+ import android.graphics.PorterDuffXfermode
13
+ import android.graphics.RectF
14
+ import android.graphics.RenderEffect
15
+ import android.graphics.RenderNode
16
+ import android.graphics.RuntimeShader
17
+ import android.graphics.Shader
18
+ import android.os.Looper
19
+ import androidx.annotation.RequiresApi
20
+ import com.newhu.liquidglass.core.GlassUniforms
21
+ import com.newhu.liquidglass.core.GlassOpticsModel
22
+ import com.newhu.liquidglass.core.GlassOpticalInsets
23
+ import com.newhu.liquidglass.core.SdfScaleLensConfig
24
+ import com.newhu.liquidglass.core.shader.HeightFieldGlassShader
25
+ import com.newhu.liquidglass.core.shader.SdfScaleLensShader
26
+ import com.newhu.liquidglass.core.geometry.G2RoundedRectangle
27
+ import com.newhu.liquidglass.core.geometry.ReferenceG2MaskTexture
28
+ import com.newhu.liquidglass.core.shader.ReferenceParityGlassShader
29
+ import com.newhu.liquidglass.core.shader.ReferenceGaussianDiscBackdropBlur
30
+ import com.newhu.liquidglass.telemetry.LiquidGlassPerfTelemetry
31
+ import com.newhu.liquidglass.rendering.RetainedBackdropLayer
32
+ import kotlin.math.abs
33
+ import kotlin.math.ceil
34
+ import kotlin.math.cos
35
+ import kotlin.math.floor
36
+ import kotlin.math.max
37
+ import kotlin.math.min
38
+ import kotlin.math.sin
39
+
40
+ private const val MIN_BLUR_RADIUS_PX = 0.05f
41
+ private const val SATURATION_EPSILON = 0.01f
42
+
43
+ /** Everything the renderer needs for one frame, resolved to pixels. */
44
+ internal class GlassFrame(
45
+ var widthPx: Float = 0f,
46
+ var heightPx: Float = 0f,
47
+ var cornerRadiusPx: Float = 0f,
48
+ var shapeMaskText: String? = null,
49
+ var shapeMaskFontSizePx: Float = 0f,
50
+ var shapeMaskFontWeight: Int = 700,
51
+ var progressiveBlurIntensity: Float = 0f,
52
+ var opticsModel: GlassOpticsModel = GlassOpticsModel.HEIGHT_FIELD,
53
+ var sdfScaleLens: SdfScaleLensConfig = SdfScaleLensConfig(),
54
+ var dispersion: Float = 0f,
55
+ var referenceHighlightAmbient: Boolean = false,
56
+ var densityScale: Float = 1f,
57
+ var blurRadiusPx: Float = 0f,
58
+ var backdropAlreadyBlurred: Boolean = false,
59
+ var refractionHeightPx: Float = 0f,
60
+ var refractionAmountPx: Float = 0f,
61
+ var referenceDepthEffect: Boolean = false,
62
+ var bodyRefractionAmountPx: Float = 0f,
63
+ var contentScaleX: Float = 1f,
64
+ var contentScaleY: Float = 1f,
65
+ var contentOffsetXPx: Float = 0f,
66
+ var contentOffsetYPx: Float = 0f,
67
+ /** View-layer scale applied after the backdrop shader, matching Compose graphicsLayer. */
68
+ var layerScaleX: Float = 1f,
69
+ var layerScaleY: Float = 1f,
70
+ var layerTranslationXPx: Float = 0f,
71
+ var layerTranslationYPx: Float = 0f,
72
+ var interactionProgress: Float = 0f,
73
+ var saturation: Float = 1f,
74
+ var brightness: Float = 0f,
75
+ var contrast: Float = 1f,
76
+ var tintColor: Int = Color.TRANSPARENT,
77
+ var tintAlpha: Float = 1f,
78
+ var surfaceColor: Int = Color.TRANSPARENT,
79
+ var referenceHighlightStyle: Int = 0,
80
+ var referenceHighlightFalloff: Float = 1f,
81
+ var referenceHighlightColor: Int = Color.WHITE,
82
+ var referenceInteractionProfile: Int = 0,
83
+ var referenceToggleFraction: Float = 0f,
84
+ var referenceToggleTrackColorOff: Int = Color.TRANSPARENT,
85
+ var referenceToggleTrackColorOn: Int = Color.TRANSPARENT,
86
+ var referenceToggleTrackWidthPx: Float = 0f,
87
+ var referenceToggleTrackHeightPx: Float = 0f,
88
+ var referenceToggleUseSolidBackdropColor: Boolean = false,
89
+ var referenceToggleSolidBackdropColor: Int = Color.TRANSPARENT,
90
+ var referenceToggleBackdropEnabled: Boolean = false,
91
+ var referenceOverlayColor: Int = Color.TRANSPARENT,
92
+ var referenceOverlayAlpha: Float = 0f,
93
+ var referenceOverlayBlackAlpha: Float = 0f,
94
+ var chromaticAberration: Float = 0f,
95
+ var noiseAlpha: Float = 0f,
96
+ var highlightAlpha: Float = 0f,
97
+ var specularStrength: Float = 1f,
98
+ var fresnelStrength: Float = 0.85f,
99
+ var innerShadowStrength: Float = 0.18f,
100
+ var outerShadowAlpha: Float = 0f,
101
+ var outerShadowRadiusPx: Float = 0f,
102
+ var outerShadowOffsetYPx: Float = 0f,
103
+ var highlightWidthPx: Float = 0f,
104
+ var displacementOnlyDebug: Boolean = false,
105
+ var sdfDisplacementMapDebug: Boolean = false,
106
+ var lightAngleDegrees: Float = 245f,
107
+ var pressAmount: Float = 0f,
108
+ var pressX: Float = 0f,
109
+ var pressY: Float = 0f,
110
+ var relativeX: Float = 0f,
111
+ var relativeY: Float = 0f,
112
+ var motionX: Float = 0f,
113
+ var motionY: Float = 0f,
114
+ )
115
+
116
+ /**
117
+ * Per-view drawing engine for the View system, mirroring the Compose
118
+ * `GlassPainter` tier behavior with [RenderNode]/[RenderEffect] primitives and
119
+ * the shared AGSL program from `liquidglass-core`.
120
+ */
121
+ internal class GlassViewRenderer {
122
+
123
+ private val backdropLayer = RetainedBackdropLayer("LiquidGlass")
124
+ private var runtimeShader: RuntimeShader? = null
125
+ private var sdfScaleLensShader: RuntimeShader? = null
126
+ private var referenceParityShader: RuntimeShader? = null
127
+ private var referenceBackdropBlur: ReferenceGaussianDiscBackdropBlur? = null
128
+ private var referenceSystemBlurEffect: RenderEffect? = null
129
+ private var referenceBackdropBlurRadius = Float.NaN
130
+ private var referenceBackdropBlurWidth = Float.NaN
131
+ private var referenceBackdropBlurHeight = Float.NaN
132
+ private var referenceHighlightShader: RuntimeShader? = null
133
+ private var referencePressGlowShader: RuntimeShader? = null
134
+ private var referenceInteractiveOverlayShader: RuntimeShader? = null
135
+ private var referenceParityEffect: RenderEffect? = null
136
+ private var referenceParitySignature: Int = 0
137
+ private var hasReferenceParitySignature: Boolean = false
138
+ private var directParityShader: RuntimeShader? = null
139
+ private val directParityPaint = Paint()
140
+ private var appliedDirectParitySceneShader: BitmapShader? = null
141
+ private var lastDirectParitySignature: Int = 0
142
+ private var hasDirectParitySignature: Boolean = false
143
+ private var lastDirectParityOriginX: Float = Float.NaN
144
+ private var lastDirectParityOriginY: Float = Float.NaN
145
+ private var referenceOuterShadowShader: RuntimeShader? = null
146
+ private var referenceInnerShadowShader: RuntimeShader? = null
147
+ // One immutable geometry per light-pass shader: all five reference light
148
+ // shaders are view-local. Avoid resending 14 AGSL uniforms to GPU on every
149
+ // scroll frame when the shape is stationary (but backdrop content moves).
150
+ private val cachedLightGeometry = java.util.IdentityHashMap<RuntimeShader, FloatArray>()
151
+ private val cachedLightMaskText = java.util.IdentityHashMap<RuntimeShader, String>()
152
+ private val clipPath = Path()
153
+ private val scrimPaint = Paint()
154
+ private val rimPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply { style = Paint.Style.STROKE }
155
+ private val parityHighlightPaint = Paint(Paint.ANTI_ALIAS_FLAG)
156
+ private val rectF = RectF()
157
+ private val packedShapes = FloatArray(GlassUniforms.MAX_SHAPES * GlassUniforms.SHAPE_FLOATS).apply {
158
+ for (i in 0 until GlassUniforms.MAX_SHAPES) {
159
+ val base = i * GlassUniforms.SHAPE_FLOATS
160
+ this[base] = GlassUniforms.SENTINEL_CENTER
161
+ this[base + 1] = GlassUniforms.SENTINEL_CENTER
162
+ this[base + 2] = 1f
163
+ this[base + 3] = 1f
164
+ }
165
+ }
166
+ private val packedRadii = FloatArray(GlassUniforms.MAX_SHAPES)
167
+ private var shaderEffect: RenderEffect? = null
168
+ private var sdfScaleLensEffect: RenderEffect? = null
169
+ private var cachedPrepEffect: RenderEffect? = null
170
+ private var cachedPrepBlur = Float.NaN
171
+ private var cachedPrepSaturation = Float.NaN
172
+ private var cachedPrepValid = false
173
+ private var cachedChainEffect: RenderEffect? = null
174
+ private var cachedChainPrep: RenderEffect? = null
175
+ private var cachedChainRuntimeEffect: RenderEffect? = null
176
+ private var appliedRenderEffect: RenderEffect? = null
177
+ private var cachedLightAngle = Float.NaN
178
+ private var cachedLightDirX = 0f
179
+ private var cachedLightDirY = 0f
180
+ private var cachedSdfWidth = Float.NaN
181
+ private var cachedSdfHeight = Float.NaN
182
+ private var cachedSdfMaxRawDisplacement = 0f
183
+ private var cachedSdfMaxSampleDisplacementX = 0f
184
+ private var cachedSdfMaxSampleDisplacementY = 0f
185
+ private var cachedG2Width = Float.NaN
186
+ private var cachedG2Height = Float.NaN
187
+ private var cachedG2Radius = Float.NaN
188
+ private var cachedG2Points = FloatArray(20)
189
+ private var referenceG2MaskTexture: ReferenceG2MaskTexture? = null
190
+ private var cachedShapeWidth = Float.NaN
191
+ private var cachedShapeHeight = Float.NaN
192
+ private var cachedShapeRadius = Float.NaN
193
+ private var cachedShapeModel: GlassOpticsModel? = null
194
+
195
+ /** Rebind the cached source/effect after the host window becomes visible again. */
196
+ fun invalidateHostAttachment() {
197
+ appliedRenderEffect = null
198
+ backdropLayer.invalidate()
199
+ }
200
+
201
+ fun release() {
202
+ if (android.os.Build.VERSION.SDK_INT >= 29) {
203
+ backdropLayer.release()
204
+ }
205
+ runtimeShader = null
206
+ sdfScaleLensShader = null
207
+ referenceParityShader = null
208
+ referenceBackdropBlur = null
209
+ referenceBackdropBlurRadius = Float.NaN
210
+ referenceBackdropBlurWidth = Float.NaN
211
+ referenceBackdropBlurHeight = Float.NaN
212
+ referenceHighlightShader = null
213
+ referencePressGlowShader = null
214
+ referenceInteractiveOverlayShader = null
215
+ referenceParityEffect = null
216
+ referenceParitySignature = 0
217
+ hasReferenceParitySignature = false
218
+ directParityShader = null
219
+ directParityPaint.shader = null
220
+ appliedDirectParitySceneShader = null
221
+ lastDirectParitySignature = 0
222
+ hasDirectParitySignature = false
223
+ lastDirectParityOriginX = Float.NaN
224
+ lastDirectParityOriginY = Float.NaN
225
+ referenceSystemBlurEffect = null
226
+ referenceOuterShadowShader = null
227
+ referenceInnerShadowShader = null
228
+ cachedLightGeometry.clear()
229
+ shaderEffect = null
230
+ sdfScaleLensEffect = null
231
+ cachedPrepEffect = null
232
+ cachedPrepBlur = Float.NaN
233
+ cachedPrepSaturation = Float.NaN
234
+ cachedPrepValid = false
235
+ cachedChainEffect = null
236
+ cachedChainPrep = null
237
+ cachedChainRuntimeEffect = null
238
+ appliedRenderEffect = null
239
+ cachedLightAngle = Float.NaN
240
+ cachedSdfWidth = Float.NaN
241
+ cachedSdfHeight = Float.NaN
242
+ cachedSdfMaxRawDisplacement = 0f
243
+ cachedSdfMaxSampleDisplacementX = 0f
244
+ cachedSdfMaxSampleDisplacementY = 0f
245
+ cachedG2Width = Float.NaN
246
+ cachedG2Height = Float.NaN
247
+ cachedG2Radius = Float.NaN
248
+ referenceG2MaskTexture = null
249
+ cachedShapeWidth = Float.NaN
250
+ cachedShapeHeight = Float.NaN
251
+ cachedShapeRadius = Float.NaN
252
+ cachedShapeModel = null
253
+ }
254
+
255
+ /** SHADER (33+) and BLUR (31+) tiers: backdrop slice + RenderEffect. */
256
+ @RequiresApi(31)
257
+ /** Last frame handed to the optical path, for the shared multi-shape pass. */
258
+ internal var lastFrame: GlassFrame? = null
259
+ internal var lastInsets: GlassOpticalInsets? = null
260
+
261
+ fun drawEffectGlass(
262
+ canvas: Canvas,
263
+ providerNode: RenderNode,
264
+ frame: GlassFrame,
265
+ useShader: Boolean,
266
+ sceneShader: BitmapShader? = null,
267
+ ) {
268
+ if (useShader &&
269
+ sceneShader != null &&
270
+ android.os.Build.VERSION.SDK_INT >= 33 &&
271
+ frame.opticsModel == GlassOpticsModel.REFERENCE_PARITY &&
272
+ (frame.backdropAlreadyBlurred || frame.blurRadiusPx < 0.5f) &&
273
+ !frame.displacementOnlyDebug &&
274
+ frame.progressiveBlurIntensity <= 0.001f &&
275
+ !frame.referenceToggleUseSolidBackdropColor &&
276
+ frame.shapeMaskText.isNullOrBlank() &&
277
+ drawDirectParity(canvas, sceneShader, frame)
278
+ ) {
279
+ return
280
+ }
281
+ val insets = opticalInsets(frame)
282
+ // Kept for the shared multi-shape pass, which needs the same per-surface
283
+ // values the per-surface renderer sets as uniforms.
284
+ lastFrame = frame
285
+ lastInsets = insets
286
+ val layerWidth = kotlin.math.ceil(frame.widthPx + insets.left + insets.right).toInt()
287
+ val layerHeight = kotlin.math.ceil(frame.heightPx + insets.top + insets.bottom).toInt()
288
+ if (layerWidth <= 0 || layerHeight <= 0) return
289
+
290
+ val translateX = insets.left - frame.relativeX
291
+ val translateY = insets.top - frame.relativeY
292
+ val node = backdropLayer.update(providerNode, layerWidth, layerHeight, translateX, translateY)
293
+ val effect = if (useShader && android.os.Build.VERSION.SDK_INT >= 33) {
294
+ buildShaderEffect(frame, insets)
295
+ } else {
296
+ buildBackdropPrepEffect(frame.blurRadiusPx, frame.saturation)
297
+ }
298
+ if (appliedRenderEffect !== effect) {
299
+ node.setRenderEffect(effect)
300
+ appliedRenderEffect = effect
301
+ }
302
+
303
+ if (useShader && frame.opticsModel == GlassOpticsModel.REFERENCE_PARITY && frame.outerShadowAlpha > 0f) {
304
+ drawReferenceOuterShadow(canvas, frame, insets, layerWidth, layerHeight)
305
+ }
306
+
307
+ canvas.save()
308
+ if (!useShader) {
309
+ canvas.clipPath(shapePath(frame))
310
+ }
311
+ canvas.translate(-insets.left, -insets.top)
312
+ canvas.drawRenderNode(node)
313
+ canvas.restore()
314
+
315
+ if (useShader && frame.opticsModel == GlassOpticsModel.REFERENCE_PARITY) {
316
+ drawReferencePostPasses(canvas, frame, insets, layerWidth, layerHeight)
317
+ }
318
+
319
+ if (!useShader) {
320
+ if (Color.alpha(frame.tintColor) > 0) {
321
+ drawFill(canvas, frame, frame.tintColor)
322
+ }
323
+ drawRim(canvas, frame)
324
+ }
325
+ }
326
+
327
+ @RequiresApi(33)
328
+ private fun drawReferencePostPasses(
329
+ canvas: Canvas,
330
+ frame: GlassFrame,
331
+ insets: GlassOpticalInsets,
332
+ layerWidth: Int,
333
+ layerHeight: Int,
334
+ ) {
335
+ if (frame.innerShadowStrength > 0f) {
336
+ drawReferenceInnerShadow(canvas, frame, insets, layerWidth, layerHeight)
337
+ }
338
+ if (frame.referenceInteractionProfile == 0 && frame.pressAmount > 0.001f) {
339
+ drawReferencePressGlow(canvas, frame, insets, layerWidth, layerHeight)
340
+ }
341
+ if (frame.referenceInteractionProfile == 4 && frame.pressAmount > 0.001f) {
342
+ drawReferencePressGlow(canvas, frame, insets, layerWidth, layerHeight)
343
+ }
344
+ if (frame.referenceOverlayAlpha > 0.001f || frame.referenceOverlayBlackAlpha > 0.001f) {
345
+ drawReferenceInteractiveOverlay(canvas, frame, insets, layerWidth, layerHeight)
346
+ }
347
+ if (frame.highlightAlpha > 0f) {
348
+ drawReferenceHighlight(canvas, frame, insets, layerWidth, layerHeight)
349
+ }
350
+ }
351
+
352
+ @RequiresApi(33)
353
+ private fun drawDirectParity(
354
+ canvas: Canvas,
355
+ sceneShader: BitmapShader,
356
+ frame: GlassFrame,
357
+ ): Boolean {
358
+ val width = ceil(frame.widthPx).toInt()
359
+ val height = ceil(frame.heightPx).toInt()
360
+ if (width <= 0 || height <= 0) return false
361
+ lastFrame = frame
362
+ val lightInsets = opticalInsets(frame)
363
+ lastInsets = lightInsets
364
+ val lightWidth = ceil(frame.widthPx + lightInsets.left + lightInsets.right).toInt()
365
+ val lightHeight = ceil(frame.heightPx + lightInsets.top + lightInsets.bottom).toInt()
366
+ val zeroInsets = ZERO_INSETS
367
+ updateG2Points(frame)
368
+ if (frame.outerShadowAlpha > 0f) {
369
+ drawReferenceOuterShadow(canvas, frame, lightInsets, lightWidth, lightHeight)
370
+ }
371
+ val shader = directParityShader ?: runCatching {
372
+ RuntimeShader(ReferenceParityGlassShader.SOURCE).also {
373
+ directParityShader = it
374
+ directParityPaint.shader = it
375
+ LiquidGlassPerfTelemetry.effectBuild()
376
+ }
377
+ }.getOrElse { return false }
378
+
379
+ val sig = computeReferenceParitySignature(frame, zeroInsets)
380
+ if (!hasDirectParitySignature || sig != lastDirectParitySignature) {
381
+ bindReferenceParityUniforms(
382
+ shader = shader,
383
+ frame = frame,
384
+ insets = zeroInsets,
385
+ sceneOriginX = frame.relativeX,
386
+ sceneOriginY = frame.relativeY,
387
+ forceUpload = false,
388
+ )
389
+ lastDirectParitySignature = sig
390
+ hasDirectParitySignature = true
391
+ lastDirectParityOriginX = frame.relativeX
392
+ lastDirectParityOriginY = frame.relativeY
393
+ } else if (frame.relativeX != lastDirectParityOriginX || frame.relativeY != lastDirectParityOriginY) {
394
+ shader.setFloatUniform(ReferenceParityGlassShader.SCENE_ORIGIN, frame.relativeX, frame.relativeY)
395
+ lastDirectParityOriginX = frame.relativeX
396
+ lastDirectParityOriginY = frame.relativeY
397
+ }
398
+ if (appliedDirectParitySceneShader !== sceneShader) {
399
+ shader.setInputBuffer(ReferenceParityGlassShader.CONTENT, sceneShader)
400
+ appliedDirectParitySceneShader = sceneShader
401
+ }
402
+ directParityPaint.shader = shader
403
+ canvas.drawRect(-1f, -1f, frame.widthPx + 1f, frame.heightPx + 1f, directParityPaint)
404
+ drawReferencePostPasses(canvas, frame, lightInsets, lightWidth, lightHeight)
405
+ return true
406
+ }
407
+
408
+ /** API 29–30: real backdrop, clipped, with a scrim — no RenderEffect. */
409
+ @RequiresApi(29)
410
+ fun drawBackdropScrim(
411
+ canvas: Canvas,
412
+ providerNode: RenderNode,
413
+ frame: GlassFrame,
414
+ scrimColor: Int,
415
+ ) {
416
+ canvas.save()
417
+ canvas.clipPath(shapePath(frame))
418
+ canvas.translate(-frame.relativeX, -frame.relativeY)
419
+ canvas.drawRenderNode(providerNode)
420
+ canvas.restore()
421
+ drawFill(canvas, frame, scrimColor)
422
+ drawRim(canvas, frame)
423
+ }
424
+
425
+ /** Last resort everywhere: translucent scrim + rim, no backdrop sample. */
426
+ fun drawPlainScrim(canvas: Canvas, frame: GlassFrame, scrimColor: Int) {
427
+ drawFill(canvas, frame, scrimColor)
428
+ drawRim(canvas, frame)
429
+ }
430
+
431
+ @RequiresApi(33)
432
+ private fun buildShaderEffect(frame: GlassFrame, insets: GlassOpticalInsets): RenderEffect {
433
+ if (frame.opticsModel == GlassOpticsModel.SDF_SCALE_LENS) {
434
+ return buildSdfScaleLensEffect(frame, insets)
435
+ }
436
+ if (frame.opticsModel == GlassOpticsModel.REFERENCE_PARITY) {
437
+ return buildReferenceParityEffect(frame, insets)
438
+ }
439
+ val shader = runtimeShader
440
+ ?: RuntimeShader(HeightFieldGlassShader.SOURCE).also {
441
+ runtimeShader = it
442
+ LiquidGlassPerfTelemetry.effectBuild()
443
+ }
444
+ val halfWidth = frame.widthPx / 2f
445
+ val halfHeight = frame.heightPx / 2f
446
+ packedShapes[0] = halfWidth + insets.left
447
+ packedShapes[1] = halfHeight + insets.top
448
+ packedShapes[2] = halfWidth
449
+ packedShapes[3] = halfHeight
450
+ packedRadii[0] = min(frame.cornerRadiusPx, max(min(halfWidth, halfHeight), 0f))
451
+ if (cachedLightAngle != frame.lightAngleDegrees) {
452
+ val angleRadians = Math.toRadians(frame.lightAngleDegrees.toDouble())
453
+ cachedLightDirX = cos(angleRadians).toFloat()
454
+ cachedLightDirY = sin(angleRadians).toFloat()
455
+ cachedLightAngle = frame.lightAngleDegrees
456
+ }
457
+ with(shader) {
458
+ setFloatUniform(GlassUniforms.SHAPES, packedShapes)
459
+ setFloatUniform(GlassUniforms.SHAPE_RADII, packedRadii)
460
+ setFloatUniform(GlassUniforms.MERGE_SMOOTHING, 0f)
461
+ setFloatUniform(GlassUniforms.REFRACTION_HEIGHT, frame.refractionHeightPx)
462
+ setFloatUniform(GlassUniforms.REFRACTION_AMOUNT, frame.refractionAmountPx)
463
+ setFloatUniform(GlassUniforms.BODY_REFRACTION_AMOUNT, frame.bodyRefractionAmountPx)
464
+ setFloatUniform(GlassUniforms.INTERACTION_PROGRESS, frame.interactionProgress)
465
+ setFloatUniform(GlassUniforms.CHROMATIC_ABERRATION, frame.chromaticAberration)
466
+ setFloatUniform(
467
+ GlassUniforms.TINT,
468
+ Color.red(frame.tintColor) / 255f,
469
+ Color.green(frame.tintColor) / 255f,
470
+ Color.blue(frame.tintColor) / 255f,
471
+ Color.alpha(frame.tintColor) / 255f,
472
+ )
473
+ setFloatUniform(GlassUniforms.TINT_ALPHA, frame.tintAlpha)
474
+ setFloatUniform(GlassUniforms.NOISE_ALPHA, frame.noiseAlpha)
475
+ setFloatUniform(
476
+ GlassUniforms.LIGHT_DIRECTION,
477
+ cachedLightDirX,
478
+ cachedLightDirY,
479
+ )
480
+ setFloatUniform(GlassUniforms.HIGHLIGHT_ALPHA, frame.highlightAlpha)
481
+ setFloatUniform(GlassUniforms.SPECULAR_STRENGTH, frame.specularStrength)
482
+ setFloatUniform(GlassUniforms.FRESNEL_STRENGTH, frame.fresnelStrength)
483
+ setFloatUniform(GlassUniforms.INNER_SHADOW_STRENGTH, frame.innerShadowStrength)
484
+ setFloatUniform(GlassUniforms.HIGHLIGHT_WIDTH, frame.highlightWidthPx)
485
+ setFloatUniform(GlassUniforms.PRESS_AMOUNT, max(frame.pressAmount, 0f))
486
+ setFloatUniform(GlassUniforms.MOTION, frame.motionX, frame.motionY)
487
+ setFloatUniform(GlassUniforms.DISPLACEMENT_ONLY, if (frame.displacementOnlyDebug) 1f else 0f)
488
+ setFloatUniform(
489
+ GlassUniforms.PRESS_POINT,
490
+ frame.pressX + insets.left,
491
+ frame.pressY + insets.top,
492
+ )
493
+ }
494
+ val runtimeEffect = shaderEffect
495
+ ?: RenderEffect.createRuntimeShaderEffect(shader, GlassUniforms.CONTENT).also {
496
+ shaderEffect = it
497
+ LiquidGlassPerfTelemetry.effectBuild()
498
+ }
499
+ val prep = if (frame.displacementOnlyDebug) {
500
+ null
501
+ } else {
502
+ buildBackdropPrepEffect(frame.blurRadiusPx, frame.saturation)
503
+ } ?: return runtimeEffect
504
+ if (cachedChainEffect == null || cachedChainRuntimeEffect !== runtimeEffect || cachedChainPrep !== prep) {
505
+ cachedChainRuntimeEffect = runtimeEffect
506
+ cachedChainPrep = prep
507
+ cachedChainEffect = RenderEffect.createChainEffect(runtimeEffect, prep).also {
508
+ LiquidGlassPerfTelemetry.effectBuild()
509
+ }
510
+ }
511
+ return cachedChainEffect!!
512
+ }
513
+
514
+ @RequiresApi(33)
515
+ private fun buildReferenceParityEffect(frame: GlassFrame, insets: GlassOpticalInsets): RenderEffect {
516
+ updateG2Points(frame)
517
+ val signature = computeReferenceParitySignature(frame, insets)
518
+ val existingEffect = referenceParityEffect
519
+ if (hasReferenceParitySignature && signature == referenceParitySignature && existingEffect != null) {
520
+ return existingEffect
521
+ }
522
+
523
+ val uiThread = isUiThread()
524
+ val canUseGlobalCache = uiThread &&
525
+ frame.backdropAlreadyBlurred &&
526
+ frame.interactionProgress == 0f &&
527
+ !frame.displacementOnlyDebug &&
528
+ !frame.referenceToggleBackdropEnabled &&
529
+ (frame.referenceInteractionProfile == 0 || frame.referenceInteractionProfile == 4) &&
530
+ frame.shapeMaskText.isNullOrBlank()
531
+ val cacheKey = if (canUseGlobalCache) parityEffectKey(frame, insets) else null
532
+ if (cacheKey != null) {
533
+ sharedParityEffectCache[cacheKey]?.let { cached ->
534
+ referenceParitySignature = signature
535
+ hasReferenceParitySignature = true
536
+ referenceParityEffect = cached
537
+ return cached
538
+ }
539
+ }
540
+
541
+ val shader = if (uiThread) {
542
+ sharedTemplateParityShader ?: RuntimeShader(ReferenceParityGlassShader.SOURCE).also {
543
+ sharedTemplateParityShader = it
544
+ LiquidGlassPerfTelemetry.effectBuild()
545
+ }
546
+ } else {
547
+ referenceParityShader ?: RuntimeShader(ReferenceParityGlassShader.SOURCE).also {
548
+ referenceParityShader = it
549
+ LiquidGlassPerfTelemetry.effectBuild()
550
+ }
551
+ }
552
+
553
+ referenceParitySignature = signature
554
+ hasReferenceParitySignature = true
555
+ bindReferenceParityUniforms(shader, frame, insets, 0f, 0f, uiThread)
556
+ return finishReferenceParityEffect(shader, frame, insets, cacheKey)
557
+ }
558
+
559
+ @RequiresApi(33)
560
+ private fun bindReferenceParityUniforms(
561
+ shader: RuntimeShader,
562
+ frame: GlassFrame,
563
+ insets: GlassOpticalInsets,
564
+ sceneOriginX: Float,
565
+ sceneOriginY: Float,
566
+ forceUpload: Boolean,
567
+ ) {
568
+ setReferenceGeometry(shader, frame, insets, forceUpload = forceUpload)
569
+ with(shader) {
570
+ setFloatUniform(ReferenceParityGlassShader.SCENE_ORIGIN, sceneOriginX, sceneOriginY)
571
+ setFloatUniform(ReferenceParityGlassShader.ORIGIN, insets.left, insets.top)
572
+ setFloatUniform(ReferenceParityGlassShader.SIZE, frame.widthPx, frame.heightPx)
573
+ setFloatUniform(ReferenceParityGlassShader.RADIUS, frame.cornerRadiusPx)
574
+ setFloatUniform(ReferenceParityGlassShader.REFRACTION_HEIGHT, frame.refractionHeightPx)
575
+ // WebGL shader samples at screenCoord + distance * outward SDF normal.
576
+ setFloatUniform(ReferenceParityGlassShader.REFRACTION_AMOUNT, frame.refractionAmountPx)
577
+ setFloatUniform(ReferenceParityGlassShader.DEPTH_EFFECT, if (frame.referenceDepthEffect) 1f else 0f)
578
+ setFloatUniform(ReferenceParityGlassShader.CONTENT_SCALE, frame.contentScaleX, frame.contentScaleY)
579
+ setFloatUniform(ReferenceParityGlassShader.CONTENT_OFFSET, frame.contentOffsetXPx, frame.contentOffsetYPx)
580
+ setFloatUniform(ReferenceParityGlassShader.LAYER_SCALE, frame.layerScaleX, frame.layerScaleY)
581
+ setFloatUniform(ReferenceParityGlassShader.LAYER_TRANSLATION, frame.layerTranslationXPx, frame.layerTranslationYPx)
582
+ setFloatUniform(ReferenceParityGlassShader.TOGGLE_BACKDROP_ENABLED, if (frame.referenceToggleBackdropEnabled) 1f else 0f)
583
+ setFloatUniform(ReferenceParityGlassShader.TOGGLE_FRACTION, frame.referenceToggleFraction)
584
+ setFloatUniform(
585
+ ReferenceParityGlassShader.TOGGLE_TRACK_COLOR_OFF,
586
+ Color.red(frame.referenceToggleTrackColorOff) / 255f,
587
+ Color.green(frame.referenceToggleTrackColorOff) / 255f,
588
+ Color.blue(frame.referenceToggleTrackColorOff) / 255f,
589
+ Color.alpha(frame.referenceToggleTrackColorOff) / 255f,
590
+ )
591
+ setFloatUniform(
592
+ ReferenceParityGlassShader.TOGGLE_TRACK_COLOR_ON,
593
+ Color.red(frame.referenceToggleTrackColorOn) / 255f,
594
+ Color.green(frame.referenceToggleTrackColorOn) / 255f,
595
+ Color.blue(frame.referenceToggleTrackColorOn) / 255f,
596
+ Color.alpha(frame.referenceToggleTrackColorOn) / 255f,
597
+ )
598
+ setFloatUniform(ReferenceParityGlassShader.TOGGLE_TRACK_SIZE, frame.referenceToggleTrackWidthPx, frame.referenceToggleTrackHeightPx)
599
+ setFloatUniform(ReferenceParityGlassShader.TOGGLE_INSET, 2f * frame.densityScale)
600
+ setFloatUniform(ReferenceParityGlassShader.TOGGLE_BLUR_RADIUS, frame.blurRadiusPx)
601
+ setFloatUniform(ReferenceParityGlassShader.TOGGLE_PRESS_PROGRESS, frame.interactionProgress)
602
+ setFloatUniform(ReferenceParityGlassShader.INTERACTION_PROGRESS, frame.interactionProgress)
603
+ setFloatUniform(ReferenceParityGlassShader.INTERACTION_PROFILE, frame.referenceInteractionProfile.toFloat())
604
+ setFloatUniform(ReferenceParityGlassShader.TOGGLE_USE_SOLID, if (frame.referenceToggleUseSolidBackdropColor) 1f else 0f)
605
+ setFloatUniform(
606
+ ReferenceParityGlassShader.TOGGLE_SOLID_COLOR,
607
+ Color.red(frame.referenceToggleSolidBackdropColor) / 255f,
608
+ Color.green(frame.referenceToggleSolidBackdropColor) / 255f,
609
+ Color.blue(frame.referenceToggleSolidBackdropColor) / 255f,
610
+ Color.alpha(frame.referenceToggleSolidBackdropColor) / 255f,
611
+ )
612
+ setFloatUniform(ReferenceParityGlassShader.DISPERSION, frame.dispersion.coerceIn(0f, 1f))
613
+ setFloatUniform(ReferenceParityGlassShader.SATURATION, frame.saturation)
614
+ setFloatUniform(ReferenceParityGlassShader.BRIGHTNESS, frame.brightness)
615
+ setFloatUniform(ReferenceParityGlassShader.CONTRAST, frame.contrast)
616
+ setFloatUniform(ReferenceParityGlassShader.DISPLACEMENT_ONLY, if (frame.displacementOnlyDebug) 1f else 0f)
617
+ val textLightAngle = Math.toRadians(frame.lightAngleDegrees.toDouble())
618
+ setFloatUniform(
619
+ ReferenceParityGlassShader.TEXT_LIGHT,
620
+ frame.highlightAlpha,
621
+ frame.highlightWidthPx,
622
+ cos(textLightAngle).toFloat(),
623
+ sin(textLightAngle).toFloat(),
624
+ )
625
+ setFloatUniform(ReferenceParityGlassShader.PROGRESSIVE_BLUR_INTENSITY, frame.progressiveBlurIntensity)
626
+ setFloatUniform(
627
+ ReferenceParityGlassShader.TINT,
628
+ Color.red(frame.tintColor) / 255f,
629
+ Color.green(frame.tintColor) / 255f,
630
+ Color.blue(frame.tintColor) / 255f,
631
+ Color.alpha(frame.tintColor) / 255f,
632
+ )
633
+ setFloatUniform(ReferenceParityGlassShader.TINT_ALPHA, frame.tintAlpha)
634
+ setFloatUniform(
635
+ ReferenceParityGlassShader.SURFACE_COLOR,
636
+ Color.red(frame.surfaceColor) / 255f,
637
+ Color.green(frame.surfaceColor) / 255f,
638
+ Color.blue(frame.surfaceColor) / 255f,
639
+ Color.alpha(frame.surfaceColor) / 255f,
640
+ )
641
+ for (index in 0 until 10) {
642
+ setFloatUniform(
643
+ ReferenceParityGlassShader.G2_POINTS[index],
644
+ cachedG2Points[index * 2],
645
+ cachedG2Points[index * 2 + 1],
646
+ )
647
+ }
648
+ }
649
+ }
650
+
651
+ @RequiresApi(33)
652
+ private fun finishReferenceParityEffect(
653
+ shader: RuntimeShader,
654
+ frame: GlassFrame,
655
+ insets: GlassOpticalInsets,
656
+ cacheKey: ParityEffectKey?,
657
+ ): RenderEffect {
658
+ val runtimeEffect = RenderEffect.createRuntimeShaderEffect(shader, ReferenceParityGlassShader.CONTENT).also {
659
+ referenceParityEffect = it
660
+ LiquidGlassPerfTelemetry.effectBuild()
661
+ if (cacheKey != null) {
662
+ putSharedParityEffect(cacheKey, it)
663
+ }
664
+ }
665
+ // Saturation stays in the optical pass after the seven reference samples.
666
+ // The backdrop pre-pass uses the pinned WebGL shader's 16-point Vogel disc,
667
+ // including its 3-sigma support and normalized Gaussian weights.
668
+ val prep = if (frame.backdropAlreadyBlurred) null else buildReferenceBackdropBlurEffect(frame, insets)
669
+ if (prep == null) return runtimeEffect
670
+ if (cachedChainEffect == null || cachedChainRuntimeEffect !== runtimeEffect || cachedChainPrep !== prep) {
671
+ cachedChainRuntimeEffect = runtimeEffect
672
+ cachedChainPrep = prep
673
+ cachedChainEffect = RenderEffect.createChainEffect(runtimeEffect, prep).also {
674
+ LiquidGlassPerfTelemetry.effectBuild()
675
+ }
676
+ }
677
+ return cachedChainEffect!!
678
+ }
679
+
680
+ private fun computeReferenceParitySignature(frame: GlassFrame, insets: GlassOpticalInsets): Int {
681
+ var result = insets.left.toBits()
682
+ result = 31 * result + insets.top.toBits()
683
+ result = 31 * result + frame.widthPx.toBits()
684
+ result = 31 * result + frame.heightPx.toBits()
685
+ result = 31 * result + frame.cornerRadiusPx.toBits()
686
+ result = 31 * result + frame.refractionHeightPx.toBits()
687
+ result = 31 * result + frame.refractionAmountPx.toBits()
688
+ result = 31 * result + if (frame.referenceDepthEffect) 1 else 0
689
+ result = 31 * result + frame.contentScaleX.toBits()
690
+ result = 31 * result + frame.contentScaleY.toBits()
691
+ result = 31 * result + frame.contentOffsetXPx.toBits()
692
+ result = 31 * result + frame.contentOffsetYPx.toBits()
693
+ result = 31 * result + frame.layerScaleX.toBits()
694
+ result = 31 * result + frame.layerScaleY.toBits()
695
+ result = 31 * result + frame.layerTranslationXPx.toBits()
696
+ result = 31 * result + frame.layerTranslationYPx.toBits()
697
+ result = 31 * result + if (frame.referenceToggleBackdropEnabled) 1 else 0
698
+ result = 31 * result + frame.referenceToggleFraction.toBits()
699
+ result = 31 * result + frame.referenceToggleTrackColorOff
700
+ result = 31 * result + frame.referenceToggleTrackColorOn
701
+ result = 31 * result + frame.referenceToggleTrackWidthPx.toBits()
702
+ result = 31 * result + frame.referenceToggleTrackHeightPx.toBits()
703
+ result = 31 * result + frame.densityScale.toBits()
704
+ result = 31 * result + frame.blurRadiusPx.toBits()
705
+ result = 31 * result + frame.interactionProgress.toBits()
706
+ result = 31 * result + frame.referenceInteractionProfile
707
+ result = 31 * result + if (frame.referenceToggleUseSolidBackdropColor) 1 else 0
708
+ result = 31 * result + frame.referenceToggleSolidBackdropColor
709
+ result = 31 * result + frame.dispersion.toBits()
710
+ result = 31 * result + frame.saturation.toBits()
711
+ result = 31 * result + frame.brightness.toBits()
712
+ result = 31 * result + frame.contrast.toBits()
713
+ result = 31 * result + if (frame.displacementOnlyDebug) 1 else 0
714
+ result = 31 * result + frame.lightAngleDegrees.toBits()
715
+ result = 31 * result + frame.highlightAlpha.toBits()
716
+ result = 31 * result + frame.highlightWidthPx.toBits()
717
+ result = 31 * result + frame.progressiveBlurIntensity.toBits()
718
+ result = 31 * result + frame.tintColor
719
+ result = 31 * result + frame.tintAlpha.toBits()
720
+ result = 31 * result + frame.surfaceColor
721
+ result = 31 * result + (frame.shapeMaskText?.hashCode() ?: 0)
722
+ result = 31 * result + frame.shapeMaskFontSizePx.toBits()
723
+ result = 31 * result + frame.shapeMaskFontWeight
724
+ result = 31 * result + if (frame.backdropAlreadyBlurred) 1 else 0
725
+ result = 31 * result + cachedG2Points.contentHashCode()
726
+ return result
727
+ }
728
+
729
+ @RequiresApi(33)
730
+ private fun buildReferenceBackdropBlurEffect(frame: GlassFrame, insets: GlassOpticalInsets): RenderEffect? {
731
+ // The pinned WebGL sampler bypasses blur below 0.5px. Small radii use
732
+ // the 16-point Gaussian disc; large radii (>16px) fall back to separable
733
+ // platform blur so sparse disc taps do not produce discrete ghost text.
734
+ if (frame.blurRadiusPx < 0.5f) return null
735
+ val width = kotlin.math.ceil(frame.widthPx + insets.left + insets.right).toFloat()
736
+ val height = kotlin.math.ceil(frame.heightPx + insets.top + insets.bottom).toFloat()
737
+ if (frame.blurRadiusPx > 16f) {
738
+ val existing = referenceSystemBlurEffect
739
+ if (existing != null && referenceBackdropBlurRadius == frame.blurRadiusPx && referenceBackdropBlur == null) {
740
+ return existing
741
+ }
742
+ referenceBackdropBlur = null
743
+ referenceBackdropBlurRadius = frame.blurRadiusPx
744
+ referenceBackdropBlurWidth = width
745
+ referenceBackdropBlurHeight = height
746
+ return RenderEffect.createBlurEffect(
747
+ frame.blurRadiusPx,
748
+ frame.blurRadiusPx,
749
+ Shader.TileMode.CLAMP,
750
+ ).also {
751
+ referenceSystemBlurEffect = it
752
+ LiquidGlassPerfTelemetry.effectBuild()
753
+ }
754
+ }
755
+ val blur = referenceBackdropBlur
756
+ if (blur == null || referenceBackdropBlurRadius != frame.blurRadiusPx) {
757
+ referenceSystemBlurEffect = null
758
+ referenceBackdropBlurRadius = frame.blurRadiusPx
759
+ referenceBackdropBlurWidth = width
760
+ referenceBackdropBlurHeight = height
761
+ val fresh = ReferenceGaussianDiscBackdropBlur.create(frame.blurRadiusPx, width, height).also {
762
+ referenceBackdropBlur = it
763
+ LiquidGlassPerfTelemetry.effectBuild()
764
+ }
765
+ return fresh.effect
766
+ }
767
+ if (referenceBackdropBlurWidth != width || referenceBackdropBlurHeight != height) {
768
+ referenceBackdropBlurWidth = width
769
+ referenceBackdropBlurHeight = height
770
+ blur.updateSize(width, height)
771
+ }
772
+ return blur.effect
773
+ }
774
+
775
+ @RequiresApi(33)
776
+ private fun drawReferenceOuterShadow(
777
+ canvas: Canvas, frame: GlassFrame, insets: GlassOpticalInsets, layerWidth: Int, layerHeight: Int,
778
+ ) {
779
+ val shader: RuntimeShader
780
+ if (isUiThread() && frame.shapeMaskText.isNullOrBlank()) {
781
+ val key = OuterShadowKey(
782
+ insets.left.toBits(), insets.top.toBits(),
783
+ frame.widthPx.toBits(), frame.heightPx.toBits(), frame.cornerRadiusPx.toBits(),
784
+ frame.outerShadowAlpha.toBits(), frame.outerShadowRadiusPx.toBits(), frame.outerShadowOffsetYPx.toBits(),
785
+ )
786
+ shader = sharedOuterShadowCache[key] ?: RuntimeShader(referenceLightPassSource(ReferenceParityGlassShader.OUTER_SHADOW_SOURCE)).also { s ->
787
+ LiquidGlassPerfTelemetry.effectBuild()
788
+ setReferenceGeometry(s, frame, insets, forceUpload = true)
789
+ s.setFloatUniform(
790
+ ReferenceParityGlassShader.SHADOW_PARAMS,
791
+ frame.outerShadowAlpha,
792
+ frame.outerShadowRadiusPx,
793
+ frame.outerShadowOffsetYPx,
794
+ 0f,
795
+ )
796
+ putSharedLightShader(sharedOuterShadowCache, key, s)
797
+ }
798
+ } else {
799
+ shader = referenceOuterShadowShader
800
+ ?: RuntimeShader(referenceLightPassSource(ReferenceParityGlassShader.OUTER_SHADOW_SOURCE)).also {
801
+ referenceOuterShadowShader = it
802
+ LiquidGlassPerfTelemetry.effectBuild()
803
+ }
804
+ setReferenceGeometry(shader, frame, insets)
805
+ shader.setFloatUniform(
806
+ ReferenceParityGlassShader.SHADOW_PARAMS,
807
+ frame.outerShadowAlpha,
808
+ frame.outerShadowRadiusPx,
809
+ frame.outerShadowOffsetYPx,
810
+ 0f,
811
+ )
812
+ }
813
+ parityHighlightPaint.xfermode = null
814
+ drawReferenceLightPass(canvas, shader, frame, insets, layerWidth, layerHeight, outerShadow = true)
815
+ }
816
+
817
+ @RequiresApi(33)
818
+ private fun drawReferenceInnerShadow(
819
+ canvas: Canvas, frame: GlassFrame, insets: GlassOpticalInsets, layerWidth: Int, layerHeight: Int,
820
+ ) {
821
+ // Upstream modulates the shadow's blur radius and offset as well as
822
+ // its alpha for toggle, slider, and tab-indicator interaction.
823
+ val shadowProgress = if (frame.referenceInteractionProfile in 1..3) {
824
+ frame.interactionProgress.coerceIn(0f, 1f)
825
+ } else {
826
+ 1f
827
+ }
828
+ val radius = 4f * frame.densityScale * shadowProgress
829
+ val offsetY = 4f * frame.densityScale * shadowProgress
830
+ val shader: RuntimeShader
831
+ if (isUiThread() && frame.shapeMaskText.isNullOrBlank() && frame.referenceInteractionProfile !in 1..3) {
832
+ val key = InnerShadowKey(
833
+ insets.left.toBits(), insets.top.toBits(),
834
+ frame.widthPx.toBits(), frame.heightPx.toBits(), frame.cornerRadiusPx.toBits(),
835
+ frame.innerShadowStrength.toBits(), radius.toBits(), offsetY.toBits(),
836
+ )
837
+ shader = sharedInnerShadowCache[key] ?: RuntimeShader(referenceLightPassSource(ReferenceParityGlassShader.INNER_SHADOW_SOURCE)).also { s ->
838
+ LiquidGlassPerfTelemetry.effectBuild()
839
+ setReferenceGeometry(s, frame, insets, forceUpload = true)
840
+ s.setFloatUniform(
841
+ ReferenceParityGlassShader.INNER_SHADOW_PARAMS,
842
+ frame.innerShadowStrength,
843
+ radius,
844
+ offsetY,
845
+ 0f,
846
+ )
847
+ putSharedLightShader(sharedInnerShadowCache, key, s)
848
+ }
849
+ } else {
850
+ shader = referenceInnerShadowShader
851
+ ?: RuntimeShader(referenceLightPassSource(ReferenceParityGlassShader.INNER_SHADOW_SOURCE)).also {
852
+ referenceInnerShadowShader = it
853
+ LiquidGlassPerfTelemetry.effectBuild()
854
+ }
855
+ setReferenceGeometry(shader, frame, insets)
856
+ shader.setFloatUniform(
857
+ ReferenceParityGlassShader.INNER_SHADOW_PARAMS,
858
+ frame.innerShadowStrength,
859
+ radius,
860
+ offsetY,
861
+ 0f,
862
+ )
863
+ }
864
+ parityHighlightPaint.xfermode = null
865
+ drawReferenceLightPass(canvas, shader, frame, insets, layerWidth, layerHeight)
866
+ }
867
+
868
+ @RequiresApi(33)
869
+ private fun drawReferenceHighlight(
870
+ canvas: Canvas, frame: GlassFrame, insets: GlassOpticalInsets, layerWidth: Int, layerHeight: Int,
871
+ ) {
872
+ val shader: RuntimeShader
873
+ if (isUiThread() && frame.shapeMaskText.isNullOrBlank() && frame.referenceInteractionProfile !in 1..3) {
874
+ val key = HighlightKey(
875
+ insets.left.toBits(), insets.top.toBits(),
876
+ frame.widthPx.toBits(), frame.heightPx.toBits(), frame.cornerRadiusPx.toBits(),
877
+ frame.highlightAlpha.toBits(), frame.highlightWidthPx.toBits(), frame.lightAngleDegrees.toBits(),
878
+ frame.referenceHighlightStyle, frame.referenceHighlightFalloff.toBits(), frame.referenceHighlightColor,
879
+ )
880
+ shader = sharedHighlightCache[key] ?: RuntimeShader(referenceLightPassSource(ReferenceParityGlassShader.HIGHLIGHT_SOURCE)).also { s ->
881
+ LiquidGlassPerfTelemetry.effectBuild()
882
+ setReferenceGeometry(s, frame, insets, forceUpload = true)
883
+ val angle = Math.toRadians(frame.lightAngleDegrees.toDouble())
884
+ s.setFloatUniform(ReferenceParityGlassShader.HIGHLIGHT_PASS_PARAMS, frame.highlightAlpha, frame.highlightWidthPx, cos(angle).toFloat(), sin(angle).toFloat())
885
+ s.setFloatUniform(ReferenceParityGlassShader.HIGHLIGHT_PASS_STYLE, frame.referenceHighlightStyle.toFloat())
886
+ s.setFloatUniform(ReferenceParityGlassShader.HIGHLIGHT_PASS_FALLOFF, frame.referenceHighlightFalloff)
887
+ s.setFloatUniform(
888
+ ReferenceParityGlassShader.HIGHLIGHT_PASS_COLOR,
889
+ Color.red(frame.referenceHighlightColor) / 255f,
890
+ Color.green(frame.referenceHighlightColor) / 255f,
891
+ Color.blue(frame.referenceHighlightColor) / 255f,
892
+ Color.alpha(frame.referenceHighlightColor) / 255f,
893
+ )
894
+ putSharedLightShader(sharedHighlightCache, key, s)
895
+ }
896
+ } else {
897
+ shader = referenceHighlightShader
898
+ ?: RuntimeShader(referenceLightPassSource(ReferenceParityGlassShader.HIGHLIGHT_SOURCE)).also {
899
+ referenceHighlightShader = it
900
+ LiquidGlassPerfTelemetry.effectBuild()
901
+ }
902
+ setReferenceGeometry(shader, frame, insets)
903
+ val angle = Math.toRadians(frame.lightAngleDegrees.toDouble())
904
+ shader.setFloatUniform(ReferenceParityGlassShader.HIGHLIGHT_PASS_PARAMS, frame.highlightAlpha, frame.highlightWidthPx, cos(angle).toFloat(), sin(angle).toFloat())
905
+ shader.setFloatUniform(ReferenceParityGlassShader.HIGHLIGHT_PASS_STYLE, frame.referenceHighlightStyle.toFloat())
906
+ shader.setFloatUniform(ReferenceParityGlassShader.HIGHLIGHT_PASS_FALLOFF, frame.referenceHighlightFalloff)
907
+ shader.setFloatUniform(
908
+ ReferenceParityGlassShader.HIGHLIGHT_PASS_COLOR,
909
+ Color.red(frame.referenceHighlightColor) / 255f,
910
+ Color.green(frame.referenceHighlightColor) / 255f,
911
+ Color.blue(frame.referenceHighlightColor) / 255f,
912
+ Color.alpha(frame.referenceHighlightColor) / 255f,
913
+ )
914
+ }
915
+ // The pinned WebGL renderer uses additive blending for Default and
916
+ // Plain. Ambient is the only style composited with SrcOver.
917
+ parityHighlightPaint.xfermode = if (frame.referenceHighlightStyle != 1) {
918
+ PorterDuffXfermode(PorterDuff.Mode.ADD)
919
+ } else {
920
+ null
921
+ }
922
+ drawReferenceLightPass(canvas, shader, frame, insets, layerWidth, layerHeight)
923
+ }
924
+
925
+ @RequiresApi(33)
926
+ private fun drawReferenceInteractiveOverlay(
927
+ canvas: Canvas, frame: GlassFrame, insets: GlassOpticalInsets, layerWidth: Int, layerHeight: Int,
928
+ ) {
929
+ // Reference Toggle/Slider: solid white knob at rest, fading away when
930
+ // the lens is pressed. Reference Tabs: 10% theme-aware idle overlay,
931
+ // followed by 3% black during interaction. These are POST-body
932
+ // SrcOver layers, not a tint inside the refracted sample.
933
+ val baseAlpha = frame.referenceOverlayAlpha.coerceIn(0f, 1f)
934
+ val blackAlpha = frame.referenceOverlayBlackAlpha.coerceIn(0f, 1f)
935
+ val alpha = baseAlpha * (1f - blackAlpha) + blackAlpha
936
+ if (alpha <= 0.001f) return
937
+ val shader = referenceInteractiveOverlayShader
938
+ ?: RuntimeShader(referenceLightPassSource(ReferenceParityGlassShader.INTERACTIVE_OVERLAY_SOURCE)).also {
939
+ referenceInteractiveOverlayShader = it
940
+ LiquidGlassPerfTelemetry.effectBuild()
941
+ }
942
+ setReferenceGeometry(shader, frame, insets)
943
+ val basePremul = baseAlpha * (1f - blackAlpha)
944
+ shader.setFloatUniform(
945
+ "interactiveOverlay",
946
+ Color.red(frame.referenceOverlayColor) / 255f * basePremul,
947
+ Color.green(frame.referenceOverlayColor) / 255f * basePremul,
948
+ Color.blue(frame.referenceOverlayColor) / 255f * basePremul,
949
+ alpha,
950
+ )
951
+ parityHighlightPaint.xfermode = null
952
+ drawReferenceLightPass(canvas, shader, frame, insets, layerWidth, layerHeight)
953
+ }
954
+
955
+ @RequiresApi(33)
956
+ private fun drawReferencePressGlow(
957
+ canvas: Canvas, frame: GlassFrame, insets: GlassOpticalInsets, layerWidth: Int, layerHeight: Int,
958
+ ) {
959
+ val shader = referencePressGlowShader
960
+ ?: RuntimeShader(referenceLightPassSource(ReferenceParityGlassShader.PRESS_GLOW_SOURCE)).also {
961
+ referencePressGlowShader = it
962
+ LiquidGlassPerfTelemetry.effectBuild()
963
+ }
964
+ setReferenceGeometry(shader, frame, insets)
965
+ val radius = min(frame.widthPx, frame.heightPx) * 1.5f
966
+ shader.setFloatUniform(
967
+ ReferenceParityGlassShader.PRESS_GLOW,
968
+ frame.pressAmount.coerceIn(0f, 1f),
969
+ radius,
970
+ frame.pressX - frame.widthPx * 0.5f,
971
+ frame.pressY - frame.heightPx * 0.5f,
972
+ )
973
+ parityHighlightPaint.xfermode = PorterDuffXfermode(PorterDuff.Mode.ADD)
974
+ drawReferenceLightPass(canvas, shader, frame, insets, layerWidth, layerHeight)
975
+ }
976
+
977
+ /**
978
+ * Highlight and shadow outputs depend only on local shape coordinates and
979
+ * uniforms. They do not sample the backdrop, so replaying the Provider's
980
+ * complete RenderNode through a RuntimeShader RenderEffect is unnecessary.
981
+ */
982
+ @RequiresApi(33)
983
+ private fun drawReferenceLightPass(
984
+ canvas: Canvas,
985
+ shader: RuntimeShader,
986
+ frame: GlassFrame,
987
+ insets: GlassOpticalInsets,
988
+ layerWidth: Int,
989
+ layerHeight: Int,
990
+ outerShadow: Boolean = false,
991
+ paint: Paint = parityHighlightPaint,
992
+ ) {
993
+ // Restrict geometry-only passes to their true footprint: the backdrop
994
+ // crop padding is not part of the highlight, inner shadow or press glow.
995
+ val reach = if (outerShadow) {
996
+ max(frame.outerShadowRadiusPx, 3f) + abs(frame.outerShadowOffsetYPx) + 1f
997
+ } else 1f
998
+ val left = if (outerShadow) insets.left - reach else max(0f, insets.left - reach)
999
+ val top = if (outerShadow) insets.top - reach else max(0f, insets.top - reach)
1000
+ val right = if (outerShadow) insets.left + frame.widthPx + reach else min(layerWidth.toFloat(), insets.left + frame.widthPx + reach)
1001
+ val bottom = if (outerShadow) insets.top + frame.heightPx + reach else min(layerHeight.toFloat(), insets.top + frame.heightPx + reach)
1002
+ if (right <= left || bottom <= top) return
1003
+ paint.shader = shader
1004
+ val saveCount = canvas.save()
1005
+ canvas.translate(-insets.left, -insets.top)
1006
+ canvas.drawRect(left, top, right, bottom, paint)
1007
+ canvas.restoreToCount(saveCount)
1008
+ paint.shader = null
1009
+ }
1010
+
1011
+ private fun referenceLightPassSource(source: String): String =
1012
+ source.removePrefix("uniform shader ${ReferenceParityGlassShader.CONTENT};\n")
1013
+
1014
+ @RequiresApi(33)
1015
+ private fun setReferenceGeometry(
1016
+ shader: RuntimeShader,
1017
+ frame: GlassFrame,
1018
+ insets: GlassOpticalInsets,
1019
+ forceUpload: Boolean = false,
1020
+ ) {
1021
+ val text = frame.shapeMaskText?.takeIf { it.isNotBlank() }
1022
+ if (!forceUpload) {
1023
+ val key = cachedLightGeometry[shader]
1024
+ if (key != null &&
1025
+ key[0] == insets.left && key[1] == insets.top &&
1026
+ key[2] == frame.widthPx && key[3] == frame.heightPx &&
1027
+ key[4] == frame.cornerRadiusPx &&
1028
+ (text == null || text == cachedLightMaskText[shader])
1029
+ ) return
1030
+ }
1031
+ val textSdfSpreadPx = 8f * frame.densityScale
1032
+ val mask = if (text != null) {
1033
+ referenceG2MaskTexture?.takeIf {
1034
+ it.matchesText(frame.widthPx, frame.heightPx, text, frame.shapeMaskFontSizePx, frame.shapeMaskFontWeight, textSdfSpreadPx)
1035
+ } ?: ReferenceG2MaskTexture.obtainText(
1036
+ frame.widthPx,
1037
+ frame.heightPx,
1038
+ text,
1039
+ frame.shapeMaskFontSizePx,
1040
+ frame.shapeMaskFontWeight,
1041
+ textSdfSpreadPx,
1042
+ ).also { referenceG2MaskTexture = it }
1043
+ } else {
1044
+ referenceG2MaskTexture?.takeIf {
1045
+ it.matches(frame.widthPx, frame.heightPx, frame.cornerRadiusPx)
1046
+ } ?: ReferenceG2MaskTexture.obtain(frame.widthPx, frame.heightPx, frame.cornerRadiusPx).also {
1047
+ referenceG2MaskTexture = it
1048
+ }
1049
+ }
1050
+ shader.setInputBuffer(ReferenceParityGlassShader.G2_MASK, mask.shader)
1051
+ shader.setFloatUniform(
1052
+ ReferenceParityGlassShader.G2_MASK_TEXTURE_SIZE,
1053
+ mask.textureSize.toFloat(),
1054
+ mask.textureSize.toFloat(),
1055
+ )
1056
+ shader.setFloatUniform(
1057
+ ReferenceParityGlassShader.G2_MASK_ELEMENT_SIZE,
1058
+ frame.widthPx,
1059
+ frame.heightPx,
1060
+ )
1061
+ shader.setFloatUniform(
1062
+ ReferenceParityGlassShader.G2_MASK_ENABLED,
1063
+ if (text != null || frame.cornerRadiusPx > 0.001f) 1f else 0f,
1064
+ )
1065
+ shader.setFloatUniform(
1066
+ ReferenceParityGlassShader.G2_MASK_SDF_SCALE,
1067
+ if (text != null) mask.sdfScale else frame.cornerRadiusPx,
1068
+ )
1069
+ shader.setFloatUniform(
1070
+ ReferenceParityGlassShader.G2_MASK_TEXT_NORMALS,
1071
+ if (text != null) 1f else 0f,
1072
+ )
1073
+ updateG2Points(frame)
1074
+ shader.setFloatUniform(ReferenceParityGlassShader.ORIGIN, insets.left, insets.top)
1075
+ shader.setFloatUniform(ReferenceParityGlassShader.SIZE, frame.widthPx, frame.heightPx)
1076
+ shader.setFloatUniform(ReferenceParityGlassShader.RADIUS, frame.cornerRadiusPx)
1077
+ shader.setFloatUniform(ReferenceParityGlassShader.CONTENT_SCALE, 1f, 1f)
1078
+ for (index in 0 until 10) {
1079
+ shader.setFloatUniform(
1080
+ ReferenceParityGlassShader.G2_POINTS[index],
1081
+ cachedG2Points[index * 2],
1082
+ cachedG2Points[index * 2 + 1],
1083
+ )
1084
+ }
1085
+ if (!forceUpload) {
1086
+ cachedLightGeometry[shader] = floatArrayOf(insets.left, insets.top, frame.widthPx, frame.heightPx, frame.cornerRadiusPx)
1087
+ if (text != null) cachedLightMaskText[shader] = text else cachedLightMaskText.remove(shader)
1088
+ }
1089
+ }
1090
+
1091
+ private fun updateG2Points(frame: GlassFrame) {
1092
+ if (cachedG2Width == frame.widthPx && cachedG2Height == frame.heightPx && cachedG2Radius == frame.cornerRadiusPx) return
1093
+ cachedG2Width = frame.widthPx
1094
+ cachedG2Height = frame.heightPx
1095
+ cachedG2Radius = frame.cornerRadiusPx
1096
+ cachedG2Points = G2RoundedRectangle.sdfControlPoints(frame.widthPx, frame.heightPx, frame.cornerRadiusPx)
1097
+ }
1098
+
1099
+ @RequiresApi(33)
1100
+ private fun buildSdfScaleLensEffect(frame: GlassFrame, insets: GlassOpticalInsets): RenderEffect {
1101
+ val shader = sdfScaleLensShader
1102
+ ?: RuntimeShader(SdfScaleLensShader.SOURCE).also {
1103
+ sdfScaleLensShader = it
1104
+ LiquidGlassPerfTelemetry.effectBuild()
1105
+ }
1106
+ ensureSdfDisplacementBounds(frame)
1107
+ with(shader) {
1108
+ setFloatUniform(SdfScaleLensShader.GLASS_ORIGIN, insets.left, insets.top)
1109
+ setFloatUniform(SdfScaleLensShader.GLASS_SIZE, frame.widthPx, frame.heightPx)
1110
+ setFloatUniform(SdfScaleLensShader.GLASS_RADIUS, frame.cornerRadiusPx)
1111
+ setFloatUniform(SdfScaleLensShader.MAX_RAW_DISPLACEMENT, cachedSdfMaxRawDisplacement)
1112
+ setFloatUniform(SdfScaleLensShader.CONTRAST, frame.sdfScaleLens.contrast)
1113
+ setFloatUniform(SdfScaleLensShader.BRIGHTNESS, frame.sdfScaleLens.brightness)
1114
+ setFloatUniform(SdfScaleLensShader.SATURATION, frame.sdfScaleLens.saturation)
1115
+ setFloatUniform(SdfScaleLensShader.OUTER_SHADOW_ALPHA, frame.sdfScaleLens.outerShadowAlpha)
1116
+ setFloatUniform(
1117
+ SdfScaleLensShader.OUTER_SHADOW_BLUR,
1118
+ frame.sdfScaleLens.outerShadowBlurRadiusDp * frame.densityScale,
1119
+ )
1120
+ setFloatUniform(
1121
+ SdfScaleLensShader.OUTER_SHADOW_OFFSET_Y,
1122
+ frame.sdfScaleLens.outerShadowOffsetYDp * frame.densityScale,
1123
+ )
1124
+ setFloatUniform(SdfScaleLensShader.INNER_SHADOW_ALPHA, frame.sdfScaleLens.innerShadowAlpha)
1125
+ setFloatUniform(
1126
+ SdfScaleLensShader.INNER_SHADOW_EXTENT,
1127
+ frame.sdfScaleLens.innerShadowExtentDp * frame.densityScale,
1128
+ )
1129
+ setFloatUniform(
1130
+ SdfScaleLensShader.DISPLACEMENT_MAP_DEBUG,
1131
+ if (frame.sdfDisplacementMapDebug) 1f else 0f,
1132
+ )
1133
+ setFloatUniform(
1134
+ SdfScaleLensShader.DISPLACEMENT_ONLY_DEBUG,
1135
+ if (frame.displacementOnlyDebug) 1f else 0f,
1136
+ )
1137
+ }
1138
+ val runtimeEffect = sdfScaleLensEffect
1139
+ ?: RenderEffect.createRuntimeShaderEffect(shader, GlassUniforms.CONTENT).also {
1140
+ sdfScaleLensEffect = it
1141
+ LiquidGlassPerfTelemetry.effectBuild()
1142
+ }
1143
+ val prep = if (frame.displacementOnlyDebug || frame.sdfDisplacementMapDebug) {
1144
+ null
1145
+ } else {
1146
+ buildBackdropPrepEffect(frame.blurRadiusPx, 1f)
1147
+ } ?: return runtimeEffect
1148
+ if (cachedChainEffect == null || cachedChainRuntimeEffect !== runtimeEffect || cachedChainPrep !== prep) {
1149
+ cachedChainRuntimeEffect = runtimeEffect
1150
+ cachedChainPrep = prep
1151
+ cachedChainEffect = RenderEffect.createChainEffect(runtimeEffect, prep).also {
1152
+ LiquidGlassPerfTelemetry.effectBuild()
1153
+ }
1154
+ }
1155
+ return cachedChainEffect!!
1156
+ }
1157
+
1158
+ @RequiresApi(31)
1159
+ private fun buildBackdropPrepEffect(blurRadiusPx: Float, saturation: Float): RenderEffect? {
1160
+ if (cachedPrepValid && cachedPrepBlur == blurRadiusPx && cachedPrepSaturation == saturation) {
1161
+ return cachedPrepEffect
1162
+ }
1163
+ val blur = if (blurRadiusPx > MIN_BLUR_RADIUS_PX) {
1164
+ RenderEffect.createBlurEffect(blurRadiusPx, blurRadiusPx, Shader.TileMode.CLAMP).also {
1165
+ LiquidGlassPerfTelemetry.effectBuild()
1166
+ }
1167
+ } else {
1168
+ null
1169
+ }
1170
+ val effect = if (abs(saturation - 1f) < SATURATION_EPSILON) {
1171
+ blur
1172
+ } else {
1173
+ val filter = ColorMatrixColorFilter(ColorMatrix().apply { setSaturation(saturation) })
1174
+ if (blur != null) {
1175
+ RenderEffect.createColorFilterEffect(filter, blur).also { LiquidGlassPerfTelemetry.effectBuild() }
1176
+ } else {
1177
+ RenderEffect.createColorFilterEffect(filter).also { LiquidGlassPerfTelemetry.effectBuild() }
1178
+ }
1179
+ }
1180
+ cachedPrepBlur = blurRadiusPx
1181
+ cachedPrepSaturation = saturation
1182
+ cachedPrepEffect = effect
1183
+ cachedPrepValid = true
1184
+ return effect
1185
+ }
1186
+
1187
+ internal fun opticalInsets(frame: GlassFrame): GlassOpticalInsets {
1188
+ if (frame.opticsModel == GlassOpticsModel.REFERENCE_PARITY) {
1189
+ // The native RuntimeShader chain samples an expanded backdrop
1190
+ // RenderNode. Do not contract these margins without a proven
1191
+ // region-alignment invariant: fixed-input device captures showed
1192
+ // a roughly 0.8/255 change throughout the interior when the
1193
+ // independent extents were replaced by max(...).
1194
+ if (frame.backdropAlreadyBlurred &&
1195
+ !frame.referenceToggleBackdropEnabled &&
1196
+ frame.referenceInteractionProfile != 1
1197
+ ) {
1198
+ val strokeHalf = max(kotlin.math.ceil(frame.highlightWidthPx), 0.5f)
1199
+ val highlightSigma = max(frame.highlightWidthPx * 0.5f, 0.35f)
1200
+ val highlightMargin = if (frame.highlightAlpha > 0.001f) {
1201
+ strokeHalf + 4f * highlightSigma
1202
+ } else {
1203
+ 0f
1204
+ }
1205
+ val basePad = max(highlightMargin + 2f, 4f)
1206
+ val amt = frame.refractionAmountPx
1207
+ if (amt < 0f && frame.widthPx > 0f && frame.heightPx > 0f) {
1208
+ val maxScale = max(max(frame.layerScaleX, frame.layerScaleY), 1f)
1209
+ val dispersionFactor = if (frame.dispersion > 0.5f) 2f else 1f
1210
+ val maxDisp = (-amt) * 1.3f * dispersionFactor * maxScale
1211
+ val refrH = frame.refractionHeightPx.coerceAtLeast(0f)
1212
+ val overshootX = max(0f, maxDisp + min(refrH, frame.widthPx * 0.5f) - frame.widthPx)
1213
+ val overshootY = max(0f, maxDisp + min(refrH, frame.heightPx * 0.5f) - frame.heightPx)
1214
+ val marginX = basePad + overshootX
1215
+ val marginY = basePad + overshootY
1216
+ return GlassOpticalInsets(
1217
+ left = marginX + max(-frame.contentOffsetXPx, 0f),
1218
+ top = marginY + max(-frame.contentOffsetYPx, 0f),
1219
+ right = marginX + max(frame.contentOffsetXPx, 0f),
1220
+ bottom = marginY + max(frame.contentOffsetYPx, 0f),
1221
+ )
1222
+ }
1223
+ val margin = basePad + abs(amt)
1224
+ return GlassOpticalInsets(
1225
+ left = margin + max(-frame.contentOffsetXPx, 0f),
1226
+ top = margin + max(-frame.contentOffsetYPx, 0f),
1227
+ right = margin + max(frame.contentOffsetXPx, 0f),
1228
+ bottom = margin + max(frame.contentOffsetYPx, 0f),
1229
+ )
1230
+ }
1231
+ val blurExtent = frame.blurRadiusPx * 3f
1232
+ val refractExtent = abs(frame.refractionAmountPx)
1233
+ val strokeExtent = frame.highlightWidthPx + 2f
1234
+ // The outer shadow is a procedural light pass: it never reads the
1235
+ // backdrop, and it is clipped to its own footprint where it is drawn.
1236
+ // Carrying its radius into this margin only enlarged the layer the
1237
+ // optical shader has to evaluate — on the fixture that was 70% of a
1238
+ // 328px margin, i.e. ~3x the shader work for no sampled pixel.
1239
+ val margin = blurExtent + refractExtent + strokeExtent
1240
+ // Keep the validated optical margins unchanged. A reference effect
1241
+ // that deliberately samples away from its glass body needs extra
1242
+ // source pixels on that side of the layer so the child shader is
1243
+ // not evaluated against a clipped consumer crop.
1244
+ return GlassOpticalInsets(
1245
+ left = margin + max(-frame.contentOffsetXPx, 0f),
1246
+ top = margin + max(-frame.contentOffsetYPx, 0f),
1247
+ right = margin + max(frame.contentOffsetXPx, 0f),
1248
+ bottom = margin + max(frame.contentOffsetYPx, 0f),
1249
+ )
1250
+ }
1251
+ if (frame.opticsModel != GlassOpticsModel.SDF_SCALE_LENS) {
1252
+ val margin = frame.blurRadiusPx * 2f + abs(frame.refractionAmountPx) +
1253
+ abs(frame.bodyRefractionAmountPx) + 4f
1254
+ return GlassOpticalInsets(margin, margin, margin, margin)
1255
+ }
1256
+ ensureSdfDisplacementBounds(frame)
1257
+ val shadowExtent = frame.sdfScaleLens.outerShadowBlurRadiusDp * frame.densityScale * 3f
1258
+ val shadowOffset = frame.sdfScaleLens.outerShadowOffsetYDp * frame.densityScale
1259
+ val prepBlurExtent = frame.blurRadiusPx * 3f
1260
+ val safety = 1f
1261
+ return GlassOpticalInsets(
1262
+ left = cachedSdfMaxSampleDisplacementX + shadowExtent + prepBlurExtent + safety,
1263
+ top = cachedSdfMaxSampleDisplacementY + max(shadowExtent - shadowOffset, 0f) + prepBlurExtent + safety,
1264
+ right = cachedSdfMaxSampleDisplacementX + shadowExtent + prepBlurExtent + safety,
1265
+ bottom = cachedSdfMaxSampleDisplacementY + shadowExtent + shadowOffset + prepBlurExtent + safety,
1266
+ )
1267
+ }
1268
+
1269
+ private fun ensureSdfDisplacementBounds(frame: GlassFrame) {
1270
+ if (cachedSdfWidth == frame.widthPx && cachedSdfHeight == frame.heightPx) return
1271
+ cachedSdfWidth = frame.widthPx
1272
+ cachedSdfHeight = frame.heightPx
1273
+ cachedSdfMaxRawDisplacement = SdfScaleLensShader.maxRawDisplacementPx(frame.widthPx, frame.heightPx)
1274
+ val (maxX, maxY) = SdfScaleLensShader.maxSampleDisplacementAxesPx(frame.widthPx, frame.heightPx)
1275
+ cachedSdfMaxSampleDisplacementX = maxX
1276
+ cachedSdfMaxSampleDisplacementY = maxY
1277
+ }
1278
+
1279
+ private fun shapePath(frame: GlassFrame): Path {
1280
+ if (cachedShapeWidth != frame.widthPx || cachedShapeHeight != frame.heightPx || cachedShapeRadius != frame.cornerRadiusPx || cachedShapeModel != frame.opticsModel) {
1281
+ if (frame.opticsModel == GlassOpticsModel.REFERENCE_PARITY) {
1282
+ clipPath.set(G2RoundedRectangle.path(frame.widthPx, frame.heightPx, frame.cornerRadiusPx))
1283
+ } else {
1284
+ clipPath.rewind()
1285
+ rectF.set(0f, 0f, frame.widthPx, frame.heightPx)
1286
+ clipPath.addRoundRect(rectF, frame.cornerRadiusPx, frame.cornerRadiusPx, Path.Direction.CW)
1287
+ }
1288
+ cachedShapeWidth = frame.widthPx
1289
+ cachedShapeHeight = frame.heightPx
1290
+ cachedShapeRadius = frame.cornerRadiusPx
1291
+ cachedShapeModel = frame.opticsModel
1292
+ }
1293
+ return clipPath
1294
+ }
1295
+
1296
+ private fun drawFill(canvas: Canvas, frame: GlassFrame, color: Int) {
1297
+ scrimPaint.shader = null
1298
+ scrimPaint.color = color
1299
+ canvas.drawPath(shapePath(frame), scrimPaint)
1300
+ }
1301
+
1302
+ private fun drawRim(canvas: Canvas, frame: GlassFrame) {
1303
+ if (frame.highlightAlpha <= 0f || frame.highlightWidthPx <= 0f) return
1304
+ val angleRadians = Math.toRadians(frame.lightAngleDegrees.toDouble())
1305
+ val dirX = cos(angleRadians).toFloat()
1306
+ val dirY = sin(angleRadians).toFloat()
1307
+ val cx = frame.widthPx / 2f
1308
+ val cy = frame.heightPx / 2f
1309
+ val reach = max(frame.widthPx, frame.heightPx) / 2f
1310
+ val alpha = (frame.highlightAlpha * 255).toInt().coerceIn(0, 255)
1311
+ rimPaint.strokeWidth = frame.highlightWidthPx
1312
+ rimPaint.shader = LinearGradient(
1313
+ cx + dirX * reach, cy + dirY * reach,
1314
+ cx - dirX * reach, cy - dirY * reach,
1315
+ intArrayOf(
1316
+ Color.argb(alpha, 255, 255, 255),
1317
+ Color.argb((alpha * 0.08f).toInt(), 255, 255, 255),
1318
+ Color.argb((alpha * 0.55f).toInt(), 255, 255, 255),
1319
+ ),
1320
+ floatArrayOf(0f, 0.5f, 1f),
1321
+ Shader.TileMode.CLAMP,
1322
+ )
1323
+ canvas.drawPath(shapePath(frame), rimPaint)
1324
+ }
1325
+
1326
+ private companion object {
1327
+ private const val PARITY_EFFECT_CACHE_CAPACITY = 96
1328
+ private const val LIGHT_SHADER_CACHE_CAPACITY = 64
1329
+ private val ZERO_INSETS = GlassOpticalInsets(0f, 0f, 0f, 0f)
1330
+
1331
+ private data class ParityEffectKey(
1332
+ val insetLeftBits: Int,
1333
+ val insetTopBits: Int,
1334
+ val widthBits: Int,
1335
+ val heightBits: Int,
1336
+ val radiusBits: Int,
1337
+ val refrHeightBits: Int,
1338
+ val refrAmountBits: Int,
1339
+ val depthEffect: Boolean,
1340
+ val contentScaleXBits: Int,
1341
+ val contentScaleYBits: Int,
1342
+ val contentOffsetXBits: Int,
1343
+ val contentOffsetYBits: Int,
1344
+ val layerScaleXBits: Int,
1345
+ val layerScaleYBits: Int,
1346
+ val layerTransXBits: Int,
1347
+ val layerTransYBits: Int,
1348
+ val interactionProfile: Int,
1349
+ val dispersionBits: Int,
1350
+ val saturationBits: Int,
1351
+ val brightnessBits: Int,
1352
+ val contrastBits: Int,
1353
+ val lightAngleBits: Int,
1354
+ val highlightAlphaBits: Int,
1355
+ val highlightWidthBits: Int,
1356
+ val progressiveBlurBits: Int,
1357
+ val tintColor: Int,
1358
+ val tintAlphaBits: Int,
1359
+ val surfaceColor: Int,
1360
+ )
1361
+
1362
+ private data class OuterShadowKey(
1363
+ val insetLeftBits: Int,
1364
+ val insetTopBits: Int,
1365
+ val widthBits: Int,
1366
+ val heightBits: Int,
1367
+ val radiusBits: Int,
1368
+ val alphaBits: Int,
1369
+ val shadowRadiusBits: Int,
1370
+ val offsetYBits: Int,
1371
+ )
1372
+
1373
+ private data class InnerShadowKey(
1374
+ val insetLeftBits: Int,
1375
+ val insetTopBits: Int,
1376
+ val widthBits: Int,
1377
+ val heightBits: Int,
1378
+ val radiusBits: Int,
1379
+ val strengthBits: Int,
1380
+ val shadowRadiusBits: Int,
1381
+ val offsetYBits: Int,
1382
+ )
1383
+
1384
+ private data class HighlightKey(
1385
+ val insetLeftBits: Int,
1386
+ val insetTopBits: Int,
1387
+ val widthBits: Int,
1388
+ val heightBits: Int,
1389
+ val radiusBits: Int,
1390
+ val alphaBits: Int,
1391
+ val widthStrokeBits: Int,
1392
+ val angleBits: Int,
1393
+ val style: Int,
1394
+ val falloffBits: Int,
1395
+ val color: Int,
1396
+ )
1397
+
1398
+ private var sharedTemplateParityShader: RuntimeShader? = null
1399
+ private val sharedParityEffectCache = LinkedHashMap<ParityEffectKey, RenderEffect>(PARITY_EFFECT_CACHE_CAPACITY, 0.75f, true)
1400
+ private val sharedOuterShadowCache = LinkedHashMap<OuterShadowKey, RuntimeShader>(LIGHT_SHADER_CACHE_CAPACITY, 0.75f, true)
1401
+ private val sharedInnerShadowCache = LinkedHashMap<InnerShadowKey, RuntimeShader>(LIGHT_SHADER_CACHE_CAPACITY, 0.75f, true)
1402
+ private val sharedHighlightCache = LinkedHashMap<HighlightKey, RuntimeShader>(LIGHT_SHADER_CACHE_CAPACITY, 0.75f, true)
1403
+
1404
+ private fun isUiThread(): Boolean = try {
1405
+ val main = Looper.getMainLooper()
1406
+ main != null && Looper.myLooper() === main
1407
+ } catch (_: Throwable) {
1408
+ false
1409
+ }
1410
+
1411
+ private fun parityEffectKey(frame: GlassFrame, insets: GlassOpticalInsets): ParityEffectKey =
1412
+ ParityEffectKey(
1413
+ insetLeftBits = insets.left.toBits(),
1414
+ insetTopBits = insets.top.toBits(),
1415
+ widthBits = frame.widthPx.toBits(),
1416
+ heightBits = frame.heightPx.toBits(),
1417
+ radiusBits = frame.cornerRadiusPx.toBits(),
1418
+ refrHeightBits = frame.refractionHeightPx.toBits(),
1419
+ refrAmountBits = frame.refractionAmountPx.toBits(),
1420
+ depthEffect = frame.referenceDepthEffect,
1421
+ contentScaleXBits = frame.contentScaleX.toBits(),
1422
+ contentScaleYBits = frame.contentScaleY.toBits(),
1423
+ contentOffsetXBits = frame.contentOffsetXPx.toBits(),
1424
+ contentOffsetYBits = frame.contentOffsetYPx.toBits(),
1425
+ layerScaleXBits = frame.layerScaleX.toBits(),
1426
+ layerScaleYBits = frame.layerScaleY.toBits(),
1427
+ layerTransXBits = frame.layerTranslationXPx.toBits(),
1428
+ layerTransYBits = frame.layerTranslationYPx.toBits(),
1429
+ interactionProfile = frame.referenceInteractionProfile,
1430
+ dispersionBits = frame.dispersion.toBits(),
1431
+ saturationBits = frame.saturation.toBits(),
1432
+ brightnessBits = frame.brightness.toBits(),
1433
+ contrastBits = frame.contrast.toBits(),
1434
+ lightAngleBits = frame.lightAngleDegrees.toBits(),
1435
+ highlightAlphaBits = frame.highlightAlpha.toBits(),
1436
+ highlightWidthBits = frame.highlightWidthPx.toBits(),
1437
+ progressiveBlurBits = frame.progressiveBlurIntensity.toBits(),
1438
+ tintColor = frame.tintColor,
1439
+ tintAlphaBits = frame.tintAlpha.toBits(),
1440
+ surfaceColor = frame.surfaceColor,
1441
+ )
1442
+
1443
+ private fun putSharedParityEffect(key: ParityEffectKey, effect: RenderEffect) {
1444
+ sharedParityEffectCache[key] = effect
1445
+ if (sharedParityEffectCache.size > PARITY_EFFECT_CACHE_CAPACITY) {
1446
+ val eldest = sharedParityEffectCache.entries.iterator().next()
1447
+ sharedParityEffectCache.remove(eldest.key)
1448
+ }
1449
+ }
1450
+
1451
+ private fun <K> putSharedLightShader(cache: LinkedHashMap<K, RuntimeShader>, key: K, shader: RuntimeShader) {
1452
+ cache[key] = shader
1453
+ if (cache.size > LIGHT_SHADER_CACHE_CAPACITY) {
1454
+ val eldest = cache.entries.iterator().next()
1455
+ cache.remove(eldest.key)
1456
+ }
1457
+ }
1458
+ }
1459
+ }