[EFL] Refactor GraphicsContext3DEFL.
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 22 Nov 2012 04:11:34 +0000 (04:11 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 22 Nov 2012 04:11:34 +0000 (04:11 +0000)
https://bugs.webkit.org/show_bug.cgi?id=101291.

Patch by Kondapally Kalyan <kalyan.kondapally@intel.com> on 2012-11-21
Reviewed by Kenneth Rohde Christiansen.

GraphicsContext3DEfl creates GraphicsContext3DPrivate, which acts as its platform Layer.
GraphicsContext3DPrivate needs to handle the following cases:
1) To provide an off-screen buffer for accelerated composition.
2) Render to a current context.
3) To render directly to host window. (currently not supported.)

Before this patch Evas was used to provide us an off-screen context and buffer. GLX was used in
the other supported case. Evas acts as a glue layer to provide us with appropriate
GL bindings (OpenGL functions), GL context and drawable (surface/offscreenbuffer).
However, primitive rendering is handled by TextureMapper and OpenGLShims is used to load the needed GL functions.

It would be for our advantage to be able to take in to use any optimisations/extensions
provided by underlying drivers, specific to a platform (e.g. GLX_MESA_copy_sub_buffer etc.).
This patch introduces an abstraction layer to make it easy to add support for any GL backend (GLX, EGL etc.)
and do any platform specific optimizations as needed without complicating GraphicsContext3DPrivate class.
Two new classes are added with this implementation, GLPlatformContext and GLPlatformSurface.
GraphicsContext3DPrivate would create and own a GLPlatformContext and GLPlatformSurface.

GLPlatformContext encapsulates an OpenGL context hiding any platform specific management.
It uses GL extension ARB_robustness (when available) to detect driver resets.
It defines a simple interface for things that need to be handled by the context. Support
for multi-threaded usage and shared context-group would be added later.

GLPlatformSurface encapsulates an OpenGL drawable hiding any platform specific management.
It defines a simple interface for things that need to be handled by the surface.
It creates an off-screen rendering area. Any GLPlatformContext (compatible with the surface)
can be used to render into this off-screen area.

This patch also adds GLX implementation. To keep the patch to minimum EGL support would be added in another changeset.

* PlatformEfl.cmake:
* platform/graphics/efl/GraphicsContext3DEfl.cpp:
(WebCore::GraphicsContext3D::create):
(WebCore::GraphicsContext3D::GraphicsContext3D):
(WebCore::GraphicsContext3D::~GraphicsContext3D):
(WebCore::GraphicsContext3D::makeContextCurrent):
(WebCore::GraphicsContext3D::setContextLostCallback):
* platform/graphics/efl/GraphicsContext3DPrivate.cpp:
(WebCore::GraphicsContext3DPrivate::GraphicsContext3DPrivate):
(GraphicsContext3DPrivate::~GraphicsContext3DPrivate):
(GraphicsContext3DPrivate::releaseResources):
(GraphicsContext3DPrivate::setContextLostCallback):
(GraphicsContext3DPrivate::platformGraphicsContext3D):
(GraphicsContext3DPrivate::makeContextCurrent):
(GraphicsContext3DPrivate::createGraphicsSurfaces):
(GraphicsContext3DPrivate::copyToGraphicsSurface):
(GraphicsContext3DPrivate::graphicsSurfaceToken):
* platform/graphics/efl/GraphicsContext3DPrivate.h:
(GraphicsContext3DPrivate):
* platform/graphics/opengl/GLDefs.h: Added.
(WebCore):
* platform/graphics/opengl/GLPlatformContext.cpp: Added.
(WebCore):
(WebCore::GLPlatformContext::createContext):
(WebCore::GLPlatformContext::createOffScreenContext):
(WebCore::GLPlatformContext::createCurrentContextWrapper):
(WebCore::GLPlatformContext::GLPlatformContext):
(WebCore::GLPlatformContext::~GLPlatformContext):
(WebCore::GLPlatformContext::makeCurrent):
(WebCore::GLPlatformContext::isValid):
(WebCore::GLPlatformContext::releaseCurrent):
(WebCore::GLPlatformContext::handle):
(WebCore::GLPlatformContext::isCurrentContext):
(WebCore::GLPlatformContext::initialize):
(WebCore::GLPlatformContext::getCurrent):
(WebCore::GLPlatformContext::platformMakeCurrent):
(WebCore::GLPlatformContext::platformReleaseCurrent):
(WebCore::GLPlatformContext::destroy):
* platform/graphics/opengl/GLPlatformContext.h: Added.
(WebCore):
(GLPlatformContext):
* platform/graphics/opengl/GLPlatformSurface.cpp: Added.
(WebCore):
(WebCore::GLPlatformSurface::createOffscreenSurface):
(WebCore::GLPlatformSurface::createTransportSurface):
(WebCore::GLPlatformSurface::GLPlatformSurface):
(WebCore::GLPlatformSurface::~GLPlatformSurface):
(WebCore::GLPlatformSurface::handle):
(WebCore::GLPlatformSurface::geometry):
(WebCore::GLPlatformSurface::sharedDisplay):
(WebCore::GLPlatformSurface::configuration):
(WebCore::GLPlatformSurface::swapBuffers):
(WebCore::GLPlatformSurface::copyTexture):
(WebCore::GLPlatformSurface::updateContents):
(WebCore::GLPlatformSurface::setGeometry):
(WebCore::GLPlatformSurface::destroy):
* platform/graphics/opengl/GLPlatformSurface.h: Added.
(WebCore):
(GLPlatformSurface):
    GLXOffScreenContext creates an off-screen context. This is used when
    renderstyle is RenderOffscreen.
    It uses GL extension GLX_ARB_create_context (when available)
    to create a context else falls back to use glXCreateNewContext.
* platform/graphics/surfaces/glx/GLXContext.cpp: Added.
(WebCore):
(WebCore::initializeARBExtensions):
(WebCore::GLXOffScreenContext::GLXOffScreenContext):
(WebCore::GLXOffScreenContext::initialize):
(WebCore::GLXOffScreenContext::~GLXOffScreenContext):
(WebCore::GLXOffScreenContext::isCurrentContext):
(WebCore::GLXOffScreenContext::platformMakeCurrent):
(WebCore::GLXOffScreenContext::platformReleaseCurrent):
(WebCore::GLXOffScreenContext::freeResources):
(WebCore::GLXOffScreenContext::destroy):
    GLXCurrentContextWrapper acts as a wrapper for current context.
    This is used when renderstyle is RenderToCurrentGLContext.
* platform/graphics/surfaces/glx/GLXContext.h: Added.
(WebCore):
(GLXCurrentContextWrapper):
(WebCore::GLXCurrentContextWrapper::GLXCurrentContextWrapper):
(WebCore::GLXCurrentContextWrapper::~GLXCurrentContextWrapper):
(GLXOffScreenContext):
* platform/graphics/surfaces/glx/GLXSurface.cpp: Added.
(WebCore):
(WebCore::GLXSurface::GLXSurface):
(WebCore::GLXSurface::~GLXSurface):
(WebCore::GLXSurface::visualInfo):
(WebCore::GLXSurface::xWindow):
(WebCore::GLXSurface::pBufferConfiguration):
(WebCore::GLXSurface::transportSurfaceConfiguration):
(WebCore::GLXSurface::isXRenderExtensionSupported):
    GLXTransportSurface creates Window and uses it as an off-screen surface.
    Any GLContext that was created with respect to configuration can be used
    to render into this.
    This is used when contents of the buffer are to be provided to UI Process
    for display.
(WebCore::GLXTransportSurface::GLXTransportSurface):
(WebCore::GLXTransportSurface::~GLXTransportSurface):
(WebCore::GLXTransportSurface::configuration):
(WebCore::GLXTransportSurface::swapBuffers):
(WebCore::GLXTransportSurface::setGeometry):
(WebCore::GLXTransportSurface::initialize):
(WebCore::GLXTransportSurface::destroy):
(WebCore::GLXTransportSurface::freeResources):
   GLXPBuffer, Creates a GL surface (PBuffer) used for offscreen rendering.
   Any GLContext that was created with respect to configuration can be used
   to render into this.
(WebCore::GLXPBuffer::GLXPBuffer):
(WebCore::GLXPBuffer::~GLXPBuffer):
(WebCore::GLXPBuffer::initialize):
(WebCore::GLXPBuffer::configuration):
(WebCore::GLXPBuffer::destroy):
(WebCore::GLXPBuffer::freeResources):
* platform/graphics/surfaces/glx/GLXSurface.h: Added.
(WebCore):
    Creates X resources which are shared between surface and context.
(SharedX11Resources):
(WebCore::SharedX11Resources::create):
(WebCore::SharedX11Resources::deref):
(WebCore::SharedX11Resources::getXWindow):
(WebCore::SharedX11Resources::display):
(WebCore::SharedX11Resources::visualInfo):
(WebCore::SharedX11Resources::createConfig):
(WebCore::SharedX11Resources::pBufferContextConfig):
(WebCore::SharedX11Resources::surfaceContextConfig):
(WebCore::SharedX11Resources::isXRenderExtensionSupported):
(WebCore::SharedX11Resources::SharedX11Resources):
(WebCore::SharedX11Resources::~SharedX11Resources):
(GLXSurface):
(GLXTransportSurface):
(GLXPBuffer):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@135468 268f45cc-cd09-0410-ab3c-d52691b4dbfc

