From 49ed5bb28d501cd6751bd59dc25a60a4293bcd75 Mon Sep 17 00:00:00 2001
From: Chia-I Wu <olv@lunarg.com>
Date: Mon, 10 Jan 2011 12:39:46 +0800
Subject: targets/egl-static: New EGL target for scons.

This target is based on and replaces egl-gdi.  It is suitable for both
windows and x11.
---
 src/egl/main/egldriver.c                  |  20 ++-
 src/gallium/targets/egl-gdi/SConscript    |  55 --------
 src/gallium/targets/egl-gdi/egl-static.c  | 143 --------------------
 src/gallium/targets/egl-static/egl.c      | 129 ++++++++++++++++++
 src/gallium/targets/egl-static/egl_pipe.c | 216 ++++++++++++++++++++++++++++++
 src/gallium/targets/egl-static/egl_pipe.h |  40 ++++++
 src/gallium/targets/egl-static/egl_st.c   | 105 +++++++++++++++
 src/gallium/targets/egl-static/egl_st.h   |  40 ++++++
 8 files changed, 544 insertions(+), 204 deletions(-)
 delete mode 100644 src/gallium/targets/egl-gdi/SConscript
 delete mode 100644 src/gallium/targets/egl-gdi/egl-static.c
 create mode 100644 src/gallium/targets/egl-static/egl.c
 create mode 100644 src/gallium/targets/egl-static/egl_pipe.c
 create mode 100644 src/gallium/targets/egl-static/egl_pipe.h
 create mode 100644 src/gallium/targets/egl-static/egl_st.c
 create mode 100644 src/gallium/targets/egl-static/egl_st.h

diff --git a/src/egl/main/egldriver.c b/src/egl/main/egldriver.c
index 62c56955134..46876d00565 100644
--- a/src/egl/main/egldriver.c
+++ b/src/egl/main/egldriver.c
@@ -141,9 +141,6 @@ _eglOpenLibrary(const char *driverPath, lib_handle *handle)
    if (!lib) {
       _eglLog(_EGL_WARNING, "Could not open driver %s (%s)",
               driverPath, error);
-      if (!getenv("EGL_DRIVER"))
-         _eglLog(_EGL_WARNING,
-                 "The driver can be overridden by setting EGL_DRIVER");
       return NULL;
    }
 
@@ -467,6 +464,19 @@ _eglAddUserDriver(void)
 }
 
 
+/**
+ * Add egl_gallium to the module array.
+ */
+static void
+_eglAddGalliumDriver(void)
+{
+#ifndef _EGL_BUILT_IN_DRIVER_GALLIUM
+   void *external = (void *) "egl_gallium";
+   _eglPreloadForEach(_eglGetSearchPath(), _eglLoaderFile, external);
+#endif
+}
+
+
 /**
  * Add built-in drivers to the module array.
  */
@@ -491,14 +501,12 @@ _eglAddBuiltInDrivers(void)
 static EGLBoolean
 _eglAddDrivers(void)
 {
-   void *external = (void *) "egl_gallium";
-
    if (_eglModules)
       return EGL_TRUE;
 
    /* the order here decides the priorities of the drivers */
    _eglAddUserDriver();
-   _eglPreloadForEach(_eglGetSearchPath(), _eglLoaderFile, external);
+   _eglAddGalliumDriver();
    _eglAddBuiltInDrivers();
 
    return (_eglModules != NULL);
diff --git a/src/gallium/targets/egl-gdi/SConscript b/src/gallium/targets/egl-gdi/SConscript
deleted file mode 100644
index d52eeb70fd5..00000000000
--- a/src/gallium/targets/egl-gdi/SConscript
+++ /dev/null
@@ -1,55 +0,0 @@
-#######################################################################
-# SConscript for egl-gdi target
-
-Import('*')
-
-env = env.Clone()
-
-env.Append(CPPPATH = [
-        '#/src/gallium/state_trackers/egl',
-        '#/src/gallium/state_trackers/vega',
-        '#/src/egl/main',
-        '#/src/mesa',
-])
-
-env.Append(CPPDEFINES = [
-        'FEATURE_VG=1',
-        'GALLIUM_SOFTPIPE',
-        'GALLIUM_RBUG',
-        'GALLIUM_TRACE',
-])
-
-env.Append(LIBS = [
-    'gdi32',
-    'user32',
-    'kernel32',
-    'ws2_32',
-])
-
-env.Prepend(LIBS = [
-    st_egl_gdi,
-    ws_gdi,
-    identity,
-    trace,
-    rbug,
-    softpipe,
-    vgapi,
-    st_vega,
-    gallium,
-    egl,
-])
-
-if env['llvm']:
-    env.Append(CPPDEFINES = 'GALLIUM_LLVMPIPE')
-    env.Prepend(LIBS = [llvmpipe])
-
-egl_gallium = env.SharedLibrary(
-    target ='egl_gallium',
-    source = 'egl-static.c',
-)
-
-env['no_import_lib'] = 1
-
-egl_gdi = env.InstallSharedLibrary(egl_gallium)
-
-env.Alias('egl-gdi', egl_gdi)
diff --git a/src/gallium/targets/egl-gdi/egl-static.c b/src/gallium/targets/egl-gdi/egl-static.c
deleted file mode 100644
index da6e5ce3396..00000000000
--- a/src/gallium/targets/egl-gdi/egl-static.c
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- * Mesa 3-D graphics library
- * Version:  7.9
- *
- * Copyright (C) 2010 LunarG Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- * Authors:
- *    Chia-I Wu <olv@lunarg.com>
- */
-
-#include "common/egl_g3d_loader.h"
-#include "state_tracker/st_gl_api.h"
-#include "vg_api.h"
-#include "target-helpers/inline_sw_helper.h"
-#include "target-helpers/inline_debug_helper.h"
-#include "egldriver.h"
-
-static struct st_api *stapis[ST_API_COUNT];
-
-static struct st_api *
-get_st_api(enum st_api_type api)
-{
-   struct st_api *stapi;
-
-   stapi = stapis[api];
-   if (stapi)
-      return stapi;
-
-   switch (api) {
-#if FEATURE_GL || FEATURE_ES1 || FEATURE_ES2
-   case ST_API_OPENGL:
-      stapi = st_gl_api_create();
-      break;
-#endif
-#if FEATURE_VG
-   case ST_API_OPENVG:
-      stapi = (struct st_api *) vg_api_get();
-      break;
-#endif
-   default:
-      break;
-   }
-
-   stapis[api] = stapi;
-
-   return stapi;
-}
-
-static struct st_api *
-guess_gl_api(enum st_profile_type profile)
-{
-   return get_st_api(ST_API_OPENGL);
-}
-
-static struct pipe_screen *
-create_drm_screen(const char *name, int fd)
-{
-   return NULL;
-}
-
-static struct pipe_screen *
-create_sw_screen(struct sw_winsys *ws)
-{
-   struct pipe_screen *screen;
-
-   screen = sw_screen_create(ws);
-   if (screen)
-      screen = debug_screen_wrap(screen);
-
-   return screen;
-}
-
-static void
-init_loader(struct egl_g3d_loader *loader)
-{
-#if FEATURE_GL
-   loader->profile_masks[ST_API_OPENGL] |= ST_PROFILE_DEFAULT_MASK;
-#endif
-#if FEATURE_ES1
-   loader->profile_masks[ST_API_OPENGL] |= ST_PROFILE_OPENGL_ES1_MASK;
-#endif
-#if FEATURE_ES2
-   loader->profile_masks[ST_API_OPENGL] |= ST_PROFILE_OPENGL_ES2_MASK;
-#endif
-#if FEATURE_VG
-   loader->profile_masks[ST_API_OPENVG] |= ST_PROFILE_DEFAULT_MASK;
-#endif
-
-   loader->get_st_api = get_st_api;
-   loader->guess_gl_api = guess_gl_api;
-   loader->create_drm_screen = create_drm_screen;
-   loader->create_sw_screen = create_sw_screen;
-}
-
-static void
-egl_g3d_unload(_EGLDriver *drv)
-{
-   int i;
-
-   egl_g3d_destroy_driver(drv);
-
-   for (i = 0; i < ST_API_COUNT; i++) {
-      if (stapis[i]) {
-         stapis[i]->destroy(stapis[i]);
-         stapis[i] = NULL;
-      }
-   }
-}
-
-static struct egl_g3d_loader loader;
-
-_EGLDriver *
-_eglMain(const char *args)
-{
-   _EGLDriver *drv;
-
-   init_loader(&loader);
-   drv = egl_g3d_create_driver(&loader);
-   if (drv) {
-      drv->Name = "Gallium";
-      drv->Unload = egl_g3d_unload;
-   }
-
-   return drv;
-}
diff --git a/src/gallium/targets/egl-static/egl.c b/src/gallium/targets/egl-static/egl.c
new file mode 100644
index 00000000000..e617ff50208
--- /dev/null
+++ b/src/gallium/targets/egl-static/egl.c
@@ -0,0 +1,129 @@
+/*
+ * Mesa 3-D graphics library
+ * Version:  7.10
+ *
+ * Copyright (C) 2010-2011 LunarG Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Chia-I Wu <olv@lunarg.com>
+ */
+
+#include "common/egl_g3d_loader.h"
+#include "egldriver.h"
+
+#include "egl_pipe.h"
+#include "egl_st.h"
+
+static struct egl_g3d_loader egl_g3d_loader;
+
+static struct st_module {
+   boolean initialized;
+   struct st_api *stapi;
+} st_modules[ST_API_COUNT];
+
+static struct st_api *
+get_st_api(enum st_api_type api)
+{
+   struct st_module *stmod = &st_modules[api];
+
+   if (!stmod->initialized) {
+      stmod->stapi = egl_st_create_api(api);
+      stmod->initialized = TRUE;
+   }
+
+   return stmod->stapi;
+}
+
+static struct st_api *
+guess_gl_api(enum st_profile_type profile)
+{
+   return get_st_api(ST_API_OPENGL);
+}
+
+static struct pipe_screen *
+create_drm_screen(const char *name, int fd)
+{
+   return egl_pipe_create_drm_screen(name, fd);
+}
+
+static struct pipe_screen *
+create_sw_screen(struct sw_winsys *ws)
+{
+   return egl_pipe_create_swrast_screen(ws);
+}
+
+static const struct egl_g3d_loader *
+loader_init(void)
+{
+   int i;
+
+   for (i = 0; i < ST_API_COUNT; i++)
+      egl_g3d_loader.profile_masks[i] = egl_st_get_profile_mask(i);
+
+   egl_g3d_loader.get_st_api = get_st_api;
+   egl_g3d_loader.guess_gl_api = guess_gl_api;
+   egl_g3d_loader.create_drm_screen = create_drm_screen;
+   egl_g3d_loader.create_sw_screen = create_sw_screen;
+
+   return &egl_g3d_loader;
+}
+
+static void
+loader_fini(void)
+{
+   int i;
+
+   for (i = 0; i < ST_API_COUNT; i++) {
+      struct st_module *stmod = &st_modules[i];
+
+      if (stmod->stapi) {
+         stmod->stapi->destroy(stmod->stapi);
+         stmod->stapi = NULL;
+      }
+      stmod->initialized = FALSE;
+   }
+}
+
+static void
+egl_g3d_unload(_EGLDriver *drv)
+{
+   egl_g3d_destroy_driver(drv);
+   loader_fini();
+}
+
+_EGLDriver *
+_EGL_MAIN(const char *args)
+{
+   const struct egl_g3d_loader *loader;
+   _EGLDriver *drv;
+
+   loader = loader_init();
+   drv = egl_g3d_create_driver(loader);
+   if (!drv) {
+      loader_fini();
+      return NULL;
+   }
+
+   drv->Name = "Gallium";
+   drv->Unload = egl_g3d_unload;
+
+   return drv;
+}
diff --git a/src/gallium/targets/egl-static/egl_pipe.c b/src/gallium/targets/egl-static/egl_pipe.c
new file mode 100644
index 00000000000..2684ede307f
--- /dev/null
+++ b/src/gallium/targets/egl-static/egl_pipe.c
@@ -0,0 +1,216 @@
+/*
+ * Mesa 3-D graphics library
+ * Version:  7.10
+ *
+ * Copyright (C) 2011 LunarG Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Chia-I Wu <olv@lunarg.com>
+ */
+#include "target-helpers/inline_debug_helper.h"
+#include "target-helpers/inline_sw_helper.h"
+#include "state_tracker/drm_driver.h"
+#include "egl_pipe.h"
+
+/* for i915 */
+#include "i915/drm/i915_drm_public.h"
+#include "i915/i915_public.h"
+/* for i965 */
+#include "target-helpers/inline_wrapper_sw_helper.h"
+#include "i965/drm/i965_drm_public.h"
+#include "i965/brw_public.h"
+/* for nouveau */
+#include "nouveau/drm/nouveau_drm_public.h"
+/* for r300 */
+#include "radeon/drm/radeon_drm_public.h"
+#include "r300/r300_public.h"
+/* for r600 */
+#include "r600/drm/r600_drm_public.h"
+#include "r600/r600_public.h"
+/* for vmwgfx */
+#include "svga/drm/svga_drm_public.h"
+#include "svga/svga_public.h"
+
+static struct pipe_screen *
+pipe_i915_create_screen(int fd)
+{
+#if _EGL_PIPE_I915
+   struct i915_winsys *iws;
+   struct pipe_screen *screen;
+
+   iws = i915_drm_winsys_create(fd);
+   if (!iws)
+      return NULL;
+
+   screen = i915_screen_create(iws);
+   if (!screen)
+      return NULL;
+
+   screen = debug_screen_wrap(screen);
+
+   return screen;
+#else
+   return NULL;
+#endif
+}
+
+static struct pipe_screen *
+pipe_i965_create_screen(int fd)
+{
+#if _EGL_PIPE_I965
+   struct brw_winsys_screen *bws;
+   struct pipe_screen *screen;
+
+   bws = i965_drm_winsys_screen_create(fd);
+   if (!bws)
+      return NULL;
+
+   screen = brw_screen_create(bws);
+   if (!screen)
+      return NULL;
+
+   screen = sw_screen_wrap(screen);
+
+   screen = debug_screen_wrap(screen);
+
+   return screen;
+#else
+   return NULL;
+#endif
+}
+
+static struct pipe_screen *
+pipe_nouveau_create_screen(int fd)
+{
+#if _EGL_PIPE_NOUVEAU
+   struct pipe_screen *screen;
+
+   screen = nouveau_drm_screen_create(fd);
+   if (!screen)
+      return NULL;
+
+   screen = debug_screen_wrap(screen);
+
+   return screen;
+#else
+   return NULL;
+#endif
+}
+
+static struct pipe_screen *
+pipe_r300_create_screen(int fd)
+{
+#if _EGL_PIPE_R300
+   struct r300_winsys_screen *sws;
+   struct pipe_screen *screen;
+
+   sws = r300_drm_winsys_screen_create(fd);
+   if (!sws)
+      return NULL;
+
+   screen = r300_screen_create(sws);
+   if (!screen)
+      return NULL;
+
+   screen = debug_screen_wrap(screen);
+
+   return screen;
+#else
+   return NULL;
+#endif
+}
+
+static struct pipe_screen *
+pipe_r600_create_screen(int fd)
+{
+#if _EGL_PIPE_R600
+   struct radeon *rw;
+   struct pipe_screen *screen;
+
+   rw = r600_drm_winsys_create(fd);
+   if (!rw)
+      return NULL;
+
+   screen = r600_screen_create(rw);
+   if (!screen)
+      return NULL;
+
+   screen = debug_screen_wrap(screen);
+
+   return screen;
+#else
+   return NULL;
+#endif
+}
+
+static struct pipe_screen *
+pipe_vmwgfx_create_screen(int fd)
+{
+#if _EGL_PIPE_VMWGFX
+   struct svga_winsys_screen *sws;
+   struct pipe_screen *screen;
+
+   sws = svga_drm_winsys_screen_create(fd);
+   if (!sws)
+      return NULL;
+
+   screen = svga_screen_create(sws);
+   if (!screen)
+      return NULL;
+
+   screen = debug_screen_wrap(screen);
+
+   return screen;
+#else
+   return NULL;
+#endif
+}
+
+struct pipe_screen *
+egl_pipe_create_drm_screen(const char *name, int fd)
+{
+   if (strcmp(name, "i915") == 0)
+      return pipe_i915_create_screen(fd);
+   else if (strcmp(name, "i965") == 0)
+      return pipe_i965_create_screen(fd);
+   else if (strcmp(name, "nouveau") == 0)
+      return pipe_nouveau_create_screen(fd);
+   else if (strcmp(name, "r300") == 0)
+      return pipe_r300_create_screen(fd);
+   else if (strcmp(name, "r600") == 0)
+      return pipe_r600_create_screen(fd);
+   else if (strcmp(name, "vmwgfx") == 0)
+      return pipe_vmwgfx_create_screen(fd);
+   else
+      return NULL;
+}
+
+struct pipe_screen *
+egl_pipe_create_swrast_screen(struct sw_winsys *ws)
+{
+   struct pipe_screen *screen;
+
+   screen = sw_screen_create(ws);
+   if (screen)
+      screen = debug_screen_wrap(screen);
+
+   return screen;
+}
diff --git a/src/gallium/targets/egl-static/egl_pipe.h b/src/gallium/targets/egl-static/egl_pipe.h
new file mode 100644
index 00000000000..569b2d067c4
--- /dev/null
+++ b/src/gallium/targets/egl-static/egl_pipe.h
@@ -0,0 +1,40 @@
+/*
+ * Mesa 3-D graphics library
+ * Version:  7.10
+ *
+ * Copyright (C) 2011 LunarG Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Chia-I Wu <olv@lunarg.com>
+ */
+#ifndef _EGL_PIPE_H_
+#define _EGL_PIPE_H_
+
+struct pipe_screen;
+struct sw_winsys;
+
+struct pipe_screen *
+egl_pipe_create_drm_screen(const char *name, int fd);
+
+struct pipe_screen *
+egl_pipe_create_swrast_screen(struct sw_winsys *ws);
+
+#endif /* _EGL_PIPE_H_ */
diff --git a/src/gallium/targets/egl-static/egl_st.c b/src/gallium/targets/egl-static/egl_st.c
new file mode 100644
index 00000000000..3db52621def
--- /dev/null
+++ b/src/gallium/targets/egl-static/egl_st.c
@@ -0,0 +1,105 @@
+/*
+ * Mesa 3-D graphics library
+ * Version:  7.10
+ *
+ * Copyright (C) 2011 LunarG Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Chia-I Wu <olv@lunarg.com>
+ */
+#include "util/u_debug.h"
+#include "state_tracker/st_api.h"
+#include "egl_st.h"
+
+/* for st/mesa */
+#include "state_tracker/st_gl_api.h"
+/* for st/vega */
+#include "vg_api.h"
+
+static struct st_api *
+st_GL_create_api(void)
+{
+#if FEATURE_GL || FEATURE_ES1 || FEATURE_ES2
+   return st_gl_api_create();
+#else
+   return NULL;
+#endif
+}
+
+static struct st_api *
+st_OpenVG_create_api(void)
+{
+#if FEATURE_VG
+   return (struct st_api *) vg_api_get();
+#else
+   return NULL;
+#endif
+}
+
+struct st_api *
+egl_st_create_api(enum st_api_type api)
+{
+   struct st_api *stapi;
+
+   switch (api) {
+   case ST_API_OPENGL:
+      stapi = st_GL_create_api();
+      break;
+   case ST_API_OPENVG:
+      stapi = st_OpenVG_create_api();
+      break;
+   default:
+      assert(!"Unknown API Type\n");
+      stapi = NULL;
+      break;
+   }
+
+   return stapi;
+}
+
+uint
+egl_st_get_profile_mask(enum st_api_type api)
+{
+   uint mask = 0x0;
+
+   switch (api) {
+   case ST_API_OPENGL:
+#if FEATURE_GL
+      mask |= ST_PROFILE_DEFAULT_MASK;
+#endif
+#if FEATURE_ES1
+      mask |= ST_PROFILE_OPENGL_ES1_MASK;
+#endif
+#if FEATURE_ES2
+      mask |= ST_PROFILE_OPENGL_ES2_MASK;
+#endif
+      break;
+   case ST_API_OPENVG:
+#if FEATURE_VG
+      mask |= ST_PROFILE_DEFAULT_MASK;
+#endif
+      break;
+   default:
+      break;
+   }
+
+   return mask;
+}
diff --git a/src/gallium/targets/egl-static/egl_st.h b/src/gallium/targets/egl-static/egl_st.h
new file mode 100644
index 00000000000..ba82faf0b0e
--- /dev/null
+++ b/src/gallium/targets/egl-static/egl_st.h
@@ -0,0 +1,40 @@
+/*
+ * Mesa 3-D graphics library
+ * Version:  7.10
+ *
+ * Copyright (C) 2011 LunarG Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Chia-I Wu <olv@lunarg.com>
+ */
+#ifndef _EGL_ST_H_
+#define _EGL_ST_H_
+
+#include "pipe/p_compiler.h"
+#include "state_tracker/st_api.h"
+
+struct st_api *
+egl_st_create_api(enum st_api_type api);
+
+uint
+egl_st_get_profile_mask(enum st_api_type api);
+
+#endif /* _EGL_ST_H_ */
-- 
cgit v1.2.3