diff options
author | Michal Klocek <michal.klocek@qt.io> | 2018-07-24 10:42:56 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2018-08-02 20:52:30 +0000 |
commit | 0a1aa2c3cdaf78d39784a428883f3d9aeb23017d (patch) | |
tree | 494e958900d45cc3f4e259aec2a9dd24b4e840b3 /src/core/ozone | |
parent | 3ee51f8f085da394851857b0d6a42df537ca99da (diff) |
Move last surface and context classes to ozone
Moves last two remaining classes to ozone.
Now all the context and surface handling is in ozone subdir.
Change-Id: I87d4570f866b905e8f79a73d70f04bd8b21f6e1b
Reviewed-by: Jüri Valdmann <juri.valdmann@qt.io>
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_surface_qt.cpp | 233 | ||||
-rw-r--r-- | src/core/ozone/gl_surface_qt.h | 82 |
4 files changed, 578 insertions, 0 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..ad78b7d2b --- /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::getXConfig() +{ + 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..cecceabc9 --- /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* getXConfig(); + 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_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 |