Skip to content

Commit

Permalink
Fixed compilation of refactored EGL on X11
Browse files Browse the repository at this point in the history
  • Loading branch information
lkosmid authored and FernetMenta committed Dec 6, 2015
1 parent 3b2dfb9 commit f475de7
Show file tree
Hide file tree
Showing 13 changed files with 371 additions and 36 deletions.
1 change: 1 addition & 0 deletions xbmc/rendering/gles/RenderSystemGLES.h
Expand Up @@ -61,6 +61,7 @@ class CRenderSystemGLES : public CRenderSystemBase
virtual bool IsExtSupported(const char* extension);

virtual void SetVSync(bool vsync);
virtual void ResetVSync() { m_bVsyncInit = false; }

virtual void SetViewPort(CRect& viewPort);
virtual void GetViewPort(CRect& viewPort);
Expand Down
10 changes: 7 additions & 3 deletions xbmc/system.h
Expand Up @@ -160,7 +160,6 @@
#endif
#define HAS_GL
#ifdef HAVE_X11
#define HAS_GLX
#define HAS_X11_WIN_EVENTS
#endif
#ifdef HAVE_SDL
Expand Down Expand Up @@ -189,6 +188,13 @@
#define HAS_FILESYSTEM_SFTP
#endif

#if defined(HAVE_X11)
#define HAS_EGL
#if !defined(HAVE_LIBGLESV2)
#define HAS_GLX
#endif
#endif

/****************************************
* Additional platform specific includes
****************************************/
Expand Down Expand Up @@ -230,9 +236,7 @@
#undef HAS_LIRC
#endif

// EGL detected. Dont use GLX!
#ifdef HAVE_LIBEGL
#undef HAS_GLX
#define HAS_EGL
#endif

Expand Down
5 changes: 4 additions & 1 deletion xbmc/windowing/WindowingFactory.h
Expand Up @@ -29,7 +29,10 @@
#elif defined(TARGET_WINDOWS) && defined(HAS_DX)
#include "windows/WinSystemWin32DX.h"

#elif defined(TARGET_LINUX) && defined(HAVE_X11)
#elif defined(TARGET_LINUX) && defined(HAVE_X11) && defined(HAS_GLES)
#include "X11/WinSystemX11GLESContext.h"

#elif defined(TARGET_LINUX) && defined(HAVE_X11) && defined(HAS_GL)
#include "X11/WinSystemX11GLContext.h"

#elif defined(TARGET_LINUX) && defined(HAS_GLES) && defined(HAS_EGL) && !defined(HAVE_X11)
Expand Down
16 changes: 0 additions & 16 deletions xbmc/windowing/X11/GLContext.h
Expand Up @@ -21,26 +21,16 @@
#pragma once

#if defined(HAVE_X11)
#include "GL/glx.h"
#include "EGL/egl.h"
#include "X11/Xlib.h"
#include "guilib/DirtyRegion.h"

#define EGL_NO_CONFIG (EGLConfig)0

class CGLContext
{
public:
CGLContext(Display *dpy)
{
m_dpy = dpy;
m_extensions = "";
m_glxWindow = 0;
m_glxContext = 0;
m_eglDisplay = EGL_NO_DISPLAY;
m_eglSurface = EGL_NO_SURFACE;
m_eglContext = EGL_NO_CONTEXT;
m_eglConfig = EGL_NO_CONFIG;
}
virtual bool Refresh(bool force, int screen, Window glWindow, bool &newContext) = 0;
virtual void Destroy() = 0;
Expand All @@ -55,12 +45,6 @@ class CGLContext
std::string m_extensions;

Display *m_dpy;
GLXWindow m_glxWindow;
GLXContext m_glxContext;
EGLDisplay m_eglDisplay;
EGLSurface m_eglSurface;
EGLContext m_eglContext;
EGLConfig m_eglConfig;
};

#endif
74 changes: 71 additions & 3 deletions xbmc/windowing/X11/GLContextEGL.cpp
Expand Up @@ -17,17 +17,35 @@
* <http://www.gnu.org/licenses/>.
*
*/

#include "system.h"

#if defined(HAVE_X11)
#if defined(HAVE_X11) && defined(HAS_EGL)

#ifdef HAS_GL
// always define GL_GLEXT_PROTOTYPES before include gl headers
#if !defined(GL_GLEXT_PROTOTYPES)
#define GL_GLEXT_PROTOTYPES
#endif
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glext.h>
#elif HAS_GLES == 2
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#endif

#include "GLContextEGL.h"
#include "utils/log.h"

