servo/components
Mukilan Thiyagarajan 55bb289b30
android: fix broken rendering in emulators (#31727)
Android's OpenGL emulation layer (goldfish-opengl) has pre-processing
logic that looks for samplers of the type `samplerExternalOES` and
does a simple textual [replacement to change the type][1] to `sampler2D`
before compilation. It also [marks the sampler][2] as 'replaced' so
it can emulate the correct type at runtime.

However, this logic can lead to false positives when the sampler is
declared inside conditional macros. Hence, the sampler's type can be
incorrectly marked as `samplerExternalOES` even though the #if, #ifdef
conditional logic would have declared the type as `sampler2D`.
This seems to be a [known limitation][3].

WebRender (in particular the shared.glsl include) has such conditional
declaration of the texture units used from the shaders.
In particular, the sampler [sColor0 here][4] is declared within ifdefs
to have different types depending on the flags enabled, to allow the
shader to work with different image target kinds.

WebRender also maintain two versions of the compiled shaders in its cache:
  1. An unoptimized version with all the conditional logic preserved
     in the source until the shader is compiled at runtime on Android,
     when the shader is actually used.
  2. Multiple optimized versions for combinations of features required
     These versions are produced during Servo [build][5]. Thus the
     optimized versions eliminate most of the conditional declarations
     at build time.

The bug in Servo with current code is because, [by default][6], WebRender
uses the *unoptimized* versions of the shaders. This means the conditional
GLSL source is evaluated at runtime by the Android emulator and thus ends
up with the incorrect type for the sColor0 sampler unit, which breaks the
[texture sampling in the fragment shader][7], causing it to always return
Vec4(0, 0, 0, 1) and rendering all elements on the page black.

This change forces WebRender to use the *optimized* version as a
workaround - the optimized versions have unconditional code for the
sampler declarations so are not susceptible to the emulator issue.

[1]: https://android.googlesource.com/device/generic/goldfish-opengl/+/refs/tags/android-platform-11.0.0_r40/system/GLESv2_enc/GL2Encoder.cpp#1644
[2]: https://android.googlesource.com/device/generic/goldfish-opengl/+/refs/tags/android-platform-11.0.0_r40/system/GLESv2_enc/GL2Encoder.cpp#1673
[3]: https://android.googlesource.com/device/generic/goldfish-opengl/+/refs/tags/android-platform-11.0.0_r40/system/GLESv2_enc/GL2Encoder.cpp#1571
[4]: b36399019c/webrender/res/shared.glsl (L206)
[5]: b36399019c/webrender/build.rs (L289)
[6]: b36399019c/webrender/src/renderer/init.rs (L214)
[7]: b36399019c/webrender/res/composite.glsl (L189)

Fixes #31726.

Signed-off-by: Mukilan Thiyagarajan <mukilan@igalia.com>
2024-03-18 10:57:42 +00:00
..
allocator rustdoc: Add some basic Safety sections to unsafe functions (#31639) 2024-03-13 10:44:59 +00:00
background_hang_monitor fix: missing thread name when spawning (#31656) 2024-03-14 10:40:58 +00:00
bluetooth clippy: fix warnings in components/bluetooth (#31566) 2024-03-07 23:32:35 +00:00
canvas fonts: Add FontIdentifier and LocalFontIdentifier (#31658) 2024-03-14 11:31:00 +00:00
compositing dependencies: Upgrade to WebRender 0.64 (#31486) 2024-03-14 17:40:54 +00:00
config compositor: Remove the is_running_problem_test setting (#31589) 2024-03-09 02:29:43 +00:00
config_plugins clippy: fix warnings in components/config* (#31562) 2024-03-08 07:15:56 +00:00
constellation constellation: allow event tracing to be configured with RUST_LOG (#31659) 2024-03-14 12:28:36 +00:00
deny_public_fields Strict import formatting (grouping and granularity) (#30325) 2023-09-11 19:16:54 +00:00
devtools Fix clippy warnings in components/rand (#31549) 2024-03-07 23:16:42 +00:00
dom_struct clippy: fix warnings in various modules in components (#31568) 2024-03-08 14:28:04 +00:00
domobject_derive clippy: fix warnings in various modules in components (#31568) 2024-03-08 14:28:04 +00:00
geometry dependencies: Upgrade to WebRender 0.64 (#31486) 2024-03-14 17:40:54 +00:00
gfx clippy: Fix several warnings (#31710) 2024-03-18 08:33:43 +00:00
hyper_serde clippy: fix warnings in various modules in components (#31568) 2024-03-08 14:28:04 +00:00
jstraceable_derive Update to syn 2 where possible (#30387) 2023-09-19 15:57:37 +00:00
layout dependencies: Upgrade to WebRender 0.64 (#31486) 2024-03-14 17:40:54 +00:00
layout_2020 clippy: Fix several warnings (#31710) 2024-03-18 08:33:43 +00:00
layout_thread dependencies: Upgrade to WebRender 0.64 (#31486) 2024-03-14 17:40:54 +00:00
layout_thread_2020 layout: Add basic support for getClientRects() queries (#31696) 2024-03-15 17:20:47 +00:00
media clippy: fix warnings in various modules in components (#31568) 2024-03-08 14:28:04 +00:00
metrics clippy: Fix assorted warnings in components/ (#31628) 2024-03-13 08:31:58 +00:00
net fix: missing thread name when spawning (#31656) 2024-03-14 10:40:58 +00:00
pixels clippy: fix warnings in various modules in components (#31568) 2024-03-08 14:28:04 +00:00
profile clippy: fix warnings in various modules in components (#31568) 2024-03-08 14:28:04 +00:00
rand Fix clippy warnings in components/rand (#31549) 2024-03-07 23:16:42 +00:00
range clippy: fix warnings in various modules in components (#31568) 2024-03-08 14:28:04 +00:00
remutex clippy: fix warnings in various modules in components (#31568) 2024-03-08 14:28:04 +00:00
script clippy: Fix some warnings in the script crate (#31719) 2024-03-18 10:05:18 +00:00
servo android: fix broken rendering in emulators (#31727) 2024-03-18 10:57:42 +00:00
shared Updated comment with 'layout_traits' to 'script_layout_interface' (#31707) 2024-03-15 22:15:14 +00:00
url clippy: fix warnings in various modules in components (#31568) 2024-03-08 14:28:04 +00:00
webdriver_server clippy: Fix assorted warnings in components/ (#31628) 2024-03-13 08:31:58 +00:00
webgpu clippy: Fix assorted warnings in components/ (#31628) 2024-03-13 08:31:58 +00:00