From 0ef89f3de068053c9bd4f2fd2238fa8d66b01f37 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sun, 17 Jan 2021 10:29:49 -0800 Subject: [PATCH] window: remove some dead code on Windows Since removing non-GL usage, this code is dead. --- window/src/os/windows/gdi.rs | 120 -------------------------------- window/src/os/windows/mod.rs | 2 - window/src/os/windows/window.rs | 10 +-- 3 files changed, 3 insertions(+), 129 deletions(-) delete mode 100644 window/src/os/windows/gdi.rs diff --git a/window/src/os/windows/gdi.rs b/window/src/os/windows/gdi.rs deleted file mode 100644 index 38c1e2a76..000000000 --- a/window/src/os/windows/gdi.rs +++ /dev/null @@ -1,120 +0,0 @@ -use crate::bitmaps::BitmapImage; -use anyhow::bail; -use std::io::Error as IoError; -use winapi::shared::windef::*; -use winapi::um::wingdi::*; - -pub struct GdiBitmap { - hdc: HDC, - hbitmap: HBITMAP, - data: *mut u8, - width: usize, - height: usize, -} - -impl BitmapImage for GdiBitmap { - unsafe fn pixel_data(&self) -> *const u8 { - self.data - } - - unsafe fn pixel_data_mut(&mut self) -> *mut u8 { - self.data - } - - fn image_dimensions(&self) -> (usize, usize) { - (self.width, self.height) - } -} - -impl Drop for GdiBitmap { - fn drop(&mut self) { - unsafe { - DeleteObject(self.hbitmap as _); - } - unsafe { - DeleteObject(self.hdc as _); - } - } -} - -impl GdiBitmap { - pub fn hdc(&self) -> HDC { - self.hdc - } - - pub fn hbitmap(&self) -> HBITMAP { - self.hbitmap - } - - /// A helper for initializing a window - pub(crate) fn new_empty() -> Self { - Self { - hdc: std::ptr::null_mut(), - hbitmap: std::ptr::null_mut(), - data: std::ptr::null_mut(), - width: 0, - height: 0, - } - } - - pub fn new_compatible(width: usize, height: usize, hdc: HDC) -> anyhow::Result { - let hdc = unsafe { CreateCompatibleDC(hdc) }; - if hdc.is_null() { - let err = IoError::last_os_error(); - bail!("CreateCompatibleDC: {}", err); - } - - let mut data = std::ptr::null_mut(); - let bmi = BITMAPINFO { - bmiHeader: BITMAPINFOHEADER { - biSize: std::mem::size_of::() as u32, - biPlanes: 1, - biBitCount: 32, - biWidth: width as i32, - // Windows bitmaps are upside-down vs. the rest of the world, so - // we need to supply a negative height here: - // https://stackoverflow.com/a/9023702/149111 - biHeight: -(height as i32), - biClrImportant: 0, - biClrUsed: 0, - biCompression: 0, - biSizeImage: width as u32 * height as u32 * 4, - biXPelsPerMeter: 0, - biYPelsPerMeter: 0, - }, - bmiColors: [RGBQUAD { - rgbBlue: 0, - rgbRed: 0, - rgbGreen: 0, - rgbReserved: 0, - }], - }; - let hbitmap = unsafe { - CreateDIBSection( - hdc, - &bmi, - DIB_RGB_COLORS, - &mut data, - std::ptr::null_mut(), - 0, - ) - }; - - if hbitmap.is_null() { - let err = IoError::last_os_error(); - bail!("CreateDIBSection: {}", err); - } - - unsafe { - SelectObject(hdc, hbitmap as _); - } - - Ok(Self { - hdc, - hbitmap, - data: data as *mut u8, - width, - height, - }) - } -} diff --git a/window/src/os/windows/mod.rs b/window/src/os/windows/mod.rs index 9b72fe642..4e2921683 100644 --- a/window/src/os/windows/mod.rs +++ b/window/src/os/windows/mod.rs @@ -1,13 +1,11 @@ pub mod connection; pub mod event; -pub mod gdi; mod wgl; pub mod window; pub use self::window::*; pub use connection::*; pub use event::*; -pub use gdi::*; /// Convert a rust string to a windows wide string fn wide_string(s: &str) -> Vec { diff --git a/window/src/os/windows/window.rs b/window/src/os/windows/window.rs index 87e1f4c0f..e01037d38 100644 --- a/window/src/os/windows/window.rs +++ b/window/src/os/windows/window.rs @@ -1,12 +1,9 @@ -use super::gdi::*; use super::*; -use crate::bitmaps::*; -use crate::color::Color; use crate::connection::ConnectionOps; use crate::{ config, Clipboard, Dimensions, KeyCode, KeyEvent, Modifiers, MouseButtons, MouseCursor, - MouseEvent, MouseEventKind, MousePress, Operator, Point, Rect, ScreenPoint, WindowCallbacks, - WindowOps, WindowOpsMut, + MouseEvent, MouseEventKind, MousePress, Point, Rect, ScreenPoint, WindowCallbacks, WindowOps, + WindowOpsMut, }; use anyhow::{bail, Context}; use lazy_static::lazy_static; @@ -26,7 +23,6 @@ use winapi::shared::ntdef::*; use winapi::shared::windef::*; use winapi::um::imm::*; use winapi::um::libloaderapi::GetModuleHandleW; -use winapi::um::wingdi::*; use winapi::um::winuser::*; use winreg::{enums::HKEY_CURRENT_USER, RegKey}; @@ -718,7 +714,7 @@ unsafe fn wm_paint(hwnd: HWND, _msg: UINT, _wparam: WPARAM, _lparam: LPARAM) -> }, rgbReserved: [0; 32], }; - let dc = BeginPaint(hwnd, &mut ps); + let _ = BeginPaint(hwnd, &mut ps); let mut rect = RECT { left: 0,