Skip to content

Commit

Permalink
fix(skia): Enable scaling on HW accelerated render surface
Browse files Browse the repository at this point in the history
Does not support fractional scaling correctly.
  • Loading branch information
MartinZikmund authored and jeromelaban committed Aug 9, 2022
1 parent c6bad3f commit 249c821
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/Uno.UI.Runtime.Skia.Gtk/GLRenderSurfaceBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,12 @@ private void UnoGLDrawingArea_Render(object o, RenderArgs args)
_grContext = TryBuildGRContext();
}

var dpi = _dpi ?? 1f;
var scaledGuardBand = (int)(GuardBand * dpi);
// manage the drawing surface
var res = (int)Math.Max(1.0, Screen.Resolution / 96.0);
var w = Math.Max(0, AllocatedWidth * res);
var h = Math.Max(0, AllocatedHeight * res);
var w = (int)Math.Max(0, AllocatedWidth * dpi);
var h = (int)Math.Max(0, AllocatedHeight * dpi);

if (_renderTarget == null || _surface == null || _renderTarget.Width != w || _renderTarget.Height != h)
{
Expand All @@ -106,8 +108,8 @@ private void UnoGLDrawingArea_Render(object o, RenderArgs args)
}

var glInfo = new GRGlFramebufferInfo((uint)framebuffer, colorType.ToGlSizedFormat());

_renderTarget = new GRBackendRenderTarget(w + GuardBand, h + GuardBand, samples, stencil, glInfo);
_renderTarget = new GRBackendRenderTarget(w + scaledGuardBand, h + scaledGuardBand, samples, stencil, glInfo);

// create the surface
_surface?.Dispose();
Expand All @@ -126,9 +128,16 @@ private void UnoGLDrawingArea_Render(object o, RenderArgs args)
using (new SKAutoCanvasRestore(canvas, true))
{
canvas.Clear(BackgroundColor);

if (_dpi != null)
{
canvas.SetMatrix(SKMatrix.CreateScale((float)dpi, (float)dpi));
}
canvas.Translate(new SKPoint(0, GuardBand));

WUX.Window.Current.Compositor.Render(_surface);

canvas.SetMatrix(SKMatrix.CreateScale((float)1 / dpi, (float)1 / dpi));
}

// update the control
Expand Down

0 comments on commit 249c821

Please sign in to comment.