summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Grenville <[email protected]>2013-04-26 14:01:20 +0800
committerRichard Grenville <[email protected]>2013-04-26 14:01:20 +0800
commitb5116f646543d1bcc72f3fd1e9c54be10d9ea8a7 (patch)
treeb715f6150abeb2bc302ab44a5b2c1512decd9a8c
parentec2cd6276d6b137b946a48f4dffaaecd793bff0f (diff)
downloadtdebase-b5116f646543d1bcc72f3fd1e9c54be10d9ea8a7.tar.gz
tdebase-b5116f646543d1bcc72f3fd1e9c54be10d9ea8a7.zip
Improvement: Enhance --glx-swap-method
- Enhance --glx-swap-method to support longer buffers ages (3-6), and automatic buffer age detection via GLX_EXT_buffer_age.
-rw-r--r--common.h73
-rw-r--r--compton.c25
-rw-r--r--dbus.c6
-rw-r--r--opengl.c72
4 files changed, 122 insertions, 54 deletions
diff --git a/common.h b/common.h
index 6e8c4cf5f..04eae104b 100644
--- a/common.h
+++ b/common.h
@@ -64,6 +64,7 @@
#include <sys/poll.h>
#include <assert.h>
#include <time.h>
+#include <ctype.h>
#include <sys/time.h>
#include <X11/Xlib.h>
@@ -107,6 +108,10 @@
#define GL_TEXTURE_RECTANGLE 0x84F5
#endif
+#ifndef GLX_BACK_BUFFER_AGE_EXT
+#define GLX_BACK_BUFFER_AGE_EXT 0x20F4
+#endif
+
#endif
// === Macros ===
@@ -175,6 +180,9 @@
/// @brief Maximum OpenGL FBConfig depth.
#define OPENGL_MAX_DEPTH 32
+/// @brief Maximum OpenGL buffer age.
+#define CGLX_MAX_BUFFER_AGE 5
+
// Window flags
// Window size is changed
@@ -285,11 +293,11 @@ enum backend {
};
/// @brief Possible swap methods.
-enum glx_swap_method {
- SWAPM_UNDEFINED,
- SWAPM_EXCHANGE,
- SWAPM_COPY,
- NUM_SWAPM,
+enum {
+ SWAPM_BUFFER_AGE = -1,
+ SWAPM_UNDEFINED = 0,
+ SWAPM_COPY = 1,
+ SWAPM_EXCHANGE = 2,
};
typedef struct _glx_texture glx_texture_t;
@@ -383,7 +391,7 @@ typedef struct {
/// Whether to avoid rebinding pixmap on window damage.
bool glx_no_rebind_pixmap;
/// GLX swap method we assume OpenGL uses.
- enum glx_swap_method glx_swap_method;
+ int glx_swap_method;
/// Whether to try to detect WM windows and mark them as focused.
bool mark_wmwin_focused;
/// Whether to mark override-redirect windows as focused.
@@ -576,7 +584,7 @@ typedef struct {
/// The region needs to painted on next paint.
XserverRegion all_damage;
/// The region damaged on the last paint.
- XserverRegion all_damage_last;
+ XserverRegion all_damage_last[CGLX_MAX_BUFFER_AGE];
/// Whether all windows are currently redirected.
bool redirected;
/// Whether there's a highest full-screen window, and all windows could
@@ -958,7 +966,6 @@ typedef enum {
extern const char * const WINTYPES[NUM_WINTYPES];
extern const char * const VSYNC_STRS[NUM_VSYNC + 1];
extern const char * const BACKEND_STRS[NUM_BKEND + 1];
-extern const char * const GLX_SWAP_METHODS_STRS[NUM_SWAPM + 1];
extern session_t *ps_g;
// == Debugging code ==
@@ -1357,13 +1364,51 @@ parse_backend(session_t *ps, const char *str) {
*/
static inline bool
parse_glx_swap_method(session_t *ps, const char *str) {
- for (enum glx_swap_method i = 0; GLX_SWAP_METHODS_STRS[i]; ++i)
- if (!strcasecmp(str, GLX_SWAP_METHODS_STRS[i])) {
- ps->o.glx_swap_method = i;
- return true;
+ // Parse alias
+ if (!strcmp("undefined", str)) {
+ ps->o.glx_swap_method = 0;
+ return true;
+ }
+
+ if (!strcmp("copy", str)) {
+ ps->o.glx_swap_method = 1;
+ return true;
+ }
+
+ if (!strcmp("exchange", str)) {
+ ps->o.glx_swap_method = 2;
+ return true;
+ }
+
+ if (!strcmp("buffer-age", str)) {
+ ps->o.glx_swap_method = -1;
+ return true;
+ }
+
+ // Parse number
+ {
+ char *pc = NULL;
+ int age = strtol(str, &pc, 0);
+ if (!pc || str == pc) {
+ printf_errf("(\"%s\"): Invalid number.", str);
+ return false;
}
- printf_errf("(\"%s\"): Invalid GLX swap method argument.", str);
- return false;
+
+ for (; *pc; ++pc)
+ if (!isspace(*pc)) {
+ printf_errf("(\"%s\"): Trailing characters.", str);
+ return false;
+ }
+
+ if (age > CGLX_MAX_BUFFER_AGE + 1 || age < -1) {
+ printf_errf("(\"%s\"): Number too large / too small.", str);
+ return false;
+ }
+
+ ps->o.glx_swap_method = age;
+ }
+
+ return true;
}
timeout_t *
diff --git a/compton.c b/compton.c
index 61cd5bcc1..05e115c83 100644
--- a/compton.c
+++ b/compton.c
@@ -50,14 +50,6 @@ const char * const BACKEND_STRS[NUM_BKEND + 1] = {
NULL
};
-/// Names of GLX swap methods.
-const char * const GLX_SWAP_METHODS_STRS[NUM_SWAPM + 1] = {
- "undefined", // SWAPM_UNDEFINED
- "exchange", // SWAPM_EXCHANGE
- "copy", // SWAPM_COPY
- NULL
-};
-
/// Function pointers to init VSync modes.
static bool (* const (VSYNC_FUNCS_INIT[NUM_VSYNC]))(session_t *ps) = {
[VSYNC_DRM ] = vsync_drm_init,
@@ -4266,12 +4258,14 @@ usage(void) {
" GLX backend: Avoid rebinding pixmap on window damage. Probably\n"
" could improve performance on rapid window content changes, but is\n"
" known to break things on some drivers.\n"
- "--glx-swap-method undefined/exchange/copy\n"
+ "--glx-swap-method undefined/copy/exchange/3/4/5/6/buffer-age\n"
" GLX backend: GLX buffer swap method we assume. Could be\n"
- " \"undefined\", \"exchange\", or \"copy\". \"undefined\" is the slowest\n"
- " and the safest; \"exchange\" and \"copy\" are faster but may fail on\n"
- " some drivers. Useless with --glx-use-copysubbuffermesa. Defaults to\n"
- " \"undefined\".\n"
+ " undefined (0), copy (1), exchange (2), 3-6, or buffer-age (-1).\n"
+ " \"undefined\" is the slowest and the safest, and the default value.\n"
+ " 1 is fastest, but may fail on some drivers, 2-6 are gradually slower\n"
+ " but safer (6 is still faster than 0). -1 means auto-detect using\n"
+ " GLX_EXT_buffer_age, supported by some drivers. Useless with\n"
+ " --glx-use-copysubbuffermesa.\n"
#undef WARNING
#ifndef CONFIG_DBUS
#define WARNING WARNING_DISABLED
@@ -6027,7 +6021,7 @@ session_init(session_t *ps_old, int argc, char **argv) {
.tmout_lst = NULL,
.all_damage = None,
- .all_damage_last = None,
+ .all_damage_last = { None },
.time_start = { 0, 0 },
.redirected = false,
.unredir_possible = false,
@@ -6478,7 +6472,8 @@ session_destroy(session_t *ps) {
free_root_tile(ps);
free_region(ps, &ps->screen_reg);
free_region(ps, &ps->all_damage);
- free_region(ps, &ps->all_damage_last);
+ for (int i = 0; i < CGLX_MAX_BUFFER_AGE; ++i)
+ free_region(ps, &ps->all_damage_last[i]);
free(ps->expose_rects);
free(ps->shadow_corner);
free(ps->shadow_top);
diff --git a/dbus.c b/dbus.c
index bef51a73d..a80c012dc 100644
--- a/dbus.c
+++ b/dbus.c
@@ -914,11 +914,7 @@ cdbus_process_opts_get(session_t *ps, DBusMessage *msg) {
cdbus_m_opts_get_do(glx_copy_from_front, cdbus_reply_bool);
cdbus_m_opts_get_do(glx_use_copysubbuffermesa, cdbus_reply_bool);
cdbus_m_opts_get_do(glx_no_rebind_pixmap, cdbus_reply_bool);
- if (!strcmp("glx_swap_method", target)) {
- assert(ps->o.glx_swap_method < sizeof(GLX_SWAP_METHODS_STRS) / sizeof(GLX_SWAP_METHODS_STRS[0]));
- cdbus_reply_string(ps, msg, GLX_SWAP_METHODS_STRS[ps->o.glx_swap_method]);
- return true;
- }
+ cdbus_m_opts_get_do(glx_swap_method, cdbus_reply_int32);
#endif
cdbus_m_opts_get_do(track_focus, cdbus_reply_bool);
diff --git a/opengl.c b/opengl.c
index 50f64f529..8fb4e153e 100644
--- a/opengl.c
+++ b/opengl.c
@@ -54,18 +54,20 @@ glx_init(session_t *ps, bool need_render) {
if (need_render && !glx_hasglxext(ps, "GLX_EXT_texture_from_pixmap"))
goto glx_init_end;
- // Get GLX context
- ps->glx_context = glXCreateContext(ps->dpy, pvis, None, GL_TRUE);
-
if (!ps->glx_context) {
- printf_errf("(): Failed to get GLX context.");
- goto glx_init_end;
- }
+ // Get GLX context
+ ps->glx_context = glXCreateContext(ps->dpy, pvis, None, GL_TRUE);
- // Attach GLX context
- if (!glXMakeCurrent(ps->dpy, get_tgt_window(ps), ps->glx_context)) {
- printf_errf("(): Failed to attach GLX context.");
- goto glx_init_end;
+ if (!ps->glx_context) {
+ printf_errf("(): Failed to get GLX context.");
+ goto glx_init_end;
+ }
+
+ // Attach GLX context
+ if (!glXMakeCurrent(ps->dpy, get_tgt_window(ps), ps->glx_context)) {
+ printf_errf("(): Failed to attach GLX context.");
+ goto glx_init_end;
+ }
}
// Ensure we have a stencil buffer. X Fixes does not guarantee rectangles
@@ -111,6 +113,7 @@ glx_init(session_t *ps, bool need_render) {
if (need_render && !glx_update_fbconfig(ps))
goto glx_init_end;
+ // Render preparations
if (need_render) {
glx_on_root_change(ps);
@@ -588,20 +591,44 @@ glx_paint_pre(session_t *ps, XserverRegion *preg) {
ps->glx_z = 0.0;
// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- // Exchange swap is interested in the raw damaged region only
- XserverRegion all_damage_last = ps->all_damage_last;
- ps->all_damage_last = None;
- if (SWAPM_EXCHANGE == ps->o.glx_swap_method && *preg)
- ps->all_damage_last = copy_region(ps, *preg);
+ // Get buffer age
+ int buffer_age = ps->o.glx_swap_method;
+ bool trace_damage = (ps->o.glx_swap_method < 0 || ps->o.glx_swap_method > 1);
+
+ // Query GLX_EXT_buffer_age for buffer age
+ if (SWAPM_BUFFER_AGE == buffer_age) {
+ unsigned val = 0;
+ glXQueryDrawable(ps->dpy, get_tgt_window(ps),
+ GLX_BACK_BUFFER_AGE_EXT, &val);
+ buffer_age = val;
+ }
+
+ // Buffer age too high
+ if (buffer_age > CGLX_MAX_BUFFER_AGE + 1)
+ buffer_age = 0;
+
+ // Make sure buffer age >= 0
+ buffer_age = max_i(buffer_age, 0);
+
+ // Trace raw damage regions
+ XserverRegion newdamage = None;
+ if (trace_damage && *preg)
+ newdamage = copy_region(ps, *preg);
// OpenGL doesn't support partial repaint without GLX_MESA_copy_sub_buffer,
// we could redraw the whole screen or copy unmodified pixels from
// front buffer with --glx-copy-from-front.
- if (ps->o.glx_use_copysubbuffermesa || SWAPM_COPY == ps->o.glx_swap_method
- || !*preg) {
+ if (ps->o.glx_use_copysubbuffermesa || 1 == buffer_age || !*preg) {
}
- else if (SWAPM_EXCHANGE == ps->o.glx_swap_method && all_damage_last) {
- XFixesUnionRegion(ps->dpy, *preg, *preg, all_damage_last);
+ else if (buffer_age > 1) {
+ for (int i = 0; i < buffer_age - 1; ++i) {
+ XserverRegion dmg = ps->all_damage_last[i];
+ if (!dmg) {
+ free_region(ps, preg);
+ break;
+ }
+ XFixesUnionRegion(ps->dpy, *preg, *preg, dmg);
+ }
}
else if (!ps->o.glx_copy_from_front) {
free_region(ps, preg);
@@ -625,7 +652,12 @@ glx_paint_pre(session_t *ps, XserverRegion *preg) {
}
}
- free_region(ps, &all_damage_last);
+ if (trace_damage) {
+ free_region(ps, &ps->all_damage_last[CGLX_MAX_BUFFER_AGE - 1]);
+ memmove(ps->all_damage_last + 1, ps->all_damage_last,
+ (CGLX_MAX_BUFFER_AGE - 1) * sizeof(XserverRegion));
+ ps->all_damage_last[0] = newdamage;
+ }
glx_set_clip(ps, *preg, NULL);