Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance rendering framework with new RenderNode architecture #1196

Merged
merged 36 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
b390a16
feat: add RenderNode, RenderNodeContext, and RenderNodeOperation clas…
yuto-trd Dec 7, 2024
8bfccdd
feat: add various RenderNode implementations for enhanced rendering c…
yuto-trd Dec 7, 2024
a7ddf50
feat: implement IPopable interface and update PushedState to use it
yuto-trd Dec 7, 2024
75a4d76
feat: Implement GraphicsContext2D class for recording RenderNodes.
yuto-trd Dec 7, 2024
ed6ed55
feat: mark CombinedFilterEffect and MultiTransform as obsolete, sugge…
yuto-trd Dec 7, 2024
d60229b
feat: add OnUntracked callback and improve node disposal in GraphicsC…
yuto-trd Dec 7, 2024
98ffbb1
feat: add RenderNodeCache and RenderNodeProcessor for enhanced render…
yuto-trd Dec 7, 2024
02840bb
feat: add unit tests for GraphicsContext2D to validate rendering beha…
yuto-trd Dec 7, 2024
380f10e
feat: mark multiple rendering classes as obsolete to suggest alternat…
yuto-trd Dec 7, 2024
e3a298f
feat: update rendering methods to use GraphicsContext2D and mark Defe…
yuto-trd Dec 7, 2024
47c17ab
feat: mark DeferradCanvas as obsolete and comment out rendering logic
yuto-trd Dec 7, 2024
47bdf57
feat: refactor rendering cache to use RenderNodeCacheContext and upda…
yuto-trd Dec 7, 2024
fb733b1
feat: update RenderLayer to use DrawableRenderNode and GraphicsContex…
yuto-trd Dec 7, 2024
9007049
feat: update ImmediateCanvas to use RenderNodeCacheContext and commen…
yuto-trd Dec 7, 2024
f908a04
feat: refactor PlayerViewModel to use DrawableRenderNode and Graphics…
yuto-trd Dec 7, 2024
40c340e
fix: build error
yuto-trd Dec 7, 2024
54a2942
fix: Fixed possible memory leak code
yuto-trd Dec 7, 2024
54ef03c
feat: Add TODO for supporting multiple EffectTargets in TransformEffect
yuto-trd Dec 7, 2024
c0c5f48
feat: Implement DrawDrawable method in ImmediateCanvas
yuto-trd Dec 7, 2024
af96e69
refactor: Replace Render calls with DrawDrawable in unit tests
yuto-trd Dec 7, 2024
8e93486
refactor: Remove DeferradCanvasTests and update GraphicsContext2DTest…
yuto-trd Dec 7, 2024
9499210
fix: correct behavior of PushLayer
yuto-trd Dec 7, 2024
ae75457
feat: Add TODO to disable caching when context.IsCacheEnabled is fals…
yuto-trd Dec 7, 2024
c870404
refactor: Remove obsolete rendering nodes and interfaces
yuto-trd Dec 7, 2024
1d308d8
refactor: Remove obsolete Cache references and update rendering logic
yuto-trd Dec 7, 2024
a6d89f7
change: relocate files previously moved temporarily under Rendering.V2
yuto-trd Dec 7, 2024
46c9398
feat: implement logic for creating cache
yuto-trd Dec 7, 2024
ed6503e
change: move cache ownership from RenderNodeCacheContext to RenderNode
yuto-trd Dec 7, 2024
85e4e23
feat: add bounds calculation for RenderLayer
yuto-trd Dec 7, 2024
5c728dc
change: refactor HitTest implementation to use RenderNode
yuto-trd Dec 7, 2024
65696f5
test: reorganize rendering tests and add new test cases for render nodes
yuto-trd Dec 7, 2024
241b454
fix: correct processing in RenderNodeProcessor.Rasterize
yuto-trd Dec 7, 2024
4f8be4e
test: add unit tests for EllipseRenderNode, RectClipRenderNode, Recta…
yuto-trd Dec 8, 2024
35e9ab5
feat: simplify FilterEffectActivator
yuto-trd Dec 9, 2024
1fc4db9
fix: resolve exception occurring in RenderNode caching
yuto-trd Dec 9, 2024
1ccb01e
refactor: streamline FilterEffectActivator by removing unnecessary fi…
yuto-trd Dec 9, 2024
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
Next Next commit
feat: add RenderNode, RenderNodeContext, and RenderNodeOperation clas…
…ses for rendering framework
  • Loading branch information
yuto-trd committed Dec 7, 2024
commit b390a167a03067075a9c7283978333db162d1e85
31 changes: 31 additions & 0 deletions src/Beutl.Engine/Graphics/Rendering/V2/RenderNode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
namespace Beutl.Graphics.Rendering.V2;

public abstract class RenderNode : INode
{
~RenderNode()
{
if (!IsDisposed)
{
OnDispose(false);
IsDisposed = true;
}
}

public bool IsDisposed { get; private set; }

public abstract RenderNodeOperation[] Process(RenderNodeContext context);

public void Dispose()
{
if (!IsDisposed)
{
OnDispose(true);
IsDisposed = true;
GC.SuppressFinalize(this);
}
}

protected virtual void OnDispose(bool disposing)
{
}
}
15 changes: 15 additions & 0 deletions src/Beutl.Engine/Graphics/Rendering/V2/RenderNodeContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace Beutl.Graphics.Rendering.V2;

public class RenderNodeContext(IImmediateCanvasFactory canvasFactory, RenderNodeOperation[] input)
{
public RenderNodeOperation[] Input { get; } = input;

public IImmediateCanvasFactory CanvasFactory { get; } = canvasFactory;

public bool IsRenderCacheEnabled { get; set; } = true;

public Rect CalculateBounds()
{
return Input.Aggregate<RenderNodeOperation, Rect>(default, (current, operation) => current.Union(operation.Bounds));
}
}
70 changes: 70 additions & 0 deletions src/Beutl.Engine/Graphics/Rendering/V2/RenderNodeOperation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using SkiaSharp;

namespace Beutl.Graphics.Rendering.V2;

public abstract class RenderNodeOperation : IDisposable
{
public bool IsDisposed { get; private set; }

// Invalidになることはない
public abstract Rect Bounds { get; }

public abstract void Render(ImmediateCanvas canvas);

public abstract bool HitTest(Point point);

public void Dispose()
{
if (!IsDisposed)
{
OnDispose(true);
IsDisposed = true;
GC.SuppressFinalize(this);
}
}

protected virtual void OnDispose(bool disposing)
{
}

public static RenderNodeOperation CreateDecorator(
RenderNodeOperation child, Action<ImmediateCanvas> render,
Func<Point, bool>? hitTest = null,
Action? onDispose = null)
{
return CreateLambda(child.Bounds, render, hitTest: hitTest ?? child.HitTest, onDispose: () =>
{
child.Dispose();
onDispose?.Invoke();
});
}

public static RenderNodeOperation CreateLambda(
Rect bounds, Action<ImmediateCanvas> render,
Func<Point, bool>? hitTest = null,
Action? onDispose = null)
{
return new LambdaRenderNodeOperation(bounds, render, hitTest, onDispose);
}

public static RenderNodeOperation CreateFromSurface(Rect bounds, Point position, SKSurface surface)
{
return CreateLambda(bounds, canvas => canvas.DrawSurface(surface, position), bounds.Contains, surface.Dispose);
}

private class LambdaRenderNodeOperation(
Rect bounds,
Action<ImmediateCanvas> render,
Func<Point, bool>? hitTest,
Action? onDispose)
: RenderNodeOperation
{
public override Rect Bounds => bounds;

public override void Render(ImmediateCanvas canvas) => render(canvas);

public override bool HitTest(Point point) => hitTest?.Invoke(point) ?? false;

protected override void OnDispose(bool disposing) => onDispose?.Invoke();
}
}