Imported Upstream version 0.1.0+git20131207+e452e83
[deb_libhybris.git] / hybris / egl / ws.c
CommitLineData
d42e7319
JB
1/*
2 * Copyright (C) 2013 libhybris
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <ws.h>
18#include <stdlib.h>
19#include <dlfcn.h>
20#include <stdlib.h>
21#include <assert.h>
22#include <stdio.h>
23
24static struct ws_module *ws = NULL;
25
26static void _init_ws()
27{
28 if (ws == NULL)
29 {
30 char ws_name[2048];
31 char *egl_platform;
32
33 // Mesa uses EGL_PLATFORM for its own purposes.
34 // Add HYBRIS_EGLPLATFORM to avoid the conflicts
35 egl_platform=getenv("HYBRIS_EGLPLATFORM");
36
37 if (egl_platform == NULL)
38 egl_platform=getenv("EGL_PLATFORM");
39
40 if (egl_platform == NULL)
41 egl_platform = DEFAULT_EGL_PLATFORM;
42
43 snprintf(ws_name, 2048, PKGLIBDIR "eglplatform_%s.so", egl_platform);
44
45 void *wsmod = (void *) dlopen(ws_name, RTLD_LAZY);
46 if (wsmod==NULL)
47 {
48 fprintf(stderr, "ERROR: %s\n\t%s\n", ws_name, dlerror());
49 assert(0);
50 }
51 ws = dlsym(wsmod, "ws_module_info");
52 assert(ws != NULL);
53 }
54}
55
56
57int ws_IsValidDisplay(EGLNativeDisplayType display)
58{
59 _init_ws();
60 return ws->IsValidDisplay(display);
61}
62
63EGLNativeWindowType ws_CreateWindow(EGLNativeWindowType win, EGLNativeDisplayType display)
64{
65 _init_ws();
66 return ws->CreateWindow(win, display);
67}
68
69void ws_DestroyWindow(EGLNativeWindowType win)
70{
71 _init_ws();
72 return ws->DestroyWindow(win);
73}
74
75__eglMustCastToProperFunctionPointerType ws_eglGetProcAddress(const char *procname)
76{
77 _init_ws();
78 return ws->eglGetProcAddress(procname);
79}
80
81void ws_passthroughImageKHR(EGLContext *ctx, EGLenum *target, EGLClientBuffer *buffer, const EGLint **attrib_list)
82{
83 _init_ws();
84 return ws->passthroughImageKHR(ctx, target, buffer, attrib_list);
85}
86
87const char *ws_eglQueryString(EGLDisplay dpy, EGLint name, const char *(*real_eglQueryString)(EGLDisplay dpy, EGLint name))
88{
89 _init_ws();
90 return ws->eglQueryString(dpy, name, real_eglQueryString);
91}
92
93// vim:ts=4:sw=4:noexpandtab