Example #1
0
        public void Dispose()
        {
            var image        = new X11.XImage();
            int bitsPerPixel = 32;

            image.width            = Size.Width;
            image.height           = Size.Height;
            image.format           = 2; //ZPixmap;
            image.data             = Address;
            image.byte_order       = 0; // LSBFirst;
            image.bitmap_unit      = bitsPerPixel;
            image.bitmap_bit_order = 0; // LSBFirst;
            image.bitmap_pad       = bitsPerPixel;
            image.depth            = 24;
            image.bytes_per_line   = RowBytes - Size.Width * 4;
            image.bits_per_pixel   = bitsPerPixel;
            X11.XLockDisplay(_display);
            X11.XInitImage(ref image);
            var gc = X11.XCreateGC(_display, _xid, 0, IntPtr.Zero);

            X11.XPutImage(_display, _xid, gc, ref image, 0, 0, 0, 0, (uint)Size.Width, (uint)Size.Height);
            X11.XFreeGC(_display, gc);
            X11.XSync(_display, true);
            X11.XUnlockDisplay(_display);
            _blob.Dispose();
        }
Example #2
0
        public static void Initialize()
        {
            if (!s_gtkInitialized)
            {
                try
                {
                    X11.XInitThreads();
                }catch {}
                Resolver.Resolve();
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
                {
                    using (var backends = new Utf8Buffer("x11"))
                        Native.GdkSetAllowedBackends?.Invoke(backends);
                }
                Native.GtkInit(0, IntPtr.Zero);
                var disp = Native.GdkGetDefaultDisplay();
                DisplayClassName =
                    Utf8Buffer.StringFromPtr(Native.GTypeName(Marshal.ReadIntPtr(Marshal.ReadIntPtr(disp))));

                using (var utf = new Utf8Buffer("avalonia.app." + Guid.NewGuid()))
                    App = Native.GtkApplicationNew(utf, 0);
                //Mark current thread as UI thread
                s_tlsMarker      = true;
                s_gtkInitialized = true;
            }
            AvaloniaLocator.CurrentMutable.Bind <IWindowingPlatform>().ToConstant(Instance)
            .Bind <IClipboard>().ToSingleton <ClipboardImpl>()
            .Bind <IStandardCursorFactory>().ToConstant(new CursorFactory())
            .Bind <IKeyboardDevice>().ToConstant(Keyboard)
            .Bind <IPlatformSettings>().ToConstant(Instance)
            .Bind <IPlatformThreadingInterface>().ToConstant(Instance)
            .Bind <ISystemDialogImpl>().ToSingleton <SystemDialog>()
            .Bind <IRenderLoop>().ToConstant(new DefaultRenderLoop(60))
            .Bind <IPlatformIconLoader>().ToConstant(new PlatformIconLoader());
        }
        void GtkThread(TaskCompletionSource <bool> tcs)
        {
            try
            {
                X11.XInitThreads();
            }catch {}
            Resolver.Resolve();
            if (Native.GdkWindowForeignNewForDisplay == null)
            {
                throw new Exception("gdk_x11_window_foreign_new_for_display is not found in your libgdk-3.so");
            }
            using (var backends = new Utf8Buffer("x11"))
                Native.GdkSetAllowedBackends?.Invoke(backends);
            if (!Native.GtkInitCheck(0, IntPtr.Zero))
            {
                tcs.SetResult(false);
                return;
            }

            using (var utf = new Utf8Buffer($"avalonia.app.a{Guid.NewGuid().ToString("N")}"))
                App = Native.GtkApplicationNew(utf, 0);
            if (App == IntPtr.Zero)
            {
                tcs.SetResult(false);
                return;
            }
            GdkDisplay = Native.GdkGetDefaultDisplay();
            tcs.SetResult(true);
            while (true)
            {
                Native.GtkMainIteration();
            }
        }
Example #4
0
 private ILockedFramebuffer LockX11Framebuffer(int width, int height)
 {
     if (!_window.GdkWindowHandle.HasValue)
     {
         return(null);
     }
     if (X11Display == IntPtr.Zero)
     {
         X11Display = X11.XOpenDisplay(IntPtr.Zero);
         if (X11Display == IntPtr.Zero)
         {
             return(null);
         }
         X11.XSetErrorHandler(X11ErrorHandlerDelegate);
     }
     return(new X11Framebuffer(X11Display, _window.GdkWindowHandle.Value, width, height, _window.LastKnownScaleFactor));
 }
Example #5
0
        public static void Initialize(Gtk3PlatformOptions options)
        {
            Resolver.Custom      = options.CustomResolver;
            UseDeferredRendering = EnvOption("USE_DEFERRED_RENDERING", true, options.UseDeferredRendering);
            var useGpu = EnvOption("USE_GPU", false, options.UseGpuAcceleration);

            if (!s_gtkInitialized)
            {
                try
                {
                    X11.XInitThreads();
                }catch {}
                Resolver.Resolve();
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
                {
                    using (var backends = new Utf8Buffer("x11"))
                        Native.GdkSetAllowedBackends?.Invoke(backends);
                }
                Native.GtkInit(0, IntPtr.Zero);
                var disp = Native.GdkGetDefaultDisplay();
                DisplayClassName =
                    Utf8Buffer.StringFromPtr(Native.GTypeName(Marshal.ReadIntPtr(Marshal.ReadIntPtr(disp))));

                using (var utf = new Utf8Buffer("avalonia.app." + Guid.NewGuid()))
                    App = Native.GtkApplicationNew(utf, 0);
                //Mark current thread as UI thread
                s_tlsMarker      = true;
                s_gtkInitialized = true;
            }
            AvaloniaLocator.CurrentMutable.Bind <IWindowingPlatform>().ToConstant(Instance)
            .Bind <IClipboard>().ToSingleton <ClipboardImpl>()
            .Bind <IStandardCursorFactory>().ToConstant(new CursorFactory())
            .Bind <IKeyboardDevice>().ToConstant(Keyboard)
            .Bind <IPlatformSettings>().ToConstant(Instance)
            .Bind <IPlatformThreadingInterface>().ToConstant(Instance)
            .Bind <ISystemDialogImpl>().ToSingleton <SystemDialog>()
            .Bind <IRenderLoop>().ToConstant(new RenderLoop())
            .Bind <IRenderTimer>().ToConstant(new DefaultRenderTimer(60))
            .Bind <PlatformHotkeyConfiguration>().ToSingleton <PlatformHotkeyConfiguration>()
            .Bind <IPlatformIconLoader>().ToConstant(new PlatformIconLoader());
            if (useGpu)
            {
                EglGlPlatformFeature.TryInitialize();
            }
        }