Title: [190558] trunk/Source/WebCore
Revision
190558
Author
[email protected]
Date
2015-10-05 00:13:50 -0700 (Mon, 05 Oct 2015)

Log Message

GLContext should control ownership of context-related objects
https://bugs.webkit.org/show_bug.cgi?id=149794

Reviewed by Martin Robinson.

Creation of GLContext objects can depend on various platform-specific
objects like native window representations. Since these objects are
used solely for the GLContext purposes, it would make sense to allow
GLContext to provide an extensible way to impose ownership on these
objects and control their lifetime.

GLContext::Data is declared with a defaulted virtual destructor.
Users of these implementations can declare classes that derive from
GLContext::Data and store context-related objects in instances of the
derived class, and ensure that these objects are properly cleaned up
when GLContext destroys the Data object.

The GLContext::Data object is managed through a protected
std::unique_ptr<> member in the GLContext class. For now the member
is only set in GLContextEGL::createWindowContext() and is destroyed
during the GLContext destruction.

The local OffscreenContextData class in
PlatformDisplayWayland::createSharingGLContext() derives from
GLContext::Data and is used to store the wl_surface and
EGLNativeWindowType (aka wl_egl_window) objects for offscreen
GLContexts under the Wayland platform that are used for the sharing
context and WebGL, effectively avoiding the leak that would further
propagate problems into the compositor and the graphics library.
(Such offscreen contexts are actually mimicked via a 1x1px
wl_egl_window object that acts as a dummy base for the related
wl_surface object).

* platform/graphics/GLContext.h:
* platform/graphics/egl/GLContextEGL.cpp:
(WebCore::GLContextEGL::createWindowContext):
* platform/graphics/egl/GLContextEGL.h:
* platform/graphics/wayland/PlatformDisplayWayland.cpp:
(WebCore::PlatformDisplayWayland::createSharingGLContext):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (190557 => 190558)


--- trunk/Source/WebCore/ChangeLog	2015-10-05 07:04:44 UTC (rev 190557)
+++ trunk/Source/WebCore/ChangeLog	2015-10-05 07:13:50 UTC (rev 190558)
@@ -1,5 +1,47 @@
 2015-10-05  Zan Dobersek  <[email protected]>
 
+        GLContext should control ownership of context-related objects
+        https://bugs.webkit.org/show_bug.cgi?id=149794
+
+        Reviewed by Martin Robinson.
+
+        Creation of GLContext objects can depend on various platform-specific
+        objects like native window representations. Since these objects are
+        used solely for the GLContext purposes, it would make sense to allow
+        GLContext to provide an extensible way to impose ownership on these
+        objects and control their lifetime.
+
+        GLContext::Data is declared with a defaulted virtual destructor.
+        Users of these implementations can declare classes that derive from
+        GLContext::Data and store context-related objects in instances of the
+        derived class, and ensure that these objects are properly cleaned up
+        when GLContext destroys the Data object.
+
+        The GLContext::Data object is managed through a protected
+        std::unique_ptr<> member in the GLContext class. For now the member
+        is only set in GLContextEGL::createWindowContext() and is destroyed
+        during the GLContext destruction.
+
+        The local OffscreenContextData class in
+        PlatformDisplayWayland::createSharingGLContext() derives from
+        GLContext::Data and is used to store the wl_surface and
+        EGLNativeWindowType (aka wl_egl_window) objects for offscreen
+        GLContexts under the Wayland platform that are used for the sharing
+        context and WebGL, effectively avoiding the leak that would further
+        propagate problems into the compositor and the graphics library.
+        (Such offscreen contexts are actually mimicked via a 1x1px
+        wl_egl_window object that acts as a dummy base for the related
+        wl_surface object).
+
+        * platform/graphics/GLContext.h:
+        * platform/graphics/egl/GLContextEGL.cpp:
+        (WebCore::GLContextEGL::createWindowContext):
+        * platform/graphics/egl/GLContextEGL.h:
+        * platform/graphics/wayland/PlatformDisplayWayland.cpp:
+        (WebCore::PlatformDisplayWayland::createSharingGLContext):
+
+2015-10-05  Zan Dobersek  <[email protected]>
+
         Make gdk.h inclusion in FontPlatformDataFreeType.cpp properly GTK-specific
         https://bugs.webkit.org/show_bug.cgi?id=149793
 

Modified: trunk/Source/WebCore/platform/graphics/GLContext.h (190557 => 190558)


--- trunk/Source/WebCore/platform/graphics/GLContext.h	2015-10-05 07:04:44 UTC (rev 190557)
+++ trunk/Source/WebCore/platform/graphics/GLContext.h	2015-10-05 07:13:50 UTC (rev 190558)
@@ -79,6 +79,14 @@
 #if ENABLE(GRAPHICS_CONTEXT_3D)
     virtual PlatformGraphicsContext3D platformContext() = 0;
 #endif
