Skip to content

Commit

Permalink
Gtk: Attempt to fix redraw issues on linux with NVidia cards
Browse files Browse the repository at this point in the history
  • Loading branch information
cwensley committed Feb 20, 2021
1 parent efaae07 commit 34a0c32
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 25 deletions.
19 changes: 0 additions & 19 deletions src/Eto.Veldrid.Gtk/GtkVeldridDrawingArea.cs

This file was deleted.

45 changes: 39 additions & 6 deletions src/Eto.Veldrid.Gtk/GtkVeldridSurfaceHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,23 @@

namespace Eto.Veldrid.Gtk
{
public class GtkVeldridSurfaceHandler : GtkControl<GtkVeldridDrawingArea, VeldridSurface, VeldridSurface.ICallback>, VeldridSurface.IHandler, VeldridSurface.IOpenGL
public class GtkVeldridSurfaceHandler : GtkControl<GLArea, VeldridSurface, VeldridSurface.ICallback>, VeldridSurface.IHandler, VeldridSurface.IOpenGL
{
public Size RenderSize => Size.Round((SizeF)Widget.Size * Scale);

float Scale => Widget.ParentWindow?.Screen?.LogicalPixelSize ?? 1;

public GtkVeldridSurfaceHandler()
{
Control = new GtkVeldridDrawingArea();
Control = new GLArea();
Control.CanFocus = true;

// Veldrid technically supports as low as OpenGL 3.0, but the full
// complement of features is only available with 3.3 and higher.
Control.SetRequiredVersion(3, 3);

Control.HasDepthBuffer = true;
Control.HasStencilBuffer = true;

Control.Realized += Control_InitializeGraphicsBackend;
}
Expand Down Expand Up @@ -62,17 +70,25 @@ void Control_InitializeGraphicsBackend(object sender, EventArgs e)
Callback.OnInitializeBackend(Widget, new InitializeEventArgs(RenderSize));

Control.Render += Control_Render;
Widget.SizeChanged += Widget_SizeChanged;
Control.Resize += Control_Resize;
}

private void Widget_SizeChanged(object sender, EventArgs e)
bool skipDraw;

private void Control_Resize(object o, ResizeArgs args)
{
skipDraw = false;
Callback.OnResize(Widget, new ResizeEventArgs(RenderSize));
}

void Control_Render(object o, RenderArgs args)
{
Callback.OnDraw(Widget, EventArgs.Empty);
if (!skipDraw)
{
skipDraw = true;
Callback.OnDraw(Widget, EventArgs.Empty);
}
skipDraw = false;
}

// TODO: Figure this one out! The docstring for this property in Veldrid's OpenGLPlatformInfo is ambiguous.
Expand All @@ -92,7 +108,12 @@ void VeldridSurface.IOpenGL.DeleteContext(IntPtr context)

void VeldridSurface.IOpenGL.SwapBuffers()
{
// This happens automatically in GLArea, so no need to do anything.
// GLArea doesn't support drawing directly, so we queue a render but don't actually call OnDraw
if (skipDraw)
return;

skipDraw = true;
Control.QueueRender();
}

void VeldridSurface.IOpenGL.SetSyncToVerticalBlank(bool on)
Expand All @@ -106,5 +127,17 @@ void VeldridSurface.IOpenGL.SetSwapchainFramebuffer()
void VeldridSurface.IOpenGL.ResizeSwapchain(uint width, uint height)
{
}

void Eto.Forms.Control.IHandler.Invalidate(Rectangle rect, bool invalidateChildren)
{
skipDraw = false;
Control.QueueRender();
}

void Eto.Forms.Control.IHandler.Invalidate(bool invalidateChildren)
{
skipDraw = false;
Control.QueueRender();
}
}
}

0 comments on commit 34a0c32

Please sign in to comment.