Adopt CAMachPort-as-layer-contents
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 17 Feb 2015 02:28:52 +0000 (02:28 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 17 Feb 2015 02:28:52 +0000 (02:28 +0000)
https://bugs.webkit.org/show_bug.cgi?id=141687
<rdar://problem/19393233>

Reviewed by Simon Fraser.

No new tests, just a performance bump.

* platform/cocoa/MachSendRight.h:
(WebCore::MachSendRight::operator bool):
Add an operator bool() that checks if the underlying port is nonnull.

* platform/spi/cocoa/QuartzCoreSPI.h:
Add some SPI.

* Shared/mac/RemoteLayerBackingStore.h:
* Shared/mac/RemoteLayerBackingStore.mm:
(WebKit::RemoteLayerBackingStore::decode):
If we have CAMachPort, just keep the MachSendRight around.

(WebKit::RemoteLayerBackingStore::applyBackingStoreToLayer):
If we have CAMachPort, make one and leak our send right into it. CAMachPort
will adopt the port and destroy it when needed.

(WebKit::RemoteLayerBackingStore::setBufferVolatility):
Tiny style fix.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@180203 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/cocoa/MachSendRight.h
Source/WebCore/platform/spi/cocoa/QuartzCoreSPI.h
Source/WebKit2/ChangeLog
Source/WebKit2/Shared/mac/RemoteLayerBackingStore.h
Source/WebKit2/Shared/mac/RemoteLayerBackingStore.mm

index 095c3ea654cb7a02c32a6139262c768f67407aca..1e206ab526e216542769600e8e8b43973fc62a6c 100644 (file)
@@ -1,3 +1,20 @@
+2015-02-16  Tim Horton  <timothy_horton@apple.com>
+
+        Adopt CAMachPort-as-layer-contents
+        https://bugs.webkit.org/show_bug.cgi?id=141687
+        <rdar://problem/19393233>
+
+        Reviewed by Simon Fraser.
+
+        No new tests, just a performance bump.
+
+        * platform/cocoa/MachSendRight.h:
+        (WebCore::MachSendRight::operator bool):
+        Add an operator bool() that checks if the underlying port is nonnull.
+
+        * platform/spi/cocoa/QuartzCoreSPI.h:
+        Add some SPI.
+
 2015-02-15  Sam Weinig  <sam@webkit.org>
 
         Add experimental <attachment> element support
index 7c02df6cb07b2b90ce8fb02075a33366b3cb0cf0..44c5bcc3d55408ab9ac0ac558518167da2957fd0 100644 (file)
@@ -50,6 +50,8 @@ public:
     WEBCORE_EXPORT MachSendRight copySendRight() const;
     WEBCORE_EXPORT mach_port_t leakSendRight() WARN_UNUSED_RETURN;
 
+    explicit operator bool() const { return m_port != MACH_PORT_NULL; }
+
 private:
     explicit MachSendRight(mach_port_t);
 
index cabb17e9eae2b66d13baa3ad5b0c637718fc5de0..b62a5c2b54482ab596491efebd675a6599f9535f 100644 (file)
@@ -142,3 +142,9 @@ EXTERN_C NSString * const kCAFilterExclusionBlendMode;
 EXTERN_C NSString * const kCAContextDisplayName;
 EXTERN_C NSString * const kCAContextDisplayId;
 EXTERN_C NSString * const kCAContextIgnoresHitTest;
+
+// FIXME: These should move into the !USE(APPLE_INTERNAL_SDK) block once they are more readily available.
+typedef struct _CAMachPort *CAMachPortRef;
+extern "C" {
+CAMachPortRef CAMachPortCreate(mach_port_t);
+};
index be0c33ff27e407f959a02286d9dd57c5b314830f..42ada8997c02febd0a9dadecb7f64eae84d704cf 100644 (file)
@@ -1,3 +1,23 @@
+2015-02-16  Tim Horton  <timothy_horton@apple.com>
+
+        Adopt CAMachPort-as-layer-contents
+        https://bugs.webkit.org/show_bug.cgi?id=141687
+        <rdar://problem/19393233>
+
+        Reviewed by Simon Fraser.
+
+        * Shared/mac/RemoteLayerBackingStore.h:
+        * Shared/mac/RemoteLayerBackingStore.mm:
+        (WebKit::RemoteLayerBackingStore::decode):
+        If we have CAMachPort, just keep the MachSendRight around.
+
+        (WebKit::RemoteLayerBackingStore::applyBackingStoreToLayer):
+        If we have CAMachPort, make one and leak our send right into it. CAMachPort
+        will adopt the port and destroy it when needed.
+
+        (WebKit::RemoteLayerBackingStore::setBufferVolatility):
+        Tiny style fix.
+
 2015-02-15  Sam Weinig  <sam@webkit.org>
 
         Add experimental <attachment> element support
index bae090b1a915252ec9cda46be2ff8d20f1bc0229..067cf6e01cdb87e64136eca9b49780a4e55a6072 100644 (file)
@@ -29,6 +29,7 @@
 #include "ShareableBitmap.h"
 #include <WebCore/FloatRect.h>
 #include <WebCore/IOSurface.h>
+#include <WebCore/MachSendRight.h>
 #include <WebCore/Region.h>
 #include <chrono>
 
@@ -133,6 +134,7 @@ private:
     Buffer m_backBuffer;
 #if USE(IOSURFACE)
     Buffer m_secondaryBackBuffer;
+    WebCore::MachSendRight m_frontBufferSendRight;
 #endif
 
     RetainPtr<CGContextRef> m_frontContextPendingFlush;
index 8a02ece9181464c6881022236f36768b0ce88389..4bc3a3edbcc5f3b4cc4556b7c13a6ffe1696572b 100644 (file)
 #import <WebCore/GraphicsContextCG.h>
 #import <WebCore/IOSurface.h>
 #import <WebCore/IOSurfacePool.h>
-#import <WebCore/MachSendRight.h>
 #import <WebCore/QuartzCoreSPI.h>
+#import <WebCore/SoftLinking.h>
 #import <WebCore/WebLayer.h>
 
 #if USE(IOSURFACE)
 #import <mach/mach_port.h>
 #endif
 
+SOFT_LINK_FRAMEWORK(QuartzCore);
+SOFT_LINK_MAY_FAIL(QuartzCore, CAMachPortCreate, CAMachPortRef, (mach_port_t port), (port));
+
 using namespace WebCore;
 
 namespace WebKit {
@@ -138,7 +141,12 @@ bool RemoteLayerBackingStore::decode(IPC::ArgumentDecoder& decoder, RemoteLayerB
         MachSendRight sendRight;
         if (!decoder.decode(sendRight))
             return false;
-        result.m_frontBuffer.surface = IOSurface::createFromSendRight(sendRight, ColorSpaceDeviceRGB);
+
+        if (canLoadCAMachPortCreate())
+            result.m_frontBufferSendRight = WTF::move(sendRight);
+        else
+            result.m_frontBuffer.surface = IOSurface::createFromSendRight(sendRight, ColorSpaceDeviceRGB);
+
         return true;
     }
 #endif
@@ -375,7 +383,12 @@ void RemoteLayerBackingStore::applyBackingStoreToLayer(CALayer *layer)
 
 #if USE(IOSURFACE)
     if (acceleratesDrawing()) {
-        layer.contents = (id)m_frontBuffer.surface->surface();
+        if (canLoadCAMachPortCreate()) {
+            ASSERT(m_frontBufferSendRight);
+            RetainPtr<CAMachPortRef> port = adoptCF(CAMachPortCreate(m_frontBufferSendRight.leakSendRight()));
+            layer.contents = (id)port.get();
+        } else
+            layer.contents = (id)m_frontBuffer.surface->surface();
         return;
     }
 #endif
@@ -392,7 +405,7 @@ RetainPtr<CGContextRef> RemoteLayerBackingStore::takeFrontContextPendingFlush()
 #if USE(IOSURFACE)
 bool RemoteLayerBackingStore::setBufferVolatility(BufferType type, bool isVolatile)
 {
-    switch(type) {
+    switch (type) {
     case BufferType::Front:
         if (m_frontBuffer.surface && m_frontBuffer.isVolatile != isVolatile) {
             if (isVolatile)