These are chat archives for AvaloniaUI/Avalonia

4th
Nov 2017
Wiesław Šoltés
@wieslawsoltes
Nov 04 2017 06:09
Avalonia now has Resources so porting from WPF got a bit easier.
Wiesław Šoltés
@wieslawsoltes
Nov 04 2017 08:08
Big Jake
@jakesays
Nov 04 2017 15:13
css-like selectors?
Big Jake
@jakesays
Nov 04 2017 15:27
so i'm looking for a UI for a small screen - 320x240 on linux, using coreclr. is the skia backend in good enough shape?
Nikita Tsukanov
@kekekeks
Nov 04 2017 15:28
Skia backend - yes
Our /dev/fb0 support... Well, I've only tested it on my laptop and with QEMU VM
And I haven't even started working on support for /dev/drm
Big Jake
@jakesays
Nov 04 2017 15:33
i just need the framebuffer
its a pretty simple screen
is there support for the linux input system?
Nikita Tsukanov
@kekekeks
Nov 04 2017 15:34
There is some basic support for evdev
Big Jake
@jakesays
Nov 04 2017 15:35
ok cool. just need to be able to handle my finger. lol
when did you guys switch to portable.xaml?
oh and is ide usable?
damn you guys have been busy! i see an avalonedit port.
Nikita Tsukanov
@kekekeks
Nov 04 2017 15:43
IDE isn't completely usable yet
Big Jake
@jakesays
Nov 04 2017 15:46
i got excited when i saw the vs plugin, but then remembered i'm doing all my dev in wsl
i could probably still make it work
hmm. this would be an interesting port: https://github.com/ArthurHub/HTML-Renderer
would make for an interesting rich text control
Nikita Tsukanov
@kekekeks
Nov 04 2017 15:49
We already have it ported
Back in 2015, I think
Big Jake
@jakesays
Nov 04 2017 15:50
oh??
awesome!
does it work?
Nikita Tsukanov
@kekekeks
Nov 04 2017 15:51
Nobody have checked if it does since 2016
Big Jake
@jakesays
Nov 04 2017 15:52
damn wish i had more time
Nikita Tsukanov
@kekekeks
Nov 04 2017 15:52
It would probably be better to make the original one to target netstandard
and push our backend to their main repo
Big Jake
@jakesays
Nov 04 2017 15:52
yeah
so avalonia is netstandard 2 compliant?
Nikita Tsukanov
@kekekeks
Nov 04 2017 16:09
yep
AlessandroMiorelli
@AlessandroMiorelli
Nov 04 2017 16:11

@Nikita I followed your suggestion. I took a piece of code form some example

var fb = new Framebuffer(PixelFormat.Bgra8888, (int)this.Width, (int)this.Height);
var r = AvaloniaLocator.Current.GetService<IPlatformRenderInterface>();
using (var target = r.CreateRenderTarget(new object[] { fb }))
{
var bmp = new Bitmap(PixelFormat.Bgra8888, fb.Address, fb.Width, fb.Height, fb.RowBytes);
bmp.Save(@"D:\test1.bmp");
}

fb.Deallocate();

using (var rtb = new RenderTargetBitmap((int)this.Width, (int)this.Height))
{
rtb.Render(this);
rtb.Save(@"D:\test2.png");
}

All bytes in fb.Address are 0. So test1.bmp doesn't contain antything
test2.png is correct

What is wrong?
Thank you

Nikita Tsukanov
@kekekeks
Nov 04 2017 16:14
Well, you aren't rendering anything
AlessandroMiorelli
@AlessandroMiorelli
Nov 04 2017 16:22
ops, sorry. I thought this feature return the buffer of the window content
Nikita Tsukanov
@kekekeks
Nov 04 2017 16:25
Nope, you can render controls to a render target
one of the possible render targets is a framebuffer
AlessandroMiorelli
@AlessandroMiorelli
Nov 04 2017 16:26
In my WPF application I use rendertargetbitmap Render and after that CopyPixel to get the pixels
how can I render targets in a framebuffer?
Nikita Tsukanov
@kekekeks
Nov 04 2017 16:26
You can render to a framebuffer instead of RTB
AlessandroMiorelli
@AlessandroMiorelli
Nov 04 2017 16:34
var fb = new Framebuffer(PixelFormat.Bgra8888, (int)this.Width, (int)this.Height);
var r = AvaloniaLocator.Current.GetService<IPlatformRenderInterface>();
using (var target = r.CreateRenderTarget(new object[] { fb }))
using (var ctx = target.CreateDrawingContext(null))
{
Avalonia.Rendering.Render(this, ctx);
}
            var bmp = new Bitmap(PixelFormat.Bgra8888, fb.Address, fb.Width, fb.Height, fb.RowBytes);
            bmp.Save(@"D:\test1.bmp");

            fb.Deallocate();
something like that?
Nikita Tsukanov
@kekekeks
Nov 04 2017 16:44
Yeah, but you can probably render to your video card's framebuffer directly
instead of using intermediate bitmaps
It gives you an IntPtr, right?
AlessandroMiorelli
@AlessandroMiorelli
Nov 04 2017 16:57
Right
I don’t find avaloniA.rendering what should I add?
AlessandroMiorelli
@AlessandroMiorelli
Nov 04 2017 17:11
Should I call this function in ui thread or can I call in another thread?
Big Jake
@jakesays
Nov 04 2017 17:30
@kekekeks hey how does omnigui compare to avalonia?
Wiesław Šoltés
@wieslawsoltes
Nov 04 2017 17:43

