Log Message
[iOS] ResourceUsageOverlay should work on iOS. <https://webkit.org/b/152021>
Reviewed by Antti Koivisto. Source/WebCore: Make ResourceUsageOverlay work on iOS and on Mac desktops with UI-side compositing. * page/ResourceUsageOverlay.cpp: (WebCore::ResourceUsageOverlay::initialize): Move the overlay to the top of the view on iOS for now. * page/ResourceUsageOverlay.h: * page/cocoa/ResourceUsageOverlayCocoa.mm: (WebCore::createColor): Make a custom CGColor factory since we can't use CGColorCreateGenericRGB on iOS. (WebCore::MemoryCategoryInfo::MemoryCategoryInfo): (WebCore::ResourceUsageOverlay::platformInitialize): Put the overlay CALayer into a container layer and hook it up with GraphicsLayer::setContentsToPlatformLayer so it works with all compositing modes. (WebCore::showText): Move CGContextSaveGState call to the top of the function to preserve everything. (WebCore::drawGraphLabel): (WebCore::drawCpuHistory): (WebCore::drawGCHistory): (WebCore::ResourceUsageOverlay::platformDraw): Flip the CGContext if needed. (WebCore::runSamplerThread): Update the layer rects on each thread iteration. This shouldn't be necessary but it papers over an issue where the containing layer would shrink down to 0x0 and disappear. Added a FIXME for this. * platform/spi/cocoa/MachVMSPI.h: Add purgeable VM SPI. Source/WTF: * wtf/Platform.h: Enable RESOURCE_USAGE_OVERLAY for all COCOA platforms.
Modified Paths
- trunk/Source/WTF/ChangeLog
- trunk/Source/WTF/wtf/Platform.h
- trunk/Source/WebCore/ChangeLog
- trunk/Source/WebCore/page/ResourceUsageOverlay.cpp
- trunk/Source/WebCore/page/ResourceUsageOverlay.h
- trunk/Source/WebCore/page/cocoa/ResourceUsageOverlayCocoa.mm
- trunk/Source/WebCore/platform/spi/cocoa/MachVMSPI.h
Diff
Modified: trunk/Source/WTF/ChangeLog (193872 => 193873)
--- trunk/Source/WTF/ChangeLog 2015-12-09 23:07:10 UTC (rev 193872)
+++ trunk/Source/WTF/ChangeLog 2015-12-09 23:21:14 UTC (rev 193873)
@@ -1,3 +1,12 @@
+2015-12-09 Andreas Kling <akl...@apple.com>
+
+ [iOS] ResourceUsageOverlay should work on iOS.
+ <https://webkit.org/b/152021>
+
+ Reviewed by Antti Koivisto.
+
+ * wtf/Platform.h: Enable RESOURCE_USAGE_OVERLAY for all COCOA platforms.
+
2015-12-08 Joseph Pecoraro <pecor...@apple.com>
Create a Sandbox SPI header
Modified: trunk/Source/WTF/wtf/Platform.h (193872 => 193873)
--- trunk/Source/WTF/wtf/Platform.h 2015-12-09 23:07:10 UTC (rev 193872)
+++ trunk/Source/WTF/wtf/Platform.h 2015-12-09 23:21:14 UTC (rev 193873)
@@ -1079,7 +1079,7 @@
#define USE_IOSURFACE 1
#endif
-#if PLATFORM(MAC)
+#if PLATFORM(COCOA)
#define ENABLE_RESOURCE_USAGE_OVERLAY 1
#endif
Modified: trunk/Source/WebCore/ChangeLog (193872 => 193873)
--- trunk/Source/WebCore/ChangeLog 2015-12-09 23:07:10 UTC (rev 193872)
+++ trunk/Source/WebCore/ChangeLog 2015-12-09 23:21:14 UTC (rev 193873)
@@ -1,3 +1,30 @@
+2015-12-09 Andreas Kling <akl...@apple.com>
+
+ [iOS] ResourceUsageOverlay should work on iOS.
+ <https://webkit.org/b/152021>
+
+ Reviewed by Antti Koivisto.
+
+ Make ResourceUsageOverlay work on iOS and on Mac desktops with UI-side compositing.
+
+ * page/ResourceUsageOverlay.cpp:
+ (WebCore::ResourceUsageOverlay::initialize): Move the overlay to the top of the view on iOS for now.
+ * page/ResourceUsageOverlay.h:
+ * page/cocoa/ResourceUsageOverlayCocoa.mm:
+ (WebCore::createColor): Make a custom CGColor factory since we can't use CGColorCreateGenericRGB on iOS.
+ (WebCore::MemoryCategoryInfo::MemoryCategoryInfo):
+ (WebCore::ResourceUsageOverlay::platformInitialize): Put the overlay CALayer into a container layer and
+ hook it up with GraphicsLayer::setContentsToPlatformLayer so it works with all compositing modes.
+ (WebCore::showText): Move CGContextSaveGState call to the top of the function to preserve everything.
+ (WebCore::drawGraphLabel):
+ (WebCore::drawCpuHistory):
+ (WebCore::drawGCHistory):
+ (WebCore::ResourceUsageOverlay::platformDraw): Flip the CGContext if needed.
+ (WebCore::runSamplerThread): Update the layer rects on each thread iteration. This shouldn't be
+ necessary but it papers over an issue where the containing layer would shrink down to 0x0 and
+ disappear. Added a FIXME for this.
+ * platform/spi/cocoa/MachVMSPI.h: Add purgeable VM SPI.
+
2015-12-09 Brady Eidson <beid...@apple.com>
Modern IDB: storage/indexeddb/database-closepending-flag.html fails.
Modified: trunk/Source/WebCore/page/ResourceUsageOverlay.cpp (193872 => 193873)
--- trunk/Source/WebCore/page/ResourceUsageOverlay.cpp 2015-12-09 23:07:10 UTC (rev 193872)
+++ trunk/Source/WebCore/page/ResourceUsageOverlay.cpp 2015-12-09 23:21:14 UTC (rev 193873)
@@ -61,7 +61,15 @@
return;
FrameView& frameView = *m_page.mainFrame().view();
- m_overlay->setFrame(IntRect(frameView.width() / 2 - normalWidth / 2, frameView.height() - normalHeight - 20, normalWidth, normalHeight));
+
+ IntRect initialRect(frameView.width() / 2 - normalWidth / 2, frameView.height() - normalHeight - 20, normalWidth, normalHeight);
+
+#if PLATFORM(IOS)
+ // FIXME: The overlay should be stuck to the viewport instead of moving along with the page.
+ initialRect.setY(20);
+#endif
+
+ m_overlay->setFrame(initialRect);
m_overlay->setShouldIgnoreMouseEventsOutsideBounds(false);
m_page.mainFrame().pageOverlayController().installPageOverlay(m_overlay.get(), PageOverlay::FadeMode::DoNotFade);
platformInitialize();
Modified: trunk/Source/WebCore/page/ResourceUsageOverlay.h (193872 => 193873)
--- trunk/Source/WebCore/page/ResourceUsageOverlay.h 2015-12-09 23:07:10 UTC (rev 193872)
+++ trunk/Source/WebCore/page/ResourceUsageOverlay.h 2015-12-09 23:21:14 UTC (rev 193873)
@@ -58,6 +58,9 @@
void platformDraw(CGContextRef);
#endif
+ static const int normalWidth = 570;
+ static const int normalHeight = 130;
+
private:
void pageOverlayDestroyed(PageOverlay&) override { }
void willMoveToPage(PageOverlay&, Page*) override { }
@@ -79,10 +82,8 @@
#if PLATFORM(COCOA)
ThreadIdentifier m_threadID { 0 };
RetainPtr<CALayer> m_layer;
+ RetainPtr<CALayer> m_containerLayer;
#endif
-
- static const int normalWidth = 570;
- static const int normalHeight = 130;
};
}
Modified: trunk/Source/WebCore/page/cocoa/ResourceUsageOverlayCocoa.mm (193872 => 193873)
--- trunk/Source/WebCore/page/cocoa/ResourceUsageOverlayCocoa.mm 2015-12-09 23:07:10 UTC (rev 193872)
+++ trunk/Source/WebCore/page/cocoa/ResourceUsageOverlayCocoa.mm 2015-12-09 23:21:14 UTC (rev 193873)
@@ -144,6 +144,13 @@
static const unsigned NumberOfCategories = 8;
}
+static CGColorRef createColor(float r, float g, float b, float a)
+{
+ static CGColorSpaceRef colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceSRGB);
+ CGFloat components[4] = { r, g, b, a };
+ return CGColorCreate(colorSpace, components);
+}
+
struct MemoryCategoryInfo {
MemoryCategoryInfo() { } // Needed for std::array.
@@ -154,7 +161,7 @@
{
float r, g, b, a;
Color(rgba).getRGBA(r, g, b, a);
- color = adoptCF(CGColorCreateGenericRGB(r, g, b, a));
+ color = adoptCF(createColor(r, g, b, a));
}
String name;
@@ -217,12 +224,19 @@
m_layer = adoptNS([[WebOverlayLayer alloc] initWithResourceUsageOverlay:this]);
- [overlay().layer().platformLayer() addSublayer:m_layer.get()];
+ m_containerLayer = adoptNS([[CALayer alloc] init]);
+ [m_containerLayer.get() addSublayer:m_layer.get()];
+ [m_containerLayer.get() setAnchorPoint:CGPointZero];
+ [m_containerLayer.get() setBounds:CGRectMake(0, 0, normalWidth, normalHeight)];
+
+ [m_layer.get() setAnchorPoint:CGPointZero];
[m_layer.get() setContentsScale:2.0];
- [m_layer.get() setBackgroundColor:adoptCF(CGColorCreateGenericRGB(0, 0, 0, 0.8)).get()];
- [m_layer.get() setFrame:CGRectMake(0, 0, normalWidth, normalHeight)];
+ [m_layer.get() setBackgroundColor:adoptCF(createColor(0, 0, 0, 0.8)).get()];
+ [m_layer.get() setBounds:CGRectMake(0, 0, normalWidth, normalHeight)];
+ overlay().layer().setContentsToPlatformLayer(m_layer.get(), GraphicsLayer::NoContentsLayer);
+
data.overlayLayers.add(m_layer.get());
}
@@ -235,17 +249,23 @@
static void showText(CGContextRef context, float x, float y, CGColorRef color, const String& text)
{
+ CGContextSaveGState(context);
+
CGContextSetTextDrawingMode(context, kCGTextFill);
CGContextSetFillColorWithColor(context, color);
- CGContextSaveGState(context);
-
CGContextSetTextMatrix(context, CGAffineTransformMakeScale(1, -1));
// FIXME: Don't use deprecated APIs.
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+
+#if PLATFORM(IOS)
+ CGContextSelectFont(context, "Courier", 10, kCGEncodingMacRoman);
+#else
CGContextSelectFont(context, "Menlo", 11, kCGEncodingMacRoman);
+#endif
+
CString cstr = text.ascii();
CGContextShowTextAtPoint(context, x, y, cstr.data(), cstr.length());
#pragma clang diagnostic pop
@@ -255,15 +275,15 @@
static void drawGraphLabel(CGContextRef context, float x, float y, const String& text)
{
- static CGColorRef black = CGColorCreateGenericRGB(0, 0, 0, 1);
+ static CGColorRef black = createColor(0, 0, 0, 1);
showText(context, x + 5, y - 3, black, text);
- static CGColorRef white = CGColorCreateGenericRGB(1, 1, 1, 1);
+ static CGColorRef white = createColor(1, 1, 1, 1);
showText(context, x + 4, y - 4, white, text);
}
static void drawCpuHistory(CGContextRef context, float x1, float y1, float y2, RingBuffer<float>& history)
{
- static CGColorRef cpuColor = CGColorCreateGenericRGB(0, 1, 0, 1);
+ static CGColorRef cpuColor = createColor(0, 1, 0, 1);
CGContextSetStrokeColorWithColor(context, cpuColor);
CGContextSetLineWidth(context, 1);
@@ -296,7 +316,7 @@
CGContextSetLineWidth(context, 1);
- static CGColorRef capacityColor = CGColorCreateGenericRGB(1, 0, 0.3, 1);
+ static CGColorRef capacityColor = createColor(1, 0, 0.3, 1);
CGContextSetStrokeColorWithColor(context, capacityColor);
size_t i = 0;
@@ -310,7 +330,7 @@
i++;
});
- static CGColorRef sizeColor = CGColorCreateGenericRGB(0.6, 0.5, 0.9, 1);
+ static CGColorRef sizeColor = createColor(0.6, 0.5, 0.9, 1);
CGContextSetStrokeColorWithColor(context, sizeColor);
i = 0;
@@ -414,13 +434,18 @@
auto& data = ""
LockHolder locker(data.lock);
+ if (![m_layer.get() contentsAreFlipped]) {
+ CGContextScaleCTM(context, 1, -1);
+ CGContextTranslateCTM(context, 0, -normalHeight);
+ }
+
CGContextSetShouldAntialias(context, false);
CGContextSetShouldSmoothFonts(context, false);
CGRect viewBounds = m_overlay->bounds();
CGContextClearRect(context, viewBounds);
- static CGColorRef colorForLabels = CGColorCreateGenericRGB(0.9, 0.9, 0.9, 1);
+ static CGColorRef colorForLabels = createColor(0.9, 0.9, 0.9, 1);
showText(context, 10, 20, colorForLabels, String::format(" CPU: %g", data.cpuHistory.last()));
showText(context, 10, 30, colorForLabels, " Footprint: " + formatByteNumber(data.totalDirty.last()));
@@ -587,8 +612,15 @@
}
[CATransaction begin];
- for (CALayer *layer : layers)
+ for (CALayer *layer : layers) {
+ // FIXME: It shouldn't be necessary to update the bounds on every single thread loop iteration,
+ // but something is causing them to become 0x0.
+ CALayer *containerLayer = [layer superlayer];
+ CGRect rect = CGRectMake(0, 0, ResourceUsageOverlay::normalWidth, ResourceUsageOverlay::normalHeight);
+ [layer setBounds:rect];
+ [containerLayer setBounds:rect];
[layer setNeedsDisplay];
+ }
[CATransaction commit];
// FIXME: Find a way to get the size of the current GC heap size safely from the sampler thread.
Modified: trunk/Source/WebCore/platform/spi/cocoa/MachVMSPI.h (193872 => 193873)
--- trunk/Source/WebCore/platform/spi/cocoa/MachVMSPI.h 2015-12-09 23:07:10 UTC (rev 193872)
+++ trunk/Source/WebCore/platform/spi/cocoa/MachVMSPI.h 2015-12-09 23:21:14 UTC (rev 193873)
@@ -42,5 +42,6 @@
EXTERN_C kern_return_t mach_vm_region(vm_map_t targetTask, mach_vm_address_t*, mach_vm_size_t*, vm_region_flavor_t, vm_region_info_t,
mach_msg_type_number_t* infoCount, mach_port_t* objectName);
EXTERN_C kern_return_t mach_vm_region_recurse(vm_map_t targetTask, mach_vm_address_t*, mach_vm_size_t*, uint32_t* depth, vm_region_recurse_info_t, mach_msg_type_number_t* infoCount);
+EXTERN_C kern_return_t mach_vm_purgable_control(vm_map_t target, mach_vm_address_t, vm_purgable_t control, int* state);
#endif // MachVMSPI_h
_______________________________________________ webkit-changes mailing list webkit-changes@lists.webkit.org https://lists.webkit.org/mailman/listinfo/webkit-changes