Changeset 230351 in webkit


Ignore:
Timestamp:
Apr 6, 2018 12:37:17 PM (6 years ago)
Author:
Brent Fulgham
Message:

WebCore::screenColorSpace is retrieving CGColorSpace from NSScreen directly
https://bugs.webkit.org/show_bug.cgi?id=184343
<rdar://problem/39224881>

Reviewed by Per Arne Vollan.

Revise ScreenProperties to serialize the screen's color space, and later
retrieve that in the WebContent process. This allows us to close off
the CGSWindowServer connection.

  • platform/ScreenProperties.h:

(WebCore::ScreenProperties::encode const): Add CGColorSpaceRef support.
(WebCore::ScreenProperties::decode): Ditto.

  • platform/mac/PlatformScreenMac.mm:

(WebCore::displayID): Add assertion to prevent use in WebContent process.
(WebCore::firstScreen): Ditto.
(WebCore::getScreenProperties): Add support for CGColorSpaceRef.
(WebCore::screenColorSpace): Retrieve cached version when in WebContent process.
Assert that NSScreen is not accessed in WebContent process.

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r230350 r230351  
     12018-04-06  Brent Fulgham  <bfulgham@apple.com>
     2
     3        WebCore::screenColorSpace is retrieving CGColorSpace from NSScreen directly
     4        https://bugs.webkit.org/show_bug.cgi?id=184343
     5        <rdar://problem/39224881>
     6
     7        Reviewed by Per Arne Vollan.
     8
     9        Revise ScreenProperties to serialize the screen's color space, and later
     10        retrieve that in the WebContent process. This allows us to close off
     11        the CGSWindowServer connection.
     12
     13        * platform/ScreenProperties.h:
     14        (WebCore::ScreenProperties::encode const): Add CGColorSpaceRef support.
     15        (WebCore::ScreenProperties::decode): Ditto.
     16        * platform/mac/PlatformScreenMac.mm:
     17        (WebCore::displayID): Add assertion to prevent use in WebContent process.
     18        (WebCore::firstScreen): Ditto.
     19        (WebCore::getScreenProperties): Add support for CGColorSpaceRef.
     20        (WebCore::screenColorSpace): Retrieve cached version when in WebContent process.
     21        Assert that NSScreen is not accessed in WebContent process.
     22
    1232018-04-06  Ms2ger  <Ms2ger@igalia.com>
    224
  • trunk/Source/WebCore/platform/ScreenProperties.h

    r230323 r230351  
    2626#pragma once
    2727
     28#if PLATFORM(MAC)
     29
    2830#include "FloatRect.h"
     31#include <wtf/RetainPtr.h>
     32#include <wtf/text/WTFString.h>
     33
     34typedef struct CGColorSpace *CGColorSpaceRef;
    2935
    3036namespace WebCore {
     
    3339    FloatRect screenAvailableRect;
    3440    FloatRect screenRect;
     41    RetainPtr<CGColorSpaceRef> colorSpace;
    3542    int screenDepth { 0 };
    3643    int screenDepthPerComponent { 0 };
    3744    bool screenHasInvertedColors { false };
    3845    bool screenIsMonochrome { false };
     46
     47    enum EncodedColorSpaceDataType {
     48        Null,
     49        ColorSpaceName,
     50        ColorSpaceData,
     51    };
    3952
    4053    template<class Encoder> void encode(Encoder&) const;
     
    4659{
    4760    encoder << screenAvailableRect << screenRect << screenDepth << screenDepthPerComponent << screenHasInvertedColors << screenIsMonochrome;
     61
     62    if (colorSpace) {
     63        // Try to encode the name.
     64        if (auto name = adoptCF(CGColorSpaceCopyName(colorSpace.get()))) {
     65            encoder.encodeEnum(ColorSpaceName);
     66            encoder << String(name.get());
     67            return;
     68        }
     69
     70        // Failing that, just encode the ICC data.
     71        if (auto profileData = adoptCF(CGColorSpaceCopyICCData(colorSpace.get()))) {
     72            encoder.encodeEnum(ColorSpaceData);
     73
     74            Vector<uint8_t> iccData;
     75            iccData.append(CFDataGetBytePtr(profileData.get()), CFDataGetLength(profileData.get()));
     76
     77            encoder << iccData;
     78            return;
     79        }
     80    }
     81
     82    // The color space was null or failed to be encoded.
     83    encoder << Null;
    4884}
    4985
     
    81117        return std::nullopt;
    82118
    83     return { { WTFMove(*screenAvailableRect), WTFMove(*screenRect), WTFMove(*screenDepth), WTFMove(*screenDepthPerComponent), WTFMove(*screenHasInvertedColors), WTFMove(*screenIsMonochrome) } };
     119    EncodedColorSpaceDataType dataType;
     120    if (!decoder.decodeEnum(dataType))
     121        return std::nullopt;
     122
     123    RetainPtr<CGColorSpaceRef> cgColorSpace;
     124    switch (dataType) {
     125    case Null:
     126        break;
     127    case ColorSpaceName: {
     128        std::optional<String> colorSpaceName;
     129        decoder >> colorSpaceName;
     130        ASSERT(colorSpaceName);
     131        if (!colorSpaceName)
     132            return std::nullopt;
     133
     134        cgColorSpace = adoptCF(CGColorSpaceCreateWithName(colorSpaceName->createCFString().get()));
     135        break;
     136    }
     137    case ColorSpaceData: {
     138        std::optional<Vector<uint8_t>> iccData;
     139        decoder >> iccData;
     140        ASSERT(iccData);
     141        if (!iccData)
     142            return std::nullopt;
     143
     144        auto colorSpaceData = adoptCF(CFDataCreate(kCFAllocatorDefault, iccData->data(), iccData->size()));
     145        // FIXME: <http://webkit.org/b/184358> We should switch to CGColorSpaceCreateICCBased.
     146#pragma clang diagnostic push
     147#pragma clang diagnostic ignored "-Wdeprecated-declarations"
     148        cgColorSpace = adoptCF(CGColorSpaceCreateWithICCProfile(colorSpaceData.get()));
     149#pragma clang diagnostic pop
     150        break;
     151    }
     152    }
     153
     154    return { { WTFMove(*screenAvailableRect), WTFMove(*screenRect), WTFMove(cgColorSpace), WTFMove(*screenDepth), WTFMove(*screenDepthPerComponent), WTFMove(*screenHasInvertedColors), WTFMove(*screenIsMonochrome) } };
    84155}
    85156
    86157} // namespace WebCore
    87158
     159#endif // PLATFORM(MAC)
  • trunk/Source/WebCore/platform/mac/PlatformScreenMac.mm

    r230331 r230351  
    4949static PlatformDisplayID displayID(NSScreen *screen)
    5050{
    51     // FIXME: <http://webkit.org/b/184343> We should assert here if in WebContent process.
     51    RELEASE_ASSERT(hasProcessPrivilege(ProcessPrivilege::CanCommunicateWithWindowServer));
    5252    return [[[screen deviceDescription] objectForKey:@"NSScreenNumber"] intValue];
    5353}
     
    7272static NSScreen *firstScreen()
    7373{
    74     // FIXME: <http://webkit.org/b/184343> We should assert here if in WebContent process.
     74    RELEASE_ASSERT(hasProcessPrivilege(ProcessPrivilege::CanCommunicateWithWindowServer));
    7575    NSArray *screens = [NSScreen screens];
    7676    if (![screens count])
     
    103103void getScreenProperties(HashMap<PlatformDisplayID, ScreenProperties>& screenProperties)
    104104{
     105    RELEASE_ASSERT(hasProcessPrivilege(ProcessPrivilege::CanCommunicateWithWindowServer));
    105106    for (NSScreen *screen in [NSScreen screens]) {
    106         FloatRect screenAvailableRect = [screen visibleFrame];
    107         screenAvailableRect.setY(NSMaxY([screen frame]) - (screenAvailableRect.y() + screenAvailableRect.height())); // flip
    108         FloatRect screenRect = [screen frame];
     107        FloatRect screenAvailableRect = screen.visibleFrame;
     108        screenAvailableRect.setY(NSMaxY(screen.frame) - (screenAvailableRect.y() + screenAvailableRect.height())); // flip
     109        FloatRect screenRect = screen.frame;
     110
     111        RetainPtr<CGColorSpaceRef> colorSpace = screen.colorSpace.CGColorSpace;
     112
    109113        int screenDepth = NSBitsPerPixelFromDepth(screen.depth);
    110114        int screenDepthPerComponent = NSBitsPerSampleFromDepth(screen.depth);
     
    112116        bool screenIsMonochrome = CGDisplayUsesForceToGray();
    113117
    114         screenProperties.set(WebCore::displayID(screen), ScreenProperties { screenAvailableRect, screenRect, screenDepth, screenDepthPerComponent, screenHasInvertedColors, screenIsMonochrome });
     118        screenProperties.set(WebCore::displayID(screen), ScreenProperties { screenAvailableRect, screenRect, colorSpace, screenDepth, screenDepthPerComponent, screenHasInvertedColors, screenIsMonochrome });
    115119    }
    116120}
     
    214218CGColorSpaceRef screenColorSpace(Widget* widget)
    215219{
    216     // FIXME: <http://webkit.org/b/184343> We should assert here if in WebContent process.
     220    if (!screenProperties().isEmpty())
     221        return getScreenProperties(widget).colorSpace.get();
     222
     223    RELEASE_ASSERT(hasProcessPrivilege(ProcessPrivilege::CanCommunicateWithWindowServer));
    217224    return screen(widget).colorSpace.CGColorSpace;
    218225}
Note: See TracChangeset for help on using the changeset viewer.