Repository: google/filament
File: filament/backend/src/opengl/platforms/PlatformEGL.cpp (C++)

Code before:
        LOG(WARNING) << "Ignoring pending GL error " << io::hex << error;
    }
}

// ---------------------------------------------------------------------------------------------

PlatformEGL::PlatformEGL() noexcept = default;

int PlatformEGL::getOSVersion() const noexcept {
    return 0;
}

bool PlatformEGL::isOpenGL() const noexcept {
    return false;
}

PlatformEGL::ExternalImageEGL::~ExternalImageEGL() = default;

Driver* PlatformEGL::createDriver(void* sharedContext, const DriverConfig& driverConfig) {
    static constexpr int kMaxNumEGLDevices = 32;

    EGLint major, minor;
    EGLBoolean initialized = false;

    EGLDeviceEXT eglDevices[kMaxNumEGLDevices];
    EGLint numDevices;
    PFNEGLQUERYDEVICESEXTPROC const eglQueryDevicesEXT =
        PFNEGLQUERYDEVICESEXTPROC(eglGetProcAddress("eglQueryDevicesEXT"));
    PFNEGLGETPLATFORMDISPLAYEXTPROC const getPlatformDisplay =
        PFNEGLGETPLATFORMDISPLAYEXTPROC(eglGetProcAddress("eglGetPlatformDisplay"));

    if (eglQueryDevicesEXT != nullptr) {
        eglQueryDevicesEXT(kMaxNumEGLDevices, eglDevices, &numDevices);
        for (int i = 0; i < numDevices && !initialized; ++i) {
            mEGLDisplay = getPlatformDisplay(EGL_PLATFORM_DEVICE_EXT, eglDevices[i], nullptr);
            initialized = eglInitialize(mEGLDisplay, &major, &minor);
        }
    }

    if (!initialized) {
        mEGLDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
        assert_invariant(mEGLDisplay != EGL_NO_DISPLAY);
        initialized = eglInitialize(mEGLDisplay, &major, &minor);
    }

    if (UTILS_UNLIKELY(!initialized)) {
        LOG(ERROR) << "eglInitialize failed";
        return nullptr;
    }

#if defined(FILAMENT_IMPORT_ENTRY_POINTS)

Review comment (bug):
this is only used within the `if (eglQueryDevicesEXT != nullptr) {` block below. You can move this within the block.

Code after:
        LOG(WARNING) << "Ignoring pending GL error " << io::hex << error;
    }
}

// ---------------------------------------------------------------------------------------------

PlatformEGL::PlatformEGL() noexcept = default;

int PlatformEGL::getOSVersion() const noexcept {
    return 0;
}

bool PlatformEGL::isOpenGL() const noexcept {
    return false;
}

PlatformEGL::ExternalImageEGL::~ExternalImageEGL() = default;

Driver* PlatformEGL::createDriver(void* sharedContext, const DriverConfig& driverConfig) {
    static constexpr int kMaxNumEGLDevices = 32;

    EGLint major, minor;
    EGLBoolean initialized = false;

    PFNEGLQUERYDEVICESEXTPROC const eglQueryDevicesEXT =
        PFNEGLQUERYDEVICESEXTPROC(eglGetProcAddress("eglQueryDevicesEXT"));
    PFNEGLGETPLATFORMDISPLAYEXTPROC const getPlatformDisplay =
        PFNEGLGETPLATFORMDISPLAYEXTPROC(eglGetProcAddress("eglGetPlatformDisplay"));

    if (eglQueryDevicesEXT != nullptr && getPlatformDisplay != nullptr) {
        EGLint numDevices = 0;
        EGLDeviceEXT eglDevices[kMaxNumEGLDevices];
        if (eglQueryDevicesEXT(kMaxNumEGLDevices, eglDevices, &numDevices)) {
            for (int i = 0; i < numDevices && !initialized; ++i) {
                mEGLDisplay = getPlatformDisplay(EGL_PLATFORM_DEVICE_EXT, eglDevices[i], nullptr);
                initialized = eglInitialize(mEGLDisplay, &major, &minor);
            }
        }
    }

    if (!initialized) {
        mEGLDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
        assert_invariant(mEGLDisplay != EGL_NO_DISPLAY);
        initialized = eglInitialize(mEGLDisplay, &major, &minor);
    }

    if (UTILS_UNLIKELY(!initialized)) {
        LOG(ERROR) << "eglInitialize failed";
        return nullptr;
    }