Commit 9f838913 authored by Peng Huang's avatar Peng Huang Committed by Chromium LUCI CQ

Support using statically linked ANGLE on all platforms

Right now, chromium only supports linking ANGLE statically on Android,
to make it easier to work and on related changes on Linux, we should\
support it on all platforms.

Bug: 1161513
Change-Id: I9aaef20e88aa14be9881260d6d2b34c8417610a0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2608029Reviewed-by: default avatarJonathan Backer <backer@chromium.org>
Commit-Queue: Peng Huang <penghuang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#842059}
parent f9f209f5
......@@ -8,7 +8,6 @@ import("//build/config/chromeos/ui_mode.gni")
declare_args() {
# Should ANGLE be linked statically?
# False by default, enabling currently supported only on Android
use_static_angle = is_android
# Should EGL support be compiled?
......
......@@ -31,15 +31,16 @@ component("init") {
public_deps = [ "//ui/gl" ]
if (use_static_angle) {
sources += [ "gl_initializer_angle.cc" ]
deps += [ "//third_party/angle:libEGL_static" ]
}
if (is_android) {
sources += [
"gl_factory_android.cc",
"gl_initializer_android.cc",
]
if (use_static_angle) {
deps += [ "//third_party/angle:libEGL_static" ]
}
} else if (is_win && !use_ozone) {
sources += [
"gl_factory_win.cc",
......
......@@ -5,6 +5,7 @@
#ifndef UI_GL_INIT_GL_INITIALIZER_H_
#define UI_GL_INIT_GL_INITIALIZER_H_
#include "ui/gl/buildflags.h"
#include "ui/gl/gl_implementation.h"
namespace gl {
......@@ -22,6 +23,10 @@ bool InitializeGLOneOffPlatform();
// Initializes a particular GL implementation.
bool InitializeStaticGLBindings(GLImplementation implementation);
#if BUILDFLAG(USE_STATIC_ANGLE)
bool InitializeStaticANGLEEGL();
#endif // BUILDFLAG(USE_STATIC_ANGLE)
// Clears GL bindings for all implementations supported by platform.
void ShutdownGLPlatform();
......
......@@ -9,31 +9,17 @@
#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/native_library.h"
#include "ui/gl/buildflags.h"
#include "ui/gl/gl_bindings.h"
#include "ui/gl/gl_egl_api_implementation.h"
#include "ui/gl/gl_gl_api_implementation.h"
#include "ui/gl/gl_surface_egl.h"
#if BUILDFLAG(USE_STATIC_ANGLE)
#include <EGL/egl.h>
#endif // BUILDFLAG(USE_STATIC_ANGLE)
#include "ui/gl/init/gl_initializer.h"
namespace gl {
namespace init {
namespace {
#if BUILDFLAG(USE_STATIC_ANGLE)
bool InitializeStaticANGLEEGLInternal() {
#pragma push_macro("eglGetProcAddress")
#undef eglGetProcAddress
SetGLGetProcAddressProc(&eglGetProcAddress);
#pragma pop_macro("eglGetProcAddress")
return true;
}
#endif // BUILDFLAG(USE_STATIC_ANGLE)
bool InitializeStaticNativeEGLInternal() {
base::NativeLibrary gles_library = LoadLibraryAndPrintError("libGLESv2.so");
if (!gles_library)
......@@ -68,7 +54,7 @@ bool InitializeStaticEGLInternal(GLImplementation implementation) {
#if BUILDFLAG(USE_STATIC_ANGLE)
// Use ANGLE if it is requested and it is statically linked
if (implementation == kGLImplementationEGLANGLE) {
initialized = InitializeStaticANGLEEGLInternal();
initialized = InitializeStaticANGLEEGL();
}
#endif // BUILDFLAG(USE_STATIC_ANGLE)
......
// Copyright 2020 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/gl/init/gl_initializer.h"
#include <EGL/egl.h>
namespace gl {
namespace init {
bool InitializeStaticANGLEEGL() {
#pragma push_macro("eglGetProcAddress")
#undef eglGetProcAddress
SetGLGetProcAddressProc(&eglGetProcAddress);
#pragma pop_macro("eglGetProcAddress")
return true;
}
} // namespace init
} // namespace gl
......@@ -11,7 +11,6 @@
#include "build/build_config.h"
#include "ui/gfx/switches.h"
#include "ui/gfx/x/connection.h"
#include "ui/gl/buildflags.h"
#include "ui/gl/gl_bindings.h"
#include "ui/gl/gl_egl_api_implementation.h"
#include "ui/gl/gl_gl_api_implementation.h"
......@@ -20,6 +19,7 @@
#include "ui/gl/gl_surface_glx.h"
#include "ui/gl/gl_switches.h"
#include "ui/gl/init/gl_display_egl_util_x11.h"
#include "ui/gl/init/gl_initializer.h"
namespace gl {
namespace init {
......@@ -35,9 +35,6 @@ const char kGLLibraryName[] = "libGL.so.1";
const char kGLESv2LibraryName[] = "libGLESv2.so.2";
const char kEGLLibraryName[] = "libEGL.so.1";
const char kGLESv2ANGLELibraryName[] = "libGLESv2.so";
const char kEGLANGLELibraryName[] = "libEGL.so";
#if BUILDFLAG(ENABLE_SWIFTSHADER)
const char kGLESv2SwiftShaderLibraryName[] = "libGLESv2.so";
const char kEGLSwiftShaderLibraryName[] = "libEGL.so";
......@@ -79,10 +76,9 @@ bool InitializeStaticGLXInternal() {
return true;
}
bool InitializeStaticEGLInternal(GLImplementation implementation) {
bool InitializeStaticEGLInternalFromLibrary(GLImplementation implementation) {
base::FilePath glesv2_path(kGLESv2LibraryName);
base::FilePath egl_path(kEGLLibraryName);
if (implementation == kGLImplementationSwiftShaderGL) {
#if BUILDFLAG(ENABLE_SWIFTSHADER)
base::FilePath module_path;
......@@ -96,12 +92,19 @@ bool InitializeStaticEGLInternal(GLImplementation implementation) {
return false;
#endif
} else if (implementation == kGLImplementationEGLANGLE) {
#if !BUILDFLAG(USE_STATIC_ANGLE)
base::FilePath module_path;
if (!base::PathService::Get(base::DIR_MODULE, &module_path))
return false;
const char kGLESv2ANGLELibraryName[] = "libGLESv2.so";
const char kEGLANGLELibraryName[] = "libEGL.so";
glesv2_path = module_path.Append(kGLESv2ANGLELibraryName);
egl_path = module_path.Append(kEGLANGLELibraryName);
#else // BUILDFLAG(USE_STATIC_ANGLE)
NOTREACHED();
#endif
}
base::NativeLibrary gles_library = LoadLibraryAndPrintError(glesv2_path);
......@@ -127,6 +130,25 @@ bool InitializeStaticEGLInternal(GLImplementation implementation) {
SetGLGetProcAddressProc(get_proc_address);
AddGLNativeLibrary(egl_library);
AddGLNativeLibrary(gles_library);
return true;
}
bool InitializeStaticEGLInternal(GLImplementation implementation) {
#if BUILDFLAG(USE_STATIC_ANGLE)
if (implementation == kGLImplementationEGLANGLE) {
// Use ANGLE if it is requested and it is statically linked
if (!InitializeStaticANGLEEGL())
return false;
} else if (!InitializeStaticEGLInternalFromLibrary(implementation))
return false;
}
#else
if (!InitializeStaticEGLInternalFromLibrary(implementation)) {
return false;
}
#endif // !BUILDFLAG(USE_STATIC_ANGLE)
if (implementation == kGLImplementationEGLANGLE) {
SetGLImplementation(kGLImplementationEGLANGLE);
} else {
......
......@@ -16,13 +16,13 @@
#include "base/native_library.h"
#include "base/path_service.h"
#include "base/threading/thread_restrictions.h"
#include "ui/gl/buildflags.h"
#include "ui/gl/gl_bindings.h"
#include "ui/gl/gl_context.h"
#include "ui/gl/gl_gl_api_implementation.h"
#include "ui/gl/gl_implementation.h"
#include "ui/gl/gl_surface.h"
#include "ui/gl/gpu_switching_manager.h"
#include "ui/gl/init/gl_initializer.h"
#if defined(USE_EGL)
#include "ui/gl/gl_egl_api_implementation.h"
......@@ -97,7 +97,7 @@ const char kEGLANGLELibraryName[] = "libEGL.dylib";
const char kGLESv2SwiftShaderLibraryName[] = "libswiftshader_libGLESv2.dylib";
const char kEGLSwiftShaderLibraryName[] = "libswiftshader_libEGL.dylib";
bool InitializeStaticEGLInternal(GLImplementation implementation) {
bool InitializeStaticEGLInternalFromLibrary(GLImplementation implementation) {
// Some unit test targets depend on Angle/SwiftShader but aren't built
// as app bundles. In that case, the .dylib is next to the executable.
base::FilePath base_dir;
......@@ -123,6 +123,9 @@ bool InitializeStaticEGLInternal(GLImplementation implementation) {
} else {
glesv2_path = base_dir.Append(kGLESv2ANGLELibraryName);
egl_path = base_dir.Append(kEGLANGLELibraryName);
#if BUILDFLAG(USE_STATIC_ANGLE)
NOTREACHED();
#endif
}
base::NativeLibrary gles_library = LoadLibraryAndPrintError(glesv2_path);
......@@ -152,8 +155,26 @@ bool InitializeStaticEGLInternal(GLImplementation implementation) {
// currently
AddGLNativeLibrary(gles_library);
AddGLNativeLibrary(egl_library);
SetGLImplementation(implementation);
return true;
}
bool InitializeStaticEGLInternal(GLImplementation implementation) {
#if BUILDFLAG(USE_STATIC_ANGLE)
if (implementation == kGLImplementationEGLANGLE) {
// Use ANGLE if it is requested and it is statically linked
if (!InitializeStaticANGLEEGL())
return false;
} else if (!InitializeStaticEGLInternalFromLibrary(implementation)) {
return false;
}
#else
if (!InitializeStaticEGLInternalFromLibrary(implementation)) {
return false;
}
#endif // !BUILDFLAG(USE_STATIC_ANGLE)
SetGLImplementation(implementation);
InitializeStaticGLBindingsGL();
InitializeStaticGLBindingsEGL();
......
......@@ -17,7 +17,6 @@
#include "base/threading/thread_restrictions.h"
#include "base/trace_event/trace_event.h"
#include "base/win/windows_version.h"
#include "ui/gl/buildflags.h"
#include "ui/gl/gl_bindings.h"
#include "ui/gl/gl_egl_api_implementation.h"
#include "ui/gl/gl_gl_api_implementation.h"
......@@ -45,7 +44,7 @@ bool LoadD3DXLibrary(const base::FilePath& module_path,
return true;
}
bool InitializeStaticEGLInternal(GLImplementation implementation) {
bool InitializeStaticEGLInternalFromLibrary(GLImplementation implementation) {
base::FilePath module_path;
if (!base::PathService::Get(base::DIR_MODULE, &module_path))
return false;
......@@ -67,6 +66,9 @@ bool InitializeStaticEGLInternal(GLImplementation implementation) {
#endif
} else {
gles_path = module_path;
#if BUILDFLAG(USE_STATIC_ANGLE)
NOTREACHED();
#endif
}
// Load libglesv2.dll before libegl.dll because the latter is dependent on
......@@ -103,8 +105,26 @@ bool InitializeStaticEGLInternal(GLImplementation implementation) {
SetGLGetProcAddressProc(get_proc_address);
AddGLNativeLibrary(egl_library);
AddGLNativeLibrary(gles_library);
SetGLImplementation(implementation);
return true;
}
bool InitializeStaticEGLInternal(GLImplementation implementation) {
#if BUILDFLAG(USE_STATIC_ANGLE)
if (implementation == kGLImplementationEGLANGLE) {
// Use ANGLE if it is requested and it is statically linked
if (!InitializeStaticANGLEEGL())
return false;
} else if (!InitializeStaticEGLInternalFromLibrary(implementation)) {
return false;
}
#else
if (!InitializeStaticEGLInternalFromLibrary(implementation)) {
return false;
}
#endif // !BUILDFLAG(USE_STATIC_ANGLE)
SetGLImplementation(implementation);
InitializeStaticGLBindingsGL();
InitializeStaticGLBindingsEGL();
......
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