Skip to content

Commit 4a145bf

Browse files
committed
WPF ByteArrayWritableBitmapRenderHandler - Remove base class
AbstractRenderHandler - change pixel properties to internal so they can be shared ByteArrayWritableBitmapRenderHandler WritableBitmapRenderHandler - run Format Document (changed fields to read only) Follow up to #2652
1 parent 5c292cd commit 4a145bf

File tree

3 files changed

+37
-14
lines changed

3 files changed

+37
-14
lines changed

CefSharp.Wpf/Rendering/AbstractRenderHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ public abstract class AbstractRenderHandler : IDisposable, IRenderHandler
2323
[DllImport("kernel32.dll", EntryPoint = "CopyMemory", SetLastError = false)]
2424
protected static extern void CopyMemory(IntPtr dest, IntPtr src, uint count);
2525

26-
protected static readonly PixelFormat PixelFormat = PixelFormats.Pbgra32;
27-
protected static int BytesPerPixel = PixelFormat.BitsPerPixel / 8;
26+
internal static readonly PixelFormat PixelFormat = PixelFormats.Pbgra32;
27+
internal static int BytesPerPixel = PixelFormat.BitsPerPixel / 8;
2828

2929
protected object lockObject = new object();
3030

CefSharp.Wpf/Rendering/Experimental/ByteArrayWritableBitmapRenderHandler.cs

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
44

55
using System;
6-
using System.IO.MemoryMappedFiles;
76
using System.Runtime.InteropServices;
87
using System.Windows;
98
using System.Windows.Controls;
109
using System.Windows.Media.Imaging;
1110
using System.Windows.Threading;
11+
1212
using Rect = CefSharp.Structs.Rect;
1313

1414
namespace CefSharp.Wpf.Rendering.Experimental
@@ -20,11 +20,12 @@ namespace CefSharp.Wpf.Rendering.Experimental
2020
/// wise.
2121
/// </summary>
2222
/// <seealso cref="CefSharp.Wpf.IRenderHandler" />
23-
public class ByteArrayWritableBitmapRenderHandler : AbstractRenderHandler
23+
public class ByteArrayWritableBitmapRenderHandler : IRenderHandler
2424
{
25-
private double dpiX;
26-
private double dpiY;
27-
private bool invalidateDirtyRect;
25+
private readonly double dpiX;
26+
private readonly double dpiY;
27+
private readonly bool invalidateDirtyRect;
28+
private readonly DispatcherPriority dispatcherPriority;
2829

2930
/// <summary>
3031
/// Initializes a new instance of the <see cref="WritableBitmapRenderHandler"/> class.
@@ -41,11 +42,28 @@ public ByteArrayWritableBitmapRenderHandler(double dpiX, double dpiY, bool inval
4142
this.dispatcherPriority = dispatcherPriority;
4243
}
4344

44-
protected override void CreateOrUpdateBitmap(bool isPopup, Rect dirtyRect, IntPtr buffer, int width, int height, Image image, ref Size currentSize, ref MemoryMappedFile mappedFile, ref MemoryMappedViewAccessor viewAccessor)
45+
/// <summary>
46+
/// Called when an element has been rendered to the shared texture handle.
47+
/// This method is only called when <see cref="IWindowInfo.SharedTextureEnabled"/> is set to true
48+
/// </summary>
49+
/// <param name="isPopup">indicates whether the element is the view or the popup widget.</param>
50+
/// <param name="dirtyRect">contains the set of rectangles in pixel coordinates that need to be repainted</param>
51+
/// <param name="sharedHandle">is the handle for a D3D11 Texture2D that can be accessed via ID3D11Device using the OpenSharedResource method.</param>
52+
void IRenderHandler.OnAcceleratedPaint(bool isPopup, Rect dirtyRect, IntPtr sharedHandle)
53+
{
54+
//NOT USED
55+
}
56+
57+
void IRenderHandler.OnPaint(bool isPopup, Rect dirtyRect, IntPtr buffer, int width, int height, Image image)
4558
{
59+
if (image.Dispatcher.HasShutdownStarted)
60+
{
61+
return;
62+
}
63+
4664
int pixels = width * height;
47-
int numberOfBytes = pixels * BytesPerPixel;
48-
var stride = width * BytesPerPixel;
65+
int numberOfBytes = pixels * AbstractRenderHandler.BytesPerPixel;
66+
var stride = width * AbstractRenderHandler.BytesPerPixel;
4967
var tempBuffer = new byte[numberOfBytes];
5068

5169
//Copy unmanaged memory to our buffer
@@ -63,7 +81,7 @@ protected override void CreateOrUpdateBitmap(bool isPopup, Rect dirtyRect, IntPt
6381
GC.Collect(1);
6482
}
6583

66-
image.Source = bitmap = new WriteableBitmap(width, height, dpiX, dpiY, PixelFormat, null);
84+
image.Source = bitmap = new WriteableBitmap(width, height, dpiX, dpiY, AbstractRenderHandler.PixelFormat, null);
6785
}
6886

6987
//Get a ptr to our temp buffer
@@ -92,5 +110,10 @@ protected override void CreateOrUpdateBitmap(bool isPopup, Rect dirtyRect, IntPt
92110
}
93111
}), dispatcherPriority);
94112
}
113+
114+
void IDisposable.Dispose()
115+
{
116+
117+
}
95118
}
96119
}

CefSharp.Wpf/Rendering/WritableBitmapRenderHandler.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ namespace CefSharp.Wpf.Rendering
2020
/// <seealso cref="CefSharp.Wpf.IRenderHandler" />
2121
public class WritableBitmapRenderHandler : AbstractRenderHandler
2222
{
23-
private double dpiX;
24-
private double dpiY;
25-
private bool invalidateDirtyRect;
23+
private readonly double dpiX;
24+
private readonly double dpiY;
25+
private readonly bool invalidateDirtyRect;
2626

2727
/// <summary>
2828
/// Initializes a new instance of the <see cref="WritableBitmapRenderHandler"/> class.

0 commit comments

Comments
 (0)