diff options
author | Allan Sandfeld Jensen <allan.jensen@theqtcompany.com> | 2016-06-11 17:18:29 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@theqtcompany.com> | 2016-06-11 18:34:14 +0200 |
commit | 6c2a111f8c82b56388abf409a61a3e0d56a52156 (patch) | |
tree | 0f5a7ad320f034233c065fc994980b10afe434ad /src/core/gl_surface_qt.cpp | |
parent | c4fc323d0771e24ae726065cdce9eafef2c09c41 (diff) | |
parent | d6e3ba85138a6147b9b34a1c3363b2d3b20ba284 (diff) |
Merge remote-tracking branch 'origin/5.6' into 5.7
Change-Id: Ib010ede9756fb02992a3276ae7ec90ef1ab56a00
Diffstat (limited to 'src/core/gl_surface_qt.cpp')
-rw-r--r-- | src/core/gl_surface_qt.cpp | 82 |
1 files changed, 80 insertions, 2 deletions
diff --git a/src/core/gl_surface_qt.cpp b/src/core/gl_surface_qt.cpp index 8283e4cc4..f499d853e 100644 --- a/src/core/gl_surface_qt.cpp +++ b/src/core/gl_surface_qt.cpp @@ -87,6 +87,7 @@ void* g_display; const char* g_extensions = NULL; +bool g_egl_surfaceless_context_supported = false; } // namespace @@ -109,6 +110,26 @@ private: DISALLOW_COPY_AND_ASSIGN(GLSurfaceQtEGL); }; +// The following comment is cited from chromium/ui/gl/gl_surface_egl.cc: +// SurfacelessEGL is used as Offscreen surface when platform supports +// KHR_surfaceless_context and GL_OES_surfaceless_context. This would avoid the +// need to create a dummy EGLsurface in case we render to client API targets. +class GLSurfacelessQtEGL : public GLSurfaceQt { +public: + explicit GLSurfacelessQtEGL(const gfx::Size& size); + + public: + bool Initialize() Q_DECL_OVERRIDE; + void Destroy() Q_DECL_OVERRIDE; + bool IsSurfaceless() const Q_DECL_OVERRIDE; + bool Resize(const gfx::Size& size, float scale_factor, bool has_alpha) Q_DECL_OVERRIDE; + EGLSurface GetHandle() Q_DECL_OVERRIDE; + void* GetShareHandle() Q_DECL_OVERRIDE; + +private: + DISALLOW_COPY_AND_ASSIGN(GLSurfacelessQtEGL); +}; + GLSurfaceQt::~GLSurfaceQt() { @@ -342,6 +363,23 @@ bool GLSurfaceQtEGL::InitializeOneOff() return false; } + g_egl_surfaceless_context_supported = ExtensionsContain(g_extensions, "EGL_KHR_surfaceless_context"); + if (g_egl_surfaceless_context_supported) { + scoped_refptr<GLSurface> surface = new GLSurfacelessQtEGL(Size(1, 1)); + scoped_refptr<GLContext> context = GLContext::CreateGLContext( + NULL, surface.get(), PreferIntegratedGpu); + + if (!context->MakeCurrent(surface.get())) + g_egl_surfaceless_context_supported = false; + + // Ensure context supports GL_OES_surfaceless_context. + if (g_egl_surfaceless_context_supported) { + g_egl_surfaceless_context_supported = context->HasExtension( + "GL_OES_surfaceless_context"); + context->ReleaseCurrent(surface.get()); + } + } + initialized = true; return true; } @@ -426,7 +464,7 @@ bool GLSurfaceQtEGL::Initialize() g_config, pbuffer_attributes); if (!m_surfaceBuffer) { - LOG(ERROR) << "eglCreatePbufferSurface failed with error ", GetLastEGLErrorString(); + LOG(ERROR) << "eglCreatePbufferSurface failed with error " << GetLastEGLErrorString(); Destroy(); return false; } @@ -502,6 +540,41 @@ void* GLSurfaceQt::GetConfig() return g_config; } +GLSurfacelessQtEGL::GLSurfacelessQtEGL(const gfx::Size& size) + : GLSurfaceQt(size) +{ +} + +bool GLSurfacelessQtEGL::Initialize() +{ + return true; +} + +void GLSurfacelessQtEGL::Destroy() +{ +} + +bool GLSurfacelessQtEGL::IsSurfaceless() const +{ + return true; +} + +bool GLSurfacelessQtEGL::Resize(const gfx::Size& size, float scale_factor, bool has_alpha) +{ + m_size = size; + return true; +} + +EGLSurface GLSurfacelessQtEGL::GetHandle() +{ + return EGL_NO_SURFACE; +} + +void* GLSurfacelessQtEGL::GetShareHandle() +{ + return NULL; +} + // static scoped_refptr<GLSurface> GLSurface::CreateOffscreenGLSurface(const gfx::Size& size) @@ -525,7 +598,12 @@ GLSurface::CreateOffscreenGLSurface(const gfx::Size& size) #endif } case kGLImplementationEGLGLES2: { - scoped_refptr<GLSurface> surface = new GLSurfaceQtEGL(size); + scoped_refptr<GLSurface> surface; + if (g_egl_surfaceless_context_supported) + surface = new GLSurfacelessQtEGL(size); + else + surface = new GLSurfaceQtEGL(size); + if (!surface->Initialize()) return NULL; return surface; |