<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[284392] branches/safari-612-branch/Source</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/284392">284392</a></dd>
<dt>Author</dt> <dd>repstein@apple.com</dd>
<dt>Date</dt> <dd>2021-10-18 12:59:25 -0700 (Mon, 18 Oct 2021)</dd>
</dl>

<h3>Log Message</h3>
<pre>Apply patch. rdar://problem/84124701</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#branchessafari612branchSourceWebCoreChangeLog">branches/safari-612-branch/Source/WebCore/ChangeLog</a></li>
<li><a href="#branchessafari612branchSourceWebCorePlatformMaccmake">branches/safari-612-branch/Source/WebCore/PlatformMac.cmake</a></li>
<li><a href="#branchessafari612branchSourceWebCoreSourcesCocoatxt">branches/safari-612-branch/Source/WebCore/SourcesCocoa.txt</a></li>
<li><a href="#branchessafari612branchSourceWebCoreWebCorexcodeprojprojectpbxproj">branches/safari-612-branch/Source/WebCore/WebCore.xcodeproj/project.pbxproj</a></li>
<li><a href="#branchessafari612branchSourceWebCoreplatformgraphicscvImageTransferSessionVTh">branches/safari-612-branch/Source/WebCore/platform/graphics/cv/ImageTransferSessionVT.h</a></li>
<li><a href="#branchessafari612branchSourceWebCoreplatformgraphicscvImageTransferSessionVTmm">branches/safari-612-branch/Source/WebCore/platform/graphics/cv/ImageTransferSessionVT.mm</a></li>
<li><a href="#branchessafari612branchSourceWebCoreplatformmediastreammacRealtimeIncomingVideoSourceCocoamm">branches/safari-612-branch/Source/WebCore/platform/mediastream/mac/RealtimeIncomingVideoSourceCocoa.mm</a></li>
<li><a href="#branchessafari612branchSourceWebCoreplatformmediastreammacRealtimeVideoUtilitiesh">branches/safari-612-branch/Source/WebCore/platform/mediastream/mac/RealtimeVideoUtilities.h</a></li>
<li><a href="#branchessafari612branchSourceWebCoreplatformnetworkmacWebCoreURLResponsemm">branches/safari-612-branch/Source/WebCore/platform/network/mac/WebCoreURLResponse.mm</a></li>
<li><a href="#branchessafari612branchSourceWebKitChangeLog">branches/safari-612-branch/Source/WebKit/ChangeLog</a></li>
<li><a href="#branchessafari612branchSourceWebKitGPUProcesswebrtcLibWebRTCCodecsProxyh">branches/safari-612-branch/Source/WebKit/GPUProcess/webrtc/LibWebRTCCodecsProxy.h</a></li>
<li><a href="#branchessafari612branchSourceWebKitGPUProcesswebrtcLibWebRTCCodecsProxymm">branches/safari-612-branch/Source/WebKit/GPUProcess/webrtc/LibWebRTCCodecsProxy.mm</a></li>
<li><a href="#branchessafari612branchSourceWebKitWebProcessGPUwebrtcLibWebRTCCodecscpp">branches/safari-612-branch/Source/WebKit/WebProcess/GPU/webrtc/LibWebRTCCodecs.cpp</a></li>
<li><a href="#branchessafari612branchSourceWebKitWebProcessGPUwebrtcLibWebRTCCodecsh">branches/safari-612-branch/Source/WebKit/WebProcess/GPU/webrtc/LibWebRTCCodecs.h</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#branchessafari612branchSourceWebCoreplatformgraphicscvCVUtilitiesh">branches/safari-612-branch/Source/WebCore/platform/graphics/cv/CVUtilities.h</a></li>
<li><a href="#branchessafari612branchSourceWebCoreplatformgraphicscvCVUtilitiesmm">branches/safari-612-branch/Source/WebCore/platform/graphics/cv/CVUtilities.mm</a></li>
</ul>

