Title: [249604] trunk/Source/WebCore
Revision
249604
Author
[email protected]
Date
2019-09-06 19:39:25 -0700 (Fri, 06 Sep 2019)

Log Message

PathDirect2D Cleanups
https://bugs.webkit.org/show_bug.cgi?id=201534

Reviewed by Fujii Hironori.

1. Add a COMPtr<> move operator.
2. Reduce copying ID2D1Geometry objects.
3. Protect against using the ID2D1PathGeometry after the
   ID2D1GeometrySink's Close operation is used.
4. Add a debug-only 'refCount' function to COMPtr to help
   track down memory errors.

* platform/graphics/Path.h:
(WebCore::Path::activePath const): Deleted.
* platform/graphics/win/Direct2DOperations.cpp:
(WebCore::Direct2D::fillPath):
(WebCore::Direct2D::drawPath):
* platform/graphics/win/PathDirect2D.cpp:
* platform/win/COMPtr.h:
(COMPtr::COMPtr):
(=):
(refCount):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (249603 => 249604)


--- trunk/Source/WebCore/ChangeLog	2019-09-07 01:53:20 UTC (rev 249603)
+++ trunk/Source/WebCore/ChangeLog	2019-09-07 02:39:25 UTC (rev 249604)
@@ -1,3 +1,28 @@
+2019-09-06  Brent Fulgham  <[email protected]>
+
+        PathDirect2D Cleanups
+        https://bugs.webkit.org/show_bug.cgi?id=201534
+
+        Reviewed by Fujii Hironori.
+
+        1. Add a COMPtr<> move operator.
+        2. Reduce copying ID2D1Geometry objects.
+        3. Protect against using the ID2D1PathGeometry after the
+           ID2D1GeometrySink's Close operation is used.
+        4. Add a debug-only 'refCount' function to COMPtr to help
+           track down memory errors.
+
+        * platform/graphics/Path.h:
+        (WebCore::Path::activePath const): Deleted.
+        * platform/graphics/win/Direct2DOperations.cpp:
+        (WebCore::Direct2D::fillPath):
+        (WebCore::Direct2D::drawPath):
+        * platform/graphics/win/PathDirect2D.cpp:
+        * platform/win/COMPtr.h:
+        (COMPtr::COMPtr):
+        (=):
+        (refCount):
+
 2019-09-06  Chris Dumez  <[email protected]>
 
         Move the ResourceLoadObserver logic to WebKit2

Modified: trunk/Source/WebCore/platform/graphics/Path.h (249603 => 249604)


--- trunk/Source/WebCore/platform/graphics/Path.h	2019-09-07 01:53:20 UTC (rev 249603)
+++ trunk/Source/WebCore/platform/graphics/Path.h	2019-09-07 02:39:25 UTC (rev 249604)
@@ -194,14 +194,12 @@
 #endif
 
 #if USE(DIRECT2D)
-        ID2D1GeometrySink* activePath() const { return m_activePath.get(); }
         void appendGeometry(ID2D1Geometry*);
         void createGeometryWithFillMode(WindRule, COMPtr<ID2D1GeometryGroup>&) const;
-        void drawDidComplete();
 
-        HRESULT initializePathState();
         void openFigureAtCurrentPointIfNecessary();
-        void closeAnyOpenGeometries();
+        void closeAnyOpenGeometries(unsigned figureEndStyle) const;
+        void clearGeometries();
 #endif
 
 #ifndef NDEBUG
@@ -210,10 +208,10 @@
 
     private:
 #if USE(DIRECT2D)
+        Vector<ID2D1Geometry*> m_geometries;
         COMPtr<ID2D1GeometryGroup> m_path;
-        COMPtr<ID2D1PathGeometry> m_activePathGeometry;
-        COMPtr<ID2D1GeometrySink> m_activePath;
-        size_t m_openFigureCount { 0 };
+        mutable COMPtr<ID2D1GeometrySink> m_activePath;
+        mutable bool m_figureIsOpened { false };
 #else
         PlatformPathPtr m_path { nullptr };
 #endif

Modified: trunk/Source/WebCore/platform/graphics/win/Direct2DOperations.cpp (249603 => 249604)


--- trunk/Source/WebCore/platform/graphics/win/Direct2DOperations.cpp	2019-09-07 01:53:20 UTC (rev 249603)
+++ trunk/Source/WebCore/platform/graphics/win/Direct2DOperations.cpp	2019-09-07 02:39:25 UTC (rev 249604)
@@ -495,11 +495,7 @@
 
 void fillPath(PlatformContextDirect2D& platformContext, const Path& path, const FillSource& fillSource, const ShadowState& shadowState)
 {
-    if (path.activePath()) {
-        // Make sure it's closed. This might fail if the path was already closed, so
-        // ignore the return value.
-        path.activePath()->Close();
-    }
+    path.closeAnyOpenGeometries(D2D1_FIGURE_END_OPEN);
 
     auto context = platformContext.renderTarget();
 
@@ -582,8 +578,7 @@
 {
     auto context = platformContext.renderTarget();
 
-    if (path.activePath())
-        path.activePath()->Close();
+    path.closeAnyOpenGeometries(D2D1_FIGURE_END_OPEN);
 
     context->SetTags(1, __LINE__);
 

Modified: trunk/Source/WebCore/platform/graphics/win/PathDirect2D.cpp (249603 => 249604)


--- trunk/Source/WebCore/platform/graphics/win/PathDirect2D.cpp	2019-09-07 01:53:20 UTC (rev 249603)
+++ trunk/Source/WebCore/platform/graphics/win/PathDirect2D.cpp	2019-09-07 02:39:25 UTC (rev 249604)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016 Apple Inc.  All rights reserved.
+ * Copyright (C) 2016-2019 Apple Inc.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -62,9 +62,9 @@
 
     path.moveTo(points.first());
 
-    ASSERT(path.activePath());
+    ASSERT(path.m_activePath);
 
-    path.activePath()->AddLines(d2dPoints.data(), d2dPoints.size());
+    path.m_activePath->AddLines(d2dPoints.data(), d2dPoints.size());
     path.closeSubpath();
 
     return path;
@@ -72,7 +72,10 @@
 
 Path::Path() = default;
 
-Path::~Path() = default;
+Path::~Path()
+{
+    clearGeometries();
+}
 
 PlatformPathPtr Path::ensurePlatformPath()
 {
@@ -81,34 +84,41 @@
         ASSERT(SUCCEEDED(hr));
         if (FAILED(hr))
             return nullptr;
+        ASSERT(refCount(m_path.get()) == 1);
     }
 
     return m_path.get();
 }
 
+void Path::clearGeometries()
+{
+    // Manually clean these up so that we can use this vector with Direct2D APIs.
+    for (auto* geometry : m_geometries)
+        geometry->Release();
+    m_geometries.clear();
+}
+
 void Path::appendGeometry(ID2D1Geometry* geometry)
 {
+#if !ASSERT_DISABLED
+    unsigned before = refCount(geometry);
+#endif
+
     unsigned geometryCount = m_path ? m_path->GetSourceGeometryCount() : 0;
-    Vector<ID2D1Geometry*> geometries(geometryCount, nullptr);
 
-    // Note: 'GetSourceGeometries' returns geometries that have a +1 ref count.
-    // so they must be released before we return.
-    if (geometryCount)
-        m_path->GetSourceGeometries(geometries.data(), geometryCount);
+    RELEASE_ASSERT(m_geometries.size() == geometryCount);
 
     geometry->AddRef();
-    geometries.append(geometry);
+    m_geometries.append(geometry);
 
     auto fillMode = m_path ? m_path->GetFillMode() : D2D1_FILL_MODE_WINDING;
 
-    COMPtr<ID2D1GeometryGroup> protectedPath = m_path;
     m_path = nullptr;
 
-    HRESULT hr = GraphicsContext::systemFactory()->CreateGeometryGroup(fillMode, geometries.data(), geometries.size(), &m_path);
+    HRESULT hr = GraphicsContext::systemFactory()->CreateGeometryGroup(fillMode, m_geometries.data(), m_geometries.size(), &m_path);
     RELEASE_ASSERT(SUCCEEDED(hr));
 
-    for (auto entry : geometries)
-        entry->Release();
+    ASSERT(refCount(geometry) == before + 1);
 }
 
 void Path::createGeometryWithFillMode(WindRule webkitFillMode, COMPtr<ID2D1GeometryGroup>& path) const
@@ -124,50 +134,41 @@
 
     unsigned geometryCount = m_path->GetSourceGeometryCount();
 
-    Vector<ID2D1Geometry*> geometries(geometryCount, nullptr);
-    ASSERT(geometryCount);
+    ASSERT(m_geometries.size() == geometryCount);
 
-    // Note: 'GetSourceGeometries' returns geometries that have a +1 ref count.
-    // so they must be released before we return.
-    m_path->GetSourceGeometries(geometries.data(), geometryCount);
-
-    HRESULT hr = GraphicsContext::systemFactory()->CreateGeometryGroup(fillMode, geometries.data(), geometries.size(), &path);
+    HRESULT hr = GraphicsContext::systemFactory()->CreateGeometryGroup(fillMode, const_cast<ID2D1Geometry**>(m_geometries.data()), m_geometries.size(), &path);
     RELEASE_ASSERT(SUCCEEDED(hr));
-
-    for (auto entry : geometries)
-        entry->Release();
+    ASSERT(refCount(path.get()) == 1);
 }
 
 Path::Path(const Path& other)
 {
-    if (other.platformPath() && other.activePath()) {
-        auto otherPath = other.platformPath();
+#if !ASSERT_DISABLED
+    unsigned pathCount = refCount(other.m_path.get());
+    unsigned activePathCount = refCount(other.m_activePath.get());
+#endif
+    m_path = other.m_path;
+    m_activePath = other.m_activePath;
+    m_geometries = other.m_geometries;
+    for (auto* geometry : m_geometries)
+        geometry->AddRef();
 
-        unsigned geometryCount = otherPath->GetSourceGeometryCount();
-
-        Vector<ID2D1Geometry*> geometries(geometryCount, nullptr);
-        ASSERT(geometryCount);
-
-        // Note: 'GetSourceGeometries' returns geometries that have a +1 ref count.
-        // so they must be released before we return.
-        otherPath->GetSourceGeometries(geometries.data(), geometryCount);
-
-        HRESULT hr = GraphicsContext::systemFactory()->CreateGeometryGroup(other.m_path->GetFillMode(), geometries.data(), geometryCount, &m_path);
-        RELEASE_ASSERT(SUCCEEDED(hr));
-
-        for (auto entry : geometries)
-            entry->Release();
-    }
+    ASSERT(!m_path || refCount(m_path.get()) == pathCount + 1);
+    ASSERT(!m_activePath || refCount(m_activePath.get()) == activePathCount + 1);
 }
     
 Path::Path(Path&& other)
 {
-    m_path = other.m_path;
-    m_activePath = other.m_activePath;
-    m_activePathGeometry = other.m_activePathGeometry;
-    other.m_path = nullptr;
-    other.m_activePath = nullptr;
-    other.m_activePathGeometry = nullptr;
+#if !ASSERT_DISABLED
+    unsigned pathCount = refCount(other.m_path.get());
+    unsigned activePathCount = refCount(other.m_activePath.get());
+#endif
+    m_path = WTFMove(other.m_path);
+    m_activePath = WTFMove(other.m_activePath);
+    m_geometries = WTFMove(other.m_geometries);
+
+    ASSERT(refCount(m_path.get()) == pathCount);
+    ASSERT(refCount(m_activePath.get()) == activePathCount);
 }
 
 Path& Path::operator=(const Path& other)
