Fixed bug 3273 - Fix for slow video subsystem initialization when using XRandR.
authorSam Lantinga <slouken@libsdl.org>
Tue, 05 Sep 2017 08:24:38 -0700
changeset 11454f6b9e7bd038a
parent 11453 a2424c89f53e
child 11455 9e33d1be5d65
Fixed bug 3273 - Fix for slow video subsystem initialization when using XRandR.

Martín Golini

I'm having a very slow initialization of the video subsystem that locks the window creation for about 500 ms ( tested in at least 4 different systems ). What i found is that X11_InitModes_XRandR is using XRRGetScreenResources, that explicitly ask to poll the hardware for changes. This is not really necessary since if the data is already available you can use XRRGetScreenResourcesCurrent.
I attached a tentative patch that fix this issue. With the patch there's no lock when the subsystem is initialized and the window creation is instant in my applications. The patch only uses XRRGetScreenResourcesCurrent in X11_InitModes_XRandR but it could be potentially used in X11_GetDisplayModes and X11_SetDisplayMode.
src/video/x11/SDL_x11modes.c
src/video/x11/SDL_x11sym.h
     1.1 --- a/src/video/x11/SDL_x11modes.c	Mon Sep 04 23:10:12 2017 -0700
     1.2 +++ b/src/video/x11/SDL_x11modes.c	Tue Sep 05 08:24:38 2017 -0700
     1.3 @@ -396,9 +396,16 @@
     1.4                  X11_XFree(pixmapformats);
     1.5              }
     1.6  
     1.7 -            res = X11_XRRGetScreenResources(dpy, RootWindow(dpy, screen));
     1.8 -            if (!res) {
     1.9 -                continue;
    1.10 +            res = X11_XRRGetScreenResourcesCurrent(dpy, RootWindow(dpy, screen));
    1.11 +            if (!res || res->noutput == 0) {
    1.12 +                if (res) {
    1.13 +                    X11_XRRFreeScreenResources(res);
    1.14 +                }
    1.15 +
    1.16 +                res = X11_XRRGetScreenResources(dpy, RootWindow(dpy, screen));
    1.17 +                if (!res) {
    1.18 +                    continue;
    1.19 +                }
    1.20              }
    1.21  
    1.22              for (output = 0; output < res->noutput; output++) {
     2.1 --- a/src/video/x11/SDL_x11sym.h	Mon Sep 04 23:10:12 2017 -0700
     2.2 +++ b/src/video/x11/SDL_x11sym.h	Tue Sep 05 08:24:38 2017 -0700
     2.3 @@ -292,6 +292,7 @@
     2.4  SDL_X11_SYM(void,XRRSetScreenSize,(Display *dpy, Window window,int width, int height,int mmWidth, int mmHeight),(dpy,window,width,height,mmWidth,mmHeight),)
     2.5  SDL_X11_SYM(Status,XRRGetScreenSizeRange,(Display *dpy, Window window,int *minWidth, int *minHeight, int *maxWidth, int *maxHeight),(dpy,window,minWidth,minHeight,maxWidth,maxHeight),return)
     2.6  SDL_X11_SYM(XRRScreenResources *,XRRGetScreenResources,(Display *dpy, Window window),(dpy, window),return)
     2.7 +SDL_X11_SYM(XRRScreenResources *,XRRGetScreenResourcesCurrent,(Display *dpy, Window window),(dpy, window),return)
     2.8  SDL_X11_SYM(void,XRRFreeScreenResources,(XRRScreenResources *resources),(resources),)
     2.9  SDL_X11_SYM(XRROutputInfo *,XRRGetOutputInfo,(Display *dpy, XRRScreenResources *resources, RROutput output),(dpy,resources,output),return)
    2.10  SDL_X11_SYM(void,XRRFreeOutputInfo,(XRROutputInfo *outputInfo),(outputInfo),)