Beispiel #1
0
            public XImageCursor(IntPtr display, IBitmapImpl bitmap, PixelPoint hotSpot)
            {
                var size = Marshal.SizeOf <XcursorImage>() +
                           (bitmap.PixelSize.Width * bitmap.PixelSize.Height * 4);
                var runtimePlatform = AvaloniaLocator.Current.GetService <IRuntimePlatform>() ??
                                      throw new InvalidOperationException("Unable to locate IRuntimePlatform");
                var platformRenderInterface = AvaloniaLocator.Current.GetService <IPlatformRenderInterface>() ??
                                              throw new InvalidOperationException("Unable to locate IPlatformRenderInterface");

                _pixelSize = bitmap.PixelSize;
                _blob      = runtimePlatform.AllocBlob(size);

                var image = (XcursorImage *)_blob.Address;

                image->version = 1;
                image->size    = Marshal.SizeOf <XcursorImage>();
                image->width   = bitmap.PixelSize.Width;
                image->height  = bitmap.PixelSize.Height;
                image->xhot    = hotSpot.X;
                image->yhot    = hotSpot.Y;
                image->pixels  = (IntPtr)(image + 1);

                using (var renderTarget = platformRenderInterface.CreateRenderTarget(new[] { this }))
                    using (var ctx = renderTarget.CreateDrawingContext(null))
                    {
                        var r = new Rect(_pixelSize.ToSize(1));
                        ctx.DrawBitmap(RefCountable.CreateUnownedNotClonable(bitmap), 1, r, r);
                    }

                Handle = XLib.XcursorImageLoadCursor(display, _blob.Address);
            }
Beispiel #2
0
 public ManagedCairoSurface(int width, int height)
 {
     _plat   = AvaloniaLocator.Current.GetService <IRuntimePlatform>();
     Stride  = width * 4;
     _size   = height * Stride;
     _blob   = _plat.AllocBlob(_size * 2);
     Buffer  = _blob.Address;
     Surface = Native.CairoImageSurfaceCreateForData(Buffer, 1, width, height, Stride);
 }
Beispiel #3
0
 public X11Framebuffer(IntPtr display, IntPtr xid, int width, int height, int factor)
 {
     _display = display;
     _xid     = xid;
     Size     = new PixelSize(width * factor, height * factor);
     RowBytes = Size.Width * 4;
     Dpi      = new Vector(96, 96) * factor;
     Format   = PixelFormat.Bgra8888;
     _blob    = AvaloniaLocator.Current.GetService <IRuntimePlatform>().AllocBlob(RowBytes * Size.Height);
     Address  = _blob.Address;
 }
Beispiel #4
0
 public X11Framebuffer(IntPtr display, IntPtr xid, int depth, int width, int height, double factor)
 {
     _display = display;
     _xid     = xid;
     _depth   = depth;
     Size     = new PixelSize(width, height);
     RowBytes = width * 4;
     Dpi      = new Vector(96, 96) * factor;
     Format   = PixelFormat.Bgra8888;
     _blob    = AvaloniaGlobals.RuntimePlatform.AllocBlob(RowBytes * height);
     Address  = _blob.Address;
 }
Beispiel #5
0
        public X11Framebuffer(IntPtr display, IntPtr xid, int depth, int width, int height, double factor)
        {
            // HACK! Please fix renderer, should never ask for 0x0 bitmap.
            width  = Math.Max(1, width);
            height = Math.Max(1, height);

            _display = display;
            _xid     = xid;
            _depth   = depth;
            Size     = new PixelSize(width, height);
            RowBytes = width * 4;
            Dpi      = new Vector(96, 96) * factor;
            Format   = PixelFormat.Bgra8888;
            _blob    = AvaloniaLocator.Current.GetService <IRuntimePlatform>().AllocBlob(RowBytes * height);
            Address  = _blob.Address;
        }
Beispiel #6
0
        public EmulatedFramebuffer(TopLevelImpl.TopLevelView view)
        {
            _view = view;

            _isDeferred  = !Dispatcher.UIThread.CheckAccess();
            _logicalSize = _view.LogicalSize;
            var pixelSize = _view.PixelSize;

            Width    = (int)pixelSize.Width;
            Height   = (int)pixelSize.Height;
            RowBytes = Width * 4;
            Dpi      = new Vector(96 * pixelSize.Width / _logicalSize.Width, 96 * pixelSize.Height / _logicalSize.Height);
            Format   = PixelFormat.Rgba8888;
            var size = Height * RowBytes;

            _blob = AvaloniaLocator.Current.GetService <IRuntimePlatform>().AllocBlob(size);
            memset(Address, 0, new IntPtr(size));
        }
            public FramebufferData(IUnmanagedBlob data, int width, int height)
            {
                Data = data;
                Size = new PixelSize(width, height);

                var header = new UnmanagedMethods.BITMAPINFOHEADER();

                header.Init();

                header.biPlanes   = 1;
                header.biBitCount = _bytesPerPixel * 8;
                header.Init();

                header.biWidth  = width;
                header.biHeight = -height;

                Header = header;
            }
Beispiel #8
0
 public WindowFramebuffer(IntPtr handle, int width, int height)
 {
     if (width <= 0)
     {
         throw new ArgumentException("width is less than zero");
     }
     if (height <= 0)
     {
         throw new ArgumentException("height is less than zero");
     }
     _handle = handle;
     _bmpInfo.Init();
     _bmpInfo.biPlanes   = 1;
     _bmpInfo.biBitCount = 32;
     _bmpInfo.Init();
     _bmpInfo.biWidth  = width;
     _bmpInfo.biHeight = -height;
     _bitmapBlob       = AvaloniaLocator.Current.GetService <IRuntimePlatform>().AllocBlob(width * height * 4);
 }
Beispiel #9
0
 public WindowFramebuffer(IntPtr handle, PixelSize size)
 {
     if (size.Width <= 0)
     {
         throw new ArgumentException("Width is less than zero");
     }
     if (size.Height <= 0)
     {
         throw new ArgumentException("Height is less than zero");
     }
     _handle = handle;
     _bmpInfo.Init();
     _bmpInfo.biPlanes   = 1;
     _bmpInfo.biBitCount = 32;
     _bmpInfo.Init();
     _bmpInfo.biWidth  = size.Width;
     _bmpInfo.biHeight = -size.Height;
     _bitmapBlob       = AvaloniaGlobals.RuntimePlatform.AllocBlob(size.Width * size.Height * 4);
 }