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
3 // found in the LICENSE file.
5 #include "ui/ozone/common/egl_util.h"
7 #include "base/files/file_path.h"
12 const char kDefaultEglSoname
[] = "libEGL.so.1";
13 const char kDefaultGlesSoname
[] = "libGLESv2.so.2";
17 bool LoadDefaultEGLGLES2Bindings(
18 SurfaceFactoryOzone::AddGLLibraryCallback add_gl_library
,
19 SurfaceFactoryOzone::SetGLGetProcAddressProcCallback
20 set_gl_get_proc_address
) {
21 return LoadEGLGLES2Bindings(add_gl_library
, set_gl_get_proc_address
,
22 kDefaultEglSoname
, kDefaultGlesSoname
);
25 bool LoadEGLGLES2Bindings(
26 SurfaceFactoryOzone::AddGLLibraryCallback add_gl_library
,
27 SurfaceFactoryOzone::SetGLGetProcAddressProcCallback
28 set_gl_get_proc_address
,
29 const char* egl_library_name
,
30 const char* gles_library_name
) {
31 base::NativeLibraryLoadError error
;
32 base::NativeLibrary gles_library
=
33 base::LoadNativeLibrary(base::FilePath(gles_library_name
), &error
);
35 LOG(WARNING
) << "Failed to load GLES library: " << error
.ToString();
39 base::NativeLibrary egl_library
=
40 base::LoadNativeLibrary(base::FilePath(egl_library_name
), &error
);
42 LOG(WARNING
) << "Failed to load EGL library: " << error
.ToString();
43 base::UnloadNativeLibrary(gles_library
);
47 SurfaceFactoryOzone::GLGetProcAddressProc get_proc_address
=
48 reinterpret_cast<SurfaceFactoryOzone::GLGetProcAddressProc
>(
49 base::GetFunctionPointerFromNativeLibrary(egl_library
,
50 "eglGetProcAddress"));
51 if (!get_proc_address
) {
52 LOG(ERROR
) << "eglGetProcAddress not found.";
53 base::UnloadNativeLibrary(egl_library
);
54 base::UnloadNativeLibrary(gles_library
);
58 set_gl_get_proc_address
.Run(get_proc_address
);
59 add_gl_library
.Run(egl_library
);
60 add_gl_library
.Run(gles_library
);