summaryrefslogtreecommitdiffstats
path: root/src/renderer/mod.rs
diff options
context:
space:
mode:
authorMatt Keeler <mkeeler@users.noreply.github.com>2018-11-10 11:08:48 -0500
committerChristian Duerr <chrisduerr@users.noreply.github.com>2018-11-10 16:08:48 +0000
commit2434547fce7bf47a848f088f2600e8ba7027a62b (patch)
tree551a50b1071e6208c76c9e26b38b40f60605f2c7 /src/renderer/mod.rs
parent81617983bb4b3b17f18dab938bb572757aa54920 (diff)
Upgrade Glutin to v0.19.0
Some changes include: • Use the with_hardware_acceleration function on the ContextBuilder to not require the discrete GPU • Remove the LMenu and RMenu virtual key codes (winit 0.16.0 removed these because Windows now generates LAlt and RAlt instead • Replace set_cursor_state with hide_cursor (winit 0.16.0 removed the set_cursor_state function) • Replace GlWindow::hidpi_factor with GlWindow::get_hidpi_factor and change to expecting an f64 • Use the glutin/winit dpi size and position types where possible Glutin's dpi change event has been implemented. All size events now return logical sizes. As a result of that, the logical sizes are translated in the `display::handle_rezize` method so DPI scaling works correctly. When the DPI is changed, the glyph cache is updated to make use of the correct font size again. Moving a window to a different screen which is a different DPI caused a racing condition where the logical size of the event was sent to the `handle_resize` method in `src/display.rs`, however if there was a DPI change event before `handle_resize` is able to process this message, it would incorrectly use the new DPI to scale the resize event. To solve this issue instead of sending the logical size to the `handle_resize` method and then converting it to a physical size in there, the `LogicalSize` of the resize event is transformed into a `PhysicalSize` as soon as it's received. This fixes potential racing conditions since all events are processed in order. The padding has been changed so it's also scaled by DPR. The `scale_with_dpi` config option has been removed. If it's not present a warning will be emitted. The `winit` dependency on Windows has been removed. All interactions with winit in Alacritty are handled through glutin.
Diffstat (limited to 'src/renderer/mod.rs')
-rw-r--r--src/renderer/mod.rs62
1 files changed, 30 insertions, 32 deletions
diff --git a/src/renderer/mod.rs b/src/renderer/mod.rs
index 28b44633..cb36210f 100644
--- a/src/renderer/mod.rs
+++ b/src/renderer/mod.rs
@@ -31,9 +31,7 @@ use notify::{watcher, DebouncedEvent, RecursiveMode, Watcher};
use config::{self, Config, Delta};
use term::{self, cell, RenderableCell};
-use window::{Pixels, Size};
-
-use Rgb;
+use {PhysicalSize, Rgb};
// Shader paths for live reload
static TEXT_SHADER_F_PATH: &'static str = concat!(env!("CARGO_MANIFEST_DIR"), "/res/text.f.glsl");
@@ -291,20 +289,25 @@ impl GlyphCache {
&mut self,
font: &config::Font,
size: font::Size,
+ dpr: f64,
loader: &mut L
) -> Result<(), font::Error> {
// Clear currently cached data in both GL and the registry
loader.clear();
self.cache = HashMap::default();
+ // Update dpi scaling
+ self.rasterizer.update_dpr(dpr as f32);
+
// Recompute font keys
let font = font.to_owned().with_size(size);
- info!("Font size changed: {:?}", font.size);
let (regular, bold, italic) = Self::compute_font_keys(&font, &mut self.rasterizer)?;
self.rasterizer.get_glyph(GlyphKey { font_key: regular, c: 'm', size: font.size() })?;
let metrics = self.rasterizer.metrics(regular, size)?;
+ info!("Font size changed: {:?} [DPR: {}]", font.size, dpr);
+
self.font_size = font.size;
self.font_key = regular;
self.bold_key = bold;
@@ -468,8 +471,8 @@ const ATLAS_SIZE: i32 = 1024;
impl QuadRenderer {
// TODO should probably hand this a transform instead of width/height
- pub fn new(config: &Config, size: Size<Pixels<u32>>) -> Result<QuadRenderer, Error> {
- let program = ShaderProgram::new(config, size)?;
+ pub fn new(config: &Config, size: PhysicalSize, dpr: f64) -> Result<QuadRenderer, Error> {
+ let program = ShaderProgram::new(config, size, dpr)?;
let mut vao: GLuint = 0;
let mut vbo: GLuint = 0;
@@ -664,13 +667,7 @@ impl QuadRenderer {
while let Ok(msg) = self.rx.try_recv() {
match msg {
Msg::ShaderReload => {
- self.reload_shaders(
- config,
- Size {
- width: Pixels(props.width as u32),
- height: Pixels(props.height as u32),
- },
- );
+ self.reload_shaders(config, PhysicalSize::new(f64::from(props.width), f64::from(props.height)), props.dpr);
}
}
}
@@ -722,9 +719,9 @@ impl QuadRenderer {
})
}
- pub fn reload_shaders(&mut self, config: &Config, size: Size<Pixels<u32>>) {
+ pub fn reload_shaders(&mut self, config: &Config, size: PhysicalSize, dpr: f64) {
warn!("Reloading shaders ...");
- let program = match ShaderProgram::new(config, size) {
+ let program = match ShaderProgram::new(config, size, dpr) {
Ok(program) => {
warn!(" ... OK");
program
@@ -750,23 +747,20 @@ impl QuadRenderer {
self.program = program;
}
- pub fn resize(&mut self, width: i32, height: i32) {
- let padding_x = i32::from(self.program.padding_x);
- let padding_y = i32::from(self.program.padding_y);
+ pub fn resize(&mut self, size: PhysicalSize, dpr: f64) {
+ let (width, height) : (u32, u32) = size.into();
+
+ let padding_x = (f64::from(self.program.padding_x) * dpr) as i32;
+ let padding_y = (f64::from(self.program.padding_y) * dpr) as i32;
// viewport
unsafe {
- gl::Viewport(
- padding_x,
- padding_y,
- width - 2 * padding_x,
- height - 2 * padding_y,
- );
+ gl::Viewport(padding_x, padding_y, (width as i32) - 2 * padding_x, (height as i32) - 2 * padding_y);
}
// update projection
self.program.activate();
- self.program.update_projection(width as f32, height as f32);
+ self.program.update_projection(width as f32, height as f32, dpr as f32);
self.program.deactivate();
}
}
@@ -1004,7 +998,8 @@ impl ShaderProgram {
pub fn new(
config: &Config,
- size: Size<Pixels<u32>>,
+ size: PhysicalSize,
+ dpr: f64
) -> Result<ShaderProgram, ShaderCreationError> {
let vertex_source = if cfg!(feature = "live-shader-reload") {
None
@@ -1066,17 +1061,20 @@ impl ShaderProgram {
padding_y: config.padding().y,
};
- shader.update_projection(*size.width as f32, *size.height as f32);
+ shader.update_projection(size.width as f32, size.height as f32, dpr as f32);
shader.deactivate();
Ok(shader)
}
- fn update_projection(&self, width: f32, height: f32) {
+ fn update_projection(&self, width: f32, height: f32, dpr: f32) {
+ let padding_x = (f32::from(self.padding_x) * dpr).floor();
+ let padding_y = (f32::from(self.padding_y) * dpr).floor();
+
// Bounds check
- if (width as u32) < (2 * u32::from(self.padding_x)) ||
- (height as u32) < (2 * u32::from(self.padding_y))
+ if (width as u32) < (2 * padding_x as u32) ||
+ (height as u32) < (2 * padding_y as u32)
{
return;
}
@@ -1088,8 +1086,8 @@ impl ShaderProgram {
// correctly.
let ortho = cgmath::ortho(
0.,
- width - 2. * f32::from(self.padding_x),
- 2. * f32::from(self.padding_y),
+ width - (2. * padding_x),
+ 2. * padding_y,
height,
-1.,
1.,