[Mesa-dev] [PATCH 02/25] glx/dri2: use mapping table for dri2_convert_glx_query_renderer_attribs()

Emil Velikov emil.l.velikov at gmail.com
Fri Feb 21 19:03:52 PST 2014


Signed-off-by: Emil Velikov <emil.l.velikov at gmail.com>
---

Might seem like a bikeshed but it makes the code a lot
more readable IMHO.

Could be squashed in the following commit depending on
how people feel with the idea of using a mapping table.

-Emil

 src/glx/dri2_query_renderer.c | 54 ++++++++++++++++++++++---------------------
 1 file changed, 28 insertions(+), 26 deletions(-)

diff --git a/src/glx/dri2_query_renderer.c b/src/glx/dri2_query_renderer.c
index b50a202..3baba86 100644
--- a/src/glx/dri2_query_renderer.c
+++ b/src/glx/dri2_query_renderer.c
@@ -27,35 +27,37 @@
 #include "dri_interface.h"
 #include "dri2_priv.h"
 
+#define __RENDERER(attrib) \
+    { GLX_RENDERER_##attrib##_MESA, __DRI2_RENDERER_##attrib }
+
+static const struct {
+   unsigned int glx_attrib, dri2_attrib;
+} query_renderer_map[] = {
+  __RENDERER(VENDOR_ID),
+  __RENDERER(DEVICE_ID),
+  __RENDERER(VERSION),
+  __RENDERER(ACCELERATED),
+  __RENDERER(VIDEO_MEMORY),
+  __RENDERER(UNIFIED_MEMORY_ARCHITECTURE),
+  __RENDERER(PREFERRED_PROFILE),
+  __RENDERER(OPENGL_CORE_PROFILE_VERSION),
+  __RENDERER(OPENGL_COMPATIBILITY_PROFILE_VERSION),
+  __RENDERER(OPENGL_ES_PROFILE_VERSION),
+  __RENDERER(OPENGL_ES2_PROFILE_VERSION),
+};
+
+#undef __RENDERER
+
 static int
 dri2_convert_glx_query_renderer_attribs(int attribute)
 {
-   switch (attribute) {
-   case GLX_RENDERER_VENDOR_ID_MESA:
-      return __DRI2_RENDERER_VENDOR_ID;
-   case GLX_RENDERER_DEVICE_ID_MESA:
-      return __DRI2_RENDERER_DEVICE_ID;
-   case GLX_RENDERER_VERSION_MESA:
-      return __DRI2_RENDERER_VERSION;
-   case GLX_RENDERER_ACCELERATED_MESA:
-      return __DRI2_RENDERER_ACCELERATED;
-   case GLX_RENDERER_VIDEO_MEMORY_MESA:
-      return __DRI2_RENDERER_VIDEO_MEMORY;
-   case GLX_RENDERER_UNIFIED_MEMORY_ARCHITECTURE_MESA:
-      return __DRI2_RENDERER_UNIFIED_MEMORY_ARCHITECTURE;
-   case GLX_RENDERER_PREFERRED_PROFILE_MESA:
-      return __DRI2_RENDERER_PREFERRED_PROFILE;
-   case GLX_RENDERER_OPENGL_CORE_PROFILE_VERSION_MESA:
-      return __DRI2_RENDERER_OPENGL_CORE_PROFILE_VERSION;
-   case GLX_RENDERER_OPENGL_COMPATIBILITY_PROFILE_VERSION_MESA:
-      return __DRI2_RENDERER_OPENGL_COMPATIBILITY_PROFILE_VERSION;
-   case GLX_RENDERER_OPENGL_ES_PROFILE_VERSION_MESA:
-      return __DRI2_RENDERER_OPENGL_ES_PROFILE_VERSION;
-   case GLX_RENDERER_OPENGL_ES2_PROFILE_VERSION_MESA:
-      return __DRI2_RENDERER_OPENGL_ES2_PROFILE_VERSION;
-   default:
-      return -1;
-   }
+   int i;
+
+   for (i = 0; i < ARRAY_SIZE(query_renderer_map); i++)
+      if (query_renderer_map[i].glx_attrib == attribute)
+         return query_renderer_map[i].dri2_attrib;
+
+   return -1;
 }
 
 _X_HIDDEN int
-- 
1.9.0



More information about the mesa-dev mailing list