mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2025-11-01 22:58:38 -04:00
Use wl_container_of() instead of casts
This slightly improves type safety.
The culprits were found with:
git grep -E '\([a-z0-9_ ]+ \*\)\W?[a-z]'
This commit is contained in:
parent
c2c536de03
commit
fe06e5f49a
29 changed files with 85 additions and 55 deletions
|
|
@ -25,7 +25,8 @@ static const struct wlr_buffer_impl buffer_impl;
|
|||
static struct wlr_drm_dumb_buffer *drm_dumb_buffer_from_buffer(
|
||||
struct wlr_buffer *wlr_buf) {
|
||||
assert(wlr_buf->impl == &buffer_impl);
|
||||
return (struct wlr_drm_dumb_buffer *)wlr_buf;
|
||||
struct wlr_drm_dumb_buffer *buf = wl_container_of(wlr_buf, buf, base);
|
||||
return buf;
|
||||
}
|
||||
|
||||
static struct wlr_drm_dumb_buffer *create_buffer(
|
||||
|
|
@ -163,7 +164,8 @@ static const struct wlr_allocator_interface allocator_impl;
|
|||
static struct wlr_drm_dumb_allocator *drm_dumb_alloc_from_alloc(
|
||||
struct wlr_allocator *wlr_alloc) {
|
||||
assert(wlr_alloc->impl == &allocator_impl);
|
||||
return (struct wlr_drm_dumb_allocator *)wlr_alloc;
|
||||
struct wlr_drm_dumb_allocator *alloc = wl_container_of(wlr_alloc, alloc, base);
|
||||
return alloc;
|
||||
}
|
||||
|
||||
static struct wlr_buffer *allocator_create_buffer(
|
||||
|
|
|
|||
|
|
@ -17,9 +17,10 @@
|
|||
static const struct wlr_buffer_impl buffer_impl;
|
||||
|
||||
static struct wlr_gbm_buffer *get_gbm_buffer_from_buffer(
|
||||
struct wlr_buffer *buffer) {
|
||||
assert(buffer->impl == &buffer_impl);
|
||||
return (struct wlr_gbm_buffer *)buffer;
|
||||
struct wlr_buffer *wlr_buffer) {
|
||||
assert(wlr_buffer->impl == &buffer_impl);
|
||||
struct wlr_gbm_buffer *buffer = wl_container_of(wlr_buffer, buffer, base);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
static bool export_gbm_bo(struct gbm_bo *bo,
|
||||
|
|
@ -179,9 +180,10 @@ static const struct wlr_buffer_impl buffer_impl = {
|
|||
static const struct wlr_allocator_interface allocator_impl;
|
||||
|
||||
static struct wlr_gbm_allocator *get_gbm_alloc_from_alloc(
|
||||
struct wlr_allocator *alloc) {
|
||||
assert(alloc->impl == &allocator_impl);
|
||||
return (struct wlr_gbm_allocator *)alloc;
|
||||
struct wlr_allocator *wlr_alloc) {
|
||||
assert(wlr_alloc->impl == &allocator_impl);
|
||||
struct wlr_gbm_allocator *alloc = wl_container_of(wlr_alloc, alloc, base);
|
||||
return alloc;
|
||||
}
|
||||
|
||||
struct wlr_allocator *wlr_gbm_allocator_create(int fd) {
|
||||
|
|
|
|||
|
|
@ -17,7 +17,8 @@ static const struct wlr_buffer_impl buffer_impl;
|
|||
static struct wlr_shm_buffer *shm_buffer_from_buffer(
|
||||
struct wlr_buffer *wlr_buffer) {
|
||||
assert(wlr_buffer->impl == &buffer_impl);
|
||||
return (struct wlr_shm_buffer *)wlr_buffer;
|
||||
struct wlr_shm_buffer *buffer = wl_container_of(wlr_buffer, buffer, base);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
static void buffer_destroy(struct wlr_buffer *wlr_buffer) {
|
||||
|
|
|
|||
|
|
@ -45,7 +45,8 @@ bool wlr_renderer_is_gles2(struct wlr_renderer *wlr_renderer) {
|
|||
struct wlr_gles2_renderer *gles2_get_renderer(
|
||||
struct wlr_renderer *wlr_renderer) {
|
||||
assert(wlr_renderer_is_gles2(wlr_renderer));
|
||||
return (struct wlr_gles2_renderer *)wlr_renderer;
|
||||
struct wlr_gles2_renderer *renderer = wl_container_of(wlr_renderer, renderer, wlr_renderer);
|
||||
return renderer;
|
||||
}
|
||||
|
||||
static struct wlr_gles2_renderer *gles2_get_renderer_in_context(
|
||||
|
|
@ -634,7 +635,7 @@ static int gles2_get_render_time(struct wlr_render_timer *wlr_timer) {
|
|||
}
|
||||
|
||||
static void gles2_render_timer_destroy(struct wlr_render_timer *wlr_timer) {
|
||||
struct wlr_gles2_render_timer *timer = (struct wlr_gles2_render_timer *)wlr_timer;
|
||||
struct wlr_gles2_render_timer *timer = wl_container_of(wlr_timer, timer, base);
|
||||
struct wlr_gles2_renderer *renderer = timer->renderer;
|
||||
|
||||
struct wlr_egl_context prev_ctx;
|
||||
|
|
|
|||
|
|
@ -25,7 +25,8 @@ bool wlr_texture_is_gles2(struct wlr_texture *wlr_texture) {
|
|||
struct wlr_gles2_texture *gles2_get_texture(
|
||||
struct wlr_texture *wlr_texture) {
|
||||
assert(wlr_texture_is_gles2(wlr_texture));
|
||||
return (struct wlr_gles2_texture *)wlr_texture;
|
||||
struct wlr_gles2_texture *texture = wl_container_of(wlr_texture, texture, wlr_texture);
|
||||
return texture;
|
||||
}
|
||||
|
||||
static bool gles2_texture_update_from_buffer(struct wlr_texture *wlr_texture,
|
||||
|
|
|
|||
|
|
@ -20,7 +20,8 @@ bool wlr_renderer_is_pixman(struct wlr_renderer *wlr_renderer) {
|
|||
static struct wlr_pixman_renderer *get_renderer(
|
||||
struct wlr_renderer *wlr_renderer) {
|
||||
assert(wlr_renderer_is_pixman(wlr_renderer));
|
||||
return (struct wlr_pixman_renderer *)wlr_renderer;
|
||||
struct wlr_pixman_renderer *renderer = wl_container_of(wlr_renderer, renderer, wlr_renderer);
|
||||
return renderer;
|
||||
}
|
||||
|
||||
bool begin_pixman_data_ptr_access(struct wlr_buffer *wlr_buffer, pixman_image_t **image_ptr,
|
||||
|
|
@ -76,7 +77,8 @@ bool wlr_texture_is_pixman(struct wlr_texture *texture) {
|
|||
static struct wlr_pixman_texture *get_texture(
|
||||
struct wlr_texture *wlr_texture) {
|
||||
assert(wlr_texture_is_pixman(wlr_texture));
|
||||
return (struct wlr_pixman_texture *)wlr_texture;
|
||||
struct wlr_pixman_texture *texture = wl_container_of(wlr_texture, texture, wlr_texture);
|
||||
return texture;
|
||||
}
|
||||
|
||||
static void texture_destroy(struct wlr_texture *wlr_texture) {
|
||||
|
|
|
|||
|
|
@ -52,7 +52,8 @@ bool wlr_renderer_is_vk(struct wlr_renderer *wlr_renderer) {
|
|||
|
||||
struct wlr_vk_renderer *vulkan_get_renderer(struct wlr_renderer *wlr_renderer) {
|
||||
assert(wlr_renderer_is_vk(wlr_renderer));
|
||||
return (struct wlr_vk_renderer *)wlr_renderer;
|
||||
struct wlr_vk_renderer *renderer = wl_container_of(wlr_renderer, renderer, wlr_renderer);
|
||||
return renderer;
|
||||
}
|
||||
|
||||
static struct wlr_vk_render_format_setup *find_or_create_render_setup(
|
||||
|
|
|
|||
|
|
@ -22,7 +22,8 @@ bool wlr_texture_is_vk(struct wlr_texture *wlr_texture) {
|
|||
|
||||
struct wlr_vk_texture *vulkan_get_texture(struct wlr_texture *wlr_texture) {
|
||||
assert(wlr_texture_is_vk(wlr_texture));
|
||||
return (struct wlr_vk_texture *)wlr_texture;
|
||||
struct wlr_vk_texture *texture = wl_container_of(wlr_texture, texture, wlr_texture);
|
||||
return texture;
|
||||
}
|
||||
|
||||
static VkImageAspectFlagBits mem_plane_aspect(unsigned i) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue