Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
https://bugs.webkit.org/show_bug.cgi?id=268318 rdar://121873837 Reviewed by Brady Eidson. Start using generated serialization for CGColorSpace instead of hand-rolled serializers. * Source/WebKit/DerivedSources-input.xcfilelist: * Source/WebKit/DerivedSources.make: * Source/WebKit/Shared/cf/ArgumentCodersCF.cpp: (IPC::ArgumentCoder<CGColorSpaceRef>::encode): Deleted. (IPC::ArgumentCoder<RetainPtr<CGColorSpaceRef>>::decode): Deleted. * Source/WebKit/Shared/cf/ArgumentCodersCF.h: * Source/WebKit/Shared/cf/CFTypes.serialization.in: * Source/WebKit/Shared/cf/CoreIPCCGColorSpace.h: Added. (WebKit::CoreIPCCGColorSpace::CoreIPCCGColorSpace): (WebKit::CoreIPCCGColorSpace::toCF const): * Source/WebKit/Shared/cf/CoreIPCCGColorSpace.serialization.in: Copied from Source/WebKit/Shared/cf/CFTypes.serialization.in. * Source/WebKit/WebKit.xcodeproj/project.pbxproj: * Tools/TestWebKitAPI/Tests/IPC/IPCSerialization.mm: (TEST): Canonical link: https://commits.webkit.org/274188@main
- Loading branch information
Pascoe
committed
Feb 7, 2024
1 parent
f7b9c81
commit de7f3c3
Showing
9 changed files
with
128 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Copyright (C) 2024 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 | ||
|
||
#if PLATFORM(COCOA) | ||
|
||
#import <CoreGraphics/CoreGraphics.h> | ||
#import <WebCore/Color.h> | ||
#import <WebCore/ColorSpace.h> | ||
#import <WebCore/ColorSpaceCG.h> | ||
#import <wtf/RetainPtr.h> | ||
|
||
using CGColorSpaceSerialization = std::variant<WebCore::ColorSpace, RetainPtr<CFStringRef>, RetainPtr<CFTypeRef>>; | ||
|
||
namespace WebKit { | ||
class CoreIPCCGColorSpace { | ||
public: | ||
CoreIPCCGColorSpace(CGColorSpaceRef cgColorSpace) | ||
{ | ||
if (auto colorSpace = WebCore::colorSpaceForCGColorSpace(cgColorSpace)) | ||
m_cgColorSpace = *colorSpace; | ||
else if (RetainPtr<CFStringRef> name = CGColorSpaceGetName(cgColorSpace)) | ||
m_cgColorSpace = WTFMove(name); | ||
else if (auto propertyList = adoptCF(CGColorSpaceCopyPropertyList(cgColorSpace))) | ||
m_cgColorSpace = WTFMove(propertyList); | ||
else | ||
// FIXME: This should be removed once we can prove only non-null cgColorSpaces. | ||
m_cgColorSpace = WebCore::ColorSpace::SRGB; | ||
} | ||
|
||
CoreIPCCGColorSpace(CGColorSpaceSerialization data) | ||
: m_cgColorSpace(data) | ||
{ | ||
} | ||
|
||
RetainPtr<CGColorSpaceRef> toCF() const | ||
{ | ||
auto colorSpace = WTF::switchOn(m_cgColorSpace, | ||
[](WebCore::ColorSpace colorSpace) -> RetainPtr<CGColorSpaceRef> { | ||
return RetainPtr { cachedNullableCGColorSpace(colorSpace) }; | ||
}, | ||
[](RetainPtr<CFStringRef> name) -> RetainPtr<CGColorSpaceRef> { | ||
return adoptCF(CGColorSpaceCreateWithName(name.get())); | ||
}, | ||
[](RetainPtr<CFTypeRef> propertyList) -> RetainPtr<CGColorSpaceRef> { | ||
return adoptCF(CGColorSpaceCreateWithPropertyList(propertyList.get())); | ||
} | ||
); | ||
if (UNLIKELY(!colorSpace)) | ||
return nullptr; | ||
return colorSpace; | ||
} | ||
|
||
CGColorSpaceSerialization m_cgColorSpace; | ||
}; | ||
|
||
} | ||
|
||
#endif |
31 changes: 31 additions & 0 deletions
31
Source/WebKit/Shared/cf/CoreIPCCGColorSpace.serialization.in
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Copyright (C) 2024 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. | ||
|
||
#if PLATFORM(COCOA) | ||
|
||
webkit_platform_headers: "CoreIPCCGColorSpace.h" | ||
|
||
[WebKitPlatform, AdditionalEncoder=StreamConnectionEncoder] class WebKit::CoreIPCCGColorSpace { | ||
CGColorSpaceSerialization m_cgColorSpace; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters