zed/crates
Antonio Scandurra 4700d33728
Fix flickering (#9012)
See https://zed.dev/channel/gpui-536

Fixes https://github.com/zed-industries/zed/issues/9010
Fixes https://github.com/zed-industries/zed/issues/8883
Fixes https://github.com/zed-industries/zed/issues/8640
Fixes https://github.com/zed-industries/zed/issues/8598
Fixes https://github.com/zed-industries/zed/issues/8579
Fixes https://github.com/zed-industries/zed/issues/8363
Fixes https://github.com/zed-industries/zed/issues/8207


### Problem

After transitioning Zed to GPUI 2, we started noticing that interacting
with the mouse on many UI elements would lead to a pretty annoying
flicker. The main issue with the old approach was that hover state was
calculated based on the previous frame. That is, when computing whether
a given element was hovered in the current frame, we would use
information about the same element in the previous frame.

However, inspecting the previous frame tells us very little about what
should be hovered in the current frame, as elements in the current frame
may have changed significantly.

### Solution

This pull request's main contribution is the introduction of a new
`after_layout` phase when redrawing the window. The key idea is that
we'll give every element a chance to register a hitbox (see
`ElementContext::insert_hitbox`) before painting anything. Then, during
the `paint` phase, elements can determine whether they're the topmost
and draw their hover state accordingly.

We are also removing the ability to give an arbitrary z-index to
elements. Instead, we will follow the much simpler painter's algorithm.
That is, an element that gets painted after will be drawn on top of an
element that got painted earlier. Elements can still escape their
current "stacking context" by using the new `ElementContext::defer_draw`
method (see `Overlay` for an example). Elements drawn using this method
will still be logically considered as being children of their original
parent (for keybinding, focus and cache invalidation purposes) but their
layout and paint passes will be deferred until the currently-drawn
element is done.

With these changes we also reworked geometry batching within the
`Scene`. The new approach uses an AABB tree to determine geometry
occlusion, which allows the GPU to render non-overlapping geometry in
parallel.

### Performance

Performance is slightly better than on `main` even though this new
approach is more correct and we're maintaining an extra data structure
(the AABB tree).


