Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit eef976c

Browse files
committed
Bug 1612440 - Move some scene-related transaction handling code to the scene builder thread. r=gw
The goal is to move this code out of the render backend to avoid requiring the messages to transit through this thread. Other similar changes are in progress. Differential Revision: https://phabricator.services.mozilla.com/D71781
1 parent 86ba544 commit eef976c

File tree

3 files changed

+170
-220
lines changed

3 files changed

+170
-220
lines changed

gfx/wr/webrender/src/render_backend.rs

Lines changed: 31 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
//! See the comment at the top of the `renderer` module for a description of
99
//! how these two pieces interact.
1010
11-
use api::{ApiMsg, BuiltDisplayList, ClearCache, DebugCommand, DebugFlags};
11+
use api::{ApiMsg, ClearCache, DebugCommand, DebugFlags};
1212
use api::{DocumentId, DocumentLayer, ExternalScrollId, FrameMsg, HitTestFlags, HitTestResult};
1313
use api::{IdNamespace, MemoryReport, PipelineId, RenderNotifier, SceneMsg, ScrollClamping};
1414
use api::{ScrollLocation, TransactionMsg, ResourceUpdate, BlobImageKey};
@@ -30,7 +30,7 @@ use crate::glyph_rasterizer::{FontInstance};
3030
use crate::gpu_cache::GpuCache;
3131
use crate::hit_test::{HitTest, HitTester, SharedHitTester};
3232
use crate::intern::DataStore;
33-
use crate::internal_types::{DebugOutput, FastHashMap, FastHashSet, RenderedDocument, ResultMsg};
33+
use crate::internal_types::{DebugOutput, FastHashMap, RenderedDocument, ResultMsg};
3434
use malloc_size_of::{MallocSizeOf, MallocSizeOfOps};
3535
use crate::picture::{RetainedTiles, TileCacheLogger};
3636
use crate::prim_store::{PrimitiveScratchBuffer, PrimitiveInstance};
@@ -398,10 +398,6 @@ struct Document {
398398
/// The builder object that prodces frames, kept around to preserve some retained state.
399399
frame_builder: FrameBuilder,
400400

401-
/// A set of pipelines that the caller has requested be
402-
/// made available as output textures.
403-
output_pipelines: FastHashSet<PipelineId>,
404-
405401
/// A data structure to allow hit testing against rendered frames. This is updated
406402
/// every time we produce a fully rendered frame.
407403
hit_tester: Option<Arc<HitTester>>,
@@ -461,7 +457,6 @@ impl Document {
461457
stamp: FrameStamp::first(id),
462458
scene: BuiltScene::empty(),
463459
frame_builder: FrameBuilder::new(),
464-
output_pipelines: FastHashSet::default(),
465460
hit_tester: None,
466461
shared_hit_tester: Arc::new(SharedHitTester::new()),
467462
dynamic_properties: SceneProperties::new(),
@@ -665,11 +660,6 @@ impl Document {
665660
}
666661
}
667662

668-
pub fn discard_frame_state_for_pipeline(&mut self, pipeline_id: PipelineId) {
669-
self.scene.spatial_tree
670-
.discard_frame_state_for_pipeline(pipeline_id);
671-
}
672-
673663
/// Returns true if any nodes actually changed position or false otherwise.
674664
pub fn scroll_nearest_scrolling_ancestor(
675665
&mut self,
@@ -822,90 +812,6 @@ impl RenderBackend {
822812
}
823813
}
824814

825-
fn process_scene_msg(
826-
&mut self,
827-
document_id: DocumentId,
828-
message: SceneMsg,
829-
txn: &mut Transaction,
830-
) {
831-
let doc = self.documents.get_mut(&document_id).expect("No document?");
832-
833-
match message {
834-
SceneMsg::UpdateEpoch(pipeline_id, epoch) => {
835-
txn.epoch_updates.push((pipeline_id, epoch));
836-
}
837-
SceneMsg::SetPageZoom(factor) => {
838-
doc.view.page_zoom_factor = factor.get();
839-
}
840-
SceneMsg::SetQualitySettings { settings } => {
841-
doc.view.quality_settings = settings;
842-
}
843-
SceneMsg::SetDocumentView {
844-
device_rect,
845-
device_pixel_ratio,
846-
} => {
847-
doc.view.device_rect = device_rect;
848-
doc.view.device_pixel_ratio = device_pixel_ratio;
849-
}
850-
SceneMsg::SetDisplayList {
851-
epoch,
852-
pipeline_id,
853-
background,
854-
viewport_size,
855-
content_size,
856-
list_descriptor,
857-
list_data,
858-
preserve_frame_state,
859-
} => {
860-
profile_scope!("SetDisplayList");
861-
862-
let built_display_list =
863-
BuiltDisplayList::from_data(list_data, list_descriptor);
864-
865-
if !preserve_frame_state {
866-
doc.discard_frame_state_for_pipeline(pipeline_id);
867-
}
868-
869-
let display_list_len = built_display_list.data().len();
870-
let (builder_start_time_ns, builder_end_time_ns, send_time_ns) =
871-
built_display_list.times();
872-
873-
txn.display_list_updates.push(DisplayListUpdate {
874-
built_display_list,
875-
pipeline_id,
876-
epoch,
877-
background,
878-
viewport_size,
879-
content_size,
880-
timings: TransactionTimings {
881-
builder_start_time_ns,
882-
builder_end_time_ns,
883-
send_time_ns,
884-
scene_build_start_time_ns: 0,
885-
scene_build_end_time_ns: 0,
886-
blob_rasterization_end_time_ns: 0,
887-
display_list_len,
888-
},
889-
});
890-
}
891-
SceneMsg::SetRootPipeline(pipeline_id) => {
892-
profile_scope!("SetRootPipeline");
893-
txn.set_root_pipeline = Some(pipeline_id);
894-
}
895-
SceneMsg::RemovePipeline(pipeline_id) => {
896-
profile_scope!("RemovePipeline");
897-
txn.removed_pipelines.push((pipeline_id, document_id));
898-
}
899-
SceneMsg::EnableFrameOutput(pipeline_id, enable) => {
900-
if enable {
901-
doc.output_pipelines.insert(pipeline_id);
902-
} else {
903-
doc.output_pipelines.remove(&pipeline_id);
904-
}
905-
}
906-
}
907-
}
908-
909815
fn next_namespace_id(&self) -> IdNamespace {
910816
IdNamespace(NEXT_NAMESPACE_ID.fetch_add(1, Ordering::Relaxed) as u32)
911817
}
@@ -1051,6 +957,7 @@ impl RenderBackend {
1051957

1052958
if let Some(doc) = self.documents.get_mut(&txn.document_id) {
1053959
doc.removed_pipelines.append(&mut txn.removed_pipelines);
960+
doc.view = txn.view;
1054961

1055962
if let Some(built_scene) = txn.built_scene.take() {
1056963
doc.new_async_scene_ready(
@@ -1178,6 +1085,11 @@ impl RenderBackend {
11781085
);
11791086
let old = self.documents.insert(document_id, document);
11801087
debug_assert!(old.is_none());
1088+
1089+
self.scene_tx.send(
1090+
SceneBuilderRequest::AddDocument(document_id, initial_size, layer)
1091+
).unwrap();
1092+
11811093
}
11821094
ApiMsg::DeleteDocument(document_id) => {
11831095
self.documents.remove(&document_id);
@@ -1405,39 +1317,41 @@ impl RenderBackend {
14051317
let use_high_priority = transaction_msgs.iter()
14061318
.any(|transaction_msg| !transaction_msg.low_priority);
14071319

1408-
let mut txns : Vec<Box<Transaction>> = document_ids.iter().zip(transaction_msgs.drain(..))
1320+
let txns : Vec<Box<Transaction>> = document_ids.iter().zip(transaction_msgs.drain(..))
14091321
.map(|(&document_id, mut transaction_msg)| {
1322+
1323+
self.resource_cache.pre_scene_building_update(
1324+
&mut transaction_msg.resource_updates,
1325+
&mut profile_counters.resources,
1326+
);
1327+
1328+
// TODO(nical) I believe this is wrong. We should discard this state when swapping the
1329+
// scene after it is built.
1330+
for msg in &transaction_msg.scene_ops {
1331+
if let SceneMsg::SetDisplayList { preserve_frame_state: false, pipeline_id, .. } = *msg {
1332+
self.documents
1333+
.get_mut(&document_id)
1334+
.unwrap()
1335+
.scene
1336+
.spatial_tree
1337+
.discard_frame_state_for_pipeline(pipeline_id);
1338+
}
1339+
}
1340+
14101341
let mut txn = Box::new(Transaction {
14111342
document_id,
1412-
display_list_updates: Vec::new(),
1413-
removed_pipelines: Vec::new(),
1414-
epoch_updates: Vec::new(),
1415-
request_scene_build: None,
14161343
blob_rasterizer: None,
14171344
blob_requests: Vec::new(),
14181345
resource_updates: transaction_msg.resource_updates,
14191346
frame_ops: transaction_msg.frame_ops,
1347+
scene_ops: transaction_msg.scene_ops,
14201348
rasterized_blobs: Vec::new(),
14211349
notifications: transaction_msg.notifications,
1422-
set_root_pipeline: None,
14231350
render_frame: transaction_msg.generate_frame,
14241351
invalidate_rendered_frame: transaction_msg.invalidate_rendered_frame,
1352+
fonts: self.resource_cache.get_font_instances(),
14251353
});
14261354

1427-
self.resource_cache.pre_scene_building_update(
1428-
&mut txn.resource_updates,
1429-
&mut profile_counters.resources,
1430-
);
1431-
1432-
for scene_msg in transaction_msg.scene_ops.drain(..) {
1433-
let _timer = profile_counters.total_time.timer();
1434-
self.process_scene_msg(
1435-
document_id,
1436-
scene_msg,
1437-
&mut txn,
1438-
)
1439-
}
1440-
14411355
let blobs_to_rasterize = get_blob_image_updates(&txn.resource_updates);
14421356
if !blobs_to_rasterize.is_empty() {
14431357
let (blob_rasterizer, blob_requests) = self.resource_cache
@@ -1453,19 +1367,7 @@ impl RenderBackend {
14531367
!txn.can_skip_scene_builder() || txn.blob_rasterizer.is_some()
14541368
});
14551369

1456-
if use_scene_builder {
1457-
for txn in txns.iter_mut() {
1458-
let doc = self.documents.get_mut(&txn.document_id).unwrap();
1459-
1460-
if txn.should_build_scene() {
1461-
txn.request_scene_build = Some(SceneRequest {
1462-
view: doc.view.clone(),
1463-
font_instances: self.resource_cache.get_font_instances(),
1464-
output_pipelines: doc.output_pipelines.clone(),
1465-
});
1466-
}
1467-
}
1468-
} else {
1370+
if !use_scene_builder {
14691371
self.prepare_for_frames();
14701372
self.maybe_force_nop_documents(
14711373
frame_counter,
@@ -2072,7 +1974,6 @@ impl RenderBackend {
20721974
view: view.clone(),
20731975
stamp: FrameStamp::first(id),
20741976
frame_builder: FrameBuilder::new(),
2075-
output_pipelines: FastHashSet::default(),
20761977
dynamic_properties: properties,
20771978
hit_tester: None,
20781979
shared_hit_tester: Arc::new(SharedHitTester::new()),
@@ -2122,7 +2023,6 @@ impl RenderBackend {
21222023
scene,
21232024
view: view.clone(),
21242025
config: self.frame_config.clone(),
2125-
output_pipelines: self.documents[&id].output_pipelines.clone(),
21262026
font_instances: self.resource_cache.get_font_instances(),
21272027
build_frame,
21282028
interners,

gfx/wr/webrender/src/renderer.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2476,6 +2476,7 @@ impl Renderer {
24762476

24772477
let mut scene_builder = SceneBuilderThread::new(
24782478
config,
2479+
device_pixel_ratio,
24792480
make_size_of_ops(),
24802481
scene_builder_hooks,
24812482
scene_builder_channels,

0 commit comments

Comments
 (0)