1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/ozone/common/egl_util.h"
#include "base/files/file_path.h"
#include "base/path_service.h"
#include "build/build_config.h"
#include "ui/gl/buildflags.h"
#include "ui/gl/egl_util.h"
#include "ui/gl/gl_bindings.h"
#include "ui/gl/gl_implementation.h"
namespace ui {
namespace {
#if defined(OS_WIN)
const base::FilePath::CharType kDefaultEglSoname[] =
FILE_PATH_LITERAL("libEGL.dll");
const base::FilePath::CharType kDefaultGlesSoname[] =
FILE_PATH_LITERAL("libGLESv2.dll");
const base::FilePath::CharType kAngleEglSoname[] =
FILE_PATH_LITERAL("libEGL.dll");
const base::FilePath::CharType kAngleGlesSoname[] =
FILE_PATH_LITERAL("libGLESv2.dll");
#else
#if defined(OS_FUCHSIA)
const base::FilePath::CharType kDefaultEglSoname[] =
FILE_PATH_LITERAL("libEGL.so");
const base::FilePath::CharType kDefaultGlesSoname[] =
FILE_PATH_LITERAL("libGLESv2.so");
#else // !defined(OS_FUCHSIA)
const base::FilePath::CharType kDefaultEglSoname[] =
FILE_PATH_LITERAL("libEGL.so.1");
const base::FilePath::CharType kDefaultGlesSoname[] =
FILE_PATH_LITERAL("libGLESv2.so.2");
#endif
const base::FilePath::CharType kAngleEglSoname[] =
FILE_PATH_LITERAL("libEGL.so");
const base::FilePath::CharType kAngleGlesSoname[] =
FILE_PATH_LITERAL("libGLESv2.so");
#endif // !defined(OS_WIN)
#if BUILDFLAG(ENABLE_SWIFTSHADER)
#if defined(OS_WIN)
const base::FilePath::CharType kGLESv2SwiftShaderLibraryName[] =
FILE_PATH_LITERAL("libGLESv2.dll");
const base::FilePath::CharType kEGLSwiftShaderLibraryName[] =
FILE_PATH_LITERAL("libEGL.dll");
#elif defined(OS_FUCHSIA)
const base::FilePath::CharType kGLESv2SwiftShaderLibraryName[] =
FILE_PATH_LITERAL("libswiftshader_libGLESv2.so");
const base::FilePath::CharType kEGLSwiftShaderLibraryName[] =
FILE_PATH_LITERAL("libswiftshader_libEGL.so");
#else // !defined(OS_WIN) && !defined(OS_FUCHSIA)
const base::FilePath::CharType kGLESv2SwiftShaderLibraryName[] =
FILE_PATH_LITERAL("libGLESv2.so");
const base::FilePath::CharType kEGLSwiftShaderLibraryName[] =
FILE_PATH_LITERAL("libEGL.so");
#endif // !defined(OS_WIN) && !defined(OS_FUCHSIA)
#endif // BUILDFLAG(ENABLE_SWIFTSHADER)
bool LoadEGLGLES2Bindings(const base::FilePath& egl_library_path,
const base::FilePath& gles_library_path) {
base::NativeLibraryLoadError error;
base::NativeLibrary gles_library =
base::LoadNativeLibrary(gles_library_path, &error);
if (!gles_library) {
LOG(ERROR) << "Failed to load GLES library: " << gles_library_path << ": "
<< error.ToString();
return false;
}
base::NativeLibrary egl_library =
base::LoadNativeLibrary(base::FilePath(egl_library_path), &error);
if (!egl_library) {
LOG(ERROR) << "Failed to load EGL library: " << egl_library_path << ": "
<< error.ToString();
base::UnloadNativeLibrary(gles_library);
return false;
}
gl::GLGetProcAddressProc get_proc_address =
reinterpret_cast<gl::GLGetProcAddressProc>(
base::GetFunctionPointerFromNativeLibrary(egl_library,
"eglGetProcAddress"));
if (!get_proc_address) {
LOG(ERROR) << "eglGetProcAddress not found.";
base::UnloadNativeLibrary(egl_library);
base::UnloadNativeLibrary(gles_library);
return false;
}
gl::SetGLGetProcAddressProc(get_proc_address);
gl::AddGLNativeLibrary(egl_library);
gl::AddGLNativeLibrary(gles_library);
return true;
}
} // namespace
bool LoadDefaultEGLGLES2Bindings(gl::GLImplementation implementation) {
base::FilePath glesv2_path;
base::FilePath egl_path;
if (implementation == gl::kGLImplementationSwiftShaderGL) {
#if BUILDFLAG(ENABLE_SWIFTSHADER)
base::FilePath module_path;
#if !defined(OS_FUCHSIA)
if (!base::PathService::Get(base::DIR_MODULE, &module_path))
return false;
module_path = module_path.Append(FILE_PATH_LITERAL("swiftshader/"));
#endif
glesv2_path = module_path.Append(kGLESv2SwiftShaderLibraryName);
egl_path = module_path.Append(kEGLSwiftShaderLibraryName);
#else
return false;
#endif
} else if (implementation == gl::kGLImplementationEGLANGLE) {
glesv2_path = base::FilePath(kAngleGlesSoname);
egl_path = base::FilePath(kAngleEglSoname);
} else {
glesv2_path = base::FilePath(kDefaultGlesSoname);
egl_path = base::FilePath(kDefaultEglSoname);
}
return LoadEGLGLES2Bindings(egl_path, glesv2_path);
}
EGLConfig ChooseEGLConfig(EGLDisplay display, const int32_t* attributes) {
int32_t num_configs;
if (!eglChooseConfig(display, attributes, nullptr, 0, &num_configs)) {
LOG(ERROR) << "eglChooseConfig failed with error "
<< GetLastEGLErrorString();
return nullptr;
}
if (num_configs == 0) {
LOG(ERROR) << "No suitable EGL configs found.";
return nullptr;
}
EGLConfig config;
if (!eglChooseConfig(display, attributes, &config, 1, &num_configs)) {
LOG(ERROR) << "eglChooseConfig failed with error "
<< GetLastEGLErrorString();
return nullptr;
}
return config;
}
} // namespace ui
|