<!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>[191963] 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/191963">191963</a></dd>
<dt>Author</dt> <dd>akling@apple.com</dd>
<dt>Date</dt> <dd>2015-11-03 11:54:12 -0800 (Tue, 03 Nov 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>ResourceUsageOverlay should draw itself using WebCore::GraphicsContext.
&lt;https://webkit.org/b/150841&gt;

Reviewed by Antti Koivisto.

Use WebCore text drawing primitives instead of poking at the CGContext directly.
And stop using deprecated CoreGraphics APIs, too.

* page/cocoa/ResourceUsageOverlayCocoa.mm:
(WebCore::drawCpuHistory):
(WebCore::drawGCHistory):

    Adjust for unflipped Y axis.

(WebCore::fontCascade):
(WebCore::showText):

    Draw using WebCore text drawing primitives.

(WebCore::ResourceUsageOverlay::draw):

    Remove CGContext calls and stop flipping the Y axis.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorepagecocoaResourceUsageOverlayCocoamm">trunk/Source/WebCore/page/cocoa/ResourceUsageOverlayCocoa.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (191962 => 191963)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2015-11-03 19:25:52 UTC (rev 191962)
+++ trunk/Source/WebCore/ChangeLog        2015-11-03 19:54:12 UTC (rev 191963)
</span><span class="lines">@@ -1,3 +1,28 @@
</span><ins>+2015-11-03  Andreas Kling  &lt;akling@apple.com&gt;
+
+        ResourceUsageOverlay should draw itself using WebCore::GraphicsContext.
+        &lt;https://webkit.org/b/150841&gt;
+
+        Reviewed by Antti Koivisto.
+
+        Use WebCore text drawing primitives instead of poking at the CGContext directly.
+        And stop using deprecated CoreGraphics APIs, too.
+
+        * page/cocoa/ResourceUsageOverlayCocoa.mm:
+        (WebCore::drawCpuHistory):
+        (WebCore::drawGCHistory):
+
+            Adjust for unflipped Y axis.
+
+        (WebCore::fontCascade):
+        (WebCore::showText):
+
+            Draw using WebCore text drawing primitives.
+
+        (WebCore::ResourceUsageOverlay::draw):
+
+            Remove CGContext calls and stop flipping the Y axis.
+
</ins><span class="cx"> 2015-11-03  Youenn Fablet  &lt;youenn.fablet@crf.canon.fr&gt;
</span><span class="cx"> 
</span><span class="cx">         [Streams API] Vended promise capabilities should not need @resolve/@reject fields
</span></span></pre></div>
<a id="trunkSourceWebCorepagecocoaResourceUsageOverlayCocoamm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/cocoa/ResourceUsageOverlayCocoa.mm (191962 => 191963)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/cocoa/ResourceUsageOverlayCocoa.mm        2015-11-03 19:25:52 UTC (rev 191962)
+++ trunk/Source/WebCore/page/cocoa/ResourceUsageOverlayCocoa.mm        2015-11-03 19:54:12 UTC (rev 191963)
</span><span class="lines">@@ -185,9 +185,9 @@
</span><span class="cx"> static void drawCpuHistory(GraphicsContext&amp; gc, float x1, float y1, float y2, RingBuffer&lt;float&gt;&amp; history)
</span><span class="cx"> {
</span><span class="cx">     Ref&lt;Gradient&gt; gradient = Gradient::create(FloatPoint(0, y1), FloatPoint(0, y2));
</span><del>-    gradient-&gt;addColorStop(0.0, Color(0, 255, 0));
</del><ins>+    gradient-&gt;addColorStop(0.0, Color(255, 0, 0));
</ins><span class="cx">     gradient-&gt;addColorStop(0.5, Color(255, 255, 0));
</span><del>-    gradient-&gt;addColorStop(1.0, Color(255, 0, 0));
</del><ins>+    gradient-&gt;addColorStop(1.0, Color(0, 255, 0));
</ins><span class="cx">     gc.setStrokeGradient(WTF::move(gradient));
</span><span class="cx">     gc.setStrokeThickness(1);
</span><span class="cx"> 
</span><span class="lines">@@ -198,8 +198,8 @@
</span><span class="cx">         float yScale = y2 - y1;
</span><span class="cx"> 
</span><span class="cx">         Path path;
</span><del>-        path.moveTo(FloatPoint(x1 + i, y1));
-        path.addLineTo(FloatPoint(x1 + i, y1 + (yScale * cpu)));
</del><ins>+        path.moveTo(FloatPoint(x1 + i, y2));
+        path.addLineTo(FloatPoint(x1 + i, y2 - (yScale * cpu)));
</ins><span class="cx">         gc.strokePath(path);
</span><span class="cx">         i++;
</span><span class="cx">     });
</span><span class="lines">@@ -216,9 +216,9 @@
</span><span class="cx">     gc.setStrokeThickness(1);
</span><span class="cx"> 
</span><span class="cx">     Ref&lt;Gradient&gt; capacityGradient = Gradient::create(FloatPoint(0, y1), FloatPoint(0, y2));
</span><del>-    capacityGradient-&gt;addColorStop(0.0, Color(0xCC, 0x00, 0x33));
</del><ins>+    capacityGradient-&gt;addColorStop(0.0, Color(0xFF, 0x00, 0x00));
</ins><span class="cx">     capacityGradient-&gt;addColorStop(0.5, Color(0xFF, 0x00, 0x33));
</span><del>-    capacityGradient-&gt;addColorStop(1.0, Color(0xFF, 0x00, 0x00));
</del><ins>+    capacityGradient-&gt;addColorStop(1.0, Color(0xCC, 0x00, 0x33));
</ins><span class="cx">     gc.setStrokeGradient(WTF::move(capacityGradient));
</span><span class="cx"> 
</span><span class="cx">     size_t i = 0;
</span><span class="lines">@@ -228,16 +228,16 @@
</span><span class="cx">         float yScale = y2 - y1;
</span><span class="cx"> 
</span><span class="cx">         Path path;
</span><del>-        path.moveTo(FloatPoint(x1 + i, y1));
-        path.addLineTo(FloatPoint(x1 + i, y1 + (yScale * mem)));
</del><ins>+        path.moveTo(FloatPoint(x1 + i, y2));
+        path.addLineTo(FloatPoint(x1 + i, y2 - (yScale * mem)));
</ins><span class="cx">         gc.strokePath(path);
</span><span class="cx">         i++;
</span><span class="cx">     });
</span><span class="cx"> 
</span><span class="cx">     Ref&lt;Gradient&gt; sizeGradient = Gradient::create(FloatPoint(0, y1), FloatPoint(0, y2));
</span><del>-    sizeGradient-&gt;addColorStop(0.0, Color(0x29, 0x56, 0x8F));
</del><ins>+    sizeGradient-&gt;addColorStop(0.0, Color(0x96, 0xB1, 0xD2));
</ins><span class="cx">     sizeGradient-&gt;addColorStop(0.5, Color(0x47, 0x71, 0xA5));
</span><del>-    sizeGradient-&gt;addColorStop(1.0, Color(0x96, 0xB1, 0xD2));
</del><ins>+    sizeGradient-&gt;addColorStop(1.0, Color(0x29, 0x56, 0x8F));
</ins><span class="cx">     gc.setStrokeGradient(WTF::move(sizeGradient));
</span><span class="cx"> 
</span><span class="cx">     i = 0;
</span><span class="lines">@@ -247,8 +247,8 @@
</span><span class="cx">         float yScale = y2 - y1;
</span><span class="cx"> 
</span><span class="cx">         Path path;
</span><del>-        path.moveTo(FloatPoint(x1 + i, y1));
-        path.addLineTo(FloatPoint(x1 + i, y1 + (yScale * mem)));
</del><ins>+        path.moveTo(FloatPoint(x1 + i, y2));
+        path.addLineTo(FloatPoint(x1 + i, y2 - (yScale * mem)));
</ins><span class="cx">         gc.strokePath(path);
</span><span class="cx">         i++;
</span><span class="cx">     });
</span><span class="lines">@@ -307,16 +307,27 @@
</span><span class="cx">     return String::format(&quot;%lu&quot;, number);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-// FIXME: All of this should be done without using CGContext directly, so the code can be cross-platform.
</del><ins>+static FontCascade&amp; fontCascade()
+{
+    static NeverDestroyed&lt;FontCascade&gt; font;
+    static std::once_flag onceFlag;
+    std::call_once(onceFlag, [] {
+        FontCascadeDescription fontDescription;
+        fontDescription.setFamilies({ &quot;Menlo&quot; });
+        fontDescription.setSpecifiedSize(11);
+        fontDescription.setComputedSize(11);
+        font.get() = FontCascade(fontDescription, 0, 0);
+        font.get().update(nullptr);
+    });
+    return font;
+}
</ins><span class="cx"> 
</span><del>-#pragma clang diagnostic push
-#pragma clang diagnostic ignored &quot;-Wdeprecated-declarations&quot;
-
</del><span class="cx"> static void showText(GraphicsContext&amp; gc, float x, float y, Color color, const String&amp; text)
</span><span class="cx"> {
</span><ins>+    gc.setShouldSmoothFonts(false);
+    gc.setTextDrawingMode(TextModeFill);
</ins><span class="cx">     gc.setFillColor(color, ColorSpaceDeviceRGB);
</span><del>-    CString cstr = text.ascii();
-    CGContextShowTextAtPoint(gc.platformContext(), x, y, cstr.data(), cstr.length());
</del><ins>+    gc.drawText(fontCascade(), TextRun(text), FloatPoint(x, y));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void ResourceUsageOverlay::draw(GraphicsContext&amp; context)
</span><span class="lines">@@ -331,42 +342,27 @@
</span><span class="cx">     context.setShouldSmoothFonts(false);
</span><span class="cx"> 
</span><span class="cx">     context.clearRect(m_overlay-&gt;bounds());
</span><del>-    CGContextRef ctx = context.platformContext();
</del><span class="cx">     CGRect viewBounds = m_overlay-&gt;bounds();
</span><span class="cx"> 
</span><del>-    context.translate(0, viewBounds.size.height);
-    context.scale(FloatSize(1, -1));
-
-    {
-    GraphicsContextStateSaver saver(context);
-
-    CGContextSetLineWidth(ctx, 2.0);
-    CGContextSelectFont(ctx, &quot;Menlo&quot;, 11.0, kCGEncodingMacRoman);
-    CGContextSetCharacterSpacing(ctx, 1.7);
-    CGContextSetTextDrawingMode(ctx, kCGTextFill);
-
</del><span class="cx">     size_t bmallocWithDeductions = data.bmalloc - gcHeapCapacity;
</span><span class="cx">     size_t footprintWithDeductions = data.sumDirty - data.bmalloc - data.layers - data.images - data.libcMalloc - data.jitCode;
</span><span class="cx"> 
</span><del>-    showText(context, 10, 10, colorForOther,      &quot;      Other: &quot; + formatByteNumber(footprintWithDeductions));
-    showText(context, 10, 20, colorForGCHeap,     &quot;    GC heap: &quot; + formatByteNumber(gcHeapSize) + &quot; (&quot; + formatByteNumber(gcHeapCapacity) + &quot;)&quot;);
-    showText(context, 10, 30, colorForJITCode,    &quot;     JS JIT: &quot; + formatByteNumber(data.jitCode));
-    showText(context, 10, 40, colorForLayers,     &quot;     Layers: &quot; + formatByteNumber(data.layers));
-    showText(context, 10, 50, colorForImages,     &quot;     Images: &quot; + formatByteNumber(data.images));
-    showText(context, 10, 60, colorForLibcMalloc, &quot;libc malloc: &quot; + formatByteNumber(data.libcMalloc));
-    showText(context, 10, 70, colorForFastMalloc, &quot;    bmalloc: &quot; + formatByteNumber(bmallocWithDeductions));
-    
-    showText(context, 10, 90, colorForLabels,     &quot;  Footprint: &quot; + formatByteNumber(data.sumDirty));
-    showText(context, 10, 100, colorForLabels, String::format(&quot;        CPU: %g&quot;, data.cpuHistory.last()));
-    }
</del><ins>+    showText(context, 10,  20, colorForLabels, String::format(&quot;        CPU: %g&quot;, data.cpuHistory.last()));
+    showText(context, 10,  30, colorForLabels,     &quot;  Footprint: &quot; + formatByteNumber(data.sumDirty));
</ins><span class="cx"> 
</span><ins>+    showText(context, 10,  50, colorForFastMalloc, &quot;    bmalloc: &quot; + formatByteNumber(bmallocWithDeductions));
+    showText(context, 10,  60, colorForLibcMalloc, &quot;libc malloc: &quot; + formatByteNumber(data.libcMalloc));
+    showText(context, 10,  70, colorForImages,     &quot;     Images: &quot; + formatByteNumber(data.images));
+    showText(context, 10,  80, colorForLayers,     &quot;     Layers: &quot; + formatByteNumber(data.layers));
+    showText(context, 10,  90, colorForJITCode,    &quot;     JS JIT: &quot; + formatByteNumber(data.jitCode));
+    showText(context, 10, 100, colorForGCHeap,     &quot;    GC heap: &quot; + formatByteNumber(gcHeapSize) + &quot; (&quot; + formatByteNumber(gcHeapCapacity) + &quot;)&quot;);
+    showText(context, 10, 110, colorForOther,      &quot;      Other: &quot; + formatByteNumber(footprintWithDeductions));
+
</ins><span class="cx">     drawCpuHistory(context, m_overlay-&gt;frame().width() - 50, 0, viewBounds.size.height, data.cpuHistory);
</span><span class="cx">     drawGCHistory(context, m_overlay-&gt;frame().width() - 100, 0, viewBounds.size.height, data.gcHeapSizeHistory, data.gcHeapCapacityHistory);
</span><span class="cx">     drawMemoryPie(context, m_overlay-&gt;frame().width() - 150, 0, data);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-#pragma clang diagnostic pop
-
</del><span class="cx"> static std::array&lt;size_t, 256&gt; dirtyPagesPerVMTag()
</span><span class="cx"> {
</span><span class="cx">     std::array&lt;size_t, 256&gt; dirty;
</span></span></pre>
</div>
</div>

</body>
</html>