On Mon, 1 Aug 2016 19:17:53 +0200 Armin Krezović <[email protected]> wrote:
> This uses container_of instead of explicit cast to retrieve > backend and output objects from generic weston_backend and > weston_output pointers. > > Signed-off-by: Armin Krezović <[email protected]> > --- > libweston/compositor-drm.c | 69 > +++++++++++++++++++++++++++------------------- > 1 file changed, 40 insertions(+), 29 deletions(-) > > diff --git a/libweston/compositor-drm.c b/libweston/compositor-drm.c > index 737fa9d..fb9c623 100644 > --- a/libweston/compositor-drm.c > +++ b/libweston/compositor-drm.c > @@ -224,6 +224,18 @@ static struct gl_renderer_interface *gl_renderer; > > static const char default_seat[] = "seat0"; > > +static inline struct drm_output * > +to_drm_output(struct weston_output *base) > +{ > + return container_of(base, struct drm_output, base); > +} > + > +static inline struct drm_backend * > +to_drm_backend(struct weston_compositor *base) > +{ > + return container_of(base->backend, struct drm_backend, base); > +} > + > static void > drm_output_set_cursor(struct drm_output *output); > > @@ -234,7 +246,7 @@ static int > drm_sprite_crtc_supported(struct drm_output *output, uint32_t supported) > { > struct weston_compositor *ec = output->base.compositor; > - struct drm_backend *b =(struct drm_backend *)ec->backend; > + struct drm_backend *b = to_drm_backend(ec); > int crtc; > > for (crtc = 0; crtc < b->num_crtcs; crtc++) { > @@ -505,8 +517,7 @@ static struct weston_plane * > drm_output_prepare_scanout_view(struct drm_output *output, > struct weston_view *ev) > { > - struct drm_backend *b = > - (struct drm_backend *)output->base.compositor->backend; > + struct drm_backend *b = to_drm_backend(output->base.compositor); > struct weston_buffer *buffer = ev->surface->buffer_ref.buffer; > struct weston_buffer_viewport *viewport = &ev->surface->buffer_viewport; > struct gbm_bo *bo; > @@ -552,7 +563,7 @@ static void > drm_output_render_gl(struct drm_output *output, pixman_region32_t *damage) > { > struct drm_backend *b = > - (struct drm_backend *)output->base.compositor->backend; > + to_drm_backend(output->base.compositor); Hi Armin, this and several other cases below would probably fit on one line now. But the issue I didn't just land this patch is... > struct gbm_bo *bo; > > output->base.compositor->renderer->repaint_output(&output->base, > @@ -602,7 +613,7 @@ static void > drm_output_render(struct drm_output *output, pixman_region32_t *damage) > { > struct weston_compositor *c = output->base.compositor; > - struct drm_backend *b = (struct drm_backend *)c->backend; > + struct drm_backend *b = to_drm_backend(c); > > if (b->use_pixman) > drm_output_render_pixman(output, damage); > @@ -618,9 +629,9 @@ drm_output_set_gamma(struct weston_output *output_base, > uint16_t size, uint16_t *r, uint16_t *g, uint16_t *b) > { > int rc; > - struct drm_output *output = (struct drm_output *) output_base; > + struct drm_output *output = to_drm_output(output_base); > struct drm_backend *backend = > - (struct drm_backend *) output->base.compositor->backend; > + to_drm_backend(output->base.compositor); > > /* check */ > if (output_base->gamma_size != size) > @@ -664,9 +675,9 @@ static int > drm_output_repaint(struct weston_output *output_base, > pixman_region32_t *damage) > { > - struct drm_output *output = (struct drm_output *) output_base; > + struct drm_output *output = to_drm_output(output_base); > struct drm_backend *backend = > - (struct drm_backend *)output->base.compositor->backend; > + to_drm_backend(output->base.compositor); > struct drm_sprite *s; > struct drm_mode *mode; > int ret = 0; > @@ -763,9 +774,9 @@ err_pageflip: > static void > drm_output_start_repaint_loop(struct weston_output *output_base) > { > - struct drm_output *output = (struct drm_output *) output_base; > - struct drm_backend *backend = (struct drm_backend *) > - output_base->compositor->backend; > + struct drm_output *output = to_drm_output(output_base); > + struct drm_backend *backend = > + to_drm_backend(output_base->compositor); > uint32_t fb_id; > struct timespec ts, tnow; > struct timespec vbl2now; > @@ -873,7 +884,7 @@ static void > page_flip_handler(int fd, unsigned int frame, > unsigned int sec, unsigned int usec, void *data) > { > - struct drm_output *output = (struct drm_output *) data; > + struct drm_output *output = to_drm_output(data); ...the data argument is already a struct drm_output *. It comes from the drmModePageFlip() call which is implemented in libdrm. The only thing to do here would be to just drop the cast, since void* casts automatically. Otherwise the whole patch looks good. Thanks, pq
pgpTXk7LndISS.pgp
Description: OpenPGP digital signature
_______________________________________________ wayland-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/wayland-devel
