Rendering artifcts when rendering Skia commands in Qt

234 views
Skip to first unread message

Daljit

unread,
Oct 19, 2021, 11:04:34 AM10/19/21
to skia-discuss

Hi,

I'm using Skia in my Qt Quick application. The integration is done through the QSGRenderNode class which allows OpenGL commands to be rendered in paralled with the other Qt Quick content.

To render the content I'm using the following code which creates an SkSurface from the default framebuffer:

sk_sp<SkSurface> SkiaQuickPainter::MakeSkiaSurface(QOpenGLFramebufferObject *fbo)

{

sk_sp<SkSurface> surface = nullptr;

GrGLFramebufferInfo info;

info.fFBOID = fbo ? fbo->handle() : 0;

info.fFormat = GL_RGBA8;

auto surfaceFormat = QOpenGLContext::currentContext()->format();

float renderWidth = fbo ? fbo->width() : m_window->width();

float renderHeight = fbo ? fbo->height() : m_window->height();

GrBackendRenderTarget desc

(renderWidth,

renderHeight,

surfaceFormat.samples(),

surfaceFormat.stencilBufferSize(),

info);

sk_sp<SkColorSpace> srgb = SkColorSpace::MakeSRGB();

surface = SkSurface::MakeFromBackendRenderTarget(m_skiaContext.get(), desc, kBottomLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType, srgb, nullptr, nullptr);

return surface;

}

Then before rendering the content I call GrDirectContext::resetContext() and then call the skia commands. This works fine, but there is a problem. If I try to draw an SkPath (e.g. like this one https://fiddle.skia.org/c/@bezier_curves) skia seems to introduce rendering artifacts on the Qt Quick UI elements. For example, below the text of the button below (which is a Qt Quick button) appears pixelated (the yellow path is an SkPath)Schermata da 2021-10-19 15-33-50.png

The strange thing is that if for example I draw a SkPath composed of a single line, this rendering artifact is not produced (if I call lineTo more than once in a SkPath the issue appears). Example below (yellow is an SkPath)

Schermata del 2021-10-19 15-39-07.png


At first I thought, this was because Skia was messing with the opengl state but I made sure that I always call QQuickWindow::resetOpenGLState() after I finish the rendering with Skia so that shouldn't be a problem.

I've tested this on Linux and Windows.

Any clue on what might be the problem and how to fix it?

Daljit

unread,
Feb 28, 2022, 5:38:03 PM2/28/22
to skia-discuss
I've been investigating this issue for quite sometime now, but haven't been able to come up with a solution. It seems that Skia is quite "invasive" and Qt is unable to recover the OpenGL state to its original state, but not really sure. I've created a small git repo here https://github.com/daljit97/SkiaQtBug which reproduces the problem (it includes a binary of Skia for x64 Windows, but you need Qt to be installed on your system). I've also tried to use Skia in a different thread with a separate OpenGL context and I wasn't able to reproduce the problem that way.
Does anyone on the Skia team have any idea on where the problem might lie?

Brian Osman

unread,
Feb 28, 2022, 5:47:50 PM2/28/22
to skia-d...@googlegroups.com
Hmm. I suspect you're right that Qt's GL state restoration is probably missing something that Skia is changing. Your best bet to track that down is probably to use a GPU debugger like RenderDoc. That will let you record and replay frames of your application, then step through the replay and examine the GL state at each draw call. If you get that working, you can try doing something like:

1) Record a frame where Skia has not drawn anything (or is only drawing a single line)
2) Record a frame where Skia has drawn a complex path, and the Qt rendering is impacted
3) Find the "same" Qt element in both replays (drawn correctly in #1 and incorrectly in #2). Compare the GL state on the two traces - hopefully there will be something obviously different in the render state that explains what's happening.

Assuming you can find the relevant state, it may require a Qt fix/patch (given that it's state that Skia is changing, but Qt isn't restoring). (Or you can manually save/restore whatever it is at the same time that you hand off control).

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/skia-discuss/67be7835-db41-4982-8898-82b082a82617n%40googlegroups.com.

Daljit

unread,
Feb 28, 2022, 9:40:16 PM2/28/22
to skia-discuss
Ok thanks I will try that and see where it goes.
Reply all
Reply to author
Forward
0 new messages