nv50,nvc0: buffer resources can be bound as other things down the line
[mesa.git] / src / gallium / targets / egl-static / egl.c
1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 2010-2011 LunarG Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *
24 * Authors:
25 * Chia-I Wu <olv@lunarg.com>
26 */
27
28 #include "common/egl_g3d_loader.h"
29 #include "egldriver.h"
30 #include "egllog.h"
31 #include "loader.h"
32
33 #include "egl_pipe.h"
34 #include "egl_st.h"
35 #include "target-helpers/inline_drm_helper.h"
36
37 static struct egl_g3d_loader egl_g3d_loader;
38
39 static struct st_module {
40 boolean initialized;
41 struct st_api *stapi;
42 } st_modules[ST_API_COUNT];
43
44 static struct st_api *
45 get_st_api(enum st_api_type api)
46 {
47 struct st_module *stmod = &st_modules[api];
48
49 if (!stmod->initialized) {
50 stmod->stapi = egl_st_create_api(api);
51 stmod->initialized = TRUE;
52 }
53
54 return stmod->stapi;
55 }
56
57
58 static struct pipe_screen *
59 create_drm_screen(const char *constname, int fd)
60 {
61 return dd_create_screen(fd);
62 }
63
64 static struct pipe_screen *
65 create_sw_screen(struct sw_winsys *ws)
66 {
67 return egl_pipe_create_swrast_screen(ws);
68 }
69
70 static const struct egl_g3d_loader *
71 loader_init(void)
72 {
73 egl_g3d_loader.get_st_api = get_st_api;
74 egl_g3d_loader.create_drm_screen = create_drm_screen;
75 egl_g3d_loader.create_sw_screen = create_sw_screen;
76
77 loader_set_logger(_eglLog);
78
79 return &egl_g3d_loader;
80 }
81
82 static void
83 loader_fini(void)
84 {
85 int i;
86
87 for (i = 0; i < ST_API_COUNT; i++) {
88 struct st_module *stmod = &st_modules[i];
89
90 if (stmod->stapi) {
91 egl_st_destroy_api(stmod->stapi);
92 stmod->stapi = NULL;
93 }
94 stmod->initialized = FALSE;
95 }
96 }
97
98 static void
99 egl_g3d_unload(_EGLDriver *drv)
100 {
101 egl_g3d_destroy_driver(drv);
102 loader_fini();
103 }
104
105 _EGLDriver *
106 _EGL_MAIN(const char *args)
107 {
108 const struct egl_g3d_loader *loader;
109 _EGLDriver *drv;
110
111 loader = loader_init();
112 drv = egl_g3d_create_driver(loader);
113 if (!drv) {
114 loader_fini();
115 return NULL;
116 }
117
118 drv->Name = "Gallium";
119 drv->Unload = egl_g3d_unload;
120
121 return drv;
122 }