mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
Move hit testing information out of WebRender
Store hit testing information in a data structure that sits alongside the display list in the compositor. This will allow the compositor to store more information per-node. The data structure also takes care of de-duplicating information between successive display list entries. In the future, the data structure can be even more aggressive in producing smaller side hit testing lists, if necessary.
This commit is contained in:
parent
d95c371d79
commit
6d4b7e7a22
10 changed files with 225 additions and 107 deletions
44
components/script_traits/compositor.rs
Normal file
44
components/script_traits/compositor.rs
Normal file
|
@ -0,0 +1,44 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
//! Defines data structures which are consumed by the Compositor.
|
||||
|
||||
use embedder_traits::Cursor;
|
||||
|
||||
/// Information that Servo keeps alongside WebRender display items
|
||||
/// in order to add more context to hit test results.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct HitTestInfo {
|
||||
/// The id of the node of this hit test item.
|
||||
pub node: u64,
|
||||
|
||||
/// The cursor of this node's hit test item.
|
||||
pub cursor: Option<Cursor>,
|
||||
}
|
||||
|
||||
/// A data structure which stores compositor-side information about
|
||||
/// display lists sent to the compositor.
|
||||
/// by a WebRender display list.
|
||||
#[derive(Debug, Default, Deserialize, Serialize)]
|
||||
pub struct CompositorDisplayListInfo {
|
||||
/// An array of `HitTestInfo` which is used to store information
|
||||
/// to assist the compositor to take various actions (set the cursor,
|
||||
/// scroll without layout) using a WebRender hit test result.
|
||||
pub hit_test_info: Vec<HitTestInfo>,
|
||||
}
|
||||
|
||||
impl CompositorDisplayListInfo {
|
||||
/// Add or re-use a duplicate HitTestInfo entry in this `CompositorHitTestInfo`
|
||||
/// and return the index.
|
||||
pub fn add_hit_test_info(&mut self, node: u64, cursor: Option<Cursor>) -> usize {
|
||||
if let Some(last) = self.hit_test_info.last() {
|
||||
if node == last.node && cursor == last.cursor {
|
||||
return self.hit_test_info.len() - 1;
|
||||
}
|
||||
}
|
||||
|
||||
self.hit_test_info.push(HitTestInfo { node, cursor });
|
||||
self.hit_test_info.len() - 1
|
||||
}
|
||||
}
|
|
@ -18,11 +18,13 @@ extern crate malloc_size_of_derive;
|
|||
#[macro_use]
|
||||
extern crate serde;
|
||||
|
||||
pub mod compositor;
|
||||
mod script_msg;
|
||||
pub mod serializable;
|
||||
pub mod transferable;
|
||||
pub mod webdriver_msg;
|
||||
|
||||
use crate::compositor::CompositorDisplayListInfo;
|
||||
use crate::serializable::{BlobData, BlobImpl};
|
||||
use crate::transferable::MessagePortImpl;
|
||||
use crate::webdriver_msg::{LoadStatus, WebDriverScriptCommand};
|
||||
|
@ -30,7 +32,7 @@ use bluetooth_traits::BluetoothRequest;
|
|||
use canvas_traits::webgl::WebGLPipeline;
|
||||
use crossbeam_channel::{Receiver, RecvTimeoutError, Sender};
|
||||
use devtools_traits::{DevtoolScriptControlMsg, ScriptToDevtoolsControlMsg, WorkerId};
|
||||
use embedder_traits::EventLoopWaker;
|
||||
use embedder_traits::{Cursor, EventLoopWaker};
|
||||
use euclid::{default::Point2D, Length, Rect, Scale, Size2D, UnknownUnit, Vector2D};
|
||||
use gfx_traits::Epoch;
|
||||
use http::HeaderMap;
|
||||
|
@ -74,7 +76,7 @@ use webrender_api::{
|
|||
BuiltDisplayList, DocumentId, ExternalImageData, ExternalScrollId, ImageData, ImageDescriptor,
|
||||
ImageKey, ScrollClamping,
|
||||
};
|
||||
use webrender_api::{BuiltDisplayListDescriptor, HitTestFlags, HitTestResult};
|
||||
use webrender_api::{BuiltDisplayListDescriptor, HitTestFlags};
|
||||
|
||||
pub use crate::script_msg::{
|
||||
DOMMessage, HistoryEntryReplacement, Job, JobError, JobResult, JobResultValue, JobType,
|
||||
|
@ -1110,6 +1112,25 @@ impl From<i32> for MediaSessionActionType {
|
|||
}
|
||||
}
|
||||
|
||||
/// The result of a hit test in the compositor.
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct CompositorHitTestResult {
|
||||
/// The pipeline id of the resulting item.
|
||||
pub pipeline_id: PipelineId,
|
||||
|
||||
/// The hit test point in the item's viewport.
|
||||
pub point_in_viewport: euclid::default::Point2D<f32>,
|
||||
|
||||
/// The hit test point relative to the item itself.
|
||||
pub point_relative_to_item: euclid::default::Point2D<f32>,
|
||||
|
||||
/// The node address of the hit test result.
|
||||
pub node: UntrustedNodeAddress,
|
||||
|
||||
/// The cursor that should be used when hovering the item hit by the hit test.
|
||||
pub cursor: Option<Cursor>,
|
||||
}
|
||||
|
||||
/// The set of WebRender operations that can be initiated by the content process.
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub enum WebrenderMsg {
|
||||
|
@ -1125,6 +1146,7 @@ pub enum WebrenderMsg {
|
|||
LayoutSize,
|
||||
ipc::IpcBytesReceiver,
|
||||
BuiltDisplayListDescriptor,
|
||||
CompositorDisplayListInfo,
|
||||
),
|
||||
/// Perform a hit test operation. The result will be returned via
|
||||
/// the provided channel sender.
|
||||
|
@ -1132,7 +1154,7 @@ pub enum WebrenderMsg {
|
|||
Option<webrender_api::PipelineId>,
|
||||
WorldPoint,
|
||||
HitTestFlags,
|
||||
IpcSender<HitTestResult>,
|
||||
IpcSender<Vec<CompositorHitTestResult>>,
|
||||
),
|
||||
/// Create a new image key. The result will be returned via the
|
||||
/// provided channel sender.
|
||||
|
@ -1178,6 +1200,7 @@ impl WebrenderIpcSender {
|
|||
&self,
|
||||
epoch: Epoch,
|
||||
size: LayoutSize,
|
||||
display_list_info: CompositorDisplayListInfo,
|
||||
(pipeline, size2, list): (webrender_api::PipelineId, LayoutSize, BuiltDisplayList),
|
||||
) {
|
||||
let (data, descriptor) = list.into_data();
|
||||
|
@ -1189,6 +1212,7 @@ impl WebrenderIpcSender {
|
|||
size2,
|
||||
receiver,
|
||||
descriptor,
|
||||
display_list_info,
|
||||
)) {
|
||||
warn!("Error sending display list: {}", e);
|
||||
}
|
||||
|
@ -1205,7 +1229,7 @@ impl WebrenderIpcSender {
|
|||
pipeline: Option<webrender_api::PipelineId>,
|
||||
point: WorldPoint,
|
||||
flags: HitTestFlags,
|
||||
) -> HitTestResult {
|
||||
) -> Vec<CompositorHitTestResult> {
|
||||
let (sender, receiver) = ipc::channel().unwrap();
|
||||
self.0
|
||||
.send(WebrenderMsg::HitTest(pipeline, point, flags, sender))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue