Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | |
michael@0 | 2 | /* |
michael@0 | 3 | * Copyright 2011 Google Inc. |
michael@0 | 4 | * |
michael@0 | 5 | * Use of this source code is governed by a BSD-style license that can be |
michael@0 | 6 | * found in the LICENSE file. |
michael@0 | 7 | */ |
michael@0 | 8 | |
michael@0 | 9 | #include "gl/GrGLInterface.h" |
michael@0 | 10 | #include "gl/GrGLUtil.h" |
michael@0 | 11 | #define WIN32_LEAN_AND_MEAN |
michael@0 | 12 | #include <windows.h> |
michael@0 | 13 | |
michael@0 | 14 | /* |
michael@0 | 15 | * Windows makes the GL funcs all be __stdcall instead of __cdecl :( |
michael@0 | 16 | * This implementation will only work if GR_GL_FUNCTION_TYPE is __stdcall. |
michael@0 | 17 | * Otherwise, a springboard would be needed that hides the calling convention. |
michael@0 | 18 | */ |
michael@0 | 19 | |
michael@0 | 20 | #define SET_PROC(F) interface->fFunctions.f ## F = (GrGL ## F ## Proc) GetProcAddress(alu.get(), "gl" #F); |
michael@0 | 21 | #define WGL_SET_PROC(F) interface->fFunctions.f ## F = (GrGL ## F ## Proc) wglGetProcAddress("gl" #F); |
michael@0 | 22 | #define WGL_SET_PROC_SUFFIX(F, S) interface->fFunctions.f ## F = (GrGL ## F ## Proc) wglGetProcAddress("gl" #F #S); |
michael@0 | 23 | |
michael@0 | 24 | class AutoLibraryUnload { |
michael@0 | 25 | public: |
michael@0 | 26 | AutoLibraryUnload(const char* moduleName) { |
michael@0 | 27 | fModule = LoadLibrary(moduleName); |
michael@0 | 28 | } |
michael@0 | 29 | ~AutoLibraryUnload() { |
michael@0 | 30 | if (NULL != fModule) { |
michael@0 | 31 | FreeLibrary(fModule); |
michael@0 | 32 | } |
michael@0 | 33 | } |
michael@0 | 34 | HMODULE get() const { return fModule; } |
michael@0 | 35 | |
michael@0 | 36 | private: |
michael@0 | 37 | HMODULE fModule; |
michael@0 | 38 | }; |
michael@0 | 39 | |
michael@0 | 40 | const GrGLInterface* GrGLCreateNativeInterface() { |
michael@0 | 41 | AutoLibraryUnload alu("opengl32.dll"); |
michael@0 | 42 | if (NULL == alu.get()) { |
michael@0 | 43 | return NULL; |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | if (NULL != wglGetCurrentContext()) { |
michael@0 | 47 | |
michael@0 | 48 | // These should always be present and don't require wglGetProcAddress |
michael@0 | 49 | GrGLGetStringProc glGetString = |
michael@0 | 50 | (GrGLGetStringProc) GetProcAddress(alu.get(), "glGetString"); |
michael@0 | 51 | GrGLGetIntegervProc glGetIntegerv = |
michael@0 | 52 | (GrGLGetIntegervProc) GetProcAddress(alu.get(), "glGetIntegerv"); |
michael@0 | 53 | if (NULL == glGetString || NULL == glGetIntegerv) { |
michael@0 | 54 | return NULL; |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | // This may or may not succeed depending on the gl version. |
michael@0 | 58 | GrGLGetStringiProc glGetStringi = (GrGLGetStringiProc) wglGetProcAddress("glGetStringi"); |
michael@0 | 59 | |
michael@0 | 60 | GrGLExtensions extensions; |
michael@0 | 61 | if (!extensions.init(kGL_GrGLStandard, glGetString, glGetStringi, glGetIntegerv)) { |
michael@0 | 62 | return NULL; |
michael@0 | 63 | } |
michael@0 | 64 | const char* versionString = (const char*) glGetString(GR_GL_VERSION); |
michael@0 | 65 | GrGLVersion glVer = GrGLGetVersionFromString(versionString); |
michael@0 | 66 | |
michael@0 | 67 | if (glVer < GR_GL_VER(1,5)) { |
michael@0 | 68 | // We must have array and element_array buffer objects. |
michael@0 | 69 | return NULL; |
michael@0 | 70 | } |
michael@0 | 71 | GrGLInterface* interface = SkNEW(GrGLInterface); |
michael@0 | 72 | |
michael@0 | 73 | // Functions that are part of GL 1.1 will return NULL in |
michael@0 | 74 | // wglGetProcAddress |
michael@0 | 75 | SET_PROC(BindTexture) |
michael@0 | 76 | SET_PROC(BlendFunc) |
michael@0 | 77 | |
michael@0 | 78 | if (glVer >= GR_GL_VER(1,4) || |
michael@0 | 79 | extensions.has("GL_ARB_imaging") || |
michael@0 | 80 | extensions.has("GL_EXT_blend_color")) { |
michael@0 | 81 | WGL_SET_PROC(BlendColor); |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | SET_PROC(Clear) |
michael@0 | 85 | SET_PROC(ClearColor) |
michael@0 | 86 | SET_PROC(ClearStencil) |
michael@0 | 87 | SET_PROC(ColorMask) |
michael@0 | 88 | SET_PROC(CopyTexSubImage2D) |
michael@0 | 89 | SET_PROC(CullFace) |
michael@0 | 90 | SET_PROC(DeleteTextures) |
michael@0 | 91 | SET_PROC(DepthMask) |
michael@0 | 92 | SET_PROC(Disable) |
michael@0 | 93 | SET_PROC(DrawArrays) |
michael@0 | 94 | SET_PROC(DrawElements) |
michael@0 | 95 | SET_PROC(DrawBuffer) |
michael@0 | 96 | SET_PROC(Enable) |
michael@0 | 97 | SET_PROC(FrontFace) |
michael@0 | 98 | SET_PROC(Finish) |
michael@0 | 99 | SET_PROC(Flush) |
michael@0 | 100 | SET_PROC(GenTextures) |
michael@0 | 101 | SET_PROC(GetError) |
michael@0 | 102 | SET_PROC(GetIntegerv) |
michael@0 | 103 | SET_PROC(GetString) |
michael@0 | 104 | SET_PROC(GetTexLevelParameteriv) |
michael@0 | 105 | SET_PROC(LineWidth) |
michael@0 | 106 | SET_PROC(LoadIdentity) |
michael@0 | 107 | SET_PROC(LoadMatrixf) |
michael@0 | 108 | SET_PROC(MatrixMode) |
michael@0 | 109 | SET_PROC(PixelStorei) |
michael@0 | 110 | SET_PROC(ReadBuffer) |
michael@0 | 111 | SET_PROC(ReadPixels) |
michael@0 | 112 | SET_PROC(Scissor) |
michael@0 | 113 | SET_PROC(StencilFunc) |
michael@0 | 114 | SET_PROC(StencilMask) |
michael@0 | 115 | SET_PROC(StencilOp) |
michael@0 | 116 | SET_PROC(TexGenfv) |
michael@0 | 117 | SET_PROC(TexGeni) |
michael@0 | 118 | SET_PROC(TexImage2D) |
michael@0 | 119 | SET_PROC(TexParameteri) |
michael@0 | 120 | SET_PROC(TexParameteriv) |
michael@0 | 121 | if (glVer >= GR_GL_VER(4,2) || extensions.has("GL_ARB_texture_storage")) { |
michael@0 | 122 | WGL_SET_PROC(TexStorage2D); |
michael@0 | 123 | } else if (extensions.has("GL_EXT_texture_storage")) { |
michael@0 | 124 | WGL_SET_PROC_SUFFIX(TexStorage2D, EXT); |
michael@0 | 125 | } |
michael@0 | 126 | SET_PROC(TexSubImage2D) |
michael@0 | 127 | SET_PROC(Viewport) |
michael@0 | 128 | |
michael@0 | 129 | WGL_SET_PROC(ActiveTexture); |
michael@0 | 130 | WGL_SET_PROC(AttachShader); |
michael@0 | 131 | WGL_SET_PROC(BeginQuery); |
michael@0 | 132 | WGL_SET_PROC(BindAttribLocation); |
michael@0 | 133 | WGL_SET_PROC(BindBuffer); |
michael@0 | 134 | WGL_SET_PROC(BindFragDataLocation); |
michael@0 | 135 | WGL_SET_PROC(BufferData); |
michael@0 | 136 | WGL_SET_PROC(BufferSubData); |
michael@0 | 137 | WGL_SET_PROC(CompileShader); |
michael@0 | 138 | WGL_SET_PROC(CompressedTexImage2D); |
michael@0 | 139 | WGL_SET_PROC(CreateProgram); |
michael@0 | 140 | WGL_SET_PROC(CreateShader); |
michael@0 | 141 | WGL_SET_PROC(DeleteBuffers); |
michael@0 | 142 | WGL_SET_PROC(DeleteQueries); |
michael@0 | 143 | WGL_SET_PROC(DeleteProgram); |
michael@0 | 144 | WGL_SET_PROC(DeleteShader); |
michael@0 | 145 | WGL_SET_PROC(DisableVertexAttribArray); |
michael@0 | 146 | WGL_SET_PROC(DrawBuffers); |
michael@0 | 147 | WGL_SET_PROC(EnableVertexAttribArray); |
michael@0 | 148 | WGL_SET_PROC(EndQuery); |
michael@0 | 149 | WGL_SET_PROC(GenBuffers); |
michael@0 | 150 | WGL_SET_PROC(GenerateMipmap); |
michael@0 | 151 | WGL_SET_PROC(GenQueries); |
michael@0 | 152 | WGL_SET_PROC(GetBufferParameteriv); |
michael@0 | 153 | WGL_SET_PROC(GetQueryiv); |
michael@0 | 154 | WGL_SET_PROC(GetQueryObjectiv); |
michael@0 | 155 | WGL_SET_PROC(GetQueryObjectuiv); |
michael@0 | 156 | if (glVer > GR_GL_VER(3,3) || extensions.has("GL_ARB_timer_query")) { |
michael@0 | 157 | WGL_SET_PROC(GetQueryObjecti64v); |
michael@0 | 158 | WGL_SET_PROC(GetQueryObjectui64v); |
michael@0 | 159 | WGL_SET_PROC(QueryCounter); |
michael@0 | 160 | } else if (extensions.has("GL_EXT_timer_query")) { |
michael@0 | 161 | WGL_SET_PROC_SUFFIX(GetQueryObjecti64v, EXT); |
michael@0 | 162 | WGL_SET_PROC_SUFFIX(GetQueryObjectui64v, EXT); |
michael@0 | 163 | } |
michael@0 | 164 | WGL_SET_PROC(GetProgramInfoLog); |
michael@0 | 165 | WGL_SET_PROC(GetProgramiv); |
michael@0 | 166 | WGL_SET_PROC(GetShaderInfoLog); |
michael@0 | 167 | WGL_SET_PROC(GetShaderiv); |
michael@0 | 168 | WGL_SET_PROC(GetStringi) |
michael@0 | 169 | WGL_SET_PROC(GetUniformLocation); |
michael@0 | 170 | WGL_SET_PROC(LinkProgram); |
michael@0 | 171 | WGL_SET_PROC(ShaderSource); |
michael@0 | 172 | WGL_SET_PROC(StencilFuncSeparate); |
michael@0 | 173 | WGL_SET_PROC(StencilMaskSeparate); |
michael@0 | 174 | WGL_SET_PROC(StencilOpSeparate); |
michael@0 | 175 | WGL_SET_PROC(Uniform1f); |
michael@0 | 176 | WGL_SET_PROC(Uniform1i); |
michael@0 | 177 | WGL_SET_PROC(Uniform1fv); |
michael@0 | 178 | WGL_SET_PROC(Uniform1iv); |
michael@0 | 179 | WGL_SET_PROC(Uniform2f); |
michael@0 | 180 | WGL_SET_PROC(Uniform2i); |
michael@0 | 181 | WGL_SET_PROC(Uniform2fv); |
michael@0 | 182 | WGL_SET_PROC(Uniform2iv); |
michael@0 | 183 | WGL_SET_PROC(Uniform3f); |
michael@0 | 184 | WGL_SET_PROC(Uniform3i); |
michael@0 | 185 | WGL_SET_PROC(Uniform3fv); |
michael@0 | 186 | WGL_SET_PROC(Uniform3iv); |
michael@0 | 187 | WGL_SET_PROC(Uniform4f); |
michael@0 | 188 | WGL_SET_PROC(Uniform4i); |
michael@0 | 189 | WGL_SET_PROC(Uniform4fv); |
michael@0 | 190 | WGL_SET_PROC(Uniform4iv); |
michael@0 | 191 | WGL_SET_PROC(UniformMatrix2fv); |
michael@0 | 192 | WGL_SET_PROC(UniformMatrix3fv); |
michael@0 | 193 | WGL_SET_PROC(UniformMatrix4fv); |
michael@0 | 194 | WGL_SET_PROC(UseProgram); |
michael@0 | 195 | WGL_SET_PROC(VertexAttrib4fv); |
michael@0 | 196 | WGL_SET_PROC(VertexAttribPointer); |
michael@0 | 197 | WGL_SET_PROC(BindFragDataLocationIndexed); |
michael@0 | 198 | |
michael@0 | 199 | if (glVer >= GR_GL_VER(3,0) || extensions.has("GL_ARB_vertex_array_object")) { |
michael@0 | 200 | // no ARB suffix for GL_ARB_vertex_array_object |
michael@0 | 201 | WGL_SET_PROC(BindVertexArray); |
michael@0 | 202 | WGL_SET_PROC(DeleteVertexArrays); |
michael@0 | 203 | WGL_SET_PROC(GenVertexArrays); |
michael@0 | 204 | } |
michael@0 | 205 | |
michael@0 | 206 | // First look for GL3.0 FBO or GL_ARB_framebuffer_object (same since |
michael@0 | 207 | // GL_ARB_framebuffer_object doesn't use ARB suffix.) |
michael@0 | 208 | if (glVer >= GR_GL_VER(3,0) || extensions.has("GL_ARB_framebuffer_object")) { |
michael@0 | 209 | WGL_SET_PROC(GenFramebuffers); |
michael@0 | 210 | WGL_SET_PROC(GetFramebufferAttachmentParameteriv); |
michael@0 | 211 | WGL_SET_PROC(GetRenderbufferParameteriv); |
michael@0 | 212 | WGL_SET_PROC(BindFramebuffer); |
michael@0 | 213 | WGL_SET_PROC(FramebufferTexture2D); |
michael@0 | 214 | WGL_SET_PROC(CheckFramebufferStatus); |
michael@0 | 215 | WGL_SET_PROC(DeleteFramebuffers); |
michael@0 | 216 | WGL_SET_PROC(RenderbufferStorage); |
michael@0 | 217 | WGL_SET_PROC(GenRenderbuffers); |
michael@0 | 218 | WGL_SET_PROC(DeleteRenderbuffers); |
michael@0 | 219 | WGL_SET_PROC(FramebufferRenderbuffer); |
michael@0 | 220 | WGL_SET_PROC(BindRenderbuffer); |
michael@0 | 221 | WGL_SET_PROC(RenderbufferStorageMultisample); |
michael@0 | 222 | WGL_SET_PROC(BlitFramebuffer); |
michael@0 | 223 | } else if (extensions.has("GL_EXT_framebuffer_object")) { |
michael@0 | 224 | WGL_SET_PROC_SUFFIX(GenFramebuffers, EXT); |
michael@0 | 225 | WGL_SET_PROC_SUFFIX(GetFramebufferAttachmentParameteriv, EXT); |
michael@0 | 226 | WGL_SET_PROC_SUFFIX(GetRenderbufferParameteriv, EXT); |
michael@0 | 227 | WGL_SET_PROC_SUFFIX(BindFramebuffer, EXT); |
michael@0 | 228 | WGL_SET_PROC_SUFFIX(FramebufferTexture2D, EXT); |
michael@0 | 229 | WGL_SET_PROC_SUFFIX(CheckFramebufferStatus, EXT); |
michael@0 | 230 | WGL_SET_PROC_SUFFIX(DeleteFramebuffers, EXT); |
michael@0 | 231 | WGL_SET_PROC_SUFFIX(RenderbufferStorage, EXT); |
michael@0 | 232 | WGL_SET_PROC_SUFFIX(GenRenderbuffers, EXT); |
michael@0 | 233 | WGL_SET_PROC_SUFFIX(DeleteRenderbuffers, EXT); |
michael@0 | 234 | WGL_SET_PROC_SUFFIX(FramebufferRenderbuffer, EXT); |
michael@0 | 235 | WGL_SET_PROC_SUFFIX(BindRenderbuffer, EXT); |
michael@0 | 236 | if (extensions.has("GL_EXT_framebuffer_multisample")) { |
michael@0 | 237 | WGL_SET_PROC_SUFFIX(RenderbufferStorageMultisample, EXT); |
michael@0 | 238 | } |
michael@0 | 239 | if (extensions.has("GL_EXT_framebuffer_blit")) { |
michael@0 | 240 | WGL_SET_PROC_SUFFIX(BlitFramebuffer, EXT); |
michael@0 | 241 | } |
michael@0 | 242 | } else { |
michael@0 | 243 | // we must have FBOs |
michael@0 | 244 | delete interface; |
michael@0 | 245 | return NULL; |
michael@0 | 246 | } |
michael@0 | 247 | WGL_SET_PROC(MapBuffer); |
michael@0 | 248 | WGL_SET_PROC(UnmapBuffer); |
michael@0 | 249 | |
michael@0 | 250 | if (extensions.has("GL_NV_path_rendering")) { |
michael@0 | 251 | WGL_SET_PROC_SUFFIX(PathCommands, NV); |
michael@0 | 252 | WGL_SET_PROC_SUFFIX(PathCoords, NV); |
michael@0 | 253 | WGL_SET_PROC_SUFFIX(PathSubCommands, NV); |
michael@0 | 254 | WGL_SET_PROC_SUFFIX(PathSubCoords, NV); |
michael@0 | 255 | WGL_SET_PROC_SUFFIX(PathString, NV); |
michael@0 | 256 | WGL_SET_PROC_SUFFIX(PathGlyphs, NV); |
michael@0 | 257 | WGL_SET_PROC_SUFFIX(PathGlyphRange, NV); |
michael@0 | 258 | WGL_SET_PROC_SUFFIX(WeightPaths, NV); |
michael@0 | 259 | WGL_SET_PROC_SUFFIX(CopyPath, NV); |
michael@0 | 260 | WGL_SET_PROC_SUFFIX(InterpolatePaths, NV); |
michael@0 | 261 | WGL_SET_PROC_SUFFIX(TransformPath, NV); |
michael@0 | 262 | WGL_SET_PROC_SUFFIX(PathParameteriv, NV); |
michael@0 | 263 | WGL_SET_PROC_SUFFIX(PathParameteri, NV); |
michael@0 | 264 | WGL_SET_PROC_SUFFIX(PathParameterfv, NV); |
michael@0 | 265 | WGL_SET_PROC_SUFFIX(PathParameterf, NV); |
michael@0 | 266 | WGL_SET_PROC_SUFFIX(PathDashArray, NV); |
michael@0 | 267 | WGL_SET_PROC_SUFFIX(GenPaths, NV); |
michael@0 | 268 | WGL_SET_PROC_SUFFIX(DeletePaths, NV); |
michael@0 | 269 | WGL_SET_PROC_SUFFIX(IsPath, NV); |
michael@0 | 270 | WGL_SET_PROC_SUFFIX(PathStencilFunc, NV); |
michael@0 | 271 | WGL_SET_PROC_SUFFIX(PathStencilDepthOffset, NV); |
michael@0 | 272 | WGL_SET_PROC_SUFFIX(StencilFillPath, NV); |
michael@0 | 273 | WGL_SET_PROC_SUFFIX(StencilStrokePath, NV); |
michael@0 | 274 | WGL_SET_PROC_SUFFIX(StencilFillPathInstanced, NV); |
michael@0 | 275 | WGL_SET_PROC_SUFFIX(StencilStrokePathInstanced, NV); |
michael@0 | 276 | WGL_SET_PROC_SUFFIX(PathCoverDepthFunc, NV); |
michael@0 | 277 | WGL_SET_PROC_SUFFIX(PathColorGen, NV); |
michael@0 | 278 | WGL_SET_PROC_SUFFIX(PathTexGen, NV); |
michael@0 | 279 | WGL_SET_PROC_SUFFIX(PathFogGen, NV); |
michael@0 | 280 | WGL_SET_PROC_SUFFIX(CoverFillPath, NV); |
michael@0 | 281 | WGL_SET_PROC_SUFFIX(CoverStrokePath, NV); |
michael@0 | 282 | WGL_SET_PROC_SUFFIX(CoverFillPathInstanced, NV); |
michael@0 | 283 | WGL_SET_PROC_SUFFIX(CoverStrokePathInstanced, NV); |
michael@0 | 284 | WGL_SET_PROC_SUFFIX(GetPathParameteriv, NV); |
michael@0 | 285 | WGL_SET_PROC_SUFFIX(GetPathParameterfv, NV); |
michael@0 | 286 | WGL_SET_PROC_SUFFIX(GetPathCommands, NV); |
michael@0 | 287 | WGL_SET_PROC_SUFFIX(GetPathCoords, NV); |
michael@0 | 288 | WGL_SET_PROC_SUFFIX(GetPathDashArray, NV); |
michael@0 | 289 | WGL_SET_PROC_SUFFIX(GetPathMetrics, NV); |
michael@0 | 290 | WGL_SET_PROC_SUFFIX(GetPathMetricRange, NV); |
michael@0 | 291 | WGL_SET_PROC_SUFFIX(GetPathSpacing, NV); |
michael@0 | 292 | WGL_SET_PROC_SUFFIX(GetPathColorGeniv, NV); |
michael@0 | 293 | WGL_SET_PROC_SUFFIX(GetPathColorGenfv, NV); |
michael@0 | 294 | WGL_SET_PROC_SUFFIX(GetPathTexGeniv, NV); |
michael@0 | 295 | WGL_SET_PROC_SUFFIX(GetPathTexGenfv, NV); |
michael@0 | 296 | WGL_SET_PROC_SUFFIX(IsPointInFillPath, NV); |
michael@0 | 297 | WGL_SET_PROC_SUFFIX(IsPointInStrokePath, NV); |
michael@0 | 298 | WGL_SET_PROC_SUFFIX(GetPathLength, NV); |
michael@0 | 299 | WGL_SET_PROC_SUFFIX(PointAlongPath, NV); |
michael@0 | 300 | } |
michael@0 | 301 | |
michael@0 | 302 | if (extensions.has("GL_EXT_debug_marker")) { |
michael@0 | 303 | WGL_SET_PROC_SUFFIX(InsertEventMarker, EXT); |
michael@0 | 304 | WGL_SET_PROC_SUFFIX(PushGroupMarker, EXT); |
michael@0 | 305 | WGL_SET_PROC_SUFFIX(PopGroupMarker, EXT); |
michael@0 | 306 | } |
michael@0 | 307 | |
michael@0 | 308 | interface->fStandard = kGL_GrGLStandard; |
michael@0 | 309 | interface->fExtensions.swap(&extensions); |
michael@0 | 310 | |
michael@0 | 311 | return interface; |
michael@0 | 312 | } else { |
michael@0 | 313 | return NULL; |
michael@0 | 314 | } |
michael@0 | 315 | } |