1 /*
2  * Copyright 2014 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 #include "include/gpu/gl/GrGLAssembleInterface.h"
8 #include "include/gpu/gl/GrGLInterface.h"
9 #include "src/gpu/gl/GrGLUtil.h"
10 
11 #include <EGL/egl.h>
12 #ifndef GL_GLEXT_PROTOTYPES
13 #define GL_GLEXT_PROTOTYPES
14 #endif
15 #include <GLES2/gl2.h>
16 
egl_get_gl_proc(void * ctx,const char name[])17 static GrGLFuncPtr egl_get_gl_proc(void* ctx, const char name[]) {
18     SkASSERT(nullptr == ctx);
19     // https://www.khronos.org/registry/EGL/extensions/KHR/EGL_KHR_get_all_proc_addresses.txt
20     // eglGetProcAddress() is not guaranteed to support the querying of non-extension EGL functions.
21     #define M(X) if (0 == strcmp(#X, name)) { return (GrGLFuncPtr) X; }
22     M(eglGetCurrentDisplay)
23     M(eglQueryString)
24     M(glActiveTexture)
25     M(glAttachShader)
26     M(glBindAttribLocation)
27     M(glBindBuffer)
28     M(glBindFramebuffer)
29     M(glBindRenderbuffer)
30     M(glBindTexture)
31     M(glBlendColor)
32     M(glBlendEquation)
33     M(glBlendFunc)
34     M(glBufferData)
35     M(glBufferSubData)
36     M(glCheckFramebufferStatus)
37     M(glClear)
38     M(glClearColor)
39     M(glClearStencil)
40     M(glColorMask)
41     M(glCompileShader)
42     M(glCompressedTexImage2D)
43     M(glCompressedTexSubImage2D)
44     M(glCopyTexSubImage2D)
45     M(glCreateProgram)
46     M(glCreateShader)
47     M(glCullFace)
48     M(glDeleteBuffers)
49     M(glDeleteFramebuffers)
50     M(glDeleteProgram)
51     M(glDeleteRenderbuffers)
52     M(glDeleteShader)
53     M(glDeleteTextures)
54     M(glDepthMask)
55     M(glDisable)
56     M(glDisableVertexAttribArray)
57     M(glDrawArrays)
58     M(glDrawElements)
59     M(glEnable)
60     M(glEnableVertexAttribArray)
61     M(glFinish)
62     M(glFlush)
63     M(glFramebufferRenderbuffer)
64     M(glFramebufferTexture2D)
65     M(glFrontFace)
66     M(glGenBuffers)
67     M(glGenFramebuffers)
68     M(glGenRenderbuffers)
69     M(glGenTextures)
70     M(glGenerateMipmap)
71     M(glGetBufferParameteriv)
72     M(glGetError)
73     M(glGetFramebufferAttachmentParameteriv)
74     M(glGetIntegerv)
75     M(glGetProgramInfoLog)
76     M(glGetProgramiv)
77     M(glGetRenderbufferParameteriv)
78     M(glGetShaderInfoLog)
79     M(glGetShaderPrecisionFormat)
80     M(glGetShaderiv)
81     M(glGetString)
82     M(glGetUniformLocation)
83     M(glIsTexture)
84     M(glLineWidth)
85     M(glLinkProgram)
86     M(glPixelStorei)
87     M(glReadPixels)
88     M(glRenderbufferStorage)
89     M(glScissor)
90     M(glShaderSource)
91     M(glStencilFunc)
92     M(glStencilFuncSeparate)
93     M(glStencilMask)
94     M(glStencilMaskSeparate)
95     M(glStencilOp)
96     M(glStencilOpSeparate)
97     M(glTexImage2D)
98     M(glTexParameterf)
99     M(glTexParameterfv)
100     M(glTexParameteri)
101     M(glTexParameteriv)
102     M(glTexSubImage2D)
103     M(glUniform1f)
104     M(glUniform1fv)
105     M(glUniform1i)
106     M(glUniform1iv)
107     M(glUniform2f)
108     M(glUniform2fv)
109     M(glUniform2i)
110     M(glUniform2iv)
111     M(glUniform3f)
112     M(glUniform3fv)
113     M(glUniform3i)
114     M(glUniform3iv)
115     M(glUniform4f)
116     M(glUniform4fv)
117     M(glUniform4i)
118     M(glUniform4iv)
119     M(glUniformMatrix2fv)
120     M(glUniformMatrix3fv)
121     M(glUniformMatrix4fv)
122     M(glUseProgram)
123     M(glVertexAttrib1f)
124     M(glVertexAttrib2fv)
125     M(glVertexAttrib3fv)
126     M(glVertexAttrib4fv)
127     M(glVertexAttribPointer)
128     M(glViewport)
129     #undef M
130     return eglGetProcAddress(name);
131 }
132 
GrGLMakeEGLInterface()133 sk_sp<const GrGLInterface> GrGLMakeEGLInterface() {
134     return GrGLMakeAssembledInterface(nullptr, egl_get_gl_proc);
135 }
136