<!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>[208019] trunk</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/208019">208019</a></dd>
<dt>Author</dt> <dd>bfulgham@apple.com</dd>
<dt>Date</dt> <dd>2016-10-27 17:21:31 -0700 (Thu, 27 Oct 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>[Win][Direct2D] Create a RAII Helper Class for the Render Target
https://bugs.webkit.org/show_bug.cgi?id=164005

Reviewed by Alex Christensen.

Source/WebCore:

Tested by existing SVG, image, and Canvas layout tests.

* platform/graphics/GraphicsContext.h:
* platform/graphics/win/GradientDirect2D.cpp:
(WebCore::Gradient::fill): Use new convenience helper class.
* platform/graphics/win/GraphicsContextDirect2D.cpp:
(WebCore::GraphicsContext::didBeginDraw):
(WebCore::GraphicsContextPlatformPrivate::GraphicsContextPlatformPrivate):
(WebCore::GraphicsContextPlatformPrivate::~GraphicsContextPlatformPrivate): Add an
assertion that we are in a valid state when cleaning up the graphics context.
(WebCore::GraphicsContextPlatformPrivate::clip): Clipping can only happen in a Draw operation.
Open a new BeginDraw if asked to Clip. The Begin must stay active when this method returns,
as the Clip layer is only valid during a Draw operation.
(WebCore::GraphicsContextPlatformPrivate::beginDraw): Added.
(WebCore::GraphicsContextPlatformPrivate::endDraw): Added.
(WebCore::GraphicsContext::beginDrawIfNeeded): Added.
(WebCore::GraphicsContext::endDraw): Added.
(WebCore::GraphicsContext::drawWithoutShadow): Revise to use new RenderTargetHelper class.
(WebCore::GraphicsContext::drawWithShadow): Ditto.
(WebCore::GraphicsContext::platformFillRoundedRect): Ditto.
(WebCore::GraphicsContext::fillRectWithRoundedHole): Ditto.
(WebCore::GraphicsContext::setDidBeginDraw): Deleted.
* platform/graphics/win/GraphicsContextPlatformPrivateDirect2D.h:
(WebCore::GraphicsContextPlatformPrivate::didBeginDraw): Revise to use count instead of
a separate boolean.
* platform/graphics/win/ImageBufferDataDirect2D.cpp:
(WebCore::ImageBufferData::getData): Revise to use new RenderTargetHelper class.
* platform/graphics/win/NativeImageDirect2D.cpp:
(WebCore::drawNativeImage): Ditto.
* platform/graphics/win/RenderTargetHelper.h: Added.
(WebCore::RenderTargetHelper::RenderTargetHelper):
(WebCore::RenderTargetHelper::~RenderTargetHelper):
(WebCore::RenderTargetHelper::endDraw):
* svg/graphics/SVGImage.cpp:
(WebCore::SVGImage::nativeImage): Revise to use new RenderTargetHelper class.

Source/WebKit/win:

* WebView.cpp:
(WebView::sizeChanged): Construct RenderTarget with higher-resolution display timer.
(WebView::paintWithDirect2D): Revise to use new RenderTargetHelper class.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsGraphicsContexth">trunk/Source/WebCore/platform/graphics/GraphicsContext.h</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicswinGradientDirect2Dcpp">trunk/Source/WebCore/platform/graphics/win/GradientDirect2D.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicswinGraphicsContextDirect2Dcpp">trunk/Source/WebCore/platform/graphics/win/GraphicsContextDirect2D.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicswinGraphicsContextPlatformPrivateDirect2Dh">trunk/Source/WebCore/platform/graphics/win/GraphicsContextPlatformPrivateDirect2D.h</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicswinImageBufferDataDirect2Dcpp">trunk/Source/WebCore/platform/graphics/win/ImageBufferDataDirect2D.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicswinNativeImageDirect2Dcpp">trunk/Source/WebCore/platform/graphics/win/NativeImageDirect2D.cpp</a></li>
<li><a href="#trunkSourceWebCoresvggraphicsSVGImagecpp">trunk/Source/WebCore/svg/graphics/SVGImage.cpp</a></li>
<li><a href="#trunkSourceWebKitwinChangeLog">trunk/Source/WebKit/win/ChangeLog</a></li>
<li><a href="#trunkSourceWebKitwinWebViewcpp">trunk/Source/WebKit/win/WebView.cpp</a></li>
<li><a href="#trunkToolsTestWebKitAPIPlatformWincmake">trunk/Tools/TestWebKitAPI/PlatformWin.cmake</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreplatformgraphicswinRenderTargetScopedDrawingh">trunk/Source/WebCore/platform/graphics/win/RenderTargetScopedDrawing.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (208018 => 208019)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-10-27 23:46:13 UTC (rev 208018)
+++ trunk/Source/WebCore/ChangeLog        2016-10-28 00:21:31 UTC (rev 208019)
</span><span class="lines">@@ -1,3 +1,46 @@
</span><ins>+2016-10-25  Brent Fulgham  &lt;bfulgham@apple.com&gt;
+
+        [Win][Direct2D] Create a RAII Helper Class for the Render Target
+        https://bugs.webkit.org/show_bug.cgi?id=164005
+
+        Reviewed by Alex Christensen.
+
+        Tested by existing SVG, image, and Canvas layout tests.
+
+        * platform/graphics/GraphicsContext.h:
+        * platform/graphics/win/GradientDirect2D.cpp:
+        (WebCore::Gradient::fill): Use new convenience helper class.
+        * platform/graphics/win/GraphicsContextDirect2D.cpp:
+        (WebCore::GraphicsContext::didBeginDraw):
+        (WebCore::GraphicsContextPlatformPrivate::GraphicsContextPlatformPrivate):
+        (WebCore::GraphicsContextPlatformPrivate::~GraphicsContextPlatformPrivate): Add an
+        assertion that we are in a valid state when cleaning up the graphics context.
+        (WebCore::GraphicsContextPlatformPrivate::clip): Clipping can only happen in a Draw operation.
+        Open a new BeginDraw if asked to Clip. The Begin must stay active when this method returns,
+        as the Clip layer is only valid during a Draw operation.
+        (WebCore::GraphicsContextPlatformPrivate::beginDraw): Added.
+        (WebCore::GraphicsContextPlatformPrivate::endDraw): Added.
+        (WebCore::GraphicsContext::beginDrawIfNeeded): Added.
+        (WebCore::GraphicsContext::endDraw): Added.
+        (WebCore::GraphicsContext::drawWithoutShadow): Revise to use new RenderTargetHelper class.
+        (WebCore::GraphicsContext::drawWithShadow): Ditto.
+        (WebCore::GraphicsContext::platformFillRoundedRect): Ditto.
+        (WebCore::GraphicsContext::fillRectWithRoundedHole): Ditto.
+        (WebCore::GraphicsContext::setDidBeginDraw): Deleted.
+        * platform/graphics/win/GraphicsContextPlatformPrivateDirect2D.h:
+        (WebCore::GraphicsContextPlatformPrivate::didBeginDraw): Revise to use count instead of
+        a separate boolean.
+        * platform/graphics/win/ImageBufferDataDirect2D.cpp:
+        (WebCore::ImageBufferData::getData): Revise to use new RenderTargetHelper class.
+        * platform/graphics/win/NativeImageDirect2D.cpp:
+        (WebCore::drawNativeImage): Ditto.
+        * platform/graphics/win/RenderTargetHelper.h: Added.
+        (WebCore::RenderTargetHelper::RenderTargetHelper):
+        (WebCore::RenderTargetHelper::~RenderTargetHelper):
+        (WebCore::RenderTargetHelper::endDraw):
+        * svg/graphics/SVGImage.cpp:
+        (WebCore::SVGImage::nativeImage): Revise to use new RenderTargetHelper class.
+
</ins><span class="cx"> 2016-10-27  Wenson Hsieh  &lt;wenson_hsieh@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Support &quot;insertFromDrop&quot; and &quot;deleteByDrag&quot; for the InputEvent spec
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsGraphicsContexth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/GraphicsContext.h (208018 => 208019)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/GraphicsContext.h        2016-10-27 23:46:13 UTC (rev 208018)
+++ trunk/Source/WebCore/platform/graphics/GraphicsContext.h        2016-10-28 00:21:31 UTC (rev 208019)
</span><span class="lines">@@ -552,9 +552,10 @@
</span><span class="cx">     WEBCORE_EXPORT static ID2D1Factory* systemFactory();
</span><span class="cx">     WEBCORE_EXPORT static ID2D1RenderTarget* defaultRenderTarget();
</span><span class="cx"> 
</span><del>-    WEBCORE_EXPORT void setDidBeginDraw(bool);
</del><ins>+    WEBCORE_EXPORT bool beginDrawIfNeeded();
</ins><span class="cx">     WEBCORE_EXPORT bool didBeginDraw() const;
</span><span class="cx">     D2D1_COLOR_F colorWithGlobalAlpha(const Color&amp;) const;
</span><ins>+    WEBCORE_EXPORT void endDraw();
</ins><span class="cx"> 
</span><span class="cx">     ID2D1Brush* solidStrokeBrush() const;
</span><span class="cx">     ID2D1Brush* solidFillBrush() const;
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicswinGradientDirect2Dcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/win/GradientDirect2D.cpp (208018 => 208019)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/win/GradientDirect2D.cpp        2016-10-27 23:46:13 UTC (rev 208018)
+++ trunk/Source/WebCore/platform/graphics/win/GradientDirect2D.cpp        2016-10-28 00:21:31 UTC (rev 208019)
</span><span class="lines">@@ -28,6 +28,7 @@
</span><span class="cx"> 
</span><span class="cx"> #include &quot;FloatPoint.h&quot;
</span><span class="cx"> #include &quot;GraphicsContext.h&quot;
</span><ins>+#include &quot;RenderTargetScopedDrawing.h&quot;
</ins><span class="cx"> #include &lt;d2d1.h&gt;
</span><span class="cx"> #include &lt;wtf/RetainPtr.h&gt;
</span><span class="cx"> 
</span><span class="lines">@@ -120,8 +121,7 @@
</span><span class="cx">     if (!m_cachedHash || !m_gradient)
</span><span class="cx">         generateGradient(d2dContext);
</span><span class="cx"> 
</span><del>-    if (!context-&gt;didBeginDraw())
-        d2dContext-&gt;BeginDraw();
</del><ins>+    RenderTargetScopedDrawing scopedDraw(*context);
</ins><span class="cx"> 
</span><span class="cx">     d2dContext-&gt;SetTags(GRADIENT_DRAWING, __LINE__);
</span><span class="cx"> 
</span><span class="lines">@@ -128,12 +128,6 @@
</span><span class="cx">     const D2D1_RECT_F d2dRect = rect;
</span><span class="cx">     d2dContext-&gt;FillRectangle(&amp;d2dRect, m_gradient);
</span><span class="cx"> 
</span><del>-    if (!context-&gt;didBeginDraw()) {
-        D2D1_TAG first, second;
-        HRESULT hr = d2dContext-&gt;EndDraw(&amp;first, &amp;second);
-        RELEASE_ASSERT(SUCCEEDED(hr));
-    }
-
</del><span class="cx">     if (needScaling)
</span><span class="cx">         context-&gt;restore();
</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 (208018 => 208019)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/win/GraphicsContextDirect2D.cpp        2016-10-27 23:46:13 UTC (rev 208018)
+++ trunk/Source/WebCore/platform/graphics/win/GraphicsContextDirect2D.cpp        2016-10-28 00:21:31 UTC (rev 208019)
</span><span class="lines">@@ -34,6 +34,7 @@
</span><span class="cx"> #include &quot;ImageBuffer.h&quot;
</span><span class="cx"> #include &quot;Logging.h&quot;
</span><span class="cx"> #include &quot;NotImplemented.h&quot;
</span><ins>+#include &quot;RenderTargetScopedDrawing.h&quot;
</ins><span class="cx"> #include &quot;URL.h&quot;
</span><span class="cx"> #include &lt;d2d1.h&gt;
</span><span class="cx"> #include &lt;d2d1effects.h&gt;
</span><span class="lines">@@ -98,15 +99,9 @@
</span><span class="cx">     return defaultRenderTarget;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void GraphicsContext::setDidBeginDraw(bool didBeginDraw)
-{
-    RELEASE_ASSERT(m_data);
-    m_data-&gt;m_didBeginDraw = didBeginDraw;
-}
-
</del><span class="cx"> bool GraphicsContext::didBeginDraw() const
</span><span class="cx"> {
</span><del>-    return m_data-&gt;m_didBeginDraw;
</del><ins>+    return m_data-&gt;didBeginDraw();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void GraphicsContext::platformInit(HDC hdc, bool hasAlpha)
</span><span class="lines">@@ -277,14 +272,9 @@
</span><span class="cx">     HRESULT hr = platformContext()-&gt;CreateBitmap(pixelData.size(), pixelData.buffer(), pixelData.bytesPerRow(), &amp;bitmapProperties, &amp;bitmap);
</span><span class="cx">     ASSERT(SUCCEEDED(hr));
</span><span class="cx"> 
</span><del>-    if (!didBeginDraw())
-        platformContext()-&gt;BeginDraw();
-
</del><ins>+    RenderTargetScopedDrawing scopedDraw(*this);
</ins><span class="cx">     platformContext()-&gt;DrawBitmap(bitmap.get(), dstRect);
</span><span class="cx"> 
</span><del>-    if (!didBeginDraw())
-        hr = platformContext()-&gt;EndDraw();
-
</del><span class="cx">     ::DeleteDC(hdc);
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -308,6 +298,19 @@
</span><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+GraphicsContextPlatformPrivate::GraphicsContextPlatformPrivate(ID2D1RenderTarget* renderTarget)
+    : m_renderTarget(renderTarget)
+{
+}
+
+GraphicsContextPlatformPrivate::~GraphicsContextPlatformPrivate()
+{
+    if (!m_renderTarget)
+        return;
+
+    ASSERT(!m_beginDrawCount.unsafeGet());
+}
+
</ins><span class="cx"> COMPtr&lt;ID2D1SolidColorBrush&gt; GraphicsContextPlatformPrivate::brushWithColor(const D2D1_COLOR_F&amp; color)
</span><span class="cx"> {
</span><span class="cx">     RGBA32 colorKey = makeRGBA32FromFloats(color.r, color.g, color.b, color.a);
</span><span class="lines">@@ -340,6 +343,10 @@
</span><span class="cx"> 
</span><span class="cx"> void GraphicsContextPlatformPrivate::clip(const FloatRect&amp; rect)
</span><span class="cx"> {
</span><ins>+    // In D2D, we can only clip in the context of a 'BeginDraw', and the clip can
+    // only live as long as the draw is happening.
+    beginDrawIfNeeded();
+
</ins><span class="cx">     if (m_renderStates.isEmpty())
</span><span class="cx">         save();
</span><span class="cx"> 
</span><span class="lines">@@ -354,6 +361,10 @@
</span><span class="cx"> 
</span><span class="cx"> void GraphicsContextPlatformPrivate::clip(ID2D1Geometry* path)
</span><span class="cx"> {
</span><ins>+    // In D2D, we can only clip in the context of a 'BeginDraw', and the clip can
+    // only live as long as the draw is happening.
+    beginDrawIfNeeded();
+
</ins><span class="cx">     ASSERT(m_renderStates.size());
</span><span class="cx">     if (!m_renderStates.size())
</span><span class="cx">         return;
</span><span class="lines">@@ -389,6 +400,17 @@
</span><span class="cx">     RELEASE_ASSERT(SUCCEEDED(hr));
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void GraphicsContextPlatformPrivate::beginDrawIfNeeded()
+{
+    ASSERT(m_renderTarget.get());
+    if (didBeginDraw())
+        return;
+
+    m_renderTarget-&gt;BeginDraw();
+
+    ++m_beginDrawCount;
+}
+
</ins><span class="cx"> void GraphicsContextPlatformPrivate::endDraw()
</span><span class="cx"> {
</span><span class="cx">     ASSERT(m_renderTarget.get());
</span><span class="lines">@@ -397,6 +419,8 @@
</span><span class="cx"> 
</span><span class="cx">     if (!SUCCEEDED(hr))
</span><span class="cx">         WTFLogAlways(&quot;Failed in GraphicsContextPlatformPrivate::endDraw: hr=%ld, first=%ld, second=%ld&quot;, hr, first, second);
</span><ins>+
+    --m_beginDrawCount;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void GraphicsContextPlatformPrivate::restore()
</span><span class="lines">@@ -493,6 +517,19 @@
</span><span class="cx">     return m_data-&gt;m_patternFillBrush.get();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+bool GraphicsContext::beginDrawIfNeeded()
+{
+    bool neededToBeginDraw = !m_data-&gt;didBeginDraw();
+
+    m_data-&gt;beginDrawIfNeeded();
+    return neededToBeginDraw;
+}
+
+void GraphicsContext::endDraw()
+{
+    m_data-&gt;endDraw();
+}
+
</ins><span class="cx"> void GraphicsContext::drawPattern(Image&amp; image, const FloatRect&amp; destRect, const FloatRect&amp; tileRect, const AffineTransform&amp; patternTransform, const FloatPoint&amp; phase, const FloatSize&amp; spacing, CompositeOperator op, BlendMode blendMode)
</span><span class="cx"> {
</span><span class="cx">     if (paintingDisabled() || !patternTransform.isInvertible())
</span><span class="lines">@@ -877,19 +914,14 @@
</span><span class="cx"> 
</span><span class="cx"> void GraphicsContext::drawWithoutShadow(const FloatRect&amp; /*boundingRect*/, const std::function&lt;void(ID2D1RenderTarget*)&gt;&amp; drawCommands)
</span><span class="cx"> {
</span><del>-    auto context = platformContext();
-
-    if (!didBeginDraw())
-        context-&gt;BeginDraw();
-
-    drawCommands(context);
-
-    if (!didBeginDraw())
-        m_data-&gt;endDraw();
</del><ins>+    RenderTargetScopedDrawing scopedDraw(*this);
+    drawCommands(platformContext());
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void GraphicsContext::drawWithShadow(const FloatRect&amp; boundingRect, const std::function&lt;void(ID2D1RenderTarget*)&gt;&amp; drawCommands)
</span><span class="cx"> {
</span><ins>+    RenderTargetScopedDrawing scopedDraw(*this);
+
</ins><span class="cx">     auto context = platformContext();
</span><span class="cx"> 
</span><span class="cx">     // Render the current geometry to a bitmap context
</span><span class="lines">@@ -942,10 +974,7 @@
</span><span class="cx">     auto flip = D2D1::Matrix3x2F::Scale(D2D1::SizeF(1.0f, -1.0f));
</span><span class="cx">     deviceContext-&gt;SetTransform(ctm * flip * translate);
</span><span class="cx"> 
</span><del>-    deviceContext-&gt;BeginDraw();
</del><span class="cx">     deviceContext-&gt;DrawImage(compositor.get(), D2D1_INTERPOLATION_MODE_LINEAR);
</span><del>-    hr = deviceContext-&gt;EndDraw();
-    ASSERT(SUCCEEDED(hr));
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void GraphicsContext::fillPath(const Path&amp; path)
</span><span class="lines">@@ -1136,9 +1165,8 @@
</span><span class="cx">         notImplemented();
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    if (!didBeginDraw())
-        context-&gt;BeginDraw();
-    
</del><ins>+    RenderTargetScopedDrawing scopedDraw(*this);
+
</ins><span class="cx">     context-&gt;SetTags(1, __LINE__);
</span><span class="cx"> 
</span><span class="cx">     const FloatRect&amp; r = rect.rect();
</span><span class="lines">@@ -1158,9 +1186,6 @@
</span><span class="cx">         fillPath(path);
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    if (!didBeginDraw())
-        m_data-&gt;endDraw();
-
</del><span class="cx">     if (drawOwnShadow)
</span><span class="cx">         stateSaver.restore();
</span><span class="cx"> }
</span><span class="lines">@@ -1177,8 +1202,7 @@
</span><span class="cx"> 
</span><span class="cx">     auto context = platformContext();
</span><span class="cx"> 
</span><del>-    if (!didBeginDraw())
-        context-&gt;BeginDraw();
</del><ins>+    RenderTargetScopedDrawing scopedDraw(*this);
</ins><span class="cx"> 
</span><span class="cx">     context-&gt;SetTags(1, __LINE__);
</span><span class="cx"> 
</span><span class="lines">@@ -1208,9 +1232,6 @@
</span><span class="cx"> 
</span><span class="cx">     fillPath(path);
</span><span class="cx"> 
</span><del>-    if (!didBeginDraw())
-        m_data-&gt;endDraw();
-
</del><span class="cx">     if (drawOwnShadow)
</span><span class="cx">         stateSaver.restore();
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicswinGraphicsContextPlatformPrivateDirect2Dh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/win/GraphicsContextPlatformPrivateDirect2D.h (208018 => 208019)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/win/GraphicsContextPlatformPrivateDirect2D.h        2016-10-27 23:46:13 UTC (rev 208018)
+++ trunk/Source/WebCore/platform/graphics/win/GraphicsContextPlatformPrivateDirect2D.h        2016-10-28 00:21:31 UTC (rev 208019)
</span><span class="lines">@@ -32,6 +32,7 @@
</span><span class="cx"> #include &lt;d2d1effects.h&gt;
</span><span class="cx"> #include &lt;d2d1helper.h&gt;
</span><span class="cx"> #include &lt;windows.h&gt;
</span><ins>+#include &lt;wtf/CheckedArithmetic.h&gt;
</ins><span class="cx"> #include &lt;wtf/TinyLRUCache.h&gt;
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="lines">@@ -39,10 +40,8 @@
</span><span class="cx"> class GraphicsContextPlatformPrivate {
</span><span class="cx">     WTF_MAKE_FAST_ALLOCATED;
</span><span class="cx"> public:
</span><del>-    GraphicsContextPlatformPrivate(ID2D1RenderTarget* renderTarget)
-        : m_renderTarget(renderTarget)
-    {
-    }
</del><ins>+    GraphicsContextPlatformPrivate(ID2D1RenderTarget*);
+    ~GraphicsContextPlatformPrivate();
</ins><span class="cx"> 
</span><span class="cx">     enum Direct2DLayerType { AxisAlignedClip, LayerClip };
</span><span class="cx"> 
</span><span class="lines">@@ -49,6 +48,7 @@
</span><span class="cx">     void clip(const FloatRect&amp;);
</span><span class="cx">     void clip(const Path&amp;);
</span><span class="cx">     void clip(ID2D1Geometry*);
</span><ins>+    void beginDrawIfNeeded();
</ins><span class="cx">     void endDraw();
</span><span class="cx">     void flush();
</span><span class="cx">     void save();
</span><span class="lines">@@ -75,11 +75,13 @@
</span><span class="cx"> 
</span><span class="cx">     COMPtr&lt;ID2D1SolidColorBrush&gt; brushWithColor(const D2D1_COLOR_F&amp;);
</span><span class="cx"> 
</span><ins>+    bool didBeginDraw() const { return m_beginDrawCount.unsafeGet(); }
+
</ins><span class="cx">     HDC m_hdc { nullptr };
</span><span class="cx">     D2D1_BLEND_MODE m_blendMode { D2D1_BLEND_MODE_MULTIPLY };
</span><span class="cx">     D2D1_COMPOSITE_MODE m_compositeMode { D2D1_COMPOSITE_MODE_SOURCE_OVER };
</span><ins>+    Checked&lt;unsigned&gt; m_beginDrawCount { 0 };
</ins><span class="cx">     bool m_shouldIncludeChildWindows { false };
</span><del>-    bool m_didBeginDraw { false };
</del><span class="cx">     bool m_strokeSyleIsDirty { false };
</span><span class="cx"> 
</span><span class="cx">     COMPtr&lt;ID2D1SolidColorBrush&gt; m_solidStrokeBrush;
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicswinImageBufferDataDirect2Dcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/win/ImageBufferDataDirect2D.cpp (208018 => 208019)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/win/ImageBufferDataDirect2D.cpp        2016-10-27 23:46:13 UTC (rev 208018)
+++ trunk/Source/WebCore/platform/graphics/win/ImageBufferDataDirect2D.cpp        2016-10-28 00:21:31 UTC (rev 208019)
</span><span class="lines">@@ -33,6 +33,7 @@
</span><span class="cx"> #include &quot;HWndDC.h&quot;
</span><span class="cx"> #include &quot;IntRect.h&quot;
</span><span class="cx"> #include &quot;NotImplemented.h&quot;
</span><ins>+#include &quot;RenderTargetScopedDrawing.h&quot;
</ins><span class="cx"> #include &lt;d2d1.h&gt;
</span><span class="cx"> #include &lt;runtime/JSCInlines.h&gt;
</span><span class="cx"> #include &lt;runtime/TypedArrayInlines.h&gt;
</span><span class="lines">@@ -63,24 +64,24 @@
</span><span class="cx">     auto bitmapDC = adoptGDIObject(::CreateCompatibleDC(windowDC));
</span><span class="cx">     HGDIOBJ oldBitmap = ::SelectObject(bitmapDC.get(), bitmap.get());
</span><span class="cx"> 
</span><del>-    HRESULT hr;
</del><ins>+    BOOL ok = TRUE;
</ins><span class="cx"> 
</span><del>-    COMPtr&lt;ID2D1GdiInteropRenderTarget&gt; gdiRenderTarget;
-    hr = platformContext-&gt;QueryInterface(__uuidof(ID2D1GdiInteropRenderTarget), (void**)&amp;gdiRenderTarget);
-    if (FAILED(hr))
-        return nullptr;
</del><ins>+    {
+        RenderTargetScopedDrawing scopedDraw(*context);
</ins><span class="cx"> 
</span><del>-    platformContext-&gt;BeginDraw();
</del><ins>+        COMPtr&lt;ID2D1GdiInteropRenderTarget&gt; gdiRenderTarget;
+        HRESULT hr = platformContext-&gt;QueryInterface(__uuidof(ID2D1GdiInteropRenderTarget), (void**)&amp;gdiRenderTarget);
+        if (FAILED(hr))
+            return nullptr;
</ins><span class="cx"> 
</span><del>-    HDC hdc = nullptr;
-    hr = gdiRenderTarget-&gt;GetDC(D2D1_DC_INITIALIZE_MODE_COPY, &amp;hdc);
</del><ins>+        HDC hdc = nullptr;
+        hr = gdiRenderTarget-&gt;GetDC(D2D1_DC_INITIALIZE_MODE_COPY, &amp;hdc);
</ins><span class="cx"> 
</span><del>-    BOOL ok = ::BitBlt(bitmapDC.get(), 0, 0, rect.width(), rect.height(), hdc, rect.x(), rect.y(), SRCCOPY);
</del><ins>+        ok = ::BitBlt(bitmapDC.get(), 0, 0, rect.width(), rect.height(), hdc, rect.x(), rect.y(), SRCCOPY);
</ins><span class="cx"> 
</span><del>-    hr = gdiRenderTarget-&gt;ReleaseDC(nullptr);
</del><ins>+        hr = gdiRenderTarget-&gt;ReleaseDC(nullptr);
+    }
</ins><span class="cx"> 
</span><del>-    hr = platformContext-&gt;EndDraw();
-
</del><span class="cx">     if (!ok)
</span><span class="cx">         return nullptr;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicswinNativeImageDirect2Dcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/win/NativeImageDirect2D.cpp (208018 => 208019)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/win/NativeImageDirect2D.cpp        2016-10-27 23:46:13 UTC (rev 208018)
+++ trunk/Source/WebCore/platform/graphics/win/NativeImageDirect2D.cpp        2016-10-28 00:21:31 UTC (rev 208019)
</span><span class="lines">@@ -32,6 +32,7 @@
</span><span class="cx"> #include &quot;GraphicsContext.h&quot;
</span><span class="cx"> #include &quot;IntSize.h&quot;
</span><span class="cx"> #include &quot;NotImplemented.h&quot;
</span><ins>+#include &quot;RenderTargetScopedDrawing.h&quot;
</ins><span class="cx"> #include &lt;d2d1.h&gt;
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="lines">@@ -85,14 +86,13 @@
</span><span class="cx"> 
</span><span class="cx">     float opacity = 1.0f;
</span><span class="cx"> 
</span><del>-    if (!context.didBeginDraw())
-        platformContext-&gt;BeginDraw();
</del><ins>+    bool temporaryDraw = context.beginDrawIfNeeded();
</ins><span class="cx"> 
</span><span class="cx">     platformContext-&gt;DrawBitmap(image.get(), destRect, opacity, D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR, adjustedSrcRect);
</span><span class="cx"> 
</span><span class="cx">     HRESULT hr = S_OK;
</span><del>-    if (!context.didBeginDraw())
-        hr = platformContext-&gt;EndDraw();
</del><ins>+    if (temporaryDraw)
+        context.endDraw();
</ins><span class="cx">     else
</span><span class="cx">         hr = platformContext-&gt;Flush();
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicswinRenderTargetScopedDrawingh"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/platform/graphics/win/RenderTargetScopedDrawing.h (0 => 208019)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/win/RenderTargetScopedDrawing.h                                (rev 0)
+++ trunk/Source/WebCore/platform/graphics/win/RenderTargetScopedDrawing.h        2016-10-28 00:21:31 UTC (rev 208019)
</span><span class="lines">@@ -0,0 +1,60 @@
</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.
+ */
+
+#pragma once
+
+#include &quot;GraphicsContext.h&quot;
+
+namespace WebCore {
+
+class RenderTargetScopedDrawing {
+    WTF_MAKE_NONCOPYABLE(RenderTargetScopedDrawing);
+public:
+    RenderTargetScopedDrawing(GraphicsContext&amp; context)
+        : m_context(context)
+    {
+        m_drawIsScoped = context.beginDrawIfNeeded();
+    }
+
+    ~RenderTargetScopedDrawing()
+    {
+        endDraw();
+    }
+
+    void endDraw()
+    {
+        if (!m_drawIsScoped)
+            return;
+            
+        m_context.endDraw();
+        m_drawIsScoped = false;
+    }
+
+private:
+    GraphicsContext&amp; m_context;
+    bool m_drawIsScoped;
+};
+
+} // namespace WebCore
</ins></span></pre></div>
<a id="trunkSourceWebCoresvggraphicsSVGImagecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/svg/graphics/SVGImage.cpp (208018 => 208019)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/svg/graphics/SVGImage.cpp        2016-10-27 23:46:13 UTC (rev 208018)
+++ trunk/Source/WebCore/svg/graphics/SVGImage.cpp        2016-10-28 00:21:31 UTC (rev 208019)
</span><span class="lines">@@ -1,6 +1,6 @@
</span><span class="cx"> /*
</span><span class="cx">  * Copyright (C) 2006 Eric Seidel &lt;eric@webkit.org&gt;
</span><del>- * Copyright (C) 2008, 2009, 2015 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2008-2009, 2015-2016 Apple Inc. All rights reserved.
</ins><span class="cx">  * Copyright (C) Research In Motion Limited 2011. All rights reserved.
</span><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="lines">@@ -56,6 +56,7 @@
</span><span class="cx"> 
</span><span class="cx"> #if USE(DIRECT2D)
</span><span class="cx"> #include &quot;COMPtr.h&quot;
</span><ins>+#include &quot;RenderTargetScopedDrawing.h&quot;
</ins><span class="cx"> #include &lt;d2d1.h&gt;
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="lines">@@ -224,15 +225,13 @@
</span><span class="cx">     HRESULT hr = platformContext-&gt;CreateCompatibleRenderTarget(IntSize(rect().size()), &amp;nativeImageTarget);
</span><span class="cx">     ASSERT(SUCCEEDED(hr));
</span><span class="cx"> 
</span><del>-    nativeImageTarget-&gt;BeginDraw();
</del><span class="cx">     GraphicsContext localContext(nativeImageTarget.get());
</span><del>-    localContext.setDidBeginDraw(true);
</del><span class="cx"> 
</span><del>-    draw(localContext, rect(), rect(), CompositeSourceOver, BlendModeNormal, ImageOrientationDescription());
</del><ins>+    {
+        RenderTargetScopedDrawing scopedDraw(localContext);
+        draw(localContext, rect(), rect(), CompositeSourceOver, BlendModeNormal, ImageOrientationDescription());
+    }
</ins><span class="cx"> 
</span><del>-    hr = nativeImageTarget-&gt;Flush();
-    ASSERT(SUCCEEDED(hr));
-
</del><span class="cx">     COMPtr&lt;ID2D1Bitmap&gt; nativeImage;
</span><span class="cx">     hr = nativeImageTarget-&gt;GetBitmap(&amp;nativeImage);
</span><span class="cx">     ASSERT(SUCCEEDED(hr));
</span></span></pre></div>
<a id="trunkSourceWebKitwinChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/win/ChangeLog (208018 => 208019)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/win/ChangeLog        2016-10-27 23:46:13 UTC (rev 208018)
+++ trunk/Source/WebKit/win/ChangeLog        2016-10-28 00:21:31 UTC (rev 208019)
</span><span class="lines">@@ -1,3 +1,14 @@
</span><ins>+2016-10-25  Brent Fulgham  &lt;bfulgham@apple.com&gt;
+
+        [Win][Direct2D] Create a RAII Helper Class for the Render Target
+        https://bugs.webkit.org/show_bug.cgi?id=164005
+
+        Reviewed by Alex Christensen.
+
+        * WebView.cpp:
+        (WebView::sizeChanged): Construct RenderTarget with higher-resolution display timer.
+        (WebView::paintWithDirect2D): Revise to use new RenderTargetHelper class.
+
</ins><span class="cx"> 2016-10-27  Wenson Hsieh  &lt;wenson_hsieh@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Support &quot;insertFromDrop&quot; and &quot;deleteByDrag&quot; for the InputEvent spec
</span></span></pre></div>
<a id="trunkSourceWebKitwinWebViewcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/win/WebView.cpp (208018 => 208019)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/win/WebView.cpp        2016-10-27 23:46:13 UTC (rev 208018)
+++ trunk/Source/WebKit/win/WebView.cpp        2016-10-28 00:21:31 UTC (rev 208019)
</span><span class="lines">@@ -164,6 +164,7 @@
</span><span class="cx"> #include &lt;WebCore/WindowMessageBroadcaster.h&gt;
</span><span class="cx"> #include &lt;WebCore/WindowsTouch.h&gt;
</span><span class="cx"> #include &lt;bindings/ScriptValue.h&gt;
</span><ins>+#include &lt;comdef.h&gt;
</ins><span class="cx"> #include &lt;d2d1.h&gt;
</span><span class="cx"> #include &lt;wtf/MainThread.h&gt;
</span><span class="cx"> #include &lt;wtf/RAMSize.h&gt;
</span><span class="lines">@@ -196,6 +197,10 @@
</span><span class="cx"> #include &lt;WebCore/FullScreenController.h&gt;
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+#if USE(DIRECT2D)
+#include &lt;WebCore/RenderTargetScopedDrawing.h&gt;
+#endif
+
</ins><span class="cx"> #include &lt;ShlObj.h&gt;
</span><span class="cx"> #include &lt;comutil.h&gt;
</span><span class="cx"> #include &lt;dimm.h&gt;
</span><span class="lines">@@ -1063,7 +1068,7 @@
</span><span class="cx">     // Create a Direct2D render target.
</span><span class="cx">     auto renderTargetProperties = D2D1::RenderTargetProperties();
</span><span class="cx">     renderTargetProperties.usage = D2D1_RENDER_TARGET_USAGE_GDI_COMPATIBLE;
</span><del>-    auto hwndRenderTargetProperties = D2D1::HwndRenderTargetProperties(m_viewWindow, newSize);
</del><ins>+    auto hwndRenderTargetProperties = D2D1::HwndRenderTargetProperties(m_viewWindow, newSize, D2D1_PRESENT_OPTIONS_IMMEDIATELY);
</ins><span class="cx">     HRESULT hr = GraphicsContext::systemFactory()-&gt;CreateHwndRenderTarget(&amp;renderTargetProperties, &amp;hwndRenderTargetProperties, &amp;m_renderTarget);
</span><span class="cx">     ASSERT(SUCCEEDED(hr));
</span><span class="cx"> #endif
</span><span class="lines">@@ -1217,7 +1222,6 @@
</span><span class="cx"> 
</span><span class="cx"> void WebView::paintWithDirect2D()
</span><span class="cx"> {
</span><del>-#if USE(DIRECT2D)
</del><span class="cx">     Frame* coreFrame = core(m_mainFrame);
</span><span class="cx">     if (!coreFrame)
</span><span class="cx">         return;
</span><span class="lines">@@ -1236,46 +1240,43 @@
</span><span class="cx"> 
</span><span class="cx">         auto pixelSize = D2D1::SizeU(clientRect.width(), clientRect.height());
</span><span class="cx"> 
</span><del>-        auto hwndRenderTargetProperties = D2D1::HwndRenderTargetProperties(m_viewWindow, pixelSize);
</del><ins>+        auto hwndRenderTargetProperties = D2D1::HwndRenderTargetProperties(m_viewWindow, pixelSize, D2D1_PRESENT_OPTIONS_IMMEDIATELY);
</ins><span class="cx">         HRESULT hr = GraphicsContext::systemFactory()-&gt;CreateHwndRenderTarget(&amp;renderTargetProperties, &amp;hwndRenderTargetProperties, &amp;m_renderTarget);
</span><span class="cx">         if (!SUCCEEDED(hr))
</span><span class="cx">             return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    m_renderTarget-&gt;BeginDraw();
</del><ins>+    RECT clientRect = {};
+    GraphicsContext gc(m_renderTarget.get());
</ins><span class="cx"> 
</span><del>-    m_renderTarget-&gt;SetTags(WEBKIT_DRAWING, __LINE__);
-    m_renderTarget-&gt;Clear();
</del><ins>+    {
+        WebCore::RenderTargetScopedDrawing scopedDraw(gc);
</ins><span class="cx"> 
</span><del>-    // Direct2D honors the scale factor natively.
-    float scaleFactor = 1.0f;
-    float inverseScaleFactor = 1.0f / scaleFactor;
</del><ins>+        m_renderTarget-&gt;SetTags(WEBKIT_DRAWING, __LINE__);
+        m_renderTarget-&gt;Clear();
</ins><span class="cx"> 
</span><del>-    RECT clientRect;
-    GetClientRect(m_viewWindow, &amp;clientRect);
</del><ins>+        // Direct2D honors the scale factor natively.
+        float scaleFactor = 1.0f;
+        float inverseScaleFactor = 1.0f / scaleFactor;
</ins><span class="cx"> 
</span><del>-    IntRect dirtyRectPixels(0, 0, clientRect.right, clientRect.bottom);
-    FloatRect logicalDirtyRectFloat = dirtyRectPixels;
-    logicalDirtyRectFloat.scale(inverseScaleFactor);
-    IntRect logicalDirtyRect(enclosingIntRect(logicalDirtyRectFloat));
</del><ins>+        GetClientRect(m_viewWindow, &amp;clientRect);
</ins><span class="cx"> 
</span><del>-    GraphicsContext gc(m_renderTarget.get());
-    gc.setDidBeginDraw(true);
</del><ins>+        IntRect dirtyRectPixels(0, 0, clientRect.right, clientRect.bottom);
+        FloatRect logicalDirtyRectFloat = dirtyRectPixels;
+        logicalDirtyRectFloat.scale(inverseScaleFactor);
+        IntRect logicalDirtyRect(enclosingIntRect(logicalDirtyRectFloat));
</ins><span class="cx"> 
</span><del>-    if (frameView &amp;&amp; frameView-&gt;frame().contentRenderer()) {
-        gc.save();
-        gc.scale(FloatSize(scaleFactor, scaleFactor));
-        gc.clip(logicalDirtyRect);
-        frameView-&gt;paint(gc, logicalDirtyRect);
-        gc.restore();
-        if (m_shouldInvertColors)
-            gc.fillRect(logicalDirtyRect, Color::white, CompositeDifference);
</del><ins>+        if (frameView &amp;&amp; frameView-&gt;frame().contentRenderer()) {
+            gc.save();
+            gc.scale(FloatSize(scaleFactor, scaleFactor));
+            gc.clip(logicalDirtyRect);
+            frameView-&gt;paint(gc, logicalDirtyRect);
+            gc.restore();
+            if (m_shouldInvertColors)
+                gc.fillRect(logicalDirtyRect, Color::white, CompositeDifference);
+        }
</ins><span class="cx">     }
</span><span class="cx"> 
</span><del>-    HRESULT hr = m_renderTarget-&gt;EndDraw();
-    // FIXME: Recognize and recover from error state:
-    UNUSED_PARAM(hr);
-
</del><span class="cx">     ::ValidateRect(m_viewWindow, &amp;clientRect);
</span><span class="cx"> #else
</span><span class="cx">     ASSERT_NOT_REACHED();
</span><span class="lines">@@ -3151,6 +3152,7 @@
</span><span class="cx">     m_page-&gt;setDeviceScaleFactor(deviceScaleFactor());
</span><span class="cx"> 
</span><span class="cx">     setSmartInsertDeleteEnabled(TRUE);
</span><ins>+
</ins><span class="cx">     return hr;
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPIPlatformWincmake"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/PlatformWin.cmake (208018 => 208019)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/PlatformWin.cmake        2016-10-27 23:46:13 UTC (rev 208018)
+++ trunk/Tools/TestWebKitAPI/PlatformWin.cmake        2016-10-28 00:21:31 UTC (rev 208019)
</span><span class="lines">@@ -28,6 +28,8 @@
</span><span class="cx"> set(test_webcore_LIBRARIES
</span><span class="cx">     Crypt32
</span><span class="cx">     D2d1
</span><ins>+    Dwrite
+    dxguid
</ins><span class="cx">     Iphlpapi
</span><span class="cx">     Psapi
</span><span class="cx">     Shlwapi
</span><span class="lines">@@ -35,6 +37,7 @@
</span><span class="cx">     WebCore${DEBUG_SUFFIX}
</span><span class="cx">     WebCoreDerivedSources${DEBUG_SUFFIX}
</span><span class="cx">     WebKit${DEBUG_SUFFIX}
</span><ins>+    WindowsCodecs
</ins><span class="cx">     gtest
</span><span class="cx"> )
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>