mirror of
https://github.com/wez/wezterm.git
synced 2024-12-28 07:55:03 +03:00
window: remove non-opengl paint, rename paint_opengl -> paint
This commit is contained in:
parent
972c07a692
commit
cf6914c5d8
@ -681,11 +681,6 @@ impl WindowCallbacks for TermWindow {
|
||||
}
|
||||
}
|
||||
|
||||
fn paint(&mut self, ctx: &mut dyn PaintContext) {
|
||||
// We shouldn't get here: we should only ever be running with OpenGL
|
||||
ctx.clear(Color::rgb(0, 0, 0));
|
||||
}
|
||||
|
||||
fn opengl_context_lost(&mut self, prior_window: &dyn WindowOps) -> anyhow::Result<()> {
|
||||
log::error!("context was lost, set up a new window");
|
||||
let activity = Activity::new();
|
||||
@ -792,7 +787,7 @@ impl WindowCallbacks for TermWindow {
|
||||
}
|
||||
}
|
||||
|
||||
fn paint_opengl(&mut self, frame: &mut glium::Frame) {
|
||||
fn paint(&mut self, frame: &mut glium::Frame) {
|
||||
self.check_for_config_reload();
|
||||
let config = configuration();
|
||||
let start = std::time::Instant::now();
|
||||
|
@ -29,11 +29,6 @@ impl WindowCallbacks for MyWindow {
|
||||
Connection::get().unwrap().terminate_message_loop();
|
||||
}
|
||||
|
||||
fn paint(&mut self, context: &mut dyn PaintContext) {
|
||||
// Pick a purple background color
|
||||
context.clear(Color::rgb(0x40, 0x20, 0x60));
|
||||
}
|
||||
|
||||
fn resize(&mut self, dims: Dimensions) {
|
||||
eprintln!("resize {:?}", dims);
|
||||
}
|
||||
|
@ -106,7 +106,7 @@ impl WindowCallbacks for MyWindow {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn paint_opengl(&mut self, frame: &mut glium::Frame) {
|
||||
fn paint(&mut self, frame: &mut glium::Frame) {
|
||||
// Window contents are gray in opengl mode
|
||||
use glium::Surface;
|
||||
frame.clear_color_srgb(0.25, 0.125, 0.375, 1.0);
|
||||
@ -133,34 +133,6 @@ impl WindowCallbacks for MyWindow {
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
fn paint(&mut self, context: &mut dyn PaintContext) {
|
||||
// Pick a purple background color
|
||||
context.clear(Color::rgb(0x40, 0x20, 0x60));
|
||||
|
||||
// This line doesn't need anti-aliasing
|
||||
context.draw_line(
|
||||
Point::new(0, 0),
|
||||
Point::new(100, 100),
|
||||
Color::rgb(0xff, 0xff, 0xff),
|
||||
Operator::Over,
|
||||
);
|
||||
|
||||
// This shallower line should need some
|
||||
context.draw_line(
|
||||
Point::new(100, 0),
|
||||
Point::new(200, 120),
|
||||
Color::rgb(0xff, 0x80, 0xff),
|
||||
Operator::Over,
|
||||
);
|
||||
|
||||
context.draw_line(
|
||||
Point::new(0, 0),
|
||||
self.cursor_pos,
|
||||
Color::rgb(0xff, 0xff, 0x80),
|
||||
Operator::Over,
|
||||
);
|
||||
}
|
||||
|
||||
fn resize(&mut self, dims: Dimensions) {
|
||||
eprintln!("resize {:?}", dims);
|
||||
}
|
||||
|
@ -126,17 +126,9 @@ pub trait WindowCallbacks: Any {
|
||||
/// Called when window gains/loses focus
|
||||
fn focus_change(&mut self, focused: bool) {}
|
||||
|
||||
/// Called when the window contents need painting.
|
||||
/// This is used only when the software renderer is enabled (which
|
||||
/// is the default). When the window is set to opengl mode, the
|
||||
/// `paint_opengl` function is called instead.
|
||||
fn paint(&mut self, context: &mut dyn PaintContext) {
|
||||
context.clear(Color::rgb(0x20, 0x40, 0x60));
|
||||
}
|
||||
|
||||
/// Called when the window has opengl mode enabled and the window
|
||||
/// contents need painting.
|
||||
fn paint_opengl(&mut self, frame: &mut glium::Frame) {
|
||||
fn paint(&mut self, frame: &mut glium::Frame) {
|
||||
use glium::Surface;
|
||||
frame.clear_color_srgb(0.25, 0.125, 0.375, 1.0);
|
||||
}
|
||||
|
@ -1548,7 +1548,7 @@ impl WindowView {
|
||||
(width as u32, height as u32),
|
||||
);
|
||||
|
||||
inner.callbacks.paint_opengl(&mut frame);
|
||||
inner.callbacks.paint(&mut frame);
|
||||
frame
|
||||
.finish()
|
||||
.expect("frame.finish failed and we don't know how to recover");
|
||||
|
@ -570,51 +570,13 @@ impl WaylandWindowInner {
|
||||
),
|
||||
);
|
||||
|
||||
self.callbacks.paint_opengl(&mut frame);
|
||||
self.callbacks.paint(&mut frame);
|
||||
frame.finish()?;
|
||||
// self.damage();
|
||||
self.refresh_frame();
|
||||
self.need_paint = false;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if self.pool.is_used() {
|
||||
// Buffer still in use by server; retry later
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if self.window.is_none() {
|
||||
// Window has been closed; complete gracefully
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
self.pool
|
||||
.resize(4 * self.dimensions.pixel_width * self.dimensions.pixel_height)?;
|
||||
|
||||
let dpi = self.get_dpi();
|
||||
let mut context = MmapImage {
|
||||
mmap: self.pool.mmap(),
|
||||
dimensions: (self.dimensions.pixel_width, self.dimensions.pixel_height),
|
||||
dpi,
|
||||
};
|
||||
self.callbacks.paint(&mut context);
|
||||
context.mmap.flush()?;
|
||||
|
||||
let buffer = self.pool.buffer(
|
||||
0,
|
||||
self.dimensions.pixel_width as i32,
|
||||
self.dimensions.pixel_height as i32,
|
||||
4 * self.dimensions.pixel_width as i32,
|
||||
toolkit::reexports::client::protocol::wl_shm::Format::Argb8888,
|
||||
);
|
||||
|
||||
self.surface.attach(Some(&buffer), 0, 0);
|
||||
self.damage();
|
||||
|
||||
self.surface.commit();
|
||||
self.refresh_frame();
|
||||
self.need_paint = false;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -784,36 +784,8 @@ unsafe fn wm_paint(hwnd: HWND, _msg: UINT, _wparam: WPARAM, _lparam: LPARAM) ->
|
||||
let mut frame =
|
||||
glium::Frame::new(Rc::clone(&gl_context), (width as u32, height as u32));
|
||||
|
||||
inner.callbacks.borrow_mut().paint_opengl(&mut frame);
|
||||
inner.callbacks.borrow_mut().paint(&mut frame);
|
||||
frame.finish().expect("frame.finish failed");
|
||||
EndPaint(hwnd, &mut ps);
|
||||
return Some(0);
|
||||
}
|
||||
|
||||
if width > 0 && height > 0 {
|
||||
let mut bitmap = inner.bitmap.borrow_mut();
|
||||
let (bm_width, bm_height) = bitmap.image_dimensions();
|
||||
if bm_width != width || bm_height != height {
|
||||
*bitmap = GdiBitmap::new_compatible(width, height, dc).unwrap();
|
||||
}
|
||||
let dpi = GetDpiForWindow(hwnd);
|
||||
let mut context = GdiGraphicsContext {
|
||||
dpi,
|
||||
bitmap: &mut bitmap,
|
||||
};
|
||||
|
||||
inner.callbacks.borrow_mut().paint(&mut context);
|
||||
BitBlt(
|
||||
dc,
|
||||
0,
|
||||
0,
|
||||
width as i32,
|
||||
height as i32,
|
||||
context.bitmap.hdc(),
|
||||
0,
|
||||
0,
|
||||
SRCCOPY,
|
||||
);
|
||||
}
|
||||
|
||||
EndPaint(hwnd, &mut ps);
|
||||
|
@ -149,13 +149,10 @@ impl XWindowInner {
|
||||
let window_dimensions =
|
||||
Rect::from_size(Size::new(self.width as isize, self.height as isize));
|
||||
|
||||
if self.paint_all {
|
||||
self.paint_all = false;
|
||||
self.expose.clear();
|
||||
self.expose.push_back(window_dimensions);
|
||||
} else if self.expose.is_empty() {
|
||||
if !self.paint_all && self.expose.is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
self.expose.clear();
|
||||
|
||||
if let Some(gl_context) = self.gl_state.as_ref() {
|
||||
if gl_context.is_context_lost() {
|
||||
@ -165,79 +162,13 @@ impl XWindowInner {
|
||||
return self.paint();
|
||||
}
|
||||
|
||||
self.expose.clear();
|
||||
|
||||
let mut frame = glium::Frame::new(
|
||||
Rc::clone(&gl_context),
|
||||
(u32::from(self.width), u32::from(self.height)),
|
||||
);
|
||||
|
||||
self.callbacks.paint_opengl(&mut frame);
|
||||
self.callbacks.paint(&mut frame);
|
||||
frame.finish()?;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let (buf_width, buf_height) = self.buffer_image.image_dimensions();
|
||||
if buf_width != self.width.into() || buf_height != self.height.into() {
|
||||
// Window was resized, so we need to update our buffer
|
||||
let conn = self.conn();
|
||||
self.buffer_image = BufferImage::new(
|
||||
&conn,
|
||||
self.window_id,
|
||||
self.width as usize,
|
||||
self.height as usize,
|
||||
);
|
||||
}
|
||||
|
||||
for rect in self.expose.drain(..) {
|
||||
// Clip the rectangle to the current window size.
|
||||
// It can be larger than the window size in the case where we are working
|
||||
// through a series of resize exposures during a live resize, and we're
|
||||
// now sized smaller then when we queued the exposure.
|
||||
let rect = Rect::new(
|
||||
rect.origin,
|
||||
Size::new(
|
||||
rect.size.width.min(self.width as isize),
|
||||
rect.size.height.min(self.height as isize),
|
||||
),
|
||||
);
|
||||
|
||||
let mut context = X11GraphicsContext {
|
||||
buffer: &mut self.buffer_image,
|
||||
};
|
||||
|
||||
self.callbacks.paint(&mut context);
|
||||
|
||||
match &self.buffer_image {
|
||||
BufferImage::Shared(ref im) => {
|
||||
self.window_context.copy_area(
|
||||
im,
|
||||
rect.origin.x as i16,
|
||||
rect.origin.y as i16,
|
||||
&self.window_id,
|
||||
rect.origin.x as i16,
|
||||
rect.origin.y as i16,
|
||||
rect.size.width as u16,
|
||||
rect.size.height as u16,
|
||||
);
|
||||
}
|
||||
BufferImage::Image(ref buffer) => {
|
||||
if rect == window_dimensions {
|
||||
self.window_context.put_image(0, 0, buffer);
|
||||
} else {
|
||||
let mut im =
|
||||
Image::new(rect.size.width as usize, rect.size.height as usize);
|
||||
|
||||
im.draw_image(Point::new(0, 0), Some(rect), buffer, Operator::Source);
|
||||
|
||||
self.window_context.put_image(
|
||||
rect.origin.x as i16,
|
||||
rect.origin.y as i16,
|
||||
&im,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
Loading…
Reference in New Issue
Block a user