Changeset 230351 in webkit
- Timestamp:
- Apr 6, 2018 12:37:17 PM (6 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r230350 r230351 1 2018-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 1 23 2018-04-06 Ms2ger <Ms2ger@igalia.com> 2 24 -
trunk/Source/WebCore/platform/ScreenProperties.h
r230323 r230351 26 26 #pragma once 27 27 28 #if PLATFORM(MAC) 29 28 30 #include "FloatRect.h" 31 #include <wtf/RetainPtr.h> 32 #include <wtf/text/WTFString.h> 33 34 typedef struct CGColorSpace *CGColorSpaceRef; 29 35 30 36 namespace WebCore { … … 33 39 FloatRect screenAvailableRect; 34 40 FloatRect screenRect; 41 RetainPtr<CGColorSpaceRef> colorSpace; 35 42 int screenDepth { 0 }; 36 43 int screenDepthPerComponent { 0 }; 37 44 bool screenHasInvertedColors { false }; 38 45 bool screenIsMonochrome { false }; 46 47 enum EncodedColorSpaceDataType { 48 Null, 49 ColorSpaceName, 50 ColorSpaceData, 51 }; 39 52 40 53 template<class Encoder> void encode(Encoder&) const; … … 46 59 { 47 60 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; 48 84 } 49 85 … … 81 117 return std::nullopt; 82 118 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) } }; 84 155 } 85 156 86 157 } // namespace WebCore 87 158 159 #endif // PLATFORM(MAC) -
trunk/Source/WebCore/platform/mac/PlatformScreenMac.mm
r230331 r230351 49 49 static PlatformDisplayID displayID(NSScreen *screen) 50 50 { 51 // FIXME: <http://webkit.org/b/184343> We should assert here if in WebContent process.51 RELEASE_ASSERT(hasProcessPrivilege(ProcessPrivilege::CanCommunicateWithWindowServer)); 52 52 return [[[screen deviceDescription] objectForKey:@"NSScreenNumber"] intValue]; 53 53 } … … 72 72 static NSScreen *firstScreen() 73 73 { 74 // FIXME: <http://webkit.org/b/184343> We should assert here if in WebContent process.74 RELEASE_ASSERT(hasProcessPrivilege(ProcessPrivilege::CanCommunicateWithWindowServer)); 75 75 NSArray *screens = [NSScreen screens]; 76 76 if (![screens count]) … … 103 103 void getScreenProperties(HashMap<PlatformDisplayID, ScreenProperties>& screenProperties) 104 104 { 105 RELEASE_ASSERT(hasProcessPrivilege(ProcessPrivilege::CanCommunicateWithWindowServer)); 105 106 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 109 113 int screenDepth = NSBitsPerPixelFromDepth(screen.depth); 110 114 int screenDepthPerComponent = NSBitsPerSampleFromDepth(screen.depth); … … 112 116 bool screenIsMonochrome = CGDisplayUsesForceToGray(); 113 117 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 }); 115 119 } 116 120 } … … 214 218 CGColorSpaceRef screenColorSpace(Widget* widget) 215 219 { 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)); 217 224 return screen(widget).colorSpace.CGColorSpace; 218 225 }
Note: See TracChangeset
for help on using the changeset viewer.