Move rendering related functions out of compton.c

Moved:
* Blur kernel related functions to kernel.c
* Vsync related functions to vsync.c
* paint related functions to render.c

This will make the `split-backend` branch easier to rebase.

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui
2018-12-15 21:11:41 +00:00
parent 85c5d34ce1
commit baeb4572ff
16 changed files with 1726 additions and 1647 deletions

View File

@ -34,6 +34,7 @@
#include "x.h"
#include "c2.h"
#include "log.h" // XXX clean up
#include "render.h"
// == Functions ==
// TODO move static inline functions that are only used in compton.c, into
@ -53,16 +54,6 @@ win *find_toplevel2(session_t *ps, Window wid);
void map_win(session_t *ps, Window id);
/**
* Reset filter on a <code>Picture</code>.
*/
static inline void
xrfilter_reset(session_t *ps, xcb_render_picture_t p) {
#define FILTER "Nearest"
xcb_render_set_picture_filter(ps->c, p, strlen(FILTER), FILTER, 0, NULL);
#undef FILTER
}
/**
* Subtract two unsigned long values.
*
@ -103,17 +94,6 @@ array_wid_exists(const Window *arr, int count, Window wid) {
return false;
}
/**
* Destroy a <code>Picture</code>.
*/
inline static void
free_picture(session_t *ps, xcb_render_picture_t *p) {
if (*p) {
xcb_render_free_picture(ps->c, *p);
*p = None;
}
}
/**
* Destroy a condition list.
*/
@ -123,29 +103,7 @@ free_wincondlst(c2_lptr_t **pcondlst) {
continue;
}
#ifdef CONFIG_OPENGL
/**
* Bind texture in paint_t if we are using GLX backend.
*/
static inline bool
paint_bind_tex(session_t *ps, paint_t *ppaint,
unsigned wid, unsigned hei, unsigned depth, bool force)
{
if (!ppaint->pixmap)
return false;
if (force || !glx_tex_binded(ppaint->ptex, ppaint->pixmap))
return glx_bind_pixmap(ps, &ppaint->ptex, ppaint->pixmap, wid, hei, depth);
return true;
}
#else
static inline bool
paint_bind_tex(session_t *ps, paint_t *ppaint,
unsigned wid, unsigned hei, unsigned depth, bool force)
{
return true;
}
#ifndef CONFIG_OPENGL
static inline void
free_paint_glx(session_t *ps, paint_t *p) {}
static inline void
@ -156,18 +114,6 @@ free_texture(session_t *ps, glx_texture_t **t) {
}
#endif
/**
* Free paint_t.
*/
static inline void
free_paint(session_t *ps, paint_t *ppaint) {
free_paint_glx(ps, ppaint);
free_picture(ps, &ppaint->pict);
if (ppaint->pixmap)
xcb_free_pixmap(ps->c, ppaint->pixmap);
ppaint->pixmap = XCB_NONE;
}
/**
* Create a XTextProperty of a single string.
*/
@ -220,59 +166,14 @@ dump_drawable(session_t *ps, Drawable drawable) {
}
}
/**
* Validate a pixmap.
*
* Detect whether the pixmap is valid with XGetGeometry. Well, maybe there
* are better ways.
*/
static inline bool
validate_pixmap(session_t *ps, xcb_pixmap_t pxmap) {
if (!pxmap) return false;
Window rroot = None;
int rx = 0, ry = 0;
unsigned rwid = 0, rhei = 0, rborder = 0, rdepth = 0;
return XGetGeometry(ps->dpy, pxmap, &rroot, &rx, &ry,
&rwid, &rhei, &rborder, &rdepth) && rwid && rhei;
}
/**
* Validate pixmap of a window, and destroy pixmap and picture if invalid.
*/
static inline void
win_validate_pixmap(session_t *ps, win *w) {
// Destroy pixmap and picture, if invalid
if (!validate_pixmap(ps, w->paint.pixmap))
if (!x_validate_pixmap(ps, w->paint.pixmap))
free_paint(ps, &w->paint);
}
/**
* Normalize a convolution kernel.
*/
static inline void
normalize_conv_kern(int wid, int hei, xcb_render_fixed_t *kern) {
double sum = 0.0;
for (int i = 0; i < wid * hei; ++i)
sum += XFIXED_TO_DOUBLE(kern[i]);
double factor = 1.0 / sum;
for (int i = 0; i < wid * hei; ++i)
kern[i] = DOUBLE_TO_XFIXED(XFIXED_TO_DOUBLE(kern[i]) * factor);
}
#ifdef CONFIG_OPENGL
/**
* Ensure we have a GLX context.
*/
static inline bool
ensure_glx_context(session_t *ps) {
// Create GLX context
if (!glx_has_context(ps))
glx_init(ps, false);
return ps->psglx->context;
}
#endif
// vim: set et sw=2 :