2 * Copyright (C) 2012 Intel Corporation. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
27 #include "GLXContext.h"
29 #if USE(ACCELERATED_COMPOSITING) && USE(GLX)
31 #include "X11Helper.h"
35 typedef GLXContext (*GLXCREATECONTEXTATTRIBSARBPROC)(Display*, GLXFBConfig, GLXContext, Bool, const int*);
36 static GLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB = 0;
38 static int Attribs[] = {
39 GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB,
40 GLX_LOSE_CONTEXT_ON_RESET_ARB,
43 static void initializeARBExtensions()
45 static bool initialized = false;
50 if (GLPlatformContext::supportsGLXExtension(X11Helper::nativeDisplay(), "GLX_ARB_create_context_robustness"))
51 glXCreateContextAttribsARB = reinterpret_cast<GLXCREATECONTEXTATTRIBSARBPROC>(glXGetProcAddress(reinterpret_cast<const GLubyte*>("glXCreateContextAttribsARB")));
54 GLXOffScreenContext::GLXOffScreenContext()
59 bool GLXOffScreenContext::initialize(GLPlatformSurface* surface)
64 Display* x11Display = surface->sharedDisplay();
68 GLXFBConfig config = surface->configuration();
71 initializeARBExtensions();
73 if (glXCreateContextAttribsARB)
74 m_contextHandle = glXCreateContextAttribsARB(x11Display, config, 0, true, Attribs);
76 if (m_contextHandle) {
77 // The GLX_ARB_create_context_robustness spec requires that a context created with
78 // GLX_CONTEXT_ROBUST_ACCESS_BIT_ARB bit set must also support GL_ARB_robustness or
79 // a version of OpenGL incorporating equivalent functionality.
80 // The spec also defines similar requirements for attribute GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB.
81 if (platformMakeCurrent(surface) && GLPlatformContext::supportsGLExtension("GL_ARB_robustness"))
82 m_resetLostContext = true;
84 glXDestroyContext(x11Display, m_contextHandle);
88 m_contextHandle = glXCreateNewContext(x11Display, config, GLX_RGBA_TYPE, 0, true);
97 GLXOffScreenContext::~GLXOffScreenContext()
101 bool GLXOffScreenContext::isCurrentContext() const
103 return m_contextHandle == glXGetCurrentContext();
106 bool GLXOffScreenContext::platformMakeCurrent(GLPlatformSurface* surface)
108 return glXMakeCurrent(surface->sharedDisplay(), surface->handle(), m_contextHandle);
111 void GLXOffScreenContext::platformReleaseCurrent()
113 Display* x11Display = X11Helper::nativeDisplay();
117 glXMakeCurrent(x11Display, 0, 0);
120 void GLXOffScreenContext::freeResources()
122 Display* x11Display = X11Helper::nativeDisplay();
127 glXDestroyContext(x11Display, m_contextHandle);
132 void GLXOffScreenContext::destroy()
135 GLPlatformContext::destroy();