VirtualBox

Changeset 83217 in vbox


Ignore:
Timestamp:
Mar 6, 2020 9:35:40 AM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
136357
Message:

bugref:9637. optional dlopen'ing libXrandr instead of linking. not complete.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/x11/VBoxClient/display-svga-x11.cpp

    r83210 r83217  
    3838 */
    3939#include <stdio.h>
     40#include <dlfcn.h>
    4041#include "VBoxClient.h"
    4142
     
    5455
    5556#define OLD_JUNK
     57
     58//#define DL_OPEN_RANDR
    5659
    5760/** Maximum number of supported screens.  DRM and X11 both limit this to 32. */
     
    114117    int hOutputCount;
    115118    Window rootWindow;
     119    void *pRandLibraryHandle;
     120    void (*pXRRSelectInput) (Display *, Window, int);
     121    Bool (*pXRRQueryExtension) (Display *, int *, int *);
     122    Status (*pXRRQueryVersion) (Display *, int *, int*);
    116123};
    117124
     
    358365    if (RT_FAILURE(startX11MonitorThread()))
    359366        return false;
     367#ifdef DL_OPEN_RANDR
     368    if (x11Context.pXRRSelectInput)
     369        x11Context.pXRRSelectInput(x11Context.pDisplay, x11Context.rootWindow, x11Context.hEventMask);
     370#else
    360371    XRRSelectInput(x11Context.pDisplay, x11Context.rootWindow, x11Context.hEventMask);
     372#endif
    361373    return true;
    362374}
     
    370382    }
    371383    stopX11MonitorThread();
     384    if (x11Context.pRandLibraryHandle)
     385    {
     386        dlclose(x11Context.pRandLibraryHandle);
     387        x11Context.pRandLibraryHandle = NULL;
     388    }
     389#ifdef DL_OPEN_RANDR
     390    if (x11Context.pXRRSelectInput)
     391        x11Context.pXRRSelectInput(x11Context.pDisplay, x11Context.rootWindow, 0);
     392#else
    372393    XRRSelectInput(x11Context.pDisplay, x11Context.rootWindow, 0);
     394#endif
    373395    XCloseDisplay(x11Context.pDisplay);
    374396}
     397
     398#ifdef DL_OPEN_RANDR
     399static int openLibRandR()
     400{
     401    x11Context.pRandLibraryHandle = dlopen("/usr/lib/x86_64-linux-gnu/libXrandr.so", RTLD_LAZY /*| RTLD_LOCAL */);
     402
     403    if (!x11Context.pRandLibraryHandle)
     404    {
     405        VBClLogFatalError("Could not locate libXranr for dlopen\n");
     406        return VERR_NOT_FOUND;
     407    }
     408
     409    x11Context.pXRRSelectInput = (void (*)(Display*, Window, int))
     410        dlsym(x11Context.pRandLibraryHandle, "XRRSelectInput");
     411    if (!x11Context.pXRRSelectInput)
     412    {
     413        VBClLogFatalError("Could not find address for the symbol XRRSelectInput\n");
     414        dlclose(x11Context.pRandLibraryHandle);
     415        x11Context.pRandLibraryHandle = NULL;
     416        return VERR_NOT_FOUND;
     417    }
     418    x11Context.pXRRQueryExtension = (Bool (*)(Display *, int *, int *))
     419        dlsym(x11Context.pRandLibraryHandle, "XRRQueryExtension");
     420    if (!x11Context.pXRRQueryExtension)
     421    {
     422        VBClLogFatalError("Could not find address for the symbol XRRQueryExtension\n");
     423        dlclose(x11Context.pRandLibraryHandle);
     424        x11Context.pRandLibraryHandle = NULL;
     425        return VERR_NOT_FOUND;
     426    }
     427    x11Context.pXRRQueryVersion = (Status (*)(Display *, int *, int*))
     428        dlsym(x11Context.pRandLibraryHandle, "XRRQueryVersion");
     429    if (!x11Context.pXRRQueryVersion)
     430    {
     431        VBClLogFatalError("Could not find address for the symbol XRRQueryVersion\n");
     432        dlclose(x11Context.pRandLibraryHandle);
     433        x11Context.pRandLibraryHandle = NULL;
     434        return VERR_NOT_FOUND;
     435    }
     436    return VINF_SUCCESS;
     437}
     438#endif
    375439
    376440static void x11Connect()
     
    389453        return;
    390454    }
    391     if (!XRRQueryExtension(x11Context.pDisplay, &x11Context.hRandREventBase, &x11Context.hRandRErrorBase))
    392     {
    393         XCloseDisplay(x11Context.pDisplay);
    394         x11Context.pDisplay = NULL;
    395         return;
    396     }
    397     if (!XRRQueryVersion(x11Context.pDisplay, &x11Context.hRandRMajor, &x11Context.hRandRMinor))
    398     {
    399         XCloseDisplay(x11Context.pDisplay);
    400         x11Context.pDisplay = NULL;
    401         return;
     455    bool fSuccess = false;
     456#ifdef DL_OPEN_RANDR
     457    if (x11Context.pXRRQueryExtension)
     458        fSuccess = x11Context.pXRRQueryExtension(x11Context.pDisplay, &x11Context.hRandREventBase, &x11Context.hRandRErrorBase);
     459#else
     460    fSuccess = XRRQueryExtension(x11Context.pDisplay, &x11Context.hRandREventBase, &x11Context.hRandRErrorBase);
     461#endif
     462    if (fSuccess)
     463    {
     464        fSuccess = false;
     465#ifdef DL_OPEN_RANDR
     466    if (x11Context.pXRRQueryVersion)
     467        fSuccess = x11Context.pXRRQueryVersion(x11Context.pDisplay, &x11Context.hRandRMajor, &x11Context.hRandRMinor);
     468#else
     469        fSuccess = XRRQueryVersion(x11Context.pDisplay, &x11Context.hRandRMajor, &x11Context.hRandRMinor);
     470#endif
     471        if (!fSuccess)
     472        {
     473            XCloseDisplay(x11Context.pDisplay);
     474            x11Context.pDisplay = NULL;
     475            return;
     476        }
    402477    }
    403478    x11Context.hEventMask = 0;
     
    411486    x11Context.rootWindow = DefaultRootWindow(x11Context.pDisplay);
    412487    x11Context.hOutputCount = determineOutputCount();
     488    x11Context.pXRRSelectInput = NULL;
     489    x11Context.pRandLibraryHandle = NULL;
     490    x11Context.pXRRQueryExtension = NULL;
     491    x11Context.pXRRQueryVersion = NULL;
     492#ifdef DL_OPEN_RANDR
     493    if (openLibRandR() != VINF_SUCCESS)
     494    {
     495        XCloseDisplay(x11Context.pDisplay);
     496        x11Context.pDisplay = NULL;
     497        return;
     498    }
     499#endif
    413500}
    414501
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette