Changeset 135468 in webkit


Ignore:
Timestamp:
Nov 21, 2012 8:11:34 PM (11 years ago)
Author:
commit-queue@webkit.org
Message:

[EFL] Refactor GraphicsContext3DEFL.
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):

Location:
trunk/Source/WebCore
Files:
10 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r135465 r135468  
     12012-11-21  Kondapally Kalyan  <kalyan.kondapally@intel.com>
     2
     3        [EFL] Refactor GraphicsContext3DEFL.
     4        https://bugs.webkit.org/show_bug.cgi?id=101291.
     5
     6        Reviewed by Kenneth Rohde Christiansen.
     7
     8        GraphicsContext3DEfl creates GraphicsContext3DPrivate, which acts as its platform Layer.
     9        GraphicsContext3DPrivate needs to handle the following cases:
     10        1) To provide an off-screen buffer for accelerated composition.
     11        2) Render to a current context.
     12        3) To render directly to host window. (currently not supported.)
     13
     14        Before this patch Evas was used to provide us an off-screen context and buffer. GLX was used in
     15        the other supported case. Evas acts as a glue layer to provide us with appropriate
     16        GL bindings (OpenGL functions), GL context and drawable (surface/offscreenbuffer).
     17        However, primitive rendering is handled by TextureMapper and OpenGLShims is used to load the needed GL functions.
     18
     19        It would be for our advantage to be able to take in to use any optimisations/extensions
     20        provided by underlying drivers, specific to a platform (e.g. GLX_MESA_copy_sub_buffer etc.).
     21        This patch introduces an abstraction layer to make it easy to add support for any GL backend (GLX, EGL etc.)
     22        and do any platform specific optimizations as needed without complicating GraphicsContext3DPrivate class.
     23        Two new classes are added with this implementation, GLPlatformContext and GLPlatformSurface.
     24        GraphicsContext3DPrivate would create and own a GLPlatformContext and GLPlatformSurface.
     25
     26        GLPlatformContext encapsulates an OpenGL context hiding any platform specific management.
     27        It uses GL extension ARB_robustness (when available) to detect driver resets.
     28        It defines a simple interface for things that need to be handled by the context. Support
     29        for multi-threaded usage and shared context-group would be added later.
     30
     31        GLPlatformSurface encapsulates an OpenGL drawable hiding any platform specific management.
     32        It defines a simple interface for things that need to be handled by the surface.
     33        It creates an off-screen rendering area. Any GLPlatformContext (compatible with the surface)
     34        can be used to render into this off-screen area.
     35
     36        This patch also adds GLX implementation. To keep the patch to minimum EGL support would be added in another changeset.
     37
     38        * PlatformEfl.cmake:
     39        * platform/graphics/efl/GraphicsContext3DEfl.cpp:
     40        (WebCore::GraphicsContext3D::create):
     41        (WebCore::GraphicsContext3D::GraphicsContext3D):
     42        (WebCore::GraphicsContext3D::~GraphicsContext3D):
     43        (WebCore::GraphicsContext3D::makeContextCurrent):
     44        (WebCore::GraphicsContext3D::setContextLostCallback):
     45        * platform/graphics/efl/GraphicsContext3DPrivate.cpp:
     46        (WebCore::GraphicsContext3DPrivate::GraphicsContext3DPrivate):
     47        (GraphicsContext3DPrivate::~GraphicsContext3DPrivate):
     48        (GraphicsContext3DPrivate::releaseResources):
     49        (GraphicsContext3DPrivate::setContextLostCallback):
     50        (GraphicsContext3DPrivate::platformGraphicsContext3D):
     51        (GraphicsContext3DPrivate::makeContextCurrent):
     52        (GraphicsContext3DPrivate::createGraphicsSurfaces):
     53        (GraphicsContext3DPrivate::copyToGraphicsSurface):
     54        (GraphicsContext3DPrivate::graphicsSurfaceToken):
     55        * platform/graphics/efl/GraphicsContext3DPrivate.h:
     56        (GraphicsContext3DPrivate):
     57        * platform/graphics/opengl/GLDefs.h: Added.
     58        (WebCore):
     59        * platform/graphics/opengl/GLPlatformContext.cpp: Added.
     60        (WebCore):
     61        (WebCore::GLPlatformContext::createContext):
     62        (WebCore::GLPlatformContext::createOffScreenContext):
     63        (WebCore::GLPlatformContext::createCurrentContextWrapper):
     64        (WebCore::GLPlatformContext::GLPlatformContext):
     65        (WebCore::GLPlatformContext::~GLPlatformContext):
     66        (WebCore::GLPlatformContext::makeCurrent):
     67        (WebCore::GLPlatformContext::isValid):
     68        (WebCore::GLPlatformContext::releaseCurrent):
     69        (WebCore::GLPlatformContext::handle):
     70        (WebCore::GLPlatformContext::isCurrentContext):
     71        (WebCore::GLPlatformContext::initialize):
     72        (WebCore::GLPlatformContext::getCurrent):
     73        (WebCore::GLPlatformContext::platformMakeCurrent):
     74        (WebCore::GLPlatformContext::platformReleaseCurrent):
     75        (WebCore::GLPlatformContext::destroy):
     76        * platform/graphics/opengl/GLPlatformContext.h: Added.
     77        (WebCore):
     78        (GLPlatformContext):
     79        * platform/graphics/opengl/GLPlatformSurface.cpp: Added.
     80        (WebCore):
     81        (WebCore::GLPlatformSurface::createOffscreenSurface):
     82        (WebCore::GLPlatformSurface::createTransportSurface):
     83        (WebCore::GLPlatformSurface::GLPlatformSurface):
     84        (WebCore::GLPlatformSurface::~GLPlatformSurface):
     85        (WebCore::GLPlatformSurface::handle):
     86        (WebCore::GLPlatformSurface::geometry):
     87        (WebCore::GLPlatformSurface::sharedDisplay):
     88        (WebCore::GLPlatformSurface::configuration):
     89        (WebCore::GLPlatformSurface::swapBuffers):
     90        (WebCore::GLPlatformSurface::copyTexture):
     91        (WebCore::GLPlatformSurface::updateContents):
     92        (WebCore::GLPlatformSurface::setGeometry):
     93        (WebCore::GLPlatformSurface::destroy):
     94        * platform/graphics/opengl/GLPlatformSurface.h: Added.
     95        (WebCore):
     96        (GLPlatformSurface):
     97            GLXOffScreenContext creates an off-screen context. This is used when
     98            renderstyle is RenderOffscreen.
     99            It uses GL extension GLX_ARB_create_context (when available)
     100            to create a context else falls back to use glXCreateNewContext.
     101        * platform/graphics/surfaces/glx/GLXContext.cpp: Added.
     102        (WebCore):
     103        (WebCore::initializeARBExtensions):
     104        (WebCore::GLXOffScreenContext::GLXOffScreenContext):
     105        (WebCore::GLXOffScreenContext::initialize):
     106        (WebCore::GLXOffScreenContext::~GLXOffScreenContext):
     107        (WebCore::GLXOffScreenContext::isCurrentContext):
     108        (WebCore::GLXOffScreenContext::platformMakeCurrent):
     109        (WebCore::GLXOffScreenContext::platformReleaseCurrent):
     110        (WebCore::GLXOffScreenContext::freeResources):
     111        (WebCore::GLXOffScreenContext::destroy):
     112            GLXCurrentContextWrapper acts as a wrapper for current context.
     113            This is used when renderstyle is RenderToCurrentGLContext.
     114        * platform/graphics/surfaces/glx/GLXContext.h: Added.
     115        (WebCore):
     116        (GLXCurrentContextWrapper):
     117        (WebCore::GLXCurrentContextWrapper::GLXCurrentContextWrapper):
     118        (WebCore::GLXCurrentContextWrapper::~GLXCurrentContextWrapper):
     119        (GLXOffScreenContext):
     120        * platform/graphics/surfaces/glx/GLXSurface.cpp: Added.
     121        (WebCore):
     122        (WebCore::GLXSurface::GLXSurface):
     123        (WebCore::GLXSurface::~GLXSurface):
     124        (WebCore::GLXSurface::visualInfo):
     125        (WebCore::GLXSurface::xWindow):
     126        (WebCore::GLXSurface::pBufferConfiguration):
     127        (WebCore::GLXSurface::transportSurfaceConfiguration):
     128        (WebCore::GLXSurface::isXRenderExtensionSupported):
     129            GLXTransportSurface creates Window and uses it as an off-screen surface.
     130            Any GLContext that was created with respect to configuration can be used
     131            to render into this.
     132            This is used when contents of the buffer are to be provided to UI Process
     133            for display.
     134        (WebCore::GLXTransportSurface::GLXTransportSurface):
     135        (WebCore::GLXTransportSurface::~GLXTransportSurface):
     136        (WebCore::GLXTransportSurface::configuration):
     137        (WebCore::GLXTransportSurface::swapBuffers):
     138        (WebCore::GLXTransportSurface::setGeometry):
     139        (WebCore::GLXTransportSurface::initialize):
     140        (WebCore::GLXTransportSurface::destroy):
     141        (WebCore::GLXTransportSurface::freeResources):
     142           GLXPBuffer, Creates a GL surface (PBuffer) used for offscreen rendering.
     143           Any GLContext that was created with respect to configuration can be used
     144           to render into this.
     145        (WebCore::GLXPBuffer::GLXPBuffer):
     146        (WebCore::GLXPBuffer::~GLXPBuffer):
     147        (WebCore::GLXPBuffer::initialize):
     148        (WebCore::GLXPBuffer::configuration):
     149        (WebCore::GLXPBuffer::destroy):
     150        (WebCore::GLXPBuffer::freeResources):
     151        * platform/graphics/surfaces/glx/GLXSurface.h: Added.
     152        (WebCore):
     153            Creates X resources which are shared between surface and context.
     154        (SharedX11Resources):
     155        (WebCore::SharedX11Resources::create):
     156        (WebCore::SharedX11Resources::deref):
     157        (WebCore::SharedX11Resources::getXWindow):
     158        (WebCore::SharedX11Resources::display):
     159        (WebCore::SharedX11Resources::visualInfo):
     160        (WebCore::SharedX11Resources::createConfig):
     161        (WebCore::SharedX11Resources::pBufferContextConfig):
     162        (WebCore::SharedX11Resources::surfaceContextConfig):
     163        (WebCore::SharedX11Resources::isXRenderExtensionSupported):
     164        (WebCore::SharedX11Resources::SharedX11Resources):
     165        (WebCore::SharedX11Resources::~SharedX11Resources):
     166        (GLXSurface):
     167        (GLXTransportSurface):
     168        (GLXPBuffer):
     169
    11702012-11-21  Andreas Kling  <akling@apple.com>
    2171
  • trunk/Source/WebCore/PlatformEfl.cmake

    r135100 r135468  
    260260    "${WEBCORE_DIR}/platform/graphics/opengl"
    261261    "${WEBCORE_DIR}/platform/graphics/surfaces"
     262    "${WEBCORE_DIR}/platform/graphics/surfaces/glx"
    262263    "${WEBCORE_DIR}/platform/graphics/texmap"
    263264  )
     
    269270    platform/graphics/opengl/Extensions3DOpenGL.cpp
    270271    platform/graphics/opengl/Extensions3DOpenGLCommon.cpp
     272    platform/graphics/opengl/GLPlatformContext.cpp
     273    platform/graphics/opengl/GLPlatformSurface.cpp
    271274    platform/graphics/opengl/GraphicsContext3DOpenGL.cpp
    272275    platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp
    273276    platform/graphics/surfaces/GraphicsSurface.cpp
     277    platform/graphics/surfaces/glx/GLXSurface.cpp
     278    platform/graphics/surfaces/glx/GLXContext.cpp
    274279    platform/graphics/surfaces/qt/GraphicsSurfaceGLX.cpp
    275280    platform/graphics/texmap/TextureMapperGL.cpp
  • trunk/Source/WebCore/platform/graphics/efl/GraphicsContext3DEfl.cpp

    r135083 r135468  
    11/*
    22    Copyright (C) 2012 Samsung Electronics
     3    Copyright (C) 2012 Intel Corporation.
    34
    45    This library is free software; you can redistribute it and/or
     
    2829#include "OpenGLShims.h"
    2930#include "PlatformContextCairo.h"
    30 #include <GL/glx.h>
    3131
    3232#if USE(OPENGL_ES_2)
     
    4040PassRefPtr<GraphicsContext3D> GraphicsContext3D::create(GraphicsContext3D::Attributes attrs, HostWindow* hostWindow, RenderStyle renderStyle)
    4141{
     42    if (renderStyle == RenderDirectlyToHostWindow)
     43        return 0;
     44
    4245    RefPtr<GraphicsContext3D> context = adoptRef(new GraphicsContext3D(attrs, hostWindow, renderStyle));
    4346    return context->m_private ? context.release() : 0;
     
    6871    , m_private(adoptPtr(new GraphicsContext3DPrivate(this, hostWindow, renderStyle)))
    6972{
     73    if (!m_private || !m_private->m_platformContext) {
     74        m_private = nullptr;
     75        return;
     76    }
     77
    7078    validateAttributes();
    71 
    72     if (!m_private)
    73         return;
    74 
    75     static bool initializedShims = false;
    76     static bool success = true;
    77     if (!initializedShims) {
    78         success = initializeOpenGLShims();
    79         initializedShims = true;
    80     }
    81     if (!success) {
    82         m_private = nullptr;
    83         return;
    84     }
    85 
    86     if (renderStyle == RenderToCurrentGLContext) {
    87         // Evas doesn't allow including gl headers and Evas_GL headers at the same time,
    88         // so we need to query the current gl context/surface here instead of in GraphicsContext3DPrivate.
    89         void* currentContext = (void*)glXGetCurrentContext();
    90         void* currentSurface = (void*)glXGetCurrentDrawable();
    91         m_private->setCurrentGLContext(currentContext, currentSurface);
    92     }
    9379
    9480    if (renderStyle == RenderOffscreen) {
     
    148134    glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
    149135#endif
     136    glClearColor(0.0, 0.0, 0.0, 0.0);
    150137}
    151138
    152139GraphicsContext3D::~GraphicsContext3D()
    153140{
    154     if (m_renderStyle == RenderToCurrentGLContext || !m_private)
    155         return;
    156 
    157     makeContextCurrent();
     141    if (!m_private || !makeContextCurrent())
     142        return;
     143
     144    if (!m_fbo) {
     145        m_private->releaseResources();
     146        return;
     147    }
     148
    158149    glDeleteTextures(1, &m_texture);
    159150
     
    166157        glDeleteFramebuffers(1, &m_multisampleFBO);
    167158    } else if (m_attrs.stencil || m_attrs.depth) {
    168 
    169159#if USE(OPENGL_ES_2)
    170160        if (m_attrs.depth)
     
    176166        glDeleteRenderbuffers(1, &m_depthStencilBuffer);
    177167    }
     168
    178169    glDeleteFramebuffers(1, &m_fbo);
     170    m_private->releaseResources();
    179171}
    180172
     
    198190bool GraphicsContext3D::makeContextCurrent()
    199191{
    200     if (!m_private)
    201         return false;
    202 
    203     if (m_renderStyle == RenderToCurrentGLContext)
    204         return true;
    205 
    206192    return m_private->makeContextCurrent();
    207193}
     
    216202}
    217203
    218 void GraphicsContext3D::setContextLostCallback(PassOwnPtr<ContextLostCallback>)
    219 {
    220     notImplemented();
     204void GraphicsContext3D::setContextLostCallback(PassOwnPtr<ContextLostCallback> callBack)
     205{
     206    m_private->setContextLostCallback(callBack);
    221207}
    222208
  • trunk/Source/WebCore/platform/graphics/efl/GraphicsContext3DPrivate.cpp

    r135083 r135468  
    11/*
    22    Copyright (C) 2012 Samsung Electronics
     3    Copyright (C) 2012 Intel Corporation.
    34
    45    This library is free software; you can redistribute it and/or
     
    1920
    2021#include "config.h"
     22#include "GraphicsContext3DPrivate.h"
    2123
    2224#if USE(3D_GRAPHICS) || USE(ACCELERATED_COMPOSITING)
    23 #include "GraphicsContext3DPrivate.h"
    2425
    25 #include "GraphicsContext.h"
    2626#include "HostWindow.h"
    2727#include "NotImplemented.h"
    2828#include "PlatformContextCairo.h"
    29 #include <Ecore_Evas.h>
    30 #include <Evas_GL.h>
    31 #include <wtf/OwnArrayPtr.h>
    32 #include <wtf/text/CString.h>
     29
     30#if USE(OPENGL_ES_2)
     31#include <GLES2/gl2.h>
     32#include <GLES2/gl2ext.h>
     33#else
     34#include "OpenGLShims.h"
     35#endif
    3336
    3437namespace WebCore {
     
    3740    : m_context(context)
    3841    , m_hostWindow(hostWindow)
    39     , m_evasGL(0)
    40     , m_evasGLContext(0)
    41     , m_evasGLSurface(0)
    42     , m_glContext(0)
    43     , m_glSurface(0)
    44     , m_api(0)
    45     , m_renderStyle(renderStyle)
     42    , m_pendingSurfaceResize(false)
    4643{
    47     if (renderStyle == GraphicsContext3D::RenderToCurrentGLContext)
    48         return;
    49 
    5044    if (m_hostWindow && m_hostWindow->platformPageClient()) {
    5145        // FIXME: Implement this code path for WebKit1.
     
    5448    }
    5549
    56     // For WebKit2, we need to create a dummy ecoreEvas object for the WebProcess in order to use EvasGL APIs.
    57 #ifdef HAVE_ECORE_X
    58     ecore_evas_init();
    59     m_ecoreEvas = adoptPtr(ecore_evas_gl_x11_new(0, 0, 0, 0, 1, 1));
    60     if (!m_ecoreEvas)
    61         return;
    62 #else
    63     return;
    64 #endif
    65 
    66     Evas* evas = ecore_evas_get(m_ecoreEvas.get());
    67     if (!evas)
     50    m_platformContext = GLPlatformContext::createContext(renderStyle);
     51    if (!m_platformContext)
    6852        return;
    6953
    70     // Create a new Evas_GL object for gl rendering on efl.
    71     m_evasGL = evas_gl_new(evas);
    72     if (!m_evasGL)
    73         return;
     54    if (renderStyle == GraphicsContext3D::RenderOffscreen) {
     55#if USE(GRAPHICS_SURFACE)
     56        m_platformSurface = GLPlatformSurface::createTransportSurface();
     57#else
     58        m_platformSurface = GLPlatformSurface::createOffscreenSurface();
     59#endif
     60        if (!m_platformSurface) {
     61            m_platformContext = nullptr;
     62            return;
     63        }
    7464
    75     // Get the API for rendering using OpenGL.
    76     // This returns a structure that contains all the OpenGL functions we can use to render in Evas
    77     m_api = evas_gl_api_get(m_evasGL);
    78     if (!m_api)
    79         return;
    80 
    81     // Create a context
    82     m_evasGLContext = evas_gl_context_create(m_evasGL, 0);
    83     if (!m_evasGLContext)
    84         return;
    85 
    86     // Create a surface
    87     if (!createSurface(0, renderStyle == GraphicsContext3D::RenderDirectlyToHostWindow))
    88         return;
    89 
    90     makeContextCurrent();
    91 
     65        if (!m_platformContext->initialize(m_platformSurface.get()) || !m_platformContext->makeCurrent(m_platformSurface.get())) {
     66            releaseResources();
     67            m_platformContext = nullptr;
     68            m_platformSurface = nullptr;
    9269#if USE(GRAPHICS_SURFACE)
    93     IntSize surfaceSize(m_context->m_currentWidth, m_context->m_currentHeight);
    94     m_surfaceFlags = GraphicsSurface::SupportsTextureTarget | GraphicsSurface::SupportsSharing;
    95     if (!surfaceSize.isEmpty())
    96         m_graphicsSurface = GraphicsSurface::create(surfaceSize, m_surfaceFlags);
     70        } else
     71            m_surfaceHandle = GraphicsSurfaceToken(m_platformSurface->handle());
     72#else
     73        }
    9774#endif
     75    }
    9876}
    9977
    10078GraphicsContext3DPrivate::~GraphicsContext3DPrivate()
    10179{
    102     if (!m_evasGL)
    103         return;
    104 
    105     if (m_evasGLSurface)
    106         evas_gl_surface_destroy(m_evasGL, m_evasGLSurface);
    107 
    108     if (m_evasGLContext)
    109         evas_gl_context_destroy(m_evasGL, m_evasGLContext);
    110 
    111     evas_gl_free(m_evasGL);
    112 
    113 #if USE(GRAPHICS_SURFACE)
    114     m_graphicsSurface.clear();
    115 #endif
    11680}
    11781
    118 bool GraphicsContext3DPrivate::createSurface(PageClientEfl* pageClient, bool renderDirectlyToHostWindow)
     82void GraphicsContext3DPrivate::releaseResources()
    11983{
    120     // If RenderStyle is RenderOffscreen, we will be rendering to a FBO,
    121     // so Evas_GL_Surface has a 1x1 dummy surface.
    122     int width = 1;
    123     int height = 1;
     84    // Release the current context and drawable only after destroying any associated gl resources.
     85    if (m_platformContext)
     86        m_platformContext->destroy();
    12487
    125     // But, in case of RenderDirectlyToHostWindow, we have to render to a render target surface with the same size as our webView.
    126     if (renderDirectlyToHostWindow) {
    127         if (!pageClient)
    128             return false;
    129         // FIXME: Get geometry of webView and set size of target surface.
    130     }
     88    if (m_platformSurface)
     89        m_platformSurface->destroy();
    13190
    132     Evas_GL_Config config = {
    133         EVAS_GL_RGBA_8888,
    134         EVAS_GL_DEPTH_BIT_8,
    135         EVAS_GL_STENCIL_NONE, // FIXME: set EVAS_GL_STENCIL_BIT_8 after fixing Evas_GL bug.
    136         EVAS_GL_OPTIONS_NONE,
    137         EVAS_GL_MULTISAMPLE_NONE
    138     };
    139 
    140     // Create a new Evas_GL_Surface object
    141     m_evasGLSurface = evas_gl_surface_create(m_evasGL, &config, width, height);
    142     if (!m_evasGLSurface)
    143         return false;
    144 
    145 #if USE(ACCELERATED_COMPOSITING)
    146     if (renderDirectlyToHostWindow) {
    147         Evas_Native_Surface nativeSurface;
    148         // Fill in the Native Surface information from the given Evas GL surface.
    149         evas_gl_native_surface_get(m_evasGL, m_evasGLSurface, &nativeSurface);
    150 
    151         // FIXME: Create and specially set up a evas_object which act as the render targer surface.
    152     }
    153 #endif
    154 
    155     return true;
     91    if (m_platformContext)
     92        m_platformContext->releaseCurrent();
    15693}
    15794
    158 void GraphicsContext3DPrivate::setCurrentGLContext(void* context, void* surface)
     95bool GraphicsContext3DPrivate::createSurface(PageClientEfl*, bool)
    15996{
    160     m_glContext = context;
    161     m_glSurface = surface;
     97    notImplemented();
     98    return false;
     99}
     100
     101void GraphicsContext3DPrivate::setContextLostCallback(PassOwnPtr<GraphicsContext3D::ContextLostCallback> callBack)
     102{
     103    m_contextLostCallback = callBack;
    162104}
    163105
    164106PlatformGraphicsContext3D GraphicsContext3DPrivate::platformGraphicsContext3D() const
    165107{
    166     if (m_renderStyle == GraphicsContext3D::RenderToCurrentGLContext)
    167         return m_glContext;
    168 
    169     return m_evasGLContext;
     108    return m_platformContext->handle();
    170109}
    171110
    172111bool GraphicsContext3DPrivate::makeContextCurrent()
    173112{
    174     return evas_gl_make_current(m_evasGL, m_evasGLSurface, m_evasGLContext);
     113    bool success = m_platformContext->makeCurrent(m_platformSurface.get());
     114
     115    if (!m_platformContext->isValid()) {
     116        // FIXME: Restore context
     117        if (m_contextLostCallback)
     118            m_contextLostCallback->onContextLost();
     119
     120        success = false;
     121    }
     122
     123    return success;
    175124}
    176125
     
    183132
    184133#if USE(GRAPHICS_SURFACE)
    185 void GraphicsContext3DPrivate::createGraphicsSurfaces(const IntSize& size)
     134void GraphicsContext3DPrivate::createGraphicsSurfaces(const IntSize&)
    186135{
    187     if (size.isEmpty())
    188         m_graphicsSurface.clear();
    189     else
    190         m_graphicsSurface = GraphicsSurface::create(size, m_surfaceFlags);
     136    m_pendingSurfaceResize = true;
    191137}
    192138
    193139uint32_t GraphicsContext3DPrivate::copyToGraphicsSurface()
    194140{
    195     if (!m_graphicsSurface)
     141    if (!m_platformContext || !makeContextCurrent())
    196142        return 0;
    197143
    198     makeContextCurrent();
    199     m_graphicsSurface->copyFromTexture(m_context->m_texture, IntRect(0, 0, m_context->m_currentWidth, m_context->m_currentHeight));
    200     return m_graphicsSurface->swapBuffers();
     144    if (m_pendingSurfaceResize) {
     145        m_pendingSurfaceResize = false;
     146        m_platformSurface->setGeometry(IntRect(0, 0, m_context->m_currentWidth, m_context->m_currentHeight));
     147    }
     148
     149    if (m_context->m_attrs.antialias) {
     150#if !USE(OPENGL_ES_2)
     151        glBindFramebuffer(GL_READ_FRAMEBUFFER_EXT, m_context->m_multisampleFBO);
     152        glBindFramebuffer(GL_DRAW_FRAMEBUFFER_EXT, m_context->m_fbo);
     153        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);
     154#endif
     155    }
     156
     157    m_platformSurface->updateContents(m_context->m_texture, IntRect(0, 0, m_context->m_currentWidth, m_context->m_currentHeight), m_context->m_boundFBO);
     158    return 0;
    201159}
    202160
    203161GraphicsSurfaceToken GraphicsContext3DPrivate::graphicsSurfaceToken() const
    204162{
    205     return m_graphicsSurface->exportToken();
     163    return m_surfaceHandle;
    206164}
    207165#endif
  • trunk/Source/WebCore/platform/graphics/efl/GraphicsContext3DPrivate.h

    r135083 r135468  
    11/*
    22    Copyright (C) 2012 Samsung Electronics
     3    Copyright (C) 2012 Intel Corporation.
    34
    45    This library is free software; you can redistribute it and/or
     
    2122#define GraphicsContext3DPrivate_h
    2223
     24#if USE(3D_GRAPHICS) || USE(ACCELERATED_COMPOSITING)
     25
    2326#include "GraphicsContext3D.h"
    2427
     
    2730#endif
    2831
    29 #if USE(GRAPHICS_SURFACE)
    30 #include "GraphicsSurface.h"
    31 #endif
    32 
    33 typedef struct _Evas_GL               Evas_GL;
    34 typedef struct _Evas_GL_Surface       Evas_GL_Surface;
    35 typedef struct _Evas_GL_Context       Evas_GL_Context;
    36 typedef struct _Evas_GL_Config        Evas_GL_Config;
    37 typedef struct _Evas_GL_API           Evas_GL_API;
     32#include "GLPlatformContext.h"
     33#include <wtf/PassOwnPtr.h>
    3834
    3935class PageClientEfl;
     
    4945    ~GraphicsContext3DPrivate();
    5046
     47    bool createSurface(PageClientEfl*, bool);
    5148    PlatformGraphicsContext3D platformGraphicsContext3D() const;
    52 
     49    void setContextLostCallback(PassOwnPtr<GraphicsContext3D::ContextLostCallback>  callBack);
    5350#if USE(ACCELERATED_COMPOSITING)
    5451    PlatformLayer* platformLayer() const;
     
    6259    void createGraphicsSurfaces(const IntSize&);
    6360#endif
    64 
    6561    bool makeContextCurrent();
    66     bool createSurface(PageClientEfl*, bool renderDirectlyToEvasGLObject);
    67     void setCurrentGLContext(void*, void*);
    68 
     62    void releaseResources();
    6963    GraphicsContext3D::Attributes m_attributes;
    7064    GraphicsContext3D* m_context;
    7165    HostWindow* m_hostWindow;
     66    OwnPtr<GLPlatformContext> m_platformContext;
     67    OwnPtr<GLPlatformSurface> m_platformSurface;
    7268#if USE(GRAPHICS_SURFACE)
    73     GraphicsSurface::Flags m_surfaceFlags;
    74     RefPtr<GraphicsSurface> m_graphicsSurface;
     69    GraphicsSurfaceToken m_surfaceHandle;
    7570#endif
    76 
     71    OwnPtr<GraphicsContext3D::ContextLostCallback> m_contextLostCallback;
    7772    ListHashSet<GC3Denum> m_syntheticErrors;
    78 
    79     OwnPtr<Ecore_Evas> m_ecoreEvas;
    80     Evas_GL* m_evasGL;
    81     Evas_GL_Context* m_evasGLContext;
    82     Evas_GL_Surface* m_evasGLSurface;
    83     void* m_glContext;
    84     void* m_glSurface;
    85     Evas_GL_API* m_api;
    86     GraphicsContext3D::RenderStyle m_renderStyle;
     73    bool m_pendingSurfaceResize;
    8774};
    8875
    8976} // namespace WebCore
    9077
    91 #endif // GraphicsLayerEfl_h
     78#endif
     79
     80#endif
Note: See TracChangeset for help on using the changeset viewer.