Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix scale factor of egui context #30358

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 20 additions & 17 deletions ports/servoshell/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,23 +81,26 @@ impl App {
minibrowser: None,
};

if opts::get().minibrowser && window.winit_window().is_some() {
// Make sure the gl context is made current.
let webrender_surfman = window.webrender_surfman();
let webrender_gl = match webrender_surfman.connection().gl_api() {
GLApi::GL => unsafe {
gl::GlFns::load_with(|s| webrender_surfman.get_proc_address(s))
},
GLApi::GLES => unsafe {
gl::GlesFns::load_with(|s| webrender_surfman.get_proc_address(s))
},
};
webrender_surfman.make_gl_context_current().unwrap();
debug_assert_eq!(webrender_gl.get_error(), gleam::gl::NO_ERROR);

// Set up egui context for minibrowser ui
// Adapted from https://github.com/emilk/egui/blob/9478e50d012c5138551c38cbee16b07bc1fcf283/crates/egui_glow/examples/pure_glow.rs
app.minibrowser = Some(Minibrowser::new(&webrender_surfman, &events_loop).into());
if opts::get().minibrowser {
if let Some(winit_window) = window.winit_window() {
// Make sure the gl context is made current.
let webrender_surfman = window.webrender_surfman();
let webrender_gl = match webrender_surfman.connection().gl_api() {
GLApi::GL => unsafe {
gl::GlFns::load_with(|s| webrender_surfman.get_proc_address(s))
},
GLApi::GLES => unsafe {
gl::GlesFns::load_with(|s| webrender_surfman.get_proc_address(s))
},
};
webrender_surfman.make_gl_context_current().unwrap();
debug_assert_eq!(webrender_gl.get_error(), gleam::gl::NO_ERROR);

// Set up egui context for minibrowser ui
// Adapted from https://github.com/emilk/egui/blob/9478e50d012c5138551c38cbee16b07bc1fcf283/crates/egui_glow/examples/pure_glow.rs
app.minibrowser =
Some(Minibrowser::new(&webrender_surfman, &events_loop, winit_window).into());
}
}

if let Some(mut minibrowser) = app.minibrowser() {
Expand Down
6 changes: 5 additions & 1 deletion ports/servoshell/egui_glue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ impl EguiGlow {
/// For automatic shader version detection set `shader_version` to `None`.
pub fn new<E>(
event_loop: &winit::event_loop::EventLoopWindowTarget<E>,
window: &winit::window::Window,
gl: std::sync::Arc<glow::Context>,
shader_version: Option<ShaderVersion>,
) -> Self {
Expand All @@ -61,9 +62,12 @@ impl EguiGlow {
})
.unwrap();

let mut egui_winit = egui_winit::State::new(event_loop);
egui_winit.set_pixels_per_point(window.scale_factor() as f32);

Self {
egui_ctx: Default::default(),
egui_winit: egui_winit::State::new(event_loop),
egui_winit,
painter,
shapes: Default::default(),
textures_delta: Default::default(),
Expand Down
9 changes: 7 additions & 2 deletions ports/servoshell/minibrowser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use log::{trace, warn};
use servo::compositing::windowing::EmbedderEvent;
use servo::servo_url::ServoUrl;
use servo::webrender_surfman::WebrenderSurfman;
use winit::window::Window;

use crate::browser::Browser;
use crate::egui_glue::EguiGlow;
Expand All @@ -34,13 +35,17 @@ pub enum MinibrowserEvent {
}

impl Minibrowser {
pub fn new(webrender_surfman: &WebrenderSurfman, events_loop: &EventsLoop) -> Self {
pub fn new(
webrender_surfman: &WebrenderSurfman,
events_loop: &EventsLoop,
window: &Window,
) -> Self {
let gl = unsafe {
glow::Context::from_loader_function(|s| webrender_surfman.get_proc_address(s))
};

Self {
context: EguiGlow::new(events_loop.as_winit(), Arc::new(gl), None),
context: EguiGlow::new(events_loop.as_winit(), window, Arc::new(gl), None),
event_queue: RefCell::new(vec![]),
toolbar_height: 0f32.into(),
last_update: Instant::now(),
Expand Down