glx/dri2: use mapping table for dri2_convert_glx_query_renderer_attribs()
authorEmil Velikov <emil.l.velikov@gmail.com>
Thu, 20 Feb 2014 00:23:41 +0000 (00:23 +0000)
committerEmil Velikov <emil.l.velikov@gmail.com>
Fri, 15 Aug 2014 16:35:37 +0000 (17:35 +0100)
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
src/glx/dri2_query_renderer.c

index c1e87723913039535613d9d5393b5b95728d0cca..eb5884aba638f65de548d2f46c6090757a3846c1 100644 (file)
 #include "dri3_priv.h"
 #endif
 
+#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