Add a push version of render()
Browse files at this commit39d3cd2415cbedb3671eb4d241046b92f36a30f7Parent: 19b10741 changed file +50 -50
- src/niri.rs +50 -50
src/niri.rsmodified+50 -50
| @@ -4283,8 +4283,29 @@ impl Niri { | |||
| 4283 | renderer: &mut R, | 4283 | renderer: &mut R, |
| 4284 | output: &Output, | 4284 | output: &Output, |
| 4285 | include_pointer: bool, | 4285 | include_pointer: bool, |
| 4286 | - mut target: RenderTarget, | 4286 | + target: RenderTarget, |
| 4287 | ) -> Vec<OutputRenderElements<R>> { | 4287 | ) -> Vec<OutputRenderElements<R>> { |
| 4288 | + let mut elements = Vec::new(); | ||
| 4289 | + self.render_inner(renderer, output, include_pointer, target, &mut |elem| { | ||
| 4290 | + elements.push(elem) | ||
| 4291 | + }); | ||
| 4292 | + | ||
| 4293 | + if self.debug_draw_opaque_regions { | ||
| 4294 | + let output_scale = Scale::from(output.current_scale().fractional_scale()); | ||
| 4295 | + draw_opaque_regions(&mut elements, output_scale); | ||
| 4296 | + } | ||
| 4297 | + | ||
| 4298 | + elements | ||
| 4299 | + } | ||
| 4300 | + | ||
| 4301 | + pub fn render_inner<R: NiriRenderer>( | ||
| 4302 | + &self, | ||
| 4303 | + renderer: &mut R, | ||
| 4304 | + output: &Output, | ||
| 4305 | + include_pointer: bool, | ||
| 4306 | + mut target: RenderTarget, | ||
| 4307 | + push: &mut dyn FnMut(OutputRenderElements<R>), | ||
| 4308 | + ) { | ||
| 4288 | let _span = tracy_client::span!("Niri::render"); | 4309 | let _span = tracy_client::span!("Niri::render"); |
| 4289 | 4310 | ||
| 4290 | if target == RenderTarget::Output { | 4311 | if target == RenderTarget::Output { |
| @@ -4299,26 +4320,25 @@ impl Niri { | |||
| 4299 | let output_scale = Scale::from(output.current_scale().fractional_scale()); | 4320 | let output_scale = Scale::from(output.current_scale().fractional_scale()); |
| 4300 | 4321 | ||
| 4301 | // The pointer goes on the top. | 4322 | // The pointer goes on the top. |
| 4302 | - let mut elements = vec![]; | ||
| 4303 | if include_pointer && self.pointer_visibility.is_visible() { | 4323 | if include_pointer && self.pointer_visibility.is_visible() { |
| 4304 | - self.render_pointer(renderer, output, &mut |elem| elements.push(elem.into())); | 4324 | + self.render_pointer(renderer, output, &mut |elem| push(elem.into())); |
| 4305 | } | 4325 | } |
| 4306 | 4326 | ||
| 4307 | // Next, the screen transition texture. | 4327 | // Next, the screen transition texture. |
| 4308 | { | 4328 | { |
| 4309 | let state = self.output_state.get(output).unwrap(); | 4329 | let state = self.output_state.get(output).unwrap(); |
| 4310 | if let Some(transition) = &state.screen_transition { | 4330 | if let Some(transition) = &state.screen_transition { |
| 4311 | - elements.push(transition.render(target).into()); | 4331 | + push(transition.render(target).into()); |
| 4312 | } | 4332 | } |
| 4313 | } | 4333 | } |
| 4314 | 4334 | ||
| 4315 | // Next, the exit confirm dialog. | 4335 | // Next, the exit confirm dialog. |
| 4316 | self.exit_confirm_dialog | 4336 | self.exit_confirm_dialog |
| 4317 | - .render(renderer, output, &mut |elem| elements.push(elem.into())); | 4337 | + .render(renderer, output, &mut |elem| push(elem.into())); |
| 4318 | 4338 | ||
| 4319 | // Next, the config error notification too. | 4339 | // Next, the config error notification too. |
| 4320 | if let Some(element) = self.config_error_notification.render(renderer, output) { | 4340 | if let Some(element) = self.config_error_notification.render(renderer, output) { |
| 4321 | - elements.push(element.into()); | 4341 | + push(element.into()); |
| 4322 | } | 4342 | } |
| 4323 | 4343 | ||
| 4324 | // If the session is locked, draw the lock surface. | 4344 | // If the session is locked, draw the lock surface. |
| @@ -4332,12 +4352,12 @@ impl Niri { | |||
| 4332 | output_scale, | 4352 | output_scale, |
| 4333 | 1., | 4353 | 1., |
| 4334 | Kind::ScanoutCandidate, | 4354 | Kind::ScanoutCandidate, |
| 4335 | - &mut |elem| elements.push(elem.into()), | 4355 | + &mut |elem| push(elem.into()), |
| 4336 | ); | 4356 | ); |
| 4337 | } | 4357 | } |
| 4338 | 4358 | ||
| 4339 | // Draw the solid color background. | 4359 | // Draw the solid color background. |
| 4340 | - elements.push( | 4360 | + push( |
| 4341 | SolidColorRenderElement::from_buffer( | 4361 | SolidColorRenderElement::from_buffer( |
| 4342 | &state.lock_color_buffer, | 4362 | &state.lock_color_buffer, |
| 4343 | (0., 0.), | 4363 | (0., 0.), |
| @@ -4347,10 +4367,7 @@ impl Niri { | |||
| 4347 | .into(), | 4367 | .into(), |
| 4348 | ); | 4368 | ); |
| 4349 | 4369 | ||
| 4350 | - if self.debug_draw_opaque_regions { | 4370 | + return; |
| 4351 | - draw_opaque_regions(&mut elements, output_scale); | ||
| 4352 | - } | ||
| 4353 | - return elements; | ||
| 4354 | } | 4371 | } |
| 4355 | 4372 | ||
| 4356 | // Prepare the background elements. | 4373 | // Prepare the background elements. |
| @@ -4366,26 +4383,23 @@ impl Niri { | |||
| 4366 | // If the screenshot UI is open, draw it. | 4383 | // If the screenshot UI is open, draw it. |
| 4367 | if self.screenshot_ui.is_open() { | 4384 | if self.screenshot_ui.is_open() { |
| 4368 | self.screenshot_ui | 4385 | self.screenshot_ui |
| 4369 | - .render_output(output, target, &mut |elem| elements.push(elem.into())); | 4386 | + .render_output(output, target, &mut |elem| push(elem.into())); |
| 4370 | 4387 | ||
| 4371 | // Add the backdrop for outputs that were connected while the screenshot UI was open. | 4388 | // Add the backdrop for outputs that were connected while the screenshot UI was open. |
| 4372 | - elements.push(backdrop); | 4389 | + push(backdrop); |
| 4373 | 4390 | ||
| 4374 | - if self.debug_draw_opaque_regions { | 4391 | + return; |
| 4375 | - draw_opaque_regions(&mut elements, output_scale); | ||
| 4376 | - } | ||
| 4377 | - return elements; | ||
| 4378 | } | 4392 | } |
| 4379 | 4393 | ||
| 4380 | // Draw the hotkey overlay on top. | 4394 | // Draw the hotkey overlay on top. |
| 4381 | if let Some(element) = self.hotkey_overlay.render(renderer, output) { | 4395 | if let Some(element) = self.hotkey_overlay.render(renderer, output) { |
| 4382 | - elements.push(element.into()); | 4396 | + push(element.into()); |
| 4383 | } | 4397 | } |
| 4384 | 4398 | ||
| 4385 | // Then, the Alt-Tab switcher. | 4399 | // Then, the Alt-Tab switcher. |
| 4386 | self.window_mru_ui | 4400 | self.window_mru_ui |
| 4387 | .render_output(self, output, renderer, target, &mut |elem| { | 4401 | .render_output(self, output, renderer, target, &mut |elem| { |
| 4388 | - elements.push(elem.into()) | 4402 | + push(elem.into()) |
| 4389 | }); | 4403 | }); |
| 4390 | 4404 | ||
| 4391 | // Don't draw the focus ring on the workspaces while interactively moving above those | 4405 | // Don't draw the focus ring on the workspaces while interactively moving above those |
| @@ -4399,20 +4413,20 @@ impl Niri { | |||
| 4399 | // Get layer-shell elements. | 4413 | // Get layer-shell elements. |
| 4400 | let layer_map = layer_map_for_output(output); | 4414 | let layer_map = layer_map_for_output(output); |
| 4401 | 4415 | ||
| 4402 | - // We use macros instead of closures to avoid borrowing issues (renderer and elements go | 4416 | + // We use macros instead of closures to avoid borrowing issues (renderer and push() go |
| 4403 | // into different functions). | 4417 | // into different functions). |
| 4404 | macro_rules! push_popups_from_layer { | 4418 | macro_rules! push_popups_from_layer { |
| 4405 | ($layer:expr, $backdrop:expr, $push:expr) => {{ | 4419 | ($layer:expr, $backdrop:expr, $push:expr) => {{ |
| 4406 | self.render_layer_popups(renderer, target, &layer_map, $layer, $backdrop, $push); | 4420 | self.render_layer_popups(renderer, target, &layer_map, $layer, $backdrop, $push); |
| 4407 | }}; | 4421 | }}; |
| 4408 | ($layer:expr, true) => {{ | 4422 | ($layer:expr, true) => {{ |
| 4409 | - push_popups_from_layer!($layer, true, &mut |elem| elements.push(elem.into())); | 4423 | + push_popups_from_layer!($layer, true, &mut |elem| push(elem.into())); |
| 4410 | }}; | 4424 | }}; |
| 4411 | ($layer:expr, $push:expr) => {{ | 4425 | ($layer:expr, $push:expr) => {{ |
| 4412 | push_popups_from_layer!($layer, false, $push); | 4426 | push_popups_from_layer!($layer, false, $push); |
| 4413 | }}; | 4427 | }}; |
| 4414 | ($layer:expr) => {{ | 4428 | ($layer:expr) => {{ |
| 4415 | - push_popups_from_layer!($layer, false, &mut |elem| elements.push(elem.into())); | 4429 | + push_popups_from_layer!($layer, false, &mut |elem| push(elem.into())); |
| 4416 | }}; | 4430 | }}; |
| 4417 | } | 4431 | } |
| 4418 | macro_rules! push_normal_from_layer { | 4432 | macro_rules! push_normal_from_layer { |
| @@ -4420,13 +4434,13 @@ impl Niri { | |||
| 4420 | self.render_layer_normal(renderer, target, &layer_map, $layer, $backdrop, $push); | 4434 | self.render_layer_normal(renderer, target, &layer_map, $layer, $backdrop, $push); |
| 4421 | }}; | 4435 | }}; |
| 4422 | ($layer:expr, true) => {{ | 4436 | ($layer:expr, true) => {{ |
| 4423 | - push_normal_from_layer!($layer, true, &mut |elem| elements.push(elem.into())); | 4437 | + push_normal_from_layer!($layer, true, &mut |elem| push(elem.into())); |
| 4424 | }}; | 4438 | }}; |
| 4425 | ($layer:expr, $push:expr) => {{ | 4439 | ($layer:expr, $push:expr) => {{ |
| 4426 | push_normal_from_layer!($layer, false, $push); | 4440 | push_normal_from_layer!($layer, false, $push); |
| 4427 | }}; | 4441 | }}; |
| 4428 | ($layer:expr) => {{ | 4442 | ($layer:expr) => {{ |
| 4429 | - push_normal_from_layer!($layer, false, &mut |elem| elements.push(elem.into())); | 4443 | + push_normal_from_layer!($layer, false, &mut |elem| push(elem.into())); |
| 4430 | }}; | 4444 | }}; |
| 4431 | } | 4445 | } |
| 4432 | 4446 | ||
| @@ -4439,16 +4453,12 @@ impl Niri { | |||
| 4439 | if mon.render_above_top_layer() { | 4453 | if mon.render_above_top_layer() { |
| 4440 | self.layout | 4454 | self.layout |
| 4441 | .render_interactive_move_for_output(renderer, output, target, &mut |elem| { | 4455 | .render_interactive_move_for_output(renderer, output, target, &mut |elem| { |
| 4442 | - elements.push(elem.into()) | 4456 | + push(elem.into()) |
| 4443 | }); | 4457 | }); |
| 4444 | 4458 | ||
| 4445 | - mon.render_insert_hint_between_workspaces(renderer, &mut |elem| { | 4459 | + mon.render_insert_hint_between_workspaces(renderer, &mut |elem| push(elem.into())); |
| 4446 | - elements.push(elem.into()) | ||
| 4447 | - }); | ||
| 4448 | 4460 | ||
| 4449 | - mon.render_workspaces(renderer, target, focus_ring, &mut |elem| { | 4461 | + mon.render_workspaces(renderer, target, focus_ring, &mut |elem| push(elem.into())); |
| 4450 | - elements.push(elem.into()) | ||
| 4451 | - }); | ||
| 4452 | 4462 | ||
| 4453 | push_popups_from_layer!(Layer::Top); | 4463 | push_popups_from_layer!(Layer::Top); |
| 4454 | push_normal_from_layer!(Layer::Top); | 4464 | push_normal_from_layer!(Layer::Top); |
| @@ -4460,7 +4470,7 @@ impl Niri { | |||
| 4460 | 4470 | ||
| 4461 | // We don't expect more than one workspace when render_above_top_layer(). | 4471 | // We don't expect more than one workspace when render_above_top_layer(). |
| 4462 | if let Some((ws, _geo)) = mon.workspaces_with_render_geo().next() { | 4472 | if let Some((ws, _geo)) = mon.workspaces_with_render_geo().next() { |
| 4463 | - elements.push(ws.render_background().into()); | 4473 | + push(ws.render_background().into()); |
| 4464 | } | 4474 | } |
| 4465 | } else { | 4475 | } else { |
| 4466 | push_popups_from_layer!(Layer::Top); | 4476 | push_popups_from_layer!(Layer::Top); |
| @@ -4468,19 +4478,17 @@ impl Niri { | |||
| 4468 | 4478 | ||
| 4469 | self.layout | 4479 | self.layout |
| 4470 | .render_interactive_move_for_output(renderer, output, target, &mut |elem| { | 4480 | .render_interactive_move_for_output(renderer, output, target, &mut |elem| { |
| 4471 | - elements.push(elem.into()) | 4481 | + push(elem.into()) |
| 4472 | }); | 4482 | }); |
| 4473 | 4483 | ||
| 4474 | - mon.render_insert_hint_between_workspaces(renderer, &mut |elem| { | 4484 | + mon.render_insert_hint_between_workspaces(renderer, &mut |elem| push(elem.into())); |
| 4475 | - elements.push(elem.into()) | ||
| 4476 | - }); | ||
| 4477 | 4485 | ||
| 4478 | - // Macro instead of closure to avoid borrowing elements. | 4486 | + // Macro instead of closure to avoid borrowing push(). |
| 4479 | macro_rules! process { | 4487 | macro_rules! process { |
| 4480 | ($geo:expr) => {{ | 4488 | ($geo:expr) => {{ |
| 4481 | &mut |elem| { | 4489 | &mut |elem| { |
| 4482 | if let Some(elem) = scale_relocate_crop(elem, output_scale, zoom, $geo) { | 4490 | if let Some(elem) = scale_relocate_crop(elem, output_scale, zoom, $geo) { |
| 4483 | - elements.push(elem.into()); | 4491 | + push(elem.into()); |
| 4484 | } | 4492 | } |
| 4485 | } | 4493 | } |
| 4486 | }}; | 4494 | }}; |
| @@ -4491,9 +4499,7 @@ impl Niri { | |||
| 4491 | push_popups_from_layer!(Layer::Background, process!(geo)); | 4499 | push_popups_from_layer!(Layer::Background, process!(geo)); |
| 4492 | } | 4500 | } |
| 4493 | 4501 | ||
| 4494 | - mon.render_workspaces(renderer, target, focus_ring, &mut |elem| { | 4502 | + mon.render_workspaces(renderer, target, focus_ring, &mut |elem| push(elem.into())); |
| 4495 | - elements.push(elem.into()) | ||
| 4496 | - }); | ||
| 4497 | 4503 | ||
| 4498 | for (ws, geo) in mon.workspaces_with_render_geo() { | 4504 | for (ws, geo) in mon.workspaces_with_render_geo() { |
| 4499 | push_normal_from_layer!(Layer::Bottom, process!(geo)); | 4505 | push_normal_from_layer!(Layer::Bottom, process!(geo)); |
| @@ -4503,19 +4509,13 @@ impl Niri { | |||
| 4503 | } | 4509 | } |
| 4504 | } | 4510 | } |
| 4505 | 4511 | ||
| 4506 | - mon.render_workspace_shadows(renderer, &mut |elem| elements.push(elem.into())); | 4512 | + mon.render_workspace_shadows(renderer, &mut |elem| push(elem.into())); |
| 4507 | 4513 | ||
| 4508 | // Then the backdrop. | 4514 | // Then the backdrop. |
| 4509 | push_popups_from_layer!(Layer::Background, true); | 4515 | push_popups_from_layer!(Layer::Background, true); |
| 4510 | push_normal_from_layer!(Layer::Background, true); | 4516 | push_normal_from_layer!(Layer::Background, true); |
| 4511 | 4517 | ||
| 4512 | - elements.push(backdrop); | 4518 | + push(backdrop); |
| 4513 | - | ||
| 4514 | - if self.debug_draw_opaque_regions { | ||
| 4515 | - draw_opaque_regions(&mut elements, output_scale); | ||
| 4516 | - } | ||
| 4517 | - | ||
| 4518 | - elements | ||
| 4519 | } | 4519 | } |
| 4520 | 4520 | ||
| 4521 | fn layers_in_render_order<'a>( | 4521 | fn layers_in_render_order<'a>( |