#include "ui/gl/gl_display.h"
#include <string>
#include <type_traits>
#include <vector>
#include "base/command_line.h"
#include "base/containers/contains.h"
#include "base/debug/crash_logging.h"
#include "base/export_template.h"
#include "base/logging.h"
#include "base/metrics/histogram_macros.h"
#include "base/notreached.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/synchronization/atomic_flag.h"
#include "base/system/sys_info.h"
#include "build/build_config.h"
#include "ui/base/ozone_buildflags.h"
#include "ui/gl/angle_platform_impl.h"
#include "ui/gl/egl_util.h"
#include "ui/gl/gl_bindings.h"
#include "ui/gl/gl_context_egl.h"
#include "ui/gl/gl_display_egl_util.h"
#include "ui/gl/gl_features.h"
#include "ui/gl/gl_implementation.h"
#include "ui/gl/gl_surface.h"
#if BUILDFLAG(IS_ANDROID)
#include "base/android/build_info.h"
#endif
#ifndef EGL_ANGLE_platform_angle
#define EGL_ANGLE_platform_angle …
#define EGL_PLATFORM_ANGLE_ANGLE …
#define EGL_PLATFORM_ANGLE_TYPE_ANGLE …
#define EGL_PLATFORM_ANGLE_MAX_VERSION_MAJOR_ANGLE …
#define EGL_PLATFORM_ANGLE_MAX_VERSION_MINOR_ANGLE …
#define EGL_PLATFORM_ANGLE_TYPE_DEFAULT_ANGLE …
#define EGL_PLATFORM_ANGLE_DEBUG_LAYERS_ENABLED_ANGLE …
#define EGL_PLATFORM_ANGLE_DEVICE_TYPE_ANGLE …
#define EGL_PLATFORM_ANGLE_DEVICE_TYPE_EGL_ANGLE …
#define EGL_PLATFORM_ANGLE_DEVICE_TYPE_HARDWARE_ANGLE …
#define EGL_PLATFORM_ANGLE_DEVICE_TYPE_NULL_ANGLE …
#define EGL_PLATFORM_ANGLE_DEVICE_TYPE_SWIFTSHADER_ANGLE …
#define EGL_PLATFORM_ANGLE_NATIVE_PLATFORM_TYPE_ANGLE …
#endif
#ifndef EGL_ANGLE_platform_angle_d3d
#define EGL_ANGLE_platform_angle_d3d …
#define EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE …
#define EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE …
#define EGL_PLATFORM_ANGLE_DEVICE_TYPE_D3D_WARP_ANGLE …
#define EGL_PLATFORM_ANGLE_DEVICE_TYPE_D3D_REFERENCE_ANGLE …
#endif
#ifndef EGL_ANGLE_platform_angle_d3d_luid
#define EGL_ANGLE_platform_angle_d3d_luid …
#define EGL_PLATFORM_ANGLE_D3D_LUID_HIGH_ANGLE …
#define EGL_PLATFORM_ANGLE_D3D_LUID_LOW_ANGLE …
#endif
#ifndef EGL_ANGLE_platform_angle_d3d11on12
#define EGL_ANGLE_platform_angle_d3d11on12 …
#define EGL_PLATFORM_ANGLE_D3D11ON12_ANGLE …
#endif
#ifndef EGL_ANGLE_platform_angle_opengl
#define EGL_ANGLE_platform_angle_opengl …
#define EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE …
#define EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE …
#endif
#ifndef EGL_ANGLE_platform_angle_null
#define EGL_ANGLE_platform_angle_null …
#define EGL_PLATFORM_ANGLE_TYPE_NULL_ANGLE …
#endif
#ifndef EGL_ANGLE_platform_angle_vulkan
#define EGL_ANGLE_platform_angle_vulkan …
#define EGL_PLATFORM_ANGLE_TYPE_VULKAN_ANGLE …
#define EGL_PLATFORM_VULKAN_DISPLAY_MODE_HEADLESS_ANGLE …
#endif
#ifndef EGL_ANGLE_platform_angle_metal
#define EGL_ANGLE_platform_angle_metal …
#define EGL_PLATFORM_ANGLE_TYPE_METAL_ANGLE …
#endif
#ifndef EGL_ANGLE_x11_visual
#define EGL_ANGLE_x11_visual …
#define EGL_X11_VISUAL_ID_ANGLE …
#endif
#ifndef EGL_ANGLE_direct_composition
#define EGL_ANGLE_direct_composition …
#define EGL_DIRECT_COMPOSITION_ANGLE …
#endif
#ifndef EGL_ANGLE_display_robust_resource_initialization
#define EGL_ANGLE_display_robust_resource_initialization …
#define EGL_DISPLAY_ROBUST_RESOURCE_INITIALIZATION_ANGLE …
#endif
#ifndef EGL_ANGLE_display_power_preference
#define EGL_ANGLE_display_power_preference …
#define EGL_POWER_PREFERENCE_ANGLE …
#define EGL_LOW_POWER_ANGLE …
#define EGL_HIGH_POWER_ANGLE …
#endif
#ifndef EGL_ANGLE_platform_angle_device_id
#define EGL_ANGLE_platform_angle_device_id
#define EGL_PLATFORM_ANGLE_DEVICE_ID_HIGH_ANGLE …
#define EGL_PLATFORM_ANGLE_DEVICE_ID_LOW_ANGLE …
#define EGL_PLATFORM_ANGLE_DISPLAY_KEY_ANGLE …
#endif
#ifndef EGL_ANGLE_feature_control
#define EGL_ANGLE_feature_control …
#define EGL_FEATURE_NAME_ANGLE …
#define EGL_FEATURE_CATEGORY_ANGLE …
#define EGL_FEATURE_DESCRIPTION_ANGLE …
#define EGL_FEATURE_BUG_ANGLE …
#define EGL_FEATURE_STATUS_ANGLE …
#define EGL_FEATURE_COUNT_ANGLE …
#define EGL_FEATURE_OVERRIDES_ENABLED_ANGLE …
#define EGL_FEATURE_OVERRIDES_DISABLED_ANGLE …
#define EGL_FEATURE_ALL_DISABLED_ANGLE …
#endif
GetLastEGLErrorString;
namespace gl {
namespace {
base::AtomicFlag* GetANGLEDebugLayerFlag() { … }
std::vector<const char*> GetAttribArrayFromStringVector(
const std::vector<std::string>& strings) { … }
EGLDisplay GetPlatformANGLEDisplay(
EGLNativeDisplayType display,
EGLenum platform_type,
const std::vector<std::string>& enabled_features,
const std::vector<std::string>& disabled_features,
const std::vector<EGLAttrib>& extra_display_attribs) { … }
EGLDisplay GetDisplayFromType(
DisplayType display_type,
EGLDisplayPlatform native_display,
const std::vector<std::string>& enabled_angle_features,
const std::vector<std::string>& disabled_angle_features,
uint64_t system_device_id,
DisplayKey display_key) { … }
ANGLEImplementation GetANGLEImplementationFromDisplayType(
DisplayType display_type) { … }
const char* DisplayTypeString(DisplayType display_type) { … }
const char* GetDebugMessageTypeString(EGLint source) { … }
void EGLAPIENTRY LogEGLDebugMessage(EGLenum error,
const char* command,
EGLint message_type,
EGLLabelKHR thread_label,
EGLLabelKHR object_label,
const char* message) { … }
void SetEglDebugMessageControl() { … }
}
GLDisplay::GLDisplay(uint64_t system_device_id,
DisplayKey display_key,
DisplayPlatform type)
: … { … }
GLDisplay::~GLDisplay() = default;
template <typename GLDisplayPlatform>
GLDisplayPlatform* GLDisplay::GetAs() { … }
template EXPORT_TEMPLATE_DEFINE(…)
GLDisplayEGL* GLDisplay::GetAs<GLDisplayEGL>();
GLDisplayEGL::EGLGpuSwitchingObserver::EGLGpuSwitchingObserver(
EGLDisplay display)
: … { … }
void GLDisplayEGL::EGLGpuSwitchingObserver::OnGpuSwitched(
GpuPreference active_gpu_heuristic) { … }
#if !BUILDFLAG(IS_APPLE)
GLDisplayEGL::GLDisplayEGL(uint64_t system_device_id, DisplayKey display_key)
: … { … }
GLDisplayEGL::~GLDisplayEGL() = default;
#endif
EGLDisplay GLDisplayEGL::GetDisplay() const { … }
void GLDisplayEGL::Shutdown() { … }
bool GLDisplayEGL::IsInitialized() const { … }
void GLDisplayEGL::SetDisplay(EGLDisplay display) { … }
EGLDisplayPlatform GLDisplayEGL::GetNativeDisplay() const { … }
DisplayType GLDisplayEGL::GetDisplayType() const { … }
GLDisplayEGL* GLDisplayEGL::GetDisplayForCurrentContext() { … }
void GLDisplayEGL::EnableANGLEDebugLayer() { … }
bool GLDisplayEGL::IsEGLSurfacelessContextSupported() { … }
bool GLDisplayEGL::IsEGLContextPrioritySupported() { … }
bool GLDisplayEGL::IsAndroidNativeFenceSyncSupported() { … }
bool GLDisplayEGL::IsANGLEExternalContextAndSurfaceSupported() { … }
bool GLDisplayEGL::Initialize(bool supports_angle,
std::vector<DisplayType> init_displays,
EGLDisplayPlatform native_display) { … }
bool GLDisplayEGL::Initialize(GLDisplay* other_display) { … }
void GLDisplayEGL::InitializeForTesting() { … }
bool GLDisplayEGL::InitializeExtensionSettings() { … }
bool GLDisplayEGL::InitializeDisplay(bool supports_angle,
std::vector<DisplayType> init_displays,
EGLDisplayPlatform native_display,
gl::GLDisplayEGL* existing_display) { … }
void GLDisplayEGL::InitializeCommon(bool for_testing) { … }
}