<!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>[207863] 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/207863">207863</a></dd>
<dt>Author</dt> <dd>bfulgham@apple.com</dd>
<dt>Date</dt> <dd>2016-10-25 18:57:44 -0700 (Tue, 25 Oct 2016)</dd>
</dl>
<h3>Log Message</h3>
<pre>[Win][Direct2D] Use smart pointers for Direct2D Path types
https://bugs.webkit.org/show_bug.cgi?id=163994
Reviewed by Alex Christensen.
Tested by existing path tests.
* platform/graphics/Path.h:
(WebCore::Path::platformPath): Use a COMPtr for m_path.
* platform/graphics/win/GraphicsContextDirect2D.cpp:
(WebCore::GraphicsContext::systemFactory): Present better D2D debug output
when running a debug build.
(WebCore::GraphicsContext::platformInit): Initialize a D2D device from a
native GDI device context.
(WebCore::GraphicsContext::platformStrokeStyle): Added.
(WebCore::GraphicsContext::clipBounds): Simplify clip boundary calculations and
avoid doing math on infinities.
* platform/graphics/win/PathDirect2D.cpp:
(WebCore::scratchRenderTarget): Added.
(WebCore::Path::~Path): Switch to COMPtr implementation.
(WebCore::Path::ensurePlatformPath): Ditto.
(WebCore::Path::appendGeometry): Ditto.
(WebCore::Path::operator=): Ditto.
(WebCore::Path::initializePathState): Ditto.
(WebCore::Path::strokeContains): Provide an implementation.
(WebCore::Path::transform): Ditto.
(WebCore::Path::addEllipse): No need for explicit construction of the
D2D1::Point2F object.
(WebCore::Path::clear): Switch to COMPtr implementation.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsPathh">trunk/Source/WebCore/platform/graphics/Path.h</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicswinGraphicsContextDirect2Dcpp">trunk/Source/WebCore/platform/graphics/win/GraphicsContextDirect2D.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 (207862 => 207863)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-10-26 01:28:03 UTC (rev 207862)
+++ trunk/Source/WebCore/ChangeLog        2016-10-26 01:57:44 UTC (rev 207863)
</span><span class="lines">@@ -1,3 +1,35 @@
</span><ins>+2016-10-25 Brent Fulgham <bfulgham@apple.com>
+
+ [Win][Direct2D] Use smart pointers for Direct2D Path types
+ https://bugs.webkit.org/show_bug.cgi?id=163994
+
+ Reviewed by Alex Christensen.
+
+ Tested by existing path tests.
+
+ * platform/graphics/Path.h:
+ (WebCore::Path::platformPath): Use a COMPtr for m_path.
+ * platform/graphics/win/GraphicsContextDirect2D.cpp:
+ (WebCore::GraphicsContext::systemFactory): Present better D2D debug output
+ when running a debug build.
+ (WebCore::GraphicsContext::platformInit): Initialize a D2D device from a
+ native GDI device context.
+ (WebCore::GraphicsContext::platformStrokeStyle): Added.
+ (WebCore::GraphicsContext::clipBounds): Simplify clip boundary calculations and
+ avoid doing math on infinities.
+ * platform/graphics/win/PathDirect2D.cpp:
+ (WebCore::scratchRenderTarget): Added.
+ (WebCore::Path::~Path): Switch to COMPtr implementation.
+ (WebCore::Path::ensurePlatformPath): Ditto.
+ (WebCore::Path::appendGeometry): Ditto.
+ (WebCore::Path::operator=): Ditto.
+ (WebCore::Path::initializePathState): Ditto.
+ (WebCore::Path::strokeContains): Provide an implementation.
+ (WebCore::Path::transform): Ditto.
+ (WebCore::Path::addEllipse): No need for explicit construction of the
+ D2D1::Point2F object.
+ (WebCore::Path::clear): Switch to COMPtr implementation.
+
</ins><span class="cx"> 2016-10-25 Nan Wang <n_wang@apple.com>
</span><span class="cx">
</span><span class="cx"> LayoutTest accessibility/mac/meter-gauge-value-description.html failing
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsPathh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/Path.h (207862 => 207863)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/Path.h        2016-10-26 01:28:03 UTC (rev 207862)
+++ trunk/Source/WebCore/platform/graphics/Path.h        2016-10-26 01:57:44 UTC (rev 207863)
</span><span class="lines">@@ -165,7 +165,11 @@
</span><span class="cx">
</span><span class="cx"> // To keep Path() cheap, it does not allocate a PlatformPath immediately
</span><span class="cx"> // meaning Path::platformPath() can return null.
</span><ins>+#if USE(DIRECT2D)
+ PlatformPathPtr platformPath() const { return m_path.get(); }
+#else
</ins><span class="cx"> PlatformPathPtr platformPath() const { return m_path; }
</span><ins>+#endif
</ins><span class="cx"> // ensurePlatformPath() will allocate a PlatformPath if it has not yet been and will never return null.
</span><span class="cx"> WEBCORE_EXPORT PlatformPathPtr ensurePlatformPath();
</span><span class="cx">
</span><span class="lines">@@ -199,10 +203,12 @@
</span><span class="cx"> #endif
</span><span class="cx">
</span><span class="cx"> private:
</span><del>- PlatformPathPtr m_path { nullptr };
</del><span class="cx"> #if USE(DIRECT2D)
</span><ins>+ COMPtr<ID2D1GeometryGroup> m_path;
</ins><span class="cx"> COMPtr<ID2D1PathGeometry> m_activePathGeometry;
</span><span class="cx"> COMPtr<ID2D1GeometrySink> m_activePath;
</span><ins>+#else
+ PlatformPathPtr m_path { nullptr };
</ins><span class="cx"> #endif
</span><span class="cx"> };
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicswinGraphicsContextDirect2Dcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/win/GraphicsContextDirect2D.cpp (207862 => 207863)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/win/GraphicsContextDirect2D.cpp        2016-10-26 01:28:03 UTC (rev 207862)
+++ trunk/Source/WebCore/platform/graphics/win/GraphicsContextDirect2D.cpp        2016-10-26 01:57:44 UTC (rev 207863)
</span><span class="lines">@@ -71,7 +71,13 @@
</span><span class="cx"> {
</span><span class="cx"> static ID2D1Factory* direct2DFactory = nullptr;
</span><span class="cx"> if (!direct2DFactory) {
</span><ins>+#ifndef NDEBUG
+ D2D1_FACTORY_OPTIONS options = { };
+ options.debugLevel = D2D1_DEBUG_LEVEL_INFORMATION;
+ HRESULT hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_MULTI_THREADED, options, &direct2DFactory);
+#else
</ins><span class="cx"> HRESULT hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_MULTI_THREADED, &direct2DFactory);
</span><ins>+#endif
</ins><span class="cx"> RELEASE_ASSERT(SUCCEEDED(hr));
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -108,7 +114,23 @@
</span><span class="cx"> if (!hdc)
</span><span class="cx"> return;
</span><span class="cx">
</span><del>- COMPtr<ID2D1RenderTarget> renderTarget;
</del><ins>+ HBITMAP bitmap = static_cast<HBITMAP>(GetCurrentObject(hdc, OBJ_BITMAP));
+
+ DIBPixelData pixelData(bitmap);
+
+ auto targetProperties = D2D1::RenderTargetProperties();
+ targetProperties.pixelFormat = D2D1::PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_IGNORE);
+
+ COMPtr<ID2D1DCRenderTarget> renderTarget;
+ HRESULT hr = systemFactory()->CreateDCRenderTarget(&targetProperties, &renderTarget);
+ if (!SUCCEEDED(hr))
+ return;
+
+ RECT clientRect = IntRect(IntPoint(), pixelData.size());
+ hr = renderTarget->BindDC(hdc, &clientRect);
+ if (!SUCCEEDED(hr))
+ return;
+
</ins><span class="cx"> m_data = new GraphicsContextPlatformPrivate(renderTarget.get());
</span><span class="cx"> m_data->m_hdc = hdc;
</span><span class="cx"> // Make sure the context starts in sync with our state.
</span><span class="lines">@@ -671,6 +693,11 @@
</span><span class="cx"> return m_d2dStrokeStyle.get();
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ID2D1StrokeStyle* GraphicsContext::platformStrokeStyle() const
+{
+ return m_data->strokeStyle();
+}
+
</ins><span class="cx"> // This is only used to draw borders.
</span><span class="cx"> void GraphicsContext::drawLine(const FloatPoint& point1, const FloatPoint& point2)
</span><span class="cx"> {
</span><span class="lines">@@ -1248,14 +1275,13 @@
</span><span class="cx"> return IntRect(-2048, -2048, 4096, 4096); // FIXME: display lists.
</span><span class="cx"> }
</span><span class="cx">
</span><del>- D2D1_RECT_F d2dClipBounds = D2D1::InfiniteRect();
- FloatRect clipBounds(d2dClipBounds.left, d2dClipBounds.top, d2dClipBounds.right - d2dClipBounds.left, d2dClipBounds.bottom - d2dClipBounds.top);
</del><ins>+ D2D1_SIZE_F clipSize;
+ if (auto clipLayer = m_data->clipLayer())
+ clipSize = clipLayer->GetSize();
+ else
+ clipSize = platformContext()->GetSize();
</ins><span class="cx">
</span><del>- if (m_data->clipLayer()) {
- auto clipSize = m_data->clipLayer()->GetSize();
- clipBounds.setWidth(clipSize.width);
- clipBounds.setHeight(clipSize.height);
- }
</del><ins>+ FloatRect clipBounds(IntPoint(), clipSize);
</ins><span class="cx">
</span><span class="cx"> return enclosingIntRect(clipBounds);
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicswinPathDirect2Dcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/win/PathDirect2D.cpp (207862 => 207863)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/win/PathDirect2D.cpp        2016-10-26 01:28:03 UTC (rev 207862)
+++ trunk/Source/WebCore/platform/graphics/win/PathDirect2D.cpp        2016-10-26 01:57:44 UTC (rev 207863)
</span><span class="lines">@@ -42,6 +42,11 @@
</span><span class="cx">
</span><span class="cx"> namespace WebCore {
</span><span class="cx">
</span><ins>+static inline ID2D1RenderTarget* scratchRenderTarget()
+{
+ static COMPtr<ID2D1RenderTarget> renderTarget = adoptCOM(GraphicsContext::defaultRenderTarget());
+ return renderTarget.get();
+}
</ins><span class="cx">
</span><span class="cx"> Path Path::polygonPathFromPoints(const Vector<FloatPoint>& points)
</span><span class="cx"> {
</span><span class="lines">@@ -70,8 +75,6 @@
</span><span class="cx">
</span><span class="cx"> Path::~Path()
</span><span class="cx"> {
</span><del>- if (m_path)
- m_path->Release();
</del><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> PlatformPathPtr Path::ensurePlatformPath()
</span><span class="lines">@@ -83,7 +86,7 @@
</span><span class="cx"> return nullptr;
</span><span class="cx"> }
</span><span class="cx">
</span><del>- return m_path;
</del><ins>+ return m_path.get();
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void Path::appendGeometry(ID2D1Geometry* geometry)
</span><span class="lines">@@ -101,7 +104,7 @@
</span><span class="cx">
</span><span class="cx"> auto fillMode = m_path ? m_path->GetFillMode() : D2D1_FILL_MODE_WINDING;
</span><span class="cx">
</span><del>- COMPtr<ID2D1GeometryGroup> protectedPath = adoptCOM(m_path);
</del><ins>+ COMPtr<ID2D1GeometryGroup> protectedPath = m_path;
</ins><span class="cx"> m_path = nullptr;
</span><span class="cx">
</span><span class="cx"> HRESULT hr = GraphicsContext::systemFactory()->CreateGeometryGroup(fillMode, geometries.data(), geometries.size(), &m_path);
</span><span class="lines">@@ -162,13 +165,7 @@
</span><span class="cx">
</span><span class="cx"> Path& Path::operator=(const Path& other)
</span><span class="cx"> {
</span><del>- if (m_path)
- m_path->Release();
-
</del><span class="cx"> m_path = other.m_path;
</span><del>- if (m_path)
- m_path->AddRef();
-
</del><span class="cx"> m_activePath = other.m_activePath;
</span><span class="cx"> m_activePathGeometry = other.m_activePathGeometry;
</span><span class="cx">
</span><span class="lines">@@ -177,8 +174,6 @@
</span><span class="cx">
</span><span class="cx"> HRESULT Path::initializePathState()
</span><span class="cx"> {
</span><del>- if (m_path)
- m_path->Release();
</del><span class="cx"> m_path = nullptr;
</span><span class="cx"> m_activePath = nullptr;
</span><span class="cx"> m_activePathGeometry = nullptr;
</span><span class="lines">@@ -231,10 +226,17 @@
</span><span class="cx"> if (isNull())
</span><span class="cx"> return false;
</span><span class="cx">
</span><del>- UNUSED_PARAM(applier);
- UNUSED_PARAM(point);
- notImplemented();
- return false;
</del><ins>+ ASSERT(applier);
+
+ GraphicsContext scratchContext(scratchRenderTarget());
+ applier->strokeStyle(&scratchContext);
+
+ BOOL containsPoint = false;
+ HRESULT hr = m_path->StrokeContainsPoint(point, scratchContext.strokeThickness(), scratchContext.platformStrokeStyle(), nullptr, 1.0f, &containsPoint);
+ if (!SUCCEEDED(hr))
+ return false;
+
+ return containsPoint;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void Path::translate(const FloatSize& size)
</span><span class="lines">@@ -257,7 +259,7 @@
</span><span class="cx">
</span><span class="cx"> const D2D1_MATRIX_3X2_F& d2dTransform = static_cast<const D2D1_MATRIX_3X2_F>(transform);
</span><span class="cx"> COMPtr<ID2D1TransformedGeometry> transformedPath;
</span><del>- if (!SUCCEEDED(GraphicsContext::systemFactory()->CreateTransformedGeometry(m_path, d2dTransform, &transformedPath)))
</del><ins>+ if (!SUCCEEDED(GraphicsContext::systemFactory()->CreateTransformedGeometry(m_path.get(), d2dTransform, &transformedPath)))
</ins><span class="cx"> return;
</span><span class="cx">
</span><span class="cx"> Vector<ID2D1Geometry*> geometries;
</span><span class="lines">@@ -271,7 +273,6 @@
</span><span class="cx">
</span><span class="cx"> auto fillMode = m_path->GetFillMode();
</span><span class="cx">
</span><del>- m_path->Release();
</del><span class="cx"> m_path = nullptr;
</span><span class="cx">
</span><span class="cx"> HRESULT hr = GraphicsContext::systemFactory()->CreateGeometryGroup(fillMode, geometries.data(), geometries.size(), &m_path);
</span><span class="lines">@@ -476,7 +477,7 @@
</span><span class="cx"> void Path::addEllipse(const FloatRect& r)
</span><span class="cx"> {
</span><span class="cx"> COMPtr<ID2D1EllipseGeometry> ellipse;
</span><del>- HRESULT hr = GraphicsContext::systemFactory()->CreateEllipseGeometry(D2D1::Ellipse(D2D1::Point2F(r.center().x(), r.center().y()), r.width(), r.height()), &ellipse);
</del><ins>+ HRESULT hr = GraphicsContext::systemFactory()->CreateEllipseGeometry(D2D1::Ellipse(r.center(), r.width(), r.height()), &ellipse);
</ins><span class="cx"> RELEASE_ASSERT(SUCCEEDED(hr));
</span><span class="cx"> appendGeometry(ellipse.get());
</span><span class="cx"> }
</span><span class="lines">@@ -498,9 +499,6 @@
</span><span class="cx"> if (isNull())
</span><span class="cx"> return;
</span><span class="cx">
</span><del>- if (m_path)
- m_path->Release();
-
</del><span class="cx"> m_path = nullptr;
</span><span class="cx"> m_activePath = nullptr;
</span><span class="cx"> m_activePathGeometry = nullptr;
</span></span></pre>
</div>
</div>
</body>
</html>