Bug 1950768 - Support debug and profiler overlay with layer-compositor enabled r=gfx-reviewers,lsalzman

Differential Revision: https://phabricator.services.mozilla.com/D239832
This commit is contained in:
Glenn Watson
2025-02-27 19:27:25 +00:00
parent c1c57c4507
commit 8a4b916c17
3 changed files with 118 additions and 58 deletions

View File

@@ -1565,7 +1565,7 @@ impl LayerCompositor for WrLayerCompositor {
unsafe {
match request.usage {
CompositorSurfaceUsage::Content => {
CompositorSurfaceUsage::Content | CompositorSurfaceUsage::DebugOverlay => {
wr_compositor_create_swapchain_surface(
self.compositor,
id,
@@ -1594,7 +1594,7 @@ impl LayerCompositor for WrLayerCompositor {
};
match layer.usage {
CompositorSurfaceUsage::Content => {
CompositorSurfaceUsage::Content | CompositorSurfaceUsage::DebugOverlay => {
if layer.size.width != size.width || layer.size.height != size.height {
unsafe {
wr_compositor_resize_swapchain(

View File

@@ -473,6 +473,7 @@ pub enum CompositorSurfaceUsage {
external_image_id: ExternalImageId,
transform_index: CompositorTransformIndex,
},
DebugOverlay,
}
impl CompositorSurfaceUsage {
@@ -489,6 +490,10 @@ impl CompositorSurfaceUsage {
(CompositorSurfaceUsage::External { image_key: key1, .. }, CompositorSurfaceUsage::External { image_key: key2, .. }) => {
key1 == key2
}
(CompositorSurfaceUsage::DebugOverlay, CompositorSurfaceUsage::DebugOverlay) => true,
(CompositorSurfaceUsage::DebugOverlay, _) | (_, CompositorSurfaceUsage::DebugOverlay) => false,
}
}
}

View File

@@ -708,6 +708,8 @@ struct DebugOverlayState {
/// The current size of the debug overlay surface. None implies that the
/// debug surface isn't currently allocated.
current_size: Option<DeviceIntSize>,
layer_index: usize,
}
impl DebugOverlayState {
@@ -715,6 +717,7 @@ impl DebugOverlayState {
DebugOverlayState {
is_enabled: false,
current_size: None,
layer_index: 0,
}
}
}
@@ -1369,45 +1372,60 @@ impl Renderer {
fn bind_debug_overlay(&mut self, device_size: DeviceIntSize) -> Option<DrawTarget> {
// Debug overlay setup are only required in native compositing mode
if self.debug_overlay_state.is_enabled {
if let CompositorKind::Native { .. } = self.current_compositor_kind {
let compositor = self.compositor_config.compositor().unwrap();
let surface_size = self.debug_overlay_state.current_size.unwrap();
match self.current_compositor_kind {
CompositorKind::Native { .. } => {
let compositor = self.compositor_config.compositor().unwrap();
let surface_size = self.debug_overlay_state.current_size.unwrap();
// 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),
);
// 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),
);
// Bind the native surface to current FBO target
let draw_target = DrawTarget::NativeSurface {
offset: surface_info.origin,
external_fbo_id: surface_info.fbo_id,
dimensions: surface_size,
};
self.device.bind_draw_target(draw_target);
// Bind the native surface to current FBO target
let draw_target = DrawTarget::NativeSurface {
offset: surface_info.origin,
external_fbo_id: surface_info.fbo_id,
dimensions: surface_size,
};
self.device.bind_draw_target(draw_target);
// When native compositing, clear the debug overlay each frame.
self.device.clear_target(
Some([0.0, 0.0, 0.0, 0.0]),
None, // debug renderer does not use depth
None,
);
// When native compositing, clear the debug overlay each frame.
self.device.clear_target(
Some([0.0, 0.0, 0.0, 0.0]),
None, // debug renderer does not use depth
None,
);
Some(draw_target)
} else {
// If we're not using the native compositor, then the default
// frame buffer is already bound. Create a DrawTarget for it and
// return it.
Some(DrawTarget::new_default(device_size, self.device.surface_origin_is_top_left()))
Some(draw_target)
}
CompositorKind::Layer { .. } => {
let compositor = self.compositor_config.layer_compositor().unwrap();
compositor.bind_layer(self.debug_overlay_state.layer_index);
self.device.clear_target(
Some([0.0, 0.0, 0.0, 0.0]),
None, // debug renderer does not use depth
None,
);
Some(DrawTarget::new_default(device_size, self.device.surface_origin_is_top_left()))
}
CompositorKind::Draw { .. } => {
// If we're not using the native compositor, then the default
// frame buffer is already bound. Create a DrawTarget for it and
// return it.
Some(DrawTarget::new_default(device_size, self.device.surface_origin_is_top_left()))
}
}
} else {
None
@@ -1418,20 +1436,27 @@ impl Renderer {
fn unbind_debug_overlay(&mut self) {
// Debug overlay setup are only required in native compositing mode
if self.debug_overlay_state.is_enabled {
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(&mut self.device);
match self.current_compositor_kind {
CompositorKind::Native { .. } => {
let compositor = self.compositor_config.compositor().unwrap();
// Unbind the draw target and add it to the visual tree to be composited
compositor.unbind(&mut self.device);
compositor.add_surface(
&mut self.device,
NativeSurfaceId::DEBUG_OVERLAY,
CompositorSurfaceTransform::identity(),
DeviceIntRect::from_size(
self.debug_overlay_state.current_size.unwrap(),
),
ImageRendering::Auto,
);
compositor.add_surface(
&mut self.device,
NativeSurfaceId::DEBUG_OVERLAY,
CompositorSurfaceTransform::identity(),
DeviceIntRect::from_size(
self.debug_overlay_state.current_size.unwrap(),
),
ImageRendering::Auto,
);
}
CompositorKind::Draw { .. } => {}
CompositorKind::Layer { .. } => {
let compositor = self.compositor_config.layer_compositor().unwrap();
compositor.present_layer(self.debug_overlay_state.layer_index);
}
}
}
}
@@ -1739,10 +1764,17 @@ impl Renderer {
// Inform the client that we are finished this composition transaction if native
// compositing is enabled. This must be called after any debug / profiling compositor
// surfaces have been drawn and added to the visual tree.
if let CompositorKind::Native { .. } = self.current_compositor_kind {
profile_scope!("compositor.end_frame");
let compositor = self.compositor_config.compositor().unwrap();
compositor.end_frame(&mut self.device);
match self.current_compositor_kind {
CompositorKind::Layer { .. } => {
let compositor = self.compositor_config.layer_compositor().unwrap();
compositor.end_frame();
}
CompositorKind::Native { .. } => {
profile_scope!("compositor.end_frame");
let compositor = self.compositor_config.compositor().unwrap();
compositor.end_frame(&mut self.device);
}
CompositorKind::Draw { .. } => {}
}
}
@@ -3587,6 +3619,11 @@ impl Renderer {
}
}
}
// Should not encounter debug layers here
(CompositorSurfaceUsage::DebugOverlay, _) | (_, CompositorSurfaceUsage::DebugOverlay) => {
unreachable!();
}
}
}
None => {
@@ -3614,6 +3651,7 @@ impl Renderer {
(rect.min.to_i32(), clip_rect, is_opaque)
}
CompositorSurfaceUsage::DebugOverlay => unreachable!(),
};
input_layers.push(CompositorInputLayer {
@@ -3661,6 +3699,24 @@ impl Renderer {
})
}
// Add a debug overlay request if enabled
if self.debug_overlay_state.is_enabled {
self.debug_overlay_state.layer_index = input_layers.len();
input_layers.push(CompositorInputLayer {
usage: CompositorSurfaceUsage::DebugOverlay,
is_opaque: false,
offset: DeviceIntPoint::zero(),
clip_rect: device_size.into(),
});
swapchain_layers.push(SwapChainLayer {
opaque_items: Vec::new(),
alpha_items: Vec::new(),
clear_tiles: Vec::new(),
})
}
// Start compositing if using OS compositor
if let Some(ref mut compositor) = self.compositor_config.layer_compositor() {
let input = CompositorInputConfig {
@@ -3672,10 +3728,10 @@ impl Renderer {
for (layer_index, (layer, swapchain_layer)) in input_layers.iter().zip(swapchain_layers.iter()).enumerate() {
self.device.reset_state();
// Skip compositing external images
// Skip compositing external images or debug layers here
match layer.usage {
CompositorSurfaceUsage::Content => {}
CompositorSurfaceUsage::External { .. } => {
CompositorSurfaceUsage::External { .. } | CompositorSurfaceUsage::DebugOverlay => {
continue;
}
}
@@ -3729,6 +3785,7 @@ impl Renderer {
let transform = match layer.usage {
CompositorSurfaceUsage::Content => CompositorSurfaceTransform::identity(),
CompositorSurfaceUsage::External { transform_index, .. } => composite_state.get_compositor_transform(transform_index),
CompositorSurfaceUsage::DebugOverlay => CompositorSurfaceTransform::identity(),
};
compositor.add_surface(
@@ -3738,8 +3795,6 @@ impl Renderer {
ImageRendering::Auto,
);
}
compositor.end_frame();
}
}