Skip to content

Commit

Permalink
Expose IsAbandoned in the C# API (#1659)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattleibow committed Mar 15, 2021
1 parent 4229ffa commit 751bdf4
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
2 changes: 2 additions & 0 deletions binding/Binding/GRContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ public static GRContext CreateMetal (GRMtlBackendContext backendContext, GRConte

public GRBackend Backend => SkiaApi.gr_context_get_backend (Handle).FromNative ();

public bool IsAbandoned => SkiaApi.gr_context_is_abandoned (Handle);

public void AbandonContext (bool releaseResources = false)
{
if (releaseResources)
Expand Down
16 changes: 16 additions & 0 deletions binding/Binding/SkiaApi.generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,22 @@ private partial class Delegates {
(gr_context_get_resource_cache_usage_delegate ??= GetSymbol<Delegates.gr_context_get_resource_cache_usage> ("gr_context_get_resource_cache_usage")).Invoke (context, maxResources, maxResourceBytes);
#endif

// bool gr_context_is_abandoned(gr_context_t* context)
#if !USE_DELEGATES
[DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs (UnmanagedType.I1)]
internal static extern bool gr_context_is_abandoned (gr_context_t context);
#else
private partial class Delegates {
[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
[return: MarshalAs (UnmanagedType.I1)]
internal delegate bool gr_context_is_abandoned (gr_context_t context);
}
private static Delegates.gr_context_is_abandoned gr_context_is_abandoned_delegate;
internal static bool gr_context_is_abandoned (gr_context_t context) =>
(gr_context_is_abandoned_delegate ??= GetSymbol<Delegates.gr_context_is_abandoned> ("gr_context_is_abandoned")).Invoke (context);
#endif

// gr_context_t* gr_context_make_gl(const gr_glinterface_t* glInterface)
#if !USE_DELEGATES
[DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)]
Expand Down
2 changes: 1 addition & 1 deletion externals/skia
17 changes: 17 additions & 0 deletions tests/Tests/GRContextTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,23 @@ public void CreateDefaultContextIsValid()
}
}

[Trait(CategoryKey, GpuCategory)]
[SkippableFact]
public void AbandonContextIsAbandoned()
{
using (var ctx = CreateGlContext()) {
ctx.MakeCurrent();

var grContext = GRContext.CreateGl();

Assert.False(grContext.IsAbandoned);

grContext.AbandonContext();

Assert.True(grContext.IsAbandoned);
}
}

[Trait(CategoryKey, GpuCategory)]
[SkippableFact]
public void CreateDefaultContextWithOptionsIsValid()
Expand Down

0 comments on commit 751bdf4

Please sign in to comment.