| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ui/ozone/common/egl_util.h" | 5 #include "ui/ozone/common/egl_util.h" |
| 6 | 6 |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "ui/gl/egl_util.h" | 8 #include "ui/gl/egl_util.h" |
| 9 #include "ui/gl/gl_bindings.h" | 9 #include "ui/gl/gl_bindings.h" |
| 10 #include "ui/gl/gl_implementation.h" |
| 10 | 11 |
| 11 namespace ui { | 12 namespace ui { |
| 12 namespace { | 13 namespace { |
| 13 | 14 |
| 14 const char kDefaultEglSoname[] = "libEGL.so.1"; | 15 const char kDefaultEglSoname[] = "libEGL.so.1"; |
| 15 const char kDefaultGlesSoname[] = "libGLESv2.so.2"; | 16 const char kDefaultGlesSoname[] = "libGLESv2.so.2"; |
| 16 | 17 |
| 17 } // namespace | 18 } // namespace |
| 18 | 19 |
| 19 bool LoadDefaultEGLGLES2Bindings( | 20 bool LoadDefaultEGLGLES2Bindings() { |
| 20 SurfaceFactoryOzone::AddGLLibraryCallback add_gl_library, | 21 return LoadEGLGLES2Bindings(kDefaultEglSoname, kDefaultGlesSoname); |
| 21 SurfaceFactoryOzone::SetGLGetProcAddressProcCallback | |
| 22 set_gl_get_proc_address) { | |
| 23 return LoadEGLGLES2Bindings(add_gl_library, set_gl_get_proc_address, | |
| 24 kDefaultEglSoname, kDefaultGlesSoname); | |
| 25 } | 22 } |
| 26 | 23 |
| 27 bool LoadEGLGLES2Bindings( | 24 bool LoadEGLGLES2Bindings( |
| 28 SurfaceFactoryOzone::AddGLLibraryCallback add_gl_library, | |
| 29 SurfaceFactoryOzone::SetGLGetProcAddressProcCallback | |
| 30 set_gl_get_proc_address, | |
| 31 const char* egl_library_name, | 25 const char* egl_library_name, |
| 32 const char* gles_library_name) { | 26 const char* gles_library_name) { |
| 33 base::NativeLibraryLoadError error; | 27 base::NativeLibraryLoadError error; |
| 34 base::NativeLibrary gles_library = | 28 base::NativeLibrary gles_library = |
| 35 base::LoadNativeLibrary(base::FilePath(gles_library_name), &error); | 29 base::LoadNativeLibrary(base::FilePath(gles_library_name), &error); |
| 36 if (!gles_library) { | 30 if (!gles_library) { |
| 37 LOG(WARNING) << "Failed to load GLES library: " << error.ToString(); | 31 LOG(WARNING) << "Failed to load GLES library: " << error.ToString(); |
| 38 return false; | 32 return false; |
| 39 } | 33 } |
| 40 | 34 |
| 41 base::NativeLibrary egl_library = | 35 base::NativeLibrary egl_library = |
| 42 base::LoadNativeLibrary(base::FilePath(egl_library_name), &error); | 36 base::LoadNativeLibrary(base::FilePath(egl_library_name), &error); |
| 43 if (!egl_library) { | 37 if (!egl_library) { |
| 44 LOG(WARNING) << "Failed to load EGL library: " << error.ToString(); | 38 LOG(WARNING) << "Failed to load EGL library: " << error.ToString(); |
| 45 base::UnloadNativeLibrary(gles_library); | 39 base::UnloadNativeLibrary(gles_library); |
| 46 return false; | 40 return false; |
| 47 } | 41 } |
| 48 | 42 |
| 49 SurfaceFactoryOzone::GLGetProcAddressProc get_proc_address = | 43 gl::GLGetProcAddressProc get_proc_address = |
| 50 reinterpret_cast<SurfaceFactoryOzone::GLGetProcAddressProc>( | 44 reinterpret_cast<gl::GLGetProcAddressProc>( |
| 51 base::GetFunctionPointerFromNativeLibrary(egl_library, | 45 base::GetFunctionPointerFromNativeLibrary(egl_library, |
| 52 "eglGetProcAddress")); | 46 "eglGetProcAddress")); |
| 53 if (!get_proc_address) { | 47 if (!get_proc_address) { |
| 54 LOG(ERROR) << "eglGetProcAddress not found."; | 48 LOG(ERROR) << "eglGetProcAddress not found."; |
| 55 base::UnloadNativeLibrary(egl_library); | 49 base::UnloadNativeLibrary(egl_library); |
| 56 base::UnloadNativeLibrary(gles_library); | 50 base::UnloadNativeLibrary(gles_library); |
| 57 return false; | 51 return false; |
| 58 } | 52 } |
| 59 | 53 |
| 60 set_gl_get_proc_address.Run(get_proc_address); | 54 gl::SetGLGetProcAddressProc(get_proc_address); |
| 61 add_gl_library.Run(egl_library); | 55 gl::AddGLNativeLibrary(egl_library); |
| 62 add_gl_library.Run(gles_library); | 56 gl::AddGLNativeLibrary(gles_library); |
| 63 | 57 |
| 64 return true; | 58 return true; |
| 65 } | 59 } |
| 66 | 60 |
| 67 EGLConfig ChooseEGLConfig(EGLDisplay display, const int32_t* attributes) { | 61 EGLConfig ChooseEGLConfig(EGLDisplay display, const int32_t* attributes) { |
| 68 int32_t num_configs; | 62 int32_t num_configs; |
| 69 if (!eglChooseConfig(display, attributes, nullptr, 0, &num_configs)) { | 63 if (!eglChooseConfig(display, attributes, nullptr, 0, &num_configs)) { |
| 70 LOG(ERROR) << "eglChooseConfig failed with error " | 64 LOG(ERROR) << "eglChooseConfig failed with error " |
| 71 << GetLastEGLErrorString(); | 65 << GetLastEGLErrorString(); |
| 72 return nullptr; | 66 return nullptr; |
| 73 } | 67 } |
| 74 | 68 |
| 75 if (num_configs == 0) { | 69 if (num_configs == 0) { |
| 76 LOG(ERROR) << "No suitable EGL configs found."; | 70 LOG(ERROR) << "No suitable EGL configs found."; |
| 77 return nullptr; | 71 return nullptr; |
| 78 } | 72 } |
| 79 | 73 |
| 80 EGLConfig config; | 74 EGLConfig config; |
| 81 if (!eglChooseConfig(display, attributes, &config, 1, &num_configs)) { | 75 if (!eglChooseConfig(display, attributes, &config, 1, &num_configs)) { |
| 82 LOG(ERROR) << "eglChooseConfig failed with error " | 76 LOG(ERROR) << "eglChooseConfig failed with error " |
| 83 << GetLastEGLErrorString(); | 77 << GetLastEGLErrorString(); |
| 84 return nullptr; | 78 return nullptr; |
| 85 } | 79 } |
| 86 return config; | 80 return config; |
| 87 } | 81 } |
| 88 | 82 |
| 89 } // namespace ui | 83 } // namespace ui |
| OLD | NEW |