Skip to content
Merged
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ VisualPinball.Engine.DMD.Unity/Plugins/**/*.pdb
VisualPinball.Engine.DMD.Unity/Plugins/**/*.so
VisualPinball.Engine.DMD.Unity/Plugins/**/*.so.*
VisualPinball.Engine.DMD.Unity/Plugins/**/*.dylib
# ...but not their import settings: "*.so.*" also matches "libserum.so.meta"
!VisualPinball.Engine.DMD.Unity/Plugins/**/*.meta
23 changes: 19 additions & 4 deletions Tests/Player/ManagedDmdInputTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ public void SetUp()
_sourceIsCurrent = true;
_failCreation = false;
_errors = new List<Exception>();
_input = new ManagedDmdInput(_owner, (id, width, height) => {
_input = new ManagedDmdInput(_owner, (id, width, height, encoding) => {
_owner.VerifyOwner();
if (_failCreation) throw new InvalidOperationException("Graph initialization failed.");
var pipeline = new Pipeline(id, width, height);
var pipeline = new Pipeline(id, width, height, encoding);
_created.Add(pipeline);
return pipeline;
}, instance => _sourceIsCurrent, _errors.Add);
Expand Down Expand Up @@ -73,6 +73,20 @@ public void SingleChangedFrameSurvivesWithoutAnyFurtherSourceEvents(bool sourceC
Assert.That(_created[1].Frames[0].Instance, Is.EqualTo(changed.Instance));
}

[Test]
public void SwitchingBetweenGrayAndRgbRebuildsThePipeline()
{
_input.Feed(Frame(new byte[] { 1, 2 }), "dmd0");
_input.Feed(new PluginDisplayFrame(new byte[] { 9, 8 }, 2, 1, 2, DisplayEncoding.Luminance8, 2, 2000, 1), "dmd0");
Assert.That(_created.Count, Is.EqualTo(1), "gray stays gray, whatever the bit depth");
var rgb = new PluginDisplayFrame(new byte[] { 1, 2, 3, 4, 5, 6 }, 2, 1, 6, DisplayEncoding.Rgb24, 3, 3000, 1);
_input.Feed(rgb, "dmd0");
_created[0].FinishStop();
PumpUntil(() => _created.Count == 2);
Assert.That(_created[1].Encoding, Is.EqualTo(DisplayEncoding.Rgb24));
Assert.That(_created[1].Frames[0].Pixels.ToArray(), Is.EqualTo(new byte[] { 1, 2, 3, 4, 5, 6 }));
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved
}

[Test]
public void RebuildUsesLatestFrameAndItsShapeEncodingAndMetadata()
{
Expand Down Expand Up @@ -200,15 +214,16 @@ private sealed class Pipeline : IManagedDmdPipeline
{
internal readonly string Id;
internal readonly int Width, Height;
internal readonly DisplayEncoding Encoding;
internal readonly List<PluginDisplayFrame> Frames = new List<PluginDisplayFrame>();
private readonly TaskCompletionSource<bool> _stopped = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
internal bool Disposed;
internal bool Capture = true;
internal bool FailNextStop;
internal int StopRequests;
internal ReadOnlyMemory<byte> LastBorrowedPixels;
internal Pipeline(string id, int width, int height) { Id = id; Width = width; Height = height; }
public bool Matches(string id, int width, int height) => Id == id && Width == width && Height == height;
internal Pipeline(string id, int width, int height, DisplayEncoding encoding) { Id = id; Width = width; Height = height; Encoding = encoding; }
public bool Matches(string id, int width, int height, DisplayEncoding encoding) => Id == id && Width == width && Height == height && (Encoding == DisplayEncoding.Rgb24) == (encoding == DisplayEncoding.Rgb24);
public void Push(in PluginDisplayFrame frame)
{
if (Disposed) throw new ObjectDisposedException(nameof(Pipeline));
Expand Down
4 changes: 4 additions & 0 deletions Tests/Player/VisualPinball.Engine.DMD.Player.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@
<IsTestProject>true</IsTestProject>
<IsPackable>false</IsPackable>
<VpeSourceRoot Condition="'$(VpeSourceRoot)' == ''">../../../VisualPinball.Engine</VpeSourceRoot>
<LibDmdExtensionsRoot Condition="'$(LibDmdExtensionsRoot)' == ''">C:\Development\dmd-extensions</LibDmdExtensionsRoot>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="$(VpeSourceRoot)/VisualPinball.Plugins/VisualPinball.Plugins.csproj" />
<Compile Include="../../VisualPinball.Engine.DMD.Unity/Runtime/Plugins/ColorizationCatalog.cs" Link="ColorizationCatalog.cs" />
<Compile Include="../../VisualPinball.Engine.DMD.Unity/Runtime/ManagedDmdInput.cs" Link="ManagedDmdInput.cs" />
<!-- with VpeTypes.cs standing in for the VisualPinball.Unity types it uses -->
<Compile Include="../../VisualPinball.Engine.DMD.Unity/Runtime/VpeGleSource.cs" Link="VpeGleSource.cs" />
<ProjectReference Include="$(LibDmdExtensionsRoot)/LibDmd.Core/LibDmd.Core.csproj" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
Expand Down
112 changes: 112 additions & 0 deletions Tests/Player/VpeGleSourceTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
// Visual Pinball Engine
// Copyright (C) 2026 freezy and VPE Team
//
// SPDX-License-Identifier: MIT
// Licensed under MIT. See https://opensource.org/license/mit.

using System;
using System.Collections.Generic;
using LibDmd;
using LibDmd.Frame;
using LibDmd.Output;
using NUnit.Framework;
using VisualPinball.Engine.DMD.Unity;
using VisualPinball.Unity;

namespace VisualPinball.Engine.DMD.Tests
{
/// <summary>
/// Frames from an uncolorized source go through a real render graph, into a destination taking
/// every format (like the in-scene DMD) and one taking RGB only (like the presentation output).
/// </summary>
public sealed class VpeGleSourceTests
{
private const int Width = 4, Height = 2;

[TestCase(DisplayFrameFormat.Dmd2, 3)]
[TestCase(DisplayFrameFormat.Dmd4, 15)]
[TestCase(DisplayFrameFormat.Dmd8, 255)]
public void GrayFramesReachBothDestinations(DisplayFrameFormat format, int max)
{
var source = VpeGleSource.Create(new DisplayConfig("dmd0", Width, Height), colorize: false, rgb: false);
var everyFormat = new EveryFormatDestination("every format");
var rgbOnly = new RgbOnlyDestination("rgb only");
using (Render(source, everyFormat, rgbOnly)) {
var frame = new byte[Width * Height];
frame[0] = (byte)max;
source.Push(format, frame, frame.Length);
}

Assert.That(everyFormat.Frames, Has.Count.EqualTo(1), "in-scene");
Assert.That(everyFormat.Frames[0].Format, Is.EqualTo("Gray8"));
Assert.That(everyFormat.Frames[0].Data[0], Is.EqualTo(255));
Assert.That(rgbOnly.Frames, Has.Count.EqualTo(1), "presentation");
Assert.That(rgbOnly.Frames[0].Format, Is.EqualTo("Rgb24"));
}

[Test]
public void RgbFramesReachBothDestinations()
{
var source = VpeGleSource.Create(new DisplayConfig("dmd0", Width, Height), colorize: false, rgb: true);
var everyFormat = new EveryFormatDestination("every format");
var rgbOnly = new RgbOnlyDestination("rgb only");
using (Render(source, everyFormat, rgbOnly)) {
var frame = new byte[Width * Height * 3];
frame[0] = 200;
source.Push(DisplayFrameFormat.Dmd24, frame, frame.Length);
}

Assert.That(everyFormat.Frames, Has.Count.EqualTo(1));
Assert.That(everyFormat.Frames[0].Format, Is.EqualTo("Rgb24"));
Assert.That(everyFormat.Frames[0].Data[0], Is.EqualTo(200));
Assert.That(rgbOnly.Frames, Has.Count.EqualTo(1));
Assert.That(rgbOnly.Frames[0].Format, Is.EqualTo("Rgb24"));
}

private static IDisposable Render(VpeGleSource source, params IDestination[] destinations)
{
var graph = new RenderGraph(new UndisposedReferences(), runOnMainThread: true) {
Name = "test",
Source = source,
Destinations = new List<IDestination>(destinations),
};
return graph.Init().StartRendering(null, error => Assert.Fail(error.ToString()));
}

private class RgbOnlyDestination : IRgb24Destination
{
internal readonly List<(string Format, byte[] Data)> Frames = new List<(string, byte[])>();

internal RgbOnlyDestination(string name) => Name = name;

public string Name { get; }
public bool IsAvailable => true;
public bool NeedsDuplicateFrames => false;
public bool NeedsIdentificationFrames => false;

public void RenderRgb24(DmdFrame frame) => Record("Rgb24", frame);
public void SetColor(DmdColor color) { }
public void SetPalette(DmdColor[] colors) { }
public void ClearColor() { }
public void ClearPalette() { }
public void ClearDisplay() { }
public void Dispose() { }

protected void Record(string format, DmdFrame frame) => Frames.Add((format, (byte[])frame.Data.Clone()));
}

// the formats of the in-scene DMD
private sealed class EveryFormatDestination : RgbOnlyDestination, IGray2Destination, IGray4Destination, IGray8Destination, IRgb565Destination, IFixedSizeDestination
{
internal EveryFormatDestination(string name) : base(name) { }

public Dimensions FixedSize => new Dimensions(Width, Height);
public bool DmdAllowHdScaling => false;

public void RenderGray2(DmdFrame frame) => Record("Gray2", frame);
public void RenderGray4(DmdFrame frame) => Record("Gray4", frame);
public void RenderGray8(DmdFrame frame) => Record("Gray8", frame);
public void RenderRgb565(DmdFrame frame) => Record("Rgb565", frame);
}
}
}
36 changes: 36 additions & 0 deletions Tests/Player/VpeTypes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Visual Pinball Engine
// Copyright (C) 2026 freezy and VPE Team
//
// SPDX-License-Identifier: MIT
// Licensed under MIT. See https://opensource.org/license/mit.

// The two VisualPinball.Unity types VpeGleSource uses, so it compiles here without Unity. Same
// members and values as in VisualPinball.Unity's IGamelogicEngine.cs.
namespace VisualPinball.Unity
{
public enum DisplayFrameFormat
{
Dmd2,
Dmd4,
Dmd8,
Dmd24,
Segment,
AlphaNumeric,
Numeric,
Video24
}

public class DisplayConfig
{
public readonly string Id;
public readonly int Width;
public readonly int Height;

public DisplayConfig(string id, int width, int height)
{
Id = id;
Width = width;
Height = height;
}
}
}
43 changes: 43 additions & 0 deletions VisualPinball.Engine.DMD.Unity/Plugins/linux-x64/libcargs.so.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading