Esempio n. 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="X11CursorFactory"/> class.
 /// </summary>
 /// <param name="display">The display.</param>
 public X11CursorFactory(IntPtr display)
 {
     _display    = display;
     _nullCursor = GetNullCursor(display);
     _cursors    = Enum.GetValues(typeof(CursorFontShape)).Cast <CursorFontShape>()
                   .ToDictionary(id => id, id => XLib.XCreateFontCursor(_display, id));
 }
Esempio n. 2
0
        /// <summary>
        /// Gets the null cursor.
        /// </summary>
        /// <param name="display">The display.</param>
        /// <returns>IntPtr.</returns>
        private static IntPtr GetNullCursor(IntPtr display)
        {
            XColor color  = new XColor();
            IntPtr window = XLib.XRootWindow(display, 0);
            IntPtr pixmap = XLib.XCreateBitmapFromData(display, window, NullCursorData, 1, 1);

            return(XLib.XCreatePixmapCursor(display, pixmap, pixmap, ref color, ref color, 0, 0));
        }
Esempio n. 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="X11PlatformThreading" /> class.
        /// </summary>
        /// <param name="platform">The platform.</param>
        /// <exception cref="IronyModManager.Platform.x11.X11Exception">epoll_create1 failed
        /// or
        /// Unable to attach X11 connection handle to epoll
        /// or
        /// Unable to attach signal pipe to epoll</exception>
        public X11PlatformThreading(AvaloniaX11Platform platform)
        {
            _platform      = platform;
            _display       = platform.Display;
            _eventHandlers = platform.Windows;
            _mainThread    = Thread.CurrentThread;
            var fd = XLib.XConnectionNumber(_display);
            var ev = new epoll_event()
            {
                events = EPOLLIN,
                data   = { u32 = (int)EventCodes.X11 }
            };

            _epoll = epoll_create1(0);
            if (_epoll == -1)
            {
                throw new X11Exception("epoll_create1 failed");
            }

            if (epoll_ctl(_epoll, EPOLL_CTL_ADD, fd, ref ev) == -1)
            {
                throw new X11Exception("Unable to attach X11 connection handle to epoll");
            }

            var fds = stackalloc int[2];

            pipe2(fds, O_NONBLOCK);
            _sigread  = fds[0];
            _sigwrite = fds[1];

            ev = new epoll_event
            {
                events = EPOLLIN,
                data   = { u32 = (int)EventCodes.Signal }
            };
            if (epoll_ctl(_epoll, EPOLL_CTL_ADD, _sigread, ref ev) == -1)
            {
                throw new X11Exception("Unable to attach signal pipe to epoll");
            }
        }
