internal void SetSurface(GRContext context, SKHtmlCanvasInterop.GLInfo glInfo, SKColorType colorType, PixelSize size, double scaling) { _currentSurface = new BlazorSkiaSurface(context, glInfo, colorType, size, scaling, GRSurfaceOrigin.BottomLeft); }
public IBitmapImpl LoadBitmap(PixelFormat format, IntPtr data, PixelSize size, Vector dpi, int stride) { return(new HeadlessBitmapStub(new Size(1, 1), new Vector(96, 96))); }
public HeadlessBitmapStub(PixelSize size, Vector dpi) { PixelSize = size; Dpi = dpi; Size = PixelSize.ToSizeWithDpi(dpi); }
/// <summary> /// Creates a Direct2D brush wrapper for a Avalonia brush. /// </summary> /// <param name="brush">The avalonia brush.</param> /// <param name="destinationSize">The size of the brush's target area.</param> /// <returns>The Direct2D brush wrapper.</returns> public BrushImpl CreateBrush(IBrush brush, Size destinationSize) { var solidColorBrush = brush as ISolidColorBrush; var linearGradientBrush = brush as ILinearGradientBrush; var radialGradientBrush = brush as IRadialGradientBrush; var conicGradientBrush = brush as IConicGradientBrush; var imageBrush = brush as IImageBrush; var visualBrush = brush as IVisualBrush; if (solidColorBrush != null) { return(new SolidColorBrushImpl(solidColorBrush, _deviceContext)); } else if (linearGradientBrush != null) { return(new LinearGradientBrushImpl(linearGradientBrush, _deviceContext, destinationSize)); } else if (radialGradientBrush != null) { return(new RadialGradientBrushImpl(radialGradientBrush, _deviceContext, destinationSize)); } else if (conicGradientBrush != null) { // there is no Direct2D implementation of Conic Gradients so use Radial as a stand-in return(new SolidColorBrushImpl(conicGradientBrush, _deviceContext)); } else if (imageBrush?.Source != null) { return(new ImageBrushImpl( imageBrush, _deviceContext, (BitmapImpl)imageBrush.Source.PlatformImpl.Item, destinationSize)); } else if (visualBrush != null) { if (_visualBrushRenderer != null) { var intermediateSize = _visualBrushRenderer.GetRenderTargetSize(visualBrush); if (intermediateSize.Width >= 1 && intermediateSize.Height >= 1) { // We need to ensure the size we're requesting is an integer pixel size, otherwise // D2D alters the DPI of the render target, which messes stuff up. PixelSize.FromSize // will do the rounding for us. var dpi = new Vector(_deviceContext.DotsPerInch.Width, _deviceContext.DotsPerInch.Height); var pixelSize = PixelSize.FromSizeWithDpi(intermediateSize, dpi); using (var intermediate = new BitmapRenderTarget( _deviceContext, CompatibleRenderTargetOptions.None, pixelSize.ToSizeWithDpi(dpi).ToSharpDX())) { using (var ctx = new RenderTarget(intermediate).CreateDrawingContext(_visualBrushRenderer)) { intermediate.Clear(null); _visualBrushRenderer.RenderVisualBrush(ctx, visualBrush); } return(new ImageBrushImpl( visualBrush, _deviceContext, new D2DBitmapImpl(intermediate.Bitmap), destinationSize)); } } } else { throw new NotSupportedException("No IVisualBrushRenderer was supplied to DrawingContextImpl."); } } return(new SolidColorBrushImpl(null, _deviceContext)); }
public WicBitmapImpl(APixelFormat format, AlphaFormat alphaFormat, IntPtr data, PixelSize size, Vector dpi, int stride) { WicImpl = new Bitmap(Direct2D1Platform.ImagingFactory, size.Width, size.Height, format.ToWic(alphaFormat), BitmapCreateCacheOption.CacheOnDemand); WicImpl.SetResolution(dpi.X, dpi.Y); PixelFormat = format; Dpi = dpi; using (var l = WicImpl.Lock(BitmapLockFlags.Write)) { for (var row = 0; row < size.Height; row++) { UnmanagedMethods.CopyMemory( (l.Data.DataPointer + row * l.Stride), (data + row * stride), (UIntPtr)l.Data.Pitch); } } }
public IBitmapImpl CreateBitmap(PixelSize size, Vector dpi) { return(new WicBitmapImpl(size, dpi)); }
public IWriteableBitmapImpl CreateWriteableBitmap(PixelSize size, Vector dpi, PixelFormat?format = null) { return(new WriteableWicBitmapImpl(size, dpi, format)); }
public void SetTexture(int textureId, int internalFormat, PixelSize size, double dpiScaling) { _impl.SetBackBuffer(textureId, internalFormat, size, dpiScaling); SetIsDirty(); }
/// <summary> /// Initializes a new instance of the <see cref="WriteableBitmap"/> class. /// </summary> /// <param name="size">The size of the bitmap in device pixels.</param> /// <param name="dpi">The DPI of the bitmap.</param> /// <param name="format">The pixel format (optional).</param> /// <returns>An <see cref="IWriteableBitmapImpl"/>.</returns> public WriteableBitmap(PixelSize size, Vector dpi, PixelFormat?format = null) : base(AvaloniaLocator.Current.GetService <IPlatformRenderInterface>().CreateWriteableBitmap(size, dpi, format)) { }
public static uint XConfigureResizeWindow(IntPtr display, IntPtr window, PixelSize size) => XConfigureResizeWindow(display, window, size.Width, size.Height);
public override void Render(DrawingContext context) { base.Render(context); if (!(VisualRoot is Window w)) { return; } var screens = w.Screens.All; var scaling = ((IRenderRoot)w).RenderScaling; Pen p = new Pen(Brushes.Black); if (screens != null) { foreach (Screen screen in screens) { if (screen.Bounds.X / 10f < _leftMost) { _leftMost = screen.Bounds.X / 10f; InvalidateVisual(); return; } Rect boundsRect = new Rect(screen.Bounds.X / 10f + Math.Abs(_leftMost), screen.Bounds.Y / 10f, screen.Bounds.Width / 10f, screen.Bounds.Height / 10f); Rect workingAreaRect = new Rect(screen.WorkingArea.X / 10f + Math.Abs(_leftMost), screen.WorkingArea.Y / 10f, screen.WorkingArea.Width / 10f, screen.WorkingArea.Height / 10f); context.DrawRectangle(p, boundsRect); context.DrawRectangle(p, workingAreaRect); FormattedText text = new FormattedText() { Typeface = Typeface.Default }; text.Text = $"Bounds: {screen.Bounds.Width}:{screen.Bounds.Height}"; context.DrawText(Brushes.Black, boundsRect.Position.WithY(boundsRect.Size.Height), text); text.Text = $"WorkArea: {screen.WorkingArea.Width}:{screen.WorkingArea.Height}"; context.DrawText(Brushes.Black, boundsRect.Position.WithY(boundsRect.Size.Height + 20), text); text.Text = $"Scaling: {screen.PixelDensity * 100}%"; context.DrawText(Brushes.Black, boundsRect.Position.WithY(boundsRect.Size.Height + 40), text); text.Text = $"Primary: {screen.Primary}"; context.DrawText(Brushes.Black, boundsRect.Position.WithY(boundsRect.Size.Height + 60), text); text.Text = $"Current: {screen.Equals(w.Screens.ScreenFromBounds(new PixelRect(w.Position, PixelSize.FromSize(w.Bounds.Size, scaling))))}"; context.DrawText(Brushes.Black, boundsRect.Position.WithY(boundsRect.Size.Height + 80), text); } } context.DrawRectangle(p, new Rect(w.Position.X / 10f + Math.Abs(_leftMost), w.Position.Y / 10, w.Bounds.Width / 10, w.Bounds.Height / 10)); }
/// <summary> /// Creates a Bitmap scaled to a specified size from the current bitmap. /// </summary> /// <param name="destinationSize">The destination size.</param> /// <param name="interpolationMode">The <see cref="BitmapInterpolationMode"/> to use should any scaling be required.</param> /// <returns>An instance of the <see cref="Bitmap"/> class.</returns> public Bitmap CreateScaledBitmap(PixelSize destinationSize, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality) { return(new Bitmap(GetFactory().ResizeBitmap(PlatformImpl.Item, destinationSize, interpolationMode))); }
/// <summary> /// Initializes a new instance of the <see cref="Bitmap"/> class. /// </summary> /// <param name="format">The pixel format.</param> /// <param name="alphaFormat">The alpha format.</param> /// <param name="data">The pointer to the source bytes.</param> /// <param name="size">The size of the bitmap in device pixels.</param> /// <param name="dpi">The DPI of the bitmap.</param> /// <param name="stride">The number of bytes per row.</param> public Bitmap(PixelFormat format, AlphaFormat alphaFormat, IntPtr data, PixelSize size, Vector dpi, int stride) { PlatformImpl = RefCountable.Create(GetFactory().LoadBitmap(format, alphaFormat, data, size, dpi, stride)); }
internal void SetSurface(SKColorType colorType, PixelSize size, double scaling, Action <IntPtr, SKSizeI> blitCallback) { _currentSurface = new BlazorSkiaRasterSurface(colorType, size, scaling, blitCallback); }
public X11Window(AvaloniaX11Platform platform, bool popup) { _platform = platform; _popup = popup; _x11 = platform.Info; _mouse = platform.MouseDevice; _keyboard = platform.KeyboardDevice; var glfeature = AvaloniaLocator.Current.GetService <IWindowingPlatformGlFeature>(); XSetWindowAttributes attr = new XSetWindowAttributes(); var valueMask = default(SetWindowValuemask); attr.backing_store = 1; attr.bit_gravity = Gravity.NorthWestGravity; attr.win_gravity = Gravity.NorthWestGravity; valueMask |= SetWindowValuemask.BackPixel | SetWindowValuemask.BorderPixel | SetWindowValuemask.BackPixmap | SetWindowValuemask.BackingStore | SetWindowValuemask.BitGravity | SetWindowValuemask.WinGravity; if (popup) { attr.override_redirect = true; valueMask |= SetWindowValuemask.OverrideRedirect; } XVisualInfo?visualInfo = null; // OpenGL seems to be do weird things to it's current window which breaks resize sometimes _useRenderWindow = glfeature != null; var glx = glfeature as GlxGlPlatformFeature; if (glx != null) { visualInfo = *glx.Display.VisualInfo; } else if (glfeature == null) { visualInfo = _x11.TransparentVisualInfo; } var egl = glfeature as EglGlPlatformFeature; var visual = IntPtr.Zero; var depth = 24; if (visualInfo != null) { visual = visualInfo.Value.visual; depth = (int)visualInfo.Value.depth; attr.colormap = XCreateColormap(_x11.Display, _x11.RootWindow, visualInfo.Value.visual, 0); valueMask |= SetWindowValuemask.ColorMap; } _handle = XCreateWindow(_x11.Display, _x11.RootWindow, 10, 10, 300, 200, 0, depth, (int)CreateWindowArgs.InputOutput, visual, new UIntPtr((uint)valueMask), ref attr); if (_useRenderWindow) { _renderHandle = XCreateWindow(_x11.Display, _handle, 0, 0, 300, 200, 0, depth, (int)CreateWindowArgs.InputOutput, visual, new UIntPtr((uint)(SetWindowValuemask.BorderPixel | SetWindowValuemask.BitGravity | SetWindowValuemask.WinGravity | SetWindowValuemask.BackingStore)), ref attr); } else { _renderHandle = _handle; } Handle = new PlatformHandle(_handle, "XID"); _realSize = new PixelSize(300, 200); platform.Windows[_handle] = OnEvent; XEventMask ignoredMask = XEventMask.SubstructureRedirectMask | XEventMask.ResizeRedirectMask | XEventMask.PointerMotionHintMask; if (platform.XI2 != null) { ignoredMask |= platform.XI2.AddWindow(_handle, this); } var mask = new IntPtr(0xffffff ^ (int)ignoredMask); XSelectInput(_x11.Display, _handle, mask); var protocols = new[] { _x11.Atoms.WM_DELETE_WINDOW }; XSetWMProtocols(_x11.Display, _handle, protocols, protocols.Length); XChangeProperty(_x11.Display, _handle, _x11.Atoms._NET_WM_WINDOW_TYPE, _x11.Atoms.XA_ATOM, 32, PropertyMode.Replace, new[] { _x11.Atoms._NET_WM_WINDOW_TYPE_NORMAL }, 1); if (platform.Options.WmClass != null) { SetWmClass(platform.Options.WmClass); } var surfaces = new List <object> { new X11FramebufferSurface(_x11.DeferredDisplay, _renderHandle, depth, () => Scaling) }; if (egl != null) { surfaces.Insert(0, new EglGlPlatformSurface((EglDisplay)egl.Display, egl.DeferredContext, new SurfaceInfo(this, _x11.DeferredDisplay, _handle, _renderHandle))); } if (glx != null) { surfaces.Insert(0, new GlxGlPlatformSurface(glx.Display, glx.DeferredContext, new SurfaceInfo(this, _x11.Display, _handle, _renderHandle))); } Surfaces = surfaces.ToArray(); UpdateMotifHints(); _xic = XCreateIC(_x11.Xim, XNames.XNInputStyle, XIMProperties.XIMPreeditNothing | XIMProperties.XIMStatusNothing, XNames.XNClientWindow, _handle, IntPtr.Zero); XFlush(_x11.Display); }
public IRenderTargetBitmapImpl CreateRenderTargetBitmap(PixelSize size, Vector dpi) { throw new NotImplementedException(); }
public WindowsVideoFormats(string formatName, PixelSize resolution, WindowsCapture.VideoFormat nativeVideoFormat) { FormatName = formatName; Resolution = resolution; NativeVideoFormat = nativeVideoFormat; }
public IBitmapImpl LoadBitmap(PixelFormat format, IntPtr data, PixelSize size, Vector dpi, int stride) { throw new NotImplementedException(); }
public IRenderTargetBitmapImpl CreateRenderTargetBitmap(PixelSize size, Vector dpi) { return(new WicRenderTargetBitmapImpl(size, dpi)); }
public IWriteableBitmapImpl CreateWriteableBitmap(PixelSize size, Vector dpi, PixelFormat?fmt) { throw new NotImplementedException(); }
public IBitmapImpl LoadBitmap(PixelFormat format, IntPtr data, PixelSize size, Vector dpi, int stride) { return(new WicBitmapImpl(format, data, size, dpi, stride)); }
public WriteableWicBitmapImpl(PixelSize size, Vector dpi, PixelFormat?pixelFormat, AlphaFormat?alphaFormat) : base(size, dpi, pixelFormat, alphaFormat) { }
public X11Window(AvaloniaX11Platform platform, IWindowImpl popupParent) { _platform = platform; _popup = popupParent != null; _x11 = platform.Info; _mouse = new MouseDevice(); _touch = new TouchDevice(); _keyboard = platform.KeyboardDevice; var glfeature = AvaloniaLocator.Current.GetService <IWindowingPlatformGlFeature>(); XSetWindowAttributes attr = new XSetWindowAttributes(); var valueMask = default(SetWindowValuemask); attr.backing_store = 1; attr.bit_gravity = Gravity.NorthWestGravity; attr.win_gravity = Gravity.NorthWestGravity; valueMask |= SetWindowValuemask.BackPixel | SetWindowValuemask.BorderPixel | SetWindowValuemask.BackPixmap | SetWindowValuemask.BackingStore | SetWindowValuemask.BitGravity | SetWindowValuemask.WinGravity; if (_popup) { attr.override_redirect = true; valueMask |= SetWindowValuemask.OverrideRedirect; } XVisualInfo?visualInfo = null; // OpenGL seems to be do weird things to it's current window which breaks resize sometimes _useRenderWindow = glfeature != null; var glx = glfeature as GlxGlPlatformFeature; if (glx != null) { visualInfo = *glx.Display.VisualInfo; } else if (glfeature == null) { visualInfo = _x11.TransparentVisualInfo; } var egl = glfeature as EglGlPlatformFeature; var visual = IntPtr.Zero; var depth = 24; if (visualInfo != null) { visual = visualInfo.Value.visual; depth = (int)visualInfo.Value.depth; attr.colormap = XCreateColormap(_x11.Display, _x11.RootWindow, visualInfo.Value.visual, 0); valueMask |= SetWindowValuemask.ColorMap; } int defaultWidth = 0, defaultHeight = 0; if (!_popup && Screen != null) { var monitor = Screen.AllScreens.OrderBy(x => x.PixelDensity) .FirstOrDefault(m => m.Bounds.Contains(Position)); if (monitor != null) { // Emulate Window 7+'s default window size behavior. defaultWidth = (int)(monitor.WorkingArea.Width * 0.75d); defaultHeight = (int)(monitor.WorkingArea.Height * 0.7d); } } // check if the calculated size is zero then compensate to hardcoded resolution defaultWidth = Math.Max(defaultWidth, 300); defaultHeight = Math.Max(defaultHeight, 200); _handle = XCreateWindow(_x11.Display, _x11.RootWindow, 10, 10, defaultWidth, defaultHeight, 0, depth, (int)CreateWindowArgs.InputOutput, visual, new UIntPtr((uint)valueMask), ref attr); if (_useRenderWindow) { _renderHandle = XCreateWindow(_x11.Display, _handle, 0, 0, defaultWidth, defaultHeight, 0, depth, (int)CreateWindowArgs.InputOutput, visual, new UIntPtr((uint)(SetWindowValuemask.BorderPixel | SetWindowValuemask.BitGravity | SetWindowValuemask.WinGravity | SetWindowValuemask.BackingStore)), ref attr); } else { _renderHandle = _handle; } Handle = new PlatformHandle(_handle, "XID"); _realSize = new PixelSize(defaultWidth, defaultHeight); platform.Windows[_handle] = OnEvent; XEventMask ignoredMask = XEventMask.SubstructureRedirectMask | XEventMask.ResizeRedirectMask | XEventMask.PointerMotionHintMask; if (platform.XI2 != null) { ignoredMask |= platform.XI2.AddWindow(_handle, this); } var mask = new IntPtr(0xffffff ^ (int)ignoredMask); XSelectInput(_x11.Display, _handle, mask); var protocols = new[] { _x11.Atoms.WM_DELETE_WINDOW }; XSetWMProtocols(_x11.Display, _handle, protocols, protocols.Length); XChangeProperty(_x11.Display, _handle, _x11.Atoms._NET_WM_WINDOW_TYPE, _x11.Atoms.XA_ATOM, 32, PropertyMode.Replace, new[] { _x11.Atoms._NET_WM_WINDOW_TYPE_NORMAL }, 1); if (platform.Options.WmClass != null) { SetWmClass(platform.Options.WmClass); } var surfaces = new List <object> { new X11FramebufferSurface(_x11.DeferredDisplay, _renderHandle, depth, () => Scaling) }; if (egl != null) { surfaces.Insert(0, new EglGlPlatformSurface((EglDisplay)egl.Display, egl.DeferredContext, new SurfaceInfo(this, _x11.DeferredDisplay, _handle, _renderHandle))); } if (glx != null) { surfaces.Insert(0, new GlxGlPlatformSurface(glx.Display, glx.DeferredContext, new SurfaceInfo(this, _x11.Display, _handle, _renderHandle))); } Surfaces = surfaces.ToArray(); UpdateMotifHints(); UpdateSizeHints(null); _xic = XCreateIC(_x11.Xim, XNames.XNInputStyle, XIMProperties.XIMPreeditNothing | XIMProperties.XIMStatusNothing, XNames.XNClientWindow, _handle, IntPtr.Zero); XFlush(_x11.Display); if (_popup) { PopupPositioner = new ManagedPopupPositioner(new ManagedPopupPositionerPopupImplHelper(popupParent, MoveResize)); } if (platform.Options.UseDBusMenu) { NativeMenuExporter = DBusMenuExporter.TryCreate(_handle); } }
/// <inheritdoc /> public IBitmapImpl LoadBitmap(PixelFormat format, AlphaFormat alphaFormat, IntPtr data, PixelSize size, Vector dpi, int stride) { return(new ImmutableBitmap(size, dpi, stride, format, alphaFormat, data)); }
public IWriteableBitmapImpl CreateWriteableBitmap(PixelSize size, Vector dpi, PixelFormat?format = null) { return(new HeadlessBitmapStub(size, dpi)); }
/// <inheritdoc /> public IWriteableBitmapImpl CreateWriteableBitmap(PixelSize size, Vector dpi, PixelFormat format, AlphaFormat alphaFormat) { return(new WriteableBitmapImpl(size, dpi, format, alphaFormat)); }
public IBitmapImpl ResizeBitmap(IBitmapImpl bitmapImpl, PixelSize destinationSize, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality) { return(new HeadlessBitmapStub(destinationSize, new Vector(96, 96))); }
public GlOpenGlBitmapImpl(IGlContext context, PixelSize pixelSize, Vector dpi) { _context = context; PixelSize = pixelSize; Dpi = dpi; }
public IRenderTargetBitmapImpl CreateRenderTargetBitmap(PixelSize size, Vector dpi) { return(new HeadlessBitmapStub(size, dpi)); }
/// <inheritdoc /> public IBitmapImpl ResizeBitmap(IBitmapImpl bitmapImpl, PixelSize destinationSize, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality) { // https://github.com/sharpdx/SharpDX/issues/959 blocks implementation. throw new NotImplementedException(); }