File: fglrxinfo.c

package info (click to toggle)
xvba-video 0.8.0-5
  • links: PTS, VCS
  • area: contrib
  • in suites: wheezy
  • size: 2,240 kB
  • sloc: ansic: 11,991; sh: 8,759; makefile: 189; python: 93
file content (221 lines) | stat: -rw-r--r-- 6,741 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/*
 *  fglrxinfo.c - FGLRX driver info
 *
 *  xvba-video (C) 2009-2011 Splitted-Desktop Systems
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 */

#include "sysdeps.h"
#define NEED_REPLIES
#include <X11/Xlibint.h>
#include <X11/Xutil.h>
#include <X11/extensions/Xext.h>
#include <X11/extensions/extutil.h>
#include "fglrxinfo.h"

#define ATIFGL_EXTENSION_NAME "ATIFGLEXTENSION"
#define ATIFGL_EXTENSION_EVENTS 0

typedef struct _FGLGetDriverData {
    CARD8   reqType;
    CARD8   fireglReqType;
    CARD16  length B16;
    CARD32  screen B32;
    CARD16  size B16;
    CARD16  pad1;
} xFGLGetDriverDataReq;
#define sz_xFGLGetDriverDataReq sizeof(xFGLGetDriverDataReq)

typedef struct {
    BYTE    type;
    BYTE    pad1;
    CARD16  sequenceNumber B16;
    CARD32  length B32;
    CARD8   majorVersion;
    CARD8   minorVersion;
    CARD8   patchlevel B16;
    CARD8   BIOSVersionMajor;
    CARD8   BIOSVersionMinor;
    CARD8   HasSecondary;
    CARD16  pad3 B16;
    CARD16  pad4 B16;
    CARD16  deviceID B16;
    CARD32  pad5 B32;
    CARD32  pad6 B32;
    CARD32  pad7 B32;
    // ... there are more fields
} xFGLGetDriverDataReply;
#define sz_xFGLGetDriverDataReply sizeof(xFGLGetDriverDataReply)

#define X_FGLGetDriverData 0

static XExtensionInfo _fglext_ext_info_data;
static XExtensionInfo *fglext_ext_info = &_fglext_ext_info_data;
static /* const */ char *fglext_extension_name = ATIFGL_EXTENSION_NAME;

#define xFGLCheckExtension(dpy,i,val) \
  XextCheckExtension (dpy, i, fglext_extension_name, val)

static int close_display();
static /* const */ XExtensionHooks fglext_extension_hooks = {
    NULL,                               /* create_gc */
    NULL,                               /* copy_gc */
    NULL,                               /* flush_gc */
    NULL,                               /* free_gc */
    NULL,                               /* create_font */
    NULL,                               /* free_font */
    close_display,                      /* close_display */
    NULL,                               /* wire_to_event */
    NULL,                               /* event_to_wire */
    NULL,                               /* error */
    NULL,                               /* error_string */
};

static XEXT_GENERATE_FIND_DISPLAY (find_display, fglext_ext_info,
                                   fglext_extension_name, 
                                   &fglext_extension_hooks,
                                   ATIFGL_EXTENSION_EVENTS, NULL)

static XEXT_GENERATE_CLOSE_DISPLAY (close_display, fglext_ext_info)

Bool fglrx_is_dri_capable(Display *dpy, int screen)
{
    char **extensions;
    int i, n_extensions, has_fglext = 0, has_fglrxdri = 0;

    extensions = XListExtensions(dpy, &n_extensions);
    if (!extensions)
        return False;

    for (i = 0; i < n_extensions; i++) {
        if (strcmp(extensions[i], ATIFGL_EXTENSION_NAME) == 0)
            has_fglext = 1;
        if (strcmp(extensions[i], "ATIFGLRXDRI") == 0)
            has_fglrxdri = 1;
    }
    XFreeExtensionList(extensions);
    return has_fglext && has_fglrxdri;
}

Bool fglrx_get_version(
    Display    *dpy,
    int         screen,
    int        *ddxDriverMajorVersion,
    int        *ddxDriverMinorVersion,
    int        *ddxDriverPatchVersion
)
{
    XExtDisplayInfo *info = find_display (dpy);
    xFGLGetDriverDataReply rep;
    xFGLGetDriverDataReq  *req;

    if (ddxDriverMajorVersion)
        *ddxDriverMajorVersion = 0;
    if (ddxDriverMinorVersion)
        *ddxDriverMinorVersion = 0;
    if (ddxDriverPatchVersion)
        *ddxDriverPatchVersion = 0;

    if(!XextHasExtension(info))
        return False;

    xFGLCheckExtension (dpy, info, False);

    LockDisplay (dpy);
    GetReq (FGLGetDriverData, req);
    req->reqType = info->codes->major_opcode;
    req->fireglReqType = X_FGLGetDriverData;
    req->screen = screen;
    if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
        UnlockDisplay (dpy);
        SyncHandle ();
        return False;
    }
    UnlockDisplay (dpy);
    SyncHandle ();

    if (ddxDriverMajorVersion)
        *ddxDriverMajorVersion = rep.majorVersion;
    if (ddxDriverMinorVersion)
        *ddxDriverMinorVersion = rep.minorVersion;
    if (ddxDriverPatchVersion)
        *ddxDriverPatchVersion = rep.patchlevel;

    return True;
}

int fglrx_check_version(int major, int minor, int micro)
{
    static int is_initialized = -1;
    static int fglrx_version_major, fglrx_version_minor, fglrx_version_micro;

    if (is_initialized < 0) {
        Display *dpy = XOpenDisplay(NULL);
        if (!dpy)
            is_initialized = 0;
        else {
            is_initialized = fglrx_get_version(dpy, DefaultScreen(dpy),
                                               &fglrx_version_major,
                                               &fglrx_version_minor,
                                               &fglrx_version_micro);
            XCloseDisplay(dpy);
        }
    }

    return (is_initialized &&
            ((fglrx_version_major > major) ||
             (fglrx_version_major == major &&
              fglrx_version_minor > minor) ||
             (fglrx_version_major == major &&
              fglrx_version_minor == minor &&
              fglrx_version_micro >= micro)));
}

Bool fglrx_get_device_id(
    Display      *dpy,
    int           screen,
    unsigned int *deviceID
)
{
    XExtDisplayInfo *info = find_display(dpy);
    xFGLGetDriverDataReply rep;
    xFGLGetDriverDataReq  *req;

    if (deviceID)
        *deviceID = 0;

    if(!XextHasExtension(info))
        return False;

    xFGLCheckExtension(dpy, info, False);

    LockDisplay(dpy);
    GetReq(FGLGetDriverData, req);
    req->reqType       = info->codes->major_opcode;
    req->fireglReqType = X_FGLGetDriverData;
    req->screen        = screen;
    if (!_XReply(dpy, (xReply *) &rep, 0, xTrue)) {
        UnlockDisplay(dpy);
        SyncHandle();
        return False;
    }
    UnlockDisplay(dpy);
    SyncHandle();

    if (deviceID)
        *deviceID = rep.deviceID;
    return True;
}