| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2012 Intel Corporation. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions | |
| 6 * are met: | |
| 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. | |
| 12 * | |
| 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. | |
| 24 */ | |
| 25 | |
| 26 #include "config.h" | |
| 27 #include "GLXContext.h" | |
| 28 | |
| 29 #if USE(ACCELERATED_COMPOSITING) && USE(GLX) | |
| 30 | |
| 31 #include "X11Helper.h" | |
| 32 | |
| 33 namespace WebCore { | |
| 34 | |
| 35 typedef GLXContext (*GLXCREATECONTEXTATTRIBSARBPROC)(Display*, GLXFBConfig, GLXC
ontext, Bool, const int*); | |
| 36 static GLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB = 0; | |
| 37 | |
| 38 static int Attribs[] = { | |
| 39 GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB, | |
| 40 GLX_LOSE_CONTEXT_ON_RESET_ARB, | |
| 41 0 }; | |
| 42 | |
| 43 static void initializeARBExtensions() | |
| 44 { | |
| 45 static bool initialized = false; | |
| 46 if (initialized) | |
| 47 return; | |
| 48 | |
| 49 initialized = true; | |
| 50 if (GLPlatformContext::supportsGLXExtension(X11Helper::nativeDisplay(), "GLX
_ARB_create_context_robustness")) | |
| 51 glXCreateContextAttribsARB = reinterpret_cast<GLXCREATECONTEXTATTRIBSARB
PROC>(glXGetProcAddress(reinterpret_cast<const GLubyte*>("glXCreateContextAttrib
sARB"))); | |
| 52 } | |
| 53 | |
| 54 GLXOffScreenContext::GLXOffScreenContext() | |
| 55 : GLPlatformContext() | |
| 56 { | |
| 57 } | |
| 58 | |
| 59 bool GLXOffScreenContext::initialize(GLPlatformSurface* surface, PlatformContext
sharedContext) | |
| 60 { | |
| 61 if (!surface) | |
| 62 return false; | |
| 63 | |
| 64 Display* x11Display = surface->sharedDisplay(); | |
| 65 if (!x11Display) | |
| 66 return false; | |
| 67 | |
| 68 GLXFBConfig config = surface->configuration(); | |
| 69 | |
| 70 if (config) { | |
| 71 initializeARBExtensions(); | |
| 72 | |
| 73 if (glXCreateContextAttribsARB) | |
| 74 m_contextHandle = glXCreateContextAttribsARB(x11Display, config, sha
redContext, true, Attribs); | |
| 75 | |
| 76 if (m_contextHandle) { | |
| 77 // The GLX_ARB_create_context_robustness spec requires that a contex
t created with | |
| 78 // GLX_CONTEXT_ROBUST_ACCESS_BIT_ARB bit set must also support GL_AR
B_robustness or | |
| 79 // a version of OpenGL incorporating equivalent functionality. | |
| 80 // The spec also defines similar requirements for attribute GLX_CONT
EXT_RESET_NOTIFICATION_STRATEGY_ARB. | |
| 81 if (platformMakeCurrent(surface) && GLPlatformContext::supportsGLExt
ension("GL_ARB_robustness")) | |
| 82 m_resetLostContext = true; | |
| 83 else | |
| 84 glXDestroyContext(x11Display, m_contextHandle); | |
| 85 } | |
| 86 | |
| 87 bool supportsAlpha = surface->attributes() & GLPlatformSurface::SupportA
lpha; | |
| 88 if (!m_contextHandle) | |
| 89 m_contextHandle = glXCreateNewContext(x11Display, config, supportsAl
pha ? GLX_RGBA_TYPE : 0, sharedContext, true); | |
| 90 | |
| 91 if (m_contextHandle) | |
| 92 return true; | |
| 93 } | |
| 94 | |
| 95 return false; | |
| 96 } | |
| 97 | |
| 98 GLXOffScreenContext::~GLXOffScreenContext() | |
| 99 { | |
| 100 } | |
| 101 | |
| 102 bool GLXOffScreenContext::isCurrentContext() const | |
| 103 { | |
| 104 return m_contextHandle == glXGetCurrentContext(); | |
| 105 } | |
| 106 | |
| 107 bool GLXOffScreenContext::platformMakeCurrent(GLPlatformSurface* surface) | |
| 108 { | |
| 109 return glXMakeCurrent(surface->sharedDisplay(), surface->drawable(), m_conte
xtHandle); | |
| 110 } | |
| 111 | |
| 112 void GLXOffScreenContext::platformReleaseCurrent() | |
| 113 { | |
| 114 Display* x11Display = X11Helper::nativeDisplay(); | |
| 115 if (!x11Display) | |
| 116 return; | |
| 117 | |
| 118 glXMakeCurrent(x11Display, 0, 0); | |
| 119 } | |
| 120 | |
| 121 void GLXOffScreenContext::freeResources() | |
| 122 { | |
| 123 Display* x11Display = X11Helper::nativeDisplay(); | |
| 124 if (!x11Display) | |
| 125 return; | |
| 126 | |
| 127 if (m_contextHandle) | |
| 128 glXDestroyContext(x11Display, m_contextHandle); | |
| 129 | |
| 130 m_contextHandle = 0; | |
| 131 } | |
| 132 | |
| 133 void GLXOffScreenContext::destroy() | |
| 134 { | |
| 135 freeResources(); | |
| 136 GLPlatformContext::destroy(); | |
| 137 } | |
| 138 | |
| 139 } | |
| 140 | |
| 141 #endif | |
| OLD | NEW |