Skip to content

Commit

Permalink
Merge commit '5abbec887e883c6635e0f81a4ed3f78cfc344297' into vulkan_m…
Browse files Browse the repository at this point in the history
…ultipleframesinflight
  • Loading branch information
SupinePandora43 committed Sep 8, 2023
2 parents 4a44df0 + 5abbec8 commit f458820
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 49 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ You can learn more about Ultralight at [Ultralight's official website](https://u

* .NET >= `6.0`
* .NET Framework >= `4.6.1` (using `netstandard2.0`, untested)
* .NET Standard >= `2.0` (we do not officially support Unity [yet](https://github.com/SupinePandora43/UltralightNet/projects/3), untested)
* .NET Standard >= `2.0` ([Unity is untested](https://github.com/SupinePandora43/UltralightNet/projects/3))

## Reporting issues

Expand Down
14 changes: 7 additions & 7 deletions src/UltralightNet/Platform/Clipboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ namespace HighPerformance
/// </summary>
public unsafe struct ULClipboard
{
#if !NETSTANDARD
public delegate* unmanaged[Cdecl]<void> Clear;
public delegate* unmanaged[Cdecl]<ULString*, void> ReadPlainText;
public delegate* unmanaged[Cdecl]<ULString*, void> WritePlainText;
#else
public void* Clear, ReadPlainText, WritePlainText;
#endif
}
}
public interface IClipboard : IDisposable
public interface IClipboard
{
void Clear();
string ReadPlainText();
Expand Down Expand Up @@ -71,12 +75,8 @@ public void Dispose()
foreach (var handle in handles) if (handle.IsAllocated) handle.Free();
}

try { instance.Dispose(); }
finally
{
GC.SuppressFinalize(this);
IsDisposed = true;
}
GC.SuppressFinalize(this);
IsDisposed = true;
}
~Wrapper() => Dispose();
}
Expand Down
14 changes: 7 additions & 7 deletions src/UltralightNet/Platform/Filesystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@ namespace HighPerformance
/// </summary>
public unsafe struct ULFileSystem
{
#if !NETSTANDARD
public delegate* unmanaged[Cdecl]<ULString*, bool> FileExists;
public delegate* unmanaged[Cdecl]<ULString*, ULString*> GetFileMimeType;
public delegate* unmanaged[Cdecl]<ULString*, ULString*> GetFileCharset;
public delegate* unmanaged[Cdecl]<ULString*, ULBuffer> OpenFile;
#else
public void* FileExists, GetFileMimeType, GetFileCharset, OpenFile;
#endif
}
}
public interface IFileSystem : IDisposable
public interface IFileSystem
{
bool FileExists(string path);
string GetFileMimeType(string path);
Expand Down Expand Up @@ -74,12 +78,8 @@ public void Dispose()
foreach (var handle in handles) if (handle.IsAllocated) handle.Free();
}

try { instance.Dispose(); }
finally
{
GC.SuppressFinalize(this);
IsDisposed = true;
}
GC.SuppressFinalize(this);
IsDisposed = true;
}
~Wrapper() => Dispose();
}
Expand Down
14 changes: 7 additions & 7 deletions src/UltralightNet/Platform/FontLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ namespace HighPerformance
/// </summary>
public unsafe struct ULFontLoader
{
#if !NETSTANDARD
public delegate* unmanaged[Cdecl]<ULString*> GetFallbackFont;
public delegate* unmanaged[Cdecl]<ULString*, int, bool, ULString*> GetFallbackFontForCharacters;
public delegate* unmanaged[Cdecl]<ULString*, int, bool, ULFontFile> Load;
#else
public void* GetFallbackFont, GetFallbackFontForCharacters, Load;
#endif
}
}
public interface IFontLoader : IDisposable
public interface IFontLoader
{
string GetFallbackFont();
string GetFallbackFontForCharacters(string text, int weight, bool italic);
Expand Down Expand Up @@ -71,12 +75,8 @@ public void Dispose()
foreach (var handle in handles) if (handle.IsAllocated) handle.Free();
}

try { instance.Dispose(); }
finally
{
GC.SuppressFinalize(this);
IsDisposed = true;
}
GC.SuppressFinalize(this);
IsDisposed = true;
}
~Wrapper() => Dispose();
}
Expand Down
14 changes: 7 additions & 7 deletions src/UltralightNet/Platform/GPUDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace HighPerformance
/// </summary>
public unsafe struct ULGPUDriver
{
#if !NETSTANDARD
public delegate* unmanaged[Cdecl]<void> BeginSynchronize;
public delegate* unmanaged[Cdecl]<void> EndSynchronize;
public delegate* unmanaged[Cdecl]<uint> NextTextureId;
Expand All @@ -25,10 +26,13 @@ public unsafe struct ULGPUDriver
public delegate* unmanaged[Cdecl]<uint, ULVertexBuffer, ULIndexBuffer, void> UpdateGeometry;
public delegate* unmanaged[Cdecl]<uint, void> DestroyGeometry;
public delegate* unmanaged[Cdecl]<ULCommandList, void> UpdateCommandList;
#else
public void* BeginSynchronize, EndSynchronize, NextTextureId, CreateTexture, UpdateTexture, DestroyTexture, NextRenderBufferId, CreateRenderBuffer, DestroyRenderBuffer, NextGeometryId, CreateGeometry, UpdateGeometry, DestroyGeometry, UpdateCommandList;
#endif
}
}

