aboutsummaryrefslogtreecommitdiff
path: root/render
diff options
context:
space:
mode:
authorSimon Ser <contact@emersion.fr>2023-07-07 14:34:56 +0200
committerSimon Ser <contact@emersion.fr>2023-07-07 17:31:11 +0200
commit7a9f8d8d6bf72fcea210552b7bec9b99f342f857 (patch)
treec84c622b9ea25646c081f81b534ec7c70b84ac84 /render
parent4966857f211cb6f48852928076a59f16aadb742b (diff)
Use struct initializers instead of memset()
This is a bit more type-safe.
Diffstat (limited to 'render')
-rw-r--r--render/allocator/allocator.c7
-rw-r--r--render/drm_format_set.c5
-rw-r--r--render/gles2/texture.c9
-rw-r--r--render/pass.c5
-rw-r--r--render/swapchain.c2
-rw-r--r--render/wlr_renderer.c5
-rw-r--r--render/wlr_texture.c11
7 files changed, 25 insertions, 19 deletions
diff --git a/render/allocator/allocator.c b/render/allocator/allocator.c
index 10284cdd..2b7da4f1 100644
--- a/render/allocator/allocator.c
+++ b/render/allocator/allocator.c
@@ -22,9 +22,10 @@
void wlr_allocator_init(struct wlr_allocator *alloc,
const struct wlr_allocator_interface *impl, uint32_t buffer_caps) {
assert(impl && impl->destroy && impl->create_buffer);
- memset(alloc, 0, sizeof(*alloc));
- alloc->impl = impl;
- alloc->buffer_caps = buffer_caps;
+ *alloc = (struct wlr_allocator){
+ .impl = impl,
+ .buffer_caps = buffer_caps,
+ };
wl_signal_init(&alloc->events.destroy);
}
diff --git a/render/drm_format_set.c b/render/drm_format_set.c
index b8c33aa6..1b837fa5 100644
--- a/render/drm_format_set.c
+++ b/render/drm_format_set.c
@@ -86,8 +86,9 @@ bool wlr_drm_format_set_add(struct wlr_drm_format_set *set, uint32_t format,
}
void wlr_drm_format_init(struct wlr_drm_format *fmt, uint32_t format) {
- memset(fmt, 0, sizeof(*fmt));
- fmt->format = format;
+ *fmt = (struct wlr_drm_format){
+ .format = format,
+ };
}
bool wlr_drm_format_has(const struct wlr_drm_format *fmt, uint64_t modifier) {
diff --git a/render/gles2/texture.c b/render/gles2/texture.c
index 5faa54a2..4f884d73 100644
--- a/render/gles2/texture.c
+++ b/render/gles2/texture.c
@@ -373,8 +373,9 @@ struct wlr_texture *gles2_texture_from_buffer(struct wlr_renderer *wlr_renderer,
void wlr_gles2_texture_get_attribs(struct wlr_texture *wlr_texture,
struct wlr_gles2_texture_attribs *attribs) {
struct wlr_gles2_texture *texture = gles2_get_texture(wlr_texture);
- memset(attribs, 0, sizeof(*attribs));
- attribs->target = texture->target;
- attribs->tex = texture->tex;
- attribs->has_alpha = texture->has_alpha;
+ *attribs = (struct wlr_gles2_texture_attribs){
+ .target = texture->target,
+ .tex = texture->tex,
+ .has_alpha = texture->has_alpha,
+ };
}
diff --git a/render/pass.c b/render/pass.c
index c64772db..650353cb 100644
--- a/render/pass.c
+++ b/render/pass.c
@@ -15,8 +15,9 @@ struct wlr_render_pass_legacy {
void wlr_render_pass_init(struct wlr_render_pass *render_pass,
const struct wlr_render_pass_impl *impl) {
assert(impl->submit && impl->add_texture && impl->add_rect);
- memset(render_pass, 0, sizeof(*render_pass));
- render_pass->impl = impl;
+ *render_pass = (struct wlr_render_pass){
+ .impl = impl,
+ };
}
bool wlr_render_pass_submit(struct wlr_render_pass *render_pass) {
diff --git a/render/swapchain.c b/render/swapchain.c
index f72e722c..a2b6373b 100644
--- a/render/swapchain.c
+++ b/render/swapchain.c
@@ -42,7 +42,7 @@ static void slot_reset(struct wlr_swapchain_slot *slot) {
wl_list_remove(&slot->release.link);
}
wlr_buffer_drop(slot->buffer);
- memset(slot, 0, sizeof(*slot));
+ *slot = (struct wlr_swapchain_slot){0};
}
void wlr_swapchain_destroy(struct wlr_swapchain *swapchain) {
diff --git a/render/wlr_renderer.c b/render/wlr_renderer.c
index e8da28fd..d92d1bef 100644
--- a/render/wlr_renderer.c
+++ b/render/wlr_renderer.c
@@ -44,8 +44,9 @@ void wlr_renderer_init(struct wlr_renderer *renderer,
assert(impl->get_shm_texture_formats);
assert(impl->get_render_buffer_caps);
- memset(renderer, 0, sizeof(*renderer));
- renderer->impl = impl;
+ *renderer = (struct wlr_renderer){
+ .impl = impl,
+ };
wl_signal_init(&renderer->events.destroy);
wl_signal_init(&renderer->events.lost);
diff --git a/render/wlr_texture.c b/render/wlr_texture.c
index e327bb5c..8c003cfb 100644
--- a/render/wlr_texture.c
+++ b/render/wlr_texture.c
@@ -10,11 +10,12 @@ void wlr_texture_init(struct wlr_texture *texture, struct wlr_renderer *renderer
const struct wlr_texture_impl *impl, uint32_t width, uint32_t height) {
assert(renderer);
- memset(texture, 0, sizeof(*texture));
- texture->renderer = renderer;
- texture->impl = impl;
- texture->width = width;
- texture->height = height;
+ *texture = (struct wlr_texture){
+ .renderer = renderer,
+ .impl = impl,
+ .width = width,
+ .height = height,
+ };
}
void wlr_texture_destroy(struct wlr_texture *texture) {