Skip to content

Commit 283da66

Browse files
committed
feat: remove enum corner_location
1 parent fcdcb68 commit 283da66

File tree

13 files changed

+387
-406
lines changed

13 files changed

+387
-406
lines changed

examples/scene-graph.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include <assert.h>
22
#include <getopt.h>
33
#include <scenefx/render/fx_renderer/fx_renderer.h>
4-
#include <scenefx/types/fx/corner_location.h>
54
#include <scenefx/types/wlr_scene.h>
65
#include <stdbool.h>
76
#include <stdio.h>
@@ -145,7 +144,7 @@ static void server_handle_new_surface(struct wl_listener *listener,
145144
surface->scene_surface =
146145
wlr_scene_surface_create(&server->scene->tree, wlr_surface);
147146
wlr_scene_buffer_set_corner_radius(
148-
surface->scene_surface->buffer, corner_radius, CORNER_LOCATION_ALL);
147+
surface->scene_surface->buffer, corner_radius);
149148

150149
wlr_scene_node_set_position(&surface->scene_surface->buffer->node,
151150
pos + border_width, pos + border_width);

include/render/fx_renderer/shaders.h

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <GLES2/gl2.h>
55
#include <stdbool.h>
6+
#include "scenefx/types/fx/clipped_region.h"
67

78
struct fx_renderer;
89

@@ -20,6 +21,27 @@ enum fx_tex_shader_source {
2021
SHADER_SOURCE_TEXTURE_EXTERNAL = 3,
2122
};
2223

24+
struct shader_corner_radii {
25+
GLint top_left;
26+
GLint top_right;
27+
GLint bottom_left;
28+
GLint bottom_right;
29+
};
30+
31+
void uniform_corner_radii_set_location(
32+
struct shader_corner_radii *corners,
33+
GLuint program,
34+
const char *top_left,
35+
const char *top_right,
36+
const char *bottom_left,
37+
const char *bottom_right
38+
);
39+
40+
void uniform_corner_radii_set(
41+
struct shader_corner_radii *uniform,
42+
struct fx_corner_fradii *corners
43+
);
44+
2345
struct quad_shader {
2446
GLuint program;
2547
GLint proj;
@@ -28,10 +50,7 @@ struct quad_shader {
2850

2951
GLint clip_size;
3052
GLint clip_position;
31-
GLint clip_radius_top_left;
32-
GLint clip_radius_top_right;
33-
GLint clip_radius_bottom_left;
34-
GLint clip_radius_bottom_right;
53+
struct shader_corner_radii clip_radius;
3554
};
3655

3756
bool link_quad_program(struct quad_shader *shader, GLint client_version);
@@ -62,17 +81,11 @@ struct quad_round_shader {
6281
GLint size;
6382
GLint position;
6483

65-
GLint radius_top_left;
66-
GLint radius_top_right;
67-
GLint radius_bottom_left;
68-
GLint radius_bottom_right;
84+
struct shader_corner_radii radius;
6985

7086
GLint clip_size;
7187
GLint clip_position;
72-
GLint clip_radius_top_left;
73-
GLint clip_radius_top_right;
74-
GLint clip_radius_bottom_left;
75-
GLint clip_radius_bottom_right;
88+
struct shader_corner_radii clip_radius;
7689
};
7790

7891
bool link_quad_round_program(struct quad_round_shader *shader, GLint client_version);
@@ -94,10 +107,7 @@ struct quad_grad_round_shader {
94107
GLint count;
95108
GLint blend;
96109

97-
GLint radius_top_left;
98-
GLint radius_top_right;
99-
GLint radius_bottom_left;
100-
GLint radius_bottom_right;
110+
struct shader_corner_radii radius;
101111

102112
int max_len;
103113
};
@@ -113,19 +123,13 @@ struct tex_shader {
113123
GLint pos_attrib;
114124
GLint size;
115125
GLint position;
116-
GLint radius_top_left;
117-
GLint radius_top_right;
118-
GLint radius_bottom_left;
119-
GLint radius_bottom_right;
126+
struct shader_corner_radii radius;
120127

121128
GLint discard_transparent;
122129

123130
GLint clip_size;
124131
GLint clip_position;
125-
GLint clip_radius_top_left;
126-
GLint clip_radius_top_right;
127-
GLint clip_radius_bottom_left;
128-
GLint clip_radius_bottom_right;
132+
struct shader_corner_radii clip_radius;
129133
};
130134

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

143147
GLint clip_position;
144148
GLint clip_size;
145-
GLint clip_radius_top_left;
146-
GLint clip_radius_top_right;
147-
GLint clip_radius_bottom_left;
148-
GLint clip_radius_bottom_right;
149+
struct shader_corner_radii clip_radius;
149150
};
150151

151152
bool link_box_shadow_program(struct box_shadow_shader *shader, GLint client_version);

include/scenefx/render/pass.h

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#include "render/egl.h"
1010
#include "scenefx/types/fx/clipped_region.h"
11-
#include "scenefx/types/fx/corner_location.h"
1211

