12 #include "kernel/openbox.h"
19 XVisualInfo render_visual_info;
21 Visual *render_visual;
22 Colormap render_colormap;
24 int render_red_offset = 0, render_green_offset = 0, render_blue_offset = 0;
25 int render_red_shift, render_green_shift, render_blue_shift;
26 int render_red_mask, render_green_mask, render_blue_mask;
29 GLXContext render_glx_context;
31 int render_glx_rating(XVisualInfo *v)
36 printf("evaluating visual %d\n", v->visualid);
37 glXGetConfig(ob_display, v, GLX_BUFFER_SIZE, &val);
38 printf("buffer size %d\n", val);
52 glXGetConfig(ob_display, v, GLX_LEVEL, &val);
53 printf("level %d\n", val);
57 glXGetConfig(ob_display, v, GLX_DEPTH_SIZE, &val);
58 printf("depth size %d\n", val);
73 glXGetConfig(ob_display, v, GLX_DOUBLEBUFFER, &val);
74 printf("double buffer %d\n", val);
80 void render_startup(void)
82 int count, i = 0, val, best = 0, rate = 0, temp;
83 XVisualInfo vimatch, *vilist;
85 render_depth = DefaultDepth(ob_display, ob_screen);
86 render_visual = DefaultVisual(ob_display, ob_screen);
87 render_colormap = DefaultColormap(ob_display, ob_screen);
89 vimatch.screen = ob_screen;
90 vimatch.class = TrueColor;
91 vilist = XGetVisualInfo(ob_display, VisualScreenMask | VisualClassMask,
95 printf("looking for a GL visualin %d visuals\n", count);
96 for (i = 0; i < count; i++) {
97 glXGetConfig(ob_display, &vilist[i], GLX_USE_GL, &val);
99 temp = render_glx_rating(&vilist[i]);
108 printf("picked visual %d with rating %d\n", best, rate);
109 render_depth = vilist[best].depth;
110 render_visual = vilist[best].visual;
111 render_colormap = XCreateColormap(ob_display, ob_root,
112 render_visual, AllocNone);
113 render_visual_info = vilist[best];
114 render_glx_context = glXCreateContext(ob_display, &render_visual_info,
116 if (render_glx_context == NULL)
124 switch (render_visual->class) {
129 g_critical("unsupported visual class.\n");
135 void truecolor_startup(void)
137 unsigned long red_mask, green_mask, blue_mask;
138 XImage *timage = NULL;
140 timage = XCreateImage(ob_display, render_visual, render_depth,
141 ZPixmap, 0, NULL, 1, 1, 32, 0);
142 g_assert(timage != NULL);
143 /* find the offsets for each color in the visual's masks */
144 render_red_mask = red_mask = timage->red_mask;
145 render_green_mask = green_mask = timage->green_mask;
146 render_blue_mask = blue_mask = timage->blue_mask;
148 render_red_offset = 0;
149 render_green_offset = 0;
150 render_blue_offset = 0;
152 while (! (red_mask & 1)) { render_red_offset++; red_mask >>= 1; }
153 while (! (green_mask & 1)) { render_green_offset++; green_mask >>= 1; }
154 while (! (blue_mask & 1)) { render_blue_offset++; blue_mask >>= 1; }
156 render_red_shift = render_green_shift = render_blue_shift = 8;
157 while (red_mask) { red_mask >>= 1; render_red_shift--; }
158 while (green_mask) { green_mask >>= 1; render_green_shift--; }
159 while (blue_mask) { blue_mask >>= 1; render_blue_shift--; }
163 void render_shutdown(void)
167 Appearance *appearance_new(SurfaceType type, int numtex)
172 out = g_new(Appearance, 1);
173 out->surface.type = type;
174 out->textures = numtex;
175 if (numtex) out->texture = g_new0(Texture, numtex);
176 else out->texture = NULL;
180 p = &out->surface.data.planar;
183 p->border_color = NULL;
184 p->bevel_dark = NULL;
185 p->bevel_light = NULL;
186 p->pixel_data = NULL;
192 Appearance *appearance_copy(Appearance *orig)
194 PlanarSurface *spo, *spc;
195 Appearance *copy = g_new(Appearance, 1);
196 copy->surface.type = orig->surface.type;
197 switch (orig->surface.type) {
199 spo = &(orig->surface.data.planar);
200 spc = &(copy->surface.data.planar);
201 spc->grad = spo->grad;
202 spc->relief = spo->relief;
203 spc->bevel = spo->bevel;
204 if (spo->primary != NULL)
205 spc->primary = color_new(spo->primary->r,
208 else spc->primary = NULL;
210 if (spo->secondary != NULL)
211 spc->secondary = color_new(spo->secondary->r,
214 else spc->secondary = NULL;
216 if (spo->border_color != NULL)
217 spc->border_color = color_new(spo->border_color->r,
218 spo->border_color->g,
219 spo->border_color->b);
220 else spc->border_color = NULL;
222 if (spo->bevel_dark != NULL)
223 spc->bevel_dark = color_new(spo->bevel_dark->r,
226 else spc->bevel_dark = NULL;
228 if (spo->bevel_light != NULL)
229 spc->bevel_light = color_new(spo->bevel_light->r,
231 spo->bevel_light->b);
232 else spc->bevel_light = NULL;
234 spc->interlaced = spo->interlaced;
235 spc->border = spo->border;
236 spc->pixel_data = NULL;
239 copy->textures = orig->textures;
240 copy->texture = g_memdup(orig->texture, orig->textures * sizeof(Texture));
244 void appearance_free(Appearance *a)
250 if (a->surface.type == Surface_Planar) {
251 p = &a->surface.data.planar;
252 color_free(p->primary);
253 color_free(p->secondary);
254 color_free(p->border_color);
255 color_free(p->bevel_dark);
256 color_free(p->bevel_light);
257 g_free(p->pixel_data);
264 void pixel32_to_pixmap(pixel32 *in, Pixmap out, int x, int y, int w, int h)
268 im = XCreateImage(ob_display, render_visual, render_depth,
269 ZPixmap, 0, NULL, w, h, 32, 0);
270 g_assert(im != NULL);
271 im->byte_order = render_endian;
272 /* this malloc is a complete waste of time on normal 32bpp
273 as reduce_depth just sets im->data = data and returns
275 scratch = g_new(pixel32, im->width * im->height);
276 im->data = (char*) scratch;
277 reduce_depth(in, im);
278 XPutImage(ob_display, out, DefaultGC(ob_display, ob_screen),
279 im, 0, 0, x, y, w, h);
285 void appearance_minsize(Appearance *l, int *w, int *h)
291 switch (l->surface.type) {
293 if (l->surface.data.planar.relief != Flat) {
294 switch (l->surface.data.planar.bevel) {
302 } else if (l->surface.data.planar.border)
305 for (i = 0; i < l->textures; ++i) {
306 switch (l->texture[i].type) {
308 *w += l->texture[i].data.mask.mask->w;
309 *h += l->texture[i].data.mask.mask->h;
312 m = font_measure_string(l->texture[i].data.text.font,
313 l->texture[i].data.text.string,
314 l->texture[i].data.text.shadow,
315 l->texture[i].data.text.offset);
317 m = font_height(l->texture[i].data.text.font,
318 l->texture[i].data.text.shadow,
319 l->texture[i].data.text.offset);
323 *w += l->texture[i].data.rgba.width;
324 *h += l->texture[i].data.rgba.height;
334 gboolean render_pixmap_to_rgba(Pixmap pmap, Pixmap mask,
335 int *w, int *h, pixel32 **data)
339 guint pw, ph, mw, mh, xb, xd, i, x, y, di;
340 XImage *xi, *xm = NULL;
342 if (!XGetGeometry(ob_display, pmap, &xr, &xx, &xy, &pw, &ph, &xb, &xd))
345 if (!XGetGeometry(ob_display, mask, &xr, &xx, &xy, &mw, &mh, &xb, &xd))
347 if (pw != mw || ph != mh || xd != 1)
351 xi = XGetImage(ob_display, pmap, 0, 0, pw, ph, 0xffffffff, ZPixmap);
356 xm = XGetImage(ob_display, mask, 0, 0, mw, mh, 0xffffffff, ZPixmap);
361 *data = g_new(pixel32, pw * ph);
362 increase_depth(*data, xi);
365 /* apply transparency from the mask */
367 for (i = 0, y = 0; y < ph; ++y) {
368 for (x = 0; x < pw; ++x, ++i) {
369 if (!((((unsigned)xm->data[di + x / 8]) >> (x % 8)) & 0x1))
370 (*data)[i] &= ~(0xff << default_alpha_offset);
372 di += xm->bytes_per_line;
382 void gl_paint(Window win, Appearance *l)
386 int i, transferred = 0, sw, b, d;
387 pixel32 *source, *dest;
389 int tempx, tempy, absx, absy, absw, absh;
392 int w = l->area.width;
393 int h = l->area.height;
394 Rect tarea; /* area in which to draw textures */
395 if (w <= 0 || h <= 0 || x+w <= 0 || y+h <= 0) return;
397 g_assert(l->surface.type == Surface_Planar);
399 printf("making %p, %p, %p current\n", ob_display, win, render_glx_context);
400 err = glXMakeCurrent(ob_display, win, render_glx_context);
403 glMatrixMode(GL_MODELVIEW);
405 glMatrixMode(GL_PROJECTION);
407 glOrtho(0, 1376, 1032, 0, 0, 10);
408 if (XGetGeometry(ob_display, win, &root, &tempx, &tempy,
409 &absw, &absh, &b, &d) &&
410 XTranslateCoordinates(ob_display, win, root, tempx, tempy,
411 &absx, &absy, &child))
412 printf("window at %d, %d (%d,%d)\n", absx, absy, absw, absh);
416 glViewport(0, 0, 1376, 1032);
417 glMatrixMode(GL_MODELVIEW);
418 glTranslatef(-absx, 1032-absh-absy, 0);
419 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
422 if (l->surface.data.planar.grad == Background_ParentRelative) {
425 render_gl_gradient(&l->surface, absx+x, absy+y, absw, absh);
427 glXSwapBuffers(ob_display, win);