Xpra-org / xpra

Persistent remote applications for X11; screen sharing for X11, MacOS and MSWindows.
https://xpra.org/
GNU General Public License v2.0
1.9k stars 164 forks source link

faster cairo paint: avoid copying pixels whenever possible #4270

Closed totaam closed 2 months ago

totaam commented 2 months ago

We can use ImageSurface.create_for_data if the pixel data stride satisfies stride_for_width Another undocumented constraint is that the memory must not be read-only..

totaam commented 2 months ago

With the latest test, we report the performance of each call to make_image_surface. Unsuprisingly, the zero-copy options are way faster:

RGBA to cairo.ARGB32 :   162 MPixels/s
RGBX to cairo.ARGB32 :   156 MPixels/s
BGRA to cairo.ARGB32 :  4543 MPixels/s
BGRX to cairo.ARGB32 :   179 MPixels/s
RGB  to cairo.ARGB32 :   170 MPixels/s
BGR  to cairo.ARGB32 :   152 MPixels/s
RGBA to cairo.RGB24  :   192 MPixels/s
RGBX to cairo.RGB24  :   193 MPixels/s
BGRA to cairo.RGB24  :  4529 MPixels/s
BGRX to cairo.RGB24  :  4535 MPixels/s
RGB  to cairo.RGB24  :   192 MPixels/s
BGR  to cairo.RGB24  :   171 MPixels/s

So we should really make sure that the cairo backend tells the decoder modules to provide BGRA or BGRX, not RGB or BGR even if they take up less space.. (the OpenGL backend doesn't care - the pixel upload functions support every format)

totaam commented 2 months ago

Changing the decoders to prefer BGRX / BGRA: