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