~ubuntu-branches/ubuntu/raring/gnome-session/raring

« back to all changes in this revision

Viewing changes to tools/gnome-session-check-accelerated-helper.c

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2012-05-07 11:22:35 UTC
  • mfrom: (1.1.75) (2.2.14 sid)
  • Revision ID: package-import@ubuntu.com-20120507112235-z9pe25ur5d8zt4c6
Tags: 3.4.1-1ubuntu1
* Merge with Debian. Remaining changes:
 - debian/control.in:
   + gnome-session
     - Recommend nautilus and either unity, unity-2d or gnome-shell
     - Only suggest gnome-session-fallback (we don't want it to be installed
       by default)
     - Drop the Recommends on gnome-power-manager, the code gnome-session uses
       has moved to gnome-settings-daemon
   + gnome-session-fallback
     - Recommend cups-pk-helper for gnome-session-fallback so that
       System Settings>Printers works
 - debian/gnome-session-bin.postinst, debian/gnome-session-bin.prerm:
    Moved registering gnome-session binary as a session manager to 
    gnome-session-bin package
 - debian/postinst, postrm:
    set the default lightdm session as ubuntu if none already set
 - don't install defaults.list (installed by desktop-file-utils in ubuntu):
    debian/gnome-session-common.dirs and gnome-session-common.install
 - add debian/gnome-session-common.gsettings-override:
   set ubuntu as the default session if nothing is provided
 - debian/55gnome-session_gnomerc:
    Use POSIX string substitutions (shell internal) instead of external
    basename and cut for startup speed.
 - debian/patches/20_hide_nodisplay.patch:
    Don't show applications in the Sessions properties dialog that have
    NoDisplay=true.
 - debian/patches/21_up_start_on_demand.patch:
    Don't call dkp_client_new() until actually needed. This blocks
    for some time whilst DK-Power is started, if it wasn't running already
    (which is the case during auto-login). This can delay the whole
    session from starting.
 - debian/patches/22_support_autostart_delay.patch:
    Bugzilla patch to support adding a delay to autostart apps, using
    a "X-GNOME-Autostart-Delay" key in the desktop file
 - debian/patches/50_ubuntu_sessions.patch:
    + Add Ubuntu & Ubuntu 2D sessions
    + Add GNOME Classic (Without Effects session). Use notify-osd for
      notifications, but don't add it to RequiredComponents since notify-osd
      doesn't have an autostart .desktop file
    + gnome-shell.desktop adds --session=gnome now that the "ubuntu" session
      is the default. Use TryExec to test if gnome-shell is installed.
 - debian/patches/51_remove_session_saving_from_gui.patch:
    add GNOME_SESSION_SAVE environment variable for people wanting to
    use the save session still, knowing that it can break your system
    if used unwisely (LP: #771896)
 - debian/patches/52_xdg_current_desktop.patch:
    Set XDG_CURRENT_DESKTOP inside gnome-session based on a
    new key 'DesktopName' in gnome-session .desktop files.
 - debian/patches/80_new_upstream_session_dialog.patch:
    Bugzilla patch to change the session dialog. (Deactivated, see bug 807503)
 - debian/patches/95_dbus_request_shutdown.patch:
    Add "RequestShutdown" and "RequestReboot" DBus methods to allow other
    applications to shutdown or reboot the machine via the session manager.
 - debian/patches/96_no_catch_sigsegv.patch:
    Don't register a handler for SIGSEGV. We want Apport to catch these
    crashes so that users can submit useful crash reports.
 - debian/patches/101_screen_lock_on_suspend.patch:
    Use the same logic as gnome-power-manager for deciding the "screen
    lock on suspend" policy. This restores the Jaunty behaviour rather
    than just using the screensaver settings, which is surprising for
    users.
    This patch is deactivated for now, we'll see with the new screensaver and
    screen locking experience what to do (not rebased on gsettings as well)
  - debian/patches/103_kill_the_fail_whale.patch:
    seems that the fail whale try to come back and resist from his removal
    refreshed the patch to ensure it's killed and won't come back ever ever
    again.
  - 104_dont_show_fallback_warning.patch:
    Disable GNOME Fallback warning. It doesn't really explain anything
    and assumes that there aren't people that want to run Fallback.
  - debian/patches/105_hide_session_startup_help.patch:
    Hide Help button on Startup Applications dialog, as it is broken
    and the help documentation hasn't been written for 3.x yet.

Show diffs side-by-side

added added

removed removed

Lines of Context:
70
70
/* for strcasestr */
71
71
#define _GNU_SOURCE
72
72
 
 
73
#include <ctype.h>
73
74
#include <stdio.h>
 
75
#include <stdlib.h>
74
76
#include <string.h>
75
77
 
 
78
#include <regex.h>
 
79
 
76
80
#include <X11/Xlib.h>
77
81
#include <X11/extensions/Xcomposite.h>
78
82
#include <GL/gl.h>
87
91
}
88
92
 
89
93
static int
 
94
_parse_kcmdline (void)
 
95
{
 
96
        FILE *kcmdline;
 
97
        char *line = NULL;
 
98
        size_t line_len = 0;
 
99
        int ret = -1;
 
100
 
 
101
        kcmdline = fopen("/proc/cmdline", "r");
 
102
        if (kcmdline == NULL)
 
103
                return ret;
 
104
 
 
105
        while (getline (&line, &line_len, kcmdline) != -1) {
 
106
                const char *arg;
 
107
                const char *str;
 
108
                int key_len = strlen ("gnome.fallback=");
 
109
 
 
110
                if (line == NULL)
 
111
                        break;
 
112
 
 
113
                /* don't break if we found the argument once: last mention wins */
 
114
 
 
115
                str = line;
 
116
                do {
 
117
                        arg = strstr (str, "gnome.fallback=");
 
118
                        str = arg + key_len;
 
119
 
 
120
                        if (arg &&
 
121
                                        (arg == line || isspace (arg[-1])) && /* gnome.fallback= is really the beginning of an argument */
 
122
                                        (isdigit (arg[key_len]))) { /* the first character of the value of this argument is an integer */
 
123
                                if ((arg[key_len+1] == '\0' || isspace (arg[key_len+1]))) /* the value of this argument is only one character long */
 
124
                                        ret = arg[key_len] - '0';
 
125
                                else /* invalid value */
 
126
                                        ret = 0xDEAD;
 
127
 
 
128
                        }
 
129
                } while (arg != NULL);
 
130
 
 
131
                free (line);
 
132
                line = NULL;
 
133
                line_len = 0;
 
134
        }
 
135
 
 
136
        fclose (kcmdline);
 
137
 
 
138
        return ret;
 
139
}
 
140
 
 
141
static int
90
142
_has_composite (Display *display)
91
143
{
92
144
        int dummy1, dummy2;
98
150
}
99
151
 
100
152
static int
 
153
_is_comment (const char *line)
 
154
{
 
155
        while (*line && isspace(*line))
 
156
                line++;
 
157
 
 
158
        if (*line == '#' || *line == '\0')
 
159
                return 0;
 
160
        else
 
161
                return 1;
 
162
}
 
163
 
 
164
static int
 
165
_is_gl_renderer_blacklisted (const char *renderer)
 
166
{
 
167
        FILE *blacklist;
 
168
        char *line = NULL;
 
169
        size_t line_len = 0;
 
170
        int ret = 1;
 
171
 
 
172
        blacklist = fopen(PKGDATADIR "/hardware-compatibility", "r");
 
173
        if (blacklist == NULL)
 
174
                goto out;
 
175
 
 
176
        while (getline (&line, &line_len, blacklist) != -1) {
 
177
                int whitelist = 0;
 
178
                const char *re_str;
 
179
                regex_t re;
 
180
                int status;
 
181
 
 
182
                if (line == NULL)
 
183
                        break;
 
184
 
 
185
                /* Drop trailing \n */
 
186
                line[strlen(line) - 1] = '\0';
 
187
 
 
188
                if (_is_comment (line) == 0) {
 
189
                        free (line);
 
190
                        line = NULL;
 
191
                        continue;
 
192
                }
 
193
 
 
194
                if (line[0] == '+')
 
195
                        whitelist = 1;
 
196
                else if (line[0] == '-')
 
197
                        whitelist = 0;
 
198
                else {
 
199
                        _print_error ("Invalid syntax in this line for hardware compatibility:");
 
200
                        _print_error (line);
 
201
                        free (line);
 
202
                        line = NULL;
 
203
                        continue;
 
204
                }
 
205
 
 
206
                re_str = line + 1;
 
207
 
 
208
                if (regcomp (&re, re_str, REG_EXTENDED|REG_ICASE|REG_NOSUB) != 0) {
 
209
                        _print_error ("Cannot use this regular expression for hardware compatibility:");
 
210
                        _print_error (re_str);
 
211
                } else {
 
212
                        status = regexec (&re, renderer, 0, NULL, 0);
 
213
                        regfree(&re);
 
214
 
 
215
                        if (status == 0) {
 
216
                                if (whitelist)
 
217
                                        ret = 0;
 
218
                                goto out;
 
219
                        }
 
220
                }
 
221
 
 
222
                free (line);
 
223
                line = NULL;
 
224
        }
 
225
 
 
226
        ret = 0;
 
227
 
 
228
out:
 
229
        if (line != NULL)
 
230
                free (line);
 
231
 
 
232
        if (blacklist != NULL)
 
233
                fclose (blacklist);
 
234
 
 
235
        return ret;
 
236
}
 
237
 
 
238
static int
101
239
_has_hardware_gl (Display *display)
102
240
{
103
241
        int screen;
143
281
                goto out;
144
282
 
145
283
        renderer = (const char *) glGetString (GL_RENDERER);
146
 
        /* The current Mesa software GL renderer string is
147
 
         * "Software Rasterizer".
148
 
         * Gallium has softpipe and llvmpipe. */
149
 
        if (strcasestr (renderer, "software rasterizer") != NULL ||
150
 
            strcasestr (renderer, "softpipe") != NULL ||
151
 
            strcasestr (renderer, "llvmpipe") != NULL)
 
284
        if (_is_gl_renderer_blacklisted (renderer) != 0)
152
285
                goto out;
153
286
 
154
287
        /* we need to get the max texture size while we have a context,
257
390
int
258
391
main (int argc, char **argv)
259
392
{
 
393
        int      kcmdline_parsed;
260
394
        Display *display = NULL;
261
395
        int      ret = 1;
262
396
 
 
397
        kcmdline_parsed = _parse_kcmdline ();
 
398
        if (kcmdline_parsed >= 0) {
 
399
                if (kcmdline_parsed == 0) {
 
400
                        _print_error ("Non-fallback mode forced by kernel command line.");
 
401
                        ret = 0;
 
402
                        goto out;
 
403
                } else if (kcmdline_parsed == 1) {
 
404
                        _print_error ("Fallback mode forced by kernel command line.");
 
405
                        goto out;
 
406
                } else
 
407
                        _print_error ("Invalid value for gnome.fallback passed in kernel command line.");
 
408
        }
 
409
 
263
410
        display = XOpenDisplay (NULL);
264
411
        if (!display) {
265
412
                _print_error ("No X display.");