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 <dlfcn.h> |
| 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 namespace { |
| 13 typedef void* (*GetProcAddressProc)(const char* name); |
| 14 |
| 15 GLImplementation g_gl_implementation = kGLImplementationNone; |
| 16 void* g_shared_library; |
| 17 GetProcAddressProc g_get_proc_address; |
| 18 } // namespace anonymous |
| 19 |
| 20 bool InitializeGLBindings(GLImplementation implementation) { |
| 21 // Prevent reinitialization with a different implementation. Once the gpu |
| 22 // unit tests have initialized with kGLImplementationMock, we don't want to |
| 23 // later switch to another GL implementation. |
| 24 if (g_gl_implementation != kGLImplementationNone) |
| 25 return true; |
| 26 |
| 27 switch (implementation) { |
| 28 case kGLImplementationDesktopGL: |
| 29 g_shared_library = dlopen( |
| 30 "/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL", |
| 31 RTLD_LAZY | RTLD_LOCAL); |
| 32 if (!g_shared_library) |
| 33 return false; |
| 34 |
| 35 g_gl_implementation = kGLImplementationDesktopGL; |
| 36 g_get_proc_address = NULL; |
| 37 |
| 38 InitializeGLBindingsGL(); |
| 39 break; |
| 40 |
| 41 case kGLImplementationMockGL: |
| 42 g_get_proc_address = GetMockGLProcAddress; |
| 43 g_gl_implementation = kGLImplementationMockGL; |
| 44 InitializeGLBindingsGL(); |
| 45 break; |
| 46 |
| 47 default: |
| 48 return false; |
| 49 } |
| 50 |
| 51 return true; |
| 52 } |
| 53 |
| 54 GLImplementation GetGLImplementation() { |
| 55 return g_gl_implementation; |
| 56 } |
| 57 |
| 58 void* GetGLProcAddress(const char* name) { |
| 59 DCHECK(g_gl_implementation != kGLImplementationNone); |
| 60 |
| 61 if (g_get_proc_address) { |
| 62 void* proc = g_get_proc_address(name); |
| 63 if (proc) |
| 64 return proc; |
| 65 } |
| 66 |
| 67 if (g_shared_library) { |
| 68 void* proc = dlsym(g_shared_library, name); |
| 69 if (proc) |
| 70 return proc; |
| 71 } |
| 72 |
| 73 return NULL; |
| 74 } |
| 75 |
| 76 } // namespace gfx |
OLD | NEW |