@@ -174,9 +175,19 @@
 {
     if (this == &other)
         return *this;
+#if !ASSERT_DISABLED
+    unsigned pathCount = refCount(other.m_path.get());
+    unsigned activePathCount = refCount(other.m_activePath.get());
+#endif
     m_path = other.m_path;
     m_activePath = other.m_activePath;
-    m_activePathGeometry = other.m_activePathGeometry;
+    m_geometries = other.m_geometries;
+    for (auto* geometry : m_geometries)
+        geometry->AddRef();
+
+    ASSERT(!m_path || refCount(m_path.get()) == pathCount + 1);
+    ASSERT(!m_activePath || refCount(m_activePath.get()) == activePathCount + 1);
+
     return *this;
 }
 
@@ -184,50 +195,21 @@
 {
     if (this == &other)
         return *this;
-    m_path = other.m_path;
-    m_activePath = other.m_activePath;
-    m_activePathGeometry = other.m_activePathGeometry;
-    other.m_path = nullptr;
-    other.m_activePath = nullptr;
-    other.m_activePathGeometry = nullptr;
-    return *this;
-}
 
-HRESULT Path::initializePathState()
-{
-    m_path = nullptr;
-    m_activePath = nullptr;
-    m_activePathGeometry = nullptr;
+#if !ASSERT_DISABLED
+    unsigned pathCount = refCount(other.m_path.get());
+    unsigned activePathCount = refCount(other.m_activePath.get());
+#endif
+    m_path = WTFMove(other.m_path);
+    m_activePath = WTFMove(other.m_activePath);
+    m_geometries = WTFMove(other.m_geometries);
 
-    GraphicsContext::systemFactory()->CreatePathGeometry(&m_activePathGeometry);
+    ASSERT(refCount(m_path.get()) == pathCount);
+    ASSERT(refCount(m_activePath.get()) == activePathCount);
 
-    Vector<ID2D1Geometry*> geometries;
-    geometries.append(m_activePathGeometry.get());
-
-    HRESULT hr = GraphicsContext::systemFactory()->CreateGeometryGroup(D2D1_FILL_MODE_WINDING, geometries.data(), geometries.size(), &m_path);
-    if (FAILED(hr))
-        return hr;
-
-    return m_activePathGeometry->Open(&m_activePath);
+    return *this;
 }
 
