diff --git a/src/common.h b/src/common.h index 2a9a4d6..682dd45 100644 --- a/src/common.h +++ b/src/common.h @@ -486,6 +486,8 @@ typedef struct { } #endif +#else +typedef uint32_t glx_prog_main_t; #endif typedef struct { @@ -553,10 +555,8 @@ typedef struct _options_t { bool glx_use_gpushader4; /// Custom fragment shader for painting windows, as a string. char *glx_fshader_win_str; -#ifdef CONFIG_OPENGL /// Custom GLX program used for painting window. glx_prog_main_t glx_prog_win; -#endif /// Whether to fork to background. bool fork_after_register; /// Whether to detect rounded corners. @@ -2121,97 +2121,6 @@ void xr_glx_sync(session_t *ps, Drawable d, XSyncFence *pfence); #endif -bool -glx_init(session_t *ps, bool need_render); - -void -glx_destroy(session_t *ps); - -bool -glx_reinit(session_t *ps, bool need_render); - -void -glx_on_root_change(session_t *ps); - -bool -glx_init_blur(session_t *ps); - -#ifdef CONFIG_OPENGL -bool -glx_load_prog_main(session_t *ps, - const char *vshader_str, const char *fshader_str, - glx_prog_main_t *pprogram); -#endif - -bool -glx_bind_pixmap(session_t *ps, glx_texture_t **pptex, Pixmap pixmap, - unsigned width, unsigned height, unsigned depth); - -void -glx_release_pixmap(session_t *ps, glx_texture_t *ptex); - -void -glx_paint_pre(session_t *ps, XserverRegion *preg); - -/** - * Check if a texture is binded, or is binded to the given pixmap. - */ -static inline bool -glx_tex_binded(const glx_texture_t *ptex, Pixmap pixmap) { - return ptex && ptex->glpixmap && ptex->texture - && (!pixmap || pixmap == ptex->pixmap); -} - -void -glx_set_clip(session_t *ps, XserverRegion reg, const reg_data_t *pcache_reg); - -#ifdef CONFIG_OPENGL -bool -glx_blur_dst(session_t *ps, int dx, int dy, int width, int height, float z, - GLfloat factor_center, - XserverRegion reg_tgt, const reg_data_t *pcache_reg, - glx_blur_cache_t *pbc); -#endif - -bool -glx_dim_dst(session_t *ps, int dx, int dy, int width, int height, float z, - GLfloat factor, XserverRegion reg_tgt, const reg_data_t *pcache_reg); - -bool -glx_render_(session_t *ps, const glx_texture_t *ptex, - int x, int y, int dx, int dy, int width, int height, int z, - double opacity, bool argb, bool neg, - XserverRegion reg_tgt, const reg_data_t *pcache_reg -#ifdef CONFIG_OPENGL - , const glx_prog_main_t *pprogram -#endif - ); - -#ifdef CONFIG_OPENGL -#define \ - glx_render(ps, ptex, x, y, dx, dy, width, height, z, opacity, argb, neg, reg_tgt, pcache_reg, pprogram) \ - glx_render_(ps, ptex, x, y, dx, dy, width, height, z, opacity, argb, neg, reg_tgt, pcache_reg, pprogram) -#else -#define \ - glx_render(ps, ptex, x, y, dx, dy, width, height, z, opacity, argb, neg, reg_tgt, pcache_reg, pprogram) \ - glx_render_(ps, ptex, x, y, dx, dy, width, height, z, opacity, argb, neg, reg_tgt, pcache_reg) -#endif - -unsigned char * -glx_take_screenshot(session_t *ps, int *out_length); - -#ifdef CONFIG_OPENGL -GLuint -glx_create_shader(GLenum shader_type, const char *shader_str); - -GLuint -glx_create_program(const GLuint * const shaders, int nshaders); - -GLuint -glx_create_program_from_str(const char *vert_shader_str, - const char *frag_shader_str); -#endif - /** * Free a GLX texture. */ @@ -2261,49 +2170,6 @@ free_glx_bc(session_t *ps, glx_blur_cache_t *pbc) { #endif #endif -/** - * Free a glx_texture_t. - */ -static inline void -free_texture(session_t *ps, glx_texture_t **pptex) { - glx_texture_t *ptex = *pptex; - - // Quit if there's nothing - if (!ptex) - return; - -#ifdef CONFIG_OPENGL - glx_release_pixmap(ps, ptex); - - free_texture_r(ps, &ptex->texture); - - // Free structure itself - free(ptex); - *pptex = NULL; -#endif - assert(!*pptex); -} - -/** - * Free GLX part of paint_t. - */ -static inline void -free_paint_glx(session_t *ps, paint_t *ppaint) { - free_texture(ps, &ppaint->ptex); -} - -/** - * Free GLX part of win. - */ -static inline void -free_win_res_glx(session_t *ps, win *w) { - free_paint_glx(ps, &w->paint); - free_paint_glx(ps, &w->shadow_paint); -#ifdef CONFIG_OPENGL - free_glx_bc(ps, &w->glx_blur_cache); -#endif -} - /** * Add a OpenGL debugging marker. */ diff --git a/src/compton.c b/src/compton.c index ca3deee..c43cf78 100644 --- a/src/compton.c +++ b/src/compton.c @@ -1401,14 +1401,12 @@ win_blur_background(session_t *ps, win *w, xcb_render_picture_t tgt_buffer, } void -render_(session_t *ps, int x, int y, int dx, int dy, int wid, int hei, - double opacity, bool argb, bool neg, - xcb_render_picture_t pict, glx_texture_t *ptex, - XserverRegion reg_paint, const reg_data_t *pcache_reg -#ifdef CONFIG_OPENGL - , const glx_prog_main_t *pprogram -#endif - ) { +render(session_t *ps, int x, int y, int dx, int dy, int wid, int hei, + double opacity, bool argb, bool neg, + xcb_render_picture_t pict, glx_texture_t *ptex, + XserverRegion reg_paint, const reg_data_t *pcache_reg, + const glx_prog_main_t *pprogram) +{ xcb_connection_t *c = XGetXCBConnection(ps->dpy); switch (ps->o.backend) { case BKEND_XRENDER: @@ -1926,7 +1924,7 @@ paint_all(session_t *ps, XserverRegion region, XserverRegion region_real, win *t glXWaitX(); assert(ps->tgt_buffer.pixmap); xr_sync(ps, ps->tgt_buffer.pixmap, &ps->tgt_buffer_fence); - paint_bind_tex_real(ps, &ps->tgt_buffer, + paint_bind_tex(ps, &ps->tgt_buffer, ps->root_width, ps->root_height, ps->depth, !ps->o.glx_no_rebind_pixmap); // See #163 diff --git a/src/compton.h b/src/compton.h index 3afd29a..434c20c 100644 --- a/src/compton.h +++ b/src/compton.h @@ -25,6 +25,9 @@ #include #endif +#ifdef CONFIG_OPENGL +#include "opengl.h" +#endif #include "common.h" #include "c2.h" @@ -50,13 +53,11 @@ void set_fade_callback(session_t *ps, win *w, void map_win(session_t *ps, Window id); void -render_(session_t *ps, int x, int y, int dx, int dy, int wid, int hei, +render(session_t *ps, int x, int y, int dx, int dy, int wid, int hei, double opacity, bool argb, bool neg, xcb_render_picture_t pict, glx_texture_t *ptex, XserverRegion reg_paint, const reg_data_t *pcache_reg -#ifdef CONFIG_OPENGL , const glx_prog_main_t *pprogram -#endif ); /** @@ -196,30 +197,38 @@ free_xinerama_info(session_t *ps) { #endif } +#ifdef CONFIG_OPENGL /** * Bind texture in paint_t if we are using GLX backend. */ static inline bool -paint_bind_tex_real(session_t *ps, paint_t *ppaint, - unsigned wid, unsigned hei, unsigned depth, bool force) { -#ifdef CONFIG_OPENGL +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); -#endif return true; } - +#else static inline bool paint_bind_tex(session_t *ps, paint_t *ppaint, - unsigned wid, unsigned hei, unsigned depth, bool force) { - if (BKEND_GLX == ps->o.backend) - return paint_bind_tex_real(ps, ppaint, wid, hei, depth, force); + unsigned wid, unsigned hei, unsigned depth, bool force) +{ return true; } +static inline void +free_paint_glx(session_t *ps, paint_t *p) {} +static inline void +free_win_res_glx(session_t *ps, win *w) {} +static inline void +free_texture(session_t *ps, glx_texture_t **t) { + assert(!*t); +} +#endif /** * Free data in a reg_data_t. @@ -487,16 +496,6 @@ find_win_all(session_t *ps, const Window wid) { return w; } -#ifdef CONFIG_OPENGL -#define \ - render(ps, x, y, dx, dy, wid, hei, opacity, argb, neg, pict, ptex, reg_paint, pcache_reg, pprogram) \ - render_(ps, x, y, dx, dy, wid, hei, opacity, argb, neg, pict, ptex, reg_paint, pcache_reg, pprogram) -#else -#define \ - render(ps, x, y, dx, dy, wid, hei, opacity, argb, neg, pict, ptex, reg_paint, pcache_reg, pprogram) \ - render_(ps, x, y, dx, dy, wid, hei, opacity, argb, neg, pict, ptex, reg_paint, pcache_reg) -#endif - bool win_has_alpha(win *); static inline void win_render(session_t *ps, win *w, int x, int y, int wid, int hei, diff --git a/src/opengl.c b/src/opengl.c index 4542290..67e7aea 100644 --- a/src/opengl.c +++ b/src/opengl.c @@ -729,6 +729,9 @@ glx_load_prog_main(session_t *ps, bool glx_bind_pixmap(session_t *ps, glx_texture_t **pptex, Pixmap pixmap, unsigned width, unsigned height, unsigned depth) { + if (ps->o.backend != BKEND_GLX) + return true; + if (!pixmap) { printf_errf("(%#010lx): Binding to an empty pixmap. This can't work.", pixmap); @@ -1413,7 +1416,7 @@ glx_dim_dst(session_t *ps, int dx, int dy, int width, int height, float z, * @brief Render a region with texture data. */ bool -glx_render_(session_t *ps, const glx_texture_t *ptex, +glx_render(session_t *ps, const glx_texture_t *ptex, int x, int y, int dx, int dy, int width, int height, int z, double opacity, bool argb, bool neg, XserverRegion reg_tgt, const reg_data_t *pcache_reg diff --git a/src/opengl.h b/src/opengl.h index 8ba95cc..99e7965 100644 --- a/src/opengl.h +++ b/src/opengl.h @@ -121,3 +121,119 @@ glx_hasglext(session_t *ps, const char *ext) { return found; } + +bool +glx_dim_dst(session_t *ps, int dx, int dy, int width, int height, float z, + GLfloat factor, XserverRegion reg_tgt, const reg_data_t *); + +bool +glx_render(session_t *ps, const glx_texture_t *ptex, + int x, int y, int dx, int dy, int width, int height, int z, + double opacity, bool argb, bool neg, + XserverRegion reg_tgt, const reg_data_t *, + const glx_prog_main_t *pprogram); + +bool +glx_init(session_t *ps, bool need_render); + +void +glx_destroy(session_t *ps); + +bool +glx_reinit(session_t *ps, bool need_render); + +void +glx_on_root_change(session_t *ps); + +bool +glx_init_blur(session_t *ps); + +#ifdef CONFIG_OPENGL +bool +glx_load_prog_main(session_t *ps, + const char *vshader_str, const char *fshader_str, + glx_prog_main_t *pprogram); +#endif + +bool +glx_bind_pixmap(session_t *ps, glx_texture_t **pptex, Pixmap pixmap, + unsigned width, unsigned height, unsigned depth); + +void +glx_release_pixmap(session_t *ps, glx_texture_t *ptex); + +void glx_paint_pre(session_t *ps, XserverRegion *preg) +__attribute__((nonnull(1, 2))); + +/** + * Check if a texture is binded, or is binded to the given pixmap. + */ +static inline bool +glx_tex_binded(const glx_texture_t *ptex, Pixmap pixmap) { + return ptex && ptex->glpixmap && ptex->texture + && (!pixmap || pixmap == ptex->pixmap); +} + +void +glx_set_clip(session_t *ps, XserverRegion reg, const reg_data_t *); + +bool +glx_blur_dst(session_t *ps, int dx, int dy, int width, int height, float z, + GLfloat factor_center, + XserverRegion reg_tgt, + const reg_data_t *, + glx_blur_cache_t *pbc); + +GLuint +glx_create_shader(GLenum shader_type, const char *shader_str); + +GLuint +glx_create_program(const GLuint * const shaders, int nshaders); + +GLuint +glx_create_program_from_str(const char *vert_shader_str, + const char *frag_shader_str); + +unsigned char * +glx_take_screenshot(session_t *ps, int *out_length); + +/** + * Free a glx_texture_t. + */ +static inline void +free_texture(session_t *ps, glx_texture_t **pptex) { + glx_texture_t *ptex = *pptex; + + // Quit if there's nothing + if (!ptex) + return; + + glx_release_pixmap(ps, ptex); + + free_texture_r(ps, &ptex->texture); + + // Free structure itself + free(ptex); + *pptex = NULL; + assert(!*pptex); +} + +/** + * Free GLX part of paint_t. + */ +static inline void +free_paint_glx(session_t *ps, paint_t *ppaint) { + free_texture(ps, &ppaint->ptex); +} + +/** + * Free GLX part of win. + */ +static inline void +free_win_res_glx(session_t *ps, win *w) { + free_paint_glx(ps, &w->paint); + free_paint_glx(ps, &w->shadow_paint); +#ifdef CONFIG_OPENGL + free_glx_bc(ps, &w->glx_blur_cache); +#endif +}