[Mesa-dev] [PATCH] egl-static: Reduce code duplication for radeons

Tobias Droste tdroste at gmx.de
Fri Apr 11 19:23:10 PDT 2014


Consolidate pipe_r300_create_screen, pipe_r600_create_screen and
pipe_radeonsi_create_screen to one function.
They do exactly the same and only pass a different parameter
to radeon_drm_winsys_create.

Signed-off-by: Tobias Droste <tdroste at gmx.de>
---

This may or may not be an improvement.
Pro: Less duplicate code
Con: Radeons are handled different

The diff is looking a bit strange but the result is simply this:
#if _EGL_PIPE_R300 || _EGL_PIPE_R600 || _EGL_PIPE_RADEONSI
static struct pipe_screen *
pipe_radeon_create_screen(int fd, radeon_screen_create_t screen_create)
{
   struct radeon_winsys *rw;

   rw = radeon_drm_winsys_create(fd, screen_create);
   return rw ? debug_screen_wrap(rw->screen) : NULL;
}
#endif

 src/gallium/targets/egl-static/egl_pipe.c | 46 ++++++++-----------------------
 1 file changed, 12 insertions(+), 34 deletions(-)

diff --git a/src/gallium/targets/egl-static/egl_pipe.c b/src/gallium/targets/egl-static/egl_pipe.c
index 1f28fa2..1ccf5e0 100644
--- a/src/gallium/targets/egl-static/egl_pipe.c
+++ b/src/gallium/targets/egl-static/egl_pipe.c
@@ -134,44 +134,16 @@ pipe_nouveau_create_screen(int fd)
 #endif
 }
 
+#if _EGL_PIPE_R300 || _EGL_PIPE_R600 || _EGL_PIPE_RADEONSI
 static struct pipe_screen *
-pipe_r300_create_screen(int fd)
-{
-#if _EGL_PIPE_R300
-   struct radeon_winsys *sws;
-
-   sws = radeon_drm_winsys_create(fd, r300_screen_create);
-   return sws ? debug_screen_wrap(sws->screen) : NULL;
-#else
-   return NULL;
-#endif
-}
-
-static struct pipe_screen *
-pipe_r600_create_screen(int fd)
+pipe_radeon_create_screen(int fd, radeon_screen_create_t screen_create)
 {
-#if _EGL_PIPE_R600
    struct radeon_winsys *rw;
 
-   rw = radeon_drm_winsys_create(fd, r600_screen_create);
+   rw = radeon_drm_winsys_create(fd, screen_create);
    return rw ? debug_screen_wrap(rw->screen) : NULL;
-#else
-   return NULL;
-#endif
 }
-
-static struct pipe_screen *
-pipe_radeonsi_create_screen(int fd)
-{
-#if _EGL_PIPE_RADEONSI
-   struct radeon_winsys *rw;
-
-   rw = radeon_drm_winsys_create(fd, radeonsi_screen_create);
-   return rw ? debug_screen_wrap(rw->screen) : NULL;
-#else
-   return NULL;
 #endif
-}
 
 static struct pipe_screen *
 pipe_vmwgfx_create_screen(int fd)
@@ -223,12 +195,18 @@ egl_pipe_create_drm_screen(const char *name, int fd)
       return pipe_ilo_create_screen(fd);
    else if (strcmp(name, "nouveau") == 0)
       return pipe_nouveau_create_screen(fd);
+#if _EGL_PIPE_R300
    else if (strcmp(name, "r300") == 0)
-      return pipe_r300_create_screen(fd);
+      return pipe_radeon_create_screen(fd, r300_screen_create);
+#endif
+#if _EGL_PIPE_R600
    else if (strcmp(name, "r600") == 0)
-      return pipe_r600_create_screen(fd);
+      return pipe_radeon_create_screen(fd, r600_screen_create);
+#endif
+#if _EGL_PIPE_RADEONSI
    else if (strcmp(name, "radeonsi") == 0)
-      return pipe_radeonsi_create_screen(fd);
+      return pipe_radeon_create_screen(fd, radeonsi_screen_create);
+#endif
    else if (strcmp(name, "vmwgfx") == 0)
       return pipe_vmwgfx_create_screen(fd);
    else if ((strcmp(name, "kgsl") == 0) || (strcmp(name, "msm") == 0))
-- 
1.9.1



More information about the mesa-dev mailing list