#define EGL_NO_CONFIG (EGLConfig)0

CGLContextEGL::CGLContextEGL(Display *dpy) : CGLContext(dpy)
{
m_extPrefix = "EGL_";
m_eglDisplay = EGL_NO_DISPLAY;
m_eglSurface = EGL_NO_SURFACE;
m_eglContext = EGL_NO_CONTEXT;
m_eglConfig = EGL_NO_CONFIG;
}

CGLContextEGL::~CGLContextEGL()
Expand Down Expand Up @@ -165,7 +183,10 @@ bool CGLContextEGL::Refresh(bool force, int screen, Window glWindow, bool &newCo
}
#endif

m_eglConfig = getEGLConfig(m_eglDisplay, vInfo);
if(m_eglConfig == EGL_NO_CONFIG)
{
m_eglConfig = getEGLConfig(m_eglDisplay, vInfo);
}

if (m_eglConfig == EGL_NO_CONFIG)
{
Expand Down Expand Up @@ -364,4 +385,51 @@ bool CGLContextEGL::IsExtSupported(const char* extension)
return m_extensions.find(name) != std::string::npos;
}

XVisualInfo* CGLContextEGL::GetVisual()
{
GLint att[] =
{
EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_BLUE_SIZE, 8,
EGL_ALPHA_SIZE, 8,
EGL_BUFFER_SIZE, 32,
EGL_DEPTH_SIZE, 24,
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL_NONE
};

if (m_eglDisplay == EGL_NO_DISPLAY)
{
m_eglDisplay = eglGetDisplay((EGLNativeDisplayType)m_dpy);
if (m_eglDisplay == EGL_NO_DISPLAY)
{
CLog::Log(LOGERROR, "failed to get egl display\n");
return NULL;
}
if (!eglInitialize(m_eglDisplay, NULL, NULL))
{
CLog::Log(LOGERROR, "failed to initialize egl display\n");
return NULL;
}
}

EGLint numConfigs;
EGLConfig eglConfig = 0;
if (!eglChooseConfig(m_eglDisplay, att, &eglConfig, 1, &numConfigs) || numConfigs == 0) {
CLog::Log(LOGERROR, "Failed to choose a config %d\n", eglGetError());
}
m_eglConfig=eglConfig;

XVisualInfo x11_visual_info_template;
if (!eglGetConfigAttrib(m_eglDisplay, m_eglConfig, EGL_NATIVE_VISUAL_ID, (EGLint*)&x11_visual_info_template.visualid)) {
CLog::Log(LOGERROR, "Failed to query native visual id\n");
}
int num_visuals;
return XGetVisualInfo(m_dpy,
VisualIDMask,
&x11_visual_info_template,
&num_visuals);
}

#endif
5 changes: 5 additions & 0 deletions xbmc/windowing/X11/GLContextEGL.h
Expand Up @@ -36,6 +36,11 @@ class CGLContextEGL : public CGLContext
virtual bool SwapBuffers(const CDirtyRegionList& dirty, int &mode);
virtual void QueryExtensions();
virtual bool IsExtSupported(const char* extension);
XVisualInfo* GetVisual();
EGLDisplay m_eglDisplay;
EGLSurface m_eglSurface;
EGLContext m_eglContext;
EGLConfig m_eglConfig;
protected:
bool IsSuitableVisual(XVisualInfo *vInfo);
EGLConfig getEGLConfig(EGLDisplay eglDisplay, XVisualInfo *vInfo);
Expand Down
4 changes: 3 additions & 1 deletion xbmc/windowing/X11/GLContextGLX.cpp
Expand Up @@ -20,7 +20,7 @@

#include "system_gl.h"

#if defined(HAVE_X11)
#if defined(HAVE_X11) && defined(HAS_GL)

#include <GL/glx.h>
#include "GLContextGLX.h"
Expand All @@ -29,6 +29,8 @@
CGLContextGLX::CGLContextGLX(Display *dpy) : CGLContext(dpy)
{
m_extPrefix = "GLX_";
m_glxWindow = 0;
m_glxContext = 0;
}

bool CGLContextGLX::Refresh(bool force, int screen, Window glWindow, bool &newContext)
Expand Down
2 changes: 2 additions & 0 deletions xbmc/windowing/X11/GLContextGLX.h
Expand Up @@ -35,6 +35,8 @@ class CGLContextGLX : public CGLContext
virtual bool SwapBuffers(const CDirtyRegionList& dirty, int &mode);
virtual void QueryExtensions();
virtual bool IsExtSupported(const char* extension);
GLXWindow m_glxWindow;
GLXContext m_glxContext;
protected:
bool IsSuitableVisual(XVisualInfo *vInfo);

