]> icculus.org git repositories - dana/openbox.git/blob - render2/init.c
add a close button
[dana/openbox.git] / render2 / init.c
1 #include "instance.h"
2 #include "render.h"
3 #include "debug.h"
4
5 static int glXRating(Display *display, XVisualInfo *v)
6 {
7     int rating = 0;
8     int val;
9     RrDebug("evaluating visual %d\n", (int)v->visualid);
10     glXGetConfig(display, v, GLX_BUFFER_SIZE, &val);
11     RrDebug("buffer size %d\n", val);
12
13     switch (val) {
14     case 32:
15         rating += 300;
16     break;
17     case 24:
18         rating += 200;
19     break;
20     case 16:
21         rating += 100;
22     break;
23     }
24
25     glXGetConfig(display, v, GLX_LEVEL, &val);
26     RrDebug("level %d\n", val);
27     if (val != 0)
28         rating = -10000;
29
30     glXGetConfig(display, v, GLX_DEPTH_SIZE, &val);
31     RrDebug("depth size %d\n", val);
32     switch (val) {
33     case 32:
34         rating += 30;
35     break;
36     case 24:
37         rating += 20;
38     break;
39     case 16:
40         rating += 10;
41     break;
42     case 0:
43         rating -= 10000;
44     }
45
46     glXGetConfig(display, v, GLX_DOUBLEBUFFER, &val);
47     RrDebug("double buffer %d\n", val);
48     if (val)
49         rating++;
50     return rating;
51 }
52
53 struct RrInstance *RrInit(Display *display,
54                           int screen)
55 {
56     int count, i = 0, val, best = 0, rate = 0, temp;
57     XVisualInfo vimatch, *vilist;
58     struct RrInstance *ret = NULL;
59
60     vimatch.screen = screen;
61     vimatch.class = TrueColor;
62     vilist = XGetVisualInfo(display, VisualScreenMask | VisualClassMask,
63                             &vimatch, &count);
64
65     if (vilist) {
66         RrDebug("looking for a GL visual in %d visuals\n", count);
67         for (i = 0; i < count; i++) {
68             glXGetConfig(display, &vilist[i], GLX_USE_GL, &val);
69             if (val) {
70                 temp = glXRating(display, &vilist[i]);
71                 if (temp > rate) {
72                     best = i;
73                     rate = temp;
74                 }
75             }
76         }
77     }
78     if (rate > 0) {
79         RrDebug("picked visual %d with rating %d\n", best, rate);
80         ret = RrInstanceNew(display, screen, vilist[best]);
81     }
82     return ret;
83 }
84
85 void RrDestroy(struct RrInstance *inst)
86 {
87     if (inst) {
88         RrInstanceFree(inst);
89     }
90 }