1 /*
2 * Copyright (C) 2015 The Android Open Source Project
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 <EGL/egl.h>
18 #include <EGL/eglext.h>
19
20 #include <pthread.h>
21 #include <stdlib.h>
22 #include <string.h>
23
24 static EGLDisplay gDisplay = (EGLDisplay) 1;
25
26 typedef struct {
27 EGLSurface surface;
28 EGLContext context;
29 } ThreadState;
30
31 static pthread_key_t ThreadStateKey;
32 static pthread_once_t ThreadStateSetupOnce = PTHREAD_ONCE_INIT;
33
destroyThreadState(void * state)34 static void destroyThreadState(void* state) {
35 free(state);
36 }
37
makeThreadState()38 static void makeThreadState() {
39 pthread_key_create(&ThreadStateKey, destroyThreadState);
40 }
41
getThreadState()42 ThreadState* getThreadState() {
43 ThreadState* ptr;
44 pthread_once(&ThreadStateSetupOnce, makeThreadState);
45 if ((ptr = (ThreadState*) pthread_getspecific(ThreadStateKey)) == NULL) {
46 ptr = (ThreadState*) calloc(1, sizeof(ThreadState));
47 ptr->context = EGL_NO_CONTEXT;
48 ptr->surface = EGL_NO_SURFACE;
49 pthread_setspecific(ThreadStateKey, ptr);
50 }
51 return ptr;
52 }
53
eglGetError(void)54 EGLint eglGetError(void) {
55 return EGL_SUCCESS;
56 }
57
eglGetDisplay(EGLNativeDisplayType display_id)58 EGLDisplay eglGetDisplay(EGLNativeDisplayType display_id) {
59 return gDisplay;
60 }
61
eglInitialize(EGLDisplay dpy,EGLint * major,EGLint * minor)62 EGLBoolean eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor) {
63 return EGL_TRUE;
64 }
65
eglTerminate(EGLDisplay dpy)66 EGLBoolean eglTerminate(EGLDisplay dpy) {
67 return EGL_TRUE;
68 }
69
eglQueryString(EGLDisplay dpy,EGLint name)70 const char * eglQueryString(EGLDisplay dpy, EGLint name) {
71 return "";
72 }
73
eglChooseConfig(EGLDisplay dpy,const EGLint * attrib_list,EGLConfig * configs,EGLint config_size,EGLint * num_config)74 EGLBoolean eglChooseConfig(EGLDisplay dpy, const EGLint *attrib_list,
75 EGLConfig *configs, EGLint config_size,
76 EGLint *num_config) {
77 memset(configs, 9, sizeof(EGLConfig) * config_size);
78 *num_config = config_size;
79 return EGL_TRUE;
80 }
81
eglCreateWindowSurface(EGLDisplay dpy,EGLConfig config,EGLNativeWindowType win,const EGLint * attrib_list)82 EGLSurface eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config,
83 EGLNativeWindowType win,
84 const EGLint *attrib_list) {
85 return (EGLSurface) malloc(sizeof(void*));
86 }
87
eglCreatePbufferSurface(EGLDisplay dpy,EGLConfig config,const EGLint * attrib_list)88 EGLSurface eglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config,
89 const EGLint *attrib_list) {
90 return (EGLSurface) malloc(sizeof(void*));
91 }
92
eglDestroySurface(EGLDisplay dpy,EGLSurface surface)93 EGLBoolean eglDestroySurface(EGLDisplay dpy, EGLSurface surface) {
94 free(surface);
95 return EGL_TRUE;
96 }
97
eglQuerySurface(EGLDisplay dpy,EGLSurface surface,EGLint attribute,EGLint * value)98 EGLBoolean eglQuerySurface(EGLDisplay dpy, EGLSurface surface,
99 EGLint attribute, EGLint *value) {
100 *value = 1000;
101 return EGL_TRUE;
102 }
103
eglReleaseThread(void)104 EGLBoolean eglReleaseThread(void) {
105 return EGL_TRUE;
106 }
107
eglSurfaceAttrib(EGLDisplay dpy,EGLSurface surface,EGLint attribute,EGLint value)108 EGLBoolean eglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface,
109 EGLint attribute, EGLint value) {
110 return EGL_TRUE;
111 }
112
eglSwapInterval(EGLDisplay dpy,EGLint interval)113 EGLBoolean eglSwapInterval(EGLDisplay dpy, EGLint interval) {
114 return EGL_TRUE;
115 }
116
eglCreateContext(EGLDisplay dpy,EGLConfig config,EGLContext share_context,const EGLint * attrib_list)117 EGLContext eglCreateContext(EGLDisplay dpy, EGLConfig config,
118 EGLContext share_context,
119 const EGLint *attrib_list) {
120 return (EGLContext) malloc(sizeof(void*));
121 }
eglDestroyContext(EGLDisplay dpy,EGLContext ctx)122 EGLBoolean eglDestroyContext(EGLDisplay dpy, EGLContext ctx) {
123 free(ctx);
124 return EGL_TRUE;
125 }
126
eglMakeCurrent(EGLDisplay dpy,EGLSurface draw,EGLSurface read,EGLContext ctx)127 EGLBoolean eglMakeCurrent(EGLDisplay dpy, EGLSurface draw,
128 EGLSurface read, EGLContext ctx) {
129 ThreadState* state = getThreadState();
130 state->surface = draw;
131 state->context = ctx;
132 return EGL_TRUE;
133 }
134
eglGetCurrentContext(void)135 EGLContext eglGetCurrentContext(void) {
136 return getThreadState()->context;
137 }
138
eglGetCurrentSurface(EGLint readdraw)139 EGLSurface eglGetCurrentSurface(EGLint readdraw) {
140 return getThreadState()->surface;
141 }
142
eglGetCurrentDisplay(void)143 EGLDisplay eglGetCurrentDisplay(void) {
144 return gDisplay;
145 }
146
eglSwapBuffers(EGLDisplay dpy,EGLSurface surface)147 EGLBoolean eglSwapBuffers(EGLDisplay dpy, EGLSurface surface) {
148 return EGL_TRUE;
149 }
150
eglCreateImageKHR(EGLDisplay dpy,EGLContext ctx,EGLenum target,EGLClientBuffer buffer,const EGLint * attrib_list)151 EGLImageKHR eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list) {
152 return (EGLImageKHR) malloc(sizeof(EGLImageKHR));
153 }
154
eglDestroyImageKHR(EGLDisplay dpy,EGLImageKHR image)155 EGLBoolean eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR image) {
156 free(image);
157 return EGL_TRUE;
158 }
159
eglBeginFrame(EGLDisplay dpy,EGLSurface surface)160 void eglBeginFrame(EGLDisplay dpy, EGLSurface surface) {}
161