Esempio n. 4
0
        static public List <Monitor>?GetMonitorDevices()
        {
            List <Monitor>?result = null;

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                result = User32.GetMonitors();
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                result = XLib.GetMonitors();
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                result = AvFoundation.GetMonitors();
            }
            else
            {
                throw new NotSupportedException($"Cannot find adequate input format - OSArchitecture:[{RuntimeInformation.OSArchitecture}] - OSDescription:[{RuntimeInformation.OSDescription}]");
            }

            return(result);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="GlxDisplay" /> class.
        /// </summary>
        /// <param name="x11">The X11.</param>
        /// <exception cref="OpenGlException">Unable to choose FBConfig
        /// or
        /// Unable to get visual info from FBConfig
        /// or
        /// GL version string is null, aborting
        /// or
        /// GL renderer string is null, aborting
        /// or
        /// Renderer '{GlInterface.Renderer}' is blacklisted by '{item}'</exception>
        public GlxDisplay(X11Info x11)
        {
            _x11 = x11;

            var baseAttribs = new[]
            {
                GLX_X_RENDERABLE, 1,
                GLX_RENDER_TYPE, GLX_RGBA_BIT,
                GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT | GLX_PBUFFER_BIT,
                GLX_DOUBLEBUFFER, 1,
                GLX_RED_SIZE, 8,
                GLX_GREEN_SIZE, 8,
                GLX_BLUE_SIZE, 8,
                GLX_ALPHA_SIZE, 8,
                GLX_DEPTH_SIZE, 1,
                GLX_STENCIL_SIZE, 8,
            };

            foreach (var attribs in new[]
            {
                //baseAttribs.Concat(multiattribs),
                baseAttribs,
            })
            {
                var ptr = Glx.ChooseFBConfig(_x11.Display, x11.DefaultScreen,
                                             attribs, out var count);
                for (var c = 0; c < count; c++)
                {
                    var visual = Glx.GetVisualFromFBConfig(_x11.Display, ptr[c]);
                    // We prefer 32 bit visuals
                    if (_fbconfig == IntPtr.Zero || visual->depth == 32)
                    {
                        _fbconfig  = ptr[c];
                        VisualInfo = visual;
                        if (visual->depth == 32)
                        {
                            break;
                        }
                    }
                }

                if (_fbconfig != IntPtr.Zero)
                {
                    break;
                }
            }

            if (_fbconfig == IntPtr.Zero)
            {
                throw new OpenGlException("Unable to choose FBConfig");
            }

            if (VisualInfo == null)
            {
                throw new OpenGlException("Unable to get visual info from FBConfig");
            }
            if (Glx.GetFBConfigAttrib(_x11.Display, _fbconfig, GLX_SAMPLES, out var samples) == 0)
            {
                SampleCount = samples;
            }
            if (Glx.GetFBConfigAttrib(_x11.Display, _fbconfig, GLX_STENCIL_SIZE, out var stencil) == 0)
            {
                StencilSize = stencil;
            }

            var pbuffers = Enumerable.Range(0, 2).Select(_ => Glx.CreatePbuffer(_x11.Display, _fbconfig, new[]
            {
                GLX_PBUFFER_WIDTH, 1, GLX_PBUFFER_HEIGHT, 1, 0
            })).ToList();

            XLib.XFlush(_x11.Display);

            ImmediateContext = CreateContext(pbuffers[0], null);
            DeferredContext  = CreateContext(pbuffers[1], ImmediateContext);
            ImmediateContext.MakeCurrent();
            var err = Glx.GetError();

            GlInterface = new GlInterface(GlxInterface.SafeGetProcAddress);
            if (GlInterface.Version == null)
            {
                throw new OpenGlException("GL version string is null, aborting");
            }
            if (GlInterface.Renderer == null)
            {
                throw new OpenGlException("GL renderer string is null, aborting");
            }

            if (Environment.GetEnvironmentVariable("AVALONIA_GLX_IGNORE_RENDERER_BLACKLIST") != "1")
            {
                var blacklist = AvaloniaLocator.Current.GetService <X11PlatformOptions>()
                                ?.GlxRendererBlacklist;
                if (blacklist != null)
                {
                    foreach (var item in blacklist)
                    {
                        if (GlInterface.Renderer.Contains(item))
                        {
                            throw new OpenGlException($"Renderer '{GlInterface.Renderer}' is blacklisted by '{item}'");
                        }
                    }
                }
            }
        }
        public GlxDisplay(X11Info x11, IList <GlVersion> probeProfiles)
        {
            _x11               = x11;
            _probeProfiles     = probeProfiles.ToArray();
            _displayExtensions = Glx.GetExtensions(_x11.Display);

            var baseAttribs = new[]
            {
                GLX_X_RENDERABLE, 1,
                GLX_RENDER_TYPE, GLX_RGBA_BIT,
                GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT | GLX_PBUFFER_BIT,
                GLX_DOUBLEBUFFER, 1,
                GLX_RED_SIZE, 8,
                GLX_GREEN_SIZE, 8,
                GLX_BLUE_SIZE, 8,
                GLX_ALPHA_SIZE, 8,
                GLX_DEPTH_SIZE, 1,
                GLX_STENCIL_SIZE, 8,
            };
            int sampleCount = 0;
            int stencilSize = 0;

            foreach (var attribs in new[]
            {
                //baseAttribs.Concat(multiattribs),
                baseAttribs,
            })
            {
                var ptr = Glx.ChooseFBConfig(_x11.Display, x11.DefaultScreen,
                                             attribs, out var count);
                for (var c = 0; c < count; c++)
                {
                    var visual = Glx.GetVisualFromFBConfig(_x11.Display, ptr[c]);
                    // We prefer 32 bit visuals
                    if (_fbconfig == IntPtr.Zero || visual->depth == 32)
                    {
                        _fbconfig = ptr[c];
                        _visual   = visual;
                        if (visual->depth == 32)
                        {
                            break;
                        }
                    }
                }

                if (_fbconfig != IntPtr.Zero)
                {
                    break;
                }
            }

            if (_fbconfig == IntPtr.Zero)
            {
                throw new OpenGlException("Unable to choose FBConfig");
            }

            if (_visual == null)
            {
                throw new OpenGlException("Unable to get visual info from FBConfig");
            }
            if (Glx.GetFBConfigAttrib(_x11.Display, _fbconfig, GLX_SAMPLES, out var samples) == 0)
            {
                sampleCount = samples;
            }
            if (Glx.GetFBConfigAttrib(_x11.Display, _fbconfig, GLX_STENCIL_SIZE, out var stencil) == 0)
            {
                stencilSize = stencil;
            }

            var attributes = new[] { GLX_PBUFFER_WIDTH, 1, GLX_PBUFFER_HEIGHT, 1, 0 };

            Glx.CreatePbuffer(_x11.Display, _fbconfig, attributes);
            Glx.CreatePbuffer(_x11.Display, _fbconfig, attributes);

            XLib.XFlush(_x11.Display);

            DeferredContext = CreateContext(CreatePBuffer(), null,
                                            sampleCount, stencilSize, true);
            using (DeferredContext.MakeCurrent())
            {
                var glInterface = DeferredContext.GlInterface;
                if (glInterface.Version == null)
                {
                    throw new OpenGlException("GL version string is null, aborting");
                }
                if (glInterface.Renderer == null)
                {
                    throw new OpenGlException("GL renderer string is null, aborting");
                }

                if (Environment.GetEnvironmentVariable("AVALONIA_GLX_IGNORE_RENDERER_BLACKLIST") != "1")
                {
                    var opts      = AvaloniaLocator.Current.GetService <X11PlatformOptions>() ?? new X11PlatformOptions();
                    var blacklist = opts.GlxRendererBlacklist;
                    if (blacklist != null)
                    {
                        foreach (var item in blacklist)
                        {
                            if (glInterface.Renderer.Contains(item))
                            {
                                throw new OpenGlException(
                                          $"Renderer '{glInterface.Renderer}' is blacklisted by '{item}'");
                            }
                        }
                    }
                }
            }
        }
