Title: [224578] trunk/Source/WebCore
Revision
224578
Author
[email protected]
Date
2017-11-08 05:55:46 -0800 (Wed, 08 Nov 2017)

Log Message

[Cairo] Improve PlatformContextCairo lifetime management in GraphicsContextPlatformPrivate
https://bugs.webkit.org/show_bug.cgi?id=179424

Reviewed by Carlos Garcia Campos.

When the PlatformContextCairo object is owned by GraphicsContextPlatformPrivate,
the latter should hold it in a std::unique_ptr<>. When PlatformContextCairo is
not owned, the std::unique_ptr<> should remain null, and the PlatformContextCairo
reference should point to the externally-managed object.

A new GraphicsContextPlatformPrivate constructor accepts a std::unique_ptr<> that
manages a PlatformContextCairo object and moves it into the member variable, tying
lifetime of that PlatformContextCairo object to the private object.

This enables dropping the GraphicsContextPlatformPrivateToplevel class, and the
virtual table is no longer required. Small cleanups to the remaining class are
also performed.

No new tests -- no changes in behavior.

* platform/graphics/cairo/GraphicsContextCairo.cpp:
(WebCore::GraphicsContext::GraphicsContext):
(WebCore::GraphicsContext::platformInit):
(WebCore::GraphicsContext::platformContext const):
* platform/graphics/cairo/GraphicsContextPlatformPrivateCairo.h:
(WebCore::GraphicsContextPlatformPrivate::GraphicsContextPlatformPrivate):
(WebCore::GraphicsContextPlatformPrivate::save):
(WebCore::GraphicsContextPlatformPrivate::restore):
(WebCore::GraphicsContextPlatformPrivate::flush):
(WebCore::GraphicsContextPlatformPrivate::clip):
(WebCore::GraphicsContextPlatformPrivate::scale):
(WebCore::GraphicsContextPlatformPrivate::rotate):
(WebCore::GraphicsContextPlatformPrivate::translate):
(WebCore::GraphicsContextPlatformPrivate::concatCTM):
(WebCore::GraphicsContextPlatformPrivate::setCTM):
(WebCore::GraphicsContextPlatformPrivate::~GraphicsContextPlatformPrivate): Deleted.
(WebCore::GraphicsContextPlatformPrivateToplevel::GraphicsContextPlatformPrivateToplevel): Deleted.
(WebCore::GraphicsContextPlatformPrivateToplevel::~GraphicsContextPlatformPrivateToplevel): Deleted.
* platform/graphics/win/GraphicsContextCairoWin.cpp:
(WebCore::GraphicsContext::platformInit):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (224577 => 224578)


--- trunk/Source/WebCore/ChangeLog	2017-11-08 13:37:51 UTC (rev 224577)
+++ trunk/Source/WebCore/ChangeLog	2017-11-08 13:55:46 UTC (rev 224578)
@@ -1,5 +1,48 @@
 2017-11-08  Zan Dobersek  <[email protected]>
 
+        [Cairo] Improve PlatformContextCairo lifetime management in GraphicsContextPlatformPrivate
+        https://bugs.webkit.org/show_bug.cgi?id=179424
+
+        Reviewed by Carlos Garcia Campos.
+
+        When the PlatformContextCairo object is owned by GraphicsContextPlatformPrivate,
+        the latter should hold it in a std::unique_ptr<>. When PlatformContextCairo is
+        not owned, the std::unique_ptr<> should remain null, and the PlatformContextCairo
+        reference should point to the externally-managed object.
+
+        A new GraphicsContextPlatformPrivate constructor accepts a std::unique_ptr<> that
+        manages a PlatformContextCairo object and moves it into the member variable, tying
+        lifetime of that PlatformContextCairo object to the private object.
+
+        This enables dropping the GraphicsContextPlatformPrivateToplevel class, and the
+        virtual table is no longer required. Small cleanups to the remaining class are
+        also performed.
+
+        No new tests -- no changes in behavior.
+
+        * platform/graphics/cairo/GraphicsContextCairo.cpp:
+        (WebCore::GraphicsContext::GraphicsContext):
+        (WebCore::GraphicsContext::platformInit):
+        (WebCore::GraphicsContext::platformContext const):
+        * platform/graphics/cairo/GraphicsContextPlatformPrivateCairo.h:
+        (WebCore::GraphicsContextPlatformPrivate::GraphicsContextPlatformPrivate):
+        (WebCore::GraphicsContextPlatformPrivate::save):
+        (WebCore::GraphicsContextPlatformPrivate::restore):
+        (WebCore::GraphicsContextPlatformPrivate::flush):
+        (WebCore::GraphicsContextPlatformPrivate::clip):
+        (WebCore::GraphicsContextPlatformPrivate::scale):
+        (WebCore::GraphicsContextPlatformPrivate::rotate):
+        (WebCore::GraphicsContextPlatformPrivate::translate):
+        (WebCore::GraphicsContextPlatformPrivate::concatCTM):
+        (WebCore::GraphicsContextPlatformPrivate::setCTM):
+        (WebCore::GraphicsContextPlatformPrivate::~GraphicsContextPlatformPrivate): Deleted.
+        (WebCore::GraphicsContextPlatformPrivateToplevel::GraphicsContextPlatformPrivateToplevel): Deleted.
+        (WebCore::GraphicsContextPlatformPrivateToplevel::~GraphicsContextPlatformPrivateToplevel): Deleted.
+        * platform/graphics/win/GraphicsContextCairoWin.cpp:
+        (WebCore::GraphicsContext::platformInit):
+
+2017-11-08  Zan Dobersek  <[email protected]>
+
         [Cairo] Move transparency layers Vector to PlatformContextCairo
         https://bugs.webkit.org/show_bug.cgi?id=179420
 

Modified: trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp (224577 => 224578)


--- trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp	2017-11-08 13:37:51 UTC (rev 224577)
+++ trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp	2017-11-08 13:55:46 UTC (rev 224578)
@@ -173,7 +173,7 @@
     if (!cr)
         return;
 
-    m_data = new GraphicsContextPlatformPrivateToplevel(new PlatformContextCairo(cr));
+    m_data = new GraphicsContextPlatformPrivate(std::make_unique<PlatformContextCairo>(cr));
 }
 
 void GraphicsContext::platformInit(PlatformContextCairo* platformContext)
@@ -181,7 +181,7 @@
     if (!platformContext)
         return;
 
-    m_data = new GraphicsContextPlatformPrivate(platformContext);
+    m_data = new GraphicsContextPlatformPrivate(*platformContext);
     m_data->syncContext(platformContext->cr());
 }
 
@@ -208,7 +208,7 @@
 
 PlatformContextCairo* GraphicsContext::platformContext() const
 {
-    return m_data->platformContext;
+    return &m_data->platformContext;
 }
 
 void GraphicsContext::savePlatformState()

Modified: trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextPlatformPrivateCairo.h (224577 => 224578)


--- trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextPlatformPrivateCairo.h	2017-11-08 13:37:51 UTC (rev 224577)
+++ trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextPlatformPrivateCairo.h	2017-11-08 13:55:46 UTC (rev 224578)
@@ -25,8 +25,7 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
  */
 
-#ifndef GraphicsContextPlatformPrivateCairo_h
-#define GraphicsContextPlatformPrivateCairo_h
+#pragma once
 
 #include "GraphicsContext.h"
 
@@ -36,6 +35,7 @@
 #include "RefPtrCairo.h"
 #include <cairo.h>
 #include <math.h>
+#include <memory>
 #include <stdio.h>
 
 #if PLATFORM(WIN)
