chromium/ui/gl/gl_display.cc

// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#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

// From ANGLE's egl/eglext.h.

#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 /* EGL_ANGLE_platform_angle */

#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 /* EGL_ANGLE_platform_angle_d3d */

#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 /* EGL_ANGLE_platform_angle_d3d_luid */

#ifndef EGL_ANGLE_platform_angle_d3d11on12
#define EGL_ANGLE_platform_angle_d3d11on12
#define EGL_PLATFORM_ANGLE_D3D11ON12_ANGLE
#endif /* EGL_ANGLE_platform_angle_d3d11on12 */

#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 /* EGL_ANGLE_platform_angle_opengl */

#ifndef EGL_ANGLE_platform_angle_null
#define EGL_ANGLE_platform_angle_null
#define EGL_PLATFORM_ANGLE_TYPE_NULL_ANGLE
#endif /* EGL_ANGLE_platform_angle_null */

#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 /* EGL_ANGLE_platform_angle_vulkan */

#ifndef EGL_ANGLE_platform_angle_metal
#define EGL_ANGLE_platform_angle_metal
#define EGL_PLATFORM_ANGLE_TYPE_METAL_ANGLE
#endif /* EGL_ANGLE_platform_angle_metal */

#ifndef EGL_ANGLE_x11_visual
#define EGL_ANGLE_x11_visual
#define EGL_X11_VISUAL_ID_ANGLE
#endif /* EGL_ANGLE_x11_visual */

#ifndef EGL_ANGLE_direct_composition
#define EGL_ANGLE_direct_composition
#define EGL_DIRECT_COMPOSITION_ANGLE
#endif /* EGL_ANGLE_direct_composition */

#ifndef EGL_ANGLE_display_robust_resource_initialization
#define EGL_ANGLE_display_robust_resource_initialization
#define EGL_DISPLAY_ROBUST_RESOURCE_INITIALIZATION_ANGLE
#endif /* EGL_ANGLE_display_robust_resource_initialization */

#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 /* EGL_ANGLE_power_preference */

#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 /* EGL_ANGLE_platform_angle_device_id */

// From ANGLE's egl/eglext.h.
#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 /* EGL_ANGLE_feature_control */

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() {}

}  // namespace

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) {}

// Because on Apple platforms there is a member variable of a type (ObjCStorage)
// that is defined in gl_display_egl.mm, the constructor/destructor also have to
// be there. If making changes to this copy, be sure to adjust the other.
#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 {}

// static
GLDisplayEGL* GLDisplayEGL::GetDisplayForCurrentContext() {}

// static
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() {}

// InitializeDisplay is necessary because the static binding code
// needs a full Display init before it can query the Display extensions.
bool GLDisplayEGL::InitializeDisplay(bool supports_angle,
                                     std::vector<DisplayType> init_displays,
                                     EGLDisplayPlatform native_display,
                                     gl::GLDisplayEGL* existing_display) {}

void GLDisplayEGL::InitializeCommon(bool for_testing) {}

}  // namespace gl