Commit 1e117683 authored by sadrul's avatar sadrul Committed by Commit Bot

ozone: Allow using swiftshader with --use-gl=swiftshader.

This hooks up the ozone code so it can deal with --use-gl=swiftshader
flag correctly.

BUG=704285
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.android:android_optional_gpu_tests_rel;master.tryserver.chromium.linux:linux_optional_gpu_tests_rel;master.tryserver.chromium.mac:mac_optional_gpu_tests_rel;master.tryserver.chromium.win:win_optional_gpu_tests_rel

Review-Url: https://codereview.chromium.org/2926423002
Cr-Commit-Position: refs/heads/master@{#478817}
parent d73ae5a9
......@@ -31,6 +31,7 @@ source_set("common") {
deps = [
"//ui/gl",
"//ui/gl:gl_features",
]
visibility = [ "//ui/ozone/platform/*" ]
......
......@@ -5,8 +5,10 @@
#include "ui/ozone/common/egl_util.h"
#include "base/files/file_path.h"
#include "base/path_service.h"
#include "ui/gl/egl_util.h"
#include "ui/gl/gl_bindings.h"
#include "ui/gl/gl_features.h"
#include "ui/gl/gl_implementation.h"
namespace ui {
......@@ -15,27 +17,25 @@ namespace {
const char kDefaultEglSoname[] = "libEGL.so.1";
const char kDefaultGlesSoname[] = "libGLESv2.so.2";
} // namespace
bool LoadDefaultEGLGLES2Bindings() {
return LoadEGLGLES2Bindings(kDefaultEglSoname, kDefaultGlesSoname);
}
#if BUILDFLAG(ENABLE_SWIFTSHADER)
const char kGLESv2SwiftShaderLibraryName[] = "libGLESv2.so";
const char kEGLSwiftShaderLibraryName[] = "libEGL.so";
#endif
bool LoadEGLGLES2Bindings(
const char* egl_library_name,
const char* gles_library_name) {
bool LoadEGLGLES2Bindings(const base::FilePath& egl_library_path,
const base::FilePath& gles_library_path) {
base::NativeLibraryLoadError error;
base::NativeLibrary gles_library =
base::LoadNativeLibrary(base::FilePath(gles_library_name), &error);
base::LoadNativeLibrary(gles_library_path, &error);
if (!gles_library) {
LOG(WARNING) << "Failed to load GLES library: " << error.ToString();
LOG(ERROR) << "Failed to load GLES library: " << error.ToString();
return false;
}
base::NativeLibrary egl_library =
base::LoadNativeLibrary(base::FilePath(egl_library_name), &error);
base::LoadNativeLibrary(base::FilePath(egl_library_path), &error);
if (!egl_library) {
LOG(WARNING) << "Failed to load EGL library: " << error.ToString();
LOG(ERROR) << "Failed to load EGL library: " << error.ToString();
base::UnloadNativeLibrary(gles_library);
return false;
}
......@@ -58,6 +58,32 @@ bool LoadEGLGLES2Bindings(
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 (!PathService::Get(base::DIR_MODULE, &module_path))
return false;
module_path = module_path.Append("swiftshader/");
glesv2_path = module_path.Append(kGLESv2SwiftShaderLibraryName);
egl_path = module_path.Append(kEGLSwiftShaderLibraryName);
#else
return false;
#endif
} 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)) {
......
......@@ -7,13 +7,11 @@
#include <stdint.h>
namespace ui {
#include "ui/gl/gl_implementation.h"
bool LoadDefaultEGLGLES2Bindings();
namespace ui {
bool LoadEGLGLES2Bindings(
const char* egl_library_name,
const char* gles_library_name);
bool LoadDefaultEGLGLES2Bindings(gl::GLImplementation impl);
void* /* EGLConfig */ ChooseEGLConfig(void* /* EGLConfig */ display,
const int32_t* attributes);
......
......@@ -25,7 +25,7 @@ bool GLOzoneEGL::InitializeGLOneOffPlatform() {
bool GLOzoneEGL::InitializeStaticGLBindings(
gl::GLImplementation implementation) {
if (!LoadGLES2Bindings())
if (!LoadGLES2Bindings(implementation))
return false;
gl::SetGLImplementation(gl::kGLImplementationEGLGLES2);
......
......@@ -42,7 +42,7 @@ class GLOzoneEGL : public GLOzone {
virtual intptr_t GetNativeDisplay() = 0;
// Sets up GL bindings for the native surface.
virtual bool LoadGLES2Bindings() = 0;
virtual bool LoadGLES2Bindings(gl::GLImplementation implementation) = 0;
private:
DISALLOW_COPY_AND_ASSIGN(GLOzoneEGL);
......
......@@ -203,7 +203,7 @@ void GLOzoneEglCast::ChildDestroyed() {
DestroyWindow();
}
bool GLOzoneEglCast::LoadGLES2Bindings() {
bool GLOzoneEglCast::LoadGLES2Bindings(gl::GLImplementation implementation) {
if (state_ != kInitialized) {
InitializeHardware();
if (state_ != kInitialized) {
......
......@@ -34,7 +34,7 @@ class GLOzoneEglCast : public GLOzoneEGL {
scoped_refptr<gl::GLSurface> CreateOffscreenGLSurface(
const gfx::Size& size) override;
intptr_t GetNativeDisplay() override;
bool LoadGLES2Bindings() override;
bool LoadGLES2Bindings(gl::GLImplementation implementation) override;
intptr_t GetNativeWindow();
bool ResizeDisplay(gfx::Size viewport_size);
......
......@@ -64,7 +64,9 @@ class GLOzoneEGLGbm : public GLOzoneEGL {
protected:
intptr_t GetNativeDisplay() override { return EGL_DEFAULT_DISPLAY; }
bool LoadGLES2Bindings() override { return LoadDefaultEGLGLES2Bindings(); }
bool LoadGLES2Bindings(gl::GLImplementation impl) override {
return LoadDefaultEGLGLES2Bindings(impl);
}
private:
GbmSurfaceFactory* surface_factory_;
......@@ -108,7 +110,8 @@ std::vector<gl::GLImplementation>
GbmSurfaceFactory::GetAllowedGLImplementations() {
DCHECK(thread_checker_.CalledOnValidThread());
return std::vector<gl::GLImplementation>{gl::kGLImplementationEGLGLES2,
gl::kGLImplementationOSMesaGL};
gl::kGLImplementationOSMesaGL,
gl::kGLImplementationSwiftShaderGL};
}
GLOzone* GbmSurfaceFactory::GetGLOzone(gl::GLImplementation implementation) {
......
......@@ -141,7 +141,7 @@ class GLOzoneEGLWayland : public GLOzoneEGL {
protected:
intptr_t GetNativeDisplay() override;
bool LoadGLES2Bindings() override;
bool LoadGLES2Bindings(gl::GLImplementation impl) override;
private:
WaylandConnection* connection_;
......@@ -176,9 +176,11 @@ intptr_t GLOzoneEGLWayland::GetNativeDisplay() {
return reinterpret_cast<intptr_t>(connection_->display());
}
bool GLOzoneEGLWayland::LoadGLES2Bindings() {
bool GLOzoneEGLWayland::LoadGLES2Bindings(gl::GLImplementation impl) {
// TODO: It may not be necessary to set this environment variable when using
// swiftshader.
setenv("EGL_PLATFORM", "wayland", 0);
return LoadDefaultEGLGLES2Bindings();
return LoadDefaultEGLGLES2Bindings(impl);
}
} // namespace
......@@ -204,8 +206,10 @@ WaylandSurfaceFactory::CreateCanvasForWidget(gfx::AcceleratedWidget widget) {
std::vector<gl::GLImplementation>
WaylandSurfaceFactory::GetAllowedGLImplementations() {
std::vector<gl::GLImplementation> impls;
if (egl_implementation_)
if (egl_implementation_) {
impls.push_back(gl::kGLImplementationEGLGLES2);
impls.push_back(gl::kGLImplementationSwiftShaderGL);
}
impls.push_back(gl::kGLImplementationOSMesaGL);
return impls;
}
......
......@@ -143,7 +143,9 @@ class GLOzoneEGLX11 : public GLOzoneEGL {
return reinterpret_cast<intptr_t>(gfx::GetXDisplay());
}
bool LoadGLES2Bindings() override { return LoadDefaultEGLGLES2Bindings(); }
bool LoadGLES2Bindings(gl::GLImplementation implementation) override {
return LoadDefaultEGLGLES2Bindings(implementation);
}
private:
DISALLOW_COPY_AND_ASSIGN(GLOzoneEGLX11);
......@@ -161,9 +163,9 @@ X11SurfaceFactory::~X11SurfaceFactory() {}
std::vector<gl::GLImplementation>
X11SurfaceFactory::GetAllowedGLImplementations() {
// DesktopGL (GLX) should be the first option when crbug.com/646982 is fixed.
return std::vector<gl::GLImplementation>{gl::kGLImplementationEGLGLES2,
gl::kGLImplementationDesktopGL,
gl::kGLImplementationOSMesaGL};
return std::vector<gl::GLImplementation>{
gl::kGLImplementationEGLGLES2, gl::kGLImplementationDesktopGL,
gl::kGLImplementationOSMesaGL, gl::kGLImplementationSwiftShaderGL};
}
GLOzone* X11SurfaceFactory::GetGLOzone(gl::GLImplementation implementation) {
......@@ -171,6 +173,7 @@ GLOzone* X11SurfaceFactory::GetGLOzone(gl::GLImplementation implementation) {
case gl::kGLImplementationDesktopGL:
return glx_implementation_.get();
case gl::kGLImplementationEGLGLES2:
case gl::kGLImplementationSwiftShaderGL:
return egl_implementation_.get();
case gl::kGLImplementationOSMesaGL:
return osmesa_implementation_.get();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment