10 #include "../kernel/openbox.h"
13 Visual
*render_visual
;
14 Colormap render_colormap
;
15 int render_red_offset
= 0, render_green_offset
= 0, render_blue_offset
= 0;
16 int render_red_shift
, render_green_shift
, render_blue_shift
;
18 void render_startup(void)
22 render_depth
= DefaultDepth(ob_display
, ob_screen
);
23 render_visual
= DefaultVisual(ob_display
, ob_screen
);
24 render_colormap
= DefaultColormap(ob_display
, ob_screen
);
26 if (render_depth
< 8) {
27 XVisualInfo vinfo_template
, *vinfo_return
;
28 /* search for a TrueColor Visual... if we can't find one...
29 we will use the default visual for the screen */
33 vinfo_template
.screen
= ob_screen
;
34 vinfo_template
.class = TrueColor
;
35 vinfo_return
= XGetVisualInfo(ob_display
,
36 VisualScreenMask
| VisualClassMask
,
37 &vinfo_template
, &vinfo_nitems
);
41 for (i
= 0; i
< vinfo_nitems
; ++i
) {
42 if (vinfo_return
[i
].depth
> max_depth
) {
43 if (max_depth
== 24 && vinfo_return
[i
].depth
> 24)
44 break; /* prefer 24 bit over 32 */
45 max_depth
= vinfo_return
[i
].depth
;
49 if (max_depth
< render_depth
) best
= -1;
52 render_depth
= vinfo_return
[best
].depth
;
53 render_visual
= vinfo_return
[best
].visual
;
54 render_colormap
= XCreateColormap(ob_display
, ob_root
, render_visual
,
62 void truecolor_startup(void)
64 unsigned long red_mask
, green_mask
, blue_mask
;
65 XImage
*timage
= NULL
;
67 timage
= XCreateImage(ob_display
, render_visual
, render_depth
,
68 ZPixmap
, 0, NULL
, 1, 1, 32, 0);
69 g_assert(timage
!= NULL
);
70 /* find the offsets for each color in the visual's masks */
71 red_mask
= timage
->red_mask
;
72 green_mask
= timage
->green_mask
;
73 blue_mask
= timage
->blue_mask
;
75 render_red_offset
= 0;
76 render_green_offset
= 0;
77 render_blue_offset
= 0;
79 while (! (red_mask
& 1)) { render_red_offset
++; red_mask
>>= 1; }
80 while (! (green_mask
& 1)) { render_green_offset
++; green_mask
>>= 1; }
81 while (! (blue_mask
& 1)) { render_blue_offset
++; blue_mask
>>= 1; }
83 render_red_shift
= render_green_shift
= render_blue_shift
= 8;
84 while (red_mask
) { red_mask
>>= 1; render_red_shift
--; }
85 while (green_mask
) { green_mask
>>= 1; render_green_shift
--; }
86 while (blue_mask
) { blue_mask
>>= 1; render_blue_shift
--; }
90 void x_paint(Window win
, Appearance
*l
, int x
, int y
, int w
, int h
)
92 int i
, transferred
= 0;
95 if (w
<= 0 || h
<= 0 || x
+w
<= 0 || y
+h
<= 0) return;
97 g_assert(l
->surface
.type
== Surface_Planar
);
99 oldp
= l
->pixmap
; /* save to free after changing the visible pixmap */
100 l
->pixmap
= XCreatePixmap(ob_display
, ob_root
, x
+w
, y
+h
, render_depth
);
101 g_assert(l
->pixmap
!= None
);
103 if (l
->xftdraw
!= NULL
)
104 XftDrawDestroy(l
->xftdraw
);
105 l
->xftdraw
= XftDrawCreate(ob_display
, l
->pixmap
, render_visual
,
107 g_assert(l
->xftdraw
!= NULL
);
109 g_free(l
->surface
.data
.planar
.pixel_data
);
110 l
->surface
.data
.planar
.pixel_data
= g_new(pixel32
, w
* h
);
113 if (l
->surface
.data
.planar
.grad
== Background_ParentRelative
) {
114 memset(l
->surface
.data
.planar
.pixel_data
, 0, w
*h
*4);
116 else if (l
->surface
.data
.planar
.grad
== Background_Solid
)
117 gradient_solid(l
, x
, y
, w
, h
);
118 else gradient_render(&l
->surface
, w
, h
);
120 for (i
= 0; i
< l
->textures
; i
++) {
121 switch (l
->texture
[i
].type
) {
125 if (l
->surface
.data
.planar
.grad
!= Background_Solid
)
126 pixel32_to_pixmap(l
->surface
.data
.planar
.pixel_data
,
129 if (l
->xftdraw
== NULL
) {
130 l
->xftdraw
= XftDrawCreate(ob_display
, l
->pixmap
,
131 render_visual
, render_colormap
);
133 font_draw(l
->xftdraw
, &l
->texture
[i
].data
.text
,
134 &l
->texture
[i
].position
);
139 if (l
->surface
.data
.planar
.grad
!= Background_Solid
)
140 pixel32_to_pixmap(l
->surface
.data
.planar
.pixel_data
,
143 if (l
->texture
[i
].data
.mask
.color
->gc
== None
)
144 color_allocate_gc(l
->texture
[i
].data
.mask
.color
);
145 mask_draw(l
->pixmap
, &l
->texture
[i
].data
.mask
,
146 &l
->texture
[i
].position
);
149 image_draw(l
->surface
.data
.planar
.pixel_data
,
150 &l
->texture
[i
].data
.rgba
,
151 &l
->texture
[i
].position
);
158 if (l
->surface
.data
.planar
.grad
!= Background_Solid
)
159 pixel32_to_pixmap(l
->surface
.data
.planar
.pixel_data
, l
->pixmap
164 XSetWindowBackgroundPixmap(ob_display
, win
, l
->pixmap
);
165 XClearWindow(ob_display
, win
);
166 if (oldp
!= None
) XFreePixmap(ob_display
, oldp
);
170 void gl_paint(Window win, Appearance *l)
172 glXMakeCurrent(ob_display, win, gl_context);
176 void render_shutdown(void)
180 Appearance
*appearance_new(SurfaceType type
, int numtex
)
185 out
= g_new(Appearance
, 1);
186 out
->surface
.type
= type
;
187 out
->textures
= numtex
;
189 if (numtex
) out
->texture
= g_new0(Texture
, numtex
);
190 else out
->texture
= NULL
;
195 p
= &out
->surface
.data
.planar
;
198 p
->border_color
= NULL
;
199 p
->pixel_data
= NULL
;
205 Appearance
*appearance_copy(Appearance
*orig
)
207 PlanarSurface
*spo
, *spc
;
208 Appearance
*copy
= g_new(Appearance
, 1);
209 copy
->surface
.type
= orig
->surface
.type
;
210 switch (orig
->surface
.type
) {
212 spo
= &(orig
->surface
.data
.planar
);
213 spc
= &(copy
->surface
.data
.planar
);
214 spc
->grad
= spo
->grad
;
215 spc
->relief
= spo
->relief
;
216 spc
->bevel
= spo
->bevel
;
217 if (spo
->primary
!= NULL
)
218 spc
->primary
= color_new(spo
->primary
->r
,
221 else spc
->primary
= NULL
;
223 if (spo
->secondary
!= NULL
)
224 spc
->secondary
= color_new(spo
->secondary
->r
,
227 else spc
->secondary
= NULL
;
229 if (spo
->border_color
!= NULL
)
230 spc
->border_color
= color_new(spo
->border_color
->r
,
231 spo
->border_color
->g
,
232 spo
->border_color
->b
);
233 else spc
->border_color
= NULL
;
235 spc
->interlaced
= spo
->interlaced
;
236 spc
->border
= spo
->border
;
237 spc
->pixel_data
= NULL
;
240 copy
->textures
= orig
->textures
;
241 copy
->texture
= g_memdup(orig
->texture
, orig
->textures
* sizeof(Texture
));
243 copy
->xftdraw
= NULL
;
247 void appearance_free(Appearance
*a
)
250 if (a
->pixmap
!= None
) XFreePixmap(ob_display
, a
->pixmap
);
251 if (a
->xftdraw
!= NULL
) XftDrawDestroy(a
->xftdraw
);
254 if (a
->surface
.type
== Surface_Planar
) {
255 p
= &a
->surface
.data
.planar
;
256 if (p
->primary
!= NULL
) color_free(p
->primary
);
257 if (p
->secondary
!= NULL
) color_free(p
->secondary
);
258 if (p
->border_color
!= NULL
) color_free(p
->border_color
);
259 if (p
->pixel_data
!= NULL
) g_free(p
->pixel_data
);
265 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
= endian
;
272 im
->data
= (char *)in
;
273 reduce_depth((pixel32
*)im
->data
, im
);
274 XPutImage(ob_display
, out
, DefaultGC(ob_display
, ob_screen
),
275 im
, 0, 0, x
, y
, w
, h
);