From 6c395ff7972a1b578c5f4bc4bf6fab0eae78f54e Mon Sep 17 00:00:00 2001 From: Nicolas Silva Date: Thu, 19 Jan 2023 15:40:50 +0000 Subject: [PATCH] Bug 1808549 - Pass the WR device to Compositor methods. r=gfx-reviewers,lsalzman This will be needed by the draw compositor which can't own the device renderer's device but needs to use it. Other implementations can just ignore the parameter. Differential Revision: https://phabricator.services.mozilla.com/D165958 --- gfx/webrender_bindings/src/bindings.rs | 37 +++++---- gfx/wr/webrender/src/composite.rs | 31 +++++-- .../webrender/src/compositor/sw_compositor.rs | 81 ++++++++++--------- gfx/wr/webrender/src/renderer/init.rs | 2 +- gfx/wr/webrender/src/renderer/mod.rs | 51 +++++++----- 5 files changed, 119 insertions(+), 83 deletions(-) diff --git a/gfx/webrender_bindings/src/bindings.rs b/gfx/webrender_bindings/src/bindings.rs index 9d91d3ad966c..582bfebbcc2b 100644 --- a/gfx/webrender_bindings/src/bindings.rs +++ b/gfx/webrender_bindings/src/bindings.rs @@ -1269,6 +1269,7 @@ pub struct WrCompositor(*mut c_void); impl Compositor for WrCompositor { fn create_surface( &mut self, + _device: &mut Device, id: NativeSurfaceId, virtual_offset: DeviceIntPoint, tile_size: DeviceIntSize, @@ -1279,43 +1280,43 @@ impl Compositor for WrCompositor { } } - fn create_external_surface(&mut self, id: NativeSurfaceId, is_opaque: bool) { + fn create_external_surface(&mut self, _device: &mut Device, id: NativeSurfaceId, is_opaque: bool) { unsafe { wr_compositor_create_external_surface(self.0, id, is_opaque); } } - fn create_backdrop_surface(&mut self, id: NativeSurfaceId, color: ColorF) { + fn create_backdrop_surface(&mut self, _device: &mut Device, id: NativeSurfaceId, color: ColorF) { unsafe { wr_compositor_create_backdrop_surface(self.0, id, color); } } - fn destroy_surface(&mut self, id: NativeSurfaceId) { + fn destroy_surface(&mut self, _device: &mut Device, id: NativeSurfaceId) { unsafe { wr_compositor_destroy_surface(self.0, id); } } - fn create_tile(&mut self, id: NativeTileId) { + fn create_tile(&mut self, _device: &mut Device, id: NativeTileId) { unsafe { wr_compositor_create_tile(self.0, id.surface_id, id.x, id.y); } } - fn destroy_tile(&mut self, id: NativeTileId) { + fn destroy_tile(&mut self, _device: &mut Device, id: NativeTileId) { unsafe { wr_compositor_destroy_tile(self.0, id.surface_id, id.x, id.y); } } - fn attach_external_image(&mut self, id: NativeSurfaceId, external_image: ExternalImageId) { + fn attach_external_image(&mut self, _device: &mut Device, id: NativeSurfaceId, external_image: ExternalImageId) { unsafe { wr_compositor_attach_external_image(self.0, id, external_image); } } - fn bind(&mut self, id: NativeTileId, dirty_rect: DeviceIntRect, valid_rect: DeviceIntRect) -> NativeSurfaceInfo { + fn bind(&mut self, _device: &mut Device, id: NativeTileId, dirty_rect: DeviceIntRect, valid_rect: DeviceIntRect) -> NativeSurfaceInfo { let mut surface_info = NativeSurfaceInfo { origin: DeviceIntPoint::zero(), fbo_id: 0, @@ -1335,13 +1336,13 @@ impl Compositor for WrCompositor { surface_info } - fn unbind(&mut self) { + fn unbind(&mut self, _device: &mut Device) { unsafe { wr_compositor_unbind(self.0); } } - fn begin_frame(&mut self) { + fn begin_frame(&mut self, _device: &mut Device) { unsafe { wr_compositor_begin_frame(self.0); } @@ -1349,6 +1350,7 @@ impl Compositor for WrCompositor { fn add_surface( &mut self, + _device: &mut Device, id: NativeSurfaceId, transform: CompositorSurfaceTransform, clip_rect: DeviceIntRect, @@ -1361,6 +1363,7 @@ impl Compositor for WrCompositor { fn start_compositing( &mut self, + _device: &mut Device, clear_color: ColorF, dirty_rects: &[DeviceIntRect], opaque_rects: &[DeviceIntRect], @@ -1377,25 +1380,25 @@ impl Compositor for WrCompositor { } } - fn end_frame(&mut self) { + fn end_frame(&mut self, _device: &mut Device) { unsafe { wr_compositor_end_frame(self.0); } } - fn enable_native_compositor(&mut self, enable: bool) { + fn enable_native_compositor(&mut self, _device: &mut Device, enable: bool) { unsafe { wr_compositor_enable_native_compositor(self.0, enable); } } - fn deinit(&mut self) { + fn deinit(&mut self, _device: &mut Device) { unsafe { wr_compositor_deinit(self.0); } } - fn get_capabilities(&self) -> CompositorCapabilities { + fn get_capabilities(&self, _device: &mut Device) -> CompositorCapabilities { unsafe { let mut caps: CompositorCapabilities = Default::default(); wr_compositor_get_capabilities(self.0, &mut caps); @@ -1403,7 +1406,7 @@ impl Compositor for WrCompositor { } } - fn get_window_visibility(&self) -> WindowVisibility { + fn get_window_visibility(&self, _device: &mut Device) -> WindowVisibility { unsafe { let mut visibility: WindowVisibility = Default::default(); wr_compositor_get_window_visibility(self.0, &mut visibility); @@ -1428,6 +1431,7 @@ impl MappableCompositor for WrCompositor { /// while supporting some form of native layers. fn map_tile( &mut self, + _device: &mut Device, id: NativeTileId, dirty_rect: DeviceIntRect, valid_rect: DeviceIntRect, @@ -1457,7 +1461,7 @@ impl MappableCompositor for WrCompositor { /// Unmap a tile that was was previously mapped via map_tile to signal /// that SWGL is done rendering to the buffer. - fn unmap_tile(&mut self) { + fn unmap_tile(&mut self, _device: &mut Device) { unsafe { wr_compositor_unmap_tile(self.0); } @@ -1465,13 +1469,14 @@ impl MappableCompositor for WrCompositor { fn lock_composite_surface( &mut self, + _device: &mut Device, ctx: *mut c_void, external_image_id: ExternalImageId, composite_info: *mut SWGLCompositeSurfaceInfo, ) -> bool { unsafe { wr_swgl_lock_composite_surface(ctx, external_image_id, composite_info) } } - fn unlock_composite_surface(&mut self, ctx: *mut c_void, external_image_id: ExternalImageId) { + fn unlock_composite_surface(&mut self, _device: &mut Device, ctx: *mut c_void, external_image_id: ExternalImageId) { unsafe { wr_swgl_unlock_composite_surface(ctx, external_image_id) } } } diff --git a/gfx/wr/webrender/src/composite.rs b/gfx/wr/webrender/src/composite.rs index f699865ade9f..e87e777ad485 100644 --- a/gfx/wr/webrender/src/composite.rs +++ b/gfx/wr/webrender/src/composite.rs @@ -15,6 +15,7 @@ use crate::prim_store::DeferredResolve; use crate::resource_cache::{ImageRequest, ResourceCache}; use crate::util::{Preallocator, ScaleOffset}; use crate::tile_cache::PictureCacheDebugInfo; +use crate::device::Device; use std::{ops, u64, os::raw::c_void}; /* @@ -1081,6 +1082,7 @@ pub trait Compositor { /// Create a new OS compositor surface with the given properties. fn create_surface( &mut self, + device: &mut Device, id: NativeSurfaceId, virtual_offset: DeviceIntPoint, tile_size: DeviceIntSize, @@ -1093,6 +1095,7 @@ pub trait Compositor { /// and not create_tile/destroy_tile/bind/unbind. fn create_external_surface( &mut self, + device: &mut Device, id: NativeSurfaceId, is_opaque: bool, ); @@ -1100,6 +1103,7 @@ pub trait Compositor { /// Create a new OS backdrop surface that will display a color. fn create_backdrop_surface( &mut self, + device: &mut Device, id: NativeSurfaceId, color: ColorF, ); @@ -1112,18 +1116,21 @@ pub trait Compositor { /// by the operating system). fn destroy_surface( &mut self, + device: &mut Device, id: NativeSurfaceId, ); /// Create a new OS compositor tile with the given properties. fn create_tile( &mut self, + device: &mut Device, id: NativeTileId, ); /// Destroy an existing compositor tile. fn destroy_tile( &mut self, + device: &mut Device, id: NativeTileId, ); @@ -1133,6 +1140,7 @@ pub trait Compositor { /// many different images attached (like one for each video frame). fn attach_external_image( &mut self, + device: &mut Device, id: NativeSurfaceId, external_image: ExternalImageId ); @@ -1143,6 +1151,7 @@ pub trait Compositor { /// surfaces can be composited early while others are still updating. fn invalidate_tile( &mut self, + _device: &mut Device, _id: NativeTileId, _valid_rect: DeviceIntRect ) {} @@ -1160,6 +1169,7 @@ pub trait Compositor { /// affect the coordinates of the returned origin). fn bind( &mut self, + device: &mut Device, id: NativeTileId, dirty_rect: DeviceIntRect, valid_rect: DeviceIntRect, @@ -1169,10 +1179,11 @@ pub trait Compositor { /// finished issuing OpenGL commands on the current surface. fn unbind( &mut self, + device: &mut Device, ); /// Begin the frame - fn begin_frame(&mut self); + fn begin_frame(&mut self, device: &mut Device); /// Add a surface to the visual tree to be composited. Visuals must /// be added every frame, between the begin/end transaction call. The @@ -1185,6 +1196,7 @@ pub trait Compositor { // TODO(gw): We might need to add a concept of a hierachy in future. fn add_surface( &mut self, + device: &mut Device, id: NativeSurfaceId, transform: CompositorSurfaceTransform, clip_rect: DeviceIntRect, @@ -1199,6 +1211,7 @@ pub trait Compositor { /// opaque, this is currently only computed if the caller is SwCompositor. fn start_compositing( &mut self, + _device: &mut Device, _clear_color: ColorF, _dirty_rects: &[DeviceIntRect], _opaque_rects: &[DeviceIntRect], @@ -1207,20 +1220,20 @@ pub trait Compositor { /// Commit any changes in the compositor tree for this frame. WR calls /// this once when all surface and visual updates are complete, to signal /// that the OS composite transaction should be applied. - fn end_frame(&mut self); + fn end_frame(&mut self, device: &mut Device); /// Enable/disable native compositor usage - fn enable_native_compositor(&mut self, enable: bool); + fn enable_native_compositor(&mut self, device: &mut Device, enable: bool); /// Safely deinitialize any remaining resources owned by the compositor. - fn deinit(&mut self); + fn deinit(&mut self, device: &mut Device); /// Get the capabilities struct for this compositor. This is used to /// specify what features a compositor supports, depending on the /// underlying platform - fn get_capabilities(&self) -> CompositorCapabilities; + fn get_capabilities(&self, device: &mut Device) -> CompositorCapabilities; - fn get_window_visibility(&self) -> WindowVisibility; + fn get_window_visibility(&self, device: &mut Device) -> WindowVisibility; } /// Information about the underlying data buffer of a mapped tile. @@ -1255,6 +1268,7 @@ pub trait MappableCompositor: Compositor { /// while supporting some form of native layers. fn map_tile( &mut self, + device: &mut Device, id: NativeTileId, dirty_rect: DeviceIntRect, valid_rect: DeviceIntRect, @@ -1262,15 +1276,16 @@ pub trait MappableCompositor: Compositor { /// Unmap a tile that was was previously mapped via map_tile to signal /// that SWGL is done rendering to the buffer. - fn unmap_tile(&mut self); + fn unmap_tile(&mut self, device: &mut Device); fn lock_composite_surface( &mut self, + device: &mut Device, ctx: *mut c_void, external_image_id: ExternalImageId, composite_info: *mut SWGLCompositeSurfaceInfo, ) -> bool; - fn unlock_composite_surface(&mut self, ctx: *mut c_void, external_image_id: ExternalImageId); + fn unlock_composite_surface(&mut self, device: &mut Device, ctx: *mut c_void, external_image_id: ExternalImageId); } /// Defines an interface to a non-native (application-level) Compositor which handles diff --git a/gfx/wr/webrender/src/compositor/sw_compositor.rs b/gfx/wr/webrender/src/compositor/sw_compositor.rs index bf1e754772b6..c235b0102a61 100644 --- a/gfx/wr/webrender/src/compositor/sw_compositor.rs +++ b/gfx/wr/webrender/src/compositor/sw_compositor.rs @@ -14,6 +14,7 @@ use crate::{ api::units::*, api::ColorDepth, api::ColorF, api::ExternalImageId, api::ImageRendering, api::YuvRangedColorSpace, Compositor, CompositorCapabilities, CompositorSurfaceTransform, NativeSurfaceId, NativeSurfaceInfo, NativeTileId, profiler, MappableCompositor, SWGLCompositeSurfaceInfo, WindowVisibility, + device::Device, }; pub struct SwTile { @@ -1018,7 +1019,7 @@ impl SwCompositor { } /// Lock a surface with an attached external image for compositing. - fn try_lock_composite_surface(&mut self, id: &NativeSurfaceId) { + fn try_lock_composite_surface(&mut self, device: &mut Device, id: &NativeSurfaceId) { if let Some(surface) = self.surfaces.get_mut(id) { if let Some(external_image) = surface.external_image { // If the surface has an attached external image, attempt to lock the external image @@ -1033,7 +1034,7 @@ impl SwCompositor { }; assert!(!surface.tiles.is_empty()); let mut tile = &mut surface.tiles[0]; - if self.compositor.lock_composite_surface(self.gl.into(), external_image, &mut info) { + if self.compositor.lock_composite_surface(device, self.gl.into(), external_image, &mut info) { tile.valid_rect = DeviceIntRect::from_size(info.size); surface.composite_surface = Some(info); } else { @@ -1045,12 +1046,12 @@ impl SwCompositor { } /// Look for any attached external images that have been locked and then unlock them. - fn unlock_composite_surfaces(&mut self) { + fn unlock_composite_surfaces(&mut self, device: &mut Device) { for &(ref id, _, _, _) in self.frame_surfaces.iter().chain(self.late_surfaces.iter()) { if let Some(surface) = self.surfaces.get_mut(id) { if let Some(external_image) = surface.external_image { if surface.composite_surface.is_some() { - self.compositor.unlock_composite_surface(self.gl.into(), external_image); + self.compositor.unlock_composite_surface(device, self.gl.into(), external_image); surface.composite_surface = None; } } @@ -1147,13 +1148,14 @@ impl SwCompositor { impl Compositor for SwCompositor { fn create_surface( &mut self, + device: &mut Device, id: NativeSurfaceId, virtual_offset: DeviceIntPoint, tile_size: DeviceIntSize, is_opaque: bool, ) { if self.use_native_compositor { - self.compositor.create_surface(id, virtual_offset, tile_size, is_opaque); + self.compositor.create_surface(device, id, virtual_offset, tile_size, is_opaque); } self.max_tile_size = DeviceIntSize::new( self.max_tile_size.width.max(tile_size.width), @@ -1165,24 +1167,24 @@ impl Compositor for SwCompositor { self.surfaces.insert(id, SwSurface::new(tile_size, is_opaque)); } - fn create_external_surface(&mut self, id: NativeSurfaceId, is_opaque: bool) { + fn create_external_surface(&mut self, device: &mut Device, id: NativeSurfaceId, is_opaque: bool) { if self.use_native_compositor { - self.compositor.create_external_surface(id, is_opaque); + self.compositor.create_external_surface(device, id, is_opaque); } self.surfaces .insert(id, SwSurface::new(DeviceIntSize::zero(), is_opaque)); } - fn create_backdrop_surface(&mut self, _id: NativeSurfaceId, _color: ColorF) { + fn create_backdrop_surface(&mut self, _device: &mut Device, _id: NativeSurfaceId, _color: ColorF) { unreachable!("Not implemented.") } - fn destroy_surface(&mut self, id: NativeSurfaceId) { + fn destroy_surface(&mut self, device: &mut Device, id: NativeSurfaceId) { if let Some(surface) = self.surfaces.remove(&id) { self.deinit_surface(&surface); } if self.use_native_compositor { - self.compositor.destroy_surface(id); + self.compositor.destroy_surface(device, id); } if self.surfaces.is_empty() { if let Some(depth_id) = self.depth_id.take() { @@ -1191,7 +1193,7 @@ impl Compositor for SwCompositor { } } - fn deinit(&mut self) { + fn deinit(&mut self, device: &mut Device) { if let Some(ref composite_thread) = self.composite_thread { composite_thread.deinit(); } @@ -1205,13 +1207,13 @@ impl Compositor for SwCompositor { } if self.use_native_compositor { - self.compositor.deinit(); + self.compositor.deinit(device); } } - fn create_tile(&mut self, id: NativeTileId) { + fn create_tile(&mut self, device: &mut Device, id: NativeTileId) { if self.use_native_compositor { - self.compositor.create_tile(id); + self.compositor.create_tile(device, id); } if let Some(surface) = self.surfaces.get_mut(&id.surface_id) { let mut tile = SwTile::new(id.x, id.y); @@ -1242,7 +1244,7 @@ impl Compositor for SwCompositor { } } - fn destroy_tile(&mut self, id: NativeTileId) { + fn destroy_tile(&mut self, device: &mut Device, id: NativeTileId) { if let Some(surface) = self.surfaces.get_mut(&id.surface_id) { if let Some(idx) = surface.tiles.iter().position(|t| t.x == id.x && t.y == id.y) { let tile = surface.tiles.remove(idx); @@ -1250,13 +1252,13 @@ impl Compositor for SwCompositor { } } if self.use_native_compositor { - self.compositor.destroy_tile(id); + self.compositor.destroy_tile(device, id); } } - fn attach_external_image(&mut self, id: NativeSurfaceId, external_image: ExternalImageId) { + fn attach_external_image(&mut self, device: &mut Device, id: NativeSurfaceId, external_image: ExternalImageId) { if self.use_native_compositor { - self.compositor.attach_external_image(id, external_image); + self.compositor.attach_external_image(device, id, external_image); } if let Some(surface) = self.surfaces.get_mut(&id) { // Surfaces with attached external images have a single tile at the origin encompassing @@ -1269,9 +1271,9 @@ impl Compositor for SwCompositor { } } - fn invalidate_tile(&mut self, id: NativeTileId, valid_rect: DeviceIntRect) { + fn invalidate_tile(&mut self, device: &mut Device, id: NativeTileId, valid_rect: DeviceIntRect) { if self.use_native_compositor { - self.compositor.invalidate_tile(id, valid_rect); + self.compositor.invalidate_tile(device, id, valid_rect); } if let Some(surface) = self.surfaces.get_mut(&id.surface_id) { if let Some(tile) = surface.tiles.iter_mut().find(|t| t.x == id.x && t.y == id.y) { @@ -1281,7 +1283,7 @@ impl Compositor for SwCompositor { } } - fn bind(&mut self, id: NativeTileId, dirty_rect: DeviceIntRect, valid_rect: DeviceIntRect) -> NativeSurfaceInfo { + fn bind(&mut self, device: &mut Device, id: NativeTileId, dirty_rect: DeviceIntRect, valid_rect: DeviceIntRect) -> NativeSurfaceInfo { let mut surface_info = NativeSurfaceInfo { origin: DeviceIntPoint::zero(), fbo_id: 0, @@ -1299,7 +1301,7 @@ impl Compositor for SwCompositor { let mut stride = 0; let mut buf = ptr::null_mut(); if self.use_native_compositor { - if let Some(tile_info) = self.compositor.map_tile(id, dirty_rect, valid_rect) { + if let Some(tile_info) = self.compositor.map_tile(device, id, dirty_rect, valid_rect) { stride = tile_info.stride; buf = tile_info.data; } @@ -1341,7 +1343,7 @@ impl Compositor for SwCompositor { surface_info } - fn unbind(&mut self) { + fn unbind(&mut self, device: &mut Device) { let id = self.cur_tile; if let Some(surface) = self.surfaces.get(&id.surface_id) { if let Some(tile) = surface.tiles.iter().find(|t| t.x == id.x && t.y == id.y) { @@ -1356,7 +1358,7 @@ impl Compositor for SwCompositor { self.gl.resolve_framebuffer(tile.fbo_id); if self.use_native_compositor { - self.compositor.unmap_tile(); + self.compositor.unmap_tile(device); } else { // If we're not relying on a native compositor, then composite // any tiles that are dependent on this tile being updated but @@ -1367,28 +1369,29 @@ impl Compositor for SwCompositor { } } - fn begin_frame(&mut self) { + fn begin_frame(&mut self, device: &mut Device) { self.reset_overlaps(); if self.use_native_compositor { - self.compositor.begin_frame(); + self.compositor.begin_frame(device); } } fn add_surface( &mut self, + device: &mut Device, id: NativeSurfaceId, transform: CompositorSurfaceTransform, clip_rect: DeviceIntRect, filter: ImageRendering, ) { if self.use_native_compositor { - self.compositor.add_surface(id, transform, clip_rect, filter); + self.compositor.add_surface(device, id, transform, clip_rect, filter); } if self.composite_thread.is_some() { // If the surface has an attached external image, try to lock that now. - self.try_lock_composite_surface(&id); + self.try_lock_composite_surface(device, &id); // If we're already busy compositing, then add to the queue of late // surfaces instead of trying to sort into the main frame queue. @@ -1408,7 +1411,7 @@ impl Compositor for SwCompositor { /// frame will not have overlap dependencies assigned and so must instead /// be added to the late_surfaces queue to be processed at the end of the /// frame. - fn start_compositing(&mut self, clear_color: ColorF, dirty_rects: &[DeviceIntRect], _opaque_rects: &[DeviceIntRect]) { + fn start_compositing(&mut self, device: &mut Device, clear_color: ColorF, dirty_rects: &[DeviceIntRect], _opaque_rects: &[DeviceIntRect]) { self.is_compositing = true; // Opaque rects are currently only computed here, not by WR itself, so we @@ -1429,7 +1432,7 @@ impl Compositor for SwCompositor { } } - self.compositor.start_compositing(clear_color, dirty_rects, &opaque_rects); + self.compositor.start_compositing(device, clear_color, dirty_rects, &opaque_rects); if let Some(dirty_rect) = dirty_rects .iter() @@ -1477,11 +1480,11 @@ impl Compositor for SwCompositor { } } - fn end_frame(&mut self) { + fn end_frame(&mut self, device: &mut Device,) { self.is_compositing = false; if self.use_native_compositor { - self.compositor.end_frame(); + self.compositor.end_frame(device); } else if let Some(ref composite_thread) = self.composite_thread { // Need to wait for the SwComposite thread to finish any queued jobs. composite_thread.wait_for_composites(false); @@ -1508,7 +1511,7 @@ impl Compositor for SwCompositor { self.locked_framebuffer = None; - self.unlock_composite_surfaces(); + self.unlock_composite_surfaces(device); } self.frame_surfaces.clear(); @@ -1517,19 +1520,19 @@ impl Compositor for SwCompositor { self.reset_overlaps(); } - fn enable_native_compositor(&mut self, enable: bool) { + fn enable_native_compositor(&mut self, device: &mut Device, enable: bool) { // TODO: The SwComposite thread is not properly instantiated if this is // ever actually toggled. assert_eq!(self.use_native_compositor, enable); - self.compositor.enable_native_compositor(enable); + self.compositor.enable_native_compositor(device, enable); self.use_native_compositor = enable; } - fn get_capabilities(&self) -> CompositorCapabilities { - self.compositor.get_capabilities() + fn get_capabilities(&self, device: &mut Device) -> CompositorCapabilities { + self.compositor.get_capabilities(device) } - fn get_window_visibility(&self) -> WindowVisibility { - self.compositor.get_window_visibility() + fn get_window_visibility(&self, device: &mut Device) -> WindowVisibility { + self.compositor.get_window_visibility(device) } } diff --git a/gfx/wr/webrender/src/renderer/init.rs b/gfx/wr/webrender/src/renderer/init.rs index e10f65ac5258..72adeff3f271 100644 --- a/gfx/wr/webrender/src/renderer/init.rs +++ b/gfx/wr/webrender/src/renderer/init.rs @@ -501,7 +501,7 @@ pub fn create_webrender_instance( CompositorKind::Draw { max_partial_present_rects, draw_previous_partial_present_regions } } CompositorConfig::Native { ref compositor } => { - let capabilities = compositor.get_capabilities(); + let capabilities = compositor.get_capabilities(&mut device); CompositorKind::Native { capabilities, diff --git a/gfx/wr/webrender/src/renderer/mod.rs b/gfx/wr/webrender/src/renderer/mod.rs index c234c5ef9d0f..ef083bb2caca 100644 --- a/gfx/wr/webrender/src/renderer/mod.rs +++ b/gfx/wr/webrender/src/renderer/mod.rs @@ -1269,7 +1269,7 @@ impl Renderer { // the size has changed. if let Some(current_size) = self.debug_overlay_state.current_size { if !self.debug_overlay_state.is_enabled || current_size != framebuffer_size { - compositor.destroy_surface(NativeSurfaceId::DEBUG_OVERLAY); + compositor.destroy_surface(&mut self.device, NativeSurfaceId::DEBUG_OVERLAY); self.debug_overlay_state.current_size = None; } } @@ -1277,12 +1277,14 @@ impl Renderer { // Allocate a new surface, if we need it and there isn't one. if self.debug_overlay_state.is_enabled && self.debug_overlay_state.current_size.is_none() { compositor.create_surface( + &mut self.device, NativeSurfaceId::DEBUG_OVERLAY, DeviceIntPoint::zero(), framebuffer_size, false, ); compositor.create_tile( + &mut self.device, NativeTileId::DEBUG_OVERLAY, ); self.debug_overlay_state.current_size = Some(framebuffer_size); @@ -1300,11 +1302,13 @@ impl Renderer { // Ensure old surface is invalidated before binding compositor.invalidate_tile( + &mut self.device, NativeTileId::DEBUG_OVERLAY, DeviceIntRect::from_size(surface_size), ); // Bind the native surface let surface_info = compositor.bind( + &mut self.device, NativeTileId::DEBUG_OVERLAY, DeviceIntRect::from_size(surface_size), DeviceIntRect::from_size(surface_size), @@ -1344,9 +1348,10 @@ impl Renderer { if let CompositorKind::Native { .. } = self.current_compositor_kind { let compositor = self.compositor_config.compositor().unwrap(); // Unbind the draw target and add it to the visual tree to be composited - compositor.unbind(); + compositor.unbind(&mut self.device); compositor.add_surface( + &mut self.device, NativeSurfaceId::DEBUG_OVERLAY, CompositorSurfaceTransform::identity(), DeviceIntRect::from_size( @@ -1384,7 +1389,7 @@ impl Renderer { self.compositor_config .compositor() .unwrap() - .destroy_surface(NativeSurfaceId::DEBUG_OVERLAY); + .destroy_surface(&mut self.device, NativeSurfaceId::DEBUG_OVERLAY); self.debug_overlay_state.current_size = None; } false @@ -1400,7 +1405,7 @@ impl Renderer { }; if let Some(config) = self.compositor_config.compositor() { - config.enable_native_compositor(enable); + config.enable_native_compositor(&mut self.device, enable); } self.current_compositor_kind = compositor_kind; } @@ -1439,7 +1444,7 @@ impl Renderer { // we can create debug overlays after drawing the main surfaces. if let CompositorKind::Native { .. } = self.current_compositor_kind { let compositor = self.compositor_config.compositor().unwrap(); - compositor.begin_frame(); + compositor.begin_frame(&mut self.device); } // Update the state of the debug overlay surface, ensuring that @@ -1656,7 +1661,7 @@ impl Renderer { if let CompositorKind::Native { .. } = self.current_compositor_kind { profile_scope!("compositor.end_frame"); let compositor = self.compositor_config.compositor().unwrap(); - compositor.end_frame(); + compositor.end_frame(&mut self.device); } } @@ -2710,6 +2715,7 @@ impl Renderer { .compositor() .unwrap() .bind( + &mut self.device, NativeTileId { surface_id: native_surface_id, x: 0, @@ -2825,7 +2831,7 @@ impl Renderer { self.compositor_config .compositor() .unwrap() - .unbind(); + .unbind(&mut self.device); } self.gpu_profiler.finish_sampler(opaque_sampler); @@ -4142,6 +4148,7 @@ impl Renderer { let _inserted = self.allocated_native_surfaces.insert(id); debug_assert!(_inserted, "bug: creating existing surface"); compositor.create_surface( + &mut self.device, id, virtual_offset, tile_size, @@ -4152,6 +4159,7 @@ impl Renderer { let _inserted = self.allocated_native_surfaces.insert(id); debug_assert!(_inserted, "bug: creating existing surface"); compositor.create_external_surface( + &mut self.device, id, is_opaque, ); @@ -4160,6 +4168,7 @@ impl Renderer { let _inserted = self.allocated_native_surfaces.insert(id); debug_assert!(_inserted, "bug: creating existing surface"); compositor.create_backdrop_surface( + &mut self.device, id, color, ); @@ -4167,16 +4176,16 @@ impl Renderer { NativeSurfaceOperationDetails::DestroySurface { id } => { let _existed = self.allocated_native_surfaces.remove(&id); debug_assert!(_existed, "bug: removing unknown surface"); - compositor.destroy_surface(id); + compositor.destroy_surface(&mut self.device, id); } NativeSurfaceOperationDetails::CreateTile { id } => { - compositor.create_tile(id); + compositor.create_tile(&mut self.device, id); } NativeSurfaceOperationDetails::DestroyTile { id } => { - compositor.destroy_tile(id); + compositor.destroy_tile(&mut self.device, id); } NativeSurfaceOperationDetails::AttachExternalImage { id, external_image } => { - compositor.attach_external_image(id, external_image); + compositor.attach_external_image(&mut self.device, id, external_image); } } } @@ -4279,7 +4288,7 @@ impl Renderer { tile.transform_index, ).to_i32(); - compositor.invalidate_tile(id, valid_rect); + compositor.invalidate_tile(&mut self.device, id, valid_rect); } } } @@ -4291,7 +4300,7 @@ impl Renderer { for surface in &frame.composite_state.external_surfaces { if let Some((native_surface_id, size)) = surface.update_params { let surface_rect = size.into(); - compositor.invalidate_tile(NativeTileId { surface_id: native_surface_id, x: 0, y: 0 }, surface_rect); + compositor.invalidate_tile(&mut self.device, NativeTileId { surface_id: native_surface_id, x: 0, y: 0 }, surface_rect); } } // Finally queue native surfaces for early composition, if applicable. By now, @@ -4302,6 +4311,7 @@ impl Renderer { frame.composite_state.composite_native( self.clear_color, &results.dirty_rects, + &mut self.device, &mut **compositor, ); } @@ -4350,6 +4360,7 @@ impl Renderer { CompositorKind::Native { .. } => { let compositor = self.compositor_config.compositor().unwrap(); compositor.bind( + &mut self.device, id, picture_target.dirty_rect, picture_target.valid_rect, @@ -4390,7 +4401,7 @@ impl Renderer { match self.current_compositor_kind { CompositorKind::Native { .. } => { let compositor = self.compositor_config.compositor().unwrap(); - compositor.unbind(); + compositor.unbind(&mut self.device); } CompositorKind::Draw { .. } => { unreachable!(); @@ -4945,7 +4956,7 @@ impl Renderer { let y: f32 = 40.0; if let CompositorConfig::Native { ref mut compositor, .. } = self.compositor_config { - let visibility = compositor.get_window_visibility(); + let visibility = compositor.get_window_visibility(&mut self.device); let color = if visibility.is_fully_occluded { ColorU::new(255, 0, 0, 255) @@ -5019,13 +5030,13 @@ impl Renderer { // surfaces are freed. if let CompositorConfig::Native { mut compositor, .. } = self.compositor_config { for id in self.allocated_native_surfaces.drain() { - compositor.destroy_surface(id); + compositor.destroy_surface(&mut self.device, id); } // Destroy the debug overlay surface, if currently allocated. if self.debug_overlay_state.current_size.is_some() { - compositor.destroy_surface(NativeSurfaceId::DEBUG_OVERLAY); + compositor.destroy_surface(&mut self.device, NativeSurfaceId::DEBUG_OVERLAY); } - compositor.deinit(); + compositor.deinit(&mut self.device); } self.gpu_cache_texture.deinit(&mut self.device); if let Some(dither_matrix_texture) = self.dither_matrix_texture { @@ -5694,6 +5705,7 @@ impl CompositeState { &self, clear_color: ColorF, dirty_rects: &[DeviceIntRect], + device: &mut Device, compositor: &mut dyn Compositor, ) { // Add each surface to the visual tree. z-order is implicit based on @@ -5701,13 +5713,14 @@ impl CompositeState { // surface. for surface in &self.descriptor.surfaces { compositor.add_surface( + device, surface.surface_id.expect("bug: no native surface allocated"), surface.transform, surface.clip_rect.to_i32(), surface.image_rendering, ); } - compositor.start_compositing(clear_color, dirty_rects, &[]); + compositor.start_compositing(device, clear_color, dirty_rects, &[]); } }