public interface IGPUDriver : IDisposable
public interface IGPUDriver
{
uint NextTextureId();
void CreateTexture(uint textureId, ULBitmap bitmap);
Expand Down Expand Up @@ -145,12 +149,8 @@ public void Dispose()
foreach (var handle in handles) if (handle.IsAllocated) handle.Free();
}

try { instance.Dispose(); }
finally
{
GC.SuppressFinalize(this);
IsDisposed = true;
}
GC.SuppressFinalize(this);
IsDisposed = true;
}
~Wrapper() => Dispose();
}
Expand Down
14 changes: 7 additions & 7 deletions src/UltralightNet/Platform/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ namespace HighPerformance
/// </summary>
public unsafe struct ULLogger
{
#if !NETSTANDARD
public delegate* unmanaged[Cdecl]<ULLogLevel, ULString*, void> LogMessage;
#else
public void* LogMessage;
#endif
}
}
public interface ILogger : IDisposable
public interface ILogger
{
void LogMessage(ULLogLevel logLevel, string message);

Expand Down Expand Up @@ -56,12 +60,8 @@ public void Dispose()
if (IsDisposed) return;
if (handle.IsAllocated) handle.Free();

try { instance.Dispose(); }
finally
{
GC.SuppressFinalize(this);
IsDisposed = true;
}
GC.SuppressFinalize(this);
IsDisposed = true;
}
~Wrapper() => Dispose();
}
Expand Down
14 changes: 7 additions & 7 deletions src/UltralightNet/Platform/SurfaceDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace HighPerformance
/// </summary>
public unsafe struct ULSurfaceDefinition
{
#if !NETSTANDARD
public delegate* unmanaged[Cdecl]<uint, uint, nint> Create;
public delegate* unmanaged[Cdecl]<nint, void> Destroy;
public delegate* unmanaged[Cdecl]<nint, uint> GetWidth;
Expand All @@ -19,9 +20,12 @@ public unsafe struct ULSurfaceDefinition
public delegate* unmanaged[Cdecl]<nint, byte*> LockPixels;
public delegate* unmanaged[Cdecl]<nint, void> UnlockPixels;
public delegate* unmanaged[Cdecl]<nint, uint, uint, void> Resize;
#else
public void* Create, Destroy, GetWidth, GetHeight, GetRowBytes, GetSize, LockPixels, UnlockPixels, Resize;
#endif
}
}
public interface ISurfaceDefinition : IDisposable
public interface ISurfaceDefinition
{
nint Create(uint width, uint height);
void Destroy(nint id);
Expand Down Expand Up @@ -96,12 +100,8 @@ public void Dispose()
foreach (var handle in handles) if (handle.IsAllocated) handle.Free();
}

try { instance.Dispose(); }
finally
{
GC.SuppressFinalize(this);
IsDisposed = true;
}
GC.SuppressFinalize(this);
IsDisposed = true;
}
~Wrapper() => Dispose();
}
Expand Down
8 changes: 4 additions & 4 deletions src/UltralightNet/ULPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,13 @@ public static Renderer CreateRenderer(ULConfig config, bool dispose = true)
if (SetDefaultFileSystem && filesystemWrapper is null) FileSystem = config.ResourcePathPrefix is "resources/" ? DefaultFileSystem : throw new ArgumentException("Default file system supports only \"resources\" ResourcePathPrefix", nameof(config));
else if (ErrorMissingResources && filesystemWrapper is not null)
{
#if !NETSTANDARD
var path = config.ResourcePathPrefix + "icudt67l.dat";
using ULString str = new(path.AsSpan());
if (filesystemWrapper.NativeStruct.FileExists is null || !filesystemWrapper.NativeStruct.FileExists(&str)) throw new Exception($"{nameof(FileSystem)}.{nameof(IFileSystem.FileExists)}(\"{path}\") returned 'false'. {nameof(ULConfig)}.{nameof(ULConfig.ResourcePathPrefix)} + \"icudt67l.dat\" is required for Renderer creation. (Set {nameof(ULPlatform)}.{nameof(ErrorMissingResources)} to \'false\' to ignore this exception, however, be ready for unhandled crash.)");
#else
// throw new PlatformNotSupportedException("We're unable to check presence of required files on netstandard");
#endif
}

if (SetDefaultFontLoader && fontloaderWrapper is null) throw new Exception($"{nameof(FontLoader)} not set.");
Expand Down Expand Up @@ -118,8 +122,6 @@ private static void LogMessage(ULLogLevel logLevel, ULString* message)
ULLogger? ILogger.GetNativeStruct() => null;
#endif

void IDisposable.Dispose() { }

ref struct SpanEnumerator<T> where T : IEquatable<T>
{
ReadOnlySpan<T> span;
Expand Down Expand Up @@ -189,7 +191,5 @@ ULBuffer IFileSystem.OpenFile(string path)
#elif NETSTANDARD2_0
ULFileSystem? IFileSystem.GetNativeStruct() => null;
#endif

void IDisposable.Dispose() { }
}
}
10 changes: 8 additions & 2 deletions src/UltralightNet/ULSurface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,13 @@ public ULIntRect DirtyBounds

public nint Id => Methods.ulSurfaceGetUserData(Ptr);

public unsafe ULBitmap Bitmap => ULBitmap.FromHandle(Methods.ulBitmapSurfaceGetBitmap(Ptr), false);

public unsafe ULBitmap? Bitmap
{
get
{
var handle = Methods.ulBitmapSurfaceGetBitmap(Ptr);
return handle is not null ? ULBitmap.FromHandle(handle, false) : null;
}
}
internal static ULSurface FromHandle(nuint handle) => new(handle);
}

0 comments on commit f458820

Please sign in to comment.