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

Code before:
    #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,
        wgpu::BackendType::OpenGL,
        wgpu::BackendType::OpenGLES };
    constexpr std::array forceFallbackAdapters = { false, true };
    constexpr size_t totalCombinations =
            powerPreferences.size() * backendTypes.size() * forceFallbackAdapters.size();
    std::vector<wgpu::RequestAdapterOptions> requests;

Review comment (bug):
for safety/consistent should we not initialize as many of these as possible? e.g. `Display* display{ nullptr };`

Code after:
    #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,
        wgpu::BackendType::OpenGL,
        wgpu::BackendType::OpenGLES };
    constexpr std::array forceFallbackAdapters = { false, true };
    constexpr size_t totalCombinations =
            powerPreferences.size() * backendTypes.size() * forceFallbackAdapters.size();
    std::vector<wgpu::RequestAdapterOptions> requests;