![before_after](https://github.com/zed-industries/zed/assets/482957/c8120b07-1dbd-4776-834a-d040e569a71e)

Release Notes:

- Fixed a bug that was causing popovers to flicker.

---------

Co-authored-by: Nathan Sobo <nathan@zed.dev>
Co-authored-by: Thorsten <thorsten@zed.dev>
2024-03-11 10:45:57 +01:00
..
activity_indicator Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
ai Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
assets Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
assistant Fix flickering (#9012) 2024-03-11 10:45:57 +01:00
audio Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
auto_update Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
breadcrumbs Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
call Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
channel Fix joining hosted projects (#9038) 2024-03-07 19:56:41 -07:00
cli Fix flickering (#9012) 2024-03-11 10:45:57 +01:00
client Fix joining hosted projects (#9038) 2024-03-07 19:56:41 -07:00
clock Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
collab Fix flickering (#9012) 2024-03-11 10:45:57 +01:00
collab_ui Fix flickering (#9012) 2024-03-11 10:45:57 +01:00
collections Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
color Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
command_palette Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
command_palette_hooks Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
copilot Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
copilot_ui Splice remove suggesion hints when those are cleared in the editor. (#9088) 2024-03-09 02:00:01 +02:00
db Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
diagnostics Fix flickering (#9012) 2024-03-11 10:45:57 +01:00
editor Fix flickering (#9012) 2024-03-11 10:45:57 +01:00
extension Add rs-notify implementation of fs::watch (#9040) 2024-03-08 22:18:44 -08:00
extension_api Provide wasm extensions with APIs needed for using pre-installed LSP binaries (#9085) 2024-03-08 17:18:06 -05:00
extensions_ui Fix flickering (#9012) 2024-03-11 10:45:57 +01:00
feature_flags Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
feedback Remove feedback button from status bar (#9100) 2024-03-09 06:15:08 -05:00
file_finder Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
fs Add rs-notify implementation of fs::watch (#9040) 2024-03-08 22:18:44 -08:00
fsevent Add rs-notify implementation of fs::watch (#9040) 2024-03-08 22:18:44 -08:00
fuzzy Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
git Add editor::RevertSelectedHunks to revert git diff hunks in the editor (#9068) 2024-03-09 01:37:24 +02:00
go_to_line Allow highlighting editor rows from multiple sources concurrently (#9153) 2024-03-11 02:17:32 +02:00
gpui Fix flickering (#9012) 2024-03-11 10:45:57 +01:00
gpui_macros Fix flickering (#9012) 2024-03-11 10:45:57 +01:00
install_cli Fix flickering (#9012) 2024-03-11 10:45:57 +01:00
journal Fix panic in open urls (#9032) 2024-03-07 13:52:50 -07:00
language Add editor::RevertSelectedHunks to revert git diff hunks in the editor (#9068) 2024-03-09 01:37:24 +02:00
language_selector Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
language_tools Fix flickering (#9012) 2024-03-11 10:45:57 +01:00
languages Fix flickering (#9012) 2024-03-11 10:45:57 +01:00
live_kit_client Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
live_kit_server Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
lsp Always resolve code action if needed (#8904) 2024-03-05 23:42:12 +02:00
markdown_preview Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
media Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
menu Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
multi_buffer Add editor::RevertSelectedHunks to revert git diff hunks in the editor (#9068) 2024-03-09 01:37:24 +02:00
node_runtime Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
notifications Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
outline Allow highlighting editor rows from multiple sources concurrently (#9153) 2024-03-11 02:17:32 +02:00
picker Small fixes to task modal & long commands (#8974) 2024-03-07 03:21:11 +02:00
prettier Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
project Always single-quote directory when cd'ing to get shell env (#9145) 2024-03-10 13:53:24 +01:00
project_core Add rs-notify implementation of fs::watch (#9040) 2024-03-08 22:18:44 -08:00
project_panel Fix flickering (#9012) 2024-03-11 10:45:57 +01:00
project_symbols Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
quick_action_bar Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
recent_projects Fix panic in open urls (#9032) 2024-03-07 13:52:50 -07:00
refineable Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
release_channel Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
rich_text Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
rope Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
rpc Fix joining hosted projects (#9038) 2024-03-07 19:56:41 -07:00
search Update Project search to Project Search. (#8943) 2024-03-06 15:23:55 +01:00
semantic_index Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
settings Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
snippet Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
sqlez Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
sqlez_macros Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
story Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
storybook Fix flickering (#9012) 2024-03-11 10:45:57 +01:00
sum_tree Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
task Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
tasks_ui Task::spawn now takes an optional task name as an argument. 2024-03-08 15:28:42 +01:00
telemetry_events Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
terminal Fix flickering (#9012) 2024-03-11 10:45:57 +01:00
terminal_view Fix flickering (#9012) 2024-03-11 10:45:57 +01:00
text Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
theme Fix flickering (#9012) 2024-03-11 10:45:57 +01:00
theme_importer Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
theme_selector Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
time_format Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
ui Fix flickering (#9012) 2024-03-11 10:45:57 +01:00
util Make comment above util::fs::remove_matching a doc comment (#9051) 2024-03-07 21:15:52 -08:00
vcs_menu Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00
vim Fix Vim code formating (#9098) 2024-03-11 10:03:51 +02:00
welcome Fix panic in open urls (#9032) 2024-03-07 13:52:50 -07:00
workspace Fix flickering (#9012) 2024-03-11 10:45:57 +01:00
zed Always single-quote directory when cd'ing to get shell env (#9145) 2024-03-10 13:53:24 +01:00
zed_actions Move Clippy configuration to the workspace level (#8891) 2024-03-05 12:01:17 -05:00