14 files changed:
Source/WebCore/ChangeLog
Source/WebCore/PlatformEfl.cmake
Source/WebCore/platform/graphics/efl/GraphicsContext3DEfl.cpp
Source/WebCore/platform/graphics/efl/GraphicsContext3DPrivate.cpp
Source/WebCore/platform/graphics/efl/GraphicsContext3DPrivate.h
Source/WebCore/platform/graphics/opengl/GLDefs.h [new file with mode: 0644]
Source/WebCore/platform/graphics/opengl/GLPlatformContext.cpp [new file with mode: 0644]
Source/WebCore/platform/graphics/opengl/GLPlatformContext.h [new file with mode: 0644]
Source/WebCore/platform/graphics/opengl/GLPlatformSurface.cpp [new file with mode: 0644]
Source/WebCore/platform/graphics/opengl/GLPlatformSurface.h [new file with mode: 0644]
Source/WebCore/platform/graphics/surfaces/glx/GLXContext.cpp [new file with mode: 0644]
Source/WebCore/platform/graphics/surfaces/glx/GLXContext.h [new file with mode: 0644]
Source/WebCore/platform/graphics/surfaces/glx/GLXSurface.cpp [new file with mode: 0644]
Source/WebCore/platform/graphics/surfaces/glx/GLXSurface.h [new file with mode: 0644]

index 4658ddd..fc2f169 100644 (file)
@@ -1,3 +1,172 @@
+2012-11-21  Kondapally Kalyan  <kalyan.kondapally@intel.com>
+
+        [EFL] Refactor GraphicsContext3DEFL.
+        https://bugs.webkit.org/show_bug.cgi?id=101291.
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        GraphicsContext3DEfl creates GraphicsContext3DPrivate, which acts as its platform Layer.
+        GraphicsContext3DPrivate needs to handle the following cases:
+        1) To provide an off-screen buffer for accelerated composition.
+        2) Render to a current context.
+        3) To render directly to host window. (currently not supported.)
+
+        Before this patch Evas was used to provide us an off-screen context and buffer. GLX was used in
+        the other supported case. Evas acts as a glue layer to provide us with appropriate
+        GL bindings (OpenGL functions), GL context and drawable (surface/offscreenbuffer).
+        However, primitive rendering is handled by TextureMapper and OpenGLShims is used to load the needed GL functions.
+
+        It would be for our advantage to be able to take in to use any optimisations/extensions
+        provided by underlying drivers, specific to a platform (e.g. GLX_MESA_copy_sub_buffer etc.).
+        This patch introduces an abstraction layer to make it easy to add support for any GL backend (GLX, EGL etc.)
+        and do any platform specific optimizations as needed without complicating GraphicsContext3DPrivate class.
+        Two new classes are added with this implementation, GLPlatformContext and GLPlatformSurface.
+        GraphicsContext3DPrivate would create and own a GLPlatformContext and GLPlatformSurface.
+
+        GLPlatformContext encapsulates an OpenGL context hiding any platform specific management.
+        It uses GL extension ARB_robustness (when available) to detect driver resets.
+        It defines a simple interface for things that need to be handled by the context. Support
+        for multi-threaded usage and shared context-group would be added later.
+
+        GLPlatformSurface encapsulates an OpenGL drawable hiding any platform specific management.
+        It defines a simple interface for things that need to be handled by the surface.
+        It creates an off-screen rendering area. Any GLPlatformContext (compatible with the surface)
+        can be used to render into this off-screen area.
+
+        This patch also adds GLX implementation. To keep the patch to minimum EGL support would be added in another changeset.
+
+        * PlatformEfl.cmake:
+        * platform/graphics/efl/GraphicsContext3DEfl.cpp:
+        (WebCore::GraphicsContext3D::create):
+        (WebCore::GraphicsContext3D::GraphicsContext3D):
+        (WebCore::GraphicsContext3D::~GraphicsContext3D):
+        (WebCore::GraphicsContext3D::makeContextCurrent):
+        (WebCore::GraphicsContext3D::setContextLostCallback):
+        * platform/graphics/efl/GraphicsContext3DPrivate.cpp:
+        (WebCore::GraphicsContext3DPrivate::GraphicsContext3DPrivate):
+        (GraphicsContext3DPrivate::~GraphicsContext3DPrivate):
+        (GraphicsContext3DPrivate::releaseResources):
+        (GraphicsContext3DPrivate::setContextLostCallback):
+        (GraphicsContext3DPrivate::platformGraphicsContext3D):
+        (GraphicsContext3DPrivate::makeContextCurrent):
+        (GraphicsContext3DPrivate::createGraphicsSurfaces):
+        (GraphicsContext3DPrivate::copyToGraphicsSurface):
+        (GraphicsContext3DPrivate::graphicsSurfaceToken):
+        * platform/graphics/efl/GraphicsContext3DPrivate.h:
+        (GraphicsContext3DPrivate):
+        * platform/graphics/opengl/GLDefs.h: Added.
+        (WebCore):
+        * platform/graphics/opengl/GLPlatformContext.cpp: Added.
+        (WebCore):
+        (WebCore::GLPlatformContext::createContext):
+        (WebCore::GLPlatformContext::createOffScreenContext):
+        (WebCore::GLPlatformContext::createCurrentContextWrapper):
+        (WebCore::GLPlatformContext::GLPlatformContext):
+        (WebCore::GLPlatformContext::~GLPlatformContext):
+        (WebCore::GLPlatformContext::makeCurrent):
+        (WebCore::GLPlatformContext::isValid):
+        (WebCore::GLPlatformContext::releaseCurrent):
+        (WebCore::GLPlatformContext::handle):
+        (WebCore::GLPlatformContext::isCurrentContext):
+        (WebCore::GLPlatformContext::initialize):
+        (WebCore::GLPlatformContext::getCurrent):
+        (WebCore::GLPlatformContext::platformMakeCurrent):
+        (WebCore::GLPlatformContext::platformReleaseCurrent):
+        (WebCore::GLPlatformContext::destroy):
+        * platform/graphics/opengl/GLPlatformContext.h: Added.
+        (WebCore):
+        (GLPlatformContext):
+        * platform/graphics/opengl/GLPlatformSurface.cpp: Added.
+        (WebCore):
+        (WebCore::GLPlatformSurface::createOffscreenSurface):
+        (WebCore::GLPlatformSurface::createTransportSurface):
+        (WebCore::GLPlatformSurface::GLPlatformSurface):
+        (WebCore::GLPlatformSurface::~GLPlatformSurface):
+        (WebCore::GLPlatformSurface::handle):
+        (WebCore::GLPlatformSurface::geometry):
+        (WebCore::GLPlatformSurface::sharedDisplay):
+        (WebCore::GLPlatformSurface::configuration):
+        (WebCore::GLPlatformSurface::swapBuffers):
+        (WebCore::GLPlatformSurface::copyTexture):
+        (WebCore::GLPlatformSurface::updateContents):
+        (WebCore::GLPlatformSurface::setGeometry):
+        (WebCore::GLPlatformSurface::destroy):
+        * platform/graphics/opengl/GLPlatformSurface.h: Added.
+        (WebCore):
+        (GLPlatformSurface):
+            GLXOffScreenContext creates an off-screen context. This is used when
+            renderstyle is RenderOffscreen.
+            It uses GL extension GLX_ARB_create_context (when available)
+            to create a context else falls back to use glXCreateNewContext.
+        * platform/graphics/surfaces/glx/GLXContext.cpp: Added.
+        (WebCore):
+        (WebCore::initializeARBExtensions):
+        (WebCore::GLXOffScreenContext::GLXOffScreenContext):
+        (WebCore::GLXOffScreenContext::initialize):
+        (WebCore::GLXOffScreenContext::~GLXOffScreenContext):
+        (WebCore::GLXOffScreenContext::isCurrentContext):
+        (WebCore::GLXOffScreenContext::platformMakeCurrent):
+        (WebCore::GLXOffScreenContext::platformReleaseCurrent):
+        (WebCore::GLXOffScreenContext::freeResources):
+        (WebCore::GLXOffScreenContext::destroy):
+            GLXCurrentContextWrapper acts as a wrapper for current context.
+            This is used when renderstyle is RenderToCurrentGLContext.
+        * platform/graphics/surfaces/glx/GLXContext.h: Added.
+        (WebCore):
+        (GLXCurrentContextWrapper):
+        (WebCore::GLXCurrentContextWrapper::GLXCurrentContextWrapper):
+        (WebCore::GLXCurrentContextWrapper::~GLXCurrentContextWrapper):
+        (GLXOffScreenContext):
+        * platform/graphics/surfaces/glx/GLXSurface.cpp: Added.
+        (WebCore):
+        (WebCore::GLXSurface::GLXSurface):
+        (WebCore::GLXSurface::~GLXSurface):
+        (WebCore::GLXSurface::visualInfo):
+        (WebCore::GLXSurface::xWindow):
+        (WebCore::GLXSurface::pBufferConfiguration):
+        (WebCore::GLXSurface::transportSurfaceConfiguration):
+        (WebCore::GLXSurface::isXRenderExtensionSupported):
+            GLXTransportSurface creates Window and uses it as an off-screen surface.
+            Any GLContext that was created with respect to configuration can be used
+            to render into this.
+            This is used when contents of the buffer are to be provided to UI Process
+            for display.
+        (WebCore::GLXTransportSurface::GLXTransportSurface):
+        (WebCore::GLXTransportSurface::~GLXTransportSurface):
+        (WebCore::GLXTransportSurface::configuration):
+        (WebCore::GLXTransportSurface::swapBuffers):
+        (WebCore::GLXTransportSurface::setGeometry):
+        (WebCore::GLXTransportSurface::initialize):
+        (WebCore::GLXTransportSurface::destroy):
+        (WebCore::GLXTransportSurface::freeResources):
+           GLXPBuffer, Creates a GL surface (PBuffer) used for offscreen rendering.
+           Any GLContext that was created with respect to configuration can be used
+           to render into this.
+        (WebCore::GLXPBuffer::GLXPBuffer):
+        (WebCore::GLXPBuffer::~GLXPBuffer):
+        (WebCore::GLXPBuffer::initialize):
+        (WebCore::GLXPBuffer::configuration):
+        (WebCore::GLXPBuffer::destroy):
+        (WebCore::GLXPBuffer::freeResources):
+        * platform/graphics/surfaces/glx/GLXSurface.h: Added.
+        (WebCore):
+            Creates X resources which are shared between surface and context.
+        (SharedX11Resources):
+        (WebCore::SharedX11Resources::create):
+        (WebCore::SharedX11Resources::deref):
+        (WebCore::SharedX11Resources::getXWindow):
+        (WebCore::SharedX11Resources::display):
+        (WebCore::SharedX11Resources::visualInfo):
+        (WebCore::SharedX11Resources::createConfig):
+        (WebCore::SharedX11Resources::pBufferContextConfig):
+        (WebCore::SharedX11Resources::surfaceContextConfig):
+        (WebCore::SharedX11Resources::isXRenderExtensionSupported):
+        (WebCore::SharedX11Resources::SharedX11Resources):
+        (WebCore::SharedX11Resources::~SharedX11Resources):
+        (GLXSurface):
+        (GLXTransportSurface):
+        (GLXPBuffer):
+
 2012-11-21  Andreas Kling  <akling@apple.com>
 
         Re-virtualize CSSRule.
