lv2 / pugl

A minimal portable API for embeddable GUIs
https://gitlab.com/lv2/pugl/
ISC License
174 stars 34 forks source link

Windows: Cairo widgets going black #119

Open brummer10 opened 9 months ago

brummer10 commented 9 months ago

I recently started to use DPF for some of my projects which in turn use pugl. I run into issues with cairo under windows. Widgets tend to black out after a short while and there is now way to repaint them other then restart the host. This is the original issue reported on DPF: https://github.com/DISTRHO/DPF/issues/437 So I gone check what happens and end up with this patch. https://github.com/brummer10/ToneTwistPlugs/blob/main/pugl.patch

It create a cairo_image_surface on puglWinCairoEnter and provide the cairo_t* pointer for it as DrawContext instead using a HBITMAP. Now all cairo drawings happen outside WM_PAINT. Then, on puglWinCairoLeave we do the paint (BeginPaint -> create win32 surface, copy the image surface over, destroy anything and EndPaint.) I tested this on windows11 and it works perfect. Surly it could be optimized as we didn't relay need to create and destroy the cairo_image_surface on each WM_PAINT, this is only necessary on resize, otherwise we could reuse it. Just I can't see were resizing is handled in the win_cairo source.

brummer10 commented 9 months ago

Doing some optimisation. Now the cairo image surface will be reused as long the size didn't changed, if the size changed it will be re-created to match the new size. https://github.com/brummer10/StompTuner/blob/main/pugl.patch