1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/src/gpu/gl/win/GrGLCreateNativeInterface_win.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,315 @@ 1.4 + 1.5 +/* 1.6 + * Copyright 2011 Google Inc. 1.7 + * 1.8 + * Use of this source code is governed by a BSD-style license that can be 1.9 + * found in the LICENSE file. 1.10 + */ 1.11 + 1.12 +#include "gl/GrGLInterface.h" 1.13 +#include "gl/GrGLUtil.h" 1.14 +#define WIN32_LEAN_AND_MEAN 1.15 +#include <windows.h> 1.16 + 1.17 +/* 1.18 + * Windows makes the GL funcs all be __stdcall instead of __cdecl :( 1.19 + * This implementation will only work if GR_GL_FUNCTION_TYPE is __stdcall. 1.20 + * Otherwise, a springboard would be needed that hides the calling convention. 1.21 + */ 1.22 + 1.23 +#define SET_PROC(F) interface->fFunctions.f ## F = (GrGL ## F ## Proc) GetProcAddress(alu.get(), "gl" #F); 1.24 +#define WGL_SET_PROC(F) interface->fFunctions.f ## F = (GrGL ## F ## Proc) wglGetProcAddress("gl" #F); 1.25 +#define WGL_SET_PROC_SUFFIX(F, S) interface->fFunctions.f ## F = (GrGL ## F ## Proc) wglGetProcAddress("gl" #F #S); 1.26 + 1.27 +class AutoLibraryUnload { 1.28 +public: 1.29 + AutoLibraryUnload(const char* moduleName) { 1.30 + fModule = LoadLibrary(moduleName); 1.31 + } 1.32 + ~AutoLibraryUnload() { 1.33 + if (NULL != fModule) { 1.34 + FreeLibrary(fModule); 1.35 + } 1.36 + } 1.37 + HMODULE get() const { return fModule; } 1.38 + 1.39 +private: 1.40 + HMODULE fModule; 1.41 +}; 1.42 + 1.43 +const GrGLInterface* GrGLCreateNativeInterface() { 1.44 + AutoLibraryUnload alu("opengl32.dll"); 1.45 + if (NULL == alu.get()) { 1.46 + return NULL; 1.47 + } 1.48 + 1.49 + if (NULL != wglGetCurrentContext()) { 1.50 + 1.51 + // These should always be present and don't require wglGetProcAddress 1.52 + GrGLGetStringProc glGetString = 1.53 + (GrGLGetStringProc) GetProcAddress(alu.get(), "glGetString"); 1.54 + GrGLGetIntegervProc glGetIntegerv = 1.55 + (GrGLGetIntegervProc) GetProcAddress(alu.get(), "glGetIntegerv"); 1.56 + if (NULL == glGetString || NULL == glGetIntegerv) { 1.57 + return NULL; 1.58 + } 1.59 + 1.60 + // This may or may not succeed depending on the gl version. 1.61 + GrGLGetStringiProc glGetStringi = (GrGLGetStringiProc) wglGetProcAddress("glGetStringi"); 1.62 + 1.63 + GrGLExtensions extensions; 1.64 + if (!extensions.init(kGL_GrGLStandard, glGetString, glGetStringi, glGetIntegerv)) { 1.65 + return NULL; 1.66 + } 1.67 + const char* versionString = (const char*) glGetString(GR_GL_VERSION); 1.68 + GrGLVersion glVer = GrGLGetVersionFromString(versionString); 1.69 + 1.70 + if (glVer < GR_GL_VER(1,5)) { 1.71 + // We must have array and element_array buffer objects. 1.72 + return NULL; 1.73 + } 1.74 + GrGLInterface* interface = SkNEW(GrGLInterface); 1.75 + 1.76 + // Functions that are part of GL 1.1 will return NULL in 1.77 + // wglGetProcAddress 1.78 + SET_PROC(BindTexture) 1.79 + SET_PROC(BlendFunc) 1.80 + 1.81 + if (glVer >= GR_GL_VER(1,4) || 1.82 + extensions.has("GL_ARB_imaging") || 1.83 + extensions.has("GL_EXT_blend_color")) { 1.84 + WGL_SET_PROC(BlendColor); 1.85 + } 1.86 + 1.87 + SET_PROC(Clear) 1.88 + SET_PROC(ClearColor) 1.89 + SET_PROC(ClearStencil) 1.90 + SET_PROC(ColorMask) 1.91 + SET_PROC(CopyTexSubImage2D) 1.92 + SET_PROC(CullFace) 1.93 + SET_PROC(DeleteTextures) 1.94 + SET_PROC(DepthMask) 1.95 + SET_PROC(Disable) 1.96 + SET_PROC(DrawArrays) 1.97 + SET_PROC(DrawElements) 1.98 + SET_PROC(DrawBuffer) 1.99 + SET_PROC(Enable) 1.100 + SET_PROC(FrontFace) 1.101 + SET_PROC(Finish) 1.102 + SET_PROC(Flush) 1.103 + SET_PROC(GenTextures) 1.104 + SET_PROC(GetError) 1.105 + SET_PROC(GetIntegerv) 1.106 + SET_PROC(GetString) 1.107 + SET_PROC(GetTexLevelParameteriv) 1.108 + SET_PROC(LineWidth) 1.109 + SET_PROC(LoadIdentity) 1.110 + SET_PROC(LoadMatrixf) 1.111 + SET_PROC(MatrixMode) 1.112 + SET_PROC(PixelStorei) 1.113 + SET_PROC(ReadBuffer) 1.114 + SET_PROC(ReadPixels) 1.115 + SET_PROC(Scissor) 1.116 + SET_PROC(StencilFunc) 1.117 + SET_PROC(StencilMask) 1.118 + SET_PROC(StencilOp) 1.119 + SET_PROC(TexGenfv) 1.120 + SET_PROC(TexGeni) 1.121 + SET_PROC(TexImage2D) 1.122 + SET_PROC(TexParameteri) 1.123 + SET_PROC(TexParameteriv) 1.124 + if (glVer >= GR_GL_VER(4,2) || extensions.has("GL_ARB_texture_storage")) { 1.125 + WGL_SET_PROC(TexStorage2D); 1.126 + } else if (extensions.has("GL_EXT_texture_storage")) { 1.127 + WGL_SET_PROC_SUFFIX(TexStorage2D, EXT); 1.128 + } 1.129 + SET_PROC(TexSubImage2D) 1.130 + SET_PROC(Viewport) 1.131 + 1.132 + WGL_SET_PROC(ActiveTexture); 1.133 + WGL_SET_PROC(AttachShader); 1.134 + WGL_SET_PROC(BeginQuery); 1.135 + WGL_SET_PROC(BindAttribLocation); 1.136 + WGL_SET_PROC(BindBuffer); 1.137 + WGL_SET_PROC(BindFragDataLocation); 1.138 + WGL_SET_PROC(BufferData); 1.139 + WGL_SET_PROC(BufferSubData); 1.140 + WGL_SET_PROC(CompileShader); 1.141 + WGL_SET_PROC(CompressedTexImage2D); 1.142 + WGL_SET_PROC(CreateProgram); 1.143 + WGL_SET_PROC(CreateShader); 1.144 + WGL_SET_PROC(DeleteBuffers); 1.145 + WGL_SET_PROC(DeleteQueries); 1.146 + WGL_SET_PROC(DeleteProgram); 1.147 + WGL_SET_PROC(DeleteShader); 1.148 + WGL_SET_PROC(DisableVertexAttribArray); 1.149 + WGL_SET_PROC(DrawBuffers); 1.150 + WGL_SET_PROC(EnableVertexAttribArray); 1.151 + WGL_SET_PROC(EndQuery); 1.152 + WGL_SET_PROC(GenBuffers); 1.153 + WGL_SET_PROC(GenerateMipmap); 1.154 + WGL_SET_PROC(GenQueries); 1.155 + WGL_SET_PROC(GetBufferParameteriv); 1.156 + WGL_SET_PROC(GetQueryiv); 1.157 + WGL_SET_PROC(GetQueryObjectiv); 1.158 + WGL_SET_PROC(GetQueryObjectuiv); 1.159 + if (glVer > GR_GL_VER(3,3) || extensions.has("GL_ARB_timer_query")) { 1.160 + WGL_SET_PROC(GetQueryObjecti64v); 1.161 + WGL_SET_PROC(GetQueryObjectui64v); 1.162 + WGL_SET_PROC(QueryCounter); 1.163 + } else if (extensions.has("GL_EXT_timer_query")) { 1.164 + WGL_SET_PROC_SUFFIX(GetQueryObjecti64v, EXT); 1.165 + WGL_SET_PROC_SUFFIX(GetQueryObjectui64v, EXT); 1.166 + } 1.167 + WGL_SET_PROC(GetProgramInfoLog); 1.168 + WGL_SET_PROC(GetProgramiv); 1.169 + WGL_SET_PROC(GetShaderInfoLog); 1.170 + WGL_SET_PROC(GetShaderiv); 1.171 + WGL_SET_PROC(GetStringi) 1.172 + WGL_SET_PROC(GetUniformLocation); 1.173 + WGL_SET_PROC(LinkProgram); 1.174 + WGL_SET_PROC(ShaderSource); 1.175 + WGL_SET_PROC(StencilFuncSeparate); 1.176 + WGL_SET_PROC(StencilMaskSeparate); 1.177 + WGL_SET_PROC(StencilOpSeparate); 1.178 + WGL_SET_PROC(Uniform1f); 1.179 + WGL_SET_PROC(Uniform1i); 1.180 + WGL_SET_PROC(Uniform1fv); 1.181 + WGL_SET_PROC(Uniform1iv); 1.182 + WGL_SET_PROC(Uniform2f); 1.183 + WGL_SET_PROC(Uniform2i); 1.184 + WGL_SET_PROC(Uniform2fv); 1.185 + WGL_SET_PROC(Uniform2iv); 1.186 + WGL_SET_PROC(Uniform3f); 1.187 + WGL_SET_PROC(Uniform3i); 1.188 + WGL_SET_PROC(Uniform3fv); 1.189 + WGL_SET_PROC(Uniform3iv); 1.190 + WGL_SET_PROC(Uniform4f); 1.191 + WGL_SET_PROC(Uniform4i); 1.192 + WGL_SET_PROC(Uniform4fv); 1.193 + WGL_SET_PROC(Uniform4iv); 1.194 + WGL_SET_PROC(UniformMatrix2fv); 1.195 + WGL_SET_PROC(UniformMatrix3fv); 1.196 + WGL_SET_PROC(UniformMatrix4fv); 1.197 + WGL_SET_PROC(UseProgram); 1.198 + WGL_SET_PROC(VertexAttrib4fv); 1.199 + WGL_SET_PROC(VertexAttribPointer); 1.200 + WGL_SET_PROC(BindFragDataLocationIndexed); 1.201 + 1.202 + if (glVer >= GR_GL_VER(3,0) || extensions.has("GL_ARB_vertex_array_object")) { 1.203 + // no ARB suffix for GL_ARB_vertex_array_object 1.204 + WGL_SET_PROC(BindVertexArray); 1.205 + WGL_SET_PROC(DeleteVertexArrays); 1.206 + WGL_SET_PROC(GenVertexArrays); 1.207 + } 1.208 + 1.209 + // First look for GL3.0 FBO or GL_ARB_framebuffer_object (same since 1.210 + // GL_ARB_framebuffer_object doesn't use ARB suffix.) 1.211 + if (glVer >= GR_GL_VER(3,0) || extensions.has("GL_ARB_framebuffer_object")) { 1.212 + WGL_SET_PROC(GenFramebuffers); 1.213 + WGL_SET_PROC(GetFramebufferAttachmentParameteriv); 1.214 + WGL_SET_PROC(GetRenderbufferParameteriv); 1.215 + WGL_SET_PROC(BindFramebuffer); 1.216 + WGL_SET_PROC(FramebufferTexture2D); 1.217 + WGL_SET_PROC(CheckFramebufferStatus); 1.218 + WGL_SET_PROC(DeleteFramebuffers); 1.219 + WGL_SET_PROC(RenderbufferStorage); 1.220 + WGL_SET_PROC(GenRenderbuffers); 1.221 + WGL_SET_PROC(DeleteRenderbuffers); 1.222 + WGL_SET_PROC(FramebufferRenderbuffer); 1.223 + WGL_SET_PROC(BindRenderbuffer); 1.224 + WGL_SET_PROC(RenderbufferStorageMultisample); 1.225 + WGL_SET_PROC(BlitFramebuffer); 1.226 + } else if (extensions.has("GL_EXT_framebuffer_object")) { 1.227 + WGL_SET_PROC_SUFFIX(GenFramebuffers, EXT); 1.228 + WGL_SET_PROC_SUFFIX(GetFramebufferAttachmentParameteriv, EXT); 1.229 + WGL_SET_PROC_SUFFIX(GetRenderbufferParameteriv, EXT); 1.230 + WGL_SET_PROC_SUFFIX(BindFramebuffer, EXT); 1.231 + WGL_SET_PROC_SUFFIX(FramebufferTexture2D, EXT); 1.232 + WGL_SET_PROC_SUFFIX(CheckFramebufferStatus, EXT); 1.233 + WGL_SET_PROC_SUFFIX(DeleteFramebuffers, EXT); 1.234 + WGL_SET_PROC_SUFFIX(RenderbufferStorage, EXT); 1.235 + WGL_SET_PROC_SUFFIX(GenRenderbuffers, EXT); 1.236 + WGL_SET_PROC_SUFFIX(DeleteRenderbuffers, EXT); 1.237 + WGL_SET_PROC_SUFFIX(FramebufferRenderbuffer, EXT); 1.238 + WGL_SET_PROC_SUFFIX(BindRenderbuffer, EXT); 1.239 + if (extensions.has("GL_EXT_framebuffer_multisample")) { 1.240 + WGL_SET_PROC_SUFFIX(RenderbufferStorageMultisample, EXT); 1.241 + } 1.242 + if (extensions.has("GL_EXT_framebuffer_blit")) { 1.243 + WGL_SET_PROC_SUFFIX(BlitFramebuffer, EXT); 1.244 + } 1.245 + } else { 1.246 + // we must have FBOs 1.247 + delete interface; 1.248 + return NULL; 1.249 + } 1.250 + WGL_SET_PROC(MapBuffer); 1.251 + WGL_SET_PROC(UnmapBuffer); 1.252 + 1.253 + if (extensions.has("GL_NV_path_rendering")) { 1.254 + WGL_SET_PROC_SUFFIX(PathCommands, NV); 1.255 + WGL_SET_PROC_SUFFIX(PathCoords, NV); 1.256 + WGL_SET_PROC_SUFFIX(PathSubCommands, NV); 1.257 + WGL_SET_PROC_SUFFIX(PathSubCoords, NV); 1.258 + WGL_SET_PROC_SUFFIX(PathString, NV); 1.259 + WGL_SET_PROC_SUFFIX(PathGlyphs, NV); 1.260 + WGL_SET_PROC_SUFFIX(PathGlyphRange, NV); 1.261 + WGL_SET_PROC_SUFFIX(WeightPaths, NV); 1.262 + WGL_SET_PROC_SUFFIX(CopyPath, NV); 1.263 + WGL_SET_PROC_SUFFIX(InterpolatePaths, NV); 1.264 + WGL_SET_PROC_SUFFIX(TransformPath, NV); 1.265 + WGL_SET_PROC_SUFFIX(PathParameteriv, NV); 1.266 + WGL_SET_PROC_SUFFIX(PathParameteri, NV); 1.267 + WGL_SET_PROC_SUFFIX(PathParameterfv, NV); 1.268 + WGL_SET_PROC_SUFFIX(PathParameterf, NV); 1.269 + WGL_SET_PROC_SUFFIX(PathDashArray, NV); 1.270 + WGL_SET_PROC_SUFFIX(GenPaths, NV); 1.271 + WGL_SET_PROC_SUFFIX(DeletePaths, NV); 1.272 + WGL_SET_PROC_SUFFIX(IsPath, NV); 1.273 + WGL_SET_PROC_SUFFIX(PathStencilFunc, NV); 1.274 + WGL_SET_PROC_SUFFIX(PathStencilDepthOffset, NV); 1.275 + WGL_SET_PROC_SUFFIX(StencilFillPath, NV); 1.276 + WGL_SET_PROC_SUFFIX(StencilStrokePath, NV); 1.277 + WGL_SET_PROC_SUFFIX(StencilFillPathInstanced, NV); 1.278 + WGL_SET_PROC_SUFFIX(StencilStrokePathInstanced, NV); 1.279 + WGL_SET_PROC_SUFFIX(PathCoverDepthFunc, NV); 1.280 + WGL_SET_PROC_SUFFIX(PathColorGen, NV); 1.281 + WGL_SET_PROC_SUFFIX(PathTexGen, NV); 1.282 + WGL_SET_PROC_SUFFIX(PathFogGen, NV); 1.283 + WGL_SET_PROC_SUFFIX(CoverFillPath, NV); 1.284 + WGL_SET_PROC_SUFFIX(CoverStrokePath, NV); 1.285 + WGL_SET_PROC_SUFFIX(CoverFillPathInstanced, NV); 1.286 + WGL_SET_PROC_SUFFIX(CoverStrokePathInstanced, NV); 1.287 + WGL_SET_PROC_SUFFIX(GetPathParameteriv, NV); 1.288 + WGL_SET_PROC_SUFFIX(GetPathParameterfv, NV); 1.289 + WGL_SET_PROC_SUFFIX(GetPathCommands, NV); 1.290 + WGL_SET_PROC_SUFFIX(GetPathCoords, NV); 1.291 + WGL_SET_PROC_SUFFIX(GetPathDashArray, NV); 1.292 + WGL_SET_PROC_SUFFIX(GetPathMetrics, NV); 1.293 + WGL_SET_PROC_SUFFIX(GetPathMetricRange, NV); 1.294 + WGL_SET_PROC_SUFFIX(GetPathSpacing, NV); 1.295 + WGL_SET_PROC_SUFFIX(GetPathColorGeniv, NV); 1.296 + WGL_SET_PROC_SUFFIX(GetPathColorGenfv, NV); 1.297 + WGL_SET_PROC_SUFFIX(GetPathTexGeniv, NV); 1.298 + WGL_SET_PROC_SUFFIX(GetPathTexGenfv, NV); 1.299 + WGL_SET_PROC_SUFFIX(IsPointInFillPath, NV); 1.300 + WGL_SET_PROC_SUFFIX(IsPointInStrokePath, NV); 1.301 + WGL_SET_PROC_SUFFIX(GetPathLength, NV); 1.302 + WGL_SET_PROC_SUFFIX(PointAlongPath, NV); 1.303 + } 1.304 + 1.305 + if (extensions.has("GL_EXT_debug_marker")) { 1.306 + WGL_SET_PROC_SUFFIX(InsertEventMarker, EXT); 1.307 + WGL_SET_PROC_SUFFIX(PushGroupMarker, EXT); 1.308 + WGL_SET_PROC_SUFFIX(PopGroupMarker, EXT); 1.309 + } 1.310 + 1.311 + interface->fStandard = kGL_GrGLStandard; 1.312 + interface->fExtensions.swap(&extensions); 1.313 + 1.314 + return interface; 1.315 + } else { 1.316 + return NULL; 1.317 + } 1.318 +}