~compiz-team/compiz/0.9.11

« back to all changes in this revision

Viewing changes to plugins/opengl/include/opengl/xtoglsync.h

  • Committer: CI Train Bot
  • Author(s): Stephen M. Webb
  • Date: 2015-01-22 14:51:41 UTC
  • mfrom: (3869.1.2 lp-269904-trusty)
  • Revision ID: ci-train-bot@canonical.com-20150122145141-m6fpm6djd2s54try
Use the GL_EXT_x11_sync_object OpenGL extension to synchronize updates with X11 to avoid unrefreshed parts of the screen on Nvidia hardware. Fixes: #269904
Approved by: Christopher Townsend

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright © 2011 NVIDIA Corporation
 
3
 *
 
4
 * Permission to use, copy, modify, distribute, and sell this software
 
5
 * and its documentation for any purpose is hereby granted without
 
6
 * fee, provided that the above copyright notice appear in all copies
 
7
 * and that both that copyright notice and this permission notice
 
8
 * appear in supporting documentation, and that the name of
 
9
 * NVIDIA Corporation not be used in advertising or publicity pertaining to
 
10
 * distribution of the software without specific, written prior permission.
 
11
 * NVIDIA Corporation makes no representations about the suitability of this
 
12
 * software for any purpose. It is provided "as is" without express or
 
13
 * implied warranty.
 
14
 *
 
15
 * NVIDIA CORPORATION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 
16
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
 
17
 * NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY SPECIAL, INDIRECT OR
 
18
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
 
19
 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
 
20
 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
 
21
 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
22
 *
 
23
 * Authors: James Jones <jajones@nvidia.com>
 
24
 */
 
25
 
 
26
#ifndef _GLXTOGLSYNC_H
 
27
#define _GLXTOGLSYNC_H
 
28
 
 
29
#include <composite/composite.h>
 
30
#include <opengl/opengl.h>
 
31
#include <X11/extensions/sync.h>
 
32
 
 
33
#include "opengl/opengl.h"
 
34
 
 
35
/**
 
36
 * Class that manages an XFenceSync wrapped in a GLsync object.
 
37
 *
 
38
 * Can be used to synchronize operations in the GL command stream
 
39
 * with operations in the X command stream.
 
40
 */
 
41
class XToGLSync {
 
42
    public:
 
43
        XToGLSync ();
 
44
        ~XToGLSync ();
 
45
 
 
46
        XSyncAlarm alarm (void) const { return a; }
 
47
        bool isReady (void) const { return state == XTOGLS_READY; }
 
48
 
 
49
        /**
 
50
         * Sends the trigger request to the server. The fence will be signaled
 
51
         * after all rendering has completed.
 
52
         */
 
53
        void trigger (void);
 
54
 
 
55
        /**
 
56
         * Calls glWaitSync. Any OpenGL commands after this will wait for the
 
57
         * fence to be signaled.
 
58
         */
 
59
        void insertWait (void);
 
60
 
 
61
        /**
 
62
         * Blocks until the fence is signaled, or until a timeout expires.
 
63
         *
 
64
         * \param The maximum time to wait, in nanoseconds.
 
65
         * \return One of \c GL_ALREADY_SIGNALED, \c GL_CONDITION_SATISFIED,
 
66
         *      \c GL_TIMEOUT_EXPIRED, or \c GL_WAIT_FAILED.
 
67
         */
 
68
        GLenum checkUpdateFinished (GLuint64 timeout);
 
69
 
 
70
        /**
 
71
         * Resets the fence.
 
72
         */
 
73
        void reset (void);
 
74
        void handleEvent (XSyncAlarmNotifyEvent *ev);
 
75
 
 
76
    private:
 
77
        XSyncFence f;
 
78
        GLsync fGL;
 
79
 
 
80
        XSyncCounter c;
 
81
        XSyncAlarm a;
 
82
        XSyncValue nextCounterValue;
 
83
 
 
84
        enum {
 
85
            XTOGLS_READY,
 
86
            XTOGLS_TRIGGER_SENT,
 
87
            XTOGLS_WAITING,
 
88
            XTOGLS_DONE,
 
89
            XTOGLS_RESET_PENDING,
 
90
        } state;
 
91
 
 
92
        static bool syncValuesInitialized;
 
93
        static XSyncValue zero;
 
94
        static XSyncValue one;
 
95
 
 
96
        static Bool alarmEventPredicate (Display *dpy, XEvent *ev, XPointer arg);
 
97
};
 
98
 
 
99
#endif