@@ -46,17 +46,14 @@
 
 class GraphicsContextPlatformPrivate {
 public:
-    GraphicsContextPlatformPrivate(PlatformContextCairo* newPlatformContext)
-        : platformContext(newPlatformContext)
-#if PLATFORM(WIN) || (PLATFORM(GTK) && OS(WINDOWS))
-        // NOTE:  These may note be needed: review and remove once Cairo implementation is complete
-        , m_hdc(0)
-        , m_shouldIncludeChildWindows(false)
-#endif
+    GraphicsContextPlatformPrivate(PlatformContextCairo& platformContext)
+        : platformContext(platformContext)
     {
     }
 
-    virtual ~GraphicsContextPlatformPrivate()
+    GraphicsContextPlatformPrivate(std::unique_ptr<PlatformContextCairo>&& platformContext)
+        : ownedPlatformContext(WTFMove(platformContext))
+        , platformContext(*ownedPlatformContext)
     {
     }
 
@@ -75,46 +72,29 @@
     void syncContext(cairo_t* cr);
 #else
     // On everything else, we do nothing.
-    void save() {}
-    void restore() {}
-    void flush() {}
-    void clip(const FloatRect&) {}
-    void clip(const Path&) {}
-    void scale(const FloatSize&) {}
-    void rotate(float) {}
-    void translate(float, float) {}
-    void concatCTM(const AffineTransform&) {}
-    void setCTM(const AffineTransform&) {}
+    void save() { }
+    void restore() { }
+    void flush() { }
+    void clip(const FloatRect&) { }
+    void clip(const Path&) { }
+    void scale(const FloatSize&) { }
+    void rotate(float) { }
+    void translate(float, float) { }
+    void concatCTM(const AffineTransform&) { }
+    void setCTM(const AffineTransform&) { }
     void syncContext(cairo_t*) { }
 #endif
 
-    PlatformContextCairo* platformContext;
+    std::unique_ptr<PlatformContextCairo> ownedPlatformContext;
+    PlatformContextCairo& platformContext;
 
 #if PLATFORM(WIN) || (PLATFORM(GTK) && OS(WINDOWS))
-    HDC m_hdc;
-    bool m_shouldIncludeChildWindows;
+    // NOTE: These may note be needed: review and remove once Cairo implementation is complete
+    HDC m_hdc { 0 };
+    bool m_shouldIncludeChildWindows { false }
 #endif
 };
 
-// This is a specialized private section for the Cairo GraphicsContext, which knows how
-// to clean up the heap allocated PlatformContextCairo that we must use for the top-level
-// GraphicsContext.
-class GraphicsContextPlatformPrivateToplevel : public GraphicsContextPlatformPrivate {
-public:
-    GraphicsContextPlatformPrivateToplevel(PlatformContextCairo* platformContext)
-        : GraphicsContextPlatformPrivate(platformContext)
-    {
-    }
-
-    virtual ~GraphicsContextPlatformPrivateToplevel()
-    {
-        delete platformContext;
-    }
-};
-
-
 } // namespace WebCore
 
 #endif // USE(CAIRO)
-
-#endif // GraphicsContextPlatformPrivateCairo_h

Modified: trunk/Source/WebCore/platform/graphics/win/GraphicsContextCairoWin.cpp (224577 => 224578)


--- trunk/Source/WebCore/platform/graphics/win/GraphicsContextCairoWin.cpp	2017-11-08 13:37:51 UTC (rev 224577)
+++ trunk/Source/WebCore/platform/graphics/win/GraphicsContextCairoWin.cpp	2017-11-08 13:55:46 UTC (rev 224578)
@@ -79,7 +79,7 @@
 
     cairo_t* cr = createCairoContextWithHDC(dc, hasAlpha);
 
-    m_data = new GraphicsContextPlatformPrivateToplevel(new PlatformContextCairo(cr));
+    m_data = new GraphicsContextPlatformPrivate(std::make_unique<PlatformContextCairo>(cr));
     m_data->m_hdc = dc;
     if (platformContext()->cr()) {
         // Make sure the context starts in sync with our state.
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to