8 #include "../kernel/openbox.h"
11 Visual
*render_visual
;
12 Colormap render_colormap
;
14 void render_startup(void)
18 render_depth
= DefaultDepth(ob_display
, ob_screen
);
19 render_visual
= DefaultVisual(ob_display
, ob_screen
);
20 render_colormap
= DefaultColormap(ob_display
, ob_screen
);
22 if (render_depth
< 8) {
23 XVisualInfo vinfo_template
, *vinfo_return
;
24 // search for a TrueColor Visual... if we can't find one...
25 // we will use the default visual for the screen
29 vinfo_template
.screen
= ob_screen
;
30 vinfo_template
.class = TrueColor
;
31 vinfo_return
= XGetVisualInfo(ob_display
,
32 VisualScreenMask
| VisualClassMask
,
33 &vinfo_template
, &vinfo_nitems
);
37 for (i
= 0; i
< vinfo_nitems
; ++i
) {
38 if (vinfo_return
[i
].depth
> max_depth
) {
39 if (max_depth
== 24 && vinfo_return
[i
].depth
> 24)
40 break; // prefer 24 bit over 32
41 max_depth
= vinfo_return
[i
].depth
;
45 if (max_depth
< render_depth
) best
= -1;
48 render_depth
= vinfo_return
[best
].depth
;
49 render_visual
= vinfo_return
[best
].visual
;
50 render_colormap
= XCreateColormap(ob_display
, ob_root
, render_visual
,
57 void x_paint(Window win
, Appearance
*l
, int x
, int y
, int w
, int h
)
63 if (w
<= 0 || h
<= 0) return;
65 g_assert(l
->surface
.type
== Surface_Planar
);
66 // printf("painting window %ld\n", win);
68 oldp
= l
->pixmap
; /* save to free after changing the visible pixmap */
69 l
->pixmap
= XCreatePixmap(ob_display
, ob_root
, x
+w
, y
+h
, render_depth
);
70 g_assert(l
->pixmap
!= None
);
72 if (l
->xftdraw
!= NULL
)
73 XftDrawDestroy(l
->xftdraw
);
74 l
->xftdraw
= XftDrawCreate(ob_display
, l
->pixmap
, render_visual
,
76 g_assert(l
->xftdraw
!= NULL
);
78 if (l
->surface
.data
.planar
.pixel_data
!= NULL
)
79 g_free(l
->surface
.data
.planar
.pixel_data
);
80 l
->surface
.data
.planar
.pixel_data
= g_new(pixel32
, w
* h
);
82 if (l
->surface
.data
.planar
.grad
== Background_Solid
)
83 gradient_solid(l
, x
, y
, w
, h
);
84 else gradient_render(&l
->surface
, w
, h
);
86 /*reduce depth here...
87 also, this is not the right place for this code, it's only here so
88 text rendering shows up for now.
90 if (l
->surface
.data
.planar
.grad
!= Background_Solid
) {
91 im
= XCreateImage(ob_display
, render_visual
, render_depth
,
92 ZPixmap
, 0, NULL
, w
, h
, 32, 0);
94 im
->byte_order
= endian
;
95 im
->data
= l
->surface
.data
.planar
.pixel_data
;
96 XPutImage(ob_display
, l
->pixmap
, DefaultGC(ob_display
, ob_screen
),
97 im
, 0, 0, x
, y
, w
, h
);
102 for (i
= 0; i
< l
->textures
; i
++) {
103 switch (l
->texture
[i
].type
) {
105 if (l
->xftdraw
== NULL
) {
106 l
->xftdraw
= XftDrawCreate(ob_display
, l
->pixmap
,
107 render_visual
, render_colormap
);
109 font_draw(l
->xftdraw
, &l
->texture
[i
].data
.text
);
112 if (l
->texture
[i
].data
.mask
.color
->gc
== None
)
113 color_allocate_gc(l
->texture
[i
].data
.mask
.color
);
114 mask_draw(l
->pixmap
, &l
->texture
[i
].data
.mask
, w
, h
);
118 XSetWindowBackgroundPixmap(ob_display
, win
, l
->pixmap
);
119 XClearWindow(ob_display
, win
);
120 if (oldp
!= None
) XFreePixmap(ob_display
, oldp
);
124 void gl_paint(Window win, Appearance *l)
126 glXMakeCurrent(ob_display, win, gl_context);
130 void render_shutdown(void)
134 Appearance
*appearance_new(SurfaceType type
, int numtex
)
139 out
= g_new(Appearance
, 1);
140 out
->surface
.type
= type
;
141 out
->textures
= numtex
;
143 if (numtex
) out
->texture
= g_new(Texture
, numtex
);
148 p
= &out
->surface
.data
.planar
;
151 p
->border_color
= NULL
;
152 p
->pixel_data
= NULL
;
158 Appearance
*appearance_copy(Appearance
*orig
)
160 PlanarSurface
*spo
, *spc
;
161 Appearance
*copy
= g_new(Appearance
, 1);
162 copy
->surface
.type
= orig
->surface
.type
;
163 switch (orig
->surface
.type
) {
165 spo
= &(orig
->surface
.data
.planar
);
166 spc
= &(copy
->surface
.data
.planar
);
167 spc
->grad
= spo
->grad
;
168 spc
->relief
= spo
->relief
;
169 spc
->bevel
= spo
->bevel
;
170 if (spo
->primary
!= NULL
)
171 spc
->primary
= color_new(spo
->primary
->r
,
174 else spc
->primary
= NULL
;
176 if (spo
->secondary
!= NULL
)
177 spc
->secondary
= color_new(spo
->secondary
->r
,
180 else spc
->secondary
= NULL
;
182 if (spo
->border_color
!= NULL
)
183 spc
->border_color
= color_new(spo
->border_color
->r
,
184 spo
->border_color
->g
,
185 spo
->border_color
->b
);
186 else spc
->border_color
= NULL
;
188 spc
->interlaced
= spo
->interlaced
;
189 spc
->border
= spo
->border
;
190 spc
->pixel_data
= NULL
;
193 copy
->textures
= orig
->textures
;
194 if (orig
->textures
) {
195 copy
->texture
= malloc(orig
->textures
* sizeof(Texture
));
196 memcpy(copy
->texture
, orig
->texture
, orig
->textures
* sizeof(Texture
));
197 } else copy
->texture
= NULL
;
199 copy
->xftdraw
= NULL
;
203 void appearance_free(Appearance
*a
)
206 if (a
->pixmap
!= None
) XFreePixmap(ob_display
, a
->pixmap
);
207 if (a
->xftdraw
!= NULL
) XftDrawDestroy(a
->xftdraw
);
210 if (a
->surface
.type
== Surface_Planar
) {
211 p
= &a
->surface
.data
.planar
;
212 if (p
->primary
!= NULL
) color_free(p
->primary
);
213 if (p
->secondary
!= NULL
) color_free(p
->secondary
);
214 if (p
->border_color
!= NULL
) color_free(p
->border_color
);