+
+    class Data {
+    public:
+        virtual ~Data() = default;
+    };
+
+protected:
+    std::unique_ptr<Data> m_contextData;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/platform/graphics/egl/GLContextEGL.cpp (190557 => 190558)


--- trunk/Source/WebCore/platform/graphics/egl/GLContextEGL.cpp	2015-10-05 07:04:44 UTC (rev 190557)
+++ trunk/Source/WebCore/platform/graphics/egl/GLContextEGL.cpp	2015-10-05 07:13:50 UTC (rev 190558)
@@ -95,7 +95,7 @@
     return eglChooseConfig(sharedEGLDisplay(), attributeList, config, 1, &numberConfigsReturned) && numberConfigsReturned;
 }
 
-std::unique_ptr<GLContextEGL> GLContextEGL::createWindowContext(EGLNativeWindowType window, GLContext* sharingContext)
+std::unique_ptr<GLContextEGL> GLContextEGL::createWindowContext(EGLNativeWindowType window, GLContext* sharingContext, std::unique_ptr<GLContext::Data>&& contextData)
 {
     EGLContext eglSharingContext = sharingContext ? static_cast<GLContextEGL*>(sharingContext)->m_context : 0;
 
@@ -117,7 +117,9 @@
         return nullptr;
     }
 
-    return std::make_unique<GLContextEGL>(context, surface, WindowSurface);
+    auto glContext = std::make_unique<GLContextEGL>(context, surface, WindowSurface);
+    glContext->m_contextData = WTF::move(contextData);
+    return glContext;
 }
 
 std::unique_ptr<GLContextEGL> GLContextEGL::createPbufferContext(EGLContext sharingContext)

Modified: trunk/Source/WebCore/platform/graphics/egl/GLContextEGL.h (190557 => 190558)


--- trunk/Source/WebCore/platform/graphics/egl/GLContextEGL.h	2015-10-05 07:04:44 UTC (rev 190557)
+++ trunk/Source/WebCore/platform/graphics/egl/GLContextEGL.h	2015-10-05 07:13:50 UTC (rev 190558)
@@ -36,7 +36,7 @@
 public:
     enum EGLSurfaceType { PbufferSurface, WindowSurface, PixmapSurface };
     static std::unique_ptr<GLContextEGL> createContext(EGLNativeWindowType, GLContext* sharingContext = 0);
-    static std::unique_ptr<GLContextEGL> createWindowContext(EGLNativeWindowType, GLContext* sharingContext);
+    static std::unique_ptr<GLContextEGL> createWindowContext(EGLNativeWindowType, GLContext* sharingContext, std::unique_ptr<GLContext::Data>&& = nullptr);
 
     GLContextEGL(EGLContext, EGLSurface, EGLSurfaceType);
 #if PLATFORM(X11)

Modified: trunk/Source/WebCore/platform/graphics/wayland/PlatformDisplayWayland.cpp (190557 => 190558)


--- trunk/Source/WebCore/platform/graphics/wayland/PlatformDisplayWayland.cpp	2015-10-05 07:04:44 UTC (rev 190557)
+++ trunk/Source/WebCore/platform/graphics/wayland/PlatformDisplayWayland.cpp	2015-10-05 07:13:50 UTC (rev 190558)
@@ -131,9 +131,24 @@
 
 std::unique_ptr<GLContextEGL> PlatformDisplayWayland::createSharingGLContext()
 {
-    struct wl_surface* wlSurface = wl_compositor_create_surface(m_compositor);
-    EGLNativeWindowType nativeWindow = wl_egl_window_create(wlSurface, 1, 1);
-    return GLContextEGL::createWindowContext(nativeWindow, nullptr);
+    class OffscreenContextData : public GLContext::Data {
+    public:
+        virtual ~OffscreenContextData()
+        {
+            wl_egl_window_destroy(nativeWindow);
+            wl_surface_destroy(surface);
+        }
+
+        struct wl_surface* surface;
+        EGLNativeWindowType nativeWindow;
+    };
+
+    auto contextData = std::make_unique<OffscreenContextData>();
+    contextData->surface = wl_compositor_create_surface(m_compositor);
+    contextData->nativeWindow = wl_egl_window_create(contextData->surface, 1, 1);
+
+    auto nativeWindow = contextData->nativeWindow;
+    return GLContextEGL::createWindowContext(nativeWindow, nullptr, WTF::move(contextData));
 }
 
 } // namespace WebCore
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to