Changeset 254202 in webkit
- Timestamp:
- Jan 8, 2020 8:33:18 AM (4 years ago)
- Location:
- trunk/Source
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r254201 r254202 1 2020-01-08 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 Add support for encoding WebCore::Font over IPC for DisplayList::DrawGlyphs 4 https://bugs.webkit.org/show_bug.cgi?id=205830 5 <rdar://problem/57347719> 6 7 Reviewed by Dean Jackson. 8 9 Add support for encoding Fonts. In the case where the Font is installed, we use platform encoders to send across 10 the font descriptor, and reconstruct the font using this descriptor on the receiving end (see the existing 11 implementations of encodeFontInternal and decodeFontInternal). In the case where the Font is not installed, we 12 instead send the font face data over (plumbed across from the CachedFont), and reconstruct the platform font 13 data from the raw font data on the receiving end. 14 15 This allows us to render web fonts in the GPU process through the `DrawGlyphs` display list item. 16 17 * css/CSSFontFace.cpp: 18 (WebCore::CSSFontFace::font): 19 * css/CSSFontFaceSource.h: 20 * platform/graphics/Font.cpp: 21 (WebCore::Font::setFontFaceData): 22 23 Add a way to set font face data used to create the Font. This data comes from a CachedFont's data buffer, and is 24 used to serialize FontHandles when building display list items. 25 26 (WebCore::FontHandle::FontHandle): 27 28 Add a serializable wrapper class that contains a nullable Font. The encoder/decoders for FontHandle are 29 implemented in WebKit2. 30 31 * platform/graphics/Font.h: 32 (WebCore::Font::fontFaceData const): 33 * platform/graphics/displaylists/DisplayListItems.cpp: 34 (WebCore::DisplayList::DrawGlyphs::DrawGlyphs): 35 36 Finish implementing the encode/decode methods for DrawGlyphs, by sending the Font data over via FontHandle. 37 38 * platform/graphics/displaylists/DisplayListItems.h: 39 (WebCore::DisplayList::DrawGlyphs::create): 40 (WebCore::DisplayList::DrawGlyphs::encode const): 41 (WebCore::DisplayList::DrawGlyphs::decode): 42 43 When decoding `DrawGlyphs`, avoid having to rebuild the glyph Vector by adding (and using) new DrawGlyphs 44 constructors that take `Vector&&`s. 45 1 46 2020-01-08 Antoine Quint <graouts@apple.com> 2 47 -
trunk/Source/WebCore/css/CSSFontFace.cpp
r253987 r254202 36 36 #include "CSSValue.h" 37 37 #include "CSSValueList.h" 38 #include "CachedFont.h" 38 39 #include "Document.h" 39 40 #include "Font.h" … … 42 43 #include "FontFace.h" 43 44 #include "Settings.h" 45 #include "SharedBuffer.h" 44 46 #include "StyleBuilderConverter.h" 45 47 #include "StyleProperties.h" … … 674 676 } 675 677 case CSSFontFaceSource::Status::Success: 676 if (RefPtr<Font> result = source->font(fontDescription, syntheticBold, syntheticItalic, m_featureSettings, m_fontSelectionCapabilities)) 678 if (auto result = source->font(fontDescription, syntheticBold, syntheticItalic, m_featureSettings, m_fontSelectionCapabilities)) { 679 auto* cachedFont = source->cachedFont(); 680 result->setFontFaceData(cachedFont ? cachedFont->resourceBuffer() : nullptr); 677 681 return result; 682 } 678 683 break; 679 684 case CSSFontFaceSource::Status::Failure: -
trunk/Source/WebCore/css/CSSFontFaceSource.h
r252760 r254202 73 73 RefPtr<Font> font(const FontDescription&, bool syntheticBold, bool syntheticItalic, const FontFeatureSettings&, FontSelectionSpecifiedCapabilities); 74 74 75 CachedFont* cachedFont() const { return m_font.get(); } 75 76 bool requiresExternalResource() const { return m_font; } 76 77 -
trunk/Source/WebCore/platform/graphics/Font.cpp
r253987 r254202 34 34 #include <pal/spi/cocoa/CoreTextSPI.h> 35 35 #endif 36 #include "CachedFont.h" 36 37 #include "CharacterProperties.h" 37 38 #include "FontCache.h" 38 39 #include "FontCascade.h" 40 #include "FontCustomPlatformData.h" 39 41 #include "OpenTypeMathData.h" 42 #include "SharedBuffer.h" 40 43 #include <wtf/MathExtras.h> 41 44 #include <wtf/NeverDestroyed.h> … … 706 709 } 707 710 711 void Font::setFontFaceData(RefPtr<SharedBuffer>&& fontFaceData) 712 { 713 m_fontFaceData = WTFMove(fontFaceData); 714 } 715 716 FontHandle::FontHandle(Ref<SharedBuffer>&& fontFaceData, Font::Origin origin, float fontSize, bool syntheticBold, bool syntheticItalic) 717 { 718 bool wrapping; 719 auto customFontData = CachedFont::createCustomFontData(fontFaceData.get(), { }, wrapping); 720 FontDescription description; 721 description.setComputedSize(fontSize); 722 font = Font::create(CachedFont::platformDataFromCustomData(*customFontData, description, syntheticBold, syntheticItalic, { }, { }), origin); 723 } 724 708 725 } // namespace WebCore -
trunk/Source/WebCore/platform/graphics/Font.h
r253987 r254202 219 219 #endif 220 220 221 SharedBuffer* fontFaceData() const { return m_fontFaceData.get(); } 222 void setFontFaceData(RefPtr<SharedBuffer>&&); 223 221 224 private: 222 Font(const FontPlatformData&, Origin, Interstitial, Visibility, OrientationFallback);225 WEBCORE_EXPORT Font(const FontPlatformData&, Origin, Interstitial, Visibility, OrientationFallback); 223 226 224 227 void platformInit(); … … 292 295 #endif 293 296 297 RefPtr<SharedBuffer> m_fontFaceData; 298 294 299 Glyph m_spaceGlyph { 0 }; 295 300 Glyph m_zeroGlyph { 0 }; … … 320 325 unsigned m_shouldNotBeUsedForArabic : 1; 321 326 #endif 327 }; 328 329 class FontHandle { 330 public: 331 FontHandle() = default; 332 WEBCORE_EXPORT FontHandle(Ref<SharedBuffer>&& fontFaceData, Font::Origin, float fontSize, bool syntheticBold, bool syntheticItalic); 333 334 RefPtr<Font> font; 322 335 }; 323 336 -
trunk/Source/WebCore/platform/graphics/displaylists/DisplayListItems.cpp
r254047 r254202 513 513 } 514 514 515 DrawGlyphs::DrawGlyphs(const Font& font, Vector<GlyphBufferGlyph, 128>&& glyphs, Vector<GlyphBufferAdvance, 128>&& advances, const FloatPoint& blockLocation, const FloatSize& localAnchor, FontSmoothingMode smoothingMode) 516 : DrawingItem(ItemType::DrawGlyphs) 517 , m_font(const_cast<Font&>(font)) 518 , m_glyphs(WTFMove(glyphs)) 519 , m_advances(WTFMove(advances)) 520 , m_blockLocation(blockLocation) 521 , m_localAnchor(localAnchor) 522 , m_smoothingMode(smoothingMode) 523 { 524 computeBounds(); 525 } 526 515 527 DrawGlyphs::DrawGlyphs(const Font& font, const GlyphBufferGlyph* glyphs, const GlyphBufferAdvance* advances, unsigned count, const FloatPoint& blockLocation, const FloatSize& localAnchor, FontSmoothingMode smoothingMode) 516 528 : DrawingItem(ItemType::DrawGlyphs) -
trunk/Source/WebCore/platform/graphics/displaylists/DisplayListItems.h
r254047 r254202 1058 1058 } 1059 1059 1060 static Ref<DrawGlyphs> create(const Font& font, Vector<GlyphBufferGlyph, 128>&& glyphs, Vector<GlyphBufferAdvance, 128>&& advances, const FloatPoint& blockLocation, const FloatSize& localAnchor, FontSmoothingMode smoothingMode) 1061 { 1062 return adoptRef(*new DrawGlyphs(font, WTFMove(glyphs), WTFMove(advances), blockLocation, localAnchor, smoothingMode)); 1063 } 1064 1060 1065 WEBCORE_EXPORT virtual ~DrawGlyphs(); 1061 1066 … … 1073 1078 1074 1079 private: 1075 WEBCORE_EXPORT DrawGlyphs(const Font&, const GlyphBufferGlyph*, const GlyphBufferAdvance*, unsigned count, const FloatPoint& blockLocation, const FloatSize& localAnchor, FontSmoothingMode); 1080 DrawGlyphs(const Font&, const GlyphBufferGlyph*, const GlyphBufferAdvance*, unsigned count, const FloatPoint& blockLocation, const FloatSize& localAnchor, FontSmoothingMode); 1081 WEBCORE_EXPORT DrawGlyphs(const Font&, Vector<GlyphBufferGlyph, 128>&&, Vector<GlyphBufferAdvance, 128>&&, const FloatPoint& blockLocation, const FloatSize& localAnchor, FontSmoothingMode); 1076 1082 1077 1083 void computeBounds(); … … 1095 1101 void DrawGlyphs::encode(Encoder& encoder) const 1096 1102 { 1097 // FIXME: Add font data to the encoder. 1103 FontHandle handle; 1104 handle.font = m_font.ptr(); 1105 encoder << handle; 1098 1106 encoder << m_glyphs; 1099 1107 encoder << m_advances; … … 1106 1114 Optional<Ref<DrawGlyphs>> DrawGlyphs::decode(Decoder& decoder) 1107 1115 { 1116 Optional<FontHandle> handle; 1117 decoder >> handle; 1118 if (!handle || !handle->font) 1119 return WTF::nullopt; 1120 1108 1121 Optional<Vector<GlyphBufferGlyph, 128>> glyphs; 1109 1122 decoder >> glyphs; … … 1134 1147 return WTF::nullopt; 1135 1148 1136 // FIXME: Create and return a DrawGlyphs once we're able to decode font data. 1137 return WTF::nullopt; 1149 return DrawGlyphs::create(handle->font.releaseNonNull(), WTFMove(*glyphs), WTFMove(*advances), *blockLocation, *localAnchor, *smoothingMode); 1138 1150 } 1139 1151 -
trunk/Source/WebKit/ChangeLog
r254199 r254202 1 2020-01-08 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 Add support for encoding WebCore::Font over IPC for DisplayList::DrawGlyphs 4 https://bugs.webkit.org/show_bug.cgi?id=205830 5 <rdar://problem/57347719> 6 7 Reviewed by Dean Jackson. 8 9 Add basic support for encoding and decoding a FontHandle. 10 11 * Shared/Cocoa/WebCoreArgumentCodersCocoa.mm: 12 (IPC::ArgumentCoder<FontHandle>::encodePlatformData): 13 (IPC::ArgumentCoder<FontHandle>::decodePlatformData): 14 * Shared/WebCoreArgumentCoders.cpp: 15 (IPC::ArgumentCoder<FontHandle>::encode): 16 (IPC::ArgumentCoder<FontHandle>::decode): 17 18 When encoding a Font on Cocoa platforms, send across the font face data (if present); otherwise, fall back to 19 sending the font descriptor for the UIFont or NSFont (as is the case for installed fonts). 20 21 * Shared/WebCoreArgumentCoders.h: 22 * Shared/curl/WebCoreArgumentCodersCurl.cpp: 23 (IPC::ArgumentCoder<FontHandle>::encodePlatformData): 24 (IPC::ArgumentCoder<FontHandle>::decodePlatformData): 25 * Shared/soup/WebCoreArgumentCodersSoup.cpp: 26 (IPC::ArgumentCoder<FontHandle>::encodePlatformData): 27 (IPC::ArgumentCoder<FontHandle>::decodePlatformData): 28 1 29 2020-01-08 Milan Crha <mcrha@redhat.com> 2 30 -
trunk/Source/WebKit/Shared/Cocoa/WebCoreArgumentCodersCocoa.mm
r250179 r254202 29 29 #import "ArgumentCodersCocoa.h" 30 30 #import <WebCore/DictionaryPopupInfo.h> 31 #import <WebCore/Font.h> 31 32 #import <WebCore/FontAttributes.h> 32 33 … … 473 474 } 474 475 476 #if PLATFORM(IOS_FAMILY) 477 #define CocoaFont UIFont 478 #else 479 #define CocoaFont NSFont 480 #endif 481 482 void ArgumentCoder<FontHandle>::encodePlatformData(Encoder& encoder, const FontHandle& handle) 483 { 484 auto ctFont = handle.font && !handle.font->fontFaceData() ? handle.font->getCTFont() : nil; 485 encoder << !!ctFont; 486 if (ctFont) 487 encoder << (__bridge CocoaFont *)ctFont; 488 } 489 490 bool ArgumentCoder<FontHandle>::decodePlatformData(Decoder& decoder, FontHandle& handle) 491 { 492 bool hasPlatformFont; 493 if (!decoder.decode(hasPlatformFont)) 494 return false; 495 496 if (!hasPlatformFont) 497 return true; 498 499 RetainPtr<CocoaFont> font; 500 if (!IPC::decode(decoder, font)) 501 return false; 502 503 auto previousValue = handle.font; 504 handle.font = Font::create({ (__bridge CTFontRef)font.get(), static_cast<float>([font pointSize]) }); 505 return true; 506 } 507 475 508 } // namespace IPC -
trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp
r253636 r254202 49 49 #include <WebCore/FilterOperation.h> 50 50 #include <WebCore/FilterOperations.h> 51 #include <WebCore/Font.h> 51 52 #include <WebCore/FontAttributes.h> 52 53 #include <WebCore/GraphicsContext.h> … … 1126 1127 } 1127 1128 1129 void ArgumentCoder<FontHandle>::encode(Encoder& encoder, const FontHandle& handle) 1130 { 1131 encoder << !!handle.font; 1132 if (!handle.font) 1133 return; 1134 1135 auto* fontFaceData = handle.font->fontFaceData(); 1136 encoder << !!fontFaceData; 1137 if (fontFaceData) { 1138 encodeSharedBuffer(encoder, fontFaceData); 1139 auto& data = handle.font->platformData(); 1140 encoder << data.size(); 1141 encoder << data.syntheticBold(); 1142 encoder << data.syntheticOblique(); 1143 } 1144 1145 encodePlatformData(encoder, handle); 1146 } 1147 1148 bool ArgumentCoder<FontHandle>::decode(Decoder& decoder, FontHandle& handle) 1149 { 1150 Optional<bool> hasFont; 1151 decoder >> hasFont; 1152 if (!hasFont.hasValue()) 1153 return false; 1154 1155 if (!hasFont.value()) 1156 return true; 1157 1158 Optional<bool> hasFontFaceData; 1159 decoder >> hasFontFaceData; 1160 if (!hasFontFaceData.hasValue()) 1161 return false; 1162 1163 if (hasFontFaceData.value()) { 1164 RefPtr<SharedBuffer> fontFaceData; 1165 if (!decodeSharedBuffer(decoder, fontFaceData)) 1166 return false; 1167 1168 if (!fontFaceData) 1169 return false; 1170 1171 Optional<float> fontSize; 1172 decoder >> fontSize; 1173 if (!fontSize) 1174 return false; 1175 1176 Optional<bool> syntheticBold; 1177 decoder >> syntheticBold; 1178 if (!syntheticBold) 1179 return false; 1180 1181 Optional<bool> syntheticItalic; 1182 decoder >> syntheticItalic; 1183 if (!syntheticItalic) 1184 return false; 1185 1186 FontDescription description; 1187 description.setComputedSize(*fontSize); 1188 handle = { fontFaceData.releaseNonNull(), Font::Origin::Remote, *fontSize, *syntheticBold, *syntheticItalic }; 1189 } 1190 1191 return decodePlatformData(decoder, handle); 1192 } 1193 1128 1194 void ArgumentCoder<Cursor>::encode(Encoder& encoder, const Cursor& cursor) 1129 1195 { -
trunk/Source/WebKit/Shared/WebCoreArgumentCoders.h
r253495 r254202 81 81 class FloatSize; 82 82 class FixedPositionViewportConstraints; 83 class FontHandle; 83 84 class HTTPHeaderMap; 84 85 class ImageHandle; … … 380 381 }; 381 382 383 template<> struct ArgumentCoder<WebCore::FontHandle> { 384 static void encode(Encoder&, const WebCore::FontHandle&); 385 static bool decode(Decoder&, WebCore::FontHandle&); 386 static void encodePlatformData(Encoder&, const WebCore::FontHandle&); 387 static bool decodePlatformData(Decoder&, WebCore::FontHandle&); 388 }; 389 382 390 template<> struct ArgumentCoder<WebCore::ImageHandle> { 383 391 static void encode(Encoder&, const WebCore::ImageHandle&); -
trunk/Source/WebKit/Shared/curl/WebCoreArgumentCodersCurl.cpp
r242908 r254202 31 31 #include <WebCore/CurlProxySettings.h> 32 32 #include <WebCore/DictionaryPopupInfo.h> 33 #include <WebCore/Font.h> 33 34 #include <WebCore/FontAttributes.h> 34 35 #include <WebCore/ProtectionSpace.h> … … 235 236 } 236 237 237 } 238 void ArgumentCoder<FontHandle>::encodePlatformData(Encoder&, const FontHandle&) 239 { 240 ASSERT_NOT_REACHED(); 241 } 242 243 bool ArgumentCoder<FontHandle>::decodePlatformData(Decoder&, FontHandle&) 244 { 245 ASSERT_NOT_REACHED(); 246 return false; 247 } 248 249 } -
trunk/Source/WebKit/Shared/soup/WebCoreArgumentCodersSoup.cpp
r242908 r254202 32 32 #include <WebCore/CertificateInfo.h> 33 33 #include <WebCore/DictionaryPopupInfo.h> 34 #include <WebCore/Font.h> 34 35 #include <WebCore/FontAttributes.h> 35 36 #include <WebCore/ResourceError.h> … … 252 253 } 253 254 254 } 255 255 void ArgumentCoder<FontHandle>::encodePlatformData(Encoder&, const FontHandle&) 256 { 257 ASSERT_NOT_REACHED(); 258 } 259 260 bool ArgumentCoder<FontHandle>::decodePlatformData(Decoder&, FontHandle&) 261 { 262 ASSERT_NOT_REACHED(); 263 return false; 264 } 265 266 } 267
Note: See TracChangeset
for help on using the changeset viewer.