<!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.
<https://webkit.org/b/150841>
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 <akling@apple.com>
+
+ ResourceUsageOverlay should draw itself using WebCore::GraphicsContext.
+ <https://webkit.org/b/150841>
+
+ 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 <youenn.fablet@crf.canon.fr>
</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& gc, float x1, float y1, float y2, RingBuffer<float>& history)
</span><span class="cx"> {
</span><span class="cx"> Ref<Gradient> gradient = Gradient::create(FloatPoint(0, y1), FloatPoint(0, y2));
</span><del>- gradient->addColorStop(0.0, Color(0, 255, 0));
</del><ins>+ gradient->addColorStop(0.0, Color(255, 0, 0));
</ins><span class="cx"> gradient->addColorStop(0.5, Color(255, 255, 0));
</span><del>- gradient->addColorStop(1.0, Color(255, 0, 0));
</del><ins>+ gradient->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<Gradient> capacityGradient = Gradient::create(FloatPoint(0, y1), FloatPoint(0, y2));
</span><del>- capacityGradient->addColorStop(0.0, Color(0xCC, 0x00, 0x33));
</del><ins>+ capacityGradient->addColorStop(0.0, Color(0xFF, 0x00, 0x00));
</ins><span class="cx"> capacityGradient->addColorStop(0.5, Color(0xFF, 0x00, 0x33));
</span><del>- capacityGradient->addColorStop(1.0, Color(0xFF, 0x00, 0x00));
</del><ins>+ capacityGradient->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<Gradient> sizeGradient = Gradient::create(FloatPoint(0, y1), FloatPoint(0, y2));
</span><del>- sizeGradient->addColorStop(0.0, Color(0x29, 0x56, 0x8F));
</del><ins>+ sizeGradient->addColorStop(0.0, Color(0x96, 0xB1, 0xD2));
</ins><span class="cx"> sizeGradient->addColorStop(0.5, Color(0x47, 0x71, 0xA5));
</span><del>- sizeGradient->addColorStop(1.0, Color(0x96, 0xB1, 0xD2));
</del><ins>+ sizeGradient->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("%lu", 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& fontCascade()
+{
+ static NeverDestroyed<FontCascade> font;
+ static std::once_flag onceFlag;
+ std::call_once(onceFlag, [] {
+ FontCascadeDescription fontDescription;
+ fontDescription.setFamilies({ "Menlo" });
+ 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 "-Wdeprecated-declarations"
-
</del><span class="cx"> static void showText(GraphicsContext& gc, float x, float y, Color color, const String& 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& 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->bounds());
</span><del>- CGContextRef ctx = context.platformContext();
</del><span class="cx"> CGRect viewBounds = m_overlay->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, "Menlo", 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, " Other: " + formatByteNumber(footprintWithDeductions));
- showText(context, 10, 20, colorForGCHeap, " GC heap: " + formatByteNumber(gcHeapSize) + " (" + formatByteNumber(gcHeapCapacity) + ")");
- showText(context, 10, 30, colorForJITCode, " JS JIT: " + formatByteNumber(data.jitCode));
- showText(context, 10, 40, colorForLayers, " Layers: " + formatByteNumber(data.layers));
- showText(context, 10, 50, colorForImages, " Images: " + formatByteNumber(data.images));
- showText(context, 10, 60, colorForLibcMalloc, "libc malloc: " + formatByteNumber(data.libcMalloc));
- showText(context, 10, 70, colorForFastMalloc, " bmalloc: " + formatByteNumber(bmallocWithDeductions));
-
- showText(context, 10, 90, colorForLabels, " Footprint: " + formatByteNumber(data.sumDirty));
- showText(context, 10, 100, colorForLabels, String::format(" CPU: %g", data.cpuHistory.last()));
- }
</del><ins>+ showText(context, 10, 20, colorForLabels, String::format(" CPU: %g", data.cpuHistory.last()));
+ showText(context, 10, 30, colorForLabels, " Footprint: " + formatByteNumber(data.sumDirty));
</ins><span class="cx">
</span><ins>+ showText(context, 10, 50, colorForFastMalloc, " bmalloc: " + formatByteNumber(bmallocWithDeductions));
+ showText(context, 10, 60, colorForLibcMalloc, "libc malloc: " + formatByteNumber(data.libcMalloc));
+ showText(context, 10, 70, colorForImages, " Images: " + formatByteNumber(data.images));
+ showText(context, 10, 80, colorForLayers, " Layers: " + formatByteNumber(data.layers));
+ showText(context, 10, 90, colorForJITCode, " JS JIT: " + formatByteNumber(data.jitCode));
+ showText(context, 10, 100, colorForGCHeap, " GC heap: " + formatByteNumber(gcHeapSize) + " (" + formatByteNumber(gcHeapCapacity) + ")");
+ showText(context, 10, 110, colorForOther, " Other: " + formatByteNumber(footprintWithDeductions));
+
</ins><span class="cx"> drawCpuHistory(context, m_overlay->frame().width() - 50, 0, viewBounds.size.height, data.cpuHistory);
</span><span class="cx"> drawGCHistory(context, m_overlay->frame().width() - 100, 0, viewBounds.size.height, data.gcHeapSizeHistory, data.gcHeapCapacityHistory);
</span><span class="cx"> drawMemoryPie(context, m_overlay->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<size_t, 256> dirtyPagesPerVMTag()
</span><span class="cx"> {
</span><span class="cx"> std::array<size_t, 256> dirty;
</span></span></pre>
</div>
</div>
</body>
</html>