Exemple #1
0
void _glfwPlatformGetDesktopMode(GLFWvidmode* mode)
{
    int bpp;

    // Get and split display depth
    bpp = DefaultDepth(_glfwLibrary.X11.display, _glfwLibrary.X11.screen);
    _glfwSplitBPP(bpp, &mode->redBits, &mode->greenBits, &mode->blueBits);

    if (_glfwLibrary.X11.FS.modeChanged)
    {
        if (_glfwLibrary.X11.RandR.available)
        {
#if defined(_GLFW_HAS_XRANDR)
            mode->width  = _glfwLibrary.X11.FS.oldWidth;
            mode->height = _glfwLibrary.X11.FS.oldHeight;
#endif /*_GLFW_HAS_XRANDR*/
        }
        else if (_glfwLibrary.X11.VidMode.available)
        {
#if defined(_GLFW_HAS_XF86VIDMODE)
            mode->width  = _glfwLibrary.X11.FS.oldMode.hdisplay;
            mode->height = _glfwLibrary.X11.FS.oldMode.vdisplay;
#endif /*_GLFW_HAS_XF86VIDMODE*/
        }
    }
    else
    {
        mode->width = DisplayWidth(_glfwLibrary.X11.display,
                                   _glfwLibrary.X11.screen);
        mode->height = DisplayHeight(_glfwLibrary.X11.display,
                                     _glfwLibrary.X11.screen);
    }
}
Exemple #2
0
void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode)
{
    if (_glfw.x11.randr.available)
    {
        XRRScreenResources* sr;
        XRRCrtcInfo* ci;

        sr = XRRGetScreenResources(_glfw.x11.display, _glfw.x11.root);
        ci = XRRGetCrtcInfo(_glfw.x11.display, sr, monitor->x11.crtc);

        mode->width = ci->width;
        mode->height = ci->height;

        mode->refreshRate = calculateRefreshRate(getModeInfo(sr, ci->mode));

        XRRFreeCrtcInfo(ci);
        XRRFreeScreenResources(sr);
    }
    else
    {
        mode->width = DisplayWidth(_glfw.x11.display, _glfw.x11.screen);
        mode->height = DisplayHeight(_glfw.x11.display, _glfw.x11.screen);
        mode->refreshRate = 0;
    }

    _glfwSplitBPP(DefaultDepth(_glfw.x11.display, _glfw.x11.screen),
                  &mode->redBits, &mode->greenBits, &mode->blueBits);
}
Exemple #3
0
// Convert RandR mode info to GLFW video mode
//
static GLFWvidmode vidmodeFromModeInfo(const XRRModeInfo* mi)
{
    GLFWvidmode mode;
    mode.width  = mi->width;
    mode.height = mi->height;
    mode.refreshRate = calculateRefreshRate(mi);

    _glfwSplitBPP(DefaultDepth(_glfw.x11.display, _glfw.x11.screen),
                  &mode.redBits, &mode.greenBits, &mode.blueBits);

    return mode;
}
Exemple #4
0
void _glfwPlatformGetDesktopMode(GLFWvidmode* mode)
{
    DEVMODE dm;

    // Get desktop display mode
    dm.dmSize = sizeof(DEVMODE);
    EnumDisplaySettings(NULL, ENUM_REGISTRY_SETTINGS, &dm);

    // Return desktop mode parameters
    mode->width  = dm.dmPelsWidth;
    mode->height = dm.dmPelsHeight;
    _glfwSplitBPP(dm.dmBitsPerPel,
                  &mode->redBits,
                  &mode->greenBits,
                  &mode->blueBits);
}
Exemple #5
0
void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode)
{
    DEVMODEW dm;
    ZeroMemory(&dm, sizeof(dm));
    dm.dmSize = sizeof(dm);

    EnumDisplaySettingsW(monitor->win32.adapterName, ENUM_CURRENT_SETTINGS, &dm);

    mode->width  = dm.dmPelsWidth;
    mode->height = dm.dmPelsHeight;
    mode->refreshRate = dm.dmDisplayFrequency;
    _glfwSplitBPP(dm.dmBitsPerPel,
                  &mode->redBits,
                  &mode->greenBits,
                  &mode->blueBits);
}
Exemple #6
0
// Convert RandR mode info to GLFW video mode
//
static GLFWvidmode vidmodeFromModeInfo(const XRRModeInfo* mi,
                                       const XRRCrtcInfo* ci)
{
    GLFWvidmode mode;

    if (ci->rotation == RR_Rotate_90 || ci->rotation == RR_Rotate_270)
    {
        mode.width  = mi->height;
        mode.height = mi->width;
    }
    else
    {
        mode.width  = mi->width;
        mode.height = mi->height;
    }

    mode.refreshRate = calculateRefreshRate(mi);

    _glfwSplitBPP(DefaultDepth(_glfw.x11.display, _glfw.x11.screen),
                  &mode.redBits, &mode.greenBits, &mode.blueBits);

    return mode;
}
Exemple #7
0
GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found)
{
    GLFWvidmode* result;
    int depth, r, g, b;

    depth = DefaultDepth(_glfw.x11.display, _glfw.x11.screen);
    _glfwSplitBPP(depth, &r, &g, &b);

    *found = 0;

    // Build array of available resolutions

    if (_glfw.x11.randr.available)
    {
        int i, j;
        XRRScreenResources* sr;
        XRROutputInfo* oi;

        sr = XRRGetScreenResources(_glfw.x11.display, _glfw.x11.root);
        oi = XRRGetOutputInfo(_glfw.x11.display, sr, monitor->x11.output);

        result = calloc(oi->nmode, sizeof(GLFWvidmode));

        for (i = 0;  i < oi->nmode;  i++)
        {
            GLFWvidmode mode;
            const XRRModeInfo* mi = getModeInfo(sr, oi->modes[i]);

            mode.width  = mi->width;
            mode.height = mi->height;
            mode.refreshRate = calculateRefreshRate(mi);

            for (j = 0;  j < *found;  j++)
            {
                if (result[j].width == mode.width &&
                    result[j].height == mode.height &&
                    result[j].refreshRate == mode.refreshRate)
                {
                    break;
                }
            }

            if (j < *found)
            {
                // This is a duplicate, so skip it
                continue;
            }

            mode.redBits = r;
            mode.greenBits = g;
            mode.blueBits = b;

            result[*found] = mode;
            (*found)++;
        }

        XRRFreeOutputInfo(oi);
        XRRFreeScreenResources(sr);
    }
    else
    {
        *found = 1;

        result = calloc(1, sizeof(GLFWvidmode));

        result[0].width = DisplayWidth(_glfw.x11.display, _glfw.x11.screen);
        result[0].height = DisplayHeight(_glfw.x11.display, _glfw.x11.screen);
        result[0].redBits = r;
        result[0].greenBits = g;
        result[0].blueBits = b;
        result[0].refreshRate = 0;
    }

    return result;
}
Exemple #8
0
GLFWvidmode* _glfwPlatformGetVideoModes(int* found)
{
    XVisualInfo* visuals;
    XVisualInfo dummy;
    int i, j, visualCount, sizeCount, rgbCount;
    int* rgbs;
    _GLFWvidsize* sizes;
    GLFWvidmode* result;

    visuals = XGetVisualInfo(_glfwLibrary.X11.display, 0, &dummy, &visualCount);
    if (visuals == NULL)
    {
        _glfwSetError(GLFW_PLATFORM_ERROR,
                      "X11/GLX: Failed to retrieve the available visuals");
        return 0;
    }

    // Build array of available RGB channel depths

    rgbs = (int*) malloc(sizeof(int) * visualCount);
    rgbCount = 0;

    for (i = 0;  i < visualCount;  i++)
    {
        int gl, rgba, rgb, r, g, b;

        glXGetConfig(_glfwLibrary.X11.display, &visuals[i], GLX_USE_GL, &gl);
        glXGetConfig(_glfwLibrary.X11.display, &visuals[i], GLX_RGBA, &rgba);

        if (!gl || !rgba)
        {
            // The visual lacks OpenGL or true color, so skip it
            continue;
        }

        // Convert to RGB channel depths and encode
        _glfwSplitBPP(visuals[i].depth, &r, &g, &b);
        rgb = (r << 16) | (g << 8) | b;

        for (j = 0;  j < rgbCount;  j++)
        {
            if (rgbs[j] == rgb)
                break;
        }

        if (j < rgbCount)
        {
            // This channel depth is a duplicate, so skip it
            continue;
        }

        rgbs[rgbCount] = rgb;
        rgbCount++;
    }

    XFree(visuals);

    // Build all permutations of channel depths and resolutions

    sizes = getResolutions(&sizeCount);

    result = (GLFWvidmode*) malloc(sizeof(GLFWvidmode) * rgbCount * sizeCount);
    *found = 0;

    for (i = 0;  i < rgbCount;  i++)
    {
        for (j = 0;  j < sizeCount;  j++)
        {
            result[*found].width     = sizes[j].width;
            result[*found].height    = sizes[j].height;
            result[*found].redBits   = (rgbs[i] >> 16) & 255;
            result[*found].greenBits = (rgbs[i] >> 8) & 255;
            result[*found].blueBits  = rgbs[i] & 255;

            (*found)++;
        }
    }

    free(sizes);
    free(rgbs);

    return result;
}
Exemple #9
0
GLFWvidmode* _glfwPlatformGetVideoModes(int* found)
{
    int dmIndex = 0, count = 0;
    GLFWvidmode* result = NULL;

    *found = 0;

    for (;;)
    {
        int i;
        GLFWvidmode mode;
        DEVMODE dm;

        ZeroMemory(&dm, sizeof(DEVMODE));
        dm.dmSize = sizeof(DEVMODE);

        if (!EnumDisplaySettings(NULL, dmIndex, &dm))
            break;

        dmIndex++;

        if (dm.dmBitsPerPel < 15)
        {
            // Skip modes with less than 15 BPP
            continue;
        }

        mode.width = dm.dmPelsWidth;
        mode.height = dm.dmPelsHeight;
        _glfwSplitBPP(dm.dmBitsPerPel,
                        &mode.redBits,
                        &mode.greenBits,
                        &mode.blueBits);

        for (i = 0;  i < *found;  i++)
        {
            if (_glfwCompareVideoModes(result + i, &mode) == 0)
                break;
        }

        if (i < *found)
        {
            // This is a duplicate, so skip it
            continue;
        }

        if (*found == count)
        {
            void* larger;

            if (count)
                count *= 2;
            else
                count = 128;

            larger = realloc(result, count * sizeof(GLFWvidmode));
            if (!larger)
            {
                free(result);

                _glfwSetError(GLFW_OUT_OF_MEMORY, NULL);
                return NULL;
            }

            result = (GLFWvidmode*) larger;
        }

        result[*found] = mode;
        (*found)++;
    }

    return result;
}
Exemple #10
0
GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found)
{
    int modeIndex = 0, count = 0;
    GLFWvidmode* result = NULL;

    *found = 0;

    for (;;)
    {
        int i;
        GLFWvidmode mode;
        DEVMODE dm;

        ZeroMemory(&dm, sizeof(DEVMODE));
        dm.dmSize = sizeof(DEVMODE);

        if (!EnumDisplaySettings(monitor->win32.name, modeIndex, &dm))
            break;

        modeIndex++;

        if (dm.dmBitsPerPel < 15)
        {
            // Skip modes with less than 15 BPP
            continue;
        }

        mode.width  = dm.dmPelsWidth;
        mode.height = dm.dmPelsHeight;
        mode.refreshRate = dm.dmDisplayFrequency;
        _glfwSplitBPP(dm.dmBitsPerPel,
                      &mode.redBits,
                      &mode.greenBits,
                      &mode.blueBits);

        for (i = 0;  i < *found;  i++)
        {
            if (_glfwCompareVideoModes(result + i, &mode) == 0)
                break;
        }

        if (i < *found)
        {
            // This is a duplicate, so skip it
            continue;
        }

        if (*found == count)
        {
            if (count)
                count *= 2;
            else
                count = 128;

            result = (GLFWvidmode*) realloc(result, count * sizeof(GLFWvidmode));
        }

        result[*found] = mode;
        (*found)++;
    }

    return result;
}
Exemple #11
0
GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* count)
{
    int modeIndex = 0, size = 0;
    GLFWvidmode* result = NULL;

    *count = 0;

    for (;;)
    {
        int i;
        GLFWvidmode mode;
        DEVMODEW dm;

        ZeroMemory(&dm, sizeof(dm));
        dm.dmSize = sizeof(dm);

        if (!EnumDisplaySettingsW(monitor->win32.adapterName, modeIndex, &dm))
            break;

        modeIndex++;

        // Skip modes with less than 15 BPP
        if (dm.dmBitsPerPel < 15)
            continue;

        mode.width  = dm.dmPelsWidth;
        mode.height = dm.dmPelsHeight;
        mode.refreshRate = dm.dmDisplayFrequency;
        _glfwSplitBPP(dm.dmBitsPerPel,
                      &mode.redBits,
                      &mode.greenBits,
                      &mode.blueBits);

        for (i = 0;  i < *count;  i++)
        {
            if (_glfwCompareVideoModes(result + i, &mode) == 0)
                break;
        }

        // Skip duplicate modes
        if (i < *count)
            continue;

        if (monitor->win32.modesPruned)
        {
            // Skip modes not supported by the connected displays
            if (ChangeDisplaySettingsExW(monitor->win32.adapterName,
                                         &dm,
                                         NULL,
                                         CDS_TEST,
                                         NULL) != DISP_CHANGE_SUCCESSFUL)
            {
                continue;
            }
        }

        if (*count == size)
        {
            size += 128;
            result = (GLFWvidmode*) realloc(result, size * sizeof(GLFWvidmode));
        }

        (*count)++;
        result[*count - 1] = mode;
    }

    if (!*count)
    {
        // HACK: Report the current mode if no valid modes were found
        result = calloc(1, sizeof(GLFWvidmode));
        _glfwPlatformGetVideoMode(monitor, result);
        *count = 1;
    }

    return result;
}