Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -397,3 +397,4 @@ FodyWeavers.xsd
# JetBrains Rider
*.sln.iml
/CefSharp.WinForms.Direct3D.Example/obj.netcore
.idea/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this required?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a rider folder containing project specific settings files, it's not mandatory since I simply can avoid to commit that folder. It was just to make it easier when committing

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick response, should be fine to leave.

42 changes: 42 additions & 0 deletions CefSharp.Offscreen.Direct3D.Example/AcceleratedRenderHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using CefSharp.OffScreen;
using CefSharp.Structs;

namespace CefSharp.Offscreen.Direct3D.Example;

public class AcceleratedRenderHandler(ChromiumWebBrowser browser, int windowWidth, int windowHeight) : DefaultRenderHandler(browser)
{
private D3D11Renderer _renderer = null!;

public override void OnAcceleratedPaint(PaintElementType type, Rect dirtyRect, AcceleratedPaintInfo acceleratedPaintInfo)
{
base.OnAcceleratedPaint(type, dirtyRect, acceleratedPaintInfo);
_renderer ??= new D3D11Renderer(windowWidth, windowHeight);
switch (type)
{
case PaintElementType.View:
_renderer?.OnAcceleratedPaint(acceleratedPaintInfo.SharedTextureHandle, PopupOpen);
break;
case PaintElementType.Popup:
_renderer?.CreatePopupLayer(acceleratedPaintInfo.SharedTextureHandle, new Rect(PopupPosition.X, PopupPosition.Y, PopupSize.Width, PopupSize.Height));
break;
}
}

public void BrowserWasResized(int width, int height)
{
_renderer?.ResizeWindow(width, height);
}

public override void OnPopupShow(bool show)
{
base.OnPopupShow(show);
if(show) return;
_renderer?.RemovePopupLayer();
}

public new void Dispose()
{
base.Dispose();
_renderer?.Dispose();
}
}
26 changes: 26 additions & 0 deletions CefSharp.Offscreen.Direct3D.Example/Application.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
namespace CefSharp.Offscreen.Direct3D.Example;

public class Application
{
public static Uri Url { get; set; } = new("https://github.com/cefsharp/CefSharp.OnAcceleratedPaint.Example");
private readonly OffscreenBrowser _browser;
public Application()
{
var cefBrowserSettings = new BrowserSettings
{
BackgroundColor = Cef.ColorSetARGB(255, 255, 255, 255),
WebGl = CefState.Enabled,
WindowlessFrameRate = 60,
LocalStorage = CefState.Default
};

_browser = new OffscreenBrowser(1920, 1080, Url.AbsoluteUri, cefBrowserSettings);
}

public void Close()
{
_browser.Stop();
_browser.Dispose();
Cef.Shutdown();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>disable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CefSharp.OffScreen.NETCore" Version="133.4.21" />
<PackageReference Include="SharpDX.D3DCompiler" Version="4.2.0" />
<PackageReference Include="SharpDX.Direct2D1" Version="4.2.0" />
<PackageReference Include="SharpDX.Direct3D11" Version="4.2.0" />
<PackageReference Include="SharpDX.Mathematics" Version="4.2.0" />
</ItemGroup>

</Project>
Loading