Expand Down
1 change: 1 addition & 0 deletions xbmc/windowing/X11/Makefile
@@ -1,5 +1,6 @@
SRCS=WinSystemX11.cpp \
WinSystemX11GLContext.cpp \
WinSystemX11GLESContext.cpp \
GLContextEGL.cpp \
GLContextGLX.cpp \
XRandR.cpp \
Expand Down
36 changes: 33 additions & 3 deletions xbmc/windowing/X11/WinSystemX11GLContext.cpp
Expand Up @@ -19,21 +19,21 @@
*/
#include "system.h"

#if defined(HAVE_X11)
#if defined(HAVE_X11) && defined(HAS_GL)

#include <X11/Xlib.h>
#include <X11/Xutil.h>

#include "WinSystemX11GLContext.h"
#include "GLContextGLX.h"
#include "GLContextEGL.h"
#include "utils/log.h"
#include "utils/StringUtils.h"
#include "guilib/GraphicContext.h"
#include "guilib/DispResource.h"
#include "threads/SingleLock.h"
#include <vector>
#include "Application.h"
#include "GLContextEGL.h"
#include "GLContextGLX.h"

CWinSystemX11GLContext::CWinSystemX11GLContext()
{
Expand Down Expand Up @@ -63,6 +63,36 @@ bool CWinSystemX11GLContext::IsExtSupported(const char* extension)
return m_pGLContext->IsExtSupported(extension);
}

GLXWindow CWinSystemX11GLContext::GetWindow() const
{
return static_cast<CGLContextGLX*>(m_pGLContext)->m_glxWindow;
}

GLXContext CWinSystemX11GLContext::GetGlxContext() const
{
return static_cast<CGLContextGLX*>(m_pGLContext)->m_glxContext;
}

EGLDisplay CWinSystemX11GLContext::GetEGLDisplay() const
{
return static_cast<CGLContextEGL*>(m_pGLContext)->m_eglDisplay;
}

EGLSurface CWinSystemX11GLContext::GetEGLSurface() const
{
return static_cast<CGLContextEGL*>(m_pGLContext)->m_eglSurface;
}

EGLContext CWinSystemX11GLContext::GetEGLContext() const
{
return static_cast<CGLContextEGL*>(m_pGLContext)->m_eglContext;
}

EGLConfig CWinSystemX11GLContext::GetEGLConfig() const
{
return static_cast<CGLContextEGL*>(m_pGLContext)->m_eglConfig;
}

bool CWinSystemX11GLContext::SetWindow(int width, int height, bool fullscreen, const std::string &output, int *winstate)
{
int newwin = 0;
Expand Down
19 changes: 10 additions & 9 deletions xbmc/windowing/X11/WinSystemX11GLContext.h
Expand Up @@ -23,11 +23,12 @@
#if defined(HAVE_X11)

#include "WinSystemX11.h"
#include "GLContext.h"
#include "rendering/gl/RenderSystemGL.h"
#include "utils/GlobalsHandling.h"
#include "GL/glx.h"
#include "EGL/egl.h"
#include "rendering/gl/RenderSystemGL.h"
#include "utils/GlobalsHandling.h"

class CGLContext;

class CWinSystemX11GLContext : public CWinSystemX11, public CRenderSystemGL
{
Expand All @@ -42,12 +43,12 @@ class CWinSystemX11GLContext : public CWinSystemX11, public CRenderSystemGL

virtual bool IsExtSupported(const char* extension);

GLXWindow GetWindow() { return m_pGLContext->m_glxWindow; }
GLXContext GetGlxContext() { return m_pGLContext->m_glxContext; }
EGLDisplay GetEGLDisplay() const { return m_pGLContext->m_eglDisplay; }
EGLSurface GetEGLSurface() const { return m_pGLContext->m_eglSurface; }
EGLContext GetEGLContext() const { return m_pGLContext->m_eglContext; }
EGLConfig GetEGLConfig() const { return m_pGLContext->m_eglConfig; }
GLXWindow GetWindow() const;
GLXContext GetGlxContext() const;
EGLDisplay GetEGLDisplay() const;
EGLSurface GetEGLSurface() const;
EGLContext GetEGLContext() const;
EGLConfig GetEGLConfig() const;

protected:
virtual bool SetWindow(int width, int height, bool fullscreen, const std::string &output, int *winstate = NULL);
Expand Down

0 comments on commit f475de7

Please sign in to comment.