Commit 41e5902e authored by Kai Koehne's avatar Kai Koehne Committed by Andras Becsi
Browse files

Add Desktop OpenGL backend for Windows


Enabling rendering into a WGL backbuffer, in addition to the EGL/angle
one.

Change-Id: I8f2e3f5ecf52b6db22712b1129059f462725a256
Reviewed-by: default avatarAndras Becsi <andras.becsi@digia.com>
Showing with 152 additions and 21 deletions
Subproject commit e7cb808b6fcb765ad503068fa47c165c29a7570e Subproject commit 0f43b623079ebd5a3d78978ed187f52bcba7e117
...@@ -17,6 +17,14 @@ GYP_ARGS += "-D perl_exe=\"perl.exe\" -D bison_exe=\"bison.exe\" -D gperf_exe=\" ...@@ -17,6 +17,14 @@ GYP_ARGS += "-D perl_exe=\"perl.exe\" -D bison_exe=\"bison.exe\" -D gperf_exe=\"
# Gyp's parallel processing is broken on Windows # Gyp's parallel processing is broken on Windows
GYP_ARGS += "--no-parallel" GYP_ARGS += "--no-parallel"
CONFIG(release, debug|release): GYP_ARGS+= "-D qt_egl_library=\"libEGL.lib\" -D qt_glesv2_library=\"libGLESv2.lib\"" contains(QT_CONFIG, angle) {
else: GYP_ARGS+= "-D qt_egl_library=\"libEGLd.lib\" -D qt_glesv2_library=\"libGLESv2d.lib\"" CONFIG(release, debug|release) {
GYP_ARGS += "-D qt_egl_library=\"libEGL.lib\" -D qt_glesv2_library=\"libGLESv2.lib\""
} else {
GYP_ARGS += "-D qt_egl_library=\"libEGLd.lib\" -D qt_glesv2_library=\"libGLESv2d.lib\""
}
GYP_ARGS += "-D qt_gl=\"angle\""
} else {
GYP_ARGS += "-D qt_gl=\"opengl\""
}
...@@ -250,7 +250,7 @@ public: ...@@ -250,7 +250,7 @@ public:
if (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) if (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2)
m_handle = pni->nativeResourceForContext(QByteArrayLiteral("eglContext"), qtContext); m_handle = pni->nativeResourceForContext(QByteArrayLiteral("eglContext"), qtContext);
else else
qFatal("Only the EGLGLES2 implementation is supported on %s platform.", platform.toLatin1().constData()); m_handle = pni->nativeResourceForContext(QByteArrayLiteral("renderingcontext"), qtContext);
} else { } else {
qFatal("%s platform not yet supported", platform.toLatin1().constData()); qFatal("%s platform not yet supported", platform.toLatin1().constData());
// Add missing platforms once they work. // Add missing platforms once they work.
......
...@@ -64,6 +64,7 @@ ...@@ -64,6 +64,7 @@
#include "cc/quads/yuv_video_draw_quad.h" #include "cc/quads/yuv_video_draw_quad.h"
#include <QOpenGLContext> #include <QOpenGLContext>
#include <QOpenGLFramebufferObject> #include <QOpenGLFramebufferObject>
#include <QOpenGLFunctions>
#include <QSGAbstractRenderer> #include <QSGAbstractRenderer>
#include <QSGEngine> #include <QSGEngine>
#include <QSGSimpleRectNode> #include <QSGSimpleRectNode>
...@@ -75,7 +76,7 @@ ...@@ -75,7 +76,7 @@
#include <EGL/eglext.h> #include <EGL/eglext.h>
#endif #endif
class RenderPassTexture : public QSGTexture class RenderPassTexture : public QSGTexture, protected QOpenGLFunctions
{ {
public: public:
RenderPassTexture(const cc::RenderPass::Id &id); RenderPassTexture(const cc::RenderPass::Id &id);
...@@ -105,7 +106,7 @@ private: ...@@ -105,7 +106,7 @@ private:
QScopedPointer<QOpenGLFramebufferObject> m_fbo; QScopedPointer<QOpenGLFramebufferObject> m_fbo;
}; };
class MailboxTexture : public QSGTexture { class MailboxTexture : public QSGTexture, protected QOpenGLFunctions {
public: public:
MailboxTexture(const cc::TransferableResource &resource); MailboxTexture(const cc::TransferableResource &resource);
virtual int textureId() const Q_DECL_OVERRIDE { return m_textureId; } virtual int textureId() const Q_DECL_OVERRIDE { return m_textureId; }
...@@ -232,7 +233,14 @@ static void waitChromiumSync(gfx::TransferableFence *sync) ...@@ -232,7 +233,14 @@ static void waitChromiumSync(gfx::TransferableFence *sync)
break; break;
case gfx::TransferableFence::ArbSync: case gfx::TransferableFence::ArbSync:
#ifdef GL_ARB_sync #ifdef GL_ARB_sync
glWaitSync(sync->arb.sync, 0, GL_TIMEOUT_IGNORED); typedef void (QOPENGLF_APIENTRYP WaitSyncPtr)(GLsync sync, GLbitfield flags, GLuint64 timeout);
static WaitSyncPtr glWaitSync_ = 0;
if (!glWaitSync_) {
QOpenGLContext *context = QOpenGLContext::currentContext();
glWaitSync_ = (WaitSyncPtr)context->getProcAddress("glWaitSync");
Q_ASSERT(glWaitSync_);
}
glWaitSync_(sync->arb.sync, 0, GL_TIMEOUT_IGNORED);
#endif #endif
break; break;
} }
...@@ -270,7 +278,14 @@ static void deleteChromiumSync(gfx::TransferableFence *sync) ...@@ -270,7 +278,14 @@ static void deleteChromiumSync(gfx::TransferableFence *sync)
break; break;
case gfx::TransferableFence::ArbSync: case gfx::TransferableFence::ArbSync:
#ifdef GL_ARB_sync #ifdef GL_ARB_sync
glDeleteSync(sync->arb.sync); typedef void (QOPENGLF_APIENTRYP DeleteSyncPtr)(GLsync sync);
static DeleteSyncPtr glDeleteSync_ = 0;
if (!glDeleteSync_) {
QOpenGLContext *context = QOpenGLContext::currentContext();
glDeleteSync_ = (DeleteSyncPtr)context->getProcAddress("glDeleteSync");
Q_ASSERT(glDeleteSync_);
}
glDeleteSync_(sync->arb.sync);
sync->reset(); sync->reset();
#endif #endif
break; break;
...@@ -286,6 +301,7 @@ RenderPassTexture::RenderPassTexture(const cc::RenderPass::Id &id) ...@@ -286,6 +301,7 @@ RenderPassTexture::RenderPassTexture(const cc::RenderPass::Id &id)
, m_sgEngine(new QSGEngine) , m_sgEngine(new QSGEngine)
, m_rootNode(new QSGRootNode) , m_rootNode(new QSGRootNode)
{ {
initializeOpenGLFunctions();
} }
void RenderPassTexture::bind() void RenderPassTexture::bind()
...@@ -330,6 +346,7 @@ MailboxTexture::MailboxTexture(const cc::TransferableResource &resource) ...@@ -330,6 +346,7 @@ MailboxTexture::MailboxTexture(const cc::TransferableResource &resource)
, m_target(GL_TEXTURE_2D) , m_target(GL_TEXTURE_2D)
, m_importCount(1) , m_importCount(1)
{ {
initializeOpenGLFunctions();
} }
void MailboxTexture::bind() void MailboxTexture::bind()
......
...@@ -41,11 +41,16 @@ ...@@ -41,11 +41,16 @@
#include <QThread> #include <QThread>
#include <qpa/qplatformnativeinterface.h> #include <qpa/qplatformnativeinterface.h>
#include "ui/gl/gl_context_egl.h" #include "ui/gl/gl_context_egl.h"
#include "ui/gl/gl_implementation.h"
#if defined(USE_X11) #if defined(USE_X11)
#include <X11/Xlib.h> #include <X11/Xlib.h>
#endif #endif
#if defined(OS_WIN)
#include "ui/gl/gl_context_wgl.h"
#endif
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
Q_GUI_EXPORT QOpenGLContext *qt_gl_global_share_context(); Q_GUI_EXPORT QOpenGLContext *qt_gl_global_share_context();
...@@ -135,7 +140,16 @@ namespace gfx { ...@@ -135,7 +140,16 @@ namespace gfx {
scoped_refptr<GLContext> GLContext::CreateGLContext(GLShareGroup* share_group, GLSurface* compatible_surface, GpuPreference gpu_preference) scoped_refptr<GLContext> GLContext::CreateGLContext(GLShareGroup* share_group, GLSurface* compatible_surface, GpuPreference gpu_preference)
{ {
scoped_refptr<GLContext> context(new GLContextEGL(share_group)); #if defined(OS_WIN)
scoped_refptr<GLContext> context;
if (GetGLImplementation() == kGLImplementationDesktopGL)
context = new GLContextWGL(share_group);
else
context = new GLContextEGL(share_group);
#else
scoped_refptr<GLContext> context = new GLContextEGL(share_group);
#endif
if (!GLContextHelper::initializeContext(context.get(), compatible_surface)) if (!GLContextHelper::initializeContext(context.get(), compatible_surface))
return NULL; return NULL;
......
...@@ -64,6 +64,11 @@ extern "C" { ...@@ -64,6 +64,11 @@ extern "C" {
} }
#endif #endif
#if defined(OS_WIN)
#include "ui/gl/gl_surface_wgl.h"
#include "ui/gl/gl_context_wgl.h"
#endif
using ui::GetLastEGLErrorString; using ui::GetLastEGLErrorString;
namespace gfx { namespace gfx {
...@@ -239,7 +244,75 @@ void* GLSurfaceQtGLX::GetHandle() ...@@ -239,7 +244,75 @@ void* GLSurfaceQtGLX::GetHandle()
return reinterpret_cast<void*>(m_surfaceBuffer); return reinterpret_cast<void*>(m_surfaceBuffer);
} }
#endif // defined(USE_X11) #elif defined(OS_WIN)
class GLSurfaceQtWGL: public GLSurfaceQt {
public:
explicit GLSurfaceQtWGL(const gfx::Size& size);
static bool InitializeOneOff();
virtual bool Initialize() Q_DECL_OVERRIDE;
virtual void Destroy() Q_DECL_OVERRIDE;
virtual void* GetHandle() Q_DECL_OVERRIDE;
virtual void* GetDisplay() Q_DECL_OVERRIDE;
virtual void* GetConfig() Q_DECL_OVERRIDE;
protected:
~GLSurfaceQtWGL();
private:
PbufferGLSurfaceWGL *m_surfaceBuffer;
DISALLOW_COPY_AND_ASSIGN(GLSurfaceQtWGL);
};
GLSurfaceQtWGL::GLSurfaceQtWGL(const gfx::Size& size)
: GLSurfaceQt(size),
m_surfaceBuffer(0)
{
}
GLSurfaceQtWGL::~GLSurfaceQtWGL()
{
Destroy();
}
bool GLSurfaceQtWGL::InitializeOneOff()
{
return GLSurfaceWGL::InitializeOneOff();
}
bool GLSurfaceQtWGL::Initialize()
{
m_surfaceBuffer = new PbufferGLSurfaceWGL(m_size);
return m_surfaceBuffer->Initialize();
}
void GLSurfaceQtWGL::Destroy()
{
if (m_surfaceBuffer) {
delete m_surfaceBuffer;
m_surfaceBuffer = 0;
}
}
void *GLSurfaceQtWGL::GetHandle()
{
return m_surfaceBuffer->GetHandle();
}
void *GLSurfaceQtWGL::GetDisplay()
{
return m_surfaceBuffer->GetDisplay();
}
void *GLSurfaceQtWGL::GetConfig()
{
return m_surfaceBuffer->GetConfig();
}
#endif // defined(OS_WIN)
GLSurfaceQt::GLSurfaceQt() GLSurfaceQt::GLSurfaceQt()
{ {
...@@ -287,9 +360,11 @@ bool GLSurface::InitializeOneOffInternal() ...@@ -287,9 +360,11 @@ bool GLSurface::InitializeOneOffInternal()
if (GetGLImplementation() == kGLImplementationEGLGLES2) if (GetGLImplementation() == kGLImplementationEGLGLES2)
return GLSurfaceQtEGL::InitializeOneOff(); return GLSurfaceQtEGL::InitializeOneOff();
#if defined(USE_X11)
if (GetGLImplementation() == kGLImplementationDesktopGL) if (GetGLImplementation() == kGLImplementationDesktopGL)
#if defined(USE_X11)
return GLSurfaceQtGLX::InitializeOneOff(); return GLSurfaceQtGLX::InitializeOneOff();
#elif defined(OS_WIN)
return GLSurfaceQtWGL::InitializeOneOff();
#endif #endif
return false; return false;
...@@ -456,6 +531,11 @@ GLSurface::CreateOffscreenGLSurface(const gfx::Size& size) ...@@ -456,6 +531,11 @@ GLSurface::CreateOffscreenGLSurface(const gfx::Size& size)
if (!surface->Initialize()) if (!surface->Initialize())
return NULL; return NULL;
return surface; return surface;
#elif defined(OS_WIN)
scoped_refptr<GLSurface> surface = new GLSurfaceQtWGL(size);
if (!surface->Initialize())
return NULL;
return surface;
#else #else
LOG(ERROR) << "Desktop GL is not supported on this platform."; LOG(ERROR) << "Desktop GL is not supported on this platform.";
Q_UNREACHABLE(); Q_UNREACHABLE();
......
...@@ -75,6 +75,7 @@ ...@@ -75,6 +75,7 @@
#include "web_engine_library_info.h" #include "web_engine_library_info.h"
#include "web_engine_visited_links_manager.h" #include "web_engine_visited_links_manager.h"
#include <QGuiApplication> #include <QGuiApplication>
#include <QOpenGLContext>
#include <QStringList> #include <QStringList>
#include <QVector> #include <QVector>
#include <qpa/qplatformnativeinterface.h> #include <qpa/qplatformnativeinterface.h>
...@@ -170,10 +171,16 @@ WebEngineContext::WebEngineContext() ...@@ -170,10 +171,16 @@ WebEngineContext::WebEngineContext()
GLContextHelper::initialize(); GLContextHelper::initialize();
// Tell Chromium to use EGL instead of GLX if the Qt xcb plugin also does. const char *glType;
if ((qApp->platformName() == QStringLiteral("xcb") || qApp->platformName() == QStringLiteral("eglfs")) switch (QOpenGLContext::currentContext()->openGLModuleType()) {
&& qApp->platformNativeInterface()->nativeResourceForWindow(QByteArrayLiteral("egldisplay"), 0)) case QOpenGLContext::LibGL:
parsedCommandLine->AppendSwitchASCII(switches::kUseGL, gfx::kGLImplementationEGLName); glType = gfx::kGLImplementationDesktopName;
break;
case QOpenGLContext::LibGLES:
glType = gfx::kGLImplementationEGLName;
break;
}
parsedCommandLine->AppendSwitchASCII(switches::kUseGL, glType);
content::UtilityProcessHostImpl::RegisterUtilityMainThreadFactory(content::CreateInProcessUtilityThread); content::UtilityProcessHostImpl::RegisterUtilityMainThreadFactory(content::CreateInProcessUtilityThread);
content::RenderProcessHostImpl::RegisterRendererMainThreadFactory(content::CreateInProcessRendererThread); content::RenderProcessHostImpl::RegisterRendererMainThreadFactory(content::CreateInProcessRendererThread);
......
...@@ -36,6 +36,8 @@ ...@@ -36,6 +36,8 @@
#include "yuv_video_node.h" #include "yuv_video_node.h"
#include <QtGui/qopenglcontext.h>
#include <QtGui/qopenglfunctions.h>
#include <QtQuick/qsgtexture.h> #include <QtQuick/qsgtexture.h>
class YUVVideoMaterialShader : public QSGMaterialShader class YUVVideoMaterialShader : public QSGMaterialShader
...@@ -159,11 +161,13 @@ void YUVVideoMaterialShader::updateState(const RenderState &state, QSGMaterial * ...@@ -159,11 +161,13 @@ void YUVVideoMaterialShader::updateState(const RenderState &state, QSGMaterial *
program()->setUniformValue(m_id_uTexture, 1); program()->setUniformValue(m_id_uTexture, 1);
program()->setUniformValue(m_id_vTexture, 2); program()->setUniformValue(m_id_vTexture, 2);
glActiveTexture(GL_TEXTURE1); QOpenGLFunctions glFuncs(QOpenGLContext::currentContext());
glFuncs.glActiveTexture(GL_TEXTURE1);
mat->m_uTexture->bind(); mat->m_uTexture->bind();
glActiveTexture(GL_TEXTURE2); glFuncs.glActiveTexture(GL_TEXTURE2);
mat->m_vTexture->bind(); mat->m_vTexture->bind();
glActiveTexture(GL_TEXTURE0); // Finish with 0 as default texture unit glFuncs.glActiveTexture(GL_TEXTURE0); // Finish with 0 as default texture unit
mat->m_yTexture->bind(); mat->m_yTexture->bind();
program()->setUniformValue(m_id_texOffset, mat->m_texCoordRect.topLeft()); program()->setUniformValue(m_id_texOffset, mat->m_texCoordRect.topLeft());
...@@ -203,11 +207,13 @@ void YUVAVideoMaterialShader::updateState(const RenderState &state, QSGMaterial ...@@ -203,11 +207,13 @@ void YUVAVideoMaterialShader::updateState(const RenderState &state, QSGMaterial
YUVAVideoMaterial *mat = static_cast<YUVAVideoMaterial *>(newMaterial); YUVAVideoMaterial *mat = static_cast<YUVAVideoMaterial *>(newMaterial);
program()->setUniformValue(m_id_aTexture, 3); program()->setUniformValue(m_id_aTexture, 3);
glActiveTexture(GL_TEXTURE3); QOpenGLFunctions glFuncs(QOpenGLContext::currentContext());
glFuncs.glActiveTexture(GL_TEXTURE3);
mat->m_aTexture->bind(); mat->m_aTexture->bind();
// Reset the default texture unit. // Reset the default texture unit.
glActiveTexture(GL_TEXTURE0); glFuncs.glActiveTexture(GL_TEXTURE0);
} }
......
defineTest(isPlatformSupported) { defineTest(isPlatformSupported) {
static: return(false) static: return(false)
osx:lessThan(QMAKE_XCODE_VERSION, 5.1): return(false) osx:lessThan(QMAKE_XCODE_VERSION, 5.1): return(false)
win32: !contains(QT_CONFIG, angle): return(false)
linux-g++|win32-msvc2013|macx-clang: return(true) linux-g++|win32-msvc2013|macx-clang: return(true)
android-g++-b2qt: return(true) android-g++-b2qt: return(true)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment