Skip to content

Commit

Permalink
Set up mpv render API initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
karashiiro committed Mar 7, 2024
1 parent 4037a8c commit 58951a4
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 11 deletions.
7 changes: 0 additions & 7 deletions src/simulacrum-dalamud-av/MpvRender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,4 @@ public static partial class MpvRender
internal static partial void FreeContext(nint context);

public delegate void MpvRenderUpdateCallback(nint ctx);

[StructLayout(LayoutKind.Sequential)]
public struct MpvRenderParam
{
public int Type;
public nint Data;
}
}
18 changes: 14 additions & 4 deletions src/simulacrum-dalamud-av/MpvRenderContext.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
namespace Simulacrum.AV;
using System.Runtime.CompilerServices;

namespace Simulacrum.AV;

public class MpvRenderContext : IDisposable
{
private nint _context;

public MpvRenderContext(MpvHandle handle)
public unsafe MpvRenderContext(MpvHandle handle)
{
var result = MpvRender.CreateContext(_context, handle._handle, ReadOnlySpan<MpvRender.MpvRenderParam>.Empty);
MpvException.ThrowMpvError(result);
Span<MpvRenderParam> contextParams = stackalloc MpvRenderParam[2];

var apiType = "sw"u8.ToArray().AsSpan();
fixed (byte* apiTypePtr = apiType)
{
contextParams[0] = new MpvRenderParam { Type = MpvRenderParamType.ApiType, Data = (nint)apiTypePtr };

var result = MpvRender.CreateContext(_context, handle._handle, contextParams);
MpvException.ThrowMpvError(result);
}
}

private void ReleaseUnmanagedResources()
Expand Down
10 changes: 10 additions & 0 deletions src/simulacrum-dalamud-av/MpvRenderParam.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Runtime.InteropServices;

namespace Simulacrum.AV;

[StructLayout(LayoutKind.Sequential)]
public struct MpvRenderParam
{
public MpvRenderParamType Type;
public nint Data;
}
27 changes: 27 additions & 0 deletions src/simulacrum-dalamud-av/MpvRenderParamType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
namespace Simulacrum.AV;

// https://github.com/mpv-player/mpv/blob/665a47209869d7a0c4ea860b28910fcd6ca874c8/libmpv/render.h#L171
public enum MpvRenderParamType
{
Invalid,
ApiType,
OpenGLInitParams,
OpenGLFrameBufferObject,
FlipY,
Depth,
IccProfile,
AmbientLight,
X11Display,
WaylandDisplay,
AdvancedControl,
NextFrameInfo,
BlockForTargetTime,
SkipRendering,
DrmDisplay,
DrmDrawSurfaceSize,
DrmDisplayV2,
SoftwareSize,
SoftwareFormat,
SoftwareStride,
SoftwarePointer,
}

0 comments on commit 58951a4

Please sign in to comment.