OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 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 "ui/gl/gl_implementation_linux.h" |
| 6 |
| 7 #include "base/files/file_path.h" |
| 8 #include "base/logging.h" |
| 9 #include "base/native_library.h" |
| 10 #include "base/path_service.h" |
| 11 #include "ui/gl/gl_bindings.h" |
| 12 #include "ui/gl/gl_gl_api_implementation.h" |
| 13 #include "ui/gl/gl_implementation.h" |
| 14 #include "ui/gl/gl_osmesa_api_implementation.h" |
| 15 |
| 16 namespace gfx { |
| 17 |
| 18 // Load a library, printing an error message on failure. |
| 19 base::NativeLibrary LoadLibrary(const base::FilePath& filename) { |
| 20 std::string error; |
| 21 base::NativeLibrary library = base::LoadNativeLibrary(filename, |
| 22 &error); |
| 23 if (!library) { |
| 24 DVLOG(1) << "Failed to load " << filename.MaybeAsASCII() << ": " << error; |
| 25 return NULL; |
| 26 } |
| 27 return library; |
| 28 } |
| 29 |
| 30 base::NativeLibrary LoadLibrary(const char* filename) { |
| 31 return LoadLibrary(base::FilePath(filename)); |
| 32 } |
| 33 |
| 34 bool InitializeGLBindingsOSMesaGL() { |
| 35 base::FilePath module_path; |
| 36 if (!PathService::Get(base::DIR_MODULE, &module_path)) { |
| 37 LOG(ERROR) << "PathService::Get failed."; |
| 38 return false; |
| 39 } |
| 40 |
| 41 base::NativeLibrary library = LoadLibrary( |
| 42 module_path.Append("libosmesa.so")); |
| 43 if (!library) |
| 44 return false; |
| 45 |
| 46 GLGetProcAddressProc get_proc_address = |
| 47 reinterpret_cast<GLGetProcAddressProc>( |
| 48 base::GetFunctionPointerFromNativeLibrary( |
| 49 library, "OSMesaGetProcAddress")); |
| 50 if (!get_proc_address) { |
| 51 LOG(ERROR) << "OSMesaGetProcAddress not found."; |
| 52 base::UnloadNativeLibrary(library); |
| 53 return false; |
| 54 } |
| 55 |
| 56 SetGLGetProcAddressProc(get_proc_address); |
| 57 AddGLNativeLibrary(library); |
| 58 SetGLImplementation(kGLImplementationOSMesaGL); |
| 59 |
| 60 InitializeGLBindingsGL(); |
| 61 InitializeGLBindingsOSMESA(); |
| 62 return true; |
| 63 } |
| 64 |
| 65 } // namespace gfx |
OLD | NEW |