Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(145)

Side by Side Diff: ui/ozone/common/egl_util.cc

Issue 2926423002: ozone: Allow using swiftshader with --use-gl=swiftshader. (Closed)
Patch Set: . Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/ozone/common/egl_util.h ('k') | ui/ozone/common/gl_ozone_egl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/path_service.h"
8 #include "ui/gl/egl_util.h" 9 #include "ui/gl/egl_util.h"
9 #include "ui/gl/gl_bindings.h" 10 #include "ui/gl/gl_bindings.h"
11 #include "ui/gl/gl_features.h"
10 #include "ui/gl/gl_implementation.h" 12 #include "ui/gl/gl_implementation.h"
11 13
12 namespace ui { 14 namespace ui {
13 namespace { 15 namespace {
14 16
15 const char kDefaultEglSoname[] = "libEGL.so.1"; 17 const char kDefaultEglSoname[] = "libEGL.so.1";
16 const char kDefaultGlesSoname[] = "libGLESv2.so.2"; 18 const char kDefaultGlesSoname[] = "libGLESv2.so.2";
17 19
18 } // namespace 20 #if BUILDFLAG(ENABLE_SWIFTSHADER)
21 const char kGLESv2SwiftShaderLibraryName[] = "libGLESv2.so";
22 const char kEGLSwiftShaderLibraryName[] = "libEGL.so";
23 #endif
19 24
20 bool LoadDefaultEGLGLES2Bindings() { 25 bool LoadEGLGLES2Bindings(const base::FilePath& egl_library_path,
21 return LoadEGLGLES2Bindings(kDefaultEglSoname, kDefaultGlesSoname); 26 const base::FilePath& gles_library_path) {
22 }
23
24 bool LoadEGLGLES2Bindings(
25 const char* egl_library_name,
26 const char* gles_library_name) {
27 base::NativeLibraryLoadError error; 27 base::NativeLibraryLoadError error;
28 base::NativeLibrary gles_library = 28 base::NativeLibrary gles_library =
29 base::LoadNativeLibrary(base::FilePath(gles_library_name), &error); 29 base::LoadNativeLibrary(gles_library_path, &error);
30 if (!gles_library) { 30 if (!gles_library) {
31 LOG(WARNING) << "Failed to load GLES library: " << error.ToString(); 31 LOG(ERROR) << "Failed to load GLES library: " << error.ToString();
32 return false; 32 return false;
33 } 33 }
34 34
35 base::NativeLibrary egl_library = 35 base::NativeLibrary egl_library =
36 base::LoadNativeLibrary(base::FilePath(egl_library_name), &error); 36 base::LoadNativeLibrary(base::FilePath(egl_library_path), &error);
37 if (!egl_library) { 37 if (!egl_library) {
38 LOG(WARNING) << "Failed to load EGL library: " << error.ToString(); 38 LOG(ERROR) << "Failed to load EGL library: " << error.ToString();
39 base::UnloadNativeLibrary(gles_library); 39 base::UnloadNativeLibrary(gles_library);
40 return false; 40 return false;
41 } 41 }
42 42
43 gl::GLGetProcAddressProc get_proc_address = 43 gl::GLGetProcAddressProc get_proc_address =
44 reinterpret_cast<gl::GLGetProcAddressProc>( 44 reinterpret_cast<gl::GLGetProcAddressProc>(
45 base::GetFunctionPointerFromNativeLibrary(egl_library, 45 base::GetFunctionPointerFromNativeLibrary(egl_library,
46 "eglGetProcAddress")); 46 "eglGetProcAddress"));
47 if (!get_proc_address) { 47 if (!get_proc_address) {
48 LOG(ERROR) << "eglGetProcAddress not found."; 48 LOG(ERROR) << "eglGetProcAddress not found.";
49 base::UnloadNativeLibrary(egl_library); 49 base::UnloadNativeLibrary(egl_library);
50 base::UnloadNativeLibrary(gles_library); 50 base::UnloadNativeLibrary(gles_library);
51 return false; 51 return false;
52 } 52 }
53 53
54 gl::SetGLGetProcAddressProc(get_proc_address); 54 gl::SetGLGetProcAddressProc(get_proc_address);
55 gl::AddGLNativeLibrary(egl_library); 55 gl::AddGLNativeLibrary(egl_library);
56 gl::AddGLNativeLibrary(gles_library); 56 gl::AddGLNativeLibrary(gles_library);
57 57
58 return true; 58 return true;
59 } 59 }
60 60
61 } // namespace
62
63 bool LoadDefaultEGLGLES2Bindings(gl::GLImplementation implementation) {
64 base::FilePath glesv2_path;
65 base::FilePath egl_path;
66
67 if (implementation == gl::kGLImplementationSwiftShaderGL) {
68 #if BUILDFLAG(ENABLE_SWIFTSHADER)
69 base::FilePath module_path;
70 if (!PathService::Get(base::DIR_MODULE, &module_path))
71 return false;
72 module_path = module_path.Append("swiftshader/");
73
74 glesv2_path = module_path.Append(kGLESv2SwiftShaderLibraryName);
75 egl_path = module_path.Append(kEGLSwiftShaderLibraryName);
76 #else
77 return false;
78 #endif
79 } else {
80 glesv2_path = base::FilePath(kDefaultGlesSoname);
81 egl_path = base::FilePath(kDefaultEglSoname);
82 }
83
84 return LoadEGLGLES2Bindings(egl_path, glesv2_path);
85 }
86
61 EGLConfig ChooseEGLConfig(EGLDisplay display, const int32_t* attributes) { 87 EGLConfig ChooseEGLConfig(EGLDisplay display, const int32_t* attributes) {
62 int32_t num_configs; 88 int32_t num_configs;
63 if (!eglChooseConfig(display, attributes, nullptr, 0, &num_configs)) { 89 if (!eglChooseConfig(display, attributes, nullptr, 0, &num_configs)) {
64 LOG(ERROR) << "eglChooseConfig failed with error " 90 LOG(ERROR) << "eglChooseConfig failed with error "
65 << GetLastEGLErrorString(); 91 << GetLastEGLErrorString();
66 return nullptr; 92 return nullptr;
67 } 93 }
68 94
69 if (num_configs == 0) { 95 if (num_configs == 0) {
70 LOG(ERROR) << "No suitable EGL configs found."; 96 LOG(ERROR) << "No suitable EGL configs found.";
71 return nullptr; 97 return nullptr;
72 } 98 }
73 99
74 EGLConfig config; 100 EGLConfig config;
75 if (!eglChooseConfig(display, attributes, &config, 1, &num_configs)) { 101 if (!eglChooseConfig(display, attributes, &config, 1, &num_configs)) {
76 LOG(ERROR) << "eglChooseConfig failed with error " 102 LOG(ERROR) << "eglChooseConfig failed with error "
77 << GetLastEGLErrorString(); 103 << GetLastEGLErrorString();
78 return nullptr; 104 return nullptr;
79 } 105 }
80 return config; 106 return config;
81 } 107 }
82 108
83 } // namespace ui 109 } // namespace ui
OLDNEW
« no previous file with comments | « ui/ozone/common/egl_util.h ('k') | ui/ozone/common/gl_ozone_egl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698