script: Refactor channels in ScriptThread into receivers and senders (#34776)

Create two new data structures in the `script` crate to hold senders and
receiver:

- `ScriptThreadSenders`: holds all outgoing channels from the
  `ScriptThread` including a channel to the `ScriptThread` itself. The
  ultimate goal with this is to reduce duplication by giving a boxed
  version of this this to `Window`s.
- `ScriptThradReceivers`: holds all incoming channels to the
  `ScriptThread`. This isn't cloenable like the senders. This is used to
  abstract away `recv()` and `try_recv()` methods used to make the
  `ScriptThread` event loop easier to read.

In addition:

- The many duplicated `ScriptThread` self-senders for the `TaskManager`
  have been removed and, in general, a lot of boilerplate is removed as
  well.
- Visibilty of all methods affected by this change is changed to
  `pub(crate)` in order to take advantage of dead code detection. Some
  dead code produced from macros is removed.
- Some conversion code is refactord into implementations of the `From`
  trait.
- The names of channels uses a standard "sender" and "receiver" naming
  as well as trying to be descriptive of where they go in `ScriptThread`
  as well as `InitialScriptState`

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
Martin Robinson 2024-12-26 04:34:54 +01:00 committed by GitHub
parent 1e95712772
commit 5f927a2c28
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
30 changed files with 732 additions and 902 deletions

View file

@ -616,33 +616,33 @@ pub struct InitialScriptState {
/// Loading into a Secure Context
pub inherited_secure_context: Option<bool>,
/// A channel with which messages can be sent to us (the script thread).
pub control_chan: IpcSender<ConstellationControlMsg>,
pub constellation_sender: IpcSender<ConstellationControlMsg>,
/// A port on which messages sent by the constellation to script can be received.
pub control_port: IpcReceiver<ConstellationControlMsg>,
pub constellation_receiver: IpcReceiver<ConstellationControlMsg>,
/// A channel on which messages can be sent to the constellation from script.
pub script_to_constellation_chan: ScriptToConstellationChan,
pub pipeline_to_constellation_sender: ScriptToConstellationChan,
/// A handle to register script-(and associated layout-)threads for hang monitoring.
pub background_hang_monitor_register: Box<dyn BackgroundHangMonitorRegister>,
/// A sender layout to communicate to the constellation.
pub layout_to_constellation_chan: IpcSender<LayoutMsg>,
pub layout_to_constellation_ipc_sender: IpcSender<LayoutMsg>,
/// A channel to the resource manager thread.
pub resource_threads: ResourceThreads,
/// A channel to the bluetooth thread.
pub bluetooth_thread: IpcSender<BluetoothRequest>,
pub bluetooth_sender: IpcSender<BluetoothRequest>,
/// The image cache for this script thread.
pub image_cache: Arc<dyn ImageCache>,
/// A channel to the time profiler thread.
pub time_profiler_chan: profile_traits::time::ProfilerChan,
pub time_profiler_sender: profile_traits::time::ProfilerChan,
/// A channel to the memory profiler thread.
pub mem_profiler_chan: mem::ProfilerChan,
pub memory_profiler_sender: mem::ProfilerChan,
/// A channel to the developer tools, if applicable.
pub devtools_chan: Option<IpcSender<ScriptToDevtoolsControlMsg>>,
pub devtools_server_sender: Option<IpcSender<ScriptToDevtoolsControlMsg>>,
/// Information about the initial window size.
pub window_size: WindowSizeData,
/// The ID of the pipeline namespace for this script thread.
pub pipeline_namespace_id: PipelineNamespaceId,
/// A ping will be sent on this channel once the script thread shuts down.
pub content_process_shutdown_chan: Sender<()>,
pub content_process_shutdown_sender: Sender<()>,
/// A channel to the WebGL thread used in this pipeline.
pub webgl_chan: Option<WebGLPipeline>,
/// The XR device registry