cleanup
This commit is contained in:
parent
4d936845f3
commit
78824390d0
4 changed files with 18 additions and 78 deletions
|
@ -13,7 +13,6 @@ mod mac;
|
||||||
any(target_os = "linux", target_os = "freebsd"),
|
any(target_os = "linux", target_os = "freebsd"),
|
||||||
any(feature = "x11", feature = "wayland")
|
any(feature = "x11", feature = "wayland")
|
||||||
),
|
),
|
||||||
target_os = "windows",
|
|
||||||
feature = "macos-blade"
|
feature = "macos-blade"
|
||||||
))]
|
))]
|
||||||
mod blade;
|
mod blade;
|
||||||
|
|
|
@ -12,7 +12,7 @@ use windows::Win32::Graphics::{
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
AtlasKey, AtlasTextureId, AtlasTextureKind, AtlasTile, Bounds, DevicePixels, PlatformAtlas,
|
AtlasKey, AtlasTextureId, AtlasTextureKind, AtlasTile, Bounds, DevicePixels, PlatformAtlas,
|
||||||
Size, platform::AtlasTextureList,
|
Point, Size, platform::AtlasTextureList,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub(crate) struct DirectXAtlas(Mutex<DirectXAtlasState>);
|
pub(crate) struct DirectXAtlas(Mutex<DirectXAtlasState>);
|
||||||
|
@ -53,25 +53,6 @@ impl DirectXAtlas {
|
||||||
let tex = lock.texture(id);
|
let tex = lock.texture(id);
|
||||||
tex.view.clone()
|
tex.view.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn allocate(
|
|
||||||
&self,
|
|
||||||
size: Size<DevicePixels>,
|
|
||||||
texture_kind: AtlasTextureKind,
|
|
||||||
) -> Option<AtlasTile> {
|
|
||||||
self.0.lock().allocate(size, texture_kind)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn clear_textures(&self, texture_kind: AtlasTextureKind) {
|
|
||||||
let mut lock = self.0.lock();
|
|
||||||
let textures = match texture_kind {
|
|
||||||
AtlasTextureKind::Monochrome => &mut lock.monochrome_textures,
|
|
||||||
AtlasTextureKind::Polychrome => &mut lock.polychrome_textures,
|
|
||||||
};
|
|
||||||
for texture in textures.iter_mut() {
|
|
||||||
texture.clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PlatformAtlas for DirectXAtlas {
|
impl PlatformAtlas for DirectXAtlas {
|
||||||
|
@ -249,10 +230,6 @@ impl DirectXAtlasState {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DirectXAtlasTexture {
|
impl DirectXAtlasTexture {
|
||||||
fn clear(&mut self) {
|
|
||||||
self.allocator.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn allocate(&mut self, size: Size<DevicePixels>) -> Option<AtlasTile> {
|
fn allocate(&mut self, size: Size<DevicePixels>) -> Option<AtlasTile> {
|
||||||
let allocation = self.allocator.allocate(size.into())?;
|
let allocation = self.allocator.allocate(size.into())?;
|
||||||
let tile = AtlasTile {
|
let tile = AtlasTile {
|
||||||
|
@ -301,3 +278,18 @@ impl DirectXAtlasTexture {
|
||||||
self.live_atlas_keys == 0
|
self.live_atlas_keys == 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<Size<DevicePixels>> for etagere::Size {
|
||||||
|
fn from(size: Size<DevicePixels>) -> Self {
|
||||||
|
etagere::Size::new(size.width.into(), size.height.into())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<etagere::Point> for Point<DevicePixels> {
|
||||||
|
fn from(value: etagere::Point) -> Self {
|
||||||
|
Point {
|
||||||
|
x: DevicePixels::from(value.x),
|
||||||
|
y: DevicePixels::from(value.y),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ use windows::{
|
||||||
core::*,
|
core::*,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{platform::blade::BladeContext, *};
|
use crate::*;
|
||||||
|
|
||||||
pub(crate) struct WindowsPlatform {
|
pub(crate) struct WindowsPlatform {
|
||||||
state: RefCell<WindowsPlatformState>,
|
state: RefCell<WindowsPlatformState>,
|
||||||
|
|
|
@ -26,7 +26,6 @@ use windows::{
|
||||||
core::*,
|
core::*,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::platform::blade::{BladeContext, BladeRenderer};
|
|
||||||
use crate::*;
|
use crate::*;
|
||||||
|
|
||||||
pub(crate) struct WindowsWindow(pub Rc<WindowsWindowStatePtr>);
|
pub(crate) struct WindowsWindow(pub Rc<WindowsWindowStatePtr>);
|
||||||
|
@ -102,9 +101,7 @@ impl WindowsWindowState {
|
||||||
};
|
};
|
||||||
let border_offset = WindowBorderOffset::default();
|
let border_offset = WindowBorderOffset::default();
|
||||||
let restore_from_minimized = None;
|
let restore_from_minimized = None;
|
||||||
// let renderer = windows_renderer::init(gpu_context, hwnd, transparent)?;
|
|
||||||
let renderer = DirectXRenderer::new(gpu_context, hwnd)?;
|
let renderer = DirectXRenderer::new(gpu_context, hwnd)?;
|
||||||
println!("GPU specs: {:#?}", renderer.gpu_specs());
|
|
||||||
let callbacks = Callbacks::default();
|
let callbacks = Callbacks::default();
|
||||||
let input_handler = None;
|
let input_handler = None;
|
||||||
let pending_surrogate = None;
|
let pending_surrogate = None;
|
||||||
|
@ -796,9 +793,7 @@ impl PlatformWindow for WindowsWindow {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn gpu_specs(&self) -> Option<GpuSpecs> {
|
fn gpu_specs(&self) -> Option<GpuSpecs> {
|
||||||
// todo(zjk)
|
self.0.state.borrow().renderer.gpu_specs().log_err()
|
||||||
// Some(self.0.state.borrow().renderer.gpu_specs())
|
|
||||||
None
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_ime_position(&self, _bounds: Bounds<ScaledPixels>) {
|
fn update_ime_position(&self, _bounds: Bounds<ScaledPixels>) {
|
||||||
|
@ -1298,52 +1293,6 @@ fn set_window_composition_attribute(hwnd: HWND, color: Option<Color>, state: u32
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mod windows_renderer {
|
|
||||||
use crate::platform::blade::{BladeContext, BladeRenderer, BladeSurfaceConfig};
|
|
||||||
use raw_window_handle as rwh;
|
|
||||||
use std::num::NonZeroIsize;
|
|
||||||
use windows::Win32::{Foundation::HWND, UI::WindowsAndMessaging::GWLP_HINSTANCE};
|
|
||||||
|
|
||||||
use crate::{get_window_long, show_error};
|
|
||||||
|
|
||||||
pub(super) fn init(
|
|
||||||
context: &BladeContext,
|
|
||||||
hwnd: HWND,
|
|
||||||
transparent: bool,
|
|
||||||
) -> anyhow::Result<BladeRenderer> {
|
|
||||||
let raw = RawWindow { hwnd };
|
|
||||||
let config = BladeSurfaceConfig {
|
|
||||||
size: Default::default(),
|
|
||||||
transparent,
|
|
||||||
};
|
|
||||||
BladeRenderer::new(context, &raw, config)
|
|
||||||
.inspect_err(|err| show_error("Failed to initialize BladeRenderer", err.to_string()))
|
|
||||||
}
|
|
||||||
|
|
||||||
struct RawWindow {
|
|
||||||
hwnd: HWND,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl rwh::HasWindowHandle for RawWindow {
|
|
||||||
fn window_handle(&self) -> Result<rwh::WindowHandle<'_>, rwh::HandleError> {
|
|
||||||
Ok(unsafe {
|
|
||||||
let hwnd = NonZeroIsize::new_unchecked(self.hwnd.0 as isize);
|
|
||||||
let mut handle = rwh::Win32WindowHandle::new(hwnd);
|
|
||||||
let hinstance = get_window_long(self.hwnd, GWLP_HINSTANCE);
|
|
||||||
handle.hinstance = NonZeroIsize::new(hinstance);
|
|
||||||
rwh::WindowHandle::borrow_raw(handle.into())
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl rwh::HasDisplayHandle for RawWindow {
|
|
||||||
fn display_handle(&self) -> Result<rwh::DisplayHandle<'_>, rwh::HandleError> {
|
|
||||||
let handle = rwh::WindowsDisplayHandle::new();
|
|
||||||
Ok(unsafe { rwh::DisplayHandle::borrow_raw(handle.into()) })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::ClickState;
|
use super::ClickState;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue