1 /*
2 * Copyright (C) 2011 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 #ifndef GL_DISPATCHH
17 #define GL_DISPATCHH
18 
19 #include <GLES/gl.h>
20 #include <GLES2/gl2.h>
21 #include <GLES3/gl3.h>
22 
23 #include "aemu/base/synchronization/Lock.h"
24 #include "host-common/logging.h"
25 
26 #include "OpenGLESDispatch/gldefs.h"
27 #include "OpenGLESDispatch/gles_functions.h"
28 #include "GLutils.h"
29 
30 #include <functional>
31 
32 #define GLAPIENTRY GL_APIENTRY
33 typedef void (*FUNCPTR_NO_ARGS_RET_VOID)();
34 typedef int (*FUNCPTR_NO_ARGS_RET_INT)();
35 typedef GLsync (*FUNCPTR_FENCE_SYNC)(GLenum, GLbitfield);
36 typedef GLenum (*FUNCPTR_CLIENT_WAIT_SYNC)(GLsync, GLbitfield, GLuint64);
37 typedef void (*FUNCPTR_DELETE_SYNC)(GLsync);
38 typedef void (*FUNCPTR_WAIT_SYNC)(GLsync, GLbitfield, GLuint64);
39 typedef void (*FUNCPTR_GET_SYNC_IV)(GLsync, GLenum pname, GLsizei bufsize, GLsizei *length, GLint *values);
40 
41 class GlLibrary;
42 
43 
44 #define GLES_DECLARE_METHOD(return_type, function_name, signature, args) \
45     static return_type (*function_name) signature;
46 
47 #if defined(ENABLE_DISPATCH_LOG)
48 #define GLES_DECLARE_UNDERLYING_METHOD(return_type, function_name, signature, args) \
49     static return_type (*function_name ## _underlying) signature;
50 #endif
51 
52 using EGLGetProcAddressFunc = std::function<void*(const char* name)>;
53 
54 class GLDispatch {
55 public:
56     // Constructor.
57     GLDispatch();
58 
59     bool isInitialized() const;
60     void dispatchFuncs(GLESVersion version, GlLibrary* glLib, EGLGetProcAddressFunc eglGPA);
61     GLESVersion getGLESVersion() const;
62 
63     LIST_GLES_FUNCTIONS(GLES_DECLARE_METHOD, GLES_DECLARE_METHOD)
64 
65     #if defined(ENABLE_DISPATCH_LOG)
66     LIST_GLES_FUNCTIONS(GLES_DECLARE_UNDERLYING_METHOD, GLES_DECLARE_UNDERLYING_METHOD)
67     #endif
68 
69 private:
70     bool                  m_isLoaded;
71     GLESVersion           m_version;
72     static android::base::Lock   s_lock;
73 };
74 
75 #endif  // GL_DISPATCH_H
76