Esempio n. 7
0
 /// <summary>
 /// Initializes this instance.
 /// </summary>
 public static void Init()
 {
     XLib.XSetErrorHandler(s_errorHandlerDelegate);
 }
Esempio n. 8
0
        public GlxDisplay(X11Info x11)
        {
            _x11 = x11;

            var baseAttribs = new[]
            {
                GLX_X_RENDERABLE, 1,
                GLX_RENDER_TYPE, GLX_RGBA_BIT,
                GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT | GLX_PBUFFER_BIT,
                GLX_DOUBLEBUFFER, 1,
                GLX_RED_SIZE, 8,
                GLX_GREEN_SIZE, 8,
                GLX_BLUE_SIZE, 8,
                GLX_ALPHA_SIZE, 8,
                GLX_DEPTH_SIZE, 1,
                GLX_STENCIL_SIZE, 8,
            };

            foreach (var attribs in new[]
            {
                //baseAttribs.Concat(multiattribs),
                baseAttribs,
            })
            {
                var ptr = Glx.ChooseFBConfig(_x11.Display, x11.DefaultScreen,
                                             attribs, out var count);
                for (var c = 0; c < count; c++)
                {
                    var visual = Glx.GetVisualFromFBConfig(_x11.Display, ptr[c]);
                    // We prefer 32 bit visuals
                    if (_fbconfig == IntPtr.Zero || visual->depth == 32)
                    {
                        _fbconfig = ptr[c];
                        _visual   = visual;
                        if (visual->depth == 32)
                        {
                            break;
                        }
                    }
                }

                if (_fbconfig != IntPtr.Zero)
                {
                    break;
                }
            }

            if (_fbconfig == IntPtr.Zero)
            {
                throw new OpenGlException("Unable to choose FBConfig");
            }

            if (_visual == null)
            {
                throw new OpenGlException("Unable to get visual info from FBConfig");
            }
            if (Glx.GetFBConfigAttrib(_x11.Display, _fbconfig, GLX_SAMPLES, out var samples) == 0)
            {
                SampleCount = samples;
            }
            if (Glx.GetFBConfigAttrib(_x11.Display, _fbconfig, GLX_STENCIL_SIZE, out var stencil) == 0)
            {
                StencilSize = stencil;
            }

            var pbuffers = Enumerable.Range(0, 2).Select(_ => Glx.CreatePbuffer(_x11.Display, _fbconfig, new[]
            {
                GLX_PBUFFER_WIDTH, 1, GLX_PBUFFER_HEIGHT, 1, 0
            })).ToList();

            XLib.XFlush(_x11.Display);

            ImmediateContext = CreateContext(pbuffers[0], null);
            DeferredContext  = CreateContext(pbuffers[1], ImmediateContext);
            ImmediateContext.MakeCurrent();
            var err = Glx.GetError();

            GlInterface = new GlInterface(GlxInterface.GlxGetProcAddress);
            if (GlInterface.Version == null)
            {
                throw new OpenGlException("GL version string is null, aborting");
            }
        }