index ca92710..662be5a 100644 (file)
@@ -259,6 +259,7 @@ IF (WTF_USE_3D_GRAPHICS)
   LIST(APPEND WebCore_INCLUDE_DIRECTORIES
     "${WEBCORE_DIR}/platform/graphics/opengl"
     "${WEBCORE_DIR}/platform/graphics/surfaces"
+    "${WEBCORE_DIR}/platform/graphics/surfaces/glx"
     "${WEBCORE_DIR}/platform/graphics/texmap"
   )
   LIST(APPEND WebCore_SOURCES
@@ -268,9 +269,13 @@ IF (WTF_USE_3D_GRAPHICS)
     platform/graphics/efl/GraphicsContext3DPrivate.cpp
     platform/graphics/opengl/Extensions3DOpenGL.cpp
     platform/graphics/opengl/Extensions3DOpenGLCommon.cpp
+    platform/graphics/opengl/GLPlatformContext.cpp
+    platform/graphics/opengl/GLPlatformSurface.cpp
     platform/graphics/opengl/GraphicsContext3DOpenGL.cpp
     platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp
     platform/graphics/surfaces/GraphicsSurface.cpp
+    platform/graphics/surfaces/glx/GLXSurface.cpp
+    platform/graphics/surfaces/glx/GLXContext.cpp
     platform/graphics/surfaces/qt/GraphicsSurfaceGLX.cpp
     platform/graphics/texmap/TextureMapperGL.cpp
     platform/graphics/texmap/TextureMapperShaderManager.cpp
index d139130..2e2a493 100644 (file)
@@ -1,5 +1,6 @@
 /*
     Copyright (C) 2012 Samsung Electronics
+    Copyright (C) 2012 Intel Corporation.
 
     This library is free software; you can redistribute it and/or
     modify it under the terms of the GNU Library General Public
@@ -27,7 +28,6 @@
 #include "NotImplemented.h"
 #include "OpenGLShims.h"
 #include "PlatformContextCairo.h"
-#include <GL/glx.h>
 
 #if USE(OPENGL_ES_2)
 #include "Extensions3DOpenGLES.h"
@@ -39,6 +39,9 @@ namespace WebCore {
 
 PassRefPtr<GraphicsContext3D> GraphicsContext3D::create(GraphicsContext3D::Attributes attrs, HostWindow* hostWindow, RenderStyle renderStyle)
 {
+    if (renderStyle == RenderDirectlyToHostWindow)
+        return 0;
+
     RefPtr<GraphicsContext3D> context = adoptRef(new GraphicsContext3D(attrs, hostWindow, renderStyle));
     return context->m_private ? context.release() : 0;
 }
@@ -67,29 +70,12 @@ GraphicsContext3D::GraphicsContext3D(GraphicsContext3D::Attributes attrs, HostWi
     , m_multisampleColorBuffer(0)
     , m_private(adoptPtr(new GraphicsContext3DPrivate(this, hostWindow, renderStyle)))
 {
-    validateAttributes();
-
-    if (!m_private)
-        return;
-
-    static bool initializedShims = false;
-    static bool success = true;
-    if (!initializedShims) {
-        success = initializeOpenGLShims();
-        initializedShims = true;
-    }
-    if (!success) {
+    if (!m_private || !m_private->m_platformContext) {
         m_private = nullptr;
         return;
     }
 
-    if (renderStyle == RenderToCurrentGLContext) {
-        // Evas doesn't allow including gl headers and Evas_GL headers at the same time,
-        // so we need to query the current gl context/surface here instead of in GraphicsContext3DPrivate.
-        void* currentContext = (void*)glXGetCurrentContext();
-        void* currentSurface = (void*)glXGetCurrentDrawable();
-        m_private->setCurrentGLContext(currentContext, currentSurface);
-    }
+    validateAttributes();
 
     if (renderStyle == RenderOffscreen) {
         // Create buffers for the canvas FBO.
@@ -147,14 +133,19 @@ GraphicsContext3D::GraphicsContext3D(GraphicsContext3D::Attributes attrs, HostWi
     glEnable(GL_POINT_SPRITE);
     glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
 #endif
+    glClearColor(0.0, 0.0, 0.0, 0.0);
 }
 
 GraphicsContext3D::~GraphicsContext3D()
 {
-    if (m_renderStyle == RenderToCurrentGLContext || !m_private)
+    if (!m_private || !makeContextCurrent())
         return;
 
-    makeContextCurrent();
+    if (!m_fbo) {
+        m_private->releaseResources();
+        return;
+    }
+
     glDeleteTextures(1, &m_texture);
 
     if (m_attrs.antialias) {
@@ -165,7 +156,6 @@ GraphicsContext3D::~GraphicsContext3D()
 
         glDeleteFramebuffers(1, &m_multisampleFBO);
     } else if (m_attrs.stencil || m_attrs.depth) {
-
 #if USE(OPENGL_ES_2)
         if (m_attrs.depth)
             glDeleteRenderbuffers(1, &m_depthBuffer);
@@ -175,7 +165,9 @@ GraphicsContext3D::~GraphicsContext3D()
 #endif
         glDeleteRenderbuffers(1, &m_depthStencilBuffer);
     }
+
     glDeleteFramebuffers(1, &m_fbo);
+    m_private->releaseResources();
 }
 
 PlatformGraphicsContext3D GraphicsContext3D::platformGraphicsContext3D()
@@ -197,12 +189,6 @@ PlatformLayer* GraphicsContext3D::platformLayer() const
 
 bool GraphicsContext3D::makeContextCurrent()
 {
-    if (!m_private)
-        return false;
-
-    if (m_renderStyle == RenderToCurrentGLContext)
-        return true;
-
     return m_private->makeContextCurrent();
 }
 
@@ -215,9 +201,9 @@ bool GraphicsContext3D::isGLES2Compliant() const
 #endif
 }
 
-void GraphicsContext3D::setContextLostCallback(PassOwnPtr<ContextLostCallback>
+void GraphicsContext3D::setContextLostCallback(PassOwnPtr<ContextLostCallback> callBack)
 {
-    notImplemented();
+    m_private->setContextLostCallback(callBack);
 }
 
 void GraphicsContext3D::setErrorMessageCallback(PassOwnPtr<ErrorMessageCallback>) 
index 62d0a6e..c9fc4a0 100644 (file)
@@ -1,5 +1,6 @@
 /*
     Copyright (C) 2012 Samsung Electronics
+    Copyright (C) 2012 Intel Corporation.
 
     This library is free software; you can redistribute it and/or
     modify it under the terms of the GNU Library General Public
 */
 
 #include "config.h"
+#include "GraphicsContext3DPrivate.h"
 
 #if USE(3D_GRAPHICS) || USE(ACCELERATED_COMPOSITING)
-#include "GraphicsContext3DPrivate.h"
 
-#include "GraphicsContext.h"
 #include "HostWindow.h"
 #include "NotImplemented.h"
 #include "PlatformContextCairo.h"
-#include <Ecore_Evas.h>
-#include <Evas_GL.h>
-#include <wtf/OwnArrayPtr.h>
-#include <wtf/text/CString.h>
+
+#if USE(OPENGL_ES_2)
+#include <GLES2/gl2.h>
+#include <GLES2/gl2ext.h>
+#else
+#include "OpenGLShims.h"
+#endif
 
 namespace WebCore {
 
 GraphicsContext3DPrivate::GraphicsContext3DPrivate(GraphicsContext3D* context, HostWindow* hostWindow, GraphicsContext3D::RenderStyle renderStyle)
     : m_context(context)
     , m_hostWindow(hostWindow)
-    , m_evasGL(0)
-    , m_evasGLContext(0)
-    , m_evasGLSurface(0)
-    , m_glContext(0)
-    , m_glSurface(0)
-    , m_api(0)
-    , m_renderStyle(renderStyle)
+    , m_pendingSurfaceResize(false)
 {
-    if (renderStyle == GraphicsContext3D::RenderToCurrentGLContext)
-        return;
-
     if (m_hostWindow && m_hostWindow->platformPageClient()) {
         // FIXME: Implement this code path for WebKit1.
         // Get Evas object from platformPageClient and set EvasGL related members.
         return;
     }
 
-    // For WebKit2, we need to create a dummy ecoreEvas object for the WebProcess in order to use EvasGL APIs.
-#ifdef HAVE_ECORE_X
-    ecore_evas_init();
-    m_ecoreEvas = adoptPtr(ecore_evas_gl_x11_new(0, 0, 0, 0, 1, 1));
-    if (!m_ecoreEvas)
+    m_platformContext = GLPlatformContext::createContext(renderStyle);
+    if (!m_platformContext)
         return;
+
+    if (renderStyle == GraphicsContext3D::RenderOffscreen) {
+#if USE(GRAPHICS_SURFACE)
+        m_platformSurface = GLPlatformSurface::createTransportSurface();
 #else
-    return;
+        m_platformSurface = GLPlatformSurface::createOffscreenSurface();
 #endif
-
-    Evas* evas = ecore_evas_get(m_ecoreEvas.get());
-    if (!evas)
-        return;
-
-    // Create a new Evas_GL object for gl rendering on efl.
-    m_evasGL = evas_gl_new(evas);
-    if (!m_evasGL)
-        return;
-
-    // Get the API for rendering using OpenGL.
-    // This returns a structure that contains all the OpenGL functions we can use to render in Evas
-    m_api = evas_gl_api_get(m_evasGL);
-    if (!m_api)
-        return;
-
-    // Create a context
-    m_evasGLContext = evas_gl_context_create(m_evasGL, 0);
-    if (!m_evasGLContext)
-        return;
-
-    // Create a surface
-    if (!createSurface(0, renderStyle == GraphicsContext3D::RenderDirectlyToHostWindow))
-        return;
-
-    makeContextCurrent();
-
+        if (!m_platformSurface) {
+            m_platformContext = nullptr;
+            return;
+        }
+
+        if (!m_platformContext->initialize(m_platformSurface.get()) || !m_platformContext->makeCurrent(m_platformSurface.get())) {
+            releaseResources();
+            m_platformContext = nullptr;
+            m_platformSurface = nullptr;
 #if USE(GRAPHICS_SURFACE)
-    IntSize surfaceSize(m_context->m_currentWidth, m_context->m_currentHeight);
-    m_surfaceFlags = GraphicsSurface::SupportsTextureTarget | GraphicsSurface::SupportsSharing;
-    if (!surfaceSize.isEmpty())
-        m_graphicsSurface = GraphicsSurface::create(surfaceSize, m_surfaceFlags);
+        } else
+            m_surfaceHandle = GraphicsSurfaceToken(m_platformSurface->handle());
+#else
+        }
 #endif
+    }
 }
 
 GraphicsContext3DPrivate::~GraphicsContext3DPrivate()
 {
-    if (!m_evasGL)
-        return;
-
-    if (m_evasGLSurface)
-        evas_gl_surface_destroy(m_evasGL, m_evasGLSurface);
+}
 
-    if (m_evasGLContext)
-        evas_gl_context_destroy(m_evasGL, m_evasGLContext);
+void GraphicsContext3DPrivate::releaseResources()
+{
+    // Release the current context and drawable only after destroying any associated gl resources.
+    if (m_platformContext)
+        m_platformContext->destroy();
 
-    evas_gl_free(m_evasGL);
+    if (m_platformSurface)
+        m_platformSurface->destroy();
 
-#if USE(GRAPHICS_SURFACE)
-    m_graphicsSurface.clear();
-#endif
+    if (m_platformContext)
+        m_platformContext->releaseCurrent();
 }
 
-bool GraphicsContext3DPrivate::createSurface(PageClientEfl* pageClient, bool renderDirectlyToHostWindow)
+bool GraphicsContext3DPrivate::createSurface(PageClientEfl*, bool)
 {
-    // If RenderStyle is RenderOffscreen, we will be rendering to a FBO,
-    // so Evas_GL_Surface has a 1x1 dummy surface.
-    int width = 1;
-    int height = 1;
-
-    // But, in case of RenderDirectlyToHostWindow, we have to render to a render target surface with the same size as our webView.
-    if (renderDirectlyToHostWindow) {
-        if (!pageClient)
-            return false;
-        // FIXME: Get geometry of webView and set size of target surface.
-    }
-
-    Evas_GL_Config config = {
-        EVAS_GL_RGBA_8888,
-        EVAS_GL_DEPTH_BIT_8,
-        EVAS_GL_STENCIL_NONE, // FIXME: set EVAS_GL_STENCIL_BIT_8 after fixing Evas_GL bug.
-        EVAS_GL_OPTIONS_NONE,
-        EVAS_GL_MULTISAMPLE_NONE
-    };
-
-    // Create a new Evas_GL_Surface object
-    m_evasGLSurface = evas_gl_surface_create(m_evasGL, &config, width, height);
-    if (!m_evasGLSurface)
-        return false;
-
-#if USE(ACCELERATED_COMPOSITING)
-    if (renderDirectlyToHostWindow) {
-        Evas_Native_Surface nativeSurface;
-        // Fill in the Native Surface information from the given Evas GL surface.
-        evas_gl_native_surface_get(m_evasGL, m_evasGLSurface, &nativeSurface);
-
-        // FIXME: Create and specially set up a evas_object which act as the render targer surface.
-    }
-#endif
-
-    return true;
+    notImplemented();
+    return false;
 }
 
-void GraphicsContext3DPrivate::setCurrentGLContext(void* context, void* surface)
+void GraphicsContext3DPrivate::setContextLostCallback(PassOwnPtr<GraphicsContext3D::ContextLostCallback> callBack)
 {
-    m_glContext = context;
-    m_glSurface = surface;
+    m_contextLostCallback = callBack;
 }
 
 PlatformGraphicsContext3D GraphicsContext3DPrivate::platformGraphicsContext3D() const
 {
-    if (m_renderStyle == GraphicsContext3D::RenderToCurrentGLContext)
-        return m_glContext;
-
-    return m_evasGLContext;
+    return m_platformContext->handle();
 }
 
 bool GraphicsContext3DPrivate::makeContextCurrent()
 {
-    return evas_gl_make_current(m_evasGL, m_evasGLSurface, m_evasGLContext);
+    bool success = m_platformContext->makeCurrent(m_platformSurface.get());
+
+    if (!m_platformContext->isValid()) {
+        // FIXME: Restore context
+        if (m_contextLostCallback)
+            m_contextLostCallback->onContextLost();
+
+        success = false;
+    }
+
+    return success;
 }
 
 #if USE(TEXTURE_MAPPER_GL)
@@ -182,27 +131,36 @@ void GraphicsContext3DPrivate::paintToTextureMapper(TextureMapper*, const FloatR
 #endif
 
 #if USE(GRAPHICS_SURFACE)
-void GraphicsContext3DPrivate::createGraphicsSurfaces(const IntSize& size)
+void GraphicsContext3DPrivate::createGraphicsSurfaces(const IntSize&)
 {
-    if (size.isEmpty())
-        m_graphicsSurface.clear();
-    else
-        m_graphicsSurface = GraphicsSurface::create(size, m_surfaceFlags);
+    m_pendingSurfaceResize = true;
 }
 
 uint32_t GraphicsContext3DPrivate::copyToGraphicsSurface()
 {
-    if (!m_graphicsSurface)
+    if (!m_platformContext || !makeContextCurrent())
         return 0;
 
-    makeContextCurrent();
-    m_graphicsSurface->copyFromTexture(m_context->m_texture, IntRect(0, 0, m_context->m_currentWidth, m_context->m_currentHeight));
-    return m_graphicsSurface->swapBuffers();
+    if (m_pendingSurfaceResize) {
+        m_pendingSurfaceResize = false;
+        m_platformSurface->setGeometry(IntRect(0, 0, m_context->m_currentWidth, m_context->m_currentHeight));
+    }
+
+    if (m_context->m_attrs.antialias) {
+#if !USE(OPENGL_ES_2)
+        glBindFramebuffer(GL_READ_FRAMEBUFFER_EXT, m_context->m_multisampleFBO);
+        glBindFramebuffer(GL_DRAW_FRAMEBUFFER_EXT, m_context->m_fbo);
+        glBlitFramebuffer(0, 0, m_context->m_currentWidth, m_context->m_currentHeight, 0, 0, m_context->m_currentWidth, m_context->m_currentHeight, GL_COLOR_BUFFER_BIT, GL_LINEAR);
+#endif
+    }
+
+    m_platformSurface->updateContents(m_context->m_texture, IntRect(0, 0, m_context->m_currentWidth, m_context->m_currentHeight), m_context->m_boundFBO);
+    return 0;
 }
 
 GraphicsSurfaceToken GraphicsContext3DPrivate::graphicsSurfaceToken() const
 {
-    return m_graphicsSurface->exportToken();
+    return m_surfaceHandle;
 }
 #endif
 
index 1ae4351..3d60b4e 100644 (file)
@@ -1,5 +1,6 @@
 /*
     Copyright (C) 2012 Samsung Electronics
+    Copyright (C) 2012 Intel Corporation.
 
     This library is free software; you can redistribute it and/or
     modify it under the terms of the GNU Library General Public
 #ifndef GraphicsContext3DPrivate_h
 #define GraphicsContext3DPrivate_h
 
+#if USE(3D_GRAPHICS) || USE(ACCELERATED_COMPOSITING)
+
 #include "GraphicsContext3D.h"
 
 #if USE(TEXTURE_MAPPER_GL)
 #include <texmap/TextureMapperPlatformLayer.h>
 #endif
 
-#if USE(GRAPHICS_SURFACE)
-#include "GraphicsSurface.h"
-#endif
-
-typedef struct _Evas_GL               Evas_GL;
-typedef struct _Evas_GL_Surface       Evas_GL_Surface;
-typedef struct _Evas_GL_Context       Evas_GL_Context;
-typedef struct _Evas_GL_Config        Evas_GL_Config;
-typedef struct _Evas_GL_API           Evas_GL_API;
+#include "GLPlatformContext.h"
+#include <wtf/PassOwnPtr.h>
 
 class PageClientEfl;
 
@@ -48,8 +44,9 @@ public:
     GraphicsContext3DPrivate(GraphicsContext3D*, HostWindow*, GraphicsContext3D::RenderStyle);
     ~GraphicsContext3DPrivate();
 
+    bool createSurface(PageClientEfl*, bool);
     PlatformGraphicsContext3D platformGraphicsContext3D() const;
-
+    void setContextLostCallback(PassOwnPtr<GraphicsContext3D::ContextLostCallback>  callBack);
 #if USE(ACCELERATED_COMPOSITING)
     PlatformLayer* platformLayer() const;
 #endif
@@ -61,31 +58,23 @@ public:
     virtual GraphicsSurfaceToken graphicsSurfaceToken() const;
     void createGraphicsSurfaces(const IntSize&);
 #endif
-
     bool makeContextCurrent();
-    bool createSurface(PageClientEfl*, bool renderDirectlyToEvasGLObject);
-    void setCurrentGLContext(void*, void*);
-
+    void releaseResources();
     GraphicsContext3D::Attributes m_attributes;
     GraphicsContext3D* m_context;
     HostWindow* m_hostWindow;
+    OwnPtr<GLPlatformContext> m_platformContext;
+    OwnPtr<GLPlatformSurface> m_platformSurface;
 #if USE(GRAPHICS_SURFACE)
-    GraphicsSurface::Flags m_surfaceFlags;
-    RefPtr<GraphicsSurface> m_graphicsSurface;
+    GraphicsSurfaceToken m_surfaceHandle;
 #endif
-
+    OwnPtr<GraphicsContext3D::ContextLostCallback> m_contextLostCallback;
     ListHashSet<GC3Denum> m_syntheticErrors;
-
-    OwnPtr<Ecore_Evas> m_ecoreEvas;
-    Evas_GL* m_evasGL;
-    Evas_GL_Context* m_evasGLContext;
-    Evas_GL_Surface* m_evasGLSurface;
-    void* m_glContext;
-    void* m_glSurface;
-    Evas_GL_API* m_api;
-    GraphicsContext3D::RenderStyle m_renderStyle;
+    bool m_pendingSurfaceResize;
 };
 
 } // namespace WebCore
 
-#endif // GraphicsLayerEfl_h
+#endif
+
+#endif
diff --git a/Source/WebCore/platform/graphics/opengl/GLDefs.h b/Source/WebCore/platform/graphics/opengl/GLDefs.h
new file mode 100644 (file)
index 0000000..6e36a11
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2012 Intel Corporation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef GLDefs_h
+#define GLDefs_h
+
+#if USE(ACCELERATED_COMPOSITING)
+
+#if USE(OPENGL_ES_2)
+#include "Extensions3DOpenGLES.h"
+#else
+#include "Extensions3DOpenGL.h"
+#endif
+
+#include "OpenGLShims.h"
+
+#include <GL/gl.h>
+#include <GL/glext.h>
+#if HAVE(GLX)
+#include <GL/glx.h>
+#endif
+
+namespace WebCore {
+
+#if HAVE(GLX)
+typedef GLXContext PlatformContext;
+typedef Display* PlatformDisplay;
+typedef GLXFBConfig PlatformSurfaceConfig;
+typedef GLXDrawable PlatformSurface;
+#else
+typedef void* PlatformContext;
+typedef void* PlatformDisplay;
+typedef void* PlatformSurfaceConfig;
+typedef void* PlatformSurface;
+#endif
+
+}
+
+#endif
+
+#endif
diff --git a/Source/WebCore/platform/graphics/opengl/GLPlatformContext.cpp b/Source/WebCore/platform/graphics/opengl/GLPlatformContext.cpp
new file mode 100644 (file)
index 0000000..17b3084
--- /dev/null
@@ -0,0 +1,196 @@
+/*
+ * Copyright (C) 2012 Intel Corporation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "GLPlatformContext.h"
+
+#if USE(ACCELERATED_COMPOSITING)
+
+#if HAVE(GLX)
+#include "GLXContext.h"
+#endif
+
+#include "NotImplemented.h"
+
+namespace WebCore {
+
+static PFNGLGETGRAPHICSRESETSTATUSARBPROC glGetGraphicsResetStatusARB = 0;
+static GLPlatformContext* m_currentContext = 0;
+
+PassOwnPtr<GLPlatformContext> GLPlatformContext::createContext(GraphicsContext3D::RenderStyle renderStyle)
+{
+    static bool initializedShims = false;
+
+    if (!initializedShims) {
+        initializedShims = initializeOpenGLShims();
+#if HAVE(GLX)
+        glGetGraphicsResetStatusARB = reinterpret_cast<PFNGLGETGRAPHICSRESETSTATUSARBPROC>(glXGetProcAddressARB(reinterpret_cast<const GLubyte*>("glGetGraphicsResetStatusARB")));
+#endif
+    }
+
+    if (!initializedShims)
+        return nullptr;
+
+    switch (renderStyle) {
+    case GraphicsContext3D::RenderOffscreen:
+        if (OwnPtr<GLPlatformContext> glxContext = GLPlatformContext::createOffScreenContext())
+            return glxContext.release();
+        break;
+    case GraphicsContext3D::RenderToCurrentGLContext:
+        if (OwnPtr<GLPlatformContext> glxContext = GLPlatformContext::createCurrentContextWrapper())
+            return glxContext.release();
+        break;
+    case GraphicsContext3D::RenderDirectlyToHostWindow:
+        ASSERT_NOT_REACHED();
+        break;
+    }
+
+    return nullptr;
+}
+
+PassOwnPtr<GLPlatformContext> GLPlatformContext::createOffScreenContext()
+{
+#if HAVE(GLX)
+    OwnPtr<GLPlatformContext> glxContext = adoptPtr(new GLXOffScreenContext());
+    return glxContext.release();
+#endif
+
+    return nullptr;
+}
+
+PassOwnPtr<GLPlatformContext> GLPlatformContext::createCurrentContextWrapper()
+{
+#if HAVE(GLX)
+    OwnPtr<GLPlatformContext> glxContext = adoptPtr(new GLXCurrentContextWrapper());
+    return glxContext.release();
+#endif
+
+    return nullptr;
+}
+
+GLPlatformContext::GLPlatformContext()
+    : m_contextHandle(0)
+    , m_resetLostContext(false)
+{
+}
+
+GLPlatformContext::~GLPlatformContext()
+{
+    if (this == m_currentContext)
+        m_currentContext = 0;
+}
+
+bool GLPlatformContext::makeCurrent(GLPlatformSurface* surface)
+{
+    m_contextLost = false;
+
+    if (isCurrentContext())
+        return true;
+
+    m_currentContext = 0;
+
+    if (!surface || (surface && !surface->handle()))
+        platformReleaseCurrent();
+    else if (platformMakeCurrent(surface))
+        m_currentContext = this;
+
+    if (m_resetLostContext && glGetGraphicsResetStatusARB) {
+        GLenum status = glGetGraphicsResetStatusARB();
+
+        switch (status) {
+        case PLATFORMCONTEXT_NO_ERROR:
+            break;
+        case PLATFORMCONTEXT_GUILTY_CONTEXT_RESET:
+            m_contextLost = true;
+            break;
+        case PLATFORMCONTEXT_INNOCENT_CONTEXT_RESET:
+            break;
+        case PLATFORMCONTEXT_UNKNOWN_CONTEXT_RESET:
+            m_contextLost = true;
+            break;
+        default:
+            break;
+        }
+    }
+
+    return m_currentContext;
+}
+
+bool GLPlatformContext::isValid() const
+{
+    return !m_contextLost;
+}
+
+void GLPlatformContext::releaseCurrent()
+{
+    if (!isCurrentContext())
+        return;
+
+    m_currentContext = 0;
+    platformReleaseCurrent();
+}
+
+PlatformContext GLPlatformContext::handle() const
+{
+    return m_contextHandle;
+}
+
+bool GLPlatformContext::isCurrentContext() const
+{
+    return true;
+}
+
+bool GLPlatformContext::initialize(GLPlatformSurface*)
+{
+    return true;
+}
+
+GLPlatformContext* GLPlatformContext::getCurrent()
+{
+    return m_currentContext;
+}
+
+bool GLPlatformContext::platformMakeCurrent(GLPlatformSurface*)
+{
+    return true;
+}
+
+void GLPlatformContext::platformReleaseCurrent()
+{
+    notImplemented();
+}
+
+void GLPlatformContext::destroy()
+{
+    m_contextHandle = 0;
+    m_resetLostContext = false;
+
+    if (this == m_currentContext)
+        m_currentContext = 0;
+}
+
+} // namespace WebCore
+
+#endif
diff --git a/Source/WebCore/platform/graphics/opengl/GLPlatformContext.h b/Source/WebCore/platform/graphics/opengl/GLPlatformContext.h
new file mode 100644 (file)
index 0000000..1959b7b
--- /dev/null
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2012 Intel Corporation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef GLPlatformContext_h
+#define GLPlatformContext_h
+
+#if USE(ACCELERATED_COMPOSITING)
+
+#include "GLDefs.h"
+#include "GLPlatformSurface.h"
+#include <wtf/Noncopyable.h>
+#include <wtf/PassOwnPtr.h>
+
+// Encapsulates an OpenGL context, hiding platform specific management.
+namespace WebCore {
+
+class GLPlatformContext {
+    WTF_MAKE_NONCOPYABLE(GLPlatformContext);
+
+public:
+    // From http://www.khronos.org/registry/gles/extensions/EXT/EXT_robustness.txt
+    enum PlatformContextReset {
+        PLATFORMCONTEXT_NO_ERROR = 0x0000,
+        PLATFORMCONTEXT_GUILTY_CONTEXT_RESET = 0x8253,
+        PLATFORMCONTEXT_INNOCENT_CONTEXT_RESET = 0x8254,
+        PLATFORMCONTEXT_UNKNOWN_CONTEXT_RESET = 0x8255,
+    };
+
+    static PassOwnPtr<GLPlatformContext> createContext(GraphicsContext3D::RenderStyle);
+
+    virtual ~GLPlatformContext();
+
+    virtual bool initialize(GLPlatformSurface*);
+
+    // Makes this and surface as current context and drawable.
+    // Calling this function with no surface is same as calling releaseCurrent.
+    // Does nothing if this is already current Context.
+    bool makeCurrent(GLPlatformSurface* = 0);
+
+    // Sets Current Context and Drawable as Null.
+    // Doesn't have any effect if this is not the current Context.
+    void releaseCurrent();
+
+    PlatformContext handle() const;
+
+    virtual bool isCurrentContext() const;
+
+    bool isValid() const;
+
+    // Destroys any GL resources associated with this context.
+    virtual void destroy();
+
+    static GLPlatformContext* getCurrent();
+
+protected:
+    GLPlatformContext();
+    virtual bool platformMakeCurrent(GLPlatformSurface*);
+    virtual void platformReleaseCurrent();
+    PlatformContext m_contextHandle;
+    bool m_resetLostContext;
+    bool m_contextLost;
+
+private:
+    static PassOwnPtr<GLPlatformContext> createOffScreenContext();
+    static PassOwnPtr<GLPlatformContext> createCurrentContextWrapper();
+};
+
+} // namespace WebCore
+
+#endif
+
+#endif // GLNativeContext_H
diff --git a/Source/WebCore/platform/graphics/opengl/GLPlatformSurface.cpp b/Source/WebCore/platform/graphics/opengl/GLPlatformSurface.cpp
new file mode 100644 (file)
index 0000000..8944dc0
--- /dev/null
@@ -0,0 +1,172 @@
+/*
+ * Copyright (C) 2012 Intel Corporation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "GLPlatformSurface.h"
+
+#if USE(ACCELERATED_COMPOSITING)
+
+#if HAVE(GLX)
+#include "GLXSurface.h"
+#endif
+
+#include "NotImplemented.h"
+
+namespace WebCore {
+
+PassOwnPtr<GLPlatformSurface> GLPlatformSurface::createOffscreenSurface()
+{
+#if HAVE(GLX)
+    OwnPtr<GLPlatformSurface> surface = adoptPtr(new GLXPBuffer());
+
+    if (surface->handle())
+        return surface.release();
+#endif
+
+    return nullptr;
+}
+
+PassOwnPtr<GLPlatformSurface> GLPlatformSurface::createTransportSurface()
+{
+#if HAVE(GLX)
+    OwnPtr<GLPlatformSurface> surface = adoptPtr(new GLXTransportSurface());
+
+    if (surface->handle())
+        return surface.release();
+#endif
+
+    return nullptr;
+}
+
+GLPlatformSurface::GLPlatformSurface()
+    : m_restoreNeeded(true)
+    , m_fboId(0)
+    , m_sharedDisplay(0)
+    , m_drawable(0)
+{
+}
+
+GLPlatformSurface::~GLPlatformSurface()
+{
+}
+
+PlatformSurface GLPlatformSurface::handle() const
+{
+    return m_drawable;
+}
+
+const IntRect& GLPlatformSurface::geometry() const
+{
+    return m_rect;
+}
+
+PlatformDisplay GLPlatformSurface::sharedDisplay() const
+{
+    return m_sharedDisplay;
+}
+
+PlatformSurfaceConfig GLPlatformSurface::configuration()
+{
+    return 0;
+}
+
+void GLPlatformSurface::swapBuffers()
+{
+    notImplemented();
+}
+
+void GLPlatformSurface::copyTexture(uint32_t texture, const IntRect& sourceRect)
+{
+    if (!m_fboId)
+        glGenFramebuffers(1, &m_fboId);
+
+    m_restoreNeeded = true;
+    int x = sourceRect.x();
+    int y = sourceRect.y();
+    int width = sourceRect.width();
+    int height = sourceRect.height();
+
+    glPushAttrib(GL_COLOR_BUFFER_BIT);
+
+    GLint previousFBO;
+    glGetIntegerv(GL_FRAMEBUFFER_BINDING, &previousFBO);
+
+    glBindFramebuffer(GL_READ_FRAMEBUFFER, m_fboId);
+
+    glBindTexture(GL_TEXTURE_2D, texture);
+    glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
+
+    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
+
+    glBlitFramebuffer(x, y, width, height, x, y, width, height, GL_COLOR_BUFFER_BIT, GL_LINEAR);
+
+    glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
+    glBindTexture(GL_TEXTURE_2D, 0);
+    glBindFramebuffer(GL_FRAMEBUFFER, previousFBO);
+
+    glPopAttrib();
+}
+
+void GLPlatformSurface::updateContents(uint32_t texture, const IntRect& sourceRect, const GLuint bindFboId)
+{
+    m_restoreNeeded = false;
+
+    if (!m_fboId)
+        glGenFramebuffers(1, &m_fboId);
+
+    int x = sourceRect.x();
+    int y = sourceRect.y();
+    int width = sourceRect.width();
+    int height = sourceRect.height();
+
+    glBindFramebuffer(GL_READ_FRAMEBUFFER, m_fboId);
+    glBindTexture(GL_TEXTURE_2D, texture);
+    glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
+    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
+    glBlitFramebuffer(x, y, width, height, x, y, width, height, GL_COLOR_BUFFER_BIT, GL_LINEAR);
+    swapBuffers();
+    glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
+    glBindTexture(GL_TEXTURE_2D, 0);
+    glBindFramebuffer(GL_FRAMEBUFFER, bindFboId);
+}
+
+void GLPlatformSurface::setGeometry(const IntRect& newRect)
+{
+    m_rect = newRect;
+}
+
+void GLPlatformSurface::destroy()
+{
+    m_rect = IntRect();
+
+    if (m_fboId)
+        glDeleteFramebuffers(1, &m_fboId);
+
+    m_fboId = 0;
+}
+
+}
+
+#endif
diff --git a/Source/WebCore/platform/graphics/opengl/GLPlatformSurface.h b/Source/WebCore/platform/graphics/opengl/GLPlatformSurface.h
new file mode 100644 (file)
index 0000000..f1066b7
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2012 Intel Corporation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef GLPlatformSurface_h
+#define GLPlatformSurface_h
+
+#if USE(ACCELERATED_COMPOSITING)
+
+#include "GLDefs.h"
+#include <wtf/Noncopyable.h>
+#include <wtf/PassOwnPtr.h>
+
+// Encapsulates a surface that can be rendered to with GL, hiding platform
+// specific management.
+namespace WebCore {
+
+class GLPlatformSurface {
+    WTF_MAKE_NONCOPYABLE(GLPlatformSurface);
+
+public:
+    // Creates a GL surface used for offscreen rendering.
+    static PassOwnPtr<GLPlatformSurface> createOffscreenSurface();
+
+    // Creates a GL surface used for offscreen rendering. The results can be transported
+    // to the UI process for display.
+    static PassOwnPtr<GLPlatformSurface> createTransportSurface();
+
+    virtual ~GLPlatformSurface();
+
+    const IntRect& geometry() const;
+
+    // Get the underlying platform specific surface handle.
+    PlatformSurface handle() const;
+
+    PlatformDisplay sharedDisplay() const;
+
+    virtual void swapBuffers();
+
+    virtual void copyTexture(uint32_t texture, const IntRect& sourceRect);
+
+    // Convenience Function to update surface backbuffer with texture contents and restore current FBO.
+    // Function does the following(in order):
+    // a)Blits texture contents to back buffer.
+    // b)Calls Swap Buffers.
+    // c)Sets current FBO as bindFboId.
+    virtual void updateContents(uint32_t texture, const IntRect& sourceRect, const GLuint bindFboId);
+
+    virtual void setGeometry(const IntRect& newRect);
+
+    virtual PlatformSurfaceConfig configuration();
+
+    virtual void destroy();
+
+protected:
+    GLPlatformSurface();
+    bool m_restoreNeeded;
+    IntRect m_rect;
+    GLuint m_fboId;
+    PlatformDisplay m_sharedDisplay;
+    PlatformSurface m_drawable;
+};
+
+}
+
+#endif
+
+#endif
diff --git a/Source/WebCore/platform/graphics/surfaces/glx/GLXContext.cpp b/Source/WebCore/platform/graphics/surfaces/glx/GLXContext.cpp
new file mode 100644 (file)
index 0000000..295f06c
--- /dev/null
@@ -0,0 +1,123 @@
+/*
+ * Copyright (C) 2012 Intel Corporation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "GLXContext.h"
+
+#if USE(ACCELERATED_COMPOSITING) && HAVE(GLX)
+
+namespace WebCore {
+
+typedef GLXContext (*GLXCREATECONTEXTATTRIBSARBPROC)(Display*, GLXFBConfig, GLXContext, Bool, const int*);
+static GLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB = 0;
+
+static int Attribs[] = {
+    GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB,
+    GLX_LOSE_CONTEXT_ON_RESET_ARB,
+    0 };
+
+static void initializeARBExtensions()
+{
+    static bool initialized = false;
+
+    if (initialized)
+        return;
+
+    initialized = true;
+    glXCreateContextAttribsARB = reinterpret_cast<GLXCREATECONTEXTATTRIBSARBPROC>(glXGetProcAddress(reinterpret_cast<const GLubyte*>("glXCreateContextAttribsARB")));
+}
+
+GLXOffScreenContext::GLXOffScreenContext()
+    : GLPlatformContext()
+    , m_display(0)
+{
+}
+
+bool GLXOffScreenContext::initialize(GLPlatformSurface* surface)
+{
+    if (!surface)
+        return false;
+
+    m_display = surface->sharedDisplay();
+    if (!m_display)
+        return false;
+
+    GLXFBConfig config = surface->configuration();
+
+    if (config) {
+        initializeARBExtensions();
+
+        if (glXCreateContextAttribsARB)
+            m_contextHandle = glXCreateContextAttribsARB(m_display, config, 0, true, Attribs);
+
+        if (m_contextHandle)
+            m_resetLostContext = true;
+        else
+            m_contextHandle = glXCreateNewContext(m_display, config, GLX_RGBA_TYPE, 0, true);
+
+        if (m_contextHandle)
+            return true;
+    }
+
+    return false;
+}
+
+GLXOffScreenContext::~GLXOffScreenContext()
+{
+}
+
+bool GLXOffScreenContext::isCurrentContext() const
+{
+    return m_contextHandle == glXGetCurrentContext();
+}
+
+bool GLXOffScreenContext::platformMakeCurrent(GLPlatformSurface* surface)
+{
+    return glXMakeCurrent(surface->sharedDisplay(), surface->handle(), m_contextHandle);
+}
+
+void GLXOffScreenContext::platformReleaseCurrent()
+{
+    glXMakeCurrent(m_display, 0, 0);
+}
+
+void GLXOffScreenContext::freeResources()
+{
+    if (m_contextHandle)
+        glXDestroyContext(m_display, m_contextHandle);
+
+    m_contextHandle = 0;
+    m_display = 0;
+}
+
+void GLXOffScreenContext::destroy()
+{
+    freeResources();
+    GLPlatformContext::destroy();
+}
+
+}
+
+#endif
diff --git a/Source/WebCore/platform/graphics/surfaces/glx/GLXContext.h b/Source/WebCore/platform/graphics/surfaces/glx/GLXContext.h
new file mode 100644 (file)
index 0000000..7cff8d5
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2012 Intel Corporation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef GLXContext_h
+#define GLXContext_h
+
+#if USE(ACCELERATED_COMPOSITING) && HAVE(GLX)
+
+#include "GLPlatformContext.h"
+
+namespace WebCore {
+
+class GLXCurrentContextWrapper : public GLPlatformContext {
+    WTF_MAKE_NONCOPYABLE(GLXCurrentContextWrapper);
+
+public:
+    GLXCurrentContextWrapper()
+        : GLPlatformContext()
+    {
+        m_contextHandle = glXGetCurrentContext();
+    }
+
+    virtual ~GLXCurrentContextWrapper() { }
+};
+
+class GLXOffScreenContext : public GLPlatformContext {
+    WTF_MAKE_NONCOPYABLE(GLXOffScreenContext);
+
+public:
+    GLXOffScreenContext();
+    virtual ~GLXOffScreenContext();
+    bool initialize(GLPlatformSurface*);
+    bool platformMakeCurrent(GLPlatformSurface*);
+    void platformReleaseCurrent();
+    void destroy();
+    bool isCurrentContext() const;
+
+private:
+    void freeResources();
+    Display* m_display;
+};
+
+}
+
+#endif // GLXCURRENTCONTEXWRAPPER_H
+
+#endif
diff --git a/Source/WebCore/platform/graphics/surfaces/glx/GLXSurface.cpp b/Source/WebCore/platform/graphics/surfaces/glx/GLXSurface.cpp
new file mode 100644 (file)
index 0000000..38f2c0b
--- /dev/null
@@ -0,0 +1,204 @@
+/*
+ * Copyright (C) 2012 Intel Corporation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "GLXSurface.h"
+
+#if USE(ACCELERATED_COMPOSITING) && HAVE(GLX)
+
+namespace WebCore {
+
+SharedX11Resources* SharedX11Resources::m_staticSharedResource = 0;
+
+static const int pbufferAttributes[] = { GLX_PBUFFER_WIDTH, 1, GLX_PBUFFER_HEIGHT, 1, 0 };
+
+GLXSurface::GLXSurface()
+    : GLPlatformSurface()
+{
+    m_sharedResources = SharedX11Resources::create();
+    m_sharedDisplay = m_sharedResources->display();
+}
+
+GLXSurface::~GLXSurface()
+{
+}
+
+XVisualInfo* GLXSurface::visualInfo()
+{
+    return m_sharedResources->visualInfo();
+}
+
+Window GLXSurface::xWindow()
+{
+    return m_sharedResources->getXWindow();
+}
+
+GLXFBConfig GLXSurface::pBufferConfiguration()
+{
+    return m_sharedResources->pBufferContextConfig();
+}
+
+GLXFBConfig GLXSurface::transportSurfaceConfiguration()
+{
+    return m_sharedResources->surfaceContextConfig();
+}
+
+bool GLXSurface::isXRenderExtensionSupported()
+{
+    return m_sharedResources->isXRenderExtensionSupported();
+}
+
+GLXTransportSurface::GLXTransportSurface()
+    : GLXSurface()
+{
+    initialize();
+}
+
+GLXTransportSurface::~GLXTransportSurface()
+{
+}
+
+PlatformSurfaceConfig GLXTransportSurface::configuration()
+{
+    return transportSurfaceConfiguration();
+}
+
+void GLXTransportSurface::swapBuffers()
+{
+    if (!m_drawable)
+        return;
+
+    if (m_restoreNeeded) {
+        GLint oldFBO;
+        glGetIntegerv(GL_FRAMEBUFFER_BINDING, &oldFBO);
+        glBindFramebuffer(GL_FRAMEBUFFER, 0);
+        glXSwapBuffers(sharedDisplay(), m_drawable);
+        glBindFramebuffer(GL_FRAMEBUFFER, oldFBO);
+    } else
+        glXSwapBuffers(sharedDisplay(), m_drawable);
+}
+
+void GLXTransportSurface::setGeometry(const IntRect& newRect)
+{
+    GLPlatformSurface::setGeometry(newRect);
+    int width = newRect.width();
+    int height = newRect.height();
+    XResizeWindow(sharedDisplay(), m_drawable, width, height);
+}
+
+void GLXTransportSurface::initialize()
+{
+    Display* display = sharedDisplay();
+    GLXFBConfig config = transportSurfaceConfiguration();
+    if (!config)
+        return;
+
+    XVisualInfo* visInfo = visualInfo();
+    if (!visInfo)
+        return;
+
+    Colormap cmap = XCreateColormap(display, xWindow(), visInfo->visual, AllocNone);
+    XSetWindowAttributes attribute;
+    attribute.background_pixel = WhitePixel(display, 0);
+    attribute.border_pixel = BlackPixel(display, 0);
+    attribute.colormap = cmap;
+    m_drawable = XCreateWindow(display, xWindow(), 0, 0, 1, 1, 0, visInfo->depth, InputOutput, visInfo->visual, CWBackPixel | CWBorderPixel | CWColormap, &attribute);
+    if (!m_drawable)
+        return;
+
+    XSetWindowBackgroundPixmap(display, m_drawable, 0);
+    XCompositeRedirectWindow(display, m_drawable, CompositeRedirectManual);
+
+    if (isXRenderExtensionSupported())
+        XMapWindow(display, m_drawable);
+}
+
+void GLXTransportSurface::destroy()
+{
+    freeResources();
+    GLPlatformSurface::destroy();
+}
+
+void GLXTransportSurface::freeResources()
+{
+    if (!m_drawable)
+        return;
+
+    GLPlatformSurface::destroy();
+    Display* display = sharedDisplay();
+    if (!display)
+        return;
+
+    XDestroyWindow(display, m_drawable);
+    m_drawable = 0;
+}
+
+GLXPBuffer::GLXPBuffer()
+    : GLXSurface()
+{
+    initialize();
+}
+
+GLXPBuffer::~GLXPBuffer()
+{
+}
+
+void GLXPBuffer::initialize()
+{
+    Display* display = sharedDisplay();
+    GLXFBConfig config = pBufferConfiguration();
+    if (!config)
+        return;
+
+    m_drawable = glXCreatePbuffer(display, config, pbufferAttributes);
+}
+
+PlatformSurfaceConfig GLXPBuffer::configuration()
+{
+    return pBufferConfiguration();
+}
+
+void GLXPBuffer::destroy()
+{
+    freeResources();
+}
+
+void GLXPBuffer::freeResources()
+{
+    if (!m_drawable)
+        return;
+
+    GLPlatformSurface::destroy();
+    Display* display = sharedDisplay();
+    if (!display)
+        return;
+
+    glXDestroyPbuffer(display, m_drawable);
+    m_drawable = 0;
+}
+
+}
+
+#endif
diff --git a/Source/WebCore/platform/graphics/surfaces/glx/GLXSurface.h b/Source/WebCore/platform/graphics/surfaces/glx/GLXSurface.h
new file mode 100644 (file)
index 0000000..dd71397
--- /dev/null
@@ -0,0 +1,288 @@
+/*
+ * Copyright (C) 2012 Intel Corporation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef GLXSurface_h
+#define GLXSurface_h
+
+#if USE(ACCELERATED_COMPOSITING) && HAVE(GLX)
+
+#include "GLPlatformSurface.h"
+
+#include <X11/extensions/Xcomposite.h>
+#include <X11/extensions/Xrender.h>
+#include <wtf/Noncopyable.h>
+
+namespace WebCore {
+
+class SharedX11Resources : public WTF::RefCountedBase {
+    WTF_MAKE_NONCOPYABLE(SharedX11Resources);
+
+public:
+    static PassRefPtr<SharedX11Resources> create()
+    {
+        if (!m_staticSharedResource)
+            m_staticSharedResource = new SharedX11Resources();
+        else
+            m_staticSharedResource->ref();
+
+        return adoptRef(m_staticSharedResource);
+    }
+
+    void deref()
+    {
+        if (derefBase()) {
+            m_staticSharedResource = 0;
+            delete this;
+        }
+    }
+
+    Window getXWindow()
+    {
+        if (!m_window) {
+            Display* dpy = display();
+            XSetWindowAttributes attributes;
+            attributes.override_redirect = true;
+            m_window = XCreateSimpleWindow(dpy, XDefaultRootWindow(dpy), -1, -1, 1, 1, 0, BlackPixel(dpy, 0), WhitePixel(dpy, 0));
+            // From http://tronche.com/gui/x/xlib/window/attributes/
+            XChangeWindowAttributes(dpy, m_window, CWOverrideRedirect, &attributes);
+            XMapWindow(dpy, m_window);
+        }
+
+        return m_window;
+    }
+
+    Display* display()
+    {
+        if (!m_display)
+            m_display = XOpenDisplay(0);
+
+        return m_display;
+    }
+
+    XVisualInfo* visualInfo()
+    {
+        if (!m_VisualInfo)
+            surfaceContextConfig();
+
+        return m_VisualInfo;
+    }
+
+    GLXFBConfig createConfig(const int attributes[])
+    {
+        int numReturned;
+        m_VisualInfo = 0;
+        GLXFBConfig* temp = glXChooseFBConfig(display(), DefaultScreen(display()), attributes, &numReturned);
+
+        if (!numReturned)
+            return 0;
+
+        GLXFBConfig selectedConfig = 0;
+        bool found = false;
+
+        for (int i = 0; i < numReturned; ++i) {
+            m_VisualInfo = glXGetVisualFromFBConfig(display(), temp[i]);
+            if (!m_VisualInfo)
+                continue;
+
+            if (m_supportsXRenderExtension) {
+                XRenderPictFormat* format = XRenderFindVisualFormat(display(), m_VisualInfo->visual);
+                if (format && format->direct.alphaMask > 0) {
+                    selectedConfig = temp[i];
+                    found = true;
+                    break;
+                }
+            } else if (m_VisualInfo->depth == 32) {
+                selectedConfig = temp[i];
+                found = true;
+            }
+        }
+
+        // Did not find any visual supporting alpha, select the first available config.
+        if (!found) {
+            selectedConfig = temp[0];
+            m_VisualInfo = glXGetVisualFromFBConfig(m_display, temp[0]);
+        }
+
+        XFree(temp);
+
+        return selectedConfig;
+    }
+
+    GLXFBConfig pBufferContextConfig()
+    {
+        if (!m_pbufferfbConfig) {
+            static const int attributes[] = {
+                GLX_LEVEL, 0,
+                GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT,
+                GLX_RENDER_TYPE,   GLX_RGBA_BIT,
+                GLX_RED_SIZE,      1,
+                GLX_GREEN_SIZE,    1,
+                GLX_BLUE_SIZE,     1,
+                GLX_DOUBLEBUFFER,  GL_FALSE,
+                None
+            };
+
+            int numReturned;
+            GLXFBConfig* temp = glXChooseFBConfig(display(), DefaultScreen(display()), attributes, &numReturned);
+            if (numReturned)
+                m_pbufferfbConfig = temp[0];
+            XFree(temp);
+        }
+
+        return m_pbufferfbConfig;
+    }
+
+    GLXFBConfig surfaceContextConfig()
+    {
+        if (!m_surfaceContextfbConfig) {
+            static int attributes[] = {
+                GLX_LEVEL, 0,
+                GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
+                GLX_RENDER_TYPE,   GLX_RGBA_BIT,
+                GLX_RED_SIZE,      1,
+                GLX_GREEN_SIZE,    1,
+                GLX_BLUE_SIZE,     1,
+                GLX_ALPHA_SIZE,    1,
+                GLX_DEPTH_SIZE,    1,
+                GLX_X_VISUAL_TYPE, GLX_TRUE_COLOR,
+                GLX_DOUBLEBUFFER,  True,
+                None
+            };
+
+            int eventBasep, errorBasep;
+            m_supportsXRenderExtension = XRenderQueryExtension(display(), &eventBasep, &errorBasep);
+
+            m_surfaceContextfbConfig = createConfig(attributes);
+        }
+
+        return m_surfaceContextfbConfig;
+    }
+
+    bool isXRenderExtensionSupported()
+    {
+        return m_supportsXRenderExtension;
+    }
+
+private:
+    SharedX11Resources()
+        : m_supportsXRenderExtension(false)
+        , m_markForDeletion(false)
+        , m_window(0)
+        , m_display(0)
+        , m_pbufferfbConfig(0)
+        , m_surfaceContextfbConfig(0)
+        , m_VisualInfo(0)
+    {
+    }
+
+    ~SharedX11Resources()
+    {
+        if (!m_display)
+            return;
+
+        if (m_window) {
+            XUnmapWindow(m_display, m_window);
+            XDestroyWindow(m_display, m_window);
+            m_window = 0;
+        }
+
+        if (m_pbufferfbConfig)
+            m_pbufferfbConfig = 0;
+
+        if (m_surfaceContextfbConfig)
+            m_surfaceContextfbConfig = 0;
+
+        if (m_VisualInfo) {
+            XFree(m_VisualInfo);
+            m_VisualInfo = 0;
+        }
+
+        XCloseDisplay(m_display);
+        m_display = 0;
+    }
+
+    static SharedX11Resources* m_staticSharedResource;
+    bool m_supportsXRenderExtension;
+    bool m_markForDeletion;
+    Window m_window;
+    Display* m_display;
+    GLXFBConfig m_pbufferfbConfig;
+    GLXFBConfig m_surfaceContextfbConfig;
+    XVisualInfo* m_VisualInfo;
+};
+
+class GLXSurface : public GLPlatformSurface {
+    WTF_MAKE_NONCOPYABLE(GLXSurface);
+
+public:
+    GLXSurface();
+    virtual ~GLXSurface();
+
+protected:
+    XVisualInfo* visualInfo();
+    Window xWindow();
+    GLXFBConfig pBufferConfiguration();
+    GLXFBConfig transportSurfaceConfiguration();
+    bool isXRenderExtensionSupported();
+
+private:
+    RefPtr<SharedX11Resources> m_sharedResources;
+};
+
+class GLXTransportSurface : public GLXSurface {
+    WTF_MAKE_NONCOPYABLE(GLXTransportSurface);
+
+public:
+    GLXTransportSurface();
+    virtual ~GLXTransportSurface();
+    PlatformSurfaceConfig configuration();
+    void swapBuffers();
+    void setGeometry(const IntRect& newRect);
+    void destroy();
+
+private:
+    void initialize();
+    void freeResources();
+};
+
+class GLXPBuffer : public GLXSurface {
+    WTF_MAKE_NONCOPYABLE(GLXPBuffer);
+
+public:
+    GLXPBuffer();
+    virtual ~GLXPBuffer();
+    PlatformSurfaceConfig configuration();
+    void destroy();
+
+private:
+    void initialize();
+    void freeResources();
+};
+
+}
+
+#endif
+
+#endif