• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "SkTypes.h"
8 #if defined(SK_BUILD_FOR_ANDROID)
9 
10 #include "gl/GrGLInterface.h"
11 #include "gl/GrGLAssembleInterface.h"
12 #include "gl/GrGLUtil.h"
13 
14 #include <EGL/egl.h>
15 #include <GLES2/gl2.h>
16 
android_get_gl_proc(void * ctx,const char name[])17 static GrGLFuncPtr android_get_gl_proc(void* ctx, const char name[]) {
18     SkASSERT(nullptr == ctx);
19     // Some older drivers on Android have busted eglGetProcAdddress Functions that
20     // will return the wrong pointer for built in GLES2 functions. This set of functions
21     // was generated on a Xoom by finding mismatches between the function pulled in via gl2.h and
22     // the address returned by eglGetProcAddress.
23     if (0 == strcmp("glActiveTexture", name)) {
24         return (GrGLFuncPtr) glActiveTexture;
25     } else if (0 == strcmp("glAttachShader", name)) {
26         return (GrGLFuncPtr) glAttachShader;
27     } else if (0 == strcmp("glBindAttribLocation", name)) {
28         return (GrGLFuncPtr) glBindAttribLocation;
29     } else if (0 == strcmp("glBindBuffer", name)) {
30         return (GrGLFuncPtr) glBindBuffer;
31     } else if (0 == strcmp("glBindTexture", name)) {
32         return (GrGLFuncPtr) glBindTexture;
33     } else if (0 == strcmp("glBlendColor", name)) {
34         return (GrGLFuncPtr) glBlendColor;
35     } else if (0 == strcmp("glBlendEquation", name)) {
36         return (GrGLFuncPtr) glBlendEquation;
37     } else if (0 == strcmp("glBlendFunc", name)) {
38         return (GrGLFuncPtr) glBlendFunc;
39     } else if (0 == strcmp("glBufferData", name)) {
40         return (GrGLFuncPtr) glBufferData;
41     } else if (0 == strcmp("glBufferSubData", name)) {
42         return (GrGLFuncPtr) glBufferSubData;
43     } else if (0 == strcmp("glClear", name)) {
44         return (GrGLFuncPtr) glClear;
45     } else if (0 == strcmp("glClearColor", name)) {
46         return (GrGLFuncPtr) glClearColor;
47     } else if (0 == strcmp("glClearStencil", name)) {
48         return (GrGLFuncPtr) glClearStencil;
49     } else if (0 == strcmp("glColorMask", name)) {
50         return (GrGLFuncPtr) glColorMask;
51     } else if (0 == strcmp("glCompileShader", name)) {
52         return (GrGLFuncPtr) glCompileShader;
53     } else if (0 == strcmp("glCompressedTexImage2D", name)) {
54         return (GrGLFuncPtr) glCompressedTexImage2D;
55     } else if (0 == strcmp("glCompressedTexSubImage2D", name)) {
56         return (GrGLFuncPtr) glCompressedTexSubImage2D;
57     } else if (0 == strcmp("glCopyTexSubImage2D", name)) {
58         return (GrGLFuncPtr) glCopyTexSubImage2D;
59     } else if (0 == strcmp("glCreateProgram", name)) {
60         return (GrGLFuncPtr) glCreateProgram;
61     } else if (0 == strcmp("glCreateShader", name)) {
62         return (GrGLFuncPtr) glCreateShader;
63     } else if (0 == strcmp("glCullFace", name)) {
64         return (GrGLFuncPtr) glCullFace;
65     } else if (0 == strcmp("glDeleteBuffers", name)) {
66         return (GrGLFuncPtr) glDeleteBuffers;
67     } else if (0 == strcmp("glDeleteProgram", name)) {
68         return (GrGLFuncPtr) glDeleteProgram;
69     } else if (0 == strcmp("glDeleteShader", name)) {
70         return (GrGLFuncPtr) glDeleteShader;
71     } else if (0 == strcmp("glDeleteTextures", name)) {
72         return (GrGLFuncPtr) glDeleteTextures;
73     } else if (0 == strcmp("glDepthMask", name)) {
74         return (GrGLFuncPtr) glDepthMask;
75     } else if (0 == strcmp("glDisable", name)) {
76         return (GrGLFuncPtr) glDisable;
77     } else if (0 == strcmp("glDisableVertexAttribArray", name)) {
78         return (GrGLFuncPtr) glDisableVertexAttribArray;
79     } else if (0 == strcmp("glDrawArrays", name)) {
80         return (GrGLFuncPtr) glDrawArrays;
81     } else if (0 == strcmp("glDrawElements", name)) {
82         return (GrGLFuncPtr) glDrawElements;
83     } else if (0 == strcmp("glEnable", name)) {
84         return (GrGLFuncPtr) glEnable;
85     } else if (0 == strcmp("glEnableVertexAttribArray", name)) {
86         return (GrGLFuncPtr) glEnableVertexAttribArray;
87     } else if (0 == strcmp("glFinish", name)) {
88         return (GrGLFuncPtr) glFinish;
89     } else if (0 == strcmp("glFlush", name)) {
90         return (GrGLFuncPtr) glFlush;
91     } else if (0 == strcmp("glFrontFace", name)) {
92         return (GrGLFuncPtr) glFrontFace;
93     } else if (0 == strcmp("glGenBuffers", name)) {
94         return (GrGLFuncPtr) glGenBuffers;
95     } else if (0 == strcmp("glGenerateMipmap", name)) {
96         return (GrGLFuncPtr) glGenerateMipmap;
97     } else if (0 == strcmp("glGenTextures", name)) {
98         return (GrGLFuncPtr) glGenTextures;
99     } else if (0 == strcmp("glGetBufferParameteriv", name)) {
100         return (GrGLFuncPtr) glGetBufferParameteriv;
101     } else if (0 == strcmp("glGetError", name)) {
102         return (GrGLFuncPtr) glGetError;
103     } else if (0 == strcmp("glGetIntegerv", name)) {
104         return (GrGLFuncPtr) glGetIntegerv;
105     } else if (0 == strcmp("glGetProgramInfoLog", name)) {
106         return (GrGLFuncPtr) glGetProgramInfoLog;
107     } else if (0 == strcmp("glGetProgramiv", name)) {
108         return (GrGLFuncPtr) glGetProgramiv;
109     } else if (0 == strcmp("glGetShaderInfoLog", name)) {
110         return (GrGLFuncPtr) glGetShaderInfoLog;
111     } else if (0 == strcmp("glGetShaderiv", name)) {
112         return (GrGLFuncPtr) glGetShaderiv;
113     } else if (0 == strcmp("glGetShaderPrecisionFormat", name)) {
114         return (GrGLFuncPtr) glGetShaderPrecisionFormat;
115     } else if (0 == strcmp("glGetString", name)) {
116         return (GrGLFuncPtr) glGetString;
117     } else if (0 == strcmp("glGetUniformLocation", name)) {
118         return (GrGLFuncPtr) glGetUniformLocation;
119     } else if (0 == strcmp("glLineWidth", name)) {
120         return (GrGLFuncPtr) glLineWidth;
121     } else if (0 == strcmp("glLinkProgram", name)) {
122         return (GrGLFuncPtr) glLinkProgram;
123     } else if (0 == strcmp("glPixelStorei", name)) {
124         return (GrGLFuncPtr) glPixelStorei;
125     } else if (0 == strcmp("glReadPixels", name)) {
126         return (GrGLFuncPtr) glReadPixels;
127     } else if (0 == strcmp("glScissor", name)) {
128         return (GrGLFuncPtr) glScissor;
129     } else if (0 == strcmp("glShaderSource", name)) {
130         return (GrGLFuncPtr) glShaderSource;
131     } else if (0 == strcmp("glStencilFunc", name)) {
132         return (GrGLFuncPtr) glStencilFunc;
133     } else if (0 == strcmp("glStencilFuncSeparate", name)) {
134         return (GrGLFuncPtr) glStencilFuncSeparate;
135     } else if (0 == strcmp("glStencilMask", name)) {
136         return (GrGLFuncPtr) glStencilMask;
137     } else if (0 == strcmp("glStencilMaskSeparate", name)) {
138         return (GrGLFuncPtr) glStencilMaskSeparate;
139     } else if (0 == strcmp("glStencilOp", name)) {
140         return (GrGLFuncPtr) glStencilOp;
141     } else if (0 == strcmp("glStencilOpSeparate", name)) {
142         return (GrGLFuncPtr) glStencilOpSeparate;
143     } else if (0 == strcmp("glTexImage2D", name)) {
144         return (GrGLFuncPtr) glTexImage2D;
145     } else if (0 == strcmp("glTexParameteri", name)) {
146         return (GrGLFuncPtr) glTexParameteri;
147     } else if (0 == strcmp("glTexParameteriv", name)) {
148         return (GrGLFuncPtr) glTexParameteriv;
149     } else if (0 == strcmp("glTexSubImage2D", name)) {
150         return (GrGLFuncPtr) glTexSubImage2D;
151     } else if (0 == strcmp("glUniform1f", name)) {
152         return (GrGLFuncPtr) glUniform1f;
153     } else if (0 == strcmp("glUniform1i", name)) {
154         return (GrGLFuncPtr) glUniform1i;
155     } else if (0 == strcmp("glUniform1fv", name)) {
156         return (GrGLFuncPtr) glUniform1fv;
157     } else if (0 == strcmp("glUniform1iv", name)) {
158         return (GrGLFuncPtr) glUniform1iv;
159     } else if (0 == strcmp("glUniform2f", name)) {
160         return (GrGLFuncPtr) glUniform2f;
161     } else if (0 == strcmp("glUniform2i", name)) {
162         return (GrGLFuncPtr) glUniform2i;
163     } else if (0 == strcmp("glUniform2fv", name)) {
164         return (GrGLFuncPtr) glUniform2fv;
165     } else if (0 == strcmp("glUniform2iv", name)) {
166         return (GrGLFuncPtr) glUniform2iv;
167     } else if (0 == strcmp("glUniform3f", name)) {
168         return (GrGLFuncPtr) glUniform3f;
169     } else if (0 == strcmp("glUniform3i", name)) {
170         return (GrGLFuncPtr) glUniform3i;
171     } else if (0 == strcmp("glUniform3fv", name)) {
172         return (GrGLFuncPtr) glUniform3fv;
173     } else if (0 == strcmp("glUniform3iv", name)) {
174         return (GrGLFuncPtr) glUniform3iv;
175     } else if (0 == strcmp("glUniform4f", name)) {
176         return (GrGLFuncPtr) glUniform4f;
177     } else if (0 == strcmp("glUniform4i", name)) {
178         return (GrGLFuncPtr) glUniform4i;
179     } else if (0 == strcmp("glUniform4fv", name)) {
180         return (GrGLFuncPtr) glUniform4fv;
181     } else if (0 == strcmp("glUniform4iv", name)) {
182         return (GrGLFuncPtr) glUniform4iv;
183     } else if (0 == strcmp("glUniformMatrix2fv", name)) {
184         return (GrGLFuncPtr) glUniformMatrix2fv;
185     } else if (0 == strcmp("glUniformMatrix3fv", name)) {
186         return (GrGLFuncPtr) glUniformMatrix3fv;
187     } else if (0 == strcmp("glUniformMatrix4fv", name)) {
188         return (GrGLFuncPtr) glUniformMatrix4fv;
189     } else if (0 == strcmp("glUseProgram", name)) {
190         return (GrGLFuncPtr) glUseProgram;
191     } else if (0 == strcmp("glVertexAttrib1f", name)) {
192         return (GrGLFuncPtr) glVertexAttrib1f;
193     } else if (0 == strcmp("glVertexAttrib2fv", name)) {
194         return (GrGLFuncPtr) glVertexAttrib2fv;
195     } else if (0 == strcmp("glVertexAttrib3fv", name)) {
196         return (GrGLFuncPtr) glVertexAttrib3fv;
197     } else if (0 == strcmp("glVertexAttrib4fv", name)) {
198         return (GrGLFuncPtr) glVertexAttrib4fv;
199     } else if (0 == strcmp("glVertexAttribPointer", name)) {
200         return (GrGLFuncPtr) glVertexAttribPointer;
201     } else if (0 == strcmp("glViewport", name)) {
202         return (GrGLFuncPtr) glViewport;
203     } else if (0 == strcmp("glBindFramebuffer", name)) {
204         return (GrGLFuncPtr) glBindFramebuffer;
205     } else if (0 == strcmp("glBindRenderbuffer", name)) {
206         return (GrGLFuncPtr) glBindRenderbuffer;
207     } else if (0 == strcmp("glCheckFramebufferStatus", name)) {
208         return (GrGLFuncPtr) glCheckFramebufferStatus;
209     } else if (0 == strcmp("glDeleteFramebuffers", name)) {
210         return (GrGLFuncPtr) glDeleteFramebuffers;
211     } else if (0 == strcmp("glDeleteRenderbuffers", name)) {
212         return (GrGLFuncPtr) glDeleteRenderbuffers;
213     } else if (0 == strcmp("glFramebufferRenderbuffer", name)) {
214         return (GrGLFuncPtr) glFramebufferRenderbuffer;
215     } else if (0 == strcmp("glFramebufferTexture2D", name)) {
216         return (GrGLFuncPtr) glFramebufferTexture2D;
217     } else if (0 == strcmp("glGenFramebuffers", name)) {
218         return (GrGLFuncPtr) glGenFramebuffers;
219     } else if (0 == strcmp("glGenRenderbuffers", name)) {
220         return (GrGLFuncPtr) glGenRenderbuffers;
221     } else if (0 == strcmp("glGetFramebufferAttachmentParameteriv", name)) {
222         return (GrGLFuncPtr) glGetFramebufferAttachmentParameteriv;
223     } else if (0 == strcmp("glGetRenderbufferParameteriv", name)) {
224         return (GrGLFuncPtr) glGetRenderbufferParameteriv;
225     } else if (0 == strcmp("glRenderbufferStorage", name)) {
226         return (GrGLFuncPtr) glRenderbufferStorage;
227     } else if (0 == strcmp("eglQueryString", name)) {
228         return (GrGLFuncPtr) eglQueryString;
229     } else if (0 == strcmp("eglGetCurrentDisplay", name)) {
230         return (GrGLFuncPtr) eglGetCurrentDisplay;
231     }
232     return eglGetProcAddress(name);
233 }
234 
GrGLCreateNativeInterface()235 const GrGLInterface* GrGLCreateNativeInterface() {
236     return GrGLAssembleInterface(nullptr, android_get_gl_proc);
237 }
238 
239 #endif//defined(SK_BUILD_FOR_ANDROID)
240