Title: [132389] trunk/Source
Revision
132389
Author
[email protected]
Date
2012-10-24 13:20:59 -0700 (Wed, 24 Oct 2012)

Log Message

[Qt-on-Mac] GraphicsSurfaces should not create a global IOSurface handle
https://bugs.webkit.org/show_bug.cgi?id=89885

Reviewed by Kenneth Rohde Christiansen.

Source/WebCore:

Use mach_port instead of global tokens for IOSurfaces.
Global IOSurfaces are accessible from other processes using their handle, while mach_ports
can only be shared directly via IPC.

Tested by existing WebGL tests.

* platform/graphics/surfaces/GraphicsSurfaceToken.h:
(GraphicsSurfaceToken):
* platform/graphics/surfaces/mac/GraphicsSurfaceMac.cpp:
(WebCore::GraphicsSurfacePrivate::GraphicsSurfacePrivate):
(WebCore::GraphicsSurfacePrivate::~GraphicsSurfacePrivate):

Source/WebKit2:

Use mach_port instead of global tokens for IOSurfaces.
Global IOSurfaces are accessible from other processes, while mach_ports can only be shared
directly via IPC.

* Shared/CoordinatedGraphics/CoordinatedGraphicsArgumentCoders.cpp:
(CoreIPC::::encode):
(CoreIPC::::decode):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (132388 => 132389)


--- trunk/Source/WebCore/ChangeLog	2012-10-24 20:18:36 UTC (rev 132388)
+++ trunk/Source/WebCore/ChangeLog	2012-10-24 20:20:59 UTC (rev 132389)
@@ -1,3 +1,22 @@
+2012-10-24  Noam Rosenthal  <[email protected]>
+
+        [Qt-on-Mac] GraphicsSurfaces should not create a global IOSurface handle
+        https://bugs.webkit.org/show_bug.cgi?id=89885
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        Use mach_port instead of global tokens for IOSurfaces.
+        Global IOSurfaces are accessible from other processes using their handle, while mach_ports
+        can only be shared directly via IPC.
+
+        Tested by existing WebGL tests.
+
+        * platform/graphics/surfaces/GraphicsSurfaceToken.h:
+        (GraphicsSurfaceToken):
+        * platform/graphics/surfaces/mac/GraphicsSurfaceMac.cpp:
+        (WebCore::GraphicsSurfacePrivate::GraphicsSurfacePrivate):
+        (WebCore::GraphicsSurfacePrivate::~GraphicsSurfacePrivate):
+
 2012-10-24  Rick Byers  <[email protected]>
 
         image-set doesn't round-trip properly with cssText

Modified: trunk/Source/WebCore/platform/graphics/surfaces/GraphicsSurfaceToken.h (132388 => 132389)