<h3>Removed Paths</h3>
<ul>
<li><a href="#branchessafari612branchSourceWebCoreplatformmediastreammacRealtimeVideoUtilitiesmm">branches/safari-612-branch/Source/WebCore/platform/mediastream/mac/RealtimeVideoUtilities.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchessafari612branchSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-612-branch/Source/WebCore/ChangeLog (284391 => 284392)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-612-branch/Source/WebCore/ChangeLog      2021-10-18 19:59:10 UTC (rev 284391)
+++ branches/safari-612-branch/Source/WebCore/ChangeLog 2021-10-18 19:59:25 UTC (rev 284392)
</span><span class="lines">@@ -1,5 +1,76 @@
</span><span class="cx"> 2021-10-18  Russell Epstein  <repstein@apple.com>
</span><span class="cx"> 
</span><ins>+        Apply patch. rdar://problem/84124701
+
+    2021-10-18  Kimmo Kinnunen  <kkinnunen@apple.com>
+
+            Add utility to create CVPixelBuffers from IOSurfaces
+            https://bugs.webkit.org/show_bug.cgi?id=230338
+
+            Reviewed by Youenn Fablet.
+
+            Move the functionality of creating CVPixelBuffers
+            from IOSurfaces from ImageTransferSessionVT to
+            standalone functions in new header CVUtilities.
+            The functionality did not use any state of
+            ImageTransferSessionVT.
+
+            This functionality is useful in other scenarios too.
+
+            Remove instantiations of ImageTransferSessionVT from
+            the old call sites, as it was never used for anything
+            else than creation of the pixel buffer.
+
+            Move the related CVPixelBufferPool instantiation
+            from RealtimeVideoUtilities.h to CVUtilities.h
+
+            Remove the usage of kCVPixelFormatOpenGLESCompatibility
+            from the CVPixelBuffer creation code. It was incorrect property
+            all along, property of pixel formats not of pixel buffers. The
+            intended property was kCVPixelBufferOpenGLESCompatibilityKey
+            but it is not needed anymore.
+            Retains the usage of kCVPixelBufferOpenGLCompatibilityKey, though
+            it is incorrect and unneeded for the current operation too.
+            Since theoretically this could affect something on Mac, this
+            will be removed in a separate fix.
+
+            No new tests, a refactor.
+
+            * PlatformMac.cmake:
+            * SourcesCocoa.txt:
+            * WebCore.xcodeproj/project.pbxproj:
+            * platform/graphics/cv/CVUtilities.h: Added.
+            * platform/graphics/cv/CVUtilities.mm: Added.
+            (WebCore::createIOSurfaceCVPixelBufferPool):
+            (WebCore::createCVPixelBufferFromPool):
+            (WebCore::pixelBufferCreationOptions):
+            (WebCore::createCVPixelBuffer):
+            The added functions return Expected<object, status> since
+            some of the callers want to log the failure status code.
+            * platform/graphics/cv/ImageTransferSessionVT.h:
+            * platform/graphics/cv/ImageTransferSessionVT.mm:
+            (WebCore::ImageTransferSessionVT::setSize):
+            (WebCore::ImageTransferSessionVT::convertPixelBuffer):
+            (WebCore::ImageTransferSessionVT::convertCMSampleBuffer):
+            (WebCore::ImageTransferSessionVT::createCMSampleBuffer):
+            (WebCore::cvPixelFormatOpenGLKey): Deleted.
+            Incorrect, replaced with Mac-only use of OpenGLCompatibilityKey in
+            CVUtilities.mm.
+            (WebCore::roundUpToMacroblockMultiple): Deleted.
+            Use the similar function in WTF.
+            (WebCore::ImageTransferSessionVT::ioSurfacePixelBufferCreationOptions): Deleted.
+            * platform/mediastream/mac/RealtimeIncomingVideoSourceCocoa.mm:
+            (WebCore::RealtimeIncomingVideoSourceCocoa::pixelBufferPool):
+            * platform/mediastream/mac/RealtimeVideoUtilities.h:
+            Preserved, since preferedPixelBufferFormat means
+            "the pixel buffer format that is preferred by media stream implementations"
+            which does not fit to category of "CoreVideo Utilities".
+            * platform/mediastream/mac/RealtimeVideoUtilities.mm: Removed.
+            * platform/network/mac/WebCoreURLResponse.mm:
+            Fix unified build failure due to a missing include.
+
+2021-10-18  Russell Epstein  <repstein@apple.com>
+
</ins><span class="cx">         Apply patch. rdar://problem/84124706
</span><span class="cx"> 
</span><span class="cx">     2021-10-18  David Kilzer  <ddkilzer@apple.com>
</span></span></pre></div>
<a id="branchessafari612branchSourceWebCorePlatformMaccmake"></a>
<div class="modfile"><h4>Modified: branches/safari-612-branch/Source/WebCore/PlatformMac.cmake (284391 => 284392)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-612-branch/Source/WebCore/PlatformMac.cmake      2021-10-18 19:59:10 UTC (rev 284391)
+++ branches/safari-612-branch/Source/WebCore/PlatformMac.cmake 2021-10-18 19:59:25 UTC (rev 284392)
</span><span class="lines">@@ -337,6 +337,7 @@
</span><span class="cx">     platform/graphics/coretext/FontPlatformDataCoreText.cpp
</span><span class="cx">     platform/graphics/coretext/GlyphPageCoreText.cpp
</span><span class="cx"> 
</span><ins>+    platform/graphics/cv/CVUtilities.mm
</ins><span class="cx">     platform/graphics/cv/GraphicsContextGLCVANGLE.cpp
</span><span class="cx">     platform/graphics/cv/ImageRotationSessionVT.mm
</span><span class="cx">     platform/graphics/cv/PixelBufferConformerCV.cpp
</span></span></pre></div>
<a id="branchessafari612branchSourceWebCoreSourcesCocoatxt"></a>
<div class="modfile"><h4>Modified: branches/safari-612-branch/Source/WebCore/SourcesCocoa.txt (284391 => 284392)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-612-branch/Source/WebCore/SourcesCocoa.txt       2021-10-18 19:59:10 UTC (rev 284391)
+++ branches/safari-612-branch/Source/WebCore/SourcesCocoa.txt  2021-10-18 19:59:25 UTC (rev 284392)
</span><span class="lines">@@ -392,6 +392,7 @@
</span><span class="cx"> platform/graphics/coretext/FontCoreText.cpp
</span><span class="cx"> platform/graphics/coretext/FontPlatformDataCoreText.cpp
</span><span class="cx"> platform/graphics/coretext/GlyphPageCoreText.cpp
</span><ins>+platform/graphics/cv/CVUtilities.mm
</ins><span class="cx"> platform/graphics/cv/ImageTransferSessionVT.mm
</span><span class="cx"> platform/graphics/cv/PixelBufferConformerCV.cpp
</span><span class="cx"> platform/graphics/cv/GraphicsContextGLCVANGLE.cpp
</span><span class="lines">@@ -539,7 +540,6 @@
</span><span class="cx"> platform/mediastream/mac/RealtimeMediaSourceCenterMac.mm
</span><span class="cx"> platform/mediastream/mac/RealtimeOutgoingAudioSourceCocoa.cpp
</span><span class="cx"> platform/mediastream/mac/RealtimeOutgoingVideoSourceCocoa.cpp
</span><del>-platform/mediastream/mac/RealtimeVideoUtilities.mm
</del><span class="cx"> platform/mediastream/mac/ScreenDisplayCapturerMac.mm
</span><span class="cx"> platform/mediastream/mac/WebAudioSourceProviderCocoa.mm
</span><span class="cx"> platform/mediastream/mac/WindowDisplayCapturerMac.mm
</span></span></pre></div>
<a id="branchessafari612branchSourceWebCoreWebCorexcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: branches/safari-612-branch/Source/WebCore/WebCore.xcodeproj/project.pbxproj (284391 => 284392)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-612-branch/Source/WebCore/WebCore.xcodeproj/project.pbxproj      2021-10-18 19:59:10 UTC (rev 284391)
+++ branches/safari-612-branch/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2021-10-18 19:59:25 UTC (rev 284392)
</span><span class="lines">@@ -2321,6 +2321,7 @@
</span><span class="cx">          7B45AB5525FBA9DE00FD27F4 /* GraphicsContextGLANGLEEGLUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 7B45AB5425FBA9DD00FD27F4 /* GraphicsContextGLANGLEEGLUtilities.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">          7B6DC81925712E9200380C70 /* GraphicsContextGLIOSurfaceSwapChain.h in Headers */ = {isa = PBXBuildFile; fileRef = 7B6DC81725712E9200380C70 /* GraphicsContextGLIOSurfaceSwapChain.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">          7B7311FB25C092B7003B2796 /* ScopedHighPerformanceGPURequest.h in Headers */ = {isa = PBXBuildFile; fileRef = 7B7311FA25C092B7003B2796 /* ScopedHighPerformanceGPURequest.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><ins>+               7B8ED5F026F0C13D008AC023 /* CVUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 7B8ED5ED26F0C123008AC023 /* CVUtilities.h */; settings = {ATTRIBUTES = (Private, ); }; };
</ins><span class="cx">           7B90417025501142006EEB8C /* RemoteGraphicsContextGLProxyBase.h in Headers */ = {isa = PBXBuildFile; fileRef = 7B90416E25501109006EEB8C /* RemoteGraphicsContextGLProxyBase.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">          7BB34A1725345CB200029D08 /* GraphicsContextGLANGLEUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BB34A1625345CB200029D08 /* GraphicsContextGLANGLEUtilities.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">          7BB34A48253776CA00029D08 /* GraphicsContextGLImageExtractor.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BB34A45253776C600029D08 /* GraphicsContextGLImageExtractor.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="lines">@@ -7837,7 +7838,6 @@
</span><span class="cx">          415747441E38699E00E914D8 /* LibWebRTCProvider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LibWebRTCProvider.h; path = libwebrtc/LibWebRTCProvider.h; sourceTree = "<group>"; };
</span><span class="cx">          4157EBF81E3AB06800AC9FE9 /* MockLibWebRTCPeerConnection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MockLibWebRTCPeerConnection.h; sourceTree = "<group>"; };
</span><span class="cx">          4157EBF91E3AB06800AC9FE9 /* MockLibWebRTCPeerConnection.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MockLibWebRTCPeerConnection.cpp; sourceTree = "<group>"; };
</span><del>-               4158649F23BF7B9300A0A61E /* RealtimeVideoUtilities.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RealtimeVideoUtilities.mm; sourceTree = "<group>"; };
</del><span class="cx">           4158DCB624FFCD1B00B9DA41 /* RTCIceComponent.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = RTCIceComponent.idl; sourceTree = "<group>"; };
</span><span class="cx">          4158DCB824FFCDC300B9DA41 /* RTCIceProtocol.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = RTCIceProtocol.idl; sourceTree = "<group>"; };
</span><span class="cx">          4158DCB924FFCDC300B9DA41 /* RTCIceTcpCandidateType.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = RTCIceTcpCandidateType.idl; sourceTree = "<group>"; };
</span><span class="lines">@@ -10466,6 +10466,8 @@
</span><span class="cx">          7B6DC81725712E9200380C70 /* GraphicsContextGLIOSurfaceSwapChain.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GraphicsContextGLIOSurfaceSwapChain.h; sourceTree = "<group>"; };
</span><span class="cx">          7B7311FA25C092B7003B2796 /* ScopedHighPerformanceGPURequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScopedHighPerformanceGPURequest.h; sourceTree = "<group>"; };
</span><span class="cx">          7B774C6225FB93550091395F /* GraphicsContextGLANGLEEGLUtilities.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = GraphicsContextGLANGLEEGLUtilities.cpp; sourceTree = "<group>"; };
</span><ins>+               7B8ED5ED26F0C123008AC023 /* CVUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CVUtilities.h; sourceTree = "<group>"; };
+               7B8ED5EF26F0C123008AC023 /* CVUtilities.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CVUtilities.mm; sourceTree = "<group>"; };
</ins><span class="cx">           7B90416E25501109006EEB8C /* RemoteGraphicsContextGLProxyBase.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RemoteGraphicsContextGLProxyBase.h; sourceTree = "<group>"; };
</span><span class="cx">          7BB34A1625345CB200029D08 /* GraphicsContextGLANGLEUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GraphicsContextGLANGLEUtilities.h; sourceTree = "<group>"; };
</span><span class="cx">          7BB34A45253776C600029D08 /* GraphicsContextGLImageExtractor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GraphicsContextGLImageExtractor.h; sourceTree = "<group>"; };
</span><span class="lines">@@ -17468,7 +17470,6 @@
</span><span class="cx">                          5CDD833C1E4324BB00621B83 /* RealtimeOutgoingVideoSourceCocoa.h */,
</span><span class="cx">                          419242472127B7CC00634FCF /* RealtimeOutgoingVideoSourceCocoa.mm */,
</span><span class="cx">                          41D1938F2152C561006F14CA /* RealtimeVideoUtilities.h */,
</span><del>-                               4158649F23BF7B9300A0A61E /* RealtimeVideoUtilities.mm */,
</del><span class="cx">                           416F807C24509F3300B68F02 /* ScreenDisplayCapturerMac.h */,
</span><span class="cx">                          416F807A24509F3200B68F02 /* ScreenDisplayCapturerMac.mm */,
</span><span class="cx">                          07D6373E1BB0B11300256CE9 /* WebAudioSourceProviderCocoa.h */,
</span><span class="lines">@@ -28051,6 +28052,8 @@
</span><span class="cx">          CD9D827C1C7BB2ED006FF066 /* cv */ = {
</span><span class="cx">                  isa = PBXGroup;
</span><span class="cx">                  children = (
</span><ins>+                               7B8ED5ED26F0C123008AC023 /* CVUtilities.h */,
+                               7B8ED5EF26F0C123008AC023 /* CVUtilities.mm */,
</ins><span class="cx">                           7B10339D2549720100C8C1AC /* GraphicsContextGLCV.h */,
</span><span class="cx">                          7B10339A2549720000C8C1AC /* GraphicsContextGLCVANGLE.cpp */,
</span><span class="cx">                          7B10339C2549720100C8C1AC /* GraphicsContextGLCVANGLE.h */,
</span><span class="lines">@@ -31695,6 +31698,7 @@
</span><span class="cx">                          62CD325A1157E57C0063B0A7 /* CustomEvent.h in Headers */,
</span><span class="cx">                          5C5D2385227A0652000B9BDA /* CustomHeaderFields.h in Headers */,
</span><span class="cx">                          4B1E13E721790D660042CF98 /* CustomPaintCanvas.h in Headers */,
</span><ins>+                               7B8ED5F026F0C13D008AC023 /* CVUtilities.h in Headers */,
</ins><span class="cx">                           A8CB413E0E8633FD0032C4F0 /* DashArray.h in Headers */,
</span><span class="cx">                          97BC6A211505F081001B74AC /* Database.h in Headers */,
</span><span class="cx">                          97BC6A241505F081001B74AC /* DatabaseAuthorizer.h in Headers */,
</span></span></pre></div>
<a id="branchessafari612branchSourceWebCoreplatformgraphicscvCVUtilitiesh"></a>
<div class="addfile"><h4>Added: branches/safari-612-branch/Source/WebCore/platform/graphics/cv/CVUtilities.h (0 => 284392)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-612-branch/Source/WebCore/platform/graphics/cv/CVUtilities.h                             (rev 0)
+++ branches/safari-612-branch/Source/WebCore/platform/graphics/cv/CVUtilities.h        2021-10-18 19:59:25 UTC (rev 284392)
</span><span class="lines">@@ -0,0 +1,46 @@
</span><ins>+/*
+ * Copyright (C) 2021 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include <CoreVideo/CoreVideo.h>
+#include <utility>
+#include <wtf/Expected.h>
+#include <wtf/RetainPtr.h>
+
+using CVPixelBufferPoolRef = struct __CVPixelBufferPool*;
+using CVPixelBufferRef = struct __CVBuffer*;
+
+namespace WebCore {
+
+// Creates CVPixelBufferPool that creates CVPixelBuffers backed by IOSurfaces.
+// These buffers can be for example sent through IPC.
+WEBCORE_EXPORT Expected<RetainPtr<CVPixelBufferPoolRef>, CVReturn> createIOSurfaceCVPixelBufferPool(size_t width, size_t height, OSType pixelFormat, unsigned minimumBufferCount = 0u);
+
+WEBCORE_EXPORT Expected<RetainPtr<CVPixelBufferRef>, CVReturn> createCVPixelBufferFromPool(CVPixelBufferPoolRef);
+
+WEBCORE_EXPORT Expected<RetainPtr<CVPixelBufferRef>, CVReturn> createCVPixelBuffer(IOSurfaceRef);
+
+}
</ins></span></pre></div>
<a id="branchessafari612branchSourceWebCoreplatformgraphicscvCVUtilitiesmm"></a>
<div class="addfile"><h4>Added: branches/safari-612-branch/Source/WebCore/platform/graphics/cv/CVUtilities.mm (0 => 284392)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-612-branch/Source/WebCore/platform/graphics/cv/CVUtilities.mm                            (rev 0)
+++ branches/safari-612-branch/Source/WebCore/platform/graphics/cv/CVUtilities.mm       2021-10-18 19:59:25 UTC (rev 284392)
</span><span class="lines">@@ -0,0 +1,110 @@
</span><ins>+/*
+ * Copyright (C) 2021 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "CVUtilities.h"
+
+#import <wtf/StdLibExtras.h>
+#import "CoreVideoSoftLink.h"
+
+namespace WebCore {
+
+Expected<RetainPtr<CVPixelBufferPoolRef>, CVReturn> createIOSurfaceCVPixelBufferPool(size_t width, size_t height, OSType format, unsigned minimumBufferCount)
+{
+    auto pixelAttributes = @{
+        (__bridge NSString *)kCVPixelBufferWidthKey : @(width),
+        (__bridge NSString *)kCVPixelBufferHeightKey : @(height),
+        (__bridge NSString *)kCVPixelBufferPixelFormatTypeKey : @(format),
+        (__bridge NSString *)kCVPixelBufferCGImageCompatibilityKey : @NO,
+#if PLATFORM(MAC)
+        (__bridge NSString *)kCVPixelBufferOpenGLCompatibilityKey : @YES,
+#endif
+        (__bridge NSString *)kCVPixelBufferIOSurfacePropertiesKey : @{ }
+    };
+    NSDictionary *poolOptions = nullptr;
+    if (minimumBufferCount) {
+        poolOptions = @{
+            (__bridge NSString *)kCVPixelBufferPoolMinimumBufferCountKey : @(minimumBufferCount)
+        };
+    }
+    CVPixelBufferPoolRef pool = nullptr;
+    auto status = CVPixelBufferPoolCreate(kCFAllocatorDefault, (__bridge CFDictionaryRef)poolOptions, (__bridge CFDictionaryRef)pixelAttributes, &pool);
+    if (status != kCVReturnSuccess || !pool)
+        return makeUnexpected(status);
+    return adoptCF(pool);
+}
+
+Expected<RetainPtr<CVPixelBufferRef>, CVReturn> createCVPixelBufferFromPool(CVPixelBufferPoolRef pixelBufferPool)
+{
+    CVPixelBufferRef pixelBuffer = nullptr;
+    auto status = CVPixelBufferPoolCreatePixelBuffer(kCFAllocatorDefault, pixelBufferPool, &pixelBuffer);
+    if (status != kCVReturnSuccess || !pixelBuffer)
+        return makeUnexpected(status);
+    return adoptCF(pixelBuffer);
+}
+
+static CFDictionaryRef pixelBufferCreationOptions(IOSurfaceRef surface)
+{
+#if PLATFORM(MAC)
+    auto format = IOSurfaceGetPixelFormat(surface);
+    if (format == kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange || format == kCVPixelFormatType_420YpCbCr8BiPlanarFullRange) {
+        // YUV formats might contain extra pixels due to block size. Define the picture position
+        // in the buffer as the default top-left position. The caller might use the pixel buffer
+        // with APIs that expect the properties.
+        constexpr size_t macroblockSize = 16;
+        auto width = IOSurfaceGetWidth(surface);
+        auto height = IOSurfaceGetHeight(surface);
+        auto extendedRight = roundUpToMultipleOf(macroblockSize, width) - width;
+        auto extendedBottom = roundUpToMultipleOf(macroblockSize, height) - height;
+        if ((IOSurfaceGetBytesPerRowOfPlane(surface, 0) >= width + extendedRight)
+            && (IOSurfaceGetBytesPerRowOfPlane(surface, 1) >= width + extendedRight)
+            && (IOSurfaceGetAllocSize(surface) >= (height + extendedBottom) * IOSurfaceGetBytesPerRowOfPlane(surface, 0) * 3 / 2)) {
+            return (__bridge CFDictionaryRef) @{
+                (__bridge NSString *)kCVPixelBufferOpenGLCompatibilityKey : @YES,
+                (__bridge NSString *)kCVPixelBufferExtendedPixelsRightKey : @(extendedRight),
+                (__bridge NSString *)kCVPixelBufferExtendedPixelsBottomKey : @(extendedBottom)
+            };
+        }
+    }
+#else
+    UNUSED_PARAM(surface);
+#endif
+    return (__bridge CFDictionaryRef) @{
+#if PLATFORM(MAC)
+        (__bridge NSString *)kCVPixelBufferOpenGLCompatibilityKey : @YES
+#endif
+    };
+}
+
+Expected<RetainPtr<CVPixelBufferRef>, CVReturn> createCVPixelBuffer(IOSurfaceRef surface)
+{
+    CVPixelBufferRef pixelBuffer = nullptr;
+    auto status = CVPixelBufferCreateWithIOSurface(kCFAllocatorDefault, surface, pixelBufferCreationOptions(surface), &pixelBuffer);
+    if (status != kCVReturnSuccess || !pixelBuffer)
+        return makeUnexpected(status);
+    return adoptCF(pixelBuffer);
+}
+
+}
</ins></span></pre></div>
<a id="branchessafari612branchSourceWebCoreplatformgraphicscvImageTransferSessionVTh"></a>
<div class="modfile"><h4>Modified: branches/safari-612-branch/Source/WebCore/platform/graphics/cv/ImageTransferSessionVT.h (284391 => 284392)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-612-branch/Source/WebCore/platform/graphics/cv/ImageTransferSessionVT.h  2021-10-18 19:59:10 UTC (rev 284391)
+++ branches/safari-612-branch/Source/WebCore/platform/graphics/cv/ImageTransferSessionVT.h     2021-10-18 19:59:25 UTC (rev 284392)
</span><span class="lines">@@ -58,11 +58,6 @@
</span><span class="cx"> #endif
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-#if !PLATFORM(MACCATALYST)
-    WEBCORE_EXPORT RetainPtr<CVPixelBufferRef> createPixelBuffer(IOSurfaceRef);
-    WEBCORE_EXPORT RetainPtr<CVPixelBufferRef> createPixelBuffer(IOSurfaceRef, const IntSize&);
-#endif
-
</del><span class="cx">     uint32_t pixelFormat() const { return m_pixelFormat; }
</span><span class="cx"> 
</span><span class="cx"> private:
</span><span class="lines">@@ -69,7 +64,6 @@
</span><span class="cx">     WEBCORE_EXPORT explicit ImageTransferSessionVT(uint32_t pixelFormat);
</span><span class="cx"> 
</span><span class="cx"> #if !PLATFORM(MACCATALYST)
</span><del>-    CFDictionaryRef ioSurfacePixelBufferCreationOptions(IOSurfaceRef);
</del><span class="cx">     RetainPtr<CMSampleBufferRef> createCMSampleBuffer(IOSurfaceRef, const MediaTime&, const IntSize&);
</span><span class="cx"> #endif
</span><span class="cx"> 
</span></span></pre></div>
<a id="branchessafari612branchSourceWebCoreplatformgraphicscvImageTransferSessionVTmm"></a>
<div class="modfile"><h4>Modified: branches/safari-612-branch/Source/WebCore/platform/graphics/cv/ImageTransferSessionVT.mm (284391 => 284392)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-612-branch/Source/WebCore/platform/graphics/cv/ImageTransferSessionVT.mm 2021-10-18 19:59:10 UTC (rev 284391)
+++ branches/safari-612-branch/Source/WebCore/platform/graphics/cv/ImageTransferSessionVT.mm    2021-10-18 19:59:25 UTC (rev 284392)
</span><span class="lines">@@ -26,6 +26,7 @@
</span><span class="cx"> #import "config.h"
</span><span class="cx"> #import "ImageTransferSessionVT.h"
</span><span class="cx"> 
</span><ins>+#import "CVUtilities.h"
</ins><span class="cx"> #import "GraphicsContextCG.h"
</span><span class="cx"> #import "Logging.h"
</span><span class="cx"> #import "MediaSampleAVFObjC.h"
</span><span class="lines">@@ -43,15 +44,6 @@
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><del>-static inline CFStringRef cvPixelFormatOpenGLKey()
-{
-#if PLATFORM(IOS_FAMILY) && !PLATFORM(MACCATALYST)
-    return kCVPixelFormatOpenGLESCompatibility;
-#else
-    return kCVPixelBufferOpenGLCompatibilityKey;
-#endif
-}
-
</del><span class="cx"> ImageTransferSessionVT::ImageTransferSessionVT(uint32_t pixelFormat)
</span><span class="cx"> {
</span><span class="cx">     VTPixelTransferSessionRef transferSession;
</span><span class="lines">@@ -84,29 +76,11 @@
</span><span class="cx"> {
</span><span class="cx">     if (m_size == size && m_outputBufferPool)
</span><span class="cx">         return true;
</span><del>-
-    NSDictionary* pixelBufferOptions = @{
-        (__bridge NSString *)kCVPixelBufferWidthKey : @(size.width()),
-        (__bridge NSString *)kCVPixelBufferHeightKey : @(size.height()),
-        (__bridge NSString *)kCVPixelBufferPixelFormatTypeKey : @(m_pixelFormat),
-        (__bridge NSString *)cvPixelFormatOpenGLKey() : @YES,
-        (__bridge NSString *)kCVPixelBufferIOSurfacePropertiesKey : @{ /*empty dictionary*/ },
-    };
-
-    NSDictionary* pixelBufferPoolOptions = @{
-        (__bridge NSString *)kCVPixelBufferPoolMinimumBufferCountKey: @(6)
-    };
-
-    CVPixelBufferPoolRef bufferPool;
-    auto status = CVPixelBufferPoolCreate(kCFAllocatorDefault, (__bridge CFDictionaryRef)pixelBufferPoolOptions, (__bridge CFDictionaryRef)pixelBufferOptions, &bufferPool);
-    ASSERT(!status);
-    if (status != kCVReturnSuccess)
</del><ins>+    auto bufferPool = createIOSurfaceCVPixelBufferPool(size.width(), size.height(), m_pixelFormat, 6).value_or(nullptr);
+    if (!bufferPool)
</ins><span class="cx">         return false;
</span><del>-
-    m_outputBufferPool = adoptCF(bufferPool);
</del><ins>+    m_outputBufferPool = WTFMove(bufferPool);
</ins><span class="cx">     m_size = size;
</span><del>-    m_ioSurfaceBufferAttributes = nullptr;
-
</del><span class="cx">     return true;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -118,28 +92,22 @@
</span><span class="cx">     if (!sourceBuffer || !setSize(size))
</span><span class="cx">         return nullptr;
</span><span class="cx"> 
</span><del>-    CVPixelBufferRef outputBuffer = nullptr;
-    auto status = CVPixelBufferPoolCreatePixelBuffer(kCFAllocatorDefault, m_outputBufferPool.get(), &outputBuffer);
-    if (status) {
-        RELEASE_LOG(Media, "ImageTransferSessionVT::convertPixelBuffer, CVPixelBufferPoolCreatePixelBuffer failed with error %d", static_cast<int>(status));
</del><ins>+    auto result = createCVPixelBufferFromPool(m_outputBufferPool.get());
+    if (!result) {
+        RELEASE_LOG(Media, "ImageTransferSessionVT::convertPixelBuffer, createCVPixelBufferFromPool failed with error %d", static_cast<int>(result.error()));
</ins><span class="cx">         return nullptr;
</span><span class="cx">     }
</span><del>-    auto result = adoptCF(outputBuffer);
</del><ins>+    auto outputBuffer = WTFMove(*result);
</ins><span class="cx"> 
</span><del>-    auto err = VTPixelTransferSessionTransferImage(m_transferSession.get(), sourceBuffer, outputBuffer);
</del><ins>+    auto err = VTPixelTransferSessionTransferImage(m_transferSession.get(), sourceBuffer, outputBuffer.get());
</ins><span class="cx">     if (err) {
</span><span class="cx">         RELEASE_LOG(Media, "ImageTransferSessionVT::convertPixelBuffer, VTPixelTransferSessionTransferImage failed with error %d", static_cast<int>(err));
</span><span class="cx">         return nullptr;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    return result;
</del><ins>+    return outputBuffer;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-RetainPtr<CVPixelBufferRef> ImageTransferSessionVT::createPixelBuffer(CMSampleBufferRef sourceBuffer, const IntSize& size)
-{
-    return convertPixelBuffer(PAL::CMSampleBufferGetImageBuffer(sourceBuffer), size);
-}
-
</del><span class="cx"> RetainPtr<CMSampleBufferRef> ImageTransferSessionVT::convertCMSampleBuffer(CMSampleBufferRef sourceBuffer, const IntSize& size)
</span><span class="cx"> {
</span><span class="cx">     if (!sourceBuffer)
</span><span class="lines">@@ -154,7 +122,7 @@
</span><span class="cx">     if (!setSize(size))
</span><span class="cx">         return nullptr;
</span><span class="cx"> 
</span><del>-    auto convertedPixelBuffer = createPixelBuffer(sourceBuffer, size);
</del><ins>+    auto convertedPixelBuffer = convertPixelBuffer(pixelBuffer, size);
</ins><span class="cx">     if (!convertedPixelBuffer)
</span><span class="cx">         return nullptr;
</span><span class="cx"> 
</span><span class="lines">@@ -266,82 +234,11 @@
</span><span class="cx"> 
</span><span class="cx"> #if !PLATFORM(MACCATALYST)
</span><span class="cx"> 
</span><del>-#if PLATFORM(MAC)
-static int32_t roundUpToMacroblockMultiple(int32_t size)
</del><ins>+RetainPtr<CMSampleBufferRef> ImageTransferSessionVT::createCMSampleBuffer(IOSurfaceRef surface, const MediaTime &sampleTime, const IntSize &size)
</ins><span class="cx"> {
</span><del>-    return (size + 15) & ~15;
-}
-#endif
-
-CFDictionaryRef ImageTransferSessionVT::ioSurfacePixelBufferCreationOptions(IOSurfaceRef surface)
-{
-    if (m_ioSurfaceBufferAttributes)
-        return m_ioSurfaceBufferAttributes.get();
-
-    m_ioSurfaceBufferAttributes = (__bridge CFDictionaryRef) @{
-        (__bridge NSString *)cvPixelFormatOpenGLKey() : @YES,
-    };
-
-#if PLATFORM(MAC)
-    auto format = IOSurfaceGetPixelFormat(surface);
-    auto width = IOSurfaceGetWidth(surface);
-    auto height = IOSurfaceGetHeight(surface);
-    auto extendedRight = roundUpToMacroblockMultiple(width) - width;
-    auto extendedBottom = roundUpToMacroblockMultiple(height) - height;
-
-    if ((format == kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange || format == kCVPixelFormatType_420YpCbCr8BiPlanarFullRange)
-        && (IOSurfaceGetBytesPerRowOfPlane(surface, 0) >= width + extendedRight)
-        && (IOSurfaceGetBytesPerRowOfPlane(surface, 1) >= width + extendedRight)
-        && (IOSurfaceGetAllocSize(surface) >= (height + extendedBottom) * IOSurfaceGetBytesPerRowOfPlane(surface, 0) * 3 / 2)) {
-            m_ioSurfaceBufferAttributes = (__bridge CFDictionaryRef) @{
-                (__bridge NSString *)kCVPixelBufferOpenGLCompatibilityKey : @YES,
-                (__bridge NSString *)kCVPixelBufferExtendedPixelsRightKey : @(extendedRight),
-                (__bridge NSString *)kCVPixelBufferExtendedPixelsBottomKey : @(extendedBottom)
-            };
-    }
-#else
-    UNUSED_PARAM(surface);
-#endif
-
-    return m_ioSurfaceBufferAttributes.get();
-}
-
-RetainPtr<CVPixelBufferRef> ImageTransferSessionVT::createPixelBuffer(IOSurfaceRef surface)
-{
-    if (!surface)
-        return nullptr;
-
-    CVPixelBufferRef pixelBuffer;
-    auto status = CVPixelBufferCreateWithIOSurface(kCFAllocatorDefault, surface, ioSurfacePixelBufferCreationOptions(surface), &pixelBuffer);
-    if (status) {
-        RELEASE_LOG(Media, "CVPixelBufferCreateWithIOSurface failed with error code: %d", static_cast<int>(status));
-        return nullptr;
-    }
-    return adoptCF(pixelBuffer);
-}
-
-RetainPtr<CVPixelBufferRef> ImageTransferSessionVT::createPixelBuffer(IOSurfaceRef surface, const IntSize& size)
-{
</del><span class="cx">     if (!surface || !setSize(size))
</span><span class="cx">         return nullptr;
</span><del>-
-    CVPixelBufferRef pixelBuffer;
-    auto status = CVPixelBufferCreateWithIOSurface(kCFAllocatorDefault, surface, ioSurfacePixelBufferCreationOptions(surface), &pixelBuffer);
-    if (status) {
-        RELEASE_LOG(Media, "CVPixelBufferCreateWithIOSurface failed with error code: %d", static_cast<int>(status));
-        return nullptr;
-    }
-
-    auto retainedBuffer = adoptCF(pixelBuffer);
-    if (m_size == IntSize(CVPixelBufferGetWidth(pixelBuffer), CVPixelBufferGetHeight(pixelBuffer)) && m_pixelFormat == CVPixelBufferGetPixelFormatType(pixelBuffer))
-        return retainedBuffer;
-
-    return convertPixelBuffer(pixelBuffer, size);
-}
-
-RetainPtr<CMSampleBufferRef> ImageTransferSessionVT::createCMSampleBuffer(IOSurfaceRef surface, const MediaTime& sampleTime, const IntSize& size)
-{
-    auto pixelBuffer = createPixelBuffer(surface, size);
</del><ins>+    auto pixelBuffer = createCVPixelBuffer(surface).value_or(nullptr);
</ins><span class="cx">     if (!pixelBuffer)
</span><span class="cx">         return nullptr;
</span><span class="cx"> 
</span></span></pre></div>
<a id="branchessafari612branchSourceWebCoreplatformmediastreammacRealtimeIncomingVideoSourceCocoamm"></a>
<div class="modfile"><h4>Modified: branches/safari-612-branch/Source/WebCore/platform/mediastream/mac/RealtimeIncomingVideoSourceCocoa.mm (284391 => 284392)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-612-branch/Source/WebCore/platform/mediastream/mac/RealtimeIncomingVideoSourceCocoa.mm   2021-10-18 19:59:10 UTC (rev 284391)
+++ branches/safari-612-branch/Source/WebCore/platform/mediastream/mac/RealtimeIncomingVideoSourceCocoa.mm      2021-10-18 19:59:25 UTC (rev 284392)
</span><span class="lines">@@ -30,6 +30,7 @@
</span><span class="cx"> 
</span><span class="cx"> #if USE(LIBWEBRTC)
</span><span class="cx"> 
</span><ins>+#import "CVUtilities.h"
</ins><span class="cx"> #import "Logging.h"
</span><span class="cx"> #import "MediaSampleAVFObjC.h"
</span><span class="cx"> #import "RealtimeVideoUtilities.h"
</span><span class="lines">@@ -39,6 +40,7 @@
</span><span class="cx"> #import <webrtc/sdk/WebKit/WebKitUtilities.h>
</span><span class="cx"> ALLOW_UNUSED_PARAMETERS_END
</span><span class="cx"> 
</span><ins>+#import "CoreVideoSoftLink.h"
</ins><span class="cx"> #import <pal/cf/CoreMediaSoftLink.h>
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="lines">@@ -98,10 +100,12 @@
</span><span class="cx">         case webrtc::BufferType::I010:
</span><span class="cx">             poolBufferType = kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange;
</span><span class="cx">         }
</span><del>-        m_pixelBufferPool = createPixelBufferPool(width, height, poolBufferType);
-        m_pixelBufferPoolWidth = width;
-        m_pixelBufferPoolHeight = height;
-        m_pixelBufferPoolBufferType = bufferType;
</del><ins>+        if (auto pool = createIOSurfaceCVPixelBufferPool(width, height, poolBufferType)) {
+            m_pixelBufferPool = WTFMove(*pool);
+            m_pixelBufferPoolWidth = width;
+            m_pixelBufferPoolHeight = height;
+            m_pixelBufferPoolBufferType = bufferType;
+        }
</ins><span class="cx">     }
</span><span class="cx">     return m_pixelBufferPool.get();
</span><span class="cx"> }
</span></span></pre></div>
<a id="branchessafari612branchSourceWebCoreplatformmediastreammacRealtimeVideoUtilitiesh"></a>
<div class="modfile"><h4>Modified: branches/safari-612-branch/Source/WebCore/platform/mediastream/mac/RealtimeVideoUtilities.h (284391 => 284392)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-612-branch/Source/WebCore/platform/mediastream/mac/RealtimeVideoUtilities.h      2021-10-18 19:59:10 UTC (rev 284391)
+++ branches/safari-612-branch/Source/WebCore/platform/mediastream/mac/RealtimeVideoUtilities.h 2021-10-18 19:59:25 UTC (rev 284392)
</span><span class="lines">@@ -27,9 +27,6 @@
</span><span class="cx"> 
</span><span class="cx"> #include <CoreVideo/CoreVideo.h>
</span><span class="cx"> 
</span><del>-using CVPixelBufferPoolRef = struct __CVPixelBufferPool*;
-using CVPixelBufferRef = struct __CVBuffer*;
-
</del><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><span class="cx"> static inline OSType preferedPixelBufferFormat()
</span><span class="lines">@@ -41,7 +38,4 @@
</span><span class="cx"> #endif
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-WEBCORE_EXPORT RetainPtr<CVPixelBufferPoolRef> createPixelBufferPool(size_t width, size_t height, OSType);
-WEBCORE_EXPORT RetainPtr<CVPixelBufferRef> createPixelBufferFromPool(CVPixelBufferPoolRef);
-
</del><span class="cx"> }
</span></span></pre></div>
<a id="branchessafari612branchSourceWebCoreplatformmediastreammacRealtimeVideoUtilitiesmm"></a>
<div class="delfile"><h4>Deleted: branches/safari-612-branch/Source/WebCore/platform/mediastream/mac/RealtimeVideoUtilities.mm (284391 => 284392)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-612-branch/Source/WebCore/platform/mediastream/mac/RealtimeVideoUtilities.mm     2021-10-18 19:59:10 UTC (rev 284391)
+++ branches/safari-612-branch/Source/WebCore/platform/mediastream/mac/RealtimeVideoUtilities.mm        2021-10-18 19:59:25 UTC (rev 284392)
</span><span class="lines">@@ -1,67 +0,0 @@
</span><del>-/*
- * Copyright (C) 2020 Apple Inc.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted, provided that the following conditions
- * are required to be met:
- *
- * 1.  Redistributions of source code must retain the above copyright
- *     notice, this list of conditions and the following disclaimer.
- * 2.  Redistributions in binary form must reproduce the above copyright
- *     notice, this list of conditions and the following disclaimer in the
- *     documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS "AS IS" AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL APPLE INC. AND ITS CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#import "config.h"
-#import "RealtimeVideoUtilities.h"
-
-#import "CoreVideoSoftLink.h"
-
-namespace WebCore {
-
-RetainPtr<CVPixelBufferPoolRef> createPixelBufferPool(size_t width, size_t height, OSType videoCaptureFormat)
-{
-    auto pixelAttributes = @{
-        (__bridge NSString *)kCVPixelBufferWidthKey: @(width),
-        (__bridge NSString *)kCVPixelBufferHeightKey: @(height),
-        (__bridge NSString *)kCVPixelBufferPixelFormatTypeKey: @(videoCaptureFormat),
-        (__bridge NSString *)kCVPixelBufferCGImageCompatibilityKey: @NO,
-#if PLATFORM(IOS_FAMILY)
-        (__bridge NSString *)kCVPixelFormatOpenGLESCompatibility : @YES,
-#else
-        (__bridge NSString *)kCVPixelBufferOpenGLCompatibilityKey : @YES,
-#endif
-        (__bridge NSString *)kCVPixelBufferIOSurfacePropertiesKey : @{ }
-    };
-
-    CVPixelBufferPoolRef pool = nullptr;
-    auto status = CVPixelBufferPoolCreate(kCFAllocatorDefault, nullptr, (__bridge CFDictionaryRef)pixelAttributes, &pool);
-
-    if (status != kCVReturnSuccess)
-        return nullptr;
-
-    return adoptCF(pool);
-}
-
-RetainPtr<CVPixelBufferRef> createPixelBufferFromPool(CVPixelBufferPoolRef pixelBufferPool)
-{
-    CVPixelBufferRef pixelBuffer = nullptr;
-    auto status = CVPixelBufferPoolCreatePixelBuffer(kCFAllocatorDefault, pixelBufferPool, &pixelBuffer);
-
-    if (status != kCVReturnSuccess)
-        return nullptr;
-    return adoptCF(pixelBuffer);
-}
-
-}
</del></span></pre></div>
<a id="branchessafari612branchSourceWebCoreplatformnetworkmacWebCoreURLResponsemm"></a>
<div class="modfile"><h4>Modified: branches/safari-612-branch/Source/WebCore/platform/network/mac/WebCoreURLResponse.mm (284391 => 284392)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-612-branch/Source/WebCore/platform/network/mac/WebCoreURLResponse.mm     2021-10-18 19:59:10 UTC (rev 284391)
+++ branches/safari-612-branch/Source/WebCore/platform/network/mac/WebCoreURLResponse.mm        2021-10-18 19:59:25 UTC (rev 284392)
</span><span class="lines">@@ -35,6 +35,7 @@
</span><span class="cx"> #import <pal/spi/cf/CFNetworkSPI.h>
</span><span class="cx"> #import <wtf/Assertions.h>
</span><span class="cx"> #import <wtf/RetainPtr.h>
</span><ins>+#import <wtf/SortedArrayMap.h>
</ins><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span></span></pre></div>
<a id="branchessafari612branchSourceWebKitChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-612-branch/Source/WebKit/ChangeLog (284391 => 284392)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-612-branch/Source/WebKit/ChangeLog       2021-10-18 19:59:10 UTC (rev 284391)
+++ branches/safari-612-branch/Source/WebKit/ChangeLog  2021-10-18 19:59:25 UTC (rev 284392)
</span><span class="lines">@@ -1,5 +1,33 @@
</span><span class="cx"> 2021-10-18  Russell Epstein  <repstein@apple.com>
</span><span class="cx"> 
</span><ins>+        Apply patch. rdar://problem/84124701
+
+    2021-10-18  Kimmo Kinnunen  <kkinnunen@apple.com>
+
+            Add utility to create CVPixelBuffers from IOSurfaces
+            https://bugs.webkit.org/show_bug.cgi?id=230338
+
+            Reviewed by Youenn Fablet.
+
+            The helper function moved from ImageTransferSessionVT
+            to free standalone function. Stop instantiating the
+            object and just call the function.
+
+            In both of the cases, the pixel buffer is created out of
+            the IOSurface and the pool is not used. In both of the cases
+            the size and the pixel format of the image transfer session
+            is the same as the input IOSurface.
+
+            * GPUProcess/webrtc/LibWebRTCCodecsProxy.h:
+            * GPUProcess/webrtc/LibWebRTCCodecsProxy.mm:
+            * WebProcess/GPU/webrtc/LibWebRTCCodecs.cpp:
+            (WebKit::LibWebRTCCodecs::completedDecoding):
+            (WebKit::LibWebRTCCodecs::encodeFrame):
+            (WebKit::LibWebRTCCodecs::pixelBufferPool):
+            * WebProcess/GPU/webrtc/LibWebRTCCodecs.h:
+
+2021-10-18  Russell Epstein  <repstein@apple.com>
+
</ins><span class="cx">         Apply patch. rdar://problem/84124706
</span><span class="cx"> 
</span><span class="cx">     2021-10-18  David Kilzer  <ddkilzer@apple.com>
</span></span></pre></div>
<a id="branchessafari612branchSourceWebKitGPUProcesswebrtcLibWebRTCCodecsProxyh"></a>
<div class="modfile"><h4>Modified: branches/safari-612-branch/Source/WebKit/GPUProcess/webrtc/LibWebRTCCodecsProxy.h (284391 => 284392)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-612-branch/Source/WebKit/GPUProcess/webrtc/LibWebRTCCodecsProxy.h        2021-10-18 19:59:10 UTC (rev 284391)
+++ branches/safari-612-branch/Source/WebKit/GPUProcess/webrtc/LibWebRTCCodecsProxy.h   2021-10-18 19:59:25 UTC (rev 284392)
</span><span class="lines">@@ -31,7 +31,6 @@
</span><span class="cx"> #include "DataReference.h"
</span><span class="cx"> #include "RTCDecoderIdentifier.h"
</span><span class="cx"> #include "RTCEncoderIdentifier.h"
</span><del>-#include <WebCore/ImageTransferSessionVT.h>
</del><span class="cx"> #include <wtf/Lock.h>
</span><span class="cx"> 
</span><span class="cx"> namespace IPC {
</span><span class="lines">@@ -93,7 +92,6 @@
</span><span class="cx">     HashMap<RTCEncoderIdentifier, webrtc::LocalEncoder> m_encoders WTF_GUARDED_BY_LOCK(m_lock); // Only modified on the libWebRTCCodecsQueue but may get accessed from the main thread.
</span><span class="cx"> 
</span><span class="cx">     Ref<WorkQueue> m_queue;
</span><del>-    std::unique_ptr<WebCore::ImageTransferSessionVT> m_imageTransferSession;
</del><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> }
</span></span></pre></div>
<a id="branchessafari612branchSourceWebKitGPUProcesswebrtcLibWebRTCCodecsProxymm"></a>
<div class="modfile"><h4>Modified: branches/safari-612-branch/Source/WebKit/GPUProcess/webrtc/LibWebRTCCodecsProxy.mm (284391 => 284392)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-612-branch/Source/WebKit/GPUProcess/webrtc/LibWebRTCCodecsProxy.mm       2021-10-18 19:59:10 UTC (rev 284391)
+++ branches/safari-612-branch/Source/WebKit/GPUProcess/webrtc/LibWebRTCCodecsProxy.mm  2021-10-18 19:59:25 UTC (rev 284392)
</span><span class="lines">@@ -33,6 +33,7 @@
</span><span class="cx"> #import "LibWebRTCCodecsMessages.h"
</span><span class="cx"> #import "LibWebRTCCodecsProxyMessages.h"
</span><span class="cx"> #import "WebCoreArgumentCoders.h"
</span><ins>+#import <WebCore/CVUtilities.h>
</ins><span class="cx"> #import <WebCore/LibWebRTCProvider.h>
</span><span class="cx"> #import <WebCore/RemoteVideoSample.h>
</span><span class="cx"> #import <webrtc/sdk/WebKit/WebKitDecoder.h>
</span><span class="lines">@@ -207,12 +208,13 @@
</span><span class="cx">     if (!encoder)
</span><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    if (!m_imageTransferSession || m_imageTransferSession->pixelFormat() != sample.videoFormat())
-        m_imageTransferSession = WebCore::ImageTransferSessionVT::create(sample.videoFormat());
-
</del><span class="cx"> #if !PLATFORM(MACCATALYST)
</span><del>-    auto pixelBuffer = m_imageTransferSession->createPixelBuffer(sample.surface());
-    webrtc::encodeLocalEncoderFrame(encoder, pixelBuffer.get(), sample.time().toTimeScale(1000000).timeValue(), timeStamp, toWebRTCVideoRotation(sample.rotation()), shouldEncodeAsKeyFrame);
</del><ins>+    if (!sample.surface())
+        return;
+    auto pixelBuffer = WebCore::createCVPixelBuffer(sample.surface());
+    if (!pixelBuffer)
+        return;
+    webrtc::encodeLocalEncoderFrame(encoder, pixelBuffer->get(), sample.time().toTimeScale(1000000).timeValue(), timeStamp, toWebRTCVideoRotation(sample.rotation()), shouldEncodeAsKeyFrame);
</ins><span class="cx"> #endif
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="branchessafari612branchSourceWebKitWebProcessGPUwebrtcLibWebRTCCodecscpp"></a>
<div class="modfile"><h4>Modified: branches/safari-612-branch/Source/WebKit/WebProcess/GPU/webrtc/LibWebRTCCodecs.cpp (284391 => 284392)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-612-branch/Source/WebKit/WebProcess/GPU/webrtc/LibWebRTCCodecs.cpp       2021-10-18 19:59:10 UTC (rev 284391)
+++ branches/safari-612-branch/Source/WebKit/WebProcess/GPU/webrtc/LibWebRTCCodecs.cpp  2021-10-18 19:59:25 UTC (rev 284392)
</span><span class="lines">@@ -33,9 +33,9 @@
</span><span class="cx"> #include "LibWebRTCCodecsProxyMessages.h"
</span><span class="cx"> #include "WebCoreArgumentCoders.h"
</span><span class="cx"> #include "WebProcess.h"
</span><ins>+#include <WebCore/CVUtilities.h>
</ins><span class="cx"> #include <WebCore/LibWebRTCMacros.h>
</span><span class="cx"> #include <WebCore/PlatformMediaSessionManager.h>
</span><del>-#include <WebCore/RealtimeVideoUtilities.h>
</del><span class="cx"> #include <WebCore/RemoteVideoSample.h>
</span><span class="cx"> #include <WebCore/RuntimeEnabledFeatures.h>
</span><span class="cx"> #include <WebCore/VP9UtilitiesCocoa.h>
</span><span class="lines">@@ -331,15 +331,9 @@
</span><span class="cx">     if (!decoder->decodedImageCallback)
</span><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    if (!m_imageTransferSession || m_imageTransferSession->pixelFormat() != remoteSample.videoFormat())
-        m_imageTransferSession = WebCore::ImageTransferSessionVT::create(remoteSample.videoFormat());
-
-    if (!m_imageTransferSession) {
-        ASSERT_NOT_REACHED();
</del><ins>+    if (!remoteSample.surface())
</ins><span class="cx">         return;
</span><del>-    }
-
-    auto pixelBuffer = m_imageTransferSession->createPixelBuffer(remoteSample.surface(), remoteSample.size());
</del><ins>+    auto pixelBuffer = createCVPixelBuffer(remoteSample.surface()).value_or(nullptr);
</ins><span class="cx">     if (!pixelBuffer) {
</span><span class="cx">         ASSERT_NOT_REACHED();
</span><span class="cx">         return;
</span><span class="lines">@@ -443,7 +437,7 @@
</span><span class="cx">         if (!pixelBufferPool)
</span><span class="cx">             return nullptr;
</span><span class="cx"> 
</span><del>-        return WebCore::createPixelBufferFromPool(pixelBufferPool).leakRef();
</del><ins>+        return WebCore::createCVPixelBufferFromPool(pixelBufferPool).value_or(nullptr).leakRef();
</ins><span class="cx">     }));
</span><span class="cx"> 
</span><span class="cx">     if (!pixelBuffer)
</span><span class="lines">@@ -502,9 +496,14 @@
</span><span class="cx"> CVPixelBufferPoolRef LibWebRTCCodecs::pixelBufferPool(size_t width, size_t height, OSType type)
</span><span class="cx"> {
</span><span class="cx">     if (!m_pixelBufferPool || m_pixelBufferPoolWidth != width || m_pixelBufferPoolHeight != height) {
</span><del>-        m_pixelBufferPool = createPixelBufferPool(width, height, type);
-        m_pixelBufferPoolWidth = width;
-        m_pixelBufferPoolHeight = height;
</del><ins>+        m_pixelBufferPool = nullptr;
+        m_pixelBufferPoolWidth = 0;
+        m_pixelBufferPoolHeight = 0;
+        if (auto pool = WebCore::createIOSurfaceCVPixelBufferPool(width, height, type)) {
+            m_pixelBufferPool = WTFMove(*pool);
+            m_pixelBufferPoolWidth = width;
+            m_pixelBufferPoolHeight = height;
+        }
</ins><span class="cx">     }
</span><span class="cx">     return m_pixelBufferPool.get();
</span><span class="cx"> }
</span></span></pre></div>
<a id="branchessafari612branchSourceWebKitWebProcessGPUwebrtcLibWebRTCCodecsh"></a>
<div class="modfile"><h4>Modified: branches/safari-612-branch/Source/WebKit/WebProcess/GPU/webrtc/LibWebRTCCodecs.h (284391 => 284392)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-612-branch/Source/WebKit/WebProcess/GPU/webrtc/LibWebRTCCodecs.h 2021-10-18 19:59:10 UTC (rev 284391)
+++ branches/safari-612-branch/Source/WebKit/WebProcess/GPU/webrtc/LibWebRTCCodecs.h    2021-10-18 19:59:25 UTC (rev 284392)
</span><span class="lines">@@ -33,7 +33,6 @@
</span><span class="cx"> #include "MessageReceiver.h"
</span><span class="cx"> #include "RTCDecoderIdentifier.h"
</span><span class="cx"> #include "RTCEncoderIdentifier.h"
</span><del>-#include <WebCore/ImageTransferSessionVT.h>
</del><span class="cx"> #include <WebCore/PixelBufferConformerCV.h>
</span><span class="cx"> #include <map>
</span><span class="cx"> #include <webrtc/api/video/video_codec_type.h>
</span><span class="lines">@@ -149,7 +148,6 @@
</span><span class="cx">     Vector<Function<void()>> m_tasksToDispatchAfterEstablishingConnection;
</span><span class="cx"> 
</span><span class="cx">     Ref<WorkQueue> m_queue;
</span><del>-    std::unique_ptr<WebCore::ImageTransferSessionVT> m_imageTransferSession;
</del><span class="cx">     std::unique_ptr<WebCore::PixelBufferConformerCV> m_pixelBufferConformer;
</span><span class="cx">     RetainPtr<CVPixelBufferPoolRef> m_pixelBufferPool;
</span><span class="cx">     size_t m_pixelBufferPoolWidth { 0 };
</span></span></pre>
</div>
</div>

</body>
</html>