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"
|
2019-03-10 20:34:37 +08:00
|
|
|
#include "compiler.h"
|
|
|
|
#include "log.h"
|
2019-01-19 07:30:44 +08:00
|
|
|
#include "region.h"
|
|
|
|
#include "render.h"
|
|
|
|
#include "win.h"
|
2013-03-15 23:16:23 +08:00
|
|
|
|
2019-03-10 20:34:37 +08:00
|
|
|
#include <GL/gl.h>
|
2013-03-15 23:16:23 +08:00
|
|
|
#include <ctype.h>
|
2013-09-15 08:56:53 +08:00
|
|
|
#include <locale.h>
|
2019-03-10 20:34:37 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <xcb/render.h>
|
|
|
|
#include <xcb/xcb.h>
|
2013-03-15 23:16:23 +08:00
|
|
|
|
2019-03-30 17:07:21 +08:00
|
|
|
bool glx_dim_dst(session_t *ps, int dx, int dy, int width, int height, int z,
|
2019-03-10 20:34:37 +08:00
|
|
|
GLfloat factor, const region_t *reg_tgt);
|
2018-09-30 05:47:12 +08:00
|
|
|
|
2019-03-10 20:34:37 +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,
|
|
|
|
const region_t *reg_tgt, const glx_prog_main_t *pprogram);
|
2018-09-30 05:47:12 +08:00
|
|
|
|
2019-03-10 20:34:37 +08:00
|
|
|
bool glx_init(session_t *ps, bool need_render);
|
2018-09-30 05:47:12 +08:00
|
|
|
|
2019-03-10 20:34:37 +08:00
|
|
|
void glx_destroy(session_t *ps);
|
2018-09-30 05:47:12 +08:00
|
|
|
|
2019-03-10 20:34:37 +08:00
|
|
|
void glx_on_root_change(session_t *ps);
|
2018-09-30 05:47:12 +08:00
|
|
|
|
2019-03-10 20:34:37 +08:00
|
|
|
bool glx_init_blur(session_t *ps);
|
2018-09-30 05:47:12 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_OPENGL
|
2019-03-10 20:34:37 +08:00
|
|
|
bool glx_load_prog_main(session_t *ps, const char *vshader_str, const char *fshader_str,
|
|
|
|
glx_prog_main_t *pprogram);
|
2018-09-30 05:47:12 +08:00
|
|
|
#endif
|
|
|
|
|
2019-03-30 17:07:21 +08:00
|
|
|
bool glx_bind_pixmap(session_t *ps, glx_texture_t **pptex, xcb_pixmap_t pixmap, int width,
|
|
|
|
int height, bool repeat, const struct glx_fbconfig_info *);
|
2018-09-30 05:47:12 +08:00
|
|
|
|
2019-03-10 20:34:37 +08:00
|
|
|
void glx_release_pixmap(session_t *ps, glx_texture_t *ptex);
|
2018-09-30 05:47:12 +08:00
|
|
|
|
2019-03-10 20:34:37 +08:00
|
|
|
void glx_paint_pre(session_t *ps, region_t *preg) attr_nonnull(1, 2);
|
2018-09-30 05:47:12 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a texture is binded, or is binded to the given pixmap.
|
|
|
|
*/
|
2019-03-10 20:34:37 +08:00
|
|
|
static inline bool glx_tex_binded(const glx_texture_t *ptex, xcb_pixmap_t pixmap) {
|
|
|
|
return ptex && ptex->glpixmap && ptex->texture && (!pixmap || pixmap == ptex->pixmap);
|
2018-09-30 05:47:12 +08:00
|
|
|
}
|
|
|
|
|
2019-03-10 20:34:37 +08:00
|
|
|
void glx_set_clip(session_t *ps, const region_t *reg);
|
2018-09-30 05:47:12 +08:00
|
|
|
|
2019-03-10 20:34:37 +08:00
|
|
|
bool glx_blur_dst(session_t *ps, int dx, int dy, int width, int height, float z,
|
|
|
|
GLfloat factor_center, const region_t *reg_tgt, glx_blur_cache_t *pbc);
|
2018-09-30 05:47:12 +08:00
|
|
|
|
2019-03-10 20:34:37 +08:00
|
|
|
GLuint glx_create_shader(GLenum shader_type, const char *shader_str);
|
2018-09-30 05:47:12 +08:00
|
|
|
|
2019-03-10 20:34:37 +08:00
|
|
|
GLuint glx_create_program(const GLuint *const shaders, int nshaders);
|
2018-09-30 05:47:12 +08:00
|
|
|
|
2019-03-10 20:34:37 +08:00
|
|
|
GLuint glx_create_program_from_str(const char *vert_shader_str, const char *frag_shader_str);
|
2018-09-30 05:47:12 +08:00
|
|
|
|
2019-03-10 20:34:37 +08:00
|
|
|
unsigned char *glx_take_screenshot(session_t *ps, int *out_length);
|
2018-09-30 05:47:12 +08:00
|
|
|
|
2018-12-16 05:11:41 +08:00
|
|
|
/**
|
|
|
|
* Check if there's a GLX context.
|
|
|
|
*/
|
2019-03-10 20:34:37 +08:00
|
|
|
static inline bool glx_has_context(session_t *ps) {
|
|
|
|
return ps->psglx && ps->psglx->context;
|
2018-12-16 05:11:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ensure we have a GLX context.
|
|
|
|
*/
|
2019-03-10 20:34:37 +08:00
|
|
|
static inline bool ensure_glx_context(session_t *ps) {
|
|
|
|
// Create GLX context
|
|
|
|
if (!glx_has_context(ps))
|
|
|
|
glx_init(ps, false);
|
2018-12-16 05:11:41 +08:00
|
|
|
|
2019-03-10 20:34:37 +08:00
|
|
|
return ps->psglx->context;
|
2018-12-16 05:11:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Free a GLX texture.
|
|
|
|
*/
|
2019-03-10 20:34:37 +08:00
|
|
|
static inline void free_texture_r(session_t *ps, GLuint *ptexture) {
|
|
|
|
if (*ptexture) {
|
|
|
|
assert(glx_has_context(ps));
|
|
|
|
glDeleteTextures(1, ptexture);
|
|
|
|
*ptexture = 0;
|
|
|
|
}
|
2018-12-16 05:11:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Free a GLX Framebuffer object.
|
|
|
|
*/
|
2019-03-10 20:34:37 +08:00
|
|
|
static inline void free_glx_fbo(session_t *ps, GLuint *pfbo) {
|
|
|
|
if (*pfbo) {
|
|
|
|
glDeleteFramebuffers(1, pfbo);
|
|
|
|
*pfbo = 0;
|
|
|
|
}
|
|
|
|
assert(!*pfbo);
|
2018-12-16 05:11:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Free data in glx_blur_cache_t on resize.
|
|
|
|
*/
|
2019-03-10 20:34:37 +08:00
|
|
|
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;
|
2018-12-16 05:11:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Free a glx_blur_cache_t
|
|
|
|
*/
|
2019-03-10 20:34:37 +08:00
|
|
|
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-12-16 05:11:41 +08:00
|
|
|
}
|
|
|
|
|
2018-09-30 05:47:12 +08:00
|
|
|
/**
|
|
|
|
* Free a glx_texture_t.
|
|
|
|
*/
|
2019-03-10 20:34:37 +08:00
|
|
|
static inline void free_texture(session_t *ps, glx_texture_t **pptex) {
|
|
|
|
glx_texture_t *ptex = *pptex;
|
2018-09-30 05:47:12 +08:00
|
|
|
|
2019-03-10 20:34:37 +08:00
|
|
|
// Quit if there's nothing
|
|
|
|
if (!ptex)
|
|
|
|
return;
|
2018-09-30 05:47:12 +08:00
|
|
|
|
2019-03-10 20:34:37 +08:00
|
|
|
glx_release_pixmap(ps, ptex);
|
2018-09-30 05:47:12 +08:00
|
|
|
|
2019-03-10 20:34:37 +08:00
|
|
|
free_texture_r(ps, &ptex->texture);
|
2018-09-30 05:47:12 +08:00
|
|
|
|
2019-03-10 20:34:37 +08:00
|
|
|
// Free structure itself
|
|
|
|
free(ptex);
|
|
|
|
*pptex = NULL;
|
|
|
|
assert(!*pptex);
|
2018-09-30 05:47:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Free GLX part of paint_t.
|
|
|
|
*/
|
2019-03-10 20:34:37 +08:00
|
|
|
static inline void free_paint_glx(session_t *ps, paint_t *ppaint) {
|
|
|
|
free_texture(ps, &ppaint->ptex);
|
2018-09-30 05:47:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Free GLX part of win.
|
|
|
|
*/
|
2019-04-18 06:14:45 +08:00
|
|
|
static inline void free_win_res_glx(session_t *ps, struct managed_win *w) {
|
2019-03-10 20:34:37 +08:00
|
|
|
free_paint_glx(ps, &w->paint);
|
|
|
|
free_paint_glx(ps, &w->shadow_paint);
|
2018-09-30 05:47:12 +08:00
|
|
|
#ifdef CONFIG_OPENGL
|
2019-03-10 20:34:37 +08:00
|
|
|
free_glx_bc(ps, &w->glx_blur_cache);
|
|
|
|
free(w->paint.fbcfg);
|
2018-09-30 05:47:12 +08:00
|
|
|
#endif
|
|
|
|
}
|