Skip to content

Commit

Permalink
chore: separate render and resize
Browse files Browse the repository at this point in the history
  • Loading branch information
tsukinaha committed Oct 26, 2024
1 parent 7b958bf commit e428ad8
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/ui/mpv/mpvglarea.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use super::tsukimi_mpv::{
use crate::client::client::EMBY_CLIENT;

mod imp {
use std::thread::JoinHandle;
use std::{cell::RefCell, thread::JoinHandle};

use gtk::{
gdk::GLContext,
Expand All @@ -38,7 +38,9 @@ mod imp {
#[derive(Default)]
pub struct MPVGLArea {
pub mpv: TsukimiMPV,
pub mpv_event_loop: OnceCell<JoinHandle<()>>
pub mpv_event_loop: OnceCell<JoinHandle<()>>,
pub scaled_x: RefCell<i32>,
pub scaled_y: RefCell<i32>,
}

// The central trait for subclassing a GObject
Expand All @@ -53,6 +55,13 @@ mod imp {
impl ObjectImpl for MPVGLArea {
fn constructed(&self) {
self.parent_constructed();

let factor = self.obj().scale_factor();
let width = self.obj().width() * factor;
let height = self.obj().height() * factor;

self.scaled_x.replace(width);
self.scaled_y.replace(height);
}

fn dispose(&self) {
Expand Down Expand Up @@ -93,17 +102,22 @@ mod imp {
let Some(ctx) = binding.as_ref() else {
return glib::Propagation::Stop;
};

let factor = self.obj().scale_factor();
let width = self.obj().width() * factor;
let height = self.obj().height() * factor;
let width = self.scaled_x.borrow();
let height = self.scaled_y.borrow();
unsafe {
let mut fbo = -1;
gl::GetIntegerv(gl::FRAMEBUFFER_BINDING, &mut fbo);
ctx.render::<GLContext>(fbo, width, height, true).unwrap();
ctx.render::<GLContext>(fbo, *width, *height, true).unwrap();
}
glib::Propagation::Stop
}

fn resize(&self, width: i32, height: i32) {
let scale = self.obj().scale_factor();
self.scaled_x.replace(width * scale);
self.scaled_y.replace(height * scale);
self.parent_resize(width, height);
}
}
}

Expand Down

0 comments on commit e428ad8

Please sign in to comment.