public static void Initialize() { AvaloniaLocator.CurrentMutable.Bind <IPlatformOpenGlInterface>().ToLazy <IPlatformOpenGlInterface>(() => { var opts = AvaloniaLocator.Current.GetService <Win32PlatformOptions>(); if (opts?.UseWgl == true) { var wgl = WglPlatformOpenGlInterface.TryCreate(); return(wgl); } if (opts?.AllowEglInitialization == true) { var egl = EglPlatformOpenGlInterface.TryCreate(() => new AngleWin32EglDisplay()); if (egl is { } && opts?.UseWindowsUIComposition == true && Win32Platform.WindowsVersion.Major >= 10 && Win32Platform.WindowsVersion.Build >= 16299) { AvaloniaLocator.CurrentMutable.BindToSelf(new CompositionConnector(egl)); } return(egl); }
public static void Initialize() { Options = AvaloniaLocator.Current.GetService <AndroidPlatformOptions>() ?? new AndroidPlatformOptions(); AvaloniaLocator.CurrentMutable .Bind <IClipboard>().ToTransient <ClipboardImpl>() .Bind <ICursorFactory>().ToTransient <CursorFactory>() .Bind <IWindowingPlatform>().ToConstant(new WindowingPlatformStub()) .Bind <IKeyboardDevice>().ToSingleton <AndroidKeyboardDevice>() .Bind <IPlatformSettings>().ToConstant(Instance) .Bind <IPlatformThreadingInterface>().ToConstant(new AndroidThreadingInterface()) .Bind <IPlatformIconLoader>().ToSingleton <PlatformIconLoaderStub>() .Bind <IRenderTimer>().ToConstant(new ChoreographerTimer()) .Bind <IRenderLoop>().ToConstant(new RenderLoop()) .Bind <PlatformHotkeyConfiguration>().ToSingleton <PlatformHotkeyConfiguration>(); if (Options.UseGpu) { EglPlatformOpenGlInterface.TryInitialize(); } if (Options.UseCompositor) { Compositor = new Compositor( AvaloniaLocator.Current.GetRequiredService <IRenderLoop>(), AvaloniaLocator.Current.GetService <IPlatformOpenGlInterface>()); } }
public static void Initialize() { AvaloniaLocator.CurrentMutable.Bind <IPlatformOpenGlInterface>().ToLazy <IPlatformOpenGlInterface>(() => { var opts = AvaloniaLocator.Current.GetService <Win32PlatformOptions>(); if (opts?.UseWgl == true) { var wgl = WglPlatformOpenGlInterface.TryCreate(); return(wgl); } if (opts?.AllowEglInitialization ?? Win32Platform.WindowsVersion > Windows7) { var egl = EglPlatformOpenGlInterface.TryCreate(() => new AngleWin32EglDisplay()); if (egl != null && opts?.UseWindowsUIComposition == true) { WinUICompositorConnection.TryCreateAndRegister(egl); } return(egl); } return(null); }); }
public static void Initialize(Type appType, AndroidPlatformOptions options) { AvaloniaLocator.CurrentMutable .Bind <IClipboard>().ToTransient <ClipboardImpl>() .Bind <IStandardCursorFactory>().ToTransient <CursorFactory>() .Bind <IKeyboardDevice>().ToSingleton <AndroidKeyboardDevice>() .Bind <IPlatformSettings>().ToConstant(Instance) .Bind <IPlatformThreadingInterface>().ToConstant(new AndroidThreadingInterface()) .Bind <ISystemDialogImpl>().ToTransient <SystemDialogImpl>() .Bind <IWindowingPlatform>().ToConstant(Instance) .Bind <IPlatformIconLoader>().ToSingleton <PlatformIconLoader>() .Bind <IRenderTimer>().ToConstant(new DefaultRenderTimer(60)) .Bind <IRenderLoop>().ToConstant(new RenderLoop()) .Bind <PlatformHotkeyConfiguration>().ToSingleton <PlatformHotkeyConfiguration>() .Bind <IAssetLoader>().ToConstant(new AssetLoader(appType.Assembly)); SkiaPlatform.Initialize(); ((global::Android.App.Application)global::Android.App.Application.Context.ApplicationContext) .RegisterActivityLifecycleCallbacks(new ActivityTracker()); if (options.UseGpu) { EglPlatformOpenGlInterface.TryInitialize(); } }
public static void Initialize(Type appType, AndroidPlatformOptions options) { Options = options; AvaloniaLocator.CurrentMutable .Bind <IClipboard>().ToTransient <ClipboardImpl>() .Bind <ICursorFactory>().ToTransient <CursorFactory>() .Bind <IWindowingPlatform>().ToConstant(new WindowingPlatformStub()) .Bind <IKeyboardDevice>().ToSingleton <AndroidKeyboardDevice>() .Bind <IPlatformSettings>().ToConstant(Instance) .Bind <IPlatformThreadingInterface>().ToConstant(new AndroidThreadingInterface()) .Bind <ISystemDialogImpl>().ToTransient <SystemDialogImpl>() .Bind <IPlatformIconLoader>().ToSingleton <PlatformIconLoaderStub>() .Bind <IRenderTimer>().ToConstant(new ChoreographerTimer()) .Bind <IRenderLoop>().ToConstant(new RenderLoop()) .Bind <PlatformHotkeyConfiguration>().ToSingleton <PlatformHotkeyConfiguration>() .Bind <IAssetLoader>().ToConstant(new AssetLoader(appType.Assembly)); SkiaPlatform.Initialize(); if (options.UseGpu) { EglPlatformOpenGlInterface.TryInitialize(); } }
public static void TryCreateAndRegister(EglPlatformOpenGlInterface angle, float?backdropCornerRadius) { const int majorRequired = 10; const int buildRequired = 17134; var majorInstalled = Win32Platform.WindowsVersion.Major; var buildInstalled = Win32Platform.WindowsVersion.Build; if (majorInstalled >= majorRequired && buildInstalled >= buildRequired) { try { TryCreateAndRegisterCore(angle, backdropCornerRadius); return; } catch (Exception e) { Logger.TryGet(LogEventLevel.Error, "WinUIComposition") ?.Log(null, "Unable to initialize WinUI compositor: {0}", e); } } var osVersionNotice = $"Windows {majorRequired} Build {buildRequired} is required. Your machine has Windows {majorInstalled} Build {buildInstalled} installed."; Logger.TryGet(LogEventLevel.Warning, "WinUIComposition")?.Log(null, $"Unable to initialize WinUI compositor: {osVersionNotice}"); }
public static CompositionConnector TryCreate(EglPlatformOpenGlInterface egl) { const int majorRequired = 10; const int buildRequired = 16299; var majorInstalled = Win32Platform.WindowsVersion.Major; var buildInstalled = Win32Platform.WindowsVersion.Build; if (majorInstalled >= majorRequired && buildInstalled >= buildRequired) { try { return(new CompositionConnector(egl)); } catch (Exception e) { Logger.TryGet(LogEventLevel.Error, "WinUIComposition")?.Log(null, "Unable to initialize WinUI compositor: {0}", e); return(null); } } var osVersionNotice = $"Windows {majorRequired} Build {buildRequired} is required. Your machine has Windows {majorInstalled} Build {buildInstalled} installed."; Logger.TryGet(LogEventLevel.Warning, "WinUIComposition")?.Log(null, $"Unable to initialize WinUI compositor: {osVersionNotice}"); return(null); }
static bool TryCreateAndRegisterCore(EglPlatformOpenGlInterface angle, float?backdropCornerRadius) { var tcs = new TaskCompletionSource <bool>(); var pumpLock = new object(); var th = new Thread(() => { WinUICompositorConnection connect; try { NativeWinRTMethods.CreateDispatcherQueueController(new NativeWinRTMethods.DispatcherQueueOptions { apartmentType = NativeWinRTMethods.DISPATCHERQUEUE_THREAD_APARTMENTTYPE.DQTAT_COM_NONE, dwSize = Marshal.SizeOf <NativeWinRTMethods.DispatcherQueueOptions>(), threadType = NativeWinRTMethods.DISPATCHERQUEUE_THREAD_TYPE.DQTYPE_THREAD_CURRENT }); connect = new WinUICompositorConnection(angle, pumpLock, backdropCornerRadius); AvaloniaLocator.CurrentMutable.BindToSelf(connect); AvaloniaLocator.CurrentMutable.Bind <IRenderTimer>().ToConstant(connect); tcs.SetResult(true); } catch (Exception e) { tcs.SetException(e); return; } connect.RunLoop(); }) { IsBackground = true }; th.SetApartmentState(ApartmentState.STA); th.Start(); return(tcs.Task.Result); }
public EglSurface WrapDirect3D11Texture(EglPlatformOpenGlInterface egl, IntPtr handle, int offsetX, int offsetY, int width, int height) { if (PlatformApi != AngleOptions.PlatformApi.DirectX11) { throw new InvalidOperationException("Current platform API is " + PlatformApi); } return(egl.CreatePBufferFromClientBuffer(EGL_D3D_TEXTURE_ANGLE, handle, new[] { EGL_WIDTH, width, EGL_HEIGHT, height, EGL_FLEXIBLE_SURFACE_COMPATIBILITY_SUPPORTED_ANGLE, EGL_TRUE, EGL_TEXTURE_OFFSET_X_ANGLE, offsetX, EGL_TEXTURE_OFFSET_Y_ANGLE, offsetY, EGL_NONE })); }
public EglSurface WrapDirect3D11Texture(EglPlatformOpenGlInterface egl, IntPtr handle) { if (PlatformApi != AngleOptions.PlatformApi.DirectX11) { throw new InvalidOperationException("Current platform API is " + PlatformApi); } return(egl.CreatePBufferFromClientBuffer(EGL_D3D_TEXTURE_ANGLE, handle, new[] { EGL_NONE, EGL_NONE })); }
public static GlPlatformSurface TryCreate(IEglWindowGlPlatformSurfaceInfo info) { if (EglPlatformOpenGlInterface.TryCreate() is EglPlatformOpenGlInterface egl) { return(new GlPlatformSurface(egl, info)); } return(null); }
public GlRenderTarget( EglPlatformOpenGlInterface egl, EglGlPlatformSurfaceBase.IEglWindowGlPlatformSurfaceInfo info, EglSurface surface) : base(egl) { _info = info; _surface = surface; }
public void Initialize(X11PlatformOptions options) { Options = options; XInitThreads(); Display = XOpenDisplay(IntPtr.Zero); DeferredDisplay = XOpenDisplay(IntPtr.Zero); OrphanedWindow = XCreateSimpleWindow(Display, XDefaultRootWindow(Display), 0, 0, 1, 1, 0, IntPtr.Zero, IntPtr.Zero); if (Display == IntPtr.Zero) { throw new Exception("XOpenDisplay failed"); } XError.Init(); Info = new X11Info(Display, DeferredDisplay); Globals = new X11Globals(this); //TODO: log if (options.UseDBusMenu) { DBusHelper.TryInitialize(); } AvaloniaLocator.CurrentMutable.BindToSelf(this) .Bind <IWindowingPlatform>().ToConstant(this) .Bind <IPlatformThreadingInterface>().ToConstant(new X11PlatformThreading(this)) .Bind <IRenderTimer>().ToConstant(new SleepLoopRenderTimer(60)) .Bind <IRenderLoop>().ToConstant(new RenderLoop()) .Bind <PlatformHotkeyConfiguration>().ToConstant(new PlatformHotkeyConfiguration(KeyModifiers.Control)) .Bind <IKeyboardDevice>().ToFunc(() => KeyboardDevice) .Bind <IStandardCursorFactory>().ToConstant(new X11CursorFactory(Display)) .Bind <IClipboard>().ToConstant(new X11Clipboard(this)) .Bind <IPlatformSettings>().ToConstant(new PlatformSettingsStub()) .Bind <IPlatformIconLoader>().ToConstant(new X11IconLoader(Info)) .Bind <ISystemDialogImpl>().ToConstant(new GtkSystemDialog()) .Bind <IMountedVolumeInfoProvider>().ToConstant(new LinuxMountedVolumeInfoProvider()); X11Screens = Avalonia.X11.X11Screens.Init(this); Screens = new X11Screens(X11Screens); if (Info.XInputVersion != null) { var xi2 = new XI2Manager(); if (xi2.Init(this)) { XI2 = xi2; } } if (options.UseGpu) { if (options.UseEGL) { EglPlatformOpenGlInterface.TryInitialize(); } else { GlxPlatformOpenGlInterface.TryInitialize(Info, Options.GlProfiles); } } }
public CompositionRenderTarget(EglPlatformOpenGlInterface egl, IRef <WinUICompositedWindow> window, IEglWindowGlPlatformSurfaceInfo info) : base(egl) { _egl = egl; _window = window.Clone(); _info = info; _window.Item.ResizeIfNeeded(_info.Size); }
public static void Initialize() { AvaloniaLocator.CurrentMutable.Bind <IPlatformOpenGlInterface>().ToFunc(() => { if (!s_attemptedToInitialize) { EglPlatformInterface = EglPlatformOpenGlInterface.TryCreate(() => new AngleWin32EglDisplay()); s_attemptedToInitialize = true; } return(EglPlatformInterface); }); }
public CompositionConnector(EglPlatformOpenGlInterface egl) { EnsureDispatcherQueue(); if (_dispatcherQueueController != null) { _compositor = new Compositor(); } var interop = _compositor.As <ICompositorInterop>(); var display = egl.Display as AngleWin32EglDisplay; _graphicsDevice = interop.CreateGraphicsDevice(display.GetDirect3DDevice()); }
public WinUICompositorConnection(EglPlatformOpenGlInterface gl, object pumpLock) { _gl = gl; _pumpLock = pumpLock; _syncContext = _gl.PrimaryEglContext; _angle = (AngleWin32EglDisplay)_gl.Display; _compositor = NativeWinRTMethods.CreateInstance <ICompositor>("Windows.UI.Composition.Compositor"); _compositor2 = _compositor.QueryInterface <ICompositor2>(); _compositor5 = _compositor.QueryInterface <ICompositor5>(); _compositorInterop = _compositor.QueryInterface <ICompositorInterop>(); _compositorDesktopInterop = _compositor.QueryInterface <ICompositorDesktopInterop>(); using var device = MicroComRuntime.CreateProxyFor <IUnknown>(_angle.GetDirect3DDevice(), true); _device = _compositorInterop.CreateGraphicsDevice(device); _blurBrush = CreateBlurBrush(); }
public static void Initialize() { AvaloniaLocator.CurrentMutable.Bind <IPlatformOpenGlInterface>().ToLazy <IPlatformOpenGlInterface>(() => { var opts = AvaloniaLocator.Current.GetService <Win32PlatformOptions>(); if (opts?.UseWgl == true) { var wgl = WglPlatformOpenGlInterface.TryCreate(); return(wgl); } if (opts?.AllowEglInitialization == true) { return(EglPlatformOpenGlInterface.TryCreate(() => new AngleWin32EglDisplay())); } return(null); }); }
public CompositionRenderTarget(EglPlatformOpenGlInterface egl, Windows.UI.Composition.Visual compositionVisual, ICompositionDrawingSurfaceInterop interopSurface, IEglWindowGlPlatformSurfaceInfo info) : base(egl) { _egl = egl; _surfaceInterop = interopSurface; _info = info; _currentSize = info.Size; _compositionVisual = compositionVisual; using (_egl.PrimaryContext.MakeCurrent()) { _surfaceInterop.Resize(new POINT { X = _info.Size.Width, Y = _info.Size.Height }); } _compositionVisual.Size = new System.Numerics.Vector2(_info.Size.Width, _info.Size.Height); }
public static void Initialize() { AvaloniaLocator.CurrentMutable.Bind <IPlatformOpenGlInterface>().ToLazy <IPlatformOpenGlInterface>(() => { var opts = AvaloniaLocator.Current.GetService <Win32PlatformOptions>() ?? new Win32PlatformOptions(); if (opts.UseWgl) { var wgl = WglPlatformOpenGlInterface.TryCreate(); return(wgl); } if (opts.AllowEglInitialization ?? Win32Platform.WindowsVersion > PlatformConstants.Windows7) { var egl = EglPlatformOpenGlInterface.TryCreate(() => new AngleWin32EglDisplay()); if (egl != null) { if (opts.EglRendererBlacklist != null) { foreach (var item in opts.EglRendererBlacklist) { if (egl.PrimaryEglContext.GlInterface.Renderer.Contains(item)) { return(null); } } } if (opts.UseWindowsUIComposition) { WinUICompositorConnection.TryCreateAndRegister(egl, opts.CompositionBackdropCornerRadius); } } return(egl); } return(null); }); }
public CompositionEglGlPlatformSurface(EglPlatformOpenGlInterface egl, IEglWindowGlPlatformSurfaceInfo info) : base() { _egl = egl; _info = info; }
void Init(DrmCard card, DrmResources resources, DrmConnector connector, DrmModeInfo modeInfo) { FbDestroyDelegate = FbDestroyCallback; _card = card; uint GetCrtc() { if (resources.Encoders.TryGetValue(connector.EncoderId, out var encoder)) { // Not sure why that should work return(encoder.Encoder.crtc_id); } else { foreach (var encId in connector.EncoderIds) { if (resources.Encoders.TryGetValue(encId, out encoder) && encoder.PossibleCrtcs.Count > 0) { return(encoder.PossibleCrtcs.First().crtc_id); } } throw new InvalidOperationException("Unable to find CRTC matching the desired mode"); } } _crtcId = GetCrtc(); var device = gbm_create_device(card.Fd); _gbmTargetSurface = gbm_surface_create(device, modeInfo.Resolution.Width, modeInfo.Resolution.Height, GbmColorFormats.GBM_FORMAT_XRGB8888, GbmBoFlags.GBM_BO_USE_SCANOUT | GbmBoFlags.GBM_BO_USE_RENDERING); if (_gbmTargetSurface == null) { throw new InvalidOperationException("Unable to create GBM surface"); } _eglDisplay = new EglDisplay(new EglInterface(eglGetProcAddress), false, 0x31D7, device, null); _platformGl = new EglPlatformOpenGlInterface(_eglDisplay); _eglSurface = _platformGl.CreateWindowSurface(_gbmTargetSurface); _deferredContext = _platformGl.PrimaryEglContext; using (_deferredContext.MakeCurrent(_eglSurface)) { _deferredContext.GlInterface.ClearColor(0, 0, 0, 0); _deferredContext.GlInterface.Clear(GlConsts.GL_COLOR_BUFFER_BIT | GlConsts.GL_STENCIL_BUFFER_BIT); _eglSurface.SwapBuffers(); } var bo = gbm_surface_lock_front_buffer(_gbmTargetSurface); var fbId = GetFbIdForBo(bo); var connectorId = connector.Id; var mode = modeInfo.Mode; var res = drmModeSetCrtc(_card.Fd, _crtcId, fbId, 0, 0, &connectorId, 1, &mode); if (res != 0) { throw new Win32Exception(res, "drmModeSetCrtc failed"); } _mode = mode; _currentBo = bo; // Go trough two cycles of buffer swapping (there are render artifacts otherwise) for (var c = 0; c < 2; c++) { using (CreateGlRenderTarget().BeginDraw()) { _deferredContext.GlInterface.ClearColor(0, 0, 0, 0); _deferredContext.GlInterface.Clear(GlConsts.GL_COLOR_BUFFER_BIT | GlConsts.GL_STENCIL_BUFFER_BIT); } } }
public void Initialize(X11PlatformOptions options) { Options = options; bool useXim = false; if (EnableIme(options)) { // Attempt to configure DBus-based input method and check if we can fall back to XIM if (!X11DBusImeHelper.DetectAndRegister() && ShouldUseXim()) { useXim = true; } } // XIM doesn't work at all otherwise if (useXim) { setlocale(0, ""); } XInitThreads(); Display = XOpenDisplay(IntPtr.Zero); if (Display == IntPtr.Zero) { throw new Exception("XOpenDisplay failed"); } DeferredDisplay = XOpenDisplay(IntPtr.Zero); if (DeferredDisplay == IntPtr.Zero) { throw new Exception("XOpenDisplay failed"); } OrphanedWindow = XCreateSimpleWindow(Display, XDefaultRootWindow(Display), 0, 0, 1, 1, 0, IntPtr.Zero, IntPtr.Zero); XError.Init(); Info = new X11Info(Display, DeferredDisplay, useXim); Globals = new X11Globals(this); //TODO: log if (options.UseDBusMenu) { DBusHelper.TryInitialize(); } AvaloniaLocator.CurrentMutable.BindToSelf(this) .Bind <IWindowingPlatform>().ToConstant(this) .Bind <IPlatformThreadingInterface>().ToConstant(new X11PlatformThreading(this)) .Bind <IRenderTimer>().ToConstant(new SleepLoopRenderTimer(60)) .Bind <IRenderLoop>().ToConstant(new RenderLoop()) .Bind <PlatformHotkeyConfiguration>().ToConstant(new PlatformHotkeyConfiguration(KeyModifiers.Control)) .Bind <IKeyboardDevice>().ToFunc(() => KeyboardDevice) .Bind <ICursorFactory>().ToConstant(new X11CursorFactory(Display)) .Bind <IClipboard>().ToConstant(new X11Clipboard(this)) .Bind <IPlatformSettings>().ToConstant(new PlatformSettingsStub()) .Bind <IPlatformIconLoader>().ToConstant(new X11IconLoader(Info)) .Bind <ISystemDialogImpl>().ToConstant(new GtkSystemDialog()) .Bind <IMountedVolumeInfoProvider>().ToConstant(new LinuxMountedVolumeInfoProvider()); X11Screens = Avalonia.X11.X11Screens.Init(this); Screens = new X11Screens(X11Screens); if (Info.XInputVersion != null) { var xi2 = new XI2Manager(); if (xi2.Init(this)) { XI2 = xi2; } } if (options.UseGpu) { if (options.UseEGL) { EglPlatformOpenGlInterface.TryInitialize(); } else { GlxPlatformOpenGlInterface.TryInitialize(Info, Options.GlProfiles); } } }
private GlPlatformSurface(EglPlatformOpenGlInterface egl, IEglWindowGlPlatformSurfaceInfo info) { _egl = egl; _info = info; }
public WinUiCompositedWindowSurface(WinUICompositorConnection connection, IEglWindowGlPlatformSurfaceInfo info) : base() { _connection = connection; _egl = connection.Egl; _info = info; }