Title: [288789] trunk
Revision
288789
Author
[email protected]
Date
2022-01-29 03:49:46 -0800 (Sat, 29 Jan 2022)

Log Message

Capturing WebGL canvas through peer connection shows the image flipped
https://bugs.webkit.org/show_bug.cgi?id=235600
<rdar://problem/88043325>

Patch by Kimmo Kinnunen <[email protected]> on 2022-01-29
Reviewed by Dean Jackson.

Source/WebCore:

Mirror and rotate the WebGL image at the source since WebRTC
does not support mirroring.

Test: webrtc/canvas-to-peer-connection.html

* platform/graphics/cocoa/GraphicsContextGLCocoa.h:
* platform/graphics/cocoa/GraphicsContextGLCocoa.mm:
(WebCore::GraphicsContextGLCocoa::paintCompositedResultsToMediaSample):
* platform/graphics/cocoa/IOSurface.h:
* platform/graphics/cocoa/IOSurface.mm:
(WebCore::IOSurface::setOwnershipIdentity):
* platform/graphics/cv/CVUtilities.h:
* platform/graphics/cv/CVUtilities.mm:
(WebCore::setOwnershipIdentityForCVPixelBuffer):

LayoutTests:

Test sending WebGL image through a peer connection to a local video
and assert that the image is as drawn.

* platform/glib/TestExpectations:
* webrtc/canvas-to-peer-connection-expected.txt: Added.
* webrtc/canvas-to-peer-connection.html: Added.
* webrtc/routines.js:
* webrtc/video-replace-track.html:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (288788 => 288789)


--- trunk/LayoutTests/ChangeLog	2022-01-29 07:34:08 UTC (rev 288788)
+++ trunk/LayoutTests/ChangeLog	2022-01-29 11:49:46 UTC (rev 288789)
@@ -1,3 +1,20 @@
+2022-01-29  Kimmo Kinnunen  <[email protected]>
+
+        Capturing WebGL canvas through peer connection shows the image flipped
+        https://bugs.webkit.org/show_bug.cgi?id=235600
+        <rdar://problem/88043325>
+
+        Reviewed by Dean Jackson.
+
+        Test sending WebGL image through a peer connection to a local video
+        and assert that the image is as drawn.
+
+        * platform/glib/TestExpectations:
+        * webrtc/canvas-to-peer-connection-expected.txt: Added.
+        * webrtc/canvas-to-peer-connection.html: Added.
+        * webrtc/routines.js:
+        * webrtc/video-replace-track.html:
+
 2022-01-28  Antoine Quint  <[email protected]>
 
         [WPT] Update CSS animation tests

Modified: trunk/LayoutTests/platform/glib/TestExpectations (288788 => 288789)


--- trunk/LayoutTests/platform/glib/TestExpectations	2022-01-29 07:34:08 UTC (rev 288788)
+++ trunk/LayoutTests/platform/glib/TestExpectations	2022-01-29 11:49:46 UTC (rev 288789)
@@ -838,6 +838,7 @@
 imported/w3c/web-platform-tests/video-rvfc [ Pass ]
 fast/mediastream/getUserMedia-rvfc.html [ Pass Failure ]
 webrtc/peerConnection-rvfc.html [ Failure ]
+webrtc/canvas-to-peer-connection.html [ Failure ]
 imported/w3c/web-platform-tests/video-rvfc/request-video-frame-callback-webrtc.https.html [ Skip ]
 imported/w3c/web-platform-tests/video-rvfc/request-video-frame-callback-before-xr-session.https.html [ Skip ]
 imported/w3c/web-platform-tests/video-rvfc/request-video-frame-callback-during-xr-session.https.html [ Skip ]

Modified: trunk/LayoutTests/platform/ios-simulator/TestExpectations (288788 => 288789)


--- trunk/LayoutTests/platform/ios-simulator/TestExpectations	2022-01-29 07:34:08 UTC (rev 288788)
+++ trunk/LayoutTests/platform/ios-simulator/TestExpectations	2022-01-29 11:49:46 UTC (rev 288789)
@@ -41,6 +41,8 @@
 imported/w3c/web-platform-tests/html/browsers/browsing-the-web/history-traversal/persisted-user-state-restoration/scroll-restoration-fragment-scrolling-cross-origin.html [ Failure ]
 imported/w3c/web-platform-tests/webrtc/RTCPeerConnection-setLocalDescription-offer.html [ Failure ]
 
+webkit.org/b/235765 webrtc/canvas-to-peer-connection.html [ Failure ]
+
 # Simulator doesn't support WebAssembly.
 imported/w3c/web-platform-tests/wasm/wasm_stream_instantiate_test.html  [ Skip ]
 imported/w3c/web-platform-tests/wasm/wasm_stream_compile_test.html  [ Skip ]

Added: trunk/LayoutTests/webrtc/canvas-to-peer-connection-expected.txt (0 => 288789)


--- trunk/LayoutTests/webrtc/canvas-to-peer-connection-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/webrtc/canvas-to-peer-connection-expected.txt	2022-01-29 11:49:46 UTC (rev 288789)
@@ -0,0 +1,3 @@
+
+PASS draw: withWebGL
+

Added: trunk/LayoutTests/webrtc/canvas-to-peer-connection.html (0 => 288789)


--- trunk/LayoutTests/webrtc/canvas-to-peer-connection.html	                        (rev 0)
+++ trunk/LayoutTests/webrtc/canvas-to-peer-connection.html	2022-01-29 11:49:46 UTC (rev 288789)
@@ -0,0 +1,112 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src=""
+<script src=""
+<script src =""
+<style type="text/css">
+video { width: 40px; }
+canvas { width: 40px; }
+</style>
+</head>
+<body>
+<div id="debuge"></div>
+<script>
+"use strict";
+
+function with2DContext(subcase, canvas, patternNumber)
+{
+    drawCanvasTestPattern2D(canvas, patternNumber);
+}
+
+function withWebGL(subcase, canvas, patternNumber)
+{
+    drawCanvasTestPatternWebGL(canvas, patternNumber);
+}
+
+async function createLocalPeerConnectionStream(stream)
+{
+    return new Promise((resolve, reject) => {
+        createConnections((firstConnection) => {
+            firstConnection.addTrack(stream.getVideoTracks()[0], stream);
+        }, (secondConnection) => {
+            secondConnection._ontrack_ = (trackEvent) => {
+                assert_true(trackEvent.track instanceof MediaStreamTrack);
+                assert_true(trackEvent.receiver instanceof RTCRtpReceiver);
+                assert_true(Array.isArray(trackEvent.streams), "Array.isArray() should return true");
+                assert_true(Object.isFrozen(trackEvent.streams), "Object.isFrozen() should return true");
+                resolve(trackEvent.streams[0]);
+            };
+        });
+    });
+}
+
+function waitForVideoFrame(video)
+{
+    return new Promise((resolve) => {
+        video.requestVideoFrameCallback((now, metadata) => {
+            resolve(now, metadata);
+        });
+    });
+}
+
+const width = 500;
+const height = 500;
+
+async function testCanvasToPeerConnection(t, subcase)
+{
+    const debuge = document.getElementById("debuge");
+    const canvas = document.createElement("canvas");
+    canvas.width = width;
+    canvas.height = height;
+    debuge.appendChild(canvas);
+    t.add_cleanup(async () => debuge.removeChild(canvas));
+    const frameRate = 60;
+    const localStream = await createLocalPeerConnectionStream(canvas.captureStream());
+    t.add_cleanup(async () => closeConnections());
+    const video = document.createElement("video");
+    video.autoplay = true;
+    video.controls = false;
+    debuge.appendChild(video);
+    t.add_cleanup(async () => debuge.removeChild(video));
+    video.srcObject = localStream;
+    // FIXME: Currently we don't know which frames are skipped.
+    // Draw until video size changes and then try to clear subsequent enqueued
+    // frames.
+    const id = setInterval(() => { subcase.draw(subcase, canvas, 1)}, 100);
+    await waitForVideoSize(video, canvas.width, canvas.height);
+    clearInterval(id);
+    for (let i = 0; i < 20; ++i) {
+        subcase.draw(subcase, canvas, 1);
+        await waitForVideoFrame(video);
+        assertImageSourceContainsCanvasTestPattern(video, 1, "base case");
+    }
+    // Try to clear the video frame queue.
+    await waitFor(100);
+
+    for (let i = 0; i < 25; ++i) {
+        subcase.draw(subcase, canvas, i);
+        await waitForVideoFrame(video);
+        assertImageSourceContainsCanvasTestPattern(video, i, `iteration: ${i}`);
+    }
+}
+
+const subcases = [];
+// FIXME: Tthis should be filled when 2D context supports HTMLCanvasElement.captureStream().
+// subcases.push({draw: with2DContext});
+subcases.push({draw: withWebGL});
+
+function testDescription(subcase) {
+    return Object.keys(subcase).map((k) => `${k}: ${typeof subcase[k] === "function" ? subcase[k].name : subcase[k]}`).join(",");
+}
+
+function createCanvasToPeerConnectionTests(slice, slices) {
+    const sliceSize = Math.floor(subcases.length / slices);
+    const first = sliceSize * slice;
+    for (const subcase of subcases.slice(first, first + sliceSize))
+        promise_test(async t => { await testCanvasToPeerConnection(t, subcase); }, testDescription(subcase));
+}
+createCanvasToPeerConnectionTests(0, 1);
+</script>
+</body>
+</html>

