| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/base_paths.h" | 5 #include "base/base_paths.h" |
| 6 #include "base/file_path.h" | 6 #include "base/file_path.h" |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/mac/foundation_util.h" | 8 #include "base/mac/foundation_util.h" |
| 9 #include "base/native_library.h" | 9 #include "base/native_library.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 // Allow the main thread or another to initialize these bindings | 36 // Allow the main thread or another to initialize these bindings |
| 37 // after instituting restrictions on I/O. Going forward they will | 37 // after instituting restrictions on I/O. Going forward they will |
| 38 // likely be used in the browser process on most platforms. The | 38 // likely be used in the browser process on most platforms. The |
| 39 // one-time initialization cost is small, between 2 and 5 ms. | 39 // one-time initialization cost is small, between 2 and 5 ms. |
| 40 base::ThreadRestrictions::ScopedAllowIO allow_io; | 40 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 41 | 41 |
| 42 switch (implementation) { | 42 switch (implementation) { |
| 43 case kGLImplementationOSMesaGL: { | 43 case kGLImplementationOSMesaGL: { |
| 44 // osmesa.so is located in the build directory. This code path is only | 44 // osmesa.so is located in the build directory. This code path is only |
| 45 // valid in a developer build environment. | 45 // valid in a developer build environment. |
| 46 FilePath exe_path; | 46 base::FilePath exe_path; |
| 47 if (!PathService::Get(base::FILE_EXE, &exe_path)) { | 47 if (!PathService::Get(base::FILE_EXE, &exe_path)) { |
| 48 LOG(ERROR) << "PathService::Get failed."; | 48 LOG(ERROR) << "PathService::Get failed."; |
| 49 return false; | 49 return false; |
| 50 } | 50 } |
| 51 FilePath bundle_path = base::mac::GetAppBundlePath(exe_path); | 51 base::FilePath bundle_path = base::mac::GetAppBundlePath(exe_path); |
| 52 // Some unit test targets depend on osmesa but aren't built as app | 52 // Some unit test targets depend on osmesa but aren't built as app |
| 53 // bundles. In that case, the .so is next to the executable. | 53 // bundles. In that case, the .so is next to the executable. |
| 54 if (bundle_path.empty()) | 54 if (bundle_path.empty()) |
| 55 bundle_path = exe_path; | 55 bundle_path = exe_path; |
| 56 FilePath build_dir_path = bundle_path.DirName(); | 56 base::FilePath build_dir_path = bundle_path.DirName(); |
| 57 FilePath osmesa_path = build_dir_path.Append("osmesa.so"); | 57 base::FilePath osmesa_path = build_dir_path.Append("osmesa.so"); |
| 58 | 58 |
| 59 // When using OSMesa, just use OSMesaGetProcAddress to find entry points. | 59 // When using OSMesa, just use OSMesaGetProcAddress to find entry points. |
| 60 base::NativeLibrary library = base::LoadNativeLibrary(osmesa_path, NULL); | 60 base::NativeLibrary library = base::LoadNativeLibrary(osmesa_path, NULL); |
| 61 if (!library) { | 61 if (!library) { |
| 62 LOG(ERROR) << "osmesa.so not found at " << osmesa_path.value(); | 62 LOG(ERROR) << "osmesa.so not found at " << osmesa_path.value(); |
| 63 return false; | 63 return false; |
| 64 } | 64 } |
| 65 | 65 |
| 66 GLGetProcAddressProc get_proc_address = | 66 GLGetProcAddressProc get_proc_address = |
| 67 reinterpret_cast<GLGetProcAddressProc>( | 67 reinterpret_cast<GLGetProcAddressProc>( |
| 68 base::GetFunctionPointerFromNativeLibrary( | 68 base::GetFunctionPointerFromNativeLibrary( |
| 69 library, "OSMesaGetProcAddress")); | 69 library, "OSMesaGetProcAddress")); |
| 70 if (!get_proc_address) { | 70 if (!get_proc_address) { |
| 71 LOG(ERROR) << "OSMesaGetProcAddress not found."; | 71 LOG(ERROR) << "OSMesaGetProcAddress not found."; |
| 72 base::UnloadNativeLibrary(library); | 72 base::UnloadNativeLibrary(library); |
| 73 return false; | 73 return false; |
| 74 } | 74 } |
| 75 | 75 |
| 76 SetGLGetProcAddressProc(get_proc_address); | 76 SetGLGetProcAddressProc(get_proc_address); |
| 77 AddGLNativeLibrary(library); | 77 AddGLNativeLibrary(library); |
| 78 SetGLImplementation(kGLImplementationOSMesaGL); | 78 SetGLImplementation(kGLImplementationOSMesaGL); |
| 79 | 79 |
| 80 InitializeGLBindingsGL(); | 80 InitializeGLBindingsGL(); |
| 81 InitializeGLBindingsOSMESA(); | 81 InitializeGLBindingsOSMESA(); |
| 82 break; | 82 break; |
| 83 } | 83 } |
| 84 case kGLImplementationDesktopGL: | 84 case kGLImplementationDesktopGL: |
| 85 case kGLImplementationAppleGL: { | 85 case kGLImplementationAppleGL: { |
| 86 base::NativeLibrary library = base::LoadNativeLibrary( | 86 base::NativeLibrary library = base::LoadNativeLibrary( |
| 87 FilePath(kOpenGLFrameworkPath), NULL); | 87 base::FilePath(kOpenGLFrameworkPath), NULL); |
| 88 if (!library) { | 88 if (!library) { |
| 89 LOG(ERROR) << "OpenGL framework not found"; | 89 LOG(ERROR) << "OpenGL framework not found"; |
| 90 return false; | 90 return false; |
| 91 } | 91 } |
| 92 | 92 |
| 93 AddGLNativeLibrary(library); | 93 AddGLNativeLibrary(library); |
| 94 SetGLImplementation(implementation); | 94 SetGLImplementation(implementation); |
| 95 | 95 |
| 96 InitializeGLBindingsGL(); | 96 InitializeGLBindingsGL(); |
| 97 break; | 97 break; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 | 137 |
| 138 void ClearGLBindings() { | 138 void ClearGLBindings() { |
| 139 ClearGLBindingsGL(); | 139 ClearGLBindingsGL(); |
| 140 ClearGLBindingsOSMESA(); | 140 ClearGLBindingsOSMESA(); |
| 141 SetGLImplementation(kGLImplementationNone); | 141 SetGLImplementation(kGLImplementationNone); |
| 142 | 142 |
| 143 UnloadGLNativeLibraries(); | 143 UnloadGLNativeLibraries(); |
| 144 } | 144 } |
| 145 | 145 |
| 146 } // namespace gfx | 146 } // namespace gfx |
| OLD | NEW |