committed by
GitHub
8 changed files with 163 additions and 3 deletions
@ -0,0 +1,54 @@ |
|||||
|
using System; |
||||
|
using System.Runtime.InteropServices; |
||||
|
|
||||
|
namespace Avalonia.Gtk3 |
||||
|
{ |
||||
|
class X11 |
||||
|
{ |
||||
|
[DllImport("libX11.so.6")] |
||||
|
public static extern IntPtr XOpenDisplay(IntPtr name); |
||||
|
|
||||
|
[DllImport("libX11.so.6")] |
||||
|
public static extern IntPtr XFreeGC(IntPtr display, IntPtr gc); |
||||
|
|
||||
|
[DllImport("libX11.so.6")] |
||||
|
public static extern IntPtr XCreateGC(IntPtr display, IntPtr drawable, ulong valuemask, IntPtr values); |
||||
|
|
||||
|
[DllImport("libX11.so.6")] |
||||
|
public static extern int XInitImage(ref XImage image); |
||||
|
|
||||
|
[DllImport("libX11.so.6")] |
||||
|
public static extern int XDestroyImage(ref XImage image); |
||||
|
|
||||
|
[DllImport("libX11.so.6")] |
||||
|
public static extern IntPtr XSetErrorHandler(XErrorHandler handler); |
||||
|
|
||||
|
public delegate int XErrorHandler(IntPtr display, IntPtr error); |
||||
|
|
||||
|
[DllImport("libX11.so.6")] |
||||
|
public static extern int XPutImage(IntPtr display, IntPtr drawable, IntPtr gc, ref XImage image, |
||||
|
int srcx, int srcy, int destx, int desty, uint width, uint height); |
||||
|
|
||||
|
|
||||
|
public unsafe struct XImage |
||||
|
{ |
||||
|
public int width, height; /* size of image */ |
||||
|
public int xoffset; /* number of pixels offset in X direction */ |
||||
|
public int format; /* XYBitmap, XYPixmap, ZPixmap */ |
||||
|
public IntPtr data; /* pointer to image data */ |
||||
|
public int byte_order; /* data byte order, LSBFirst, MSBFirst */ |
||||
|
public int bitmap_unit; /* quant. of scanline 8, 16, 32 */ |
||||
|
public int bitmap_bit_order; /* LSBFirst, MSBFirst */ |
||||
|
public int bitmap_pad; /* 8, 16, 32 either XY or ZPixmap */ |
||||
|
public int depth; /* depth of image */ |
||||
|
public int bytes_per_line; /* accelerator to next scanline */ |
||||
|
public int bits_per_pixel; /* bits per pixel (ZPixmap) */ |
||||
|
public ulong red_mask; /* bits in z arrangement */ |
||||
|
public ulong green_mask; |
||||
|
public ulong blue_mask; |
||||
|
private fixed byte funcs[128]; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,55 @@ |
|||||
|
using System; |
||||
|
using System.Runtime.InteropServices; |
||||
|
using Avalonia.Platform; |
||||
|
|
||||
|
namespace Avalonia.Gtk3 |
||||
|
{ |
||||
|
class X11Framebuffer : ILockedFramebuffer |
||||
|
{ |
||||
|
private readonly IntPtr _display; |
||||
|
private readonly IntPtr _xid; |
||||
|
private IUnmanagedBlob _blob; |
||||
|
|
||||
|
public X11Framebuffer(IntPtr display, IntPtr xid, int width, int height, int factor) |
||||
|
{ |
||||
|
_display = display; |
||||
|
_xid = xid; |
||||
|
Width = width*factor; |
||||
|
Height = height*factor; |
||||
|
RowBytes = Width * 4; |
||||
|
Dpi = new Vector(96, 96) * factor; |
||||
|
Format = PixelFormat.Bgra8888; |
||||
|
_blob = AvaloniaLocator.Current.GetService<IRuntimePlatform>().AllocBlob(RowBytes * Height); |
||||
|
Address = _blob.Address; |
||||
|
} |
||||
|
|
||||
|
public void Dispose() |
||||
|
{ |
||||
|
var image = new X11.XImage(); |
||||
|
int bitsPerPixel = 32; |
||||
|
image.width = Width; |
||||
|
image.height = 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 - Width * 4; |
||||
|
image.bits_per_pixel = bitsPerPixel; |
||||
|
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) Width, (uint) Height); |
||||
|
X11.XFreeGC(_display, gc); |
||||
|
_blob.Dispose(); |
||||
|
} |
||||
|
|
||||
|
public IntPtr Address { get; } |
||||
|
public int Width { get; } |
||||
|
public int Height { get; } |
||||
|
public int RowBytes { get; } |
||||
|
public Vector Dpi { get; } |
||||
|
public PixelFormat Format { get; } |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue