[iOS] Adopt ScreenProperties class.
authorpvollan@apple.com <pvollan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 26 Mar 2020 17:04:14 +0000 (17:04 +0000)
committerpvollan@apple.com <pvollan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 26 Mar 2020 17:04:14 +0000 (17:04 +0000)
https://bugs.webkit.org/show_bug.cgi?id=191767

Reviewed by Brent Fulgham.

Source/WebCore:

On macOS, the ScreenProperties class is used to collect screen properties in the UI process
and forward these to the Web process. We should also do this on iOS, in order to be able
to block frontboard services.

No new tests. Covered by existing tests.

* Sources.txt:
* platform/PlatformScreen.h:
* platform/ScreenProperties.h:
(WebCore::ScreenData::encode const):
(WebCore::ScreenData::decode):
* platform/ios/PlatformScreenIOS.mm:
(WebCore::screenIsMonochrome):
(WebCore::screenHasInvertedColors):
(WebCore::screenSupportsExtendedColor):
(WebCore::collectScreenProperties):
* platform/mac/PlatformScreenMac.mm:
(WebCore::primaryOpenGLDisplayMask):
(WebCore::displayMaskForDisplay):
(WebCore::primaryGPUID):
(WebCore::gpuIDForDisplay):
(WebCore::screenIsMonochrome):
(WebCore::screenHasInvertedColors):
(WebCore::screenDepth):
(WebCore::screenDepthPerComponent):
(WebCore::screenRectForDisplay):
(WebCore::screenRect):
(WebCore::screenAvailableRect):
(WebCore::screenColorSpace):
(WebCore::screenSupportsExtendedColor):
(WebCore::screenProperties): Deleted.
(WebCore::primaryScreenDisplayID): Deleted.
(WebCore::setScreenProperties): Deleted.
(WebCore::screenData): Deleted.
(WebCore::getScreenProperties): Deleted.

Source/WebKit:

Make relevent macOS platform code cross platform.

* Shared/WebProcessCreationParameters.cpp:
(WebKit::WebProcessCreationParameters::encode const):
(WebKit::WebProcessCreationParameters::decode):
* Shared/WebProcessCreationParameters.h:
* UIProcess/Cocoa/WebProcessPoolCocoa.mm:
(WebKit::WebProcessPool::platformInitializeWebProcess):
* WebProcess/WebProcess.cpp:
(WebKit::WebProcess::setScreenProperties):
* WebProcess/WebProcess.h:
* WebProcess/WebProcess.messages.in:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@259049 268f45cc-cd09-0410-ab3c-d52691b4dbfc

17 files changed:
Source/WebCore/ChangeLog
Source/WebCore/Sources.txt
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/platform/PlatformScreen.cpp [new file with mode: 0644]
Source/WebCore/platform/PlatformScreen.h
Source/WebCore/platform/ScreenProperties.h
Source/WebCore/platform/ios/PlatformScreenIOS.mm
Source/WebCore/platform/mac/PlatformScreenMac.mm
Source/WebCore/testing/Internals.cpp
Source/WebKit/ChangeLog
Source/WebKit/Shared/WebProcessCreationParameters.cpp
Source/WebKit/Shared/WebProcessCreationParameters.h
Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm
Source/WebKit/UIProcess/WebProcessPool.cpp
Source/WebKit/WebProcess/WebProcess.h
Source/WebKit/WebProcess/WebProcess.messages.in
Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm

index b805a51..03f45ba 100644 (file)
@@ -1,3 +1,46 @@
+2020-03-26  Per Arne Vollan  <pvollan@apple.com>
+
+        [iOS] Adopt ScreenProperties class.
+        https://bugs.webkit.org/show_bug.cgi?id=191767
+
+        Reviewed by Brent Fulgham.
+
+        On macOS, the ScreenProperties class is used to collect screen properties in the UI process
+        and forward these to the Web process. We should also do this on iOS, in order to be able
+        to block frontboard services.
+        No new tests. Covered by existing tests.
+
+        * Sources.txt:
+        * platform/PlatformScreen.h:
+        * platform/ScreenProperties.h:
+        (WebCore::ScreenData::encode const):
+        (WebCore::ScreenData::decode):
+        * platform/ios/PlatformScreenIOS.mm:
+        (WebCore::screenIsMonochrome):
+        (WebCore::screenHasInvertedColors):
+        (WebCore::screenSupportsExtendedColor):
+        (WebCore::collectScreenProperties):
+        * platform/mac/PlatformScreenMac.mm:
+        (WebCore::primaryOpenGLDisplayMask):
+        (WebCore::displayMaskForDisplay):
+        (WebCore::primaryGPUID):
+        (WebCore::gpuIDForDisplay):
+        (WebCore::screenIsMonochrome):
+        (WebCore::screenHasInvertedColors):
+        (WebCore::screenDepth):
+        (WebCore::screenDepthPerComponent):
+        (WebCore::screenRectForDisplay):
+        (WebCore::screenRect):
+        (WebCore::screenAvailableRect):
+        (WebCore::screenColorSpace):
+        (WebCore::screenSupportsExtendedColor):
+        (WebCore::screenProperties): Deleted.
+        (WebCore::primaryScreenDisplayID): Deleted.
+        (WebCore::setScreenProperties): Deleted.
+        (WebCore::screenData): Deleted.
+        (WebCore::getScreenProperties): Deleted.
+
 2020-03-26  Rob Buis  <rbuis@igalia.com>
 
         Take into account referrer-policy in append Origin header algorithm
index cd1c7a2..1733697 100644 (file)
@@ -1775,6 +1775,7 @@ platform/Pasteboard.cpp
 platform/PasteboardCustomData.cpp
 platform/PasteboardWriterData.cpp
 platform/PlatformKeyboardEvent.cpp
+platform/PlatformScreen.cpp
 platform/PlatformSpeechSynthesisUtterance.cpp
 platform/PlatformSpeechSynthesisVoice.cpp
 platform/PlatformSpeechSynthesizer.cpp
index 9f9ed73..b78d03c 100644 (file)
                C105DA630F3AA6B8001DD44F /* TextEncodingDetector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextEncodingDetector.h; sourceTree = "<group>"; };
                C11A9ECD21403A5C00CFB20A /* SwitchingGPUClient.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SwitchingGPUClient.h; sourceTree = "<group>"; };
                C11A9ED22140578B00CFB20A /* SwitchingGPUClient.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = SwitchingGPUClient.cpp; sourceTree = "<group>"; };
+               C137846B242BEEBA00E86FA8 /* PlatformScreen.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PlatformScreen.cpp; sourceTree = "<group>"; };
                C149380522342719000CD707 /* SpeechSynthesisClient.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SpeechSynthesisClient.h; sourceTree = "<group>"; };
                C1692DD123D23ABD006E88F7 /* SystemBattery.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = SystemBattery.mm; sourceTree = "<group>"; };
                C1692DD423D23AE0006E88F7 /* SystemBattery.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SystemBattery.h; sourceTree = "<group>"; };
                                935C476609AC4D4300A6AAB4 /* PlatformKeyboardEvent.h */,
                                935C476709AC4D4300A6AAB4 /* PlatformMouseEvent.h */,
                                C5BAC16F14E30E4700008837 /* PlatformPasteboard.h */,
+                               C137846B242BEEBA00E86FA8 /* PlatformScreen.cpp */,
                                BCEC01D60C274EB4009F4EC9 /* PlatformScreen.h */,
                                2527CC9516BF95DD009DDAC0 /* PlatformSpeechSynthesisUtterance.cpp */,
                                2527CC9116BF8BA1009DDAC0 /* PlatformSpeechSynthesisUtterance.h */,
diff --git a/Source/WebCore/platform/PlatformScreen.cpp b/Source/WebCore/platform/PlatformScreen.cpp
new file mode 100644 (file)
index 0000000..cdcd668
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2020 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.
+ */
+
+#include "config.h"
+#include "PlatformScreen.h"
+
+#if PLATFORM(COCOA)
+
+#include "ScreenProperties.h"
+
+namespace WebCore {
+
+static ScreenProperties& screenProperties()
+{
+    static NeverDestroyed<ScreenProperties> screenProperties;
+    return screenProperties;
+}
+
+PlatformDisplayID primaryScreenDisplayID()
+{
+    return screenProperties().primaryDisplayID;
+}
+
+void setScreenProperties(const ScreenProperties& properties)
+{
+    screenProperties() = properties;
+}
+
+Optional<const ScreenData&> screenData(PlatformDisplayID screendisplayID)
+{
+    if (screenProperties().screenDataMap.isEmpty())
+        return WTF::nullopt;
+
+    // Return property of the first screen if the screen is not found in the map.
+    auto displayID = screendisplayID ? screendisplayID : primaryScreenDisplayID();
+    if (displayID) {
+        auto screenPropertiesForDisplay = screenProperties().screenDataMap.find(displayID);
+        if (screenPropertiesForDisplay != screenProperties().screenDataMap.end())
+            return screenPropertiesForDisplay->value;
+    }
+
+    // Last resort: use the first item in the screen list.
+    return screenProperties().screenDataMap.begin()->value;
+}
+
+} // namespace WebCore
+
+#endif // PLATFORM(COCOA)
index d39c7e7..e35774d 100644 (file)
@@ -25,6 +25,8 @@
 
 #pragma once
 
+#include <wtf/Optional.h>
+
 #if USE(GLIB)
 #include <wtf/Function.h>
 #endif
@@ -85,9 +87,15 @@ constexpr bool screenSupportsHighDynamicRange(Widget* = nullptr) { return false;
 WEBCORE_EXPORT CGColorSpaceRef screenColorSpace(Widget* = nullptr);
 #endif
 
-#if PLATFORM(MAC)
 struct ScreenProperties;
-
+struct ScreenData;
+    
+WEBCORE_EXPORT ScreenProperties collectScreenProperties();
+WEBCORE_EXPORT void setScreenProperties(const ScreenProperties&);
+Optional<const ScreenData&> screenData(PlatformDisplayID screendisplayID);
+WEBCORE_EXPORT PlatformDisplayID primaryScreenDisplayID();
+    
+#if PLATFORM(MAC)
 WEBCORE_EXPORT PlatformDisplayID displayID(NSScreen *);
 
 WEBCORE_EXPORT NSScreen *screen(NSWindow *);
@@ -102,13 +110,8 @@ WEBCORE_EXPORT NSRect toDeviceSpace(const FloatRect&, NSWindow *source);
 
 NSPoint flipScreenPoint(const NSPoint&, NSScreen *);
 
-WEBCORE_EXPORT ScreenProperties collectScreenProperties();
-WEBCORE_EXPORT void setScreenProperties(const ScreenProperties&);
-
 WEBCORE_EXPORT void setShouldOverrideScreenSupportsHighDynamicRange(bool shouldOverride, bool supportsHighDynamicRange);
 
-WEBCORE_EXPORT PlatformDisplayID primaryScreenDisplayID();
-
 uint32_t primaryOpenGLDisplayMask();
 uint32_t displayMaskForDisplay(PlatformDisplayID);
 
index edae53b..bf42016 100644 (file)
@@ -25,8 +25,6 @@
 
 #pragma once
 
-#if PLATFORM(MAC)
-
 #include "FloatRect.h"
 #include "PlatformScreen.h"
 #include <wtf/RetainPtr.h>
@@ -46,9 +44,10 @@ struct ScreenData {
     bool screenHasInvertedColors { false };
     bool screenIsMonochrome { false };
     bool screenSupportsHighDynamicRange { false };
+#if PLATFORM(MAC)
     uint32_t displayMask { 0 };
     IORegistryGPUID gpuID { 0 };
-
+#endif
     enum EncodedColorSpaceDataType {
         Null,
         ColorSpaceName,
@@ -95,7 +94,11 @@ Optional<ScreenProperties> ScreenProperties::decode(Decoder& decoder)
 template<class Encoder>
 void ScreenData::encode(Encoder& encoder) const
 {
-    encoder << screenAvailableRect << screenRect << screenDepth << screenDepthPerComponent << screenSupportsExtendedColor << screenHasInvertedColors << screenIsMonochrome << screenSupportsHighDynamicRange << displayMask << gpuID;
+    encoder << screenAvailableRect << screenRect << screenDepth << screenDepthPerComponent << screenSupportsExtendedColor << screenHasInvertedColors << screenIsMonochrome << screenSupportsHighDynamicRange;
+
+#if PLATFORM(MAC)
+    encoder << displayMask << gpuID;
+#endif
 
     if (colorSpace) {
         // Try to encode the name.
@@ -164,6 +167,7 @@ Optional<ScreenData> ScreenData::decode(Decoder& decoder)
     if (!screenSupportsHighDynamicRange)
         return WTF::nullopt;
 
+#if PLATFORM(MAC)
     Optional<uint32_t> displayMask;
     decoder >> displayMask;
     if (!displayMask)
@@ -173,7 +177,8 @@ Optional<ScreenData> ScreenData::decode(Decoder& decoder)
     decoder >> gpuID;
     if (!gpuID)
         return WTF::nullopt;
-    
+#endif
+
     EncodedColorSpaceDataType dataType;
     if (!decoder.decodeEnum(dataType))
         return WTF::nullopt;
@@ -205,9 +210,21 @@ Optional<ScreenData> ScreenData::decode(Decoder& decoder)
     }
     }
 
-    return { { WTFMove(*screenAvailableRect), WTFMove(*screenRect), WTFMove(cgColorSpace), WTFMove(*screenDepth), WTFMove(*screenDepthPerComponent), WTFMove(*screenSupportsExtendedColor), WTFMove(*screenHasInvertedColors), WTFMove(*screenIsMonochrome), WTFMove(*screenSupportsHighDynamicRange), WTFMove(*displayMask), WTFMove(*gpuID) } };
+    return { {
+        WTFMove(*screenAvailableRect),
+        WTFMove(*screenRect),
+        WTFMove(cgColorSpace),
+        WTFMove(*screenDepth),
+        WTFMove(*screenDepthPerComponent),
+        WTFMove(*screenSupportsExtendedColor),
+        WTFMove(*screenHasInvertedColors),
+        WTFMove(*screenIsMonochrome),
+        WTFMove(*screenSupportsHighDynamicRange),
+#if PLATFORM(MAC)
+        WTFMove(*displayMask),
+        WTFMove(*gpuID)
+#endif
+    } };
 }
 
 } // namespace WebCore
-
-#endif // PLATFORM(MAC)
index 37eeaa0..7ecdd84 100644 (file)
@@ -36,6 +36,7 @@
 #import "GraphicsContextCG.h"
 #import "HostWindow.h"
 #import "IntRect.h"
+#import "ScreenProperties.h"
 #import "WAKWindow.h"
 #import "Widget.h"
 #import <pal/cocoa/MediaToolboxSoftLink.h>
@@ -59,16 +60,28 @@ int screenDepthPerComponent(Widget*)
 
 bool screenIsMonochrome(Widget*)
 {
+    auto v = screenData(primaryScreenDisplayID());
+    if (v.hasValue())
+        return v->screenIsMonochrome;
+    
     return PAL::softLinkUIKitUIAccessibilityIsGrayscaleEnabled();
 }
 
 bool screenHasInvertedColors()
 {
+    auto v = screenData(primaryScreenDisplayID());
+    if (v.hasValue())
+        return v->screenHasInvertedColors;
+    
     return PAL::softLinkUIKitUIAccessibilityIsInvertColorsEnabled();
 }
 
 bool screenSupportsExtendedColor(Widget*)
 {
+    auto v = screenData(primaryScreenDisplayID());
+    if (v.hasValue())
+        return v->screenSupportsExtendedColor;
+
     return MGGetBoolAnswer(kMGQHasExtendedColorDisplay);
 }
 
@@ -141,6 +154,11 @@ FloatSize screenSize()
 {
     if (deviceHasIPadCapability() && [[PAL::getUIApplicationClass() sharedApplication] _isClassic])
         return { 320, 480 };
+
+    auto v = screenData(primaryScreenDisplayID());
+    if (v.hasValue())
+        return v->screenRect.size();
+
     return FloatSize([[PAL::getUIScreenClass() mainScreen] _referenceBounds].size);
 }
 
@@ -148,6 +166,11 @@ FloatSize availableScreenSize()
 {
     if (deviceHasIPadCapability() && [[PAL::getUIApplicationClass() sharedApplication] _isClassic])
         return { 320, 480 };
+
+    auto v = screenData(primaryScreenDisplayID());
+    if (v.hasValue())
+        return v->screenAvailableRect.size();
+
     return FloatSize([PAL::getUIScreenClass() mainScreen].bounds.size);
 }
 
@@ -168,6 +191,34 @@ float screenScaleFactor(UIScreen *screen)
     return screen.scale;
 }
 
+ScreenProperties collectScreenProperties()
+{
+    ScreenProperties screenProperties;
+
+    PlatformDisplayID displayID = 0;
+
+    for (UIScreen *screen in [PAL::getUIScreenClass() screens]) {
+        FloatRect screenAvailableRect = screen.bounds;
+        screenAvailableRect.setY(NSMaxY(screen.bounds) - (screenAvailableRect.y() + screenAvailableRect.height())); // flip
+        FloatRect screenRect = screen._referenceBounds;
+        
+        RetainPtr<CGColorSpaceRef> colorSpace = screenColorSpace(nullptr);
+        
+        int screenDepth = WebCore::screenDepth(nullptr);
+        int screenDepthPerComponent = WebCore::screenDepthPerComponent(nullptr);
+        bool screenSupportsExtendedColor = WebCore::screenSupportsExtendedColor(nullptr);
+        bool screenHasInvertedColors = WebCore::screenHasInvertedColors();
+        bool screenIsMonochrome = WebCore::screenIsMonochrome(nullptr);
+
+        screenProperties.screenDataMap.set(++displayID, ScreenData { screenAvailableRect, screenRect, colorSpace, screenDepth, screenDepthPerComponent, screenSupportsExtendedColor, screenHasInvertedColors, screenIsMonochrome });
+        
+        if (screen == [PAL::getUIScreenClass() mainScreen])
+            screenProperties.primaryDisplayID = displayID;
+    }
+    
+    return screenProperties;
+}
+
 } // namespace WebCore
 
 #endif // PLATFORM(IOS_FAMILY)
index 8570661..59cb7b3 100644 (file)
@@ -100,17 +100,6 @@ static NSScreen *screen(Widget* widget)
     return screen(displayID(widget));
 }
 
-static ScreenProperties& screenProperties()
-{
-    static NeverDestroyed<ScreenProperties> screenProperties;
-    return screenProperties;
-}
-
-PlatformDisplayID primaryScreenDisplayID()
-{
-    return screenProperties().primaryDisplayID;
-}
-
 ScreenProperties collectScreenProperties()
 {
     ASSERT(hasProcessPrivilege(ProcessPrivilege::CanCommunicateWithWindowServer));
@@ -151,60 +140,42 @@ ScreenProperties collectScreenProperties()
     return screenProperties;
 }
 
-void setScreenProperties(const ScreenProperties& properties)
-{
-    screenProperties() = properties;
-}
-
 void setShouldOverrideScreenSupportsHighDynamicRange(bool shouldOverride, bool supportsHighDynamicRange)
 {
     if (PAL::isMediaToolboxFrameworkAvailable() && PAL::canLoad_MediaToolbox_MTOverrideShouldPlayHDRVideo())
         PAL::softLink_MediaToolbox_MTOverrideShouldPlayHDRVideo(shouldOverride, supportsHighDynamicRange);
 }
 
-static ScreenData screenData(PlatformDisplayID screendisplayID)
-{
-    RELEASE_ASSERT(!screenProperties().screenDataMap.isEmpty());
-
-    // Return property of the first screen if the screen is not found in the map.
-    auto displayID = screendisplayID ? screendisplayID : primaryScreenDisplayID();
-    if (displayID) {
-        auto screenPropertiesForDisplay = screenProperties().screenDataMap.find(displayID);
-        if (screenPropertiesForDisplay != screenProperties().screenDataMap.end())
-            return screenPropertiesForDisplay->value;
-    }
-
-    // Last resort: use the first item in the screen list.
-    return screenProperties().screenDataMap.begin()->value;
-}
-
 uint32_t primaryOpenGLDisplayMask()
 {
-    if (!screenProperties().screenDataMap.isEmpty())
-        return screenData(primaryScreenDisplayID()).displayMask;
-    
+    auto v = screenData(primaryScreenDisplayID());
+    if (v.hasValue())
+        return v->displayMask;
+
     return 0;
 }
 
 uint32_t displayMaskForDisplay(PlatformDisplayID displayID)
 {
-    if (!screenProperties().screenDataMap.isEmpty())
-        return screenData(displayID).displayMask;
-    
+    auto v = screenData(displayID);
+    if (v.hasValue())
+        return v->displayMask;
+
     ASSERT_NOT_REACHED();
     return 0;
 }
 
 IORegistryGPUID primaryGPUID()
 {
-    return gpuIDForDisplay(screenProperties().primaryDisplayID);
+    return gpuIDForDisplay(primaryScreenDisplayID());
 }
 
 IORegistryGPUID gpuIDForDisplay(PlatformDisplayID displayID)
 {
 #if ENABLE(WEBPROCESS_WINDOWSERVER_BLOCKING)
-    if (!screenProperties().screenDataMap.isEmpty())
-        return screenData(displayID).gpuID;
+    auto v = screenData(displayID);
+    if (v.hasValue())
+        return v->gpuID;
 #else
     return gpuIDForDisplayMask(CGDisplayIDToOpenGLDisplayMask(displayID));
 #endif
@@ -246,15 +217,16 @@ IORegistryGPUID gpuIDForDisplayMask(GLuint displayMask)
     return (IORegistryGPUID) gpuIDHigh << 32 | gpuIDLow;
 }
 
-static ScreenData getScreenProperties(Widget* widget)
+static Optional<const ScreenData&> getScreenProperties(Widget* widget)
 {
     return screenData(displayID(widget));
 }
 
 bool screenIsMonochrome(Widget* widget)
 {
-    if (!screenProperties().screenDataMap.isEmpty())
-        return getScreenProperties(widget).screenIsMonochrome;
+    auto v = getScreenProperties(widget);
+    if (v.hasValue())
+        return v->screenIsMonochrome;
 
     // This is a system-wide accessibility setting, same on all screens.
     ASSERT(hasProcessPrivilege(ProcessPrivilege::CanCommunicateWithWindowServer));
@@ -263,8 +235,9 @@ bool screenIsMonochrome(Widget* widget)
 
 bool screenHasInvertedColors()
 {
-    if (!screenProperties().screenDataMap.isEmpty())
-        return screenData(primaryScreenDisplayID()).screenHasInvertedColors;
+    auto v = screenData(primaryScreenDisplayID());
+    if (v.hasValue())
+        return v->screenHasInvertedColors;
 
     // This is a system-wide accessibility setting, same on all screens.
     ASSERT(hasProcessPrivilege(ProcessPrivilege::CanCommunicateWithWindowServer));
@@ -273,8 +246,9 @@ bool screenHasInvertedColors()
 
 int screenDepth(Widget* widget)
 {
-    if (!screenProperties().screenDataMap.isEmpty()) {
-        auto screenDepth = getScreenProperties(widget).screenDepth;
+    auto v = getScreenProperties(widget);
+    if (v.hasValue()) {
+        auto screenDepth = v->screenDepth;
         ASSERT(screenDepth);
         return screenDepth;
     }
@@ -285,8 +259,9 @@ int screenDepth(Widget* widget)
 
 int screenDepthPerComponent(Widget* widget)
 {
-    if (!screenProperties().screenDataMap.isEmpty()) {
-        auto depthPerComponent = getScreenProperties(widget).screenDepthPerComponent;
+    auto v = getScreenProperties(widget);
+    if (v.hasValue()) {
+        auto depthPerComponent = v->screenDepthPerComponent;
         ASSERT(depthPerComponent);
         return depthPerComponent;
     }
@@ -297,8 +272,9 @@ int screenDepthPerComponent(Widget* widget)
 
 FloatRect screenRectForDisplay(PlatformDisplayID displayID)
 {
-    if (!screenProperties().screenDataMap.isEmpty()) {
-        auto screenRect = screenData(displayID).screenRect;
+    auto v = screenData(displayID);
+    if (v.hasValue()) {
+        auto screenRect = v->screenRect;
         ASSERT(!screenRect.isEmpty());
         return screenRect;
     }
@@ -314,8 +290,9 @@ FloatRect screenRectForPrimaryScreen()
 
 FloatRect screenRect(Widget* widget)
 {
-    if (!screenProperties().screenDataMap.isEmpty())
-        return getScreenProperties(widget).screenRect;
+    auto v = getScreenProperties(widget);
+    if (v.hasValue())
+        return v->screenRect;
 
     ASSERT(hasProcessPrivilege(ProcessPrivilege::CanCommunicateWithWindowServer));
     return toUserSpace([screen(widget) frame], window(widget));
@@ -323,8 +300,9 @@ FloatRect screenRect(Widget* widget)
 
 FloatRect screenAvailableRect(Widget* widget)
 {
-    if (!screenProperties().screenDataMap.isEmpty())
-        return getScreenProperties(widget).screenAvailableRect;
+    auto v = getScreenProperties(widget);
+    if (v.hasValue())
+        return v->screenAvailableRect;
 
     ASSERT(hasProcessPrivilege(ProcessPrivilege::CanCommunicateWithWindowServer));
     return toUserSpace([screen(widget) visibleFrame], window(widget));
@@ -348,8 +326,9 @@ NSScreen *screen(PlatformDisplayID displayID)
 
 CGColorSpaceRef screenColorSpace(Widget* widget)
 {
-    if (!screenProperties().screenDataMap.isEmpty())
-        return getScreenProperties(widget).colorSpace.get();
+    auto v = getScreenProperties(widget);
+    if (v.hasValue())
+        return v->colorSpace.get();
 
     ASSERT(hasProcessPrivilege(ProcessPrivilege::CanCommunicateWithWindowServer));
     return screen(widget).colorSpace.CGColorSpace;
@@ -357,8 +336,9 @@ CGColorSpaceRef screenColorSpace(Widget* widget)
 
 bool screenSupportsExtendedColor(Widget* widget)
 {
-    if (!screenProperties().screenDataMap.isEmpty())
-        return getScreenProperties(widget).screenSupportsExtendedColor;
+    auto v = getScreenProperties(widget);
+    if (v.hasValue())
+        return v->screenSupportsExtendedColor;
 
     ASSERT(hasProcessPrivilege(ProcessPrivilege::CanCommunicateWithWindowServer));
     return [screen(widget) canRepresentDisplayGamut:NSDisplayGamutP3];
@@ -366,8 +346,9 @@ bool screenSupportsExtendedColor(Widget* widget)
 
 bool screenSupportsHighDynamicRange(Widget* widget)
 {
-    if (!screenProperties().screenDataMap.isEmpty())
-        return getScreenProperties(widget).screenSupportsHighDynamicRange;
+    auto v = getScreenProperties(widget);
+    if (v.hasValue())
+        return v->screenSupportsHighDynamicRange;
 
     ASSERT(hasProcessPrivilege(ProcessPrivilege::CanCommunicateWithWindowServer));
 #if USE(MEDIATOOLBOX)
index 8701e15..af27b99 100644 (file)
@@ -5264,7 +5264,7 @@ void Internals::notifyResourceLoadObserver()
 
 unsigned Internals::primaryScreenDisplayID()
 {
-#if PLATFORM(MAC)
+#if PLATFORM(COCOA)
     return WebCore::primaryScreenDisplayID();
 #else
     return 0;
index f62af60..1468c31 100644 (file)
@@ -1,3 +1,23 @@
+2020-03-26  Per Arne Vollan  <pvollan@apple.com>
+
+        [iOS] Adopt ScreenProperties class.
+        https://bugs.webkit.org/show_bug.cgi?id=191767
+
+        Reviewed by Brent Fulgham.
+
+        Make relevent macOS platform code cross platform.
+
+        * Shared/WebProcessCreationParameters.cpp:
+        (WebKit::WebProcessCreationParameters::encode const):
+        (WebKit::WebProcessCreationParameters::decode):
+        * Shared/WebProcessCreationParameters.h:
+        * UIProcess/Cocoa/WebProcessPoolCocoa.mm:
+        (WebKit::WebProcessPool::platformInitializeWebProcess):
+        * WebProcess/WebProcess.cpp:
+        (WebKit::WebProcess::setScreenProperties):
+        * WebProcess/WebProcess.h:
+        * WebProcess/WebProcess.messages.in:
+
 2020-03-26  David Kilzer  <ddkilzer@apple.com>
 
         MESSAGE_CHECK base macros should use UNLIKELY()
index 3358f81..9dcfe9b 100644 (file)
@@ -141,10 +141,10 @@ void WebProcessCreationParameters::encode(IPC::Encoder& encoder) const
 
 #if PLATFORM(COCOA)
     encoder << mediaMIMETypes;
+    encoder << screenProperties;
 #endif
 
 #if PLATFORM(MAC)
-    encoder << screenProperties;
     encoder << useOverlayScrollbars;
 #endif
 
@@ -389,14 +389,15 @@ bool WebProcessCreationParameters::decode(IPC::Decoder& decoder, WebProcessCreat
 #if PLATFORM(COCOA)
     if (!decoder.decode(parameters.mediaMIMETypes))
         return false;
-#endif
 
-#if PLATFORM(MAC)
     Optional<WebCore::ScreenProperties> screenProperties;
     decoder >> screenProperties;
     if (!screenProperties)
         return false;
     parameters.screenProperties = WTFMove(*screenProperties);
+#endif
+
+#if PLATFORM(MAC)
     if (!decoder.decode(parameters.useOverlayScrollbars))
         return false;
 #endif
index a02d9d0..1160d6b 100644 (file)
 #include <wtf/text/WTFString.h>
 
 #if PLATFORM(COCOA)
-#include <wtf/MachSendRight.h>
-#endif
-
-#if PLATFORM(MAC)
 #include <WebCore/PlatformScreen.h>
 #include <WebCore/ScreenProperties.h>
+#include <wtf/MachSendRight.h>
 #endif
 
 #if USE(SOUP)
@@ -181,6 +178,7 @@ struct WebProcessCreationParameters {
 
 #if PLATFORM(COCOA)
     Vector<String> mediaMIMETypes;
+    WebCore::ScreenProperties screenProperties;
 #endif
 
 #if ENABLE(RESOURCE_LOAD_STATISTICS) && !RELEASE_LOG_DISABLED
@@ -188,7 +186,6 @@ struct WebProcessCreationParameters {
 #endif
 
 #if PLATFORM(MAC)
-    WebCore::ScreenProperties screenProperties;
     bool useOverlayScrollbars { true };
 #endif
 
index 692be3e..cecedad 100644 (file)
@@ -353,10 +353,10 @@ void WebProcessPool::platformInitializeWebProcess(const WebProcessProxy& process
 #if ENABLE(RESOURCE_LOAD_STATISTICS) && !RELEASE_LOG_DISABLED
     parameters.shouldLogUserInteraction = [defaults boolForKey:WebKitLogCookieInformationDefaultsKey];
 #endif
-    
-#if PLATFORM(MAC)
+
     auto screenProperties = WebCore::collectScreenProperties();
     parameters.screenProperties = WTFMove(screenProperties);
+#if PLATFORM(MAC)
     parameters.useOverlayScrollbars = ([NSScroller preferredScrollerStyle] == NSScrollerStyleOverlay);
 #endif
     
index 4bb7b46..245f5eb 100644 (file)
@@ -474,7 +474,7 @@ void WebProcessPool::setApplicationIsActive(bool isActive)
 
 void WebProcessPool::screenPropertiesStateChanged()
 {
-#if PLATFORM(MAC)
+#if PLATFORM(COCOA)
     auto screenProperties = WebCore::collectScreenProperties();
     sendToAllProcesses(Messages::WebProcess::SetScreenProperties(screenProperties));
 #endif
index 97e4676..01c76af 100644 (file)
@@ -46,9 +46,6 @@
 #include <WebCore/NetworkStorageSession.h>
 #include <WebCore/PageIdentifier.h>
 #include <WebCore/RegistrableDomain.h>
-#if PLATFORM(MAC)
-#include <WebCore/ScreenProperties.h>
-#endif
 #include <WebCore/ServiceWorkerTypes.h>
 #include <WebCore/Timer.h>
 #include <pal/HysteresisActivity.h>
@@ -61,6 +58,7 @@
 #include <wtf/text/AtomStringHash.h>
 
 #if PLATFORM(COCOA)
+#include <WebCore/ScreenProperties.h>
 #include <dispatch/dispatch.h>
 #include <wtf/MachSendRight.h>
 #endif
@@ -473,16 +471,14 @@ private:
     // Implemented in generated WebProcessMessageReceiver.cpp
     void didReceiveWebProcessMessage(IPC::Connection&, IPC::Decoder&);
 
-#if PLATFORM(MAC)
-    void setScreenProperties(const WebCore::ScreenProperties&);
-#if ENABLE(WEBPROCESS_WINDOWSERVER_BLOCKING)
+#if PLATFORM(MAC) && ENABLE(WEBPROCESS_WINDOWSERVER_BLOCKING)
     void scrollerStylePreferenceChanged(bool useOverlayScrollbars);
     void displayConfigurationChanged(CGDirectDisplayID, CGDisplayChangeSummaryFlags);
     void displayWasRefreshed(CGDirectDisplayID);
 #endif
-#endif
 
 #if PLATFORM(COCOA)
+    void setScreenProperties(const WebCore::ScreenProperties&);
     void updateProcessName();
 #endif
 
index 7c3a005..abaa9c3 100644 (file)
@@ -113,14 +113,14 @@ messages -> WebProcess LegacyReceiver NotRefCounted {
     MarkIsNoLongerPrewarmed()
     GetActivePagesOriginsForTesting() -> (Vector<String> activeOrigins) Async
 
-#if PLATFORM(MAC)
+#if PLATFORM(COCOA)
     SetScreenProperties(struct WebCore::ScreenProperties screenProperties)
-#if ENABLE(WEBPROCESS_WINDOWSERVER_BLOCKING)
+#endif
+#if PLATFORM(MAC) && ENABLE(WEBPROCESS_WINDOWSERVER_BLOCKING)
     ScrollerStylePreferenceChanged(bool useOvelayScrollbars)
     DisplayConfigurationChanged(CGDirectDisplayID displayID, CGDisplayChangeSummaryFlags flags)
     DisplayWasRefreshed(uint32_t displayID)
 #endif
-#endif
 
 #if PLATFORM(IOS_FAMILY) && !PLATFORM(MACCATALYST)
     BacklightLevelDidChange(float backlightLevel)
index 439ccda..820f9b8 100644 (file)
@@ -245,13 +245,12 @@ void WebProcess::platformInitializeWebProcess(WebProcessCreationParameters& para
         });
     }
 
-#if PLATFORM(MAC)
     WebCore::setScreenProperties(parameters.screenProperties);
-#if ENABLE(WEBPROCESS_WINDOWSERVER_BLOCKING)
+
+#if PLATFORM(MAC) && ENABLE(WEBPROCESS_WINDOWSERVER_BLOCKING)
     scrollerStylePreferenceChanged(parameters.useOverlayScrollbars);
 #endif
-#endif
-    
+
 #if PLATFORM(IOS)
     if (parameters.compilerServiceExtensionHandle)
         SandboxExtension::consumePermanently(*parameters.compilerServiceExtensionHandle);
@@ -960,15 +959,17 @@ void WebProcess::revokeAccessToAssetServices()
 }
 #endif
 
-#if PLATFORM(MAC)
 void WebProcess::setScreenProperties(const ScreenProperties& properties)
 {
     WebCore::setScreenProperties(properties);
     for (auto& page : m_pageMap.values())
         page->screenPropertiesDidChange();
+#if PLATFORM(MAC)
     updatePageScreenProperties();
+#endif
 }
 
+#if PLATFORM(MAC)
 void WebProcess::updatePageScreenProperties()
 {
     if (hasProcessPrivilege(ProcessPrivilege::CanCommunicateWithWindowServer)) {