Changeset 217208 in webkit


Ignore:
Timestamp:
May 22, 2017 12:30:39 AM (7 years ago)
Author:
Carlos Garcia Campos
Message:

[WPE] Use surfaceless context for sharing and offscreen context if available
https://bugs.webkit.org/show_bug.cgi?id=172268

Reviewed by Žan Doberšek.

Like GTK+ port does, WPE should use surfaceless contexts when possible, and only create a native offscreen
context as a fallback. We don't need to do anything special in WPE port, just to make it consistent with the
Wayland and X11 implementations. We should also avoid including EGL.h in headers, we added
GLContextEGLWayland.cpp and GLContextEGLX11.cpp to avoid that. PlatformDisplayWPE::EGLOffscreenTarget is quite
simple and only used by GLContextEGLWPE, so we could move it there like we do for Wayland and X11.

  • platform/graphics/GLContext.h: Remove EGL header includes.
  • platform/graphics/egl/GLContextEGL.cpp:

(WebCore::GLContextEGL::createWindowContext): Use createWindowSurfaceWPE() in WPE.
(WebCore::GLContextEGL::createContext): Use createWPEContext in WPE.
(WebCore::GLContextEGL::createSharingContext): Move the WPE code below to ensure we try
createSurfacelessContext() first.

  • platform/graphics/egl/GLContextEGL.h:
  • platform/graphics/egl/GLContextEGLWPE.cpp:

(WebCore::GLContextEGL::GLContextEGL): Add constructor for WPE that receives a struct wpe_renderer_backend_egl_offscreen_target*
(WebCore::GLContextEGL::createWindowSurfaceWPE): Added implementation here because eglCreateWindowSurface needs
the platform specific EGL includes and definitions.
(WebCore::GLContextEGL::createWPEContext): Create a GLContext using WPE backend API directly here.
(WebCore::GLContextEGL::destroyWPETarget): Add null check.

  • platform/graphics/wpe/PlatformDisplayWPE.cpp: Remove EGLOffscreenTarget.
  • platform/graphics/wpe/PlatformDisplayWPE.h:
Location:
trunk/Source/WebCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r217203 r217208  
     12017-05-21  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [WPE] Use surfaceless context for sharing and offscreen context if available
     4        https://bugs.webkit.org/show_bug.cgi?id=172268
     5
     6        Reviewed by Žan Doberšek.
     7
     8        Like GTK+ port does, WPE should use surfaceless contexts when possible, and only create a native offscreen
     9        context as a fallback. We don't need to do anything special in WPE port, just to make it consistent with the
     10        Wayland and X11 implementations. We should also avoid including EGL.h in headers, we added
     11        GLContextEGLWayland.cpp and GLContextEGLX11.cpp to avoid that. PlatformDisplayWPE::EGLOffscreenTarget is quite
     12        simple and only used by GLContextEGLWPE, so we could move it there like we do for Wayland and X11.
     13
     14        * platform/graphics/GLContext.h: Remove EGL header includes.
     15        * platform/graphics/egl/GLContextEGL.cpp:
     16        (WebCore::GLContextEGL::createWindowContext): Use createWindowSurfaceWPE() in WPE.
     17        (WebCore::GLContextEGL::createContext): Use createWPEContext in WPE.
     18        (WebCore::GLContextEGL::createSharingContext): Move the WPE code below to ensure we try
     19        createSurfacelessContext() first.
     20        * platform/graphics/egl/GLContextEGL.h:
     21        * platform/graphics/egl/GLContextEGLWPE.cpp:
     22        (WebCore::GLContextEGL::GLContextEGL): Add constructor for WPE that receives a struct wpe_renderer_backend_egl_offscreen_target*
     23        (WebCore::GLContextEGL::createWindowSurfaceWPE): Added implementation here because eglCreateWindowSurface needs
     24        the platform specific EGL includes and definitions.
     25        (WebCore::GLContextEGL::createWPEContext): Create a GLContext using WPE backend API directly here.
     26        (WebCore::GLContextEGL::destroyWPETarget): Add null check.
     27        * platform/graphics/wpe/PlatformDisplayWPE.cpp: Remove EGLOffscreenTarget.
     28        * platform/graphics/wpe/PlatformDisplayWPE.h:
     29
    1302017-05-21  Michael Catanzaro  <mcatanzaro@igalia.com>
    231
  • trunk/Source/WebCore/platform/graphics/GLContext.h

    r216497 r217208  
    2525#include <wtf/Noncopyable.h>
    2626
    27 #if USE(EGL) && !PLATFORM(GTK)
    28 #if PLATFORM(WPE)
    29 // FIXME: For now default to the GBM EGL platform, but this should really be
    30 // somehow deducible from the build configuration.
    31 #define __GBM__ 1
    32 #include <EGL/eglplatform.h>
    33 #else
     27#if USE(EGL) && !PLATFORM(GTK) && !PLATFORM(WPE)
    3428#include "eglplatform.h"
    35 #endif
    3629typedef EGLNativeWindowType GLNativeWindowType;
    3730#else
  • trunk/Source/WebCore/platform/graphics/egl/GLContextEGL.cpp

    r216497 r217208  
    116116        surface = createWindowSurfaceWayland(display, config, window);
    117117#endif
     118#elif PLATFORM(WPE)
     119    if (platformDisplay.type() == PlatformDisplay::Type::WPE)
     120        surface = createWindowSurfaceWPE(display, config, window);
    118121#else
    119122    surface = eglCreateWindowSurface(display, config, static_cast<EGLNativeWindowType>(window), nullptr);
     
    190193            context = createWaylandContext(platformDisplay, eglSharingContext);
    191194#endif
     195#if PLATFORM(WPE)
     196        if (platformDisplay.type() == PlatformDisplay::Type::WPE)
     197            context = createWPEContext(platformDisplay, eglSharingContext);
     198#endif
    192199    }
    193200    if (!context)
     
    204211    if (eglBindAPI(gEGLAPIVersion) == EGL_FALSE)
    205212        return nullptr;
    206 
    207 #if PLATFORM(WPE)
    208     if (platformDisplay.type() == PlatformDisplay::Type::WPE) {
    209         if (auto context = createWPEContext(platformDisplay))
    210             return context;
    211     }
    212 #endif
    213213
    214214    auto context = createSurfacelessContext(platformDisplay);
     
    222222            context = createWaylandContext(platformDisplay);
    223223#endif
     224#if PLATFORM(WPE)
     225        if (platformDisplay.type() == PlatformDisplay::Type::WPE)
     226            context = createWPEContext(platformDisplay);
     227#endif
    224228    }
    225229    if (!context)
  • trunk/Source/WebCore/platform/graphics/egl/GLContextEGL.h

    r216497 r217208  
    3434
    3535#if PLATFORM(WPE)
    36 #include "PlatformDisplayWPE.h"
     36struct wpe_renderer_backend_egl_offscreen_target;
    3737#endif
    3838
     
    7979#endif
    8080#if PLATFORM(WPE)
     81    GLContextEGL(PlatformDisplay&, EGLContext, EGLSurface, struct wpe_renderer_backend_egl_offscreen_target*);
    8182    void destroyWPETarget();
    8283#endif
     
    9596#if PLATFORM(WPE)
    9697    static std::unique_ptr<GLContextEGL> createWPEContext(PlatformDisplay&, EGLContext sharingContext = nullptr);
     98    static EGLSurface createWindowSurfaceWPE(EGLDisplay, EGLConfig, GLNativeWindowType);
    9799#endif
    98100
     
    110112#endif
    111113#if PLATFORM(WPE)
    112     std::unique_ptr<PlatformDisplayWPE::EGLOffscreenTarget> m_wpeTarget;
     114    struct wpe_renderer_backend_egl_offscreen_target* m_wpeTarget { nullptr };
    113115#endif
    114116#if USE(CAIRO)
  • trunk/Source/WebCore/platform/graphics/egl/GLContextEGLWPE.cpp

    r216930 r217208  
    2323
    2424#include "PlatformDisplayWPE.h"
     25// FIXME: For now default to the GBM EGL platform, but this should really be
     26// somehow deducible from the build configuration.
     27#define __GBM__ 1
     28#include <EGL/egl.h>
     29#include <wpe/renderer-backend-egl.h>
    2530
    2631namespace WebCore {
    2732
     33GLContextEGL::GLContextEGL(PlatformDisplay& display, EGLContext context, EGLSurface surface, struct wpe_renderer_backend_egl_offscreen_target* target)
     34    : GLContext(display)
     35    , m_context(context)
     36    , m_surface(surface)
     37    , m_type(WindowSurface)
     38    , m_wpeTarget(target)
     39{
     40}
     41
     42EGLSurface GLContextEGL::createWindowSurfaceWPE(EGLDisplay display, EGLConfig config, GLNativeWindowType window)
     43{
     44    return eglCreateWindowSurface(display, config, reinterpret_cast<EGLNativeWindowType>(window), nullptr);
     45}
     46
    2847std::unique_ptr<GLContextEGL> GLContextEGL::createWPEContext(PlatformDisplay& platformDisplay, EGLContext sharingContext)
    2948{
    30     auto offscreenTarget = downcast<PlatformDisplayWPE>(platformDisplay).createEGLOffscreenTarget();
     49    EGLDisplay display = platformDisplay.eglDisplay();
     50    EGLConfig config;
     51    if (!getEGLConfig(display, &config, WindowSurface))
     52        return nullptr;
    3153
    32     std::unique_ptr<GLContextEGL> context;
    33     if (offscreenTarget->nativeWindow())
    34         context = createWindowContext(offscreenTarget->nativeWindow(), platformDisplay, sharingContext);
    35     if (!context)
    36         context = createPbufferContext(platformDisplay, sharingContext);
     54    static const EGLint contextAttributes[] = {
     55#if USE(OPENGL_ES_2)
     56        EGL_CONTEXT_CLIENT_VERSION, 2,
     57#endif
     58        EGL_NONE
     59    };
    3760
    38     // FIXME: if available, we could also fallback to the surfaceless-based GLContext
    39     // before falling back to the pbuffer-based one.
     61    EGLContext context = eglCreateContext(display, config, sharingContext, contextAttributes);
     62    if (context == EGL_NO_CONTEXT)
     63        return nullptr;
    4064
    41     if (context)
    42         context->m_wpeTarget = WTFMove(offscreenTarget);
    43     return context;
     65    auto* target = wpe_renderer_backend_egl_offscreen_target_create();
     66    wpe_renderer_backend_egl_offscreen_target_initialize(target, downcast<PlatformDisplayWPE>(platformDisplay).backend());
     67    EGLNativeWindowType window = wpe_renderer_backend_egl_offscreen_target_get_native_window(target);
     68    if (!window) {
     69        wpe_renderer_backend_egl_offscreen_target_destroy(target);
     70        return nullptr;
     71    }
     72
     73    EGLSurface surface = eglCreateWindowSurface(display, config, static_cast<EGLNativeWindowType>(window), nullptr);
     74    if (surface == EGL_NO_SURFACE) {
     75        eglDestroyContext(display, context);
     76        wpe_renderer_backend_egl_offscreen_target_destroy(target);
     77        return nullptr;
     78    }
     79
     80    return std::unique_ptr<GLContextEGL>(new GLContextEGL(platformDisplay, context, surface, target));
    4481}
    4582
    4683void GLContextEGL::destroyWPETarget()
    4784{
    48     m_wpeTarget = nullptr;
     85    if (m_wpeTarget)
     86        wpe_renderer_backend_egl_offscreen_target_destroy(m_wpeTarget);
    4987}
    5088
  • trunk/Source/WebCore/platform/graphics/wpe/PlatformDisplayWPE.cpp

    r217123 r217208  
    3030
    3131#include "GLContextEGL.h"
    32 #include "IntSize.h"
     32// FIXME: For now default to the GBM EGL platform, but this should really be
     33// somehow deducible from the build configuration.
     34#define __GBM__ 1
    3335#include <EGL/egl.h>
    3436#include <wpe/renderer-backend-egl.h>
     
    5658}
    5759
    58 std::unique_ptr<PlatformDisplayWPE::EGLOffscreenTarget> PlatformDisplayWPE::createEGLOffscreenTarget()
    59 {
    60     return std::make_unique<EGLOffscreenTarget>(*this);
    61 }
    62 
    63 PlatformDisplayWPE::EGLOffscreenTarget::EGLOffscreenTarget(const PlatformDisplayWPE& display)
    64 {
    65     m_target = wpe_renderer_backend_egl_offscreen_target_create();
    66     wpe_renderer_backend_egl_offscreen_target_initialize(m_target, display.m_backend);
    67 }
    68 
    69 PlatformDisplayWPE::EGLOffscreenTarget::~EGLOffscreenTarget()
    70 {
    71     wpe_renderer_backend_egl_offscreen_target_destroy(m_target);
    72 }
    73 
    74 EGLNativeWindowType PlatformDisplayWPE::EGLOffscreenTarget::nativeWindow() const
    75 {
    76     return wpe_renderer_backend_egl_offscreen_target_get_native_window(m_target);
    77 }
    78 
    7960} // namespace WebCore
    8061
  • trunk/Source/WebCore/platform/graphics/wpe/PlatformDisplayWPE.h

    r217123 r217208  
    3030#include "PlatformDisplay.h"
    3131
    32 // FIXME: For now default to the GBM EGL platform, but this should really be
    33 // somehow deducible from the build configuration.
    34 #define __GBM__ 1
    35 #include <EGL/eglplatform.h>
    36 
    3732struct wpe_renderer_backend_egl;
    38 struct wpe_renderer_backend_egl_target;
    39 struct wpe_renderer_backend_egl_offscreen_target;
    4033
    4134namespace WebCore {
    42 
    43 class GLContext;
    44 class IntSize;
    4535
    4636class PlatformDisplayWPE final : public PlatformDisplay {
     
    5040
    5141    void initialize(int);
    52 
    53     class EGLOffscreenTarget {
    54     public:
    55         EGLOffscreenTarget(const PlatformDisplayWPE&);
    56         ~EGLOffscreenTarget();
    57 
    58         EGLNativeWindowType nativeWindow() const;
    59 
    60     private:
    61         struct wpe_renderer_backend_egl_offscreen_target* m_target;
    62     };
    63 
    64     std::unique_ptr<EGLOffscreenTarget> createEGLOffscreenTarget();
    6542
    6643    struct wpe_renderer_backend_egl* backend() const { return m_backend; }
Note: See TracChangeset for help on using the changeset viewer.