Modified: trunk/LayoutTests/webrtc/routines.js (288788 => 288789)


--- trunk/LayoutTests/webrtc/routines.js	2022-01-29 07:34:08 UTC (rev 288788)
+++ trunk/LayoutTests/webrtc/routines.js	2022-01-29 11:49:46 UTC (rev 288789)
@@ -298,6 +298,13 @@
     }).join('\r\n');
 }
 
+const testColors = {
+    white: [ 255, 255, 255, 255 ],
+    yellow: [ 255, 255, 0, 255 ],
+    cyan: [ 0, 255, 255, 255 ],
+    lightGreen: [ 0, 128, 0, 255 ],
+};
+
 // Sets the camera image orientation if running on test runner.
 // angle: orientation angle of the camera image in degrees
 function setMockCameraImageOrientation(angle, videoSize) {
@@ -340,18 +347,84 @@
         return n;
     }
 
-    const white = [ 255, 255, 255, 255 ];
     const whitePoint = rotatePoint([ 0.04, 0.7 ]);
-    const yellow = [ 255, 255, 0, 255 ];
     const yellowPoint = rotatePoint([ 0.08, 0.7 ]);
-    const cyan = [ 0, 255, 255, 255 ];
     const cyanPoint = rotatePoint([ 0.12, 0.7 ]);
-    const lightGreen = [ 0, 128, 0, 255 ];
     const lightGreenPoint = rotatePoint([ 0.16, 0.7 ]);
 
     let err = 11;
-    assert_array_approx_equals(getImageDataPixel(imageData, whitePoint), white, err, "white rect not found " + desc);
-    assert_array_approx_equals(getImageDataPixel(imageData, yellowPoint), yellow, err, "yellow rect not found" + desc);
-    assert_array_approx_equals(getImageDataPixel(imageData, cyanPoint), cyan, err, "cyan rect not found " + desc);
-    assert_array_approx_equals(getImageDataPixel(imageData, lightGreenPoint), lightGreen, err, "light green rect not found " + desc);
+    assert_array_approx_equals(getImageDataPixel(imageData, whitePoint), testColors.white, err, "white rect not found " + desc);
+    assert_array_approx_equals(getImageDataPixel(imageData, yellowPoint), testColors.yellow, err, "yellow rect not found" + desc);
+    assert_array_approx_equals(getImageDataPixel(imageData, cyanPoint), testColors.cyan, err, "cyan rect not found " + desc);
+    assert_array_approx_equals(getImageDataPixel(imageData, lightGreenPoint), testColors.lightGreen, err, "light green rect not found " + desc);
 }
