#include "config.h"
#include "GLXContext.h"
#if USE(GLX)
#include "X11Helper.h"
namespace WebCore {
typedef GLXContext (*GLXCREATECONTEXTATTRIBSARBPROC)(Display*, GLXFBConfig, GLXContext, Bool, const int*);
static GLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB = 0;
static int Attribs[] = {
GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB,
GLX_LOSE_CONTEXT_ON_RESET_ARB,
0 };
static void initializeARBExtensions()
{
static bool initialized = false;
if (initialized)
return;
initialized = true;
if (GLPlatformContext::supportsGLXExtension(X11Helper::nativeDisplay(), "GLX_ARB_create_context_robustness"))
glXCreateContextAttribsARB = reinterpret_cast<GLXCREATECONTEXTATTRIBSARBPROC>(glXGetProcAddress(reinterpret_cast<const GLubyte*>("glXCreateContextAttribsARB")));
}
GLXOffScreenContext::GLXOffScreenContext()
: GLPlatformContext()
{
}
bool GLXOffScreenContext::initialize(GLPlatformSurface* surface, PlatformContext sharedContext)
{
if (!surface)
return false;
Display* x11Display = X11Helper::nativeDisplay();
if (!x11Display)
return false;
GLXFBConfig config = surface->configuration();
if (config) {
initializeARBExtensions();
if (glXCreateContextAttribsARB)
m_contextHandle = glXCreateContextAttribsARB(x11Display, config, sharedContext, true, Attribs);
if (m_contextHandle) {
if (platformMakeCurrent(surface) && GLPlatformContext::supportsGLExtension("GL_ARB_robustness"))
m_resetLostContext = true;
else
glXDestroyContext(x11Display, m_contextHandle);
}
bool supportsAlpha = surface->attributes() & GLPlatformSurface::SupportAlpha;
if (!m_contextHandle)
m_contextHandle = glXCreateNewContext(x11Display, config, supportsAlpha ? GLX_RGBA_TYPE : 0, sharedContext, true);
if (m_contextHandle)
return true;
}
return false;
}
GLXOffScreenContext::~GLXOffScreenContext()
{
}
bool GLXOffScreenContext::isCurrentContext() const
{
return m_contextHandle == glXGetCurrentContext();
}
bool GLXOffScreenContext::platformMakeCurrent(GLPlatformSurface* surface)
{
return glXMakeCurrent(X11Helper::nativeDisplay(), surface->drawable(), m_contextHandle);
}
void GLXOffScreenContext::platformReleaseCurrent()
{
Display* x11Display = X11Helper::nativeDisplay();
if (!x11Display)
return;
glXMakeCurrent(x11Display, 0, 0);
}
void GLXOffScreenContext::freeResources()
{
Display* x11Display = X11Helper::nativeDisplay();
if (!x11Display)
return;
if (m_contextHandle)
glXDestroyContext(x11Display, m_contextHandle);
m_contextHandle = 0;
}
void GLXOffScreenContext::destroy()
{
freeResources();
GLPlatformContext::destroy();
}
}
#endif