Skip to content

Commit

Permalink
Merge remote-tracking branch 'yshui/next' into next
Browse files Browse the repository at this point in the history
  • Loading branch information
FT-Labs committed Dec 19, 2023
2 parents c0ed4dd + 70ea36b commit a6c8347
Show file tree
Hide file tree
Showing 19 changed files with 219 additions and 77 deletions.
80 changes: 80 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
inputs = {
flake-utils.url = github:numtide/flake-utils;
git-ignore-nix = {
url = github:hercules-ci/gitignore.nix/master;
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = {
self, flake-utils, nixpkgs, git-ignore-nix, ...
}: flake-utils.lib.eachDefaultSystem (system: let
overlay = self: super: {
picom = super.picom.overrideAttrs (oldAttrs: rec {
pname = "picom";
buildInputs = [
self.pcre2 self.xorg.xcbutil
] ++ self.lib.remove self.xorg.libXinerama (
self.lib.remove self.pcre oldAttrs.buildInputs
);
src = git-ignore-nix.lib.gitignoreSource ./.;
});
};
pkgs = import nixpkgs { inherit system overlays; config.allowBroken = true; };
overlays = [ overlay ];
in rec {
inherit overlay overlays;
defaultPackage = pkgs.picom;
devShell = defaultPackage.overrideAttrs {
buildInputs = defaultPackage.buildInputs ++ [
pkgs.clang-tools
];
};
});
}
12 changes: 4 additions & 8 deletions src/backend/backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,7 @@ struct backend_operations {
// =========== Initialization ===========

/// Initialize the backend, prepare for rendering to the target window.
/// Here is how you should choose target window:
/// 1) if ps->overlay is not XCB_NONE, use that
/// 2) use ps->root otherwise
// TODO(yshui) make the target window a parameter
backend_t *(*init)(session_t *)attr_nonnull(1);
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
Expand Down Expand Up @@ -220,18 +216,18 @@ struct backend_operations {
struct xvisual_info fmt, bool owned);

/// Create a shadow context for rendering shadows with radius `radius`.
/// Default implementation: default_backend_create_shadow_context
/// Default implementation: default_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
/// Default implementation: default_destroy_shadow_context
void (*destroy_shadow_context)(backend_t *backend_data,
struct backend_shadow_context *ctx);

/// 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
/// Default implementation: default_render_shadow
///
/// Required.
void *(*render_shadow)(backend_t *backend_data, int width, int height,
Expand Down
4 changes: 2 additions & 2 deletions src/backend/backend_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,8 @@ bool build_shadow(struct x_connection *c, double opacity, const int width,
return false;
}

void *default_backend_render_shadow(backend_t *backend_data, int width, int height,
struct backend_shadow_context *sctx, struct color color) {
void *default_render_shadow(backend_t *backend_data, int width, int height,
struct backend_shadow_context *sctx, struct color color) {
const conv *kernel = (void *)sctx;
xcb_render_picture_t shadow_pixel =
solid_picture(backend_data->c, true, 1, color.red, color.green, color.blue);
Expand Down
12 changes: 2 additions & 10 deletions src/backend/backend_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,8 @@ solid_picture(struct x_connection *, bool argb, double a, double r, double g, do
xcb_image_t *make_shadow(struct x_connection *c, const conv *kernel, double opacity,
int width, int height);

/// The default implementation of `is_win_transparent`, it simply looks at win::mode. So
/// this is not suitable for backends that alter the content of windows
bool default_is_win_transparent(void *, win *, void *);

/// The default implementation of `is_frame_transparent`, it uses win::frame_opacity. Same
/// caveat as `default_is_win_transparent` applies.
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);
void *default_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 *
Expand Down
4 changes: 2 additions & 2 deletions src/backend/dummy/dummy.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct dummy_data {
struct backend_image mask;
};

struct backend_base *dummy_init(struct session *ps attr_unused) {
struct backend_base *dummy_init(session_t *ps attr_unused, xcb_window_t target attr_unused) {
auto ret = (struct backend_base *)ccalloc(1, struct dummy_data);
ret->c = &ps->c;
ret->loop = ps->loop;
Expand Down Expand Up @@ -184,7 +184,7 @@ struct backend_operations dummy_ops = {
.bind_pixmap = dummy_bind_pixmap,
.create_shadow_context = default_create_shadow_context,
.destroy_shadow_context = default_destroy_shadow_context,
.render_shadow = default_backend_render_shadow,
.render_shadow = default_render_shadow,
.make_mask = dummy_make_mask,
.release_image = dummy_release_image,
.is_image_transparent = dummy_is_image_transparent,
Expand Down
6 changes: 3 additions & 3 deletions src/backend/gl/egl.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ static bool egl_set_swap_interval(int interval, EGLDisplay dpy) {
/**
* Initialize OpenGL.
*/
static backend_t *egl_init(session_t *ps) {
static backend_t *egl_init(session_t *ps, xcb_window_t target) {
bool success = false;
struct egl_data *gd = NULL;

Expand Down Expand Up @@ -211,8 +211,8 @@ static backend_t *egl_init(session_t *ps) {
}
// clang-format on

gd->target_win = eglCreatePlatformWindowSurfaceProc(
gd->display, config, (xcb_window_t[]){session_get_target_window(ps)}, NULL);
gd->target_win =
eglCreatePlatformWindowSurfaceProc(gd->display, config, &target, NULL);
if (gd->target_win == EGL_NO_SURFACE) {
log_error("Failed to create EGL surface.");
goto end;
Expand Down
7 changes: 5 additions & 2 deletions src/backend/gl/gl_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -1356,8 +1356,11 @@ void *gl_shadow_from_mask(backend_t *base, void *mask,

glBindTexture(GL_TEXTURE_2D, tmp_texture);
glUseProgram(gd->shadow_shader.prog);
glUniform4f(gd->shadow_shader.uniform_color, (GLfloat)color.red,
(GLfloat)color.green, (GLfloat)color.blue, (GLfloat)color.alpha);
// The shadow color is converted to the premultiplied format to respect the
// globally set glBlendFunc and thus get the correct and expected result.
glUniform4f(gd->shadow_shader.uniform_color, (GLfloat)(color.red * color.alpha),
(GLfloat)(color.green * color.alpha),
(GLfloat)(color.blue * color.alpha), (GLfloat)color.alpha);

// clang-format off
GLuint indices[] = {0, 1, 2, 2, 3, 0};
Expand Down
8 changes: 4 additions & 4 deletions src/backend/gl/glx.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,13 @@ static bool glx_set_swap_interval(int interval, Display *dpy, GLXDrawable drawab
/**
* Initialize OpenGL.
*/
static backend_t *glx_init(session_t *ps) {
static backend_t *glx_init(session_t *ps, xcb_window_t target) {
bool success = false;
glxext_init(ps->c.dpy, ps->c.screen);
auto gd = ccalloc(1, struct _glx_data);
init_backend_base(&gd->gl.base, ps);

gd->target_win = session_get_target_window(ps);
gd->target_win = target;

XVisualInfo *pvis = NULL;

Expand Down Expand Up @@ -371,12 +371,12 @@ glx_bind_pixmap(backend_t *base, xcb_pixmap_t pixmap, struct xvisual_info fmt, b
if (fmt.visual_depth > OPENGL_MAX_DEPTH) {
log_error("Requested depth %d higher than max possible depth %d.",
fmt.visual_depth, OPENGL_MAX_DEPTH);
return false;
return NULL;
}

if (fmt.visual_depth < 0) {
log_error("Pixmap %#010x with invalid depth %d", pixmap, fmt.visual_depth);
return false;
return NULL;
}

auto r =
Expand Down
40 changes: 22 additions & 18 deletions src/backend/xrender/xrender.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ static xcb_render_picture_t process_mask(struct _xrender_data *xd, struct xrende
*allocated = false;
return inner->pict;
}
const auto tmpw = to_u16_checked(inner->width);
const auto tmph = to_u16_checked(inner->height);
auto const tmpw = to_u16_checked(inner->width);
auto const tmph = to_u16_checked(inner->height);
*allocated = true;
x_clear_picture_clip_region(xd->base.c, inner->pict);
auto ret = x_create_picture_with_visual(
Expand Down Expand Up @@ -226,13 +226,13 @@ compose_impl(struct _xrender_data *xd, struct xrender_image *xrimg, coord_t dst,
region_t reg;

bool has_alpha = inner->has_alpha || img->opacity != 1;
const auto tmpw = to_u16_checked(inner->width);
const auto tmph = to_u16_checked(inner->height);
const auto tmpew = to_u16_checked(img->ewidth);
const auto tmpeh = to_u16_checked(img->eheight);
auto const tmpw = to_u16_checked(inner->width);
auto const tmph = to_u16_checked(inner->height);
auto const tmpew = to_u16_checked(img->ewidth);
auto const tmpeh = to_u16_checked(img->eheight);
// Remember: the mask has a 1-pixel border
const auto mask_dst_x = to_i16_checked(dst.x - mask_dst.x + 1);
const auto mask_dst_y = to_i16_checked(dst.y - mask_dst.y + 1);
auto const mask_dst_x = to_i16_checked(dst.x - mask_dst.x + 1);
auto const mask_dst_y = to_i16_checked(dst.y - mask_dst.y + 1);
const xcb_render_color_t dim_color = {
.red = 0, .green = 0, .blue = 0, .alpha = (uint16_t)(0xffff * img->dim)};

Expand All @@ -250,10 +250,16 @@ compose_impl(struct _xrender_data *xd, struct xrender_image *xrimg, coord_t dst,
}
if (((img->color_inverted || img->dim != 0) && has_alpha) || img->corner_radius != 0) {
// Apply image properties using a temporary image, because the source
// image is transparent. Otherwise the properties can be applied directly
// on the target image.
// image is transparent or will get transparent corners. Otherwise the
// properties can be applied directly on the target image.
// Also force a 32-bit ARGB visual for transparent corners, otherwise the
// corners become black.
auto visual =
(img->corner_radius != 0 && inner->depth != 32)
? x_get_visual_for_standard(xd->base.c, XCB_PICT_STANDARD_ARGB_32)
: inner->visual;
auto tmp_pict = x_create_picture_with_visual(
xd->base.c, inner->width, inner->height, inner->visual, 0, NULL);
xd->base.c, inner->width, inner->height, visual, 0, NULL);

// Set clip region translated to source coordinate
x_set_picture_clip_region(xd->base.c, tmp_pict, to_i16_checked(-dst.x),
Expand Down Expand Up @@ -395,8 +401,8 @@ static bool blur(backend_t *backend_data, double opacity, void *ctx_, void *mask
resize_region(&reg_op, bctx->resize_width, bctx->resize_height);

const pixman_box32_t *extent_resized = pixman_region32_extents(&reg_op_resized);
const auto height_resized = to_u16_checked(extent_resized->y2 - extent_resized->y1);
const auto width_resized = to_u16_checked(extent_resized->x2 - extent_resized->x1);
auto const height_resized = to_u16_checked(extent_resized->y2 - extent_resized->y1);
auto const width_resized = to_u16_checked(extent_resized->x2 - extent_resized->x1);
static const char *filter0 = "Nearest"; // The "null" filter
static const char *filter = "convolution";

Expand Down Expand Up @@ -872,7 +878,7 @@ static void get_blur_size(void *blur_context, int *width, int *height) {
*height = ctx->resize_height;
}

static backend_t *backend_xrender_init(session_t *ps) {
static backend_t *backend_xrender_init(session_t *ps, xcb_window_t target) {
if (ps->o.dithered_present) {
log_warn("\"dithered-present\" is not supported by the xrender backend.");
}
Expand All @@ -891,7 +897,7 @@ static backend_t *backend_xrender_init(session_t *ps) {
xd->black_pixel = solid_picture(&ps->c, true, 1, 0, 0, 0);
xd->white_pixel = solid_picture(&ps->c, true, 1, 1, 1, 1);

xd->target_win = session_get_target_window(ps);
xd->target_win = target;
xcb_render_create_picture_value_list_t pa = {
.subwindowmode = XCB_SUBWINDOW_MODE_INCLUDE_INFERIORS,
};
Expand Down Expand Up @@ -984,10 +990,8 @@ struct backend_operations xrender_ops = {
.release_image = release_image,
.create_shadow_context = default_create_shadow_context,
.destroy_shadow_context = default_destroy_shadow_context,
.render_shadow = default_backend_render_shadow,
.render_shadow = default_render_shadow,
.make_mask = make_mask,
//.prepare_win = prepare_win,
//.release_win = release_win,
.is_image_transparent = default_is_image_transparent,
.buffer_age = buffer_age,
.max_buffer_age = 2,
Expand Down
2 changes: 1 addition & 1 deletion src/c2.c
Original file line number Diff line number Diff line change
Expand Up @@ -1336,7 +1336,7 @@ static xcb_atom_t c2_get_atom_type(const c2_l_t *pleaf) {
case C2_L_TDRAWABLE: return XCB_ATOM_DRAWABLE;
default: assert(0); break;
}
unreachable;
unreachable();
}

/**
Expand Down
12 changes: 8 additions & 4 deletions src/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
#endif

// clang-format off
#if __STDC_VERSION__ <= 201710L
#define auto __auto_type
#endif
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
#define likely_if(x) if (likely(x))
Expand Down Expand Up @@ -101,10 +103,12 @@
# endif
#endif

#if defined(__GNUC__) || defined(__clang__)
# define unreachable __builtin_unreachable()
#else
# define unreachable do {} while(0)
#ifndef unreachable
# if defined(__GNUC__) || defined(__clang__)
# define unreachable() __builtin_unreachable()
# else
# define unreachable() do {} while(0)
# endif
#endif

#ifndef __has_include
Expand Down
Loading

0 comments on commit a6c8347

Please sign in to comment.