diff options
| author | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2022-07-17 20:26:28 +0200 |
|---|---|---|
| committer | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2022-07-17 20:26:28 +0200 |
| commit | 9d786ab096ed36ea384e03ee5cea498790e31eec (patch) | |
| tree | adee54b5b90a35238d5794e9ffd3ebcf65798a06 /Backends | |
| parent | 57daad000aa31c7bcfa1f76b90d40da5a21da041 (diff) | |
wip
Diffstat (limited to 'Backends')
| -rw-r--r-- | Backends/CairoBackend/src/Context.cs | 5 | ||||
| -rw-r--r-- | Backends/CairoBackend/src/EglBackend.cs | 21 | ||||
| -rw-r--r-- | Backends/CairoBackend/src/ImageBackend.cs | 9 | ||||
| -rw-r--r-- | Backends/CairoBackend/src/ImageSurface.cs | 4 | ||||
| -rw-r--r-- | Backends/CairoBackend/src/Surface.cs | 2 | ||||
| -rw-r--r-- | Backends/VkvgBackend/Crow.VkvgBackend.csproj | 2 | ||||
| -rw-r--r-- | Backends/VkvgBackend/src/DefaultBackend.cs | 19 |
7 files changed, 50 insertions, 12 deletions
diff --git a/Backends/CairoBackend/src/Context.cs b/Backends/CairoBackend/src/Context.cs index c15ecaa3..f9af1bf1 100644 --- a/Backends/CairoBackend/src/Context.cs +++ b/Backends/CairoBackend/src/Context.cs @@ -661,7 +661,8 @@ namespace Crow.CairoBackend public void RestoreTransformations() => NativeMethods.cairo_set_matrix (handle, ref savedMat); public void SetSource(IPattern pat) => NativeMethods.cairo_set_source (handle, (pat as Pattern).handle); - public void SetSource(ISurface surf, double x = 0, double y = 0) - => NativeMethods.cairo_set_source_surface (handle, (surf as Surface).handle, x, y); + public async void SetSource(ISurface surf, double x = 0, double y = 0) { + NativeMethods.cairo_set_source_surface (handle, surf.Handle, x, y); + } } } diff --git a/Backends/CairoBackend/src/EglBackend.cs b/Backends/CairoBackend/src/EglBackend.cs index 909c3cd9..073793e7 100644 --- a/Backends/CairoBackend/src/EglBackend.cs +++ b/Backends/CairoBackend/src/EglBackend.cs @@ -7,11 +7,13 @@ namespace Crow.CairoBackend { public class EglBackend : CairoBackendBase { EGLDevice device; + GLSurface winSurf; /// <summary> /// Create a new generic backend bound to the application surface /// </summary> /// <param name="width">backend surface width</param> /// <param name="height">backend surface height</param> + /// <param name="nativeWindoPointer"></param> public EglBackend (int width, int height, IntPtr nativeWindoPointer) : base (width, height, nativeWindoPointer) { if (nativeWindoPointer == IntPtr.Zero) { @@ -32,7 +34,9 @@ namespace Crow.CairoBackend Glfw3.SwapInterval (0); device = new EGLDevice (Glfw3.GetEGLDisplay (), Glfw3.GetEGLContext (hWin)); - surf = new GLSurface (device, Glfw3.GetEGLSurface (hWin), width, height); + //surf = new GLTextureSurface (device, width, height); + surf = new ImageSurface (Format.ARGB32, width, height); + winSurf = new GLSurface (device, Glfw3.GetEGLSurface (hWin), width, height); } /// <summary> /// Create a new offscreen backend, used in perfTests @@ -61,9 +65,20 @@ namespace Crow.CairoBackend } public override void FlushUIFrame(IContext ctx) { - base.FlushUIFrame (ctx); - (surf as GLSurface).SwapBuffers (); + base.FlushUIFrame (ctx); + surf.Flush(); + using (Context gr = new Context (winSurf)) { + gr.SetSource (surf); + gr.Paint(); + } + winSurf.SwapBuffers (); + } + public override void ResizeMainSurface(int width, int height) + { + base.ResizeMainSurface(width, height); + winSurf?.Dispose(); + winSurf = new GLSurface (device, Glfw3.GetEGLSurface (hWin), width, height); } } } diff --git a/Backends/CairoBackend/src/ImageBackend.cs b/Backends/CairoBackend/src/ImageBackend.cs index 96899dbd..a90d275a 100644 --- a/Backends/CairoBackend/src/ImageBackend.cs +++ b/Backends/CairoBackend/src/ImageBackend.cs @@ -79,6 +79,15 @@ namespace Crow.CairoBackend base.FlushUIFrame (ctx); } + public override void ResizeMainSurface(int width, int height) + { + if (surf is ImageSurface) { + surf?.Dispose(); + surf = new ImageSurface (Format.ARGB32, width, height); + } else { + base.ResizeMainSurface(width, height); + } + } } } diff --git a/Backends/CairoBackend/src/ImageSurface.cs b/Backends/CairoBackend/src/ImageSurface.cs index 2cfec61c..8870366a 100644 --- a/Backends/CairoBackend/src/ImageSurface.cs +++ b/Backends/CairoBackend/src/ImageSurface.cs @@ -96,5 +96,9 @@ namespace Crow.CairoBackend { public int Stride { get { return NativeMethods.cairo_image_surface_get_stride (handle); } } + public override void Resize(int width, int height) + { + + } } } diff --git a/Backends/CairoBackend/src/Surface.cs b/Backends/CairoBackend/src/Surface.cs index 80435b5e..1f44d3ab 100644 --- a/Backends/CairoBackend/src/Surface.cs +++ b/Backends/CairoBackend/src/Surface.cs @@ -41,6 +41,8 @@ namespace Crow.CairoBackend { public class Surface : ISurface { internal IntPtr handle = IntPtr.Zero; + public IntPtr Handle => handle; + protected Surface() { diff --git a/Backends/VkvgBackend/Crow.VkvgBackend.csproj b/Backends/VkvgBackend/Crow.VkvgBackend.csproj index 13386d36..b6fbb004 100644 --- a/Backends/VkvgBackend/Crow.VkvgBackend.csproj +++ b/Backends/VkvgBackend/Crow.VkvgBackend.csproj @@ -15,7 +15,7 @@ <ItemGroup> <PackageReference Include="vke" Version="0.2.0-beta" /> - <PackageReference Include="vkvg.net" Version="0.5.0-beta" /> + <PackageReference Include="vkvg.net" Version="0.6.0-beta" /> <ProjectReference Include="..\..\Drawing2D\Drawing2D.csproj" /> </ItemGroup> diff --git a/Backends/VkvgBackend/src/DefaultBackend.cs b/Backends/VkvgBackend/src/DefaultBackend.cs index 8521d503..eeed4d0a 100644 --- a/Backends/VkvgBackend/src/DefaultBackend.cs +++ b/Backends/VkvgBackend/src/DefaultBackend.cs @@ -32,7 +32,7 @@ namespace Crow.VkvgBackend protected Fence drawFence; Surface surf; Device vkvgDev; - SampleCount samples = SampleCount.Sample_1; + SampleCount samples = SampleCount.Sample_8; bool vsync = false; bool tryGetPhy (vke.PhysicalDeviceCollection physicalDevices, VkPhysicalDeviceType phyType, out PhysicalDevice phy, bool swapchainSupport) { @@ -189,6 +189,7 @@ namespace Crow.VkvgBackend new SvgHandle (vkvgDev, System.Text.Encoding.Unicode.GetBytes (svgFragment)); bool disposeContextOnFlush; IRegion clipping; + volatile bool resizeMainSurface = false; protected void clear(IContext ctx) { for (int i = 0; i < clipping.NumRectangles; i++) ctx.Rectangle (clipping.GetRectangle (i)); @@ -200,6 +201,11 @@ namespace Crow.VkvgBackend } public override IContext PrepareUIFrame(IContext existingContext, IRegion clipping) { + if (resizeMainSurface) { + createMainSurface (swapChain.Width, swapChain.Height); + clipping.UnionRectangle (new Rectangle(new Size((int)swapChain.Width, (int)swapChain.Height))); + resizeMainSurface = false; + } this.clipping = clipping; IContext ctx = existingContext; if (ctx == null) { @@ -216,23 +222,24 @@ namespace Crow.VkvgBackend { if (disposeContextOnFlush) ctx.Dispose (); - clipping = null; - - dev.WaitIdle(); int idx = swapChain.GetNextImage (); if (idx < 0) { - createMainSurface (swapChain.Width, swapChain.Height); + resizeMainSurface = true; return; } + clipping = null; + + //dev.WaitIdle(); + drawFence.Wait (); drawFence.Reset (); graphicQueue.Submit (cmds[idx], swapChain.presentComplete, drawComplete[idx], drawFence); (graphicQueue as PresentQueue).Present (swapChain, drawComplete[idx]); - dev.WaitIdle(); + //dev.WaitIdle(); } public override void ResizeMainSurface (int width, int height) { //resize is done on swapchain image aquisition failure |