Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1090)

Side by Side Diff: src/gpu/gl/mac/GrGLCreateNativeInterface_mac.cpp

Issue 254713006: Common GrGLInterface OpenGL setup function. (Closed) Base URL: https://skia.googlesource.com/skia.git@grgl
Patch Set: Address additional comment Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #include "gl/GrGLInterface.h" 10 #include "gl/GrGLInterface.h"
11 #include "../GrGLUtil.h" 11 #include "gl/GrGLAssembleInterface.h"
12 12
13 #include <dlfcn.h> 13 #include <dlfcn.h>
14 14
15 // We get the proc addresss of all GL functions dynamically because we sometimes link against
16 // alternative GL implementations (e.g. MESA) in addition to the native GL imple mentation.
17 class GLLoader { 15 class GLLoader {
18 public: 16 public:
19 GLLoader() { 17 GLLoader() {
20 fLibrary = dlopen( 18 fLibrary = dlopen(
21 "/System/Library/Frameworks/OpenGL.framework/Versions/A/Libr aries/libGL.dylib", 19 "/System/Library/Frameworks/OpenGL.framework/Versions/A/Libr aries/libGL.dylib",
22 RTLD_LAZY); 20 RTLD_LAZY);
23 } 21 }
22
24 ~GLLoader() { 23 ~GLLoader() {
25 if (NULL != fLibrary) { 24 if (NULL != fLibrary) {
26 dlclose(fLibrary); 25 dlclose(fLibrary);
27 } 26 }
28 } 27 }
29 void* handle() { 28
29 void* handle() const {
30 return NULL == fLibrary ? RTLD_DEFAULT : fLibrary; 30 return NULL == fLibrary ? RTLD_DEFAULT : fLibrary;
31 } 31 }
32
32 private: 33 private:
33 void* fLibrary; 34 void* fLibrary;
34 }; 35 };
35 36
36 static void* GetProcAddress(const char* name) { 37 class GLProcGetter {
37 static GLLoader gLoader; 38 public:
38 return dlsym(gLoader.handle(), name); 39 GLProcGetter() {}
40
41 GrGLFuncPtr getProc(const char name[]) const {
42 return (GrGLFuncPtr) dlsym(fLoader.handle(), name);
43 }
44
45 private:
46 GLLoader fLoader;
47 };
48
49 static GrGLFuncPtr mac_get_gl_proc(void* ctx, const char name[]) {
50 SkASSERT(NULL != ctx);
51 const GLProcGetter* getter = (const GLProcGetter*) ctx;
52 return getter->getProc(name);
39 } 53 }
40 54
41 #define GET_PROC(name) (interface->fFunctions.f ## name = ((GrGL ## name ## Proc ) GetProcAddress("gl" #name)))
42 #define GET_PROC_SUFFIX(name, suffix) (interface->fFunctions.f ## name = ((GrGL ## name ## Proc) GetProcAddress("gl" #name #suffix)))
43
44 const GrGLInterface* GrGLCreateNativeInterface() { 55 const GrGLInterface* GrGLCreateNativeInterface() {
45 56 GLProcGetter getter;
46 GrGLGetStringProc glGetString = (GrGLGetStringProc) GetProcAddress("glGetStr ing"); 57 return GrGLAssembleGLInterface(&getter, mac_get_gl_proc);
47 GrGLGetStringiProc glGetStringi = (GrGLGetStringiProc) GetProcAddress("glGet Stringi");
48 GrGLGetIntegervProc glGetIntegerv = (GrGLGetIntegervProc) GetProcAddress("gl GetIntegerv");
49
50 const char* verStr = (const char*) glGetString(GR_GL_VERSION);
51 GrGLVersion ver = GrGLGetVersionFromString(verStr);
52 GrGLExtensions extensions;
53 if (!extensions.init(kGL_GrGLStandard, glGetString, glGetStringi, glGetInteg erv)) {
54 return NULL;
55 }
56
57 GrGLInterface* interface = SkNEW(GrGLInterface);
58 interface->fStandard = kGL_GrGLStandard;
59
60 GET_PROC(ActiveTexture);
61 GET_PROC(AttachShader);
62 GET_PROC(BeginQuery);
63 GET_PROC(BindAttribLocation);
64 GET_PROC(BindBuffer);
65 if (ver >= GR_GL_VER(3,0)) {
66 GET_PROC(BindFragDataLocation);
67 }
68 GET_PROC(BindTexture);
69 GET_PROC(BlendFunc);
70
71 if (ver >= GR_GL_VER(1,4) ||
72 extensions.has("GL_ARB_imaging") ||
73 extensions.has("GL_EXT_blend_color")) {
74 GET_PROC(BlendColor);
75 }
76
77 GET_PROC(BufferData);
78 GET_PROC(BufferSubData);
79 GET_PROC(Clear);
80 GET_PROC(ClearColor);
81 GET_PROC(ClearStencil);
82 GET_PROC(ColorMask);
83 GET_PROC(CompileShader);
84 GET_PROC(CompressedTexImage2D);
85 GET_PROC(CopyTexSubImage2D);
86 GET_PROC(CreateProgram);
87 GET_PROC(CreateShader);
88 GET_PROC(CullFace);
89 GET_PROC(DeleteBuffers);
90 GET_PROC(DeleteProgram);
91 GET_PROC(DeleteQueries);
92 GET_PROC(DeleteShader);
93 GET_PROC(DeleteTextures);
94 GET_PROC(DepthMask);
95 GET_PROC(Disable);
96 GET_PROC(DisableVertexAttribArray);
97 GET_PROC(DrawArrays);
98 GET_PROC(DrawBuffer);
99 GET_PROC(DrawBuffers);
100 GET_PROC(DrawElements);
101 GET_PROC(Enable);
102 GET_PROC(EnableVertexAttribArray);
103 GET_PROC(EndQuery);
104 GET_PROC(Finish);
105 GET_PROC(Flush);
106 GET_PROC(FrontFace);
107 GET_PROC(GenBuffers);
108 GET_PROC(GenerateMipmap);
109 GET_PROC(GenQueries);
110 GET_PROC(GetBufferParameteriv);
111 GET_PROC(GetError);
112 GET_PROC(GetIntegerv);
113 GET_PROC(GetProgramInfoLog);
114 GET_PROC(GetProgramiv);
115 GET_PROC(GetQueryiv);
116 GET_PROC(GetQueryObjectiv);
117 GET_PROC(GetQueryObjectuiv);
118 GET_PROC(GetShaderInfoLog);
119 GET_PROC(GetShaderiv);
120 GET_PROC(GetString);
121 GET_PROC(GetStringi);
122 GET_PROC(GetTexLevelParameteriv);
123 GET_PROC(GenTextures);
124 GET_PROC(GetUniformLocation);
125 GET_PROC(LineWidth);
126 GET_PROC(LinkProgram);
127 GET_PROC(MapBuffer);
128 if (extensions.has("GL_EXT_direct_state_access")) {
129 GET_PROC_SUFFIX(MatrixLoadf, EXT);
130 GET_PROC_SUFFIX(MatrixLoadIdentity, EXT);
131 }
132 GET_PROC(PixelStorei);
133 GET_PROC(ReadBuffer);
134 GET_PROC(ReadPixels);
135 GET_PROC(Scissor);
136 GET_PROC(ShaderSource);
137 GET_PROC(StencilFunc);
138 GET_PROC(StencilFuncSeparate);
139 GET_PROC(StencilMask);
140 GET_PROC(StencilMaskSeparate);
141 GET_PROC(StencilOp);
142 GET_PROC(StencilOpSeparate);
143 GET_PROC(TexImage2D);
144 GET_PROC(TexParameteri);
145 GET_PROC(TexParameteriv);
146 if (ver >= GR_GL_VER(4,2) || extensions.has("GL_ARB_texture_storage")) {
147 GET_PROC(TexStorage2D);
148 } else if (extensions.has("GL_EXT_texture_storage")) {
149 GET_PROC_SUFFIX(TexStorage2D, EXT);
150 }
151 GET_PROC(TexSubImage2D);
152 GET_PROC(Uniform1f);
153 GET_PROC(Uniform1i);
154 GET_PROC(Uniform1fv);
155 GET_PROC(Uniform1iv);
156 GET_PROC(Uniform2f);
157 GET_PROC(Uniform2i);
158 GET_PROC(Uniform2fv);
159 GET_PROC(Uniform2iv);
160 GET_PROC(Uniform3f);
161 GET_PROC(Uniform3i);
162 GET_PROC(Uniform3fv);
163 GET_PROC(Uniform3iv);
164 GET_PROC(Uniform4f);
165 GET_PROC(Uniform4i);
166 GET_PROC(Uniform4fv);
167 GET_PROC(Uniform4iv);
168 GET_PROC(Uniform4fv);
169 GET_PROC(UniformMatrix2fv);
170 GET_PROC(UniformMatrix3fv);
171 GET_PROC(UniformMatrix4fv);
172 GET_PROC(UnmapBuffer);
173 GET_PROC(UseProgram);
174 GET_PROC(VertexAttrib4fv);
175 GET_PROC(VertexAttribPointer);
176 GET_PROC(Viewport);
177
178 if (ver >= GR_GL_VER(3,0) || extensions.has("GL_ARB_vertex_array_object")) {
179 // no ARB suffix for GL_ARB_vertex_array_object
180 GET_PROC(BindVertexArray);
181 GET_PROC(DeleteVertexArrays);
182 GET_PROC(GenVertexArrays);
183 }
184
185 if (ver >= GR_GL_VER(3,3) || extensions.has("GL_ARB_timer_query")) {
186 // ARB extension doesn't use the ARB suffix on the function name
187 GET_PROC(QueryCounter);
188 GET_PROC(GetQueryObjecti64v);
189 GET_PROC(GetQueryObjectui64v);
190 } else if (extensions.has("GL_EXT_timer_query")) {
191 GET_PROC_SUFFIX(GetQueryObjecti64v, EXT);
192 GET_PROC_SUFFIX(GetQueryObjectui64v, EXT);
193 }
194
195 if (ver >= GR_GL_VER(3,0) || extensions.has("GL_ARB_framebuffer_object")) {
196 // ARB extension doesn't use the ARB suffix on the function names
197 GET_PROC(GenFramebuffers);
198 GET_PROC(GetFramebufferAttachmentParameteriv);
199 GET_PROC(GetRenderbufferParameteriv);
200 GET_PROC(BindFramebuffer);
201 GET_PROC(FramebufferTexture2D);
202 GET_PROC(CheckFramebufferStatus);
203 GET_PROC(DeleteFramebuffers);
204 GET_PROC(RenderbufferStorage);
205 GET_PROC(GenRenderbuffers);
206 GET_PROC(DeleteRenderbuffers);
207 GET_PROC(FramebufferRenderbuffer);
208 GET_PROC(BindRenderbuffer);
209 GET_PROC(RenderbufferStorageMultisample);
210 GET_PROC(BlitFramebuffer);
211 } else {
212 if (extensions.has("GL_EXT_framebuffer_object")) {
213 GET_PROC_SUFFIX(GenFramebuffers, EXT);
214 GET_PROC_SUFFIX(GetFramebufferAttachmentParameteriv, EXT);
215 GET_PROC_SUFFIX(GetRenderbufferParameteriv, EXT);
216 GET_PROC_SUFFIX(BindFramebuffer, EXT);
217 GET_PROC_SUFFIX(FramebufferTexture2D, EXT);
218 GET_PROC_SUFFIX(CheckFramebufferStatus, EXT);
219 GET_PROC_SUFFIX(DeleteFramebuffers, EXT);
220 GET_PROC_SUFFIX(RenderbufferStorage, EXT);
221 GET_PROC_SUFFIX(GenRenderbuffers, EXT);
222 GET_PROC_SUFFIX(DeleteRenderbuffers, EXT);
223 GET_PROC_SUFFIX(FramebufferRenderbuffer, EXT);
224 GET_PROC_SUFFIX(BindRenderbuffer, EXT);
225 }
226 if (extensions.has("GL_EXT_framebuffer_multisample")) {
227 GET_PROC_SUFFIX(RenderbufferStorageMultisample, EXT);
228 }
229 if (extensions.has("GL_EXT_framebuffer_blit")) {
230 GET_PROC_SUFFIX(BlitFramebuffer, EXT);
231 }
232 }
233 if (ver >= GR_GL_VER(3,3) || extensions.has("GL_ARB_blend_func_extended")) {
234 // ARB extension doesn't use the ARB suffix on the function name
235 GET_PROC(BindFragDataLocationIndexed);
236 }
237
238 if (extensions.has("GL_EXT_debug_marker")) {
239 GET_PROC_SUFFIX(InsertEventMarker, EXT);
240 GET_PROC_SUFFIX(PushGroupMarker, EXT);
241 GET_PROC_SUFFIX(PopGroupMarker, EXT);
242 }
243
244 if (ver >= GR_GL_VER(4,3) || extensions.has("GL_ARB_invalidate_subdata")) {
245 GET_PROC(InvalidateBufferData);
246 GET_PROC(InvalidateBufferSubData);
247 GET_PROC(InvalidateFramebuffer);
248 GET_PROC(InvalidateSubFramebuffer);
249 GET_PROC(InvalidateTexImage);
250 GET_PROC(InvalidateTexSubImage);
251 }
252
253 interface->fExtensions.swap(&extensions);
254 return interface;
255 } 58 }
OLDNEW
« no previous file with comments | « src/gpu/gl/android/GrGLCreateNativeInterface_android.cpp ('k') | src/gpu/gl/mesa/GrGLCreateMesaInterface.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698