aboutsummaryrefslogtreecommitdiffstats
path: root/third_party/webrender/example-compositor/compositor
diff options
context:
space:
mode:
authorMartin Robinson <mrobinson@igalia.com>2023-09-10 14:38:56 +0200
committerGitHub <noreply@github.com>2023-09-10 12:38:56 +0000
commita9d37cb85ac2c55fc630fccffe1ba60ff00f555b (patch)
treee072f86743d0ee71f908135cb63484f84c8370f4 /third_party/webrender/example-compositor/compositor
parentc079acb3c31e695e9f16b96b9bd61b2a1c182796 (diff)
downloadservo-a9d37cb85ac2c55fc630fccffe1ba60ff00f555b.tar.gz
servo-a9d37cb85ac2c55fc630fccffe1ba60ff00f555b.zip
Upgrade WebRender to e491e1ae637b2eed1e7195855d88357e5eb3ddf9 (#30323)
* Upgrade vendored version of WebRender * Patch WebRender: upgrade version of gleam * Restore hit testing implementation * Fix WebRender warnings * Adapt Servo to new WebRender * Update results * Add a workaround for #30313 This slightly expands text boundaries in order to take into account the fact that layout isn't measuring glyph boundaries.
Diffstat (limited to 'third_party/webrender/example-compositor/compositor')
-rw-r--r--third_party/webrender/example-compositor/compositor/Cargo.toml5
-rw-r--r--third_party/webrender/example-compositor/compositor/src/main.rs107
2 files changed, 93 insertions, 19 deletions
diff --git a/third_party/webrender/example-compositor/compositor/Cargo.toml b/third_party/webrender/example-compositor/compositor/Cargo.toml
index d505e9ad295..02c6ebe0ce2 100644
--- a/third_party/webrender/example-compositor/compositor/Cargo.toml
+++ b/third_party/webrender/example-compositor/compositor/Cargo.toml
@@ -7,7 +7,10 @@ license = "MPL-2.0"
[dependencies]
webrender = { path = "../../webrender" }
-gleam = "0.12.0"
+gleam = "0.15"
[target.'cfg(windows)'.dependencies]
compositor-windows = { path = "../compositor-windows" }
+
+[target.'cfg(target_os = "linux")'.dependencies]
+compositor-wayland = { path = "../compositor-wayland" }
diff --git a/third_party/webrender/example-compositor/compositor/src/main.rs b/third_party/webrender/example-compositor/compositor/src/main.rs
index b2a7aac3a94..fef9438ec20 100644
--- a/third_party/webrender/example-compositor/compositor/src/main.rs
+++ b/third_party/webrender/example-compositor/compositor/src/main.rs
@@ -16,10 +16,12 @@ use euclid::Angle;
use gleam::gl;
use std::ffi::CString;
use std::sync::mpsc;
-use webrender::api::*;
+use webrender::{CompositorSurfaceTransform, Transaction, api::*, euclid::point2};
use webrender::api::units::*;
#[cfg(target_os = "windows")]
use compositor_windows as compositor;
+#[cfg(target_os = "linux")]
+use compositor_wayland as compositor;
use std::{env, f32, process};
// A very hacky integration with DirectComposite. It proxies calls from the compositor
@@ -42,6 +44,7 @@ impl webrender::Compositor for DirectCompositeInterface {
fn create_surface(
&mut self,
id: webrender::NativeSurfaceId,
+ _virtual_offset: DeviceIntPoint,
tile_size: DeviceIntSize,
is_opaque: bool,
) {
@@ -89,6 +92,7 @@ impl webrender::Compositor for DirectCompositeInterface {
&mut self,
id: webrender::NativeTileId,
dirty_rect: DeviceIntRect,
+ _valid_rect: DeviceIntRect,
) -> webrender::NativeSurfaceInfo {
let (fbo_id, x, y) = compositor::bind_surface(
self.window,
@@ -118,14 +122,15 @@ impl webrender::Compositor for DirectCompositeInterface {
fn add_surface(
&mut self,
id: webrender::NativeSurfaceId,
- position: DeviceIntPoint,
+ transform: CompositorSurfaceTransform,
clip_rect: DeviceIntRect,
+ _image_rendering: ImageRendering,
) {
compositor::add_surface(
self.window,
id.0,
- position.x,
- position.y,
+ transform.transform_point2d(point2(0., 0.)).unwrap().x as i32,
+ transform.transform_point2d(point2(0., 0.)).unwrap().y as i32,
clip_rect.origin.x,
clip_rect.origin.y,
clip_rect.size.width,
@@ -136,6 +141,42 @@ impl webrender::Compositor for DirectCompositeInterface {
fn end_frame(&mut self) {
compositor::end_transaction(self.window);
}
+ fn create_external_surface(&mut self, _: webrender::NativeSurfaceId, _: bool) { todo!() }
+
+ fn attach_external_image(
+ &mut self,
+ _id: webrender::NativeSurfaceId,
+ _external_image: ExternalImageId
+ ) {
+ todo!()
+ }
+
+ fn enable_native_compositor(&mut self, _enable: bool) {
+ todo!()
+ }
+
+ fn deinit(&mut self) {
+ compositor::deinit(self.window);
+ }
+
+ fn get_capabilities(&self) -> webrender::CompositorCapabilities {
+ webrender::CompositorCapabilities {
+ virtual_surface_size: 1024 * 1024,
+ ..Default::default()
+ }
+ }
+
+ fn invalidate_tile(
+ &mut self,
+ _id: webrender::NativeTileId,
+ _valid_rect: DeviceIntRect,
+ ) {}
+
+ fn start_compositing(
+ &mut self,
+ _dirty_rects: &[DeviceIntRect],
+ _opaque_rects: &[DeviceIntRect],
+ ) {}
}
// Simplisitic implementation of the WR notifier interface to know when a frame
@@ -159,7 +200,7 @@ impl RenderNotifier for Notifier {
})
}
- fn wake_up(&self) {
+ fn wake_up(&self, _composite_needed: bool) {
}
fn new_frame_ready(&self,
@@ -181,7 +222,7 @@ fn push_rotated_rect(
time: f32,
) {
let color = color.scale_rgb(time);
- let rotation = LayoutTransform::create_rotation(
+ let rotation = LayoutTransform::rotation(
0.0,
0.0,
1.0,
@@ -194,13 +235,16 @@ fn push_rotated_rect(
);
let transform = rotation
.pre_translate(-transform_origin)
- .post_translate(transform_origin);
+ .then_translate(transform_origin);
let spatial_id = builder.push_reference_frame(
LayoutPoint::zero(),
spatial_id,
TransformStyle::Flat,
PropertyBinding::Value(transform),
- ReferenceFrameKind::Transform,
+ ReferenceFrameKind::Transform {
+ is_2d_scale_translation: false,
+ should_snap: false,
+ },
);
builder.push_rect(
&CommonItemProperties::new(
@@ -235,7 +279,7 @@ fn build_display_list(
let scroll_space_info = builder.define_scroll_frame(
&fixed_space_info,
- Some(scroll_id),
+ scroll_id,
LayoutRect::new(LayoutPoint::zero(), layout_size),
LayoutRect::new(LayoutPoint::zero(), layout_size),
ScrollSensitivity::Script,
@@ -289,6 +333,32 @@ fn build_display_list(
0.1,
time,
);
+
+ push_rotated_rect(
+ builder,
+ LayoutRect::new(
+ LayoutPoint::new(100.0, 600.0),
+ LayoutSize::new(size_factor * 400.0, size_factor * 400.0),
+ ),
+ ColorF::new(1.0, 1.0, 0.0, 1.0),
+ scroll_space_info.spatial_id,
+ root_pipeline_id,
+ time,
+ time,
+ );
+
+ push_rotated_rect(
+ builder,
+ LayoutRect::new(
+ LayoutPoint::new(700.0, 600.0),
+ LayoutSize::new(size_factor * 400.0, size_factor * 400.0),
+ ),
+ ColorF::new(0.0, 1.0, 1.0, 1.0),
+ scroll_space_info.spatial_id,
+ root_pipeline_id,
+ time,
+ time,
+ );
}
#[derive(Debug, Copy, Clone)]
@@ -358,13 +428,15 @@ fn main() {
} else {
webrender::CompositorConfig::Draw {
max_partial_present_rects: 0,
+ draw_previous_partial_present_regions: false,
+ partial_present: None,
}
};
let opts = webrender::RendererOptions {
clear_color: Some(ColorF::new(1.0, 1.0, 1.0, 1.0)),
debug_flags,
- enable_picture_caching: true,
compositor_config,
+ surface_origin_is_top_left: false,
..webrender::RendererOptions::default()
};
let (tx, rx) = mpsc::channel();
@@ -383,10 +455,9 @@ fn main() {
notifier,
opts,
None,
- device_size,
).unwrap();
- let api = sender.create_api();
- let document_id = api.add_document(device_size, 0);
+ let mut api = sender.create_api();
+ let document_id = api.add_document(device_size);
let device_pixel_ratio = 1.0;
let mut current_epoch = Epoch(0);
let root_pipeline_id = PipelineId(0, 0);
@@ -399,7 +470,7 @@ fn main() {
txn.set_root_pipeline(root_pipeline_id);
if let Invalidations::Scrolling = inv_mode {
- let mut root_builder = DisplayListBuilder::new(root_pipeline_id, layout_size);
+ let mut root_builder = DisplayListBuilder::new(root_pipeline_id);
build_display_list(
&mut root_builder,
@@ -419,7 +490,7 @@ fn main() {
);
}
- txn.generate_frame();
+ txn.generate_frame(0);
api.send_transaction(document_id, txn);
// Tick the compositor (in this sample, we don't block on UI events)
@@ -429,7 +500,7 @@ fn main() {
// Update and render. This will invoke the native compositor interface implemented above
// as required.
renderer.update();
- renderer.render(device_size).unwrap();
+ renderer.render(device_size, 0).unwrap();
let _ = renderer.flush_pipeline_info();
// Construct a simple display list that can be drawn and composited by DC.
@@ -437,7 +508,7 @@ fn main() {
match inv_mode {
Invalidations::Small | Invalidations::Large => {
- let mut root_builder = DisplayListBuilder::new(root_pipeline_id, layout_size);
+ let mut root_builder = DisplayListBuilder::new(root_pipeline_id);
build_display_list(
&mut root_builder,
@@ -466,7 +537,7 @@ fn main() {
}
}
- txn.generate_frame();
+ txn.generate_frame(0);
api.send_transaction(document_id, txn);
current_epoch.0 += 1;
time += 0.001;