Skip to content

Commit

Permalink
Formally deprecated the sw-opti option
Browse files Browse the repository at this point in the history
It was deprecated in v6, but wasn't formally deprecated back then (e.g.
no warnings were printed for it). So formally deprecate it here.

This also left the refresh-rate option unused, so that will be
deprecated too.

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
  • Loading branch information
yshui committed Jan 24, 2022
1 parent 43f3560 commit 51da5d3
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 132 deletions.
3 changes: 0 additions & 3 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,6 @@ typedef struct session {
ev_timer unredir_timer;
/// Timer for fading
ev_timer fade_timer;
/// Timer for delayed drawing, right now only used by
/// swopti
ev_timer delayed_draw_timer;
/// Use an ev_idle callback for drawing
/// So we only start drawing when events are processed
ev_idle draw_idle;
Expand Down
1 change: 0 additions & 1 deletion src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,6 @@ char *parse_config(options_t *opt, const char *config_file, bool *shadow_enable,
.logpath = NULL,

.refresh_rate = 0,
.sw_opti = false,
.use_damage = true,

.shadow_red = 0.0,
Expand Down
2 changes: 0 additions & 2 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,6 @@ typedef struct options {
// === VSync & software optimization ===
/// User-specified refresh rate.
int refresh_rate;
/// Whether to enable refresh-rate-based software optimization.
bool sw_opti;
/// VSync method to use;
bool vsync;
/// Whether to use glFinish() instead of glFlush() for (possibly) better
Expand Down
5 changes: 4 additions & 1 deletion src/config_libconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,10 @@ char *parse_config_libconfig(options_t *opt, const char *config_file, bool *shad
opt->logpath = strdup(sval);
}
// --sw-opti
lcfg_lookup_bool(&cfg, "sw-opti", &opt->sw_opti);
if (lcfg_lookup_bool(&cfg, "sw-opti", &bval)) {
log_warn("The sw-opti option has been deprecated, please remove it from "
"your configuration file");
}
// --use-ewmh-active-win
lcfg_lookup_bool(&cfg, "use-ewmh-active-win", &opt->use_ewmh_active_win);
// --unredir-if-possible
Expand Down
2 changes: 1 addition & 1 deletion src/dbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,7 @@ static bool cdbus_process_opts_get(session_t *ps, DBusMessage *msg) {
cdbus_m_opts_get_do(logpath, cdbus_reply_string);

cdbus_m_opts_get_do(refresh_rate, cdbus_reply_int32);
cdbus_m_opts_get_do(sw_opti, cdbus_reply_bool);
cdbus_m_opts_get_stub(sw_opti, cdbus_reply_bool, false);
cdbus_m_opts_get_do(vsync, cdbus_reply_bool);
if (!strcmp("backend", target)) {
assert(ps->o.backend < sizeof(BACKEND_STRS) / sizeof(BACKEND_STRS[0]));
Expand Down
5 changes: 4 additions & 1 deletion src/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,10 @@ bool get_cfg(options_t *opt, int argc, char *const *argv, bool shadow_enable,
log_error("--paint-on-overlay has been removed, the feature is enabled "
"whenever possible");
failed = true; break;
P_CASEBOOL(274, sw_opti);
case 274:
log_warn("--sw-opti has been deprecated, please remove it from the "
"command line options");
break;
case 275:
// --vsync-aggressive
log_warn("--vsync-aggressive has been deprecated, please remove it"
Expand Down
129 changes: 6 additions & 123 deletions src/picom.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@
(session_t *)((char *)__mptr - offsetof(session_t, member)); \
})

static const long SWOPTI_TOLERANCE = 3000;

static bool must_use redirect_start(session_t *ps);

static void unredirect(session_t *ps);
Expand Down Expand Up @@ -611,14 +609,6 @@ static void handle_root_flags(session_t *ps) {
if (ps->o.xinerama_shadow_crop) {
cxinerama_upd_scrs(ps);
}

if (ps->o.sw_opti && !ps->o.refresh_rate) {
update_refresh_rate(ps);
if (!ps->refresh_rate) {
log_warn("Refresh rate detection failed. swopti will be "
"temporarily disabled");
}
}
ps->root_flags &= ~(uint64_t)ROOT_FLAGS_SCREEN_CHANGE;
}

Expand Down Expand Up @@ -1112,59 +1102,6 @@ void update_refresh_rate(session_t *ps) {
ps->refresh_intv = 0;
}

/**
* Initialize refresh-rated based software optimization.
*
* @return true for success, false otherwise
*/
static bool swopti_init(session_t *ps) {
log_warn("--sw-opti is going to be deprecated. If you get real benefits from "
"using "
"this option, please open an issue to let us know.");
// Prepare refresh rate
// Check if user provides one
ps->refresh_rate = ps->o.refresh_rate;
if (ps->refresh_rate)
ps->refresh_intv = US_PER_SEC / ps->refresh_rate;

// Auto-detect refresh rate otherwise
if (!ps->refresh_rate && ps->randr_exists) {
update_refresh_rate(ps);
}

// Turn off vsync_sw if we can't get the refresh rate
if (!ps->refresh_rate)
return false;

return true;
}

/**
* Modify a struct timeval timeout value to render at a fixed pace.
*
* @param ps current session
* @param[in,out] ptv pointer to the timeout
*/
static double swopti_handle_timeout(session_t *ps) {
if (!ps->refresh_intv)
return 0;

// Get the microsecond offset of the time when the we reach the timeout
// I don't think a 32-bit long could overflow here.
long offset = (get_time_timeval().tv_usec - ps->paint_tm_offset) % ps->refresh_intv;
// XXX this formula dones't work if refresh rate is not a whole number
if (offset < 0)
offset += ps->refresh_intv;

// If the target time is sufficiently close to a refresh time, don't add
// an offset, to avoid certain blocking conditions.
if (offset < SWOPTI_TOLERANCE || offset > ps->refresh_intv - SWOPTI_TOLERANCE)
return 0;

// Add an offset so we wait until the next refresh after timeout
return (double)(ps->refresh_intv - offset) / 1e6;
}

/**
* Initialize X composite overlay window.
*/
Expand Down Expand Up @@ -1563,7 +1500,6 @@ static void draw_callback_impl(EV_P_ session_t *ps, int revents attr_unused) {
}

static void draw_callback(EV_P_ ev_idle *w, int revents) {
// This function is not used if we are using --swopti
session_t *ps = session_ptr(w, draw_idle);

draw_callback_impl(EV_A_ ps, revents);
Expand All @@ -1574,46 +1510,6 @@ static void draw_callback(EV_P_ ev_idle *w, int revents) {
}
}

static void delayed_draw_timer_callback(EV_P_ ev_timer *w, int revents) {
session_t *ps = session_ptr(w, delayed_draw_timer);
draw_callback_impl(EV_A_ ps, revents);

// We might have stopped the ev_idle in delayed_draw_callback,
// so we restart it if we are in benchmark mode
if (ps->o.benchmark)
ev_idle_start(EV_A_ & ps->draw_idle);
}

static void delayed_draw_callback(EV_P_ ev_idle *w, int revents) {
// This function is only used if we are using --swopti
session_t *ps = session_ptr(w, draw_idle);
assert(ps->redraw_needed);
assert(!ev_is_active(&ps->delayed_draw_timer));

double delay = swopti_handle_timeout(ps);
if (delay < 1e-6) {
if (!ps->o.benchmark) {
ev_idle_stop(EV_A_ & ps->draw_idle);
}
return draw_callback_impl(EV_A_ ps, revents);
}

// This is a little bit hacky. When we get to this point in code, we need
// to update the screen , but we will only be updating after a delay, So
// we want to stop the ev_idle, so this callback doesn't get call repeatedly
// during the delay, we also want queue_redraw to not restart the ev_idle.
// So we stop ev_idle and leave ps->redraw_needed to be true. (effectively,
// ps->redraw_needed means if redraw is needed or if draw is in progress).
//
// We do this anyway even if we are in benchmark mode. That means we will
// have to restart draw_idle after the draw actually happened when we are in
// benchmark mode.
ev_idle_stop(EV_A_ & ps->draw_idle);

ev_timer_set(&ps->delayed_draw_timer, delay, 0);
ev_timer_start(EV_A_ & ps->delayed_draw_timer);
}

static void x_event_callback(EV_P attr_unused, ev_io *w, int revents attr_unused) {
session_t *ps = (session_t *)w;
xcb_generic_event_t *ev = xcb_poll_for_event(ps->c);
Expand Down Expand Up @@ -1698,7 +1594,6 @@ static session_t *session_init(int argc, char **argv, Display *dpy,

.refresh_rate = 0,
.refresh_intv = 0UL,
.paint_tm_offset = 0L,

#ifdef CONFIG_VSYNC_DRM
.drm_fd = -1,
Expand Down Expand Up @@ -2003,11 +1898,10 @@ static session_t *session_init(int argc, char **argv, Display *dpy,
}

// Query X RandR
if ((ps->o.sw_opti && !ps->o.refresh_rate) || ps->o.xinerama_shadow_crop) {
if (ps->o.xinerama_shadow_crop) {
if (!ps->randr_exists) {
log_fatal("No XRandR extension. sw-opti, refresh-rate or "
"xinerama-shadow-crop "
"cannot be enabled.");
log_fatal("No XRandR extension. xinerama-shadow-crop cannot be "
"enabled.");
goto err;
}
}
Expand Down Expand Up @@ -2109,15 +2003,11 @@ static session_t *session_init(int argc, char **argv, Display *dpy,
}
}

// Initialize software optimization
if (ps->o.sw_opti)
ps->o.sw_opti = swopti_init(ps);

// Monitor screen changes if vsync_sw is enabled and we are using
// an auto-detected refresh rate, or when Xinerama features are enabled
if (ps->randr_exists &&
((ps->o.sw_opti && !ps->o.refresh_rate) || ps->o.xinerama_shadow_crop))
if (ps->randr_exists && ps->o.xinerama_shadow_crop) {
xcb_randr_select_input(ps->c, ps->root, XCB_RANDR_NOTIFY_MASK_SCREEN_CHANGE);
}

cxinerama_upd_scrs(ps);

Expand All @@ -2138,13 +2028,9 @@ static session_t *session_init(int argc, char **argv, Display *dpy,
ev_io_init(&ps->xiow, x_event_callback, ConnectionNumber(ps->dpy), EV_READ);
ev_io_start(ps->loop, &ps->xiow);
ev_init(&ps->unredir_timer, tmout_unredir_callback);
if (ps->o.sw_opti)
ev_idle_init(&ps->draw_idle, delayed_draw_callback);
else
ev_idle_init(&ps->draw_idle, draw_callback);
ev_idle_init(&ps->draw_idle, draw_callback);

ev_init(&ps->fade_timer, fade_timer_callback);
ev_init(&ps->delayed_draw_timer, delayed_draw_timer_callback);

// Set up SIGUSR1 signal handler to reset program
ev_signal_init(&ps->usr1_signal, reset_enable, SIGUSR1);
Expand Down Expand Up @@ -2432,9 +2318,6 @@ static void session_destroy(session_t *ps) {
* @param ps current session
*/
static void session_run(session_t *ps) {
if (ps->o.sw_opti)
ps->paint_tm_offset = get_time_timeval().tv_usec;

// In benchmark mode, we want draw_idle handler to always be active
if (ps->o.benchmark) {
ev_idle_start(ps->loop, &ps->draw_idle);
Expand Down

0 comments on commit 51da5d3

Please sign in to comment.