1
0
Fork 0
forked from wry/wry

render: compute image width/height in single function call

This commit is contained in:
Julian Orth 2024-02-03 23:27:22 +01:00
parent db9c382002
commit 4ba8550da8
7 changed files with 18 additions and 18 deletions

View file

@ -396,17 +396,18 @@ impl MetalConnector {
buffer.dev_fb.copy_texture(&self.state, tex, 0, 0, true); buffer.dev_fb.copy_texture(&self.state, tex, 0, 0, true);
} }
} }
let (width, height) = buffer.dev_fb.size();
changes.change_object(plane.id, |c| { changes.change_object(plane.id, |c| {
c.change(plane.fb_id, buffer.drm.id().0 as _); c.change(plane.fb_id, buffer.drm.id().0 as _);
c.change(plane.crtc_id.id, crtc.id.0 as _); c.change(plane.crtc_id.id, crtc.id.0 as _);
c.change(plane.crtc_x.id, self.cursor_x.get() as _); c.change(plane.crtc_x.id, self.cursor_x.get() as _);
c.change(plane.crtc_y.id, self.cursor_y.get() as _); c.change(plane.crtc_y.id, self.cursor_y.get() as _);
c.change(plane.crtc_w.id, buffer.render_tex.width() as _); c.change(plane.crtc_w.id, width as _);
c.change(plane.crtc_h.id, buffer.render_tex.height() as _); c.change(plane.crtc_h.id, height as _);
c.change(plane.src_x.id, 0); c.change(plane.src_x.id, 0);
c.change(plane.src_y.id, 0); c.change(plane.src_y.id, 0);
c.change(plane.src_w.id, (buffer.render_tex.width() as u64) << 16); c.change(plane.src_w.id, (width as u64) << 16);
c.change(plane.src_h.id, (buffer.render_tex.height() as u64) << 16); c.change(plane.src_h.id, (height as u64) << 16);
}); });
} else { } else {
changes.change_object(plane.id, |c| { changes.change_object(plane.id, |c| {

View file

@ -270,8 +270,7 @@ pub trait GfxImage {
} }
pub trait GfxTexture: Debug { pub trait GfxTexture: Debug {
fn width(&self) -> i32; fn size(&self) -> (i32, i32);
fn height(&self) -> i32;
fn as_any(&self) -> &dyn Any; fn as_any(&self) -> &dyn Any;
} }

View file

@ -32,12 +32,8 @@ impl Texture {
} }
impl GfxTexture for Texture { impl GfxTexture for Texture {
fn width(&self) -> i32 { fn size(&self) -> (i32, i32) {
self.width() (self.width(), self.height())
}
fn height(&self) -> i32 {
self.height()
} }
fn as_any(&self) -> &dyn Any { fn as_any(&self) -> &dyn Any {

View file

@ -304,7 +304,10 @@ impl GuiElement for Label {
) )
.ok(); .ok();
let (tex, width, height) = match tex { let (tex, width, height) = match tex {
Some((t, _)) => (Some(t.clone()), t.texture.width(), t.texture.height()), Some((t, _)) => {
let (width, height) = t.texture.size();
(Some(t.clone()), width, height)
}
_ => (None, 0, 0), _ => (None, 0, 0),
}; };
self.tex.set(tex); self.tex.set(tex);

View file

@ -197,8 +197,9 @@ impl Renderer<'_> {
&Color::from_rgba_straight(20, 20, 20, 255), &Color::from_rgba_straight(20, 20, 20, 255),
); );
if let Some(tex) = placeholder.textures.get(&self.base.scale) { if let Some(tex) = placeholder.textures.get(&self.base.scale) {
let x = x + (pos.width() - tex.texture.width()) / 2; let (tex_width, tex_height) = tex.texture.size();
let y = y + (pos.height() - tex.texture.height()) / 2; let x = x + (pos.width() - tex_width) / 2;
let y = y + (pos.height() - tex_height) / 2;
self.base.render_texture( self.base.render_texture(
&tex.texture, &tex.texture,
x, x,

View file

@ -135,7 +135,7 @@ impl RendererBase<'_> {
let (twidth, theight) = if let Some(size) = tsize { let (twidth, theight) = if let Some(size) = tsize {
size size
} else { } else {
let (mut w, mut h) = (texture.width(), texture.height()); let (mut w, mut h) = texture.size();
if tscale != self.scale { if tscale != self.scale {
let tscale = tscale.to_f64(); let tscale = tscale.to_f64();
w = (w as f64 * self.scalef / tscale).round() as _; w = (w as f64 * self.scalef / tscale).round() as _;

View file

@ -194,7 +194,7 @@ impl OutputNode {
}; };
ws.title_texture.set(Some(title.clone())); ws.title_texture.set(Some(title.clone()));
let mut x = pos + 1; let mut x = pos + 1;
let mut width = title.texture.width(); let (mut width, _) = title.texture.size();
if let Some(scale) = scale { if let Some(scale) = scale {
width = (width as f64 / scale).round() as _; width = (width as f64 / scale).round() as _;
} }
@ -253,7 +253,7 @@ impl OutputNode {
break 'set_status; break 'set_status;
} }
}; };
let mut width = title.texture.width(); let (mut width, _) = title.texture.size();
if let Some(scale) = scale { if let Some(scale) = scale {
width = (width as f64 / scale).round() as _; width = (width as f64 / scale).round() as _;
} }