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

Commit 20be49d

Browse files
committed
Bug 1612440 - Separate scene and frame related data in DocumentView. r=gw
DocumentView has a mix of members that affect scene building and memebers that change frame to frame. These need to be updated at different rates and more importantly follow the respective flow of scene and frame transactions, which wasn't done properly before this change. Depends on D71781 Differential Revision: https://phabricator.services.mozilla.com/D71927
1 parent eef976c commit 20be49d

File tree

3 files changed

+62
-43
lines changed

3 files changed

+62
-43
lines changed

gfx/wr/webrender/src/render_backend.rs

Lines changed: 54 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -66,33 +66,50 @@ use crate::frame_builder::Frame;
6666
use time::precise_time_ns;
6767
use crate::util::{Recycler, VecHelper, drain_filter};
6868

69-
7069
#[cfg_attr(feature = "capture", derive(Serialize))]
7170
#[cfg_attr(feature = "replay", derive(Deserialize))]
72-
#[derive(Clone)]
71+
#[derive(Copy, Clone)]
7372
pub struct DocumentView {
73+
scene: SceneView,
74+
frame: FrameView,
75+
}
76+
77+
/// Some rendering parameters applying at the scene level.
78+
#[cfg_attr(feature = "capture", derive(Serialize))]
79+
#[cfg_attr(feature = "replay", derive(Deserialize))]
80+
#[derive(Copy, Clone)]
81+
pub struct SceneView {
7482
pub device_rect: DeviceIntRect,
7583
pub layer: DocumentLayer,
76-
pub pan: DeviceIntPoint,
7784
pub device_pixel_ratio: f32,
7885
pub page_zoom_factor: f32,
79-
pub pinch_zoom_factor: f32,
8086
pub quality_settings: QualitySettings,
8187
}
8288

83-
impl DocumentView {
84-
pub fn accumulated_scale_factor(&self) -> DevicePixelScale {
89+
impl SceneView {
90+
pub fn accumulated_scale_factor_for_snapping(&self) -> DevicePixelScale {
8591
DevicePixelScale::new(
8692
self.device_pixel_ratio *
87-
self.page_zoom_factor *
88-
self.pinch_zoom_factor
93+
self.page_zoom_factor
8994
)
9095
}
96+
}
9197

92-
pub fn accumulated_scale_factor_for_snapping(&self) -> DevicePixelScale {
98+
/// Some rendering parameters applying at the frame level.
99+
#[cfg_attr(feature = "capture", derive(Serialize))]
100+
#[cfg_attr(feature = "replay", derive(Deserialize))]
101+
#[derive(Copy, Clone)]
102+
pub struct FrameView {
103+
pan: DeviceIntPoint,
104+
pinch_zoom_factor: f32,
105+
}
106+
107+
impl DocumentView {
108+
pub fn accumulated_scale_factor(&self) -> DevicePixelScale {
93109
DevicePixelScale::new(
94-
self.device_pixel_ratio *
95-
self.page_zoom_factor
110+
self.scene.device_pixel_ratio *
111+
self.scene.page_zoom_factor *
112+
self.frame.pinch_zoom_factor
96113
)
97114
}
98115
}
@@ -446,13 +463,17 @@ impl Document {
446463
id,
447464
removed_pipelines: Vec::new(),
448465
view: DocumentView {
449-
device_rect: size.into(),
450-
layer,
451-
pan: DeviceIntPoint::zero(),
452-
page_zoom_factor: 1.0,
453-
pinch_zoom_factor: 1.0,
454-
device_pixel_ratio: default_device_pixel_ratio,
455-
quality_settings: QualitySettings::default(),
466+
scene: SceneView {
467+
device_rect: size.into(),
468+
layer,
469+
page_zoom_factor: 1.0,
470+
device_pixel_ratio: default_device_pixel_ratio,
471+
quality_settings: QualitySettings::default(),
472+
},
473+
frame: FrameView {
474+
pan: DeviceIntPoint::new(0, 0),
475+
pinch_zoom_factor: 1.0,
476+
},
456477
},
457478
stamp: FrameStamp::first(id),
458479
scene: BuiltScene::empty(),
@@ -478,7 +499,7 @@ impl Document {
478499
}
479500

480501
fn has_pixels(&self) -> bool {
481-
!self.view.device_rect.size.is_empty_or_negative()
502+
!self.view.scene.device_rect.size.is_empty_or_negative()
482503
}
483504

484505
fn process_frame_msg(
@@ -535,8 +556,8 @@ impl Document {
535556
tx.send(self.shared_hit_tester.clone()).unwrap();
536557
}
537558
FrameMsg::SetPan(pan) => {
538-
if self.view.pan != pan {
539-
self.view.pan = pan;
559+
if self.view.frame.pan != pan {
560+
self.view.frame.pan = pan;
540561
self.hit_tester_is_valid = false;
541562
self.frame_is_valid = false;
542563
}
@@ -565,8 +586,8 @@ impl Document {
565586
self.dynamic_properties.add_transforms(property_bindings);
566587
}
567588
FrameMsg::SetPinchZoom(factor) => {
568-
if self.view.pinch_zoom_factor != factor.get() {
569-
self.view.pinch_zoom_factor = factor.get();
589+
if self.view.frame.pinch_zoom_factor != factor.get() {
590+
self.view.frame.pinch_zoom_factor = factor.get();
570591
self.frame_is_valid = false;
571592
}
572593
}
@@ -594,7 +615,7 @@ impl Document {
594615
tile_cache_logger: &mut TileCacheLogger,
595616
) -> RenderedDocument {
596617
let accumulated_scale_factor = self.view.accumulated_scale_factor();
597-
let pan = self.view.pan.to_f32() / accumulated_scale_factor;
618+
let pan = self.view.frame.pan.to_f32() / accumulated_scale_factor;
598619

599620
// Advance to the next frame.
600621
self.stamp.advance();
@@ -609,8 +630,8 @@ impl Document {
609630
gpu_cache,
610631
self.stamp,
611632
accumulated_scale_factor,
612-
self.view.layer,
613-
self.view.device_rect.origin,
633+
self.view.scene.layer,
634+
self.view.scene.device_rect.origin,
614635
pan,
615636
resource_profile,
616637
&self.dynamic_properties,
@@ -637,7 +658,7 @@ impl Document {
637658

638659
fn rebuild_hit_tester(&mut self) {
639660
let accumulated_scale_factor = self.view.accumulated_scale_factor();
640-
let pan = self.view.pan.to_f32() / accumulated_scale_factor;
661+
let pan = self.view.frame.pan.to_f32() / accumulated_scale_factor;
641662

642663
self.scene.spatial_tree.update_tree(
643664
pan,
@@ -957,7 +978,7 @@ impl RenderBackend {
957978

958979
if let Some(doc) = self.documents.get_mut(&txn.document_id) {
959980
doc.removed_pipelines.append(&mut txn.removed_pipelines);
960-
doc.view = txn.view;
981+
doc.view.scene = txn.view;
961982

962983
if let Some(built_scene) = txn.built_scene.take() {
963984
doc.new_async_scene_ready(
@@ -1704,7 +1725,7 @@ impl RenderBackend {
17041725
resource_sequence_id: config.resource_id,
17051726
documents: self.documents
17061727
.iter()
1707-
.map(|(id, doc)| (*id, doc.view.clone()))
1728+
.map(|(id, doc)| (*id, doc.view))
17081729
.collect(),
17091730
};
17101731
config.serialize_for_frame(&backend, "backend");
@@ -1832,7 +1853,7 @@ impl RenderBackend {
18321853
resource_sequence_id: 0,
18331854
documents: self.documents
18341855
.iter()
1835-
.map(|(id, doc)| (*id, doc.view.clone()))
1856+
.map(|(id, doc)| (*id, doc.view))
18361857
.collect(),
18371858
};
18381859

@@ -1957,7 +1978,7 @@ impl RenderBackend {
19571978
match self.documents.entry(id) {
19581979
Occupied(entry) => {
19591980
let doc = entry.into_mut();
1960-
doc.view = view.clone();
1981+
doc.view = view;
19611982
doc.loaded_scene = scene.clone();
19621983
doc.data_stores = data_stores;
19631984
doc.dynamic_properties = properties;
@@ -1971,7 +1992,7 @@ impl RenderBackend {
19711992
id,
19721993
scene: BuiltScene::empty(),
19731994
removed_pipelines: Vec::new(),
1974-
view: view.clone(),
1995+
view,
19751996
stamp: FrameStamp::first(id),
19761997
frame_builder: FrameBuilder::new(),
19771998
dynamic_properties: properties,
@@ -2021,7 +2042,7 @@ impl RenderBackend {
20212042
scenes_to_build.push(LoadScene {
20222043
document_id: id,
20232044
scene,
2024-
view: view.clone(),
2045+
view: view.scene.clone(),
20252046
config: self.frame_config.clone(),
20262047
font_instances: self.resource_cache.get_font_instances(),
20272048
build_frame,

gfx/wr/webrender/src/scene_builder_thread.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crate::prim_store::image::{Image, YuvImage};
2222
use crate::prim_store::line_dec::LineDecoration;
2323
use crate::prim_store::picture::Picture;
2424
use crate::prim_store::text_run::TextRun;
25-
use crate::render_backend::DocumentView;
25+
use crate::render_backend::SceneView;
2626
use crate::renderer::{PipelineInfo, SceneBuilderHooks};
2727
use crate::scene::{Scene, BuiltScene, SceneStats};
2828
use std::iter;
@@ -90,7 +90,7 @@ impl Transaction {
9090
pub struct BuiltTransaction {
9191
pub document_id: DocumentId,
9292
pub built_scene: Option<BuiltScene>,
93-
pub view: DocumentView,
93+
pub view: SceneView,
9494
pub resource_updates: Vec<ResourceUpdate>,
9595
pub rasterized_blobs: Vec<(BlobImageRequest, BlobImageResult)>,
9696
pub blob_rasterizer: Option<Box<dyn AsyncBlobImageRasterizer>>,
@@ -110,7 +110,7 @@ pub struct LoadScene {
110110
pub document_id: DocumentId,
111111
pub scene: Scene,
112112
pub font_instances: SharedFontInstanceMap,
113-
pub view: DocumentView,
113+
pub view: SceneView,
114114
pub config: FrameBuilderConfig,
115115
pub build_frame: bool,
116116
pub interners: Interners,
@@ -225,7 +225,7 @@ struct Document {
225225
scene: Scene,
226226
interners: Interners,
227227
stats: SceneStats,
228-
view: DocumentView,
228+
view: SceneView,
229229
/// A set of pipelines that the caller has requested be
230230
/// made available as output textures.
231231
output_pipelines: FastHashSet<PipelineId>,
@@ -238,13 +238,11 @@ impl Document {
238238
interners: Interners::default(),
239239
stats: SceneStats::empty(),
240240
output_pipelines: FastHashSet::default(),
241-
view: DocumentView {
241+
view: SceneView {
242242
device_rect,
243243
layer,
244244
device_pixel_ratio,
245-
pan: DeviceIntPoint::zero(),
246245
page_zoom_factor: 1.0,
247-
pinch_zoom_factor: 1.0,
248246
quality_settings: QualitySettings::default(),
249247
},
250248
}
@@ -733,7 +731,7 @@ impl SceneBuilderThread {
733731
render_frame: txn.render_frame,
734732
invalidate_rendered_frame: txn.invalidate_rendered_frame,
735733
built_scene,
736-
view: doc.view.clone(),
734+
view: doc.view,
737735
rasterized_blobs: replace(&mut txn.rasterized_blobs, Vec::new()),
738736
resource_updates: replace(&mut txn.resource_updates, Vec::new()),
739737
blob_rasterizer: replace(&mut txn.blob_rasterizer, None),

gfx/wr/webrender/src/scene_building.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use crate::prim_store::image::{Image, YuvImage};
3636
use crate::prim_store::line_dec::{LineDecoration, LineDecorationCacheKey};
3737
use crate::prim_store::picture::{Picture, PictureCompositeKey, PictureKey};
3838
use crate::prim_store::text_run::TextRun;
39-
use crate::render_backend::{DocumentView};
39+
use crate::render_backend::SceneView;
4040
use crate::resource_cache::ImageRequest;
4141
use crate::scene::{Scene, BuiltScene, SceneStats, StackingContextHelpers};
4242
use crate::scene_builder_thread::Interners;
@@ -389,7 +389,7 @@ impl<'a> SceneBuilder<'a> {
389389
pub fn build(
390390
scene: &Scene,
391391
font_instances: SharedFontInstanceMap,
392-
view: &DocumentView,
392+
view: &SceneView,
393393
output_pipelines: &FastHashSet<PipelineId>,
394394
frame_builder_config: &FrameBuilderConfig,
395395
interners: &mut Interners,

0 commit comments

Comments
 (0)