Skip to content

Commit c311a58

Browse files
kpreisseramaitland
authored andcommitted
WPF - Modify CopyMemory EntryPoint to work with .Net Core (#2885)
* Fix the entrypoint declaration for CopyMemory. Contributes to #2796 * Follow-Up: Switch to RtlCopyMemory which is faster, but requires that the buffers do not overlap.
1 parent f088a7c commit c311a58

File tree

4 files changed

+6
-5
lines changed

4 files changed

+6
-5
lines changed

CefSharp.Wpf/Rendering/AbstractRenderHandler.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ namespace CefSharp.Wpf.Rendering
2020
/// <seealso cref="CefSharp.Wpf.IRenderHandler" />
2121
public abstract class AbstractRenderHandler : IDisposable, IRenderHandler
2222
{
23-
[DllImport("kernel32.dll", EntryPoint = "CopyMemory", SetLastError = false)]
24-
protected static extern void CopyMemory(IntPtr dest, IntPtr src, uint count);
23+
// Note: In contrast to RtlMoveMemory, RtlCopyMemory requires that the buffers do not overlap.
24+
[DllImport("kernel32.dll", EntryPoint = "RtlCopyMemory", SetLastError = false)]
25+
protected static extern void CopyMemory(IntPtr dest, IntPtr src, UIntPtr count);
2526

2627
internal static readonly PixelFormat PixelFormat = PixelFormats.Pbgra32;
2728
internal static int BytesPerPixel = PixelFormat.BitsPerPixel / 8;

CefSharp.Wpf/Rendering/Experimental/IncreaseBufferInteropRenderHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ protected override void CreateOrUpdateBitmap(bool isPopup, Rect dirtyRect, IntPt
6060

6161
//TODO: Performance analysis to determine which is the fastest memory copy function
6262
//NativeMethodWrapper.CopyMemoryUsingHandle(viewAccessor.SafeMemoryMappedViewHandle.DangerousGetHandle(), buffer, numberOfBytes);
63-
CopyMemory(viewAccessor.SafeMemoryMappedViewHandle.DangerousGetHandle(), buffer, (uint)numberOfBytes);
63+
CopyMemory(viewAccessor.SafeMemoryMappedViewHandle.DangerousGetHandle(), buffer, (UIntPtr)(uint)numberOfBytes);
6464

6565
//Take a reference to the backBufferHandle, once we're on the UI thread we need to check if it's still valid
6666
var backBufferHandle = mappedFile.SafeMemoryMappedFileHandle;

CefSharp.Wpf/Rendering/InteropBitmapRenderHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ protected override void CreateOrUpdateBitmap(bool isPopup, Rect dirtyRect, IntPt
5454

5555
//TODO: Performance analysis to determine which is the fastest memory copy function
5656
//NativeMethodWrapper.CopyMemoryUsingHandle(viewAccessor.SafeMemoryMappedViewHandle.DangerousGetHandle(), buffer, numberOfBytes);
57-
CopyMemory(viewAccessor.SafeMemoryMappedViewHandle.DangerousGetHandle(), buffer, (uint)numberOfBytes);
57+
CopyMemory(viewAccessor.SafeMemoryMappedViewHandle.DangerousGetHandle(), buffer, (UIntPtr)(uint)numberOfBytes);
5858

5959
//Take a reference to the backBufferHandle, once we're on the UI thread we need to check if it's still valid
6060
var backBufferHandle = mappedFile.SafeMemoryMappedFileHandle;

CefSharp.Wpf/Rendering/WritableBitmapRenderHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ protected override void CreateOrUpdateBitmap(bool isPopup, Rect dirtyRect, IntPt
6464

6565
//TODO: Performance analysis to determine which is the fastest memory copy function
6666
//NativeMethodWrapper.CopyMemoryUsingHandle(viewAccessor.SafeMemoryMappedViewHandle.DangerousGetHandle(), buffer, numberOfBytes);
67-
CopyMemory(viewAccessor.SafeMemoryMappedViewHandle.DangerousGetHandle(), buffer, (uint)numberOfBytes);
67+
CopyMemory(viewAccessor.SafeMemoryMappedViewHandle.DangerousGetHandle(), buffer, (UIntPtr)(uint)numberOfBytes);
6868

6969
//Take a reference to the sourceBuffer that's used to update our WritableBitmap,
7070
//once we're on the UI thread we need to check if it's still valid

0 commit comments

Comments
 (0)