Skip to content

Commit

Permalink
Add new blur_method dual_kawase
Browse files Browse the repository at this point in the history
  • Loading branch information
tryone144 committed Mar 25, 2020
1 parent c4c1bfe commit a31ee33
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/backend/backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ struct kernel_blur_args {
int kernel_count;
};

struct dual_kawase_blur_args {
int size;
int strength;
};

struct backend_operations {
// =========== Initialization ===========

Expand Down
6 changes: 6 additions & 0 deletions src/backend/gl/gl_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,12 @@ void *gl_create_blur_context(backend_t *base, enum blur_method method, void *arg
return ctx;
}

if (method == BLUR_METHOD_DUAL_KAWASE) {
log_warn("Blur method 'dual_kawase' is not yet implemented.");
ctx->method = BLUR_METHOD_NONE;
return ctx;
}

int nkernels;
ctx->method = BLUR_METHOD_KERNEL;
if (method == BLUR_METHOD_KERNEL) {
Expand Down
6 changes: 6 additions & 0 deletions src/backend/xrender/xrender.c
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,12 @@ void *create_blur_context(backend_t *base attr_unused, enum blur_method method,
ret->method = BLUR_METHOD_NONE;
return ret;
}
if (method == BLUR_METHOD_DUAL_KAWASE) {
log_warn("Blur method 'dual_kawase' is not compatible with the 'xrender' "
"backend.");
ret->method = BLUR_METHOD_NONE;
return ret;
}

ret->method = BLUR_METHOD_KERNEL;
struct conv **kernels;
Expand Down
3 changes: 3 additions & 0 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ enum blur_method parse_blur_method(const char *src) {
return BLUR_METHOD_BOX;
} else if (strcmp(src, "gaussian") == 0) {
return BLUR_METHOD_GAUSSIAN;
} else if (strcmp(src, "dual_kawase") == 0) {
return BLUR_METHOD_DUAL_KAWASE;
} else if (strcmp(src, "none") == 0) {
return BLUR_METHOD_NONE;
}
Expand Down Expand Up @@ -542,6 +544,7 @@ char *parse_config(options_t *opt, const char *config_file, bool *shadow_enable,
.blur_method = BLUR_METHOD_NONE,
.blur_radius = 3,
.blur_deviation = 0.84089642,
.blur_strength = 5,
.blur_background_frame = false,
.blur_background_fixed = false,
.blur_background_blacklist = NULL,
Expand Down
3 changes: 3 additions & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ enum blur_method {
BLUR_METHOD_KERNEL,
BLUR_METHOD_BOX,
BLUR_METHOD_GAUSSIAN,
BLUR_METHOD_DUAL_KAWASE,
BLUR_METHOD_INVALID,
};

Expand Down Expand Up @@ -189,6 +190,8 @@ typedef struct options {
int blur_radius;
// Standard deviation for the gaussian blur
double blur_deviation;
// Strength of the dual_kawase blur
int blur_strength;
/// Whether to blur background when the window frame is not opaque.
/// Implies blur_background.
bool blur_background_frame;
Expand Down
3 changes: 3 additions & 0 deletions src/config_libconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,8 @@ char *parse_config_libconfig(options_t *opt, const char *config_file, bool *shad
config_lookup_int(&cfg, "blur-size", &opt->blur_radius);
// --blur-deviation
config_lookup_float(&cfg, "blur-deviation", &opt->blur_deviation);
// --blur-strength
config_lookup_int(&cfg, "blur-strength", &opt->blur_strength);
// --blur-background
if (config_lookup_bool(&cfg, "blur-background", &ival) && ival) {
if (opt->blur_method == BLUR_METHOD_NONE) {
Expand Down Expand Up @@ -635,6 +637,7 @@ char *parse_config_libconfig(options_t *opt, const char *config_file, bool *shad
}

config_setting_lookup_float(blur_cfg, "deviation", &opt->blur_deviation);
config_setting_lookup_int(blur_cfg, "strength", &opt->blur_strength);
}

// Wintype settings
Expand Down
22 changes: 22 additions & 0 deletions src/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ static void usage(const char *argv0, int ret) {
"--blur-deviation\n"
" The standard deviation for the 'gaussian' blur method.\n"
"\n"
"--blur-strength\n"
" The strength level of the 'dual_kawase' blur method.\n"
"\n"
"--blur-background\n"
" Blur background of semi-transparent / ARGB windows. Bad in\n"
" performance. The switch name may change without prior\n"
Expand Down Expand Up @@ -437,6 +440,7 @@ static const struct option longopts[] = {
{"blur-method", required_argument, NULL, 328},
{"blur-size", required_argument, NULL, 329},
{"blur-deviation", required_argument, NULL, 330},
{"blur-strength", required_argument, NULL, 331},
{"experimental-backends", no_argument, NULL, 733},
{"monitor-repaint", no_argument, NULL, 800},
{"diagnostics", no_argument, NULL, 801},
Expand Down Expand Up @@ -841,6 +845,10 @@ bool get_cfg(options_t *opt, int argc, char *const *argv, bool shadow_enable,
// --blur-deviation
opt->blur_deviation = atof(optarg);
break;
case 331:
// --blur-strength
opt->blur_strength = atoi(optarg);
break;

P_CASEBOOL(733, experimental_backends);
P_CASEBOOL(800, monitor_repaint);
Expand Down Expand Up @@ -930,6 +938,20 @@ bool get_cfg(options_t *opt, int argc, char *const *argv, bool shadow_enable,
CHECK(opt->blur_kernel_count);
}

// Sanitize parameters for dual-filter kawase blur
if (opt->blur_method == BLUR_METHOD_DUAL_KAWASE) {
if (opt->blur_strength < 0 && opt->blur_radius > 500) {
log_warn("Blur radius >500 not supported by dual_kawase method, "
"capping to 500.");
opt->blur_radius = 500;
}
if (opt->blur_strength > 20) {
log_warn("Blur strength >20 not supported by dual_kawase method, "
"capping to 20.");
opt->blur_strength = 20;
}
}

if (opt->resize_damage < 0) {
log_warn("Negative --resize-damage will not work correctly.");
}
Expand Down
6 changes: 6 additions & 0 deletions src/picom.c
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,7 @@ static bool initialize_blur(session_t *ps) {
struct kernel_blur_args kargs;
struct gaussian_blur_args gargs;
struct box_blur_args bargs;
struct dual_kawase_blur_args dkargs;

void *args = NULL;
switch (ps->o.blur_method) {
Expand All @@ -721,6 +722,11 @@ static bool initialize_blur(session_t *ps) {
gargs.deviation = ps->o.blur_deviation;
args = (void *)&gargs;
break;
case BLUR_METHOD_DUAL_KAWASE:
dkargs.size = ps->o.blur_radius;
dkargs.strength = ps->o.blur_strength;
args = (void *)&dkargs;
break;
default: return true;
}

Expand Down

0 comments on commit a31ee33

Please sign in to comment.