crates/gpui/src/platform.rs 🔗
@@ -13,7 +13,6 @@ mod mac;
any(target_os = "linux", target_os = "freebsd"),
any(feature = "x11", feature = "wayland")
),
- target_os = "windows",
feature = "macos-blade"
))]
mod blade;
Junkui Zhang created
crates/gpui/src/platform.rs | 1
crates/gpui/src/platform/windows/directx_atlas.rs | 40 +++++-------
crates/gpui/src/platform/windows/platform.rs | 2
crates/gpui/src/platform/windows/window.rs | 53 ----------------
4 files changed, 18 insertions(+), 78 deletions(-)
@@ -13,7 +13,6 @@ mod mac;
any(target_os = "linux", target_os = "freebsd"),
any(feature = "x11", feature = "wayland")
),
- target_os = "windows",
feature = "macos-blade"
))]
mod blade;
@@ -12,7 +12,7 @@ use windows::Win32::Graphics::{
use crate::{
AtlasKey, AtlasTextureId, AtlasTextureKind, AtlasTile, Bounds, DevicePixels, PlatformAtlas,
- Size, platform::AtlasTextureList,
+ Point, Size, platform::AtlasTextureList,
};
pub(crate) struct DirectXAtlas(Mutex<DirectXAtlasState>);
@@ -53,25 +53,6 @@ impl DirectXAtlas {
let tex = lock.texture(id);
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 {
@@ -249,10 +230,6 @@ impl DirectXAtlasState {
}
impl DirectXAtlasTexture {
- fn clear(&mut self) {
- self.allocator.clear();
- }
-
fn allocate(&mut self, size: Size<DevicePixels>) -> Option<AtlasTile> {
let allocation = self.allocator.allocate(size.into())?;
let tile = AtlasTile {
@@ -301,3 +278,18 @@ impl DirectXAtlasTexture {
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::*,
};
-use crate::{platform::blade::BladeContext, *};
+use crate::*;
pub(crate) struct WindowsPlatform {
state: RefCell<WindowsPlatformState>,
@@ -26,7 +26,6 @@ use windows::{
core::*,
};
-use crate::platform::blade::{BladeContext, BladeRenderer};
use crate::*;
pub(crate) struct WindowsWindow(pub Rc<WindowsWindowStatePtr>);
@@ -102,9 +101,7 @@ impl WindowsWindowState {
};
let border_offset = WindowBorderOffset::default();
let restore_from_minimized = None;
- // let renderer = windows_renderer::init(gpu_context, hwnd, transparent)?;
let renderer = DirectXRenderer::new(gpu_context, hwnd)?;
- println!("GPU specs: {:#?}", renderer.gpu_specs());
let callbacks = Callbacks::default();
let input_handler = None;
let pending_surrogate = None;
@@ -796,9 +793,7 @@ impl PlatformWindow for WindowsWindow {
}
fn gpu_specs(&self) -> Option<GpuSpecs> {
- // todo(zjk)
- // Some(self.0.state.borrow().renderer.gpu_specs())
- None
+ self.0.state.borrow().renderer.gpu_specs().log_err()
}
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)]
mod tests {
use super::ClickState;