diff --git a/CefSharp.Core/NativeMethodWrapper.cpp b/CefSharp.Core/NativeMethodWrapper.cpp index 2606b5b8a..ef9612457 100644 --- a/CefSharp.Core/NativeMethodWrapper.cpp +++ b/CefSharp.Core/NativeMethodWrapper.cpp @@ -8,9 +8,9 @@ namespace CefSharp { - void NativeMethodWrapper::CopyMemoryUsingHandle(IntPtr dest, IntPtr src, int numberOfBytes) + void NativeMethodWrapper::MemoryCopy(IntPtr dest, IntPtr src, int numberOfBytes) { - CopyMemory(dest.ToPointer(), src.ToPointer(), numberOfBytes); + RtlCopyMemory(dest.ToPointer(), src.ToPointer(), numberOfBytes); } bool NativeMethodWrapper::IsFocused(IntPtr handle) diff --git a/CefSharp.Core/NativeMethodWrapper.h b/CefSharp.Core/NativeMethodWrapper.h index 9b20bd8f7..f31a1a8cc 100644 --- a/CefSharp.Core/NativeMethodWrapper.h +++ b/CefSharp.Core/NativeMethodWrapper.h @@ -11,9 +11,12 @@ namespace CefSharp public ref class NativeMethodWrapper sealed { public: - static void CopyMemoryUsingHandle(IntPtr dest, IntPtr src, int numberOfBytes); + //Method cannot be called CopyMemory/RtlCopyMemroy as that's a macro name + //Length is currently int, update if required to handle larger data structures + //(int is plenty big enough for our current use case) + static void MemoryCopy(IntPtr dest, IntPtr src, int numberOfBytes); static bool IsFocused(IntPtr handle); static void SetWindowPosition(IntPtr handle, int x, int y, int width, int height); static void SetWindowParent(IntPtr child, IntPtr newParent); }; -} \ No newline at end of file +} diff --git a/CefSharp.Wpf/Rendering/AbstractRenderHandler.cs b/CefSharp.Wpf/Rendering/AbstractRenderHandler.cs index 12ab0b43a..cf46230ad 100644 --- a/CefSharp.Wpf/Rendering/AbstractRenderHandler.cs +++ b/CefSharp.Wpf/Rendering/AbstractRenderHandler.cs @@ -4,7 +4,6 @@ using System; using System.IO.MemoryMappedFiles; -using System.Runtime.InteropServices; using System.Threading; using System.Windows; using System.Windows.Controls; @@ -20,10 +19,6 @@ namespace CefSharp.Wpf.Rendering /// public abstract class AbstractRenderHandler : IDisposable, IRenderHandler { - // Note: In contrast to RtlMoveMemory, RtlCopyMemory requires that the buffers do not overlap. - [DllImport("kernel32.dll", EntryPoint = "RtlCopyMemory", SetLastError = false)] - protected static extern void CopyMemory(IntPtr dest, IntPtr src, UIntPtr count); - internal static readonly PixelFormat PixelFormat = PixelFormats.Pbgra32; internal static int BytesPerPixel = PixelFormat.BitsPerPixel / 8; diff --git a/CefSharp.Wpf/Rendering/Experimental/IncreaseBufferInteropRenderHandler.cs b/CefSharp.Wpf/Rendering/Experimental/IncreaseBufferInteropRenderHandler.cs index 0d23bc97b..61f753437 100644 --- a/CefSharp.Wpf/Rendering/Experimental/IncreaseBufferInteropRenderHandler.cs +++ b/CefSharp.Wpf/Rendering/Experimental/IncreaseBufferInteropRenderHandler.cs @@ -58,9 +58,7 @@ namespace CefSharp.Wpf.Rendering.Experimental currentSize.Width = width; } - //TODO: Performance analysis to determine which is the fastest memory copy function - //NativeMethodWrapper.CopyMemoryUsingHandle(viewAccessor.SafeMemoryMappedViewHandle.DangerousGetHandle(), buffer, numberOfBytes); - CopyMemory(viewAccessor.SafeMemoryMappedViewHandle.DangerousGetHandle(), buffer, (UIntPtr)(uint)numberOfBytes); + NativeMethodWrapper.MemoryCopy(viewAccessor.SafeMemoryMappedViewHandle.DangerousGetHandle(), buffer, numberOfBytes); //Take a reference to the backBufferHandle, once we're on the UI thread we need to check if it's still valid var backBufferHandle = mappedFile.SafeMemoryMappedFileHandle; diff --git a/CefSharp.Wpf/Rendering/InteropBitmapRenderHandler.cs b/CefSharp.Wpf/Rendering/InteropBitmapRenderHandler.cs index 2801d9b20..4b4128ac1 100644 --- a/CefSharp.Wpf/Rendering/InteropBitmapRenderHandler.cs +++ b/CefSharp.Wpf/Rendering/InteropBitmapRenderHandler.cs @@ -52,9 +52,7 @@ namespace CefSharp.Wpf.Rendering currentSize.Width = width; } - //TODO: Performance analysis to determine which is the fastest memory copy function - //NativeMethodWrapper.CopyMemoryUsingHandle(viewAccessor.SafeMemoryMappedViewHandle.DangerousGetHandle(), buffer, numberOfBytes); - CopyMemory(viewAccessor.SafeMemoryMappedViewHandle.DangerousGetHandle(), buffer, (UIntPtr)(uint)numberOfBytes); + NativeMethodWrapper.MemoryCopy(viewAccessor.SafeMemoryMappedViewHandle.DangerousGetHandle(), buffer, numberOfBytes); //Take a reference to the backBufferHandle, once we're on the UI thread we need to check if it's still valid var backBufferHandle = mappedFile.SafeMemoryMappedFileHandle; diff --git a/CefSharp.Wpf/Rendering/WritableBitmapRenderHandler.cs b/CefSharp.Wpf/Rendering/WritableBitmapRenderHandler.cs index d4da4e401..239f5360b 100644 --- a/CefSharp.Wpf/Rendering/WritableBitmapRenderHandler.cs +++ b/CefSharp.Wpf/Rendering/WritableBitmapRenderHandler.cs @@ -62,9 +62,7 @@ namespace CefSharp.Wpf.Rendering currentSize.Width = width; } - //TODO: Performance analysis to determine which is the fastest memory copy function - //NativeMethodWrapper.CopyMemoryUsingHandle(viewAccessor.SafeMemoryMappedViewHandle.DangerousGetHandle(), buffer, numberOfBytes); - CopyMemory(viewAccessor.SafeMemoryMappedViewHandle.DangerousGetHandle(), buffer, (UIntPtr)(uint)numberOfBytes); + NativeMethodWrapper.MemoryCopy(viewAccessor.SafeMemoryMappedViewHandle.DangerousGetHandle(), buffer, numberOfBytes); //Take a reference to the sourceBuffer that's used to update our WritableBitmap, //once we're on the UI thread we need to check if it's still valid