Skip to content

Commit

Permalink
Extract common DRMContext initialization code
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisThrasher committed Oct 4, 2024
1 parent cfc43f5 commit c4ec7a0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 37 deletions.
53 changes: 16 additions & 37 deletions src/SFML/Window/DRM/DRMContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,20 +513,9 @@ EGLDisplay getInitializedDisplay()
namespace sf::priv
{
////////////////////////////////////////////////////////////
DRMContext::DRMContext(DRMContext* shared)
DRMContext::DRMContext(DRMContext* shared) :
DRMContext(shared, ContextSettings{}, VideoMode::getDesktopMode().bitsPerPixel)
{
contextCount++;

// Get the initialized EGL display
m_display = getInitializedDisplay();

// Get the best EGL config matching the default video settings
m_config = getBestConfig(m_display, VideoMode::getDesktopMode().bitsPerPixel, ContextSettings{});
updateSettings();

// Create EGL context
createContext(shared);

if (shared)
createSurface(shared->m_size, VideoMode::getDesktopMode().bitsPerPixel, false);
else // create a surface to force the GL to initialize (seems to be required for glGetString() etc )
Expand All @@ -535,40 +524,31 @@ DRMContext::DRMContext(DRMContext* shared)


////////////////////////////////////////////////////////////
DRMContext::DRMContext(DRMContext* shared, const ContextSettings& settings, const WindowImpl& owner, unsigned int bitsPerPixel)
DRMContext::DRMContext(DRMContext* shared, const ContextSettings& settings, const WindowImpl& owner, unsigned int bitsPerPixel) :
DRMContext(shared, settings, bitsPerPixel)
{
contextCount++;

// Get the initialized EGL display
m_display = getInitializedDisplay();

// Get the best EGL config matching the requested video settings
m_config = getBestConfig(m_display, bitsPerPixel, settings);
updateSettings();

// Create EGL context
createContext(shared);

const Vector2u size = owner.getSize();
createSurface(size, bitsPerPixel, true);
createSurface(owner.getSize(), bitsPerPixel, true);
}


////////////////////////////////////////////////////////////
DRMContext::DRMContext(DRMContext* shared, const ContextSettings& settings, Vector2u size)
DRMContext::DRMContext(DRMContext* shared, const ContextSettings& settings, Vector2u size) :
DRMContext(shared, settings, VideoMode::getDesktopMode().bitsPerPixel)
{
contextCount++;
createSurface(size, VideoMode::getDesktopMode().bitsPerPixel, false);
}

// Get the initialized EGL display
m_display = getInitializedDisplay();

// Get the best EGL config matching the requested video settings
m_config = getBestConfig(m_display, VideoMode::getDesktopMode().bitsPerPixel, settings);
////////////////////////////////////////////////////////////
DRMContext::DRMContext(DRMContext* shared, const ContextSettings& settings, unsigned int bitsPerPixel) :
m_display(getInitializedDisplay()),
m_config(getBestConfig(m_display, bitsPerPixel, settings))
{
++contextCount;
updateSettings();

// Create EGL context
createContext(shared);
createSurface(size, VideoMode::getDesktopMode().bitsPerPixel, false);
}


Expand Down Expand Up @@ -607,8 +587,7 @@ DRMContext::~DRMContext()
if (m_gbmSurface)
gbm_surface_destroy(m_gbmSurface);

contextCount--;
if (contextCount == 0)
if (--contextCount == 0)
cleanup();
}

Expand Down
10 changes: 10 additions & 0 deletions src/SFML/Window/DRM/DRMContext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,16 @@ class DRMContext : public GlContext
static Drm& getDRM();

private:
////////////////////////////////////////////////////////////
/// \brief Extract common initialization logic
///
/// \param shared Context to share the new one with
/// \param settings Creation parameters
/// \param bitsPerPixel Pixel depth, in bits per pixel
///
////////////////////////////////////////////////////////////
DRMContext(DRMContext* shared, const ContextSettings& settings, unsigned int bitsPerPixel);

////////////////////////////////////////////////////////////
/// \brief Helper to copy the picked EGL configuration
///
Expand Down

0 comments on commit c4ec7a0

Please sign in to comment.