diff --git a/src/backend/backend.h b/src/backend/backend.h index e0a51ca3..191e8146 100644 --- a/src/backend/backend.h +++ b/src/backend/backend.h @@ -215,12 +215,18 @@ struct backend_operations { void *(*bind_pixmap)(backend_t *backend_data, xcb_pixmap_t pixmap, struct xvisual_info fmt, bool owned); + /// Create a shadow context for rendering shadows with radius `radius`. + /// Default implementation: default_backend_create_shadow_context struct backend_shadow_context *(*create_shadow_context)(backend_t *backend_data, double radius); + /// Destroy a shadow context + /// Default implementation: default_backend_destroy_shadow_context void (*destroy_shadow_context)(backend_t *backend_data, struct backend_shadow_context *ctx); - /// Create a shadow image based on the parameters + /// Create a shadow image based on the parameters. Resulting image should have a + /// size of `width + radisu * 2` x `height + radius * 2`. Radius is set when the + /// shadow context is created. /// Default implementation: default_backend_render_shadow /// /// Required. @@ -228,7 +234,8 @@ struct backend_operations { struct backend_shadow_context *ctx, struct color color); /// Create a shadow by blurring a mask. `size` is the size of the blur. The - /// backend can use whichever blur method is the fastest. + /// backend can use whichever blur method is the fastest. The shadow produced + /// shoule be consistent with `render_shadow`. /// /// Optional. void *(*shadow_from_mask)(backend_t *backend_data, void *mask, diff --git a/src/backend/backend_common.c b/src/backend/backend_common.c index eba5cb47..d6fcce21 100644 --- a/src/backend/backend_common.c +++ b/src/backend/backend_common.c @@ -311,6 +311,21 @@ void *default_backend_render_shadow(backend_t *backend_data, int width, int heig return ret; } +/// Implement render_shadow with shadow_from_mask +void * +backend_render_shadow_from_mask(backend_t *backend_data, int width, int height, + struct backend_shadow_context *sctx, struct color color) { + region_t reg; + pixman_region32_init_rect(®, 0, 0, (unsigned int)width, (unsigned int)height); + void *mask = backend_data->ops->make_mask( + backend_data, (geometry_t){.width = width, .height = height}, ®); + pixman_region32_fini(®); + + void *shadow = backend_data->ops->shadow_from_mask(backend_data, mask, sctx, color); + backend_data->ops->release_image(backend_data, mask); + return shadow; +} + struct backend_shadow_context * default_create_shadow_context(backend_t *backend_data attr_unused, double radius) { auto ret = diff --git a/src/backend/backend_common.h b/src/backend/backend_common.h index 60286d1d..c72a1686 100644 --- a/src/backend/backend_common.h +++ b/src/backend/backend_common.h @@ -64,6 +64,11 @@ bool default_is_frame_transparent(void *, win *, void *); void *default_backend_render_shadow(backend_t *backend_data, int width, int height, struct backend_shadow_context *sctx, struct color color); + +/// Implement `render_shadow` with `shadow_from_mask`. +void * +backend_render_shadow_from_mask(backend_t *backend_data, int width, int height, + struct backend_shadow_context *sctx, struct color color); struct backend_shadow_context * default_create_shadow_context(backend_t *backend_data, double radius);