<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[206815] trunk/Source/WebCore</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/206815">206815</a></dd>
<dt>Author</dt> <dd>bfulgham@apple.com</dd>
<dt>Date</dt> <dd>2016-10-05 10:18:31 -0700 (Wed, 05 Oct 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>[Win][Direct2D] Add initial D2D Path and Gradient implementation
https://bugs.webkit.org/show_bug.cgi?id=162923

Reviewed by Alex Christensen.

This patch lands a set of new files that implements initial Path
and Gradient features on Windows using Direct2D.

No new tests until complete backend lands.

* platform/graphics/Gradient.h:
* platform/graphics/Path.cpp:
* platform/graphics/Path.h:
* platform/graphics/win/GradientDirect2D.cpp: Added.
* platform/graphics/win/PathDirect2D.cpp: Added.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsGradienth">trunk/Source/WebCore/platform/graphics/Gradient.h</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsPathcpp">trunk/Source/WebCore/platform/graphics/Path.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsPathh">trunk/Source/WebCore/platform/graphics/Path.h</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreplatformgraphicswinGradientDirect2Dcpp">trunk/Source/WebCore/platform/graphics/win/GradientDirect2D.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicswinPathDirect2Dcpp">trunk/Source/WebCore/platform/graphics/win/PathDirect2D.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (206814 => 206815)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-10-05 16:46:19 UTC (rev 206814)
+++ trunk/Source/WebCore/ChangeLog        2016-10-05 17:18:31 UTC (rev 206815)
</span><span class="lines">@@ -1,3 +1,21 @@
</span><ins>+2016-10-05  Brent Fulgham  &lt;bfulgham@apple.com&gt;
+
+        [Win][Direct2D] Add initial D2D Path and Gradient implementation
+        https://bugs.webkit.org/show_bug.cgi?id=162923
+
+        Reviewed by Alex Christensen.
+
+        This patch lands a set of new files that implements initial Path
+        and Gradient features on Windows using Direct2D.
+
+        No new tests until complete backend lands.
+
+        * platform/graphics/Gradient.h:
+        * platform/graphics/Path.cpp:
+        * platform/graphics/Path.h:
+        * platform/graphics/win/GradientDirect2D.cpp: Added.
+        * platform/graphics/win/PathDirect2D.cpp: Added.
+
</ins><span class="cx"> 2016-10-05  Romain Bellessort  &lt;romain.bellessort@crf.canon.fr&gt;
</span><span class="cx"> 
</span><span class="cx">         [Readable Streams API] Align function names with spec
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsGradienth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/Gradient.h (206814 => 206815)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/Gradient.h        2016-10-05 16:46:19 UTC (rev 206814)
+++ trunk/Source/WebCore/platform/graphics/Gradient.h        2016-10-05 17:18:31 UTC (rev 206815)
</span><span class="lines">@@ -41,6 +41,10 @@
</span><span class="cx"> typedef struct CGGradient* CGGradientRef;
</span><span class="cx"> typedef CGGradientRef PlatformGradient;
</span><span class="cx"> 
</span><ins>+#elif USE(DIRECT2D)
+interface ID2D1Brush;
+interface ID2D1RenderTarget;
+typedef ID2D1Brush* PlatformGradient;
</ins><span class="cx"> #elif USE(CAIRO)
</span><span class="cx"> typedef struct _cairo_pattern cairo_pattern_t;
</span><span class="cx"> typedef cairo_pattern_t* PlatformGradient;
</span><span class="lines">@@ -159,6 +163,8 @@
</span><span class="cx"> #if USE(CG)
</span><span class="cx">         void paint(CGContextRef);
</span><span class="cx">         void paint(GraphicsContext*);
</span><ins>+#elif USE(DIRECT2D)
+        PlatformGradient createPlatformGradientIfNecessary(ID2D1RenderTarget*);
</ins><span class="cx"> #elif USE(CAIRO)
</span><span class="cx">         PlatformGradient platformGradient(float globalAlpha);
</span><span class="cx"> #endif
</span><span class="lines">@@ -167,11 +173,15 @@
</span><span class="cx">         WEBCORE_EXPORT Gradient(const FloatPoint&amp; p0, const FloatPoint&amp; p1);
</span><span class="cx">         Gradient(const FloatPoint&amp; p0, float r0, const FloatPoint&amp; p1, float r1, float aspectRatio);
</span><span class="cx"> 
</span><del>-        void platformInit() { m_gradient = 0; }
</del><ins>+        void platformInit() { m_gradient = nullptr; }
</ins><span class="cx">         void platformDestroy();
</span><span class="cx"> 
</span><span class="cx">         void sortStopsIfNecessary();
</span><span class="cx"> 
</span><ins>+#if USE(DIRECT2D)
+        void generateGradient(ID2D1RenderTarget*);
+#endif
+
</ins><span class="cx">         // Keep any parameters relevant to rendering in sync with the structure in Gradient::hash().
</span><span class="cx">         bool m_radial;
</span><span class="cx">         FloatPoint m_p0;
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsPathcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/Path.cpp (206814 => 206815)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/Path.cpp        2016-10-05 16:46:19 UTC (rev 206814)
+++ trunk/Source/WebCore/platform/graphics/Path.cpp        2016-10-05 17:18:31 UTC (rev 206815)
</span><span class="lines">@@ -158,7 +158,7 @@
</span><span class="cx">     closeSubpath();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-#if !USE(CG)
</del><ins>+#if !USE(CG) &amp;&amp; !USE(DIRECT2D)
</ins><span class="cx"> Path Path::polygonPathFromPoints(const Vector&lt;FloatPoint&gt;&amp; points)
</span><span class="cx"> {
</span><span class="cx">     Path path;
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsPathh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/Path.h (206814 => 206815)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/Path.h        2016-10-05 16:46:19 UTC (rev 206814)
+++ trunk/Source/WebCore/platform/graphics/Path.h        2016-10-05 17:18:31 UTC (rev 206815)
</span><span class="lines">@@ -1,6 +1,6 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2003, 2006, 2009 Apple Inc. All rights reserved.
- *               2006 Rob Buis &lt;buis@kde.org&gt;
</del><ins>+ * Copyright (C) 2003, 2006, 2009, 2016 Apple Inc. All rights reserved.
+ * Copyright (C) 2006 Rob Buis &lt;buis@kde.org&gt;
</ins><span class="cx">  * Copyright (C) 2007-2008 Torch Mobile, Inc.
</span><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="lines">@@ -41,6 +41,16 @@
</span><span class="cx"> #include &lt;CoreGraphics/CGPath.h&gt;
</span><span class="cx"> typedef struct CGPath PlatformPath;
</span><span class="cx"> 
</span><ins>+#elif USE(DIRECT2D)
+#include &quot;COMPtr.h&quot;
+
+interface ID2D1Geometry;
+interface ID2D1GeometryGroup;
+interface ID2D1PathGeometry;
+interface ID2D1GeometrySink;
+
+typedef ID2D1GeometryGroup PlatformPath;
+
</ins><span class="cx"> #elif USE(CAIRO)
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="lines">@@ -171,16 +181,29 @@
</span><span class="cx"> 
</span><span class="cx">         void addBeziersForRoundedRect(const FloatRect&amp;, const FloatSize&amp; topLeftRadius, const FloatSize&amp; topRightRadius, const FloatSize&amp; bottomLeftRadius, const FloatSize&amp; bottomRightRadius);
</span><span class="cx"> 
</span><del>-#if USE(CG)
</del><ins>+#if USE(CG) || USE(DIRECT2D)
</ins><span class="cx">         void platformAddPathForRoundedRect(const FloatRect&amp;, const FloatSize&amp; topLeftRadius, const FloatSize&amp; topRightRadius, const FloatSize&amp; bottomLeftRadius, const FloatSize&amp; bottomRightRadius);
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+#if USE(DIRECT2D)
+        ID2D1GeometrySink* activePath() const { return m_activePath.get(); }
+        void appendGeometry(ID2D1Geometry*);
+        void createGeometryWithFillMode(WindRule, COMPtr&lt;ID2D1GeometryGroup&gt;&amp;) const;
+        void drawDidComplete() const;
+
+        HRESULT initializePathState();
+#endif
+
</ins><span class="cx"> #ifndef NDEBUG
</span><span class="cx">         void dump() const;
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     private:
</span><del>-        PlatformPathPtr m_path;
</del><ins>+        PlatformPathPtr m_path { nullptr };
+#if USE(DIRECT2D)
+        COMPtr&lt;ID2D1PathGeometry&gt; m_activePathGeometry;
+        COMPtr&lt;ID2D1GeometrySink&gt; m_activePath;
+#endif
</ins><span class="cx">     };
</span><span class="cx"> 
</span><span class="cx"> TextStream&amp; operator&lt;&lt;(TextStream&amp;, const Path&amp;);
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicswinGradientDirect2Dcpp"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/platform/graphics/win/GradientDirect2D.cpp (0 => 206815)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/win/GradientDirect2D.cpp                                (rev 0)
+++ trunk/Source/WebCore/platform/graphics/win/GradientDirect2D.cpp        2016-10-05 17:18:31 UTC (rev 206815)
</span><span class="lines">@@ -0,0 +1,133 @@
</span><ins>+/*
+ * Copyright (C) 2016 Apple Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#include &quot;config.h&quot;
+#include &quot;Gradient.h&quot;
+
+#include &quot;FloatPoint.h&quot;
+#include &quot;GraphicsContext.h&quot;
+#include &lt;d2d1.h&gt;
+#include &lt;wtf/RetainPtr.h&gt;
+
+#define GRADIENT_DRAWING 3
+
+namespace WebCore {
+
+void Gradient::platformDestroy()
+{
+    if (m_gradient)
+        m_gradient-&gt;Release();
+    m_gradient = nullptr;
+}
+
+ID2D1Brush* Gradient::platformGradient()
+{
+    ASSERT(m_gradient);
+    return m_gradient;
+}
+
+ID2D1Brush* Gradient::createPlatformGradientIfNecessary(ID2D1RenderTarget* context)
+{
+    generateGradient(context);
+    return m_gradient;
+}
+
+void Gradient::generateGradient(ID2D1RenderTarget* renderTarget)
+{
+    sortStopsIfNecessary();
+
+    Vector&lt;D2D1_GRADIENT_STOP&gt; gradientStops;
+    for (auto stop : m_stops)
+        gradientStops.append(D2D1::GradientStop(stop.stop, D2D1::ColorF(stop.red, stop.green, stop.blue, stop.alpha)));
+
+    COMPtr&lt;ID2D1GradientStopCollection&gt; gradientStopCollection;
+    HRESULT hr = renderTarget-&gt;CreateGradientStopCollection(gradientStops.data(), gradientStops.size(), &amp;gradientStopCollection);
+    RELEASE_ASSERT(SUCCEEDED(hr));
+
+    if (m_radial) {
+        ID2D1RadialGradientBrush* radialGradient = nullptr;
+        hr = renderTarget-&gt;CreateRadialGradientBrush(
+            D2D1::RadialGradientBrushProperties(p0(), p1(), startRadius(), endRadius()),
+            D2D1::BrushProperties(), gradientStopCollection.get(),
+            &amp;radialGradient);
+        RELEASE_ASSERT(SUCCEEDED(hr));
+        m_gradient = radialGradient;
+    } else {
+        ID2D1LinearGradientBrush* linearGradient = nullptr;
+        hr = renderTarget-&gt;CreateLinearGradientBrush(
+            D2D1::LinearGradientBrushProperties(p0(), p1()),
+            D2D1::BrushProperties(), gradientStopCollection.get(),
+            &amp;linearGradient);
+        RELEASE_ASSERT(SUCCEEDED(hr));
+        m_gradient = linearGradient;
+    }
+
+    hash();
+}
+
+void Gradient::fill(GraphicsContext* context, const FloatRect&amp; rect)
+{
+    auto d2dContext = context-&gt;platformContext();
+
+    bool needScaling = aspectRatio() != 1;
+    if (needScaling) {
+        context-&gt;save();
+        // Scale from the center of the gradient. We only ever scale non-deprecated gradients,
+        // for which m_p0 == m_p1.
+        ASSERT(m_p0 == m_p1);
+
+        D2D1_MATRIX_3X2_F ctm;
+        d2dContext-&gt;GetTransform(&amp;ctm);
+
+        AffineTransform transform(ctm);
+        transform.translate(m_p0);
+        transform.scaleNonUniform(1.0, 1.0 / aspectRatio());
+        transform.translate(-m_p0);
+
+        d2dContext-&gt;SetTransform(ctm);
+    }
+
+    if (!m_cachedHash)
+        generateGradient(d2dContext);
+
+    if (!context-&gt;didBeginDraw())
+        d2dContext-&gt;BeginDraw();
+
+    d2dContext-&gt;SetTags(GRADIENT_DRAWING, __LINE__);
+
+    const D2D1_RECT_F d2dRect = rect;
+    d2dContext-&gt;FillRectangle(&amp;d2dRect, m_gradient);
+
+    if (!context-&gt;didBeginDraw()) {
+        D2D1_TAG first, second;
+        HRESULT hr = d2dContext-&gt;EndDraw(&amp;first, &amp;second);
+        RELEASE_ASSERT(SUCCEEDED(hr));
+    }
+
+    if (needScaling)
+        context-&gt;restore();
+}
+
+}
</ins></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicswinPathDirect2Dcpp"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/platform/graphics/win/PathDirect2D.cpp (0 => 206815)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/win/PathDirect2D.cpp                                (rev 0)
+++ trunk/Source/WebCore/platform/graphics/win/PathDirect2D.cpp        2016-10-05 17:18:31 UTC (rev 206815)
</span><span class="lines">@@ -0,0 +1,517 @@
</span><ins>+/*
+ * Copyright (C) 2016 Apple Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#include &quot;config.h&quot;
+#include &quot;Path.h&quot;
+
+#if USE(DIRECT2D)
+
+#include &quot;AffineTransform.h&quot;
+#include &quot;COMPtr.h&quot;
+#include &quot;FloatRect.h&quot;
+#include &quot;GraphicsContext.h&quot;
+#include &quot;IntRect.h&quot;
+#include &quot;NotImplemented.h&quot;
+#include &quot;StrokeStyleApplier.h&quot;
+#include &lt;d2d1.h&gt;
+#include &lt;wtf/MathExtras.h&gt;
+#include &lt;wtf/RetainPtr.h&gt;
+#include &lt;wtf/text/WTFString.h&gt;
+
+namespace WebCore {
+
+
+Path Path::polygonPathFromPoints(const Vector&lt;FloatPoint&gt;&amp; points)
+{
+    Path path;
+    if (points.size() &lt; 2)
+        return path;
+
+    Vector&lt;D2D1_POINT_2F, 32&gt; d2dPoints;
+    d2dPoints.reserveInitialCapacity(points.size() - 1);
+    for (auto point : points)
+        d2dPoints.uncheckedAppend(D2D1::Point2F(point.x(), point.y()));
+
+    path.moveTo(points.first());
+
+    ASSERT(path.activePath());
+
+    path.activePath()-&gt;AddLines(d2dPoints.data(), d2dPoints.size());
+    path.closeSubpath();
+
+    return path;
+}
+
+Path::Path()
+{
+}
+
+Path::~Path()
+{
+}
+
+PlatformPathPtr Path::ensurePlatformPath()
+{
+    if (!m_path) {
+        HRESULT hr = GraphicsContext::systemFactory()-&gt;CreateGeometryGroup(D2D1_FILL_MODE_WINDING, nullptr, 0, &amp;m_path);
+        ASSERT(SUCCEEDED(hr));
+        if (FAILED(hr))
+            return nullptr;
+    }
+
+    return m_path;
+}
+
+void Path::appendGeometry(ID2D1Geometry* geometry)
+{
+    unsigned geometryCount = m_path ? m_path-&gt;GetSourceGeometryCount() : 0;
+    Vector&lt;ID2D1Geometry*&gt; geometries(geometryCount, nullptr);
+
+    if (geometryCount)
+        m_path-&gt;GetSourceGeometries(geometries.data(), geometryCount);
+
+    geometries.append(geometry);
+
+    auto fillMode = m_path ? m_path-&gt;GetFillMode() : D2D1_FILL_MODE_WINDING;
+
+    COMPtr&lt;ID2D1GeometryGroup&gt; protectedPath = m_path;
+    m_path = nullptr;
+
+    HRESULT hr = GraphicsContext::systemFactory()-&gt;CreateGeometryGroup(fillMode, geometries.data(), geometries.size(), &amp;m_path);
+    RELEASE_ASSERT(SUCCEEDED(hr));
+}
+
+void Path::createGeometryWithFillMode(WindRule webkitFillMode, COMPtr&lt;ID2D1GeometryGroup&gt;&amp; path) const
+{
+    RELEASE_ASSERT(m_path);
+
+    auto fillMode = (webkitFillMode == RULE_EVENODD) ? D2D1_FILL_MODE_ALTERNATE : D2D1_FILL_MODE_WINDING;
+
+    if (fillMode == m_path-&gt;GetFillMode()) {
+        path = m_path;
+        return;
+    }
+
+    unsigned geometryCount = m_path-&gt;GetSourceGeometryCount();
+
+    Vector&lt;ID2D1Geometry*&gt; geometries(geometryCount, nullptr);
+    ASSERT(geometryCount);
+    m_path-&gt;GetSourceGeometries(geometries.data(), geometryCount);
+
+    HRESULT hr = GraphicsContext::systemFactory()-&gt;CreateGeometryGroup(fillMode, geometries.data(), geometries.size(), &amp;path);
+    RELEASE_ASSERT(SUCCEEDED(hr));
+}
+
+Path::Path(const Path&amp; other)
+{
+    if (other.platformPath() &amp;&amp; other.activePath()) {
+        auto otherPath = other.platformPath();
+
+        unsigned geometryCount = otherPath-&gt;GetSourceGeometryCount();
+
+        Vector&lt;ID2D1Geometry*&gt; geometries(geometryCount, nullptr);
+        ASSERT(geometryCount);
+        otherPath-&gt;GetSourceGeometries(geometries.data(), geometryCount);
+
+        HRESULT hr = GraphicsContext::systemFactory()-&gt;CreateGeometryGroup(other.m_path-&gt;GetFillMode(), geometries.data(), geometryCount, &amp;m_path);
+        RELEASE_ASSERT(SUCCEEDED(hr));
+    }
+}
+
+Path&amp; Path::operator=(const Path&amp; other)
+{
+    m_path = other.m_path;
+    if (m_path)
+        m_path-&gt;AddRef();
+
+    m_activePath = other.m_activePath;
+    m_activePathGeometry = other.m_activePathGeometry;
+
+    return *this;
+}
+
+HRESULT Path::initializePathState()
+{
+    if (m_path)
+        m_path-&gt;Release();
+    m_path = nullptr;
+    m_activePath = nullptr;
+    m_activePathGeometry = nullptr;
+
+    GraphicsContext::systemFactory()-&gt;CreatePathGeometry(&amp;m_activePathGeometry);
+
+    Vector&lt;ID2D1Geometry*&gt; geometries;
+    geometries.append(m_activePathGeometry.get());
+
+    HRESULT hr = GraphicsContext::systemFactory()-&gt;CreateGeometryGroup(D2D1_FILL_MODE_WINDING, geometries.data(), geometries.size(), &amp;m_path);
+    if (FAILED(hr))
+        return hr;
+
+    return m_activePathGeometry-&gt;Open(&amp;m_activePath);
+}
+
+void Path::drawDidComplete() const
+{
+    FloatPoint currentPoint = this-&gt;currentPoint();
+
+    // To maintain proper semantics with CG, we need to clear our Direct2D
+    // path objects when a draw has finished.
+    HRESULT hr = const_cast&lt;Path*&gt;(this)-&gt;initializePathState();
+
+    if (!SUCCEEDED(hr))
+        return;
+
+    m_activePath-&gt;SetFillMode(D2D1_FILL_MODE_WINDING);
+
+    m_activePath-&gt;BeginFigure(currentPoint, D2D1_FIGURE_BEGIN_FILLED);
+}
+
+bool Path::contains(const FloatPoint&amp; point, WindRule rule) const
+{
+    if (isNull())
+        return false;
+
+    if (!fastBoundingRect().contains(point))
+        return false;
+
+    BOOL contains;
+    if (!SUCCEEDED(m_path-&gt;FillContainsPoint(D2D1::Point2F(point.x(), point.y()), nullptr, &amp;contains)))
+        return false;
+
+    return contains;
+}
+
+bool Path::strokeContains(StrokeStyleApplier* applier, const FloatPoint&amp; point) const
+{
+    if (isNull())
+        return false;
+
+    UNUSED_PARAM(applier);
+    UNUSED_PARAM(point);
+    notImplemented();
+    return false;
+}
+
+void Path::translate(const FloatSize&amp; size)
+{
+    transform(AffineTransform(1, 0, 0, 1, size.width(), size.height()));
+}
+
+void Path::transform(const AffineTransform&amp; transform)
+{
+    if (transform.isIdentity() || isEmpty())
+        return;
+
+    bool pathIsActive = false;
+    if (m_activePath) {
+        m_activePath-&gt;Close();
+        m_activePath = nullptr;
+        m_activePathGeometry = nullptr;
+        pathIsActive = true;
+    }
+
+    const D2D1_MATRIX_3X2_F&amp; d2dTransform = static_cast&lt;const D2D1_MATRIX_3X2_F&gt;(transform);
+    COMPtr&lt;ID2D1TransformedGeometry&gt; transformedPath;
+    if (!SUCCEEDED(GraphicsContext::systemFactory()-&gt;CreateTransformedGeometry(m_path, d2dTransform, &amp;transformedPath)))
+        return;
+
+    Vector&lt;ID2D1Geometry*&gt; geometries;
+    geometries.append(transformedPath.get());
+
+    if (pathIsActive) {
+        GraphicsContext::systemFactory()-&gt;CreatePathGeometry(&amp;m_activePathGeometry);
+        m_activePathGeometry-&gt;Open(&amp;m_activePath);
+        geometries.append(m_activePathGeometry.get());
+    }
+
+    auto fillMode = m_path-&gt;GetFillMode();
+
+    m_path-&gt;Release();
+    m_path = nullptr;
+
+    HRESULT hr = GraphicsContext::systemFactory()-&gt;CreateGeometryGroup(fillMode, geometries.data(), geometries.size(), &amp;m_path);
+    RELEASE_ASSERT(SUCCEEDED(hr));
+}
+
+FloatRect Path::boundingRect() const
+{
+    if (isNull())
+        return FloatRect();
+
+    D2D1_RECT_F bounds = { };
+    if (!SUCCEEDED(m_path-&gt;GetBounds(nullptr, &amp;bounds)))
+        return FloatRect();
+
+    return FloatRect(bounds.left, bounds.bottom, bounds.right - bounds.left, bounds.top - bounds.bottom);
+}
+
+FloatRect Path::fastBoundingRect() const
+{
+    if (isNull())
+        return FloatRect();
+
+    D2D1_RECT_F bounds = { };
+    if (!SUCCEEDED(m_path-&gt;GetBounds(nullptr, &amp;bounds)))
+        return FloatRect();
+
+    return FloatRect(bounds.left, bounds.bottom, bounds.right - bounds.left, bounds.top - bounds.bottom);
+}
+
+FloatRect Path::strokeBoundingRect(StrokeStyleApplier* applier) const
+{
+    if (isNull())
+        return FloatRect();
+
+    UNUSED_PARAM(applier);
+    notImplemented();
+    return FloatRect();
+}
+
+void Path::moveTo(const FloatPoint&amp; point)
+{
+    if (!m_activePath) {
+        GraphicsContext::systemFactory()-&gt;CreatePathGeometry(&amp;m_activePathGeometry);
+
+        appendGeometry(m_activePathGeometry.get());
+
+        if (!SUCCEEDED(m_activePathGeometry-&gt;Open(&amp;m_activePath)))
+            return;
+
+        m_activePath-&gt;SetFillMode(D2D1_FILL_MODE_WINDING);
+    }
+
+    m_activePath-&gt;BeginFigure(point, D2D1_FIGURE_BEGIN_FILLED);
+}
+
+void Path::addLineTo(const FloatPoint&amp; point)
+{
+    ASSERT(m_activePath.get());
+
+    m_activePath-&gt;AddLine(point);
+}
+
+void Path::addQuadCurveTo(const FloatPoint&amp; cp, const FloatPoint&amp; p)
+{
+    ASSERT(m_activePath.get());
+
+    m_activePath-&gt;AddQuadraticBezier(D2D1::QuadraticBezierSegment(cp, p));
+}
+
+void Path::addBezierCurveTo(const FloatPoint&amp; cp1, const FloatPoint&amp; cp2, const FloatPoint&amp; p)
+{
+    ASSERT(m_activePath.get());
+
+    FloatPoint beforePoint = currentPoint();
+
+    m_activePath-&gt;AddBezier(D2D1::BezierSegment(cp1, cp2, p));
+}
+
+void Path::addArcTo(const FloatPoint&amp; p1, const FloatPoint&amp; p2, float radius)
+{
+    UNUSED_PARAM(p1);
+    UNUSED_PARAM(p2);
+    UNUSED_PARAM(radius);
+    notImplemented();
+}
+
+static equalRadiusWidths(const FloatSize&amp; topLeftRadius, const FloatSize&amp; topRightRadius, const FloatSize&amp; bottomLeftRadius, const FloatSize&amp; bottomRightRadius)
+{
+    return topLeftRadius.width() == topRightRadius.width()
+        &amp;&amp; topRightRadius.width() == bottomLeftRadius.width()
+        &amp;&amp; bottomLeftRadius.width() == bottomRightRadius.width();
+}
+
+static equalRadiusHeights(const FloatSize&amp; topLeftRadius, const FloatSize&amp; topRightRadius, const FloatSize&amp; bottomLeftRadius, const FloatSize&amp; bottomRightRadius)
+{
+    return topLeftRadius.height() == bottomLeftRadius.height()
+        &amp;&amp; bottomLeftRadius.height() == topRightRadius.height()
+        &amp;&amp; topRightRadius.height() == bottomRightRadius.height();
+}
+
+void Path::platformAddPathForRoundedRect(const FloatRect&amp; rect, const FloatSize&amp; topLeftRadius, const FloatSize&amp; topRightRadius, const FloatSize&amp; bottomLeftRadius, const FloatSize&amp; bottomRightRadius)
+{
+    bool equalWidths = equalRadiusWidths(topLeftRadius, topRightRadius, bottomLeftRadius, bottomRightRadius);
+    bool equalHeights = equalRadiusHeights(topLeftRadius, topRightRadius, bottomLeftRadius, bottomRightRadius);
+
+    if (equalWidths &amp;&amp; equalHeights) {
+        // Ensure that CG can render the rounded rect.
+        float radiusWidth = topLeftRadius.width();
+        float radiusHeight = topLeftRadius.height();
+        auto rectToDraw = D2D1::RectF(rect.x(), rect.y(), rect.maxX(), rect.maxY());
+
+        COMPtr&lt;ID2D1RoundedRectangleGeometry&gt; roundRect;
+        HRESULT hr = GraphicsContext::systemFactory()-&gt;CreateRoundedRectangleGeometry(D2D1::RoundedRect(rectToDraw, radiusWidth, radiusHeight), &amp;roundRect);
+        RELEASE_ASSERT(SUCCEEDED(hr));
+        appendGeometry(roundRect.get());
+        return;
+    }
+
+    addBeziersForRoundedRect(rect, topLeftRadius, topRightRadius, bottomLeftRadius, bottomRightRadius);
+}
+
+void Path::closeSubpath()
+{
+    if (isNull())
+        return;
+
+    ASSERT(m_activePath.get());
+    m_activePath-&gt;EndFigure(D2D1_FIGURE_END_OPEN);
+}
+
+static void drawArcSection(ID2D1GeometrySink* sink, FloatPoint center, float radius, float startAngle, float endAngle, bool clockwise)
+{
+    // Direct2D wants us to specify the end point of the arc, not the center. It will be drawn from
+    // whatever the current point in the 'm_activePath' is.
+    FloatPoint p = center;
+    float endX = radius * std::cos(endAngle);
+    float endY = radius * std::sin(endAngle);
+    p.move(endX, endY);
+
+    float arcDeg = rad2deg(endAngle - startAngle);
+    D2D1_SWEEP_DIRECTION direction = clockwise ? D2D1_SWEEP_DIRECTION_CLOCKWISE : D2D1_SWEEP_DIRECTION_COUNTER_CLOCKWISE;
+    sink-&gt;AddArc(D2D1::ArcSegment(p, D2D1::SizeF(radius, radius), arcDeg, direction, D2D1_ARC_SIZE_SMALL));
+}
+
+void Path::addArc(const FloatPoint&amp; center, float radius, float startAngle, float endAngle, bool clockwise)
+{
+    if (!m_activePath) {
+        float startX = radius * std::cos(startAngle);
+        float startY = radius * std::sin(startAngle);
+
+        FloatPoint start = center;
+        start.move(startX, startY);
+        moveTo(start);
+    }
+
+    // Direct2D has problems drawing large arcs. It gets confused if drawing a complete (or
+    // nearly complete) circle in the counter-clockwise direction. So, draw any arcs larger
+    // than 180 degrees in two pieces.
+    float fullSweep = endAngle - startAngle;
+    float negate = fullSweep &lt; 0 ? -1.0f : 1.0f;
+    float maxSweep = negate * std::min(std::abs(fullSweep), piFloat);
+    float firstArcEnd = startAngle + maxSweep;
+    drawArcSection(m_activePath.get(), center, radius, startAngle, firstArcEnd, clockwise);
+
+    if (areEssentiallyEqual(firstArcEnd, endAngle))
+        return;
+
+    drawArcSection(m_activePath.get(), center, radius, firstArcEnd, endAngle, clockwise);
+}
+
+void Path::addRect(const FloatRect&amp; r)
+{
+    COMPtr&lt;ID2D1RectangleGeometry&gt; rectangle;
+    HRESULT hr = GraphicsContext::systemFactory()-&gt;CreateRectangleGeometry(static_cast&lt;D2D1_RECT_F&gt;(r), &amp;rectangle);
+    RELEASE_ASSERT(SUCCEEDED(hr));
+    appendGeometry(rectangle.get());
+}
+
+void Path::addEllipse(FloatPoint p, float radiusX, float radiusY, float rotation, float startAngle, float endAngle, bool anticlockwise)
+{
+    AffineTransform transform;
+    transform.translate(p.x(), p.y()).rotate(rad2deg(rotation)).scale(radiusX, radiusY);
+
+    notImplemented();
+}
+
+void Path::addEllipse(const FloatRect&amp; r)
+{
+    COMPtr&lt;ID2D1EllipseGeometry&gt; ellipse;
+    HRESULT hr = GraphicsContext::systemFactory()-&gt;CreateEllipseGeometry(D2D1::Ellipse(D2D1::Point2F(r.center().x(), r.center().y()), r.width(), r.height()), &amp;ellipse);
+    RELEASE_ASSERT(SUCCEEDED(hr));
+    appendGeometry(ellipse.get());
+}
+
+void Path::addPath(const Path&amp; path, const AffineTransform&amp; transform)
+{
+    if (!path.platformPath())
+        return;
+
+    if (!transform.isInvertible())
+        return;
+
+    notImplemented();
+}
+
+
+void Path::clear()
+{
+    if (isNull())
+        return;
+
+    if (m_path)
+        m_path-&gt;Release();
+
+    m_path = nullptr;
+    m_activePath = nullptr;
+    m_activePathGeometry = nullptr;
+}
+
+bool Path::isEmpty() const
+{
+    if (isNull())
+        return true;
+
+    if (!m_path-&gt;GetSourceGeometryCount())
+        return true;
+
+    return false;
+}
+
+bool Path::hasCurrentPoint() const
+{
+    return !isEmpty();
+}
+    
+FloatPoint Path::currentPoint() const 
+{
+    if (isNull())
+        return FloatPoint();
+
+    float length;
+    HRESULT hr = m_path-&gt;ComputeLength(nullptr, &amp;length);
+    if (!SUCCEEDED(hr))
+        return FloatPoint();
+
+    D2D1_POINT_2F point = { };
+    D2D1_POINT_2F tangent = { };
+    hr = m_path-&gt;ComputePointAtLength(length, nullptr, &amp;point, &amp;tangent);
+    if (!SUCCEEDED(hr))
+        return FloatPoint();
+
+    return point;
+}
+
+void Path::apply(const PathApplierFunction&amp; function) const
+{
+    if (isNull())
+        return;
+
+    notImplemented();
+}
+
+}
+
+#endif // USE(DIRECT2D)
</ins></span></pre>
</div>
</div>

</body>
</html>