diff options
Diffstat (limited to 'src/core/ozone')
-rw-r--r-- | src/core/ozone/gl_context_qt.cpp | 187 | ||||
-rw-r--r-- | src/core/ozone/gl_context_qt.h | 76 | ||||
-rw-r--r-- | src/core/ozone/gl_ozone_egl_qt.cpp | 47 | ||||
-rw-r--r-- | src/core/ozone/gl_ozone_egl_qt.h | 20 | ||||
-rw-r--r-- | src/core/ozone/gl_ozone_glx_qt.cpp | 143 | ||||
-rw-r--r-- | src/core/ozone/gl_ozone_glx_qt.h | 85 | ||||
-rw-r--r-- | src/core/ozone/gl_surface_egl_qt.cpp | 15 | ||||
-rw-r--r-- | src/core/ozone/gl_surface_glx_qt.cpp | 9 | ||||
-rw-r--r-- | src/core/ozone/gl_surface_qt.cpp | 233 | ||||
-rw-r--r-- | src/core/ozone/gl_surface_qt.h | 82 | ||||
-rw-r--r-- | src/core/ozone/ozone_platform_qt.cpp | 8 | ||||
-rw-r--r-- | src/core/ozone/platform_window_qt.h | 2 | ||||
-rw-r--r-- | src/core/ozone/surface_factory_qt.cpp | 34 | ||||
-rw-r--r-- | src/core/ozone/surface_factory_qt.h | 5 |
14 files changed, 912 insertions, 34 deletions
diff --git a/src/core/ozone/gl_context_qt.cpp b/src/core/ozone/gl_context_qt.cpp new file mode 100644 index 000000000..1850380a2 --- /dev/null +++ b/src/core/ozone/gl_context_qt.cpp @@ -0,0 +1,187 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtWebEngine module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "gl_context_qt.h" + +#include <QGuiApplication> +#include <QOpenGLContext> +#include <QThread> +#include <qpa/qplatformnativeinterface.h> +#include "ui/gl/gl_context_egl.h" +#include "ui/gl/gl_implementation.h" + +#if defined(OS_WIN) +#include "ui/gl/gl_context_wgl.h" +#endif + +QT_BEGIN_NAMESPACE + +Q_GUI_EXPORT QOpenGLContext *qt_gl_global_share_context(); +GLContextHelper* GLContextHelper::contextHelper = 0; + +namespace { + +inline void *resourceForContext(const QByteArray &resource) +{ +#ifndef QT_NO_OPENGL + QOpenGLContext *shareContext = qt_gl_global_share_context(); + if (!shareContext) { + qFatal("QWebEngine: OpenGL resource sharing is not set up in QtQuick. Please make sure to call QtWebEngine::initialize() in your main() function."); + } + return qApp->platformNativeInterface()->nativeResourceForContext(resource, shareContext); +#else + return nullptr; +#endif +} + +inline void *resourceForIntegration(const QByteArray &resource) +{ + return qApp->platformNativeInterface()->nativeResourceForIntegration(resource); +} + +} + +void GLContextHelper::initialize() +{ + if (!contextHelper) + contextHelper = new GLContextHelper; +} + +void GLContextHelper::destroy() +{ + delete contextHelper; + contextHelper = 0; +} + +bool GLContextHelper::initializeContextOnBrowserThread(gl::GLContext* context, gl::GLSurface* surface, gl::GLContextAttribs attribs) +{ + return context->Initialize(surface, attribs); +} + +bool GLContextHelper::initializeContext(gl::GLContext* context, gl::GLSurface* surface, gl::GLContextAttribs attribs) +{ + bool ret = false; + Qt::ConnectionType connType = (QThread::currentThread() == qApp->thread()) ? Qt::DirectConnection : Qt::BlockingQueuedConnection; + QMetaObject::invokeMethod(contextHelper, "initializeContextOnBrowserThread", connType, + Q_RETURN_ARG(bool, ret), + Q_ARG(gl::GLContext*, context), + Q_ARG(gl::GLSurface*, surface), + Q_ARG(gl::GLContextAttribs, attribs)); + return ret; +} + +void* GLContextHelper::getEGLConfig() +{ + QByteArray resource = QByteArrayLiteral("eglconfig"); + return resourceForContext(resource); +} + +void* GLContextHelper::getGlXConfig() +{ + return resourceForContext(QByteArrayLiteral("glxconfig")); +} + +void* GLContextHelper::getEGLDisplay() +{ + return resourceForIntegration(QByteArrayLiteral("egldisplay")); +} + +void* GLContextHelper::getXDisplay() +{ + return qApp->platformNativeInterface()->nativeResourceForScreen( + QByteArrayLiteral("display"), qApp->primaryScreen()); +} + +void* GLContextHelper::getNativeDisplay() +{ + return resourceForIntegration(QByteArrayLiteral("nativedisplay")); +} + +QFunctionPointer GLContextHelper::getGlXGetProcAddress() +{ + QFunctionPointer get_proc_address = nullptr; +#ifndef QT_NO_OPENGL + if (QOpenGLContext *context = qt_gl_global_share_context()) { + get_proc_address = context->getProcAddress("glXGetProcAddress"); + } +#endif + return get_proc_address; +} + +QFunctionPointer GLContextHelper::getEglGetProcAddress() +{ + QFunctionPointer get_proc_address = nullptr; +#ifndef QT_NO_OPENGL + if (QOpenGLContext *context = qt_gl_global_share_context()) { + get_proc_address = context->getProcAddress("eglGetProcAddress"); + } +#endif + return get_proc_address; +} + +QT_END_NAMESPACE + +#if defined(OS_WIN) +namespace gl { +namespace init { + +scoped_refptr<GLContext> CreateGLContext(GLShareGroup* share_group, + GLSurface* compatible_surface, + const GLContextAttribs& attribs) +{ + scoped_refptr<GLContext> context; + if (GetGLImplementation() == kGLImplementationDesktopGL) { + context = new GLContextWGL(share_group); + if (!context->Initialize(compatible_surface, attribs)) + return nullptr; + return context; + } else { + context = new GLContextEGL(share_group); + } + + if (!GLContextHelper::initializeContext(context.get(), compatible_surface, attribs)) + return nullptr; + + return context; +} + +} // namespace init +} // namespace gl + +#endif // defined(OS_WIN) diff --git a/src/core/ozone/gl_context_qt.h b/src/core/ozone/gl_context_qt.h new file mode 100644 index 000000000..59ee567aa --- /dev/null +++ b/src/core/ozone/gl_context_qt.h @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtWebEngine module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef GL_GL_CONTEXT_QT_H_ +#define GL_GL_CONTEXT_QT_H_ + +#include <QObject> +#include "ui/gl/gl_context.h" + +namespace gl { +class GLContext; +class GLSurface; +} + +QT_BEGIN_NAMESPACE + +class GLContextHelper : public QObject { + Q_OBJECT +public: + static void initialize(); + static void destroy(); + static bool initializeContext(gl::GLContext* context, gl::GLSurface* surface, gl::GLContextAttribs attribs); + + static void* getEGLConfig(); + static void* getGlXConfig(); + static void* getEGLDisplay(); + static void* getXDisplay(); + static void* getNativeDisplay(); + static QFunctionPointer getGlXGetProcAddress(); + static QFunctionPointer getEglGetProcAddress(); +private: + Q_INVOKABLE bool initializeContextOnBrowserThread(gl::GLContext* context, gl::GLSurface* surface, gl::GLContextAttribs attribs); + + static GLContextHelper* contextHelper; +}; + +QT_END_NAMESPACE + +#endif + diff --git a/src/core/ozone/gl_ozone_egl_qt.cpp b/src/core/ozone/gl_ozone_egl_qt.cpp index a9b3da5e2..2fa86d79b 100644 --- a/src/core/ozone/gl_ozone_egl_qt.cpp +++ b/src/core/ozone/gl_ozone_egl_qt.cpp @@ -38,11 +38,13 @@ ****************************************************************************/ #if defined(USE_OZONE) - +#include "gl_ozone_egl_qt.h" +#include "gl_context_qt.h" +#include "gl_surface_egl_qt.h" #include "base/files/file_path.h" #include "base/native_library.h" #include "gl_context_qt.h" -#include "ozone/gl_ozone_egl_qt.h" +#include "gl_ozone_egl_qt.h" #include "ui/gl/gl_context_egl.h" #include "ui/gl/gl_implementation.h" #include "ui/gl/gl_surface.h" @@ -53,12 +55,16 @@ #include <EGL/egl.h> #include <dlfcn.h> +#include <QtGui/qtgui-config.h> // for QT_NO_OPENGL + #ifndef QT_NO_OPENGL #include <QOpenGLContext> +QT_BEGIN_NAMESPACE Q_GUI_EXPORT QOpenGLContext *qt_gl_global_share_context(); +QT_END_NAMESPACE #endif -namespace QtWebEngineCore { +namespace ui { base::NativeLibrary LoadLibrary(const base::FilePath& filename) { base::NativeLibraryLoadError error; @@ -103,6 +109,39 @@ bool GLOzoneEGLQt::LoadGLES2Bindings(gl::GLImplementation /*implementation*/) return true; } +bool GLOzoneEGLQt::InitializeGLOneOffPlatform() +{ + if (!gl::GLSurfaceEGLQt::InitializeOneOff()) { + LOG(ERROR) << "GLOzoneEGLQt::InitializeOneOff failed."; + return false; + } + return true; +} + +bool GLOzoneEGLQt::InitializeExtensionSettingsOneOffPlatform() +{ + return gl::GLSurfaceEGLQt::InitializeExtensionSettingsOneOff(); +} + +scoped_refptr<gl::GLSurface> GLOzoneEGLQt::CreateViewGLSurface(gfx::AcceleratedWidget window) +{ + return nullptr; +} + +scoped_refptr<gl::GLSurface> GLOzoneEGLQt::CreateOffscreenGLSurface(const gfx::Size &size) +{ + scoped_refptr<gl::GLSurface> surface = new gl::GLSurfaceEGLQt(size); + if (surface->Initialize(gl::GLSurfaceFormat())) + return surface; + + surface = new gl::GLSurfacelessQtEGL(size); + if (surface->Initialize(gl::GLSurfaceFormat())) + return surface; + + LOG(WARNING) << "Failed to create offscreen GL surface"; + return nullptr; +} + intptr_t GLOzoneEGLQt::GetNativeDisplay() { static void *display = GLContextHelper::getNativeDisplay(); @@ -113,6 +152,6 @@ intptr_t GLOzoneEGLQt::GetNativeDisplay() return reinterpret_cast<intptr_t>(EGL_DEFAULT_DISPLAY); } -} // namespace QtWebEngineCore +} // namespace ui #endif // defined(USE_OZONE) diff --git a/src/core/ozone/gl_ozone_egl_qt.h b/src/core/ozone/gl_ozone_egl_qt.h index fc609c51c..c24d03a81 100644 --- a/src/core/ozone/gl_ozone_egl_qt.h +++ b/src/core/ozone/gl_ozone_egl_qt.h @@ -44,18 +44,16 @@ #include "ui/ozone/common/gl_ozone_egl.h" -namespace QtWebEngineCore { +namespace ui { -class GLOzoneEGLQt : public ui::GLOzoneEGL { +class GLOzoneEGLQt : public GLOzoneEGL { public: - scoped_refptr<gl::GLSurface> CreateViewGLSurface(gfx::AcceleratedWidget /*window*/) override - { - return nullptr; - } - scoped_refptr<gl::GLSurface> CreateOffscreenGLSurface(const gfx::Size& /*size*/) override - { - return nullptr; - } + bool InitializeGLOneOffPlatform() override; + bool InitializeExtensionSettingsOneOffPlatform() override; + scoped_refptr<gl::GLSurface> CreateViewGLSurface( + gfx::AcceleratedWidget window) override; + scoped_refptr<gl::GLSurface> CreateOffscreenGLSurface( + const gfx::Size& size) override; protected: // Returns native platform display handle. This is used to obtain the EGL @@ -66,7 +64,7 @@ protected: bool LoadGLES2Bindings(gl::GLImplementation implementation) override; }; -} // namespace QtWebEngineCore +} // namespace ui #endif // defined(USE_OZONE) diff --git a/src/core/ozone/gl_ozone_glx_qt.cpp b/src/core/ozone/gl_ozone_glx_qt.cpp new file mode 100644 index 000000000..9a0fea7c7 --- /dev/null +++ b/src/core/ozone/gl_ozone_glx_qt.cpp @@ -0,0 +1,143 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtWebEngine module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// Copyright 2016 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + + +#include "gl_ozone_glx_qt.h" +#include "gl_surface_glx_qt.h" +#include "ui/gl/gl_context_glx.h" +#include "ui/gl/gl_gl_api_implementation.h" +#include "ui/gl/gl_glx_api_implementation.h" +#include <dlfcn.h> + +namespace ui { + +bool GLOzoneGLXQt::InitializeGLOneOffPlatform() { + if (!gl::GLSurfaceGLXQt::InitializeOneOff()) { + LOG(ERROR) << "GLSurfaceGLXQt::InitializeOneOff failed."; + return false; + } + return true; +} + +bool GLOzoneGLXQt::InitializeStaticGLBindings( + gl::GLImplementation implementation) { + + base::NativeLibrary library = dlopen(NULL, RTLD_LAZY); + if (!library) { + LOG(ERROR) << "Failed to open GL context " << dlerror(); + return false; + } + + gl::GLGetProcAddressProc get_proc_address = + reinterpret_cast<gl::GLGetProcAddressProc>( + base::GetFunctionPointerFromNativeLibrary(library, + "glXGetProcAddress")); + if (!get_proc_address) { + LOG(ERROR) << "glxGetProcAddress not found."; + base::UnloadNativeLibrary(library); + return false; + } + + gl::SetGLGetProcAddressProc(get_proc_address); + gl::AddGLNativeLibrary(library); + gl::SetGLImplementation(gl::kGLImplementationDesktopGL); + + gl::InitializeStaticGLBindingsGL(); + gl::InitializeStaticGLBindingsGLX(); + + return true; +} + +void GLOzoneGLXQt::InitializeDebugGLBindings() { + gl::InitializeDebugGLBindingsGL(); + gl::InitializeDebugGLBindingsGLX(); +} + +void GLOzoneGLXQt::SetDisabledExtensionsPlatform( + const std::string& disabled_extensions) { + gl::SetDisabledExtensionsGLX(disabled_extensions); +} + +void GLOzoneGLXQt::ShutdownGL() { + gl::ClearBindingsGL(); + gl::ClearBindingsGLX(); +} + +bool GLOzoneGLXQt::GetGLWindowSystemBindingInfo( + gl::GLWindowSystemBindingInfo* info) { + return gl::GetGLWindowSystemBindingInfoGLX(info); +} + +scoped_refptr<gl::GLContext> GLOzoneGLXQt::CreateGLContext( + gl::GLShareGroup* share_group, + gl::GLSurface* compatible_surface, + const gl::GLContextAttribs& attribs) { + return gl::InitializeGLContext(new gl::GLContextGLX(share_group), + compatible_surface, attribs); +} + +scoped_refptr<gl::GLSurface> GLOzoneGLXQt::CreateViewGLSurface( + gfx::AcceleratedWidget window) { + return nullptr; +} + +scoped_refptr<gl::GLSurface> GLOzoneGLXQt::CreateSurfacelessViewGLSurface( + gfx::AcceleratedWidget window) { + return nullptr; +} + +scoped_refptr<gl::GLSurface> GLOzoneGLXQt::CreateOffscreenGLSurface( + const gfx::Size& size) { + scoped_refptr<gl::GLSurface> surface = new gl::GLSurfaceGLXQt(size); + if (surface->Initialize(gl::GLSurfaceFormat())) + return surface; + LOG(WARNING) << "Failed to create offscreen GL surface"; + return nullptr; +} + +bool GLOzoneGLXQt::InitializeExtensionSettingsOneOffPlatform() +{ + return gl::GLSurfaceGLXQt::InitializeExtensionSettingsOneOff(); +} + +} // namespace ui diff --git a/src/core/ozone/gl_ozone_glx_qt.h b/src/core/ozone/gl_ozone_glx_qt.h new file mode 100644 index 000000000..ffbd60454 --- /dev/null +++ b/src/core/ozone/gl_ozone_glx_qt.h @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtWebEngine module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef UI_OZONE_GLX_QT_H_ +#define UI_OZONE_GLX_QT_H + +#include "base/macros.h" +#include "ui/gl/gl_implementation.h" +#include "ui/ozone/public/gl_ozone.h" + +namespace ui { + +class GLOzoneGLXQt : public GLOzone { + +public: + GLOzoneGLXQt() {} + ~GLOzoneGLXQt() override {} + + bool InitializeGLOneOffPlatform() override; + bool InitializeStaticGLBindings(gl::GLImplementation implementation) override; + void InitializeDebugGLBindings() override; + bool InitializeExtensionSettingsOneOffPlatform() override; + void ShutdownGL() override; + void SetDisabledExtensionsPlatform( + const std::string& disabled_extensions) override; + bool GetGLWindowSystemBindingInfo( + gl::GLWindowSystemBindingInfo* info) override; + + scoped_refptr<gl::GLContext> CreateGLContext( + gl::GLShareGroup* share_group, + gl::GLSurface* compatible_surface, + const gl::GLContextAttribs& attribs) override; + + scoped_refptr<gl::GLSurface> CreateViewGLSurface( + gfx::AcceleratedWidget window) override; + + scoped_refptr<gl::GLSurface> CreateSurfacelessViewGLSurface( + gfx::AcceleratedWidget window) override; + + scoped_refptr<gl::GLSurface> CreateOffscreenGLSurface( + const gfx::Size& size) override; + +private: + DISALLOW_COPY_AND_ASSIGN(GLOzoneGLXQt); +}; + +} // namespace ui + +#endif // UI_OZONE_GLX_QT_H diff --git a/src/core/ozone/gl_surface_egl_qt.cpp b/src/core/ozone/gl_surface_egl_qt.cpp index 6de9d20b5..9fe5985ce 100644 --- a/src/core/ozone/gl_surface_egl_qt.cpp +++ b/src/core/ozone/gl_surface_egl_qt.cpp @@ -44,8 +44,8 @@ #include "gl_context_qt.h" #include "ozone/gl_surface_egl_qt.h" -#if !defined(OS_MACOSX) #include "ui/gl/gl_surface_egl.h" +#if !defined(OS_MACOSX) #include "ui/gl/egl_util.h" #include "ui/gl/init/gl_factory.h" @@ -140,7 +140,10 @@ bool GLSurfaceEGL::IsCreateContextWebGLCompatabilitySupported() { return false; } - +bool GLSurfaceEGL::IsEGLSurfacelessContextSupported() +{ + return GLSurfaceEGLQt::g_egl_surfaceless_context_supported; +} bool GLSurfaceEGL::IsEGLContextPrioritySupported() { return false; @@ -299,6 +302,10 @@ void* GLSurfacelessQtEGL::GetShareHandle() return NULL; } +} // namespace gl +#endif // !defined(OS_MACOSX) + +namespace gl { std::string DriverEGL::GetPlatformExtensions() { EGLDisplay display = GLContextHelper::getEGLDisplay(); @@ -309,6 +316,4 @@ std::string DriverEGL::GetPlatformExtensions() const char* str = g_driver_egl.fn.eglQueryStringFn(display, EGL_EXTENSIONS); return str ? std::string(str) : ""; } - -} // namespace gl -#endif // !defined(OS_MACOSX) +} // namespace gl diff --git a/src/core/ozone/gl_surface_glx_qt.cpp b/src/core/ozone/gl_surface_glx_qt.cpp index 51b0f58b0..eebefa59b 100644 --- a/src/core/ozone/gl_surface_glx_qt.cpp +++ b/src/core/ozone/gl_surface_glx_qt.cpp @@ -41,8 +41,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#if defined(USE_X11) - #include "gl_context_qt.h" #include "ozone/gl_surface_glx_qt.h" #include "ui/gl/gl_bindings.h" @@ -126,9 +124,9 @@ bool GLSurfaceGLXQt::InitializeOneOff() return false; } - g_config = GLContextHelper::getXConfig(); + g_config = GLContextHelper::getGlXConfig(); if (!g_config) { - LOG(ERROR) << "GLContextHelper::getXConfig() failed."; + LOG(ERROR) << "GLContextHelper::getGlxConfig() failed."; return false; } @@ -156,7 +154,7 @@ bool GLSurfaceGLXQt::InitializeExtensionSettingsOneOff() Display* display = static_cast<Display*>(g_display); GLSurfaceQt::g_extensions = glXQueryExtensionsString(display, 0); - g_driver_glx.InitializeExtensionBindings(); + g_driver_glx.InitializeExtensionBindings(g_extensions); return true; } @@ -210,4 +208,3 @@ void* GLSurfaceGLXQt::GetHandle() } //namespace gl -#endif // defined(USE_X11) diff --git a/src/core/ozone/gl_surface_qt.cpp b/src/core/ozone/gl_surface_qt.cpp new file mode 100644 index 000000000..7cde289ae --- /dev/null +++ b/src/core/ozone/gl_surface_qt.cpp @@ -0,0 +1,233 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtWebEngine module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE.Chromium file. + +#include "gl_surface_qt.h" + +#if !defined(OS_MACOSX) + +#include <QGuiApplication> +#include "gl_context_qt.h" +#include "qtwebenginecoreglobal_p.h" +#include "web_engine_context.h" +#include "ozone/gl_surface_egl_qt.h" + +#include "base/logging.h" +#include "base/threading/thread_restrictions.h" +#include "gpu/ipc/service/image_transport_surface.h" +#include "ui/gl/gl_bindings.h" +#include "ui/gl/gl_context.h" +#include "ui/gl/gl_implementation.h" +#include "ui/gl/init/gl_initializer.h" +#include "ui/gl/init/gl_factory.h" +#include "ui/gl/gl_gl_api_implementation.h" +#if defined(OS_WIN) +#include "ozone/gl_surface_wgl_qt.h" + +#include "gpu/ipc/service/direct_composition_surface_win.h" +#include "ui/gl/gl_context_wgl.h" +#include "ui/gl/vsync_provider_win.h" +#endif + +#include "ozone/gl_surface_egl_qt.h" +#include "ui/gl/gl_egl_api_implementation.h" + +namespace gl { + +namespace { +bool g_initializedEGL = false; +} + +void* GLSurfaceQt::g_display = NULL; +void* GLSurfaceQt::g_config = NULL; +const char* GLSurfaceQt::g_extensions = NULL; + +GLSurfaceQt::~GLSurfaceQt() +{ +} + +GLSurfaceQt::GLSurfaceQt() +{ +} + +GLSurfaceQt::GLSurfaceQt(const gfx::Size& size) + : m_size(size) +{ + // Some implementations of Pbuffer do not support having a 0 size. For such + // cases use a (1, 1) surface. + if (m_size.GetArea() == 0) + m_size.SetSize(1, 1); +} + +bool GLSurfaceQt::HasEGLExtension(const char* name) +{ + return ExtensionsContain(g_extensions, name); +} + +bool GLSurfaceQt::IsOffscreen() +{ + return true; +} + +gfx::SwapResult GLSurfaceQt::SwapBuffers(const PresentationCallback &callback) +{ + LOG(ERROR) << "Attempted to call SwapBuffers on a pbuffer."; + Q_UNREACHABLE(); + return gfx::SwapResult::SWAP_FAILED; +} + +gfx::Size GLSurfaceQt::GetSize() +{ + return m_size; +} + +GLSurfaceFormat GLSurfaceQt::GetFormat() +{ + return m_format; +} + +void* GLSurfaceQt::GetDisplay() +{ + return g_display; +} + +void* GLSurfaceQt::GetConfig() +{ + return g_config; +} + +#if defined(OS_WIN) +namespace init { +bool InitializeGLOneOffPlatform() +{ + VSyncProviderWin::InitializeOneOff(); + + if (GetGLImplementation() == kGLImplementationOSMesaGL) + return false; + + if (GetGLImplementation() == kGLImplementationEGLGLES2) + return GLSurfaceEGLQt::InitializeOneOff(); + + if (GetGLImplementation() == kGLImplementationDesktopGL) { + return GLSurfaceWGLQt::InitializeOneOff(); + + // Fallback to trying EGL with desktop GL. + if (GLSurfaceEGLQt::InitializeOneOff()) { + g_initializedEGL = true; + return true; + } + } + + return false; +} + +bool usingSoftwareDynamicGL() +{ + return QtWebEngineCore::usingSoftwareDynamicGL(); +} + +scoped_refptr<GLSurface> +CreateOffscreenGLSurfaceWithFormat(const gfx::Size& size, GLSurfaceFormat format) +{ + scoped_refptr<GLSurface> surface; + switch (GetGLImplementation()) { + case kGLImplementationDesktopGLCoreProfile: + case kGLImplementationDesktopGL: { + surface = new GLSurfaceWGLQt(size); + if (surface->Initialize(format)) + return surface; + break; + } + case kGLImplementationEGLGLES2: { + surface = new GLSurfaceEGLQt(size); + if (surface->Initialize(format)) + return surface; + + // Surfaceless context will be used ONLY if pseudo surfaceless context + // is not available since some implementations of surfaceless context + // have problems. (e.g. QTBUG-57290) + if (GLSurfaceEGLQt::g_egl_surfaceless_context_supported) { + surface = new GLSurfacelessQtEGL(size); + if (surface->Initialize(format)) + return surface; + } + LOG(ERROR) << "eglCreatePbufferSurface failed and surfaceless context not available"; + LOG(WARNING) << "Failed to create offscreen GL surface"; + break; + } + default: + break; + } + LOG(ERROR) << "Requested OpenGL implementation is not supported. Implementation: " << GetGLImplementation(); + Q_UNREACHABLE(); + return NULL; +} + +scoped_refptr<GLSurface> +CreateViewGLSurface(gfx::AcceleratedWidget window) +{ + QT_NOT_USED + return NULL; +} + +} // namespace init +#endif // defined(OS_WIN) +} // namespace gl + +#if defined(OS_WIN) +namespace gpu { +class GpuCommandBufferStub; +class GpuChannelManager; +scoped_refptr<gl::GLSurface> ImageTransportSurface::CreateNativeSurface(base::WeakPtr<ImageTransportSurfaceDelegate>, + SurfaceHandle, gl::GLSurfaceFormat) +{ + QT_NOT_USED + return scoped_refptr<gl::GLSurface>(); +} + +bool DirectCompositionSurfaceWin::IsHDRSupported() +{ + return false; +} +} // namespace gpu +#endif +#endif // !defined(OS_MACOSX) diff --git a/src/core/ozone/gl_surface_qt.h b/src/core/ozone/gl_surface_qt.h new file mode 100644 index 000000000..514527df9 --- /dev/null +++ b/src/core/ozone/gl_surface_qt.h @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtWebEngine module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + + +#ifndef GL_SURFACE_QT_H_ +#define GL_SURFACE_QT_H_ + +#include "ui/gfx/geometry/size.h" +#include "ui/gl/gl_surface.h" + +namespace gl { + +class GLSurfaceQt: public GLSurface { +public: + explicit GLSurfaceQt(const gfx::Size& size); + + static bool HasEGLExtension(const char* name); + + // Implement GLSurface. + void *GetDisplay() override; + void *GetConfig() override; + bool IsOffscreen() override; + gfx::SwapResult SwapBuffers(const PresentationCallback &callback) override; + gfx::Size GetSize() override; + GLSurfaceFormat GetFormat() override; + +protected: + GLSurfaceQt(); + virtual ~GLSurfaceQt(); + + gfx::Size m_size; + GLSurfaceFormat m_format; + +public: + static void* g_config; + static void* g_display; + static const char* g_extensions; + +private: + DISALLOW_COPY_AND_ASSIGN(GLSurfaceQt); +}; + +} + +#endif diff --git a/src/core/ozone/ozone_platform_qt.cpp b/src/core/ozone/ozone_platform_qt.cpp index 8bb5007ef..905e8f403 100644 --- a/src/core/ozone/ozone_platform_qt.cpp +++ b/src/core/ozone/ozone_platform_qt.cpp @@ -50,6 +50,7 @@ #include "ui/ozone/public/input_controller.h" #include "ui/ozone/public/ozone_platform.h" #include "ui/platform_window/platform_window_delegate.h" +#include "ui/platform_window/platform_window_init_properties.h" #include "ui/platform_window/platform_window.h" namespace ui { @@ -64,7 +65,7 @@ public: ui::SurfaceFactoryOzone* GetSurfaceFactoryOzone() override; ui::CursorFactoryOzone* GetCursorFactoryOzone() override; GpuPlatformSupportHost* GetGpuPlatformSupportHost() override; - std::unique_ptr<PlatformWindow> CreatePlatformWindow(PlatformWindowDelegate* delegate, const gfx::Rect& bounds) override; + std::unique_ptr<PlatformWindow> CreatePlatformWindow(PlatformWindowDelegate* delegate, PlatformWindowInitProperties properties) override; std::unique_ptr<display::NativeDisplayDelegate> CreateNativeDisplayDelegate() override; ui::InputController* GetInputController() override; std::unique_ptr<ui::SystemInputInjector> CreateSystemInputInjector() override; @@ -104,9 +105,9 @@ GpuPlatformSupportHost* OzonePlatformQt::GetGpuPlatformSupportHost() return gpu_platform_support_host_.get(); } -std::unique_ptr<PlatformWindow> OzonePlatformQt::CreatePlatformWindow(PlatformWindowDelegate* delegate, const gfx::Rect& bounds) +std::unique_ptr<PlatformWindow> OzonePlatformQt::CreatePlatformWindow(PlatformWindowDelegate* delegate, PlatformWindowInitProperties properties) { - return base::WrapUnique(new PlatformWindowQt(delegate, bounds)); + return base::WrapUnique(new PlatformWindowQt(delegate, properties.bounds)); } ui::InputController* OzonePlatformQt::GetInputController() @@ -145,7 +146,6 @@ void OzonePlatformQt::InitializeGPU(const ui::OzonePlatform::InitParams &) } // namespace - OzonePlatform* CreateOzonePlatformQt() { return new OzonePlatformQt; } gfx::ClientNativePixmapFactory* CreateClientNativePixmapFactoryQt() diff --git a/src/core/ozone/platform_window_qt.h b/src/core/ozone/platform_window_qt.h index d25096432..b712b706a 100644 --- a/src/core/ozone/platform_window_qt.h +++ b/src/core/ozone/platform_window_qt.h @@ -65,10 +65,12 @@ public: void SetTitle(const base::string16&) override { } void SetCapture() override { } void ReleaseCapture() override { } + bool HasCapture() const override { return false; } void ToggleFullscreen() override { } void Maximize() override { } void Minimize() override { } void Restore() override { } + PlatformWindowState GetPlatformWindowState() const override { return PLATFORM_WINDOW_STATE_UNKNOWN; } void SetCursor(PlatformCursor) override { } void MoveCursorTo(const gfx::Point&) override { } void ConfineCursorToBounds(const gfx::Rect&) override { } diff --git a/src/core/ozone/surface_factory_qt.cpp b/src/core/ozone/surface_factory_qt.cpp index f21e14c30..9570852c9 100644 --- a/src/core/ozone/surface_factory_qt.cpp +++ b/src/core/ozone/surface_factory_qt.cpp @@ -37,6 +37,17 @@ ** ****************************************************************************/ +#include "surface_factory_qt.h" +#include "qtwebenginecoreglobal_p.h" +#include "gl_context_qt.h" +#include "gl_ozone_egl_qt.h" +#if QT_CONFIG(webengine_system_x11) +#include "gl_ozone_glx_qt.h" +#endif + +#include "ui/gl/gl_surface.h" +#include <QGuiApplication> + #if defined(USE_OZONE) #include "ozone/gl_ozone_egl_qt.h" @@ -44,16 +55,31 @@ #include "ui/gl/gl_surface.h" namespace QtWebEngineCore { +SurfaceFactoryQt::SurfaceFactoryQt() +{ + Q_ASSERT(qApp); +#if QT_CONFIG(webengine_system_x11) + if (GLContextHelper::getGlXConfig()) { + m_impl = gl::kGLImplementationDesktopGL; + m_ozone.reset(new ui::GLOzoneGLXQt()); + } else +#endif + if (GLContextHelper::getEGLConfig()) { + m_impl = gl::kGLImplementationEGLGLES2; + m_ozone.reset(new ui::GLOzoneEGLQt()); + } else { + qFatal("No suitable graphics backend found\n"); + } +} + std::vector<gl::GLImplementation> SurfaceFactoryQt::GetAllowedGLImplementations() { - std::vector<gl::GLImplementation> impls; - impls.push_back(gl::kGLImplementationEGLGLES2); - return impls; + return { m_impl }; } ui::GLOzone* SurfaceFactoryQt::GetGLOzone(gl::GLImplementation implementation) { - return new GLOzoneEGLQt(); + return m_ozone.get(); } } // namespace QtWebEngineCore diff --git a/src/core/ozone/surface_factory_qt.h b/src/core/ozone/surface_factory_qt.h index b7991829c..dee41d948 100644 --- a/src/core/ozone/surface_factory_qt.h +++ b/src/core/ozone/surface_factory_qt.h @@ -48,8 +48,13 @@ namespace QtWebEngineCore { class SurfaceFactoryQt : public ui::SurfaceFactoryOzone { +public: + SurfaceFactoryQt(); std::vector<gl::GLImplementation> GetAllowedGLImplementations() override; ui::GLOzone* GetGLOzone(gl::GLImplementation implementation) override; +private: + gl::GLImplementation m_impl; + std::unique_ptr<ui::GLOzone> m_ozone; }; } // namespace QtWebEngineCore |