2018-12-16 05:11:41 +08:00
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
// Copyright (c) Yuxuan Shui <yshuiv7@gmail.com>
|
|
|
|
|
2019-01-21 05:15:20 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <xcb/composite.h>
|
|
|
|
#include <xcb/render.h>
|
2019-02-04 00:41:04 +08:00
|
|
|
#include <xcb/sync.h>
|
|
|
|
#include <xcb/xcb_image.h>
|
2019-01-21 05:15:20 +08:00
|
|
|
#include <xcb/xcb_renderutil.h>
|
2018-12-16 05:11:41 +08:00
|
|
|
|
|
|
|
#include "common.h"
|
2018-12-22 00:25:28 +08:00
|
|
|
#include "options.h"
|
2018-12-16 10:48:02 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_OPENGL
|
2019-02-09 08:36:14 +08:00
|
|
|
#include "backend/gl/glx.h"
|
2018-12-16 05:11:41 +08:00
|
|
|
#include "opengl.h"
|
2019-05-06 08:24:38 +08:00
|
|
|
|
|
|
|
#ifndef GLX_BACK_BUFFER_AGE_EXT
|
|
|
|
#define GLX_BACK_BUFFER_AGE_EXT 0x20F4
|
|
|
|
#endif
|
|
|
|
|
2018-12-16 10:48:02 +08:00
|
|
|
#endif
|
|
|
|
|
2019-01-21 00:53:39 +08:00
|
|
|
#include "compiler.h"
|
|
|
|
#include "config.h"
|
2019-02-04 00:41:04 +08:00
|
|
|
#include "kernel.h"
|
2019-01-21 00:53:39 +08:00
|
|
|
#include "log.h"
|
2019-02-04 00:41:04 +08:00
|
|
|
#include "region.h"
|
2019-01-21 00:53:39 +08:00
|
|
|
#include "types.h"
|
|
|
|
#include "utils.h"
|
2019-02-04 00:41:04 +08:00
|
|
|
#include "vsync.h"
|
|
|
|
#include "win.h"
|
|
|
|
#include "x.h"
|
2018-12-16 05:11:41 +08:00
|
|
|
|
2019-01-01 19:01:47 +08:00
|
|
|
#include "backend/backend_common.h"
|
2018-12-16 05:11:41 +08:00
|
|
|
#include "render.h"
|
|
|
|
|
2019-05-06 08:24:38 +08:00
|
|
|
#define XRFILTER_CONVOLUTION "convolution"
|
|
|
|
#define XRFILTER_GAUSSIAN "gaussian"
|
|
|
|
#define XRFILTER_BINOMIAL "binomial"
|
|
|
|
|
2018-12-16 05:11:41 +08:00
|
|
|
/**
|
|
|
|
* Bind texture in paint_t if we are using GLX backend.
|
|
|
|
*/
|
2019-03-30 17:07:21 +08:00
|
|
|
static inline bool paint_bind_tex(session_t *ps, paint_t *ppaint, int wid, int hei,
|
|
|
|
bool repeat, int depth, xcb_visualid_t visual, bool force) {
|
2019-02-04 00:41:04 +08:00
|
|
|
#ifdef CONFIG_OPENGL
|
2019-02-04 02:09:11 +08:00
|
|
|
// XXX This is a mess. But this will go away after the backend refactor.
|
|
|
|
static thread_local struct glx_fbconfig_info *argb_fbconfig = NULL;
|
2018-12-16 05:11:41 +08:00
|
|
|
if (!ppaint->pixmap)
|
|
|
|
return false;
|
|
|
|
|
2019-02-04 02:09:11 +08:00
|
|
|
struct glx_fbconfig_info *fbcfg;
|
2019-02-04 00:41:04 +08:00
|
|
|
if (!visual) {
|
2019-02-04 02:09:11 +08:00
|
|
|
assert(depth == 32);
|
|
|
|
if (!argb_fbconfig) {
|
2019-02-27 07:52:37 +08:00
|
|
|
argb_fbconfig =
|
|
|
|
glx_find_fbconfig(ps->dpy, ps->scr,
|
|
|
|
(struct xvisual_info){.red_size = 8,
|
|
|
|
.green_size = 8,
|
|
|
|
.blue_size = 8,
|
|
|
|
.alpha_size = 8,
|
|
|
|
.visual_depth = 32});
|
2019-02-04 02:09:11 +08:00
|
|
|
}
|
|
|
|
if (!argb_fbconfig) {
|
|
|
|
log_error("Failed to find appropriate FBConfig for 32 bit depth");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
fbcfg = argb_fbconfig;
|
2019-02-04 00:41:04 +08:00
|
|
|
} else {
|
2019-02-27 07:52:37 +08:00
|
|
|
auto m = x_get_visual_info(ps->c, visual);
|
2019-02-07 08:00:39 +08:00
|
|
|
if (m.visual_depth < 0) {
|
|
|
|
return false;
|
2019-02-04 02:09:11 +08:00
|
|
|
}
|
2019-02-04 00:41:04 +08:00
|
|
|
|
2019-02-07 08:00:39 +08:00
|
|
|
if (depth && depth != m.visual_depth) {
|
|
|
|
log_error("Mismatching visual depth: %d != %d", depth, m.visual_depth);
|
2019-02-04 02:09:11 +08:00
|
|
|
return false;
|
|
|
|
}
|
2019-02-04 00:41:04 +08:00
|
|
|
|
2019-02-04 02:09:11 +08:00
|
|
|
if (!ppaint->fbcfg) {
|
2019-02-07 08:00:39 +08:00
|
|
|
ppaint->fbcfg = glx_find_fbconfig(ps->dpy, ps->scr, m);
|
2019-02-04 02:09:11 +08:00
|
|
|
}
|
|
|
|
if (!ppaint->fbcfg) {
|
|
|
|
log_error("Failed to find appropriate FBConfig for X pixmap");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
fbcfg = ppaint->fbcfg;
|
2019-02-04 00:41:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (force || !glx_tex_binded(ppaint->ptex, ppaint->pixmap))
|
2019-02-09 05:48:39 +08:00
|
|
|
return glx_bind_pixmap(ps, &ppaint->ptex, ppaint->pixmap, wid, hei,
|
|
|
|
repeat, fbcfg);
|
2019-07-25 09:48:12 +08:00
|
|
|
#else
|
|
|
|
(void)ps;
|
|
|
|
(void)ppaint;
|
|
|
|
(void)wid;
|
|
|
|
(void)hei;
|
|
|
|
(void)repeat;
|
|
|
|
(void)depth;
|
|
|
|
(void)visual;
|
|
|
|
(void)force;
|
2019-02-04 00:41:04 +08:00
|
|
|
#endif
|
2018-12-16 05:11:41 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if current backend uses XRender for rendering.
|
|
|
|
*/
|
|
|
|
static inline bool bkend_use_xrender(session_t *ps) {
|
|
|
|
return BKEND_XRENDER == ps->o.backend || BKEND_XR_GLX_HYBRID == ps->o.backend;
|
|
|
|
}
|
|
|
|
|
2019-01-09 07:15:00 +08:00
|
|
|
int maximum_buffer_age(session_t *ps) {
|
2019-03-12 08:29:59 +08:00
|
|
|
if (bkend_use_glx(ps) && ps->o.use_damage) {
|
2019-01-09 07:15:00 +08:00
|
|
|
return CGLX_MAX_BUFFER_AGE;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int get_buffer_age(session_t *ps) {
|
|
|
|
#ifdef CONFIG_OPENGL
|
|
|
|
if (bkend_use_glx(ps)) {
|
2019-03-12 08:29:59 +08:00
|
|
|
if (!glxext.has_GLX_EXT_buffer_age && ps->o.use_damage) {
|
|
|
|
log_warn("GLX_EXT_buffer_age not supported by your driver,"
|
|
|
|
"`use-damage` has to be disabled");
|
|
|
|
ps->o.use_damage = false;
|
|
|
|
}
|
|
|
|
if (ps->o.use_damage) {
|
2019-01-09 07:15:00 +08:00
|
|
|
unsigned int val;
|
2019-02-07 08:00:39 +08:00
|
|
|
glXQueryDrawable(ps->dpy, get_tgt_window(ps),
|
|
|
|
GLX_BACK_BUFFER_AGE_EXT, &val);
|
2019-01-09 07:15:00 +08:00
|
|
|
return (int)val ?: -1;
|
|
|
|
}
|
2019-03-12 08:29:59 +08:00
|
|
|
return -1;
|
2019-01-09 07:15:00 +08:00
|
|
|
}
|
|
|
|
#endif
|
2019-03-12 08:29:59 +08:00
|
|
|
return ps->o.use_damage ? 1 : -1;
|
2019-01-09 07:15:00 +08:00
|
|
|
}
|
|
|
|
|
2018-12-16 05:11:41 +08:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
}
|
|
|
|
|
2019-01-09 07:15:00 +08:00
|
|
|
/// Set the input/output clip region of the target buffer (not the actual target!)
|
2018-12-21 01:03:27 +08:00
|
|
|
static inline void attr_nonnull(1, 2) set_tgt_clip(session_t *ps, region_t *reg) {
|
2018-12-16 05:11:41 +08:00
|
|
|
switch (ps->o.backend) {
|
|
|
|
case BKEND_XRENDER:
|
|
|
|
case BKEND_XR_GLX_HYBRID:
|
2019-02-03 23:59:31 +08:00
|
|
|
x_set_picture_clip_region(ps->c, ps->tgt_buffer.pict, 0, 0, reg);
|
2018-12-16 05:11:41 +08:00
|
|
|
break;
|
|
|
|
#ifdef CONFIG_OPENGL
|
|
|
|
case BKEND_GLX: glx_set_clip(ps, reg); break;
|
|
|
|
#endif
|
|
|
|
default: assert(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destroy a <code>Picture</code>.
|
|
|
|
*/
|
|
|
|
void free_picture(xcb_connection_t *c, xcb_render_picture_t *p) {
|
|
|
|
if (*p) {
|
|
|
|
xcb_render_free_picture(c, *p);
|
2018-12-28 04:45:38 +08:00
|
|
|
*p = XCB_NONE;
|
2018-12-16 05:11:41 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Free paint_t.
|
|
|
|
*/
|
|
|
|
void free_paint(session_t *ps, paint_t *ppaint) {
|
2018-12-16 10:48:02 +08:00
|
|
|
#ifdef CONFIG_OPENGL
|
2018-12-16 05:11:41 +08:00
|
|
|
free_paint_glx(ps, ppaint);
|
2018-12-16 10:48:02 +08:00
|
|
|
#endif
|
2018-12-16 05:11:41 +08:00
|
|
|
free_picture(ps->c, &ppaint->pict);
|
|
|
|
if (ppaint->pixmap)
|
|
|
|
xcb_free_pixmap(ps->c, ppaint->pixmap);
|
|
|
|
ppaint->pixmap = XCB_NONE;
|
|
|
|
}
|
|
|
|
|
2018-12-16 10:50:39 +08:00
|
|
|
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,
|
|
|
|
const region_t *reg_paint, const glx_prog_main_t *pprogram) {
|
2018-12-16 05:11:41 +08:00
|
|
|
switch (ps->o.backend) {
|
|
|
|
case BKEND_XRENDER:
|
|
|
|
case BKEND_XR_GLX_HYBRID: {
|
2019-03-30 17:07:21 +08:00
|
|
|
auto alpha_step = (int)(opacity * MAX_ALPHA);
|
2018-12-16 05:11:41 +08:00
|
|
|
xcb_render_picture_t alpha_pict = ps->alpha_picts[alpha_step];
|
|
|
|
if (alpha_step != 0) {
|
2019-03-30 17:07:21 +08:00
|
|
|
uint8_t op = ((!argb && !alpha_pict) ? XCB_RENDER_PICT_OP_SRC
|
|
|
|
: XCB_RENDER_PICT_OP_OVER);
|
|
|
|
xcb_render_composite(
|
|
|
|
ps->c, op, pict, alpha_pict, ps->tgt_buffer.pict,
|
|
|
|
to_i16_checked(x), to_i16_checked(y), 0, 0, to_i16_checked(dx),
|
|
|
|
to_i16_checked(dy), to_u16_checked(wid), to_u16_checked(hei));
|
2018-12-16 05:11:41 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#ifdef CONFIG_OPENGL
|
|
|
|
case BKEND_GLX:
|
2018-12-16 10:50:39 +08:00
|
|
|
glx_render(ps, ptex, x, y, dx, dy, wid, hei, ps->psglx->z, opacity, argb,
|
|
|
|
neg, reg_paint, pprogram);
|
2018-12-16 05:11:41 +08:00
|
|
|
ps->psglx->z += 1;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default: assert(0);
|
|
|
|
}
|
2019-07-25 09:48:12 +08:00
|
|
|
#ifndef CONFIG_OPENGL
|
|
|
|
(void)neg;
|
|
|
|
(void)ptex;
|
|
|
|
(void)reg_paint;
|
|
|
|
(void)pprogram;
|
|
|
|
#endif
|
2018-12-16 05:11:41 +08:00
|
|
|
}
|
|
|
|
|
2019-02-07 08:00:39 +08:00
|
|
|
static inline void
|
2019-04-18 06:14:45 +08:00
|
|
|
paint_region(session_t *ps, const struct managed_win *w, int x, int y, int wid, int hei,
|
|
|
|
double opacity, const region_t *reg_paint, xcb_render_picture_t pict) {
|
2018-12-16 05:11:41 +08:00
|
|
|
const int dx = (w ? w->g.x : 0) + x;
|
|
|
|
const int dy = (w ? w->g.y : 0) + y;
|
|
|
|
const bool argb = (w && (win_has_alpha(w) || ps->o.force_win_blend));
|
|
|
|
const bool neg = (w && w->invert_color);
|
|
|
|
|
|
|
|
render(ps, x, y, dx, dy, wid, hei, opacity, argb, neg, pict,
|
|
|
|
(w ? w->paint.ptex : ps->root_tile_paint.ptex), reg_paint,
|
2018-12-22 00:25:28 +08:00
|
|
|
#ifdef CONFIG_OPENGL
|
|
|
|
w ? &ps->glx_prog_win : NULL
|
|
|
|
#else
|
|
|
|
NULL
|
|
|
|
#endif
|
|
|
|
);
|
2018-12-16 05:11:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check whether a paint_t contains enough data.
|
|
|
|
*/
|
|
|
|
static inline bool paint_isvalid(session_t *ps, const paint_t *ppaint) {
|
|
|
|
// Don't check for presence of Pixmap here, because older X Composite doesn't
|
|
|
|
// provide it
|
|
|
|
if (!ppaint)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (bkend_use_xrender(ps) && !ppaint->pict)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
#ifdef CONFIG_OPENGL
|
2018-12-28 04:45:38 +08:00
|
|
|
if (BKEND_GLX == ps->o.backend && !glx_tex_binded(ppaint->ptex, XCB_NONE))
|
2018-12-16 05:11:41 +08:00
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Paint a window itself and dim it if asked.
|
|
|
|
*/
|
2019-04-18 06:14:45 +08:00
|
|
|
void paint_one(session_t *ps, struct managed_win *w, const region_t *reg_paint) {
|
2018-12-16 05:11:41 +08:00
|
|
|
// Fetch Pixmap
|
2019-03-06 06:13:22 +08:00
|
|
|
if (!w->paint.pixmap) {
|
2019-04-08 12:49:39 +08:00
|
|
|
w->paint.pixmap = x_new_id(ps->c);
|
2019-04-18 06:14:45 +08:00
|
|
|
set_ignore_cookie(ps, xcb_composite_name_window_pixmap(ps->c, w->base.id,
|
|
|
|
w->paint.pixmap));
|
2018-12-16 05:11:41 +08:00
|
|
|
}
|
|
|
|
|
2018-12-30 15:41:31 +08:00
|
|
|
xcb_drawable_t draw = w->paint.pixmap;
|
2019-03-06 06:13:22 +08:00
|
|
|
if (!draw) {
|
|
|
|
log_error("Failed to get pixmap from window %#010x (%s), window won't be "
|
|
|
|
"visible",
|
2019-04-18 06:14:45 +08:00
|
|
|
w->base.id, w->name);
|
2019-03-06 06:13:22 +08:00
|
|
|
return;
|
|
|
|
}
|
2018-12-16 05:11:41 +08:00
|
|
|
|
|
|
|
// XRender: Build picture
|
|
|
|
if (bkend_use_xrender(ps) && !w->paint.pict) {
|
|
|
|
xcb_render_create_picture_value_list_t pa = {
|
2019-01-21 00:53:39 +08:00
|
|
|
.subwindowmode = XCB_SUBWINDOW_MODE_INCLUDE_INFERIORS,
|
2018-12-16 05:11:41 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
w->paint.pict = x_create_picture_with_pictfmt_and_pixmap(
|
2019-02-03 23:59:31 +08:00
|
|
|
ps->c, w->pictfmt, draw, XCB_RENDER_CP_SUBWINDOW_MODE, &pa);
|
2018-12-16 05:11:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// GLX: Build texture
|
|
|
|
// Let glx_bind_pixmap() determine pixmap size, because if the user
|
|
|
|
// is resizing windows, the width and height we get may not be up-to-date,
|
|
|
|
// causing the jittering issue M4he reported in #7.
|
2019-02-09 05:48:39 +08:00
|
|
|
if (!paint_bind_tex(ps, &w->paint, 0, 0, false, 0, w->a.visual,
|
2019-02-04 00:41:04 +08:00
|
|
|
(!ps->o.glx_no_rebind_pixmap && w->pixmap_damaged))) {
|
2019-04-18 06:14:45 +08:00
|
|
|
log_error("Failed to bind texture for window %#010x.", w->base.id);
|
2018-12-16 05:11:41 +08:00
|
|
|
}
|
|
|
|
w->pixmap_damaged = false;
|
|
|
|
|
|
|
|
if (!paint_isvalid(ps, &w->paint)) {
|
2019-04-18 06:14:45 +08:00
|
|
|
log_error("Window %#010x is missing painting data.", w->base.id);
|
2018-12-16 05:11:41 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const int x = w->g.x;
|
|
|
|
const int y = w->g.y;
|
2019-03-30 17:07:21 +08:00
|
|
|
const uint16_t wid = to_u16_checked(w->widthb);
|
|
|
|
const uint16_t hei = to_u16_checked(w->heightb);
|
2018-12-16 05:11:41 +08:00
|
|
|
|
|
|
|
xcb_render_picture_t pict = w->paint.pict;
|
|
|
|
|
|
|
|
// Invert window color, if required
|
|
|
|
if (bkend_use_xrender(ps) && w->invert_color) {
|
2019-02-27 07:52:37 +08:00
|
|
|
xcb_render_picture_t newpict = x_create_picture_with_pictfmt(
|
|
|
|
ps->c, ps->root, wid, hei, w->pictfmt, 0, NULL);
|
2018-12-16 05:11:41 +08:00
|
|
|
if (newpict) {
|
|
|
|
// Apply clipping region to save some CPU
|
|
|
|
if (reg_paint) {
|
|
|
|
region_t reg;
|
|
|
|
pixman_region32_init(®);
|
|
|
|
pixman_region32_copy(®, (region_t *)reg_paint);
|
|
|
|
pixman_region32_translate(®, -x, -y);
|
2019-01-09 07:15:00 +08:00
|
|
|
// FIXME XFixesSetPictureClipRegion(ps->dpy, newpict, 0,
|
|
|
|
// 0, reg);
|
2018-12-16 05:11:41 +08:00
|
|
|
pixman_region32_fini(®);
|
|
|
|
}
|
|
|
|
|
2018-12-28 04:45:38 +08:00
|
|
|
xcb_render_composite(ps->c, XCB_RENDER_PICT_OP_SRC, pict, XCB_NONE,
|
2018-12-16 10:50:39 +08:00
|
|
|
newpict, 0, 0, 0, 0, 0, 0, wid, hei);
|
2019-02-07 08:00:39 +08:00
|
|
|
xcb_render_composite(ps->c, XCB_RENDER_PICT_OP_DIFFERENCE,
|
|
|
|
ps->white_picture, XCB_NONE, newpict, 0, 0,
|
|
|
|
0, 0, 0, 0, wid, hei);
|
2018-12-16 05:11:41 +08:00
|
|
|
// We use an extra PictOpInReverse operation to get correct
|
|
|
|
// pixel alpha. There could be a better solution.
|
|
|
|
if (win_has_alpha(w))
|
2018-12-16 10:50:39 +08:00
|
|
|
xcb_render_composite(ps->c, XCB_RENDER_PICT_OP_IN_REVERSE,
|
2019-01-01 08:15:51 +08:00
|
|
|
pict, XCB_NONE, newpict, 0, 0, 0, 0,
|
|
|
|
0, 0, wid, hei);
|
2018-12-16 05:11:41 +08:00
|
|
|
pict = newpict;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (w->frame_opacity == 1) {
|
2019-02-09 23:50:40 +08:00
|
|
|
paint_region(ps, w, 0, 0, wid, hei, w->opacity, reg_paint, pict);
|
2018-12-16 05:11:41 +08:00
|
|
|
} else {
|
|
|
|
// Painting parameters
|
|
|
|
const margin_t extents = win_calc_frame_extents(w);
|
2019-03-30 18:19:31 +08:00
|
|
|
const auto t = extents.top;
|
|
|
|
const auto l = extents.left;
|
|
|
|
const auto b = extents.bottom;
|
|
|
|
const auto r = extents.right;
|
2018-12-16 05:11:41 +08:00
|
|
|
|
2018-12-16 10:50:39 +08:00
|
|
|
#define COMP_BDR(cx, cy, cwid, chei) \
|
2019-02-18 07:47:46 +08:00
|
|
|
paint_region(ps, w, (cx), (cy), (cwid), (chei), w->frame_opacity * w->opacity, \
|
2019-02-07 08:00:39 +08:00
|
|
|
reg_paint, pict)
|
2018-12-16 05:11:41 +08:00
|
|
|
|
|
|
|
// Sanitize the margins, in case some broken WM makes
|
|
|
|
// top_width + bottom_width > height in some cases.
|
|
|
|
|
|
|
|
do {
|
|
|
|
// top
|
|
|
|
int body_height = hei;
|
|
|
|
// ctop = checked top
|
2019-01-01 08:15:51 +08:00
|
|
|
// Make sure top margin is smaller than height
|
2019-03-30 17:07:21 +08:00
|
|
|
int ctop = min2(body_height, t);
|
2018-12-16 05:11:41 +08:00
|
|
|
if (ctop > 0)
|
|
|
|
COMP_BDR(0, 0, wid, ctop);
|
|
|
|
|
|
|
|
body_height -= ctop;
|
|
|
|
if (body_height <= 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
// bottom
|
|
|
|
// cbot = checked bottom
|
2019-01-01 08:15:51 +08:00
|
|
|
// Make sure bottom margin is not too large
|
2019-03-30 17:07:21 +08:00
|
|
|
int cbot = min2(body_height, b);
|
2018-12-16 05:11:41 +08:00
|
|
|
if (cbot > 0)
|
|
|
|
COMP_BDR(0, hei - cbot, wid, cbot);
|
|
|
|
|
2019-01-01 08:15:51 +08:00
|
|
|
// Height of window exclude the margin
|
|
|
|
body_height -= cbot;
|
2018-12-16 05:11:41 +08:00
|
|
|
if (body_height <= 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
// left
|
|
|
|
int body_width = wid;
|
2019-03-30 17:07:21 +08:00
|
|
|
int cleft = min2(body_width, l);
|
2018-12-16 05:11:41 +08:00
|
|
|
if (cleft > 0)
|
|
|
|
COMP_BDR(0, ctop, cleft, body_height);
|
|
|
|
|
|
|
|
body_width -= cleft;
|
|
|
|
if (body_width <= 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
// right
|
2019-03-30 17:07:21 +08:00
|
|
|
int cright = min2(body_width, r);
|
2018-12-16 05:11:41 +08:00
|
|
|
if (cright > 0)
|
|
|
|
COMP_BDR(wid - cright, ctop, cright, body_height);
|
|
|
|
|
|
|
|
body_width -= cright;
|
|
|
|
if (body_width <= 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
// body
|
|
|
|
paint_region(ps, w, cleft, ctop, body_width, body_height,
|
2019-02-09 23:50:40 +08:00
|
|
|
w->opacity, reg_paint, pict);
|
2018-12-16 05:11:41 +08:00
|
|
|
} while (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef COMP_BDR
|
|
|
|
|
|
|
|
if (pict != w->paint.pict)
|
|
|
|
free_picture(ps->c, &pict);
|
|
|
|
|
|
|
|
// Dimming the window if needed
|
|
|
|
if (w->dim) {
|
|
|
|
double dim_opacity = ps->o.inactive_dim;
|
|
|
|
if (!ps->o.inactive_dim_fixed)
|
2019-02-09 23:50:40 +08:00
|
|
|
dim_opacity *= w->opacity;
|
2018-12-16 05:11:41 +08:00
|
|
|
|
|
|
|
switch (ps->o.backend) {
|
|
|
|
case BKEND_XRENDER:
|
|
|
|
case BKEND_XR_GLX_HYBRID: {
|
2019-03-30 17:07:21 +08:00
|
|
|
auto cval = (uint16_t)(0xffff * dim_opacity);
|
2018-12-16 05:11:41 +08:00
|
|
|
|
|
|
|
// Premultiply color
|
|
|
|
xcb_render_color_t color = {
|
|
|
|
.red = 0,
|
|
|
|
.green = 0,
|
|
|
|
.blue = 0,
|
|
|
|
.alpha = cval,
|
|
|
|
};
|
|
|
|
|
|
|
|
xcb_rectangle_t rect = {
|
2019-03-30 17:07:21 +08:00
|
|
|
.x = to_i16_checked(x),
|
|
|
|
.y = to_i16_checked(y),
|
2018-12-16 05:11:41 +08:00
|
|
|
.width = wid,
|
|
|
|
.height = hei,
|
|
|
|
};
|
|
|
|
|
|
|
|
xcb_render_fill_rectangles(ps->c, XCB_RENDER_PICT_OP_OVER,
|
2018-12-16 10:50:39 +08:00
|
|
|
ps->tgt_buffer.pict, color, 1, &rect);
|
2018-12-16 05:11:41 +08:00
|
|
|
} break;
|
|
|
|
#ifdef CONFIG_OPENGL
|
|
|
|
case BKEND_GLX:
|
2019-03-30 17:07:21 +08:00
|
|
|
glx_dim_dst(ps, x, y, wid, hei, (int)(ps->psglx->z - 0.7),
|
|
|
|
(float)dim_opacity, reg_paint);
|
2018-12-16 05:11:41 +08:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default: assert(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extern const char *background_props_str[];
|
|
|
|
|
|
|
|
static bool get_root_tile(session_t *ps) {
|
|
|
|
/*
|
|
|
|
if (ps->o.paint_on_overlay) {
|
|
|
|
return ps->root_picture;
|
|
|
|
} */
|
|
|
|
|
|
|
|
assert(!ps->root_tile_paint.pixmap);
|
|
|
|
ps->root_tile_fill = false;
|
|
|
|
|
|
|
|
bool fill = false;
|
2019-02-07 08:30:32 +08:00
|
|
|
xcb_pixmap_t pixmap = x_get_root_back_pixmap(ps);
|
2018-12-16 05:11:41 +08:00
|
|
|
|
|
|
|
// Make sure the pixmap we got is valid
|
2019-02-03 23:59:31 +08:00
|
|
|
if (pixmap && !x_validate_pixmap(ps->c, pixmap))
|
2018-12-21 01:03:27 +08:00
|
|
|
pixmap = XCB_NONE;
|
2018-12-16 05:11:41 +08:00
|
|
|
|
|
|
|
// Create a pixmap if there isn't any
|
|
|
|
if (!pixmap) {
|
2019-03-30 17:07:21 +08:00
|
|
|
pixmap = x_create_pixmap(ps->c, (uint8_t)ps->depth, ps->root, 1, 1);
|
2018-12-16 05:11:41 +08:00
|
|
|
if (pixmap == XCB_NONE) {
|
2018-12-21 01:03:27 +08:00
|
|
|
log_error("Failed to create pixmaps for root tile.");
|
|
|
|
return false;
|
2018-12-16 05:11:41 +08:00
|
|
|
}
|
|
|
|
fill = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create Picture
|
|
|
|
xcb_render_create_picture_value_list_t pa = {
|
2019-01-21 00:53:39 +08:00
|
|
|
.repeat = true,
|
2018-12-16 05:11:41 +08:00
|
|
|
};
|
|
|
|
ps->root_tile_paint.pict = x_create_picture_with_visual_and_pixmap(
|
2019-02-03 23:59:31 +08:00
|
|
|
ps->c, ps->vis, pixmap, XCB_RENDER_CP_REPEAT, &pa);
|
2018-12-16 05:11:41 +08:00
|
|
|
|
|
|
|
// Fill pixmap if needed
|
|
|
|
if (fill) {
|
|
|
|
xcb_render_color_t col;
|
|
|
|
xcb_rectangle_t rect;
|
|
|
|
|
|
|
|
col.red = col.green = col.blue = 0x8080;
|
|
|
|
col.alpha = 0xffff;
|
|
|
|
|
|
|
|
rect.x = rect.y = 0;
|
|
|
|
rect.width = rect.height = 1;
|
|
|
|
|
|
|
|
xcb_render_fill_rectangles(ps->c, XCB_RENDER_PICT_OP_SRC,
|
|
|
|
ps->root_tile_paint.pict, col, 1, &rect);
|
|
|
|
}
|
|
|
|
|
|
|
|
ps->root_tile_fill = fill;
|
|
|
|
ps->root_tile_paint.pixmap = pixmap;
|
|
|
|
#ifdef CONFIG_OPENGL
|
|
|
|
if (BKEND_GLX == ps->o.backend)
|
2019-02-09 05:48:39 +08:00
|
|
|
return paint_bind_tex(ps, &ps->root_tile_paint, 0, 0, true, 0, ps->vis, false);
|
2018-12-16 05:11:41 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Paint root window content.
|
|
|
|
*/
|
|
|
|
static void paint_root(session_t *ps, const region_t *reg_paint) {
|
2018-12-21 01:03:27 +08:00
|
|
|
// If there is no root tile pixmap, try getting one.
|
|
|
|
// If that fails, give up.
|
|
|
|
if (!ps->root_tile_paint.pixmap && !get_root_tile(ps))
|
|
|
|
return;
|
2018-12-16 05:11:41 +08:00
|
|
|
|
|
|
|
paint_region(ps, NULL, 0, 0, ps->root_width, ps->root_height, 1.0, reg_paint,
|
|
|
|
ps->root_tile_paint.pict);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate shadow <code>Picture</code> for a window.
|
|
|
|
*/
|
2019-04-18 06:14:45 +08:00
|
|
|
static bool win_build_shadow(session_t *ps, struct managed_win *w, double opacity) {
|
2018-12-16 05:11:41 +08:00
|
|
|
const int width = w->widthb;
|
|
|
|
const int height = w->heightb;
|
2018-12-21 01:03:27 +08:00
|
|
|
// log_trace("(): building shadow for %s %d %d", w->name, width, height);
|
2018-12-16 05:11:41 +08:00
|
|
|
|
|
|
|
xcb_image_t *shadow_image = NULL;
|
2018-12-28 04:45:38 +08:00
|
|
|
xcb_pixmap_t shadow_pixmap = XCB_NONE, shadow_pixmap_argb = XCB_NONE;
|
|
|
|
xcb_render_picture_t shadow_picture = XCB_NONE, shadow_picture_argb = XCB_NONE;
|
|
|
|
xcb_gcontext_t gc = XCB_NONE;
|
2018-12-16 05:11:41 +08:00
|
|
|
|
2019-01-09 07:15:00 +08:00
|
|
|
shadow_image = make_shadow(ps->c, ps->gaussian_map, opacity, width, height);
|
2018-12-16 05:11:41 +08:00
|
|
|
if (!shadow_image) {
|
2018-12-21 01:03:27 +08:00
|
|
|
log_error("failed to make shadow");
|
2018-12-28 04:45:38 +08:00
|
|
|
return XCB_NONE;
|
2018-12-16 05:11:41 +08:00
|
|
|
}
|
|
|
|
|
2019-02-04 00:41:04 +08:00
|
|
|
shadow_pixmap =
|
|
|
|
x_create_pixmap(ps->c, 8, ps->root, shadow_image->width, shadow_image->height);
|
2018-12-16 10:50:39 +08:00
|
|
|
shadow_pixmap_argb =
|
2019-02-03 23:59:31 +08:00
|
|
|
x_create_pixmap(ps->c, 32, ps->root, shadow_image->width, shadow_image->height);
|
2018-12-16 05:11:41 +08:00
|
|
|
|
|
|
|
if (!shadow_pixmap || !shadow_pixmap_argb) {
|
2018-12-21 01:03:27 +08:00
|
|
|
log_error("failed to create shadow pixmaps");
|
2018-12-16 05:11:41 +08:00
|
|
|
goto shadow_picture_err;
|
|
|
|
}
|
|
|
|
|
|
|
|
shadow_picture = x_create_picture_with_standard_and_pixmap(
|
2019-02-03 23:59:31 +08:00
|
|
|
ps->c, XCB_PICT_STANDARD_A_8, shadow_pixmap, 0, NULL);
|
2018-12-16 05:11:41 +08:00
|
|
|
shadow_picture_argb = x_create_picture_with_standard_and_pixmap(
|
2019-02-03 23:59:31 +08:00
|
|
|
ps->c, XCB_PICT_STANDARD_ARGB_32, shadow_pixmap_argb, 0, NULL);
|
2018-12-16 05:11:41 +08:00
|
|
|
if (!shadow_picture || !shadow_picture_argb)
|
|
|
|
goto shadow_picture_err;
|
|
|
|
|
2019-04-08 12:49:39 +08:00
|
|
|
gc = x_new_id(ps->c);
|
2018-12-16 05:11:41 +08:00
|
|
|
xcb_create_gc(ps->c, gc, shadow_pixmap, 0, NULL);
|
|
|
|
|
|
|
|
xcb_image_put(ps->c, shadow_pixmap, gc, shadow_image, 0, 0, 0);
|
|
|
|
xcb_render_composite(ps->c, XCB_RENDER_PICT_OP_SRC, ps->cshadow_picture,
|
|
|
|
shadow_picture, shadow_picture_argb, 0, 0, 0, 0, 0, 0,
|
|
|
|
shadow_image->width, shadow_image->height);
|
|
|
|
|
|
|
|
assert(!w->shadow_paint.pixmap);
|
|
|
|
w->shadow_paint.pixmap = shadow_pixmap_argb;
|
|
|
|
assert(!w->shadow_paint.pict);
|
|
|
|
w->shadow_paint.pict = shadow_picture_argb;
|
|
|
|
|
|
|
|
xcb_free_gc(ps->c, gc);
|
|
|
|
xcb_image_destroy(shadow_image);
|
|
|
|
xcb_free_pixmap(ps->c, shadow_pixmap);
|
|
|
|
xcb_render_free_picture(ps->c, shadow_picture);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
shadow_picture_err:
|
|
|
|
if (shadow_image)
|
|
|
|
xcb_image_destroy(shadow_image);
|
|
|
|
if (shadow_pixmap)
|
|
|
|
xcb_free_pixmap(ps->c, shadow_pixmap);
|
|
|
|
if (shadow_pixmap_argb)
|
|
|
|
xcb_free_pixmap(ps->c, shadow_pixmap_argb);
|
|
|
|
if (shadow_picture)
|
|
|
|
xcb_render_free_picture(ps->c, shadow_picture);
|
|
|
|
if (shadow_picture_argb)
|
|
|
|
xcb_render_free_picture(ps->c, shadow_picture_argb);
|
|
|
|
if (gc)
|
|
|
|
xcb_free_gc(ps->c, gc);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Paint the shadow of a window.
|
|
|
|
*/
|
2019-04-18 06:14:45 +08:00
|
|
|
static inline void
|
|
|
|
win_paint_shadow(session_t *ps, struct managed_win *w, region_t *reg_paint) {
|
2018-12-16 05:11:41 +08:00
|
|
|
// Bind shadow pixmap to GLX texture if needed
|
2019-02-09 05:48:39 +08:00
|
|
|
paint_bind_tex(ps, &w->shadow_paint, 0, 0, false, 32, 0, false);
|
2018-12-16 05:11:41 +08:00
|
|
|
|
|
|
|
if (!paint_isvalid(ps, &w->shadow_paint)) {
|
2019-04-18 06:14:45 +08:00
|
|
|
log_error("Window %#010x is missing shadow data.", w->base.id);
|
2018-12-16 05:11:41 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-12-16 10:50:39 +08:00
|
|
|
render(ps, 0, 0, w->g.x + w->shadow_dx, w->g.y + w->shadow_dy, w->shadow_width,
|
|
|
|
w->shadow_height, w->shadow_opacity, true, false, w->shadow_paint.pict,
|
|
|
|
w->shadow_paint.ptex, reg_paint, NULL);
|
2018-12-16 05:11:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Blur an area on a buffer.
|
|
|
|
*
|
|
|
|
* @param ps current session
|
|
|
|
* @param tgt_buffer a buffer as both source and destination
|
|
|
|
* @param x x pos
|
|
|
|
* @param y y pos
|
|
|
|
* @param wid width
|
|
|
|
* @param hei height
|
|
|
|
* @param blur_kerns blur kernels, ending with a NULL, guaranteed to have at
|
|
|
|
* least one kernel
|
|
|
|
* @param reg_clip a clipping region to be applied on intermediate buffers
|
|
|
|
*
|
|
|
|
* @return true if successful, false otherwise
|
|
|
|
*/
|
2019-06-08 04:53:23 +08:00
|
|
|
static bool xr_blur_dst(session_t *ps, xcb_render_picture_t tgt_buffer, int16_t x, int16_t y,
|
|
|
|
uint16_t wid, uint16_t hei, struct x_convolution_kernel **blur_kerns,
|
|
|
|
int nkernels, const region_t *reg_clip) {
|
|
|
|
assert(blur_kerns);
|
2018-12-16 05:11:41 +08:00
|
|
|
assert(blur_kerns[0]);
|
|
|
|
|
|
|
|
// Directly copying from tgt_buffer to it does not work, so we create a
|
|
|
|
// Picture in the middle.
|
2018-12-22 07:44:42 +08:00
|
|
|
xcb_render_picture_t tmp_picture =
|
2019-02-27 08:30:27 +08:00
|
|
|
x_create_picture_with_visual(ps->c, ps->root, wid, hei, ps->vis, 0, NULL);
|
2018-12-16 05:11:41 +08:00
|
|
|
|
|
|
|
if (!tmp_picture) {
|
2018-12-21 01:03:27 +08:00
|
|
|
log_error("Failed to build intermediate Picture.");
|
2018-12-16 05:11:41 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (reg_clip && tmp_picture)
|
2019-02-03 23:59:31 +08:00
|
|
|
x_set_picture_clip_region(ps->c, tmp_picture, 0, 0, reg_clip);
|
2018-12-16 05:11:41 +08:00
|
|
|
|
|
|
|
xcb_render_picture_t src_pict = tgt_buffer, dst_pict = tmp_picture;
|
2019-06-08 04:53:23 +08:00
|
|
|
for (int i = 0; i < nkernels; ++i) {
|
2019-06-06 14:37:48 +08:00
|
|
|
xcb_render_fixed_t *convolution_blur = blur_kerns[i]->kernel;
|
2019-02-18 07:47:46 +08:00
|
|
|
// `x / 65536.0` converts from X fixed point to double
|
2019-03-30 17:07:21 +08:00
|
|
|
int kwid = (int)((double)convolution_blur[0] / 65536.0),
|
|
|
|
khei = (int)((double)convolution_blur[1] / 65536.0);
|
2018-12-16 05:11:41 +08:00
|
|
|
bool rd_from_tgt = (tgt_buffer == src_pict);
|
|
|
|
|
|
|
|
// Copy from source picture to destination. The filter must
|
|
|
|
// be applied on source picture, to get the nearby pixels outside the
|
|
|
|
// window.
|
2019-03-30 17:07:21 +08:00
|
|
|
xcb_render_set_picture_filter(
|
|
|
|
ps->c, src_pict, strlen(XRFILTER_CONVOLUTION), XRFILTER_CONVOLUTION,
|
|
|
|
(uint32_t)(kwid * khei + 2), convolution_blur);
|
2019-02-07 08:00:39 +08:00
|
|
|
xcb_render_composite(ps->c, XCB_RENDER_PICT_OP_SRC, src_pict, XCB_NONE,
|
|
|
|
dst_pict, (rd_from_tgt ? x : 0),
|
|
|
|
(rd_from_tgt ? y : 0), 0, 0, (rd_from_tgt ? 0 : x),
|
|
|
|
(rd_from_tgt ? 0 : y), wid, hei);
|
2018-12-16 05:11:41 +08:00
|
|
|
xrfilter_reset(ps, src_pict);
|
|
|
|
|
|
|
|
{
|
|
|
|
xcb_render_picture_t tmp = src_pict;
|
|
|
|
src_pict = dst_pict;
|
|
|
|
dst_pict = tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (src_pict != tgt_buffer)
|
2018-12-28 04:45:38 +08:00
|
|
|
xcb_render_composite(ps->c, XCB_RENDER_PICT_OP_SRC, src_pict, XCB_NONE,
|
2018-12-16 05:11:41 +08:00
|
|
|
tgt_buffer, 0, 0, 0, 0, x, y, wid, hei);
|
|
|
|
|
|
|
|
free_picture(ps->c, &tmp_picture);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Blur the background of a window.
|
|
|
|
*/
|
2019-04-18 06:14:45 +08:00
|
|
|
static inline void
|
2019-06-06 14:37:48 +08:00
|
|
|
win_blur_background(session_t *ps, struct managed_win *w, xcb_render_picture_t tgt_buffer,
|
|
|
|
const region_t *reg_paint) {
|
2019-03-30 17:07:21 +08:00
|
|
|
const int16_t x = w->g.x;
|
|
|
|
const int16_t y = w->g.y;
|
|
|
|
const auto wid = to_u16_checked(w->widthb);
|
|
|
|
const auto hei = to_u16_checked(w->heightb);
|
2018-12-16 05:11:41 +08:00
|
|
|
|
|
|
|
double factor_center = 1.0;
|
|
|
|
// Adjust blur strength according to window opacity, to make it appear
|
|
|
|
// better during fading
|
|
|
|
if (!ps->o.blur_background_fixed) {
|
2019-02-09 23:50:40 +08:00
|
|
|
double pct = 1.0 - w->opacity * (1.0 - 1.0 / 9.0);
|
2018-12-16 05:11:41 +08:00
|
|
|
factor_center = pct * 8.0 / (1.1 - pct);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (ps->o.backend) {
|
|
|
|
case BKEND_XRENDER:
|
|
|
|
case BKEND_XR_GLX_HYBRID: {
|
|
|
|
// Normalize blur kernels
|
2019-06-08 04:53:23 +08:00
|
|
|
for (int i = 0; i < ps->o.blur_kernel_count; i++) {
|
2019-02-18 07:47:46 +08:00
|
|
|
// Note: `x * 65536` converts double `x` to a X fixed point
|
|
|
|
// representation. `x / 65536` is the other way.
|
|
|
|
auto kern_src = ps->o.blur_kerns[i];
|
2019-06-06 14:37:48 +08:00
|
|
|
auto kern_dst = ps->blur_kerns_cache[i];
|
2018-12-16 05:11:41 +08:00
|
|
|
|
2019-06-06 14:37:48 +08:00
|
|
|
assert(!kern_dst || (kern_src->w == kern_dst->kernel[0] / 65536 &&
|
|
|
|
kern_src->h == kern_dst->kernel[1] / 65536));
|
2018-12-16 05:11:41 +08:00
|
|
|
|
|
|
|
// Skip for fixed factor_center if the cache exists already
|
2019-02-21 00:43:42 +08:00
|
|
|
if (ps->o.blur_background_fixed && kern_dst) {
|
2018-12-16 05:11:41 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-06-06 14:37:48 +08:00
|
|
|
x_create_convolution_kernel(kern_src, factor_center,
|
|
|
|
&ps->blur_kerns_cache[i]);
|
2018-12-16 05:11:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Minimize the region we try to blur, if the window itself is not
|
|
|
|
// opaque, only the frame is.
|
|
|
|
region_t reg_blur = win_get_bounding_shape_global_by_val(w);
|
2019-07-13 19:29:39 +08:00
|
|
|
if (w->mode == WMODE_FRAME_TRANS && !ps->o.force_win_blend) {
|
2018-12-16 05:11:41 +08:00
|
|
|
region_t reg_noframe;
|
|
|
|
pixman_region32_init(®_noframe);
|
|
|
|
win_get_region_noframe_local(w, ®_noframe);
|
|
|
|
pixman_region32_translate(®_noframe, w->g.x, w->g.y);
|
|
|
|
pixman_region32_subtract(®_blur, ®_blur, ®_noframe);
|
|
|
|
pixman_region32_fini(®_noframe);
|
|
|
|
}
|
|
|
|
// Translate global coordinates to local ones
|
|
|
|
pixman_region32_translate(®_blur, -x, -y);
|
2019-06-08 04:53:23 +08:00
|
|
|
xr_blur_dst(ps, tgt_buffer, x, y, wid, hei, ps->blur_kerns_cache,
|
|
|
|
ps->o.blur_kernel_count, ®_blur);
|
2018-12-16 05:11:41 +08:00
|
|
|
pixman_region32_clear(®_blur);
|
|
|
|
} break;
|
|
|
|
#ifdef CONFIG_OPENGL
|
|
|
|
case BKEND_GLX:
|
|
|
|
// TODO: Handle frame opacity
|
2019-03-30 17:07:21 +08:00
|
|
|
glx_blur_dst(ps, x, y, wid, hei, (float)ps->psglx->z - 0.5f,
|
|
|
|
(float)factor_center, reg_paint, &w->glx_blur_cache);
|
2018-12-16 05:11:41 +08:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default: assert(0);
|
|
|
|
}
|
2019-07-25 09:48:12 +08:00
|
|
|
#ifndef CONFIG_OPENGL
|
|
|
|
(void)reg_paint;
|
|
|
|
#endif
|
2018-12-16 05:11:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// paint all windows
|
|
|
|
/// region = ??
|
|
|
|
/// region_real = the damage region
|
2019-04-18 06:14:45 +08:00
|
|
|
void paint_all(session_t *ps, struct managed_win *t, bool ignore_damage) {
|
2019-04-20 07:27:32 +08:00
|
|
|
if (ps->o.xrender_sync_fence || (ps->drivers & DRIVER_NVIDIA)) {
|
2019-02-03 23:59:31 +08:00
|
|
|
if (ps->xsync_exists && !x_fence_sync(ps->c, ps->sync_fence)) {
|
2019-01-01 08:15:51 +08:00
|
|
|
log_error("x_fence_sync failed, xrender-sync-fence will be "
|
|
|
|
"disabled from now on.");
|
2018-12-30 15:41:31 +08:00
|
|
|
xcb_sync_destroy_fence(ps->c, ps->sync_fence);
|
2018-12-31 06:13:30 +08:00
|
|
|
ps->sync_fence = XCB_NONE;
|
2018-12-30 15:41:31 +08:00
|
|
|
ps->o.xrender_sync_fence = false;
|
2019-04-20 07:27:32 +08:00
|
|
|
ps->xsync_exists = false;
|
2018-12-30 15:41:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-09 07:15:00 +08:00
|
|
|
region_t region;
|
|
|
|
pixman_region32_init(®ion);
|
|
|
|
int buffer_age = get_buffer_age(ps);
|
|
|
|
if (buffer_age == -1 || buffer_age > ps->ndamage || ignore_damage) {
|
|
|
|
pixman_region32_copy(®ion, &ps->screen_reg);
|
|
|
|
} else {
|
|
|
|
for (int i = 0; i < get_buffer_age(ps); i++) {
|
2019-03-30 17:07:21 +08:00
|
|
|
auto curr = ((ps->damage - ps->damage_ring) + i) % ps->ndamage;
|
2019-01-09 07:15:00 +08:00
|
|
|
pixman_region32_union(®ion, ®ion, &ps->damage_ring[curr]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!pixman_region32_not_empty(®ion)) {
|
|
|
|
return;
|
2018-12-30 15:41:31 +08:00
|
|
|
}
|
2018-12-16 05:11:41 +08:00
|
|
|
|
|
|
|
#ifdef DEBUG_REPAINT
|
|
|
|
static struct timespec last_paint = {0};
|
|
|
|
#endif
|
|
|
|
|
2019-01-09 07:15:00 +08:00
|
|
|
if (ps->o.resize_damage > 0) {
|
2019-07-06 20:26:25 +08:00
|
|
|
resize_region_in_place(®ion, ps->o.resize_damage, ps->o.resize_damage);
|
2019-01-09 07:15:00 +08:00
|
|
|
}
|
2018-12-16 05:11:41 +08:00
|
|
|
|
2019-01-09 07:15:00 +08:00
|
|
|
// Remove the damaged area out of screen
|
|
|
|
pixman_region32_intersect(®ion, ®ion, &ps->screen_reg);
|
2018-12-16 05:11:41 +08:00
|
|
|
|
|
|
|
if (!paint_isvalid(ps, &ps->tgt_buffer)) {
|
|
|
|
if (!ps->tgt_buffer.pixmap) {
|
|
|
|
free_paint(ps, &ps->tgt_buffer);
|
2019-03-30 17:07:21 +08:00
|
|
|
ps->tgt_buffer.pixmap =
|
|
|
|
x_create_pixmap(ps->c, (uint8_t)ps->depth, ps->root,
|
|
|
|
ps->root_width, ps->root_height);
|
2018-12-16 05:11:41 +08:00
|
|
|
if (ps->tgt_buffer.pixmap == XCB_NONE) {
|
2018-12-21 01:03:27 +08:00
|
|
|
log_fatal("Failed to allocate a screen-sized pixmap for"
|
|
|
|
"painting");
|
2018-12-16 05:11:41 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (BKEND_GLX != ps->o.backend)
|
|
|
|
ps->tgt_buffer.pict = x_create_picture_with_visual_and_pixmap(
|
2019-02-03 23:59:31 +08:00
|
|
|
ps->c, ps->vis, ps->tgt_buffer.pixmap, 0, 0);
|
2018-12-16 05:11:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (BKEND_XRENDER == ps->o.backend) {
|
2019-02-03 23:59:31 +08:00
|
|
|
x_set_picture_clip_region(ps->c, ps->tgt_picture, 0, 0, ®ion);
|
2018-12-16 05:11:41 +08:00
|
|
|
}
|
|
|
|
|
2019-01-09 07:15:00 +08:00
|
|
|
#ifdef CONFIG_OPENGL
|
|
|
|
if (bkend_use_glx(ps)) {
|
|
|
|
ps->psglx->z = 0.0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-12-16 05:11:41 +08:00
|
|
|
region_t reg_tmp, *reg_paint;
|
|
|
|
pixman_region32_init(®_tmp);
|
|
|
|
if (t) {
|
2019-01-09 07:15:00 +08:00
|
|
|
// Calculate the region upon which the root window is to be
|
|
|
|
// painted based on the ignore region of the lowest window, if
|
|
|
|
// available
|
|
|
|
pixman_region32_subtract(®_tmp, ®ion, t->reg_ignore);
|
2018-12-16 05:11:41 +08:00
|
|
|
reg_paint = ®_tmp;
|
|
|
|
} else {
|
2019-01-09 07:15:00 +08:00
|
|
|
reg_paint = ®ion;
|
2018-12-16 05:11:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
set_tgt_clip(ps, reg_paint);
|
|
|
|
paint_root(ps, reg_paint);
|
|
|
|
|
|
|
|
// Windows are sorted from bottom to top
|
2019-01-09 07:15:00 +08:00
|
|
|
// Each window has a reg_ignore, which is the region obscured by all the
|
|
|
|
// windows on top of that window. This is used to reduce the number of
|
|
|
|
// pixels painted.
|
2018-12-16 05:11:41 +08:00
|
|
|
//
|
|
|
|
// Whether this is beneficial is to be determined XXX
|
2019-04-18 06:14:45 +08:00
|
|
|
for (auto w = t; w; w = w->prev_trans) {
|
2018-12-16 05:11:41 +08:00
|
|
|
region_t bshape = win_get_bounding_shape_global_by_val(w);
|
|
|
|
// Painting shadow
|
|
|
|
if (w->shadow) {
|
|
|
|
// Lazy shadow building
|
|
|
|
if (!w->shadow_paint.pixmap)
|
|
|
|
if (!win_build_shadow(ps, w, 1))
|
2018-12-21 01:03:27 +08:00
|
|
|
log_error("build shadow failed");
|
2018-12-16 05:11:41 +08:00
|
|
|
|
2019-01-09 07:15:00 +08:00
|
|
|
// Shadow doesn't need to be painted underneath the body
|
|
|
|
// of the windows above. Because no one can see it
|
|
|
|
pixman_region32_subtract(®_tmp, ®ion, w->reg_ignore);
|
2018-12-16 05:11:41 +08:00
|
|
|
|
|
|
|
// Mask out the region we don't want shadow on
|
|
|
|
if (pixman_region32_not_empty(&ps->shadow_exclude_reg))
|
2019-02-07 08:00:39 +08:00
|
|
|
pixman_region32_subtract(®_tmp, ®_tmp,
|
|
|
|
&ps->shadow_exclude_reg);
|
2019-01-09 07:15:00 +08:00
|
|
|
|
|
|
|
// Might be worth while to crop the region to shadow
|
|
|
|
// border
|
2019-03-30 17:07:21 +08:00
|
|
|
assert(w->shadow_width >= 0 && w->shadow_height >= 0);
|
2019-02-07 08:00:39 +08:00
|
|
|
pixman_region32_intersect_rect(
|
2019-03-30 17:07:21 +08:00
|
|
|
®_tmp, ®_tmp, w->g.x + w->shadow_dx, w->g.y + w->shadow_dy,
|
|
|
|
(uint)w->shadow_width, (uint)w->shadow_height);
|
2019-01-09 07:15:00 +08:00
|
|
|
|
|
|
|
// Mask out the body of the window from the shadow if
|
|
|
|
// needed Doing it here instead of in make_shadow() for
|
|
|
|
// saving GPU power and handling shaped windows (XXX
|
|
|
|
// unconfirmed)
|
2018-12-16 05:11:41 +08:00
|
|
|
if (!ps->o.wintype_option[w->window_type].full_shadow)
|
|
|
|
pixman_region32_subtract(®_tmp, ®_tmp, &bshape);
|
|
|
|
|
|
|
|
if (ps->o.xinerama_shadow_crop && w->xinerama_scr >= 0 &&
|
|
|
|
w->xinerama_scr < ps->xinerama_nscrs)
|
2019-01-09 07:15:00 +08:00
|
|
|
// There can be a window where number of screens
|
|
|
|
// is updated, but the screen number attached to
|
|
|
|
// the windows have not.
|
2018-12-16 05:11:41 +08:00
|
|
|
//
|
2019-01-09 07:15:00 +08:00
|
|
|
// Window screen number will be updated
|
|
|
|
// eventually, so here we just check to make sure
|
|
|
|
// we don't access out of bounds.
|
2018-12-16 05:11:41 +08:00
|
|
|
pixman_region32_intersect(
|
2019-02-07 08:00:39 +08:00
|
|
|
®_tmp, ®_tmp,
|
|
|
|
&ps->xinerama_scr_regs[w->xinerama_scr]);
|
2018-12-16 05:11:41 +08:00
|
|
|
|
|
|
|
// Detect if the region is empty before painting
|
|
|
|
if (pixman_region32_not_empty(®_tmp)) {
|
|
|
|
set_tgt_clip(ps, ®_tmp);
|
|
|
|
win_paint_shadow(ps, w, ®_tmp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-09 07:15:00 +08:00
|
|
|
// Calculate the paint region based on the reg_ignore of the current
|
|
|
|
// window and its bounding region.
|
2019-01-28 17:58:14 +08:00
|
|
|
// Remember, reg_ignore is the union of all windows above the current
|
2019-01-09 07:15:00 +08:00
|
|
|
// window.
|
|
|
|
pixman_region32_subtract(®_tmp, ®ion, w->reg_ignore);
|
2018-12-16 05:11:41 +08:00
|
|
|
pixman_region32_intersect(®_tmp, ®_tmp, &bshape);
|
|
|
|
pixman_region32_fini(&bshape);
|
|
|
|
|
|
|
|
if (pixman_region32_not_empty(®_tmp)) {
|
|
|
|
set_tgt_clip(ps, ®_tmp);
|
|
|
|
// Blur window background
|
|
|
|
if (w->blur_background &&
|
2019-07-13 19:29:39 +08:00
|
|
|
(w->mode == WMODE_TRANS ||
|
|
|
|
(ps->o.blur_background_frame && w->mode == WMODE_FRAME_TRANS) ||
|
|
|
|
ps->o.force_win_blend))
|
2018-12-16 10:50:39 +08:00
|
|
|
win_blur_background(ps, w, ps->tgt_buffer.pict, ®_tmp);
|
2018-12-16 05:11:41 +08:00
|
|
|
|
|
|
|
// Painting the window
|
|
|
|
paint_one(ps, w, ®_tmp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Free up all temporary regions
|
|
|
|
pixman_region32_fini(®_tmp);
|
|
|
|
|
2019-01-09 07:15:00 +08:00
|
|
|
// Move the head of the damage ring
|
|
|
|
ps->damage = ps->damage - 1;
|
|
|
|
if (ps->damage < ps->damage_ring) {
|
|
|
|
ps->damage = ps->damage_ring + ps->ndamage - 1;
|
|
|
|
}
|
|
|
|
pixman_region32_clear(ps->damage);
|
|
|
|
|
2018-12-16 05:11:41 +08:00
|
|
|
// Do this as early as possible
|
|
|
|
set_tgt_clip(ps, &ps->screen_reg);
|
|
|
|
|
|
|
|
if (ps->o.vsync) {
|
|
|
|
// Make sure all previous requests are processed to achieve best
|
|
|
|
// effect
|
|
|
|
x_sync(ps->c);
|
|
|
|
#ifdef CONFIG_OPENGL
|
|
|
|
if (glx_has_context(ps)) {
|
|
|
|
if (ps->o.vsync_use_glfinish)
|
|
|
|
glFinish();
|
|
|
|
else
|
|
|
|
glFlush();
|
|
|
|
glXWaitX();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2019-03-10 22:55:17 +08:00
|
|
|
if (ps->vsync_wait) {
|
|
|
|
ps->vsync_wait(ps);
|
|
|
|
}
|
|
|
|
|
2019-03-30 17:07:21 +08:00
|
|
|
auto rwidth = to_u16_checked(ps->root_width);
|
|
|
|
auto rheight = to_u16_checked(ps->root_height);
|
2018-12-16 05:11:41 +08:00
|
|
|
switch (ps->o.backend) {
|
|
|
|
case BKEND_XRENDER:
|
|
|
|
if (ps->o.monitor_repaint) {
|
2019-02-04 00:41:04 +08:00
|
|
|
// Copy the screen content to a new picture, and highlight the
|
|
|
|
// paint region. This is not very efficient, but since it's for
|
|
|
|
// debug only, we don't really care
|
|
|
|
|
|
|
|
// First we create a new picture, and copy content from the buffer
|
|
|
|
// to it
|
2019-02-09 05:48:39 +08:00
|
|
|
auto pictfmt = x_get_pictform_for_visual(ps->c, ps->vis);
|
2018-12-22 07:44:42 +08:00
|
|
|
xcb_render_picture_t new_pict = x_create_picture_with_pictfmt(
|
2019-03-30 17:07:21 +08:00
|
|
|
ps->c, ps->root, rwidth, rheight, pictfmt, 0, NULL);
|
2018-12-16 05:11:41 +08:00
|
|
|
xcb_render_composite(ps->c, XCB_RENDER_PICT_OP_SRC,
|
2019-03-30 17:07:21 +08:00
|
|
|
ps->tgt_buffer.pict, XCB_NONE, new_pict, 0,
|
|
|
|
0, 0, 0, 0, 0, rwidth, rheight);
|
2018-12-16 05:11:41 +08:00
|
|
|
|
|
|
|
// Next, we set the region of paint and highlight it
|
2019-02-03 23:59:31 +08:00
|
|
|
x_set_picture_clip_region(ps->c, new_pict, 0, 0, ®ion);
|
2019-01-09 07:15:00 +08:00
|
|
|
xcb_render_composite(ps->c, XCB_RENDER_PICT_OP_OVER, ps->white_picture,
|
2019-03-30 17:07:21 +08:00
|
|
|
ps->alpha_picts[MAX_ALPHA / 2], new_pict, 0,
|
|
|
|
0, 0, 0, 0, 0, rwidth, rheight);
|
2018-12-16 05:11:41 +08:00
|
|
|
|
2019-01-09 07:15:00 +08:00
|
|
|
// Finally, clear clip regions of new_pict and the screen, and put
|
|
|
|
// the whole thing on screen
|
2019-02-03 23:59:31 +08:00
|
|
|
x_set_picture_clip_region(ps->c, new_pict, 0, 0, &ps->screen_reg);
|
|
|
|
x_set_picture_clip_region(ps->c, ps->tgt_picture, 0, 0, &ps->screen_reg);
|
2018-12-16 05:11:41 +08:00
|
|
|
xcb_render_composite(ps->c, XCB_RENDER_PICT_OP_SRC, new_pict,
|
2018-12-28 04:45:38 +08:00
|
|
|
XCB_NONE, ps->tgt_picture, 0, 0, 0, 0, 0, 0,
|
2019-03-30 17:07:21 +08:00
|
|
|
rwidth, rheight);
|
2018-12-16 05:11:41 +08:00
|
|
|
xcb_render_free_picture(ps->c, new_pict);
|
|
|
|
} else
|
2019-03-30 17:07:21 +08:00
|
|
|
xcb_render_composite(ps->c, XCB_RENDER_PICT_OP_SRC,
|
|
|
|
ps->tgt_buffer.pict, XCB_NONE, ps->tgt_picture,
|
|
|
|
0, 0, 0, 0, 0, 0, rwidth, rheight);
|
2018-12-16 05:11:41 +08:00
|
|
|
break;
|
|
|
|
#ifdef CONFIG_OPENGL
|
|
|
|
case BKEND_XR_GLX_HYBRID:
|
|
|
|
x_sync(ps->c);
|
|
|
|
if (ps->o.vsync_use_glfinish)
|
|
|
|
glFinish();
|
|
|
|
else
|
|
|
|
glFlush();
|
|
|
|
glXWaitX();
|
|
|
|
assert(ps->tgt_buffer.pixmap);
|
2019-02-18 07:47:46 +08:00
|
|
|
paint_bind_tex(ps, &ps->tgt_buffer, ps->root_width, ps->root_height,
|
|
|
|
false, ps->depth, ps->vis, !ps->o.glx_no_rebind_pixmap);
|
2018-12-16 05:11:41 +08:00
|
|
|
if (ps->o.vsync_use_glfinish)
|
|
|
|
glFinish();
|
|
|
|
else
|
|
|
|
glFlush();
|
|
|
|
glXWaitX();
|
|
|
|
glx_render(ps, ps->tgt_buffer.ptex, 0, 0, 0, 0, ps->root_width,
|
2019-01-09 07:15:00 +08:00
|
|
|
ps->root_height, 0, 1.0, false, false, ®ion, NULL);
|
2018-12-16 05:11:41 +08:00
|
|
|
// falls through
|
|
|
|
case BKEND_GLX: glXSwapBuffers(ps->dpy, get_tgt_window(ps)); break;
|
|
|
|
#endif
|
|
|
|
default: assert(0);
|
|
|
|
}
|
|
|
|
|
2019-02-07 08:41:24 +08:00
|
|
|
x_sync(ps->c);
|
2018-12-16 05:11:41 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_OPENGL
|
|
|
|
if (glx_has_context(ps)) {
|
|
|
|
glFlush();
|
|
|
|
glXWaitX();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef DEBUG_REPAINT
|
|
|
|
struct timespec now = get_time_timespec();
|
|
|
|
struct timespec diff = {0};
|
|
|
|
timespec_subtract(&diff, &now, &last_paint);
|
2018-12-21 01:03:27 +08:00
|
|
|
log_trace("[ %5ld:%09ld ] ", diff.tv_sec, diff.tv_nsec);
|
2018-12-16 05:11:41 +08:00
|
|
|
last_paint = now;
|
2018-12-21 01:03:27 +08:00
|
|
|
log_trace("paint:");
|
2018-12-16 05:11:41 +08:00
|
|
|
for (win *w = t; w; w = w->prev_trans)
|
2018-12-21 01:03:27 +08:00
|
|
|
log_trace(" %#010lx", w->id);
|
2018-12-16 05:11:41 +08:00
|
|
|
#endif
|
|
|
|
|
2019-01-09 07:15:00 +08:00
|
|
|
// Free the paint region
|
|
|
|
pixman_region32_fini(®ion);
|
2018-12-16 05:11:41 +08:00
|
|
|
}
|
|
|
|
|
2018-12-16 08:53:41 +08:00
|
|
|
/**
|
|
|
|
* Query needed X Render / OpenGL filters to check for their existence.
|
|
|
|
*/
|
|
|
|
static bool xr_init_blur(session_t *ps) {
|
|
|
|
// Query filters
|
|
|
|
xcb_render_query_filters_reply_t *pf = xcb_render_query_filters_reply(
|
|
|
|
ps->c, xcb_render_query_filters(ps->c, get_tgt_window(ps)), NULL);
|
|
|
|
if (pf) {
|
2018-12-16 10:50:39 +08:00
|
|
|
xcb_str_iterator_t iter = xcb_render_query_filters_filters_iterator(pf);
|
2018-12-16 08:53:41 +08:00
|
|
|
for (; iter.rem; xcb_str_next(&iter)) {
|
|
|
|
int len = xcb_str_name_length(iter.data);
|
|
|
|
char *name = xcb_str_name(iter.data);
|
|
|
|
// Check for the convolution filter
|
|
|
|
if (strlen(XRFILTER_CONVOLUTION) == len &&
|
2019-01-01 08:15:51 +08:00
|
|
|
!memcmp(XRFILTER_CONVOLUTION, name, strlen(XRFILTER_CONVOLUTION)))
|
2018-12-16 08:53:41 +08:00
|
|
|
ps->xrfilter_convolution_exists = true;
|
|
|
|
}
|
|
|
|
free(pf);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Turn features off if any required filter is not present
|
|
|
|
if (!ps->xrfilter_convolution_exists) {
|
2018-12-21 01:03:27 +08:00
|
|
|
log_error("Xrender convolution filter "
|
|
|
|
"unsupported by your X server. "
|
|
|
|
"Background blur is not possible.");
|
2018-12-16 08:53:41 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Pregenerate alpha pictures.
|
|
|
|
*/
|
|
|
|
static bool init_alpha_picts(session_t *ps) {
|
|
|
|
ps->alpha_picts = ccalloc(MAX_ALPHA + 1, xcb_render_picture_t);
|
|
|
|
|
|
|
|
for (int i = 0; i <= MAX_ALPHA; ++i) {
|
|
|
|
double o = (double)i / MAX_ALPHA;
|
2019-02-27 07:21:11 +08:00
|
|
|
ps->alpha_picts[i] = solid_picture(ps->c, ps->root, false, o, 0, 0, 0);
|
2018-12-16 08:53:41 +08:00
|
|
|
if (ps->alpha_picts[i] == XCB_NONE)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool init_render(session_t *ps) {
|
|
|
|
// Initialize OpenGL as early as possible
|
2019-02-09 07:57:14 +08:00
|
|
|
#ifdef CONFIG_OPENGL
|
|
|
|
glxext_init(ps->dpy, ps->scr);
|
|
|
|
#endif
|
2018-12-16 08:53:41 +08:00
|
|
|
if (bkend_use_glx(ps)) {
|
|
|
|
#ifdef CONFIG_OPENGL
|
|
|
|
if (!glx_init(ps, true))
|
2018-12-21 01:03:27 +08:00
|
|
|
return false;
|
2018-12-16 08:53:41 +08:00
|
|
|
#else
|
2018-12-21 01:03:27 +08:00
|
|
|
log_error("GLX backend support not compiled in.");
|
|
|
|
return false;
|
2018-12-16 08:53:41 +08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize VSync
|
|
|
|
if (!vsync_init(ps)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize window GL shader
|
|
|
|
if (BKEND_GLX == ps->o.backend && ps->o.glx_fshader_win_str) {
|
|
|
|
#ifdef CONFIG_OPENGL
|
2019-07-25 09:27:02 +08:00
|
|
|
if (!glx_load_prog_main(NULL, ps->o.glx_fshader_win_str, &ps->glx_prog_win))
|
2018-12-16 08:53:41 +08:00
|
|
|
return false;
|
|
|
|
#else
|
2018-12-21 01:03:27 +08:00
|
|
|
log_error("GLSL supported not compiled in, can't load "
|
|
|
|
"shader.");
|
2018-12-16 08:53:41 +08:00
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!init_alpha_picts(ps)) {
|
2018-12-21 01:03:27 +08:00
|
|
|
log_error("Failed to init alpha pictures.");
|
2018-12-16 08:53:41 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Blur filter
|
2019-06-09 08:07:29 +08:00
|
|
|
if (ps->o.blur_method && ps->o.blur_method != BLUR_METHOD_KERNEL) {
|
|
|
|
log_warn("Old backends only support blur method \"kernel\". Your blur "
|
|
|
|
"setting will not be applied");
|
|
|
|
ps->o.blur_method = BLUR_METHOD_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ps->o.blur_method == BLUR_METHOD_KERNEL) {
|
2019-06-08 04:53:23 +08:00
|
|
|
ps->blur_kerns_cache =
|
|
|
|
ccalloc(ps->o.blur_kernel_count, struct x_convolution_kernel *);
|
2019-06-06 14:37:48 +08:00
|
|
|
|
2019-02-19 05:08:21 +08:00
|
|
|
bool ret = false;
|
2018-12-16 10:48:02 +08:00
|
|
|
if (ps->o.backend == BKEND_GLX) {
|
|
|
|
#ifdef CONFIG_OPENGL
|
2018-12-16 08:53:41 +08:00
|
|
|
ret = glx_init_blur(ps);
|
2018-12-16 10:48:02 +08:00
|
|
|
#else
|
|
|
|
assert(false);
|
|
|
|
#endif
|
2019-02-19 05:08:21 +08:00
|
|
|
} else {
|
2018-12-16 08:53:41 +08:00
|
|
|
ret = xr_init_blur(ps);
|
2019-02-19 05:08:21 +08:00
|
|
|
}
|
|
|
|
if (!ret) {
|
|
|
|
return ret;
|
|
|
|
}
|
2018-12-16 08:53:41 +08:00
|
|
|
}
|
|
|
|
|
2019-02-27 07:21:11 +08:00
|
|
|
ps->black_picture = solid_picture(ps->c, ps->root, true, 1, 0, 0, 0);
|
|
|
|
ps->white_picture = solid_picture(ps->c, ps->root, true, 1, 1, 1, 1);
|
2018-12-16 08:53:41 +08:00
|
|
|
|
|
|
|
if (ps->black_picture == XCB_NONE || ps->white_picture == XCB_NONE) {
|
2018-12-21 01:03:27 +08:00
|
|
|
log_error("Failed to create solid xrender pictures.");
|
2018-12-16 08:53:41 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generates another Picture for shadows if the color is modified by
|
|
|
|
// user
|
2019-03-30 17:07:21 +08:00
|
|
|
if (ps->o.shadow_red == 0 && ps->o.shadow_green == 0 && ps->o.shadow_blue == 0) {
|
2018-12-16 08:53:41 +08:00
|
|
|
ps->cshadow_picture = ps->black_picture;
|
|
|
|
} else {
|
2019-02-27 07:21:11 +08:00
|
|
|
ps->cshadow_picture = solid_picture(ps->c, ps->root, true, 1, ps->o.shadow_red,
|
|
|
|
ps->o.shadow_green, ps->o.shadow_blue);
|
2018-12-16 08:53:41 +08:00
|
|
|
if (ps->cshadow_picture == XCB_NONE) {
|
2018-12-21 01:03:27 +08:00
|
|
|
log_error("Failed to create shadow picture.");
|
2018-12-16 08:53:41 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-12-16 11:00:56 +08:00
|
|
|
/**
|
|
|
|
* Free root tile related things.
|
|
|
|
*/
|
|
|
|
void free_root_tile(session_t *ps) {
|
|
|
|
free_picture(ps->c, &ps->root_tile_paint.pict);
|
|
|
|
#ifdef CONFIG_OPENGL
|
|
|
|
free_texture(ps, &ps->root_tile_paint.ptex);
|
|
|
|
#else
|
|
|
|
assert(!ps->root_tile_paint.ptex);
|
|
|
|
#endif
|
|
|
|
if (ps->root_tile_fill) {
|
|
|
|
xcb_free_pixmap(ps->c, ps->root_tile_paint.pixmap);
|
|
|
|
ps->root_tile_paint.pixmap = XCB_NONE;
|
|
|
|
}
|
2018-12-28 04:45:38 +08:00
|
|
|
ps->root_tile_paint.pixmap = XCB_NONE;
|
2018-12-16 11:00:56 +08:00
|
|
|
ps->root_tile_fill = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void deinit_render(session_t *ps) {
|
|
|
|
// Free alpha_picts
|
|
|
|
for (int i = 0; i <= MAX_ALPHA; ++i)
|
|
|
|
free_picture(ps->c, &ps->alpha_picts[i]);
|
|
|
|
free(ps->alpha_picts);
|
|
|
|
ps->alpha_picts = NULL;
|
|
|
|
|
|
|
|
// Free cshadow_picture and black_picture
|
|
|
|
if (ps->cshadow_picture == ps->black_picture)
|
|
|
|
ps->cshadow_picture = XCB_NONE;
|
|
|
|
else
|
|
|
|
free_picture(ps->c, &ps->cshadow_picture);
|
|
|
|
|
|
|
|
free_picture(ps->c, &ps->black_picture);
|
|
|
|
free_picture(ps->c, &ps->white_picture);
|
|
|
|
|
|
|
|
// Free other X resources
|
|
|
|
free_root_tile(ps);
|
|
|
|
|
|
|
|
#ifdef CONFIG_OPENGL
|
2019-02-04 02:09:34 +08:00
|
|
|
free(ps->root_tile_paint.fbcfg);
|
2019-06-06 14:27:30 +08:00
|
|
|
if (bkend_use_glx(ps)) {
|
|
|
|
glx_destroy(ps);
|
|
|
|
}
|
2018-12-16 11:00:56 +08:00
|
|
|
#endif
|
2019-06-06 14:37:48 +08:00
|
|
|
|
2019-06-08 04:53:23 +08:00
|
|
|
for (int i = 0; i < ps->o.blur_kernel_count; i++) {
|
2019-06-06 14:37:48 +08:00
|
|
|
free(ps->blur_kerns_cache[i]);
|
|
|
|
}
|
|
|
|
free(ps->blur_kerns_cache);
|
2018-12-16 11:00:56 +08:00
|
|
|
}
|
|
|
|
|
2018-12-16 05:11:41 +08:00
|
|
|
// vim: set ts=8 sw=8 noet :
|