Repository: google/filament
File: filament/backend/src/webgpu/platform/WebGPUPlatformLinux.cpp (C++)

Code before:
#include <array>
#include <cstddef>
#include <cstdint>
#include <vector>

#if defined(__linux__) || defined(__FreeBSD__)
    #define LINUX_OR_FREEBSD 1
#endif

// Platform specific includes and defines
#if defined(__linux__) && defined(FILAMENT_SUPPORTS_WAYLAND)
    #include <dlfcn.h>
    namespace {
    typedef struct _wl {
        struct wl_display* display;
        struct wl_surface* surface;
        uint32_t width;
        uint32_t height;
    } wl;
    }// namespace
#elif defined(LINUX_OR_FREEBSD) && defined(FILAMENT_SUPPORTS_X11) && defined(FILAMENT_SUPPORTS_XLIB)
    // TODO: we should allow for headless on Linux explicitly. Right now headless path doesn't work
    #include <dlfcn.h>
    #include <X11/Xlib.h>

    static constexpr const char* LIBRARY_X11 = "libX11.so.6";

    namespace {
        typedef Display* (*X11_OPEN_DISPLAY)(const char*);
        struct XEnv {
            X11_OPEN_DISPLAY openDisplay;
            Display* display;
            void* library = nullptr;
        } g_x11;
    } // namespace
#else
    #error Not a supported Linux or FeeBSD + WebGPU platform
#endif

/**
 * Linux OS specific implementation aspects of the WebGPU Backend
 */

namespace filament::backend {

std::vector<wgpu::RequestAdapterOptions> WebGPUPlatform::getAdapterOptions() {
    constexpr std::array powerPreferences = {
        wgpu::PowerPreference::HighPerformance,
        wgpu::PowerPreference::LowPower };
    constexpr std::array backendTypes = {
        wgpu::BackendType::Vulkan,

Review comment (suggestion):
nit: uniform initialization and prefer std::string_view, e.g. `constexpr std::string_view LIBRARY_X11{ "libX11.so.6" };`

Code after:
#include <array>
#include <cstddef>
#include <cstdint>
#include <vector>

#if defined(__linux__) || defined(__FreeBSD__)
    #define LINUX_OR_FREEBSD 1
#endif

// Platform specific includes and defines
#if defined(__linux__) && defined(FILAMENT_SUPPORTS_WAYLAND)
    #include <dlfcn.h>
    namespace {
    typedef struct _wl {
        struct wl_display* display;
        struct wl_surface* surface;
        uint32_t width;
        uint32_t height;
    } wl;
    }// namespace
#elif defined(LINUX_OR_FREEBSD) && defined(FILAMENT_SUPPORTS_X11) && defined(FILAMENT_SUPPORTS_XLIB)
    // TODO: we should allow for headless on Linux explicitly. Right now headless path doesn't work
    #include <dlfcn.h>
    #include <X11/Xlib.h>

    static constexpr const char* LIBRARY_X11 { "libX11.so.6" };

    namespace {
        typedef Display* (*X11_OPEN_DISPLAY)(const char*);
        struct XEnv final {
            X11_OPEN_DISPLAY openDisplay;
            Display* display { nullptr };
            void* library { nullptr };
        } g_x11;
    } // namespace
#else
    #error Not a supported Linux or FeeBSD + WebGPU platform
#endif

/**
 * Linux OS specific implementation aspects of the WebGPU Backend
 */

namespace filament::backend {

std::vector<wgpu::RequestAdapterOptions> WebGPUPlatform::getAdapterOptions() {
    constexpr std::array powerPreferences = {
        wgpu::PowerPreference::HighPerformance,
        wgpu::PowerPreference::LowPower };
    constexpr std::array backendTypes = {
        wgpu::BackendType::Vulkan,