Added a test for assembling the GL interface
This commit is contained in:
Родитель
11a48f65cd
Коммит
8a1149a140
|
@ -20,5 +20,57 @@ namespace SkiaSharp.Tests
|
|||
Assert.True(glInterface.Validate());
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AssembleInterfaceIsValid()
|
||||
{
|
||||
using (var ctx = CreateGlContext()) {
|
||||
ctx.MakeCurrent();
|
||||
|
||||
if (IsMac) {
|
||||
var lib = MacDynamicLibraries.dlopen("/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib", 1);
|
||||
|
||||
var glInterface = GRGlInterface.AssembleGlInterface((context, name) => {
|
||||
return MacDynamicLibraries.dlsym(lib, name);
|
||||
});
|
||||
|
||||
Assert.NotNull(glInterface);
|
||||
Assert.True(glInterface.Validate());
|
||||
|
||||
MacDynamicLibraries.dlclose(lib);
|
||||
} else if (IsWindows) {
|
||||
var lib = WindowsDynamicLibraries.LoadLibrary("opengl32.dll");
|
||||
|
||||
var glInterface = GRGlInterface.AssembleGlInterface((context, name) => {
|
||||
var ptr = WindowsDynamicLibraries.GetProcAddress(lib, name);
|
||||
if (ptr == IntPtr.Zero) {
|
||||
ptr = wglGetProcAddress(name);
|
||||
}
|
||||
return ptr;
|
||||
});
|
||||
|
||||
Assert.NotNull(glInterface);
|
||||
Assert.True(glInterface.Validate());
|
||||
|
||||
WindowsDynamicLibraries.FreeLibrary(lib);
|
||||
} else if (IsLinux) {
|
||||
var lib = LinuxDynamicLibraries.dlopen("libGL.so.1", 1);
|
||||
|
||||
var glInterface = GRGlInterface.AssembleGlInterface((context, name) => {
|
||||
return LinuxDynamicLibraries.dlsym(lib, name);
|
||||
});
|
||||
|
||||
Assert.NotNull(glInterface);
|
||||
Assert.True(glInterface.Validate());
|
||||
|
||||
LinuxDynamicLibraries.dlclose(lib);
|
||||
} else {
|
||||
// more platforms !!!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[DllImport("opengl32.dll", CallingConvention = CallingConvention.Winapi)]
|
||||
public static extern IntPtr wglGetProcAddress([MarshalAs(UnmanagedType.LPStr)] string lpszProc);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,6 +53,39 @@ namespace SkiaSharp.Tests
|
|||
protected static bool IsWindows => !IsUnix;
|
||||
#endif
|
||||
|
||||
public static class MacDynamicLibraries
|
||||
{
|
||||
private const string SystemLibrary = "/usr/lib/libSystem.dylib";
|
||||
[DllImport(SystemLibrary)]
|
||||
public static extern IntPtr dlopen(string path, int mode);
|
||||
[DllImport(SystemLibrary)]
|
||||
public static extern IntPtr dlsym(IntPtr handle, string symbol);
|
||||
[DllImport(SystemLibrary)]
|
||||
public static extern void dlclose(IntPtr handle);
|
||||
}
|
||||
|
||||
public static class LinuxDynamicLibraries
|
||||
{
|
||||
private const string SystemLibrary = "libdl.so";
|
||||
[DllImport(SystemLibrary)]
|
||||
public static extern IntPtr dlopen(string path, int mode);
|
||||
[DllImport(SystemLibrary)]
|
||||
public static extern IntPtr dlsym(IntPtr handle, string symbol);
|
||||
[DllImport(SystemLibrary)]
|
||||
public static extern void dlclose(IntPtr handle);
|
||||
}
|
||||
|
||||
public static class WindowsDynamicLibraries
|
||||
{
|
||||
private const string SystemLibrary = "Kernel32.dll";
|
||||
[DllImport (SystemLibrary, SetLastError = true, CharSet = CharSet.Ansi)]
|
||||
public static extern IntPtr LoadLibrary(string lpFileName);
|
||||
[DllImport (SystemLibrary, SetLastError = true, CharSet = CharSet.Ansi)]
|
||||
public static extern IntPtr GetProcAddress(IntPtr hModule, string lpProcName);
|
||||
[DllImport (SystemLibrary, SetLastError = true, CharSet = CharSet.Ansi)]
|
||||
public static extern void FreeLibrary(IntPtr hModule);
|
||||
}
|
||||
|
||||
protected GlContext CreateGlContext()
|
||||
{
|
||||
if (IsLinux) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче