Skip to content

Commit

Permalink
webrender: make webrender resizable
Browse files Browse the repository at this point in the history
  • Loading branch information
harryfei committed Aug 14, 2020
1 parent 4397bd6 commit bd140fd
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 16 deletions.
23 changes: 12 additions & 11 deletions rust_src/src/webrender_backend/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use font_kit::handle::Handle as FontHandle;
use gleam::gl::{self, Gl};
use glutin::{
self,
dpi::{LogicalSize, PhysicalPosition},
dpi::{LogicalSize, PhysicalPosition, PhysicalSize},
event::{Event, WindowEvent},
event_loop::{ControlFlow, EventLoopProxy},
monitor::MonitorHandle,
Expand Down Expand Up @@ -118,7 +118,9 @@ impl Output {

let window_loop_thread = std::thread::spawn(move || {
let events_loop = glutin::event_loop::EventLoop::new_any_thread();
let window_builder = glutin::window::WindowBuilder::new().with_maximized(true);
let window_builder = glutin::window::WindowBuilder::new()
.with_visible(false)
.with_maximized(true);

let window_context = glutin::ContextBuilder::new()
.build_windowed(window_builder, &events_loop)
Expand All @@ -127,19 +129,10 @@ impl Output {
let current_context = unsafe { window_context.make_current() }.unwrap();
let (current_context, window) = unsafe { current_context.split() };

std::thread::sleep_ms(100);

let gl = Self::get_gl_api(&current_context);

gl.clear_color(1.0, 1.0, 1.0, 1.0);
gl.clear(self::gl::COLOR_BUFFER_BIT);
gl.flush();
current_context.swap_buffers().ok();

let events_loop_proxy = events_loop.create_proxy();

std::thread::sleep_ms(100);

let device_pixel_ratio = window.scale_factor() as f32;

let mut device_size = {
Expand Down Expand Up @@ -335,6 +328,10 @@ impl Output {
self.window.set_visible(false);
}

pub fn maximize(&self) {
self.window.set_maximized(true);
}

pub fn set_display_info(&mut self, mut dpyinfo: DisplayInfoRef) {
self.output.display_info = dpyinfo.as_mut();
}
Expand All @@ -349,6 +346,10 @@ impl Output {
self.window.inner_size().to_logical(scale_factor)
}

pub fn get_physical_size(&self) -> PhysicalSize<u32> {
self.window.inner_size()
}

pub fn display<F>(&mut self, f: F)
where
F: Fn(&mut DisplayListBuilder, SpaceAndClipInfo),
Expand Down
77 changes: 72 additions & 5 deletions rust_src/src/webrender_backend/term.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ use crate::{
lists::{LispConsCircularChecks, LispConsEndChecks},
remacs_sys::{
allocate_kboard, create_terminal, current_kboard, draw_fringe_bitmap_params,
draw_window_fringes, face_id, frame_parm_handler, glyph_row, glyph_row_area, glyph_string,
initial_kboard, input_event, output_method, redisplay_interface, run, terminal,
text_cursor_kinds, xlispstrdup, Fcons, Lisp_Frame, Lisp_Window, Qbackground_color, Qnil,
Qwr, Vframe_list, KBOARD,
draw_window_fringes, face_id, frame_parm_handler, fullscreen_type, glyph_row,
glyph_row_area, glyph_string, initial_kboard, input_event, output_method,
redisplay_interface, run, terminal, text_cursor_kinds, xlispstrdup, Fcons, Lisp_Frame,
Lisp_Window, Qbackground_color, Qfullscreen, Qmaximized, Qnil, Qwr, Vframe_list, KBOARD,
},
remacs_sys::{
display_and_set_cursor, kbd_buffer_store_event_hold, update_face_from_frame_parameter,
change_frame_size, display_and_set_cursor, do_pending_window_change,
kbd_buffer_store_event_hold, store_frame_param, update_face_from_frame_parameter,
window_box, x_clear_end_of_line, x_clear_window_mouse_face, x_draw_right_divider,
x_draw_vertical_border, x_fix_overlapping_area, x_get_glyph_overhangs, x_produce_glyphs,
x_set_bottom_divider_width, x_set_font, x_set_font_backend, x_set_left_fringe,
Expand Down Expand Up @@ -472,12 +473,77 @@ extern "C" fn read_input_event(terminal: *mut terminal, hold_quit: *mut input_ev
}
}

Event::WindowEvent {
event: WindowEvent::Resized(size),
..
} => {
let mut frame: LispFrameRef = top_frame.into();
unsafe {
change_frame_size(
frame.as_mut(),
size.width as i32,
size.height as i32 - frame.menu_bar_height,
false,
true,
false,
true,
);

do_pending_window_change(false);
}
}

_ => {}
});

count
}

extern "C" fn fullscreen(f: *mut Lisp_Frame) {
let frame: LispFrameRef = f.into();
let mut output: OutputRef = unsafe { frame.output_data.wr.into() };

if !frame.is_visible() {
return;
}

if frame.want_fullscreen() == fullscreen_type::FULLSCREEN_MAXIMIZED {
let origin_size = output.get_physical_size();

output.maximize();

let mut wait = true;

while wait {
output.poll_events(|e| {
if let Event::WindowEvent {
event: WindowEvent::Resized(size),
..
} = e
{
if size != origin_size {
unsafe {
change_frame_size(
f,
size.width as i32,
size.height as i32 - frame.menu_bar_height,
false,
true,
false,
true,
)
};

wait = false;
}
}
});
}

unsafe { store_frame_param(f, Qfullscreen, Qmaximized) };
}
}

fn wr_create_terminal(mut dpyinfo: DisplayInfoRef) -> TerminalRef {
let terminal_ptr = unsafe {
create_terminal(
Expand All @@ -496,6 +562,7 @@ fn wr_create_terminal(mut dpyinfo: DisplayInfoRef) -> TerminalRef {
// Other hooks are NULL by default.
terminal.clear_frame_hook = Some(clear_frame);
terminal.read_socket_hook = Some(read_input_event);
terminal.fullscreen_hook = Some(fullscreen);

terminal
}
Expand Down

0 comments on commit bd140fd

Please sign in to comment.