Ticket #2383: vsync.patch

File vsync.patch, 4.5 KB (added by Anduin Withers, 18 years ago)
  • vsync.cpp

     
    3535#include "util-x11.h"    // for OpenGL VSync
    3636
    3737#ifdef USING_OPENGL_VSYNC
    38 #define GLX_GLXEXT_PROTOTYPES
    3938#define XMD_H 1
    4039#include <GL/glx.h>
    4140#include <GL/gl.h>
     
    437436    UpdateNexttrigger();
    438437}
    439438
     439#ifdef USING_OPENGL_VSYNC
     440class OpenGLVideoSyncPrivate
     441{
     442  public:
     443    OpenGLVideoSyncPrivate()
     444    {
     445        glXGetProcAddress("glXGetVideoSyncSGI", m_glXGetVideoSyncSGI);
     446        glXGetProcAddress("glXWaitVideoSyncSGI", m_glXWaitVideoSyncSGI);
     447    }
     448
     449    bool funcsLoaded()
     450    {
     451        return m_glXGetVideoSyncSGI && m_glXWaitVideoSyncSGI;
     452    }
     453
     454  public:
     455    int glXGetVideoSyncSGI(unsigned int *count)
     456    {
     457        return m_glXGetVideoSyncSGI(count);
     458    }
     459
     460    int glXWaitVideoSyncSGI(int divisor, int remainder, unsigned int *count)
     461    {
     462        return m_glXWaitVideoSyncSGI(divisor, remainder, count);
     463    }
     464
     465  private:
     466    template <typename T>
     467    void glXGetProcAddress(const char * const procName, T &ret)
     468    {
     469        ret = reinterpret_cast<T>(glXGetProcAddressARB((const GLubyte *)
     470                                                       procName));
     471        if (!ret)
     472        {
     473            VERBOSE(VB_PLAYBACK,
     474                    QString("Error: glXGetProcAddressARB unable to find %1")
     475                    .arg(procName));
     476        }
     477    }
     478
     479  private:
     480    PFNGLXGETVIDEOSYNCSGIPROC m_glXGetVideoSyncSGI;
     481    PFNGLXWAITVIDEOSYNCSGIPROC m_glXWaitVideoSyncSGI;
     482};
     483#endif // USING_OPENGL_VSYNC
     484
    440485OpenGLVideoSync::OpenGLVideoSync(VideoOutput *video_output,
    441486                                 int frame_interval, int refresh_interval,
    442487                                 bool interlaced)
    443488    : VideoSync(video_output, frame_interval, refresh_interval, interlaced),
    444       m_drawable(0), m_context(0)
     489      m_drawable(0), m_context(0), m_imp(0)
    445490{
     491#ifdef USING_OPENGL_VSYNC
     492    m_imp = new OpenGLVideoSyncPrivate;
     493#endif // USING_OPENGL_VSYNC
    446494}
    447495
    448496OpenGLVideoSync::~OpenGLVideoSync()
     
    457505        if (m_drawable)
    458506            X11S(XDestroyWindow(vo->XJ_disp, m_drawable));
    459507    }
     508    delete m_imp;
    460509#endif /* USING_OPENGL_VSYNC */
    461510}
    462511
     
    503552        return false;
    504553    }
    505554
     555    if (!m_imp->funcsLoaded())
     556    {
     557       VERBOSE(VB_PLAYBACK, QString("GL sync functions not found"));
     558       return false;
     559    }
     560
    506561    int attribList[] = {GLX_RGBA,
    507562                        GLX_RED_SIZE, 1,
    508563                        GLX_GREEN_SIZE, 1,
     
    552607    if (ret != False)
    553608    {
    554609        unsigned int count;
    555         X11S(ret = glXGetVideoSyncSGI(&count));
     610        X11S(ret = m_imp->glXGetVideoSyncSGI(&count));
    556611        if (ret == 0)
    557612        {
    558613            VERBOSE(VB_PLAYBACK, "Using OpenGLVideoSync");
     
    631686
    632687    // Wait for a refresh so we start out synched
    633688    unsigned int count;
    634     err = glXGetVideoSyncSGI(&count);
     689    err = m_imp->glXGetVideoSyncSGI(&count);
    635690    checkGLSyncError("OpenGLVideoSync::Start(): Frame Number Query", err);
    636     err = glXWaitVideoSyncSGI(2, (count+1)%2 ,&count);
     691    err = m_imp->glXWaitVideoSyncSGI(2, (count+1)%2 ,&count);
    637692    checkGLSyncError("OpenGLVideoSync::Start(): A/V Sync", err);
    638693
    639694    // Initialize next trigger
     
    649704    OffsetTimeval(m_nexttrigger, sync_delay);
    650705
    651706    unsigned int frameNum = 0;
    652     int err = glXGetVideoSyncSGI(&frameNum);
     707    int err = m_imp->glXGetVideoSyncSGI(&frameNum);
    653708    checkGLSyncError("Frame Number Query", err);
    654709
    655710    // Always sync to the next retrace execpt when we are very late.
    656711    if ((m_delay = CalcDelay()) > -(m_refresh_interval/2))
    657712    {
    658         err = glXWaitVideoSyncSGI(2, (frameNum+1)%2 ,&frameNum);
     713        err = m_imp->glXWaitVideoSyncSGI(2, (frameNum+1)%2 ,&frameNum);
    659714        checkGLSyncError(msg1, err);
    660715        m_delay = CalcDelay();
    661716    }
     
    664719    if (m_delay > 0)
    665720    {
    666721        uint n = m_delay / m_refresh_interval + 1;
    667         err = glXWaitVideoSyncSGI((n+1), (frameNum+n)%(n+1), &frameNum);
     722        err = m_imp->glXWaitVideoSyncSGI((n+1), (frameNum+n)%(n+1), &frameNum);
    668723        checkGLSyncError(msg2, err);
    669724        m_delay = CalcDelay();
    670725    }
  • vsync.h

     
    214214  private:
    215215    GLXDrawable m_drawable;
    216216    GLXContext  m_context;
     217  private:
     218    class OpenGLVideoSyncPrivate *m_imp;
    217219};
    218220
    219221#ifdef __linux__