• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 The SwiftShader Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //    http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 // main.cpp: DLL entry point and management of thread-local data.
16 
17 #include "main.h"
18 
19 #include "libEGL.hpp"
20 #include "Context.hpp"
21 #include "Surface.hpp"
22 
23 #include "resource.h"
24 #include "Common/Thread.hpp"
25 #include "Common/SharedLibrary.hpp"
26 #include "common/debug.h"
27 
28 #include <EGL/eglext.h>
29 
30 static sw::Thread::LocalStorageKey currentTLS = TLS_OUT_OF_INDEXES;
31 
32 #if !defined(_MSC_VER)
33 #define CONSTRUCTOR __attribute__((constructor))
34 #define DESTRUCTOR __attribute__((destructor))
35 #else
36 #define CONSTRUCTOR
37 #define DESTRUCTOR
38 #endif
39 
40 namespace egl
41 {
releaseCurrent(void * storage)42 void releaseCurrent(void *storage)
43 {
44 	// This pthread destructor is called after the TLS is already reset to NULL,
45 	// so we can't call EGL functions here to do the cleanup.
46 
47 	Current *current = (Current*)storage;
48 
49 	if(current)
50 	{
51 		if(current->drawSurface)
52 		{
53 			current->drawSurface->release();
54 		}
55 
56 		if(current->readSurface)
57 		{
58 			current->readSurface->release();
59 		}
60 
61 		if(current->context)
62 		{
63 			current->context->release();
64 		}
65 
66 		free(current);
67 	}
68 }
69 
attachThread()70 Current *attachThread()
71 {
72 	TRACE("()");
73 
74 	if(currentTLS == TLS_OUT_OF_INDEXES)
75 	{
76 		currentTLS = sw::Thread::allocateLocalStorageKey(releaseCurrent);
77 	}
78 
79 	Current *current = (Current*)sw::Thread::allocateLocalStorage(currentTLS, sizeof(Current));
80 
81 	current->error = EGL_SUCCESS;
82 	current->API = EGL_OPENGL_ES_API;
83 	current->context = nullptr;
84 	current->drawSurface = nullptr;
85 	current->readSurface = nullptr;
86 
87 	return current;
88 }
89 
detachThread()90 void detachThread()
91 {
92 	TRACE("()");
93 
94 	eglMakeCurrent(EGL_NO_DISPLAY, EGL_NO_CONTEXT, EGL_NO_SURFACE, EGL_NO_SURFACE);
95 
96 	sw::Thread::freeLocalStorage(currentTLS);
97 }
98 
attachProcess()99 CONSTRUCTOR void attachProcess()
100 {
101 	TRACE("()");
102 
103 	#if !defined(ANGLE_DISABLE_TRACE) && defined(TRACE_OUTPUT_FILE)
104 		FILE *debug = fopen(TRACE_OUTPUT_FILE, "rt");
105 
106 		if(debug)
107 		{
108 			fclose(debug);
109 			debug = fopen(TRACE_OUTPUT_FILE, "wt");   // Erase
110 			fclose(debug);
111 		}
112 	#endif
113 
114 	attachThread();
115 }
116 
detachProcess()117 DESTRUCTOR void detachProcess()
118 {
119 	TRACE("()");
120 
121 	detachThread();
122 	sw::Thread::freeLocalStorageKey(currentTLS);
123 }
124 }
125 
126 #if defined(_WIN32)
127 #ifdef DEBUGGER_WAIT_DIALOG
DebuggerWaitDialogProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)128 static INT_PTR CALLBACK DebuggerWaitDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
129 {
130 	RECT rect;
131 
132 	switch(uMsg)
133 	{
134 	case WM_INITDIALOG:
135 		GetWindowRect(GetDesktopWindow(), &rect);
136 		SetWindowPos(hwnd, HWND_TOP, rect.right / 2, rect.bottom / 2, 0, 0, SWP_NOSIZE);
137 		SetTimer(hwnd, 1, 100, NULL);
138 		return TRUE;
139 	case WM_COMMAND:
140 		if(LOWORD(wParam) == IDCANCEL)
141 		{
142 			EndDialog(hwnd, 0);
143 		}
144 		break;
145 	case WM_TIMER:
146 		if(IsDebuggerPresent())
147 		{
148 			EndDialog(hwnd, 0);
149 		}
150 	}
151 
152 	return FALSE;
153 }
154 
WaitForDebugger(HINSTANCE instance)155 static void WaitForDebugger(HINSTANCE instance)
156 {
157 	if(!IsDebuggerPresent())
158 	{
159 		HRSRC dialog = FindResource(instance, MAKEINTRESOURCE(IDD_DIALOG1), RT_DIALOG);
160 		DLGTEMPLATE *dialogTemplate = (DLGTEMPLATE*)LoadResource(instance, dialog);
161 		DialogBoxIndirect(instance, dialogTemplate, NULL, DebuggerWaitDialogProc);
162 	}
163 }
164 #endif
165 
DllMain(HINSTANCE instance,DWORD reason,LPVOID reserved)166 extern "C" BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved)
167 {
168 	switch(reason)
169 	{
170 	case DLL_PROCESS_ATTACH:
171 		#ifdef DEBUGGER_WAIT_DIALOG
172 			WaitForDebugger(instance);
173 		#endif
174 		egl::attachProcess();
175 		break;
176 	case DLL_THREAD_ATTACH:
177 		egl::attachThread();
178 		break;
179 	case DLL_THREAD_DETACH:
180 		egl::detachThread();
181 		break;
182 	case DLL_PROCESS_DETACH:
183 		egl::detachProcess();
184 		break;
185 	default:
186 		break;
187 	}
188 
189 	return TRUE;
190 }
191 #endif
192 
193 namespace egl
194 {
getCurrent(void)195 static Current *getCurrent(void)
196 {
197 	Current *current = (Current*)sw::Thread::getLocalStorage(currentTLS);
198 
199 	if(!current)
200 	{
201 		current = attachThread();
202 	}
203 
204 	return current;
205 }
206 
setCurrentError(EGLint error)207 void setCurrentError(EGLint error)
208 {
209 	Current *current = getCurrent();
210 
211 	current->error = error;
212 }
213 
getCurrentError()214 EGLint getCurrentError()
215 {
216 	Current *current = getCurrent();
217 
218 	return current->error;
219 }
220 
setCurrentAPI(EGLenum API)221 void setCurrentAPI(EGLenum API)
222 {
223 	Current *current = getCurrent();
224 
225 	current->API = API;
226 }
227 
getCurrentAPI()228 EGLenum getCurrentAPI()
229 {
230 	Current *current = getCurrent();
231 
232 	return current->API;
233 }
234 
setCurrentContext(egl::Context * ctx)235 void setCurrentContext(egl::Context *ctx)
236 {
237 	Current *current = getCurrent();
238 
239 	if(ctx)
240 	{
241 		ctx->addRef();
242 	}
243 
244 	if(current->context)
245 	{
246 		current->context->release();
247 	}
248 
249 	current->context = ctx;
250 }
251 
getCurrentContext()252 NO_SANITIZE_FUNCTION egl::Context *getCurrentContext()
253 {
254 	Current *current = getCurrent();
255 
256 	return current->context;
257 }
258 
setCurrentDrawSurface(egl::Surface * surface)259 void setCurrentDrawSurface(egl::Surface *surface)
260 {
261 	Current *current = getCurrent();
262 
263 	if(surface)
264 	{
265 		surface->addRef();
266 	}
267 
268 	if(current->drawSurface)
269 	{
270 		current->drawSurface->release();
271 	}
272 
273 	current->drawSurface = surface;
274 }
275 
getCurrentDrawSurface()276 egl::Surface *getCurrentDrawSurface()
277 {
278 	Current *current = getCurrent();
279 
280 	return current->drawSurface;
281 }
282 
setCurrentReadSurface(egl::Surface * surface)283 void setCurrentReadSurface(egl::Surface *surface)
284 {
285 	Current *current = getCurrent();
286 
287 	if(surface)
288 	{
289 		surface->addRef();
290 	}
291 
292 	if(current->readSurface)
293 	{
294 		current->readSurface->release();
295 	}
296 
297 	current->readSurface = surface;
298 }
299 
getCurrentReadSurface()300 egl::Surface *getCurrentReadSurface()
301 {
302 	Current *current = getCurrent();
303 
304 	return current->readSurface;
305 }
306 
error(EGLint errorCode)307 void error(EGLint errorCode)
308 {
309 	egl::setCurrentError(errorCode);
310 
311 	if(errorCode != EGL_SUCCESS)
312 	{
313 		switch(errorCode)
314 		{
315 		case EGL_NOT_INITIALIZED:     TRACE("\t! Error generated: not initialized\n");     break;
316 		case EGL_BAD_ACCESS:          TRACE("\t! Error generated: bad access\n");          break;
317 		case EGL_BAD_ALLOC:           TRACE("\t! Error generated: bad alloc\n");           break;
318 		case EGL_BAD_ATTRIBUTE:       TRACE("\t! Error generated: bad attribute\n");       break;
319 		case EGL_BAD_CONFIG:          TRACE("\t! Error generated: bad config\n");          break;
320 		case EGL_BAD_CONTEXT:         TRACE("\t! Error generated: bad context\n");         break;
321 		case EGL_BAD_CURRENT_SURFACE: TRACE("\t! Error generated: bad current surface\n"); break;
322 		case EGL_BAD_DISPLAY:         TRACE("\t! Error generated: bad display\n");         break;
323 		case EGL_BAD_MATCH:           TRACE("\t! Error generated: bad match\n");           break;
324 		case EGL_BAD_NATIVE_PIXMAP:   TRACE("\t! Error generated: bad native pixmap\n");   break;
325 		case EGL_BAD_NATIVE_WINDOW:   TRACE("\t! Error generated: bad native window\n");   break;
326 		case EGL_BAD_PARAMETER:       TRACE("\t! Error generated: bad parameter\n");       break;
327 		case EGL_BAD_SURFACE:         TRACE("\t! Error generated: bad surface\n");         break;
328 		case EGL_CONTEXT_LOST:        TRACE("\t! Error generated: context lost\n");        break;
329 		default:                      TRACE("\t! Error generated: <0x%X>\n", errorCode);   break;
330 		}
331 	}
332 }
333 }
334 
335 namespace egl
336 {
337 EGLint GetError(void);
338 EGLDisplay GetDisplay(EGLNativeDisplayType display_id);
339 EGLBoolean Initialize(EGLDisplay dpy, EGLint *major, EGLint *minor);
340 EGLBoolean Terminate(EGLDisplay dpy);
341 const char *QueryString(EGLDisplay dpy, EGLint name);
342 EGLBoolean GetConfigs(EGLDisplay dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config);
343 EGLBoolean ChooseConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config);
344 EGLBoolean GetConfigAttrib(EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value);
345 EGLSurface CreateWindowSurface(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType window, const EGLint *attrib_list);
346 EGLSurface CreatePbufferSurface(EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list);
347 EGLSurface CreatePixmapSurface(EGLDisplay dpy, EGLConfig config, EGLNativePixmapType pixmap, const EGLint *attrib_list);
348 EGLBoolean DestroySurface(EGLDisplay dpy, EGLSurface surface);
349 EGLBoolean QuerySurface(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint *value);
350 EGLBoolean BindAPI(EGLenum api);
351 EGLenum QueryAPI(void);
352 EGLBoolean WaitClient(void);
353 EGLBoolean ReleaseThread(void);
354 EGLSurface CreatePbufferFromClientBuffer(EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, EGLConfig config, const EGLint *attrib_list);
355 EGLBoolean SurfaceAttrib(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value);
356 EGLBoolean BindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer);
357 EGLBoolean ReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer);
358 EGLBoolean SwapInterval(EGLDisplay dpy, EGLint interval);
359 EGLContext CreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list);
360 EGLBoolean DestroyContext(EGLDisplay dpy, EGLContext ctx);
361 EGLBoolean MakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx);
362 EGLContext GetCurrentContext(void);
363 EGLSurface GetCurrentSurface(EGLint readdraw);
364 EGLDisplay GetCurrentDisplay(void);
365 EGLBoolean QueryContext(EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint *value);
366 EGLBoolean WaitGL(void);
367 EGLBoolean WaitNative(EGLint engine);
368 EGLBoolean SwapBuffers(EGLDisplay dpy, EGLSurface surface);
369 EGLBoolean CopyBuffers(EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target);
370 EGLImageKHR CreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list);
371 EGLImageKHR CreateImage(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLAttrib *attrib_list);
372 EGLBoolean DestroyImageKHR(EGLDisplay dpy, EGLImageKHR image);
373 EGLDisplay GetPlatformDisplayEXT(EGLenum platform, void *native_display, const EGLint *attrib_list);
374 EGLDisplay GetPlatformDisplay(EGLenum platform, void *native_display, const EGLAttrib *attrib_list);
375 EGLSurface CreatePlatformWindowSurfaceEXT(EGLDisplay dpy, EGLConfig config, void *native_window, const EGLint *attrib_list);
376 EGLSurface CreatePlatformWindowSurface(EGLDisplay dpy, EGLConfig config, void *native_window, const EGLAttrib *attrib_list);
377 EGLSurface CreatePlatformPixmapSurfaceEXT(EGLDisplay dpy, EGLConfig config, void *native_pixmap, const EGLint *attrib_list);
378 EGLSurface CreatePlatformPixmapSurface(EGLDisplay dpy, EGLConfig config, void *native_pixmap, const EGLAttrib *attrib_list);
379 EGLSyncKHR CreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint *attrib_list);
380 EGLSyncKHR CreateSync(EGLDisplay dpy, EGLenum type, const EGLAttrib *attrib_list);
381 EGLBoolean DestroySyncKHR(EGLDisplay dpy, EGLSyncKHR sync);
382 EGLint ClientWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags, EGLTimeKHR timeout);
383 EGLBoolean GetSyncAttribKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint attribute, EGLint *value);
384 EGLBoolean GetSyncAttrib(EGLDisplay dpy, EGLSyncKHR sync, EGLint attribute, EGLAttrib *value);
385 __eglMustCastToProperFunctionPointerType GetProcAddress(const char *procname);
386 }
387 
388 extern "C"
389 {
eglGetError(void)390 EGLAPI EGLint EGLAPIENTRY eglGetError(void)
391 {
392 	return egl::GetError();
393 }
394 
eglGetDisplay(EGLNativeDisplayType display_id)395 EGLAPI EGLDisplay EGLAPIENTRY eglGetDisplay(EGLNativeDisplayType display_id)
396 {
397 	return egl::GetDisplay(display_id);
398 }
399 
eglInitialize(EGLDisplay dpy,EGLint * major,EGLint * minor)400 EGLAPI EGLBoolean EGLAPIENTRY eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor)
401 {
402 	return egl::Initialize(dpy, major, minor);
403 }
404 
eglTerminate(EGLDisplay dpy)405 EGLAPI EGLBoolean EGLAPIENTRY eglTerminate(EGLDisplay dpy)
406 {
407 	return egl::Terminate(dpy);
408 }
409 
eglQueryString(EGLDisplay dpy,EGLint name)410 EGLAPI const char *EGLAPIENTRY eglQueryString(EGLDisplay dpy, EGLint name)
411 {
412 	return egl::QueryString(dpy, name);
413 }
414 
eglGetConfigs(EGLDisplay dpy,EGLConfig * configs,EGLint config_size,EGLint * num_config)415 EGLAPI EGLBoolean EGLAPIENTRY eglGetConfigs(EGLDisplay dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config)
416 {
417 	return egl::GetConfigs(dpy, configs, config_size, num_config);
418 }
419 
eglChooseConfig(EGLDisplay dpy,const EGLint * attrib_list,EGLConfig * configs,EGLint config_size,EGLint * num_config)420 EGLAPI EGLBoolean EGLAPIENTRY eglChooseConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config)
421 {
422 	return egl::ChooseConfig(dpy, attrib_list, configs, config_size, num_config);
423 }
424 
eglGetConfigAttrib(EGLDisplay dpy,EGLConfig config,EGLint attribute,EGLint * value)425 EGLAPI EGLBoolean EGLAPIENTRY eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value)
426 {
427 	return egl::GetConfigAttrib(dpy, config, attribute, value);
428 }
429 
eglCreateWindowSurface(EGLDisplay dpy,EGLConfig config,EGLNativeWindowType window,const EGLint * attrib_list)430 EGLAPI EGLSurface EGLAPIENTRY eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType window, const EGLint *attrib_list)
431 {
432 	return egl::CreateWindowSurface(dpy, config, window, attrib_list);
433 }
434 
eglCreatePbufferSurface(EGLDisplay dpy,EGLConfig config,const EGLint * attrib_list)435 EGLAPI EGLSurface EGLAPIENTRY eglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list)
436 {
437 	return egl::CreatePbufferSurface(dpy, config, attrib_list);
438 }
439 
eglCreatePixmapSurface(EGLDisplay dpy,EGLConfig config,EGLNativePixmapType pixmap,const EGLint * attrib_list)440 EGLAPI EGLSurface EGLAPIENTRY eglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config, EGLNativePixmapType pixmap, const EGLint *attrib_list)
441 {
442 	return egl::CreatePixmapSurface(dpy, config, pixmap, attrib_list);
443 }
444 
eglDestroySurface(EGLDisplay dpy,EGLSurface surface)445 EGLAPI EGLBoolean EGLAPIENTRY eglDestroySurface(EGLDisplay dpy, EGLSurface surface)
446 {
447 	return egl::DestroySurface(dpy, surface);
448 }
449 
eglQuerySurface(EGLDisplay dpy,EGLSurface surface,EGLint attribute,EGLint * value)450 EGLAPI EGLBoolean EGLAPIENTRY eglQuerySurface(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint *value)
451 {
452 	return egl::QuerySurface(dpy, surface, attribute, value);
453 }
454 
eglBindAPI(EGLenum api)455 EGLAPI EGLBoolean EGLAPIENTRY eglBindAPI(EGLenum api)
456 {
457 	return egl::BindAPI(api);
458 }
459 
eglQueryAPI(void)460 EGLAPI EGLenum EGLAPIENTRY eglQueryAPI(void)
461 {
462 	return egl::QueryAPI();
463 }
464 
eglWaitClient(void)465 EGLAPI EGLBoolean EGLAPIENTRY eglWaitClient(void)
466 {
467 	return egl::WaitClient();
468 }
469 
eglReleaseThread(void)470 EGLAPI EGLBoolean EGLAPIENTRY eglReleaseThread(void)
471 {
472 	return egl::ReleaseThread();
473 }
474 
eglCreatePbufferFromClientBuffer(EGLDisplay dpy,EGLenum buftype,EGLClientBuffer buffer,EGLConfig config,const EGLint * attrib_list)475 EGLAPI EGLSurface EGLAPIENTRY eglCreatePbufferFromClientBuffer(EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, EGLConfig config, const EGLint *attrib_list)
476 {
477 	return egl::CreatePbufferFromClientBuffer(dpy, buftype, buffer, config, attrib_list);
478 }
479 
eglSurfaceAttrib(EGLDisplay dpy,EGLSurface surface,EGLint attribute,EGLint value)480 EGLAPI EGLBoolean EGLAPIENTRY eglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value)
481 {
482 	return egl::SurfaceAttrib(dpy, surface, attribute, value);
483 }
484 
eglBindTexImage(EGLDisplay dpy,EGLSurface surface,EGLint buffer)485 EGLAPI EGLBoolean EGLAPIENTRY eglBindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer)
486 {
487 	return egl::BindTexImage(dpy, surface, buffer);
488 }
489 
eglReleaseTexImage(EGLDisplay dpy,EGLSurface surface,EGLint buffer)490 EGLAPI EGLBoolean EGLAPIENTRY eglReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer)
491 {
492 	return egl::ReleaseTexImage(dpy, surface, buffer);
493 }
494 
eglSwapInterval(EGLDisplay dpy,EGLint interval)495 EGLAPI EGLBoolean EGLAPIENTRY eglSwapInterval(EGLDisplay dpy, EGLint interval)
496 {
497 	return egl::SwapInterval(dpy, interval);
498 }
499 
eglCreateContext(EGLDisplay dpy,EGLConfig config,EGLContext share_context,const EGLint * attrib_list)500 EGLAPI EGLContext EGLAPIENTRY eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list)
501 {
502 	return egl::CreateContext(dpy, config, share_context, attrib_list);
503 }
504 
eglDestroyContext(EGLDisplay dpy,EGLContext ctx)505 EGLAPI EGLBoolean EGLAPIENTRY eglDestroyContext(EGLDisplay dpy, EGLContext ctx)
506 {
507 	return egl::DestroyContext(dpy, ctx);
508 }
509 
eglMakeCurrent(EGLDisplay dpy,EGLSurface draw,EGLSurface read,EGLContext ctx)510 EGLAPI EGLBoolean EGLAPIENTRY eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx)
511 {
512 	return egl::MakeCurrent(dpy, draw, read, ctx);
513 }
514 
eglGetCurrentContext(void)515 EGLAPI EGLContext EGLAPIENTRY eglGetCurrentContext(void)
516 {
517 	return egl::GetCurrentContext();
518 }
519 
eglGetCurrentSurface(EGLint readdraw)520 EGLAPI EGLSurface EGLAPIENTRY eglGetCurrentSurface(EGLint readdraw)
521 {
522 	return egl::GetCurrentSurface(readdraw);
523 }
524 
eglGetCurrentDisplay(void)525 EGLAPI EGLDisplay EGLAPIENTRY eglGetCurrentDisplay(void)
526 {
527 	return egl::GetCurrentDisplay();
528 }
529 
eglQueryContext(EGLDisplay dpy,EGLContext ctx,EGLint attribute,EGLint * value)530 EGLAPI EGLBoolean EGLAPIENTRY eglQueryContext(EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint *value)
531 {
532 	return egl::QueryContext(dpy, ctx, attribute, value);
533 }
534 
eglWaitGL(void)535 EGLAPI EGLBoolean EGLAPIENTRY eglWaitGL(void)
536 {
537 	return egl::WaitClient();
538 }
539 
eglWaitNative(EGLint engine)540 EGLAPI EGLBoolean EGLAPIENTRY eglWaitNative(EGLint engine)
541 {
542 	return egl::WaitNative(engine);
543 }
544 
eglSwapBuffers(EGLDisplay dpy,EGLSurface surface)545 EGLAPI EGLBoolean EGLAPIENTRY eglSwapBuffers(EGLDisplay dpy, EGLSurface surface)
546 {
547 	return egl::SwapBuffers(dpy, surface);
548 }
549 
eglCopyBuffers(EGLDisplay dpy,EGLSurface surface,EGLNativePixmapType target)550 EGLAPI EGLBoolean EGLAPIENTRY eglCopyBuffers(EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target)
551 {
552 	return egl::CopyBuffers(dpy, surface, target);
553 }
554 
eglCreateImageKHR(EGLDisplay dpy,EGLContext ctx,EGLenum target,EGLClientBuffer buffer,const EGLint * attrib_list)555 EGLAPI EGLImageKHR EGLAPIENTRY eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list)
556 {
557 	return egl::CreateImageKHR(dpy, ctx, target, buffer, attrib_list);
558 }
559 
eglCreateImage(EGLDisplay dpy,EGLContext ctx,EGLenum target,EGLClientBuffer buffer,const EGLAttrib * attrib_list)560 EGLAPI EGLImageKHR EGLAPIENTRY eglCreateImage(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLAttrib *attrib_list)
561 {
562 	return egl::CreateImage(dpy, ctx, target, buffer, attrib_list);
563 }
564 
eglDestroyImageKHR(EGLDisplay dpy,EGLImageKHR image)565 EGLAPI EGLBoolean EGLAPIENTRY eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR image)
566 {
567 	return egl::DestroyImageKHR(dpy, image);
568 }
569 
eglDestroyImage(EGLDisplay dpy,EGLImageKHR image)570 EGLAPI EGLBoolean EGLAPIENTRY eglDestroyImage(EGLDisplay dpy, EGLImageKHR image)
571 {
572 	return egl::DestroyImageKHR(dpy, image);
573 }
574 
eglGetPlatformDisplayEXT(EGLenum platform,void * native_display,const EGLint * attrib_list)575 EGLAPI EGLDisplay EGLAPIENTRY eglGetPlatformDisplayEXT(EGLenum platform, void *native_display, const EGLint *attrib_list)
576 {
577 	return egl::GetPlatformDisplayEXT(platform, native_display, attrib_list);
578 }
579 
eglGetPlatformDisplay(EGLenum platform,void * native_display,const EGLAttrib * attrib_list)580 EGLAPI EGLDisplay EGLAPIENTRY eglGetPlatformDisplay(EGLenum platform, void *native_display, const EGLAttrib *attrib_list)
581 {
582 	return egl::GetPlatformDisplay(platform, native_display, attrib_list);
583 }
584 
eglCreatePlatformWindowSurfaceEXT(EGLDisplay dpy,EGLConfig config,void * native_window,const EGLint * attrib_list)585 EGLAPI EGLSurface EGLAPIENTRY eglCreatePlatformWindowSurfaceEXT(EGLDisplay dpy, EGLConfig config, void *native_window, const EGLint *attrib_list)
586 {
587 	return egl::CreatePlatformWindowSurfaceEXT(dpy, config, native_window, attrib_list);
588 }
589 
eglCreatePlatformWindowSurface(EGLDisplay dpy,EGLConfig config,void * native_window,const EGLAttrib * attrib_list)590 EGLAPI EGLSurface EGLAPIENTRY eglCreatePlatformWindowSurface(EGLDisplay dpy, EGLConfig config, void *native_window, const EGLAttrib *attrib_list)
591 {
592 	return egl::CreatePlatformWindowSurface(dpy, config, native_window, attrib_list);
593 }
594 
eglCreatePlatformPixmapSurfaceEXT(EGLDisplay dpy,EGLConfig config,void * native_pixmap,const EGLint * attrib_list)595 EGLAPI EGLSurface EGLAPIENTRY eglCreatePlatformPixmapSurfaceEXT(EGLDisplay dpy, EGLConfig config, void *native_pixmap, const EGLint *attrib_list)
596 {
597 	return egl::CreatePlatformPixmapSurfaceEXT(dpy, config, native_pixmap, attrib_list);
598 }
599 
eglCreatePlatformPixmapSurface(EGLDisplay dpy,EGLConfig config,void * native_pixmap,const EGLAttrib * attrib_list)600 EGLAPI EGLSurface EGLAPIENTRY eglCreatePlatformPixmapSurface(EGLDisplay dpy, EGLConfig config, void *native_pixmap, const EGLAttrib *attrib_list)
601 {
602 	return egl::CreatePlatformPixmapSurface(dpy, config, native_pixmap, attrib_list);
603 }
604 
eglCreateSyncKHR(EGLDisplay dpy,EGLenum type,const EGLint * attrib_list)605 EGLAPI EGLSyncKHR EGLAPIENTRY eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint *attrib_list)
606 {
607 	return egl::CreateSyncKHR(dpy, type, attrib_list);
608 }
609 
eglCreateSync(EGLDisplay dpy,EGLenum type,const EGLAttrib * attrib_list)610 EGLAPI EGLSyncKHR EGLAPIENTRY eglCreateSync(EGLDisplay dpy, EGLenum type, const EGLAttrib *attrib_list)
611 {
612 	return egl::CreateSync(dpy, type, attrib_list);
613 }
614 
eglDestroySyncKHR(EGLDisplay dpy,EGLSyncKHR sync)615 EGLAPI EGLBoolean EGLAPIENTRY eglDestroySyncKHR(EGLDisplay dpy, EGLSyncKHR sync)
616 {
617 	return egl::DestroySyncKHR(dpy, sync);
618 }
619 
eglDestroySync(EGLDisplay dpy,EGLSyncKHR sync)620 EGLAPI EGLBoolean EGLAPIENTRY eglDestroySync(EGLDisplay dpy, EGLSyncKHR sync)
621 {
622 	return egl::DestroySyncKHR(dpy, sync);
623 }
624 
eglClientWaitSyncKHR(EGLDisplay dpy,EGLSyncKHR sync,EGLint flags,EGLTimeKHR timeout)625 EGLAPI EGLint EGLAPIENTRY eglClientWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags, EGLTimeKHR timeout)
626 {
627 	return egl::ClientWaitSyncKHR(dpy, sync, flags, timeout);
628 }
629 
eglClientWaitSync(EGLDisplay dpy,EGLSyncKHR sync,EGLint flags,EGLTimeKHR timeout)630 EGLAPI EGLint EGLAPIENTRY eglClientWaitSync(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags, EGLTimeKHR timeout)
631 {
632 	return egl::ClientWaitSyncKHR(dpy, sync, flags, timeout);
633 }
634 
eglGetSyncAttribKHR(EGLDisplay dpy,EGLSyncKHR sync,EGLint attribute,EGLint * value)635 EGLAPI EGLBoolean EGLAPIENTRY eglGetSyncAttribKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint attribute, EGLint *value)
636 {
637 	return egl::GetSyncAttribKHR(dpy, sync, attribute, value);
638 }
639 
eglGetSyncAttrib(EGLDisplay dpy,EGLSyncKHR sync,EGLint attribute,EGLAttrib * value)640 EGLAPI EGLBoolean EGLAPIENTRY eglGetSyncAttrib(EGLDisplay dpy, EGLSyncKHR sync, EGLint attribute, EGLAttrib *value)
641 {
642 	return egl::GetSyncAttrib(dpy, sync, attribute, value);
643 }
644 
eglWaitSyncKHR(EGLDisplay dpy,EGLSyncKHR sync,EGLint flags)645 EGLAPI EGLint EGLAPIENTRY eglWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags)
646 {
647 	return egl::ClientWaitSyncKHR(dpy, sync, flags, EGL_FOREVER_KHR);
648 }
649 
eglWaitSync(EGLDisplay dpy,EGLSync sync,EGLint flags)650 EGLAPI EGLBoolean EGLAPIENTRY eglWaitSync(EGLDisplay dpy, EGLSync sync, EGLint flags)
651 {
652 	return egl::ClientWaitSyncKHR(dpy, sync, flags, EGL_FOREVER_KHR);
653 }
654 
eglGetProcAddress(const char * procname)655 EGLAPI __eglMustCastToProperFunctionPointerType EGLAPIENTRY eglGetProcAddress(const char *procname)
656 {
657 	return egl::GetProcAddress(procname);
658 }
659 }
660 
LibEGLexports()661 LibEGLexports::LibEGLexports()
662 {
663 	this->eglGetError = egl::GetError;
664 	this->eglGetDisplay = egl::GetDisplay;
665 	this->eglInitialize = egl::Initialize;
666 	this->eglTerminate = egl::Terminate;
667 	this->eglQueryString = egl::QueryString;
668 	this->eglGetConfigs = egl::GetConfigs;
669 	this->eglChooseConfig = egl::ChooseConfig;
670 	this->eglGetConfigAttrib = egl::GetConfigAttrib;
671 	this->eglCreateWindowSurface = egl::CreateWindowSurface;
672 	this->eglCreatePbufferSurface = egl::CreatePbufferSurface;
673 	this->eglCreatePixmapSurface = egl::CreatePixmapSurface;
674 	this->eglDestroySurface = egl::DestroySurface;
675 	this->eglQuerySurface = egl::QuerySurface;
676 	this->eglBindAPI = egl::BindAPI;
677 	this->eglQueryAPI = egl::QueryAPI;
678 	this->eglWaitClient = egl::WaitClient;
679 	this->eglReleaseThread = egl::ReleaseThread;
680 	this->eglCreatePbufferFromClientBuffer = egl::CreatePbufferFromClientBuffer;
681 	this->eglSurfaceAttrib = egl::SurfaceAttrib;
682 	this->eglBindTexImage = egl::BindTexImage;
683 	this->eglReleaseTexImage = egl::ReleaseTexImage;
684 	this->eglSwapInterval = egl::SwapInterval;
685 	this->eglCreateContext = egl::CreateContext;
686 	this->eglDestroyContext = egl::DestroyContext;
687 	this->eglMakeCurrent = egl::MakeCurrent;
688 	this->eglGetCurrentContext = egl::GetCurrentContext;
689 	this->eglGetCurrentSurface = egl::GetCurrentSurface;
690 	this->eglGetCurrentDisplay = egl::GetCurrentDisplay;
691 	this->eglQueryContext = egl::QueryContext;
692 	this->eglWaitGL = egl::WaitGL;
693 	this->eglWaitNative = egl::WaitNative;
694 	this->eglSwapBuffers = egl::SwapBuffers;
695 	this->eglCopyBuffers = egl::CopyBuffers;
696 	this->eglCreateImageKHR = egl::CreateImageKHR;
697 	this->eglDestroyImageKHR = egl::DestroyImageKHR;
698 	this->eglGetProcAddress = egl::GetProcAddress;
699 	this->eglCreateSyncKHR = egl::CreateSyncKHR;
700 	this->eglDestroySyncKHR = egl::DestroySyncKHR;
701 	this->eglClientWaitSyncKHR = egl::ClientWaitSyncKHR;
702 	this->eglGetSyncAttribKHR = egl::GetSyncAttribKHR;
703 
704 	this->clientGetCurrentContext = egl::getCurrentContext;
705 }
706 
libEGL_swiftshader()707 extern "C" EGLAPI LibEGLexports *libEGL_swiftshader()
708 {
709 	static LibEGLexports libEGL;
710 	return &libEGL;
711 }
712 
713 LibGLES_CM libGLES_CM;
714 LibGLESv2 libGLESv2;
715