Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions examples/scene-graph.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <assert.h>
#include <getopt.h>
#include <scenefx/render/fx_renderer/fx_renderer.h>
#include <scenefx/types/fx/corner_location.h>
#include <scenefx/types/wlr_scene.h>
#include <stdbool.h>
#include <stdio.h>
Expand Down Expand Up @@ -145,7 +144,7 @@ static void server_handle_new_surface(struct wl_listener *listener,
surface->scene_surface =
wlr_scene_surface_create(&server->scene->tree, wlr_surface);
wlr_scene_buffer_set_corner_radius(
surface->scene_surface->buffer, corner_radius, CORNER_LOCATION_ALL);
surface->scene_surface->buffer, corner_radius);

wlr_scene_node_set_position(&surface->scene_surface->buffer->node,
pos + border_width, pos + border_width);
Expand Down
57 changes: 29 additions & 28 deletions include/render/fx_renderer/shaders.h
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like these changes actually add some LOC over the original implementation overall, I think we should scrap this bit to keep the diff lean

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know we save some LOC in fx_pass.c but I think we add more in shaders.c for a positive overall LOC diff, esp considering the glUniform1f calls in fx_pass can be oneliners now

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <GLES2/gl2.h>
#include <stdbool.h>
#include "scenefx/types/fx/clipped_region.h"

struct fx_renderer;

Expand All @@ -20,6 +21,27 @@ enum fx_tex_shader_source {
SHADER_SOURCE_TEXTURE_EXTERNAL = 3,
};

struct shader_corner_radii {
GLint top_left;
GLint top_right;
GLint bottom_left;
GLint bottom_right;
};

void uniform_corner_radii_set_location(
struct shader_corner_radii *corners,
GLuint program,
const char *top_left,
const char *top_right,
const char *bottom_left,
const char *bottom_right
);

void uniform_corner_radii_set(
struct shader_corner_radii *uniform,
struct fx_corner_fradii *corners
);

struct quad_shader {
GLuint program;
GLint proj;
Expand All @@ -28,10 +50,7 @@ struct quad_shader {

GLint clip_size;
GLint clip_position;
GLint clip_radius_top_left;
GLint clip_radius_top_right;
GLint clip_radius_bottom_left;
GLint clip_radius_bottom_right;
struct shader_corner_radii clip_radius;
};

bool link_quad_program(struct quad_shader *shader, GLint client_version);
Expand Down Expand Up @@ -62,17 +81,11 @@ struct quad_round_shader {
GLint size;
GLint position;

GLint radius_top_left;
GLint radius_top_right;
GLint radius_bottom_left;
GLint radius_bottom_right;
struct shader_corner_radii radius;

GLint clip_size;
GLint clip_position;
GLint clip_radius_top_left;
GLint clip_radius_top_right;
GLint clip_radius_bottom_left;
GLint clip_radius_bottom_right;
struct shader_corner_radii clip_radius;
};

bool link_quad_round_program(struct quad_round_shader *shader, GLint client_version);
Expand All @@ -94,10 +107,7 @@ struct quad_grad_round_shader {
GLint count;
GLint blend;

GLint radius_top_left;
GLint radius_top_right;
GLint radius_bottom_left;
GLint radius_bottom_right;
struct shader_corner_radii radius;

int max_len;
};
Expand All @@ -113,19 +123,13 @@ struct tex_shader {
GLint pos_attrib;
GLint size;
GLint position;
GLint radius_top_left;
GLint radius_top_right;
GLint radius_bottom_left;
GLint radius_bottom_right;
struct shader_corner_radii radius;

GLint discard_transparent;

GLint clip_size;
GLint clip_position;
GLint clip_radius_top_left;
GLint clip_radius_top_right;
GLint clip_radius_bottom_left;
GLint clip_radius_bottom_right;
struct shader_corner_radii clip_radius;
};

bool link_tex_program(struct tex_shader *shader, GLint client_version, enum fx_tex_shader_source source);
Expand All @@ -142,10 +146,7 @@ struct box_shadow_shader {

GLint clip_position;
GLint clip_size;
GLint clip_radius_top_left;
GLint clip_radius_top_right;
GLint clip_radius_bottom_left;
GLint clip_radius_bottom_right;
struct shader_corner_radii clip_radius;
};

bool link_box_shadow_program(struct box_shadow_shader *shader, GLint client_version);
Expand Down
23 changes: 9 additions & 14 deletions include/scenefx/render/pass.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include "render/egl.h"
#include "scenefx/types/fx/clipped_region.h"
#include "scenefx/types/fx/corner_location.h"

struct fx_gles_render_pass {
struct wlr_render_pass base;
Expand Down Expand Up @@ -55,15 +54,14 @@ struct fx_gradient {
struct fx_render_texture_options {
struct wlr_render_texture_options base;
const struct wlr_box *clip_box; // Used to clip csd. Ignored if NULL
enum corner_location corners;
int corner_radius;
struct fx_corner_fradii corners;
bool discard_transparent;
struct clipped_region clipped_region;
struct clipped_fregion clipped_region;
};

struct fx_render_rect_options {
struct wlr_render_rect_options base;
struct clipped_region clipped_region;
struct clipped_fregion clipped_region;
};

struct fx_render_rect_grad_options {
Expand All @@ -73,21 +71,19 @@ struct fx_render_rect_grad_options {

struct fx_render_rounded_rect_options {
struct wlr_render_rect_options base;
int corner_radius;
enum corner_location corners;
struct clipped_region clipped_region;
struct fx_corner_fradii corners;
struct clipped_fregion clipped_region;
};

struct fx_render_rounded_rect_grad_options {
struct wlr_render_rect_options base;
struct fx_gradient gradient;
int corner_radius;
enum corner_location corners;
struct fx_corner_fradii corners;
};

struct fx_render_box_shadow_options {
struct wlr_box box;
struct clipped_region clipped_region;
struct clipped_fregion clipped_region;
/* Clip region, leave NULL to disable clipping */
const pixman_region32_t *clip;

Expand All @@ -104,9 +100,8 @@ struct fx_render_blur_pass_options {
bool use_optimized_blur;
bool ignore_transparent;
float blur_strength;
int corner_radius;
enum corner_location corners;
struct clipped_region clipped_region;
struct fx_corner_radii corners;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all the other options have a fradii type, why not blur_pass_options?

struct clipped_fregion clipped_region;
};

/**
Expand Down
113 changes: 110 additions & 3 deletions include/scenefx/types/fx/clipped_region.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,119 @@

#include <wlr/util/box.h>

#include "scenefx/types/fx/corner_location.h"
// uint16_t is a reasonable enough range for corner radius
// and makes it 8 bytes wide, making it cheap with optimisations
// Note: layout is on purpose to be clockwise
struct fx_corner_radii {
uint16_t top_left;
uint16_t top_right;
uint16_t bottom_right;
uint16_t bottom_left;
};

struct fx_corner_fradii {
float top_left;
float top_right;
float bottom_right;
float bottom_left;
};
Comment on lines +16 to +21
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fradii stuff is just needed on the scenefx side as far as I could tell, we should move it and its functions to a private header (unless I missed a case)


#define CORNER_RADIUS_MAX (UINT16_MAX)

static __always_inline uint16_t corner_radius_clamp(int radius) {
if (radius <= 0) {
return 0;
}

if (radius > CORNER_RADIUS_MAX) {
return CORNER_RADIUS_MAX;
}

return radius;
}

static __always_inline struct fx_corner_radii corner_radii_new(int top_left, int top_right, int bottom_right, int bottom_left) {
return (struct fx_corner_radii) {
corner_radius_clamp(top_left),
corner_radius_clamp(top_right),
corner_radius_clamp(bottom_right),
corner_radius_clamp(bottom_left),
};
}

static __always_inline struct fx_corner_radii corner_radii_all(int radius) {
return corner_radii_new(radius, radius, radius, radius);
}

static __always_inline struct fx_corner_radii corner_radii_none() {
return corner_radii_all(0);
}

static __always_inline struct fx_corner_radii corner_radii_top(int radius) {
return corner_radii_new(radius, radius, 0, 0);
}

static __always_inline struct fx_corner_radii corner_radii_bottom(int radius) {
return corner_radii_new(0, 0, radius, radius);
}

static __always_inline struct fx_corner_radii corner_radii_left(int radius) {
return corner_radii_new(radius, 0, 0, radius);
}

static __always_inline struct fx_corner_radii corner_radii_right(int radius) {
return corner_radii_new(0, radius, radius, 0);
}

struct fx_corner_radii fx_corner_radii_extend(struct fx_corner_radii corners, int extend);

void fx_corner_radii_transform(enum wl_output_transform transform,
struct fx_corner_radii *corners);

struct fx_corner_fradii fx_corner_radii_scale(struct fx_corner_radii, float scale);

bool fx_corner_radii_eq(struct fx_corner_radii lhs, struct fx_corner_radii rhs);

/**
* Retains the corner values from `input` based on if the corresponding corner value in `filter` is non-zero
*
* This can be compared to an `AND` operation
*/
static __always_inline struct fx_corner_radii fx_corner_radii_filter(struct fx_corner_radii input, struct fx_corner_radii filter) {
return corner_radii_new(
input.top_left && filter.top_left ? input.top_left : 0,
input.top_right && filter.top_right ? input.top_right : 0,
input.bottom_right && filter.bottom_right ? input.bottom_right : 0,
input.bottom_left && filter.bottom_left ? input.bottom_left : 0
);
};

/**
* Picks the value of the corner from `lhs` if non-zero, otherwise picks the corner value from `rhs`
*
* This can be compared to an `OR` operation
*/
static __always_inline struct fx_corner_radii fx_corner_radii_pick(struct fx_corner_radii lhs, struct fx_corner_radii rhs) {
return corner_radii_new(
lhs.top_left ? lhs.top_left : rhs.top_left,
lhs.top_right ? lhs.top_right : rhs.top_right,
lhs.bottom_right ? lhs.bottom_right : rhs.bottom_right,
lhs.bottom_left ? lhs.bottom_left : rhs.bottom_left
);
};

bool fx_corner_radii_is_empty(const struct fx_corner_radii* corners);

bool fx_corner_fradii_is_empty(const struct fx_corner_fradii* corners);

struct clipped_region {
struct wlr_box area;
int corner_radius;
enum corner_location corners;
struct fx_corner_radii corners;
};

struct clipped_fregion {
struct wlr_box area;
struct fx_corner_fradii corners;
};

struct clipped_region clipped_region_get_default(void);
Expand Down
26 changes: 0 additions & 26 deletions include/scenefx/types/fx/corner_location.h

This file was deleted.

Loading