1 /****************************************************************************
2 **
3 ** Copyright (C) 2018 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the QtWebEngine module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39
40 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
41 // Use of this source code is governed by a BSD-style license that can be
42 // found in the LICENSE file.
43
44 #include "gl_context_qt.h"
45 #include "ozone/gl_surface_glx_qt.h"
46 #include "ui/gl/gl_bindings.h"
47 #include "ui/gl/gl_surface_glx.h"
48 #include <GL/glx.h>
49 #include <GL/glxext.h>
50
51 namespace gl {
52
53 bool GLSurfaceGLXQt::s_initialized = false;
54
~GLSurfaceGLXQt()55 GLSurfaceGLXQt::~GLSurfaceGLXQt()
56 {
57 Destroy();
58 }
59
ShutdownOneOff()60 void GLSurfaceGLX::ShutdownOneOff()
61 {
62 }
63
IsCreateContextSupported()64 bool GLSurfaceGLX::IsCreateContextSupported()
65 {
66 return ExtensionsContain(GLSurfaceQt::g_extensions, "GLX_ARB_create_context");
67 }
68
IsCreateContextRobustnessSupported()69 bool GLSurfaceGLX::IsCreateContextRobustnessSupported()
70 {
71 return GLContextHelper::isCreateContextRobustnessSupported() && HasGLXExtension("GLX_ARB_create_context_robustness");
72 }
73
IsEXTSwapControlSupported()74 bool GLSurfaceGLX::IsEXTSwapControlSupported()
75 {
76 return HasGLXExtension("GLX_EXT_swap_control");
77 }
78
IsMESASwapControlSupported()79 bool GLSurfaceGLX::IsMESASwapControlSupported()
80 {
81 return HasGLXExtension("GLX_MESA_swap_control");
82 }
83
IsCreateContextProfileSupported()84 bool GLSurfaceGLX::IsCreateContextProfileSupported()
85 {
86 return false; // ExtensionsContain(g_extensions, "GLX_ARB_create_context_profile");
87 }
88
IsCreateContextES2ProfileSupported()89 bool GLSurfaceGLX::IsCreateContextES2ProfileSupported()
90 {
91 return ExtensionsContain(GLSurfaceQt::g_extensions, "GLX_ARB_create_context_es2_profile");
92 }
93
IsOMLSyncControlSupported()94 bool GLSurfaceGLX::IsOMLSyncControlSupported()
95 {
96 return false; // ExtensionsContain(g_extensions, "GLX_OML_sync_control");
97 }
98
HasGLXExtension(const char * name)99 bool GLSurfaceGLX::HasGLXExtension(const char *name)
100 {
101 return ExtensionsContain(GLSurfaceQt::g_extensions, name);
102 }
103
IsTextureFromPixmapSupported()104 bool GLSurfaceGLX::IsTextureFromPixmapSupported()
105 {
106 return ExtensionsContain(GLSurfaceQt::g_extensions, "GLX_EXT_texture_from_pixmap");
107 }
108
GetGLXExtensions()109 const char* GLSurfaceGLX::GetGLXExtensions()
110 {
111 return GLSurfaceQt::g_extensions;
112 }
113
InitializeOneOff()114 bool GLSurfaceGLXQt::InitializeOneOff()
115 {
116 if (s_initialized)
117 return true;
118
119 XInitThreads();
120
121 g_display = GLContextHelper::getXDisplay();
122 if (!g_display) {
123 LOG(ERROR) << "GLContextHelper::getXDisplay() failed.";
124 return false;
125 }
126
127 g_config = GLContextHelper::getGlXConfig();
128 if (!g_config) {
129 LOG(ERROR) << "GLContextHelper::getGlxConfig() failed.";
130 return false;
131 }
132
133 Display* display = static_cast<Display*>(g_display);
134 int major, minor;
135 if (!glXQueryVersion(display, &major, &minor)) {
136 LOG(ERROR) << "glxQueryVersion failed.";
137 return false;
138 }
139
140 if (major == 1 && minor < 3) {
141 LOG(ERROR) << "GLX 1.3 or later is required.";
142 return false;
143 }
144
145 s_initialized = true;
146 return true;
147 }
148
149
InitializeExtensionSettingsOneOff()150 bool GLSurfaceGLXQt::InitializeExtensionSettingsOneOff()
151 {
152 if (!s_initialized)
153 return false;
154
155 Display* display = static_cast<Display*>(g_display);
156 GLSurfaceQt::g_extensions = glXQueryExtensionsString(display, 0);
157 g_driver_glx.InitializeExtensionBindings(g_extensions);
158 return true;
159 }
160
InitializeExtensionSettingsOneOff()161 bool GLSurfaceGLX::InitializeExtensionSettingsOneOff()
162 {
163 return GLSurfaceGLXQt::InitializeExtensionSettingsOneOff();
164 }
165
Initialize(GLSurfaceFormat format)166 bool GLSurfaceGLXQt::Initialize(GLSurfaceFormat format)
167 {
168 Q_ASSERT(!m_surfaceBuffer);
169
170 Display* display = static_cast<Display*>(g_display);
171 const int pbuffer_attributes[] = {
172 GLX_PBUFFER_WIDTH, m_size.width(),
173 GLX_PBUFFER_HEIGHT, m_size.height(),
174 GLX_LARGEST_PBUFFER, x11::False,
175 GLX_PRESERVED_CONTENTS, x11::False,
176 x11::None // MEMO doc: ...must be terminated with None or NULL
177 };
178
179 m_surfaceBuffer = glXCreatePbuffer(display, static_cast<GLXFBConfig>(g_config), pbuffer_attributes);
180 m_format = format;
181
182 if (!m_surfaceBuffer) {
183 Destroy();
184 LOG(ERROR) << "glXCreatePbuffer failed.";
185 return false;
186 }
187 return true;
188 }
189
Destroy()190 void GLSurfaceGLXQt::Destroy()
191 {
192 if (m_surfaceBuffer) {
193 glXDestroyPbuffer(static_cast<Display*>(g_display), m_surfaceBuffer);
194 m_surfaceBuffer = 0;
195 }
196 }
197
GLSurfaceGLXQt(const gfx::Size & size)198 GLSurfaceGLXQt::GLSurfaceGLXQt(const gfx::Size& size)
199 : GLSurfaceQt(size),
200 m_surfaceBuffer(0)
201 {
202 }
203
GetHandle()204 void* GLSurfaceGLXQt::GetHandle()
205 {
206 return reinterpret_cast<void*>(m_surfaceBuffer);
207 }
208
209 } //namespace gl
210
211