+
+// Draws a canvas test pattern with WebGL.
+// Can be checked with `assertImageSourceContainsCanvasTestPattern()`.
+// Pattern is four colors, it can detect flips and rotations.
+// `patternNumber` can be used in to test multiple subsequent frames (pass in frame number).
+// Pattern is four boxes with color cycled based on patternNumber % 4.
+function drawCanvasTestPatternWebGL(canvas, patternNumber)
+{
+    patternNumber = patternNumber || 0;
+    const gl = canvas.getContext("webgl", { depth: false, stencil: false, antialias: false });
+    gl.enable(gl.SCISSOR_TEST);
+    const boxSize = [ canvas.width, canvas.height ];
+    const boxes = [
+        [0.0, 0.5, 0.5, 1.0],
+        [0.5, 0.5, 1.0, 1.0],
+        [0.5, 0.0, 1.0, 0.5],
+        [0.0, 0.0, 0.5, 0.5],
+    ];
+    const boxColors = Object.values(testColors);
+    for (let n = 0; n < 4; ++n) {
+        const i = (n + patternNumber) % boxes.length;
+        const color = boxColors[i];
+        const box = boxes[n];
+        gl.scissor(box[0] * boxSize[0], box[1] * boxSize[1], box[2] * boxSize[0], box[3] * boxSize[1]);
+        gl.clearColor(color[0] / 255., color[1] / 255, color[2] / 255., color[3] / 255.);
+        gl.clear(gl.COLOR_BUFFER_BIT);
+    }
+}
+
+function assertImageSourceContainsCanvasTestPattern(imageSource, patternNumber, desc)
+{
+    patternNumber = patternNumber || 0;
+    desc = desc || "";
+    const verifyWidth = 300;
+    // FIXME: canvas-to-peer-connection on Catalina-WK2 would fail with 0 -> 8 and 255 -> 240 for some reason.
+    // https://bugs.webkit.org/show_bug.cgi?id=235708
+    const err = 25;
+    let imageSourceSize;
+    let imageSourceHeight;
+    if (imageSource instanceof HTMLVideoElement)
+        imageSourceSize = [imageSource.videoWidth, imageSource.videoHeight];
+    else
+        imageSourceSize = [imageSource.width, imageSource.height];
+
+    const canvas = document.createElement("canvas");
+    const debuge = document.getElementById("debuge");
+    if (debuge)
+        debuge.appendChild(canvas);
+
+    canvas.width = verifyWidth;
+    canvas.height = (verifyWidth / imageSourceSize[0]) * imageSourceSize[1];
+    const ctx = canvas.getContext("2d");
+    ctx.drawImage(imageSource, 0, 0, canvas.width, canvas.height);
+    const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
+    const pointColors = Object.values(testColors);
+    const points = [
+        [ 0.1, 0.1 ],
+        [ 0.9, 0.1 ],
+        [ 0.9, 0.9 ],
+        [ 0.1, 0.9 ],
+    ];
+    for (let n = 0; n < 4; ++n) {
+        let i = (n + patternNumber) % points.length;
+        let color = pointColors[i];
+        let point = points[n];
+        assert_array_approx_equals(getImageDataPixel(imageData, point), color, err, `rect ${color.join(",")} at ${point.join(",")} not found ${desc}`);
+    }
+    if (debuge)
+        debuge.removeChild(canvas);
+}
\ No newline at end of file

Modified: trunk/LayoutTests/webrtc/video-replace-track.html (288788 => 288789)


--- trunk/LayoutTests/webrtc/video-replace-track.html	2022-01-29 07:34:08 UTC (rev 288788)
+++ trunk/LayoutTests/webrtc/video-replace-track.html	2022-01-29 11:49:46 UTC (rev 288789)
@@ -11,7 +11,6 @@
 <div id="log"></div>
         <video id="video" autoplay=""></video>
         <canvas id="canvas" width="640" height="480"></canvas>
-        <script src =""
         <script>
 video = document.getElementById("video");
 canvas = document.getElementById("canvas");

Modified: trunk/Source/WebCore/ChangeLog (288788 => 288789)


--- trunk/Source/WebCore/ChangeLog	2022-01-29 07:34:08 UTC (rev 288788)
+++ trunk/Source/WebCore/ChangeLog	2022-01-29 11:49:46 UTC (rev 288789)
@@ -1,3 +1,26 @@
+2022-01-29  Kimmo Kinnunen  <[email protected]>
+
+        Capturing WebGL canvas through peer connection shows the image flipped
+        https://bugs.webkit.org/show_bug.cgi?id=235600
+        <rdar://problem/88043325>
+
+        Reviewed by Dean Jackson.
+
+        Mirror and rotate the WebGL image at the source since WebRTC
+        does not support mirroring.
+
+        Test: webrtc/canvas-to-peer-connection.html
+
+        * platform/graphics/cocoa/GraphicsContextGLCocoa.h:
+        * platform/graphics/cocoa/GraphicsContextGLCocoa.mm:
+        (WebCore::GraphicsContextGLCocoa::paintCompositedResultsToMediaSample):
+        * platform/graphics/cocoa/IOSurface.h:
+        * platform/graphics/cocoa/IOSurface.mm:
+        (WebCore::IOSurface::setOwnershipIdentity):
+        * platform/graphics/cv/CVUtilities.h:
+        * platform/graphics/cv/CVUtilities.mm:
+        (WebCore::setOwnershipIdentityForCVPixelBuffer):
+
 2022-01-28  Antti Koivisto  <[email protected]>
 
         [CSS container Queries] Include container queries in RuleSets

Modified: trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLCocoa.h (288788 => 288789)


--- trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLCocoa.h	2022-01-29 07:34:08 UTC (rev 288788)
+++ trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLCocoa.h	2022-01-29 11:49:46 UTC (rev 288789)
@@ -30,20 +30,26 @@
 #include "GraphicsContextGLANGLE.h"
 #include "IOSurface.h"
 
-#if ENABLE(VIDEO)
-namespace WebCore {
-class GraphicsContextGLCVCocoa;
-}
-#endif
-
 #if PLATFORM(MAC)
 #include "ScopedHighPerformanceGPURequest.h"
 #endif
 
+#if ENABLE(MEDIA_STREAM)
+#include <memory>
+#endif
+
 namespace WebCore {
 
 class ProcessIdentity;
 
+#if ENABLE(VIDEO)
+class GraphicsContextGLCVCocoa;
+#endif
+
+#if ENABLE(MEDIA_STREAM)
+class ImageRotationSessionVT;
+#endif
+
 class WEBCORE_EXPORT GraphicsContextGLCocoa : public GraphicsContextGLANGLE {
 public:
     static RefPtr<GraphicsContextGLCocoa> create(WebCore::GraphicsContextGLAttributes&&, ProcessIdentity&& resourceOwner);
@@ -91,6 +97,9 @@
     bool m_switchesGPUOnDisplayReconfiguration { false };
     ScopedHighPerformanceGPURequest m_highPerformanceGPURequest;
 #endif
+#if ENABLE(MEDIA_STREAM)
+    std::unique_ptr<ImageRotationSessionVT> m_mediaSampleRotationSession;
+#endif
     friend class GraphicsContextGLCVCocoa;
 };
 

Modified: trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLCocoa.mm (288788 => 288789)


--- trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLCocoa.mm	2022-01-29 07:34:08 UTC (rev 288788)
+++ trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLCocoa.mm	2022-01-29 11:49:46 UTC (rev 288789)
@@ -54,6 +54,7 @@
 #endif
 
 #if ENABLE(MEDIA_STREAM)
+#include "ImageRotationSessionVT.h"
 #include "MediaSampleAVFObjC.h"
 #endif
 
@@ -775,11 +776,19 @@
         return nullptr;
     if (displayBuffer.surface->size() != getInternalFramebufferSize())
         return nullptr;
-    m_swapChain.markDisplayBufferInUse();
+    // Display surface is not marked in use since we will mirror and rotate it explicitly.
     auto pixelBuffer = createCVPixelBuffer(displayBuffer.surface->surface());
     if (!pixelBuffer)
         return nullptr;
-    return MediaSampleAVFObjC::createImageSample(WTFMove(*pixelBuffer), MediaSampleAVFObjC::VideoRotation::UpsideDown, true);
+    // Mirror and rotate the pixel buffer explicitly, as WebRTC encoders cannot mirror.
+    if (!m_mediaSampleRotationSession)
+        m_mediaSampleRotationSession = makeUnique<ImageRotationSessionVT>(ImageRotationSessionVT::RotationProperties { true, false, 180 }, getInternalFramebufferSize(), ImageRotationSessionVT::IsCGImageCompatible::No);
+    auto mediaSamplePixelBuffer = m_mediaSampleRotationSession->rotate(pixelBuffer->get());
+    if (!mediaSamplePixelBuffer)
+        return nullptr;
+    if (m_resourceOwner)
+        setOwnershipIdentityForCVPixelBuffer(mediaSamplePixelBuffer.get(), m_resourceOwner);
+    return MediaSampleAVFObjC::createImageSample(WTFMove(mediaSamplePixelBuffer), MediaSampleAVFObjC::VideoRotation::None, false);
 }
 #endif
 

Modified: trunk/Source/WebCore/platform/graphics/cocoa/IOSurface.h (288788 => 288789)


--- trunk/Source/WebCore/platform/graphics/cocoa/IOSurface.h	2022-01-29 07:34:08 UTC (rev 288788)
+++ trunk/Source/WebCore/platform/graphics/cocoa/IOSurface.h	2022-01-29 11:49:46 UTC (rev 288789)
@@ -164,6 +164,7 @@
 #endif // HAVE(IOSURFACE_ACCELERATOR)
 
     WEBCORE_EXPORT void setOwnershipIdentity(const ProcessIdentity&);
+    WEBCORE_EXPORT static void setOwnershipIdentity(IOSurfaceRef, const ProcessIdentity&);
 
     void migrateColorSpaceToProperties();
 

Modified: trunk/Source/WebCore/platform/graphics/cocoa/IOSurface.mm (288788 => 288789)


--- trunk/Source/WebCore/platform/graphics/cocoa/IOSurface.mm	2022-01-29 07:34:08 UTC (rev 288788)
+++ trunk/Source/WebCore/platform/graphics/cocoa/IOSurface.mm	2022-01-29 11:49:46 UTC (rev 288789)
@@ -521,13 +521,20 @@
 
 void IOSurface::setOwnershipIdentity(const ProcessIdentity& resourceOwner)
 {
+    setOwnershipIdentity(m_surface.get(), resourceOwner);
+}
+
+void IOSurface::setOwnershipIdentity(IOSurfaceRef surface, const ProcessIdentity& resourceOwner)
+{
 #if HAVE(IOSURFACE_SET_OWNERSHIP_IDENTITY) && HAVE(TASK_IDENTITY_TOKEN)
     ASSERT(resourceOwner);
+    ASSERT(surface);
     task_id_token_t ownerTaskIdToken = resourceOwner.taskIdToken();
-    auto result = IOSurfaceSetOwnershipIdentity(m_surface.get(), ownerTaskIdToken, kIOSurfaceMemoryLedgerTagGraphics, 0);
+    auto result = IOSurfaceSetOwnershipIdentity(surface, ownerTaskIdToken, kIOSurfaceMemoryLedgerTagGraphics, 0);
     if (result != kIOReturnSuccess)
-        RELEASE_LOG_ERROR(IOSurface, "IOSurface::setOwnershipIdentity: Failed to claim ownership of IOSurface %p, task id token: %d, error: %d", m_surface.get(), (int)ownerTaskIdToken, result);
+        RELEASE_LOG_ERROR(IOSurface, "IOSurface::setOwnershipIdentity: Failed to claim ownership of IOSurface %p, task id token: %d, error: %d", surface, (int)ownerTaskIdToken, result);
 #else
+    UNUSED_PARAM(surface);
     UNUSED_PARAM(resourceOwner);
 #endif
 }

Modified: trunk/Source/WebCore/platform/graphics/cv/CVUtilities.h (288788 => 288789)


--- trunk/Source/WebCore/platform/graphics/cv/CVUtilities.h	2022-01-29 07:34:08 UTC (rev 288788)
+++ trunk/Source/WebCore/platform/graphics/cv/CVUtilities.h	2022-01-29 11:49:46 UTC (rev 288789)
@@ -35,6 +35,7 @@
 using CVPixelBufferRef = struct __CVBuffer*;
 
 namespace WebCore {
+class ProcessIdentity;
 
 // Creates CVPixelBufferPool that creates CVPixelBuffers backed by IOSurfaces.
 // These buffers can be for example sent through IPC.
@@ -45,4 +46,8 @@
 WEBCORE_EXPORT Expected<RetainPtr<CVPixelBufferRef>, CVReturn> createCVPixelBuffer(IOSurfaceRef);
 
 RetainPtr<CGColorSpaceRef> createCGColorSpaceForCVPixelBuffer(CVPixelBufferRef);
+
+// Should be called with non-empty ProcessIdentity.
+WEBCORE_EXPORT void setOwnershipIdentityForCVPixelBuffer(CVPixelBufferRef, const ProcessIdentity&);
+
 }

Modified: trunk/Source/WebCore/platform/graphics/cv/CVUtilities.mm (288788 => 288789)


--- trunk/Source/WebCore/platform/graphics/cv/CVUtilities.mm	2022-01-29 07:34:08 UTC (rev 288788)
+++ trunk/Source/WebCore/platform/graphics/cv/CVUtilities.mm	2022-01-29 11:49:46 UTC (rev 288789)
@@ -27,6 +27,7 @@
 #import "CVUtilities.h"
 
 #import "ColorSpaceCG.h"
+#import "IOSurface.h"
 #import <wtf/StdLibExtras.h>
 #import <wtf/cf/TypeCastsCF.h>
 #import "CoreVideoSoftLink.h"
@@ -132,4 +133,11 @@
     return sRGBColorSpaceRef();
 }
 
+void setOwnershipIdentityForCVPixelBuffer(CVPixelBufferRef pixelBuffer, const ProcessIdentity& owner)
+{
+    auto surface = CVPixelBufferGetIOSurface(pixelBuffer);
+    ASSERT(surface);
+    IOSurface::setOwnershipIdentity(surface, owner);
 }
+
+}
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to