From b24efd2853e49c9d9237c319aeeb6ccdad5cbf15 Mon Sep 17 00:00:00 2001 From: amaitland Date: Fri, 30 Oct 2020 14:28:01 +1000 Subject: [PATCH] WPF - Resize Glitches (Image glitches during resize) - WritableBitmapRenderHandler/InteropBitmapRenderHandler ignore update if size doesn't match It's possible that OnPaint is called multiple times before our BeginInvoke call is marshalled onto the UI Thread. In those cases we check width/height and ignore the call if it doesn't match Issue #3114 --- CefSharp.Wpf/Rendering/InteropBitmapRenderHandler.cs | 12 ++++++++++++ .../Rendering/WritableBitmapRenderHandler.cs | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/CefSharp.Wpf/Rendering/InteropBitmapRenderHandler.cs b/CefSharp.Wpf/Rendering/InteropBitmapRenderHandler.cs index 4b4128ac1..57130c317 100644 --- a/CefSharp.Wpf/Rendering/InteropBitmapRenderHandler.cs +++ b/CefSharp.Wpf/Rendering/InteropBitmapRenderHandler.cs @@ -67,6 +67,18 @@ namespace CefSharp.Wpf.Rendering return; } + var size = isPopup ? popupSize : viewSize; + + //If OnPaint is called multiple times before + //our BeginInvoke call we check the size matches our most recent + //update, the buffer has already been overriden (frame is dropped effectively) + //so we ignore this call + //https://github.com/cefsharp/CefSharp/issues/3114 + if (size.Width != width || size.Height != height) + { + return; + } + if (createNewBitmap) { if (image.Source != null) diff --git a/CefSharp.Wpf/Rendering/WritableBitmapRenderHandler.cs b/CefSharp.Wpf/Rendering/WritableBitmapRenderHandler.cs index bc0253ccf..2efe77c1e 100644 --- a/CefSharp.Wpf/Rendering/WritableBitmapRenderHandler.cs +++ b/CefSharp.Wpf/Rendering/WritableBitmapRenderHandler.cs @@ -83,6 +83,18 @@ namespace CefSharp.Wpf.Rendering return; } + var size = isPopup ? popupSize : viewSize; + + //If OnPaint is called multiple times before + //our BeginInvoke call we check the size matches our most recent + //update, the buffer has already been overriden (frame is dropped effectively) + //so we ignore this call + //https://github.com/cefsharp/CefSharp/issues/3114 + if (size.Width != width || size.Height != height) + { + return; + } + if (createNewBitmap) { if (image.Source != null)