9 #include "../kernel/openbox.h"
12 Visual
*render_visual
;
13 Colormap render_colormap
;
14 int render_red_offset
= 0, render_green_offset
= 0, render_blue_offset
= 0;
15 int render_red_shift
, render_green_shift
, render_blue_shift
;
17 void render_startup(void)
21 render_depth
= DefaultDepth(ob_display
, ob_screen
);
22 render_visual
= DefaultVisual(ob_display
, ob_screen
);
23 render_colormap
= DefaultColormap(ob_display
, ob_screen
);
25 if (render_depth
< 8) {
26 XVisualInfo vinfo_template
, *vinfo_return
;
27 /* search for a TrueColor Visual... if we can't find one...
28 we will use the default visual for the screen */
32 vinfo_template
.screen
= ob_screen
;
33 vinfo_template
.class = TrueColor
;
34 vinfo_return
= XGetVisualInfo(ob_display
,
35 VisualScreenMask
| VisualClassMask
,
36 &vinfo_template
, &vinfo_nitems
);
40 for (i
= 0; i
< vinfo_nitems
; ++i
) {
41 if (vinfo_return
[i
].depth
> max_depth
) {
42 if (max_depth
== 24 && vinfo_return
[i
].depth
> 24)
43 break; /* prefer 24 bit over 32 */
44 max_depth
= vinfo_return
[i
].depth
;
48 if (max_depth
< render_depth
) best
= -1;
51 render_depth
= vinfo_return
[best
].depth
;
52 render_visual
= vinfo_return
[best
].visual
;
53 render_colormap
= XCreateColormap(ob_display
, ob_root
, render_visual
,
61 void truecolor_startup(void)
63 unsigned long red_mask
, green_mask
, blue_mask
;
64 XImage
*timage
= NULL
;
66 timage
= XCreateImage(ob_display
, render_visual
, render_depth
,
67 ZPixmap
, 0, NULL
, 1, 1, 32, 0);
68 g_assert(timage
!= NULL
);
69 /* find the offsets for each color in the visual's masks */
70 red_mask
= timage
->red_mask
;
71 green_mask
= timage
->green_mask
;
72 blue_mask
= timage
->blue_mask
;
74 render_red_offset
= 0;
75 render_green_offset
= 0;
76 render_blue_offset
= 0;
78 while (! (red_mask
& 1)) { render_red_offset
++; red_mask
>>= 1; }
79 while (! (green_mask
& 1)) { render_green_offset
++; green_mask
>>= 1; }
80 while (! (blue_mask
& 1)) { render_blue_offset
++; blue_mask
>>= 1; }
82 render_red_shift
= render_green_shift
= render_blue_shift
= 8;
83 while (red_mask
) { red_mask
>>= 1; render_red_shift
--; }
84 while (green_mask
) { green_mask
>>= 1; render_green_shift
--; }
85 while (blue_mask
) { blue_mask
>>= 1; render_blue_shift
--; }
89 void x_paint(Window win
, Appearance
*l
, int x
, int y
, int w
, int h
)
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
);
112 if (l
->surface
.data
.planar
.grad
== Background_Solid
)
113 gradient_solid(l
, x
, y
, w
, h
);
114 else gradient_render(&l
->surface
, w
, h
);
116 /*this is not the right place for this code, it's only here so
117 text rendering shows up for now.
119 if (l
->surface
.data
.planar
.grad
!= Background_Solid
) {
120 im
= XCreateImage(ob_display
, render_visual
, render_depth
,
121 ZPixmap
, 0, NULL
, w
, h
, 32, 0);
122 g_assert(im
!= NULL
);
123 im
->byte_order
= endian
;
124 im
->data
= (char *)l
->surface
.data
.planar
.pixel_data
;
125 reduce_depth((pixel32
*)im
->data
, im
);
126 XPutImage(ob_display
, l
->pixmap
, DefaultGC(ob_display
, ob_screen
),
127 im
, 0, 0, x
, y
, w
, h
);
132 for (i
= 0; i
< l
->textures
; i
++) {
133 switch (l
->texture
[i
].type
) {
135 if (l
->xftdraw
== NULL
) {
136 l
->xftdraw
= XftDrawCreate(ob_display
, l
->pixmap
,
137 render_visual
, render_colormap
);
139 font_draw(l
->xftdraw
, &l
->texture
[i
].data
.text
, x
, y
, w
, h
);
142 if (l
->texture
[i
].data
.mask
.color
->gc
== None
)
143 color_allocate_gc(l
->texture
[i
].data
.mask
.color
);
144 mask_draw(l
->pixmap
, &l
->texture
[i
].data
.mask
, w
, h
);
148 XSetWindowBackgroundPixmap(ob_display
, win
, l
->pixmap
);
149 XClearWindow(ob_display
, win
);
150 if (oldp
!= None
) XFreePixmap(ob_display
, oldp
);
154 void gl_paint(Window win, Appearance *l)
156 glXMakeCurrent(ob_display, win, gl_context);
160 void render_shutdown(void)
164 Appearance
*appearance_new(SurfaceType type
, int numtex
)
169 out
= g_new(Appearance
, 1);
170 out
->surface
.type
= type
;
171 out
->textures
= numtex
;
173 if (numtex
) out
->texture
= g_new(Texture
, numtex
);
174 else out
->texture
= NULL
;
179 p
= &out
->surface
.data
.planar
;
182 p
->border_color
= NULL
;
183 p
->pixel_data
= NULL
;
189 Appearance
*appearance_copy(Appearance
*orig
)
191 PlanarSurface
*spo
, *spc
;
192 Appearance
*copy
= g_new(Appearance
, 1);
193 copy
->surface
.type
= orig
->surface
.type
;
194 switch (orig
->surface
.type
) {
196 spo
= &(orig
->surface
.data
.planar
);
197 spc
= &(copy
->surface
.data
.planar
);
198 spc
->grad
= spo
->grad
;
199 spc
->relief
= spo
->relief
;
200 spc
->bevel
= spo
->bevel
;
201 if (spo
->primary
!= NULL
)
202 spc
->primary
= color_new(spo
->primary
->r
,
205 else spc
->primary
= NULL
;
207 if (spo
->secondary
!= NULL
)
208 spc
->secondary
= color_new(spo
->secondary
->r
,
211 else spc
->secondary
= NULL
;
213 if (spo
->border_color
!= NULL
)
214 spc
->border_color
= color_new(spo
->border_color
->r
,
215 spo
->border_color
->g
,
216 spo
->border_color
->b
);
217 else spc
->border_color
= NULL
;
219 spc
->interlaced
= spo
->interlaced
;
220 spc
->border
= spo
->border
;
221 spc
->pixel_data
= NULL
;
224 copy
->textures
= orig
->textures
;
225 copy
->texture
= g_memdup(orig
->texture
, orig
->textures
* sizeof(Texture
));
227 copy
->xftdraw
= NULL
;
231 void appearance_free(Appearance
*a
)
234 if (a
->pixmap
!= None
) XFreePixmap(ob_display
, a
->pixmap
);
235 if (a
->xftdraw
!= NULL
) XftDrawDestroy(a
->xftdraw
);
238 if (a
->surface
.type
== Surface_Planar
) {
239 p
= &a
->surface
.data
.planar
;
240 if (p
->primary
!= NULL
) color_free(p
->primary
);
241 if (p
->secondary
!= NULL
) color_free(p
->secondary
);
242 if (p
->border_color
!= NULL
) color_free(p
->border_color
);
243 if (p
->pixel_data
!= NULL
) g_free(p
->pixel_data
);