Merge pull request #201 from yshui/debug-mode

Debug mode
This commit is contained in:
yshui 2019-07-07 16:22:29 +01:00 committed by GitHub
commit 3cd61c9281
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 85 additions and 24 deletions

View File

@ -25,6 +25,7 @@
#include "backend/gl/gl_common.h" #include "backend/gl/gl_common.h"
#include "backend/gl/glx.h" #include "backend/gl/glx.h"
#include "common.h" #include "common.h"
#include "compton.h"
#include "compiler.h" #include "compiler.h"
#include "config.h" #include "config.h"
#include "log.h" #include "log.h"
@ -221,7 +222,7 @@ static backend_t *glx_init(session_t *ps) {
gd->display = ps->dpy; gd->display = ps->dpy;
gd->screen = ps->scr; gd->screen = ps->scr;
gd->target_win = ps->overlay != XCB_NONE ? ps->overlay : ps->root; gd->target_win = session_get_target_window(ps);
XVisualInfo *pvis = NULL; XVisualInfo *pvis = NULL;
@ -310,10 +311,7 @@ static backend_t *glx_init(session_t *ps) {
} }
// Attach GLX context // Attach GLX context
GLXDrawable tgt = ps->overlay; GLXDrawable tgt = gd->target_win;
if (!tgt) {
tgt = ps->root;
}
if (!glXMakeCurrent(ps->dpy, tgt, gd->ctx)) { if (!glXMakeCurrent(ps->dpy, tgt, gd->ctx)) {
log_error("Failed to attach GLX context."); log_error("Failed to attach GLX context.");
goto end; goto end;

View File

@ -14,6 +14,7 @@
#include "backend/backend.h" #include "backend/backend.h"
#include "backend/backend_common.h" #include "backend/backend_common.h"
#include "common.h" #include "common.h"
#include "compton.h"
#include "config.h" #include "config.h"
#include "kernel.h" #include "kernel.h"
#include "log.h" #include "log.h"
@ -532,18 +533,12 @@ backend_t *backend_xrender_init(session_t *ps) {
xd->black_pixel = solid_picture(ps->c, ps->root, true, 1, 0, 0, 0); xd->black_pixel = solid_picture(ps->c, ps->root, true, 1, 0, 0, 0);
xd->white_pixel = solid_picture(ps->c, ps->root, true, 1, 1, 1, 1); xd->white_pixel = solid_picture(ps->c, ps->root, true, 1, 1, 1, 1);
if (ps->overlay != XCB_NONE) { xd->target_win = session_get_target_window(ps);
xd->target = x_create_picture_with_visual_and_pixmap(
ps->c, ps->vis, ps->overlay, 0, NULL);
xd->target_win = ps->overlay;
} else {
xcb_render_create_picture_value_list_t pa = { xcb_render_create_picture_value_list_t pa = {
.subwindowmode = XCB_SUBWINDOW_MODE_INCLUDE_INFERIORS, .subwindowmode = XCB_SUBWINDOW_MODE_INCLUDE_INFERIORS,
}; };
xd->target = x_create_picture_with_visual_and_pixmap( xd->target = x_create_picture_with_visual_and_pixmap(
ps->c, ps->vis, ps->root, XCB_RENDER_CP_SUBWINDOW_MODE, &pa); ps->c, ps->vis, xd->target_win, XCB_RENDER_CP_SUBWINDOW_MODE, &pa);
xd->target_win = ps->root;
}
auto pictfmt = x_get_pictform_for_visual(ps->c, ps->vis); auto pictfmt = x_get_pictform_for_visual(ps->c, ps->vis);
if (!pictfmt) { if (!pictfmt) {

View File

@ -171,6 +171,8 @@ typedef struct session {
// Damage root_damage; // Damage root_damage;
/// X Composite overlay window. Used if <code>--paint-on-overlay</code>. /// X Composite overlay window. Used if <code>--paint-on-overlay</code>.
xcb_window_t overlay; xcb_window_t overlay;
/// The target window for debug mode
xcb_window_t debug_window;
/// Whether the root tile is filled by compton. /// Whether the root tile is filled by compton.
bool root_tile_fill; bool root_tile_fill;
/// Picture of the root window background. /// Picture of the root window background.

View File

@ -513,6 +513,10 @@ static struct managed_win *paint_preprocess(session_t *ps, bool *fade_running) {
to_paint = false; to_paint = false;
} }
if (w->base.id == ps->debug_window || w->client_win == ps->debug_window) {
to_paint = false;
}
if ((w->flags & WIN_FLAGS_IMAGE_ERROR) != 0) { if ((w->flags & WIN_FLAGS_IMAGE_ERROR) != 0) {
to_paint = false; to_paint = false;
} }
@ -902,7 +906,9 @@ static bool register_cm(session_t *ps) {
// Unredirect the window if it's redirected, just in case // Unredirect the window if it's redirected, just in case
if (ps->redirected) if (ps->redirected)
xcb_composite_unredirect_window(ps->c, ps->reg_win, xcb_composite_unredirect_window(ps->c, ps->reg_win,
XCB_COMPOSITE_REDIRECT_MANUAL); ps->o.debug_mode
? XCB_COMPOSITE_REDIRECT_AUTOMATIC
: XCB_COMPOSITE_REDIRECT_MANUAL);
{ {
XClassHint *h = XAllocClassHint(); XClassHint *h = XAllocClassHint();
@ -1094,6 +1100,45 @@ static bool init_overlay(session_t *ps) {
return true; return true;
} }
static bool init_debug_window(session_t *ps) {
xcb_colormap_t colormap = x_new_id(ps->c);
ps->debug_window = x_new_id(ps->c);
auto err = xcb_request_check(
ps->c, xcb_create_colormap_checked(ps->c, XCB_COLORMAP_ALLOC_NONE, colormap,
ps->root, ps->vis));
if (err) {
goto err_out;
}
err = xcb_request_check(
ps->c, xcb_create_window_checked(ps->c, (uint8_t)ps->depth, ps->debug_window,
ps->root, 0, 0, to_u16_checked(ps->root_width),
to_u16_checked(ps->root_height), 0,
XCB_WINDOW_CLASS_INPUT_OUTPUT, ps->vis,
XCB_CW_COLORMAP, (uint32_t[]){colormap, 0}));
if (err) {
goto err_out;
}
err = xcb_request_check(ps->c, xcb_map_window(ps->c, ps->debug_window));
if (err) {
goto err_out;
}
return true;
err_out:
free(err);
return false;
}
xcb_window_t session_get_target_window(session_t *ps) {
if (ps->o.debug_mode) {
return ps->debug_window;
}
return ps->overlay != XCB_NONE ? ps->overlay : ps->root;
}
/** /**
* Redirect all windows. * Redirect all windows.
* *
@ -1109,7 +1154,9 @@ static bool redir_start(session_t *ps) {
xcb_map_window(ps->c, ps->overlay); xcb_map_window(ps->c, ps->overlay);
} }
xcb_composite_redirect_subwindows(ps->c, ps->root, XCB_COMPOSITE_REDIRECT_MANUAL); xcb_composite_redirect_subwindows(ps->c, ps->root,
ps->o.debug_mode ? XCB_COMPOSITE_REDIRECT_AUTOMATIC
: XCB_COMPOSITE_REDIRECT_MANUAL);
x_sync(ps->c); x_sync(ps->c);
@ -1155,7 +1202,9 @@ static void redir_stop(session_t *ps) {
destroy_backend(ps); destroy_backend(ps);
xcb_composite_unredirect_subwindows(ps->c, ps->root, XCB_COMPOSITE_REDIRECT_MANUAL); xcb_composite_unredirect_subwindows(ps->c, ps->root,
ps->o.debug_mode ? XCB_COMPOSITE_REDIRECT_AUTOMATIC
: XCB_COMPOSITE_REDIRECT_MANUAL);
// Unmap overlay window // Unmap overlay window
if (ps->overlay) if (ps->overlay)
xcb_unmap_window(ps->c, ps->overlay); xcb_unmap_window(ps->c, ps->overlay);
@ -1791,9 +1840,15 @@ static session_t *session_init(int argc, char **argv, Display *dpy,
// Overlay must be initialized before double buffer, and before creation // Overlay must be initialized before double buffer, and before creation
// of OpenGL context. // of OpenGL context.
if (!ps->o.debug_mode) {
if (!init_overlay(ps)) { if (!init_overlay(ps)) {
goto err; goto err;
} }
} else {
if (!init_debug_window(ps)) {
goto err;
}
}
ps->drivers = detect_driver(ps->c, ps->backend_data, ps->root); ps->drivers = detect_driver(ps->c, ps->backend_data, ps->root);

View File

@ -59,6 +59,8 @@ void discard_ignore(session_t *ps, unsigned long sequence);
void set_root_flags(session_t *ps, uint64_t flags); void set_root_flags(session_t *ps, uint64_t flags);
xcb_window_t session_get_target_window(session_t *);
/** /**
* Set a <code>switch_t</code> array of all unset wintypes to true. * Set a <code>switch_t</code> array of all unset wintypes to true.
*/ */

View File

@ -62,6 +62,8 @@ typedef struct options {
// === Debugging === // === Debugging ===
bool monitor_repaint; bool monitor_repaint;
bool print_diagnostics; bool print_diagnostics;
/// Render to a separate window instead of taking over the screen
bool debug_mode;
// === General === // === General ===
/// Use the experimental new backends? /// Use the experimental new backends?
bool experimental_backends; bool experimental_backends;

View File

@ -308,9 +308,14 @@ static void usage(int ret) {
"--benchmark-wid window-id\n" "--benchmark-wid window-id\n"
" Specify window ID to repaint in benchmark mode. If omitted or is 0,\n" " Specify window ID to repaint in benchmark mode. If omitted or is 0,\n"
" the whole screen is repainted.\n" " the whole screen is repainted.\n"
"\n"
"--monitor-repaint\n" "--monitor-repaint\n"
" Highlight the updated area of the screen. For debugging the xrender\n" " Highlight the updated area of the screen. For debugging the xrender\n"
" backend only.\n"; " backend only.\n"
"\n"
"--debug-mode\n"
" Render into a separate window, and don't take over the screen. Useful\n"
" when you want to attach a debugger to compton\n";
FILE *f = (ret ? stderr : stdout); FILE *f = (ret ? stderr : stdout);
fputs(usage_text, f); fputs(usage_text, f);
#undef WARNING_DISABLED #undef WARNING_DISABLED
@ -406,6 +411,7 @@ static const struct option longopts[] = {
{"experimental-backends", no_argument, NULL, 733}, {"experimental-backends", no_argument, NULL, 733},
{"monitor-repaint", no_argument, NULL, 800}, {"monitor-repaint", no_argument, NULL, 800},
{"diagnostics", no_argument, NULL, 801}, {"diagnostics", no_argument, NULL, 801},
{"debug-mode", no_argument, NULL, 802},
// Must terminate with a NULL entry // Must terminate with a NULL entry
{NULL, 0, NULL, 0}, {NULL, 0, NULL, 0},
}; };
@ -777,6 +783,7 @@ void get_cfg(options_t *opt, int argc, char *const *argv, bool shadow_enable,
P_CASEBOOL(733, experimental_backends); P_CASEBOOL(733, experimental_backends);
P_CASEBOOL(800, monitor_repaint); P_CASEBOOL(800, monitor_repaint);
case 801: opt->print_diagnostics = true; break; case 801: opt->print_diagnostics = true; break;
P_CASEBOOL(802, debug_mode);
default: usage(1); break; default: usage(1); break;
#undef P_CASEBOOL #undef P_CASEBOOL
} }