Add IBitmapFactory so that different Rendering methods can be plugged in (potentially a .Net 4.5 InteropBitmapInfo can be created)

Move into Rendering namespace
This commit is contained in:
amaitland
2015-01-29 15:25:08 +10:00
parent 9a52f082de
commit bfec2c95b1
11 changed files with 58 additions and 32 deletions
@@ -94,14 +94,11 @@ namespace CefSharp
if(bitmapInfo->DirtyRectSupport)
{
auto rects = gcnew List<CefDirtyRect>(dirtyRects.size());
//NOTE: According to https://bitbucket.org/chromiumembedded/branches-2171-cef3/commits/ce984ddff3268a50cf9967487327e1257015b98c
// There is only one rect now that's a union of all dirty regions. API Still passes in a vector
for each(CefRect r in dirtyRects)
{
rects->Add(CefDirtyRect(r.x, r.y, r.width, r.height));
}
bitmapInfo->DirtyRects = rects;
CefRect r = dirtyRects.front();
bitmapInfo->DirtyRect = CefDirtyRect(r.x, r.y, r.width, r.height);
}
auto backBufferHandle = (HANDLE)bitmapInfo->BackBufferHandle;
+5 -3
View File
@@ -93,7 +93,7 @@
<ItemGroup>
<Compile Include="DelegateCommand.cs" />
<Compile Include="DisposableEventWrapper.cs" />
<Compile Include="InteropBitmapInfo.cs" />
<Compile Include="Rendering\InteropBitmapInfo.cs" />
<Compile Include="IWpfWebBrowser.cs" />
<Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType>
@@ -101,9 +101,10 @@
<AppDesigner Include="Properties\" />
<Compile Include="ChromiumWebBrowser.cs" />
<Compile Include="RenderingEventArgs.cs" />
<Compile Include="Rendering\BitmapFactory.cs" />
<Compile Include="WM.cs" />
<Compile Include="WpfBitmapInfo.cs" />
<Compile Include="WritableBitmapInfo.cs" />
<Compile Include="Rendering\WpfBitmapInfo.cs" />
<Compile Include="Rendering\WritableBitmapInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CefSharp.Core\CefSharp.Core.vcxproj">
@@ -115,6 +116,7 @@
<Name>CefSharp</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
+7 -2
View File
@@ -4,6 +4,7 @@
using System.Text;
using CefSharp.Internals;
using CefSharp.Wpf.Rendering;
using Microsoft.Win32.SafeHandles;
using System;
using System.Collections.Generic;
@@ -47,6 +48,7 @@ namespace CefSharp.Wpf
public IDragHandler DragHandler { get; set; }
public IResourceHandler ResourceHandler { get; set; }
public IGeolocationHandler GeolocationHandler { get; set; }
public IBitmapFactory BitmapFactory { get; set; }
public event EventHandler<ConsoleMessageEventArgs> ConsoleMessage;
public event EventHandler<StatusMessageEventArgs> StatusMessage;
@@ -635,8 +637,11 @@ namespace CefSharp.Wpf
public BitmapInfo CreateBitmapInfo(bool isPopup)
{
return new InteropBitmapInfo { IsPopup = isPopup };
//return new WritableBitmapInfo { IsPopup = isPopup };
if (BitmapFactory == null)
{
throw new Exception("BitmapFactory cannot be null");
}
return BitmapFactory.CreateBitmap(isPopup);
}
void IRenderWebBrowser.InvokeRenderAsync(BitmapInfo bitmapInfo)
+17
View File
@@ -0,0 +1,17 @@
// Copyright © 2010-2014 The CefSharp Authors. All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
using CefSharp.Internals;
namespace CefSharp.Wpf.Rendering
{
public class BitmapFactory : IBitmapFactory
{
public BitmapInfo CreateBitmap(bool isPopup)
{
//return new WritableBitmapInfo { IsPopup = isPopup };
return new InteropBitmapInfo { IsPopup = isPopup };
}
}
}
@@ -2,7 +2,7 @@
using System.Windows.Media;
using System.Windows.Media.Imaging;
namespace CefSharp.Wpf
namespace CefSharp.Wpf.Rendering
{
public class InteropBitmapInfo : WpfBitmapInfo
{
@@ -5,7 +5,7 @@
using System.Windows.Media.Imaging;
using CefSharp.Internals;
namespace CefSharp.Wpf
namespace CefSharp.Wpf.Rendering
{
public abstract class WpfBitmapInfo : BitmapInfo
{
@@ -6,7 +6,7 @@ using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Imaging;
namespace CefSharp.Wpf
namespace CefSharp.Wpf.Rendering
{
public class WritableBitmapInfo : WpfBitmapInfo
{
@@ -32,26 +32,17 @@ namespace CefSharp.Wpf
public override void Invalidate()
{
//int stride = browserWidth * 4;
var stride = Width * BytesPerPixel;
var sourceBufferSize = stride * Height;
var stride = Width*BytesPerPixel;
var sourceBufferSize = stride*Height;
if (Width == 0 || Height == 0)
if (Width == 0 || Height == 0 || DirtyRect.Width == 0 || DirtyRect.Height == 0)
{
return;
}
foreach (var dirtyRect in DirtyRects)
{
if (dirtyRect.Width == 0 || dirtyRect.Height == 0)
{
continue;
}
// Update the dirty region
var sourceRect = new Int32Rect(dirtyRect.X, dirtyRect.Y, dirtyRect.Width, dirtyRect.Height);
Bitmap.WritePixels(sourceRect, BackBufferHandle, sourceBufferSize, stride, dirtyRect.X, dirtyRect.Y);
}
// Update the dirty region
var sourceRect = new Int32Rect(DirtyRect.X, DirtyRect.Y, DirtyRect.Width, DirtyRect.Height);
Bitmap.WritePixels(sourceRect, BackBufferHandle, sourceBufferSize, stride, DirtyRect.X, DirtyRect.Y);
}
public override BitmapSource CreateBitmap()
+1 -1
View File
@@ -3,6 +3,7 @@
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
using System;
using CefSharp.Wpf.Rendering;
namespace CefSharp.Wpf
{
@@ -20,6 +21,5 @@ namespace CefSharp.Wpf
/// The bitmap info being rendered.
/// </summary>
public WpfBitmapInfo BitmapInfo { get; private set; }
}
}
+1
View File
@@ -92,6 +92,7 @@
<Compile Include="CefFileDialogMode.cs" />
<Compile Include="DefaultResourceHandler.cs" />
<Compile Include="DragOperationsMask.cs" />
<Compile Include="IBitmapFactory.cs" />
<Compile Include="IDragData.cs" />
<Compile Include="IFocusHandler.cs" />
<Compile Include="IDragHandler.cs" />
+13
View File
@@ -0,0 +1,13 @@
// Copyright © 2010-2014 The CefSharp Authors. All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
using CefSharp.Internals;
namespace CefSharp
{
public interface IBitmapFactory
{
BitmapInfo CreateBitmap(bool isPopup);
}
}
+1 -1
View File
@@ -25,7 +25,7 @@ namespace CefSharp.Internals
public abstract bool CreateNewBitmap { get; }
public abstract void ClearBitmap();
public IList<CefDirtyRect> DirtyRects { get; set; }
public CefDirtyRect DirtyRect { get; set; }
protected BitmapInfo()
{