2018-10-03 17:14:51 -04:00
|
|
|
// SPDX-License-Identifier: MIT
|
2013-03-15 11:16:23 -04:00
|
|
|
/*
|
|
|
|
* Compton - a compositor for X11
|
|
|
|
*
|
|
|
|
* Based on `xcompmgr` - Copyright (c) 2003, Keith Packard
|
|
|
|
*
|
|
|
|
* Copyright (c) 2011-2013, Christopher Jeffrey
|
2018-10-03 17:24:12 -04:00
|
|
|
* See LICENSE-mit for more information.
|
2013-03-15 11:16:23 -04:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2018-10-03 17:14:51 -04:00
|
|
|
#pragma once
|
|
|
|
|
2013-03-15 11:16:23 -04:00
|
|
|
#include "common.h"
|
2019-01-18 18:30:44 -05:00
|
|
|
#include "region.h"
|
|
|
|
#include "render.h"
|
|
|
|
#include "compiler.h"
|
|
|
|
#include "win.h"
|
2018-12-15 12:53:17 -05:00
|
|
|
#include "log.h"
|
2013-03-15 11:16:23 -04:00
|
|
|
|
2019-01-20 16:15:20 -05:00
|
|
|
#include <xcb/xcb.h>
|
2019-02-03 11:41:04 -05:00
|
|
|
#include <xcb/render.h>
|
2019-01-20 16:15:20 -05:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2013-03-15 11:16:23 -04:00
|
|
|
#include <ctype.h>
|
2013-09-14 20:56:53 -04:00
|
|
|
#include <locale.h>
|
2019-01-20 16:15:20 -05:00
|
|
|
#include <GL/glx.h>
|
2013-03-15 11:16:23 -04:00
|
|
|
|
2018-09-29 17:47:12 -04: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-29 23:56:00 -04:00
|
|
|
GLfloat factor, const region_t *reg_tgt);
|
2018-09-29 17:47:12 -04: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-29 23:56:00 -04:00
|
|
|
const region_t *reg_tgt,
|
2018-09-29 17:47:12 -04: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-09-30 15:53:52 -04:00
|
|
|
glx_bind_pixmap(session_t *ps, glx_texture_t **pptex, xcb_pixmap_t pixmap,
|
2019-02-08 16:48:39 -05:00
|
|
|
unsigned width, unsigned height, bool repeat, const struct glx_fbconfig_info *);
|
2018-09-29 17:47:12 -04:00
|
|
|
|
|
|
|
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-29 23:56:00 -04:00
|
|
|
void glx_paint_pre(session_t *ps, region_t *preg)
|
2018-12-19 15:50:02 -05:00
|
|
|
attr_nonnull(1, 2);
|
2018-09-29 17:47:12 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a texture is binded, or is binded to the given pixmap.
|
|
|
|
*/
|
|
|
|
static inline bool
|
2018-09-30 15:53:52 -04:00
|
|
|
glx_tex_binded(const glx_texture_t *ptex, xcb_pixmap_t pixmap) {
|
2018-09-29 17:47:12 -04: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-29 23:56:00 -04:00
|
|
|
glx_set_clip(session_t *ps, const region_t *reg);
|
2018-09-29 17:47:12 -04: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-29 23:56:00 -04:00
|
|
|
const region_t *reg_tgt,
|
2018-09-29 17:47:12 -04: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);
|
|
|
|
|
2018-12-15 16:11:41 -05:00
|
|
|
/**
|
|
|
|
* Check if there's a GLX context.
|
|
|
|
*/
|
|
|
|
static inline bool
|
|
|
|
glx_has_context(session_t *ps) {
|
|
|
|
return ps->psglx && ps->psglx->context;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Free a GLX texture.
|
|
|
|
*/
|
|
|
|
static inline void
|
|
|
|
free_texture_r(session_t *ps, GLuint *ptexture) {
|
|
|
|
if (*ptexture) {
|
|
|
|
assert(glx_has_context(ps));
|
|
|
|
glDeleteTextures(1, ptexture);
|
|
|
|
*ptexture = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Free a GLX Framebuffer object.
|
|
|
|
*/
|
|
|
|
static inline void
|
|
|
|
free_glx_fbo(session_t *ps, GLuint *pfbo) {
|
|
|
|
if (*pfbo) {
|
|
|
|
glDeleteFramebuffers(1, pfbo);
|
|
|
|
*pfbo = 0;
|
|
|
|
}
|
|
|
|
assert(!*pfbo);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Free data in glx_blur_cache_t on resize.
|
|
|
|
*/
|
|
|
|
static inline void
|
|
|
|
free_glx_bc_resize(session_t *ps, glx_blur_cache_t *pbc) {
|
|
|
|
free_texture_r(ps, &pbc->textures[0]);
|
|
|
|
free_texture_r(ps, &pbc->textures[1]);
|
|
|
|
pbc->width = 0;
|
|
|
|
pbc->height = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Free a glx_blur_cache_t
|
|
|
|
*/
|
|
|
|
static inline void
|
|
|
|
free_glx_bc(session_t *ps, glx_blur_cache_t *pbc) {
|
|
|
|
free_glx_fbo(ps, &pbc->fbo);
|
|
|
|
free_glx_bc_resize(ps, pbc);
|
|
|
|
}
|
|
|
|
|
2018-09-29 17:47:12 -04:00
|
|
|
/**
|
|
|
|
* 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);
|
2019-02-03 11:41:04 -05:00
|
|
|
free(w->paint.fbcfg);
|
2018-09-29 17:47:12 -04:00
|
|
|
#endif
|
|
|
|
}
|