Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/GLXLibrary.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2
 * This Source Code Form is subject to the terms of the Mozilla Public
3
 * License, v. 2.0. If a copy of the MPL was not distributed with this
4
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6
#ifndef GFX_GLXLIBRARY_H
7
#define GFX_GLXLIBRARY_H
8
9
#include "GLContextTypes.h"
10
#include "prlink.h"
11
typedef realGLboolean GLboolean;
12
13
// stuff from glx.h
14
#include "X11/Xlib.h"
15
#include "X11/Xutil.h" // for XVisualInfo
16
#include "X11UndefineNone.h"
17
typedef struct __GLXcontextRec* GLXContext;
18
typedef XID GLXPixmap;
19
typedef XID GLXDrawable;
20
/* GLX 1.3 and later */
21
typedef struct __GLXFBConfigRec* GLXFBConfig;
22
// end of stuff from glx.h
23
#include "prenv.h"
24
25
struct PRLibrary;
26
class gfxASurface;
27
28
namespace mozilla {
29
namespace gl {
30
31
class GLXLibrary
32
{
33
public:
34
    bool EnsureInitialized();
35
36
private:
37
    void BeforeGLXCall() const;
38
    void AfterGLXCall() const;
39
40
public:
41
42
#ifdef DEBUG
43
#define BEFORE_CALL BeforeGLXCall();
44
#define AFTER_CALL AfterGLXCall();
45
#else
46
#define BEFORE_CALL
47
#define AFTER_CALL
48
#endif
49
50
#define WRAP(X) \
51
0
    { \
52
0
        BEFORE_CALL \
53
0
        const auto ret = mSymbols. X ; \
54
0
        AFTER_CALL \
55
0
        return ret; \
56
0
    }
Unexecuted instantiation: mozilla::gl::GLXLibrary::fQueryVersion(_XDisplay*, int*, int*) const
Unexecuted instantiation: mozilla::gl::GLXLibrary::fGetClientString(_XDisplay*, int) const
Unexecuted instantiation: mozilla::gl::GLXLibrary::fQueryServerString(_XDisplay*, int, int) const
Unexecuted instantiation: mozilla::gl::GLXLibrary::fQueryExtensionsString(_XDisplay*, int) const
Unexecuted instantiation: mozilla::gl::GLXLibrary::fChooseFBConfig(_XDisplay*, int, int const*, int*) const
Unexecuted instantiation: mozilla::gl::GLXLibrary::fGetFBConfigAttrib(_XDisplay*, __GLXFBConfigRec*, int, int*) const
Unexecuted instantiation: mozilla::gl::GLXLibrary::fCreatePixmap(_XDisplay*, __GLXFBConfigRec*, unsigned long, int const*) const
Unexecuted instantiation: mozilla::gl::GLXLibrary::fCreateContextAttribs(_XDisplay*, __GLXFBConfigRec*, __GLXcontextRec*, int, int const*) const
Unexecuted instantiation: mozilla::gl::GLXLibrary::fCreateNewContext(_XDisplay*, __GLXFBConfigRec*, int, __GLXcontextRec*, int) const
Unexecuted instantiation: mozilla::gl::GLXLibrary::fMakeCurrent(_XDisplay*, unsigned long, __GLXcontextRec*) const
Unexecuted instantiation: mozilla::gl::GLXLibrary::fGetCurrentContext() const
Unexecuted instantiation: mozilla::gl::GLXLibrary::fGetConfig(_XDisplay*, XVisualInfo*, int, int*) const
Unexecuted instantiation: mozilla::gl::GLXLibrary::fGetFBConfigs(_XDisplay*, int, int*) const
Unexecuted instantiation: mozilla::gl::GLXLibrary::fChooseVisual(_XDisplay*, int, int*) const
Unexecuted instantiation: mozilla::gl::GLXLibrary::fCreateGLXPixmapWithConfig(_XDisplay*, __GLXFBConfigRec*, unsigned long) const
Unexecuted instantiation: mozilla::gl::GLXLibrary::fGetVideoSync(unsigned int*) const
Unexecuted instantiation: mozilla::gl::GLXLibrary::fWaitVideoSync(int, int, unsigned int*) const
57
#define VOID_WRAP(X) \
58
0
    { \
59
0
        BEFORE_CALL \
60
0
        mSymbols. X ; \
61
0
        AFTER_CALL \
62
0
    }
Unexecuted instantiation: mozilla::gl::GLXLibrary::fDestroyPixmap(_XDisplay*, unsigned long) const
Unexecuted instantiation: mozilla::gl::GLXLibrary::fWaitX() const
Unexecuted instantiation: mozilla::gl::GLXLibrary::fBindTexImage(_XDisplay*, unsigned long, int, int const*) const
Unexecuted instantiation: mozilla::gl::GLXLibrary::fReleaseTexImage(_XDisplay*, unsigned long, int) const
Unexecuted instantiation: mozilla::gl::GLXLibrary::fDestroyContext(_XDisplay*, __GLXcontextRec*) const
Unexecuted instantiation: mozilla::gl::GLXLibrary::fSwapInterval(_XDisplay*, unsigned long, int) const
Unexecuted instantiation: mozilla::gl::GLXLibrary::fSwapBuffers(_XDisplay*, unsigned long) const
Unexecuted instantiation: mozilla::gl::GLXLibrary::fWaitGL() const
63
64
    void           fDestroyContext(Display* display, GLXContext context) const
65
        VOID_WRAP( fDestroyContext(display, context) )
66
67
    Bool      fMakeCurrent(Display* display, GLXDrawable drawable, GLXContext context) const
68
        WRAP( fMakeCurrent(display, drawable, context) )
69
70
    XVisualInfo* fGetConfig(Display* display, XVisualInfo* info, int attrib, int* value) const
71
        WRAP(    fGetConfig(display, info, attrib, value) )
72
73
    GLXContext fGetCurrentContext() const
74
        WRAP(  fGetCurrentContext() )
75
76
    GLXFBConfig* fChooseFBConfig(Display* display, int screen, const int* attrib_list, int* nelements) const
77
        WRAP(    fChooseFBConfig(display, screen, attrib_list, nelements) )
78
79
    XVisualInfo* fChooseVisual(Display* display, int screen, int* attrib_list) const
80
        WRAP(    fChooseVisual(display, screen, attrib_list) )
81
82
    GLXFBConfig* fGetFBConfigs(Display* display, int screen, int* nelements) const
83
        WRAP(    fGetFBConfigs(display, screen, nelements) )
84
85
    GLXContext fCreateNewContext(Display* display, GLXFBConfig config, int render_type, GLXContext share_list, Bool direct) const
86
        WRAP(  fCreateNewContext(display, config, render_type, share_list, direct) )
87
88
    int       fGetFBConfigAttrib(Display* display, GLXFBConfig config, int attribute, int* value) const
89
        WRAP( fGetFBConfigAttrib(display, config, attribute, value) )
90
91
    void           fSwapBuffers(Display* display, GLXDrawable drawable) const
92
        VOID_WRAP( fSwapBuffers(display, drawable) )
93
94
    const char* fQueryExtensionsString(Display* display, int screen) const
95
        WRAP(   fQueryExtensionsString(display, screen) )
96
97
    const char* fGetClientString(Display* display, int screen) const
98
        WRAP(   fGetClientString(display, screen) )
99
100
    const char* fQueryServerString(Display* display, int screen, int name) const
101
        WRAP(   fQueryServerString(display, screen, name) )
102
103
    GLXPixmap fCreatePixmap(Display* display, GLXFBConfig config, Pixmap pixmap, const int* attrib_list) const
104
        WRAP( fCreatePixmap(display, config, pixmap, attrib_list) )
105
106
    GLXPixmap fCreateGLXPixmapWithConfig(Display* display, GLXFBConfig config, Pixmap pixmap) const
107
        WRAP( fCreateGLXPixmapWithConfig(display, config, pixmap) )
108
109
    void           fDestroyPixmap(Display* display, GLXPixmap pixmap) const
110
        VOID_WRAP( fDestroyPixmap(display, pixmap) )
111
112
    Bool      fQueryVersion(Display* display, int* major, int* minor) const
113
        WRAP( fQueryVersion(display, major, minor) )
114
115
    void           fBindTexImage(Display* display, GLXDrawable drawable, int buffer, const int* attrib_list) const
116
        VOID_WRAP( fBindTexImageEXT(display, drawable, buffer, attrib_list) )
117
118
    void           fReleaseTexImage(Display* display, GLXDrawable drawable, int buffer) const
119
        VOID_WRAP( fReleaseTexImageEXT(display, drawable, buffer) )
120
121
    void           fWaitGL() const
122
        VOID_WRAP( fWaitGL() )
123
124
    void           fWaitX() const
125
        VOID_WRAP( fWaitX() )
126
127
    GLXContext fCreateContextAttribs(Display* display, GLXFBConfig config, GLXContext share_list, Bool direct, const int* attrib_list) const
128
        WRAP(  fCreateContextAttribsARB(display, config, share_list, direct, attrib_list) )
129
130
    int       fGetVideoSync(unsigned int* count) const
131
        WRAP( fGetVideoSyncSGI(count) )
132
133
    int       fWaitVideoSync(int divisor, int remainder, unsigned int* count) const
134
        WRAP( fWaitVideoSyncSGI(divisor, remainder, count) )
135
136
    void           fSwapInterval(Display* dpy, GLXDrawable drawable, int interval) const
137
        VOID_WRAP( fSwapIntervalEXT(dpy, drawable, interval) )
138
139
#undef WRAP
140
#undef VOID_WRAP
141
#undef BEFORE_CALL
142
#undef AFTER_CALL
143
144
    ////
145
146
    GLXPixmap CreatePixmap(gfxASurface* aSurface);
147
    void DestroyPixmap(Display* aDisplay, GLXPixmap aPixmap);
148
    void BindTexImage(Display* aDisplay, GLXPixmap aPixmap);
149
    void ReleaseTexImage(Display* aDisplay, GLXPixmap aPixmap);
150
    void UpdateTexImage(Display* aDisplay, GLXPixmap aPixmap);
151
152
    ////
153
154
    bool UseTextureFromPixmap() { return mUseTextureFromPixmap; }
155
0
    bool HasRobustness() { return mHasRobustness; }
156
0
    bool HasVideoMemoryPurge() { return mHasVideoMemoryPurge; }
157
0
    bool HasCreateContextAttribs() { return mHasCreateContextAttribs; }
158
    bool SupportsTextureFromPixmap(gfxASurface* aSurface);
159
    bool SupportsVideoSync();
160
0
    bool SupportsSwapControl() const { return bool(mSymbols.fSwapIntervalEXT); }
161
0
    bool IsATI() { return mIsATI; }
162
0
    bool IsMesa() { return mClientIsMesa; }
163
164
0
    PRFuncPtr GetGetProcAddress() const {
165
0
        return (PRFuncPtr)mSymbols.fGetProcAddress;
166
0
    }
167
168
private:
169
    struct {
170
        void         (GLAPIENTRY *fDestroyContext) (Display*, GLXContext);
171
        Bool         (GLAPIENTRY *fMakeCurrent) (Display*, GLXDrawable, GLXContext);
172
        XVisualInfo* (GLAPIENTRY *fGetConfig) (Display*, XVisualInfo*, int, int*);
173
        GLXContext   (GLAPIENTRY *fGetCurrentContext) ();
174
        void*        (GLAPIENTRY *fGetProcAddress) (const char*);
175
        GLXFBConfig* (GLAPIENTRY *fChooseFBConfig) (Display*, int, const int*, int*);
176
        XVisualInfo* (GLAPIENTRY *fChooseVisual) (Display*, int, const int*);
177
        GLXFBConfig* (GLAPIENTRY *fGetFBConfigs) (Display*, int, int*);
178
        GLXContext   (GLAPIENTRY *fCreateNewContext) (Display*, GLXFBConfig, int,
179
                                                      GLXContext, Bool);
180
        int          (GLAPIENTRY *fGetFBConfigAttrib) (Display*, GLXFBConfig, int, int*);
181
        void         (GLAPIENTRY *fSwapBuffers) (Display*, GLXDrawable);
182
        const char*  (GLAPIENTRY *fQueryExtensionsString) (Display*, int);
183
        const char*  (GLAPIENTRY *fGetClientString) (Display*, int);
184
        const char*  (GLAPIENTRY *fQueryServerString) (Display*, int, int);
185
        GLXPixmap    (GLAPIENTRY *fCreatePixmap) (Display*, GLXFBConfig, Pixmap,
186
                                                  const int*);
187
        GLXPixmap    (GLAPIENTRY *fCreateGLXPixmapWithConfig) (Display*, GLXFBConfig,
188
                                                              Pixmap);
189
        void         (GLAPIENTRY *fDestroyPixmap) (Display*, GLXPixmap);
190
        Bool         (GLAPIENTRY *fQueryVersion) (Display*, int*, int*);
191
        void         (GLAPIENTRY *fWaitGL) ();
192
        void         (GLAPIENTRY *fWaitX) ();
193
        void         (GLAPIENTRY *fBindTexImageEXT) (Display*, GLXDrawable, int,
194
                                                     const int*);
195
        void         (GLAPIENTRY *fReleaseTexImageEXT) (Display*, GLXDrawable, int);
196
        GLXContext   (GLAPIENTRY *fCreateContextAttribsARB) (Display*, GLXFBConfig,
197
                                                             GLXContext, Bool,
198
                                                             const int*);
199
        int          (GLAPIENTRY *fGetVideoSyncSGI) (unsigned int*);
200
        int          (GLAPIENTRY *fWaitVideoSyncSGI) (int, int, unsigned int*);
201
        void         (GLAPIENTRY *fSwapIntervalEXT) (Display*, GLXDrawable, int);
202
    } mSymbols = {};
203
204
#ifdef DEBUG
205
    void BeforeGLXCall();
206
    void AfterGLXCall();
207
#endif
208
209
    bool mInitialized = false;
210
    bool mTriedInitializing = false;
211
    bool mUseTextureFromPixmap = false;
212
    bool mDebug = false;
213
    bool mHasRobustness = false;
214
    bool mHasVideoMemoryPurge = false;
215
    bool mHasCreateContextAttribs = false;
216
    bool mHasVideoSync = false;
217
    bool mIsATI = false;
218
    bool mIsNVIDIA = false;
219
    bool mClientIsMesa = false;
220
    PRLibrary* mOGLLibrary = nullptr;
221
};
222
223
// a global GLXLibrary instance
224
extern GLXLibrary sGLXLibrary;
225
226
} /* namespace gl */
227
} /* namespace mozilla */
228
#endif /* GFX_GLXLIBRARY_H */
229