1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-24 22:01:47 +03:00
This commit is contained in:
Wez Furlong 2019-10-01 22:20:52 -07:00
parent c0411197fa
commit 85311373a5
7 changed files with 63 additions and 40 deletions

View File

@ -492,10 +492,14 @@ impl TermWindow {
}
SendString(s) => tab.writer().write_all(s.as_bytes())?,
Hide => {
self.window.as_ref().map(|w| w.hide());
if let Some(w) = self.window.as_ref() {
w.hide();
}
}
Show => {
self.window.as_ref().map(|w| w.show());
if let Some(w) = self.window.as_ref() {
w.show();
}
}
CloseCurrentTab => self.close_current_tab(),
Nop => {}
@ -520,6 +524,7 @@ impl TermWindow {
});
}
#[allow(clippy::float_cmp)]
fn scaling_changed(&mut self, dimensions: Dimensions, font_scale: f64) {
let mux = Mux::get().unwrap();
if let Some(window) = mux.get_window(self.mux_window_id) {
@ -569,13 +574,13 @@ impl TermWindow {
}
fn decrease_font_size(&mut self) {
self.scaling_changed(self.dimensions.clone(), self.fonts.get_font_scale() * 0.9);
self.scaling_changed(self.dimensions, self.fonts.get_font_scale() * 0.9);
}
fn increase_font_size(&mut self) {
self.scaling_changed(self.dimensions.clone(), self.fonts.get_font_scale() * 1.1);
self.scaling_changed(self.dimensions, self.fonts.get_font_scale() * 1.1);
}
fn reset_font_size(&mut self) {
self.scaling_changed(self.dimensions.clone(), 1.);
self.scaling_changed(self.dimensions, 1.);
}
fn close_current_tab(&mut self) {
@ -623,6 +628,7 @@ impl TermWindow {
Ok(())
}
#[allow(clippy::too_many_arguments)]
fn render_screen_line(
&self,
ctx: &mut dyn PaintContext,
@ -877,6 +883,7 @@ impl TermWindow {
Ok(())
}
#[allow(clippy::too_many_arguments)]
fn compute_cell_fg_bg(
&self,
line_idx: usize,
@ -929,6 +936,7 @@ impl TermWindow {
}
/// Perform the load and render of a glyph
#[allow(clippy::float_cmp)]
fn load_glyph(&self, info: &GlyphInfo, style: &TextStyle) -> Fallible<Rc<CachedGlyph>> {
let (has_color, glyph, cell_width, cell_height) = {
let font = self.fonts.cached_font(style)?;
@ -947,7 +955,6 @@ impl TermWindow {
} else {
1.0f64
};
#[cfg_attr(feature = "cargo-clippy", allow(clippy::float_cmp))]
let (x_offset, y_offset) = if scale != 1.0 {
(info.x_offset * scale, info.y_offset * scale)
} else {

View File

@ -55,6 +55,7 @@ mod avx {
size == align_lo(size, align)
}
#[allow(clippy::cast_ptr_alignment)]
pub unsafe fn fill_pixel(
mut dest: *mut u8,
stride_bytes: usize,
@ -69,34 +70,28 @@ mod avx {
if is_aligned(dest as usize, 32) && is_aligned(stride_bytes, 32) {
for _row in 0..height_pixels {
for col in (0..aligned_width).step_by(8) {
std::arch::x86_64::_mm256_store_si256(
dest.offset(4 * col as isize) as *mut _,
bgra256,
);
std::arch::x86_64::_mm256_store_si256(dest.add(4 * col) as *mut _, bgra256);
}
if width_pixels != aligned_width {
std::arch::x86_64::_mm256_storeu_si256(
dest.offset(4 * (width_pixels as isize - 8)) as *mut _,
dest.add(4 * (width_pixels - 8)) as *mut _,
bgra256,
);
}
dest = dest.offset(stride_bytes as isize);
dest = dest.add(stride_bytes);
}
} else {
for _row in 0..height_pixels {
for col in (0..aligned_width).step_by(8) {
std::arch::x86_64::_mm256_storeu_si256(
dest.offset(4 * col as isize) as *mut _,
bgra256,
);
std::arch::x86_64::_mm256_storeu_si256(dest.add(4 * col) as *mut _, bgra256);
}
if width_pixels != aligned_width {
std::arch::x86_64::_mm256_storeu_si256(
dest.offset(4 * (width_pixels as isize - 8)) as *mut _,
dest.add(4 * (width_pixels - 8)) as *mut _,
bgra256,
);
}
dest = dest.offset(stride_bytes as isize);
dest = dest.add(stride_bytes);
}
}
}
@ -118,6 +113,7 @@ pub trait BitmapImage {
fn pixels(&self) -> &[u32] {
let (width, height) = self.image_dimensions();
unsafe {
#[allow(clippy::cast_ptr_alignment)]
let first = self.pixel_data() as *const u32;
std::slice::from_raw_parts(first, width * height)
}
@ -127,6 +123,7 @@ pub trait BitmapImage {
fn pixels_mut(&mut self) -> &mut [u32] {
let (width, height) = self.image_dimensions();
unsafe {
#[allow(clippy::cast_ptr_alignment)]
let first = self.pixel_data_mut() as *mut u32;
std::slice::from_raw_parts_mut(first, width * height)
}
@ -139,7 +136,8 @@ pub trait BitmapImage {
debug_assert!(x < width && y < height);
unsafe {
let offset = (y * width * 4) + (x * 4);
&mut *(self.pixel_data_mut().offset(offset as isize) as *mut u32)
#[allow(clippy::cast_ptr_alignment)]
&mut *(self.pixel_data_mut().add(offset) as *mut u32)
}
}
@ -150,7 +148,8 @@ pub trait BitmapImage {
debug_assert!(x < width && y < height);
unsafe {
let offset = (y * width * 4) + (x * 4);
&*(self.pixel_data().offset(offset as isize) as *const u32)
#[allow(clippy::cast_ptr_alignment)]
&*(self.pixel_data().add(offset) as *const u32)
}
}
@ -197,7 +196,7 @@ pub trait BitmapImage {
unsafe {
avx::fill_pixel(
self.pixel_data_mut()
.offset(4 * ((dest_y * dim_width) + dest_x) as isize),
.add(4 * ((dest_y * dim_width) + dest_x)),
dim_width * 4,
max_x - dest_x,
max_y - dest_y,
@ -237,7 +236,7 @@ pub trait BitmapImage {
let pix = self.pixel_mut(x as usize, y as usize);
let color: Color = LinSrgba::from_components((red, green, blue, alpha * value)).into();
*pix = color.composite(Color(*pix), &operator).0;
*pix = color.composite(Color(*pix), operator).0;
}
}
@ -308,7 +307,7 @@ pub trait BitmapImage {
dest_y as usize,
);
for (src_pix, dest_pix) in src_pixels.iter().zip(dest_pixels.iter_mut()) {
*dest_pix = Color(*src_pix).composite(Color(*dest_pix), &operator).0;
*dest_pix = Color(*src_pix).composite(Color(*dest_pix), operator).0;
}
}
}
@ -333,7 +332,7 @@ impl Image {
/// The buffer is initialized to all zeroes.
pub fn new(width: usize, height: usize) -> Image {
let size = height * width * 4;
let mut data = Vec::with_capacity(size);
let mut data = vec![0; size];
data.resize(size, 0);
Image {
data,
@ -349,6 +348,7 @@ impl Image {
for y in 0..height {
let src_offset = y * stride;
let dest_offset = y * width * 4;
#[allow(clippy::identity_op)]
for x in 0..width {
let blue = data[src_offset + (x * 3) + 0];
let green = data[src_offset + (x * 3) + 1];
@ -370,6 +370,7 @@ impl Image {
for y in 0..height {
let src_offset = y * stride;
let dest_offset = y * width * 4;
#[allow(clippy::identity_op)]
for x in 0..width {
let blue = data[src_offset + (x * 4) + 0];
let green = data[src_offset + (x * 4) + 1];
@ -391,6 +392,7 @@ impl Image {
for y in 0..height {
let src_offset = y * stride;
let dest_offset = y * width * 4;
#[allow(clippy::identity_op)]
for x in 0..width {
let red = data[src_offset + (x * 4) + 0];
let green = data[src_offset + (x * 4) + 1];
@ -410,6 +412,7 @@ impl Image {
for y in 0..height {
let src_offset = y * stride;
let dest_offset = y * width * 4;
#[allow(clippy::identity_op)]
for x in 0..width {
let gray = data[src_offset + x];
image.data[dest_offset + (x * 4) + 0] = gray;

View File

@ -8,18 +8,18 @@ lazy_static::lazy_static! {
fn generate_srgb8_to_linear_f32_table() -> [f32; 256] {
let mut table = [0.; 256];
for val in 0..256 {
for (val, entry) in table.iter_mut().enumerate() {
let c = (val as f32) / 255.0;
let f = if c < 0.04045 {
*entry = if c < 0.04045 {
c / 12.92
} else {
((c + 0.055) / 1.055).powf(2.4)
};
table[val] = f;
}
table
}
#[allow(clippy::unreadable_literal)]
fn generate_linear_f32_to_srgb8_table() -> [u32; 104] {
// My intent was to generate this array on the fly using the code that is commented
// out below. It is based on this gist:
@ -107,7 +107,9 @@ fn linear_f32_to_srgbf32(f: f32) -> f32 {
}
*/
#[allow(clippy::unreadable_literal)]
const ALMOST_ONE: u32 = 0x3f7fffff;
#[allow(clippy::unreadable_literal)]
const MINVAL: u32 = (127 - 13) << 23;
fn linear_f32_to_srgb8_using_table(f: f32) -> u8 {
@ -133,6 +135,7 @@ fn linear_f32_to_srgb8_using_table(f: f32) -> u8 {
}
#[cfg(target_arch = "x86_64")]
#[allow(clippy::unreadable_literal)]
fn linear_f32_to_srgb8_vec(s: LinSrgba) -> Color {
use std::arch::x86_64::*;
@ -189,6 +192,7 @@ pub struct Color(pub u32);
impl From<LinSrgba> for Color {
#[inline]
#[allow(clippy::many_single_char_names)]
fn from(s: LinSrgba) -> Color {
if is_x86_feature_detected!("sse2") {
linear_f32_to_srgb8_vec(s)
@ -271,12 +275,13 @@ impl Color {
#[inline]
pub fn rgba(red: u8, green: u8, blue: u8, alpha: u8) -> Color {
#[allow(clippy::cast_lossless)]
let word = (blue as u32) << 24 | (green as u32) << 16 | (red as u32) << 8 | alpha as u32;
Color(word.to_be())
}
#[inline]
pub fn as_rgba(&self) -> (u8, u8, u8, u8) {
pub fn as_rgba(self) -> (u8, u8, u8, u8) {
let host = u32::from_be(self.0);
(
(host >> 8) as u8,
@ -289,23 +294,23 @@ impl Color {
/// Compute the composite of two colors according to the supplied operator.
/// self is the src operand, dest is the dest operand.
#[inline]
pub fn composite(&self, dest: Color, operator: &Operator) -> Color {
pub fn composite(self, dest: Color, operator: Operator) -> Color {
match operator {
&Operator::Over => {
let src: LinSrgba = (*self).into();
Operator::Over => {
let src: LinSrgba = self.into();
let dest: LinSrgba = dest.into();
src.over(dest).into()
}
&Operator::Source => *self,
&Operator::Multiply => {
let src: LinSrgba = (*self).into();
Operator::Source => self,
Operator::Multiply => {
let src: LinSrgba = self.into();
let dest: LinSrgba = dest.into();
let result: Color = src.multiply(dest).into();
result
}
&Operator::MultiplyThenOver(ref tint) => {
Operator::MultiplyThenOver(ref tint) => {
// First multiply by the tint color. This colorizes the glyph.
let src: LinSrgba = (*self).into();
let src: LinSrgba = self.into();
let tint: LinSrgba = (*tint).into();
let mut tinted = src.multiply(tint);
// We take the alpha from the source. This is important because

View File

@ -97,6 +97,7 @@ bitflags! {
#[derive(Default)]
pub struct MouseButtons: u8 {
const NONE = 0;
#[allow(clippy::identity_op)]
const LEFT = 1<<0;
const RIGHT = 1<<1;
const MIDDLE = 1<<2;

View File

@ -1,3 +1,6 @@
// let () = msg_send! is a common pattern for objc
#![allow(clippy::let_unit_value)]
use super::window::WindowInner;
use crate::connection::ConnectionOps;
use crate::spawn::*;
@ -95,7 +98,7 @@ impl ConnectionOps for Connection {
fn schedule_timer<F: FnMut() + 'static>(&self, interval: std::time::Duration, callback: F) {
let secs_f64 =
(interval.as_secs() as f64) + (interval.subsec_nanos() as f64 / 1_000_000_000_f64);
(interval.as_secs() as f64) + (f64::from(interval.subsec_nanos()) / 1_000_000_000_f64);
let callback = Box::into_raw(Box::new(callback));
@ -110,7 +113,7 @@ impl ConnectionOps for Connection {
}
extern "C" fn release_callback<F: FnMut()>(info: *const std::ffi::c_void) {
let callback: Box<F> = unsafe { Box::from_raw(std::mem::transmute(info)) };
let callback: Box<F> = unsafe { Box::from_raw(info as *mut F) };
drop(callback);
}

View File

@ -1,3 +1,6 @@
// let () = msg_send! is a common pattern for objc
#![allow(clippy::let_unit_value)]
use super::{nsstring, nsstring_to_str};
use crate::bitmaps::Image;
use crate::connection::ConnectionOps;
@ -256,6 +259,7 @@ impl<'a> PaintContext for MacGraphicsContext<'a> {
}
}
#[allow(clippy::identity_op)]
fn decode_mouse_buttons(mask: u64) -> MouseButtons {
let mut buttons = MouseButtons::NONE;
@ -507,7 +511,7 @@ impl WindowView {
inner.callbacks.paint(&mut ctx);
let cg_image = BitmapRef::with_image(&mut *buffer);
let cg_image = BitmapRef::with_image(&*buffer);
fn nsimage_from_cgimage(cg: &CGImageRef, size: NSSize) -> StrongPtr {
unsafe {

View File

@ -72,7 +72,7 @@ static VTBL: RawWakerVTable = RawWakerVTable::new(
impl TaskWaker {
fn new_waker(slot: usize) -> Waker {
let raw = RawWaker::new(unsafe { std::mem::transmute(slot) }, &VTBL);
let raw = RawWaker::new(slot as *const (), &VTBL);
unsafe { Waker::from_raw(raw) }
}