OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include <vector> |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "app/gfx/gl/gl_bindings.h" |
| 9 #include "app/gfx/gl/gl_implementation.h" |
| 10 |
| 11 namespace gfx { |
| 12 |
| 13 namespace { |
| 14 |
| 15 typedef void* (GL_BINDING_CALL *GetProcAddressProc)(const char* name); |
| 16 |
| 17 GLImplementation g_gl_implementation = kGLImplementationNone; |
| 18 std::vector<HMODULE> g_modules; |
| 19 static GetProcAddressProc g_get_proc_address; |
| 20 |
| 21 void GL_BINDING_CALL MarshalClearDepthToClearDepthf(GLclampd depth) { |
| 22 glClearDepthf(static_cast<GLclampf>(depth)); |
| 23 } |
| 24 |
| 25 void GL_BINDING_CALL MarshalDepthRangeToDepthRangef(GLclampd z_near, |
| 26 GLclampd z_far) { |
| 27 glDepthRangef(static_cast<GLclampf>(z_near), static_cast<GLclampf>(z_far)); |
| 28 } |
| 29 |
| 30 } // namespace anonymous |
| 31 |
| 32 bool InitializeGLBindings(GLImplementation implementation) { |
| 33 // Prevent reinitialization with a different implementation. Once the gpu |
| 34 // unit tests have initialized with kGLImplementationMock, we don't want to |
| 35 // later switch to another GL implementation. |
| 36 if (g_gl_implementation != kGLImplementationNone) |
| 37 return true; |
| 38 |
| 39 HMODULE module; |
| 40 switch (implementation) { |
| 41 case kGLImplementationOSMesaGL: |
| 42 // When using OSMesa, just use OSMesaGetProcAddress to find entry points. |
| 43 module = LoadLibraryA("osmesa.dll"); |
| 44 if (!module) |
| 45 return false; |
| 46 |
| 47 g_gl_implementation = kGLImplementationOSMesaGL; |
| 48 |
| 49 g_get_proc_address = reinterpret_cast<GetProcAddressProc>( |
| 50 GetProcAddress(module, "OSMesaGetProcAddress")); |
| 51 DCHECK(g_get_proc_address); |
| 52 |
| 53 InitializeGLBindingsGL(); |
| 54 InitializeGLBindingsOSMESA(); |
| 55 break; |
| 56 |
| 57 case kGLImplementationEGLGLES2: |
| 58 // When using EGL, first try eglGetProcAddress and then Windows |
| 59 // GetProcAddress on both the EGL and GLES2 DLLs. |
| 60 module = LoadLibraryA("libegl.dll"); |
| 61 if (!module) |
| 62 return false; |
| 63 |
| 64 g_gl_implementation = kGLImplementationEGLGLES2; |
| 65 |
| 66 g_get_proc_address = reinterpret_cast<GetProcAddressProc>( |
| 67 GetProcAddress(module, "eglGetProcAddress")); |
| 68 DCHECK(g_get_proc_address); |
| 69 |
| 70 g_modules.push_back(module); |
| 71 |
| 72 module = LoadLibraryA("libglesv2.dll"); |
| 73 DCHECK(module); |
| 74 |
| 75 g_modules.push_back(module); |
| 76 |
| 77 InitializeGLBindingsGL(); |
| 78 InitializeGLBindingsEGL(); |
| 79 |
| 80 // These two functions take single precision float ranther than double |
| 81 // precision float parameters in GLES. |
| 82 ::gfx::g_glClearDepth = MarshalClearDepthToClearDepthf; |
| 83 ::gfx::g_glDepthRange = MarshalDepthRangeToDepthRangef; |
| 84 break; |
| 85 |
| 86 case kGLImplementationDesktopGL: |
| 87 // When using Windows OpenGL, first try wglGetProcAddress and then |
| 88 // Windows GetProcAddress. |
| 89 module = LoadLibraryA("opengl32.dll"); |
| 90 if (!module) |
| 91 return false; |
| 92 |
| 93 g_gl_implementation = kGLImplementationDesktopGL; |
| 94 |
| 95 g_get_proc_address = reinterpret_cast<GetProcAddressProc>( |
| 96 GetProcAddress(module, "wglGetProcAddress")); |
| 97 DCHECK(g_get_proc_address); |
| 98 |
| 99 g_modules.push_back(module); |
| 100 |
| 101 InitializeGLBindingsGL(); |
| 102 InitializeGLBindingsWGL(); |
| 103 break; |
| 104 |
| 105 case kGLImplementationMockGL: |
| 106 g_get_proc_address = GetMockGLProcAddress; |
| 107 g_gl_implementation = kGLImplementationMockGL; |
| 108 InitializeGLBindingsGL(); |
| 109 break; |
| 110 |
| 111 default: |
| 112 return false; |
| 113 } |
| 114 |
| 115 return true; |
| 116 } |
| 117 |
| 118 GLImplementation GetGLImplementation() { |
| 119 return g_gl_implementation; |
| 120 } |
| 121 |
| 122 void* GetGLProcAddress(const char* name) { |
| 123 DCHECK(g_gl_implementation != kGLImplementationNone); |
| 124 |
| 125 if (g_get_proc_address) { |
| 126 void* proc = g_get_proc_address(name); |
| 127 if (proc) |
| 128 return proc; |
| 129 } |
| 130 |
| 131 for (size_t i = 0; i < g_modules.size(); ++i) { |
| 132 void* proc = GetProcAddress(g_modules[i], name); |
| 133 if (proc) |
| 134 return proc; |
| 135 } |
| 136 |
| 137 return NULL; |
| 138 } |
| 139 |
| 140 } // namespace gfx |
OLD | NEW |