-void Path::drawDidComplete()
-{
-    FloatPoint currentPoint = this->currentPoint();
-
-    // To maintain proper semantics with CG, we need to clear our Direct2D
-    // path objects when a draw has finished.
-    HRESULT hr = const_cast<Path*>(this)->initializePathState();
-
-    if (!SUCCEEDED(hr))
-        return;
-
-    m_activePath->SetFillMode(D2D1_FILL_MODE_WINDING);
-
-    m_activePath->BeginFigure(currentPoint, D2D1_FIGURE_BEGIN_FILLED);
-    ++m_openFigureCount;
-}
-
 bool Path::contains(const FloatPoint& point, WindRule rule) const
 {
     if (isNull())
@@ -237,7 +219,7 @@
         return false;
 
     BOOL contains;
-    if (!SUCCEEDED(m_path->FillContainsPoint(D2D1::Point2F(point.x(), point.y()), nullptr, &contains)))
+    if (!SUCCEEDED(m_path->FillContainsPoint(point, nullptr, &contains)))
         return false;
 
     return contains;
@@ -254,28 +236,33 @@
     GraphicsContext scratchContext(&scratchContextD2D, GraphicsContext::BitmapRenderingContextType::GPUMemory);
     applier->strokeStyle(&scratchContext);
 
+#if !ASSERT_DISABLED
+    unsigned before = refCount(m_path.get());
+#endif
+
     BOOL containsPoint = false;
     HRESULT hr = m_path->StrokeContainsPoint(point, scratchContext.strokeThickness(), scratchContext.platformStrokeStyle(), nullptr, 1.0f, &containsPoint);
     if (!SUCCEEDED(hr))
         return false;
 
+    ASSERT(refCount(m_path.get()) == before);
     return containsPoint;
 }
 
