Diff
Modified: trunk/Source/WebCore/ChangeLog (286837 => 286838)
--- trunk/Source/WebCore/ChangeLog 2021-12-10 08:22:37 UTC (rev 286837)
+++ trunk/Source/WebCore/ChangeLog 2021-12-10 08:24:30 UTC (rev 286838)
@@ -1,3 +1,53 @@
+2021-12-10 Kimmo Kinnunen <kkinnu...@apple.com>
+
+ IOSurface memory attribution is hard to use in constructors
+ https://bugs.webkit.org/show_bug.cgi?id=232988
+ <rdar://problem/85541918>
+
+ Reviewed by Chris Dumez.
+
+ Add WebCore::ProcessIdentity type that can be used to communicate memory attribution.
+ For non-Cocoa ports, this is nullptr.
+ This is used in WebCore to set the memory attribution of IOSurface and objects
+ that hold IOSurfaces.
+ This is instantiated in WebKit.
+ Currently the only useful way to instantiate ProcessIdentity is by receiving
+ the ProcessIdentity as a message and create it this way for the
+ sender process.
+
+ No new tests, refactor.
+
+ * Headers.cmake:
+ * Sources.txt:
+ * WebCore.xcodeproj/project.pbxproj:
+ * platform/Logging.h:
+ Add WebCore Process log tag since the code moved from WebKit to ProcessIdentity
+ used that tag to log.
+ * platform/ProcessIdentity.cpp: Added.
+ (WebCore::ProcessIdentity::ProcessIdentity):
+ (WebCore::ProcessIdentity::taskIdToken const):
+ (WebCore::ProcessIdentity::sendRight const):
+ (WebCore::ProcessIdentity::operator bool const):
+ * platform/ProcessIdentity.h: Added.
+ Add the ProcessIdentity type that can be used to communicate memory attribution.
+ * platform/graphics/RemoteVideoSample.h:
+ (WebCore::RemoteVideoSample::setOwnershipIdentity):
+ * platform/graphics/angle/GraphicsContextGLANGLE.h:
+ * platform/graphics/cocoa/GraphicsContextGLCocoa.h:
+ * platform/graphics/cocoa/GraphicsContextGLCocoa.mm:
+ (WebCore::GraphicsContextGLCocoa::create):
+ (WebCore::GraphicsContextGLCocoa::GraphicsContextGLCocoa):
+ (WebCore::GraphicsContextGLANGLE::allocateAndBindDisplayBufferBacking):
+ Add an example use where the constructor takes the memory attribution token.
+ This may be needed in the future when the token is used as a parameter in
+ the ANGLE context creation.
+ Use the token in creating the IOSurface. This fixes a bug where WebGL
+ back buffers would not be attributed until they were sent to WP.
+ * platform/graphics/cocoa/IOSurface.h:
+ * platform/graphics/cocoa/IOSurface.mm:
+ (WebCore::IOSurface::setOwnershipIdentity):
+ * platform/graphics/cocoa/WebProcessGraphicsContextGLCocoa.mm:
+
2021-12-10 Adrian Perez de Castro <ape...@igalia.com>
Non-unified build fixes, mid December 2021 edition
Modified: trunk/Source/WebCore/Headers.cmake (286837 => 286838)
--- trunk/Source/WebCore/Headers.cmake 2021-12-10 08:22:37 UTC (rev 286837)
+++ trunk/Source/WebCore/Headers.cmake 2021-12-10 08:24:30 UTC (rev 286838)
@@ -1291,6 +1291,7 @@
platform/PopupMenuClient.h
platform/PopupMenuStyle.h
platform/ProcessIdentifier.h
+ platform/ProcessIdentity.h
platform/ProcessQualified.h
platform/PromisedAttachmentInfo.h
platform/PublicSuffix.h
Modified: trunk/Source/WebCore/Sources.txt (286837 => 286838)
--- trunk/Source/WebCore/Sources.txt 2021-12-10 08:22:37 UTC (rev 286837)
+++ trunk/Source/WebCore/Sources.txt 2021-12-10 08:24:30 UTC (rev 286838)
@@ -1886,6 +1886,7 @@
platform/PlatformWheelEvent.cpp
platform/PreviewConverter.cpp
platform/ProcessIdentifier.cpp
+platform/ProcessIdentity.cpp
platform/ReferrerPolicy.cpp
platform/RemoteCommandListener.cpp
platform/RuntimeApplicationChecks.cpp
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (286837 => 286838)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2021-12-10 08:22:37 UTC (rev 286837)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2021-12-10 08:24:30 UTC (rev 286838)
@@ -2391,6 +2391,7 @@
7BB34A48253776CA00029D08 /* GraphicsContextGLImageExtractor.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BB34A45253776C600029D08 /* GraphicsContextGLImageExtractor.h */; settings = {ATTRIBUTES = (Private, ); }; };
7BB680BA25BA1BE4002B8738 /* GraphicsChecksMac.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BB680B825BA1BE4002B8738 /* GraphicsChecksMac.h */; settings = {ATTRIBUTES = (Private, ); }; };
7BDDA31F274FA0210038659E /* GraphicsContextGLCocoa.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BDDA31D274F9DA50038659E /* GraphicsContextGLCocoa.h */; settings = {ATTRIBUTES = (Private, ); }; };
+ 7BDDA34C275A01310038659E /* ProcessIdentity.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BDDA349275A01300038659E /* ProcessIdentity.h */; settings = {ATTRIBUTES = (Private, ); }; };
7BE7427381FA906FBB4F0F2C /* JSSVGGraphicsElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 950C4C02BED8936F818E2F99 /* JSSVGGraphicsElement.h */; };
7BFF59F42757726700773D39 /* DisplayConfigurationMonitor.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BFF59EF275771E800773D39 /* DisplayConfigurationMonitor.h */; settings = {ATTRIBUTES = (Private, ); }; };
7C029C6E2493C8F800268204 /* ColorTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C029C6D2493C8F800268204 /* ColorTypes.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -11418,6 +11419,8 @@
7BCD42DC2705C94900EB2127 /* ANGLEUtilitiesCocoa.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ANGLEUtilitiesCocoa.h; sourceTree = "<group>"; };
7BDDA31C274F9DA40038659E /* GraphicsContextGLCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = GraphicsContextGLCocoa.mm; sourceTree = "<group>"; };
7BDDA31D274F9DA50038659E /* GraphicsContextGLCocoa.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GraphicsContextGLCocoa.h; sourceTree = "<group>"; };
+ 7BDDA349275A01300038659E /* ProcessIdentity.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ProcessIdentity.h; sourceTree = "<group>"; };
+ 7BDDA34B275A01300038659E /* ProcessIdentity.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ProcessIdentity.cpp; sourceTree = "<group>"; };
7BE7265B25763B8D00E85D98 /* RemoteGraphicsContextGLProxyBase.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = RemoteGraphicsContextGLProxyBase.cpp; sourceTree = "<group>"; };
7BFF59EF275771E800773D39 /* DisplayConfigurationMonitor.h */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.h; fileEncoding = 4; path = DisplayConfigurationMonitor.h; sourceTree = "<group>"; };
7BFF59F1275771E800773D39 /* DisplayConfigurationMonitor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DisplayConfigurationMonitor.cpp; sourceTree = "<group>"; };
@@ -29778,6 +29781,8 @@
A1ADAF7C2360FD3E009CB776 /* PreviewConverterProvider.h */,
51F645D21FECDBC800B54DED /* ProcessIdentifier.cpp */,
51F645D31FECDBC800B54DED /* ProcessIdentifier.h */,
+ 7BDDA34B275A01300038659E /* ProcessIdentity.cpp */,
+ 7BDDA349275A01300038659E /* ProcessIdentity.h */,
1CC54AFB270F92DA005BF8BE /* ProcessQualified.h */,
F47A633C1FF6FD500081B3CC /* PromisedAttachmentInfo.h */,
0081FEFD16B0A244008AAA7A /* PublicSuffix.h */,
@@ -36320,6 +36325,7 @@
B71FE6DF11091CB300DAEF77 /* PrintContext.h in Headers */,
6B0A07F221FA4B5C00D57391 /* PrivateClickMeasurement.h in Headers */,
51F645D51FECDBCE00B54DED /* ProcessIdentifier.h in Headers */,
+ 7BDDA34C275A01310038659E /* ProcessIdentity.h in Headers */,
A8EA7EBC0A1945D000A8EF5F /* ProcessingInstruction.h in Headers */,
1CC54AFE270F96AE005BF8BE /* ProcessQualified.h in Headers */,
E42050172141901B0066EF3B /* ProcessWarming.h in Headers */,
Modified: trunk/Source/WebCore/platform/Logging.h (286837 => 286838)
--- trunk/Source/WebCore/platform/Logging.h 2021-12-10 08:22:37 UTC (rev 286837)
+++ trunk/Source/WebCore/platform/Logging.h 2021-12-10 08:24:30 UTC (rev 286838)
@@ -94,6 +94,7 @@
M(Plugins) \
M(PopupBlocking) \
M(PrivateClickMeasurement) \
+ M(Process) \
M(Progress) \
M(RemoteInspector) \
M(RequestAnimationFrame) \
Copied: trunk/Source/WebCore/platform/ProcessIdentity.cpp (from rev 286837, trunk/Source/WebKit/WebProcess/GPU/graphics/cocoa/ImageBufferShareableMappedIOSurfaceBackend.h) (0 => 286838)
--- trunk/Source/WebCore/platform/ProcessIdentity.cpp (rev 0)
+++ trunk/Source/WebCore/platform/ProcessIdentity.cpp 2021-12-10 08:24:30 UTC (rev 286838)
@@ -0,0 +1,65 @@
+/*
+ * 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. ``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
+ * 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.
+ */
+
+#include "config.h"
+#include "ProcessIdentity.h"
+
+#include "Logging.h"
+
+#if HAVE(TASK_IDENTITY_TOKEN)
+#include <mach/mach.h>
+#endif
+
+namespace WebCore {
+
+ProcessIdentity::ProcessIdentity(CurrentProcessTag)
+{
+#if HAVE(TASK_IDENTITY_TOKEN)
+ task_id_token_t identityToken;
+ kern_return_t kr = task_create_identity_token(mach_task_self(), &identityToken);
+ if (kr == KERN_SUCCESS)
+ m_taskIdToken = MachSendRight::adopt(identityToken);
+ else
+ RELEASE_LOG_ERROR(Process, "task_create_identity_token() failed: %{private}s (%x)", mach_error_string(kr), kr);
+#endif
+}
+
+ProcessIdentity::operator bool() const
+{
+#if HAVE(TASK_IDENTITY_TOKEN)
+ return static_cast<bool>(m_taskIdToken);
+#else
+ return false;
+#endif
+}
+
+#if HAVE(TASK_IDENTITY_TOKEN)
+ProcessIdentity::ProcessIdentity(MachSendRight&& taskIdToken)
+ : m_taskIdToken(WTFMove(taskIdToken))
+{
+}
+#endif
+
+}
Added: trunk/Source/WebCore/platform/ProcessIdentity.h (0 => 286838)
--- trunk/Source/WebCore/platform/ProcessIdentity.h (rev 0)
+++ trunk/Source/WebCore/platform/ProcessIdentity.h 2021-12-10 08:24:30 UTC (rev 286838)
@@ -0,0 +1,91 @@
+/*
+ * 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. ``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
+ * 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 <optional>
+
+#if HAVE(TASK_IDENTITY_TOKEN)
+#include <wtf/MachSendRight.h>
+#else
+#include <variant>
+#endif
+
+namespace WebCore {
+
+// Object to access proof of process identity.
+// ProcessIdentifier identifies a process.
+// ProcessIdentity grants access to the identity.
+// Empty ProcessIdentity does not do anything.
+class ProcessIdentity {
+public:
+ // Creates an process identity for current process or empty on error.
+ enum CurrentProcessTag { CurrentProcess };
+ WEBCORE_EXPORT explicit ProcessIdentity(CurrentProcessTag);
+
+ // Creates an empty process identity that does not grant any access.
+ ProcessIdentity() = default;
+
+ // Returns true for a process identity or false on empty identity.
+ WEBCORE_EXPORT operator bool() const;
+
+#if HAVE(TASK_IDENTITY_TOKEN)
+ task_id_token_t taskIdToken() const { return m_taskIdToken.sendRight(); }
+#endif
+
+ template<typename Encoder> void encode(Encoder&) const;
+ template<typename Decoder> static std::optional<ProcessIdentity> decode(Decoder&);
+
+private:
+#if HAVE(TASK_IDENTITY_TOKEN)
+ WEBCORE_EXPORT ProcessIdentity(MachSendRight&& taskIdToken);
+ MachSendRight m_taskIdToken;
+#endif
+};
+
+template<typename Encoder> void ProcessIdentity::encode(Encoder& encoder) const
+{
+#if HAVE(TASK_IDENTITY_TOKEN)
+ encoder << m_taskIdToken;
+#else
+ UNUSED_PARAM(encoder);
+#endif
+}
+
+template<typename Decoder> std::optional<ProcessIdentity> ProcessIdentity::decode(Decoder& decoder)
+{
+#if HAVE(TASK_IDENTITY_TOKEN)
+ std::optional<MachSendRight> identitySendRight;
+ decoder >> identitySendRight;
+ if (identitySendRight)
+ return ProcessIdentity { WTFMove(*identitySendRight) };
+ return std::nullopt;
+#else
+ UNUSED_PARAM(decoder);
+ return ProcessIdentity { };
+#endif
+}
+
+}
Modified: trunk/Source/WebCore/platform/graphics/RemoteVideoSample.h (286837 => 286838)
--- trunk/Source/WebCore/platform/graphics/RemoteVideoSample.h 2021-12-10 08:22:37 UTC (rev 286837)
+++ trunk/Source/WebCore/platform/graphics/RemoteVideoSample.h 2021-12-10 08:24:30 UTC (rev 286838)
@@ -37,6 +37,8 @@
namespace WebCore {
+class ProcessIdentity;
+
class RemoteVideoSample {
public:
RemoteVideoSample() = default;
@@ -48,9 +50,7 @@
WEBCORE_EXPORT static std::unique_ptr<RemoteVideoSample> create(RetainPtr<CVPixelBufferRef>&&, MediaTime&& presentationTime, MediaSample::VideoRotation = MediaSample::VideoRotation::None);
WEBCORE_EXPORT IOSurfaceRef surface() const;
-#if HAVE(IOSURFACE_SET_OWNERSHIP_IDENTITY)
- void setOwnershipIdentity(task_id_token_t newOwner);
-#endif
+ void setOwnershipIdentity(const ProcessIdentity&);
const MediaTime& time() const { return m_time; }
uint32_t videoFormat() const { return m_videoFormat; }
@@ -119,13 +119,11 @@
bool m_mirrored { false };
};
-#if HAVE(IOSURFACE_SET_OWNERSHIP_IDENTITY)
-inline void RemoteVideoSample::setOwnershipIdentity(task_id_token_t newOwner)
+inline void RemoteVideoSample::setOwnershipIdentity(const ProcessIdentity& resourceOwner)
{
if (m_ioSurface)
- m_ioSurface->setOwnershipIdentity(newOwner);
+ m_ioSurface->setOwnershipIdentity(resourceOwner);
}
-#endif
}
Modified: trunk/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.h (286837 => 286838)
--- trunk/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.h 2021-12-10 08:22:37 UTC (rev 286837)
+++ trunk/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.h 2021-12-10 08:24:30 UTC (rev 286838)
@@ -36,6 +36,7 @@
#if PLATFORM(COCOA)
#include "GraphicsContextGLIOSurfaceSwapChain.h"
#include "IOSurface.h"
+#include "ProcessIdentity.h"
#endif
@@ -427,6 +428,7 @@
std::unique_ptr<ExtensionsGLANGLE> m_extensions;
#if PLATFORM(COCOA)
+ // FIXME: Move these to GraphicsContextGLCocoa.
GraphicsContextGLIOSurfaceSwapChain m_swapChain;
EGLDisplay m_displayObj { nullptr };
PlatformGraphicsContextGL m_contextObj { nullptr };
@@ -436,6 +438,7 @@
// When preserveDrawingBuffer == true, this is blitted to during display prepare.
std::unique_ptr<IOSurface> m_displayBufferBacking;
void* m_displayBufferPbuffer { nullptr };
+ ProcessIdentity m_resourceOwner;
#endif
#if USE(COORDINATED_GRAPHICS)
GCGLuint m_compositorTexture { 0 };
Modified: trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLCocoa.h (286837 => 286838)
--- trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLCocoa.h 2021-12-10 08:22:37 UTC (rev 286837)
+++ trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLCocoa.h 2021-12-10 08:24:30 UTC (rev 286838)
@@ -42,9 +42,11 @@
namespace WebCore {
+class ProcessIdentity;
+
class WEBCORE_EXPORT GraphicsContextGLCocoa : public GraphicsContextGLANGLE {
public:
- static RefPtr<GraphicsContextGLCocoa> create(WebCore::GraphicsContextGLAttributes&&);
+ static RefPtr<GraphicsContextGLCocoa> create(WebCore::GraphicsContextGLAttributes&&, ProcessIdentity&& resourceOwner);
~GraphicsContextGLCocoa();
IOSurface* displayBuffer();
void markDisplayBufferInUse();
@@ -76,9 +78,8 @@
void updateContextOnDisplayReconfiguration();
#endif
protected:
- GraphicsContextGLCocoa(WebCore::GraphicsContextGLAttributes&&);
+ GraphicsContextGLCocoa(WebCore::GraphicsContextGLAttributes&&, ProcessIdentity&& resourceOwner);
bool isValid() const;
-
#if ENABLE(VIDEO)
std::unique_ptr<GraphicsContextGLCVCocoa> m_cv;
#endif
Modified: trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLCocoa.mm (286837 => 286838)
--- trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLCocoa.mm 2021-12-10 08:22:37 UTC (rev 286837)
+++ trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLCocoa.mm 2021-12-10 08:24:30 UTC (rev 286838)
@@ -35,6 +35,7 @@
#import "GraphicsContextGLIOSurfaceSwapChain.h"
#import "GraphicsContextGLOpenGLManager.h"
#import "Logging.h"
+#import "ProcessIdentity.h"
#import "RuntimeApplicationChecks.h"
#import <CoreGraphics/CGBitmapContext.h>
#import <Metal/Metal.h>
@@ -192,19 +193,22 @@
}
#endif
-RefPtr<GraphicsContextGLCocoa> GraphicsContextGLCocoa::create(GraphicsContextGLAttributes&& attributes)
+RefPtr<GraphicsContextGLCocoa> GraphicsContextGLCocoa::create(GraphicsContextGLAttributes&& attributes, ProcessIdentity&& resourceOwner)
{
- auto context = adoptRef(*new GraphicsContextGLCocoa(WTFMove(attributes)));
+ auto context = adoptRef(*new GraphicsContextGLCocoa(WTFMove(attributes), WTFMove(resourceOwner)));
if (!context->isValid())
return nullptr;
return context;
}
-GraphicsContextGLCocoa::GraphicsContextGLCocoa(GraphicsContextGLAttributes&& creationAttributes)
+GraphicsContextGLCocoa::GraphicsContextGLCocoa(GraphicsContextGLAttributes&& creationAttributes, ProcessIdentity&& resourceOwner)
: GraphicsContextGLANGLE(WTFMove(creationAttributes))
{
if (!isValid())
return;
+ // FIXME: Move this to initializer list once m_resourceOwner moves to GraphicsContextGLCocoa.
+ m_resourceOwner = WTFMove(resourceOwner);
+
#if PLATFORM(MAC)
auto attributes = contextAttributes();
if (!attributes.useMetal && attributes.effectivePowerPreference() == GraphicsContextGLPowerPreference::HighPerformance)
@@ -557,7 +561,8 @@
auto backing = IOSurface::create(getInternalFramebufferSize(), DestinationColorSpace::SRGB());
if (!backing)
return false;
-
+ if (m_resourceOwner)
+ backing->setOwnershipIdentity(m_resourceOwner);
backing->migrateColorSpaceToProperties();
const bool usingAlpha = contextAttributes().alpha;
Modified: trunk/Source/WebCore/platform/graphics/cocoa/IOSurface.h (286837 => 286838)
--- trunk/Source/WebCore/platform/graphics/cocoa/IOSurface.h 2021-12-10 08:22:37 UTC (rev 286837)
+++ trunk/Source/WebCore/platform/graphics/cocoa/IOSurface.h 2021-12-10 08:24:30 UTC (rev 286838)
@@ -46,6 +46,7 @@
class GraphicsContext;
class HostWindow;
class ImageBuffer;
+class ProcessIdentity;
enum class PixelFormat : uint8_t;
enum class VolatilityState : uint8_t;
@@ -159,9 +160,7 @@
WEBCORE_EXPORT static void convertToFormat(std::unique_ptr<WebCore::IOSurface>&& inSurface, Format, Function<void(std::unique_ptr<WebCore::IOSurface>)>&&);
#endif // HAVE(IOSURFACE_ACCELERATOR)
-#if HAVE(IOSURFACE_SET_OWNERSHIP_IDENTITY)
- WEBCORE_EXPORT void setOwnershipIdentity(task_id_token_t newOwner);
-#endif
+ WEBCORE_EXPORT void setOwnershipIdentity(const ProcessIdentity&);
void migrateColorSpaceToProperties();
Modified: trunk/Source/WebCore/platform/graphics/cocoa/IOSurface.mm (286837 => 286838)
--- trunk/Source/WebCore/platform/graphics/cocoa/IOSurface.mm 2021-12-10 08:22:37 UTC (rev 286837)
+++ trunk/Source/WebCore/platform/graphics/cocoa/IOSurface.mm 2021-12-10 08:24:30 UTC (rev 286838)
@@ -34,6 +34,7 @@
#import "ImageBuffer.h"
#import "Logging.h"
#import "PlatformScreen.h"
+#import "ProcessIdentity.h"
#import <pal/spi/cg/CoreGraphicsSPI.h>
#import <wtf/Assertions.h>
#import <wtf/MachSendRight.h>
@@ -484,14 +485,18 @@
#endif // HAVE(IOSURFACE_ACCELERATOR)
-#if HAVE(IOSURFACE_SET_OWNERSHIP_IDENTITY)
-void IOSurface::setOwnershipIdentity(task_id_token_t newOwner)
+void IOSurface::setOwnershipIdentity(const ProcessIdentity& resourceOwner)
{
- auto result = IOSurfaceSetOwnershipIdentity(m_surface.get(), newOwner, kIOSurfaceMemoryLedgerTagGraphics, 0);
+#if HAVE(IOSURFACE_SET_OWNERSHIP_IDENTITY) && HAVE(TASK_IDENTITY_TOKEN)
+ ASSERT(resourceOwner);
+ task_id_token_t ownerTaskIdToken = resourceOwner.taskIdToken();
+ auto result = IOSurfaceSetOwnershipIdentity(m_surface.get(), ownerTaskIdToken, kIOSurfaceMemoryLedgerTagGraphics, 0);
if (result != kIOReturnSuccess)
- RELEASE_LOG_ERROR(IOSurface, "IOSurface::setOwnershipIdentity: Failed to claim ownership of IOSurface %p, newOwner: %d, error: %d", m_surface.get(), (int)newOwner, result);
+ 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);
+#else
+ UNUSED_PARAM(resourceOwner);
+#endif
}
-#endif
void IOSurface::migrateColorSpaceToProperties()
{
Modified: trunk/Source/WebCore/platform/graphics/cocoa/WebProcessGraphicsContextGLCocoa.mm (286837 => 286838)
--- trunk/Source/WebCore/platform/graphics/cocoa/WebProcessGraphicsContextGLCocoa.mm 2021-12-10 08:22:37 UTC (rev 286837)
+++ trunk/Source/WebCore/platform/graphics/cocoa/WebProcessGraphicsContextGLCocoa.mm 2021-12-10 08:24:30 UTC (rev 286838)
@@ -29,6 +29,7 @@
#if ENABLE(WEBGL)
#import "GraphicsContextGLCocoa.h" // NOLINT
#import "GraphicsContextGLOpenGLManager.h"
+#import "ProcessIdentity.h"
#import "WebGLLayer.h"
#import <wtf/BlockObjCExceptions.h>
@@ -77,7 +78,7 @@
};
WebProcessGraphicsContextGLCocoa::WebProcessGraphicsContextGLCocoa(GraphicsContextGLAttributes&& attributes)
- : GraphicsContextGLCocoa(WTFMove(attributes))
+ : GraphicsContextGLCocoa(WTFMove(attributes), { })
, m_webGLLayer(createWebGLLayer(contextAttributes()))
{
#if PLATFORM(MAC)
Modified: trunk/Source/WebKit/ChangeLog (286837 => 286838)
--- trunk/Source/WebKit/ChangeLog 2021-12-10 08:22:37 UTC (rev 286837)
+++ trunk/Source/WebKit/ChangeLog 2021-12-10 08:24:30 UTC (rev 286838)
@@ -1,3 +1,54 @@
+2021-12-10 Kimmo Kinnunen <kkinnu...@apple.com>
+
+ IOSurface memory attribution is hard to use in constructors
+ https://bugs.webkit.org/show_bug.cgi?id=232988
+ <rdar://problem/85541918>
+
+ Reviewed by Chris Dumez.
+
+ Remove ifdefs and direct use of task_id_token_t.
+ Instead, use WebCore::ProcessIdentifier. This way the
+ cross-platform code is easier to author.
+
+ * GPUProcess/GPUConnectionToWebProcess.cpp:
+ (WebKit::GPUConnectionToWebProcess::GPUConnectionToWebProcess):
+ * GPUProcess/GPUConnectionToWebProcess.h:
+ (WebKit::GPUConnectionToWebProcess::webProcessIdentity const):
+ (WebKit::GPUConnectionToWebProcess::webProcessIdentityToken const): Deleted.
+ * GPUProcess/graphics/RemoteGraphicsContextGLCocoa.cpp:
+ (WebKit::RemoteGraphicsContextGLCocoa::RemoteGraphicsContextGLCocoa):
+ (WebKit::RemoteGraphicsContextGLCocoa::platformWorkQueueInitialize):
+ (WebKit::RemoteGraphicsContextGLCocoa::prepareForDisplay):
+ * GPUProcess/graphics/RemoteImageBuffer.h:
+ (WebKit::RemoteImageBuffer::setOwnershipIdentity):
+ (WebKit::RemoteImageBuffer::setProcessOwnership): Deleted.
+ * GPUProcess/graphics/RemoteRenderingBackend.cpp:
+ (WebKit::RemoteRenderingBackend::RemoteRenderingBackend):
+ (WebKit::RemoteRenderingBackend::createImageBufferWithQualifiedIdentifier):
+ * GPUProcess/graphics/RemoteRenderingBackend.h:
+ * GPUProcess/webrtc/LibWebRTCCodecsProxy.mm:
+ (WebKit::Function<void):
+ * Shared/GPUProcessConnectionParameters.h:
+ (WebKit::GPUProcessConnectionParameters::encode const):
+ (WebKit::GPUProcessConnectionParameters::decode):
+ * UIProcess/Cocoa/UserMediaCaptureManagerProxy.cpp:
+ (WebKit::UserMediaCaptureManagerProxy::SourceProxy::SourceProxy):
+ (WebKit::UserMediaCaptureManagerProxy::SourceProxy::setShouldApplyRotation):
+ (WebKit::UserMediaCaptureManagerProxy::createMediaSourceForCaptureDeviceWithConstraints):
+ (WebKit::UserMediaCaptureManagerProxy::clone):
+ (WebKit::UserMediaCaptureManagerProxy::SourceProxy::setWebProcessIdentityToken): Deleted.
+ * UIProcess/Cocoa/UserMediaCaptureManagerProxy.h:
+ (WebKit::UserMediaCaptureManagerProxy::ConnectionProxy::webProcessIdentityToken const): Deleted.
+ * UIProcess/WebProcessProxy.cpp:
+ * WebProcess/GPU/graphics/ImageBufferShareableBitmapBackend.h:
+ (WebKit::ImageBufferShareableBitmapBackend::setOwnershipIdentity):
+ * WebProcess/GPU/graphics/cocoa/ImageBufferShareableMappedIOSurfaceBackend.cpp:
+ (WebKit::ImageBufferShareableMappedIOSurfaceBackend::setOwnershipIdentity):
+ (WebKit::ImageBufferShareableMappedIOSurfaceBackend::setProcessOwnership): Deleted.
+ * WebProcess/GPU/graphics/cocoa/ImageBufferShareableMappedIOSurfaceBackend.h:
+ * WebProcess/cocoa/WebProcessCocoa.mm:
+ (WebKit::WebProcess::platformInitializeGPUProcessConnectionParameters):
+
2021-12-10 Adrian Perez de Castro <ape...@igalia.com>
Non-unified build fixes, mid December 2021 edition
Modified: trunk/Source/WebKit/GPUProcess/GPUConnectionToWebProcess.cpp (286837 => 286838)
--- trunk/Source/WebKit/GPUProcess/GPUConnectionToWebProcess.cpp 2021-12-10 08:22:37 UTC (rev 286837)
+++ trunk/Source/WebKit/GPUProcess/GPUConnectionToWebProcess.cpp 2021-12-10 08:24:30 UTC (rev 286838)
@@ -207,12 +207,11 @@
m_process.startCapturingAudio();
}
#endif
-#if HAVE(IOSURFACE_SET_OWNERSHIP_IDENTITY)
- std::optional<task_id_token_t> webProcessIdentityToken() const final
+
+ const ProcessIdentity& resourceOwner() const final
{
- return m_process.webProcessIdentityToken();
+ return m_process.webProcessIdentity();
}
-#endif
GPUConnectionToWebProcess& m_process;
};
@@ -228,9 +227,7 @@
: m_connection(IPC::Connection::createServerConnection(connectionIdentifier, *this))
, m_gpuProcess(gpuProcess)
, m_webProcessIdentifier(webProcessIdentifier)
-#if HAVE(TASK_IDENTITY_TOKEN)
- , m_webProcessIdentityToken(WTFMove(parameters.webProcessIdentityToken))
-#endif
+ , m_webProcessIdentity(WTFMove(parameters.webProcessIdentity))
, m_remoteMediaPlayerManagerProxy(makeUniqueRef<RemoteMediaPlayerManagerProxy>(*this))
, m_sessionID(sessionID)
#if PLATFORM(COCOA) && USE(LIBWEBRTC)
Modified: trunk/Source/WebKit/GPUProcess/GPUConnectionToWebProcess.h (286837 => 286838)
--- trunk/Source/WebKit/GPUProcess/GPUConnectionToWebProcess.h 2021-12-10 08:22:37 UTC (rev 286837)
+++ trunk/Source/WebKit/GPUProcess/GPUConnectionToWebProcess.h 2021-12-10 08:24:30 UTC (rev 286838)
@@ -41,6 +41,7 @@
#include <WebCore/NowPlayingManager.h>
#include <WebCore/PageIdentifier.h>
#include <WebCore/ProcessIdentifier.h>
+#include <WebCore/ProcessIdentity.h>
#include <pal/SessionID.h>
#include <wtf/Logger.h>
#include <wtf/MachSendRight.h>
@@ -155,10 +156,7 @@
void dispatchDisplayWasReconfiguredForTesting() { dispatchDisplayWasReconfigured(); };
#endif
-#if HAVE(TASK_IDENTITY_TOKEN)
- task_id_token_t webProcessIdentityToken() const { return static_cast<task_id_token_t>(m_webProcessIdentityToken.sendRight()); }
-#endif
-
+ const WebCore::ProcessIdentity& webProcessIdentity() const { return m_webProcessIdentity; }
#if ENABLE(ENCRYPTED_MEDIA)
RemoteCDMFactoryProxy& cdmFactoryProxy();
#endif
@@ -283,9 +281,7 @@
IPC::MessageReceiverMap m_messageReceiverMap;
Ref<GPUProcess> m_gpuProcess;
const WebCore::ProcessIdentifier m_webProcessIdentifier;
-#if HAVE(TASK_IDENTITY_TOKEN)
- MachSendRight m_webProcessIdentityToken;
-#endif
+ const WebCore::ProcessIdentity m_webProcessIdentity;
#if ENABLE(WEB_AUDIO)
std::unique_ptr<RemoteAudioDestinationManager> m_remoteAudioDestinationManager;
#endif
Modified: trunk/Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGLCocoa.cpp (286837 => 286838)
--- trunk/Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGLCocoa.cpp 2021-12-10 08:22:37 UTC (rev 286837)
+++ trunk/Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGLCocoa.cpp 2021-12-10 08:24:30 UTC (rev 286838)
@@ -29,6 +29,7 @@
#if ENABLE(GPU_PROCESS) && ENABLE(WEBGL) && PLATFORM(COCOA)
#include "GPUConnectionToWebProcess.h"
+#include <WebCore/ProcessIdentity.h>
#include <wtf/MachSendRight.h>
namespace WebKit {
@@ -45,9 +46,7 @@
void platformWorkQueueInitialize(WebCore::GraphicsContextGLAttributes&&) final;
void prepareForDisplay(CompletionHandler<void(WTF::MachSendRight&&)>&&) final;
private:
-#if HAVE(IOSURFACE_SET_OWNERSHIP_IDENTITY)
- task_id_token_t m_webProcessIdentityToken;
-#endif
+ const ProcessIdentity m_resourceOwner;
};
}
@@ -61,9 +60,7 @@
RemoteGraphicsContextGLCocoa::RemoteGraphicsContextGLCocoa(GPUConnectionToWebProcess& gpuConnectionToWebProcess, GraphicsContextGLIdentifier graphicsContextGLIdentifier, RemoteRenderingBackend& renderingBackend, IPC::StreamConnectionBuffer&& stream)
: RemoteGraphicsContextGL(gpuConnectionToWebProcess, graphicsContextGLIdentifier, renderingBackend, WTFMove(stream))
-#if HAVE(IOSURFACE_SET_OWNERSHIP_IDENTITY)
- , m_webProcessIdentityToken(gpuConnectionToWebProcess.webProcessIdentityToken())
-#endif
+ , m_resourceOwner(gpuConnectionToWebProcess.webProcessIdentity())
{
}
@@ -71,7 +68,7 @@
void RemoteGraphicsContextGLCocoa::platformWorkQueueInitialize(WebCore::GraphicsContextGLAttributes&& attributes)
{
assertIsCurrent(m_streamThread);
- m_context = GraphicsContextGLCocoa::create(WTFMove(attributes));
+ m_context = GraphicsContextGLCocoa::create(WTFMove(attributes), ProcessIdentity { m_resourceOwner });
}
void RemoteGraphicsContextGLCocoa::prepareForDisplay(CompletionHandler<void(WTF::MachSendRight&&)>&& completionHandler)
@@ -82,10 +79,6 @@
MachSendRight sendRight;
if (displayBuffer) {
m_context->markDisplayBufferInUse();
-#if HAVE(IOSURFACE_SET_OWNERSHIP_IDENTITY)
- // Mark the IOSurface as being owned by the WebProcess even though it was constructed by the GPUProcess so that Jetsam knows which process to kill.
- displayBuffer->setOwnershipIdentity(m_webProcessIdentityToken);
-#endif
sendRight = displayBuffer->createSendRight();
}
completionHandler(WTFMove(sendRight));
Modified: trunk/Source/WebKit/GPUProcess/graphics/RemoteImageBuffer.h (286837 => 286838)
--- trunk/Source/WebKit/GPUProcess/graphics/RemoteImageBuffer.h 2021-12-10 08:22:37 UTC (rev 286837)
+++ trunk/Source/WebKit/GPUProcess/graphics/RemoteImageBuffer.h 2021-12-10 08:24:30 UTC (rev 286838)
@@ -69,13 +69,11 @@
context().restore();
}
-#if HAVE(IOSURFACE_SET_OWNERSHIP_IDENTITY)
- void setProcessOwnership(task_id_token_t newOwner)
+ void setOwnershipIdentity(const WebCore::ProcessIdentity& resourceOwner)
{
if (m_backend)
- m_backend->setProcessOwnership(newOwner);
+ m_backend->setOwnershipIdentity(resourceOwner);
}
-#endif
private:
friend class RemoteRenderingBackend;
Modified: trunk/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.cpp (286837 => 286838)
--- trunk/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.cpp 2021-12-10 08:22:37 UTC (rev 286837)
+++ trunk/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.cpp 2021-12-10 08:24:30 UTC (rev 286838)
@@ -85,6 +85,7 @@
, m_streamConnection(IPC::StreamServerConnection::create(gpuConnectionToWebProcess.connection(), WTFMove(streamBuffer), m_workQueue.get()))
, m_remoteResourceCache(gpuConnectionToWebProcess.webProcessIdentifier())
, m_gpuConnectionToWebProcess(gpuConnectionToWebProcess)
+ , m_resourceOwner(gpuConnectionToWebProcess.webProcessIdentity())
, m_renderingBackendIdentifier(creationParameters.identifier)
{
ASSERT(RunLoop::isMain());
@@ -174,10 +175,9 @@
if (renderingMode == RenderingMode::Accelerated) {
if (auto acceleratedImageBuffer = AcceleratedRemoteImageBuffer::create(logicalSize, resolutionScale, colorSpace, pixelFormat, *this, imageBufferResourceIdentifier)) {
-#if HAVE(IOSURFACE_SET_OWNERSHIP_IDENTITY)
// Mark the IOSurface as being owned by the WebProcess even though it was constructed by the GPUProcess so that Jetsam knows which process to kill.
- acceleratedImageBuffer->setProcessOwnership(m_gpuConnectionToWebProcess->webProcessIdentityToken());
-#endif
+ if (m_resourceOwner)
+ acceleratedImageBuffer->setOwnershipIdentity(m_resourceOwner);
imageBuffer = WTFMove(acceleratedImageBuffer);
}
}
Modified: trunk/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.h (286837 => 286838)
--- trunk/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.h 2021-12-10 08:22:37 UTC (rev 286837)
+++ trunk/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.h 2021-12-10 08:24:30 UTC (rev 286838)
@@ -46,6 +46,7 @@
#include <WebCore/DisplayListItems.h>
#include <WebCore/DisplayListReplayer.h>
#include <WebCore/ProcessIdentifier.h>
+#include <WebCore/ProcessIdentity.h>
#include <wtf/WeakPtr.h>
namespace WebCore {
@@ -133,6 +134,7 @@
Ref<IPC::StreamServerConnection> m_streamConnection;
RemoteResourceCache m_remoteResourceCache;
Ref<GPUConnectionToWebProcess> m_gpuConnectionToWebProcess;
+ WebCore::ProcessIdentity m_resourceOwner;
RenderingBackendIdentifier m_renderingBackendIdentifier;
IPC::Semaphore m_getPixelBufferSemaphore;
RefPtr<SharedMemory> m_getPixelBufferSharedMemory;
Modified: trunk/Source/WebKit/GPUProcess/webrtc/LibWebRTCCodecsProxy.mm (286837 => 286838)
--- trunk/Source/WebKit/GPUProcess/webrtc/LibWebRTCCodecsProxy.mm 2021-12-10 08:22:37 UTC (rev 286837)
+++ trunk/Source/WebKit/GPUProcess/webrtc/LibWebRTCCodecsProxy.mm 2021-12-10 08:24:30 UTC (rev 286838)
@@ -76,15 +76,10 @@
static Function<void(CVPixelBufferRef pixelBuffer, uint32_t timeStampNs, uint32_t timeStamp)> createDecoderCallback(RTCDecoderIdentifier identifier, GPUConnectionToWebProcess& gpuConnectionToWebProcess)
{
- return [connection = Ref { gpuConnectionToWebProcess.connection() },
-#if HAVE(IOSURFACE_SET_OWNERSHIP_IDENTITY)
- token = gpuConnectionToWebProcess.webProcessIdentityToken(),
-#endif
- identifier](CVPixelBufferRef pixelBuffer, uint32_t timeStampNs, uint32_t timeStamp) {
+ return [connection = Ref { gpuConnectionToWebProcess.connection() }, resourceOwner = gpuConnectionToWebProcess.webProcessIdentity(), identifier] (CVPixelBufferRef pixelBuffer, uint32_t timeStampNs, uint32_t timeStamp) {
if (auto sample = WebCore::RemoteVideoSample::create(pixelBuffer, MediaTime(timeStampNs, 1))) {
-#if HAVE(IOSURFACE_SET_OWNERSHIP_IDENTITY)
- sample->setOwnershipIdentity(token);
-#endif
+ if (resourceOwner)
+ sample->setOwnershipIdentity(resourceOwner);
connection->send(Messages::LibWebRTCCodecs::CompletedDecoding { identifier, timeStamp, *sample }, 0);
}
};
Modified: trunk/Source/WebKit/Shared/GPUProcessConnectionParameters.h (286837 => 286838)
--- trunk/Source/WebKit/Shared/GPUProcessConnectionParameters.h 2021-12-10 08:22:37 UTC (rev 286837)
+++ trunk/Source/WebKit/Shared/GPUProcessConnectionParameters.h 2021-12-10 08:24:30 UTC (rev 286838)
@@ -28,14 +28,13 @@
#if ENABLE(GPU_PROCESS)
#include "WebCoreArgumentCoders.h"
+#include <WebCore/ProcessIdentity.h>
#include <wtf/MachSendRight.h>
namespace WebKit {
struct GPUProcessConnectionParameters {
-#if HAVE(TASK_IDENTITY_TOKEN)
- MachSendRight webProcessIdentityToken;
-#endif
+ WebCore::ProcessIdentity webProcessIdentity;
Vector<String> overrideLanguages;
#if ENABLE(IPC_TESTING_API)
bool ignoreInvalidMessageForTesting { false };
@@ -46,9 +45,7 @@
void encode(IPC::Encoder& encoder) const
{
-#if HAVE(TASK_IDENTITY_TOKEN)
- encoder << webProcessIdentityToken;
-#endif
+ encoder << webProcessIdentity;
encoder << overrideLanguages;
#if ENABLE(IPC_TESTING_API)
encoder << ignoreInvalidMessageForTesting;
@@ -60,12 +57,10 @@
static std::optional<GPUProcessConnectionParameters> decode(IPC::Decoder& decoder)
{
-#if HAVE(TASK_IDENTITY_TOKEN)
- std::optional<MachSendRight> webProcessIdentityToken;
- decoder >> webProcessIdentityToken;
- if (!webProcessIdentityToken)
+ std::optional<WebCore::ProcessIdentity> webProcessIdentity;
+ decoder >> webProcessIdentity;
+ if (!webProcessIdentity)
return std::nullopt;
-#endif
std::optional<Vector<String>> overrideLanguages;
decoder >> overrideLanguages;
@@ -86,9 +81,7 @@
#endif
return GPUProcessConnectionParameters {
-#if HAVE(TASK_IDENTITY_TOKEN)
- WTFMove(*webProcessIdentityToken),
-#endif
+ WTFMove(*webProcessIdentity),
WTFMove(*overrideLanguages),
#if ENABLE(IPC_TESTING_API)
*ignoreInvalidMessageForTesting,
Modified: trunk/Source/WebKit/UIProcess/Cocoa/UserMediaCaptureManagerProxy.cpp (286837 => 286838)
--- trunk/Source/WebKit/UIProcess/Cocoa/UserMediaCaptureManagerProxy.cpp 2021-12-10 08:22:37 UTC (rev 286837)
+++ trunk/Source/WebKit/UIProcess/Cocoa/UserMediaCaptureManagerProxy.cpp 2021-12-10 08:24:30 UTC (rev 286838)
@@ -57,9 +57,10 @@
, private RealtimeMediaSource::VideoSampleObserver {
WTF_MAKE_FAST_ALLOCATED;
public:
- SourceProxy(RealtimeMediaSourceIdentifier id, Ref<IPC::Connection>&& connection, Ref<RealtimeMediaSource>&& source)
+ SourceProxy(RealtimeMediaSourceIdentifier id, Ref<IPC::Connection>&& connection, ProcessIdentity&& resourceOwner, Ref<RealtimeMediaSource>&& source)
: m_id(id)
, m_connection(WTFMove(connection))
+ , m_resourceOwner(WTFMove(resourceOwner))
, m_source(WTFMove(source))
{
m_source->addObserver(*this);
@@ -125,9 +126,6 @@
}
void setShouldApplyRotation(bool shouldApplyRotation) { m_shouldApplyRotation = true; }
-#if HAVE(IOSURFACE_SET_OWNERSHIP_IDENTITY)
- void setWebProcessIdentityToken(std::optional<task_id_token_t> token) { m_webProcessIdentityToken = token;}
-#endif
private:
void sourceStopped() final {
@@ -188,10 +186,8 @@
} else
remoteSample = RemoteVideoSample::create(sample);
if (remoteSample) {
-#if HAVE(IOSURFACE_SET_OWNERSHIP_IDENTITY)
- if (m_webProcessIdentityToken)
- remoteSample->setOwnershipIdentity(*m_webProcessIdentityToken);
-#endif
+ if (m_resourceOwner)
+ remoteSample->setOwnershipIdentity(m_resourceOwner);
m_connection->send(Messages::RemoteCaptureSampleManager::VideoSampleAvailable(m_id, WTFMove(*remoteSample), metadata), 0);
}
}
@@ -244,6 +240,7 @@
RealtimeMediaSourceIdentifier m_id;
WeakPtr<PlatformMediaSessionManager> m_sessionManager;
Ref<IPC::Connection> m_connection;
+ ProcessIdentity m_resourceOwner;
Ref<RealtimeMediaSource> m_source;
std::unique_ptr<CARingBuffer> m_ringBuffer;
CAAudioStreamDescription m_description { };
@@ -257,9 +254,6 @@
size_t m_frameChunkSize { 0 };
MediaTime m_startTime;
bool m_shouldReset { false };
-#if HAVE(TASK_IDENTITY_TOKEN)
- std::optional<task_id_token_t> m_webProcessIdentityToken;
-#endif
};
UserMediaCaptureManagerProxy::UserMediaCaptureManagerProxy(UniqueRef<ConnectionProxy>&& connectionProxy)
@@ -323,12 +317,7 @@
}
ASSERT(!m_proxies.contains(id));
- auto proxy = makeUnique<SourceProxy>(id, m_connectionProxy->connection(), WTFMove(source));
-#if HAVE(IOSURFACE_SET_OWNERSHIP_IDENTITY)
- if (device.type() != WebCore::CaptureDevice::DeviceType::Microphone)
- proxy->setWebProcessIdentityToken(m_connectionProxy->webProcessIdentityToken());
-#endif
-
+ auto proxy = makeUnique<SourceProxy>(id, m_connectionProxy->connection(), ProcessIdentity { m_connectionProxy->resourceOwner() }, WTFMove(source));
m_proxies.add(id, WTFMove(proxy));
} else
invalidConstraints = WTFMove(sourceOrError.errorMessage);
@@ -394,7 +383,7 @@
MESSAGE_CHECK(m_proxies.contains(clonedID));
MESSAGE_CHECK(!m_proxies.contains(newSourceID));
if (auto* proxy = m_proxies.get(clonedID))
- m_proxies.add(newSourceID, makeUnique<SourceProxy>(newSourceID, m_connectionProxy->connection(), proxy->source().clone()));
+ m_proxies.add(newSourceID, makeUnique<SourceProxy>(newSourceID, m_connectionProxy->connection(), ProcessIdentity { m_connectionProxy->resourceOwner() }, proxy->source().clone()));
}
void UserMediaCaptureManagerProxy::requestToEnd(RealtimeMediaSourceIdentifier sourceID)
Modified: trunk/Source/WebKit/UIProcess/Cocoa/UserMediaCaptureManagerProxy.h (286837 => 286838)
--- trunk/Source/WebKit/UIProcess/Cocoa/UserMediaCaptureManagerProxy.h 2021-12-10 08:22:37 UTC (rev 286837)
+++ trunk/Source/WebKit/UIProcess/Cocoa/UserMediaCaptureManagerProxy.h 2021-12-10 08:24:30 UTC (rev 286838)
@@ -32,6 +32,7 @@
#include "UserMediaCaptureManager.h"
#include <WebCore/CaptureDevice.h>
#include <WebCore/OrientationNotifier.h>
+#include <WebCore/ProcessIdentity.h>
#include <WebCore/RealtimeMediaSource.h>
#include <WebCore/RealtimeMediaSourceIdentifier.h>
#include <pal/spi/cocoa/TCCSPI.h>
@@ -59,9 +60,7 @@
virtual bool willStartCapture(WebCore::CaptureDevice::DeviceType) const = 0;
virtual Logger& logger() = 0;
virtual bool setCaptureAttributionString() { return true; }
-#if HAVE(IOSURFACE_SET_OWNERSHIP_IDENTITY)
- virtual std::optional<task_id_token_t> webProcessIdentityToken() const { return { }; };
-#endif
+ virtual const WebCore::ProcessIdentity& resourceOwner() const = 0;
#if ENABLE(APP_PRIVACY_REPORT)
virtual void setTCCIdentity() { }
#endif
Modified: trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp (286837 => 286838)
--- trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp 2021-12-10 08:22:37 UTC (rev 286837)
+++ trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp 2021-12-10 08:24:30 UTC (rev 286838)
@@ -216,6 +216,13 @@
return true;
}
+ const WebCore::ProcessIdentity& resourceOwner() const final
+ {
+ // FIXME: should obtain WebContent process identity from WebContent.
+ static NeverDestroyed<WebCore::ProcessIdentity> dummy;
+ return dummy.get();
+ }
+
RefPtr<Logger> m_logger;
WebProcessProxy& m_process;
};
Modified: trunk/Source/WebKit/WebProcess/GPU/graphics/ImageBufferShareableBitmapBackend.h (286837 => 286838)
--- trunk/Source/WebKit/WebProcess/GPU/graphics/ImageBufferShareableBitmapBackend.h 2021-12-10 08:22:37 UTC (rev 286837)
+++ trunk/Source/WebKit/WebProcess/GPU/graphics/ImageBufferShareableBitmapBackend.h 2021-12-10 08:24:30 UTC (rev 286838)
@@ -31,6 +31,10 @@
#include <WebCore/PlatformImageBufferBackend.h>
#include <wtf/IsoMalloc.h>
+namespace WebCore {
+class ProcessIdentity;
+}
+
namespace WebKit {
class ShareableBitmap;
@@ -61,6 +65,7 @@
std::optional<WebCore::PixelBuffer> getPixelBuffer(const WebCore::PixelBufferFormat& outputFormat, const WebCore::IntRect&) const override;
void putPixelBuffer(const WebCore::PixelBuffer&, const WebCore::IntRect& srcRect, const WebCore::IntPoint& destPoint, WebCore::AlphaPremultiplication destFormat) override;
+ void setOwnershipIdentity(const WebCore::ProcessIdentity&) { }
private:
unsigned bytesPerRow() const override;
Modified: trunk/Source/WebKit/WebProcess/GPU/graphics/cocoa/ImageBufferShareableMappedIOSurfaceBackend.cpp (286837 => 286838)
--- trunk/Source/WebKit/WebProcess/GPU/graphics/cocoa/ImageBufferShareableMappedIOSurfaceBackend.cpp 2021-12-10 08:22:37 UTC (rev 286837)
+++ trunk/Source/WebKit/WebProcess/GPU/graphics/cocoa/ImageBufferShareableMappedIOSurfaceBackend.cpp 2021-12-10 08:24:30 UTC (rev 286838)
@@ -77,13 +77,11 @@
return ImageBufferBackendHandle(m_surface->createSendRight());
}
-#if HAVE(IOSURFACE_SET_OWNERSHIP_IDENTITY)
-void ImageBufferShareableMappedIOSurfaceBackend::setProcessOwnership(task_id_token_t processIdentityToken)
+void ImageBufferShareableMappedIOSurfaceBackend::setOwnershipIdentity(const WebCore::ProcessIdentity& resourceOwner)
{
ASSERT(surface());
- surface()->setOwnershipIdentity(processIdentityToken);
+ surface()->setOwnershipIdentity(resourceOwner);
}
-#endif
} // namespace WebKit
Modified: trunk/Source/WebKit/WebProcess/GPU/graphics/cocoa/ImageBufferShareableMappedIOSurfaceBackend.h (286837 => 286838)
--- trunk/Source/WebKit/WebProcess/GPU/graphics/cocoa/ImageBufferShareableMappedIOSurfaceBackend.h 2021-12-10 08:22:37 UTC (rev 286837)
+++ trunk/Source/WebKit/WebProcess/GPU/graphics/cocoa/ImageBufferShareableMappedIOSurfaceBackend.h 2021-12-10 08:24:30 UTC (rev 286838)
@@ -31,6 +31,10 @@
#include <WebCore/ImageBufferIOSurfaceBackend.h>
#include <wtf/IsoMalloc.h>
+namespace WebCore {
+class ProcessIdentity;
+}
+
namespace WebKit {
class ShareableBitmap;
@@ -46,9 +50,7 @@
ImageBufferBackendHandle createImageBufferBackendHandle() const;
-#if HAVE(IOSURFACE_SET_OWNERSHIP_IDENTITY)
- void setProcessOwnership(task_id_token_t);
-#endif
+ void setOwnershipIdentity(const WebCore::ProcessIdentity&);
};
} // namespace WebKit
Modified: trunk/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm (286837 => 286838)
--- trunk/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm 2021-12-10 08:22:37 UTC (rev 286837)
+++ trunk/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm 2021-12-10 08:24:30 UTC (rev 286838)
@@ -1226,14 +1226,7 @@
#if ENABLE(GPU_PROCESS)
void WebProcess::platformInitializeGPUProcessConnectionParameters(GPUProcessConnectionParameters& parameters)
{
-#if HAVE(TASK_IDENTITY_TOKEN)
- task_id_token_t identityToken;
- kern_return_t kr = task_create_identity_token(mach_task_self(), &identityToken);
- if (kr == KERN_SUCCESS)
- parameters.webProcessIdentityToken = MachSendRight::adopt(identityToken);
- else
- RELEASE_LOG_ERROR(Process, "Call to task_create_identity_token() failed: %{private}s (%x)", mach_error_string(kr), kr);
-#endif
+ parameters.webProcessIdentity = ProcessIdentity { ProcessIdentity::CurrentProcess };
parameters.overrideLanguages = userPreferredLanguagesOverride();
}
Modified: trunk/Tools/ChangeLog (286837 => 286838)
--- trunk/Tools/ChangeLog 2021-12-10 08:22:37 UTC (rev 286837)
+++ trunk/Tools/ChangeLog 2021-12-10 08:24:30 UTC (rev 286838)
@@ -1,3 +1,16 @@
+2021-12-10 Kimmo Kinnunen <kkinnu...@apple.com>
+
+ IOSurface memory attribution is hard to use in constructors
+ https://bugs.webkit.org/show_bug.cgi?id=232988
+ <rdar://problem/85541918>
+
+ Reviewed by Chris Dumez.
+
+ Update constructor calling base class constructor, add empty
+ ProcesseIdentity.
+
+ * TestWebKitAPI/Tests/WebCore/cocoa/TestGraphicsContextGLCocoa.mm:
+
2021-12-09 Antoine Quint <grao...@webkit.org>
[Model] Add load and error events to distinguish resource load from model readiness
Modified: trunk/Tools/TestWebKitAPI/Tests/WebCore/cocoa/TestGraphicsContextGLCocoa.mm (286837 => 286838)
--- trunk/Tools/TestWebKitAPI/Tests/WebCore/cocoa/TestGraphicsContextGLCocoa.mm 2021-12-10 08:22:37 UTC (rev 286837)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/cocoa/TestGraphicsContextGLCocoa.mm 2021-12-10 08:24:30 UTC (rev 286838)
@@ -32,6 +32,7 @@
#import <Metal/Metal.h>
#import <WebCore/Color.h>
#import <WebCore/GraphicsContextGLCocoa.h>
+#import <WebCore/ProcessIdentity.h>
#import <optional>
#import <wtf/HashSet.h>
#import <wtf/MemoryFootprint.h>
@@ -67,7 +68,7 @@
attributes.stencil = false;
attributes.alpha = true;
attributes.preserveDrawingBuffer = false;
- auto context = WebCore::GraphicsContextGLCocoa::create(WTFMove(attributes));
+ auto context = WebCore::GraphicsContextGLCocoa::create(WTFMove(attributes), { });
if (!context)
return nullptr;
context->reshape(contextSize.width(), contextSize.height());
@@ -119,15 +120,15 @@
WebCore::GraphicsContextGLAttributes attributes;
attributes.useMetal = true;
EXPECT_EQ(attributes.powerPreference, WebCore::GraphicsContextGLPowerPreference::Default);
- auto defaultContext = WebCore::GraphicsContextGLCocoa::create(WebCore::GraphicsContextGLAttributes { attributes });
+ auto defaultContext = WebCore::GraphicsContextGLCocoa::create(WebCore::GraphicsContextGLAttributes { attributes }, { });
ASSERT_NE(defaultContext, nullptr);
attributes.powerPreference = WebCore::GraphicsContextGLPowerPreference::LowPower;
- auto lowPowerContext = WebCore::GraphicsContextGLCocoa::create(WebCore::GraphicsContextGLAttributes { attributes });
+ auto lowPowerContext = WebCore::GraphicsContextGLCocoa::create(WebCore::GraphicsContextGLAttributes { attributes }, { });
ASSERT_NE(lowPowerContext, nullptr);
attributes.powerPreference = WebCore::GraphicsContextGLPowerPreference::HighPerformance;
- auto highPerformanceContext = WebCore::GraphicsContextGLCocoa::create(WebCore::GraphicsContextGLAttributes { attributes });
+ auto highPerformanceContext = WebCore::GraphicsContextGLCocoa::create(WebCore::GraphicsContextGLAttributes { attributes }, { });
ASSERT_NE(highPerformanceContext, nullptr);
EXPECT_NE(lowPowerContext->getString(WebCore::GraphicsContextGL::RENDERER), highPerformanceContext->getString(WebCore::GraphicsContextGL::RENDERER));