--- trunk/Source/WebCore/platform/graphics/surfaces/GraphicsSurfaceToken.h	2012-10-24 20:18:36 UTC (rev 132388)
+++ trunk/Source/WebCore/platform/graphics/surfaces/GraphicsSurfaceToken.h	2012-10-24 20:20:59 UTC (rev 132389)
@@ -33,10 +33,11 @@
 
 struct GraphicsSurfaceToken {
 
-#if OS(DARWIN) || OS(LINUX)
+#if OS(DARWIN)
+    typedef mach_port_t BufferHandle;
+#elif OS(LINUX)
     typedef uint32_t BufferHandle;
-#endif
-#if OS(WINDOWS)
+#elif OS(WINDOWS)
     typedef HANDLE BufferHandle;
 #endif
 

Modified: trunk/Source/WebCore/platform/graphics/surfaces/mac/GraphicsSurfaceMac.cpp (132388 => 132389)


--- trunk/Source/WebCore/platform/graphics/surfaces/mac/GraphicsSurfaceMac.cpp	2012-10-24 20:18:36 UTC (rev 132388)
+++ trunk/Source/WebCore/platform/graphics/surfaces/mac/GraphicsSurfaceMac.cpp	2012-10-24 20:20:59 UTC (rev 132389)
@@ -29,6 +29,7 @@
 #include <IOSurface/IOSurface.h>
 #include <OpenGL/OpenGL.h>
 #include <OpenGL/gl.h>
+#include <mach/mach.h>
 
 #if PLATFORM(QT)
 #include <QGuiApplication>
@@ -79,8 +80,8 @@
         , m_readFbo(0)
         , m_drawFbo(0)
     {
-        m_frontBuffer = IOSurfaceLookup(m_token.frontBufferHandle);
-        m_backBuffer = IOSurfaceLookup(m_token.backBufferHandle);
+        m_frontBuffer = IOSurfaceLookupFromMachPort(m_token.frontBufferHandle);
+        m_backBuffer = IOSurfaceLookupFromMachPort(m_token.backBufferHandle);
     }
 
     GraphicsSurfacePrivate(const PlatformGraphicsContext3D shareContext, const IntSize& size, GraphicsSurface::Flags flags)
@@ -127,8 +128,8 @@
         if (!allocSize)
             return;
 
-        const void *keys[7];
-        const void *values[7];
+        const void *keys[6];
+        const void *values[6];
         keys[0] = kIOSurfaceWidth;
         values[0] = CFNumberCreate(0, kCFNumberIntType, &width);
         keys[1] = kIOSurfaceHeight;
@@ -141,17 +142,18 @@
         values[4] = CFNumberCreate(0, kCFNumberLongType, &bytesPerRow);
         keys[5] = kIOSurfaceAllocSize;
         values[5] = CFNumberCreate(0, kCFNumberLongType, &allocSize);
-        keys[6] = kIOSurfaceIsGlobal;
-        values[6] = (flags & GraphicsSurface::SupportsSharing) ? kCFBooleanTrue : kCFBooleanFalse;
 
-        CFDictionaryRef dict = CFDictionaryCreate(0, keys, values, 7, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
-        for (unsigned i = 0; i < 7; i++)
+        CFDictionaryRef dict = CFDictionaryCreate(0, keys, values, 6, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
+        for (unsigned i = 0; i < 6; i++)
             CFRelease(values[i]);
 
         m_frontBuffer = IOSurfaceCreate(dict);
         m_backBuffer = IOSurfaceCreate(dict);
 
-        m_token = GraphicsSurfaceToken(IOSurfaceGetID(m_frontBuffer), IOSurfaceGetID(m_backBuffer));
+        if (!(flags & GraphicsSurface::SupportsSharing))
+            return;
+
+        m_token = GraphicsSurfaceToken(IOSurfaceCreateMachPort(m_frontBuffer), IOSurfaceCreateMachPort(m_backBuffer));
     }
 
     ~GraphicsSurfacePrivate()
@@ -177,6 +179,11 @@
         if (m_context)
             CGLReleaseContext(m_context);
 
+        if (m_token.frontBufferHandle)
+            mach_port_deallocate(mach_task_self(), m_token.frontBufferHandle);
+        if (m_token.backBufferHandle)
+            mach_port_deallocate(mach_task_self(), m_token.backBufferHandle);
+
     }
 
     uint32_t swapBuffers()

Modified: trunk/Source/WebKit2/ChangeLog (132388 => 132389)


--- trunk/Source/WebKit2/ChangeLog	2012-10-24 20:18:36 UTC (rev 132388)
+++ trunk/Source/WebKit2/ChangeLog	2012-10-24 20:20:59 UTC (rev 132389)
@@ -1,3 +1,18 @@
+2012-10-24  Noam Rosenthal  <[email protected]>
+
+        [Qt-on-Mac] GraphicsSurfaces should not create a global IOSurface handle
+        https://bugs.webkit.org/show_bug.cgi?id=89885
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        Use mach_port instead of global tokens for IOSurfaces.
+        Global IOSurfaces are accessible from other processes, while mach_ports can only be shared
+        directly via IPC.
+
+        * Shared/CoordinatedGraphics/CoordinatedGraphicsArgumentCoders.cpp:
+        (CoreIPC::::encode):
+        (CoreIPC::::decode):
+
 2012-10-24  Anders Carlsson  <[email protected]>
 
         Add per destination ID message receivers

Modified: trunk/Source/WebKit2/Shared/CoordinatedGraphics/CoordinatedGraphicsArgumentCoders.cpp (132388 => 132389)


--- trunk/Source/WebKit2/Shared/CoordinatedGraphics/CoordinatedGraphicsArgumentCoders.cpp	2012-10-24 20:18:36 UTC (rev 132388)
+++ trunk/Source/WebKit2/Shared/CoordinatedGraphics/CoordinatedGraphicsArgumentCoders.cpp	2012-10-24 20:20:59 UTC (rev 132389)
@@ -717,28 +717,20 @@
 void ArgumentCoder<WebCore::GraphicsSurfaceToken>::encode(ArgumentEncoder* encoder, const WebCore::GraphicsSurfaceToken& token)
 {
 #if OS(DARWIN)
-    encoder->encode(token.frontBufferHandle);
-    encoder->encode(token.backBufferHandle);
-#endif
-#if OS(WINDOWS)
+    encoder->encode(Attachment(token.frontBufferHandle, MACH_MSG_TYPE_MOVE_SEND));
+    encoder->encode(Attachment(token.backBufferHandle, MACH_MSG_TYPE_MOVE_SEND));
+#elif OS(WINDOWS)
     uint64_t frontBuffer = reinterpret_cast<uintptr_t>(token.frontBufferHandle);
     encoder->encode(frontBuffer);
     uint64_t backBuffer = reinterpret_cast<uintptr_t>(token.backBufferHandle);
     encoder->encode(backBuffer);
-#endif
-#if OS(LINUX)
+#elif OS(LINUX)
     encoder->encode(token.frontBufferHandle);
 #endif
 }
 
 bool ArgumentCoder<WebCore::GraphicsSurfaceToken>::decode(ArgumentDecoder* decoder, WebCore::GraphicsSurfaceToken& token)
 {
-#if OS(DARWIN)
-    if (!decoder->decode(token.frontBufferHandle))
-        return false;
-    if (!decoder->decode(token.backBufferHandle))
-        return false;
-#endif
 #if OS(WINDOWS)
     uint64_t frontBufferHandle;
     if (!decoder->decode(frontBufferHandle))
@@ -748,8 +740,15 @@
     if (!decoder->decode(backBufferHandle))
         return false;
     token.backBufferHandle = reinterpret_cast<GraphicsSurfaceToken::BufferHandle>(backBufferHandle);
-#endif
-#if OS(LINUX)
+#elif OS(DARWIN)
+    Attachment frontAttachment, backAttachment;
+    if (!decoder->decode(frontAttachment))
+        return false;
+    if (!decoder->decode(backAttachment))
+        return false;
+
+    token = GraphicsSurfaceToken(frontAttachment.port(), backAttachment.port());
+#elif OS(LINUX)
     if (!decoder->decode(token.frontBufferHandle))
         return false;
 #endif
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to