diff --git a/src/core/gl_context_qt.cpp b/src/core/gl_context_qt.cpp index 1d51292dc11fa8d3906284e9e133d984459ec341..f440679cfb0d5202846a2db9d862140b7b03cf93 100644 --- a/src/core/gl_context_qt.cpp +++ b/src/core/gl_context_qt.cpp @@ -41,6 +41,8 @@ #include "gl_context_qt.h" +#include <QGuiApplication> +#include <QThread> #include "ui/gl/gl_context_egl.h" QT_BEGIN_NAMESPACE @@ -53,6 +55,12 @@ void GLContextHelper::initialize() contextHelper = new GLContextHelper; } +void GLContextHelper::destroy() +{ + delete contextHelper; + contextHelper = 0; +} + bool GLContextHelper::initializeContextOnBrowserThread(gfx::GLContext* context, gfx::GLSurface* surface) { return context->Initialize(surface, gfx::PreferDiscreteGpu); @@ -61,7 +69,8 @@ bool GLContextHelper::initializeContextOnBrowserThread(gfx::GLContext* context, bool GLContextHelper::initializeContext(gfx::GLContext* context, gfx::GLSurface* surface) { bool ret = false; - QMetaObject::invokeMethod(contextHelper, "initializeContextOnBrowserThread", Qt::BlockingQueuedConnection, + Qt::ConnectionType connType = (QThread::currentThread() == qApp->thread()) ? Qt::DirectConnection : Qt::BlockingQueuedConnection; + QMetaObject::invokeMethod(contextHelper, "initializeContextOnBrowserThread", connType, Q_RETURN_ARG(bool, ret), Q_ARG(gfx::GLContext*, context), Q_ARG(gfx::GLSurface*, surface)); @@ -70,7 +79,7 @@ bool GLContextHelper::initializeContext(gfx::GLContext* context, gfx::GLSurface* QT_END_NAMESPACE -#if defined(USE_OZONE) +#if defined(USE_OZONE) || defined(OS_ANDROID) namespace gfx { diff --git a/src/core/gl_context_qt.h b/src/core/gl_context_qt.h index efe8958beeeec4b15a5685068f367b1255ef337e..1ad6d29448253ab9b1251ec951a038ebf0bfe196 100644 --- a/src/core/gl_context_qt.h +++ b/src/core/gl_context_qt.h @@ -44,17 +44,18 @@ #include <QObject> -QT_BEGIN_NAMESPACE - namespace gfx { class GLContext; class GLSurface; } +QT_BEGIN_NAMESPACE + class GLContextHelper : public QObject { Q_OBJECT public: static void initialize(); + static void destroy(); static bool initializeContext(gfx::GLContext* context, gfx::GLSurface* surface); private: diff --git a/src/core/surface_factory_qt.cpp b/src/core/surface_factory_qt.cpp index 3b4dcfc8b30463a32caa1d4f03e88d335964760d..9db9a9d2c4427894a9d4d80a1a0e0fdb802006ed 100644 --- a/src/core/surface_factory_qt.cpp +++ b/src/core/surface_factory_qt.cpp @@ -50,7 +50,7 @@ #include <QGuiApplication> #include <qpa/qplatformnativeinterface.h> -#if defined(USE_OZONE) +#if defined(USE_OZONE) || defined(OS_ANDROID) #include <EGL/egl.h> #ifndef QT_LIBDIR_EGL @@ -62,7 +62,12 @@ bool SurfaceFactoryQt::LoadEGLGLES2Bindings(AddGLLibraryCallback add_gl_library, SetGLGetProcAddressProcCallback set_gl_get_proc_address) { - +#if defined(OS_ANDROID) + // This is done in gl_implementation_android.cc for now. We might need to switch if we + // start supporting the emulator platform but that would be a more intrusive change. + Q_UNREACHABLE(); + return false; +#else base::FilePath libEGLPath = toFilePath(QT_LIBDIR_EGL); libEGLPath = libEGLPath.Append("libEGL.so"); base::NativeLibrary eglLibrary = gfx::LoadLibrary(libEGLPath); @@ -91,6 +96,7 @@ bool SurfaceFactoryQt::LoadEGLGLES2Bindings(AddGLLibraryCallback add_gl_library, gfx::AddGLNativeLibrary(eglLibrary); gfx::AddGLNativeLibrary(gles2Library); return true; +#endif } intptr_t SurfaceFactoryQt::GetNativeDisplay() diff --git a/src/core/surface_factory_qt.h b/src/core/surface_factory_qt.h index 28a377e2c644fd56edd518628725a6235cc893ee..78ccbf2e2101fda2f914cdee16b742f603718759 100644 --- a/src/core/surface_factory_qt.h +++ b/src/core/surface_factory_qt.h @@ -42,7 +42,7 @@ #ifndef SURFACE_FACTORY_QT #define SURFACE_FACTORY_QT -#if defined(USE_OZONE) +#if defined(USE_OZONE) || defined(OS_ANDROID) #include "ui/gfx/ozone/surface_factory_ozone.h" diff --git a/src/core/web_engine_context.cpp b/src/core/web_engine_context.cpp index d2550e48d1b50c0fcb943b867d67c6bf1778ea35..feec45e904c4b831acce432a24e947744014d994 100644 --- a/src/core/web_engine_context.cpp +++ b/src/core/web_engine_context.cpp @@ -75,6 +75,7 @@ #include "gl_context_qt.h" #include "media_capture_devices_dispatcher.h" #include "type_conversion.h" +#include "surface_factory_qt.h" #include "web_engine_library_info.h" #include <QGuiApplication> #include <QStringList> @@ -94,6 +95,7 @@ void destroyContext() WebEngineContext::~WebEngineContext() { + GLContextHelper::destroy(); m_runLoop->AfterRun(); } @@ -159,6 +161,11 @@ WebEngineContext::WebEngineContext() parsedCommandLine->AppendSwitch(cc::switches::kDisableCompositedAntialiasing); parsedCommandLine->AppendSwitchASCII(switches::kProfilerTiming, switches::kProfilerTimingDisabledValue); + + // On eAndroid we use this to get the native display + // from Qt in GLSurfaceEGL::InitializeOneOff. + m_surfaceFactory.reset(new SurfaceFactoryQt()); + gfx::SurfaceFactoryOzone::SetInstance(m_surfaceFactory.get()); #endif GLContextHelper::initialize(); diff --git a/src/core/web_engine_context.h b/src/core/web_engine_context.h index e0624afa1009fc5396a07df4c20a68a3cac3cef1..13554066b6f3fb7245cfc2d88e16e0e3372d9b2f 100644 --- a/src/core/web_engine_context.h +++ b/src/core/web_engine_context.h @@ -55,6 +55,7 @@ class ContentMainRunner; } class ContentMainDelegateQt; +class SurfaceFactoryQt; class WebEngineContext : public base::RefCounted<WebEngineContext> { public: @@ -69,6 +70,9 @@ private: scoped_ptr<ContentMainDelegateQt> m_mainDelegate; scoped_ptr<content::ContentMainRunner> m_contentRunner; scoped_ptr<content::BrowserMainRunner> m_browserRunner; +#if defined(OS_ANDROID) + scoped_ptr<SurfaceFactoryQt> m_surfaceFactory; +#endif }; #endif // WEB_ENGINE_CONTEXT_H