text: re-use textures if possible
This commit is contained in:
parent
bf90204db6
commit
a04870388f
10 changed files with 153 additions and 45 deletions
|
|
@ -3,7 +3,6 @@ use {
|
|||
backend::KeyState,
|
||||
cursor::KnownCursor,
|
||||
fixed::Fixed,
|
||||
gfx_api::GfxTexture,
|
||||
ifs::wl_seat::{
|
||||
collect_kb_foci, collect_kb_foci2, wl_pointer::PendingScroll, NodeSeatState, SeatId,
|
||||
WlSeatGlobal, BTN_LEFT,
|
||||
|
|
@ -12,7 +11,7 @@ use {
|
|||
renderer::Renderer,
|
||||
scale::Scale,
|
||||
state::State,
|
||||
text,
|
||||
text::{self, TextTexture},
|
||||
tree::{
|
||||
walker::NodeVisitor, ContainingNode, Direction, FindTreeResult, FoundNode, Node,
|
||||
NodeId, ToplevelData, ToplevelNode, WorkspaceNode,
|
||||
|
|
@ -24,7 +23,7 @@ use {
|
|||
numcell::NumCell,
|
||||
rc_eq::rc_eq,
|
||||
scroller::Scroller,
|
||||
smallmap::SmallMapMut,
|
||||
smallmap::{SmallMap, SmallMapMut},
|
||||
},
|
||||
},
|
||||
ahash::AHashMap,
|
||||
|
|
@ -77,7 +76,7 @@ tree_id!(ContainerNodeId);
|
|||
pub struct ContainerTitle {
|
||||
pub x: i32,
|
||||
pub y: i32,
|
||||
pub tex: Rc<dyn GfxTexture>,
|
||||
pub tex: TextTexture,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
|
|
@ -128,6 +127,7 @@ pub struct ContainerChild {
|
|||
pub node: Rc<dyn ToplevelNode>,
|
||||
pub active: Cell<bool>,
|
||||
title: RefCell<String>,
|
||||
pub title_tex: SmallMap<Scale, TextTexture, 2>,
|
||||
pub title_rect: Cell<Rect>,
|
||||
focus_history: Cell<Option<LinkedNode<NodeRef<ContainerChild>>>>,
|
||||
|
||||
|
|
@ -182,6 +182,7 @@ impl ContainerNode {
|
|||
content: Default::default(),
|
||||
factor: Cell::new(1.0),
|
||||
title: Default::default(),
|
||||
title_tex: Default::default(),
|
||||
title_rect: Default::default(),
|
||||
focus_history: Default::default(),
|
||||
}),
|
||||
|
|
@ -289,6 +290,7 @@ impl ContainerNode {
|
|||
content: Default::default(),
|
||||
factor: Default::default(),
|
||||
title: Default::default(),
|
||||
title_tex: Default::default(),
|
||||
title_rect: Default::default(),
|
||||
focus_history: Default::default(),
|
||||
});
|
||||
|
|
@ -678,6 +680,7 @@ impl ContainerNode {
|
|||
}
|
||||
let title = child.title.borrow_mut();
|
||||
for (scale, _) in scales.iter() {
|
||||
let old_tex = child.title_tex.remove(scale);
|
||||
let titles = rd.titles.get_or_default_mut(*scale);
|
||||
'render_title: {
|
||||
let mut th = th;
|
||||
|
|
@ -693,12 +696,24 @@ impl ContainerNode {
|
|||
break 'render_title;
|
||||
}
|
||||
if let Some(ctx) = &ctx {
|
||||
match text::render(ctx, width, th, &font, title.deref(), color, scalef) {
|
||||
Ok(t) => titles.push(ContainerTitle {
|
||||
x: rect.x1(),
|
||||
y: rect.y1(),
|
||||
tex: t,
|
||||
}),
|
||||
match text::render(
|
||||
ctx,
|
||||
old_tex,
|
||||
width,
|
||||
th,
|
||||
&font,
|
||||
title.deref(),
|
||||
color,
|
||||
scalef,
|
||||
) {
|
||||
Ok(t) => {
|
||||
child.title_tex.insert(*scale, t.clone());
|
||||
titles.push(ContainerTitle {
|
||||
x: rect.x1(),
|
||||
y: rect.y1(),
|
||||
tex: t,
|
||||
})
|
||||
}
|
||||
Err(e) => {
|
||||
log::error!("Could not render title {}: {}", title, ErrorFmt(e));
|
||||
}
|
||||
|
|
@ -1268,6 +1283,7 @@ impl ContainingNode for ContainerNode {
|
|||
content: Default::default(),
|
||||
factor: Cell::new(node.factor.get()),
|
||||
title: Default::default(),
|
||||
title_tex: Default::default(),
|
||||
title_rect: Cell::new(node.title_rect.get()),
|
||||
focus_history: Cell::new(None),
|
||||
});
|
||||
|
|
|
|||
|
|
@ -3,13 +3,12 @@ use {
|
|||
backend::KeyState,
|
||||
cursor::KnownCursor,
|
||||
fixed::Fixed,
|
||||
gfx_api::GfxTexture,
|
||||
ifs::wl_seat::{NodeSeatState, SeatId, WlSeatGlobal, BTN_LEFT},
|
||||
rect::Rect,
|
||||
renderer::Renderer,
|
||||
scale::Scale,
|
||||
state::State,
|
||||
text,
|
||||
text::{self, TextTexture},
|
||||
tree::{
|
||||
walker::NodeVisitor, ContainingNode, FindTreeResult, FoundNode, Node, NodeId,
|
||||
StackedNode, ToplevelNode, WorkspaceNode,
|
||||
|
|
@ -44,7 +43,7 @@ pub struct FloatNode {
|
|||
pub layout_scheduled: Cell<bool>,
|
||||
pub render_titles_scheduled: Cell<bool>,
|
||||
pub title: RefCell<String>,
|
||||
pub title_textures: CopyHashMap<Scale, Rc<dyn GfxTexture>>,
|
||||
pub title_textures: CopyHashMap<Scale, TextTexture>,
|
||||
seats: RefCell<AHashMap<SeatId, SeatState>>,
|
||||
}
|
||||
|
||||
|
|
@ -179,7 +178,6 @@ impl FloatNode {
|
|||
let bw = theme.sizes.border_width.get();
|
||||
let font = theme.font.borrow_mut();
|
||||
let title = self.title.borrow_mut();
|
||||
self.title_textures.clear();
|
||||
let pos = self.position.get();
|
||||
if pos.width() <= 2 * bw || title.is_empty() {
|
||||
return;
|
||||
|
|
@ -190,6 +188,7 @@ impl FloatNode {
|
|||
};
|
||||
let scales = self.state.scales.lock();
|
||||
for (scale, _) in scales.iter() {
|
||||
let old_tex = self.title_textures.remove(scale);
|
||||
let mut th = th;
|
||||
let mut scalef = None;
|
||||
let mut width = pos.width() - 2 * bw;
|
||||
|
|
@ -202,7 +201,7 @@ impl FloatNode {
|
|||
if th == 0 || width == 0 {
|
||||
continue;
|
||||
}
|
||||
let texture = match text::render(&ctx, width, th, &font, &title, tc, scalef) {
|
||||
let texture = match text::render(&ctx, old_tex, width, th, &font, &title, tc, scalef) {
|
||||
Ok(t) => t,
|
||||
Err(e) => {
|
||||
log::error!("Could not render title {}: {}", title, ErrorFmt(e));
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ use {
|
|||
renderer::Renderer,
|
||||
scale::Scale,
|
||||
state::State,
|
||||
text,
|
||||
text::{self, TextTexture},
|
||||
tree::{
|
||||
walker::NodeVisitor, Direction, FindTreeResult, FoundNode, Node, NodeId, WorkspaceNode,
|
||||
},
|
||||
|
|
@ -165,6 +165,7 @@ impl OutputNode {
|
|||
let output_width = self.global.pos.get().width();
|
||||
rd.underline = Rect::new_sized(0, th, output_width, 1).unwrap();
|
||||
for ws in self.workspaces.iter() {
|
||||
let old_tex = ws.title_texture.take();
|
||||
let mut title_width = th;
|
||||
'create_texture: {
|
||||
if let Some(ctx) = self.state.render_ctx.get() {
|
||||
|
|
@ -177,6 +178,7 @@ impl OutputNode {
|
|||
};
|
||||
let title = match text::render_fitting(
|
||||
&ctx,
|
||||
old_tex,
|
||||
Some(texture_height),
|
||||
&font,
|
||||
&ws.name,
|
||||
|
|
@ -190,8 +192,9 @@ impl OutputNode {
|
|||
break 'create_texture;
|
||||
}
|
||||
};
|
||||
ws.title_texture.set(Some(title.clone()));
|
||||
let mut x = pos + 1;
|
||||
let mut width = title.width();
|
||||
let mut width = title.texture.width();
|
||||
if let Some(scale) = scale {
|
||||
width = (width as f64 / scale).round() as _;
|
||||
}
|
||||
|
|
@ -205,7 +208,7 @@ impl OutputNode {
|
|||
x2: pos + title_width,
|
||||
tex_x: x,
|
||||
tex_y: 0,
|
||||
tex: title,
|
||||
tex: title.texture,
|
||||
ws: ws.deref().clone(),
|
||||
});
|
||||
}
|
||||
|
|
@ -224,6 +227,7 @@ impl OutputNode {
|
|||
pos += title_width;
|
||||
}
|
||||
'set_status: {
|
||||
let old_tex = rd.status.take().map(|s| s.tex);
|
||||
let ctx = match self.state.render_ctx.get() {
|
||||
Some(ctx) => ctx,
|
||||
_ => break 'set_status,
|
||||
|
|
@ -235,6 +239,7 @@ impl OutputNode {
|
|||
let tc = self.state.theme.colors.bar_text.get();
|
||||
let title = match text::render_fitting(
|
||||
&ctx,
|
||||
old_tex,
|
||||
Some(texture_height),
|
||||
&font,
|
||||
&status,
|
||||
|
|
@ -248,7 +253,7 @@ impl OutputNode {
|
|||
break 'set_status;
|
||||
}
|
||||
};
|
||||
let mut width = title.width();
|
||||
let mut width = title.texture.width();
|
||||
if let Some(scale) = scale {
|
||||
width = (width as f64 / scale).round() as _;
|
||||
}
|
||||
|
|
@ -324,6 +329,7 @@ impl OutputNode {
|
|||
desired_output: CloneCell::new(self.global.output_id.clone()),
|
||||
jay_workspaces: Default::default(),
|
||||
capture: self.state.default_workspace_capture.clone(),
|
||||
title_texture: Default::default(),
|
||||
});
|
||||
ws.output_link
|
||||
.set(Some(self.workspaces.add_last(ws.clone())));
|
||||
|
|
@ -473,7 +479,7 @@ pub struct OutputTitle {
|
|||
pub struct OutputStatus {
|
||||
pub tex_x: i32,
|
||||
pub tex_y: i32,
|
||||
pub tex: Rc<dyn GfxTexture>,
|
||||
pub tex: TextTexture,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
|
|
|
|||
|
|
@ -3,13 +3,12 @@ use {
|
|||
client::Client,
|
||||
cursor::KnownCursor,
|
||||
fixed::Fixed,
|
||||
gfx_api::GfxTexture,
|
||||
ifs::wl_seat::{NodeSeatState, WlSeatGlobal},
|
||||
rect::Rect,
|
||||
renderer::Renderer,
|
||||
scale::Scale,
|
||||
state::State,
|
||||
text,
|
||||
text::{self, TextTexture},
|
||||
tree::{
|
||||
Direction, FindTreeResult, FoundNode, Node, NodeId, NodeVisitor, ToplevelData,
|
||||
ToplevelNode,
|
||||
|
|
@ -25,7 +24,7 @@ pub struct PlaceholderNode {
|
|||
id: PlaceholderNodeId,
|
||||
toplevel: ToplevelData,
|
||||
destroyed: Cell<bool>,
|
||||
pub textures: SmallMap<Scale, Rc<dyn GfxTexture>, 2>,
|
||||
pub textures: SmallMap<Scale, TextTexture, 2>,
|
||||
}
|
||||
|
||||
impl PlaceholderNode {
|
||||
|
|
@ -47,11 +46,11 @@ impl PlaceholderNode {
|
|||
}
|
||||
|
||||
pub fn update_texture(&self) {
|
||||
self.textures.clear();
|
||||
if let Some(ctx) = self.toplevel.state.render_ctx.get() {
|
||||
let scales = self.toplevel.state.scales.lock();
|
||||
let rect = self.toplevel.pos.get();
|
||||
for (scale, _) in scales.iter() {
|
||||
let old_tex = self.textures.remove(scale);
|
||||
let mut width = rect.width();
|
||||
let mut height = rect.height();
|
||||
if *scale != 1 {
|
||||
|
|
@ -63,6 +62,7 @@ impl PlaceholderNode {
|
|||
let font = format!("monospace {}", width / 10);
|
||||
match text::render_fitting(
|
||||
&ctx,
|
||||
old_tex,
|
||||
Some(height),
|
||||
&font,
|
||||
"Fullscreen",
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ use {
|
|||
},
|
||||
rect::Rect,
|
||||
renderer::Renderer,
|
||||
text::TextTexture,
|
||||
tree::{
|
||||
container::ContainerNode, walker::NodeVisitor, ContainingNode, Direction,
|
||||
FindTreeResult, FoundNode, Node, NodeId, NodeVisitorBase, OutputNode, StackedNode,
|
||||
|
|
@ -43,6 +44,7 @@ pub struct WorkspaceNode {
|
|||
pub desired_output: CloneCell<Rc<OutputId>>,
|
||||
pub jay_workspaces: CopyHashMap<(ClientId, JayWorkspaceId), Rc<JayWorkspace>>,
|
||||
pub capture: Cell<bool>,
|
||||
pub title_texture: Cell<Option<TextTexture>>,
|
||||
}
|
||||
|
||||
impl WorkspaceNode {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue