<commit_before>﻿using System;
using Avalonia.Platform;
using Avalonia.Platform.Interop;

namespace Avalonia.OpenGL
{
    public class EglInterface : GlInterfaceBase
    {
        public EglInterface() : base(Load())
        {
            
        }
        
        public EglInterface(string library) : base(Load(library))
        {
        }

        static Func<string, bool, IntPtr> Load()
        {
            var os = AvaloniaLocator.Current.GetService<IRuntimePlatform>().GetRuntimeInfo().OperatingSystem;
            if(os == OperatingSystemType.Linux || os == OperatingSystemType.Android)
                return Load("libEGL.so.1");
            if (os == OperatingSystemType.WinNT)
                return Load(@"libegl.dll");
            throw new PlatformNotSupportedException();
        }

        static Func<string, bool, IntPtr> Load(string library)
        {
            var dyn = AvaloniaLocator.Current.GetService<IDynamicLibraryLoader>();
            var lib = dyn.LoadLibrary(library);
            return (s, o) => dyn.GetProcAddress(lib, s, o);
        }

        // ReSharper disable UnassignedGetOnlyAutoProperty
        public delegate int EglGetError();
        [GlEntryPoint("eglGetError")]
        public EglGetError GetError { get; }

        public delegate IntPtr EglGetDisplay(IntPtr nativeDisplay);
        [GlEntryPoint("eglGetDisplay")]
        public EglGetDisplay GetDisplay { get; }<commit_msg>[Win32] Use a proper DllImport for libegl.dll<commit_after>﻿using System;
using System.Runtime.InteropServices;
using Avalonia.Platform;
using Avalonia.Platform.Interop;

namespace Avalonia.OpenGL
{
    public class EglInterface : GlInterfaceBase
    {
        public EglInterface() : base(Load())
        {
            
        }
        
        public EglInterface(string library) : base(Load(library))
        {
        }

        [DllImport("libegl.dll", CharSet = CharSet.Ansi)]
        static extern IntPtr eglGetProcAddress(string proc);
        
        static Func<string, bool, IntPtr> Load()
        {
            var os = AvaloniaLocator.Current.GetService<IRuntimePlatform>().GetRuntimeInfo().OperatingSystem;
            if(os == OperatingSystemType.Linux || os == OperatingSystemType.Android)
                return Load("libEGL.so.1");
            if (os == OperatingSystemType.WinNT)
            {
                var disp = eglGetProcAddress("eglGetPlatformDisplayEXT");
                if (disp == IntPtr.Zero)
                    throw new OpenGlException("libegl.dll doesn't have eglGetPlatformDisplayEXT entry point");
                return (name, optional) =>
                {
                    var r = eglGetProcAddress(name);
                    if (r == IntPtr.Zero && !optional)
                        throw new OpenGlException($"Entry point {r} is not found");
                    return r;
                };
            }

            throw new PlatformNotSupportedException();
        }

        static Func<string, bool, IntPtr> Load(string library)
        {
            var dyn = AvaloniaLocator.Current.GetService<IDynamicLibraryLoader>();
            var lib = dyn.LoadLibrary(library);
            return (s, o) => dyn.GetProcAddress(lib, s, o);
        }

        // ReSharper disable UnassignedGetOnlyAutoProperty
        public delegate int EglGetError();
        [GlEntryPoint("eglGetError")]
        public EglGetError GetError { get; }

        public delegate IntPtr EglGetDisplay(IntPtr nativeDisplay);
        [GlEntryPoint("eglGetDisplay")]
        public EglGetDisplay GetDisplay { get; }
{'fraction_non_alphanumeric': 0.09655751469353484, 'fraction_numerical': 0.001119507416736636, 'mean_word_length': 2.126859142607174, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1991357', 'n_tokens_mistral': 988, 'n_tokens_neox': 949, 'n_words': 210}