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 static EGLSyncKHR gFence = (EGLSyncKHR)1;
26
27 typedef struct {
28 EGLSurface surface;
29 EGLContext context;
30 } ThreadState;
31
32 static pthread_key_t ThreadStateKey;
33 static pthread_once_t ThreadStateSetupOnce = PTHREAD_ONCE_INIT;
34
destroyThreadState(void * state)35 static void destroyThreadState(void* state) {
36 free(state);
37 }
38
makeThreadState()39 static void makeThreadState() {
40 pthread_key_create(&ThreadStateKey, destroyThreadState);
41 }
42
getThreadState()43 ThreadState* getThreadState() {
44 ThreadState* ptr;
45 pthread_once(&ThreadStateSetupOnce, makeThreadState);
46 if ((ptr = (ThreadState*)pthread_getspecific(ThreadStateKey)) == NULL) {
47 ptr = (ThreadState*)calloc(1, sizeof(ThreadState));
48 ptr->context = EGL_NO_CONTEXT;
49 ptr->surface = EGL_NO_SURFACE;
50 pthread_setspecific(ThreadStateKey, ptr);
51 }
52 return ptr;
53 }
54
eglGetError(void)55 EGLint eglGetError(void) {
56 return EGL_SUCCESS;
57 }
58
eglGetDisplay(EGLNativeDisplayType display_id)59 EGLDisplay eglGetDisplay(EGLNativeDisplayType display_id) {
60 return gDisplay;
61 }
62
eglInitialize(EGLDisplay dpy,EGLint * major,EGLint * minor)63 EGLBoolean eglInitialize(EGLDisplay dpy, EGLint* major, EGLint* minor) {
64 return EGL_TRUE;
65 }
66
eglTerminate(EGLDisplay dpy)67 EGLBoolean eglTerminate(EGLDisplay dpy) {
68 return EGL_TRUE;
69 }
70
eglQueryString(EGLDisplay dpy,EGLint name)71 const char* eglQueryString(EGLDisplay dpy, EGLint name) {
72 if (name == EGL_EXTENSIONS) {
73 return "EGL_KHR_swap_buffers_with_damage";
74 }
75 return "";
76 }
77
eglChooseConfig(EGLDisplay dpy,const EGLint * attrib_list,EGLConfig * configs,EGLint config_size,EGLint * num_config)78 EGLBoolean eglChooseConfig(EGLDisplay dpy, const EGLint* attrib_list, EGLConfig* configs,
79 EGLint config_size, EGLint* num_config) {
80 memset(configs, 9, sizeof(EGLConfig) * config_size);
81 *num_config = config_size;
82 return EGL_TRUE;
83 }
84
eglCreateWindowSurface(EGLDisplay dpy,EGLConfig config,EGLNativeWindowType win,const EGLint * attrib_list)85 EGLSurface eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win,
86 const EGLint* attrib_list) {
87 return (EGLSurface)malloc(sizeof(void*));
88 }
89
eglCreatePbufferSurface(EGLDisplay dpy,EGLConfig config,const EGLint * attrib_list)90 EGLSurface eglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config, const EGLint* attrib_list) {
91 return (EGLSurface)malloc(sizeof(void*));
92 }
93
eglDestroySurface(EGLDisplay dpy,EGLSurface surface)94 EGLBoolean eglDestroySurface(EGLDisplay dpy, EGLSurface surface) {
95 free(surface);
96 return EGL_TRUE;
97 }
98
eglQuerySurface(EGLDisplay dpy,EGLSurface surface,EGLint attribute,EGLint * value)99 EGLBoolean eglQuerySurface(EGLDisplay dpy, EGLSurface surface, 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, EGLint attribute, EGLint value) {
109 return EGL_TRUE;
110 }
111
eglSwapInterval(EGLDisplay dpy,EGLint interval)112 EGLBoolean eglSwapInterval(EGLDisplay dpy, EGLint interval) {
113 return EGL_TRUE;
114 }
115
eglCreateContext(EGLDisplay dpy,EGLConfig config,EGLContext share_context,const EGLint * attrib_list)116 EGLContext eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_context,
117 const EGLint* attrib_list) {
118 return (EGLContext)malloc(sizeof(void*));
119 }
eglDestroyContext(EGLDisplay dpy,EGLContext ctx)120 EGLBoolean eglDestroyContext(EGLDisplay dpy, EGLContext ctx) {
121 free(ctx);
122 return EGL_TRUE;
123 }
124
eglMakeCurrent(EGLDisplay dpy,EGLSurface draw,EGLSurface read,EGLContext ctx)125 EGLBoolean eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx) {
126 ThreadState* state = getThreadState();
127 state->surface = draw;
128 state->context = ctx;
129 return EGL_TRUE;
130 }
131
eglGetCurrentContext(void)132 EGLContext eglGetCurrentContext(void) {
133 return getThreadState()->context;
134 }
135
eglGetCurrentSurface(EGLint readdraw)136 EGLSurface eglGetCurrentSurface(EGLint readdraw) {
137 return getThreadState()->surface;
138 }
139
eglGetCurrentDisplay(void)140 EGLDisplay eglGetCurrentDisplay(void) {
141 return gDisplay;
142 }
143
eglSwapBuffers(EGLDisplay dpy,EGLSurface surface)144 EGLBoolean eglSwapBuffers(EGLDisplay dpy, EGLSurface surface) {
145 return EGL_TRUE;
146 }
147
eglSwapBuffersWithDamageKHR(EGLDisplay dpy,EGLSurface surface,EGLint * rects,EGLint rectCount)148 EGLBoolean eglSwapBuffersWithDamageKHR(EGLDisplay dpy, EGLSurface surface, EGLint* rects,
149 EGLint rectCount) {
150 return EGL_TRUE;
151 }
152
eglCreateImageKHR(EGLDisplay dpy,EGLContext ctx,EGLenum target,EGLClientBuffer buffer,const EGLint * attrib_list)153 EGLImageKHR eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target,
154 EGLClientBuffer buffer, const EGLint* attrib_list) {
155 return (EGLImageKHR)malloc(sizeof(EGLImageKHR));
156 }
157
eglCreateSyncKHR(EGLDisplay dpy,EGLenum type,const EGLint * attrib_list)158 EGLSyncKHR eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint* attrib_list) {
159 return gFence;
160 }
161
eglDestroySyncKHR(EGLDisplay dpy,EGLSyncKHR sync)162 EGLBoolean eglDestroySyncKHR(EGLDisplay dpy, EGLSyncKHR sync) {
163 return EGL_TRUE;
164 }
165
eglClientWaitSyncKHR(EGLDisplay dpy,EGLSyncKHR sync,EGLint flags,EGLTimeKHR timeout)166 EGLint eglClientWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags, EGLTimeKHR timeout) {
167 return EGL_CONDITION_SATISFIED_KHR;
168 }
169
eglDestroyImageKHR(EGLDisplay dpy,EGLImageKHR image)170 EGLBoolean eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR image) {
171 free(image);
172 return EGL_TRUE;
173 }
174
eglBeginFrame(EGLDisplay dpy,EGLSurface surface)175 void eglBeginFrame(EGLDisplay dpy, EGLSurface surface) {}
176