Adopt CAMachPort-as-layer-contents
[WebKit-https.git] / Source / WebKit2 / Shared / mac / RemoteLayerBackingStore.mm
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)