-void Path::closeAnyOpenGeometries()
+void Path::closeAnyOpenGeometries(unsigned figureEndStyle) const
 {
-    ASSERT(m_activePath);
+    if (m_figureIsOpened) {
+        ASSERT(m_activePath);
 
-    if (!m_openFigureCount)
-        return;
+        auto endStyle = static_cast<D2D1_FIGURE_END>(figureEndStyle);
+        m_activePath->EndFigure(endStyle);
+        m_figureIsOpened = false;
 
-    while (m_openFigureCount) {
-        m_activePath->EndFigure(D2D1_FIGURE_END_OPEN);
-        --m_openFigureCount;
+        HRESULT hr = m_activePath->Close();
+        ASSERT(SUCCEEDED(hr));
     }
 
-    HRESULT hr = m_activePath->Close();
-    ASSERT(SUCCEEDED(hr));
+    m_activePath = nullptr;
 }
 
 void Path::translate(const FloatSize& size)
@@ -288,49 +275,32 @@
     if (transform.isIdentity() || isEmpty())
         return;
 
-    Optional<FloatPoint> currentPoint;
-    if (hasCurrentPoint())
-        currentPoint = this->currentPoint();
+    if (m_activePath)
+        closeAnyOpenGeometries(D2D1_FIGURE_END_OPEN);
 
-    bool pathIsActive = false;
-    if (m_activePath) {
-        closeAnyOpenGeometries();
-        m_activePath = nullptr;
-        m_activePathGeometry = nullptr;
-        pathIsActive = true;
-    }
+#if !ASSERT_DISABLED
+    unsigned before = refCount(m_path.get());
+#endif
 
     COMPtr<ID2D1TransformedGeometry> transformedPath;
     if (!SUCCEEDED(GraphicsContext::systemFactory()->CreateTransformedGeometry(m_path.get(), transform, &transformedPath)))
         return;
 
-    Vector<ID2D1Geometry*> geometries;
-    geometries.append(transformedPath.get());
+    ASSERT(refCount(m_path.get()) == before);
+    ASSERT(refCount(transformedPath.get()) == 1);
 
-    if (pathIsActive) {
-        GraphicsContext::systemFactory()->CreatePathGeometry(&m_activePathGeometry);
-        m_activePathGeometry->Open(&m_activePath);
-        geometries.append(m_activePathGeometry.get());
-    }
-
     auto fillMode = m_path->GetFillMode();
 
     m_path = nullptr;
 
-    HRESULT hr = GraphicsContext::systemFactory()->CreateGeometryGroup(fillMode, geometries.data(), geometries.size(), &m_path);
-    RELEASE_ASSERT(SUCCEEDED(hr));
+    clearGeometries();
 
-    if (!currentPoint)
-        return;
+    transformedPath->AddRef();
+    m_geometries.append(transformedPath.get());
 
-    if (!m_activePath)
-        return;
-
-    m_activePath->SetFillMode(fillMode);
-
-    auto transformedPoint = transform.mapPoint(currentPoint.value());
-    m_activePath->BeginFigure(transformedPoint, D2D1_FIGURE_BEGIN_FILLED);
-    m_openFigureCount = 1;
+    HRESULT hr = GraphicsContext::systemFactory()->CreateGeometryGroup(fillMode, m_geometries.data(), m_geometries.size(), &m_path);
+    RELEASE_ASSERT(SUCCEEDED(hr));
+    ASSERT(refCount(m_path.get()) == 1);
 }
 
 FloatRect Path::boundingRect() const
