Skip to content

Commit

Permalink
text: render text asynchronously
Browse files Browse the repository at this point in the history
  • Loading branch information
mahkoh committed Sep 28, 2024
1 parent d9eb14e commit 12f358c
Show file tree
Hide file tree
Showing 12 changed files with 891 additions and 419 deletions.
26 changes: 19 additions & 7 deletions src/compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ use {
tasks::{self, idle},
tracy::enable_profiler,
tree::{
container_layout, container_render_data, float_layout, float_titles,
output_render_data, DisplayNode, NodeIds, OutputNode, TearingMode, VrrMode,
WorkspaceNode,
container_layout, container_render_positions, container_render_titles, float_layout,
float_titles, output_render_data, placeholder_render_textures, DisplayNode, NodeIds,
OutputNode, TearingMode, VrrMode, WorkspaceNode,
},
user_session::import_environment,
utils::{
Expand Down Expand Up @@ -180,13 +180,15 @@ fn start_compositor2(
input_device_handlers: Default::default(),
theme: Default::default(),
pending_container_layout: Default::default(),
pending_container_render_data: Default::default(),
pending_container_render_positions: Default::default(),
pending_container_render_title: Default::default(),
pending_output_render_data: Default::default(),
pending_float_layout: Default::default(),
pending_float_titles: Default::default(),
pending_input_popup_positioning: Default::default(),
pending_toplevel_screencasts: Default::default(),
pending_screencast_reallocs_or_reconfigures: Default::default(),
pending_placeholder_render_textures: Default::default(),
dbus: Dbus::new(&engine, &ring, &run_toplevel),
fdcloser: FdCloser::new(),
logger: logger.clone(),
Expand Down Expand Up @@ -374,9 +376,19 @@ fn start_global_event_handlers(
container_layout(state.clone()),
),
eng.spawn2(
"container render",
"container render positions",
Phase::PostLayout,
container_render_data(state.clone()),
container_render_positions(state.clone()),
),
eng.spawn2(
"container titles",
Phase::PostLayout,
container_render_titles(state.clone()),
),
eng.spawn2(
"placeholder textures",
Phase::PostLayout,
placeholder_render_textures(state.clone()),
),
eng.spawn2(
"output render",
Expand Down Expand Up @@ -577,7 +589,7 @@ fn create_dummy_output(state: &Rc<State>) {
jay_workspaces: Default::default(),
may_capture: Cell::new(false),
has_capture: Cell::new(false),
title_texture: Cell::new(None),
title_texture: Default::default(),
attention_requests: Default::default(),
render_highlight: Default::default(),
});
Expand Down
100 changes: 53 additions & 47 deletions src/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,20 +131,22 @@ impl Renderer<'_> {
);
}
if let Some(status) = &rd.status {
let (x, y) = self.base.scale_point(x + status.tex_x, y + status.tex_y);
self.base.render_texture(
&status.tex.texture,
None,
x,
y,
None,
None,
scale,
None,
None,
AcquireSync::None,
ReleaseSync::None,
);
if let Some(texture) = status.tex.texture() {
let (x, y) = self.base.scale_point(x + status.tex_x, y);
self.base.render_texture(
&texture,
None,
x,
y,
None,
None,
scale,
None,
None,
AcquireSync::None,
ReleaseSync::None,
);
}
}
}
if let Some(ws) = output.workspace.get() {
Expand Down Expand Up @@ -196,23 +198,25 @@ impl Renderer<'_> {
std::slice::from_ref(&pos.at_point(x, y)),
&Color::from_rgba_straight(20, 20, 20, 255),
);
if let Some(tex) = placeholder.textures.get(&self.base.scale) {
let (tex_width, tex_height) = tex.texture.size();
let x = x + (pos.width() - tex_width) / 2;
let y = y + (pos.height() - tex_height) / 2;
self.base.render_texture(
&tex.texture,
None,
x,
y,
None,
None,
self.base.scale,
None,
None,
AcquireSync::None,
ReleaseSync::None,
);
if let Some(tex) = placeholder.textures.borrow().get(&self.base.scale) {
if let Some(texture) = tex.texture() {
let (tex_width, tex_height) = texture.size();
let x = x + (pos.width() - tex_width) / 2;
let y = y + (pos.height() - tex_height) / 2;
self.base.render_texture(
&texture,
None,
x,
y,
None,
None,
self.base.scale,
None,
None,
AcquireSync::None,
ReleaseSync::None,
);
}
}
self.render_tl_aux(placeholder.tl_data(), bounds, true);
}
Expand Down Expand Up @@ -243,7 +247,7 @@ impl Renderer<'_> {
for title in titles {
let (x, y) = self.base.scale_point(x + title.x, y + title.y);
self.base.render_texture(
&title.tex.texture,
&title.tex,
None,
x,
y,
Expand Down Expand Up @@ -466,21 +470,23 @@ impl Renderer<'_> {
let title_underline =
[Rect::new_sized(x + bw, y + bw + th, pos.width() - 2 * bw, 1).unwrap()];
self.base.fill_boxes(&title_underline, &uc);
if let Some(title) = floating.title_textures.get(&self.base.scale) {
let (x, y) = self.base.scale_point(x + bw, y + bw);
self.base.render_texture(
&title.texture,
None,
x,
y,
None,
None,
self.base.scale,
None,
None,
AcquireSync::None,
ReleaseSync::None,
);
if let Some(title) = floating.title_textures.borrow().get(&self.base.scale) {
if let Some(texture) = title.texture() {
let (x, y) = self.base.scale_point(x + bw, y + bw);
self.base.render_texture(
&texture,
None,
x,
y,
None,
None,
self.base.scale,
None,
None,
AcquireSync::None,
ReleaseSync::None,
);
}
}
let body = Rect::new_sized(
x + bw,
Expand Down
34 changes: 23 additions & 11 deletions src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,15 @@ pub struct State {
pub config: CloneCell<Option<Rc<ConfigProxy>>>,
pub theme: Theme,
pub pending_container_layout: AsyncQueue<Rc<ContainerNode>>,
pub pending_container_render_data: AsyncQueue<Rc<ContainerNode>>,
pub pending_container_render_positions: AsyncQueue<Rc<ContainerNode>>,
pub pending_container_render_title: AsyncQueue<Rc<ContainerNode>>,
pub pending_output_render_data: AsyncQueue<Rc<OutputNode>>,
pub pending_float_layout: AsyncQueue<Rc<FloatNode>>,
pub pending_float_titles: AsyncQueue<Rc<FloatNode>>,
pub pending_input_popup_positioning: AsyncQueue<Rc<ZwpInputPopupSurfaceV2>>,
pub pending_toplevel_screencasts: AsyncQueue<Rc<JayScreencast>>,
pub pending_screencast_reallocs_or_reconfigures: AsyncQueue<Rc<JayScreencast>>,
pub pending_placeholder_render_textures: AsyncQueue<Rc<PlaceholderNode>>,
pub dbus: Dbus,
pub fdcloser: Arc<FdCloser>,
pub logger: Option<Arc<Logger>>,
Expand Down Expand Up @@ -343,22 +345,28 @@ impl DrmDevData {
struct UpdateTextTexturesVisitor;
impl NodeVisitorBase for UpdateTextTexturesVisitor {
fn visit_container(&mut self, node: &Rc<ContainerNode>) {
node.children.iter().for_each(|c| c.title_tex.clear());
node.schedule_compute_render_data();
node.children
.iter()
.for_each(|c| c.title_tex.borrow_mut().clear());
node.schedule_render_titles();
node.node_visit_children(self);
}
fn visit_output(&mut self, node: &Rc<OutputNode>) {
node.schedule_update_render_data();
node.node_visit_children(self);
}
fn visit_float(&mut self, node: &Rc<FloatNode>) {
node.title_textures.clear();
node.title_textures.borrow_mut().clear();
node.schedule_render_titles();
node.node_visit_children(self);
}
fn visit_workspace(&mut self, node: &Rc<WorkspaceNode>) {
node.title_texture.take();
node.node_visit_children(self);
}
fn visit_placeholder(&mut self, node: &Rc<PlaceholderNode>) {
node.textures.clear();
node.update_texture();
node.textures.borrow_mut().clear();
node.schedule_update_texture();
node.node_visit_children(self);
}
}
Expand Down Expand Up @@ -463,11 +471,13 @@ impl State {
impl NodeVisitorBase for Walker {
fn visit_container(&mut self, node: &Rc<ContainerNode>) {
node.render_data.borrow_mut().titles.clear();
node.children.iter().for_each(|c| c.title_tex.clear());
node.children
.iter()
.for_each(|c| c.title_tex.borrow_mut().clear());
node.node_visit_children(self);
}
fn visit_workspace(&mut self, node: &Rc<WorkspaceNode>) {
node.title_texture.set(None);
node.title_texture.take();
node.node_visit_children(self);
}
fn visit_output(&mut self, node: &Rc<OutputNode>) {
Expand All @@ -477,11 +487,11 @@ impl State {
node.node_visit_children(self);
}
fn visit_float(&mut self, node: &Rc<FloatNode>) {
node.title_textures.clear();
node.title_textures.borrow_mut().clear();
node.node_visit_children(self);
}
fn visit_placeholder(&mut self, node: &Rc<PlaceholderNode>) {
node.textures.clear();
node.textures.borrow_mut().clear();
node.node_visit_children(self);
}
}
Expand Down Expand Up @@ -819,13 +829,15 @@ impl State {
}
self.dbus.clear();
self.pending_container_layout.clear();
self.pending_container_render_data.clear();
self.pending_container_render_positions.clear();
self.pending_container_render_title.clear();
self.pending_output_render_data.clear();
self.pending_float_layout.clear();
self.pending_float_titles.clear();
self.pending_input_popup_positioning.clear();
self.pending_toplevel_screencasts.clear();
self.pending_screencast_reallocs_or_reconfigures.clear();
self.pending_placeholder_render_textures.clear();
self.render_ctx_watchers.clear();
self.workspace_watchers.clear();
self.toplevel_lists.clear();
Expand Down
Loading

0 comments on commit 12f358c

Please sign in to comment.