base: Change DCHECK_IS_ON to a macro DCHECK_IS_ON().
[chromium-blink-merge.git] / ui / ozone / common / egl_util.cc
blob8000360c7b0c4a99be228bcdb2f46b5a788a398a
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"
9 namespace ui {
10 namespace {
12 const char kDefaultEglSoname[] = "libEGL.so.1";
13 const char kDefaultGlesSoname[] = "libGLESv2.so.2";
15 } // namespace
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);
34 if (!gles_library) {
35 LOG(WARNING) << "Failed to load GLES library: " << error.ToString();
36 return false;
39 base::NativeLibrary egl_library =
40 base::LoadNativeLibrary(base::FilePath(egl_library_name), &error);
41 if (!egl_library) {
42 LOG(WARNING) << "Failed to load EGL library: " << error.ToString();
43 base::UnloadNativeLibrary(gles_library);
44 return false;
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);
55 return false;
58 set_gl_get_proc_address.Run(get_proc_address);
59 add_gl_library.Run(egl_library);
60 add_gl_library.Run(gles_library);
62 return true;
65 } // namespace ui