Fixed unit tests crashes and a WGL deadlock (#1228 for master) (#1237)

This commit is contained in:
Matthew Leibowitz 2020-04-22 12:52:59 +02:00 коммит произвёл GitHub
Родитель 2550d14410
Коммит 0195b18746
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
6 изменённых файлов: 15 добавлений и 11 удалений

Просмотреть файл

@ -39,7 +39,7 @@ namespace SkiaSharp
/// Retrieve or create an instance for the native handle.
/// </summary>
/// <returns>The instance, or null if the handle was null.</returns>
internal static TSkiaObject GetOrAddObject<TSkiaObject> (IntPtr handle, bool owns, bool unrefExisting, bool refNew, Func<IntPtr, bool, TSkiaObject> objectFactory)
internal static TSkiaObject GetOrAddObject<TSkiaObject> (IntPtr handle, bool owns, bool unrefExisting, Func<IntPtr, bool, TSkiaObject> objectFactory)
where TSkiaObject : SKObject
{
if (handle == IntPtr.Zero)
@ -65,8 +65,6 @@ namespace SkiaSharp
var obj = objectFactory.Invoke (handle, owns);
if (refNew && obj is ISKReferenceCounted toRef)
toRef.SafeRef ();
return obj;
} finally {
instancesLock.ExitUpgradeableReadLock ();

Просмотреть файл

@ -992,7 +992,7 @@ namespace SkiaSharp
}
internal static SKCanvas GetObject (IntPtr handle, bool owns = true, bool unrefExisting = true) =>
GetOrAddObject (handle, owns, unrefExisting, false, (h, o) => new SKCanvas (h, o));
GetOrAddObject (handle, owns, unrefExisting, (h, o) => new SKCanvas (h, o));
}
public class SKAutoCanvasRestore : IDisposable

Просмотреть файл

@ -179,7 +179,7 @@ namespace SkiaSharp
//
internal static SKColorSpace GetObject (IntPtr handle, bool owns = true, bool unrefExisting = true) =>
GetOrAddObject (handle, owns, unrefExisting, false, (h, o) => new SKColorSpace (h, o));
GetOrAddObject (handle, owns, unrefExisting, (h, o) => new SKColorSpace (h, o));
private sealed class SKColorSpaceStatic : SKColorSpace
{

Просмотреть файл

@ -86,7 +86,7 @@ namespace SkiaSharp
if (handle == IntPtr.Zero)
return null;
return HandleDictionary.GetOrAddObject (handle, true, true, false, objectFactory);
return HandleDictionary.GetOrAddObject (handle, true, true, objectFactory);
}
internal static TSkiaObject GetOrAddObject<TSkiaObject> (IntPtr handle, bool owns, Func<IntPtr, bool, TSkiaObject> objectFactory)
@ -95,16 +95,16 @@ namespace SkiaSharp
if (handle == IntPtr.Zero)
return null;
return HandleDictionary.GetOrAddObject (handle, owns, true, false, objectFactory);
return HandleDictionary.GetOrAddObject (handle, owns, true, objectFactory);
}
internal static TSkiaObject GetOrAddObject<TSkiaObject> (IntPtr handle, bool owns, bool unrefExisting, bool refNew, Func<IntPtr, bool, TSkiaObject> objectFactory)
internal static TSkiaObject GetOrAddObject<TSkiaObject> (IntPtr handle, bool owns, bool unrefExisting, Func<IntPtr, bool, TSkiaObject> objectFactory)
where TSkiaObject : SKObject
{
if (handle == IntPtr.Zero)
return null;
return HandleDictionary.GetOrAddObject (handle, owns, unrefExisting, refNew, objectFactory);
return HandleDictionary.GetOrAddObject (handle, owns, unrefExisting, objectFactory);
}
internal static void RegisterHandle (IntPtr handle, SKObject instance)

Просмотреть файл

@ -40,6 +40,6 @@ namespace SkiaSharp
//
internal static SKPicture GetObject (IntPtr handle, bool owns = true, bool unrefExisting = true) =>
GetOrAddObject (handle, owns, unrefExisting, false, (h, o) => new SKPicture (h, o));
GetOrAddObject (handle, owns, unrefExisting, (h, o) => new SKPicture (h, o));
}
}

Просмотреть файл

@ -7,6 +7,8 @@ namespace SkiaSharp.Tests
{
internal class WglContext : GlContext
{
private static readonly object fLock = new object();
private static ushort gWC;
private static IntPtr fWindow;
@ -82,7 +84,11 @@ namespace SkiaSharp.Tests
};
var piFormats = new int[1];
uint nFormats;
Wgl.wglChoosePixelFormatARB(fDeviceContext, iAttrs, null, (uint)piFormats.Length, piFormats, out nFormats);
lock (fLock)
{
// HACK: This call seems to cause deadlocks on some systems.
Wgl.wglChoosePixelFormatARB(fDeviceContext, iAttrs, null, (uint)piFormats.Length, piFormats, out nFormats);
}
if (nFormats == 0)
{
Destroy();