33// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
44
55using System ;
6- using System . IO . MemoryMappedFiles ;
76using System . Runtime . InteropServices ;
87using System . Windows ;
98using System . Windows . Controls ;
109using System . Windows . Media . Imaging ;
1110using System . Windows . Threading ;
11+
1212using Rect = CefSharp . Structs . Rect ;
1313
1414namespace 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}
0 commit comments