@@ -374,38 +344,45 @@
 
 void Path::openFigureAtCurrentPointIfNecessary()
 {
-    if (m_openFigureCount)
+    if (m_figureIsOpened)
         return;
 
+    if (!m_activePath) {
+        COMPtr<ID2D1PathGeometry> activePathGeometry;
+        GraphicsContext::systemFactory()->CreatePathGeometry(&activePathGeometry);
+        HRESULT hr = activePathGeometry->Open(&m_activePath);
+        RELEASE_ASSERT(SUCCEEDED(hr));
+        appendGeometry(activePathGeometry.leakRef());
+        ASSERT(refCount(m_activePath.get()) == 1);
+    }
+
     m_activePath->SetFillMode(D2D1_FILL_MODE_WINDING);
     m_activePath->BeginFigure(currentPoint(), D2D1_FIGURE_BEGIN_FILLED);
-    ++m_openFigureCount;
+    m_figureIsOpened = true;
 }
 
 void Path::moveTo(const FloatPoint& point)
 {
-    if (m_activePath) {
-        closeAnyOpenGeometries();
-        m_activePath = nullptr;
-        m_activePathGeometry = nullptr;
-    }
+    if (m_activePath)
+        closeAnyOpenGeometries(D2D1_FIGURE_END_OPEN);
 
-    GraphicsContext::systemFactory()->CreatePathGeometry(&m_activePathGeometry);
+    COMPtr<ID2D1PathGeometry> activePathGeometry;
+    GraphicsContext::systemFactory()->CreatePathGeometry(&activePathGeometry);
 
-    appendGeometry(m_activePathGeometry.get());
-
-    if (!SUCCEEDED(m_activePathGeometry->Open(&m_activePath)))
+    if (!SUCCEEDED(activePathGeometry->Open(&m_activePath)))
         return;
 
+    appendGeometry(activePathGeometry.leakRef());
+
+    ASSERT(refCount(m_activePath.get()) == 1);
+
     m_activePath->SetFillMode(D2D1_FILL_MODE_WINDING);
     m_activePath->BeginFigure(point, D2D1_FIGURE_BEGIN_FILLED);
-    m_openFigureCount = 1;
+    m_figureIsOpened = true;
 }
 
 void Path::addLineTo(const FloatPoint& point)
 {
-    ASSERT(m_activePath.get());
-
     openFigureAtCurrentPointIfNecessary();
     m_activePath->AddLine(point);
 }
@@ -412,8 +389,6 @@
 
 void Path::addQuadCurveTo(const FloatPoint& cp, const FloatPoint& p)
 {
-    ASSERT(m_activePath.get());
-
     openFigureAtCurrentPointIfNecessary();
     m_activePath->AddQuadraticBezier(D2D1::QuadraticBezierSegment(cp, p));
 }
@@ -420,8 +395,6 @@
 
 void Path::addBezierCurveTo(const FloatPoint& cp1, const FloatPoint& cp2, const FloatPoint& p)
 {
-    ASSERT(m_activePath.get());
-
     openFigureAtCurrentPointIfNecessary();
     m_activePath->AddBezier(D2D1::BezierSegment(cp1, cp2, p));
 }
@@ -495,6 +468,7 @@
         HRESULT hr = GraphicsContext::systemFactory()->CreateRoundedRectangleGeometry(D2D1::RoundedRect(rectToDraw, radiusWidth, radiusHeight), &roundRect);
         RELEASE_ASSERT(SUCCEEDED(hr));
         appendGeometry(roundRect.get());
+        ASSERT(refCount(roundRect.get()) == 2);
         return;
     }
 
@@ -503,27 +477,17 @@
 
 void Path::closeSubpath()
 {
-    if (isNull())
+    if (isNull()) {
+        m_activePath = nullptr;
         return;
+    }
 
     if (!m_activePath) {
-        ASSERT(!m_openFigureCount);
-        ASSERT(!m_activePathGeometry);
+        ASSERT(!m_figureIsOpened);
         return;
     }
 
-    if (!m_openFigureCount)
-        return;
-
-    m_activePath->EndFigure(D2D1_FIGURE_END_CLOSED);
-    --m_openFigureCount;
-    if (m_openFigureCount > 0) {
-        ASSERT(m_activePathGeometry);
-        return;
-    }
-
-    HRESULT hr = m_activePath->Close();
-    ASSERT(SUCCEEDED(hr));
+    closeAnyOpenGeometries(D2D1_FIGURE_END_CLOSED);
 }
 
 static FloatPoint arcStart(const FloatPoint& center, float radius, float startAngle)
