private DeferredState _Reducer(DeferredState state, DeferredContext context) { Func<object> action = null; switch (context.ContextType) { case ContextType.Then: if (state.Reason != null) { if (context.Reject != null) { action = () => context.Reject(state.Reason); } } else if (context.Fulfill != null) { action = () => context.Fulfill(state.Value); } break; case ContextType.Catch: if (state.Reason != null) { action = () => context.Reject(state.Reason); } break; case ContextType.Finally: action = () => context.Fulfill(state.Value); break; } if (action == null) { return state; } object result = null; try { result = action(); } catch (Exception ex) { return new DeferredState(ex); } if (result is Promise) { Promise p = result as Promise; } }
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}'"); } } } } } }