2018-10-04 05:14:51 +08:00
|
|
|
// SPDX-License-Identifier: MIT
|
2013-03-15 23:16:23 +08:00
|
|
|
/*
|
|
|
|
* Compton - a compositor for X11
|
|
|
|
*
|
|
|
|
* Based on `xcompmgr` - Copyright (c) 2003, Keith Packard
|
|
|
|
*
|
|
|
|
* Copyright (c) 2011-2013, Christopher Jeffrey
|
2018-10-04 05:24:12 +08:00
|
|
|
* See LICENSE-mit for more information.
|
2013-03-15 23:16:23 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2018-10-04 05:14:51 +08:00
|
|
|
#pragma once
|
|
|
|
|
2013-03-15 23:16:23 +08:00
|
|
|
#include "common.h"
|
|
|
|
|
|
|
|
#include <ctype.h>
|
2013-09-15 08:56:53 +08:00
|
|
|
#include <locale.h>
|
2013-03-15 23:16:23 +08:00
|
|
|
|
2013-04-25 09:27:14 +08:00
|
|
|
#ifdef DEBUG_GLX_ERR
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a textual representation of an OpenGL error.
|
|
|
|
*/
|
|
|
|
static inline const char *
|
|
|
|
glx_dump_err_str(GLenum err) {
|
|
|
|
switch (err) {
|
|
|
|
CASESTRRET(GL_NO_ERROR);
|
|
|
|
CASESTRRET(GL_INVALID_ENUM);
|
|
|
|
CASESTRRET(GL_INVALID_VALUE);
|
|
|
|
CASESTRRET(GL_INVALID_OPERATION);
|
|
|
|
CASESTRRET(GL_INVALID_FRAMEBUFFER_OPERATION);
|
|
|
|
CASESTRRET(GL_OUT_OF_MEMORY);
|
|
|
|
CASESTRRET(GL_STACK_UNDERFLOW);
|
|
|
|
CASESTRRET(GL_STACK_OVERFLOW);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check for GLX error.
|
|
|
|
*
|
|
|
|
* http://blog.nobel-joergensen.com/2013/01/29/debugging-opengl-using-glgeterror/
|
|
|
|
*/
|
|
|
|
static inline void
|
|
|
|
glx_check_err_(session_t *ps, const char *func, int line) {
|
2014-07-28 12:50:15 +08:00
|
|
|
if (!ps->psglx->context) return;
|
2013-04-25 09:27:14 +08:00
|
|
|
|
|
|
|
GLenum err = GL_NO_ERROR;
|
2014-07-04 18:27:13 +08:00
|
|
|
|
2013-04-25 09:27:14 +08:00
|
|
|
while (GL_NO_ERROR != (err = glGetError())) {
|
|
|
|
print_timestamp(ps);
|
|
|
|
printf("%s():%d: GLX error ", func, line);
|
|
|
|
const char *errtext = glx_dump_err_str(err);
|
|
|
|
if (errtext) {
|
|
|
|
printf_dbg("%s\n", errtext);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
printf_dbg("%d\n", err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define glx_check_err(ps) glx_check_err_(ps, __func__, __LINE__)
|
2014-03-17 23:25:34 +08:00
|
|
|
#else
|
|
|
|
#define glx_check_err(ps) ((void) 0)
|
2013-04-25 09:27:14 +08:00
|
|
|
#endif
|
|
|
|
|
2013-03-16 22:54:43 +08:00
|
|
|
/**
|
|
|
|
* Check if a word is in string.
|
|
|
|
*/
|
|
|
|
static inline bool
|
|
|
|
wd_is_in_str(const char *haystick, const char *needle) {
|
|
|
|
if (!haystick)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
assert(*needle);
|
|
|
|
|
|
|
|
const char *pos = haystick - 1;
|
|
|
|
while ((pos = strstr(pos + 1, needle))) {
|
|
|
|
// Continue if it isn't a word boundary
|
|
|
|
if (((pos - haystick) && !isspace(*(pos - 1)))
|
|
|
|
|| (strlen(pos) > strlen(needle) && !isspace(pos[strlen(needle)])))
|
|
|
|
continue;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-03-15 23:16:23 +08:00
|
|
|
/**
|
|
|
|
* Check if a GLX extension exists.
|
|
|
|
*/
|
|
|
|
static inline bool
|
2013-03-16 22:54:43 +08:00
|
|
|
glx_hasglxext(session_t *ps, const char *ext) {
|
2013-03-15 23:16:23 +08:00
|
|
|
const char *glx_exts = glXQueryExtensionsString(ps->dpy, ps->scr);
|
2013-03-16 22:54:43 +08:00
|
|
|
if (!glx_exts) {
|
|
|
|
printf_errf("(): Failed get GLX extension list.");
|
2013-03-15 23:16:23 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-03-16 22:54:43 +08:00
|
|
|
bool found = wd_is_in_str(glx_exts, ext);
|
|
|
|
if (!found)
|
|
|
|
printf_errf("(): Missing GLX extension %s.", ext);
|
|
|
|
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a GLX extension exists.
|
|
|
|
*/
|
|
|
|
static inline bool
|
|
|
|
glx_hasglext(session_t *ps, const char *ext) {
|
|
|
|
const char *gl_exts = (const char *) glGetString(GL_EXTENSIONS);
|
|
|
|
if (!gl_exts) {
|
|
|
|
printf_errf("(): Failed get GL extension list.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool found = wd_is_in_str(gl_exts, ext);
|
|
|
|
if (!found)
|
|
|
|
printf_errf("(): Missing GL extension %s.", ext);
|
|
|
|
|
|
|
|
return found;
|
2013-03-15 23:16:23 +08:00
|
|
|
}
|
2018-09-30 05:47:12 +08:00
|
|
|
|
|
|
|
bool
|
|
|
|
glx_dim_dst(session_t *ps, int dx, int dy, int width, int height, float z,
|
Convert XfixesRegion to pixman region
Re-did the painting logic, and document it.
It is unclear to me what is the previous painting logic. But the current
one is basically this:
1. Go through all windows top to bottom, and put visible windows (not
unmapped, opacity > 0, etc) into a linked list, from bottom to top
2. Accumulate a region of ignore on each window, which is basically the
region of screen that is obscured by all the windows above current
one.
3. Paint all the visible windows from bottom to top. Subtract the region
of ignore from the painting region. If we need to paint shadow, we
subtract the body of the window from the shadow painting region too,
because we don't want shadow behind the window.
4. region of ignore is invalidated when window stack change, an
window on top moved or changed shape, when window changed between
opaque and transparent, etc.
Notes:
It is unclear whether all the different shapes of a window (extents,
noframe, border, bounding shape, etc) are calculated correctly or not.
It is unclear if window shape related events are handled correctly or
not. Need more testing.
Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
2018-09-30 11:56:00 +08:00
|
|
|
GLfloat factor, const region_t *reg_tgt);
|
2018-09-30 05:47:12 +08:00
|
|
|
|
|
|
|
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,
|
Convert XfixesRegion to pixman region
Re-did the painting logic, and document it.
It is unclear to me what is the previous painting logic. But the current
one is basically this:
1. Go through all windows top to bottom, and put visible windows (not
unmapped, opacity > 0, etc) into a linked list, from bottom to top
2. Accumulate a region of ignore on each window, which is basically the
region of screen that is obscured by all the windows above current
one.
3. Paint all the visible windows from bottom to top. Subtract the region
of ignore from the painting region. If we need to paint shadow, we
subtract the body of the window from the shadow painting region too,
because we don't want shadow behind the window.
4. region of ignore is invalidated when window stack change, an
window on top moved or changed shape, when window changed between
opaque and transparent, etc.
Notes:
It is unclear whether all the different shapes of a window (extents,
noframe, border, bounding shape, etc) are calculated correctly or not.
It is unclear if window shape related events are handled correctly or
not. Need more testing.
Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
2018-09-30 11:56:00 +08:00
|
|
|
const region_t *reg_tgt,
|
2018-09-30 05:47:12 +08:00
|
|
|
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
|
2018-10-01 03:53:52 +08:00
|
|
|
glx_bind_pixmap(session_t *ps, glx_texture_t **pptex, xcb_pixmap_t pixmap,
|
2018-09-30 05:47:12 +08:00
|
|
|
unsigned width, unsigned height, unsigned depth);
|
|
|
|
|
|
|
|
void
|
|
|
|
glx_release_pixmap(session_t *ps, glx_texture_t *ptex);
|
|
|
|
|
Convert XfixesRegion to pixman region
Re-did the painting logic, and document it.
It is unclear to me what is the previous painting logic. But the current
one is basically this:
1. Go through all windows top to bottom, and put visible windows (not
unmapped, opacity > 0, etc) into a linked list, from bottom to top
2. Accumulate a region of ignore on each window, which is basically the
region of screen that is obscured by all the windows above current
one.
3. Paint all the visible windows from bottom to top. Subtract the region
of ignore from the painting region. If we need to paint shadow, we
subtract the body of the window from the shadow painting region too,
because we don't want shadow behind the window.
4. region of ignore is invalidated when window stack change, an
window on top moved or changed shape, when window changed between
opaque and transparent, etc.
Notes:
It is unclear whether all the different shapes of a window (extents,
noframe, border, bounding shape, etc) are calculated correctly or not.
It is unclear if window shape related events are handled correctly or
not. Need more testing.
Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
2018-09-30 11:56:00 +08:00
|
|
|
void glx_paint_pre(session_t *ps, region_t *preg)
|
2018-09-30 05:47:12 +08:00
|
|
|
__attribute__((nonnull(1, 2)));
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a texture is binded, or is binded to the given pixmap.
|
|
|
|
*/
|
|
|
|
static inline bool
|
2018-10-01 03:53:52 +08:00
|
|
|
glx_tex_binded(const glx_texture_t *ptex, xcb_pixmap_t pixmap) {
|
2018-09-30 05:47:12 +08:00
|
|
|
return ptex && ptex->glpixmap && ptex->texture
|
|
|
|
&& (!pixmap || pixmap == ptex->pixmap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
Convert XfixesRegion to pixman region
Re-did the painting logic, and document it.
It is unclear to me what is the previous painting logic. But the current
one is basically this:
1. Go through all windows top to bottom, and put visible windows (not
unmapped, opacity > 0, etc) into a linked list, from bottom to top
2. Accumulate a region of ignore on each window, which is basically the
region of screen that is obscured by all the windows above current
one.
3. Paint all the visible windows from bottom to top. Subtract the region
of ignore from the painting region. If we need to paint shadow, we
subtract the body of the window from the shadow painting region too,
because we don't want shadow behind the window.
4. region of ignore is invalidated when window stack change, an
window on top moved or changed shape, when window changed between
opaque and transparent, etc.
Notes:
It is unclear whether all the different shapes of a window (extents,
noframe, border, bounding shape, etc) are calculated correctly or not.
It is unclear if window shape related events are handled correctly or
not. Need more testing.
Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
2018-09-30 11:56:00 +08:00
|
|
|
glx_set_clip(session_t *ps, const region_t *reg);
|
2018-09-30 05:47:12 +08:00
|
|
|
|
|
|
|
bool
|
|
|
|
glx_blur_dst(session_t *ps, int dx, int dy, int width, int height, float z,
|
|
|
|
GLfloat factor_center,
|
Convert XfixesRegion to pixman region
Re-did the painting logic, and document it.
It is unclear to me what is the previous painting logic. But the current
one is basically this:
1. Go through all windows top to bottom, and put visible windows (not
unmapped, opacity > 0, etc) into a linked list, from bottom to top
2. Accumulate a region of ignore on each window, which is basically the
region of screen that is obscured by all the windows above current
one.
3. Paint all the visible windows from bottom to top. Subtract the region
of ignore from the painting region. If we need to paint shadow, we
subtract the body of the window from the shadow painting region too,
because we don't want shadow behind the window.
4. region of ignore is invalidated when window stack change, an
window on top moved or changed shape, when window changed between
opaque and transparent, etc.
Notes:
It is unclear whether all the different shapes of a window (extents,
noframe, border, bounding shape, etc) are calculated correctly or not.
It is unclear if window shape related events are handled correctly or
not. Need more testing.
Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
2018-09-30 11:56:00 +08:00
|
|
|
const region_t *reg_tgt,
|
2018-09-30 05:47:12 +08:00
|
|
|
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
|
|
|
|
}
|