@@ -600,6 +564,7 @@
     HRESULT hr = GraphicsContext::systemFactory()->CreateRectangleGeometry(r, &rectangle);
     RELEASE_ASSERT(SUCCEEDED(hr));
     appendGeometry(rectangle.get());
+    ASSERT(refCount(rectangle.get()) == 2);
 }
 
 void Path::addEllipse(FloatPoint p, float radiusX, float radiusY, float rotation, float startAngle, float endAngle, bool anticlockwise)
@@ -620,6 +585,7 @@
     HRESULT hr = GraphicsContext::systemFactory()->CreateEllipseGeometry(D2D1::Ellipse(r.center(), 0.5 * r.width(), 0.5 * r.height()), &ellipse);
     RELEASE_ASSERT(SUCCEEDED(hr));
     appendGeometry(ellipse.get());
+    ASSERT(refCount(ellipse.get()) == 2);
 }
 
 void Path::addPath(const Path& path, const AffineTransform& transform)
@@ -641,7 +607,7 @@
 
     m_path = nullptr;
     m_activePath = nullptr;
-    m_activePathGeometry = nullptr;
+    clearGeometries();
 }
 
 bool Path::isEmpty() const
@@ -652,6 +618,8 @@
     if (!m_path->GetSourceGeometryCount())
         return true;
 
+    ASSERT(m_path->GetSourceGeometryCount() == m_geometries.size());
+
     return false;
 }
 

Modified: trunk/Source/WebCore/platform/win/COMPtr.h (249603 => 249604)


--- trunk/Source/WebCore/platform/win/COMPtr.h	2019-09-07 01:53:20 UTC (rev 249603)
+++ trunk/Source/WebCore/platform/win/COMPtr.h	2019-09-07 02:39:25 UTC (rev 249604)
@@ -46,10 +46,11 @@
 template<typename T> class COMPtr {
 public:
     typedef T* PtrType;
-    COMPtr() : m_ptr(0) { }
+    COMPtr() : m_ptr(nullptr) { }
     COMPtr(T* ptr) : m_ptr(ptr) { if (m_ptr) m_ptr->AddRef(); }
     COMPtr(AdoptCOMTag, T* ptr) : m_ptr(ptr) { }
     COMPtr(const COMPtr& o) : m_ptr(o.m_ptr) { if (T* ptr = m_ptr) ptr->AddRef(); }
+    COMPtr(COMPtr&& o) : m_ptr(o.leakRef()) { }
 
     COMPtr(QueryTag, IUnknown* ptr) : m_ptr(copyQueryInterfaceRef(ptr)) { }
     template<typename U> COMPtr(QueryTag, const COMPtr<U>& ptr) : m_ptr(copyQueryInterfaceRef(ptr.get())) { }
@@ -79,6 +80,7 @@
     operator UnspecifiedBoolType() const { return m_ptr ? &COMPtr::get : 0; }
 
     COMPtr& operator=(const COMPtr&);
+    COMPtr& operator=(COMPtr&&);
     COMPtr& operator=(T*);
     template<typename U> COMPtr& operator=(const COMPtr<U>&);
 
@@ -165,6 +167,14 @@
     return *this;
 }
 
+template<typename T> inline COMPtr<T>& COMPtr<T>::operator=(COMPtr<T>&& o)
+{
+    if (T* ptr = m_ptr)
+        ptr->Release();
+    m_ptr = o.leakRef();
+    return *this;
+}
+
 template<typename T> template<typename U> inline COMPtr<T>& COMPtr<T>::operator=(const COMPtr<U>& o)
 {
     T* optr = o.get();
@@ -218,6 +228,19 @@
     return a != b.get();
 }
 
+#if !ASSERT_DISABLED
+inline unsigned refCount(IUnknown* ptr)
+{
+    if (!ptr)
+        return 0;
+
+    unsigned temp = ptr->AddRef();
+    unsigned value = ptr->Release();
+    ASSERT(temp = value + 1);
+    return value;
+}
+#endif
+
 namespace WTF {
 
 template<typename P> struct IsSmartPtr<COMPtr<P>> {
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to