mirror of
https://github.com/cefsharp/CefSharp.git
synced 2026-12-05 11:42:36 +00:00
Move BytesPerPixel to BitmapInfo - simplifies code
This commit is contained in:
@@ -177,7 +177,7 @@ namespace CefSharp
|
||||
HANDLE* fileMappingHandle, HANDLE* backBufferHandle, const void* buffer)
|
||||
{
|
||||
int pixels = newWidth * newHeight;
|
||||
int numberOfBytes = pixels * _renderWebBrowser->BytesPerPixel;
|
||||
int numberOfBytes = pixels * bitmapInfo->BytesPerPixel;
|
||||
|
||||
if (*backBufferHandle == NULL ||
|
||||
bitmapInfo->Width != newWidth ||
|
||||
|
||||
@@ -347,11 +347,6 @@ namespace CefSharp.OffScreen
|
||||
}
|
||||
|
||||
#region IRenderWebBrowser (rendering to bitmap; derived from CefSharp.Wpf.ChromiumWebBrowser)
|
||||
/// <summary>The bitmap buffer is 32 BPP.</summary>
|
||||
int IRenderWebBrowser.BytesPerPixel
|
||||
{
|
||||
get { return 4; }
|
||||
}
|
||||
|
||||
int IRenderWebBrowser.Width
|
||||
{
|
||||
@@ -365,7 +360,8 @@ namespace CefSharp.OffScreen
|
||||
|
||||
public BitmapInfo CreateBitmapInfo(bool isPopup)
|
||||
{
|
||||
return new GdiBitmapInfo { IsPopup = isPopup };
|
||||
//The bitmap buffer is 32 BPP
|
||||
return new GdiBitmapInfo { IsPopup = isPopup, BytesPerPixel = 4 };
|
||||
}
|
||||
|
||||
void IRenderWebBrowser.InvokeRenderAsync(BitmapInfo bitmapInfo)
|
||||
@@ -380,7 +376,7 @@ namespace CefSharp.OffScreen
|
||||
|
||||
lock (bitmapInfo.BitmapLock)
|
||||
{
|
||||
var stride = bitmapInfo.Width * ((IRenderWebBrowser)this).BytesPerPixel;
|
||||
var stride = bitmapInfo.Width * bitmapInfo.BytesPerPixel;
|
||||
|
||||
bitmap = BitmapSourceToBitmap2(Imaging.CreateBitmapSourceFromMemorySection(bitmapInfo.FileMappingHandle,
|
||||
bitmapInfo.Width, bitmapInfo.Height, PixelFormats.Bgra32, stride, 0));
|
||||
|
||||
@@ -21,6 +21,8 @@ namespace CefSharp.Wpf
|
||||
{
|
||||
public class ChromiumWebBrowser : ContentControl, IRenderWebBrowser, IWpfWebBrowser
|
||||
{
|
||||
private static readonly PixelFormat PixelFormat = PixelFormats.Bgra32;
|
||||
private static readonly int BytesPerPixel = PixelFormat.BitsPerPixel / 8;
|
||||
private static readonly Key[] KeysToSendtoBrowser =
|
||||
{
|
||||
Key.Tab,
|
||||
@@ -118,11 +120,6 @@ namespace CefSharp.Wpf
|
||||
|
||||
#endregion
|
||||
|
||||
int IRenderWebBrowser.BytesPerPixel
|
||||
{
|
||||
get { return PixelFormat.BitsPerPixel / 8; }
|
||||
}
|
||||
|
||||
int IRenderWebBrowser.Width
|
||||
{
|
||||
get { return (int)matrix.Transform(new Point(ActualWidth, ActualHeight)).X; }
|
||||
@@ -133,11 +130,6 @@ namespace CefSharp.Wpf
|
||||
get { return (int)matrix.Transform(new Point(ActualWidth, ActualHeight)).Y; }
|
||||
}
|
||||
|
||||
private static PixelFormat PixelFormat
|
||||
{
|
||||
get { return PixelFormats.Bgra32; }
|
||||
}
|
||||
|
||||
#region Address dependency property
|
||||
|
||||
public string Address
|
||||
@@ -666,7 +658,7 @@ namespace CefSharp.Wpf
|
||||
|
||||
public BitmapInfo CreateBitmapInfo(bool isPopup)
|
||||
{
|
||||
return new InteropBitmapInfo { IsPopup = isPopup };
|
||||
return new InteropBitmapInfo { IsPopup = isPopup, BytesPerPixel = BytesPerPixel };
|
||||
}
|
||||
|
||||
void IRenderWebBrowser.InvokeRenderAsync(BitmapInfo bitmapInfo)
|
||||
@@ -687,8 +679,7 @@ namespace CefSharp.Wpf
|
||||
img.Source = null;
|
||||
GC.Collect(1);
|
||||
|
||||
var bytesPerPixel = ((IRenderWebBrowser)this).BytesPerPixel;
|
||||
var stride = bitmapInfo.Width * bytesPerPixel;
|
||||
var stride = bitmapInfo.Width * bitmapInfo.BytesPerPixel;
|
||||
|
||||
bitmap = (InteropBitmap)Imaging.CreateBitmapSourceFromMemorySection(bitmapInfo.FileMappingHandle,
|
||||
bitmapInfo.Width, bitmapInfo.Height, PixelFormat, stride, 0);
|
||||
|
||||
@@ -17,6 +17,8 @@ namespace CefSharp.Internals
|
||||
|
||||
public IntPtr FileMappingHandle { get; set; }
|
||||
|
||||
public int BytesPerPixel { get; set; }
|
||||
|
||||
public abstract void ClearBitmap();
|
||||
|
||||
protected BitmapInfo()
|
||||
|
||||
@@ -8,8 +8,6 @@ namespace CefSharp.Internals
|
||||
{
|
||||
public interface IRenderWebBrowser : IWebBrowserInternal
|
||||
{
|
||||
int BytesPerPixel { get; }
|
||||
|
||||
int Width { get; }
|
||||
int Height { get; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user