1312
struct fx_gles_render_pass {
1413
struct wlr_render_pass base;
@@ -55,15 +54,14 @@ struct fx_gradient {
5554
struct fx_render_texture_options {
5655
struct wlr_render_texture_options base;
5756
const struct wlr_box *clip_box; // Used to clip csd. Ignored if NULL
58-
enum corner_location corners;
59-
int corner_radius;
57+
struct fx_corner_fradii corners;
6058
bool discard_transparent;
61-
struct clipped_region clipped_region;
59+
struct clipped_fregion clipped_region;
6260
};
6361

6462
struct fx_render_rect_options {
6563
struct wlr_render_rect_options base;
66-
struct clipped_region clipped_region;
64+
struct clipped_fregion clipped_region;
6765
};
6866

6967
struct fx_render_rect_grad_options {
@@ -73,21 +71,19 @@ struct fx_render_rect_grad_options {
7371

7472
struct fx_render_rounded_rect_options {
7573
struct wlr_render_rect_options base;
76-
int corner_radius;
77-
enum corner_location corners;
78-
struct clipped_region clipped_region;
74+
struct fx_corner_fradii corners;
75+
struct clipped_fregion clipped_region;
7976
};
8077

8178
struct fx_render_rounded_rect_grad_options {
8279
struct wlr_render_rect_options base;
8380
struct fx_gradient gradient;
84-
int corner_radius;
85-
enum corner_location corners;
81+
struct fx_corner_fradii corners;
8682
};
8783

8884
struct fx_render_box_shadow_options {
8985
struct wlr_box box;
90-
struct clipped_region clipped_region;
86+
struct clipped_fregion clipped_region;
9187
/* Clip region, leave NULL to disable clipping */
9288
const pixman_region32_t *clip;
9389

@@ -104,9 +100,8 @@ struct fx_render_blur_pass_options {
104100
bool use_optimized_blur;
105101
bool ignore_transparent;
106102
float blur_strength;
107-
int corner_radius;
108-
enum corner_location corners;
109-
struct clipped_region clipped_region;
103+
struct fx_corner_radii corners;
104+
struct clipped_fregion clipped_region;
110105
};
111106

112107
/**

include/scenefx/types/fx/clipped_region.h

Lines changed: 82 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,91 @@
33

44
#include <wlr/util/box.h>
55

6-
#include "scenefx/types/fx/corner_location.h"
6+
// uint16_t is a reasonable enough range for corner radius
7+
// and makes it 8 bytes wide, making it cheap with optimisations
8+
// Note: layout is on purpose to be clockwise
9+
struct fx_corner_radii {
10+
uint16_t top_left;
11+
uint16_t top_right;
12+
uint16_t bottom_right;
13+
uint16_t bottom_left;
14+
};
15+
16+
struct fx_corner_fradii {
17+
float top_left;
18+
float top_right;
19+
float bottom_right;
20+
float bottom_left;
21+
};
22+
23+
#define CORNER_RADIUS_MAX (UINT16_MAX)
24+
25+
static __always_inline uint16_t corner_radius_clamp(int radius) {
26+
if (radius <= 0) {
27+
return 0;
28+
}
29+
30+
if (radius > CORNER_RADIUS_MAX) {
31+
return CORNER_RADIUS_MAX;
32+
}
33+
34+
return radius;
35+
}
36+
37+
static __always_inline struct fx_corner_radii corner_radii_new(int top_left, int top_right, int bottom_right, int bottom_left) {
38+
return (struct fx_corner_radii) {
39+
corner_radius_clamp(top_left),
40+
corner_radius_clamp(top_right),
41+
corner_radius_clamp(bottom_right),
42+
corner_radius_clamp(bottom_left),
43+
};
44+
}
45+
46+
static __always_inline struct fx_corner_radii corner_radii_all(int radius) {
47+
return corner_radii_new(radius, radius, radius, radius);
48+
}
49+
50+
static __always_inline struct fx_corner_radii corner_radii_none() {
51+
return corner_radii_all(0);
52+
}
53+
54+
static __always_inline struct fx_corner_radii corner_radii_top(int radius) {
55+
return corner_radii_new(radius, radius, 0, 0);
56+
}
57+
58+
static __always_inline struct fx_corner_radii corner_radii_bottom(int radius) {
59+
return corner_radii_new(0, 0, radius, radius);
60+
}
61+
62+
static __always_inline struct fx_corner_radii corner_radii_left(int radius) {
63+
return corner_radii_new(radius, 0, 0, radius);
64+
}
65+
66+
static __always_inline struct fx_corner_radii corner_radii_right(int radius) {
67+
return corner_radii_new(0, radius, radius, 0);
68+
}
69+
70+
struct fx_corner_radii fx_corner_radii_extend(struct fx_corner_radii corners, int extend);
71+
72+
void fx_corner_radii_transform(enum wl_output_transform transform,
73+
struct fx_corner_radii *corners);
74+
75+
struct fx_corner_fradii fx_corner_radii_scale(struct fx_corner_radii, float scale);
76+
77+
bool fx_corner_radii_eq(struct fx_corner_radii lhs, struct fx_corner_radii rhs);
78+
79+
bool fx_corner_radii_is_empty(const struct fx_corner_radii* corners);
80+
81+
bool fx_corner_fradii_is_empty(const struct fx_corner_fradii* corners);
782

883
struct clipped_region {
984
struct wlr_box area;
10-
int corner_radius;
11-
enum corner_location corners;
85+
struct fx_corner_radii corners;
86+
};
87+
88+
struct clipped_fregion {
89+
struct wlr_box area;
90+
struct fx_corner_fradii corners;
1291
};
1392

1493
struct clipped_region clipped_region_get_default(void);

include/scenefx/types/fx/corner_location.h

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)