OutSystems / WebView

Avalonia/WPF control that wraps CefGlue webview control
Apache License 2.0
358 stars 40 forks source link

OSR scaling #319

Closed tkefauver closed 10 months ago

tkefauver commented 10 months ago

I've noticed on both mac and windows when using OSR that the webview resolution is fuzzy, kind of blurry (using Avalonia11 branch). It looks fine w/o OSR but when enabled it seems like the OSR isn't taking display scaling into account. Both my mac and windows machines have ~2x scaling and the webview render looks like its using the internal window dimensions and not the screen so the resolution is low.

Is there a way to scale the output? I tried using the chromium flag force-device-scale-factor but it didn't have any effect.

joaompneves commented 10 months ago

OSR is really not recommended, because it has several issues and performance drawbacks

tkefauver commented 10 months ago

Its unfortunately necessary to work around air space issues and I know it can look equivalent to windowed rendering but I guess I'll have to dig into the glue to see what's going on with it.

tkefauver commented 10 months ago

@joaompneves I fixed it!

In the glue I wrapped the Image in AvaloniaOffScreenControlHost into a Viewbox. Then get Avalonia's screen scaling info in AttachedToVisualTree for the OffScreenRenderSurface.DeviceScaleFactor property so its scaled then. The tricky part was using DefaultDpi in AvaloniaRenderSurface.CreateBitmap and not the actual. That way the Viewbox handles the scaling and renders nice and crispy.

I could do a PR for it if you want to see.

tkefauver commented 10 months ago

Mac is not as simple, avalonia doesnt report actual scale, its always 1. Monomac does though through NSScreen. Maybe you know how but avalonia doesn't provide.

Edit: IRenderRoot.RenderScaling has the correct scaling on mac so nothing else is needed