6 #include "../kernel/openbox.h"
10 Colormap render_colormap;
12 void render_startup(void)
16 render_depth = DefaultDepth(ob_display, ob_screen);
17 render_visual = DefaultVisual(ob_display, ob_screen);
18 render_colormap = DefaultColormap(ob_display, ob_screen);
20 if (render_depth < 8) {
21 XVisualInfo vinfo_template, *vinfo_return;
22 // search for a TrueColor Visual... if we can't find one...
23 // we will use the default visual for the screen
27 vinfo_template.screen = ob_screen;
28 vinfo_template.class = TrueColor;
29 vinfo_return = XGetVisualInfo(ob_display,
30 VisualScreenMask | VisualClassMask,
31 &vinfo_template, &vinfo_nitems);
35 for (i = 0; i < vinfo_nitems; ++i) {
36 if (vinfo_return[i].depth > max_depth) {
37 if (max_depth == 24 && vinfo_return[i].depth > 24)
38 break; // prefer 24 bit over 32
39 max_depth = vinfo_return[i].depth;
43 if (max_depth < render_depth) best = -1;
46 render_depth = vinfo_return[best].depth;
47 render_visual = vinfo_return[best].visual;
48 render_colormap = XCreateColormap(ob_display, ob_root, render_visual,
55 void x_paint(Window win, Appearance *l, int w, int h)
60 if (w <= 0 || h <= 0) return;
62 g_assert(l->surface.type == Surface_Planar);
63 // printf("painting window %ld\n", win);
65 if (l->pixmap != None) XFreePixmap(ob_display, l->pixmap);
66 l->pixmap = XCreatePixmap(ob_display, ob_root, w, h, render_depth);
67 g_assert(l->pixmap != None);
69 if (l->xftdraw != NULL)
70 XftDrawDestroy(l->xftdraw);
71 l->xftdraw = XftDrawCreate(ob_display, l->pixmap, render_visual,
73 g_assert(l->xftdraw != NULL);
75 if (l->surface.data.planar.pixel_data != NULL)
76 g_free(l->surface.data.planar.pixel_data);
77 l->surface.data.planar.pixel_data = g_new(pixel32, w * h);
79 if (l->surface.data.planar.grad == Background_Solid)
80 gradient_solid(l, w, h);
81 else gradient_render(&l->surface, w, h);
82 for (i = 0; i < l->textures; i++) {
83 switch (l->texture[i].type) {
85 if (l->xftdraw == NULL) {
86 l->xftdraw = XftDrawCreate(ob_display, l->pixmap,
87 render_visual, render_colormap);
89 font_draw(l->xftdraw, l->texture[i].data.text);
94 if (l->surface.data.planar.grad != Background_Solid) {
95 im = XCreateImage(ob_display, render_visual, render_depth,
96 ZPixmap, 0, NULL, w, h, 32, 0);
98 im->byte_order = endian;
99 im->data = l->surface.data.planar.pixel_data;
100 XPutImage(ob_display, l->pixmap, DefaultGC(ob_display, ob_screen),
101 im, 0, 0, 0, 0, w, h);
105 XSetWindowBackgroundPixmap(ob_display, win, l->pixmap);
106 XClearWindow(ob_display, win);
110 void gl_paint(Window win, Appearance *l)
112 glXMakeCurrent(ob_display, win, gl_context);
116 void render_shutdown(void)
120 Appearance *appearance_new(SurfaceType type, int numtex)
125 out = g_new(Appearance, 1);
126 out->surface.type = type;
127 out->textures = numtex;
129 if (numtex) out->texture = g_new(Texture, numtex);
134 p = &out->surface.data.planar;
137 p->border_color = NULL;
138 p->pixel_data = NULL;
144 Appearance *appearance_copy(Appearance *orig)
146 PlanarSurface *spo, *spc;
147 Appearance *copy = g_new(Appearance, 1);
148 copy->surface.type = orig->surface.type;
149 switch (orig->surface.type) {
151 spo = &(orig->surface.data.planar);
152 spc = &(copy->surface.data.planar);
153 spc->grad = spo->grad;
154 spc->relief = spo->relief;
155 spc->bevel = spo->bevel;
156 if (spo->primary != NULL)
157 spc->primary = color_new(spo->primary->r,
160 else spc->primary = NULL;
162 if (spo->secondary != NULL)
163 spc->secondary = color_new(spo->secondary->r,
166 else spc->secondary = NULL;
168 if (spo->border_color != NULL)
169 spc->border_color = color_new(spo->border_color->r,
170 spo->border_color->g,
171 spo->border_color->b);
172 else spc->border_color = NULL;
174 spc->interlaced = spo->interlaced;
175 spc->border = spo->border;
176 spc->pixel_data = NULL;
179 copy->textures = orig->textures;
180 copy->texture = NULL; /* XXX FIX ME */
182 copy->xftdraw = NULL;
186 void appearance_free(Appearance *a)
189 if (a->pixmap != None) XFreePixmap(ob_display, a->pixmap);
190 if (a->xftdraw != NULL) XftDrawDestroy(a->xftdraw);
193 if (a->surface.type == Surface_Planar) {
194 p = &a->surface.data.planar;
195 if (p->primary != NULL) color_free(p->primary);
196 if (p->secondary != NULL) color_free(p->secondary);
197 if (p->border_color != NULL) color_free(p->border_color);