Sfoglia il codice sorgente

Fixed context freezes with opengl

Krzysztof Krysiński 1 settimana fa
parent
commit
0bf38a680c

+ 3 - 0
src/ChunkyImageLib/Chunk.cs

@@ -1,5 +1,6 @@
 using ChunkyImageLib.DataHolders;
 using Drawie.Backend.Core;
+using Drawie.Backend.Core.Bridge;
 using Drawie.Backend.Core.Numerics;
 using Drawie.Backend.Core.Surfaces;
 using Drawie.Backend.Core.Surfaces.ImageData;
@@ -86,6 +87,7 @@ public class Chunk : IDisposable
     /// <param name="paint">The paint to use while drawing</param>
     public void DrawChunkOn(DrawingSurface surface, VecD pos, Paint? paint = null, SamplingOptions? samplingOptions = null)
     {
+        using var ctx = DrawingBackendApi.Current.RenderingDispatcher.EnsureContext();
         if (samplingOptions == null || samplingOptions == SamplingOptions.Default)
         {
             surface.Canvas.DrawSurface(Surface.DrawingSurface, (float)pos.X, (float)pos.Y, paint);
@@ -99,6 +101,7 @@ public class Chunk : IDisposable
 
     public unsafe RectI? FindPreciseBounds(RectI? passedSearchRegion = null)
     {
+        using var ctx = DrawingBackendApi.Current.RenderingDispatcher.EnsureContext();
         RectI? bounds = null;
         if (returned)
             return bounds;

+ 3 - 0
src/ChunkyImageLib/ChunkyImage.cs

@@ -7,6 +7,7 @@ using OneOf;
 using OneOf.Types;
 using PixiEditor.Common;
 using Drawie.Backend.Core;
+using Drawie.Backend.Core.Bridge;
 using Drawie.Backend.Core.ColorsImpl;
 using Drawie.Backend.Core.ColorsImpl.Paintables;
 using Drawie.Backend.Core.Numerics;
@@ -1339,6 +1340,8 @@ public class ChunkyImage : IReadOnlyChunkyImage, IDisposable, ICloneable, ICache
         if (operation is ClearOperation)
             return true;
 
+        using var ctx = DrawingBackendApi.Current.RenderingDispatcher.EnsureContext();
+
         if (operation is IDrawOperation chunkOperation)
         {
             if (combinedRasterClips.IsT1) // Nothing is visible

+ 1 - 1
src/Drawie

@@ -1 +1 @@
-Subproject commit 34768b7075651961b0309092b28ddb12342033a8
+Subproject commit 6192ad39ba2b8ab88944f7c465a413968d37ada2

+ 1 - 1
src/PixiEditor/Models/Rendering/SceneRenderer.cs

@@ -41,6 +41,7 @@ internal class SceneRenderer : IDisposable
     {
         await DrawingBackendApi.Current.RenderingDispatcher.InvokeAsync(() =>
         {
+            using var ctx = DrawingBackendApi.Current.RenderingDispatcher.EnsureContext();
             int renderedCount = 0;
             foreach (var viewport in stateViewports)
             {
@@ -94,7 +95,6 @@ internal class SceneRenderer : IDisposable
             target.DeviceClipBounds.Size.ShortestAxis <= 0) return;*/
 
         /*TODO:
-         - [ ] Fix masks preview along with test case that fails
          - [ ] Rendering optimizer
          - [?] Render thread and proper locking/synchronization
          */

+ 2 - 0
src/PixiEditor/ViewModels/ViewModelMain.cs

@@ -4,6 +4,7 @@ using System.Threading.Tasks;
 using Avalonia.Controls.ApplicationLifetimes;
 using Avalonia.Threading;
 using CommunityToolkit.Mvvm.Input;
+using Drawie.Backend.Core.Bridge;
 using Microsoft.Extensions.DependencyInjection;
 using Drawie.Backend.Core.ColorsImpl;
 using PixiEditor.Extensions.CommonApi.UserPreferences;
@@ -346,6 +347,7 @@ internal partial class ViewModelMain : ViewModelBase, ICommandsHandler
 
         if (result != ConfirmationType.Canceled)
         {
+            using var ctx = DrawingBackendApi.Current.RenderingDispatcher.EnsureContext();
             BeforeDocumentClosed?.Invoke(document);
             if (!DocumentManagerSubViewModel.Documents.Remove(document))
                 throw new InvalidOperationException(

+ 2 - 0
src/PixiEditor/Views/Rendering/Scene.cs

@@ -273,6 +273,7 @@ internal class Scene : Zoombox.Zoombox, ICustomHitTest
 
     protected override async void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e)
     {
+        using var ctx = DrawingBackendApi.Current.RenderingDispatcher.EnsureContext();
         framebuffer?.Dispose();
         framebuffer = null;
 
@@ -922,6 +923,7 @@ internal class Scene : Zoombox.Zoombox, ICustomHitTest
 
     protected async Task FreeGraphicsResources()
     {
+        using var ctx = DrawingBackendApi.Current.RenderingDispatcher.EnsureContext();
         renderTexture?.Dispose();
         renderTexture = null;