It would probably be better to make the original one to target netstandard

@kekekeks ArthurHub/HTML-Renderer#112

danwalmsley
@danwalmsley
Nov 04 2017 19:37
@jakesays omnigui uses native controls, its more like xamarin forms, avalonia is 100% lookless controls, afaik
Jeremy Koritzinsky
@jkoritzinsky
Nov 04 2017 19:51
@jakesays @danwalmsley OmniGui is lookless like Avalonia, but with a much smaller control library, immediate-rendering only, no binding priority system, and a much less performant XAML engine. It's actually run by the guy who develops our previous XAML engine. He started it after we switch off his XAML engine because of performance issues
rconde01
@rconde01
Nov 04 2017 19:57
gui toolkit rumble
Jeremy Koritzinsky
@jkoritzinsky
Nov 04 2017 19:59
Also OmniGui won't handle the window creation. It renders into a view provided by the user
Nikita Tsukanov
@kekekeks
Nov 04 2017 20:02

Should I call this function in ui thread or can I call in another thread

It is possible to render on non-UI thread, but that involves quite complex setup

ImmediateRenderer.Render should be called on UI-thread
AlessandroMiorelli
@AlessandroMiorelli
Nov 04 2017 20:43
thank you Nikita
AlessandroMiorelli
@AlessandroMiorelli
Nov 04 2017 20:52

you wrote

"but you can probably render to your video card's framebuffer directly
instead of using intermediate bitmaps
It gives you an IntPtr, right?"

where shoud I pass IntPtr?
Nikita Tsukanov
@kekekeks
Nov 04 2017 21:11
You need to implement ILockedFramebuffer
and return that IntPtr from Address property
Just make sure to set width, height, stride and pixel format correctly
Big Jake
@jakesays
Nov 04 2017 21:12
@jkoritzinsky ok cool. thanks.
i'm trying to decide if i work today or play with skia-avalonia on my LCD
AlessandroMiorelli
@AlessandroMiorelli
Nov 04 2017 21:13
thank you
Nikita Tsukanov
@kekekeks
Nov 04 2017 21:24
@jakesays you still need to get an ARM build of libSkiaSharp somewhere...
Big Jake
@jakesays
Nov 04 2017 21:25
@kekekeks yeah i'll build it
if i get it working i'm going to try to implement my own userspace that loads just my app
but thats down the road
AlessandroMiorelli
@AlessandroMiorelli
Nov 04 2017 21:49

I'm testing the speed of rendering function

            Stopwatch stopwatch = new Stopwatch();
            var fb = new Framebuffer(PixelFormat.Bgra8888, (int)this.Width, (int)this.Height);
            var r = AvaloniaLocator.Current.GetService<IPlatformRenderInterface>();
            using (var target = r.CreateRenderTarget(new object[] { fb }))
            using (var ctx = new DrawingContext(target.CreateDrawingContext(null)))
            {
                stopwatch.Start();
                ImmediateRenderer.Render(this, ctx);
                Trace.WriteLine(stopwatch.ElapsedMilliseconds);
                var bmp = new Bitmap(PixelFormat.Bgra8888, fb.Address, fb.Width, fb.Height, fb.RowBytes);
                bmp.Save(@"D:\test1.bmp");
            }

            fb.Deallocate();

            using (var rtb = new RenderTargetBitmap((int)this.Width, (int)this.Height))
            {
                stopwatch.Restart();
                rtb.Render(this);
                Trace.WriteLine(stopwatch.ElapsedMilliseconds);
                rtb.Save(@"D:\test2.png");
            }

ImmediateRenderer.Render seems to be slower than RenderTargetBitmap Render

Nikita Tsukanov
@kekekeks
Nov 04 2017 21:51
Are you using Skia backend?
If you are using Direct2D RTB rendering will be faster, but it will take time to get it back from the video memory
So rtb.Save(@"D:\test2.png"); will be slower than bmp.Save(@"D:\test1.bmp");
It also won't actually flush the drawing operations immediately
So if you are using Direct2D backend, your benchmark is incorrect
AlessandroMiorelli
@AlessandroMiorelli
Nov 04 2017 21:53
not the "save" function. I'm watching the stopwatch.elapsedmilliseconds
Nikita Tsukanov
@kekekeks
Nov 04 2017 21:54
Yes, but you don't measure the time of rendering
You are measuring the time of sending drawing commands to DirectX
Switch to Skia backend
You also shouldn't access the bitmap data before disposing DrawingContext
It's not guaranteed to have the complete image at that point
AlessandroMiorelli
@AlessandroMiorelli
Nov 04 2017 22:00
sorry I'm newbie, what's mean "switch to skia backend"?
Nikita Tsukanov
@kekekeks
Nov 04 2017 22:03
In your Main method add UseSkia() after UsePlatformDetect()
Wiesław Šoltés
@wieslawsoltes
Nov 04 2017 23:03
@kekekeks I have finished adding support for netstandar2.0 for HTML-Renderer ArthurHub/HTML-Renderer#112 https://ci.appveyor.com/project/ArthurHub/html-renderer/build/1.5.1.136/artifacts, hopefully it will get merged in main repo :smile:
Nikita Tsukanov
@kekekeks
Nov 04 2017 23:11
:+1: