Skip to content

Commit

Permalink
backend: merge v2 backend ops back into backend_operations
Browse files Browse the repository at this point in the history
Signed-off-by: Yuxuan Shui <[email protected]>
  • Loading branch information
yshui committed May 10, 2024
1 parent 11c8d01 commit d91e260
Show file tree
Hide file tree
Showing 9 changed files with 189 additions and 204 deletions.
10 changes: 5 additions & 5 deletions src/backend/backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,22 @@ bool backend_execute(struct backend_base *backend, image_handle target, unsigned
continue;
}
succeeded =
backend->ops->v2.blit(backend, cmd->origin, target, &cmd->blit);
backend->ops->blit(backend, cmd->origin, target, &cmd->blit);
break;
case BACKEND_COMMAND_COPY_AREA:
if (!pixman_region32_not_empty(cmd->copy_area.region)) {
continue;
}
succeeded = backend->ops->v2.copy_area(backend, cmd->origin, target,
cmd->copy_area.source_image,
cmd->copy_area.region);
succeeded = backend->ops->copy_area(backend, cmd->origin, target,
cmd->copy_area.source_image,
cmd->copy_area.region);
break;
case BACKEND_COMMAND_BLUR:
if (!pixman_region32_not_empty(&cmd->blur.mask->region)) {
continue;
}
succeeded =
backend->ops->v2.blur(backend, cmd->origin, target, &cmd->blur);
backend->ops->blur(backend, cmd->origin, target, &cmd->blur);
break;
case BACKEND_COMMAND_INVALID:
default: assert(false);
Expand Down
126 changes: 61 additions & 65 deletions src/backend/backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,18 +202,37 @@ enum backend_quirk {
BACKEND_QUIRK_SLOW_BLUR = 1 << 0,
};

struct backend_ops_v2 {
/// Get backend quirks
/// @return a bitmask of `enum backend_quirk`.
uint32_t (*quirks)(struct backend_base *backend_data) attr_nonnull(1);
struct backend_operations {
// =========== Initialization ===========

/// Check if an optional image format is supported by the backend.
bool (*is_format_supported)(struct backend_base *backend_data,
enum backend_image_format format) attr_nonnull(1);
/// Initialize the backend, prepare for rendering to the target window.
backend_t *(*init)(session_t *, xcb_window_t)attr_nonnull(1);
void (*deinit)(backend_t *backend_data) attr_nonnull(1);

/// Return the capabilities of an image.
uint32_t (*image_capabilities)(struct backend_base *backend_data, image_handle image)
attr_nonnull(1, 2);
/// Called when rendering will be stopped for an unknown amount of
/// time (e.g. when screen is unredirected). Free some resources.
///
/// Optional, not yet used
void (*pause)(backend_t *backend_data, session_t *ps);

/// Called before rendering is resumed
///
/// Optional, not yet used
void (*resume)(backend_t *backend_data, session_t *ps);

/// Called when root window size changed. All existing image data ever
/// returned by this backend should remain valid after this call
/// returns.
///
/// Optional
void (*root_change)(backend_t *backend_data, session_t *ps);

// =========== Rendering ============

/// Called before when a new frame starts.
///
/// Optional
void (*prepare)(backend_t *backend_data, const region_t *reg_damage);

/// Multiply the alpha channel of the target image by a given value.
///
Expand Down Expand Up @@ -315,6 +334,23 @@ struct backend_ops_v2 {
bool (*clear)(struct backend_base *backend_data, image_handle target,
struct color color) attr_nonnull(1, 2);

/// Present the back buffer to the target window. Ideally the backend should keep
/// track of the region of the back buffer that has been updated, and use relevant
/// mechanism (when possible) to present only the updated region.
bool (*present)(struct backend_base *backend_data) attr_nonnull(1);

// ============ Resource management ===========

/// Create a shader object from a shader source.
///
/// Optional
void *(*create_shader)(backend_t *backend_data, const char *source)attr_nonnull(1, 2);

/// Free a shader object.
///
/// Required if create_shader is present.
void (*destroy_shader)(backend_t *backend_data, void *shader) attr_nonnull(1, 2);

/// Create a new, uninitialized image with the given format and size.
///
/// @param backend_data backend data
Expand All @@ -324,11 +360,6 @@ struct backend_ops_v2 {
enum backend_image_format format, geometry_t size)
attr_nonnull(1);

/// Acquire the image handle of the back buffer.
///
/// @param backend_data backend data
image_handle (*back_buffer)(struct backend_base *backend_data);

/// Bind a X pixmap to the backend's internal image data structure.
///
/// @param backend_data backend data
Expand All @@ -339,6 +370,11 @@ struct backend_ops_v2 {
image_handle (*bind_pixmap)(struct backend_base *backend_data, xcb_pixmap_t pixmap,
struct xvisual_info fmt) attr_nonnull(1);

/// Acquire the image handle of the back buffer.
///
/// @param backend_data backend data
image_handle (*back_buffer)(struct backend_base *backend_data);

/// Free resources associated with an image data structure. Releasing the image
/// returned by `back_buffer` should be a no-op.
///
Expand All @@ -348,59 +384,19 @@ struct backend_ops_v2 {
xcb_pixmap_t (*release_image)(struct backend_base *backend_data, image_handle image)
attr_nonnull(1, 2);

/// Present the back buffer to the target window. Ideally the backend should keep
/// track of the region of the back buffer that has been updated, and use relevant
/// mechanism (when possible) to present only the updated region.
bool (*present)(struct backend_base *backend_data) attr_nonnull(1);
};

struct backend_operations {
// =========== V2 ===========
struct backend_ops_v2 v2;
// =========== Initialization ===========

/// Initialize the backend, prepare for rendering to the target window.
backend_t *(*init)(session_t *, xcb_window_t)attr_nonnull(1);
void (*deinit)(backend_t *backend_data) attr_nonnull(1);

/// Called when rendering will be stopped for an unknown amount of
/// time (e.g. when screen is unredirected). Free some resources.
///
/// Optional, not yet used
void (*pause)(backend_t *backend_data, session_t *ps);

/// Called before rendering is resumed
///
/// Optional, not yet used
void (*resume)(backend_t *backend_data, session_t *ps);

/// Called when root window size changed. All existing image data ever
/// returned by this backend should remain valid after this call
/// returns.
///
/// Optional
void (*root_change)(backend_t *backend_data, session_t *ps);

// =========== Rendering ============

/// Called before when a new frame starts.
///
/// Optional
void (*prepare)(backend_t *backend_data, const region_t *reg_damage);

// ============ Resource management ===========
// =========== Query ===========

/// Create a shader object from a shader source.
///
/// Optional
void *(*create_shader)(backend_t *backend_data, const char *source)attr_nonnull(1, 2);
/// Get backend quirks
/// @return a bitmask of `enum backend_quirk`.
uint32_t (*quirks)(struct backend_base *backend_data) attr_nonnull(1);

/// Free a shader object.
///
/// Required if create_shader is present.
void (*destroy_shader)(backend_t *backend_data, void *shader) attr_nonnull(1, 2);
/// Check if an optional image format is supported by the backend.
bool (*is_format_supported)(struct backend_base *backend_data,
enum backend_image_format format) attr_nonnull(1);

// =========== Query ===========
/// Return the capabilities of an image.
uint32_t (*image_capabilities)(struct backend_base *backend_data, image_handle image)
attr_nonnull(1, 2);

/// Get the attributes of a shader.
///
Expand Down
30 changes: 14 additions & 16 deletions src/backend/dummy/dummy.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,22 +205,20 @@ bool dummy_is_format_supported(struct backend_base *base attr_unused,
}

struct backend_operations dummy_ops = {
.v2 =
{
.apply_alpha = dummy_apply_alpha,
.back_buffer = dummy_back_buffer,
.blit = dummy_blit,
.blur = dummy_blur,
.clear = dummy_clear,
.copy_area = dummy_copy_area,
.copy_area_quantize = dummy_copy_area,
.image_capabilities = dummy_image_capabilities,
.is_format_supported = dummy_is_format_supported,
.new_image = dummy_new_image,
.bind_pixmap = dummy_bind_pixmap,
.quirks = backend_no_quirks,
.release_image = dummy_release_image,
},
.apply_alpha = dummy_apply_alpha,
.back_buffer = dummy_back_buffer,
.blit = dummy_blit,
.blur = dummy_blur,
.clear = dummy_clear,
.copy_area = dummy_copy_area,
.copy_area_quantize = dummy_copy_area,
.image_capabilities = dummy_image_capabilities,
.is_format_supported = dummy_is_format_supported,
.new_image = dummy_new_image,
.bind_pixmap = dummy_bind_pixmap,
.quirks = backend_no_quirks,
.release_image = dummy_release_image,

.init = dummy_init,
.deinit = dummy_deinit,
.buffer_age = dummy_buffer_age,
Expand Down
32 changes: 15 additions & 17 deletions src/backend/gl/egl.c
Original file line number Diff line number Diff line change
Expand Up @@ -339,23 +339,21 @@ static void egl_diagnostics(backend_t *base) {
}

struct backend_operations egl_ops = {
.v2 =
{
.apply_alpha = gl_apply_alpha,
.back_buffer = gl_back_buffer,
.blit = gl_blit,
.blur = gl_blur,
.bind_pixmap = egl_bind_pixmap,
.clear = gl_clear,
.copy_area = gl_copy_area,
.copy_area_quantize = gl_copy_area_quantize,
.is_format_supported = gl_is_format_supported,
.image_capabilities = gl_image_capabilities,
.new_image = gl_new_image,
.present = egl_present,
.quirks = backend_no_quirks,
.release_image = gl_release_image,
},
.apply_alpha = gl_apply_alpha,
.back_buffer = gl_back_buffer,
.blit = gl_blit,
.blur = gl_blur,
.bind_pixmap = egl_bind_pixmap,
.clear = gl_clear,
.copy_area = gl_copy_area,
.copy_area_quantize = gl_copy_area_quantize,
.is_format_supported = gl_is_format_supported,
.image_capabilities = gl_image_capabilities,
.new_image = gl_new_image,
.present = egl_present,
.quirks = backend_no_quirks,
.release_image = gl_release_image,

.init = egl_init,
.deinit = egl_deinit,
.root_change = gl_root_change,
Expand Down
32 changes: 15 additions & 17 deletions src/backend/gl/glx.c
Original file line number Diff line number Diff line change
Expand Up @@ -518,23 +518,21 @@ static void glx_diagnostics(backend_t *base) {
}

struct backend_operations glx_ops = {
.v2 =
{
.apply_alpha = gl_apply_alpha,
.back_buffer = gl_back_buffer,
.bind_pixmap = glx_bind_pixmap,
.blit = gl_blit,
.blur = gl_blur,
.clear = gl_clear,
.copy_area = gl_copy_area,
.copy_area_quantize = gl_copy_area_quantize,
.image_capabilities = gl_image_capabilities,
.is_format_supported = gl_is_format_supported,
.new_image = gl_new_image,
.present = glx_present,
.quirks = backend_no_quirks,
.release_image = gl_release_image,
},
.apply_alpha = gl_apply_alpha,
.back_buffer = gl_back_buffer,
.bind_pixmap = glx_bind_pixmap,
.blit = gl_blit,
.blur = gl_blur,
.clear = gl_clear,
.copy_area = gl_copy_area,
.copy_area_quantize = gl_copy_area_quantize,
.image_capabilities = gl_image_capabilities,
.is_format_supported = gl_is_format_supported,
.new_image = gl_new_image,
.present = glx_present,
.quirks = backend_no_quirks,
.release_image = gl_release_image,

.init = glx_init,
.deinit = glx_deinit,
.root_change = gl_root_change,
Expand Down
32 changes: 15 additions & 17 deletions src/backend/xrender/xrender.c
Original file line number Diff line number Diff line change
Expand Up @@ -1001,23 +1001,21 @@ uint32_t xrender_quirks(struct backend_base *base) {
}

struct backend_operations xrender_ops = {
.v2 =
{
.apply_alpha = xrender_apply_alpha,
.back_buffer = xrender_back_buffer,
.bind_pixmap = xrender_bind_pixmap,
.blit = xrender_blit,
.blur = xrender_blur,
.clear = xrender_clear,
.copy_area = xrender_copy_area,
.copy_area_quantize = xrender_copy_area,
.image_capabilities = xrender_image_capabilities,
.is_format_supported = xrender_is_format_supported,
.new_image = xrender_new_image,
.present = xrender_present,
.quirks = xrender_quirks,
.release_image = xrender_release_image,
},
.apply_alpha = xrender_apply_alpha,
.back_buffer = xrender_back_buffer,
.bind_pixmap = xrender_bind_pixmap,
.blit = xrender_blit,
.blur = xrender_blur,
.clear = xrender_clear,
.copy_area = xrender_copy_area,
.copy_area_quantize = xrender_copy_area,
.image_capabilities = xrender_image_capabilities,
.is_format_supported = xrender_is_format_supported,
.new_image = xrender_new_image,
.present = xrender_present,
.quirks = xrender_quirks,
.release_image = xrender_release_image,

.init = xrender_init,
.deinit = xrender_deinit,
// TODO(yshui) make blur faster so we can use `backend_render_shadow_from_mask` for
Expand Down
11 changes: 5 additions & 6 deletions src/picom.c
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ static void destroy_backend(session_t *ps) {
}

if (ps->backend_data && ps->root_image) {
ps->backend_data->ops->v2.release_image(ps->backend_data, ps->root_image);
ps->backend_data->ops->release_image(ps->backend_data, ps->root_image);
ps->root_image = NULL;
}

Expand Down Expand Up @@ -1152,8 +1152,7 @@ void root_damaged(session_t *ps) {

if (ps->backend_data) {
if (ps->root_image) {
ps->backend_data->ops->v2.release_image(ps->backend_data,
ps->root_image);
ps->backend_data->ops->release_image(ps->backend_data, ps->root_image);
ps->root_image = NULL;
}
auto pixmap = x_get_root_back_pixmap(&ps->c, ps->atoms);
Expand Down Expand Up @@ -1187,7 +1186,7 @@ void root_damaged(session_t *ps) {
: x_get_visual_for_depth(ps->c.screen_info, r->depth);
free(r);

ps->root_image = ps->backend_data->ops->v2.bind_pixmap(
ps->root_image = ps->backend_data->ops->bind_pixmap(
ps->backend_data, pixmap, x_get_visual_info(&ps->c, visual));
ps->root_image_generation += 1;
if (!ps->root_image) {
Expand Down Expand Up @@ -1452,7 +1451,7 @@ uint8_t session_redirection_mode(session_t *ps) {
assert(!ps->o.legacy_backends);
return XCB_COMPOSITE_REDIRECT_AUTOMATIC;
}
if (!ps->o.legacy_backends && !backend_list[ps->o.backend]->v2.present) {
if (!ps->o.legacy_backends && !backend_list[ps->o.backend]->present) {
// if the backend doesn't render anything, we don't need to take over the
// screen.
return XCB_COMPOSITE_REDIRECT_AUTOMATIC;
Expand Down Expand Up @@ -2409,7 +2408,7 @@ static session_t *session_init(int argc, char **argv, Display *dpy,
log_info("The compositor is started in automatic redirection mode.");
assert(!ps->o.legacy_backends);

if (backend_list[ps->o.backend]->v2.present) {
if (backend_list[ps->o.backend]->present) {
// If the backend has `present`, we couldn't be in automatic
// redirection mode unless we are in debug mode.
assert(ps->o.debug_mode);
Expand Down
Loading

0 comments on commit d91e260

Please sign in to comment.