From 88ef8baaf5bb2db7b6ad28d04ee1d74668cca6f5 Mon Sep 17 00:00:00 2001 From: Kaur Kuut Date: Mon, 11 May 2020 16:25:04 +0300 Subject: [PATCH] Move HWND render target creation to WM_CREATE. --- CHANGELOG.md | 2 ++ druid-shell/src/platform/windows/window.rs | 25 +++++++++++++--------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ad67de9eb4..25f9abc6c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -102,6 +102,7 @@ This means that druid no longer requires cairo on macOS and uses Core Graphics i - GTK: Support file filters in open/save dialogs. ([#903] by [@jneem]) - GTK: Support DPI values other than 96. ([#904] by [@xStrom]) - Windows: Removed flashes of white background at the edge of the window when resizing. ([#915] by [@xStrom]) +- Windows: Reduced chance of white flash when opening a new window. ([#916] by [@xStrom]) - X11: Support key and mouse button state. ([#920] by [@jneem]) - Routing `LifeCycle::FocusChanged` to descendant widgets. ([#925] by [@yrns]) - Built-in open and save menu items now show the correct label and submit the right commands. ([#930] by [@finnerale]) @@ -201,6 +202,7 @@ This means that druid no longer requires cairo on macOS and uses Core Graphics i [#905]: https://github.com/xi-editor/druid/pull/905 [#909]: https://github.com/xi-editor/druid/pull/909 [#915]: https://github.com/xi-editor/druid/pull/915 +[#916]: https://github.com/xi-editor/druid/pull/916 [#917]: https://github.com/xi-editor/druid/pull/917 [#920]: https://github.com/xi-editor/druid/pull/920 [#924]: https://github.com/xi-editor/druid/pull/924 diff --git a/druid-shell/src/platform/windows/window.rs b/druid-shell/src/platform/windows/window.rs index 23854ef19c..5843d0e799 100644 --- a/druid-shell/src/platform/windows/window.rs +++ b/druid-shell/src/platform/windows/window.rs @@ -422,22 +422,27 @@ impl WndProc for MyWndProc { //println!("wndproc msg: {}", msg); match msg { WM_CREATE => { - let dcomp_state = unsafe { - create_dcomp_state(self.present_strategy, hwnd).unwrap_or_else(|e| { - warn!("Creating swapchain failed, falling back to hwnd: {:?}", e); - None - }) - }; - - self.state.borrow_mut().as_mut().unwrap().dcomp_state = dcomp_state; if let Some(state) = self.handle.borrow().state.upgrade() { state.hwnd.set(hwnd); } - let handle = self.handle.borrow().to_owned(); if let Some(state) = self.state.borrow_mut().as_mut() { + let dcomp_state = unsafe { + create_dcomp_state(self.present_strategy, hwnd).unwrap_or_else(|e| { + warn!("Creating swapchain failed, falling back to hwnd: {:?}", e); + None + }) + }; + if dcomp_state.is_none() { + unsafe { + let rt = paint::create_render_target(&self.d2d_factory, hwnd); + state.render_target = rt.ok(); + } + } + state.dcomp_state = dcomp_state; + + let handle = self.handle.borrow().to_owned(); state.handler.connect(&handle.into()); } - Some(0) } WM_ERASEBKGND => Some(0),