Move BytesPerPixel to BitmapInfo - simplifies code

This commit is contained in:
amaitland
2014-12-16 23:41:11 +10:00
parent 33b0e4710e
commit 85c44f7754
5 changed files with 10 additions and 23 deletions
@@ -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 ||
+3 -7
View File
@@ -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));
+4 -13
View File
@@ -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);
+2
View File
@@ -17,6 +17,8 @@ namespace CefSharp.Internals
public IntPtr FileMappingHandle { get; set; }
public int BytesPerPixel { get; set; }
public abstract void ClearBitmap();
protected BitmapInfo()
-2
View File
@@ -8,8 +8,6 @@ namespace CefSharp.Internals
{
public interface IRenderWebBrowser : IWebBrowserInternal
{
int BytesPerPixel { get; }
int Width { get; }
int Height { get; }